summaryrefslogtreecommitdiff
path: root/src/network
diff options
context:
space:
mode:
authorYu Watanabe <watanabe.yu+github@gmail.com>2020-09-29 23:31:38 +0900
committerYu Watanabe <watanabe.yu+github@gmail.com>2020-10-07 02:44:42 +0900
commitb0ba6938df4b096ecd0f956bd501b564b6da7295 (patch)
treea3ae26394a37c6553c767a5c83c7f140cdb79936 /src/network
parenteab052d2b3e73b6b3787d00131ae2d191e7a4ec6 (diff)
downloadsystemd-b0ba6938df4b096ecd0f956bd501b564b6da7295.tar.gz
network: drop list of static neighbors
[Neighbor] sections are managed by both LIST and Hashmap. Let's drop list, as they store the completely same information.
Diffstat (limited to 'src/network')
-rw-r--r--src/network/networkd-link.c2
-rw-r--r--src/network/networkd-neighbor.c51
-rw-r--r--src/network/networkd-neighbor.h2
-rw-r--r--src/network/networkd-network.c12
-rw-r--r--src/network/networkd-network.h2
5 files changed, 24 insertions, 45 deletions
diff --git a/src/network/networkd-link.c b/src/network/networkd-link.c
index 6df7ce74a0..48cf83a753 100644
--- a/src/network/networkd-link.c
+++ b/src/network/networkd-link.c
@@ -2602,7 +2602,7 @@ static bool link_is_neighbor_configured(Link *link, Neighbor *neighbor) {
if (!link->network)
return false;
- LIST_FOREACH(neighbors, net_neighbor, link->network->neighbors)
+ HASHMAP_FOREACH(net_neighbor, link->network->neighbors_by_section)
if (neighbor_equal(net_neighbor, neighbor))
return true;
diff --git a/src/network/networkd-neighbor.c b/src/network/networkd-neighbor.c
index 3eec965533..0b4ceafb31 100644
--- a/src/network/networkd-neighbor.c
+++ b/src/network/networkd-neighbor.c
@@ -18,12 +18,8 @@ void neighbor_free(Neighbor *neighbor) {
return;
if (neighbor->network) {
- LIST_REMOVE(neighbors, neighbor->network->neighbors, neighbor);
- assert(neighbor->network->n_neighbors > 0);
- neighbor->network->n_neighbors--;
-
- if (neighbor->section)
- hashmap_remove(neighbor->network->neighbors_by_section, neighbor->section);
+ assert(neighbor->section);
+ hashmap_remove(neighbor->network->neighbors_by_section, neighbor->section);
}
network_config_section_free(neighbor->section);
@@ -43,19 +39,17 @@ static int neighbor_new_static(Network *network, const char *filename, unsigned
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);
- neighbor = hashmap_get(network->neighbors_by_section, n);
- if (neighbor) {
- *ret = TAKE_PTR(neighbor);
+ r = network_config_section_new(filename, section_line, &n);
+ if (r < 0)
+ return r;
- return 0;
- }
+ neighbor = hashmap_get(network->neighbors_by_section, n);
+ if (neighbor) {
+ *ret = TAKE_PTR(neighbor);
+ return 0;
}
neighbor = new(Neighbor, 1);
@@ -65,25 +59,18 @@ static int neighbor_new_static(Network *network, const char *filename, unsigned
*neighbor = (Neighbor) {
.network = network,
.family = AF_UNSPEC,
+ .section = TAKE_PTR(n),
};
- LIST_APPEND(neighbors, network->neighbors, neighbor);
- network->n_neighbors++;
-
- if (filename) {
- neighbor->section = TAKE_PTR(n);
-
- r = hashmap_ensure_allocated(&network->neighbors_by_section, &network_config_hash_ops);
- if (r < 0)
- return r;
+ r = hashmap_ensure_allocated(&network->neighbors_by_section, &network_config_hash_ops);
+ if (r < 0)
+ return r;
- r = hashmap_put(network->neighbors_by_section, neighbor->section, neighbor);
- if (r < 0)
- return r;
- }
+ r = hashmap_put(network->neighbors_by_section, neighbor->section, neighbor);
+ if (r < 0)
+ return r;
*ret = TAKE_PTR(neighbor);
-
return 0;
}
@@ -320,7 +307,7 @@ int link_set_neighbors(Link *link) {
link->neighbors_configured = false;
- LIST_FOREACH(neighbors, neighbor, link->network->neighbors) {
+ HASHMAP_FOREACH(neighbor, link->network->neighbors_by_section) {
r = neighbor_configure(neighbor, link, NULL);
if (r < 0)
return log_link_warning_errno(link, r, "Could not set neighbor: %m");
diff --git a/src/network/networkd-neighbor.h b/src/network/networkd-neighbor.h
index 3f21a25c2f..34083cf526 100644
--- a/src/network/networkd-neighbor.h
+++ b/src/network/networkd-neighbor.h
@@ -29,8 +29,6 @@ struct Neighbor {
union in_addr_union in_addr;
union lladdr_union lladdr;
size_t lladdr_size;
-
- LIST_FIELDS(Neighbor, neighbors);
};
void neighbor_free(Neighbor *neighbor);
diff --git a/src/network/networkd-network.c b/src/network/networkd-network.c
index de15074550..f4b03beeab 100644
--- a/src/network/networkd-network.c
+++ b/src/network/networkd-network.c
@@ -151,7 +151,7 @@ static int network_resolve_stacked_netdevs(Network *network) {
int network_verify(Network *network) {
RoutePrefix *route_prefix, *route_prefix_next;
- Neighbor *neighbor, *neighbor_next;
+ Neighbor *neighbor;
AddressLabel *label, *label_next;
Address *address, *address_next;
Prefix *prefix, *prefix_next;
@@ -308,7 +308,7 @@ int network_verify(Network *network) {
if (mdb_entry_verify(mdb) < 0)
mdb_entry_free(mdb);
- LIST_FOREACH_SAFE(neighbors, neighbor, neighbor_next, network->neighbors)
+ HASHMAP_FOREACH(neighbor, network->neighbors_by_section)
if (neighbor_section_verify(neighbor) < 0)
neighbor_free(neighbor);
@@ -645,7 +645,6 @@ static Network *network_free(Network *network) {
AddressLabel *label;
FdbEntry *fdb_entry;
MdbEntry *mdb_entry;
- Neighbor *neighbor;
Address *address;
Prefix *prefix;
Route *route;
@@ -720,9 +719,6 @@ static Network *network_free(Network *network) {
while ((ipv6_proxy_ndp_address = network->ipv6_proxy_ndp_addresses))
ipv6_proxy_ndp_address_free(ipv6_proxy_ndp_address);
- while ((neighbor = network->neighbors))
- neighbor_free(neighbor);
-
while ((label = network->address_labels))
address_label_free(label);
@@ -737,7 +733,7 @@ static Network *network_free(Network *network) {
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);
+ hashmap_free_with_destructor(network->neighbors_by_section, neighbor_free);
hashmap_free(network->address_labels_by_section);
hashmap_free(network->prefixes_by_section);
hashmap_free(network->route_prefixes_by_section);
@@ -870,7 +866,7 @@ bool network_has_static_ipv6_configurations(Network *network) {
if (mdb->family == AF_INET6)
return true;
- LIST_FOREACH(neighbors, neighbor, network->neighbors)
+ HASHMAP_FOREACH(neighbor, network->neighbors_by_section)
if (neighbor->family == AF_INET6)
return true;
diff --git a/src/network/networkd-network.h b/src/network/networkd-network.h
index 12ec6ef1b2..5ab609bcc0 100644
--- a/src/network/networkd-network.h
+++ b/src/network/networkd-network.h
@@ -288,7 +288,6 @@ struct Network {
LIST_HEAD(FdbEntry, static_fdb_entries);
LIST_HEAD(MdbEntry, static_mdb_entries);
LIST_HEAD(IPv6ProxyNDPAddress, ipv6_proxy_ndp_addresses);
- LIST_HEAD(Neighbor, neighbors);
LIST_HEAD(AddressLabel, address_labels);
LIST_HEAD(Prefix, static_prefixes);
LIST_HEAD(RoutePrefix, static_route_prefixes);
@@ -298,7 +297,6 @@ struct Network {
unsigned n_static_fdb_entries;
unsigned n_static_mdb_entries;
unsigned n_ipv6_proxy_ndp_addresses;
- unsigned n_neighbors;
unsigned n_address_labels;
unsigned n_static_prefixes;
unsigned n_static_route_prefixes;