]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
lib/addns: Prepare for multiple IPs per NS record
authorVolker Lendecke <vl@samba.org>
Sun, 3 May 2026 07:56:11 +0000 (09:56 +0200)
committerVolker Lendecke <vl@samba.org>
Fri, 3 Jul 2026 08:08:36 +0000 (08:08 +0000)
struct dns_rr_srv for SRV records already supports multiple
IPs. Prepare for the same with NS records. No changes in the callers
required, nobody looks at that yet.

Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Stefan Metzmacher <metze@samba.org>
lib/addns/dnsquery.c
libcli/dns/dns.h

index 55ba5a68d392722baae654918f902e0c73b9f956..b0c7b40275bd1247583d89a2c867488ace89b531 100644 (file)
@@ -231,6 +231,40 @@ fail:
        return status;
 }
 
+static bool ads_dns_add_ns_ip(struct dns_rr_ns *nss,
+                             size_t num_nss,
+                             const char *hostname,
+                             const struct samba_sockaddr *addr)
+{
+       size_t i;
+
+       for (i = 0; i < num_nss; i++) {
+               struct dns_rr_ns *ns = &nss[i];
+               size_t num_ips = talloc_array_length(ns->ss_s);
+               struct samba_sockaddr *tmp = NULL;
+
+               if (!strequal(ns->hostname, hostname)) {
+                       continue;
+               }
+
+               if (num_ips == SIZE_MAX) {
+                       continue;
+               }
+
+               tmp = talloc_realloc(nss,
+                                    ns->ss_s,
+                                    struct samba_sockaddr,
+                                    num_ips + 1);
+               if (tmp == NULL) {
+                       return false;
+               }
+               ns->ss_s = tmp;
+               ns->ss_s[num_ips] = *addr;
+       }
+
+       return true;
+}
+
 struct ads_dns_lookup_ns_state {
        struct dns_rr_ns *nss;
        size_t num_nss;
@@ -308,19 +342,19 @@ static void ads_dns_lookup_ns_done(struct tevent_req *subreq)
                struct dns_res_rec *ar = &reply->additional[i];
                struct samba_sockaddr addr = {};
                bool ok;
-               size_t j;
 
                ok = dns_res_rec_get_sockaddr(ar, &addr);
                if (!ok) {
                        continue;
                }
 
-               for (j=0; j<state->num_nss; j++) {
-                       struct dns_rr_ns *ns = &state->nss[j];
-
-                       if (strequal(ns->hostname, ar->name)) {
-                               ns->ss = addr.u.ss;
-                       }
+               ok = ads_dns_add_ns_ip(state->nss,
+                                      state->num_nss,
+                                      ar->name,
+                                      &addr);
+               if (!ok) {
+                       tevent_req_oom(req);
+                       return;
                }
        }
 
index 6e5b888d6570ea707ab440845e918bf760b2b584..e2f25be4976a90183a3b65226fb4d03b3a33d299 100644 (file)
@@ -58,7 +58,7 @@ struct dns_rr_srv {
 
 struct dns_rr_ns {
        const char *hostname;
-       struct sockaddr_storage ss;
+       struct samba_sockaddr *ss_s; /* support multi-homed hosts */
 };
 
 #endif