summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/network/networkd-network.c10
-rw-r--r--src/network/networkd-network.h2
-rw-r--r--src/network/networkd-nexthop.c55
-rw-r--r--src/network/networkd-nexthop.h2
4 files changed, 24 insertions, 45 deletions
diff --git a/src/network/networkd-network.c b/src/network/networkd-network.c
index c642e86fda..d8831561c4 100644
--- a/src/network/networkd-network.c
+++ b/src/network/networkd-network.c
@@ -152,7 +152,7 @@ int network_verify(Network *network) {
RoutePrefix *route_prefix, *route_prefix_next;
Neighbor *neighbor, *neighbor_next;
AddressLabel *label, *label_next;
- NextHop *nexthop, *nextnop_next;
+ NextHop *nexthop;
Address *address, *address_next;
Prefix *prefix, *prefix_next;
Route *route, *route_next;
@@ -298,7 +298,7 @@ int network_verify(Network *network) {
if (route_section_verify(route, network) < 0)
route_free(route);
- LIST_FOREACH_SAFE(nexthops, nexthop, nextnop_next, network->static_nexthops)
+ HASHMAP_FOREACH(nexthop, network->nexthops_by_section)
if (nexthop_section_verify(nexthop) < 0)
nexthop_free(nexthop);
@@ -649,7 +649,6 @@ static Network *network_free(Network *network) {
MdbEntry *mdb_entry;
Neighbor *neighbor;
Address *address;
- NextHop *nexthop;
Prefix *prefix;
Route *route;
@@ -711,9 +710,6 @@ static Network *network_free(Network *network) {
while ((route = network->static_routes))
route_free(route);
- while ((nexthop = network->static_nexthops))
- nexthop_free(nexthop);
-
while ((address = network->static_addresses))
address_free(address);
@@ -740,7 +736,7 @@ static Network *network_free(Network *network) {
hashmap_free(network->addresses_by_section);
hashmap_free(network->routes_by_section);
- hashmap_free(network->nexthops_by_section);
+ hashmap_free_with_destructor(network->nexthops_by_section, nexthop_free);
hashmap_free(network->fdb_entries_by_section);
hashmap_free(network->mdb_entries_by_section);
hashmap_free(network->neighbors_by_section);
diff --git a/src/network/networkd-network.h b/src/network/networkd-network.h
index bc006944d7..c92b751866 100644
--- a/src/network/networkd-network.h
+++ b/src/network/networkd-network.h
@@ -286,7 +286,6 @@ struct Network {
LIST_HEAD(Address, static_addresses);
LIST_HEAD(Route, static_routes);
- LIST_HEAD(NextHop, static_nexthops);
LIST_HEAD(FdbEntry, static_fdb_entries);
LIST_HEAD(MdbEntry, static_mdb_entries);
LIST_HEAD(IPv6ProxyNDPAddress, ipv6_proxy_ndp_addresses);
@@ -297,7 +296,6 @@ struct Network {
unsigned n_static_addresses;
unsigned n_static_routes;
- unsigned n_static_nexthops;
unsigned n_static_fdb_entries;
unsigned n_static_mdb_entries;
unsigned n_ipv6_proxy_ndp_addresses;
diff --git a/src/network/networkd-nexthop.c b/src/network/networkd-nexthop.c
index 6ff616d906..6c9d1c57dd 100644
--- a/src/network/networkd-nexthop.c
+++ b/src/network/networkd-nexthop.c
@@ -20,13 +20,8 @@ void nexthop_free(NextHop *nexthop) {
return;
if (nexthop->network) {
- LIST_REMOVE(nexthops, nexthop->network->static_nexthops, nexthop);
-
- assert(nexthop->network->n_static_nexthops > 0);
- nexthop->network->n_static_nexthops--;
-
- if (nexthop->section)
- hashmap_remove(nexthop->network->nexthops_by_section, nexthop->section);
+ assert(nexthop->section);
+ hashmap_remove(nexthop->network->nexthops_by_section, nexthop->section);
}
network_config_section_free(nexthop->section);
@@ -64,19 +59,17 @@ static int nexthop_new_static(Network *network, const char *filename, unsigned s
assert(network);
assert(ret);
- assert(!!filename == (section_line > 0));
-
- if (filename) {
- r = network_config_section_new(filename, section_line, &n);
- if (r < 0)
- return r;
+ assert(filename);
+ assert(section_line > 0);
- nexthop = hashmap_get(network->nexthops_by_section, n);
- if (nexthop) {
- *ret = TAKE_PTR(nexthop);
+ r = network_config_section_new(filename, section_line, &n);
+ if (r < 0)
+ return r;
- return 0;
- }
+ nexthop = hashmap_get(network->nexthops_by_section, n);
+ if (nexthop) {
+ *ret = TAKE_PTR(nexthop);
+ return 0;
}
r = nexthop_new(&nexthop);
@@ -85,23 +78,17 @@ static int nexthop_new_static(Network *network, const char *filename, unsigned s
nexthop->protocol = RTPROT_STATIC;
nexthop->network = network;
- LIST_PREPEND(nexthops, network->static_nexthops, nexthop);
- network->n_static_nexthops++;
+ nexthop->section = TAKE_PTR(n);
- if (filename) {
- nexthop->section = TAKE_PTR(n);
-
- r = hashmap_ensure_allocated(&network->nexthops_by_section, &network_config_hash_ops);
- if (r < 0)
- return r;
+ r = hashmap_ensure_allocated(&network->nexthops_by_section, &network_config_hash_ops);
+ if (r < 0)
+ return r;
- r = hashmap_put(network->nexthops_by_section, nexthop->section, nexthop);
- if (r < 0)
- return r;
- }
+ r = hashmap_put(network->nexthops_by_section, nexthop->section, nexthop);
+ if (r < 0)
+ return r;
*ret = TAKE_PTR(nexthop);
-
return 0;
}
@@ -343,12 +330,12 @@ int link_set_nexthop(Link *link) {
link->static_nexthops_configured = false;
- LIST_FOREACH(nexthops, nh, link->network->static_nexthops) {
+ HASHMAP_FOREACH(nh, link->network->nexthops_by_section) {
r = nexthop_configure(nh, link);
if (r < 0)
return log_link_warning_errno(link, r, "Could not set nexthop: %m");
- if (r > 0)
- link->nexthop_messages++;
+
+ link->nexthop_messages++;
}
if (link->nexthop_messages == 0) {
diff --git a/src/network/networkd-nexthop.h b/src/network/networkd-nexthop.h
index af6bf7b0c2..2ff8b4b81e 100644
--- a/src/network/networkd-nexthop.h
+++ b/src/network/networkd-nexthop.h
@@ -26,8 +26,6 @@ struct NextHop {
uint32_t id;
union in_addr_union gw;
-
- LIST_FIELDS(NextHop, nexthops);
};
void nexthop_free(NextHop *nexthop);