[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: broken IPv6 code



In article <[🔎] 84r92orkk8.fsf@snoopy.apana.org.au> (at 31 Dec 2000 20:45:11 +1100), Brian May <bam@debian.org> says:

> socket(PF_INET6, SOCK_STREAM, 6)        = 3
> setsockopt(3, SOL_SOCKET, SO_REUSEADDR, [1], 4) = 0
> bind(3, {sin_family=AF_INET6, sin6_port=htons(8024), inet_pton(AF_INET6, "::", &sin6_addr), sin6_flowinfo=htonl(0)}}, 24) = 0
> listen(3, 128)                          = 0
> socket(PF_INET, SOCK_STREAM, IPPROTO_TCP) = 4
> setsockopt(4, SOL_SOCKET, SO_REUSEADDR, [1], 4) = 0
> bind(4, {sin_family=AF_INET, sin_port=htons(8024), sin_addr=inet_addr("0.0.0.0")}}, 16) = -1 EADDRINUSE (Address already in use)
> write(2, "telnetd: ", 9telnetd: )                = 9
> write(2, "bind", 4bind)                     = 4
> write(2, ": ", 2: )                       = 2
> write(2, "Address already in use\n", 23Address already in use
> ) = 23
> _exit(1)                                = ?
> 
> 
> Debian potato, 2.2.18, and no, port 8024 is not already in use.

8024 is already in use (by ipv6).


> As far as I am aware, this is the standard way of binding both to IPv6
> and IPv4, however, it obvious does not work. It this a kernel bug?  a
> glibc bug? or a bug in the above code?

No, it is not standard.  In fact, there're NO standards.

On RFC 2553 compliance systems, ipv4 communication should go to ipv6
socket in ipv4-mapped manner.  However, bind(2) behavior is not specified,
and is different between systems, such as NetBSD, FreeBSD, Linux and Solaris.
Situation is very complicated and server application must be coded 
carefully.

(Origianl) Linux kernels shere port number between ipv6 and ipv4.
This is not a bug and is expected behavior of (original) Linux kernel.

On USAGI linux24 kernels, you can bind both ipv6 and ipv4 socket to the
same port number by CONFIG_IPV6_DOUBLE_BIND option. 
Its hehavior is like KAME's freebsd3's one.  For example, 
if there's only ipv6-wildcard socket, ipv4 connection will go to ipv6 
socket.  If there're both of ipv6-wildcard and ipv4-wildcard socket, 
it will go to ipv4 socket.

Reference:
 USAGI Project: <http://www.linux-ipv6.org>
 KAME Project:  <http://www.kame.net>

-- 
Hideaki YOSHIFUJI @ USAGI Project  <yoshfuji@linux-ipv6.org>
PGP5i FP: F731 6599 5EB2 BBA7 1515  1323 1806 A96F 5700 6B25 



Reply to: