mirror of
https://github.com/systemd/systemd.git
synced 2024-11-02 02:21:44 +03:00
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.
This commit is contained in:
parent
64753f354d
commit
d6a2a0f9a7
@ -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));
|
||||
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;
|
||||
|
||||
label = hashmap_get(network->address_labels_by_section, n);
|
||||
if (label) {
|
||||
*ret = TAKE_PTR(label);
|
||||
|
||||
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++;
|
||||
r = hashmap_ensure_allocated(&network->address_labels_by_section, &network_config_hash_ops);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
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_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;
|
||||
}
|
||||
|
||||
|
@ -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);
|
||||
|
@ -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");
|
||||
|
@ -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))
|
||||
|
@ -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;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user