Signed-off-by: Chen Fan <chen.fan.fnst(a)cn.fujitsu.com>
---
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)
+{
+ int family;
+
+ if (virSocketAddrIsNumeric(address, &family)) {
+ if (family == AF_INET) {
+ if (STREQ(address, "127.0.0.1"))
+ return true;
+ }
+
+ if (family == AF_INET6) {
+ if (STREQ(address, "::1"))
+ return true;
+ }
+ } else {
+ if (STRPREFIX(address, "localhost"))
+ return true;
+
+ if (STREQ(address, "[::1]"))
+ return true;
+ }
+
+ 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__ */
--
1.9.3