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",
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);
}
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:
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)
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);