Subject: IPv4-mapped IPv6 IP bind()ing problems...
To: None <tech-net@netbsd.org>
From: icmps <icmp@icmps.org>
List: tech-net
Date: 03/06/2003 16:42:20
Hey, recently I have had trouble with a simple IPv6 program
(http://65.243.82.153/test.c) to bind a local IPv4-mapped IPv6 address
(::ffff:127.0.0.1).  The problem is that it returns EADDRNOTAVAIL
regardless of whether the v6only sysctl is 1 or 0 (I always change it to
0...).  I tested the program on other boxes... older -current, 1.5
-current and 1.6_STABLE (mine, w/ a kernel from ~january 03 sources) and
they all exhibit the exact same behavior.

Of course, ::ffff:127.0.0.1 w/o a port (basically to use IPv4 over
AF_INET6, it works on Linux & FreeBSD so reasonably I expected it to
work on NetBSD too) would/should always be available... is this wrong?

I looked through the mailing lists and saw a similar problem @ 
http://mail-index.netbsd.org/current-users/2002/11/05/0006.html

So, curiously I checked my in6_pcb.c and found that opt_inet.h was NOT
included.... thus omitting an entire section of code which, at least,
makes connect() return EADDRNOTAVAIL, imo, erroneously.  Though,
seemingly this doesn't explain the bind()... I looked in
in6_pcb.c:in6_pcbbind() and see (line 182 in -stable sources):

            /*
             * since we do not check port number duplicate with IPv4
space,
             * we reject it at this moment.  If we leave it, we would
             * mistakenly allow normal users to hijack tcp/udp ports
from
             * other users.
             */
             if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr))
                     return(EADDRNOTAVAIL);

is this the source of my problems? I'm just curious as to why I cannot
bind a IPv4-mapped IPv6 IP since it works fine on other OSes... am I
doing something wrong?

By the way, for the connect() thing above, I figured it was a bug and
filed PR kern/20559 - if this is invalid, feel free to close it.

Thanks,
Icmp