diff --git a/man/systemd.netdev.xml b/man/systemd.netdev.xml index 7b702e8ed1..c690786130 100644 --- a/man/systemd.netdev.xml +++ b/man/systemd.netdev.xml @@ -1486,7 +1486,6 @@ Protocol=4 /etc/systemd/network/25-fou-ipip.netdev [NetDev] -[NetDev] Name=ipip-tun Kind=ipip diff --git a/src/libsystemd-network/network-internal.c b/src/libsystemd-network/network-internal.c index 949798a1d3..d35e3e2ce1 100644 --- a/src/libsystemd-network/network-internal.c +++ b/src/libsystemd-network/network-internal.c @@ -255,11 +255,10 @@ int config_parse_ifalias(const char *unit, return 0; } - free(*s); - if (*n) - *s = TAKE_PTR(n); + if (isempty(n)) + *s = mfree(*s); else - *s = NULL; + free_and_replace(*s, n); return 0; } @@ -294,7 +293,7 @@ int config_parse_hwaddr(const char *unit, return 0; } - *hwaddr = TAKE_PTR(n); + free_and_replace(*hwaddr, n); return 0; } diff --git a/src/network/netdev/bond.c b/src/network/netdev/bond.c index 43019c3700..248b7b4eef 100644 --- a/src/network/netdev/bond.c +++ b/src/network/netdev/bond.c @@ -376,10 +376,8 @@ int config_parse_arp_ip_target_address(const char *unit, return 0; } - LIST_PREPEND(arp_ip_target, b->arp_ip_targets, buffer); + LIST_PREPEND(arp_ip_target, b->arp_ip_targets, TAKE_PTR(buffer)); b->n_arp_ip_targets++; - - buffer = NULL; } if (b->n_arp_ip_targets > NETDEV_BOND_ARP_TARGETS_MAX) diff --git a/src/network/netdev/netdev-gperf.gperf b/src/network/netdev/netdev-gperf.gperf index f754f230d7..4cf92204ba 100644 --- a/src/network/netdev/netdev-gperf.gperf +++ b/src/network/netdev/netdev-gperf.gperf @@ -108,7 +108,9 @@ GENEVE.TOS, config_parse_uint8, 0, GENEVE.TTL, config_parse_uint8, 0, offsetof(Geneve, ttl) GENEVE.UDPChecksum, config_parse_bool, 0, offsetof(Geneve, udpcsum) GENEVE.UDP6ZeroCheckSumRx, config_parse_bool, 0, offsetof(Geneve, udp6zerocsumrx) +GENEVE.UDP6ZeroChecksumRx, config_parse_bool, 0, offsetof(Geneve, udp6zerocsumrx) GENEVE.UDP6ZeroCheckSumTx, config_parse_bool, 0, offsetof(Geneve, udp6zerocsumtx) +GENEVE.UDP6ZeroChecksumTx, config_parse_bool, 0, offsetof(Geneve, udp6zerocsumtx) GENEVE.DestinationPort, config_parse_ip_port, 0, offsetof(Geneve, dest_port) GENEVE.FlowLabel, config_parse_geneve_flow_label, 0, 0 Tun.OneQueue, config_parse_bool, 0, offsetof(TunTap, one_queue) diff --git a/src/network/netdev/vcan.c b/src/network/netdev/vcan.c index f06ad0fb42..574d1cad31 100644 --- a/src/network/netdev/vcan.c +++ b/src/network/netdev/vcan.c @@ -4,5 +4,6 @@ const NetDevVTable vcan_vtable = { .object_size = sizeof(VCan), + .sections = "Match\0NetDev\0", .create_type = NETDEV_CREATE_INDEPENDENT, }; diff --git a/src/network/netdev/vrf.c b/src/network/netdev/vrf.c index b18090f7a1..5efab537cc 100644 --- a/src/network/netdev/vrf.c +++ b/src/network/netdev/vrf.c @@ -27,7 +27,7 @@ static int netdev_vrf_fill_message_create(NetDev *netdev, Link *link, sd_netlink const NetDevVTable vrf_vtable = { .object_size = sizeof(Vrf), - .sections = "NetDev\0VRF\0", + .sections = "Match\0NetDev\0VRF\0", .fill_message_create = netdev_vrf_fill_message_create, .create_type = NETDEV_CREATE_MASTER, }; diff --git a/src/network/networkd-address.c b/src/network/networkd-address.c index a87786876b..9cccf25cb9 100644 --- a/src/network/networkd-address.c +++ b/src/network/networkd-address.c @@ -91,10 +91,8 @@ void address_free(Address *address) { assert(address->network->n_static_addresses > 0); address->network->n_static_addresses--; - if (address->section) { + if (address->section) hashmap_remove(address->network->addresses_by_section, address->section); - network_config_section_free(address->section); - } } if (address->link) { @@ -105,6 +103,8 @@ void address_free(Address *address) { memzero(&address->link->ipv6ll_address, sizeof(struct in6_addr)); } + network_config_section_free(address->section); + free(address->label); free(address); } diff --git a/src/network/networkd-fdb.c b/src/network/networkd-fdb.c index 694065e3d9..aa0c4c800f 100644 --- a/src/network/networkd-fdb.c +++ b/src/network/networkd-fdb.c @@ -200,7 +200,7 @@ int config_parse_fdb_hwaddr( &fdb_entry->mac_addr->ether_addr_octet[4], &fdb_entry->mac_addr->ether_addr_octet[5]); - if (ETHER_ADDR_LEN != r) { + if (r != ETHER_ADDR_LEN) { log_syntax(unit, LOG_ERR, filename, line, 0, "Not a valid MAC address, ignoring assignment: %s", rvalue); return 0; } diff --git a/src/network/networkd-ipv6-proxy-ndp.c b/src/network/networkd-ipv6-proxy-ndp.c index c4e2091142..cb25812260 100644 --- a/src/network/networkd-ipv6-proxy-ndp.c +++ b/src/network/networkd-ipv6-proxy-ndp.c @@ -88,16 +88,16 @@ void ipv6_proxy_ndp_address_free(IPv6ProxyNDPAddress *ipv6_proxy_ndp_address) { } int config_parse_ipv6_proxy_ndp_address( - const char *unit, - const char *filename, - unsigned line, - const char *section, - unsigned section_line, - const char *lvalue, - int ltype, - const char *rvalue, - void *data, - void *userdata) { + const char *unit, + const char *filename, + unsigned line, + const char *section, + unsigned section_line, + const char *lvalue, + int ltype, + const char *rvalue, + void *data, + void *userdata) { Network *network = userdata; _cleanup_(ipv6_proxy_ndp_address_freep) IPv6ProxyNDPAddress *ipv6_proxy_ndp_address = NULL; diff --git a/src/network/networkd-manager.c b/src/network/networkd-manager.c index 9dcd911535..c8a6f81fd8 100644 --- a/src/network/networkd-manager.c +++ b/src/network/networkd-manager.c @@ -201,7 +201,7 @@ static int manager_udev_process_link(sd_device_monitor *monitor, sd_device *devi } if (!STR_IN_SET(action, "add", "change")) { - log_device_debug(device, "Ignoring udev %s event for device: %m", action); + log_device_debug(device, "Ignoring udev %s event for device.", action); return 0; } diff --git a/src/network/networkd-network-gperf.gperf b/src/network/networkd-network-gperf.gperf index ac924596f3..adbba5f480 100644 --- a/src/network/networkd-network-gperf.gperf +++ b/src/network/networkd-network-gperf.gperf @@ -38,8 +38,8 @@ Link.AllMulticast, config_parse_tristate, Link.Unmanaged, config_parse_bool, 0, offsetof(Network, unmanaged) Link.RequiredForOnline, config_parse_bool, 0, offsetof(Network, required_for_online) Network.Description, config_parse_string, 0, offsetof(Network, description) -Network.Bridge, config_parse_netdev, 0, offsetof(Network, bridge) -Network.Bond, config_parse_netdev, 0, offsetof(Network, bond) +Network.Bridge, config_parse_netdev, 0, 0 +Network.Bond, config_parse_netdev, 0, 0 Network.VLAN, config_parse_netdev, 0, 0 Network.MACVLAN, config_parse_netdev, 0, 0 Network.MACVTAP, config_parse_netdev, 0, 0 diff --git a/src/network/networkd-network.c b/src/network/networkd-network.c index 8d7795d72c..1890021f51 100644 --- a/src/network/networkd-network.c +++ b/src/network/networkd-network.c @@ -607,14 +607,17 @@ int config_parse_netdev(const char *unit, switch (kind) { case NETDEV_KIND_BRIDGE: + network->bridge = netdev_unref(network->bridge); network->bridge = netdev; break; case NETDEV_KIND_BOND: + network->bond = netdev_unref(network->bond); network->bond = netdev; break; case NETDEV_KIND_VRF: + network->vrf = netdev_unref(network->vrf); network->vrf = netdev; break; diff --git a/src/network/networkd-network.h b/src/network/networkd-network.h index 1be7d46735..495fac83d3 100644 --- a/src/network/networkd-network.h +++ b/src/network/networkd-network.h @@ -78,6 +78,8 @@ typedef enum RADVPrefixDelegation { RADV_PREFIX_DELEGATION_STATIC, RADV_PREFIX_DELEGATION_DHCP6, RADV_PREFIX_DELEGATION_BOTH, + _RADV_PREFIX_DELEGATION_MAX, + _RADV_PREFIX_DELEGATION_INVALID = -1, } RADVPrefixDelegation; typedef struct NetworkConfigSection { @@ -316,3 +318,6 @@ DHCPUseDomains dhcp_use_domains_from_string(const char *s) _pure_; const char* lldp_mode_to_string(LLDPMode m) _const_; LLDPMode lldp_mode_from_string(const char *s) _pure_; + +const char* radv_prefix_delegation_to_string(RADVPrefixDelegation i) _const_; +RADVPrefixDelegation radv_prefix_delegation_from_string(const char *s) _pure_; diff --git a/src/network/networkd-radv.c b/src/network/networkd-radv.c index 9b393d82a0..600fb27d75 100644 --- a/src/network/networkd-radv.c +++ b/src/network/networkd-radv.c @@ -12,8 +12,21 @@ #include "parse-util.h" #include "sd-radv.h" #include "string-util.h" +#include "string-table.h" #include "strv.h" +static const char * const radv_prefix_delegation_table[_RADV_PREFIX_DELEGATION_MAX] = { + [RADV_PREFIX_DELEGATION_NONE] = "no", + [RADV_PREFIX_DELEGATION_STATIC] = "static", + [RADV_PREFIX_DELEGATION_DHCP6] = "dhcpv6", + [RADV_PREFIX_DELEGATION_BOTH] = "yes", +}; + +DEFINE_STRING_TABLE_LOOKUP_WITH_BOOLEAN( + radv_prefix_delegation, + RADVPrefixDelegation, + RADV_PREFIX_DELEGATION_BOTH); + int config_parse_router_prefix_delegation( const char *unit, const char *filename, @@ -27,7 +40,7 @@ int config_parse_router_prefix_delegation( void *userdata) { Network *network = userdata; - int d; + RADVPrefixDelegation d; assert(filename); assert(section); @@ -35,21 +48,14 @@ int config_parse_router_prefix_delegation( assert(rvalue); assert(data); - if (streq(rvalue, "static")) - network->router_prefix_delegation = RADV_PREFIX_DELEGATION_STATIC; - else if (streq(rvalue, "dhcpv6")) - network->router_prefix_delegation = RADV_PREFIX_DELEGATION_DHCP6; - else { - d = parse_boolean(rvalue); - if (d > 0) - network->router_prefix_delegation = RADV_PREFIX_DELEGATION_BOTH; - else - network->router_prefix_delegation = RADV_PREFIX_DELEGATION_NONE; - - if (d < 0) - log_syntax(unit, LOG_ERR, filename, line, -EINVAL, "Router prefix delegation '%s' is invalid, ignoring assignment: %m", rvalue); + d = radv_prefix_delegation_from_string(rvalue); + if (d < 0) { + log_syntax(unit, LOG_ERR, filename, line, -EINVAL, "Invalid router prefix delegation '%s', ignoring assignment.", rvalue); + return 0; } + network->router_prefix_delegation = d; + return 0; } @@ -92,13 +98,12 @@ void prefix_free(Prefix *prefix) { assert(prefix->network->n_static_prefixes > 0); prefix->network->n_static_prefixes--; - if (prefix->section) { + if (prefix->section) hashmap_remove(prefix->network->prefixes_by_section, prefix->section); - network_config_section_free(prefix->section); - } } + network_config_section_free(prefix->section); prefix->radv_prefix = sd_radv_prefix_unref(prefix->radv_prefix); free(prefix); diff --git a/src/network/test-network-tables.c b/src/network/test-network-tables.c index 521c5c2dc5..cfcfbeebf2 100644 --- a/src/network/test-network-tables.c +++ b/src/network/test-network-tables.c @@ -33,6 +33,7 @@ int main(int argc, char **argv) { test_table(lldp_mode, LLDP_MODE); test_table(netdev_kind, NETDEV_KIND); test_table(nl_union_link_info_data, NL_UNION_LINK_INFO_DATA); + test_table(radv_prefix_delegation, RADV_PREFIX_DELEGATION); test_table(wol, WOL); test_table_sparse(ipvlan_mode, NETDEV_IPVLAN_MODE); diff --git a/src/shared/vlan-util.c b/src/shared/vlan-util.c index 400994a354..2f9df7dd1b 100644 --- a/src/shared/vlan-util.c +++ b/src/shared/vlan-util.c @@ -9,6 +9,9 @@ int parse_vlanid(const char *p, uint16_t *ret) { uint16_t id; int r; + assert(p); + assert(ret); + r = safe_atou16(p, &id); if (r < 0) return r; diff --git a/test/test-network/conf/dhcp-client-timezone-router.network b/test/test-network/conf/dhcp-client-timezone-router.network index 6316f9cf59..23e04649de 100644 --- a/test/test-network/conf/dhcp-client-timezone-router.network +++ b/test/test-network/conf/dhcp-client-timezone-router.network @@ -4,5 +4,7 @@ Name=veth99 [Network] IPv6AcceptRA=false DHCP=ipv4 + +[DHCP] UseRoutes=true UseTimezone=true diff --git a/test/test-network/systemd-networkd-tests.py b/test/test-network/systemd-networkd-tests.py index b418d15e8c..1a69af149c 100755 --- a/test/test-network/systemd-networkd-tests.py +++ b/test/test-network/systemd-networkd-tests.py @@ -61,6 +61,7 @@ class Utilities(): for link in links: if os.path.exists(os.path.join('/sys/class/net', link)): subprocess.call(['ip', 'link', 'del', 'dev', link]) + time.sleep(1) def read_ipv6_sysctl_attr(self, link, attribute): with open(os.path.join(os.path.join(network_sysctl_ipv6_path, link), attribute)) as f: