]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
network: use dns_name_hash_ops_free to manage domains 37832/head
authorYu Watanabe <watanabe.yu+github@gmail.com>
Fri, 13 Jun 2025 15:08:41 +0000 (00:08 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Fri, 13 Jun 2025 15:17:14 +0000 (00:17 +0900)
src/network/networkd-dns.c
src/network/networkd-link-bus.c
src/network/networkd-state-file.c

index 44289d665865b95e327a7051d696d18d28c8a02a..eef9d46b162725436dd2b5f18f92ccea444b0bd3 100644 (file)
@@ -200,7 +200,7 @@ int config_parse_domains(
                 }
 
                 OrderedSet **set = is_route ? &n->route_domains : &n->search_domains;
-                r = ordered_set_put_strdup(set, domain);
+                r = ordered_set_put_strdup_full(set, &dns_name_hash_ops_free, domain);
                 if (r == -EEXIST)
                         continue;
                 if (r < 0)
index 297e1461bd4695398e0ea27a7e2c561fa018d62d..5b9e901bf849eec5fbf5a3b83c8476256833a1c5 100644 (file)
@@ -197,11 +197,13 @@ int bus_link_method_set_domains(sd_bus_message *message, void *userdata, sd_bus_
         if (r < 0)
                 return r;
 
-        search_domains = ordered_set_new(&string_hash_ops_free);
+        /* The method accepts an empty strv, to override the domains set in .network.
+         * Hence, we need to explicitly allocate empty sets here. */
+        search_domains = ordered_set_new(&dns_name_hash_ops_free);
         if (!search_domains)
                 return -ENOMEM;
 
-        route_domains = ordered_set_new(&string_hash_ops_free);
+        route_domains = ordered_set_new(&dns_name_hash_ops_free);
         if (!route_domains)
                 return -ENOMEM;
 
index 288390645ea352778dd486babddf735b463868c5..abd8b5a4ef60c739f22afd19c5dd4b057a4355cd 100644 (file)
@@ -8,6 +8,7 @@
 #include "sd-dhcp6-lease.h"
 
 #include "alloc-util.h"
+#include "dns-domain.h"
 #include "dns-resolver-internal.h"
 #include "errno-util.h"
 #include "escape.h"
@@ -280,9 +281,9 @@ static int link_put_domains(Link *link, bool is_route, OrderedSet **s) {
         use_domains = is_route ? USE_DOMAINS_ROUTE : USE_DOMAINS_YES;
 
         if (link_domains)
-                return ordered_set_put_string_set(s, link_domains);
+                return ordered_set_put_string_set_full(s, &dns_name_hash_ops_free, link_domains);
 
-        r = ordered_set_put_string_set(s, network_domains);
+        r = ordered_set_put_string_set_full(s, &dns_name_hash_ops_free, network_domains);
         if (r < 0)
                 return r;
 
@@ -292,14 +293,14 @@ static int link_put_domains(Link *link, bool is_route, OrderedSet **s) {
 
                 r = sd_dhcp_lease_get_domainname(link->dhcp_lease, &domainname);
                 if (r >= 0) {
-                        r = ordered_set_put_strdup(s, domainname);
+                        r = ordered_set_put_strdup_full(s, &dns_name_hash_ops_free, domainname);
                         if (r < 0)
                                 return r;
                 }
 
                 r = sd_dhcp_lease_get_search_domains(link->dhcp_lease, &domains);
                 if (r >= 0) {
-                        r = ordered_set_put_strdupv(s, domains);
+                        r = ordered_set_put_strdupv_full(s, &dns_name_hash_ops_free, domains);
                         if (r < 0)
                                 return r;
                 }
@@ -310,7 +311,7 @@ static int link_put_domains(Link *link, bool is_route, OrderedSet **s) {
 
                 r = sd_dhcp6_lease_get_domains(link->dhcp6_lease, &domains);
                 if (r >= 0) {
-                        r = ordered_set_put_strdupv(s, domains);
+                        r = ordered_set_put_strdupv_full(s, &dns_name_hash_ops_free, domains);
                         if (r < 0)
                                 return r;
                 }
@@ -320,7 +321,7 @@ static int link_put_domains(Link *link, bool is_route, OrderedSet **s) {
                 NDiscDNSSL *a;
 
                 SET_FOREACH(a, link->ndisc_dnssl) {
-                        r = ordered_set_put_strdup(s, ndisc_dnssl_domain(a));
+                        r = ordered_set_put_strdup_full(s, &dns_name_hash_ops_free, ndisc_dnssl_domain(a));
                         if (r < 0)
                                 return r;
                 }