diff options
author | Wolfgang Bumiller <w.bumiller@proxmox.com> | 2015-05-21 14:33:29 +0200 |
---|---|---|
committer | Michael Tokarev <mjt@tls.msk.ru> | 2015-06-23 20:23:39 +0300 |
commit | 3de3d698d942d1116152417f882c897b26b44e41 (patch) | |
tree | 074a9987baf053a03d1ae261142e078166d670c9 /util | |
parent | 8684e85ca911b41d6a82ac5bcc5a0bfaba5eb7da (diff) | |
download | qemu-3de3d698d942d1116152417f882c897b26b44e41.zip qemu-3de3d698d942d1116152417f882c897b26b44e41.tar.gz qemu-3de3d698d942d1116152417f882c897b26b44e41.tar.bz2 |
util/qemu-sockets: improve ai_flag hints for ipv6 hosts
*) Do not use AI_ADDRCONFIG on listening sockets, because this flag
makes it impossible to explicitly listen on '127.0.0.1' if no global
ipv4 address is configured additionally, making this a very
uncomfortable option.
*) Add AI_V4MAPPED hint for connecting sockets.
If your system is globally only connected via ipv6 you often still want
to be able to use '127.0.0.1' and 'localhost' (even if localhost doesn't
also have an ipv6 entry).
For example, PVE - unless explicitly asking for insecure mode - uses
ipv4 loopback addresses with QEMU for live migrations tunneled over SSH.
These fail to start because AI_ADDRCONFIG makes getaddrinfo refuse to
work with '127.0.0.1'.
As for the AI_V4MAPPED flag: glibc uses it by default, and providing
non-0 flags removes it. I think it makes sense to use it.
I also want to point out that glibc explicitly sidesteps POSIX standards
when passing 0 as hints by then assuming both AI_V4MAPPED and
AI_ADDRCONFIG (the latter being a rather weird choice IMO), while
according to POSIX.1-2001 it should be assumed 0. (glibc considers its
choice an improvement.)
Since either AI_CANONNAME or AI_PASSIVE are passed in our cases, glibc's
default flags in turn are disabled again unless explicitly added, which
I do with this patch.
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
Signed-off-by: Michael Tokarev <mjt@tls.msk.ru>
Diffstat (limited to 'util')
-rw-r--r-- | util/qemu-sockets.c | 9 |
1 files changed, 6 insertions, 3 deletions
diff --git a/util/qemu-sockets.c b/util/qemu-sockets.c index 4026314..2add83a 100644 --- a/util/qemu-sockets.c +++ b/util/qemu-sockets.c @@ -29,6 +29,9 @@ #ifndef AI_ADDRCONFIG # define AI_ADDRCONFIG 0 #endif +#ifndef AI_V4MAPPED +# define AI_V4MAPPED 0 +#endif /* used temporarily until all users are converted to QemuOpts */ QemuOptsList socket_optslist = { @@ -118,7 +121,7 @@ int inet_listen_opts(QemuOpts *opts, int port_offset, Error **errp) int slisten, rc, to, port_min, port_max, p; memset(&ai,0, sizeof(ai)); - ai.ai_flags = AI_PASSIVE | AI_ADDRCONFIG; + ai.ai_flags = AI_PASSIVE; ai.ai_family = PF_UNSPEC; ai.ai_socktype = SOCK_STREAM; @@ -335,7 +338,7 @@ static struct addrinfo *inet_parse_connect_opts(QemuOpts *opts, Error **errp) memset(&ai, 0, sizeof(ai)); - ai.ai_flags = AI_CANONNAME | AI_ADDRCONFIG; + ai.ai_flags = AI_CANONNAME | AI_V4MAPPED | AI_ADDRCONFIG; ai.ai_family = PF_UNSPEC; ai.ai_socktype = SOCK_STREAM; @@ -435,7 +438,7 @@ int inet_dgram_opts(QemuOpts *opts, Error **errp) /* lookup peer addr */ memset(&ai,0, sizeof(ai)); - ai.ai_flags = AI_CANONNAME | AI_ADDRCONFIG; + ai.ai_flags = AI_CANONNAME | AI_V4MAPPED | AI_ADDRCONFIG; ai.ai_family = PF_UNSPEC; ai.ai_socktype = SOCK_DGRAM; |