]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
virNetSocketCheckProtocols: Confirm IPv4 by lookup too
authorMichal Privoznik <mprivozn@redhat.com>
Wed, 15 Jul 2020 11:48:46 +0000 (13:48 +0200)
committerMichal Privoznik <mprivozn@redhat.com>
Thu, 16 Jul 2020 10:19:31 +0000 (12:19 +0200)
Historically, if we found an interface with an IPv6 address we
did not blindly trust that host is IPv6 capable (as in we can
successfully translate IPv4 addresses) but used getaddrinfo() to
confirm it. Turns out, we have use the same argument for IPv4.
For instance, in an namespace created by the following steps,
getaddrinfo("127.0.0.1", ...) fails (demonstrating by "Socket
TCP/IPv4 Accept" test case failing in virnetsockettest):

  unshare -n
  ip link set lo up
  ip link add dummy0 type dummy
  ip link set dummy0 up

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
src/rpc/virnetsocket.c

index 2edd2a21d63b5ac6b910a0403841f944c1b1e70a..45dcf48206eb61127440ef0f0e37eb10ef7c33e6 100644 (file)
@@ -205,6 +205,9 @@ int virNetSocketCheckProtocols(bool *hasIPv4,
 
     freeifaddrs(ifaddr);
 
+    if (hasIPv4 &&
+        virNetSocketCheckProtocolByLookup("127.0.0.1", AF_INET, hasIPv4) < 0)
+        return -1;
 
     if (hasIPv6 &&
         virNetSocketCheckProtocolByLookup("::1", AF_INET6, hasIPv6) < 0)