On 09/23/2014 06:04 AM, Chen Fan wrote: > Signed-off-by: Chen Fan <chen.fan.fnst@xxxxxxxxxxxxxx> > --- > src/libvirt_private.syms | 1 + > src/qemu/qemu_conf.c | 8 ++++++++ > src/util/virsocketaddr.c | 35 +++++++++++++++++++++++++++++++++++ > src/util/virsocketaddr.h | 3 +++ > 4 files changed, 47 insertions(+) > > diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms > index 51a692b..f7172b0 100644 > --- a/src/libvirt_private.syms > +++ b/src/libvirt_private.syms > @@ -1885,6 +1885,7 @@ virSocketAddrGetPort; > virSocketAddrGetRange; > virSocketAddrIsNetmask; > virSocketAddrIsNumeric; > +virSocketAddrIsLocalhost; > virSocketAddrIsPrivate; > virSocketAddrIsWildcard; > virSocketAddrMask; > diff --git a/src/qemu/qemu_conf.c b/src/qemu/qemu_conf.c > index adc6caf..30169cf 100644 > --- a/src/qemu/qemu_conf.c > +++ b/src/qemu/qemu_conf.c > @@ -707,6 +707,14 @@ int virQEMUDriverConfigLoadFile(virQEMUDriverConfigPtr cfg, > GET_VALUE_LONG("seccomp_sandbox", cfg->seccompSandbox); > > GET_VALUE_STR("migration_host", cfg->migrateHost); > + if (cfg->migrateHost && > + virSocketAddrIsLocalhost(cfg->migrateHost)) { > + virReportError(VIR_ERR_CONF_SYNTAX, > + _("migration_host must not be 'localhost' address: %s"), > + cfg->migrateHost); > + goto cleanup; > + } > + > GET_VALUE_STR("migration_address", cfg->migrationAddress); > > GET_VALUE_BOOL("log_timestamp", cfg->logTimestamp); > diff --git a/src/util/virsocketaddr.c b/src/util/virsocketaddr.c > index 64409a6..dfcaf72 100644 > --- a/src/util/virsocketaddr.c > +++ b/src/util/virsocketaddr.c > @@ -884,3 +884,38 @@ virSocketAddrIsNumeric(const char *address, int *family) > } > return sa_family == AF_INET || sa_family == AF_INET6; > } > + > +/** > + * virSocketAddrIsLocalhost: > + * @address: address to check > + * > + * Check if passed address is a 'localhost' address. > + * > + * Returns: true if @address is 'localhost' address, > + * false otherwise > + */ > +bool > +virSocketAddrIsLocalhost(const char *address) I think this function should be named 'IsNumericLocalhost' and only check for the numeric representation of localhost. If the address is numeric, we can parse it and catch all the cases (like 127.0.0.1, 2130706433, 0177.0.0.1, 0:0:0::1). But we can't check if a hostname points to localhost without resolving it. > +{ > + int family; > + > + if (virSocketAddrIsNumeric(address, &family)) { > + if (family == AF_INET) { > + if (STREQ(address, "127.0.0.1")) > + return true; > + } > + This should do what virSocketAddrIsWildcard does, only using INADDR_LOOPBACK instead of INADDR_ANY and IN6_IS_ADDR_LOOPBACK instead of IN6_IS_ADDR_UNSPECIFIED. > + if (family == AF_INET6) { > + if (STREQ(address, "::1")) > + return true; > + } > + } else { > + if (STRPREFIX(address, "localhost")) > + return true; I'd put this check in qemu_conf.c. > + > + if (STREQ(address, "[::1]")) > + return true; And strip the brackets before calling virSocketAddrParse. Jan > + } > + > + return false; > +} > diff --git a/src/util/virsocketaddr.h b/src/util/virsocketaddr.h > index 7b11afb..5269f35 100644 > --- a/src/util/virsocketaddr.h > +++ b/src/util/virsocketaddr.h > @@ -126,4 +126,7 @@ bool virSocketAddrIsPrivate(const virSocketAddr *addr); > bool virSocketAddrIsWildcard(const virSocketAddr *addr); > > bool virSocketAddrIsNumeric(const char *address, int *family); > + > +bool virSocketAddrIsLocalhost(const char *address); > + > #endif /* __VIR_SOCKETADDR_H__ */ >
Attachment:
signature.asc
Description: OpenPGP digital signature
-- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list