network: drop list of bridge FDB entries
[BridgeFDB] sections are managed by both LIST and Hashmap, and they contains the completely same information. Let's drop the list.
This commit is contained in:
parent
df3a18f87f
commit
62ed9442bf
|
@ -36,12 +36,8 @@ FdbEntry *fdb_entry_free(FdbEntry *fdb_entry) {
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
if (fdb_entry->network) {
|
if (fdb_entry->network) {
|
||||||
LIST_REMOVE(static_fdb_entries, fdb_entry->network->static_fdb_entries, fdb_entry);
|
assert(fdb_entry->section);
|
||||||
assert(fdb_entry->network->n_static_fdb_entries > 0);
|
hashmap_remove(fdb_entry->network->fdb_entries_by_section, fdb_entry->section);
|
||||||
fdb_entry->network->n_static_fdb_entries--;
|
|
||||||
|
|
||||||
if (fdb_entry->section)
|
|
||||||
hashmap_remove(fdb_entry->network->fdb_entries_by_section, fdb_entry->section);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
network_config_section_free(fdb_entry->section);
|
network_config_section_free(fdb_entry->section);
|
||||||
|
@ -63,23 +59,21 @@ static int fdb_entry_new_static(
|
||||||
|
|
||||||
assert(network);
|
assert(network);
|
||||||
assert(ret);
|
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. */
|
/* search entry in hashmap first. */
|
||||||
if (filename) {
|
fdb_entry = hashmap_get(network->fdb_entries_by_section, n);
|
||||||
r = network_config_section_new(filename, section_line, &n);
|
if (fdb_entry) {
|
||||||
if (r < 0)
|
*ret = TAKE_PTR(fdb_entry);
|
||||||
return r;
|
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;
|
return -E2BIG;
|
||||||
|
|
||||||
/* allocate space for and FDB entry. */
|
/* allocate space for and FDB entry. */
|
||||||
|
@ -90,24 +84,18 @@ static int fdb_entry_new_static(
|
||||||
/* init FDB structure. */
|
/* init FDB structure. */
|
||||||
*fdb_entry = (FdbEntry) {
|
*fdb_entry = (FdbEntry) {
|
||||||
.network = network,
|
.network = network,
|
||||||
|
.section = TAKE_PTR(n),
|
||||||
.vni = VXLAN_VID_MAX + 1,
|
.vni = VXLAN_VID_MAX + 1,
|
||||||
.fdb_ntf_flags = NEIGHBOR_CACHE_ENTRY_FLAGS_SELF,
|
.fdb_ntf_flags = NEIGHBOR_CACHE_ENTRY_FLAGS_SELF,
|
||||||
};
|
};
|
||||||
|
|
||||||
LIST_PREPEND(static_fdb_entries, network->static_fdb_entries, fdb_entry);
|
r = hashmap_ensure_allocated(&network->fdb_entries_by_section, &network_config_hash_ops);
|
||||||
network->n_static_fdb_entries++;
|
if (r < 0)
|
||||||
|
return r;
|
||||||
|
|
||||||
if (filename) {
|
r = hashmap_put(network->fdb_entries_by_section, fdb_entry->section, fdb_entry);
|
||||||
fdb_entry->section = TAKE_PTR(n);
|
if (r < 0)
|
||||||
|
return r;
|
||||||
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* return allocated FDB structure. */
|
/* return allocated FDB structure. */
|
||||||
*ret = TAKE_PTR(fdb_entry);
|
*ret = TAKE_PTR(fdb_entry);
|
||||||
|
|
|
@ -39,8 +39,6 @@ struct FdbEntry {
|
||||||
struct ether_addr mac_addr;
|
struct ether_addr mac_addr;
|
||||||
union in_addr_union destination_addr;
|
union in_addr_union destination_addr;
|
||||||
NeighborCacheEntryFlags fdb_ntf_flags;
|
NeighborCacheEntryFlags fdb_ntf_flags;
|
||||||
|
|
||||||
LIST_FIELDS(FdbEntry, static_fdb_entries);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
FdbEntry *fdb_entry_free(FdbEntry *fdb_entry);
|
FdbEntry *fdb_entry_free(FdbEntry *fdb_entry);
|
||||||
|
|
|
@ -1136,7 +1136,7 @@ static int link_set_bridge_fdb(Link *link) {
|
||||||
FdbEntry *fdb_entry;
|
FdbEntry *fdb_entry;
|
||||||
int r;
|
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);
|
r = fdb_entry_configure(link, fdb_entry);
|
||||||
if (r < 0)
|
if (r < 0)
|
||||||
return log_link_error_errno(link, r, "Failed to add MAC entry to static MAC table: %m");
|
return log_link_error_errno(link, r, "Failed to add MAC entry to static MAC table: %m");
|
||||||
|
|
|
@ -156,7 +156,7 @@ int network_verify(Network *network) {
|
||||||
Address *address, *address_next;
|
Address *address, *address_next;
|
||||||
Prefix *prefix, *prefix_next;
|
Prefix *prefix, *prefix_next;
|
||||||
Route *route, *route_next;
|
Route *route, *route_next;
|
||||||
FdbEntry *fdb, *fdb_next;
|
FdbEntry *fdb;
|
||||||
MdbEntry *mdb, *mdb_next;
|
MdbEntry *mdb, *mdb_next;
|
||||||
TrafficControl *tc;
|
TrafficControl *tc;
|
||||||
SRIOV *sr_iov;
|
SRIOV *sr_iov;
|
||||||
|
@ -300,7 +300,7 @@ int network_verify(Network *network) {
|
||||||
|
|
||||||
network_verify_nexthops(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))
|
if (section_is_invalid(fdb->section))
|
||||||
fdb_entry_free(fdb);
|
fdb_entry_free(fdb);
|
||||||
|
|
||||||
|
@ -637,7 +637,6 @@ failure:
|
||||||
static Network *network_free(Network *network) {
|
static Network *network_free(Network *network) {
|
||||||
IPv6ProxyNDPAddress *ipv6_proxy_ndp_address;
|
IPv6ProxyNDPAddress *ipv6_proxy_ndp_address;
|
||||||
RoutePrefix *route_prefix;
|
RoutePrefix *route_prefix;
|
||||||
FdbEntry *fdb_entry;
|
|
||||||
MdbEntry *mdb_entry;
|
MdbEntry *mdb_entry;
|
||||||
Address *address;
|
Address *address;
|
||||||
Prefix *prefix;
|
Prefix *prefix;
|
||||||
|
@ -704,9 +703,6 @@ static Network *network_free(Network *network) {
|
||||||
while ((address = network->static_addresses))
|
while ((address = network->static_addresses))
|
||||||
address_free(address);
|
address_free(address);
|
||||||
|
|
||||||
while ((fdb_entry = network->static_fdb_entries))
|
|
||||||
fdb_entry_free(fdb_entry);
|
|
||||||
|
|
||||||
while ((mdb_entry = network->static_mdb_entries))
|
while ((mdb_entry = network->static_mdb_entries))
|
||||||
mdb_entry_free(mdb_entry);
|
mdb_entry_free(mdb_entry);
|
||||||
|
|
||||||
|
@ -722,7 +718,7 @@ static Network *network_free(Network *network) {
|
||||||
hashmap_free(network->addresses_by_section);
|
hashmap_free(network->addresses_by_section);
|
||||||
hashmap_free(network->routes_by_section);
|
hashmap_free(network->routes_by_section);
|
||||||
hashmap_free_with_destructor(network->nexthops_by_section, nexthop_free);
|
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(network->mdb_entries_by_section);
|
||||||
hashmap_free_with_destructor(network->neighbors_by_section, neighbor_free);
|
hashmap_free_with_destructor(network->neighbors_by_section, neighbor_free);
|
||||||
hashmap_free_with_destructor(network->address_labels_by_section, address_label_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)
|
if (route->family == AF_INET6)
|
||||||
return true;
|
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)
|
if (fdb->family == AF_INET6)
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
|
|
|
@ -283,7 +283,6 @@ struct Network {
|
||||||
|
|
||||||
LIST_HEAD(Address, static_addresses);
|
LIST_HEAD(Address, static_addresses);
|
||||||
LIST_HEAD(Route, static_routes);
|
LIST_HEAD(Route, static_routes);
|
||||||
LIST_HEAD(FdbEntry, static_fdb_entries);
|
|
||||||
LIST_HEAD(MdbEntry, static_mdb_entries);
|
LIST_HEAD(MdbEntry, static_mdb_entries);
|
||||||
LIST_HEAD(IPv6ProxyNDPAddress, ipv6_proxy_ndp_addresses);
|
LIST_HEAD(IPv6ProxyNDPAddress, ipv6_proxy_ndp_addresses);
|
||||||
LIST_HEAD(Prefix, static_prefixes);
|
LIST_HEAD(Prefix, static_prefixes);
|
||||||
|
@ -291,7 +290,6 @@ struct Network {
|
||||||
|
|
||||||
unsigned n_static_addresses;
|
unsigned n_static_addresses;
|
||||||
unsigned n_static_routes;
|
unsigned n_static_routes;
|
||||||
unsigned n_static_fdb_entries;
|
|
||||||
unsigned n_static_mdb_entries;
|
unsigned n_static_mdb_entries;
|
||||||
unsigned n_ipv6_proxy_ndp_addresses;
|
unsigned n_ipv6_proxy_ndp_addresses;
|
||||||
unsigned n_static_prefixes;
|
unsigned n_static_prefixes;
|
||||||
|
|
Loading…
Reference in a new issue