From nobody Tue Apr 30 00:09:23 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1499777167013517.471997653798; Tue, 11 Jul 2017 05:46:07 -0700 (PDT) Received: from localhost ([::1]:46160 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dUuYE-0006eU-L1 for importer@patchew.org; Tue, 11 Jul 2017 08:46:02 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:34219) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dUuWh-0005ZR-RC for qemu-devel@nongnu.org; Tue, 11 Jul 2017 08:44:28 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dUuWe-0005PY-OG for qemu-devel@nongnu.org; Tue, 11 Jul 2017 08:44:27 -0400 Received: from mx1.redhat.com ([209.132.183.28]:33611) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dUuWe-0005Ow-F8 for qemu-devel@nongnu.org; Tue, 11 Jul 2017 08:44:24 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 6749B61B91; Tue, 11 Jul 2017 12:44:23 +0000 (UTC) Received: from localhost.localdomain.com (unknown [10.42.22.189]) by smtp.corp.redhat.com (Postfix) with ESMTP id B0072757B1; Tue, 11 Jul 2017 12:44:22 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 6749B61B91 Authentication-Results: ext-mx10.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx10.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=berrange@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 6749B61B91 From: "Daniel P. Berrange" To: qemu-devel@nongnu.org Date: Tue, 11 Jul 2017 13:44:07 +0100 Message-Id: <20170711124411.10499-2-berrange@redhat.com> In-Reply-To: <20170711124411.10499-1-berrange@redhat.com> References: <20170711124411.10499-1-berrange@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.39]); Tue, 11 Jul 2017 12:44:23 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL v1 1/5] sockets: ensure we can bind to both ipv4 & ipv6 separately X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" When binding to an IPv6 socket we currently force the IPV6_V6ONLY flag to off. This means that the IPv6 socket will accept both IPv4 & IPv6 sockets when QEMU is launched with something like -vnc :::1 While this is good for that case, it is bad for other cases. For example if an empty hostname is given, getaddrinfo resolves it to 2 addresses 0.0.0.0 and ::, in that order. We will thus bind to 0.0.0.0 first, and then fail to bind to :: on the same port. The same problem can happen if any other hostname lookup causes the IPv4 address to be reported before the IPv6 address. When we get an IPv6 bind failure, we should re-try the same port, but with IPV6_V6ONLY turned on again, to avoid clash with any IPv4 listener. This ensures that -vnc :1 will bind successfully to both 0.0.0.0 and ::, and also avoid -vnc :1,to=3D2 from mistakenly using a 2nd port for the :: listener. This is a regression due to commit 396f935 "ui: add ability to specify multiple VNC listen addresses". Acked-by: Gerd Hoffmann Reviewed-by: Eric Blake Reviewed-by: Philippe Mathieu-Daud=C3=A9 Signed-off-by: Daniel P. Berrange --- util/qemu-sockets.c | 31 +++++++++++++++++++++++-------- 1 file changed, 23 insertions(+), 8 deletions(-) diff --git a/util/qemu-sockets.c b/util/qemu-sockets.c index d3e5108..4c2f84b 100644 --- a/util/qemu-sockets.c +++ b/util/qemu-sockets.c @@ -208,22 +208,37 @@ static int inet_listen_saddr(InetSocketAddress *saddr, } =20 socket_set_fast_reuse(slisten); -#ifdef IPV6_V6ONLY - if (e->ai_family =3D=3D PF_INET6) { - /* listen on both ipv4 and ipv6 */ - const int off =3D 0; - qemu_setsockopt(slisten, IPPROTO_IPV6, IPV6_V6ONLY, &off, - sizeof(off)); - } -#endif =20 port_min =3D inet_getport(e); port_max =3D saddr->has_to ? saddr->to + port_offset : port_min; for (p =3D port_min; p <=3D port_max; p++) { +#ifdef IPV6_V6ONLY + /* listen on both ipv4 and ipv6 */ + int v6only =3D 0; +#endif inet_setport(e, p); +#ifdef IPV6_V6ONLY + rebind: + if (e->ai_family =3D=3D PF_INET6) { + qemu_setsockopt(slisten, IPPROTO_IPV6, IPV6_V6ONLY, &v6onl= y, + sizeof(v6only)); + } +#endif if (bind(slisten, e->ai_addr, e->ai_addrlen) =3D=3D 0) { goto listen; } + +#ifdef IPV6_V6ONLY + /* If we got EADDRINUSE from an IPv6 bind & V6ONLY is unset, + * it could be that the IPv4 port is already claimed, so retry + * with V6ONLY set + */ + if (e->ai_family =3D=3D PF_INET6 && errno =3D=3D EADDRINUSE &&= !v6only) { + v6only =3D 1; + goto rebind; + } +#endif + if (p =3D=3D port_max) { if (!e->ai_next) { error_setg_errno(errp, errno, "Failed to bind socket"); --=20 2.9.4 From nobody Tue Apr 30 00:09:23 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1499777324586794.0449761813255; Tue, 11 Jul 2017 05:48:44 -0700 (PDT) Received: from localhost ([::1]:46168 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dUuao-0000Jj-Vn for importer@patchew.org; Tue, 11 Jul 2017 08:48:43 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:34218) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dUuWh-0005ZQ-R4 for qemu-devel@nongnu.org; Tue, 11 Jul 2017 08:44:29 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dUuWf-0005QV-OO for qemu-devel@nongnu.org; Tue, 11 Jul 2017 08:44:27 -0400 Received: from mx1.redhat.com ([209.132.183.28]:54220) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dUuWf-0005Po-I7 for qemu-devel@nongnu.org; Tue, 11 Jul 2017 08:44:25 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 5F7DD80473; Tue, 11 Jul 2017 12:44:24 +0000 (UTC) Received: from localhost.localdomain.com (unknown [10.42.22.189]) by smtp.corp.redhat.com (Postfix) with ESMTP id A40FF5D964; Tue, 11 Jul 2017 12:44:23 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 5F7DD80473 Authentication-Results: ext-mx04.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx04.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=berrange@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 5F7DD80473 From: "Daniel P. Berrange" To: qemu-devel@nongnu.org Date: Tue, 11 Jul 2017 13:44:08 +0100 Message-Id: <20170711124411.10499-3-berrange@redhat.com> In-Reply-To: <20170711124411.10499-1-berrange@redhat.com> References: <20170711124411.10499-1-berrange@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Tue, 11 Jul 2017 12:44:24 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL v1 2/5] sockets: don't block IPv4 clients when listening on "::" X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" When inet_parse() parses the hostname, it is forcing the has_ipv6 && ipv6 flags if the address contains a ":". This means that if the user had set the ipv4=3Don flag, to try to restrict the listener to just ipv4, an error would not have been raised. eg -incoming tcp:[::]:9000,ipv4 should have raised an error because listening for IPv4 on "::" is a non-sensical combination. With this removed, we now call getaddrinfo() on "::" passing PF_INET and so getaddrinfo reports an error about the hostname being incompatible with the requested protocol: qemu-system-x86_64: -incoming tcp:[::]:9000,ipv4: address resolution failed for :::9000: Address family for hostname not supported Likewise it is explicitly setting the has_ipv4 & ipv4 flags when the address contains only digits + '.'. This has no ill-effect, but also has no benefit, so is removed. Acked-by: Gerd Hoffmann Reviewed-by: Philippe Mathieu-Daud=C3=A9 Reviewed-by: Eric Blake Signed-off-by: Daniel P. Berrange --- util/qemu-sockets.c | 4 ---- 1 file changed, 4 deletions(-) diff --git a/util/qemu-sockets.c b/util/qemu-sockets.c index 4c2f84b..f4ddcaf 100644 --- a/util/qemu-sockets.c +++ b/util/qemu-sockets.c @@ -618,16 +618,12 @@ int inet_parse(InetSocketAddress *addr, const char *s= tr, Error **errp) error_setg(errp, "error parsing IPv6 address '%s'", str); return -1; } - addr->ipv6 =3D addr->has_ipv6 =3D true; } else { /* hostname or IPv4 addr */ if (sscanf(str, "%64[^:]:%32[^,]%n", host, port, &pos) !=3D 2) { error_setg(errp, "error parsing address '%s'", str); return -1; } - if (host[strspn(host, "0123456789.")] =3D=3D '\0') { - addr->ipv4 =3D addr->has_ipv4 =3D true; - } } =20 addr->host =3D g_strdup(host); --=20 2.9.4 From nobody Tue Apr 30 00:09:23 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1499777166646314.5353522162849; Tue, 11 Jul 2017 05:46:06 -0700 (PDT) Received: from localhost ([::1]:46159 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dUuYE-0006eL-7P for importer@patchew.org; Tue, 11 Jul 2017 08:46:02 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:34220) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dUuWh-0005ZS-RA for qemu-devel@nongnu.org; Tue, 11 Jul 2017 08:44:29 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dUuWg-0005RA-KX for qemu-devel@nongnu.org; Tue, 11 Jul 2017 08:44:27 -0400 Received: from mx1.redhat.com ([209.132.183.28]:38748) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dUuWg-0005QS-BD for qemu-devel@nongnu.org; Tue, 11 Jul 2017 08:44:26 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 4D6937D0D4; Tue, 11 Jul 2017 12:44:25 +0000 (UTC) Received: from localhost.localdomain.com (unknown [10.42.22.189]) by smtp.corp.redhat.com (Postfix) with ESMTP id 97100757B1; Tue, 11 Jul 2017 12:44:24 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 4D6937D0D4 Authentication-Results: ext-mx02.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx02.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=berrange@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 4D6937D0D4 From: "Daniel P. Berrange" To: qemu-devel@nongnu.org Date: Tue, 11 Jul 2017 13:44:09 +0100 Message-Id: <20170711124411.10499-4-berrange@redhat.com> In-Reply-To: <20170711124411.10499-1-berrange@redhat.com> References: <20170711124411.10499-1-berrange@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Tue, 11 Jul 2017 12:44:25 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL v1 3/5] sockets: ensure we don't accept IPv4 clients when IPv4 is disabled X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Currently if you disable listening on IPv4 addresses, via the CLI flag ipv4=3Doff, we still mistakenly accept IPv4 clients via the IPv6 listener socket due to IPV6_V6ONLY flag being unset. We must ensure IPV6_V6ONLY is always set if ipv4=3Doff This fixes the following scenarios -incoming tcp::9000,ipv6=3Don -incoming tcp:[::]:9000,ipv6=3Don -chardev socket,id=3Dcdev0,host=3D,port=3D9000,server,nowait,ipv4=3Doff -chardev socket,id=3Dcdev0,host=3D,port=3D9000,server,nowait,ipv6=3Don -chardev socket,id=3Dcdev0,host=3D::,port=3D9000,server,nowait,ipv4=3Doff -chardev socket,id=3Dcdev0,host=3D::,port=3D9000,server,nowait,ipv6=3Don which all mistakenly accepted IPv4 clients Acked-by: Gerd Hoffmann Reviewed-by: Philippe Mathieu-Daud=C3=A9 Reviewed-by: Eric Blake Signed-off-by: Daniel P. Berrange --- util/qemu-sockets.c | 40 +++++++++++++++++++++++++++++++--------- 1 file changed, 31 insertions(+), 9 deletions(-) diff --git a/util/qemu-sockets.c b/util/qemu-sockets.c index f4ddcaf..37d386f 100644 --- a/util/qemu-sockets.c +++ b/util/qemu-sockets.c @@ -104,17 +104,16 @@ NetworkAddressFamily inet_netfamily(int family) * f t PF_INET6 * t - PF_INET * t f PF_INET - * t t PF_INET6 + * t t PF_INET6/PF_UNSPEC * * NB, this matrix is only about getting the necessary results * from getaddrinfo(). Some of the cases require further work * after reading results from getaddrinfo in order to fully - * apply the logic the end user wants. eg with the last case - * ipv4=3Dt + ipv6=3Dt + PF_INET6, getaddrinfo alone can only - * guarantee the ipv6=3Dt part of the request - we need more - * checks to provide ipv4=3Dt part of the guarantee. This is - * outside scope of this method and not currently handled by - * callers at all. + * apply the logic the end user wants. + * + * In the first and last cases, we must set IPV6_V6ONLY=3D0 + * when binding, to allow a single listener to potentially + * accept both IPv4+6 addresses. */ int inet_ai_family_from_address(InetSocketAddress *addr, Error **errp) @@ -124,6 +123,23 @@ int inet_ai_family_from_address(InetSocketAddress *add= r, error_setg(errp, "Cannot disable IPv4 and IPv6 at same time"); return PF_UNSPEC; } + if ((addr->has_ipv6 && addr->ipv6) && (addr->has_ipv4 && addr->ipv4)) { + /* + * Some backends can only do a single listener. In that case + * we want empty hostname to resolve to "::" and then use the + * flag IPV6_V6ONLY=3D=3D0 to get both protocols on 1 socket. This + * doesn't work for addresses other than "", so they're just + * inevitably broken until multiple listeners can be used, + * and thus we honour getaddrinfo automatic protocol detection + * Once all backends do multi-listener, remove the PF_INET6 + * branch entirely. + */ + if (!addr->host || g_str_equal(addr->host, "")) { + return PF_INET6; + } else { + return PF_UNSPEC; + } + } if ((addr->has_ipv6 && addr->ipv6) || (addr->has_ipv4 && !addr->ipv4))= { return PF_INET6; } @@ -213,8 +229,14 @@ static int inet_listen_saddr(InetSocketAddress *saddr, port_max =3D saddr->has_to ? saddr->to + port_offset : port_min; for (p =3D port_min; p <=3D port_max; p++) { #ifdef IPV6_V6ONLY - /* listen on both ipv4 and ipv6 */ - int v6only =3D 0; + /* + * Deals with first & last cases in matrix in comment + * for inet_ai_family_from_address(). + */ + int v6only =3D + ((!saddr->has_ipv4 && !saddr->has_ipv6) || + (saddr->has_ipv4 && saddr->ipv4 && + saddr->has_ipv6 && saddr->ipv6)) ? 0 : 1; #endif inet_setport(e, p); #ifdef IPV6_V6ONLY --=20 2.9.4 From nobody Tue Apr 30 00:09:23 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1499777335456296.80422959950977; Tue, 11 Jul 2017 05:48:55 -0700 (PDT) Received: from localhost ([::1]:46169 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dUuav-0000O1-4d for importer@patchew.org; Tue, 11 Jul 2017 08:48:49 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:34227) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dUuWi-0005ZU-6l for qemu-devel@nongnu.org; Tue, 11 Jul 2017 08:44:29 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dUuWh-0005Rt-GR for qemu-devel@nongnu.org; Tue, 11 Jul 2017 08:44:28 -0400 Received: from mx1.redhat.com ([209.132.183.28]:45592) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dUuWh-0005RE-Aj for qemu-devel@nongnu.org; Tue, 11 Jul 2017 08:44:27 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 3FE9983F43; Tue, 11 Jul 2017 12:44:26 +0000 (UTC) Received: from localhost.localdomain.com (unknown [10.42.22.189]) by smtp.corp.redhat.com (Postfix) with ESMTP id 889105D964; Tue, 11 Jul 2017 12:44:25 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 3FE9983F43 Authentication-Results: ext-mx03.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx03.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=berrange@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 3FE9983F43 From: "Daniel P. Berrange" To: qemu-devel@nongnu.org Date: Tue, 11 Jul 2017 13:44:10 +0100 Message-Id: <20170711124411.10499-5-berrange@redhat.com> In-Reply-To: <20170711124411.10499-1-berrange@redhat.com> References: <20170711124411.10499-1-berrange@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.27]); Tue, 11 Jul 2017 12:44:26 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL v1 4/5] io: preserve ipv4/ipv6 flags when resolving InetSocketAddress X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" The original InetSocketAddress struct may have has_ipv4 and has_ipv6 fields set, which will control both the ai_family used during DNS resolution, and later use of the V6ONLY flag. Currently the standalone DNS resolver code drops the has_ipv4 & has_ipv6 flags after resolving, which means the later bind() code won't correctly set V6ONLY. This fixes the following scenarios -vnc :0,ipv4=3Doff -vnc :0,ipv6=3Don -vnc :::0,ipv4=3Doff -vnc :::0,ipv6=3Don which all mistakenly accepted IPv4 clients Acked-by: Gerd Hoffmann Reviewed-by: Philippe Mathieu-Daud=C3=A9 Reviewed-by: Eric Blake Signed-off-by: Daniel P. Berrange --- io/dns-resolver.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/io/dns-resolver.c b/io/dns-resolver.c index 57a8896..c072d12 100644 --- a/io/dns-resolver.c +++ b/io/dns-resolver.c @@ -116,8 +116,10 @@ static int qio_dns_resolver_lookup_sync_inet(QIODNSRes= olver *resolver, .numeric =3D true, .has_to =3D iaddr->has_to, .to =3D iaddr->to, - .has_ipv4 =3D false, - .has_ipv6 =3D false, + .has_ipv4 =3D iaddr->has_ipv4, + .ipv4 =3D iaddr->ipv4, + .has_ipv6 =3D iaddr->has_ipv6, + .ipv6 =3D iaddr->ipv6, }; =20 (*addrs)[i] =3D newaddr; --=20 2.9.4 From nobody Tue Apr 30 00:09:23 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1499777483657337.8405061165364; Tue, 11 Jul 2017 05:51:23 -0700 (PDT) Received: from localhost ([::1]:46190 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dUudN-0003Le-5a for importer@patchew.org; Tue, 11 Jul 2017 08:51:21 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:34280) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dUuWm-0005cd-L7 for qemu-devel@nongnu.org; Tue, 11 Jul 2017 08:44:36 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dUuWi-0005Tk-Sn for qemu-devel@nongnu.org; Tue, 11 Jul 2017 08:44:32 -0400 Received: from mx1.redhat.com ([209.132.183.28]:44724) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dUuWi-0005SN-Gt for qemu-devel@nongnu.org; Tue, 11 Jul 2017 08:44:28 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 7D592267CD; Tue, 11 Jul 2017 12:44:27 +0000 (UTC) Received: from localhost.localdomain.com (unknown [10.42.22.189]) by smtp.corp.redhat.com (Postfix) with ESMTP id 85E02757B1; Tue, 11 Jul 2017 12:44:26 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 7D592267CD Authentication-Results: ext-mx06.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx06.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=berrange@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 7D592267CD From: "Daniel P. Berrange" To: qemu-devel@nongnu.org Date: Tue, 11 Jul 2017 13:44:11 +0100 Message-Id: <20170711124411.10499-6-berrange@redhat.com> In-Reply-To: <20170711124411.10499-1-berrange@redhat.com> References: <20170711124411.10499-1-berrange@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Tue, 11 Jul 2017 12:44:27 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL v1 5/5] tests: add functional test validating ipv4/ipv6 address flag handling X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" The semantics around handling ipv4=3Don|off & ipv6=3Don|off are quite subtle to understand in combination with the various hostname addresses and backend types. Introduce a massive test matrix that launches QEMU and validates the ability to connect a client on each protocol as appropriate. The test requires that the host has ability to bind to both :: and 0.0.0.0, on port 9000. If either protocol is not available, or if something is already listening on that port the test will skip. Although it isn't using the QTest APIs, it expects the QTEST_QEMU_BINARY env variable to be set. Reviewed-by: Eric Blake Tested-by: Eric Blake Signed-off-by: Daniel P. Berrange --- tests/.gitignore | 1 + tests/Makefile.include | 3 + tests/test-sockets-proto.c | 924 +++++++++++++++++++++++++++++++++++++++++= ++++ 3 files changed, 928 insertions(+) create mode 100644 tests/test-sockets-proto.c diff --git a/tests/.gitignore b/tests/.gitignore index 8e01b00..94d995b 100644 --- a/tests/.gitignore +++ b/tests/.gitignore @@ -75,6 +75,7 @@ test-qobject-output-visitor test-rcu-list test-replication test-shift128 +test-sockets-proto test-string-input-visitor test-string-output-visitor test-thread-pool diff --git a/tests/Makefile.include b/tests/Makefile.include index 18cd06a..77b70f2 100644 --- a/tests/Makefile.include +++ b/tests/Makefile.include @@ -337,6 +337,7 @@ check-qtest-s390x-y =3D tests/boot-serial-test$(EXESUF) =20 check-qtest-generic-y +=3D tests/qom-test$(EXESUF) check-qtest-generic-y +=3D tests/test-hmp$(EXESUF) +check-qtest-generic-y +=3D tests/test-sockets-proto$(EXESUF) =20 qapi-schema +=3D alternate-any.json qapi-schema +=3D alternate-array.json @@ -743,6 +744,8 @@ tests/usb-hcd-ehci-test$(EXESUF): tests/usb-hcd-ehci-te= st.o $(libqos-usb-obj-y) tests/usb-hcd-xhci-test$(EXESUF): tests/usb-hcd-xhci-test.o $(libqos-usb-o= bj-y) tests/pc-cpu-test$(EXESUF): tests/pc-cpu-test.o tests/postcopy-test$(EXESUF): tests/postcopy-test.o +tests/test-sockets-proto$(EXESUF): tests/test-sockets-proto.o \ + $(test-io-obj-y) tests/vhost-user-test$(EXESUF): tests/vhost-user-test.o $(test-util-obj-y)= \ $(qtest-obj-y) $(test-io-obj-y) $(libqos-virtio-obj-y) $(libqos-pc-obj-y)= \ $(chardev-obj-y) diff --git a/tests/test-sockets-proto.c b/tests/test-sockets-proto.c new file mode 100644 index 0000000..1d6beda --- /dev/null +++ b/tests/test-sockets-proto.c @@ -0,0 +1,924 @@ +/* + * QTest for IPv4/IPv6 protocol setup + * + * Copyright (c) 2017 Red Hat, Inc. + * + * This work is licensed under the terms of the GNU GPL, version 2 or late= r. + * See the COPYING file in the top-level directory. + * + */ + +#include "qemu/osdep.h" + +#include "io/channel-socket.h" +#include "qapi/error.h" +#include "qemu/cutils.h" + +typedef struct { + const char *name; + const char *args; + int ipv4; /* 0 -> disabled, 1 -> enabled */ + int ipv6; /* 0 -> disabled, 1 -> enabled, -1 -> check getaddrinfo() or= der */ + bool error; +} QSocketsData; + +/* + * This is the giant matrix of combinations we need to consider. + * There are 3 axes we deal with + * + * Axis 1: Protocol flags: + * + * ipv4=3Dunset, ipv6=3Dunset -> v4 & v6 clients ([1] + * ipv4=3Dunset, ipv6=3Doff -> v4 clients only + * ipv4=3Dunset, ipv6=3Don -> v6 clients only + * ipv4=3Doff, ipv6=3Dunset -> v6 clients only + * ipv4=3Doff, ipv6=3Doff -> error - can't disable both [2] + * ipv4=3Doff, ipv6=3Don -> v6 clients only + * ipv4=3Don, ipv6=3Dunset -> v4 clients only + * ipv4=3Don, ipv6=3Doff -> v4 clients only + * ipv4=3Don, ipv6=3Don -> v4 & v6 clients [3] + * + * Depending on the listening address, some of those combinations + * may result in errors. eg ipv4=3Doff,ipv6=3Don combined with 0.0.0.0 + * is nonsensical. + * + * [1] Some backends only support a single socket listener, so + * will actually only allow v4 clients + * [2] QEMU should fail to startup in this case + * [3] If hostname is "" or "::", then we get a single listener + * on IPv6 and thus can also accept v4 clients. For all other + * hostnames, have same problem as [1]. + * + * Axis 2: Listening address: + * + * "" - resolves to 0.0.0.0 and ::, in that order + * "0.0.0.0" - v4 clients only + * "::" - Mostly v6 clients only. Some scenarios should + * permit v4 clients too. + * + * Axis 3: Backend type: + * + * Migration - restricted to a single listener. Also relies + * on buggy inet_parse() which can't accept + * =3Doff/=3Don parameters to ipv4/ipv6 flags + * Chardevs - restricted to a single listener. + * VNC - supports multiple listeners. Also supports + * socket ranges, so has extra set of tests + * in the matrix + * + */ +static QSocketsData test_data[] =3D { + /* Migrate with "" address */ + /* XXX all settings with =3Doff are disabled due to inet_parse() bug */ + /* XXX multilistener bug - should be .ipv6 =3D 1 */ + { .ipv4 =3D 1, .ipv6 =3D -1, .error =3D false, + .name =3D "/sockets/migrate/wildcard/all", + .args =3D "-incoming tcp::9000" }, + { .ipv4 =3D 1, .ipv6 =3D 0, .error =3D false, + .name =3D "/sockets/migrate/wildcard/ipv4", + .args =3D "-incoming tcp::9000,ipv4" }, + { .ipv4 =3D 0, .ipv6 =3D 1, .error =3D false, + .name =3D "/sockets/migrate/wildcard/ipv6", + .args =3D "-incoming tcp::9000,ipv6" }, + { .ipv4 =3D 1, .ipv6 =3D 0, .error =3D false, + .name =3D "/sockets/migrate/wildcard/ipv4on", + .args =3D "-incoming tcp::9000,ipv4=3Don" }, + { .ipv4 =3D 0, .ipv6 =3D 1, .error =3D false, + .name =3D "/sockets/migrate/wildcard/ipv6on", + .args =3D "-incoming tcp::9000,ipv6=3Don" }, + /* + { .ipv4 =3D 0, .ipv6 =3D 1, .error =3D false, + .name =3D "/sockets/migrate/wildcard/ipv4off", + .args =3D "-incoming tcp::9000,ipv4=3Doff" }, + { .ipv4 =3D 1, .ipv6 =3D 0, .error =3D false, + .name =3D "/sockets/migrate/wildcard/ipv6off", + .args =3D "-incoming tcp::9000,ipv6=3Doff" }, + { .ipv4 =3D 1, .ipv6 =3D 0, .error =3D false, + .name =3D "/sockets/migrate/wildcard/ipv4onipv6off", + .args =3D "-incoming tcp::9000,ipv4=3Don,ipv6=3Doff" }, + { .ipv4 =3D 0, .ipv6 =3D 1, .error =3D false, + .name =3D "/sockets/migrate/wildcard/ipv4offipv6on", + .args =3D "-incoming tcp::9000,ipv4=3Doff,ipv6=3Don" }, + */ + { .ipv4 =3D 1, .ipv6 =3D 1, .error =3D false, + .name =3D "/sockets/migrate/wildcard/ipv4onipv6on", + .args =3D "-incoming tcp::9000,ipv4=3Don,ipv6=3Don" }, + /* + { .ipv4 =3D 0, .ipv6 =3D 0, .error =3D true, + .name =3D "/sockets/migrate/wildcard/ipv4offipv6off", + .args =3D "-incoming tcp::9000,ipv4=3Doff,ipv6=3Doff" }, + */ + + /* Migrate with 0.0.0.0 address */ + { .ipv4 =3D 1, .ipv6 =3D 0, .error =3D false, + .name =3D "/sockets/migrate/0.0.0.0/all", + .args =3D "-incoming tcp:0.0.0.0:9000" }, + { .ipv4 =3D 1, .ipv6 =3D 0, .error =3D false, + .name =3D "/sockets/migrate/0.0.0.0/ipv4", + .args =3D "-incoming tcp:0.0.0.0:9000,ipv4" }, + { .ipv4 =3D 0, .ipv6 =3D 0, .error =3D true, + .name =3D "/sockets/migrate/0.0.0.0/ipv6", + .args =3D "-incoming tcp:0.0.0.0:9000,ipv6" }, + { .ipv4 =3D 1, .ipv6 =3D 0, .error =3D false, + .name =3D "/sockets/migrate/0.0.0.0/ipv4on", + .args =3D "-incoming tcp:0.0.0.0:9000,ipv4=3Don" }, + { .ipv4 =3D 0, .ipv6 =3D 0, .error =3D true, + .name =3D "/sockets/migrate/0.0.0.0/ipv6on", + .args =3D "-incoming tcp:0.0.0.0:9000,ipv6=3Don" }, + /* + { .ipv4 =3D 0, .ipv6 =3D 0, .error =3D true, + .name =3D "/sockets/migrate/0.0.0.0/ipv4off", + .args =3D "-incoming tcp:0.0.0.0:9000,ipv4=3Doff" }, + { .ipv4 =3D 1, .ipv6 =3D 0, .error =3D false, + .name =3D "/sockets/migrate/0.0.0.0/ipv6off", + .args =3D "-incoming tcp:0.0.0.0:9000,ipv6=3Doff" }, + { .ipv4 =3D 1, .ipv6 =3D 0, .error =3D false, + .name =3D "/sockets/migrate/0.0.0.0/ipv4onipv6off", + .args =3D "-incoming tcp:0.0.0.0:9000,ipv4=3Don,ipv6=3Doff" }, + { .ipv4 =3D 0, .ipv6 =3D 0, .error =3D true, + .name =3D "/sockets/migrate/0.0.0.0/ipv4offipv6on", + .args =3D "-incoming tcp:0.0.0.0:9000,ipv4=3Doff,ipv6=3Don" }, + */ + { .ipv4 =3D 1, .ipv6 =3D 0, .error =3D false, + .name =3D "/sockets/migrate/0.0.0.0/ipv4onipv6on", + .args =3D "-incoming tcp:0.0.0.0:9000,ipv4=3Don,ipv6=3Don" }, + /* + { .ipv4 =3D 0, .ipv6 =3D 0, .error =3D true, + .name =3D "/sockets/migrate/0.0.0.0/ipv4offipv6off", + .args =3D "-incoming tcp:0.0.0.0:9000,ipv4=3Doff,ipv6=3Doff" }, + */ + + /* Migrate with :: address */ + { .ipv4 =3D 1, .ipv6 =3D 1, .error =3D false, + .name =3D "/sockets/migrate/::/all", + .args =3D "-incoming tcp:[::]:9000" }, + { .ipv4 =3D 0, .ipv6 =3D 0, .error =3D true, + .name =3D "/sockets/migrate/::/ipv4", + .args =3D "-incoming tcp:[::]:9000,ipv4" }, + { .ipv4 =3D 0, .ipv6 =3D 1, .error =3D false, + .name =3D "/sockets/migrate/::/ipv6", + .args =3D "-incoming tcp:[::]:9000,ipv6" }, + { .ipv4 =3D 0, .ipv6 =3D 0, .error =3D true, + .name =3D "/sockets/migrate/::/ipv4on", + .args =3D "-incoming tcp:[::]:9000,ipv4=3Don" }, + { .ipv4 =3D 0, .ipv6 =3D 1, .error =3D false, + .name =3D "/sockets/migrate/::/ipv6on", + .args =3D "-incoming tcp:[::]:9000,ipv6=3Don" }, + /* + { .ipv4 =3D 0, .ipv6 =3D 1, .error =3D false, + .name =3D "/sockets/migrate/::/ipv4off", + .args =3D "-incoming tcp:[::]:9000,ipv4=3Doff" }, + { .ipv4 =3D 0, .ipv6 =3D 0, .error =3D true, + .name =3D "/sockets/migrate/::/ipv6off", + .args =3D "-incoming tcp:[::]:9000,ipv6=3Doff" }, + { .ipv4 =3D 0, .ipv6 =3D 0, .error =3D true, + .name =3D "/sockets/migrate/::/ipv4onipv6off", + .args =3D "-incoming tcp:[::]:9000,ipv4=3Don,ipv6=3Doff" }, + { .ipv4 =3D 0, .ipv6 =3D 1, .error =3D false, + .name =3D "/sockets/migrate/::/ipv4offipv6on", + .args =3D "-incoming tcp:[::]:9000,ipv4=3Doff,ipv6=3Don" }, + */ + { .ipv4 =3D 1, .ipv6 =3D 1, .error =3D false, + .name =3D "/sockets/migrate/::/ipv4onipv6on", + .args =3D "-incoming tcp:[::]:9000,ipv4=3Don,ipv6=3Don" }, + /* + { .ipv4 =3D 0, .ipv6 =3D 0, .error =3D true, + .name =3D "/sockets/migrate/::/ipv4offipv6off", + .args =3D "-incoming tcp:[::]:9000,ipv4=3Doff,ipv6=3Doff" }, + */ + + + + /* Chardev with "" address */ + /* XXX multilistener bug - should be .ipv6 =3D 1 */ + { .ipv4 =3D 1, .ipv6 =3D -1, .error =3D false, + .name =3D "/sockets/chardev/wildcard/all", + .args =3D "-chardev socket,id=3Dcdev0,host=3D,port=3D9000,server,now= ait" }, + { .ipv4 =3D 1, .ipv6 =3D 0, .error =3D false, + .name =3D "/sockets/chardev/wildcard/ipv4", + .args =3D "-chardev socket,id=3Dcdev0,host=3D,port=3D9000,server,now= ait," + "ipv4" }, + { .ipv4 =3D 0, .ipv6 =3D 1, .error =3D false, + .name =3D "/sockets/chardev/wildcard/ipv6", + .args =3D "-chardev socket,id=3Dcdev0,host=3D,port=3D9000,server,now= ait," + "ipv6" }, + { .ipv4 =3D 1, .ipv6 =3D 0, .error =3D false, + .name =3D "/sockets/chardev/wildcard/ipv4on", + .args =3D "-chardev socket,id=3Dcdev0,host=3D,port=3D9000,server,now= ait," + "ipv4=3Don" }, + { .ipv4 =3D 0, .ipv6 =3D 1, .error =3D false, + .name =3D "/sockets/chardev/wildcard/ipv6on", + .args =3D "-chardev socket,id=3Dcdev0,host=3D,port=3D9000,server,now= ait," + "ipv6=3Don" }, + { .ipv4 =3D 0, .ipv6 =3D 1, .error =3D false, + .name =3D "/sockets/chardev/wildcard/ipv4off", + .args =3D "-chardev socket,id=3Dcdev0,host=3D,port=3D9000,server,now= ait," + "ipv4=3Doff" }, + { .ipv4 =3D 1, .ipv6 =3D 0, .error =3D false, + .name =3D "/sockets/chardev/wildcard/ipv6off", + .args =3D "-chardev socket,id=3Dcdev0,host=3D,port=3D9000,server,now= ait," + "ipv6=3Doff" }, + { .ipv4 =3D 1, .ipv6 =3D 0, .error =3D false, + .name =3D "/sockets/chardev/wildcard/ipv4onipv6off", + .args =3D "-chardev socket,id=3Dcdev0,host=3D,port=3D9000,server,now= ait," + "ipv4=3Don,ipv6=3Doff" }, + { .ipv4 =3D 0, .ipv6 =3D 1, .error =3D false, + .name =3D "/sockets/chardev/wildcard/ipv4offipv6on", + .args =3D "-chardev socket,id=3Dcdev0,host=3D,port=3D9000,server,now= ait," + "ipv4=3Doff,ipv6=3Don" }, + { .ipv4 =3D 1, .ipv6 =3D 1, .error =3D false, + .name =3D "/sockets/chardev/wildcard/ipv4onipv6on", + .args =3D "-chardev socket,id=3Dcdev0,host=3D,port=3D9000,server,now= ait," + "ipv4=3Don,ipv6=3Don" }, + { .ipv4 =3D 0, .ipv6 =3D 0, .error =3D true, + .name =3D "/sockets/chardev/wildcard/ipv4offipv6off", + .args =3D "-chardev socket,id=3Dcdev0,host=3D,port=3D9000,server,now= ait," + "ipv4=3Doff,ipv6=3Doff" }, + + /* Chardev with 0.0.0.0 address */ + { .ipv4 =3D 1, .ipv6 =3D 0, .error =3D false, + .name =3D "/sockets/chardev/0.0.0.0/all", + .args =3D "-chardev socket,id=3Dcdev0,host=3D0.0.0.0,port=3D9000,ser= ver,nowait" }, + { .ipv4 =3D 1, .ipv6 =3D 0, .error =3D false, + .name =3D "/sockets/chardev/0.0.0.0/ipv4", + .args =3D "-chardev socket,id=3Dcdev0,host=3D0.0.0.0,port=3D9000,ser= ver,nowait," + "ipv4" }, + { .ipv4 =3D 0, .ipv6 =3D 0, .error =3D true, + .name =3D "/sockets/chardev/0.0.0.0/ipv6", + .args =3D "-chardev socket,id=3Dcdev0,host=3D0.0.0.0,port=3D9000,ser= ver,nowait," + "ipv6" }, + { .ipv4 =3D 1, .ipv6 =3D 0, .error =3D false, + .name =3D "/sockets/chardev/0.0.0.0/ipv4on", + .args =3D "-chardev socket,id=3Dcdev0,host=3D0.0.0.0,port=3D9000,ser= ver,nowait," + "ipv4=3Don" }, + { .ipv4 =3D 0, .ipv6 =3D 0, .error =3D true, + .name =3D "/sockets/chardev/0.0.0.0/ipv6on", + .args =3D "-chardev socket,id=3Dcdev0,host=3D0.0.0.0,port=3D9000,ser= ver,nowait," + "ipv6=3Don" }, + { .ipv4 =3D 0, .ipv6 =3D 0, .error =3D true, + .name =3D "/sockets/chardev/0.0.0.0/ipv4off", + .args =3D "-chardev socket,id=3Dcdev0,host=3D0.0.0.0,port=3D9000,ser= ver,nowait," + "ipv4=3Doff" }, + { .ipv4 =3D 1, .ipv6 =3D 0, .error =3D false, + .name =3D "/sockets/chardev/0.0.0.0/ipv6off", + .args =3D "-chardev socket,id=3Dcdev0,host=3D0.0.0.0,port=3D9000,ser= ver,nowait," + "ipv6=3Doff" }, + { .ipv4 =3D 1, .ipv6 =3D 0, .error =3D false, + .name =3D "/sockets/chardev/0.0.0.0/ipv4onipv6off", + .args =3D "-chardev socket,id=3Dcdev0,host=3D0.0.0.0,port=3D9000,ser= ver,nowait," + "ipv4=3Don,ipv6=3Doff" }, + { .ipv4 =3D 0, .ipv6 =3D 0, .error =3D true, + .name =3D "/sockets/chardev/0.0.0.0/ipv4offipv6on", + .args =3D "-chardev socket,id=3Dcdev0,host=3D0.0.0.0,port=3D9000,ser= ver,nowait," + "ipv4=3Doff,ipv6=3Don" }, + { .ipv4 =3D 1, .ipv6 =3D 0, .error =3D false, + .name =3D "/sockets/chardev/0.0.0.0/ipv4onipv6on", + .args =3D "-chardev socket,id=3Dcdev0,host=3D0.0.0.0,port=3D9000,ser= ver,nowait," + "ipv4=3Don,ipv6=3Don" }, + { .ipv4 =3D 0, .ipv6 =3D 0, .error =3D true, + .name =3D "/sockets/chardev/0.0.0.0/ipv4offipv6off", + .args =3D "-chardev socket,id=3Dcdev0,host=3D0.0.0.0,port=3D9000,ser= ver,nowait," + "ipv4=3Doff,ipv6=3Doff" }, + + /* Chardev with :: address */ + { .ipv4 =3D 1, .ipv6 =3D 1, .error =3D false, + .name =3D "/sockets/chardev/::/all", + .args =3D "-chardev socket,id=3Dcdev0,host=3D::,port=3D9000,server,n= owait" }, + { .ipv4 =3D 0, .ipv6 =3D 0, .error =3D true, + .name =3D "/sockets/chardev/::/ipv4", + .args =3D "-chardev socket,id=3Dcdev0,host=3D::,port=3D9000,server,n= owait," + "ipv4" }, + { .ipv4 =3D 0, .ipv6 =3D 1, .error =3D false, + .name =3D "/sockets/chardev/::/ipv6", + .args =3D "-chardev socket,id=3Dcdev0,host=3D::,port=3D9000,server,n= owait," + "ipv6" }, + { .ipv4 =3D 0, .ipv6 =3D 0, .error =3D true, + .name =3D "/sockets/chardev/::/ipv4on", + .args =3D "-chardev socket,id=3Dcdev0,host=3D::,port=3D9000,server,n= owait," + "ipv4=3Don" }, + { .ipv4 =3D 0, .ipv6 =3D 1, .error =3D false, + .name =3D "/sockets/chardev/::/ipv6on", + .args =3D "-chardev socket,id=3Dcdev0,host=3D::,port=3D9000,server,n= owait," + "ipv6=3Don" }, + { .ipv4 =3D 0, .ipv6 =3D 1, .error =3D false, + .name =3D "/sockets/chardev/::/ipv4off", + .args =3D "-chardev socket,id=3Dcdev0,host=3D::,port=3D9000,server,n= owait," + "ipv4=3Doff" }, + { .ipv4 =3D 0, .ipv6 =3D 0, .error =3D true, + .name =3D "/sockets/chardev/::/ipv6off", + .args =3D "-chardev socket,id=3Dcdev0,host=3D::,port=3D9000,server,n= owait," + "ipv6=3Doff" }, + { .ipv4 =3D 0, .ipv6 =3D 0, .error =3D true, + .name =3D "/sockets/chardev/::/ipv4onipv6off", + .args =3D "-chardev socket,id=3Dcdev0,host=3D::,port=3D9000,server,n= owait," + "ipv4=3Don,ipv6=3Doff" }, + { .ipv4 =3D 0, .ipv6 =3D 1, .error =3D false, + .name =3D "/sockets/chardev/::/ipv4offipv6on", + .args =3D "-chardev socket,id=3Dcdev0,host=3D::,port=3D9000,server,n= owait," + "ipv4=3Doff,ipv6=3Don" }, + { .ipv4 =3D 1, .ipv6 =3D 1, .error =3D false, + .name =3D "/sockets/chardev/::/ipv4onipv6on", + .args =3D "-chardev socket,id=3Dcdev0,host=3D::,port=3D9000,server,n= owait," + "ipv4=3Don,ipv6=3Don" }, + { .ipv4 =3D 0, .ipv6 =3D 0, .error =3D true, + .name =3D "/sockets/chardev/::/ipv4offipv6off", + .args =3D "-chardev socket,id=3Dcdev0,host=3D::,port=3D9000,server,n= owait," + "ipv4=3Doff,ipv6=3Doff" }, + + + + /* Net with "" address */ + /* XXX does not yet support ipv4/ipv6 flags at all */ + /* XXX multilistener bug - should be .ipv6 =3D 1 */ + { .ipv4 =3D 1, .ipv6 =3D 0, .error =3D false, + .name =3D "/sockets/net/wildcard/all", + .args =3D "-netdev socket,id=3Dnet0,listen=3D:9000" }, + /* + { .ipv4 =3D 1, .ipv6 =3D 0, .error =3D false, + .name =3D "/sockets/net/wildcard/ipv4", + .args =3D "-netdev socket,id=3Dnet0,listen=3D:9000,ipv4" }, + { .ipv4 =3D 0, .ipv6 =3D 1, .error =3D false, + .name =3D "/sockets/net/wildcard/ipv6", + .args =3D "-netdev socket,id=3Dnet0,listen=3D:9000,ipv6" }, + { .ipv4 =3D 1, .ipv6 =3D 0, .error =3D false, + .name =3D "/sockets/net/wildcard/ipv4on", + .args =3D "-netdev socket,id=3Dnet0,listen=3D:9000,ipv4=3Don" }, + { .ipv4 =3D 0, .ipv6 =3D 1, .error =3D false, + .name =3D "/sockets/net/wildcard/ipv6on", + .args =3D "-netdev socket,id=3Dnet0,listen=3D:9000,ipv6=3Don" }, + { .ipv4 =3D 0, .ipv6 =3D 1, .error =3D false, + .name =3D "/sockets/net/wildcard/ipv4off", + .args =3D "-netdev socket,id=3Dnet0,listen=3D:9000,ipv4=3Doff" }, + { .ipv4 =3D 1, .ipv6 =3D 0, .error =3D false, + .name =3D "/sockets/net/wildcard/ipv6off", + .args =3D "-netdev socket,id=3Dnet0,listen=3D:9000,ipv6=3Doff" }, + { .ipv4 =3D 1, .ipv6 =3D 0, .error =3D false, + .name =3D "/sockets/net/wildcard/ipv4onipv6off", + .args =3D "-netdev socket,id=3Dnet0,listen=3D:9000,ipv4=3Don,ipv6=3D= off" }, + { .ipv4 =3D 0, .ipv6 =3D 1, .error =3D false, + .name =3D "/sockets/net/wildcard/ipv4offipv6on", + .args =3D "-netdev socket,id=3Dnet0,listen=3D:9000,ipv4=3Doff,ipv6= =3Don" }, + { .ipv4 =3D 1, .ipv6 =3D 1, .error =3D false, + .name =3D "/sockets/net/wildcard/ipv4onipv6on", + .args =3D "-netdev socket,id=3Dnet0,listen=3D:9000,ipv4=3Don,ipv6=3D= on" }, + { .ipv4 =3D 0, .ipv6 =3D 0, .error =3D true, + .name =3D "/sockets/net/wildcard/ipv4offipv6off", + .args =3D "-netdev socket,id=3Dnet0,listen=3D:9000,ipv4=3Doff,ipv6= =3Doff" }, + */ + + /* Net with 0.0.0.0 address */ + { .ipv4 =3D 1, .ipv6 =3D 0, .error =3D false, + .name =3D "/sockets/net/0.0.0.0/all", + .args =3D "-netdev socket,id=3Dnet0,listen=3D0.0.0.0:9000" }, + /* + { .ipv4 =3D 1, .ipv6 =3D 0, .error =3D false, + .name =3D "/sockets/net/0.0.0.0/ipv4", + .args =3D "-netdev socket,id=3Dnet0,listen=3D0.0.0.0:9000,ipv4" }, + { .ipv4 =3D 0, .ipv6 =3D 0, .error =3D true, + .name =3D "/sockets/net/0.0.0.0/ipv6", + .args =3D "-netdev socket,id=3Dnet0,listen=3D0.0.0.0:9000,ipv6" }, + { .ipv4 =3D 1, .ipv6 =3D 0, .error =3D false, + .name =3D "/sockets/net/0.0.0.0/ipv4on", + .args =3D "-netdev socket,id=3Dnet0,listen=3D0.0.0.0:9000,ipv4=3Don"= }, + { .ipv4 =3D 0, .ipv6 =3D 0, .error =3D true, + .name =3D "/sockets/net/0.0.0.0/ipv6on", + .args =3D "-netdev socket,id=3Dnet0,listen=3D0.0.0.0:9000,ipv6=3Don"= }, + { .ipv4 =3D 0, .ipv6 =3D 0, .error =3D true, + .name =3D "/sockets/net/0.0.0.0/ipv4off", + .args =3D "-netdev socket,id=3Dnet0,listen=3D0.0.0.0:9000,ipv4=3Doff= " }, + { .ipv4 =3D 1, .ipv6 =3D 0, .error =3D false, + .name =3D "/sockets/net/0.0.0.0/ipv6off", + .args =3D "-netdev socket,id=3Dnet0,listen=3D0.0.0.0:9000,ipv6=3Doff= " }, + { .ipv4 =3D 1, .ipv6 =3D 0, .error =3D false, + .name =3D "/sockets/net/0.0.0.0/ipv4onipv6off", + .args =3D "-netdev socket,id=3Dnet0,listen=3D0.0.0.0:9000,ipv4=3Don,= ipv6=3Doff" }, + { .ipv4 =3D 0, .ipv6 =3D 0, .error =3D true, + .name =3D "/sockets/net/0.0.0.0/ipv4offipv6on", + .args =3D "-netdev socket,id=3Dnet0,listen=3D0.0.0.0:9000,ipv4=3Doff= ,ipv6=3Don" }, + { .ipv4 =3D 1, .ipv6 =3D 0, .error =3D false, + .name =3D "/sockets/net/0.0.0.0/ipv4onipv6on", + .args =3D "-netdev socket,id=3Dnet0,listen=3D0.0.0.0:9000,ipv4=3Don,= ipv6=3Don" }, + { .ipv4 =3D 0, .ipv6 =3D 0, .error =3D true, + .name =3D "/sockets/net/0.0.0.0/ipv4offipv6off", + .args =3D "-netdev socket,id=3Dnet0,listen=3D0.0.0.0:9000,ipv4=3Doff= ,ipv6=3Doff" }, + */ + + /* Net with :: address */ + /* parse_host_port() doesn't cope with [] for IPv6 addrs + { .ipv4 =3D 1, .ipv6 =3D 1, .error =3D false, + .name =3D "/sockets/net/::/all", + .args =3D "-netdev socket,id=3Dnet0,listen=3D[::]:9000" }, + */ + /* + { .ipv4 =3D 0, .ipv6 =3D 0, .error =3D true, + .name =3D "/sockets/net/::/ipv4", + .args =3D "-netdev socket,id=3Dnet0,listen=3D[::]:9000,ipv4" }, + { .ipv4 =3D 0, .ipv6 =3D 1, .error =3D false, + .name =3D "/sockets/net/::/ipv6", + .args =3D "-netdev socket,id=3Dnet0,listen=3D[::]:9000,ipv6" }, + { .ipv4 =3D 0, .ipv6 =3D 0, .error =3D true, + .name =3D "/sockets/net/::/ipv4on", + .args =3D "-netdev socket,id=3Dnet0,listen=3D[::]:9000,ipv4=3Don" }, + { .ipv4 =3D 0, .ipv6 =3D 1, .error =3D false, + .name =3D "/sockets/net/::/ipv6on", + .args =3D "-netdev socket,id=3Dnet0,listen=3D[::]:9000,ipv6=3Don" }, + { .ipv4 =3D 0, .ipv6 =3D 1, .error =3D false, + .name =3D "/sockets/net/::/ipv4off", + .args =3D "-netdev socket,id=3Dnet0,listen=3D[::]:9000,ipv4=3Doff" }, + { .ipv4 =3D 0, .ipv6 =3D 0, .error =3D true, + .name =3D "/sockets/net/::/ipv6off", + .args =3D "-netdev socket,id=3Dnet0,listen=3D[::]:9000,ipv6=3Doff" }, + { .ipv4 =3D 0, .ipv6 =3D 0, .error =3D true, + .name =3D "/sockets/net/::/ipv4onipv6off", + .args =3D "-netdev socket,id=3Dnet0,listen=3D[::]:9000,ipv4=3Don,ipv= 6=3Doff" }, + { .ipv4 =3D 0, .ipv6 =3D 1, .error =3D false, + .name =3D "/sockets/net/::/ipv4offipv6on", + .args =3D "-netdev socket,id=3Dnet0,listen=3D[::]:9000,ipv4=3Doff,ip= v6=3Don" }, + { .ipv4 =3D 1, .ipv6 =3D 1, .error =3D false, + .name =3D "/sockets/net/::/ipv4onipv6on", + .args =3D "-netdev socket,id=3Dnet0,listen=3D[::]:9000,ipv4=3Don,ipv= 6=3Don" }, + { .ipv4 =3D 0, .ipv6 =3D 0, .error =3D true, + .name =3D "/sockets/net/::/ipv4offipv6off", + .args =3D "-netdev socket,id=3Dnet0,listen=3D[::]:9000,ipv4=3Doff,ip= v6=3Doff" }, + */ + + + /* VNC with "" address */ + { .ipv4 =3D 1, .ipv6 =3D 1, .error =3D false, + .name =3D "/sockets/vnc/wildcard/all", + .args =3D "-vnc :3100" }, + { .ipv4 =3D 1, .ipv6 =3D 0, .error =3D false, + .name =3D "/sockets/vnc/wildcard/ipv4", + .args =3D "-vnc :3100,ipv4" }, + { .ipv4 =3D 0, .ipv6 =3D 1, .error =3D false, + .name =3D "/sockets/vnc/wildcard/ipv6", + .args =3D "-vnc :3100,ipv6" }, + { .ipv4 =3D 1, .ipv6 =3D 0, .error =3D false, + .name =3D "/sockets/vnc/wildcard/ipv4on", + .args =3D "-vnc :3100,ipv4=3Don" }, + { .ipv4 =3D 0, .ipv6 =3D 1, .error =3D false, + .name =3D "/sockets/vnc/wildcard/ipv6on", + .args =3D "-vnc :3100,ipv6=3Don" }, + { .ipv4 =3D 0, .ipv6 =3D 1, .error =3D false, + .name =3D "/sockets/vnc/wildcard/ipv4off", + .args =3D "-vnc :3100,ipv4=3Doff" }, + { .ipv4 =3D 1, .ipv6 =3D 0, .error =3D false, + .name =3D "/sockets/vnc/wildcard/ipv6off", + .args =3D "-vnc :3100,ipv6=3Doff" }, + { .ipv4 =3D 1, .ipv6 =3D 0, .error =3D false, + .name =3D "/sockets/vnc/wildcard/ipv4onipv6off", + .args =3D "-vnc :3100,ipv4=3Don,ipv6=3Doff" }, + { .ipv4 =3D 0, .ipv6 =3D 1, .error =3D false, + .name =3D "/sockets/vnc/wildcard/ipv4offipv6on", + .args =3D "-vnc :3100,ipv4=3Doff,ipv6=3Don" }, + { .ipv4 =3D 1, .ipv6 =3D 1, .error =3D false, + .name =3D "/sockets/vnc/wildcard/ipv4onipv6on", + .args =3D "-vnc :3100,ipv4=3Don,ipv6=3Don" }, + { .ipv4 =3D 0, .ipv6 =3D 0, .error =3D true, + .name =3D "/sockets/vnc/wildcard/ipv4offipv6off", + .args =3D "-vnc :3100,ipv4=3Doff,ipv6=3Doff" }, + + /* VNC with 0.0.0.0 address */ + { .ipv4 =3D 1, .ipv6 =3D 0, .error =3D false, + .name =3D "/sockets/vnc/0.0.0.0/all", + .args =3D "-vnc 0.0.0.0:3100" }, + { .ipv4 =3D 1, .ipv6 =3D 0, .error =3D false, + .name =3D "/sockets/vnc/0.0.0.0/ipv4", + .args =3D "-vnc 0.0.0.0:3100,ipv4" }, + { .ipv4 =3D 0, .ipv6 =3D 0, .error =3D true, + .name =3D "/sockets/vnc/0.0.0.0/ipv6", + .args =3D "-vnc 0.0.0.0:3100,ipv6" }, + { .ipv4 =3D 1, .ipv6 =3D 0, .error =3D false, + .name =3D "/sockets/vnc/0.0.0.0/ipv4on", + .args =3D "-vnc 0.0.0.0:3100,ipv4=3Don" }, + { .ipv4 =3D 0, .ipv6 =3D 0, .error =3D true, + .name =3D "/sockets/vnc/0.0.0.0/ipv6on", + .args =3D "-vnc 0.0.0.0:3100,ipv6=3Don" }, + { .ipv4 =3D 0, .ipv6 =3D 0, .error =3D true, + .name =3D "/sockets/vnc/0.0.0.0/ipv4off", + .args =3D "-vnc 0.0.0.0:3100,ipv4=3Doff" }, + { .ipv4 =3D 1, .ipv6 =3D 0, .error =3D false, + .name =3D "/sockets/vnc/0.0.0.0/ipv6off", + .args =3D "-vnc 0.0.0.0:3100,ipv6=3Doff" }, + { .ipv4 =3D 1, .ipv6 =3D 0, .error =3D false, + .name =3D "/sockets/vnc/0.0.0.0/ipv4onipv6off", + .args =3D "-vnc 0.0.0.0:3100,ipv4=3Don,ipv6=3Doff" }, + { .ipv4 =3D 0, .ipv6 =3D 0, .error =3D true, + .name =3D "/sockets/vnc/0.0.0.0/ipv4offipv6on", + .args =3D "-vnc 0.0.0.0:3100,ipv4=3Doff,ipv6=3Don" }, + { .ipv4 =3D 1, .ipv6 =3D 0, .error =3D false, + .name =3D "/sockets/vnc/0.0.0.0/ipv4onipv6on", + .args =3D "-vnc 0.0.0.0:3100,ipv4=3Don,ipv6=3Don" }, + { .ipv4 =3D 0, .ipv6 =3D 0, .error =3D true, + .name =3D "/sockets/vnc/0.0.0.0/ipv4offipv6off", + .args =3D "-vnc 0.0.0.0:3100,ipv4=3Doff,ipv6=3Doff" }, + + /* VNC with :: address */ + { .ipv4 =3D 1, .ipv6 =3D 1, .error =3D false, + .name =3D "/sockets/vnc/::/all", + .args =3D "-vnc :::3100" }, + { .ipv4 =3D 0, .ipv6 =3D 0, .error =3D true, + .name =3D "/sockets/vnc/::/ipv4", + .args =3D "-vnc :::3100,ipv4" }, + { .ipv4 =3D 0, .ipv6 =3D 1, .error =3D false, + .name =3D "/sockets/vnc/::/ipv6", + .args =3D "-vnc :::3100,ipv6" }, + { .ipv4 =3D 0, .ipv6 =3D 0, .error =3D true, + .name =3D "/sockets/vnc/::/ipv4on", + .args =3D "-vnc :::3100,ipv4=3Don" }, + { .ipv4 =3D 0, .ipv6 =3D 1, .error =3D false, + .name =3D "/sockets/vnc/::/ipv6on", + .args =3D "-vnc :::3100,ipv6=3Don" }, + { .ipv4 =3D 0, .ipv6 =3D 1, .error =3D false, + .name =3D "/sockets/vnc/::/ipv4off", + .args =3D "-vnc :::3100,ipv4=3Doff" }, + { .ipv4 =3D 0, .ipv6 =3D 0, .error =3D true, + .name =3D "/sockets/vnc/::/ipv6off", + .args =3D "-vnc :::3100,ipv6=3Doff" }, + { .ipv4 =3D 0, .ipv6 =3D 0, .error =3D true, + .name =3D "/sockets/vnc/::/ipv4onipv6off", + .args =3D "-vnc :::3100,ipv4=3Don,ipv6=3Doff" }, + { .ipv4 =3D 0, .ipv6 =3D 1, .error =3D false, + .name =3D "/sockets/vnc/::/ipv4offipv6on", + .args =3D "-vnc :::3100,ipv4=3Doff,ipv6=3Don" }, + { .ipv4 =3D 1, .ipv6 =3D 1, .error =3D false, + .name =3D "/sockets/vnc/::/ipv4onipv6on", + .args =3D "-vnc :::3100,ipv4=3Don,ipv6=3Don" }, + { .ipv4 =3D 0, .ipv6 =3D 0, .error =3D true, + .name =3D "/sockets/vnc/::/ipv4offipv6off", + .args =3D "-vnc :::3100,ipv4=3Doff,ipv6=3Doff" }, + + + + /* VNC with "" address and range */ + { .ipv4 =3D 1, .ipv6 =3D 1, .error =3D false, + .name =3D "/sockets/vnc-to/wildcard/all", + .args =3D "-vnc :3100,to=3D9005" }, + { .ipv4 =3D 1, .ipv6 =3D 0, .error =3D false, + .name =3D "/sockets/vnc-to/wildcard/ipv4", + .args =3D "-vnc :3100,to=3D9005,ipv4" }, + { .ipv4 =3D 0, .ipv6 =3D 1, .error =3D false, + .name =3D "/sockets/vnc-to/wildcard/ipv6", + .args =3D "-vnc :3100,to=3D9005,ipv6" }, + { .ipv4 =3D 1, .ipv6 =3D 0, .error =3D false, + .name =3D "/sockets/vnc-to/wildcard/ipv4on", + .args =3D "-vnc :3100,to=3D9005,ipv4=3Don" }, + { .ipv4 =3D 0, .ipv6 =3D 1, .error =3D false, + .name =3D "/sockets/vnc-to/wildcard/ipv6on", + .args =3D "-vnc :3100,to=3D9005,ipv6=3Don" }, + { .ipv4 =3D 0, .ipv6 =3D 1, .error =3D false, + .name =3D "/sockets/vnc-to/wildcard/ipv4off", + .args =3D "-vnc :3100,to=3D9005,ipv4=3Doff" }, + { .ipv4 =3D 1, .ipv6 =3D 0, .error =3D false, + .name =3D "/sockets/vnc-to/wildcard/ipv6off", + .args =3D "-vnc :3100,to=3D9005,ipv6=3Doff" }, + { .ipv4 =3D 1, .ipv6 =3D 0, .error =3D false, + .name =3D "/sockets/vnc-to/wildcard/ipv4onipv6off", + .args =3D "-vnc :3100,to=3D9005,ipv4=3Don,ipv6=3Doff" }, + { .ipv4 =3D 0, .ipv6 =3D 1, .error =3D false, + .name =3D "/sockets/vnc-to/wildcard/ipv4offipv6on", + .args =3D "-vnc :3100,to=3D9005,ipv4=3Doff,ipv6=3Don" }, + { .ipv4 =3D 1, .ipv6 =3D 1, .error =3D false, + .name =3D "/sockets/vnc-to/wildcard/ipv4onipv6on", + .args =3D "-vnc :3100,to=3D9005,ipv4=3Don,ipv6=3Don" }, + { .ipv4 =3D 0, .ipv6 =3D 0, .error =3D true, + .name =3D "/sockets/vnc-to/wildcard/ipv4offipv6off", + .args =3D "-vnc :3100,to=3D9005,ipv4=3Doff,ipv6=3Doff" }, + + /* VNC with 0.0.0.0 address and range */ + { .ipv4 =3D 1, .ipv6 =3D 0, .error =3D false, + .name =3D "/sockets/vnc-to/0.0.0.0/all", + .args =3D "-vnc 0.0.0.0:3100,to=3D9005" }, + { .ipv4 =3D 1, .ipv6 =3D 0, .error =3D false, + .name =3D "/sockets/vnc-to/0.0.0.0/ipv4", + .args =3D "-vnc 0.0.0.0:3100,to=3D9005,ipv4" }, + { .ipv4 =3D 0, .ipv6 =3D 0, .error =3D true, + .name =3D "/sockets/vnc-to/0.0.0.0/ipv6", + .args =3D "-vnc 0.0.0.0:3100,to=3D9005,ipv6" }, + { .ipv4 =3D 1, .ipv6 =3D 0, .error =3D false, + .name =3D "/sockets/vnc-to/0.0.0.0/ipv4on", + .args =3D "-vnc 0.0.0.0:3100,to=3D9005,ipv4=3Don" }, + { .ipv4 =3D 0, .ipv6 =3D 0, .error =3D true, + .name =3D "/sockets/vnc-to/0.0.0.0/ipv6on", + .args =3D "-vnc 0.0.0.0:3100,to=3D9005,ipv6=3Don" }, + { .ipv4 =3D 0, .ipv6 =3D 0, .error =3D true, + .name =3D "/sockets/vnc-to/0.0.0.0/ipv4off", + .args =3D "-vnc 0.0.0.0:3100,to=3D9005,ipv4=3Doff" }, + { .ipv4 =3D 1, .ipv6 =3D 0, .error =3D false, + .name =3D "/sockets/vnc-to/0.0.0.0/ipv6off", + .args =3D "-vnc 0.0.0.0:3100,to=3D9005,ipv6=3Doff" }, + { .ipv4 =3D 1, .ipv6 =3D 0, .error =3D false, + .name =3D "/sockets/vnc-to/0.0.0.0/ipv4onipv6off", + .args =3D "-vnc 0.0.0.0:3100,to=3D9005,ipv4=3Don,ipv6=3Doff" }, + { .ipv4 =3D 0, .ipv6 =3D 0, .error =3D true, + .name =3D "/sockets/vnc-to/0.0.0.0/ipv4offipv6on", + .args =3D "-vnc 0.0.0.0:3100,to=3D9005,ipv4=3Doff,ipv6=3Don" }, + { .ipv4 =3D 1, .ipv6 =3D 0, .error =3D false, + .name =3D "/sockets/vnc-to/0.0.0.0/ipv4onipv6on", + .args =3D "-vnc 0.0.0.0:3100,to=3D9005,ipv4=3Don,ipv6=3Don" }, + { .ipv4 =3D 0, .ipv6 =3D 0, .error =3D true, + .name =3D "/sockets/vnc-to/0.0.0.0/ipv4offipv6off", + .args =3D "-vnc 0.0.0.0:3100,to=3D9005,ipv4=3Doff,ipv6=3Doff" }, + + /* VNC with :: address and range */ + { .ipv4 =3D 1, .ipv6 =3D 1, .error =3D false, + .name =3D "/sockets/vnc-to/::/all", + .args =3D "-vnc :::3100,to=3D9005" }, + { .ipv4 =3D 0, .ipv6 =3D 0, .error =3D true, + .name =3D "/sockets/vnc-to/::/ipv4", + .args =3D "-vnc :::3100,to=3D9005,ipv4" }, + { .ipv4 =3D 0, .ipv6 =3D 1, .error =3D false, + .name =3D "/sockets/vnc-to/::/ipv6", + .args =3D "-vnc :::3100,to=3D9005,ipv6" }, + { .ipv4 =3D 0, .ipv6 =3D 0, .error =3D true, + .name =3D "/sockets/vnc-to/::/ipv4on", + .args =3D "-vnc :::3100,to=3D9005,ipv4=3Don" }, + { .ipv4 =3D 0, .ipv6 =3D 1, .error =3D false, + .name =3D "/sockets/vnc-to/::/ipv6on", + .args =3D "-vnc :::3100,to=3D9005,ipv6=3Don" }, + { .ipv4 =3D 0, .ipv6 =3D 1, .error =3D false, + .name =3D "/sockets/vnc-to/::/ipv4off", + .args =3D "-vnc :::3100,to=3D9005,ipv4=3Doff" }, + { .ipv4 =3D 0, .ipv6 =3D 0, .error =3D true, + .name =3D "/sockets/vnc-to/::/ipv6off", + .args =3D "-vnc :::3100,to=3D9005,ipv6=3Doff" }, + { .ipv4 =3D 0, .ipv6 =3D 0, .error =3D true, + .name =3D "/sockets/vnc-to/::/ipv4onipv6off", + .args =3D "-vnc :::3100,to=3D9005,ipv4=3Don,ipv6=3Doff" }, + { .ipv4 =3D 0, .ipv6 =3D 1, .error =3D false, + .name =3D "/sockets/vnc-to/::/ipv4offipv6on", + .args =3D "-vnc :::3100,to=3D9005,ipv4=3Doff,ipv6=3Don" }, + { .ipv4 =3D 1, .ipv6 =3D 1, .error =3D false, + .name =3D "/sockets/vnc-to/::/ipv4onipv6on", + .args =3D "-vnc :::3100,to=3D9005,ipv4=3Don,ipv6=3Don" }, + { .ipv4 =3D 0, .ipv6 =3D 0, .error =3D true, + .name =3D "/sockets/vnc-to/::/ipv4offipv6off", + .args =3D "-vnc :::3100,to=3D9005,ipv4=3Doff,ipv6=3Doff" }, +}; + +static int check_bind(const char *hostname) +{ + int fd =3D -1; + struct addrinfo ai, *res =3D NULL; + int rc; + int ret =3D -1; + + memset(&ai, 0, sizeof(ai)); + ai.ai_flags =3D AI_CANONNAME | AI_ADDRCONFIG; + ai.ai_family =3D AF_UNSPEC; + ai.ai_socktype =3D SOCK_STREAM; + + /* lookup */ + rc =3D getaddrinfo(hostname, "9000", &ai, &res); + if (rc !=3D 0) { + goto cleanup; + } + + fd =3D qemu_socket(res->ai_family, res->ai_socktype, res->ai_protocol); + if (fd < 0) { + goto cleanup; + } + + if (bind(fd, res->ai_addr, res->ai_addrlen) < 0) { + goto cleanup; + } + + ret =3D 0; + + cleanup: + if (fd !=3D -1) { + close(fd); + } + if (res) { + freeaddrinfo(res); + } + return ret; +} + + +/* + * Validates that getaddrinfo() with a hostname of "", + * returns both an IPv4 and IPv6 address, and reports + * their order + * + * Returns: + * -1: if resolving "" didn't return IPv4+IPv6 addrs + * 0: if IPv4 addr is first + * 1: if IPv6 addr is first + */ +static int check_resolve_order(void) +{ + struct addrinfo ai, *res =3D NULL, *e; + int rc; + int ret =3D -1; + int ipv4_idx =3D -1, ipv6_idx =3D -1; + int idx; + + memset(&ai, 0, sizeof(ai)); + ai.ai_flags =3D AI_ADDRCONFIG | AI_PASSIVE; + ai.ai_family =3D AF_UNSPEC; + ai.ai_socktype =3D SOCK_STREAM; + + /* lookup */ + rc =3D getaddrinfo(NULL, "9000", &ai, &res); + if (rc !=3D 0) { + goto cleanup; + } + + for (e =3D res, idx =3D 0; e !=3D NULL; e =3D e->ai_next, idx++) { + if (e->ai_family =3D=3D AF_INET) { + ipv4_idx =3D idx; + } else if (e->ai_family =3D=3D AF_INET6) { + ipv6_idx =3D idx; + } else { + goto cleanup; + } + } + + if (ipv4_idx =3D=3D -1 || ipv6_idx =3D=3D -1) { + goto cleanup; + } + + if (ipv4_idx < ipv6_idx) { + ret =3D 0; + } else { + ret =3D 1; + } + + cleanup: + if (res) { + freeaddrinfo(res); + } + return ret; +} + +static int check_protocol_support(void) +{ + if (check_bind("0.0.0.0") < 0) { + return -1; + } + if (check_bind("::") < 0) { + return -1; + } + + return check_resolve_order(); +} + +static pid_t run_qemu(const char *args) +{ + const char *pidfile =3D "test-sockets-proto.pid"; + char *pidstr; + pid_t child; + int status; + pid_t ret; + const char *binary =3D getenv("QTEST_QEMU_BINARY"); + long pid =3D 0; + if (binary =3D=3D NULL) { + g_printerr("Missing QTEST_QEMU_BINARY env variable\n"); + exit(1); + } + + unlink(pidfile); + child =3D fork(); + if (child =3D=3D 0) { + setenv("QEMU_AUDIO_DRV", "none", true); + char *cmd =3D g_strdup_printf( + "exec %s -pidfile %s -daemonize -nodefconfig -nodefaults " + "-machine none -display none %s 1>/dev/null 2>&1", + binary, pidfile, args); + execlp("/bin/sh", "sh", "-c", cmd, NULL); + _exit(1); + } + + do { + ret =3D waitpid(child, &status, 0); + } while (ret =3D=3D -1 && errno =3D=3D EINTR); + + if (WEXITSTATUS(status) !=3D 0) { + goto cleanup; + } + + if (!g_file_get_contents(pidfile, &pidstr, NULL, NULL)) { + goto cleanup; + } + + qemu_strtol(pidstr, NULL, 0, &pid); + + cleanup: + unlink(pidfile); + return (pid_t)pid; +} + +static void test_listen(const void *opaque) +{ + const QSocketsData *data =3D opaque; + QIOChannelSocket *sioc; + SocketAddress *saddr; + Error *err =3D NULL; + pid_t child; + + /* First test IPv4 */ + saddr =3D g_new0(SocketAddress, 1); + saddr->type =3D SOCKET_ADDRESS_TYPE_INET; + saddr->u.inet.host =3D g_strdup("127.0.0.1"); + saddr->u.inet.port =3D g_strdup("9000"); + saddr->u.inet.has_ipv4 =3D true; + saddr->u.inet.ipv4 =3D true; + saddr->u.inet.has_ipv6 =3D true; + saddr->u.inet.ipv6 =3D false; + + child =3D run_qemu(data->args); + + if (!child) { + /* QEMU failed to start, so make sure we are expecting + * this scenario to fail + */ + g_assert(data->error); + goto cleanup; + } else { + g_assert(!data->error); + } + + sioc =3D qio_channel_socket_new(); + qio_channel_socket_connect_sync(sioc, saddr, &err); + + if (err !=3D NULL) { + /* We failed to connect to IPv4, make sure that + * matches the scenario expectation + */ + g_assert(data->ipv4 =3D=3D 0); + error_free(err); + err =3D NULL; + } else { + g_assert(data->ipv4 !=3D 0); + object_unref(OBJECT(sioc)); + } + + kill(child, SIGKILL); + + + /* Now test IPv6 */ + child =3D run_qemu(data->args); + + /* + * The child should always succeed, because its the + * same config as the successful run we just did above + */ + g_assert(child !=3D 0); + + g_free(saddr->u.inet.host); + saddr->u.inet.host =3D g_strdup("::1"); + saddr->u.inet.ipv4 =3D false; + saddr->u.inet.ipv6 =3D true; + + sioc =3D qio_channel_socket_new(); + qio_channel_socket_connect_sync(sioc, saddr, &err); + + if (err !=3D NULL) { + /* We failed to connect to IPv6, make sure that + * matches the scenario expectation + */ + g_assert(data->ipv6 =3D=3D 0); + error_free(err); + err =3D NULL; + } else { + g_assert(data->ipv6 !=3D 0); + object_unref(OBJECT(sioc)); + } + kill(child, SIGKILL); + + cleanup: + qapi_free_SocketAddress(saddr); +} + + +int main(int argc, char **argv) +{ + int ret; + gsize i; + int ipv6_first; + + ipv6_first =3D check_protocol_support(); + if (ipv6_first < 0) { + /* Skip test if we can't bind, or have unexpected + * results from getaddrinfo */ + return 0; + } + + signal(SIGPIPE, SIG_IGN); + + module_call_init(MODULE_INIT_QOM); + g_test_init(&argc, &argv, NULL); + + for (i =3D 0; i < G_N_ELEMENTS(test_data); i++) { + QSocketsData *data =3D &test_data[i]; + if (data->ipv6 =3D=3D -1) { + data->ipv6 =3D ipv6_first ? 1 : 0; + } + g_test_add_data_func(data->name, data, test_listen); + } + + ret =3D g_test_run(); + + return ret =3D=3D 0 ? EXIT_SUCCESS : EXIT_FAILURE; +} --=20 2.9.4