From nobody Fri Apr 19 22:55:24 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 1502381860764688.2801550397735; Thu, 10 Aug 2017 09:17:40 -0700 (PDT) Received: from localhost ([::1]:53967 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dfq9T-00006Z-9n for importer@patchew.org; Thu, 10 Aug 2017 12:17:39 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:45940) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dfpyY-0005kG-Ut for qemu-devel@nongnu.org; Thu, 10 Aug 2017 12:06:26 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dfpyU-0003SB-RA for qemu-devel@nongnu.org; Thu, 10 Aug 2017 12:06:22 -0400 Received: from mx1.redhat.com ([209.132.183.28]:55084) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dfpyL-0003NX-M6; Thu, 10 Aug 2017 12:06:10 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id AF4877BE49; Thu, 10 Aug 2017 16:06:08 +0000 (UTC) Received: from t460.lcy.redhat.com (unknown [10.42.22.189]) by smtp.corp.redhat.com (Postfix) with ESMTP id 70B638AD78; Thu, 10 Aug 2017 16:05:48 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com AF4877BE49 Authentication-Results: ext-mx01.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx01.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=berrange@redhat.com From: "Daniel P. Berrange" To: qemu-devel@nongnu.org Date: Thu, 10 Aug 2017 17:04:44 +0100 Message-Id: <20170810160451.32723-2-berrange@redhat.com> In-Reply-To: <20170810160451.32723-1-berrange@redhat.com> References: <20170810160451.32723-1-berrange@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Thu, 10 Aug 2017 16:06:08 +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] [PATCH 1/8] 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: Kevin Wolf , qemu-block@nongnu.org, Juan Quintela , "Dr. David Alan Gilbert" , Max Reitz , Gerd Hoffmann , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Paolo Bonzini 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 fed0189a5a..044183f4a0 100644 --- a/tests/.gitignore +++ b/tests/.gitignore @@ -78,6 +78,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 59e536bf0b..8caa5a7ae8 100644 --- a/tests/Makefile.include +++ b/tests/Makefile.include @@ -340,6 +340,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 @@ -750,6 +751,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 0000000000..1d6beda59f --- /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.13.3 From nobody Fri Apr 19 22:55:24 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 1502381961359968.9393762611426; Thu, 10 Aug 2017 09:19:21 -0700 (PDT) Received: from localhost ([::1]:53982 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dfqB5-0001PL-AQ for importer@patchew.org; Thu, 10 Aug 2017 12:19:19 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:46074) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dfpyk-0005uT-Ur for qemu-devel@nongnu.org; Thu, 10 Aug 2017 12:06:37 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dfpyi-0003ce-Eg for qemu-devel@nongnu.org; Thu, 10 Aug 2017 12:06:34 -0400 Received: from mx1.redhat.com ([209.132.183.28]:11613) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dfpyc-0003XR-De; Thu, 10 Aug 2017 12:06:26 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 6F075C04B93A; Thu, 10 Aug 2017 16:06:25 +0000 (UTC) Received: from t460.lcy.redhat.com (unknown [10.42.22.189]) by smtp.corp.redhat.com (Postfix) with ESMTP id 17BF58AD78; Thu, 10 Aug 2017 16:06:08 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 6F075C04B93A Authentication-Results: ext-mx07.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx07.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=berrange@redhat.com From: "Daniel P. Berrange" To: qemu-devel@nongnu.org Date: Thu, 10 Aug 2017 17:04:45 +0100 Message-Id: <20170810160451.32723-3-berrange@redhat.com> In-Reply-To: <20170810160451.32723-1-berrange@redhat.com> References: <20170810160451.32723-1-berrange@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Thu, 10 Aug 2017 16:06:25 +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] [PATCH 2/8] io: introduce a network socket listener API 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: Kevin Wolf , qemu-block@nongnu.org, Juan Quintela , "Dr. David Alan Gilbert" , Max Reitz , Gerd Hoffmann , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Paolo Bonzini 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 existing QIOChannelSocket class provides the ability to listen on a single socket at a time. This patch introduces a QIONetListener class that provides a higher level API concept around listening for network services, allowing for listening on multiple sockets. Signed-off-by: Daniel P. Berrange --- include/io/net-listener.h | 174 +++++++++++++++++++++++++ io/Makefile.objs | 1 + io/net-listener.c | 315 ++++++++++++++++++++++++++++++++++++++++++= ++++ 3 files changed, 490 insertions(+) create mode 100644 include/io/net-listener.h create mode 100644 io/net-listener.c diff --git a/include/io/net-listener.h b/include/io/net-listener.h new file mode 100644 index 0000000000..0ac5c9cc72 --- /dev/null +++ b/include/io/net-listener.h @@ -0,0 +1,174 @@ +/* + * QEMU I/O network listener + * + * Copyright (c) 2016 Red Hat, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, see . + * + */ + +#ifndef QIO_NET_LISTENER_H +#define QIO_NET_LISTENER_H + +#include "io/channel-socket.h" + +#define TYPE_QIO_NET_LISTENER "qio-net-listener" +#define QIO_NET_LISTENER(obj) \ + OBJECT_CHECK(QIONetListener, (obj), TYPE_QIO_NET_LISTENER) +#define QIO_NET_LISTENER_CLASS(klass) \ + OBJECT_CLASS_CHECK(QIONetListenerClass, klass, TYPE_QIO_NET_LISTENER) +#define QIO_NET_LISTENER_GET_CLASS(obj) \ + OBJECT_GET_CLASS(QIONetListenerClass, obj, TYPE_QIO_NET_LISTENER) + +typedef struct QIONetListener QIONetListener; +typedef struct QIONetListenerClass QIONetListenerClass; + +typedef void (*QIONetListenerClientFunc)(QIONetListener *listener, + QIOChannelSocket *sioc, + gpointer data); + +/** + * QIONetListener: + * + * The QIONetListener object encapsulates the management of a + * listening socket. It is able to listen on multiple sockets + * concurrently, to deal with the scenario where IPv4 / IPv6 + * needs separate sockets, or there is a need to listen on a + * subset of interface IP addresses, instead of the wildcard + * address. + */ +struct QIONetListener { + Object parent; + + char *name; + QIOChannelSocket **sioc; + gulong *io_tag; + size_t nsioc; + + gboolean disconnected; + + QIONetListenerClientFunc io_func; + gpointer io_data; + GDestroyNotify io_notify; +}; + +struct QIONetListenerClass { + ObjectClass parent; +}; + + +/** + * qio_net_listener_new: + * + * Create a new network listener service, which is not + * listening on any sockets initially. + * + * Returns: the new listener + */ +QIONetListener *qio_net_listener_new(void); + + +/** + * qio_net_listener_set_name: + * @listener: the network listener object + * @name: the listener name + * + * Set the name of the listener. This is used as a debugging + * aid, to set names on any GSource instances associated + * with the listener + */ +void qio_net_listener_set_name(QIONetListener *listener, + const char *name); + +/** + * qio_net_listener_open_sync: + * @listener: the network listener object + * @addr: the address to listen on + * @errp: pointer to a NULL initialized error object + * + * Synchronously open a listening connection on all + * addresses associated with @addr. This method may + * also be invoked multiple times, in order to have a + * single listener on multiple distinct addresses. + */ +int qio_net_listener_open_sync(QIONetListener *listener, + SocketAddress *addr, + Error **errp); + +/** + * qio_net_listener_add: + * @listener: the network listener object + * @sioc: the socket I/O channel + * + * Associate a listening socket I/O channel with the + * listener. The listener will acquire an new reference + * on @sioc, so the caller should release its own reference + * if it no longer requires the object. + */ +void qio_net_listener_add(QIONetListener *listener, + QIOChannelSocket *sioc); + +/** + * qio_net_listener_set_client_func: + * @listener: the network listener object + * @func: the callback function + * @data: opaque data to pass to @func + * @notify: callback to free @data + * + * Register @func to be invoked whenever a new client + * connects to the listener. @func will be invoked + * passing in the QIOChannelSocket instance for the + * client. + */ +void qio_net_listener_set_client_func(QIONetListener *listener, + QIONetListenerClientFunc func, + gpointer data, + GDestroyNotify notify); + +/** + * qio_net_listener_wait_client: + * @listener: the network listener object + * + * Block execution of the caller until a new client arrives + * on one of the listening sockets. If there was previously + * a callback registered with qio_net_listener_set_client_func + * it will be temporarily disabled, and re-enabled afterwards. + * + * Returns: the new client socket + */ +QIOChannelSocket *qio_net_listener_wait_client(QIONetListener *listener); + + +/** + * qio_net_listener_disconnect: + * @listener: the network listener object + * + * Disconnect the listener, removing all I/O callback + * watches and closing the socket channels. + */ +void qio_net_listener_disconnect(QIONetListener *listener); + + +/** + * qio_net_listener_is_disconnected: + * @listener: the network listener object + * + * Determine if the listener is connected to any socket + * channels + * + * Returns: TRUE if connected, FALSE otherwise + */ +gboolean qio_net_listener_is_disconnected(QIONetListener *listener); + +#endif /* QIO_NET_LISTENER_H */ diff --git a/io/Makefile.objs b/io/Makefile.objs index 12983cca79..9a20fce4ed 100644 --- a/io/Makefile.objs +++ b/io/Makefile.objs @@ -8,4 +8,5 @@ io-obj-y +=3D channel-watch.o io-obj-y +=3D channel-websock.o io-obj-y +=3D channel-util.o io-obj-y +=3D dns-resolver.o +io-obj-y +=3D net-listener.o io-obj-y +=3D task.o diff --git a/io/net-listener.c b/io/net-listener.c new file mode 100644 index 0000000000..065429f6fb --- /dev/null +++ b/io/net-listener.c @@ -0,0 +1,315 @@ +/* + * QEMU network listener + * + * Copyright (c) 2016 Red Hat, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, see . + * + */ + +#include "qemu/osdep.h" +#include "io/net-listener.h" +#include "io/dns-resolver.h" +#include "qapi/error.h" + +QIONetListener *qio_net_listener_new(void) +{ + QIONetListener *ret; + + ret =3D QIO_NET_LISTENER(object_new(TYPE_QIO_NET_LISTENER)); + + return ret; +} + +void qio_net_listener_set_name(QIONetListener *listener, + const char *name) +{ + g_free(listener->name); + listener->name =3D g_strdup(name); +} + + +static gboolean qio_net_listener_channel_func(QIOChannel *ioc, + GIOCondition condition, + gpointer opaque) +{ + QIONetListener *listener =3D QIO_NET_LISTENER(opaque); + QIOChannelSocket *sioc; + + sioc =3D qio_channel_socket_accept(QIO_CHANNEL_SOCKET(ioc), + NULL); + if (!sioc) { + return TRUE; + } + + if (listener->io_func) { + listener->io_func(listener, sioc, listener->io_data); + } + + object_unref(OBJECT(sioc)); + + return TRUE; +} + + +int qio_net_listener_open_sync(QIONetListener *listener, + SocketAddress *addr, + Error **errp) +{ + QIODNSResolver *resolver =3D qio_dns_resolver_get_instance(); + SocketAddress **resaddrs; + size_t nresaddrs; + size_t i; + Error *err =3D NULL; + bool success =3D false; + + if (qio_dns_resolver_lookup_sync(resolver, + addr, + &nresaddrs, + &resaddrs, + errp) < 0) { + return -1; + } + + for (i =3D 0; i < nresaddrs; i++) { + QIOChannelSocket *sioc =3D qio_channel_socket_new(); + + if (qio_channel_socket_listen_sync(sioc, resaddrs[i], + err ? NULL : &err) =3D=3D 0) { + success =3D true; + } + + qio_net_listener_add(listener, sioc); + + qapi_free_SocketAddress(resaddrs[i]); + object_unref(OBJECT(sioc)); + } + g_free(resaddrs); + + if (success) { + error_free(err); + return 0; + } else { + error_propagate(errp, err); + return -1; + } +} + + +void qio_net_listener_add(QIONetListener *listener, + QIOChannelSocket *sioc) +{ + if (listener->name) { + char *name =3D g_strdup_printf("%s-listen", listener->name); + qio_channel_set_name(QIO_CHANNEL(sioc), name); + g_free(name); + } + + listener->sioc =3D g_renew(QIOChannelSocket *, listener->sioc, + listener->nsioc + 1); + listener->io_tag =3D g_renew(gulong, listener->io_tag, listener->nsioc= + 1); + listener->sioc[listener->nsioc] =3D sioc; + listener->io_tag[listener->nsioc] =3D 0; + + object_ref(OBJECT(sioc)); + listener->disconnected =3D FALSE; + + if (listener->io_func !=3D NULL) { + object_ref(OBJECT(listener)); + listener->io_tag[listener->nsioc] =3D qio_channel_add_watch( + QIO_CHANNEL(listener->sioc[listener->nsioc]), G_IO_IN, + qio_net_listener_channel_func, + listener, (GDestroyNotify)object_unref); + } + + listener->nsioc++; +} + + +void qio_net_listener_set_client_func(QIONetListener *listener, + QIONetListenerClientFunc func, + gpointer data, + GDestroyNotify notify) +{ + size_t i; + + if (listener->io_notify) { + listener->io_notify(listener->io_data); + } + listener->io_func =3D func; + listener->io_data =3D data; + listener->io_notify =3D notify; + + for (i =3D 0; i < listener->nsioc; i++) { + if (listener->io_tag[i]) { + g_source_remove(listener->io_tag[i]); + listener->io_tag[i] =3D 0; + } + } + + if (listener->io_func !=3D NULL) { + for (i =3D 0; i < listener->nsioc; i++) { + object_ref(OBJECT(listener)); + listener->io_tag[i] =3D qio_channel_add_watch( + QIO_CHANNEL(listener->sioc[i]), G_IO_IN, + qio_net_listener_channel_func, + listener, (GDestroyNotify)object_unref); + } + } +} + + +struct QIONetListenerClientWaitData { + QIOChannelSocket *sioc; + GMainLoop *loop; +}; + + +static gboolean qio_net_listener_wait_client_func(QIOChannel *ioc, + GIOCondition condition, + gpointer opaque) +{ + struct QIONetListenerClientWaitData *data =3D opaque; + QIOChannelSocket *sioc; + + sioc =3D qio_channel_socket_accept(QIO_CHANNEL_SOCKET(ioc), + NULL); + if (!sioc) { + return TRUE; + } + + if (data->sioc) { + object_unref(OBJECT(sioc)); + } else { + data->sioc =3D sioc; + g_main_loop_quit(data->loop); + } + + return TRUE; +} + +QIOChannelSocket *qio_net_listener_wait_client(QIONetListener *listener) +{ + GMainContext *ctxt =3D g_main_context_new(); + GMainLoop *loop =3D g_main_loop_new(ctxt, TRUE); + GSource **sources; + struct QIONetListenerClientWaitData data =3D { + .sioc =3D NULL, + .loop =3D loop + }; + size_t i; + + for (i =3D 0; i < listener->nsioc; i++) { + if (listener->io_tag[i]) { + g_source_remove(listener->io_tag[i]); + listener->io_tag[i] =3D 0; + } + } + + sources =3D g_new0(GSource *, listener->nsioc); + for (i =3D 0; i < listener->nsioc; i++) { + sources[i] =3D qio_channel_create_watch(QIO_CHANNEL(listener->sioc= [i]), + G_IO_IN); + + g_source_set_callback(sources[i], + (GSourceFunc)qio_net_listener_wait_client_fu= nc, + &data, + NULL); + g_source_attach(sources[i], ctxt); + } + + g_main_loop_run(loop); + + for (i =3D 0; i < listener->nsioc; i++) { + g_source_unref(sources[i]); + } + g_main_loop_unref(loop); + g_main_context_unref(ctxt); + + if (listener->io_func !=3D NULL) { + for (i =3D 0; i < listener->nsioc; i++) { + object_ref(OBJECT(listener)); + listener->io_tag[i] =3D qio_channel_add_watch( + QIO_CHANNEL(listener->sioc[i]), G_IO_IN, + qio_net_listener_channel_func, + listener, (GDestroyNotify)object_unref); + } + } + + return data.sioc; +} + +void qio_net_listener_disconnect(QIONetListener *listener) +{ + size_t i; + + if (listener->disconnected) { + return; + } + + for (i =3D 0; i < listener->nsioc; i++) { + if (listener->io_tag[i]) { + g_source_remove(listener->io_tag[i]); + listener->io_tag[i] =3D 0; + } + qio_channel_close(QIO_CHANNEL(listener->sioc[i]), NULL); + } + listener->disconnected =3D TRUE; +} + + +gboolean qio_net_listener_is_disconnected(QIONetListener *listener) +{ + return listener->disconnected; +} + +static void qio_net_listener_init(Object *obj) +{ + QIONetListener *listener =3D QIO_NET_LISTENER(obj); + + listener->disconnected =3D TRUE; +} + +static void qio_net_listener_finalize(Object *obj) +{ + QIONetListener *listener =3D QIO_NET_LISTENER(obj); + size_t i; + + qio_net_listener_disconnect(listener); + + for (i =3D 0; i < listener->nsioc; i++) { + object_unref(OBJECT(listener->sioc[i])); + } + g_free(listener->io_tag); + g_free(listener->sioc); + g_free(listener->name); +} + +static const TypeInfo qio_net_listener_info =3D { + .parent =3D TYPE_OBJECT, + .name =3D TYPE_QIO_NET_LISTENER, + .instance_size =3D sizeof(QIONetListener), + .instance_finalize =3D qio_net_listener_finalize, + .instance_init =3D qio_net_listener_init, + .class_size =3D sizeof(QIONetListenerClass), +}; + + +static void qio_net_listener_register_types(void) +{ + type_register_static(&qio_net_listener_info); +} + + +type_init(qio_net_listener_register_types); --=20 2.13.3 From nobody Fri Apr 19 22:55:24 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 1502381538437256.2852362534803; Thu, 10 Aug 2017 09:12:18 -0700 (PDT) Received: from localhost ([::1]:53888 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dfq4G-0003hb-He for importer@patchew.org; Thu, 10 Aug 2017 12:12:16 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:46128) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dfpyt-00062O-Nb for qemu-devel@nongnu.org; Thu, 10 Aug 2017 12:06:45 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dfpys-0003fU-LG for qemu-devel@nongnu.org; Thu, 10 Aug 2017 12:06:43 -0400 Received: from mx1.redhat.com ([209.132.183.28]:40924) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dfpyn-0003de-M8; Thu, 10 Aug 2017 12:06:37 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id A29B396B3D; Thu, 10 Aug 2017 16:06:36 +0000 (UTC) Received: from t460.lcy.redhat.com (unknown [10.42.22.189]) by smtp.corp.redhat.com (Postfix) with ESMTP id C4ADB8AD79; Thu, 10 Aug 2017 16:06:25 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com A29B396B3D 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=fail smtp.mailfrom=berrange@redhat.com From: "Daniel P. Berrange" To: qemu-devel@nongnu.org Date: Thu, 10 Aug 2017 17:04:46 +0100 Message-Id: <20170810160451.32723-4-berrange@redhat.com> In-Reply-To: <20170810160451.32723-1-berrange@redhat.com> References: <20170810160451.32723-1-berrange@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Thu, 10 Aug 2017 16:06:36 +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] [PATCH 3/8] blockdev: convert internal NBD server to QIONetListener 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: Kevin Wolf , qemu-block@nongnu.org, Juan Quintela , "Dr. David Alan Gilbert" , Max Reitz , Gerd Hoffmann , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Paolo Bonzini 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" Instead of creating a QIOChannelSocket directly for the NBD server socket, use a QIONetListener. This provides the ability to listen on multiple sockets at the same time, so enables full support for IPv4/IPv6 dual stack. Signed-off-by: Daniel P. Berrange Reviewed-by: Eric Blake --- blockdev-nbd.c | 50 ++++++++++++++++---------------------------------- 1 file changed, 16 insertions(+), 34 deletions(-) diff --git a/blockdev-nbd.c b/blockdev-nbd.c index 28f551a7b0..9e3c22109c 100644 --- a/blockdev-nbd.c +++ b/blockdev-nbd.c @@ -18,10 +18,10 @@ #include "qmp-commands.h" #include "block/nbd.h" #include "io/channel-socket.h" +#include "io/net-listener.h" =20 typedef struct NBDServerData { - QIOChannelSocket *listen_ioc; - int watch; + QIONetListener *listener; QCryptoTLSCreds *tlscreds; } NBDServerData; =20 @@ -32,27 +32,13 @@ static void nbd_blockdev_client_closed(NBDClient *clien= t, bool ignored) nbd_client_put(client); } =20 -static gboolean nbd_accept(QIOChannel *ioc, GIOCondition condition, - gpointer opaque) +static void nbd_accept(QIONetListener *listener, QIOChannelSocket *cioc, + gpointer opaque) { - QIOChannelSocket *cioc; - - if (!nbd_server) { - return FALSE; - } - - cioc =3D qio_channel_socket_accept(QIO_CHANNEL_SOCKET(ioc), - NULL); - if (!cioc) { - return TRUE; - } - qio_channel_set_name(QIO_CHANNEL(cioc), "nbd-server"); nbd_client_new(NULL, cioc, nbd_server->tlscreds, NULL, nbd_blockdev_client_closed); - object_unref(OBJECT(cioc)); - return TRUE; } =20 =20 @@ -62,10 +48,8 @@ static void nbd_server_free(NBDServerData *server) return; } =20 - if (server->watch !=3D -1) { - g_source_remove(server->watch); - } - object_unref(OBJECT(server->listen_ioc)); + qio_net_listener_disconnect(server->listener); + object_unref(OBJECT(server->listener)); if (server->tlscreds) { object_unref(OBJECT(server->tlscreds)); } @@ -112,12 +96,12 @@ void nbd_server_start(SocketAddress *addr, const char = *tls_creds, } =20 nbd_server =3D g_new0(NBDServerData, 1); - nbd_server->watch =3D -1; - nbd_server->listen_ioc =3D qio_channel_socket_new(); - qio_channel_set_name(QIO_CHANNEL(nbd_server->listen_ioc), - "nbd-listener"); - if (qio_channel_socket_listen_sync( - nbd_server->listen_ioc, addr, errp) < 0) { + nbd_server->listener =3D qio_net_listener_new(); + + qio_net_listener_set_name(nbd_server->listener, + "nbd-listener"); + + if (qio_net_listener_open_sync(nbd_server->listener, addr, errp) < 0) { goto error; } =20 @@ -134,12 +118,10 @@ void nbd_server_start(SocketAddress *addr, const char= *tls_creds, } } =20 - nbd_server->watch =3D qio_channel_add_watch( - QIO_CHANNEL(nbd_server->listen_ioc), - G_IO_IN, - nbd_accept, - NULL, - NULL); + qio_net_listener_set_client_func(nbd_server->listener, + nbd_accept, + NULL, + NULL); =20 return; =20 --=20 2.13.3 From nobody Fri Apr 19 22:55:24 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 1502382036518482.2018927332932; Thu, 10 Aug 2017 09:20:36 -0700 (PDT) Received: from localhost ([::1]:53991 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dfqCI-0002UQ-Vg for importer@patchew.org; Thu, 10 Aug 2017 12:20:35 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:46216) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dfpz4-0006Fb-TR for qemu-devel@nongnu.org; Thu, 10 Aug 2017 12:06:56 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dfpz3-0003iV-Ks for qemu-devel@nongnu.org; Thu, 10 Aug 2017 12:06:54 -0400 Received: from mx1.redhat.com ([209.132.183.28]:33594) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dfpyy-0003h3-OC; Thu, 10 Aug 2017 12:06:48 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id B36107BE37; Thu, 10 Aug 2017 16:06:47 +0000 (UTC) Received: from t460.lcy.redhat.com (unknown [10.42.22.189]) by smtp.corp.redhat.com (Postfix) with ESMTP id 588A28AD95; Thu, 10 Aug 2017 16:06:36 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com B36107BE37 Authentication-Results: ext-mx01.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx01.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=berrange@redhat.com From: "Daniel P. Berrange" To: qemu-devel@nongnu.org Date: Thu, 10 Aug 2017 17:04:47 +0100 Message-Id: <20170810160451.32723-5-berrange@redhat.com> In-Reply-To: <20170810160451.32723-1-berrange@redhat.com> References: <20170810160451.32723-1-berrange@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Thu, 10 Aug 2017 16:06:47 +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] [PATCH 4/8] blockdev: convert qemu-nbd server to QIONetListener 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: Kevin Wolf , qemu-block@nongnu.org, Juan Quintela , "Dr. David Alan Gilbert" , Max Reitz , Gerd Hoffmann , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Paolo Bonzini 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" Instead of creating a QIOChannelSocket directly for the NBD server socket, use a QIONetListener. This provides the ability to listen on multiple sockets at the same time, so enables full support for IPv4/IPv6 dual stack. Signed-off-by: Daniel P. Berrange Reviewed-by: Eric Blake --- qemu-nbd.c | 50 +++++++++++++++++--------------------------------- 1 file changed, 17 insertions(+), 33 deletions(-) diff --git a/qemu-nbd.c b/qemu-nbd.c index b8666bb575..dcde7ac75c 100644 --- a/qemu-nbd.c +++ b/qemu-nbd.c @@ -38,6 +38,7 @@ #include "qapi/qmp/qstring.h" #include "qom/object_interfaces.h" #include "io/channel-socket.h" +#include "io/net-listener.h" #include "crypto/init.h" #include "trace/control.h" #include "qemu-version.h" @@ -63,8 +64,7 @@ static int persistent =3D 0; static enum { RUNNING, TERMINATE, TERMINATING, TERMINATED } state; static int shared =3D 1; static int nb_fds; -static QIOChannelSocket *server_ioc; -static int server_watch =3D -1; +static QIONetListener *server; static QCryptoTLSCreds *tlscreds; =20 static void usage(const char *name) @@ -345,44 +345,24 @@ static void nbd_client_closed(NBDClient *client, bool= negotiated) nbd_client_put(client); } =20 -static gboolean nbd_accept(QIOChannel *ioc, GIOCondition cond, gpointer op= aque) +static void nbd_accept(QIONetListener *listener, QIOChannelSocket *cioc, g= pointer opaque) { - QIOChannelSocket *cioc; - - cioc =3D qio_channel_socket_accept(QIO_CHANNEL_SOCKET(ioc), - NULL); - if (!cioc) { - return TRUE; - } - if (state >=3D TERMINATE) { - object_unref(OBJECT(cioc)); - return TRUE; + return; } =20 nb_fds++; nbd_update_server_watch(); nbd_client_new(newproto ? NULL : exp, cioc, tlscreds, NULL, nbd_client_closed); - object_unref(OBJECT(cioc)); - - return TRUE; } =20 static void nbd_update_server_watch(void) { if (nbd_can_accept()) { - if (server_watch =3D=3D -1) { - server_watch =3D qio_channel_add_watch(QIO_CHANNEL(server_ioc), - G_IO_IN, - nbd_accept, - NULL, NULL); - } + qio_net_listener_set_client_func(server, nbd_accept, NULL, NULL); } else { - if (server_watch !=3D -1) { - g_source_remove(server_watch); - server_watch =3D -1; - } + qio_net_listener_set_client_func(server, NULL, NULL, NULL); } } =20 @@ -917,24 +897,28 @@ int main(int argc, char **argv) snprintf(sockpath, 128, SOCKET_PATH, basename(device)); } =20 + server =3D qio_net_listener_new(); if (socket_activation =3D=3D 0) { - server_ioc =3D qio_channel_socket_new(); saddr =3D nbd_build_socket_address(sockpath, bindto, port); - if (qio_channel_socket_listen_sync(server_ioc, saddr, &local_err) = < 0) { - object_unref(OBJECT(server_ioc)); + if (qio_net_listener_open_sync(server, saddr, &local_err) < 0) { + object_unref(OBJECT(server)); error_report_err(local_err); - return 1; + exit(EXIT_FAILURE); } } else { + QIOChannelSocket *sioc; /* See comment in check_socket_activation above. */ assert(socket_activation =3D=3D 1); - server_ioc =3D qio_channel_socket_new_fd(FIRST_SOCKET_ACTIVATION_F= D, - &local_err); - if (server_ioc =3D=3D NULL) { + sioc =3D qio_channel_socket_new_fd(FIRST_SOCKET_ACTIVATION_FD, + &local_err); + if (sioc =3D=3D NULL) { + object_unref(OBJECT(server)); error_report("Failed to use socket activation: %s", error_get_pretty(local_err)); exit(EXIT_FAILURE); } + qio_net_listener_add(server, sioc); + object_unref(OBJECT(sioc)); } =20 if (qemu_init_main_loop(&local_err)) { --=20 2.13.3 From nobody Fri Apr 19 22:55:24 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 1502381702478819.7773194315994; Thu, 10 Aug 2017 09:15:02 -0700 (PDT) Received: from localhost ([::1]:53939 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dfq6v-00069o-3J for importer@patchew.org; Thu, 10 Aug 2017 12:15:01 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:46466) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dfpzG-0006OC-BA for qemu-devel@nongnu.org; Thu, 10 Aug 2017 12:07:07 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dfpzB-0003mc-Nm for qemu-devel@nongnu.org; Thu, 10 Aug 2017 12:07:06 -0400 Received: from mx1.redhat.com ([209.132.183.28]:45634) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dfpz5-0003j7-JB; Thu, 10 Aug 2017 12:06:55 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 9F8DC160B6E; Thu, 10 Aug 2017 16:06:54 +0000 (UTC) Received: from t460.lcy.redhat.com (unknown [10.42.22.189]) by smtp.corp.redhat.com (Postfix) with ESMTP id ED61E8AD70; Thu, 10 Aug 2017 16:06:47 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 9F8DC160B6E 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=fail smtp.mailfrom=berrange@redhat.com From: "Daniel P. Berrange" To: qemu-devel@nongnu.org Date: Thu, 10 Aug 2017 17:04:48 +0100 Message-Id: <20170810160451.32723-6-berrange@redhat.com> In-Reply-To: <20170810160451.32723-1-berrange@redhat.com> References: <20170810160451.32723-1-berrange@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.27]); Thu, 10 Aug 2017 16:06:54 +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] [PATCH 5/8] migration: convert socket server to QIONetListener 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: Kevin Wolf , qemu-block@nongnu.org, Juan Quintela , "Dr. David Alan Gilbert" , Max Reitz , Gerd Hoffmann , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Paolo Bonzini 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" Instead of creating a QIOChannelSocket directly for the migration server socket, use a QIONetListener. This provides the ability to listen on multiple sockets at the same time, so enables full support for IPv4/IPv6 dual stack. Signed-off-by: Daniel P. Berrange --- migration/socket.c | 44 ++++++++++++++----------------------------= -- tests/test-sockets-proto.c | 3 +-- 2 files changed, 15 insertions(+), 32 deletions(-) diff --git a/migration/socket.c b/migration/socket.c index 757d3821a1..34811addc5 100644 --- a/migration/socket.c +++ b/migration/socket.c @@ -24,6 +24,7 @@ #include "migration.h" #include "qemu-file.h" #include "io/channel-socket.h" +#include "io/net-listener.h" #include "trace.h" =20 =20 @@ -130,53 +131,36 @@ void unix_start_outgoing_migration(MigrationState *s, } =20 =20 -static gboolean socket_accept_incoming_migration(QIOChannel *ioc, - GIOCondition condition, - gpointer opaque) +static void socket_accept_incoming_migration(QIONetListener *listener, + QIOChannelSocket *cioc, + gpointer opaque) { - QIOChannelSocket *sioc; - Error *err =3D NULL; - - sioc =3D qio_channel_socket_accept(QIO_CHANNEL_SOCKET(ioc), - &err); - if (!sioc) { - error_report("could not accept migration connection (%s)", - error_get_pretty(err)); - goto out; - } - trace_migration_socket_incoming_accepted(); =20 - qio_channel_set_name(QIO_CHANNEL(sioc), "migration-socket-incoming"); - migration_channel_process_incoming(QIO_CHANNEL(sioc)); - object_unref(OBJECT(sioc)); + qio_channel_set_name(QIO_CHANNEL(cioc), "migration-socket-incoming"); + migration_channel_process_incoming(QIO_CHANNEL(cioc)); =20 -out: /* Close listening socket as its no longer needed */ - qio_channel_close(ioc, NULL); - return FALSE; /* unregister */ + qio_net_listener_disconnect(listener); + + object_unref(OBJECT(listener)); } =20 =20 static void socket_start_incoming_migration(SocketAddress *saddr, Error **errp) { - QIOChannelSocket *listen_ioc =3D qio_channel_socket_new(); + QIONetListener *listener =3D qio_net_listener_new(); =20 - qio_channel_set_name(QIO_CHANNEL(listen_ioc), - "migration-socket-listener"); + qio_net_listener_set_name(listener, "migration-socket-listener"); =20 - if (qio_channel_socket_listen_sync(listen_ioc, saddr, errp) < 0) { - object_unref(OBJECT(listen_ioc)); + if (qio_net_listener_open_sync(listener, saddr, errp) < 0) { + object_unref(OBJECT(listener)); qapi_free_SocketAddress(saddr); return; } =20 - qio_channel_add_watch(QIO_CHANNEL(listen_ioc), - G_IO_IN, - socket_accept_incoming_migration, - listen_ioc, - (GDestroyNotify)object_unref); + qio_net_listener_set_client_func(listener, socket_accept_incoming_migr= ation, NULL, NULL); qapi_free_SocketAddress(saddr); } =20 diff --git a/tests/test-sockets-proto.c b/tests/test-sockets-proto.c index 1d6beda59f..1495369696 100644 --- a/tests/test-sockets-proto.c +++ b/tests/test-sockets-proto.c @@ -70,8 +70,7 @@ typedef struct { 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, + { .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, --=20 2.13.3 From nobody Fri Apr 19 22:55:24 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 1502381859349865.9122138453679; Thu, 10 Aug 2017 09:17:39 -0700 (PDT) Received: from localhost ([::1]:53966 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dfq9R-00006I-Vl for importer@patchew.org; Thu, 10 Aug 2017 12:17:38 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:46545) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dfpzJ-0006Pf-7S for qemu-devel@nongnu.org; Thu, 10 Aug 2017 12:07:15 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dfpzH-0003rc-J2 for qemu-devel@nongnu.org; Thu, 10 Aug 2017 12:07:09 -0400 Received: from mx1.redhat.com ([209.132.183.28]:42333) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dfpzB-0003lj-9I; Thu, 10 Aug 2017 12:07:01 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 4D875ADAF4; Thu, 10 Aug 2017 16:07:00 +0000 (UTC) Received: from t460.lcy.redhat.com (unknown [10.42.22.189]) by smtp.corp.redhat.com (Postfix) with ESMTP id DFCB88AD70; Thu, 10 Aug 2017 16:06:54 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 4D875ADAF4 Authentication-Results: ext-mx01.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx01.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=berrange@redhat.com From: "Daniel P. Berrange" To: qemu-devel@nongnu.org Date: Thu, 10 Aug 2017 17:04:49 +0100 Message-Id: <20170810160451.32723-7-berrange@redhat.com> In-Reply-To: <20170810160451.32723-1-berrange@redhat.com> References: <20170810160451.32723-1-berrange@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Thu, 10 Aug 2017 16:07:00 +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] [PATCH 6/8] chardev: convert the socket server to QIONetListener 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: Kevin Wolf , qemu-block@nongnu.org, Juan Quintela , "Dr. David Alan Gilbert" , Max Reitz , Gerd Hoffmann , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Paolo Bonzini 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" Instead of creating a QIOChannelSocket directly for the chardev server socket, use a QIONetListener. This provides the ability to listen on multiple sockets at the same time, so enables full support for IPv4/IPv6 dual stack. Signed-off-by: Daniel P. Berrange --- chardev/char-socket.c | 70 ++++++++++++++++++------------------------= ---- tests/test-sockets-proto.c | 8 ++---- 2 files changed, 29 insertions(+), 49 deletions(-) diff --git a/chardev/char-socket.c b/chardev/char-socket.c index 1ae730a4cb..96ff2a3ff4 100644 --- a/chardev/char-socket.c +++ b/chardev/char-socket.c @@ -25,6 +25,7 @@ #include "chardev/char.h" #include "io/channel-socket.h" #include "io/channel-tls.h" +#include "io/net-listener.h" #include "qemu/error-report.h" #include "qapi/error.h" #include "qapi/clone-visitor.h" @@ -40,8 +41,7 @@ typedef struct { Chardev parent; QIOChannel *ioc; /* Client I/O channel */ QIOChannelSocket *sioc; /* Client master channel */ - QIOChannelSocket *listen_ioc; - guint listen_tag; + QIONetListener *listener; QCryptoTLSCreds *tls_creds; int connected; int max_size; @@ -93,9 +93,9 @@ static void check_report_connect_error(Chardev *chr, qemu_chr_socket_restart_timer(chr); } =20 -static gboolean tcp_chr_accept(QIOChannel *chan, - GIOCondition cond, - void *opaque); +static void tcp_chr_accept(QIONetListener *listener, + QIOChannelSocket *cioc, + void *opaque); =20 static int tcp_chr_read_poll(void *opaque); static void tcp_chr_disconnect(Chardev *chr); @@ -404,9 +404,8 @@ static void tcp_chr_disconnect(Chardev *chr) =20 tcp_chr_free_connection(chr); =20 - if (s->listen_ioc) { - s->listen_tag =3D qio_channel_add_watch( - QIO_CHANNEL(s->listen_ioc), G_IO_IN, tcp_chr_accept, chr, NULL= ); + if (s->listener) { + qio_net_listener_set_client_func(s->listener, tcp_chr_accept, chr,= NULL); } update_disconnected_filename(s); qemu_chr_be_event(chr, CHR_EVENT_CLOSED); @@ -704,9 +703,8 @@ static int tcp_chr_new_client(Chardev *chr, QIOChannelS= ocket *sioc) if (s->do_nodelay) { qio_channel_set_delay(s->ioc, false); } - if (s->listen_tag) { - g_source_remove(s->listen_tag); - s->listen_tag =3D 0; + if (s->listener) { + qio_net_listener_set_client_func(s->listener, NULL, NULL, NULL); } =20 if (s->tls_creds) { @@ -738,24 +736,14 @@ static int tcp_chr_add_client(Chardev *chr, int fd) return ret; } =20 -static gboolean tcp_chr_accept(QIOChannel *channel, - GIOCondition cond, - void *opaque) +static void tcp_chr_accept(QIONetListener *listener, + QIOChannelSocket *cioc, + void *opaque) { Chardev *chr =3D CHARDEV(opaque); - QIOChannelSocket *sioc; - - sioc =3D qio_channel_socket_accept(QIO_CHANNEL_SOCKET(channel), - NULL); - if (!sioc) { - return TRUE; - } - - tcp_chr_new_client(chr, sioc); =20 - object_unref(OBJECT(sioc)); - - return TRUE; + tcp_chr_set_client_ioc_name(chr, cioc); + tcp_chr_new_client(chr, cioc); } =20 static int tcp_chr_wait_connected(Chardev *chr, Error **errp) @@ -769,9 +757,10 @@ static int tcp_chr_wait_connected(Chardev *chr, Error = **errp) if (s->is_listen) { info_report("QEMU waiting for connection on: %s", chr->filename); - qio_channel_set_blocking(QIO_CHANNEL(s->listen_ioc), true, NUL= L); - tcp_chr_accept(QIO_CHANNEL(s->listen_ioc), G_IO_IN, chr); - qio_channel_set_blocking(QIO_CHANNEL(s->listen_ioc), false, NU= LL); + sioc =3D qio_net_listener_wait_client(s->listener); + tcp_chr_set_client_ioc_name(chr, sioc); + tcp_chr_new_client(chr, sioc); + object_unref(OBJECT(sioc)); } else { sioc =3D qio_channel_socket_new(); tcp_chr_set_client_ioc_name(chr, sioc); @@ -799,12 +788,9 @@ static void char_socket_finalize(Object *obj) s->reconnect_timer =3D 0; } qapi_free_SocketAddress(s->addr); - if (s->listen_tag) { - g_source_remove(s->listen_tag); - s->listen_tag =3D 0; - } - if (s->listen_ioc) { - object_unref(OBJECT(s->listen_ioc)); + if (s->listener) { + qio_net_listener_set_client_func(s->listener, NULL, NULL, NULL); + object_unref(OBJECT(s->listener)); } if (s->tls_creds) { object_unref(OBJECT(s->tls_creds)); @@ -937,29 +923,27 @@ static void qmp_chardev_open_socket(Chardev *chr, } else { if (s->is_listen) { char *name; - sioc =3D qio_channel_socket_new(); + s->listener =3D qio_net_listener_new(); =20 name =3D g_strdup_printf("chardev-tcp-listener-%s", chr->label= ); - qio_channel_set_name(QIO_CHANNEL(sioc), name); + qio_net_listener_set_name(s->listener, name); g_free(name); =20 - if (qio_channel_socket_listen_sync(sioc, s->addr, errp) < 0) { + if (qio_net_listener_open_sync(s->listener, s->addr, errp) < 0= ) { + object_unref(OBJECT(s->listener)); goto error; } =20 qapi_free_SocketAddress(s->addr); - s->addr =3D socket_local_address(sioc->fd, errp); + s->addr =3D socket_local_address(s->listener->sioc[0]->fd, err= p); update_disconnected_filename(s); =20 - s->listen_ioc =3D sioc; if (is_waitconnect && qemu_chr_wait_connected(chr, errp) < 0) { return; } if (!s->ioc) { - s->listen_tag =3D qio_channel_add_watch( - QIO_CHANNEL(s->listen_ioc), G_IO_IN, - tcp_chr_accept, chr, NULL); + qio_net_listener_set_client_func(s->listener, tcp_chr_acce= pt, chr, NULL); } } else if (qemu_chr_wait_connected(chr, errp) < 0) { goto error; diff --git a/tests/test-sockets-proto.c b/tests/test-sockets-proto.c index 1495369696..a92389bef6 100644 --- a/tests/test-sockets-proto.c +++ b/tests/test-sockets-proto.c @@ -18,7 +18,7 @@ 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 */ + int ipv6; /* 0 -> disabled, 1 -> enabled */ bool error; } QSocketsData; =20 @@ -189,8 +189,7 @@ static QSocketsData test_data[] =3D { =20 =20 /* Chardev with "" address */ - /* XXX multilistener bug - should be .ipv6 =3D 1 */ - { .ipv4 =3D 1, .ipv6 =3D -1, .error =3D false, + { .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, @@ -911,9 +910,6 @@ int main(int argc, char **argv) =20 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); } =20 --=20 2.13.3 From nobody Fri Apr 19 22:55:24 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 1502382205595688.3266377618716; Thu, 10 Aug 2017 09:23:25 -0700 (PDT) Received: from localhost ([::1]:54024 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dfqF2-0004t4-AO for importer@patchew.org; Thu, 10 Aug 2017 12:23:24 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:46709) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dfpzP-0006Xg-MC for qemu-devel@nongnu.org; Thu, 10 Aug 2017 12:07:17 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dfpzN-0003wM-Vq for qemu-devel@nongnu.org; Thu, 10 Aug 2017 12:07:15 -0400 Received: from mx1.redhat.com ([209.132.183.28]:56824) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dfpzI-0003rZ-6U; Thu, 10 Aug 2017 12:07:08 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 160DB6147D; Thu, 10 Aug 2017 16:07:07 +0000 (UTC) Received: from t460.lcy.redhat.com (unknown [10.42.22.189]) by smtp.corp.redhat.com (Postfix) with ESMTP id 8F83D8AD77; Thu, 10 Aug 2017 16:07:00 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 160DB6147D 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=fail smtp.mailfrom=berrange@redhat.com From: "Daniel P. Berrange" To: qemu-devel@nongnu.org Date: Thu, 10 Aug 2017 17:04:50 +0100 Message-Id: <20170810160451.32723-8-berrange@redhat.com> In-Reply-To: <20170810160451.32723-1-berrange@redhat.com> References: <20170810160451.32723-1-berrange@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.39]); Thu, 10 Aug 2017 16:07:07 +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] [PATCH 7/8] ui: convert VNC server to QIONetListener 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: Kevin Wolf , qemu-block@nongnu.org, Juan Quintela , "Dr. David Alan Gilbert" , Max Reitz , Gerd Hoffmann , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Paolo Bonzini 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 VNC server already has the ability to listen on multiple sockets. Converting it to use the QIONetListener APIs though, will reduce the amount of code in the VNC server and improve the clarity of what is left. Signed-off-by: Daniel P. Berrange --- ui/vnc.c | 194 ++++++++++++++++++-----------------------------------------= ---- ui/vnc.h | 9 +-- 2 files changed, 57 insertions(+), 146 deletions(-) diff --git a/ui/vnc.c b/ui/vnc.c index 651cbb8606..5b78541575 100644 --- a/ui/vnc.c +++ b/ui/vnc.c @@ -227,12 +227,12 @@ static VncServerInfo *vnc_server_info_get(VncDisplay = *vd) VncServerInfo *info; Error *err =3D NULL; =20 - if (!vd->nlsock) { + if (!vd->listener || !vd->listener->nsioc) { return NULL; } =20 info =3D g_malloc0(sizeof(*info)); - vnc_init_basic_info_from_server_addr(vd->lsock[0], + vnc_init_basic_info_from_server_addr(vd->listener->sioc[0], qapi_VncServerInfo_base(info), &e= rr); info->has_auth =3D true; info->auth =3D g_strdup(vnc_auth_name(vd)); @@ -378,7 +378,7 @@ VncInfo *qmp_query_vnc(Error **errp) VncDisplay *vd =3D vnc_display_find(NULL); SocketAddress *addr =3D NULL; =20 - if (vd =3D=3D NULL || !vd->nlsock) { + if (vd =3D=3D NULL || !vd->listener || !vd->listener->nsioc) { info->enabled =3D false; } else { info->enabled =3D true; @@ -387,11 +387,7 @@ VncInfo *qmp_query_vnc(Error **errp) info->has_clients =3D true; info->clients =3D qmp_query_client_list(vd); =20 - if (vd->lsock =3D=3D NULL) { - return info; - } - - addr =3D qio_channel_socket_get_local_address(vd->lsock[0], errp); + addr =3D qio_channel_socket_get_local_address(vd->listener->sioc[0= ], errp); if (!addr) { goto out_error; } @@ -571,13 +567,14 @@ VncInfo2List *qmp_query_vnc_servers(Error **errp) info->has_display =3D true; info->display =3D g_strdup(dev->id); } - for (i =3D 0; i < vd->nlsock; i++) { + for (i =3D 0; vd->listener !=3D NULL && i < vd->listener->nsioc; i= ++) { info->server =3D qmp_query_server_entry( - vd->lsock[i], false, vd->auth, vd->subauth, info->server); + vd->listener->sioc[i], false, vd->auth, vd->subauth, + info->server); } - for (i =3D 0; i < vd->nlwebsock; i++) { + for (i =3D 0; vd->wslistener !=3D NULL && i < vd->wslistener->nsio= c; i++) { info->server =3D qmp_query_server_entry( - vd->lwebsock[i], true, vd->ws_auth, + vd->wslistener->sioc[i], true, vd->ws_auth, vd->ws_subauth, info->server); } =20 @@ -2991,36 +2988,18 @@ void vnc_start_protocol(VncState *vs) qemu_add_mouse_mode_change_notifier(&vs->mouse_mode_notifier); } =20 -static gboolean vnc_listen_io(QIOChannel *ioc, - GIOCondition condition, - void *opaque) +static void vnc_listen_io(QIONetListener *listener, + QIOChannelSocket *cioc, + void *opaque) { VncDisplay *vd =3D opaque; - QIOChannelSocket *sioc =3D NULL; - Error *err =3D NULL; - bool isWebsock =3D false; - size_t i; - - for (i =3D 0; i < vd->nlwebsock; i++) { - if (ioc =3D=3D QIO_CHANNEL(vd->lwebsock[i])) { - isWebsock =3D true; - break; - } - } - - sioc =3D qio_channel_socket_accept(QIO_CHANNEL_SOCKET(ioc), &err); - if (sioc !=3D NULL) { - qio_channel_set_name(QIO_CHANNEL(sioc), - isWebsock ? "vnc-ws-server" : "vnc-server"); - qio_channel_set_delay(QIO_CHANNEL(sioc), false); - vnc_connect(vd, sioc, false, isWebsock); - object_unref(OBJECT(sioc)); - } else { - /* client probably closed connection before we got there */ - error_free(err); - } + bool isWebsock =3D listener =3D=3D vd->wslistener; =20 - return TRUE; + qio_channel_set_name(QIO_CHANNEL(cioc), + isWebsock ? "vnc-ws-server" : "vnc-server"); + qio_channel_set_delay(QIO_CHANNEL(cioc), false); + vnc_connect(vd, cioc, false, isWebsock); + object_unref(OBJECT(cioc)); } =20 static const DisplayChangeListenerOps dcl_ops =3D { @@ -3072,34 +3051,22 @@ void vnc_display_init(const char *id) =20 static void vnc_display_close(VncDisplay *vd) { - size_t i; if (!vd) { return; } vd->is_unix =3D false; - for (i =3D 0; i < vd->nlsock; i++) { - if (vd->lsock_tag[i]) { - g_source_remove(vd->lsock_tag[i]); - } - object_unref(OBJECT(vd->lsock[i])); + + if (vd->listener) { + qio_net_listener_disconnect(vd->listener); + object_unref(OBJECT(vd->listener)); } - g_free(vd->lsock); - g_free(vd->lsock_tag); - vd->lsock =3D NULL; - vd->lsock_tag =3D NULL; - vd->nlsock =3D 0; + vd->listener =3D NULL; =20 - for (i =3D 0; i < vd->nlwebsock; i++) { - if (vd->lwebsock_tag[i]) { - g_source_remove(vd->lwebsock_tag[i]); - } - object_unref(OBJECT(vd->lwebsock[i])); + if (vd->wslistener) { + qio_net_listener_disconnect(vd->wslistener); + object_unref(OBJECT(vd->wslistener)); } - g_free(vd->lwebsock); - g_free(vd->lwebsock_tag); - vd->lwebsock =3D NULL; - vd->lwebsock_tag =3D NULL; - vd->nlwebsock =3D 0; + vd->wslistener =3D NULL; =20 vd->auth =3D VNC_AUTH_INVALID; vd->subauth =3D VNC_AUTH_INVALID; @@ -3151,11 +3118,11 @@ static void vnc_display_print_local_addr(VncDisplay= *vd) SocketAddress *addr; Error *err =3D NULL; =20 - if (!vd->nlsock) { + if (!vd->listener || !vd->listener->nsioc) { return; } =20 - addr =3D qio_channel_socket_get_local_address(vd->lsock[0], &err); + addr =3D qio_channel_socket_get_local_address(vd->listener->sioc[0], &= err); if (!addr) { return; } @@ -3663,68 +3630,6 @@ static int vnc_display_connect(VncDisplay *vd, } =20 =20 -static int vnc_display_listen_addr(VncDisplay *vd, - SocketAddress *addr, - const char *name, - QIOChannelSocket ***lsock, - guint **lsock_tag, - size_t *nlsock, - Error **errp) -{ - QIODNSResolver *resolver =3D qio_dns_resolver_get_instance(); - SocketAddress **rawaddrs =3D NULL; - size_t nrawaddrs =3D 0; - Error *listenerr =3D NULL; - bool listening =3D false; - size_t i; - - if (qio_dns_resolver_lookup_sync(resolver, addr, &nrawaddrs, - &rawaddrs, errp) < 0) { - return -1; - } - - for (i =3D 0; i < nrawaddrs; i++) { - QIOChannelSocket *sioc =3D qio_channel_socket_new(); - - qio_channel_set_name(QIO_CHANNEL(sioc), name); - if (qio_channel_socket_listen_sync( - sioc, rawaddrs[i], listenerr =3D=3D NULL ? &listenerr : NU= LL) < 0) { - object_unref(OBJECT(sioc)); - continue; - } - listening =3D true; - (*nlsock)++; - *lsock =3D g_renew(QIOChannelSocket *, *lsock, *nlsock); - *lsock_tag =3D g_renew(guint, *lsock_tag, *nlsock); - - (*lsock)[*nlsock - 1] =3D sioc; - (*lsock_tag)[*nlsock - 1] =3D 0; - } - - for (i =3D 0; i < nrawaddrs; i++) { - qapi_free_SocketAddress(rawaddrs[i]); - } - g_free(rawaddrs); - - if (listenerr) { - if (!listening) { - error_propagate(errp, listenerr); - return -1; - } else { - error_free(listenerr); - } - } - - for (i =3D 0; i < *nlsock; i++) { - (*lsock_tag)[i] =3D qio_channel_add_watch( - QIO_CHANNEL((*lsock)[i]), - G_IO_IN, vnc_listen_io, vd, NULL); - } - - return 0; -} - - static int vnc_display_listen(VncDisplay *vd, SocketAddress **saddr, size_t nsaddr, @@ -3734,25 +3639,34 @@ static int vnc_display_listen(VncDisplay *vd, { size_t i; =20 - for (i =3D 0; i < nsaddr; i++) { - if (vnc_display_listen_addr(vd, saddr[i], - "vnc-listen", - &vd->lsock, - &vd->lsock_tag, - &vd->nlsock, - errp) < 0) { - return -1; + if (nsaddr) { + vd->listener =3D qio_net_listener_new(); + qio_net_listener_set_name(vd->listener, "vnc-listen"); + for (i =3D 0; i < nsaddr; i++) { + if (qio_net_listener_open_sync(vd->listener, + saddr[i], + errp) < 0) { + return -1; + } } + + qio_net_listener_set_client_func(vd->listener, + vnc_listen_io, vd, NULL); } - for (i =3D 0; i < nwsaddr; i++) { - if (vnc_display_listen_addr(vd, wsaddr[i], - "vnc-ws-listen", - &vd->lwebsock, - &vd->lwebsock_tag, - &vd->nlwebsock, - errp) < 0) { - return -1; + + if (nwsaddr) { + vd->wslistener =3D qio_net_listener_new(); + qio_net_listener_set_name(vd->wslistener, "vnc-ws-listen"); + for (i =3D 0; i < nwsaddr; i++) { + if (qio_net_listener_open_sync(vd->wslistener, + wsaddr[i], + errp) < 0) { + return -1; + } } + + qio_net_listener_set_client_func(vd->wslistener, + vnc_listen_io, vd, NULL); } =20 return 0; diff --git a/ui/vnc.h b/ui/vnc.h index 694cf32ca9..d6f685b473 100644 --- a/ui/vnc.h +++ b/ui/vnc.h @@ -37,6 +37,7 @@ #include "qemu/buffer.h" #include "io/channel-socket.h" #include "io/channel-tls.h" +#include "io/net-listener.h" #include =20 #include "keymaps.h" @@ -146,12 +147,8 @@ struct VncDisplay int num_exclusive; int connections_limit; VncSharePolicy share_policy; - size_t nlsock; - QIOChannelSocket **lsock; - guint *lsock_tag; - size_t nlwebsock; - QIOChannelSocket **lwebsock; - guint *lwebsock_tag; + QIONetListener *listener; + QIONetListener *wslistener; DisplaySurface *ds; DisplayChangeListener dcl; kbd_layout_t *kbd_layout; --=20 2.13.3 From nobody Fri Apr 19 22:55:24 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 1502382036734812.6663063866642; Thu, 10 Aug 2017 09:20:36 -0700 (PDT) Received: from localhost ([::1]:53990 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dfqCJ-0002UE-5x for importer@patchew.org; Thu, 10 Aug 2017 12:20:35 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:46752) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dfpzR-0006Z5-3S for qemu-devel@nongnu.org; Thu, 10 Aug 2017 12:07:18 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dfpzP-0003xH-KW for qemu-devel@nongnu.org; Thu, 10 Aug 2017 12:07:17 -0400 Received: from mx1.redhat.com ([209.132.183.28]:38358) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dfpzK-0003tl-Ml; Thu, 10 Aug 2017 12:07:10 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id A3244B2CE; Thu, 10 Aug 2017 16:07:09 +0000 (UTC) Received: from t460.lcy.redhat.com (unknown [10.42.22.189]) by smtp.corp.redhat.com (Postfix) with ESMTP id 54BE56BF7C; Thu, 10 Aug 2017 16:07:07 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com A3244B2CE 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=fail smtp.mailfrom=berrange@redhat.com From: "Daniel P. Berrange" To: qemu-devel@nongnu.org Date: Thu, 10 Aug 2017 17:04:51 +0100 Message-Id: <20170810160451.32723-9-berrange@redhat.com> In-Reply-To: <20170810160451.32723-1-berrange@redhat.com> References: <20170810160451.32723-1-berrange@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Thu, 10 Aug 2017 16:07:09 +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] [PATCH 8/8] sockets: fix parsing of ipv4/ipv6 opts in parse_socket_addr 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: Kevin Wolf , qemu-block@nongnu.org, Juan Quintela , "Dr. David Alan Gilbert" , Max Reitz , Gerd Hoffmann , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Paolo Bonzini 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 inet_parse() function looks for 'ipv4' and 'ipv6' flags, but only treats them as bare bool flags. The normal QemuOpts parsing would allow on/off values to be set too. This updated inet_parse() so that its handling of the 'ipv4' and 'ipv6' flags matches that done by QemuOpts. Signed-off-by: Daniel P. Berrange Reviewed-by: Eric Blake --- tests/test-sockets-proto.c | 13 ------------- util/qemu-sockets.c | 36 ++++++++++++++++++++++++++++++++---- 2 files changed, 32 insertions(+), 17 deletions(-) diff --git a/tests/test-sockets-proto.c b/tests/test-sockets-proto.c index a92389bef6..5805d2be5f 100644 --- a/tests/test-sockets-proto.c +++ b/tests/test-sockets-proto.c @@ -69,7 +69,6 @@ typedef struct { */ static QSocketsData test_data[] =3D { /* Migrate with "" address */ - /* XXX all settings with =3Doff are disabled due to inet_parse() bug */ { .ipv4 =3D 1, .ipv6 =3D 1, .error =3D false, .name =3D "/sockets/migrate/wildcard/all", .args =3D "-incoming tcp::9000" }, @@ -85,7 +84,6 @@ static QSocketsData test_data[] =3D { { .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" }, @@ -98,15 +96,12 @@ static QSocketsData test_data[] =3D { { .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" }, - */ =20 /* Migrate with 0.0.0.0 address */ { .ipv4 =3D 1, .ipv6 =3D 0, .error =3D false, @@ -124,7 +119,6 @@ static QSocketsData test_data[] =3D { { .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" }, @@ -137,15 +131,12 @@ static QSocketsData test_data[] =3D { { .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" }, - */ =20 /* Migrate with :: address */ { .ipv4 =3D 1, .ipv6 =3D 1, .error =3D false, @@ -163,7 +154,6 @@ static QSocketsData test_data[] =3D { { .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" }, @@ -176,15 +166,12 @@ static QSocketsData test_data[] =3D { { .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" }, - */ =20 =20 =20 diff --git a/util/qemu-sockets.c b/util/qemu-sockets.c index 1358c81bcc..76202949f5 100644 --- a/util/qemu-sockets.c +++ b/util/qemu-sockets.c @@ -616,6 +616,25 @@ err: } =20 /* compatibility wrapper */ +static int inet_parse_flag(const char *flagname, const char *optstr, bool = *val, + Error **errp) +{ + char *end; + size_t len; + + end =3D strstr(optstr, ","); + len =3D end ? end - optstr : strlen(optstr); + if (len =3D=3D 0 || (len =3D=3D 3 && strncmp(optstr, "=3Don", len) =3D= =3D 0)) { + *val =3D true; + } else if ((len =3D=3D 4) && strncmp(optstr, "=3Doff", len) =3D=3D 0) { + *val =3D false; + } else { + error_setg(errp, "error parsing '%s' flag '%s'", flagname, optstr); + return -1; + } + return 0; +} + int inet_parse(InetSocketAddress *addr, const char *str, Error **errp) { const char *optstr, *h; @@ -623,6 +642,7 @@ int inet_parse(InetSocketAddress *addr, const char *str= , Error **errp) char port[33]; int to; int pos; + char *begin; =20 memset(addr, 0, sizeof(*addr)); =20 @@ -664,11 +684,19 @@ int inet_parse(InetSocketAddress *addr, const char *s= tr, Error **errp) addr->has_to =3D true; addr->to =3D to; } - if (strstr(optstr, ",ipv4")) { - addr->ipv4 =3D addr->has_ipv4 =3D true; + begin =3D strstr(optstr, ",ipv4"); + if (begin) { + if (inet_parse_flag("ipv4", begin + 5, &addr->ipv4, errp) < 0) { + return -1; + } + addr->has_ipv4 =3D true; } - if (strstr(optstr, ",ipv6")) { - addr->ipv6 =3D addr->has_ipv6 =3D true; + begin =3D strstr(optstr, ",ipv6"); + if (begin) { + if (inet_parse_flag("ipv6", begin + 5, &addr->ipv6, errp) < 0) { + return -1; + } + addr->has_ipv6 =3D true; } return 0; } --=20 2.13.3