]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
network/nexthop: do not assign invalid ID
authorYu Watanabe <watanabe.yu+github@gmail.com>
Mon, 11 Dec 2023 16:59:34 +0000 (01:59 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Thu, 14 Dec 2023 09:57:43 +0000 (18:57 +0900)
This also reduces the scope of the iterator.

src/network/networkd-nexthop.c

index e04b352747039c608438e6b55d62e712fbc69542..b10ddc46b8c66f6bfb5458871017e4bbfd8eb3eb 100644 (file)
@@ -309,7 +309,6 @@ static int nexthop_add(Manager *manager, Link *link, NextHop *nexthop) {
 static int nexthop_acquire_id(Manager *manager, NextHop *nexthop) {
         _cleanup_set_free_ Set *ids = NULL;
         Network *network;
-        uint32_t id;
         int r;
 
         assert(manager);
@@ -337,16 +336,17 @@ static int nexthop_acquire_id(Manager *manager, NextHop *nexthop) {
                 }
         }
 
-        for (id = 1; id < UINT32_MAX; id++) {
+        for (uint32_t id = 1; id < UINT32_MAX; id++) {
                 if (manager_get_nexthop_by_id(manager, id, NULL) >= 0)
                         continue;
                 if (set_contains(ids, UINT32_TO_PTR(id)))
                         continue;
-                break;
+
+                nexthop->id = id;
+                return 0;
         }
 
-        nexthop->id = id;
-        return 0;
+        return -EBUSY;
 }
 
 static void log_nexthop_debug(const NextHop *nexthop, const char *str, const Link *link) {