}
int network_verify(Network *network) {
- RoutePrefix *route_prefix, *route_prefix_next;
+ RoutePrefix *route_prefix;
Address *address, *address_next;
- Prefix *prefix, *prefix_next;
+ Prefix *prefix;
Route *route, *route_next;
TrafficControl *tc;
SRIOV *sr_iov;
network_verify_neighbors(network);
network_verify_address_labels(network);
- LIST_FOREACH_SAFE(prefixes, prefix, prefix_next, network->static_prefixes)
+ HASHMAP_FOREACH(prefix, network->prefixes_by_section)
if (section_is_invalid(prefix->section))
prefix_free(prefix);
- LIST_FOREACH_SAFE(route_prefixes, route_prefix, route_prefix_next, network->static_route_prefixes)
+ HASHMAP_FOREACH(route_prefix, network->route_prefixes_by_section)
if (section_is_invalid(route_prefix->section))
route_prefix_free(route_prefix);
}
static Network *network_free(Network *network) {
- RoutePrefix *route_prefix;
Address *address;
- Prefix *prefix;
Route *route;
if (!network)
while ((address = network->static_addresses))
address_free(address);
- while ((prefix = network->static_prefixes))
- prefix_free(prefix);
-
- while ((route_prefix = network->static_route_prefixes))
- route_prefix_free(route_prefix);
-
set_free_free(network->ipv6_proxy_ndp_addresses);
hashmap_free(network->addresses_by_section);
hashmap_free(network->routes_by_section);
hashmap_free_with_destructor(network->mdb_entries_by_section, mdb_entry_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(network->prefixes_by_section);
- hashmap_free(network->route_prefixes_by_section);
+ hashmap_free_with_destructor(network->prefixes_by_section, prefix_free);
+ hashmap_free_with_destructor(network->route_prefixes_by_section, route_prefix_free);
hashmap_free_with_destructor(network->rules_by_section, routing_policy_rule_free);
ordered_hashmap_free_with_destructor(network->sr_iov_by_section, sr_iov_free);
ordered_hashmap_free_with_destructor(network->tc_by_section, traffic_control_free);
if (!hashmap_isempty(network->address_labels_by_section))
return true;
- if (!LIST_IS_EMPTY(network->static_prefixes))
+ if (!hashmap_isempty(network->prefixes_by_section))
return true;
return false;
return NULL;
if (prefix->network) {
- LIST_REMOVE(prefixes, prefix->network->static_prefixes, prefix);
- assert(prefix->network->n_static_prefixes > 0);
- prefix->network->n_static_prefixes--;
-
- if (prefix->section)
- hashmap_remove(prefix->network->prefixes_by_section,
- prefix->section);
+ assert(prefix->section);
+ hashmap_remove(prefix->network->prefixes_by_section, prefix->section);
}
network_config_section_free(prefix->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);
- if (section_line) {
- prefix = hashmap_get(network->prefixes_by_section, n);
- if (prefix) {
- *ret = TAKE_PTR(prefix);
+ r = network_config_section_new(filename, section_line, &n);
+ if (r < 0)
+ return r;
- return 0;
- }
- }
+ prefix = hashmap_get(network->prefixes_by_section, n);
+ if (prefix) {
+ *ret = TAKE_PTR(prefix);
+ return 0;
}
r = prefix_new(&prefix);
return r;
prefix->network = network;
- LIST_APPEND(prefixes, network->static_prefixes, prefix);
- network->n_static_prefixes++;
-
- if (filename) {
- prefix->section = TAKE_PTR(n);
+ prefix->section = TAKE_PTR(n);
- r = hashmap_ensure_allocated(&network->prefixes_by_section, &network_config_hash_ops);
- if (r < 0)
- return r;
+ r = hashmap_ensure_allocated(&network->prefixes_by_section, &network_config_hash_ops);
+ if (r < 0)
+ return r;
- r = hashmap_put(network->prefixes_by_section, prefix->section, prefix);
- if (r < 0)
- return r;
- }
+ r = hashmap_put(network->prefixes_by_section, prefix->section, prefix);
+ if (r < 0)
+ return r;
*ret = TAKE_PTR(prefix);
return NULL;
if (prefix->network) {
- LIST_REMOVE(route_prefixes, prefix->network->static_route_prefixes, prefix);
- assert(prefix->network->n_static_route_prefixes > 0);
- prefix->network->n_static_route_prefixes--;
-
- if (prefix->section)
- hashmap_remove(prefix->network->route_prefixes_by_section,
- prefix->section);
+ assert(prefix->section);
+ hashmap_remove(prefix->network->route_prefixes_by_section, prefix->section);
}
network_config_section_free(prefix->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);
- if (section_line) {
- prefix = hashmap_get(network->route_prefixes_by_section, n);
- if (prefix) {
- *ret = TAKE_PTR(prefix);
+ r = network_config_section_new(filename, section_line, &n);
+ if (r < 0)
+ return r;
- return 0;
- }
- }
+ prefix = hashmap_get(network->route_prefixes_by_section, n);
+ if (prefix) {
+ *ret = TAKE_PTR(prefix);
+ return 0;
}
r = route_prefix_new(&prefix);
return r;
prefix->network = network;
- LIST_APPEND(route_prefixes, network->static_route_prefixes, prefix);
- network->n_static_route_prefixes++;
-
- if (filename) {
- prefix->section = TAKE_PTR(n);
+ prefix->section = TAKE_PTR(n);
- r = hashmap_ensure_allocated(&network->route_prefixes_by_section, &network_config_hash_ops);
- if (r < 0)
- return r;
+ r = hashmap_ensure_allocated(&network->route_prefixes_by_section, &network_config_hash_ops);
+ if (r < 0)
+ return r;
- r = hashmap_put(network->route_prefixes_by_section, prefix->section, prefix);
- if (r < 0)
- return r;
- }
+ r = hashmap_put(network->route_prefixes_by_section, prefix->section, prefix);
+ if (r < 0)
+ return r;
*ret = TAKE_PTR(prefix);
}
int radv_configure(Link *link) {
- RoutePrefix *q;
- Prefix *p;
int r;
assert(link);
}
if (link->network->router_prefix_delegation & RADV_PREFIX_DELEGATION_STATIC) {
- LIST_FOREACH(prefixes, p, link->network->static_prefixes) {
+ RoutePrefix *q;
+ Prefix *p;
+
+ HASHMAP_FOREACH(p, link->network->prefixes_by_section) {
r = sd_radv_add_prefix(link->radv, p->radv_prefix, false);
if (r == -EEXIST)
continue;
return r;
}
- LIST_FOREACH(route_prefixes, q, link->network->static_route_prefixes) {
+ HASHMAP_FOREACH(q, link->network->route_prefixes_by_section) {
r = sd_radv_add_route_prefix(link->radv, q->radv_route_prefix, false);
if (r == -EEXIST)
continue;