]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
network: Add support to group links.
authorSusant Sahani <ssahani@vmware.com>
Tue, 7 Apr 2020 12:36:55 +0000 (14:36 +0200)
committerLennart Poettering <lennart@poettering.net>
Fri, 15 May 2020 13:27:07 +0000 (15:27 +0200)
Link groups are similar to port ranges found in managed switches.
You can add network interfaces to a numbered group and perform operations
on all the interfaces from that group at once.

man/systemd.network.xml
src/network/networkd-link.c
src/network/networkd-network-gperf.gperf
src/network/networkd-network.h
test/fuzz/fuzz-network-parser/directives.network

index c73bdccd8d4c44d5b06c1447903b95e4f1ab1556..d891873c7eb193580d966f9ebf475041940c4e1a 100644 (file)
           controlled by other applications.</para>
         </listitem>
       </varlistentry>
+      <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 ranges 0 to 4294967294. Default to unset.</para>
+        </listitem>
+      </varlistentry>
       <varlistentry>
         <term><varname>RequiredForOnline=</varname></term>
         <listitem>
index e261473f6f2f2150093cbc119d758abca3109732..32fe86045d6172cdaae813b1eaf7aff2ad3e09b2 100644 (file)
@@ -1825,6 +1825,53 @@ int link_down(Link *link, link_netlink_message_handler_t callback) {
         return 0;
 }
 
+static int link_group_handler(sd_netlink *rtnl, sd_netlink_message *m, Link *link) {
+        int r;
+
+        assert(link);
+
+        if (IN_SET(link->state, LINK_STATE_FAILED, LINK_STATE_LINGER))
+                return 1;
+
+        r = sd_netlink_message_get_errno(m);
+        if (r < 0)
+                log_link_message_warning_errno(link, m, r, "Could not set group for the interface");
+
+        return 1;
+}
+
+static int link_set_group(Link *link) {
+        _cleanup_(sd_netlink_message_unrefp) sd_netlink_message *req = NULL;
+        int r;
+
+        assert(link);
+        assert(link->network);
+        assert(link->manager);
+        assert(link->manager->rtnl);
+
+        if (link->network->group <= 0)
+                return 0;
+
+        log_link_debug(link, "Setting group");
+
+        r = sd_rtnl_message_new_link(link->manager->rtnl, &req, RTM_SETLINK, link->ifindex);
+        if (r < 0)
+                return log_link_error_errno(link, r, "Could not allocate RTM_SETLINK message: %m");
+
+        r = sd_netlink_message_append_u32(req, IFLA_GROUP, link->network->group);
+        if (r < 0)
+                return log_link_error_errno(link, r, "Could not set link group: %m");
+
+        r = netlink_call_async(link->manager->rtnl, NULL, req, link_group_handler,
+                               link_netlink_destroy_callback, link);
+        if (r < 0)
+                return log_link_error_errno(link, r, "Could not send rtnetlink message: %m");
+
+        link_ref(link);
+
+        return 0;
+}
+
 static int link_handle_bound_to_list(Link *link) {
         Link *l;
         Iterator i;
@@ -2819,6 +2866,10 @@ static int link_configure(Link *link) {
         if (r < 0)
                 return r;
 
+        r = link_set_group(link);
+        if (r < 0)
+                return r;
+
         if (link_ipv4ll_enabled(link, ADDRESS_FAMILY_IPV4 | ADDRESS_FAMILY_FALLBACK_IPV4)) {
                 r = ipv4ll_configure(link);
                 if (r < 0)
index 7316ccffd09848f4cf6053bbf5aacee4172ce0e8..d709633df34012f34005741f8965d1b4015dfd0f 100644 (file)
@@ -46,6 +46,7 @@ Match.KernelVersion,                         config_parse_net_condition,
 Match.Architecture,                          config_parse_net_condition,                               CONDITION_ARCHITECTURE,        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.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 90fe222e123fb20bc172ad3b145b739569e06a59..092e58d42c9c98f804ea63e3ee24615e84e92168 100644 (file)
@@ -247,6 +247,7 @@ struct Network {
 
         struct ether_addr *mac;
         uint32_t mtu;
+        uint32_t group;
         int arp;
         int multicast;
         int allmulticast;
index 07a9c8ba2d79010990d859be537f0b381d7af298..82399f7b1a7808b8d13ef3dcb1eef92cf253c6ce 100644 (file)
@@ -37,6 +37,7 @@ Unmanaged=
 MTUBytes=
 Multicast=
 MACAddress=
+Group=
 [BridgeFDB]
 VLANId=
 MACAddress=