From: Yu Watanabe Date: Fri, 21 May 2021 05:11:36 +0000 (+0900) Subject: network: allow to set Group=0 in [Link] section X-Git-Tag: v249-rc1~161^2~1 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=f0c09831bddb9f335af1b1ebfa6eb8424c2058f3;p=thirdparty%2Fsystemd.git network: allow to set Group=0 in [Link] section Previously, when a link has already in a numbered group, we cannot remove the link from the group. This also fixes the range mentioned in the man page. --- diff --git a/man/systemd.network.xml b/man/systemd.network.xml index e267d4d40c6..00bbd0f7d8a 100644 --- a/man/systemd.network.xml +++ b/man/systemd.network.xml @@ -204,10 +204,10 @@ Group= - Link groups are similar to port ranges found in managed switches. - When network interfaces are added to a numbered group, operations on - all the interfaces from that group can be performed at once. An unsigned - integer in the range 0…4294967294. Defaults to unset. + Link groups are similar to port ranges found in managed switches. When network interfaces + are added to a numbered group, operations on all the interfaces from that group can be + performed at once. Takes an unsigned integer in the range 0…4294967295. Defaults to unset. + diff --git a/src/network/networkd-link.c b/src/network/networkd-link.c index e853b45d135..97529f6be00 100644 --- a/src/network/networkd-link.c +++ b/src/network/networkd-link.c @@ -1454,7 +1454,7 @@ static int link_set_group(Link *link) { assert(link->manager); assert(link->manager->rtnl); - if (link->network->group <= 0) + if (!link->network->group_set) return 0; log_link_debug(link, "Setting group"); diff --git a/src/network/networkd-network-gperf.gperf b/src/network/networkd-network-gperf.gperf index 64b77a02769..ff22e89733a 100644 --- a/src/network/networkd-network-gperf.gperf +++ b/src/network/networkd-network-gperf.gperf @@ -59,7 +59,7 @@ Match.Architecture, config_parse_net_condition, Match.Firmware, config_parse_net_condition, CONDITION_FIRMWARE, offsetof(Network, conditions) Link.MACAddress, config_parse_hwaddr, 0, offsetof(Network, mac) Link.MTUBytes, config_parse_mtu, AF_UNSPEC, offsetof(Network, mtu) -Link.Group, config_parse_uint32, 0, offsetof(Network, group) +Link.Group, config_parse_link_group, 0, 0 Link.ARP, config_parse_tristate, 0, offsetof(Network, arp) Link.Multicast, config_parse_tristate, 0, offsetof(Network, multicast) Link.AllMulticast, config_parse_tristate, 0, offsetof(Network, allmulticast) diff --git a/src/network/networkd-network.c b/src/network/networkd-network.c index 0fa505bcbb3..734b7fbdad1 100644 --- a/src/network/networkd-network.c +++ b/src/network/networkd-network.c @@ -1110,6 +1110,43 @@ int config_parse_required_for_online( return 0; } +int config_parse_link_group( + 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; + int r; + + assert(filename); + assert(lvalue); + assert(rvalue); + assert(network); + + if (isempty(rvalue)) { + network->group = 0; + network->group_set = false; + return 0; + } + + r = safe_atou32(rvalue, &network->group); + if (r < 0) { + log_syntax(unit, LOG_WARNING, filename, line, r, + "Failed to parse Group=, ignoring assignment: %s", rvalue); + return 0; + } + + network->group_set = true; + return 0; +} + DEFINE_CONFIG_PARSE_ENUM(config_parse_required_family_for_online, link_required_address_family, AddressFamily, "Failed to parse RequiredFamilyForOnline= setting"); diff --git a/src/network/networkd-network.h b/src/network/networkd-network.h index 42a8bc3ef49..bd2e25f077e 100644 --- a/src/network/networkd-network.h +++ b/src/network/networkd-network.h @@ -97,6 +97,7 @@ struct Network { struct ether_addr *mac; uint32_t mtu; uint32_t group; + bool group_set; int arp; int multicast; int allmulticast; @@ -359,6 +360,7 @@ CONFIG_PARSER_PROTOTYPE(config_parse_required_family_for_online); CONFIG_PARSER_PROTOTYPE(config_parse_keep_configuration); CONFIG_PARSER_PROTOTYPE(config_parse_ipv6_link_local_address_gen_mode); CONFIG_PARSER_PROTOTYPE(config_parse_activation_policy); +CONFIG_PARSER_PROTOTYPE(config_parse_link_group); const struct ConfigPerfItem* network_network_gperf_lookup(const char *key, GPERF_LEN_TYPE length);