diff options
author | Paolo Bonzini <pbonzini@redhat.com> | 2015-10-12 15:35:16 +0200 |
---|---|---|
committer | Paolo Bonzini <pbonzini@redhat.com> | 2015-10-12 18:29:26 +0200 |
commit | b77e7c8e99f9ac726c4eaa2fc3461fd886017dc0 (patch) | |
tree | ed4975227ff5a2fe955ea81f36caf6469bbff8e6 /util/qemu-sockets.c | |
parent | 5ea530491fe9ac56f75bc1833cc3fd7722b24efd (diff) | |
download | qemu-b77e7c8e99f9ac726c4eaa2fc3461fd886017dc0.tar.gz qemu-b77e7c8e99f9ac726c4eaa2fc3461fd886017dc0.tar.bz2 qemu-b77e7c8e99f9ac726c4eaa2fc3461fd886017dc0.zip |
qemu-sockets: fix conversion of ipv4/ipv6 JSON to QemuOpts
The QemuOpts-based code treats "option not set" and "option set
to false" the same way for the ipv4 and ipv6 options, because it
is meant to handle only the ",ipv4" and ",ipv6" substrings in
hand-crafted option parsers.
When converting InetSocketAddress to QemuOpts, however, it is
necessary to handle all three cases (not set, set to true, set
to false). Currently we are not handling all cases correctly.
The rules are:
* if none or both options are absent, leave things as is
* if the single present option is Y, the other should be N.
This can be implemented by leaving things as is, or by setting
the other option to N as done in this patch.
* if the single present option is N, the other should be Y.
This is handled by the "else if" branch of this patch.
This ensures that the ipv4 option has an effect on Windows,
where creating the socket with PF_UNSPEC makes an ipv6
socket. With this patch, ",ipv4" will result in a PF_INET
socket instead.
Reported-by: Sair, Umair <Umair_Sair@mentor.com>
Tested-by: Sair, Umair <Umair_Sair@mentor.com>
Reviewed-by: Daniel P. Berrange <berrange@redhat.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Diffstat (limited to 'util/qemu-sockets.c')
-rw-r--r-- | util/qemu-sockets.c | 9 |
1 files changed, 6 insertions, 3 deletions
diff --git a/util/qemu-sockets.c b/util/qemu-sockets.c index 2add83a0fc..0a041a922e 100644 --- a/util/qemu-sockets.c +++ b/util/qemu-sockets.c @@ -586,12 +586,15 @@ fail: static void inet_addr_to_opts(QemuOpts *opts, const InetSocketAddress *addr) { - bool ipv4 = addr->ipv4 || !addr->has_ipv4; - bool ipv6 = addr->ipv6 || !addr->has_ipv6; + bool ipv4 = addr->has_ipv4 && addr->ipv4; + bool ipv6 = addr->has_ipv6 && addr->ipv6; - if (!ipv4 || !ipv6) { + if (ipv4 || ipv6) { qemu_opt_set_bool(opts, "ipv4", ipv4, &error_abort); qemu_opt_set_bool(opts, "ipv6", ipv6, &error_abort); + } else if (addr->has_ipv4 || addr->has_ipv6) { + qemu_opt_set_bool(opts, "ipv4", !addr->has_ipv4, &error_abort); + qemu_opt_set_bool(opts, "ipv6", !addr->has_ipv6, &error_abort); } if (addr->has_to) { qemu_opt_set_number(opts, "to", addr->to, &error_abort); |