network/radv: use hash_ops with destructor for managing prefixes
This commit is contained in:
@@ -831,9 +831,9 @@ static Network *network_free(Network *network) {
|
||||
hashmap_free_with_destructor(network->bridge_mdb_entries_by_section, bridge_mdb_free);
|
||||
ordered_hashmap_free(network->neighbors_by_section);
|
||||
hashmap_free(network->address_labels_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->pref64_prefixes_by_section, prefix64_free);
|
||||
hashmap_free(network->prefixes_by_section);
|
||||
hashmap_free(network->route_prefixes_by_section);
|
||||
hashmap_free(network->pref64_prefixes_by_section);
|
||||
hashmap_free(network->rules_by_section);
|
||||
hashmap_free_with_destructor(network->dhcp_static_leases_by_section, dhcp_static_lease_free);
|
||||
ordered_hashmap_free(network->sr_iov_by_section);
|
||||
|
||||
@@ -35,7 +35,7 @@ bool link_radv_enabled(Link *link) {
|
||||
return link->network->router_prefix_delegation;
|
||||
}
|
||||
|
||||
Prefix* prefix_free(Prefix *prefix) {
|
||||
static Prefix* prefix_free(Prefix *prefix) {
|
||||
if (!prefix)
|
||||
return NULL;
|
||||
|
||||
@@ -52,6 +52,11 @@ Prefix* prefix_free(Prefix *prefix) {
|
||||
|
||||
DEFINE_SECTION_CLEANUP_FUNCTIONS(Prefix, prefix_free);
|
||||
|
||||
DEFINE_PRIVATE_HASH_OPS_WITH_VALUE_DESTRUCTOR(
|
||||
prefix_hash_ops_by_section,
|
||||
ConfigSection, config_section_hash_func, config_section_compare_func,
|
||||
Prefix, prefix_free);
|
||||
|
||||
static int prefix_new_static(Network *network, const char *filename, unsigned section_line, Prefix **ret) {
|
||||
_cleanup_(config_section_freep) ConfigSection *n = NULL;
|
||||
_cleanup_(prefix_freep) Prefix *prefix = NULL;
|
||||
@@ -87,7 +92,7 @@ static int prefix_new_static(Network *network, const char *filename, unsigned se
|
||||
.prefix.preferred_until = USEC_INFINITY,
|
||||
};
|
||||
|
||||
r = hashmap_ensure_put(&network->prefixes_by_section, &config_section_hash_ops, prefix->section, prefix);
|
||||
r = hashmap_ensure_put(&network->prefixes_by_section, &prefix_hash_ops_by_section, prefix->section, prefix);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
@@ -95,7 +100,7 @@ static int prefix_new_static(Network *network, const char *filename, unsigned se
|
||||
return 0;
|
||||
}
|
||||
|
||||
RoutePrefix* route_prefix_free(RoutePrefix *prefix) {
|
||||
static RoutePrefix* route_prefix_free(RoutePrefix *prefix) {
|
||||
if (!prefix)
|
||||
return NULL;
|
||||
|
||||
@@ -111,6 +116,11 @@ RoutePrefix* route_prefix_free(RoutePrefix *prefix) {
|
||||
|
||||
DEFINE_SECTION_CLEANUP_FUNCTIONS(RoutePrefix, route_prefix_free);
|
||||
|
||||
DEFINE_PRIVATE_HASH_OPS_WITH_VALUE_DESTRUCTOR(
|
||||
route_prefix_hash_ops_by_section,
|
||||
ConfigSection, config_section_hash_func, config_section_compare_func,
|
||||
RoutePrefix, route_prefix_free);
|
||||
|
||||
static int route_prefix_new_static(Network *network, const char *filename, unsigned section_line, RoutePrefix **ret) {
|
||||
_cleanup_(config_section_freep) ConfigSection *n = NULL;
|
||||
_cleanup_(route_prefix_freep) RoutePrefix *prefix = NULL;
|
||||
@@ -143,7 +153,7 @@ static int route_prefix_new_static(Network *network, const char *filename, unsig
|
||||
.route.valid_until = USEC_INFINITY,
|
||||
};
|
||||
|
||||
r = hashmap_ensure_put(&network->route_prefixes_by_section, &config_section_hash_ops, prefix->section, prefix);
|
||||
r = hashmap_ensure_put(&network->route_prefixes_by_section, &route_prefix_hash_ops_by_section, prefix->section, prefix);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
@@ -151,7 +161,7 @@ static int route_prefix_new_static(Network *network, const char *filename, unsig
|
||||
return 0;
|
||||
}
|
||||
|
||||
Prefix64* prefix64_free(Prefix64 *prefix) {
|
||||
static Prefix64* prefix64_free(Prefix64 *prefix) {
|
||||
if (!prefix)
|
||||
return NULL;
|
||||
|
||||
@@ -167,6 +177,11 @@ Prefix64* prefix64_free(Prefix64 *prefix) {
|
||||
|
||||
DEFINE_SECTION_CLEANUP_FUNCTIONS(Prefix64, prefix64_free);
|
||||
|
||||
DEFINE_PRIVATE_HASH_OPS_WITH_VALUE_DESTRUCTOR(
|
||||
prefix64_hash_ops_by_section,
|
||||
ConfigSection, config_section_hash_func, config_section_compare_func,
|
||||
Prefix64, prefix64_free);
|
||||
|
||||
static int prefix64_new_static(Network *network, const char *filename, unsigned section_line, Prefix64 **ret) {
|
||||
_cleanup_(config_section_freep) ConfigSection *n = NULL;
|
||||
_cleanup_(prefix64_freep) Prefix64 *prefix = NULL;
|
||||
@@ -199,7 +214,7 @@ static int prefix64_new_static(Network *network, const char *filename, unsigned
|
||||
.prefix64.valid_until = USEC_INFINITY,
|
||||
};
|
||||
|
||||
r = hashmap_ensure_put(&network->pref64_prefixes_by_section, &config_section_hash_ops, prefix->section, prefix);
|
||||
r = hashmap_ensure_put(&network->pref64_prefixes_by_section, &prefix64_hash_ops_by_section, prefix->section, prefix);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
@@ -809,9 +824,9 @@ void network_adjust_radv(Network *network) {
|
||||
}
|
||||
|
||||
if (!FLAGS_SET(network->router_prefix_delegation, RADV_PREFIX_DELEGATION_STATIC)) {
|
||||
network->prefixes_by_section = hashmap_free_with_destructor(network->prefixes_by_section, prefix_free);
|
||||
network->route_prefixes_by_section = hashmap_free_with_destructor(network->route_prefixes_by_section, route_prefix_free);
|
||||
network->pref64_prefixes_by_section = hashmap_free_with_destructor(network->pref64_prefixes_by_section, prefix64_free);
|
||||
network->prefixes_by_section = hashmap_free(network->prefixes_by_section);
|
||||
network->route_prefixes_by_section = hashmap_free(network->route_prefixes_by_section);
|
||||
network->pref64_prefixes_by_section = hashmap_free(network->pref64_prefixes_by_section);
|
||||
}
|
||||
|
||||
if (!network->router_prefix_delegation)
|
||||
|
||||
@@ -52,10 +52,6 @@ typedef struct Prefix64 {
|
||||
sd_ndisc_prefix64 prefix64;
|
||||
} Prefix64;
|
||||
|
||||
Prefix* prefix_free(Prefix *prefix);
|
||||
RoutePrefix* route_prefix_free(RoutePrefix *prefix);
|
||||
Prefix64* prefix64_free(Prefix64 *prefix);
|
||||
|
||||
void network_adjust_radv(Network *network);
|
||||
|
||||
int link_request_radv_addresses(Link *link);
|
||||
|
||||
Reference in New Issue
Block a user