Discussion:
gethostbyname(3) doesn't appear to work under NetBSD-5.2 and NetBSD-6.1.x when hostnames appear only in /etc/hosts
Brian Buhrow
2014-06-19 08:37:44 UTC
Permalink
hello. It appears that gethostbyname(3) in NetBSD-5.2 and 6.1.x is
broken if the name you're trying to fetch is listed in /etc/hosts and
nowhere else. The problem appears to be with this change:


RCS file: /cvsroot/src/lib/libc/net/gethnamaddr.c

revision 1.73.18.3
date: 2013-12-23 23:12:44 +0000; author: riz; state: Exp; lines: +10 -7; commitid: QLuYhA2iZpQzpjix;
Apply patch (requested by bad in ticket #1887):

src/lib/libc/net/getaddrinfo.c r1.106:
this is supposed to be re-entrant, call don't call __hostalias that uses
a static buffer.

src/lib/libc/net/gethnamaddr.c r1.85:
- don't clobber hp in the RES_USE_INET6 case
- increment naddrs in the yp case
- don't use __hostalias(), it is not thread-safe.

This should finish addressing PR lib/46454
----------------------------

Here are some scripts that demonstrate the problem. Note I've only shown
the issue under NetbSD-5.1 and 5.2, but NetBSD-6.1.x exhibits the
NetBSD-5.2 broken behavior.

good script started on Wed Jun 18 23:35:48 2014
stats# uname -a
NetBSD stats 5.1_STABLE NetBSD 5.1_STABLE (X2200) #0: Mon Mar 18 11:05:41 PDT 2013 ***@lothlorien.nfbcal.org:/usr/src/sys/arch/i386/compile/X2200 i386
stats# ident /lib/libc.so.12.164 |grep 'gethnamaddr'
$NetBSD: gethnamaddr.c,v 1.73 2007/01/27 22:27:35 christos Exp $
stats# cat /etc/hosts |tail -1
192.168.3.1 this_host_only_in_etc_hosts.via.net this_host_only_in_etc_hosts
stats# getent hosts this_host_only_in_etc_hosts
192.168.3.1 this_host_only_in_etc_hosts.via.net this_host_only_in_etc_hosts
stats# exit

bad script started on Wed Jun 18 23:38:58 2014
mirkwood#
mirkwood# uname -a
NetBSD mirkwood.nfbcal.org 5.2_STABLE NetBSD 5.2_STABLE (RBL) #0: Mon Mar 24 21:42:05 PDT 2014 ***@lothlorien.nfbcal.org:/usr/src/sys/arch/i386/compile/RBL i386
mirkwood# ident /lib/libc.so.12.164 |grep 'gethnamaddr'
$NetBSD: gethnamaddr.c,v 1.73.18.3 2013/12/23 23:12:44 riz Exp $
mirkwood# cat /etc/hosts |tail -1
192.168.3.1 this_host_only_in_etc_hosts.via.net this_host_only_in_etc_hosts
mirkwood# getent hosts this_host_only_in_etc_hosts
mirkwood# exit


I'm not familiar enough with the libc resolver code to feel confident
enough to make a commitable fix. Has anyone else run into this behavior?
Even better, has anyone found a fix?
-thanks
-brian
J. Lewis Muir
2014-06-19 18:58:27 UTC
Permalink
Post by Brian Buhrow
Has anyone else run into this behavior?
Hi, Brian.

I do not have that problem on my system:

===
$ uname -a
NetBSD violin.my.domain 6.1.4 NetBSD 6.1.4 (GENERIC) amd64
$ grep piano /etc/hosts
192.168.98.1 piano.my.domain piano
$ getent hosts piano
192.168.98.1 piano.my.domain piano
===

I have not built a custom kernel, and I have not built the base system
from source. Everything is from the install ISO or NetBSD build
tarballs.

Lewis
Martin Husemann
2014-06-19 19:18:01 UTC
Permalink
I can reproduce it both on netbsd-6 as well as on -current when using
names that are not in DNS.

Martin
Martin Husemann
2014-06-19 19:19:10 UTC
Permalink
Post by Martin Husemann
I can reproduce it both on netbsd-6 as well as on -current when using
names that are not in DNS.
Actually I can *ONLY* reproduce it with IPv6 entries, v4 ones work fine.

Martin
J. Lewis Muir
2014-06-19 19:27:09 UTC
Permalink
Post by Martin Husemann
Post by Martin Husemann
I can reproduce it both on netbsd-6 as well as on -current when using
names that are not in DNS.
Actually I can *ONLY* reproduce it with IPv6 entries, v4 ones work fine.
The only IPv6 entry in my /etc/hosts is the loopback entry:

===
::1 localhost localhost.
===

Lewis
Brian Buhrow
2014-06-19 20:00:51 UTC
Permalink
On Jun 19, 9:19pm, Martin Husemann wrote:
} Subject: Re: gethostbyname(3) doesn't appear to work under NetBSD-5.2 and
} On Thu, Jun 19, 2014 at 09:18:01PM +0200, Martin Husemann wrote:
} > On Thu, Jun 19, 2014 at 01:58:27PM -0500, J. Lewis Muir wrote:
} > > I do not have that problem on my system:
} >
} > I can reproduce it both on netbsd-6 as well as on -current when using
} > names that are not in DNS.
}
} Actually I can *ONLY* reproduce it with IPv6 entries, v4 ones work fine.
}
Hello. If you turn off dns resolution for the hosts database in
nsswitch.conf, can you reproduce it for both ipv4 and ipv6 entries? I see
it for both on NetBSD-5.2, as I outlined in the bug report, and it looks
like the same problem exists in netbsd-6 and -current.

-thanks
-Brian
Martin Husemann
2014-06-19 20:07:53 UTC
Permalink
Post by Brian Buhrow
Hello. If you turn off dns resolution for the hosts database in
nsswitch.conf, can you reproduce it for both ipv4 and ipv6 entries?
No, IPv4 entries work for me in -current with "hosts: files" too.

Martin
Brian Buhrow
2014-06-19 21:09:43 UTC
Permalink
On Jun 19, 10:07pm, Martin Husemann wrote:
} Subject: Re: gethostbyname(3) doesn't appear to work under NetBSD-5.2 and
} On Thu, Jun 19, 2014 at 01:00:51PM -0700, Brian Buhrow wrote:
} > Hello. If you turn off dns resolution for the hosts database in
} > nsswitch.conf, can you reproduce it for both ipv4 and ipv6 entries?
}
} No, IPv4 entries work for me in -current with "hosts: files" too.
}
} Martin
Hello. Interesting... Ok, I didn't have a chance to test on a
-current system. Still, I think gethostbyname() and gethostbyname2() are
pretty broken when used with NetBSD-5.2 and netbsd-6 with any entries that
don't appear in dns and only appear in /etc/hosts.
Interestingly enough, getaddrinfo(3) seems to do the right thing when
presented with the same scenario. As a quick test, try turning off dns
resolution in nsswitch.conf and then using telnet, which uses
getaddrinfo(3) to do its resolution, to get to your ipv6 host that only
shows up in /etc/hosts. My guess is that you'll get resolution while
getent(1) against the same host will give you nothing.
A bit more experimentation shows that getent(1) against the hosts
database hasn't worked for IPV6 hosts since at least NetBSD-3.0. However,
IPV4 hosts work fine and getaddrinfo(3) works fine for both IPV4 and IPV6
hosts in NetBSD-3. Getaddrinfo(3) works fine for IPV4 hosts in NetBSD-5.1,
but doesn't work for IPV6 hosts. Getent(1), which uses gethostbyname(3)
works for IPV4 hosts on NetBSD-5.1 but doesn't work for IPV6 hosts.
So, to summarize, the thing that's changed, and in my view, broken,
between NetBSD-5.1 and NetBSD-5.2 is that gethostbyname and
gethostbyname2 no longer work on IPV4 hosts when those hostnames appear in
/etc/hosts and not DNS. IPV6 has probably never worked with this scenario
and while this is undoubtedly a bug, it's so long outstanding that I don't
think anyone will trip over it. Getaddrinfo(3) has also suffered a bit
from NetBSD-3 to NetBSD-5, but again, only with IPV6 hosts, so it's
probably not so bad. Clearly, this code is in need of a complete
overhaul, but the value probably isn't worth the effort. since ktrace
shows the file /etc/hosts gets read even when things don't work, it is probably
a simple logic bug that got introduced when the NetBSD-5 files were
patched. I'll see if I can figure that one out.
If it's any consolation, FreeBSD-9.2 has the same issue with IPV6
entries as we do. That is, neither gethostbyname, hostbyname2 or
getaddrinfo can retrieve IPV6 entries if they appear only in the /etc/hosts
file.

-thanks
-Brian

Eric Schnoebelen
2014-06-19 19:48:49 UTC
Permalink
Brian Buhrow writes:
- hello. It appears that gethostbyname(3) in NetBSD-5.2 and 6.1.x is
- broken if the name you're trying to fetch is listed in /etc/hosts and
- nowhere else. The problem appears to be with this change:

I'm unable to reproduce on "6.1_STABLE amd64".

One thing you've not provided is your nsswitch.conf file, it
controls how getent(1) behaves.
egsner-> grep sillyhost.cirr.com /etc/hosts
192.168.10.1 sillyhost.cirr.com sillyhost
egsner-> host sillyhost.cirr.com
Host sillyhost.cirr.com not found: 3(NXDOMAIN)
egsner-> getent hosts sillyhost.cirr.com
192.168.10.1 sillyhost.cirr.com sillyhost
egsner-> grep host /etc/nsswitch.con
hosts: files dns
# hosts: dns, files, nis, mdnsd, multicast_dns


If your nsswitch has "dns files", you may want a "[notfound=continue]"
clause between "dns" and "files" (although that is supposed to
be the default.)

I might postulate your configuration has an nsswitch.conf file
with only "dns" in it?

--
Eric Schnoebelen ***@cirr.com http://www.cirr.com
Loading...