Binding to "any"

Dag-Erling Smørgrav des at
Mon May 14 16:50:58 CEST 2007

Currently, there is a known issue with varnishd on FreeBSD, where if you
run it with "-a :80" it will only bind to IN6ADDR_ANY instead of both

This is not easy to solve.  The obvious fix, which is to bind to *all*
addresses returned by getaddrinfo() instead of just the first one, will
work on FreeBSD, but not on Linux, where you can't bind to the same port

On Linux, the current behaviour is good enough - binding to either
INADDR_ANY or IN6ADDR_ANY will give you both.

On FreeBSD, if we want both *and* the kernel has IPv6 support compiled
in, we can bind to IN6ADDR_ANY and clear the IPV6_V6ONLY socket option
(it defaults to on).  If the kernel does *not* have IPv6 support
compiled in, getaddrinfo() will still return both INADDR_ANY and
IN6ADDR_ANY, but we binding to IN6ADDR_ANY will fail.

I don't see any good way out of this mess - we're pretty much forced to
special-case the "any" case.

I've looked at other network servers, such as Apache and OpenSSH, and
they pretty much universally solve (or rather avoid) this issue by
explicitly specifying either (INADDR_ANY) or :: (IN6ADDR_ANY) as
the default listening address.

Dag-Erling Smørgrav
Senior Software Developer
Linpro AS -

More information about the varnish-dev mailing list