]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
network: change link group type to int32
authorSlava Bacherikov <slava@bacher09.org>
Sat, 13 Nov 2021 12:43:04 +0000 (14:43 +0200)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Mon, 15 Nov 2021 16:53:46 +0000 (01:53 +0900)
Both linux kernel kernel and iproute2 uses int32 type for a link group
attribute and -1 has a special meaning, so setting it to 4294967295
would make it -1 in the linux kernel (and ip link cmd).

man/systemd.network.xml
src/network/networkd-network.c
src/network/networkd-network.h
src/network/networkd-setlink.c

index ab08797a9eed0abc8cd74f539d6426f91d782cc5..dea600fbd6bffe533f4453aaf50f4bf8d495b1b4 100644 (file)
         <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. Takes an unsigned integer in the range 0…4294967295. Defaults to unset.
+          performed at once. Takes an unsigned integer in the range 0…2147483647. Defaults to unset.
           </para>
         </listitem>
       </varlistentry>
index a41bc25cca8168e4d2eda73f3a753bd26f9e676e..90da1670f0c4b703ef729a6b45f36b064647a4f7 100644 (file)
@@ -1256,6 +1256,7 @@ int config_parse_link_group(
 
         Network *network = userdata;
         int r;
+        int32_t group;
 
         assert(filename);
         assert(lvalue);
@@ -1263,19 +1264,24 @@ int config_parse_link_group(
         assert(network);
 
         if (isempty(rvalue)) {
-                network->group = 0;
-                network->group_set = false;
+                network->group = -1;
                 return 0;
         }
 
-        r = safe_atou32(rvalue, &network->group);
+        r = safe_atoi32(rvalue, &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;
+        if (group < 0) {
+                log_syntax(unit, LOG_WARNING, filename, line, r,
+                           "Value of Group= must be in the range 0…2147483647, ignoring assignment: %s", rvalue);
+                return 0;
+        }
+
+        network->group = group;
         return 0;
 }
 
index c86a492a17285f1b7c8fe466f592bfd9b24f4dc9..fb79ee85095e475b9bbf41af359a7e14de5ec8bf 100644 (file)
@@ -96,8 +96,7 @@ struct Network {
         /* [Link] section */
         struct ether_addr *mac;
         uint32_t mtu;
-        uint32_t group;
-        bool group_set;
+        int32_t group;
         int arp;
         int multicast;
         int allmulticast;
index cc44b400b2e2736f039c98c6fbfafa41a65b5143..4ec47a495f1bb67996af4976451af6702340b6a1 100644 (file)
@@ -458,7 +458,7 @@ static int link_configure(
                 break;
         }
         case SET_LINK_GROUP:
-                r = sd_netlink_message_append_u32(req, IFLA_GROUP, link->network->group);
+                r = sd_netlink_message_append_u32(req, IFLA_GROUP, (uint32_t) link->network->group);
                 if (r < 0)
                         return log_link_debug_errno(link, r, "Could not append IFLA_GROUP attribute: %m");
                 break;
@@ -770,7 +770,7 @@ int link_request_to_set_group(Link *link) {
         assert(link);
         assert(link->network);
 
-        if (!link->network->group_set)
+        if (link->network->group < 0)
                 return 0;
 
         return link_request_set_link(link, SET_LINK_GROUP, link_set_group_handler, NULL);