]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
network: nexthop: first create nexthops with ID
authorYu Watanabe <watanabe.yu+github@gmail.com>
Fri, 5 Feb 2021 01:21:19 +0000 (10:21 +0900)
committerLennart Poettering <lennart@poettering.net>
Wed, 17 Feb 2021 18:39:37 +0000 (19:39 +0100)
Otherwise, an ID-less nexthop may conflict with a later nexthop with ID.

src/network/networkd-nexthop.c

index 629fd78226c4551d980e04b1f41230ecec8d81e9..7a5a648148208fab8f7089e79acdf68e745d8f27 100644 (file)
@@ -300,6 +300,11 @@ static int nexthop_configure(NextHop *nexthop, Link *link) {
 }
 
 int link_set_nexthop(Link *link) {
+        enum {
+                PHASE_ID,         /* First phase: Nexthops with ID */
+                PHASE_WITHOUT_ID, /* Second phase: Nexthops without ID */
+                _PHASE_MAX,
+        } phase;
         NextHop *nh;
         int r;
 
@@ -313,13 +318,17 @@ int link_set_nexthop(Link *link) {
 
         link->static_nexthops_configured = false;
 
-        HASHMAP_FOREACH(nh, link->network->nexthops_by_section) {
-                r = nexthop_configure(nh, link);
-                if (r < 0)
-                        return log_link_warning_errno(link, r, "Could not set nexthop: %m");
+        for (phase = PHASE_ID; phase < _PHASE_MAX; phase++)
+                HASHMAP_FOREACH(nh, link->network->nexthops_by_section) {
+                        if ((nh->id > 0) != (phase == PHASE_ID))
+                                continue;
 
-                link->nexthop_messages++;
-        }
+                        r = nexthop_configure(nh, link);
+                        if (r < 0)
+                                return log_link_warning_errno(link, r, "Could not set nexthop: %m");
+
+                        link->nexthop_messages++;
+                }
 
         if (link->nexthop_messages == 0) {
                 link->static_nexthops_configured = true;