[Qemu-devel] [PATCH 4/4] qemu-sockets: do not require configured ipv4/ipv6 address

Marc-André Lureau posted 4 patches 6 years, 5 months ago
Maintainers: "Alex Bennée" <alex.bennee@linaro.org>, "Daniel P. Berrangé" <berrange@redhat.com>, Gerd Hoffmann <kraxel@redhat.com>, Fam Zheng <fam@euphon.net>, "Philippe Mathieu-Daudé" <philmd@redhat.com>
There is a newer version of this series
[Qemu-devel] [PATCH 4/4] qemu-sockets: do not require configured ipv4/ipv6 address
Posted by Marc-André Lureau 6 years, 5 months ago
podman containers without network don't have ipv4/ipv6 addresses other
than loopback address. However, some of our tests require
getaddrinfo("127.0.0.1") to succeed.

Alternatively, we may want to treat 127.0.0.1 as a special case, to
keep the AI_ADDRCONFIG convenience.

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
---
 util/qemu-sockets.c | 8 ++------
 1 file changed, 2 insertions(+), 6 deletions(-)

diff --git a/util/qemu-sockets.c b/util/qemu-sockets.c
index 8850a280a8..f9c1392a05 100644
--- a/util/qemu-sockets.c
+++ b/util/qemu-sockets.c
@@ -31,10 +31,6 @@
 #include "qapi/qobject-output-visitor.h"
 #include "qemu/cutils.h"
 
-#ifndef AI_ADDRCONFIG
-# define AI_ADDRCONFIG 0
-#endif
-
 #ifndef AI_V4MAPPED
 # define AI_V4MAPPED 0
 #endif
@@ -385,7 +381,7 @@ static struct addrinfo *inet_parse_connect_saddr(InetSocketAddress *saddr,
 
     memset(&ai, 0, sizeof(ai));
 
-    ai.ai_flags = AI_CANONNAME | AI_ADDRCONFIG;
+    ai.ai_flags = AI_CANONNAME;
     if (atomic_read(&useV4Mapped)) {
         ai.ai_flags |= AI_V4MAPPED;
     }
@@ -472,7 +468,7 @@ static int inet_dgram_saddr(InetSocketAddress *sraddr,
 
     /* lookup peer addr */
     memset(&ai,0, sizeof(ai));
-    ai.ai_flags = AI_CANONNAME | AI_V4MAPPED | AI_ADDRCONFIG;
+    ai.ai_flags = AI_CANONNAME | AI_V4MAPPED;
     ai.ai_family = inet_ai_family_from_address(sraddr, &err);
     ai.ai_socktype = SOCK_DGRAM;
 
-- 
2.22.0.rc1.1.g079e7d2849.dirty


Re: [Qemu-devel] [PATCH 4/4] qemu-sockets: do not require configured ipv4/ipv6 address
Posted by Daniel P. Berrangé 6 years, 5 months ago
On Fri, May 24, 2019 at 01:40:11AM +0200, Marc-André Lureau wrote:
> podman containers without network don't have ipv4/ipv6 addresses other
> than loopback address. However, some of our tests require
> getaddrinfo("127.0.0.1") to succeed.
> 
> Alternatively, we may want to treat 127.0.0.1 as a special case, to
> keep the AI_ADDRCONFIG convenience.

Keeping AI_ADDRCONFIG is mandatory as this is required for correctly
operating IPv4/IPv6 dual stack support.

In tests/socket-helpers.h I have a couple of APIs designed to help
in this case.

  int socket_can_bind_connect(const char *hostname);
  int socket_check_protocol_support(bool *has_ipv4, bool *has_ipv6);

The latter function just calls the former with "127.0.0.1" and
"::1" and reports results =.

The intention is that any test which relies on using getaddrinfo()
should call one of these functions, and then skip any tests which
have a dependancy on this working.

We certainly don't do these checks it all our tests right now
though, so it is not surprising if some fail.


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 :|