This is the mail archive of the libc-alpha@sources.redhat.com mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

getaddrinfo with PF_UNSPEC and /etc/hosts


Hello all,

It was pointed out by Rafal Wojtczuk on Owl development list that telnet
that ships with Red Hat Linux 7.2 does not behave the way one would expect
when resolving names using /etc/hosts.  That is, if you have:

nsswitch.conf:
--8<--
hosts:      files nisplus nis dns
--8<--

host.conf:
--8<--
order hosts,bind
--8<--

hosts:
--8<--
[snip]
192.168.1.100	netcore.home
--8<--

and you 'telnet netcore.home', there will be a DNS lookup for AAAA address 
of netcore.home.

On BSD's, this will not be done, and the IPv4 address is taken even though 
there might be IPv6 capability in the system.

If you change /etc/hosts to be like:
--8<--
[snip]
192.168.1.100   netcore.home
3ffe:ffff::1	netcore.home
--8<--
the lookup can be avoided.

This appears to be due to getaddrinfo implementation.

A code fragment from RHL72 telnet that brings up this issue (code is from 
OpenBSD telnet client):
--8<--
        hostname = hostp;
  	memset(&hints, 0, sizeof(hints));
        hints.ai_family = PF_UNSPEC;
        hints.ai_socktype = SOCK_STREAM;
  	  hints.ai_flags = 0;
  	if (portp == NULL) {
                portp = "telnet";
                telnetport = 1;
  	  } else if (*portp == '-') {
  	          portp++;
  		telnetport = 1;
        }
        h_errno = 0;
        error = getaddrinfo(hostp, portp, &hints, &res0);
        if (error) {
            if (error == EAI_SERVICE)
                warnx("%s: bad port", portp);
            else		 
                warnx("%s: %s", hostp, gai_strerror(error));
           if (h_errno)		 
                herror(hostp);   
           return 0;		 
        }
--8<--

A few items that may be interesting:

 - with ai.hints = AF_INET this works without lookups (natural)
 - whether IPv6 is enabled (ie. module loaded in kernel) makes no difference
 - BSD getaddrinfo avoids lookups

One could argue both ways whether this would have to fixed and at what 
priority:

 - if you add hosts to /etc/hosts, one would expect you'd only want to 
reach them via the addresses you entered them with, unless otherwise 
specified (ie: e.g. accept IPv4 if in /etc/hosts, don't loop up for IPv6)
This is what BSD does.

 - even though you add hosts /etc/hosts, you might still want to try other 
protocols, e.g. IPv6.  This is very problematic if /etc/hosts doesn't have 
both IPv4 and IPv6 entry for every name.  E.g. if connectivity is down adn 
there is no loopback-ip6 entry, there would be DNS AAAA queries for 
loopback.

IMO, this is a rather important issue as getddrinfo and friends are 
getting more and more used due to their AF-independent nature.

Hope this helps.

-- 
Pekka Savola                 "Tell me of difficulties surmounted,
Netcore Oy                   not those you stumble over and fall"
Systems. Networks. Security.  -- Robert Jordan: A Crown of Swords






Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]