qemu-devel
[Top][All Lists]
Advanced

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

Re: [Qemu-devel] [PATCH] sockets: ensure we can bind to both ipv4 & ipv6


From: Daniel P. Berrange
Subject: Re: [Qemu-devel] [PATCH] sockets: ensure we can bind to both ipv4 & ipv6 separately
Date: Fri, 28 Apr 2017 15:59:21 +0100
User-agent: Mutt/1.7.1 (2016-10-04)

On Fri, Apr 28, 2017 at 09:57:24AM -0500, Eric Blake wrote:
> On 04/28/2017 07:15 AM, Daniel P. Berrange wrote:
> > 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
> 
> At first glance, I thought that was too many :.  But I guess it is
> parsed as host:screen, with host of '::', and port offset of '1'...

Yeah, I was amazed when it actually worked in fact :-) I thought
I was going to have to use {::}:1, but it seems we reverse search
for the last ':'.

> 
> > 
> > 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
> 
> ...and matches this being parsed as host of '' and port offset of '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.
> > 
> > Signed-off-by: Daniel P. Berrange <address@hidden>
> > ---
> >  util/qemu-sockets.c | 30 ++++++++++++++++++++++--------
> >  1 file changed, 22 insertions(+), 8 deletions(-)
> > 
> 
> Reviewed-by: Eric Blake <address@hidden>
> 
> -- 
> Eric Blake, Principal Software Engineer
> Red Hat, Inc.           +1-919-301-3266
> Virtualization:  qemu.org | libvirt.org
> 




Regards,
Daniel
-- 
|: https://berrange.com      -o-    https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org         -o-            https://fstop138.berrange.com :|
|: https://entangle-photo.org    -o-    https://www.instagram.com/dberrange :|



reply via email to

[Prev in Thread] Current Thread [Next in Thread]