On Tue, Oct 01, 2013 at 11:01:36AM +0200, Ján Tomko wrote:
> 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;
> +}
This really doesn't belong in virutil.c.
I'd prefer to see this in virnetdev.{c,h} and named
virNetDevCheckIPProtocols(bool *hasIPv4, bool *hasIPv6)
and it should use 'getifaddrs' - 'getaddrinfo' isn't a
reliable way to determine if IPv6 is present. There is
code in tests/virnetsockettest.c you can move for this
purpose.
Daniel
--
|: http://berrange.com -o- http://www.flickr.com/photos/dberrange/ :|
|: http://libvirt.org -o- http://virt-manager.org :|
|: http://autobuild.org -o- http://search.cpan.org/~danberr/ :|
|: http://entangle-photo.org -o- http://live.gnome.org/gtk-vnc :|
--
libvir-list mailing list
[email protected]
https://www.redhat.com/mailman/listinfo/libvir-list