Merge pull request #30775 from yuwata/network-nexthop-is-ready
network: introduce nexthop_is_ready() helper function and use it
This commit is contained in:
@@ -269,6 +269,9 @@ static int nexthop_get_request_by_id(Manager *manager, uint32_t id, Request **re
|
||||
|
||||
assert(manager);
|
||||
|
||||
if (id == 0)
|
||||
return -EINVAL;
|
||||
|
||||
req = ordered_set_get(
|
||||
manager->request_queue,
|
||||
&(Request) {
|
||||
@@ -549,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);
|
||||
@@ -573,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);
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
@@ -1277,20 +1277,14 @@ static int route_is_ready_to_configure(const Route *route, Link *link) {
|
||||
struct nexthop_grp *nhg;
|
||||
NextHop *nh;
|
||||
|
||||
if (nexthop_get_by_id(link->manager, route->nexthop_id, &nh) < 0)
|
||||
return false;
|
||||
|
||||
if (!nexthop_exists(nh))
|
||||
return false;
|
||||
r = nexthop_is_ready(link->manager, route->nexthop_id, &nh);
|
||||
if (r <= 0)
|
||||
return r;
|
||||
|
||||
HASHMAP_FOREACH(nhg, nh->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;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user