Skip to content

Commit ce921df

Browse files
authored
network/network: hash_ops related cleanups (systemd#37120)
2 parents c96a5d9 + 1b25b88 commit ce921df

17 files changed

+97
-78
lines changed

src/network/networkd-bridge-fdb.c

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,7 @@
2222

2323
#define STATIC_BRIDGE_FDB_ENTRIES_PER_NETWORK_MAX 1024U
2424

25-
/* remove and FDB entry. */
26-
BridgeFDB *bridge_fdb_free(BridgeFDB *fdb) {
25+
static BridgeFDB* bridge_fdb_free(BridgeFDB *fdb) {
2726
if (!fdb)
2827
return NULL;
2928

@@ -40,7 +39,11 @@ BridgeFDB *bridge_fdb_free(BridgeFDB *fdb) {
4039

4140
DEFINE_SECTION_CLEANUP_FUNCTIONS(BridgeFDB, bridge_fdb_free);
4241

43-
/* create a new FDB entry or get an existing one. */
42+
DEFINE_PRIVATE_HASH_OPS_WITH_VALUE_DESTRUCTOR(
43+
bridge_fdb_hash_ops_by_section,
44+
ConfigSection, config_section_hash_func, config_section_compare_func,
45+
BridgeFDB, bridge_fdb_free);
46+
4447
static int bridge_fdb_new_static(
4548
Network *network,
4649
const char *filename,
@@ -83,13 +86,12 @@ static int bridge_fdb_new_static(
8386
.ntf_flags = NEIGHBOR_CACHE_ENTRY_FLAGS_SELF,
8487
};
8588

86-
r = hashmap_ensure_put(&network->bridge_fdb_entries_by_section, &config_section_hash_ops, fdb->section, fdb);
89+
r = hashmap_ensure_put(&network->bridge_fdb_entries_by_section, &bridge_fdb_hash_ops_by_section, fdb->section, fdb);
8790
if (r < 0)
8891
return r;
8992

9093
/* return allocated FDB structure. */
9194
*ret = TAKE_PTR(fdb);
92-
9395
return 0;
9496
}
9597

src/network/networkd-bridge-fdb.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,6 @@ typedef struct BridgeFDB {
4040
int outgoing_ifindex;
4141
} BridgeFDB;
4242

43-
BridgeFDB *bridge_fdb_free(BridgeFDB *fdb);
44-
4543
void network_drop_invalid_bridge_fdb_entries(Network *network);
4644

4745
int link_request_static_bridge_fdb(Link *link);

src/network/networkd-bridge-mdb.c

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,13 @@
1010
#include "networkd-manager.h"
1111
#include "networkd-network.h"
1212
#include "networkd-queue.h"
13+
#include "networkd-util.h"
1314
#include "string-util.h"
1415
#include "vlan-util.h"
1516

1617
#define STATIC_BRIDGE_MDB_ENTRIES_PER_NETWORK_MAX 1024U
1718

18-
/* remove MDB entry. */
19-
BridgeMDB *bridge_mdb_free(BridgeMDB *mdb) {
19+
static BridgeMDB* bridge_mdb_free(BridgeMDB *mdb) {
2020
if (!mdb)
2121
return NULL;
2222

@@ -32,7 +32,11 @@ BridgeMDB *bridge_mdb_free(BridgeMDB *mdb) {
3232

3333
DEFINE_SECTION_CLEANUP_FUNCTIONS(BridgeMDB, bridge_mdb_free);
3434

35-
/* create a new MDB entry or get an existing one. */
35+
DEFINE_PRIVATE_HASH_OPS_WITH_VALUE_DESTRUCTOR(
36+
bridge_mdb_hash_ops_by_section,
37+
ConfigSection, config_section_hash_func, config_section_compare_func,
38+
BridgeMDB, bridge_mdb_free);
39+
3640
static int bridge_mdb_new_static(
3741
Network *network,
3842
const char *filename,
@@ -74,7 +78,7 @@ static int bridge_mdb_new_static(
7478
.type = _BRIDGE_MDB_ENTRY_TYPE_INVALID,
7579
};
7680

77-
r = hashmap_ensure_put(&network->bridge_mdb_entries_by_section, &config_section_hash_ops, mdb->section, mdb);
81+
r = hashmap_ensure_put(&network->bridge_mdb_entries_by_section, &bridge_mdb_hash_ops_by_section, mdb->section, mdb);
7882
if (r < 0)
7983
return r;
8084

src/network/networkd-bridge-mdb.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55

66
#include "conf-parser.h"
77
#include "in-addr-util.h"
8-
#include "networkd-util.h"
98

109
typedef struct Link Link;
1110
typedef struct Network Network;
@@ -30,8 +29,6 @@ typedef struct BridgeMDB {
3029
uint16_t vlan_id;
3130
} BridgeMDB;
3231

33-
BridgeMDB *bridge_mdb_free(BridgeMDB *mdb);
34-
3532
void network_drop_invalid_bridge_mdb_entries(Network *network);
3633

3734
int link_request_static_bridge_mdb(Link *link);

src/network/networkd-dhcp-server-static-lease.c

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,7 @@
77
#include "networkd-network.h"
88
#include "networkd-util.h"
99

10-
DEFINE_SECTION_CLEANUP_FUNCTIONS(DHCPStaticLease, dhcp_static_lease_free);
11-
12-
DHCPStaticLease *dhcp_static_lease_free(DHCPStaticLease *static_lease) {
10+
static DHCPStaticLease* dhcp_static_lease_free(DHCPStaticLease *static_lease) {
1311
if (!static_lease)
1412
return NULL;
1513

@@ -21,6 +19,13 @@ DHCPStaticLease *dhcp_static_lease_free(DHCPStaticLease *static_lease) {
2119
return mfree(static_lease);
2220
}
2321

22+
DEFINE_SECTION_CLEANUP_FUNCTIONS(DHCPStaticLease, dhcp_static_lease_free);
23+
24+
DEFINE_PRIVATE_HASH_OPS_WITH_VALUE_DESTRUCTOR(
25+
static_lease_hash_ops_by_section,
26+
ConfigSection, config_section_hash_func, config_section_compare_func,
27+
DHCPStaticLease, dhcp_static_lease_free);
28+
2429
static int dhcp_static_lease_new(DHCPStaticLease **ret) {
2530
DHCPStaticLease *p;
2631

@@ -60,7 +65,8 @@ static int lease_new_static(Network *network, const char *filename, unsigned sec
6065

6166
static_lease->network = network;
6267
static_lease->section = TAKE_PTR(n);
63-
r = hashmap_ensure_put(&network->dhcp_static_leases_by_section, &config_section_hash_ops, static_lease->section, static_lease);
68+
69+
r = hashmap_ensure_put(&network->dhcp_static_leases_by_section, &static_lease_hash_ops_by_section, static_lease->section, static_lease);
6470
if (r < 0)
6571
return r;
6672

src/network/networkd-dhcp-server-static-lease.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ typedef struct DHCPStaticLease {
1919
size_t client_id_size;
2020
} DHCPStaticLease;
2121

22-
DHCPStaticLease *dhcp_static_lease_free(DHCPStaticLease *lease);
2322
void network_drop_invalid_static_leases(Network *network);
2423

2524
CONFIG_PARSER_PROTOTYPE(config_parse_dhcp_static_lease_address);

src/network/networkd-dns.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,7 @@ int config_parse_dnssec_negative_trust_anchors(
281281
assert(rvalue);
282282

283283
if (isempty(rvalue)) {
284-
*nta = set_free_free(*nta);
284+
*nta = set_free(*nta);
285285
return 0;
286286
}
287287

@@ -306,7 +306,7 @@ int config_parse_dnssec_negative_trust_anchors(
306306
continue;
307307
}
308308

309-
r = set_ensure_consume(nta, &dns_name_hash_ops, TAKE_PTR(w));
309+
r = set_ensure_consume(nta, &dns_name_hash_ops_free, TAKE_PTR(w));
310310
if (r < 0)
311311
return log_oom();
312312
}

src/network/networkd-ipv6-proxy-ndp.c

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,13 @@ void network_adjust_ipv6_proxy_ndp(Network *network) {
2222
log_once(LOG_WARNING,
2323
"%s: IPv6 proxy NDP addresses are set, but IPv6 is not supported by kernel, "
2424
"Ignoring IPv6 proxy NDP addresses.", network->filename);
25-
network->ipv6_proxy_ndp_addresses = set_free_free(network->ipv6_proxy_ndp_addresses);
25+
network->ipv6_proxy_ndp_addresses = set_free(network->ipv6_proxy_ndp_addresses);
26+
return;
27+
}
28+
29+
if (network->ipv6_proxy_ndp == 0) {
30+
log_warning("%s: IPv6ProxyNDP= is disabled. Ignoring IPv6ProxyNDPAddress=.", network->filename);
31+
network->ipv6_proxy_ndp_addresses = set_free(network->ipv6_proxy_ndp_addresses);
2632
}
2733
}
2834

@@ -149,7 +155,7 @@ int config_parse_ipv6_proxy_ndp_address(
149155
assert(rvalue);
150156

151157
if (isempty(rvalue)) {
152-
network->ipv6_proxy_ndp_addresses = set_free_free(network->ipv6_proxy_ndp_addresses);
158+
network->ipv6_proxy_ndp_addresses = set_free(network->ipv6_proxy_ndp_addresses);
153159
return 0;
154160
}
155161

@@ -170,11 +176,9 @@ int config_parse_ipv6_proxy_ndp_address(
170176
if (!address)
171177
return log_oom();
172178

173-
r = set_ensure_put(&network->ipv6_proxy_ndp_addresses, &in6_addr_hash_ops, address);
179+
r = set_ensure_consume(&network->ipv6_proxy_ndp_addresses, &in6_addr_hash_ops_free, TAKE_PTR(address));
174180
if (r < 0)
175181
return log_oom();
176-
if (r > 0)
177-
TAKE_PTR(address);
178182

179183
return 0;
180184
}

src/network/networkd-link-bus.c

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -479,7 +479,7 @@ int bus_link_method_set_dnssec(sd_bus_message *message, void *userdata, sd_bus_e
479479
}
480480

481481
int bus_link_method_set_dnssec_negative_trust_anchors(sd_bus_message *message, void *userdata, sd_bus_error *error) {
482-
_cleanup_set_free_free_ Set *ns = NULL;
482+
_cleanup_set_free_ Set *ns = NULL;
483483
_cleanup_strv_free_ char **ntas = NULL;
484484
Link *l = ASSERT_PTR(userdata);
485485
int r;
@@ -502,7 +502,7 @@ int bus_link_method_set_dnssec_negative_trust_anchors(sd_bus_message *message, v
502502
return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Invalid negative trust anchor domain: %s", *i);
503503
}
504504

505-
ns = set_new(&dns_name_hash_ops);
505+
ns = set_new(&dns_name_hash_ops_free);
506506
if (!ns)
507507
return -ENOMEM;
508508

@@ -523,8 +523,7 @@ int bus_link_method_set_dnssec_negative_trust_anchors(sd_bus_message *message, v
523523
if (r == 0)
524524
return 1; /* Polkit will call us back */
525525

526-
set_free_free(l->dnssec_negative_trust_anchors);
527-
l->dnssec_negative_trust_anchors = TAKE_PTR(ns);
526+
set_free_and_replace(l->dnssec_negative_trust_anchors, ns);
528527

529528
r = link_save_and_clean_full(l, /* also_save_manager = */ true);
530529
if (r < 0)

src/network/networkd-link.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@ void link_dns_settings_clear(Link *link) {
231231
link->dnssec_mode = _DNSSEC_MODE_INVALID;
232232
link->dns_over_tls_mode = _DNS_OVER_TLS_MODE_INVALID;
233233

234-
link->dnssec_negative_trust_anchors = set_free_free(link->dnssec_negative_trust_anchors);
234+
link->dnssec_negative_trust_anchors = set_free(link->dnssec_negative_trust_anchors);
235235
}
236236

237237
static void link_free_engines(Link *link) {

0 commit comments

Comments
 (0)