]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
network: introduce link_request_to_set_bond()
authorYu Watanabe <watanabe.yu+github@gmail.com>
Tue, 25 May 2021 07:49:34 +0000 (16:49 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Mon, 7 Jun 2021 21:33:27 +0000 (06:33 +0900)
This will be used in later commits.

src/network/networkd-setlink.c
src/network/networkd-setlink.h

index 0c20a98027003524fd722fb5942d0c5a91a3f316..3a96fc9d7b24210721297e2c4343fc88f94d1ee7 100644 (file)
@@ -13,6 +13,7 @@
 
 static const char *const set_link_operation_table[_SET_LINK_OPERATION_MAX] = {
         [SET_LINK_ADDRESS_GENERATION_MODE] = "IPv6LL address generation mode",
+        [SET_LINK_BOND]                    = "bond configurations",
         [SET_LINK_BRIDGE]                  = "bridge configurations",
         [SET_LINK_FLAGS]                   = "link flags",
         [SET_LINK_GROUP]                   = "interface group",
@@ -68,6 +69,10 @@ static int link_set_addrgen_mode_handler(sd_netlink *rtnl, sd_netlink_message *m
         return 0;
 }
 
+static int link_set_bond_handler(sd_netlink *rtnl, sd_netlink_message *m, Link *link) {
+        return set_link_handler_internal(rtnl, m, link, SET_LINK_BOND, true);
+}
+
 static int link_set_bridge_handler(sd_netlink *rtnl, sd_netlink_message *m, Link *link) {
         return set_link_handler_internal(rtnl, m, link, SET_LINK_BRIDGE, true);
 }
@@ -128,9 +133,15 @@ static int link_configure(
 
         log_link_debug(link, "Setting %s", set_link_operation_to_string(op));
 
-        r = sd_rtnl_message_new_link(link->manager->rtnl, &req, RTM_SETLINK, link->ifindex);
-        if (r < 0)
-                return log_link_debug_errno(link, r, "Could not allocate RTM_SETLINK message: %m");
+        if (op == SET_LINK_BOND) {
+                r = sd_rtnl_message_new_link(link->manager->rtnl, &req, RTM_NEWLINK, link->master_ifindex);
+                if (r < 0)
+                        return log_link_debug_errno(link, r, "Could not allocate RTM_NEWLINK message: %m");
+        } else {
+                r = sd_rtnl_message_new_link(link->manager->rtnl, &req, RTM_SETLINK, link->ifindex);
+                if (r < 0)
+                        return log_link_debug_errno(link, r, "Could not allocate RTM_SETLINK message: %m");
+        }
 
         switch (op) {
         case SET_LINK_ADDRESS_GENERATION_MODE:
@@ -154,6 +165,40 @@ static int link_configure(
                 if (r < 0)
                         return log_link_debug_errno(link, r, "Could not close IFLA_AF_SPEC container: %m");
                 break;
+        case SET_LINK_BOND:
+                r = sd_netlink_message_set_flags(req, NLM_F_REQUEST | NLM_F_ACK);
+                if (r < 0)
+                        return log_link_debug_errno(link, r, "Could not set netlink message flags: %m");
+
+                r = sd_netlink_message_open_container(req, IFLA_LINKINFO);
+                if (r < 0)
+                        return log_link_debug_errno(link, r, "Could not open IFLA_LINKINFO container: %m");
+
+                r = sd_netlink_message_open_container_union(req, IFLA_INFO_DATA, "bond");
+                if (r < 0)
+                        return log_link_debug_errno(link, r, "Could not open IFLA_INFO_DATA container: %m");
+
+                if (link->network->active_slave) {
+                        r = sd_netlink_message_append_u32(req, IFLA_BOND_ACTIVE_SLAVE, link->ifindex);
+                        if (r < 0)
+                                return log_link_debug_errno(link, r, "Could not append IFLA_BOND_ACTIVE_SLAVE attribute: %m");
+                }
+
+                if (link->network->primary_slave) {
+                        r = sd_netlink_message_append_u32(req, IFLA_BOND_PRIMARY, link->ifindex);
+                        if (r < 0)
+                                return log_link_debug_errno(link, r, "Could not append IFLA_BOND_PRIMARY attribute: %m");
+                }
+
+                r = sd_netlink_message_close_container(req);
+                if (r < 0)
+                        return log_link_debug_errno(link, r, "Could not close IFLA_INFO_DATA container: %m");
+
+                r = sd_netlink_message_close_container(req);
+                if (r < 0)
+                        return log_link_debug_errno(link, r, "Could not close IFLA_LINKINFO container: %m");
+
+                break;
         case SET_LINK_BRIDGE:
                 r = sd_rtnl_message_link_set_family(req, AF_BRIDGE);
                 if (r < 0)
@@ -462,6 +507,16 @@ int link_request_to_set_addrgen_mode(Link *link) {
         return 0;
 }
 
+int link_request_to_set_bond(Link *link) {
+        assert(link);
+        assert(link->network);
+
+        if (!link->network->bond)
+                return 0;
+
+        return link_request_set_link(link, SET_LINK_BOND, link_set_bond_handler, NULL);
+}
+
 int link_request_to_set_bridge(Link *link) {
         assert(link);
         assert(link->network);
index 1744073e0481174dc531248a136c884d1d9c9d07..910fbb64fe27d3bb9e91a4f30a3bb0981adef1fd 100644 (file)
@@ -8,6 +8,7 @@ typedef struct Request Request;
 
 typedef enum SetLinkOperation {
         SET_LINK_ADDRESS_GENERATION_MODE, /* Setting IPv6LL address generation mode. */
+        SET_LINK_BOND,                    /* Setting bond configs. */
         SET_LINK_BRIDGE,                  /* Setting bridge configs. */
         SET_LINK_FLAGS,                   /* Setting IFF_NOARP or friends. */
         SET_LINK_GROUP,                   /* Setting interface group. */
@@ -19,6 +20,7 @@ typedef enum SetLinkOperation {
 } SetLinkOperation;
 
 int link_request_to_set_addrgen_mode(Link *link);
+int link_request_to_set_bond(Link *link);
 int link_request_to_set_bridge(Link *link);
 int link_request_to_set_flags(Link *link);
 int link_request_to_set_group(Link *link);