diff --git a/src/network/networkd-link.c b/src/network/networkd-link.c index b9053ad659..dea1e723c3 100644 --- a/src/network/networkd-link.c +++ b/src/network/networkd-link.c @@ -2637,7 +2637,6 @@ static int remove_static_address_handler(sd_netlink *rtnl, sd_netlink_message *m static int link_drop_config(Link *link) { Address *address, *pool_address; - Route *route; int r; SET_FOREACH(address, link->addresses) { @@ -2664,15 +2663,9 @@ static int link_drop_config(Link *link) { if (r < 0) return r; - SET_FOREACH(route, link->routes) { - /* do not touch routes managed by the kernel */ - if (route->protocol == RTPROT_KERNEL) - continue; - - r = route_remove(route, link, NULL); - if (r < 0) - return r; - } + r = link_drop_routes(link); + if (r < 0) + return r; ndisc_flush(link); diff --git a/src/network/networkd-route.c b/src/network/networkd-route.c index d7ec9097b3..87006a6c44 100644 --- a/src/network/networkd-route.c +++ b/src/network/networkd-route.c @@ -566,6 +566,25 @@ int link_drop_foreign_routes(Link *link) { return r; } +int link_drop_routes(Link *link) { + Route *route; + int k, r = 0; + + assert(link); + + SET_FOREACH(route, link->routes) { + /* do not touch routes managed by the kernel */ + if (route->protocol == RTPROT_KERNEL) + continue; + + k = route_remove(route, link, NULL); + if (k < 0 && r >= 0) + r = k; + } + + return r; +} + int route_expire_handler(sd_event_source *s, uint64_t usec, void *userdata) { Route *route = userdata; int r; diff --git a/src/network/networkd-route.h b/src/network/networkd-route.h index d362298294..d5760a96a6 100644 --- a/src/network/networkd-route.h +++ b/src/network/networkd-route.h @@ -72,6 +72,7 @@ int route_configure(Route *route, Link *link, link_netlink_message_handler_t cal int route_remove(Route *route, Link *link, link_netlink_message_handler_t callback); int link_set_routes(Link *link); +int link_drop_routes(Link *link); int link_drop_foreign_routes(Link *link); int manager_rtnl_process_route(sd_netlink *rtnl, sd_netlink_message *message, Manager *m);