diff --git a/src/network/networkd-setlink.c b/src/network/networkd-setlink.c index 8519e6e7a09..8ef523dfdcf 100644 --- a/src/network/networkd-setlink.c +++ b/src/network/networkd-setlink.c @@ -1211,7 +1211,7 @@ int link_request_to_bring_up_or_down(Link *link, bool up) { return 0; } -static int link_down_now_handler(sd_netlink *rtnl, sd_netlink_message *m, Link *link) { +static int link_up_or_down_now_handler(sd_netlink *rtnl, sd_netlink_message *m, Link *link, const char *msg) { int r; assert(m); @@ -1225,7 +1225,7 @@ static int link_down_now_handler(sd_netlink *rtnl, sd_netlink_message *m, Link * r = sd_netlink_message_get_errno(m); if (r < 0) - log_link_message_warning_errno(link, m, r, "Could not bring down interface, ignoring"); + log_link_message_warning_errno(link, m, r, msg); r = link_call_getlink(link, get_link_update_flag_handler); if (r < 0) { @@ -1237,7 +1237,15 @@ static int link_down_now_handler(sd_netlink *rtnl, sd_netlink_message *m, Link * return 0; } -int link_down_now(Link *link) { +static int link_up_now_handler(sd_netlink *rtnl, sd_netlink_message *m, Link *link) { + return link_up_or_down_now_handler(rtnl, m, link, "Could not bring up interface, ignoring"); +} + +static int link_down_now_handler(sd_netlink *rtnl, sd_netlink_message *m, Link *link) { + return link_up_or_down_now_handler(rtnl, m, link, "Could not bring down interface, ignoring"); +} + +int link_up_or_down_now(Link *link, bool up) { _cleanup_(sd_netlink_message_unrefp) sd_netlink_message *req = NULL; int r; @@ -1245,17 +1253,18 @@ int link_down_now(Link *link) { assert(link->manager); assert(link->manager->rtnl); - log_link_debug(link, "Bringing link down"); + log_link_debug(link, "Bringing link %s", up ? "up" : "down"); r = sd_rtnl_message_new_link(link->manager->rtnl, &req, RTM_SETLINK, link->ifindex); if (r < 0) return log_link_warning_errno(link, r, "Could not allocate RTM_SETLINK message: %m"); - r = sd_rtnl_message_link_set_flags(req, 0, IFF_UP); + r = sd_rtnl_message_link_set_flags(req, up ? IFF_UP : 0, IFF_UP); if (r < 0) return log_link_warning_errno(link, r, "Could not set link flags: %m"); - r = netlink_call_async(link->manager->rtnl, NULL, req, link_down_now_handler, + r = netlink_call_async(link->manager->rtnl, NULL, req, + up ? link_up_now_handler : link_down_now_handler, link_netlink_destroy_callback, link); if (r < 0) return log_link_warning_errno(link, r, "Could not send rtnetlink message: %m"); diff --git a/src/network/networkd-setlink.h b/src/network/networkd-setlink.h index 841e5eeb9c4..df617f2167d 100644 --- a/src/network/networkd-setlink.h +++ b/src/network/networkd-setlink.h @@ -24,6 +24,13 @@ int link_request_to_activate(Link *link); int link_request_to_bring_up_or_down(Link *link, bool up); -int link_down_now(Link *link); +int link_up_or_down_now(Link *link, bool up); +static inline int link_up_now(Link *link) { + return link_up_or_down_now(link, true); +} +static inline int link_down_now(Link *link) { + return link_up_or_down_now(link, false); +} + int link_down_slave_links(Link *link); int link_remove(Link *link);