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.
This commit is contained in:
Yu Watanabe
2020-10-07 02:44:42 +09:00
parent eab052d2b3
commit b0ba6938df
5 changed files with 24 additions and 45 deletions
+1 -1
View File
@@ -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;
+19 -32
View File
@@ -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));
assert(filename);
assert(section_line > 0);
if (filename) {
r = network_config_section_new(filename, section_line, &n);
if (r < 0)
return r;
r = network_config_section_new(filename, section_line, &n);
if (r < 0)
return r;
neighbor = hashmap_get(network->neighbors_by_section, n);
if (neighbor) {
*ret = TAKE_PTR(neighbor);
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++;
r = hashmap_ensure_allocated(&network->neighbors_by_section, &network_config_hash_ops);
if (r < 0)
return r;
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_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");
-2
View File
@@ -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);
+4 -8
View File
@@ -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;
-2
View File
@@ -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;