Split out the part of qemuMigrationPrepareAny that decides
whether to listen on [::] or 0.0.0.0 by checking whether
IPv6 is enabled on the host.
---
src/libvirt_private.syms | 1 +
src/qemu/qemu_migration.c | 8 +-------
src/util/virutil.c | 14 ++++++++++++++
src/util/virutil.h | 1 +
4 files changed, 17 insertions(+), 7 deletions(-)
diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index 4bc4d69..157d68c 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -2065,6 +2065,7 @@ virGetUserID;
virGetUserName;
virGetUserRuntimeDirectory;
virHexToBin;
+virHostHasIPv6;
virIndexToDiskName;
virIsCapableFCHost;
virIsCapableVport;
diff --git a/src/qemu/qemu_migration.c b/src/qemu/qemu_migration.c
index 3a1aab7..c21063d 100644
--- a/src/qemu/qemu_migration.c
+++ b/src/qemu/qemu_migration.c
@@ -22,8 +22,6 @@
#include <config.h>
-#include <netdb.h>
-#include <sys/socket.h>
#include <sys/time.h>
#ifdef WITH_GNUTLS
# include <gnutls/gnutls.h>
@@ -2261,9 +2259,6 @@ qemuMigrationPrepareAny(virQEMUDriverPtr driver,
goto cleanup;
} else {
virQEMUCapsPtr qemuCaps = NULL;
- struct addrinfo *info = NULL;
- struct addrinfo hints = { .ai_flags = AI_ADDRCONFIG,
- .ai_socktype = SOCK_STREAM };
if (!(qemuCaps = virQEMUCapsCacheLookupCopy(driver->qemuCapsCache,
(*def)->emulator)))
@@ -2273,8 +2268,7 @@ qemuMigrationPrepareAny(virQEMUDriverPtr driver,
* and there is at least one IPv6 address configured
*/
if (virQEMUCapsGet(qemuCaps, QEMU_CAPS_IPV6_MIGRATION) &&
- getaddrinfo("::", NULL, &hints, &info) == 0) {
- freeaddrinfo(info);
+ virHostHasIPv6()) {
listenAddr = "[::]";
} else {
listenAddr = "0.0.0.0";
diff --git a/src/util/virutil.c b/src/util/virutil.c
index d9e0bc4..2fcd8a5 100644
--- a/src/util/virutil.c
+++ b/src/util/virutil.c
@@ -648,6 +648,20 @@ cleanup:
}
+bool
+virHostHasIPv6()
+{
+ bool ret;
+ struct addrinfo *info = NULL;
+ struct addrinfo hints = { .ai_flags = AI_ADDRCONFIG,
+ .ai_socktype = SOCK_STREAM };
+
+ ret = getaddrinfo("::", NULL, &hints, &info) == 0;
+ freeaddrinfo(info);
+ return ret;
+}
+
+
char *
virGetUserDirectory(void)
{
diff --git a/src/util/virutil.h b/src/util/virutil.h
index 4b06992..437e72c 100644
--- a/src/util/virutil.h
+++ b/src/util/virutil.h
@@ -109,6 +109,7 @@ static inline int getgid (void) { return 0; }
# endif
char *virGetHostname(void);
+bool virHostHasIPv6(void);
char *virGetUserDirectory(void);
char *virGetUserDirectoryByUID(uid_t uid);
--
1.8.1.5