]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
network/nexthop: wait for requests for group members being processed
authorYu Watanabe <watanabe.yu+github@gmail.com>
Thu, 4 Jan 2024 19:58:37 +0000 (04:58 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Thu, 4 Jan 2024 20:33:49 +0000 (05:33 +0900)
This also split out the check as nexthop_is_ready().

src/network/networkd-nexthop.c
src/network/networkd-nexthop.h

index 086f246c9658d11c1f7dc8159c5f72a1d5694969..8c963f03a32227f3e2099ddbceebae9e369e85f3 100644 (file)
@@ -552,8 +552,38 @@ static int static_nexthop_handler(sd_netlink *rtnl, sd_netlink_message *m, Reque
         return 1;
 }
 
+int nexthop_is_ready(Manager *manager, uint32_t id, NextHop **ret) {
+        NextHop *nexthop;
+
+        assert(manager);
+
+        if (id == 0)
+                return -EINVAL;
+
+        if (nexthop_get_request_by_id(manager, id, NULL) >= 0)
+                goto not_ready;
+
+        if (nexthop_get_by_id(manager, id, &nexthop) < 0)
+                goto not_ready;
+
+        if (!nexthop_exists(nexthop))
+                goto not_ready;
+
+        if (ret)
+                *ret = nexthop;
+
+        return true;
+
+not_ready:
+        if (ret)
+                *ret = NULL;
+
+        return false;
+}
+
 static bool nexthop_is_ready_to_configure(Link *link, const NextHop *nexthop) {
         struct nexthop_grp *nhg;
+        int r;
 
         assert(link);
         assert(nexthop);
@@ -576,13 +606,9 @@ static bool nexthop_is_ready_to_configure(Link *link, const NextHop *nexthop) {
 
         /* All group members must be configured first. */
         HASHMAP_FOREACH(nhg, nexthop->group) {
-                NextHop *g;
-
-                if (nexthop_get_by_id(link->manager, nhg->id, &g) < 0)
-                        return false;
-
-                if (!nexthop_exists(g))
-                        return false;
+                r = nexthop_is_ready(link->manager, nhg->id, NULL);
+                if (r <= 0)
+                        return r;
         }
 
         return gateway_is_ready(link, FLAGS_SET(nexthop->flags, RTNH_F_ONLINK), nexthop->family, &nexthop->gw);
index 564b52532fa72fb7aff3a75b14f420f256bc5e20..62429670e7908fccfcb708d55f6f28079291a4f4 100644 (file)
@@ -51,6 +51,7 @@ void link_foreignize_nexthops(Link *link);
 int link_request_static_nexthops(Link *link, bool only_ipv4);
 
 int nexthop_get_by_id(Manager *manager, uint32_t id, NextHop **ret);
+int nexthop_is_ready(Manager *manager, uint32_t id, NextHop **ret);
 int manager_rtnl_process_nexthop(sd_netlink *rtnl, sd_netlink_message *message, Manager *m);
 int manager_build_nexthop_ids(Manager *manager);