Skip to content

Commit

Permalink
Merge pull request systemd#30440 from yuwata/network-nexthop-cleanups-2
Browse files Browse the repository at this point in the history
network/nexthop: several cleanups
  • Loading branch information
yuwata authored Dec 14, 2023
2 parents 3d11b46 + 5f6ab79 commit ae3fb96
Show file tree
Hide file tree
Showing 10 changed files with 404 additions and 386 deletions.
2 changes: 1 addition & 1 deletion src/libsystemd/sd-netlink/netlink-message-rtnl.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
12 changes: 8 additions & 4 deletions src/network/networkd-json.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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;

Expand Down
5 changes: 3 additions & 2 deletions src/network/networkd-link.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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)
Expand Down
1 change: 0 additions & 1 deletion src/network/networkd-link.h
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,6 @@ typedef struct Link {
Set *addresses;
Set *neighbors;
Set *routes;
Set *nexthops;
Set *qdiscs;
Set *tclasses;

Expand Down
1 change: 0 additions & 1 deletion src/network/networkd-manager.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
3 changes: 0 additions & 3 deletions src/network/networkd-manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Loading

0 comments on commit ae3fb96

Please sign in to comment.