From: Lennart Poettering Date: Wed, 28 Nov 2018 20:25:47 +0000 (+0100) Subject: networkd: slightly rework route establishment logic X-Git-Tag: v240~183 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=bf61b05a0672de6daf2bfdf2d7f7140f941badef;p=thirdparty%2Fsystemd.git networkd: slightly rework route establishment logic Use a for() loop to merge the two very similar loops into one, and add more comments explaining the logic behing this. Follow-up for 0d34228fc03f9dc47d1024268b66a23df1914914 --- diff --git a/src/network/networkd-link.c b/src/network/networkd-link.c index c6ad712a024..db2dbef52c7 100644 --- a/src/network/networkd-link.c +++ b/src/network/networkd-link.c @@ -850,6 +850,11 @@ static int route_handler(sd_netlink *rtnl, sd_netlink_message *m, void *userdata } static int link_enter_set_routes(Link *link) { + enum { + PHASE_NON_GATEWAY, /* First phase: Routes without a gateway */ + PHASE_GATEWAY, /* Second phase: Routes with a gateway */ + _PHASE_MAX + } phase; Route *rt; int r; @@ -861,21 +866,13 @@ static int link_enter_set_routes(Link *link) { link_set_state(link, LINK_STATE_SETTING_ROUTES); - /* First add the default route i.e. Gateway.*/ - LIST_FOREACH(routes, rt, link->network->static_routes) - if (in_addr_is_null(rt->family, &rt->gw)) { - r = route_configure(rt, link, route_handler); - if (r < 0) { - log_link_warning_errno(link, r, "Could not set routes: %m"); - link_enter_failed(link); - return r; - } + /* First add the routes that enable us to talk to gateways, then add in the others that need a gateway. */ + for (phase = 0; phase < _PHASE_MAX; phase++) + LIST_FOREACH(routes, rt, link->network->static_routes) { - link->route_messages++; - } + if (in_addr_is_null(rt->family, &rt->gw) != (phase == PHASE_NON_GATEWAY)) + continue; - LIST_FOREACH(routes, rt, link->network->static_routes) - if (!in_addr_is_null(rt->family, &rt->gw)) { r = route_configure(rt, link, route_handler); if (r < 0) { log_link_warning_errno(link, r, "Could not set routes: %m");