[Xorp-hackers] Is localhost IPv4 or IPv6?

Mark Handley M.Handley at cs.ucl.ac.uk
Wed Aug 16 03:52:57 PDT 2006


I'm getting random test failures on MacOS 10.4.7 (intel):

Entering ./test_peering1.sh   -l -t test34^M
local_config 65008 192.150.187.78^M
register_rib^M
add_peer localhost 10001 localhost 20001 65008 192.150.187.78 30^M
[ 2006/08/16 11:12:11  WARNING xorp_bgp:3089 XrlBgpTarget +478 bgp_base.cc hand\
le_bgp_0_2_add_peer ] Handling method for bgp/0.2/add_peer failed: XrlCmdError \
102 Command failed AddressFamilyMismatch from line 61 of iptuple.cc: mismatch l\
ocalhost localhost^M
[ 2006/08/16 11:12:11  ERROR call_xrl:3098 XRL +59 call_xrl.cc response_handler\
 ] Failed.  Reason: 102 Command failed AddressFamilyMismatch from line 61 of ip\
tuple.cc: mismatch localhost localhost ("finder://bgp/bgp/0.2/add_peer?local_ip\
:txt=localhost&local_port:u32=10001&peer_ip:txt=localhost&peer_port:u32=20001&a\
s:u32=65008&next_hop:ipv4=192.150.187.78&holdtime:u32=30")^M
./test_peering1.sh: Tests Failed^M
SIGTERM received. Exiting.^M
./test_peering1.sh: Tests Failed^M
./test_peering1.sh: Tests Failed^M
FAIL: test_peering1.sh^M


Seemed very odd.  The AF of localhost is not the same as the AF of
localhost.  I can't reproduce this error by running test34 by itself -
I only saw it in the middle of the entire test suite.  It's not always
the same test that fails either, I've also seen test12 fail.

I instrumented the code, and it turns out that AF for _local_sock is
30 (IPv6) and AF for _peer_sock is 2 (IPv4) in the particular case I
observed, although both are specified as simply "localhost".

So, under some circumstances MacOS decides to default to IPv6 for the
IP address for "localhost" if you don't specify the AF.  This is
presumably reasonable, as the default /etc/hosts file contains:

##
# Host Database
#
# localhost is used to configure the loopback interface
# when the system is booting.  Do not change this entry.
##
127.0.0.1       localhost
255.255.255.255 broadcasthost
::1             localhost

I don't understand what the circumstances are where it chooses IPv4 vs
IPv6, but it seems like perhaps we should not be specifying localhost
by name in the test suite, but by IP address instead.

 - Mark



More information about the Xorp-hackers mailing list