nmbd uses only first IP address even when more are returned by DNS

bernd.casimir at daimlerchrysler.com bernd.casimir at daimlerchrysler.com
Thu Oct 16 07:19:47 GMT 2003


Hi,
to get rid of the inconsistency problems between WINS and DNS we modified
the SAMBA nmbd
to use DNS as the only source to respond to WINS name queries
(WINS-to-DNS-Proxy).
To be able to respond to domain controller queries we added some lines of
code that adds
"-PDC" to the DNS query when a client requests a name with type "1B" and "
-DC" if it is type "1C".

Unfortunately nmbd uses only the first IP address of the DNS response -
even when several
domain controllers are reported by DNS.

The reason for this behaviour is the function "interpret_addr" (defined in
lib/util.c) called by asyncdns_process
and queue_dns_query (both defined in nmbd/asyncdns.c) which uses h_addr
from "gethostbyname"
and not the complete list (h_addr_list):

struct hostent {
   char    *h_name;        /* official name of host */
   char    **h_aliases;    /* alias list */
   int     h_addrtype;     /* host address type */
   int     h_length;       /* length of address */
   char    **h_addr_list;  /* list of addresses */
}
#define h_addr  h_addr_list[0]  /* for backward compatibility */


uint32 interpret_addr(const char *str)
{
        struct hostent *hp;
        uint32 res;

        if (strcmp(str,"0.0.0.0") == 0)
                return(0);
        if (strcmp(str,"255.255.255.255") == 0)
                return(0xFFFFFFFF);

  /* if it's in the form of an IP address then get the lib to interpret it
*/
        if (is_ipaddress(str)) {
                res = inet_addr(str);
        } else {
                /* otherwise assume it's a network name of some sort and
use
                        sys_gethostbyname */
                if ((hp = sys_gethostbyname(str)) == 0) {
                        DEBUG(3,("sys_gethostbyname: Unknown host.
%s\n",str));
                        return 0;
                }

                if(hp->h_addr == NULL) {
                        DEBUG(3,("sys_gethostbyname: host address is
invalid for host %s\n",str));
                        return 0;
                }
                putip((char *)&res,(char *)hp->h_addr);
        }

        if (res == (uint32)-1)
                return(0);

        return(res);
}



Do you think this can be modified in a later version of samba?

Over 30.000 productive clients are running very fine with this solution.
The only drawback is that there must be a memory leak in nmbd as the used
memory
increases from hour to hour and we have to restart nmbd every night...

PS: If you are interested in the modifications for a WINS-to-DNS-Proxy I
can post the diffs...

Thanks,
Bernd






More information about the samba-technical mailing list