[Neighbor] sections are managed by both LIST and Hashmap.
Let's drop list, as they store the completely same information.
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;
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);
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);
*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;
}
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");
union in_addr_union in_addr;
union lladdr_union lladdr;
size_t lladdr_size;
-
- LIST_FIELDS(Neighbor, neighbors);
};
void neighbor_free(Neighbor *neighbor);
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;
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);
AddressLabel *label;
FdbEntry *fdb_entry;
MdbEntry *mdb_entry;
- Neighbor *neighbor;
Address *address;
Prefix *prefix;
Route *route;
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);
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);
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;
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);
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;