Re: [libvirt] [PATCH v2 2/4] migration: add migration_host support for Ipv6 address without brackets

2014-10-05 Thread Chen, Fan
On Fri, 2014-10-03 at 15:58 +0200, Ján Tomko wrote: 
> On 09/23/2014 06:04 AM, Chen Fan wrote:
> > if specifying migration_host to an Ipv6 address without brackets,
> > it was resolved to an incorrect address, such as:
> > tcp:2001:0DB8::1428:,
> > but the correct address should be:
> > tcp:[2001:0DB8::1428]:
> > so we should add brackets when parsing it.
> > 
> > Signed-off-by: Chen Fan 
> > ---
> >  src/qemu/qemu_migration.c | 24 +---
> >  1 file changed, 13 insertions(+), 11 deletions(-)
> > 
> > diff --git a/src/qemu/qemu_migration.c b/src/qemu/qemu_migration.c
> > index 155f5b9..016d131 100644
> > --- a/src/qemu/qemu_migration.c
> > +++ b/src/qemu/qemu_migration.c
> > @@ -2544,7 +2544,7 @@ qemuMigrationPrepareAny(virQEMUDriverPtr driver,
> >  if (VIR_STRDUP(migrateFrom, "stdio") < 0)
> >  goto cleanup;
> >  } else {
> > -virSocketAddr listenAddressSocket;
> > +int listenAddressFamily;
> >  bool encloseAddress = false;
> >  bool hostIPv6Capable = false;
> >  bool qemuIPv6Capable = false;
> > @@ -2565,13 +2565,9 @@ qemuMigrationPrepareAny(virQEMUDriverPtr driver,
> >  virObjectUnref(qemuCaps);
> >  
> >  if (listenAddress) {
> > -if (virSocketAddrIsNumeric(listenAddress, NULL)) {
> > +if (virSocketAddrIsNumeric(listenAddress, 
> > &listenAddressFamily)) {
> 
> Both uses of this function are in this patch (I didn't realize that when
> reviewing v1).
> 
> We can rename it to virSocketAddrNumericFamily and do
> if (virSocketAddrNumericFamily(listenAddress) == AF_INET6), removing the need
> for a temporary variable.
Right, Agreed.

> 
> >  /* listenAddress is numeric IPv4 or IPv6 */
> > -if (virSocketAddrParse(&listenAddressSocket, 
> > listenAddress, AF_UNSPEC) < 0)
> > -goto cleanup;
> > -
> > -/* address parsed successfully */
> > -if (VIR_SOCKET_ADDR_IS_FAMILY(&listenAddressSocket, 
> > AF_INET6)) {
> > +if (listenAddressFamily == AF_INET6) {
> >  if (!qemuIPv6Capable) {
> >  virReportError(VIR_ERR_ARGUMENT_UNSUPPORTED, "%s",
> > _("qemu isn't capable of IPv6"));
> > @@ -2850,11 +2846,17 @@ qemuMigrationPrepareDirect(virQEMUDriverPtr driver,
> >  goto cleanup;
> >  
> >  if (migrateHost != NULL) {
> > -if (virSocketAddrIsNumeric(migrateHost, NULL) &&
> > -virSocketAddrParse(NULL, migrateHost, AF_UNSPEC) < 0)
> > -goto cleanup;
> > +int family;
> > +bool migrateHostisIpv6Address = false;
> > +
> > +if (virSocketAddrIsNumeric(migrateHost, &family) &&
> > +(family == AF_INET6))
> > +migrateHostisIpv6Address = true;
> >  
> > -   if (VIR_STRDUP(hostname, migrateHost) < 0)
> > +if ((migrateHostisIpv6Address &&
> > + virAsprintf(&hostname, "[%s]", migrateHost) < 0) ||
> > +(!migrateHostisIpv6Address &&
> > + virAsprintf(&hostname, "%s", migrateHost) < 0))
> >  goto cleanup;
> 
> In qemuMigrationPrepareAny, we have:
> if (encloseAddress)
> incFormat = "%s:[%s]:%d";
> else
> incFormat = "%s:%s:%d";
> if (virAsprintf(&migrateFrom, incFormat,
> protocol, listenAddress, port) < 0)
> goto cleanup;
> 
> Using the same pattern here as well would make it more readable.
> 

Thanks,
Chen


> Jan
> 
> >  } else {
> >  if ((hostname = virGetHostname()) == NULL)
> > 
> 
> 


--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list

Re: [libvirt] [PATCH v2 2/4] migration: add migration_host support for Ipv6 address without brackets

2014-10-03 Thread Ján Tomko
On 09/23/2014 06:04 AM, Chen Fan wrote:
> if specifying migration_host to an Ipv6 address without brackets,
> it was resolved to an incorrect address, such as:
> tcp:2001:0DB8::1428:,
> but the correct address should be:
> tcp:[2001:0DB8::1428]:
> so we should add brackets when parsing it.
> 
> Signed-off-by: Chen Fan 
> ---
>  src/qemu/qemu_migration.c | 24 +---
>  1 file changed, 13 insertions(+), 11 deletions(-)
> 
> diff --git a/src/qemu/qemu_migration.c b/src/qemu/qemu_migration.c
> index 155f5b9..016d131 100644
> --- a/src/qemu/qemu_migration.c
> +++ b/src/qemu/qemu_migration.c
> @@ -2544,7 +2544,7 @@ qemuMigrationPrepareAny(virQEMUDriverPtr driver,
>  if (VIR_STRDUP(migrateFrom, "stdio") < 0)
>  goto cleanup;
>  } else {
> -virSocketAddr listenAddressSocket;
> +int listenAddressFamily;
>  bool encloseAddress = false;
>  bool hostIPv6Capable = false;
>  bool qemuIPv6Capable = false;
> @@ -2565,13 +2565,9 @@ qemuMigrationPrepareAny(virQEMUDriverPtr driver,
>  virObjectUnref(qemuCaps);
>  
>  if (listenAddress) {
> -if (virSocketAddrIsNumeric(listenAddress, NULL)) {
> +if (virSocketAddrIsNumeric(listenAddress, &listenAddressFamily)) 
> {

Both uses of this function are in this patch (I didn't realize that when
reviewing v1).

We can rename it to virSocketAddrNumericFamily and do
if (virSocketAddrNumericFamily(listenAddress) == AF_INET6), removing the need
for a temporary variable.

>  /* listenAddress is numeric IPv4 or IPv6 */
> -if (virSocketAddrParse(&listenAddressSocket, listenAddress, 
> AF_UNSPEC) < 0)
> -goto cleanup;
> -
> -/* address parsed successfully */
> -if (VIR_SOCKET_ADDR_IS_FAMILY(&listenAddressSocket, 
> AF_INET6)) {
> +if (listenAddressFamily == AF_INET6) {
>  if (!qemuIPv6Capable) {
>  virReportError(VIR_ERR_ARGUMENT_UNSUPPORTED, "%s",
> _("qemu isn't capable of IPv6"));
> @@ -2850,11 +2846,17 @@ qemuMigrationPrepareDirect(virQEMUDriverPtr driver,
>  goto cleanup;
>  
>  if (migrateHost != NULL) {
> -if (virSocketAddrIsNumeric(migrateHost, NULL) &&
> -virSocketAddrParse(NULL, migrateHost, AF_UNSPEC) < 0)
> -goto cleanup;
> +int family;
> +bool migrateHostisIpv6Address = false;
> +
> +if (virSocketAddrIsNumeric(migrateHost, &family) &&
> +(family == AF_INET6))
> +migrateHostisIpv6Address = true;
>  
> -   if (VIR_STRDUP(hostname, migrateHost) < 0)
> +if ((migrateHostisIpv6Address &&
> + virAsprintf(&hostname, "[%s]", migrateHost) < 0) ||
> +(!migrateHostisIpv6Address &&
> + virAsprintf(&hostname, "%s", migrateHost) < 0))
>  goto cleanup;

In qemuMigrationPrepareAny, we have:
if (encloseAddress)
incFormat = "%s:[%s]:%d";
else
incFormat = "%s:%s:%d";
if (virAsprintf(&migrateFrom, incFormat,
protocol, listenAddress, port) < 0)
goto cleanup;

Using the same pattern here as well would make it more readable.

Jan

>  } else {
>  if ((hostname = virGetHostname()) == NULL)
> 




signature.asc
Description: OpenPGP digital signature
--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list

[libvirt] [PATCH v2 2/4] migration: add migration_host support for Ipv6 address without brackets

2014-09-22 Thread Chen Fan
if specifying migration_host to an Ipv6 address without brackets,
it was resolved to an incorrect address, such as:
tcp:2001:0DB8::1428:,
but the correct address should be:
tcp:[2001:0DB8::1428]:
so we should add brackets when parsing it.

Signed-off-by: Chen Fan 
---
 src/qemu/qemu_migration.c | 24 +---
 1 file changed, 13 insertions(+), 11 deletions(-)

diff --git a/src/qemu/qemu_migration.c b/src/qemu/qemu_migration.c
index 155f5b9..016d131 100644
--- a/src/qemu/qemu_migration.c
+++ b/src/qemu/qemu_migration.c
@@ -2544,7 +2544,7 @@ qemuMigrationPrepareAny(virQEMUDriverPtr driver,
 if (VIR_STRDUP(migrateFrom, "stdio") < 0)
 goto cleanup;
 } else {
-virSocketAddr listenAddressSocket;
+int listenAddressFamily;
 bool encloseAddress = false;
 bool hostIPv6Capable = false;
 bool qemuIPv6Capable = false;
@@ -2565,13 +2565,9 @@ qemuMigrationPrepareAny(virQEMUDriverPtr driver,
 virObjectUnref(qemuCaps);
 
 if (listenAddress) {
-if (virSocketAddrIsNumeric(listenAddress, NULL)) {
+if (virSocketAddrIsNumeric(listenAddress, &listenAddressFamily)) {
 /* listenAddress is numeric IPv4 or IPv6 */
-if (virSocketAddrParse(&listenAddressSocket, listenAddress, 
AF_UNSPEC) < 0)
-goto cleanup;
-
-/* address parsed successfully */
-if (VIR_SOCKET_ADDR_IS_FAMILY(&listenAddressSocket, AF_INET6)) 
{
+if (listenAddressFamily == AF_INET6) {
 if (!qemuIPv6Capable) {
 virReportError(VIR_ERR_ARGUMENT_UNSUPPORTED, "%s",
_("qemu isn't capable of IPv6"));
@@ -2850,11 +2846,17 @@ qemuMigrationPrepareDirect(virQEMUDriverPtr driver,
 goto cleanup;
 
 if (migrateHost != NULL) {
-if (virSocketAddrIsNumeric(migrateHost, NULL) &&
-virSocketAddrParse(NULL, migrateHost, AF_UNSPEC) < 0)
-goto cleanup;
+int family;
+bool migrateHostisIpv6Address = false;
+
+if (virSocketAddrIsNumeric(migrateHost, &family) &&
+(family == AF_INET6))
+migrateHostisIpv6Address = true;
 
-   if (VIR_STRDUP(hostname, migrateHost) < 0)
+if ((migrateHostisIpv6Address &&
+ virAsprintf(&hostname, "[%s]", migrateHost) < 0) ||
+(!migrateHostisIpv6Address &&
+ virAsprintf(&hostname, "%s", migrateHost) < 0))
 goto cleanup;
 } else {
 if ((hostname = virGetHostname()) == NULL)
-- 
1.9.3

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list