From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:50350) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Zn0iy-0004EI-S6 for qemu-devel@nongnu.org; Fri, 16 Oct 2015 04:50:56 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Zn0ix-0007AP-J2 for qemu-devel@nongnu.org; Fri, 16 Oct 2015 04:50:52 -0400 Received: from mx1.redhat.com ([209.132.183.28]:33917) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Zn0ix-0007A4-3B for qemu-devel@nongnu.org; Fri, 16 Oct 2015 04:50:51 -0400 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by mx1.redhat.com (Postfix) with ESMTPS id B5636319AE2 for ; Fri, 16 Oct 2015 08:50:50 +0000 (UTC) Received: from donizetti.redhat.com (ovpn-112-80.ams2.redhat.com [10.36.112.80]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id t9G8oCag010200 for ; Fri, 16 Oct 2015 04:50:49 -0400 From: Paolo Bonzini Date: Fri, 16 Oct 2015 10:49:43 +0200 Message-Id: <1444985411-17803-22-git-send-email-pbonzini@redhat.com> In-Reply-To: <1444985411-17803-1-git-send-email-pbonzini@redhat.com> References: <1444985411-17803-1-git-send-email-pbonzini@redhat.com> Subject: [Qemu-devel] [PULL 21/49] qemu-sockets: fix conversion of ipv4/ipv6 JSON to QemuOpts List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org 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 Tested-by: Sair, Umair Reviewed-by: Daniel P. Berrange Signed-off-by: Paolo Bonzini --- util/qemu-sockets.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/util/qemu-sockets.c b/util/qemu-sockets.c index 2add83a..0a041a9 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); -- 2.5.0