1
0
mirror of https://github.com/systemd/systemd.git synced 2024-10-31 07:51:21 +03:00

network: also manage nexthops by ID

It will be used in later commits.
This commit is contained in:
Yu Watanabe 2021-02-05 12:01:07 +09:00
parent 3d81e41190
commit 69e244e321
3 changed files with 17 additions and 4 deletions

View File

@ -894,6 +894,8 @@ Manager* manager_free(Manager *m) {
m->routes = set_free(m->routes);
m->routes_foreign = set_free(m->routes_foreign);
m->nexthops_by_id = hashmap_free(m->nexthops_by_id);
sd_event_source_unref(m->speed_meter_event_source);
sd_event_unref(m->event);

View File

@ -61,6 +61,9 @@ struct Manager {
Set *rules;
Set *rules_foreign;
/* Manage nexthops by id. */
Hashmap *nexthops_by_id;
/* Manager stores routes without RTA_OIF attribute. */
Set *routes;
Set *routes_foreign;

View File

@ -28,6 +28,9 @@ NextHop *nexthop_free(NextHop *nexthop) {
if (nexthop->link) {
set_remove(nexthop->link->nexthops, nexthop);
set_remove(nexthop->link->nexthops_foreign, nexthop);
if (nexthop->link->manager && nexthop->id > 0)
hashmap_remove(nexthop->link->manager->nexthops_by_id, UINT32_TO_PTR(nexthop->id));
}
return mfree(nexthop);
@ -221,14 +224,18 @@ static int nexthop_update(Link *link, NextHop *nexthop, const NextHop *in) {
int r;
assert(link);
assert(link->manager);
assert(nexthop);
assert(in);
assert(in->id > 0);
/* Currently, this only updates ID. */
/* This updates nexthop ID if necessary, and register the nexthop to Manager. */
if (nexthop->id > 0)
return nexthop->id == in->id ? 0 : -EINVAL;
if (nexthop->id > 0) {
if (nexthop->id == in->id)
goto set_manager;
return -EINVAL;
}
nexthop = set_remove(link->nexthops, nexthop);
if (!nexthop)
@ -251,7 +258,8 @@ static int nexthop_update(Link *link, NextHop *nexthop, const NextHop *in) {
return r < 0 ? r : -EEXIST;
}
return 0;
set_manager:
return hashmap_ensure_put(&link->manager->nexthops_by_id, NULL, UINT32_TO_PTR(nexthop->id), nexthop);
}
static void log_nexthop_debug(const NextHop *nexthop, uint32_t id, const char *str, const Link *link) {