diff --git a/src/network/networkd-fdb.c b/src/network/networkd-fdb.c index 43aaebb285c..0337ec24a56 100644 --- a/src/network/networkd-fdb.c +++ b/src/network/networkd-fdb.c @@ -36,12 +36,8 @@ FdbEntry *fdb_entry_free(FdbEntry *fdb_entry) { return NULL; if (fdb_entry->network) { - LIST_REMOVE(static_fdb_entries, fdb_entry->network->static_fdb_entries, fdb_entry); - assert(fdb_entry->network->n_static_fdb_entries > 0); - fdb_entry->network->n_static_fdb_entries--; - - if (fdb_entry->section) - hashmap_remove(fdb_entry->network->fdb_entries_by_section, fdb_entry->section); + assert(fdb_entry->section); + hashmap_remove(fdb_entry->network->fdb_entries_by_section, fdb_entry->section); } network_config_section_free(fdb_entry->section); @@ -63,23 +59,21 @@ static int fdb_entry_new_static( assert(network); assert(ret); - assert(!!filename == (section_line > 0)); + assert(filename); + assert(section_line > 0); + + r = network_config_section_new(filename, section_line, &n); + if (r < 0) + return r; /* search entry in hashmap first. */ - if (filename) { - r = network_config_section_new(filename, section_line, &n); - if (r < 0) - return r; - - fdb_entry = hashmap_get(network->fdb_entries_by_section, n); - if (fdb_entry) { - *ret = TAKE_PTR(fdb_entry); - - return 0; - } + fdb_entry = hashmap_get(network->fdb_entries_by_section, n); + if (fdb_entry) { + *ret = TAKE_PTR(fdb_entry); + return 0; } - if (network->n_static_fdb_entries >= STATIC_FDB_ENTRIES_PER_NETWORK_MAX) + if (hashmap_size(network->fdb_entries_by_section) >= STATIC_FDB_ENTRIES_PER_NETWORK_MAX) return -E2BIG; /* allocate space for and FDB entry. */ @@ -90,24 +84,18 @@ static int fdb_entry_new_static( /* init FDB structure. */ *fdb_entry = (FdbEntry) { .network = network, + .section = TAKE_PTR(n), .vni = VXLAN_VID_MAX + 1, .fdb_ntf_flags = NEIGHBOR_CACHE_ENTRY_FLAGS_SELF, }; - LIST_PREPEND(static_fdb_entries, network->static_fdb_entries, fdb_entry); - network->n_static_fdb_entries++; + r = hashmap_ensure_allocated(&network->fdb_entries_by_section, &network_config_hash_ops); + if (r < 0) + return r; - if (filename) { - fdb_entry->section = TAKE_PTR(n); - - r = hashmap_ensure_allocated(&network->fdb_entries_by_section, &network_config_hash_ops); - if (r < 0) - return r; - - r = hashmap_put(network->fdb_entries_by_section, fdb_entry->section, fdb_entry); - if (r < 0) - return r; - } + r = hashmap_put(network->fdb_entries_by_section, fdb_entry->section, fdb_entry); + if (r < 0) + return r; /* return allocated FDB structure. */ *ret = TAKE_PTR(fdb_entry); diff --git a/src/network/networkd-fdb.h b/src/network/networkd-fdb.h index 521376cb864..c6b5055f8e1 100644 --- a/src/network/networkd-fdb.h +++ b/src/network/networkd-fdb.h @@ -39,8 +39,6 @@ struct FdbEntry { struct ether_addr mac_addr; union in_addr_union destination_addr; NeighborCacheEntryFlags fdb_ntf_flags; - - LIST_FIELDS(FdbEntry, static_fdb_entries); }; FdbEntry *fdb_entry_free(FdbEntry *fdb_entry); diff --git a/src/network/networkd-link.c b/src/network/networkd-link.c index b94e4945f31..c47bf75cdff 100644 --- a/src/network/networkd-link.c +++ b/src/network/networkd-link.c @@ -1136,7 +1136,7 @@ static int link_set_bridge_fdb(Link *link) { FdbEntry *fdb_entry; int r; - LIST_FOREACH(static_fdb_entries, fdb_entry, link->network->static_fdb_entries) { + HASHMAP_FOREACH(fdb_entry, link->network->fdb_entries_by_section) { r = fdb_entry_configure(link, fdb_entry); if (r < 0) return log_link_error_errno(link, r, "Failed to add MAC entry to static MAC table: %m"); diff --git a/src/network/networkd-network.c b/src/network/networkd-network.c index 95f3f653945..149c3cf2d31 100644 --- a/src/network/networkd-network.c +++ b/src/network/networkd-network.c @@ -156,7 +156,7 @@ int network_verify(Network *network) { Address *address, *address_next; Prefix *prefix, *prefix_next; Route *route, *route_next; - FdbEntry *fdb, *fdb_next; + FdbEntry *fdb; MdbEntry *mdb, *mdb_next; TrafficControl *tc; SRIOV *sr_iov; @@ -300,7 +300,7 @@ int network_verify(Network *network) { network_verify_nexthops(network); - LIST_FOREACH_SAFE(static_fdb_entries, fdb, fdb_next, network->static_fdb_entries) + HASHMAP_FOREACH(fdb, network->fdb_entries_by_section) if (section_is_invalid(fdb->section)) fdb_entry_free(fdb); @@ -637,7 +637,6 @@ failure: static Network *network_free(Network *network) { IPv6ProxyNDPAddress *ipv6_proxy_ndp_address; RoutePrefix *route_prefix; - FdbEntry *fdb_entry; MdbEntry *mdb_entry; Address *address; Prefix *prefix; @@ -704,9 +703,6 @@ static Network *network_free(Network *network) { while ((address = network->static_addresses)) address_free(address); - while ((fdb_entry = network->static_fdb_entries)) - fdb_entry_free(fdb_entry); - while ((mdb_entry = network->static_mdb_entries)) mdb_entry_free(mdb_entry); @@ -722,7 +718,7 @@ static Network *network_free(Network *network) { hashmap_free(network->addresses_by_section); hashmap_free(network->routes_by_section); hashmap_free_with_destructor(network->nexthops_by_section, nexthop_free); - hashmap_free(network->fdb_entries_by_section); + hashmap_free_with_destructor(network->fdb_entries_by_section, fdb_entry_free); hashmap_free(network->mdb_entries_by_section); hashmap_free_with_destructor(network->neighbors_by_section, neighbor_free); hashmap_free_with_destructor(network->address_labels_by_section, address_label_free); @@ -849,7 +845,7 @@ bool network_has_static_ipv6_configurations(Network *network) { if (route->family == AF_INET6) return true; - LIST_FOREACH(static_fdb_entries, fdb, network->static_fdb_entries) + HASHMAP_FOREACH(fdb, network->fdb_entries_by_section) if (fdb->family == AF_INET6) return true; diff --git a/src/network/networkd-network.h b/src/network/networkd-network.h index c129338569f..e1d22f18646 100644 --- a/src/network/networkd-network.h +++ b/src/network/networkd-network.h @@ -283,7 +283,6 @@ struct Network { LIST_HEAD(Address, static_addresses); LIST_HEAD(Route, static_routes); - LIST_HEAD(FdbEntry, static_fdb_entries); LIST_HEAD(MdbEntry, static_mdb_entries); LIST_HEAD(IPv6ProxyNDPAddress, ipv6_proxy_ndp_addresses); LIST_HEAD(Prefix, static_prefixes); @@ -291,7 +290,6 @@ struct Network { unsigned n_static_addresses; unsigned n_static_routes; - unsigned n_static_fdb_entries; unsigned n_static_mdb_entries; unsigned n_ipv6_proxy_ndp_addresses; unsigned n_static_prefixes;