]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
network: allow to set Group=0 in [Link] section
authorYu Watanabe <watanabe.yu+github@gmail.com>
Fri, 21 May 2021 05:11:36 +0000 (14:11 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Mon, 24 May 2021 22:12:05 +0000 (07:12 +0900)
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.

man/systemd.network.xml
src/network/networkd-link.c
src/network/networkd-network-gperf.gperf
src/network/networkd-network.c
src/network/networkd-network.h

index e267d4d40c68f92835d78d05daf9cee2e8038485..00bbd0f7d8acfa2b77be30aa66c71d3c01edeb7a 100644 (file)
       <varlistentry>
         <term><varname>Group=</varname></term>
         <listitem>
-          <para>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.</para>
+          <para>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.
+          </para>
         </listitem>
       </varlistentry>
       <varlistentry>
index e853b45d13505cfb29b3f660a7287a3c6aa843dc..97529f6be00b80649cd948d1ac0985d9a11144b7 100644 (file)
@@ -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");
index 64b77a0276907cf181ec2beaa12d2dae5a224b7b..ff22e89733a16917413c40e5674f8fa612058ccd 100644 (file)
@@ -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)
index 0fa505bcbb3d0418518abd111b6b5782666f418e..734b7fbdad1bbd191584b5a850d851dedf43129d 100644 (file)
@@ -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");
 
index 42a8bc3ef49c2fbdaaad40d1ede13a1b52b31c42..bd2e25f077e113b51754222c63e65c9a88b75273 100644 (file)
@@ -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);