diff options
author | Yu Watanabe <watanabe.yu+github@gmail.com> | 2020-09-29 18:20:43 +0200 |
---|---|---|
committer | Yu Watanabe <watanabe.yu+github@gmail.com> | 2020-10-06 19:44:42 +0200 |
commit | d6a2a0f9a7a325e98b053a1447b04d548a11e35e (patch) | |
tree | b5bca8b161164398bcdfe3a3558687062894535a /src | |
parent | network: make neighbor_free() return NULL (diff) | |
download | systemd-d6a2a0f9a7a325e98b053a1447b04d548a11e35e.tar.xz systemd-d6a2a0f9a7a325e98b053a1447b04d548a11e35e.zip |
network: drop list of static address labels
[IPv6AddressLabel] sections are managed by both LIST and Hashmap.
Let's drop list, as they store the completely same information.
Diffstat (limited to 'src')
-rw-r--r-- | src/network/networkd-address-label.c | 52 | ||||
-rw-r--r-- | src/network/networkd-address-label.h | 2 | ||||
-rw-r--r-- | src/network/networkd-link.c | 2 | ||||
-rw-r--r-- | src/network/networkd-network.c | 12 | ||||
-rw-r--r-- | src/network/networkd-network.h | 2 |
5 files changed, 24 insertions, 46 deletions
diff --git a/src/network/networkd-address-label.c b/src/network/networkd-address-label.c index 0d53aa9042..6c3c0409a9 100644 --- a/src/network/networkd-address-label.c +++ b/src/network/networkd-address-label.c @@ -16,16 +16,11 @@ void address_label_free(AddressLabel *label) { return; if (label->network) { - LIST_REMOVE(labels, label->network->address_labels, label); - assert(label->network->n_address_labels > 0); - label->network->n_address_labels--; - - if (label->section) { - hashmap_remove(label->network->address_labels_by_section, label->section); - network_config_section_free(label->section); - } + assert(label->section); + hashmap_remove(label->network->address_labels_by_section, label->section); } + network_config_section_free(label->section); free(label); } @@ -36,19 +31,17 @@ static int address_label_new_static(Network *network, const char *filename, unsi 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); - label = hashmap_get(network->address_labels_by_section, n); - if (label) { - *ret = TAKE_PTR(label); + r = network_config_section_new(filename, section_line, &n); + if (r < 0) + return r; - return 0; - } + label = hashmap_get(network->address_labels_by_section, n); + if (label) { + *ret = TAKE_PTR(label); + return 0; } label = new(AddressLabel, 1); @@ -57,25 +50,18 @@ static int address_label_new_static(Network *network, const char *filename, unsi *label = (AddressLabel) { .network = network, + .section = TAKE_PTR(n), }; - LIST_APPEND(labels, network->address_labels, label); - network->n_address_labels++; - - if (filename) { - label->section = TAKE_PTR(n); - - r = hashmap_ensure_allocated(&network->address_labels_by_section, &network_config_hash_ops); - if (r < 0) - return r; + r = hashmap_ensure_allocated(&network->address_labels_by_section, &network_config_hash_ops); + if (r < 0) + return r; - r = hashmap_put(network->address_labels_by_section, label->section, label); - if (r < 0) - return r; - } + r = hashmap_put(network->address_labels_by_section, label->section, label); + if (r < 0) + return r; *ret = TAKE_PTR(label); - return 0; } diff --git a/src/network/networkd-address-label.h b/src/network/networkd-address-label.h index 595072a17e..5e02dee246 100644 --- a/src/network/networkd-address-label.h +++ b/src/network/networkd-address-label.h @@ -25,8 +25,6 @@ struct AddressLabel { uint32_t label; union in_addr_union in_addr; - - LIST_FIELDS(AddressLabel, labels); }; void address_label_free(AddressLabel *label); diff --git a/src/network/networkd-link.c b/src/network/networkd-link.c index 9aebe74565..dc12a9694c 100644 --- a/src/network/networkd-link.c +++ b/src/network/networkd-link.c @@ -1322,7 +1322,7 @@ static int link_request_set_addresses(Link *link) { return r; } - LIST_FOREACH(labels, label, link->network->address_labels) { + HASHMAP_FOREACH(label, link->network->address_labels_by_section) { r = address_label_configure(label, link, NULL, false); if (r < 0) return log_link_warning_errno(link, r, "Could not set address label: %m"); diff --git a/src/network/networkd-network.c b/src/network/networkd-network.c index 0591b23e09..b170f7aa35 100644 --- a/src/network/networkd-network.c +++ b/src/network/networkd-network.c @@ -152,7 +152,7 @@ static int network_resolve_stacked_netdevs(Network *network) { int network_verify(Network *network) { RoutePrefix *route_prefix, *route_prefix_next; - AddressLabel *label, *label_next; + AddressLabel *label; Address *address, *address_next; Prefix *prefix, *prefix_next; Route *route, *route_next; @@ -310,7 +310,7 @@ int network_verify(Network *network) { network_verify_neighbors(network); - LIST_FOREACH_SAFE(labels, label, label_next, network->address_labels) + HASHMAP_FOREACH(label, network->address_labels_by_section) if (section_is_invalid(label->section)) address_label_free(label); @@ -640,7 +640,6 @@ failure: static Network *network_free(Network *network) { IPv6ProxyNDPAddress *ipv6_proxy_ndp_address; RoutePrefix *route_prefix; - AddressLabel *label; FdbEntry *fdb_entry; MdbEntry *mdb_entry; Address *address; @@ -717,9 +716,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 ((label = network->address_labels)) - address_label_free(label); - while ((prefix = network->static_prefixes)) prefix_free(prefix); @@ -732,7 +728,7 @@ static Network *network_free(Network *network) { hashmap_free(network->fdb_entries_by_section); hashmap_free(network->mdb_entries_by_section); hashmap_free_with_destructor(network->neighbors_by_section, neighbor_free); - hashmap_free(network->address_labels_by_section); + hashmap_free_with_destructor(network->address_labels_by_section, address_label_free); hashmap_free(network->prefixes_by_section); hashmap_free(network->route_prefixes_by_section); hashmap_free_with_destructor(network->rules_by_section, routing_policy_rule_free); @@ -868,7 +864,7 @@ bool network_has_static_ipv6_configurations(Network *network) { if (neighbor->family == AF_INET6) return true; - if (!LIST_IS_EMPTY(network->address_labels)) + if (!hashmap_isempty(network->address_labels_by_section)) return true; if (!LIST_IS_EMPTY(network->static_prefixes)) diff --git a/src/network/networkd-network.h b/src/network/networkd-network.h index acc4378771..4f05b92b3e 100644 --- a/src/network/networkd-network.h +++ b/src/network/networkd-network.h @@ -287,7 +287,6 @@ struct Network { LIST_HEAD(FdbEntry, static_fdb_entries); LIST_HEAD(MdbEntry, static_mdb_entries); LIST_HEAD(IPv6ProxyNDPAddress, ipv6_proxy_ndp_addresses); - LIST_HEAD(AddressLabel, address_labels); LIST_HEAD(Prefix, static_prefixes); LIST_HEAD(RoutePrefix, static_route_prefixes); @@ -296,7 +295,6 @@ struct Network { unsigned n_static_fdb_entries; unsigned n_static_mdb_entries; unsigned n_ipv6_proxy_ndp_addresses; - unsigned n_address_labels; unsigned n_static_prefixes; unsigned n_static_route_prefixes; |