]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
network/dhcp-server: use hash_ops with destructor for static lease
authorYu Watanabe <watanabe.yu+github@gmail.com>
Sat, 12 Apr 2025 17:54:06 +0000 (02:54 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Sun, 13 Apr 2025 01:10:29 +0000 (10:10 +0900)
src/network/networkd-dhcp-server-static-lease.c
src/network/networkd-dhcp-server-static-lease.h
src/network/networkd-network.c

index 8e7eec64d17027b23d7621906eb62621a75caa26..b8c7e4dde8bd941ef9a791d5475519e5ae90c1d7 100644 (file)
@@ -7,9 +7,7 @@
 #include "networkd-network.h"
 #include "networkd-util.h"
 
-DEFINE_SECTION_CLEANUP_FUNCTIONS(DHCPStaticLease, dhcp_static_lease_free);
-
-DHCPStaticLease *dhcp_static_lease_free(DHCPStaticLease *static_lease) {
+static DHCPStaticLease* dhcp_static_lease_free(DHCPStaticLease *static_lease) {
         if (!static_lease)
                 return NULL;
 
@@ -21,6 +19,13 @@ DHCPStaticLease *dhcp_static_lease_free(DHCPStaticLease *static_lease) {
         return mfree(static_lease);
 }
 
+DEFINE_SECTION_CLEANUP_FUNCTIONS(DHCPStaticLease, dhcp_static_lease_free);
+
+DEFINE_PRIVATE_HASH_OPS_WITH_VALUE_DESTRUCTOR(
+                static_lease_hash_ops_by_section,
+                ConfigSection, config_section_hash_func, config_section_compare_func,
+                DHCPStaticLease, dhcp_static_lease_free);
+
 static int dhcp_static_lease_new(DHCPStaticLease **ret) {
         DHCPStaticLease *p;
 
@@ -60,7 +65,8 @@ static int lease_new_static(Network *network, const char *filename, unsigned sec
 
         static_lease->network = network;
         static_lease->section = TAKE_PTR(n);
-        r = hashmap_ensure_put(&network->dhcp_static_leases_by_section, &config_section_hash_ops, static_lease->section, static_lease);
+
+        r = hashmap_ensure_put(&network->dhcp_static_leases_by_section, &static_lease_hash_ops_by_section, static_lease->section, static_lease);
         if (r < 0)
                 return r;
 
index 9b8e78b90d817cc27482e404d91760fa220c92a5..fe8e249d5a73ec2290eb81c5788e0364868b1eb2 100644 (file)
@@ -19,7 +19,6 @@ typedef struct DHCPStaticLease {
         size_t client_id_size;
 } DHCPStaticLease;
 
-DHCPStaticLease *dhcp_static_lease_free(DHCPStaticLease *lease);
 void network_drop_invalid_static_leases(Network *network);
 
 CONFIG_PARSER_PROTOTYPE(config_parse_dhcp_static_lease_address);
index 3ae87e939a78286d1b1b7e2c52d280d594a7944f..d036e99ec3c14c54d63e52cd1e9d01d40410609a 100644 (file)
@@ -835,7 +835,7 @@ static Network *network_free(Network *network) {
         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);
+        hashmap_free(network->dhcp_static_leases_by_section);
         ordered_hashmap_free(network->sr_iov_by_section);
         hashmap_free(network->qdiscs_by_section);
         hashmap_free(network->tclasses_by_section);