sockets: ensure we can bind to both ipv4 & ipv6 separately
commit5e059be4c7b75e20c29afb0e03b646864ae93f32
authorDaniel P. Berrange <berrange@redhat.com>
Fri, 28 Apr 2017 12:09:53 +0000 (28 13:09 +0100)
committerDaniel P. Berrange <berrange@redhat.com>
Fri, 14 Jul 2017 13:28:29 +0000 (14 14:28 +0100)
treec808cf8682e4b7f836967cc0a0a77297004245af
parent6c6076662d98c068059983d411cb2a8987ba5670
sockets: ensure we can bind to both ipv4 & ipv6 separately

When binding to an IPv6 socket we currently force the
IPV6_V6ONLY flag to off. This means that the IPv6 socket
will accept both IPv4 & IPv6 sockets when QEMU is launched
with something like

  -vnc :::1

While this is good for that case, it is bad for other
cases. For example if an empty hostname is given,
getaddrinfo resolves it to 2 addresses 0.0.0.0 and ::,
in that order. We will thus bind to 0.0.0.0 first, and
then fail to bind to :: on the same port. The same
problem can happen if any other hostname lookup causes
the IPv4 address to be reported before the IPv6 address.

When we get an IPv6 bind failure, we should re-try the
same port, but with IPV6_V6ONLY turned on again, to
avoid clash with any IPv4 listener.

This ensures that

  -vnc :1

will bind successfully to both 0.0.0.0 and ::, and also
avoid

  -vnc :1,to=2

from mistakenly using a 2nd port for the :: listener.

This is a regression due to commit 396f935 "ui: add ability to
specify multiple VNC listen addresses".

Acked-by: Gerd Hoffmann <kraxel@gmail.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
util/qemu-sockets.c