[libvirt] [PATCH] conf: Check migration_host is valid or not during libvirt restarts

Jiri Denemark jdenemar at redhat.com
Fri Aug 29 12:52:28 UTC 2014


On Fri, Aug 29, 2014 at 19:20:58 +0800, Chen Fan wrote:
> if user specified an invalid strings as migration hostname,
> like setting: migration_host = "XXXXXXX", libvirt should check
> it and return error during lbivirt restart.
> 
> Signed-off-by: Chen Fan <chen.fan.fnst at cn.fujitsu.com>
> ---
>  src/qemu/qemu_conf.c | 40 ++++++++++++++++++++++++++++++++++++++++
>  1 file changed, 40 insertions(+)
> 
> diff --git a/src/qemu/qemu_conf.c b/src/qemu/qemu_conf.c
> index e2ec54f..450ac5b 100644
> --- a/src/qemu/qemu_conf.c
> +++ b/src/qemu/qemu_conf.c
> @@ -33,6 +33,7 @@
>  #include <fcntl.h>
>  #include <sys/wait.h>
>  #include <arpa/inet.h>
> +#include <netdb.h>
>  
>  #include "virerror.h"
>  #include "qemu_conf.h"
> @@ -650,6 +651,45 @@ int virQEMUDriverConfigLoadFile(virQEMUDriverConfigPtr cfg,
>      GET_VALUE_LONG("seccomp_sandbox", cfg->seccompSandbox);
>  
>      GET_VALUE_STR("migration_host", cfg->migrateHost);
> +    if (cfg->migrateHost) {
> +        struct addrinfo hints;
> +        struct addrinfo *res;
> +
> +        memset(&hints, 0, sizeof(hints));
> +        hints.ai_flags = AI_ADDRCONFIG;
> +        hints.ai_family = AF_UNSPEC;
> +
> +        if (getaddrinfo(cfg->migrateHost, NULL, &hints, &res) != 0) {
> +            virReportError(VIR_ERR_CONF_SYNTAX,
> +                           _("migration_host: '%s' is not a valid hostname"),
> +                           cfg->migrateHost);
> +            goto cleanup;
> +        }
> +
> +        if (res == NULL) {
> +            virReportError(VIR_ERR_CONF_SYNTAX,
> +                           _("No IP address for host '%s' found"),
> +                           cfg->migrateHost);
> +            goto cleanup;
> +        }
> +
> +        freeaddrinfo(res);

I don't think this is a good idea. What if it's in fact valid and just
can't be resolved due to a temporary issue? It should only fail at the
time someone actually tries to migrate a domain.

> +
> +        if (STRPREFIX(cfg->migrateHost, "localhost")) {
> +            virReportError(VIR_ERR_CONF_SYNTAX, "%s",
> +                           _("setting migration_host to 'localhost' is not allowed"));
> +            goto cleanup;
> +        }
> +
> +        if (STREQ(cfg->migrateHost, "127.0.0.1") ||
> +            STREQ(cfg->migrateHost, "::1")) {
> +            virReportError(VIR_ERR_CONF_SYNTAX, "%s",
> +                           _("setting migration_host to '127.0.0.1' or '::1' "
> +                             "is not allowed"));
> +            goto cleanup;
> +        }
> +    }
> +

Checking for localhost could make sense.

>      GET_VALUE_STR("migration_address", cfg->migrationAddress);
>  
>      GET_VALUE_BOOL("log_timestamp", cfg->logTimestamp);

Jirka




More information about the libvir-list mailing list