r5259: make sure we give the ip of the interface that a name query comes in
authorAndrew Tridgell <tridge@samba.org>
Mon, 7 Feb 2005 11:49:55 +0000 (11:49 +0000)
committerGerald (Jerry) Carter <jerry@samba.org>
Wed, 10 Oct 2007 18:09:35 +0000 (13:09 -0500)
on as the first IP in a multi-homed reply
(This used to be commit a9128f6544d56a637e28430cbd2907acbb978281)

source4/nbt_server/interfaces.c
source4/nbt_server/query.c
source4/nbt_server/winsclient.c

index b99c17089cb878b71a497a18c0e9d2eff7921ffb..a75275dec7b60e40b0314ebfeb3ebeaa53542c92 100644 (file)
@@ -234,18 +234,35 @@ NTSTATUS nbtd_startup_interfaces(struct nbtd_server *nbtsrv)
 
 /*
   form a list of addresses that we should use in name query replies
+  we always place the IP in the given interface first
 */
-const char **nbtd_address_list(struct nbtd_server *nbtsrv, TALLOC_CTX *mem_ctx)
+const char **nbtd_address_list(struct nbtd_interface *iface, TALLOC_CTX *mem_ctx)
 {
+       struct nbtd_server *nbtsrv = iface->nbtsrv;
        const char **ret = NULL;
-       struct nbtd_interface *iface;
-       int count = 0;
+       struct nbtd_interface *iface2;
+       int count;
+
+       ret = talloc_array(mem_ctx, const char *, 2);
+       if (ret == NULL) goto failed;
+
+       ret[0] = talloc_strdup(ret, iface->ip_address);
+       if (ret[0] == NULL) goto failed;
+       ret[1] = NULL;
+
+       count = 1;
+
+       for (iface2=nbtsrv->interfaces;iface2;iface2=iface2->next) {
+               const char **ret2;
+
+               if (strcmp(iface2->ip_address, iface->ip_address) == 0) {
+                       continue;
+               }
 
-       for (iface=nbtsrv->interfaces;iface;iface=iface->next) {
-               const char **ret2 = talloc_realloc(mem_ctx, ret, const char *, count+2);
+               ret2 = talloc_realloc(mem_ctx, ret, const char *, count+2);
                if (ret2 == NULL) goto failed;
                ret = ret2;
-               ret[count] = talloc_strdup(ret, iface->ip_address);
+               ret[count] = talloc_strdup(ret, iface2->ip_address);
                if (ret[count] == NULL) goto failed;
                count++;
        }
index 80ea3d6ab818dd82270a425e092820850865d386..28406081eaf8ec4c5ca93c28f1d3e810fc699298 100644 (file)
@@ -129,5 +129,5 @@ void nbtd_request_query(struct nbt_name_socket *nbtsock,
 
        nbtd_name_query_reply(nbtsock, packet, src_address, src_port,
                              &iname->name, iname->ttl, iname->nb_flags, 
-                             nbtd_address_list(iface->nbtsrv, packet));
+                             nbtd_address_list(iface, packet));
 }
index 572d46ba4bfb5b697e816380ea34ea95782842b4..80168c9181fd07cb35316ce05f048b2e18caebed 100644 (file)
@@ -107,7 +107,7 @@ void nbtd_winsclient_refresh(struct nbtd_iface_name *iname)
        /* setup a wins name refresh request */
        io.in.name            = iname->name;
        io.in.wins_servers    = lp_wins_server_list();
-       io.in.addresses       = nbtd_address_list(iface->nbtsrv, iname);
+       io.in.addresses       = nbtd_address_list(iface, iname);
        io.in.nb_flags        = iname->nb_flags;
        io.in.ttl             = iname->ttl;