getaddrinfo and AI_PASSIVE is broken for net.ipv6.bindv6only=0
When calling getaddrinfo and specifying AF_UNSPEC and AI_PASSIVE it returns both IPv4 and IPv6 addresses when the sysctl net.ipv6.bindv6only = 0. Proper app behavior for AI_PASSIVE should be to bind and listen to all returned addresses, but the kernel does not allow binding to a V4 and V6 address with the same port. In this case getaddrinfo should return only a IPv4 or only a IPv6 address.
Illustrated with python because I'm lazy:
>>> resx = socket.
>>> print resx
[(2, 1, 6, '', ('0.0.0.0', 1234)), (10, 1, 6, '', ('::', 1234, 0, 0))]
>>> res = resx
>>> fd = socket.
>>> res = resx
>>> fd2 = socket.
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "<string>", line 1, in bind
socket.error: [Errno 98] Address already in use
At least in earlier Ubuntu releases this case returned the IPv6 address first, so most apps which don't properly use all addresses 'worked' but it was still wrong to return both addresses. The new behavior breaks IPv6 in various cases, with no possible app work-around!
Apps should not be expected to 'sense' if the system is bindv6only. getaddrinfo AF_UNSPEC/
At a minimum the old sorting behavior of putting v6 first should be restored! Real apps depend on this!
I've noted various other bugs in this same theme:
So here is one for Ubuntu with a bit more clarity on the exact problem.
DistroRelease: Ubuntu 10.10
Package: libc6 2.12.1-0ubuntu8
Uname: Linux 2.6.35-22-generic x86_64
Date: Wed Nov 10 12:52:08 2010
InstallationMedia: Ubuntu 10.10 "Maverick Meerkat" - Release amd64 (20101007)
PATH=(custom, no user)