I've discovered a related problem in the file_lookup() function. To
reproduce, add the following to /etc/hosts:
192.0.2.1 v4-host.googleapis.com
2001:db8::1 v6-host.googleapis.com
(I'm using *.googleapis.com because it's a wildcard.)
$ for x in aaaa a; do ./ahost -t $x v4-host.googleapis.com; done
googleapis.l.google.com 2607:f8b0:4001:c1b::5f
v4-host.googleapis.com 192.0.2.1
$ for x in aaaa a; do ./ahost -t $x v6-host.googleapis.com; done
v6-host.googleapis.com 2001:db8::1
googleapis.l.google.com 74.125.201.95
Notice that instead of stopping at an IPv4-only or IPv6-only
/etc/hosts entry, the opposite family "pokes through" and issues a
real DNS query.
Here is glibc's behavior, for comparison:
$ python -c 'import socket;
print(socket.getaddrinfo("v4-host.googleapis.com", 80, 0, 0,
socket.IPPROTO_TCP))'
[(2, 1, 6, '', ('192.0.2.1', 80))]
$ python -c 'import socket;
print(socket.getaddrinfo("v6-host.googleapis.com", 80, 0, 0,
socket.IPPROTO_TCP))'
[(10, 1, 6, '', ('2001:db8::1', 80, 0, 0))]
Again, I see three possible resolutions:
(1) Declare this behavior a bug, and fix it.
(2) Document this behavior as intentional.
(3) Make it a configuration option.
I'm happy to send patches, but first we need consensus on which
approach to take.
Received on 2015-05-21