diff options
Diffstat (limited to 'src/network/networkd-link.c')
-rw-r--r-- | src/network/networkd-link.c | 93 |
1 files changed, 93 insertions, 0 deletions
diff --git a/src/network/networkd-link.c b/src/network/networkd-link.c index 2eb0925d73..a4f8c59e09 100644 --- a/src/network/networkd-link.c +++ b/src/network/networkd-link.c @@ -685,6 +685,27 @@ int link_address_drop_handler(sd_rtnl *rtnl, sd_rtnl_message *m, void *userdata) return 1; } +static int link_set_handler(sd_rtnl *rtnl, sd_rtnl_message *m, void *userdata) { + _cleanup_link_unref_ Link *link = userdata; + int r; + + log_debug_link(link, "set link"); + + r = sd_rtnl_message_get_errno(m); + if (r < 0 && r != -EEXIST) { + log_struct_link(LOG_ERR, link, + "MESSAGE=%-*s: could not join netdev: %s", + IFNAMSIZ, + link->ifname, strerror(-r), + "ERRNO=%d", -r, + NULL); + link_enter_failed(link); + return 1; + } + + return 0; +} + static int set_hostname_handler(sd_bus *bus, sd_bus_message *m, void *userdata, sd_bus_error *ret_error) { _cleanup_link_unref_ Link *link = userdata; @@ -802,6 +823,69 @@ int link_set_mtu(Link *link, uint32_t mtu) { return 0; } +static int link_set_bridge(Link *link) { + _cleanup_rtnl_message_unref_ sd_rtnl_message *req = NULL; + int r; + + assert(link); + assert(link->network); + + if(link->network->cost == 0) + return 0; + + r = sd_rtnl_message_new_link(link->manager->rtnl, &req, + RTM_SETLINK, link->ifindex); + if (r < 0) { + log_error_link(link, "Could not allocate RTM_SETLINK message"); + return r; + } + + r = sd_rtnl_message_link_set_family(req, PF_BRIDGE); + if (r < 0) { + log_error_link(link, + "Could not set message family %s", strerror(-r)); + return r; + } + + r = sd_rtnl_message_open_container(req, IFLA_PROTINFO); + if (r < 0) { + log_error_link(link, + "Could not append IFLA_PROTINFO attribute: %s", + strerror(-r)); + return r; + } + + if(link->network->cost != 0) { + r = sd_rtnl_message_append_u32(req, IFLA_BRPORT_COST, link->network->cost); + if (r < 0) { + log_error_link(link, + "Could not append IFLA_BRPORT_COST attribute: %s", + strerror(-r)); + return r; + } + } + + r = sd_rtnl_message_close_container(req); + if (r < 0) { + log_error_link(link, + "Could not append IFLA_LINKINFO attribute: %s", + strerror(-r)); + return r; + } + + r = sd_rtnl_call_async(link->manager->rtnl, req, link_set_handler, link, 0, NULL); + if (r < 0) { + log_error_link(link, + "Could not send rtnetlink message: %s", + strerror(-r)); + return r; + } + + link_ref(link); + + return r; +} + static void dhcp6_handler(sd_dhcp6_client *client, int event, void *userdata) { Link *link = userdata; @@ -1037,6 +1121,15 @@ static int link_joined(Link *link) { } } + if(link->network->bridge) { + r = link_set_bridge(link); + if (r < 0) { + log_error_link(link, + "Could not set bridge message: %s", + strerror(-r)); + } + } + return link_enter_set_addresses(link); } |