Merge pull request #30440 from yuwata/network-nexthop-cleanups-2
network/nexthop: several cleanups
This commit is contained in:
@@ -336,7 +336,7 @@ int sd_rtnl_message_new_nexthop(sd_netlink *rtnl, sd_netlink_message **ret,
|
||||
return r;
|
||||
|
||||
if (nlmsg_type == RTM_NEWNEXTHOP)
|
||||
(*ret)->hdr->nlmsg_flags |= NLM_F_CREATE | NLM_F_APPEND;
|
||||
(*ret)->hdr->nlmsg_flags |= NLM_F_CREATE | NLM_F_REPLACE;
|
||||
|
||||
nhm = NLMSG_DATA((*ret)->hdr);
|
||||
|
||||
|
||||
@@ -185,16 +185,20 @@ static int nexthop_build_json(NextHop *n, JsonVariant **ret) {
|
||||
JSON_BUILD_PAIR_STRING("ConfigState", state)));
|
||||
}
|
||||
|
||||
static int nexthops_append_json(Set *nexthops, JsonVariant **v) {
|
||||
static int nexthops_append_json(Manager *manager, int ifindex, JsonVariant **v) {
|
||||
_cleanup_(json_variant_unrefp) JsonVariant *array = NULL;
|
||||
NextHop *nexthop;
|
||||
int r;
|
||||
|
||||
assert(manager);
|
||||
assert(v);
|
||||
|
||||
SET_FOREACH(nexthop, nexthops) {
|
||||
HASHMAP_FOREACH(nexthop, manager->nexthops_by_id) {
|
||||
_cleanup_(json_variant_unrefp) JsonVariant *e = NULL;
|
||||
|
||||
if (nexthop->ifindex != ifindex)
|
||||
continue;
|
||||
|
||||
r = nexthop_build_json(nexthop, &e);
|
||||
if (r < 0)
|
||||
return r;
|
||||
@@ -1354,7 +1358,7 @@ int link_build_json(Link *link, JsonVariant **ret) {
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
r = nexthops_append_json(link->nexthops, &v);
|
||||
r = nexthops_append_json(link->manager, link->ifindex, &v);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
@@ -1417,7 +1421,7 @@ int manager_build_json(Manager *manager, JsonVariant **ret) {
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
r = nexthops_append_json(manager->nexthops, &v);
|
||||
r = nexthops_append_json(manager, /* ifindex = */ 0, &v);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
|
||||
@@ -209,7 +209,6 @@ static Link *link_free(Link *link) {
|
||||
link_dns_settings_clear(link);
|
||||
|
||||
link->routes = set_free(link->routes);
|
||||
link->nexthops = set_free(link->nexthops);
|
||||
link->neighbors = set_free(link->neighbors);
|
||||
link->addresses = set_free(link->addresses);
|
||||
link->qdiscs = set_free(link->qdiscs);
|
||||
@@ -252,7 +251,9 @@ int link_get_by_index(Manager *m, int ifindex, Link **ret) {
|
||||
Link *link;
|
||||
|
||||
assert(m);
|
||||
assert(ifindex > 0);
|
||||
|
||||
if (ifindex <= 0)
|
||||
return -EINVAL;
|
||||
|
||||
link = hashmap_get(m->links_by_index, INT_TO_PTR(ifindex));
|
||||
if (!link)
|
||||
|
||||
@@ -125,7 +125,6 @@ typedef struct Link {
|
||||
Set *addresses;
|
||||
Set *neighbors;
|
||||
Set *routes;
|
||||
Set *nexthops;
|
||||
Set *qdiscs;
|
||||
Set *tclasses;
|
||||
|
||||
|
||||
@@ -649,7 +649,6 @@ Manager* manager_free(Manager *m) {
|
||||
* set_free() must be called after the above sd_netlink_unref(). */
|
||||
m->routes = set_free(m->routes);
|
||||
|
||||
m->nexthops = set_free(m->nexthops);
|
||||
m->nexthops_by_id = hashmap_free(m->nexthops_by_id);
|
||||
|
||||
sd_event_source_unref(m->speed_meter_event_source);
|
||||
|
||||
@@ -74,9 +74,6 @@ struct Manager {
|
||||
/* Manage nexthops by id. */
|
||||
Hashmap *nexthops_by_id;
|
||||
|
||||
/* Manager stores nexthops without RTA_OIF attribute. */
|
||||
Set *nexthops;
|
||||
|
||||
/* Manager stores routes without RTA_OIF attribute. */
|
||||
unsigned route_remove_messages;
|
||||
Set *routes;
|
||||
|
||||
+387
-377
File diff suppressed because it is too large
Load Diff
@@ -20,13 +20,12 @@ typedef struct Network Network;
|
||||
typedef struct NextHop {
|
||||
Network *network;
|
||||
Manager *manager;
|
||||
Link *link;
|
||||
ConfigSection *section;
|
||||
NetworkConfigSource source;
|
||||
NetworkConfigState state;
|
||||
|
||||
uint8_t protocol;
|
||||
|
||||
int ifindex;
|
||||
uint32_t id;
|
||||
bool blackhole;
|
||||
int family;
|
||||
@@ -40,13 +39,18 @@ NextHop *nexthop_free(NextHop *nexthop);
|
||||
|
||||
void network_drop_invalid_nexthops(Network *network);
|
||||
|
||||
int link_drop_managed_nexthops(Link *link);
|
||||
int link_drop_foreign_nexthops(Link *link);
|
||||
int link_drop_nexthops(Link *link, bool foreign);
|
||||
static inline int link_drop_foreign_nexthops(Link *link) {
|
||||
return link_drop_nexthops(link, /* foreign = */ true);
|
||||
}
|
||||
static inline int link_drop_managed_nexthops(Link *link) {
|
||||
return link_drop_nexthops(link, /* foreign = */ false);
|
||||
}
|
||||
void link_foreignize_nexthops(Link *link);
|
||||
|
||||
int link_request_static_nexthops(Link *link, bool only_ipv4);
|
||||
|
||||
int manager_get_nexthop_by_id(Manager *manager, uint32_t id, NextHop **ret);
|
||||
int nexthop_get_by_id(Manager *manager, uint32_t id, NextHop **ret);
|
||||
int manager_rtnl_process_nexthop(sd_netlink *rtnl, sd_netlink_message *message, Manager *m);
|
||||
|
||||
DEFINE_NETWORK_CONFIG_STATE_FUNCTIONS(NextHop, nexthop);
|
||||
|
||||
@@ -58,12 +58,14 @@ static void request_hash_func(const Request *req, struct siphash *state) {
|
||||
assert(req);
|
||||
assert(state);
|
||||
|
||||
siphash24_compress_boolean(req->link, state);
|
||||
if (req->link)
|
||||
siphash24_compress(&req->link->ifindex, sizeof(req->link->ifindex), state);
|
||||
|
||||
siphash24_compress(&req->type, sizeof(req->type), state);
|
||||
|
||||
if (req->type != REQUEST_TYPE_NEXTHOP) {
|
||||
siphash24_compress_boolean(req->link, state);
|
||||
if (req->link)
|
||||
siphash24_compress(&req->link->ifindex, sizeof(req->link->ifindex), state);
|
||||
}
|
||||
|
||||
siphash24_compress(&req->hash_func, sizeof(req->hash_func), state);
|
||||
siphash24_compress(&req->compare_func, sizeof(req->compare_func), state);
|
||||
|
||||
@@ -77,20 +79,22 @@ static int request_compare_func(const struct Request *a, const struct Request *b
|
||||
assert(a);
|
||||
assert(b);
|
||||
|
||||
r = CMP(!!a->link, !!b->link);
|
||||
if (r != 0)
|
||||
return r;
|
||||
|
||||
if (a->link) {
|
||||
r = CMP(a->link->ifindex, b->link->ifindex);
|
||||
if (r != 0)
|
||||
return r;
|
||||
}
|
||||
|
||||
r = CMP(a->type, b->type);
|
||||
if (r != 0)
|
||||
return r;
|
||||
|
||||
if (a->type != REQUEST_TYPE_NEXTHOP) {
|
||||
r = CMP(!!a->link, !!b->link);
|
||||
if (r != 0)
|
||||
return r;
|
||||
|
||||
if (a->link) {
|
||||
r = CMP(a->link->ifindex, b->link->ifindex);
|
||||
if (r != 0)
|
||||
return r;
|
||||
}
|
||||
}
|
||||
|
||||
r = CMP(PTR_TO_UINT64(a->hash_func), PTR_TO_UINT64(b->hash_func));
|
||||
if (r != 0)
|
||||
return r;
|
||||
|
||||
@@ -461,7 +461,7 @@ static int route_convert(Manager *manager, const Route *route, ConvertedRoutes *
|
||||
struct nexthop_grp *nhg;
|
||||
NextHop *nh;
|
||||
|
||||
r = manager_get_nexthop_by_id(manager, route->nexthop_id, &nh);
|
||||
r = nexthop_get_by_id(manager, route->nexthop_id, &nh);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
@@ -475,7 +475,7 @@ static int route_convert(Manager *manager, const Route *route, ConvertedRoutes *
|
||||
return r;
|
||||
|
||||
route_apply_nexthop(c->routes[0], nh, UINT8_MAX);
|
||||
c->links[0] = nh->link;
|
||||
(void) link_get_by_index(manager, nh->ifindex, c->links);
|
||||
|
||||
*ret = TAKE_PTR(c);
|
||||
return 1;
|
||||
@@ -489,7 +489,7 @@ static int route_convert(Manager *manager, const Route *route, ConvertedRoutes *
|
||||
HASHMAP_FOREACH(nhg, nh->group) {
|
||||
NextHop *h;
|
||||
|
||||
r = manager_get_nexthop_by_id(manager, nhg->id, &h);
|
||||
r = nexthop_get_by_id(manager, nhg->id, &h);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
@@ -498,7 +498,7 @@ static int route_convert(Manager *manager, const Route *route, ConvertedRoutes *
|
||||
return r;
|
||||
|
||||
route_apply_nexthop(c->routes[i], h, nhg->weight);
|
||||
c->links[i] = h->link;
|
||||
(void) link_get_by_index(manager, h->ifindex, c->links + i);
|
||||
|
||||
i++;
|
||||
}
|
||||
@@ -1284,7 +1284,7 @@ static int route_is_ready_to_configure(const Route *route, Link *link) {
|
||||
struct nexthop_grp *nhg;
|
||||
NextHop *nh;
|
||||
|
||||
if (manager_get_nexthop_by_id(link->manager, route->nexthop_id, &nh) < 0)
|
||||
if (nexthop_get_by_id(link->manager, route->nexthop_id, &nh) < 0)
|
||||
return false;
|
||||
|
||||
if (!nexthop_exists(nh))
|
||||
@@ -1293,7 +1293,7 @@ static int route_is_ready_to_configure(const Route *route, Link *link) {
|
||||
HASHMAP_FOREACH(nhg, nh->group) {
|
||||
NextHop *g;
|
||||
|
||||
if (manager_get_nexthop_by_id(link->manager, nhg->id, &g) < 0)
|
||||
if (nexthop_get_by_id(link->manager, nhg->id, &g) < 0)
|
||||
return false;
|
||||
|
||||
if (!nexthop_exists(g))
|
||||
|
||||
Reference in New Issue
Block a user