From nobody Thu Nov 6 10:36:47 2025 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; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1540921425170450.90542529193476; Tue, 30 Oct 2018 10:43:45 -0700 (PDT) Received: from localhost ([::1]:54704 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gHY3G-0007by-Nv for importer@patchew.org; Tue, 30 Oct 2018 13:43:38 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:53779) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gHXwn-0007ia-9b for qemu-devel@nongnu.org; Tue, 30 Oct 2018 13:37:02 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gHXwl-00009b-0O for qemu-devel@nongnu.org; Tue, 30 Oct 2018 13:36:56 -0400 Received: from mx1.redhat.com ([209.132.183.28]:52764) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gHXwj-00007Q-M7 for qemu-devel@nongnu.org; Tue, 30 Oct 2018 13:36:54 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 641DC99C4B; Tue, 30 Oct 2018 17:36:52 +0000 (UTC) Received: from localhost (ovpn-112-20.ams2.redhat.com [10.36.112.20]) by smtp.corp.redhat.com (Postfix) with ESMTP id CAF6160C62; Tue, 30 Oct 2018 17:36:36 +0000 (UTC) From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= To: qemu-devel@nongnu.org Date: Tue, 30 Oct 2018 21:36:21 +0400 Message-Id: <20181030173627.7711-2-marcandre.lureau@redhat.com> In-Reply-To: <20181030173627.7711-1-marcandre.lureau@redhat.com> References: <20181030173627.7711-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.38]); Tue, 30 Oct 2018 17:36:52 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL 1/7] websock: fix handshake leak X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: peter.maydell@linaro.org, =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" Missed in f69a8bde293. Thanks Valgrind: =3D=3D955=3D=3D 217 bytes in 1 blocks are definitely lost in loss record 27= 5 of 321 =3D=3D955=3D=3D at 0x483A965: realloc (vg_replace_malloc.c:785) =3D=3D955=3D=3D by 0x50B6839: __vasprintf_chk (in /usr/lib64/libc-2.28.s= o) =3D=3D955=3D=3D by 0x49AA05C: g_vasprintf (in /usr/lib64/libglib-2.0.so.= 0.5800.1) =3D=3D955=3D=3D by 0x4983440: g_strdup_vprintf (in /usr/lib64/libglib-2.= 0.so.0.5800.1) =3D=3D955=3D=3D by 0x126048: qio_channel_websock_handshake_send_res (cha= nnel-websock.c:162) =3D=3D955=3D=3D by 0x1266E6: qio_channel_websock_handshake_send_res_ok (= channel-websock.c:362) =3D=3D955=3D=3D by 0x126D3E: qio_channel_websock_handshake_process (chan= nel-websock.c:468) =3D=3D955=3D=3D by 0x126EF2: qio_channel_websock_handshake_read (channel= -websock.c:511) =3D=3D955=3D=3D by 0x12715B: qio_channel_websock_handshake_io (channel-w= ebsock.c:571) =3D=3D955=3D=3D by 0x125027: qio_channel_fd_source_dispatch (channel-wat= ch.c:84) =3D=3D955=3D=3D by 0x496326C: g_main_context_dispatch (in /usr/lib64/lib= glib-2.0.so.0.5800.1) =3D=3D955=3D=3D by 0x169EC3: glib_pollfds_poll (main-loop.c:215) Signed-off-by: Marc-Andr=C3=A9 Lureau Reviewed-by: Daniel P. Berrang=C3=A9 Reviewed-by: Philippe Mathieu-Daud=C3=A9 --- io/channel-websock.c | 1 + 1 file changed, 1 insertion(+) diff --git a/io/channel-websock.c b/io/channel-websock.c index e6608b969d..dc43dc6bb9 100644 --- a/io/channel-websock.c +++ b/io/channel-websock.c @@ -163,6 +163,7 @@ qio_channel_websock_handshake_send_res(QIOChannelWebsoc= k *ioc, responselen =3D strlen(response); buffer_reserve(&ioc->encoutput, responselen); buffer_append(&ioc->encoutput, response, responselen); + g_free(response); va_end(vargs); } =20 --=20 2.19.1.708.g4ede3d42df From nobody Thu Nov 6 10:36:47 2025 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; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (208.118.235.17 [208.118.235.17]) by mx.zohomail.com with SMTPS id 1540921184298611.9200869702336; Tue, 30 Oct 2018 10:39:44 -0700 (PDT) Received: from localhost ([::1]:54674 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gHXzH-0002Sd-S2 for importer@patchew.org; Tue, 30 Oct 2018 13:39:31 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:54079) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gHXx7-000884-Ul for qemu-devel@nongnu.org; Tue, 30 Oct 2018 13:37:18 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gHXx1-0000M0-G3 for qemu-devel@nongnu.org; Tue, 30 Oct 2018 13:37:17 -0400 Received: from mx1.redhat.com ([209.132.183.28]:36132) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gHXx1-0000Ft-4j for qemu-devel@nongnu.org; Tue, 30 Oct 2018 13:37:11 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 84B7E306B62A; Tue, 30 Oct 2018 17:37:04 +0000 (UTC) Received: from localhost (ovpn-112-20.ams2.redhat.com [10.36.112.20]) by smtp.corp.redhat.com (Postfix) with ESMTP id 5785F65F7B; Tue, 30 Oct 2018 17:36:57 +0000 (UTC) From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= To: qemu-devel@nongnu.org Date: Tue, 30 Oct 2018 21:36:22 +0400 Message-Id: <20181030173627.7711-3-marcandre.lureau@redhat.com> In-Reply-To: <20181030173627.7711-1-marcandre.lureau@redhat.com> References: <20181030173627.7711-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.41]); Tue, 30 Oct 2018 17:37:04 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL 2/7] char-socket: correctly set has_reconnect when parsing QemuOpts X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: peter.maydell@linaro.org, =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" qemu_chr_parse_socket() fills all ChardevSocket fields, but that doesn't reflect correctly the arguments given with the options / on the command line. "reconnect" takes a number as argument, and the default value is 0, which doesn't help to identify the missing option. The other arguments have default values that are less problematic, leave them set by default for now. Signed-off-by: Marc-Andr=C3=A9 Lureau Reviewed-by: Daniel P. Berrang=C3=A9 --- chardev/char-socket.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/chardev/char-socket.c b/chardev/char-socket.c index a75b46d9fe..64e24cb2ab 100644 --- a/chardev/char-socket.c +++ b/chardev/char-socket.c @@ -1117,7 +1117,7 @@ static void qemu_chr_parse_socket(QemuOpts *opts, Cha= rdevBackend *backend, sock->tn3270 =3D is_tn3270; sock->has_wait =3D true; sock->wait =3D is_waitconnect; - sock->has_reconnect =3D true; + sock->has_reconnect =3D qemu_opt_find(opts, "reconnect"); sock->reconnect =3D reconnect; sock->tls_creds =3D g_strdup(tls_creds); =20 --=20 2.19.1.708.g4ede3d42df From nobody Thu Nov 6 10:36:47 2025 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; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (208.118.235.17 [208.118.235.17]) by mx.zohomail.com with SMTPS id 1540921567563212.38380476496388; Tue, 30 Oct 2018 10:46:07 -0700 (PDT) Received: from localhost ([::1]:54731 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gHY5U-00016F-B2 for importer@patchew.org; Tue, 30 Oct 2018 13:45:56 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:54080) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gHXx7-000885-Ul for qemu-devel@nongnu.org; Tue, 30 Oct 2018 13:37:18 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gHXx4-0000PP-DW for qemu-devel@nongnu.org; Tue, 30 Oct 2018 13:37:17 -0400 Received: from mx1.redhat.com ([209.132.183.28]:49022) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gHXx2-0000M6-7C for qemu-devel@nongnu.org; Tue, 30 Oct 2018 13:37:12 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 7FC1C307D986; Tue, 30 Oct 2018 17:37:11 +0000 (UTC) Received: from localhost (ovpn-112-20.ams2.redhat.com [10.36.112.20]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9CC1360C62; Tue, 30 Oct 2018 17:37:09 +0000 (UTC) From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= To: qemu-devel@nongnu.org Date: Tue, 30 Oct 2018 21:36:23 +0400 Message-Id: <20181030173627.7711-4-marcandre.lureau@redhat.com> In-Reply-To: <20181030173627.7711-1-marcandre.lureau@redhat.com> References: <20181030173627.7711-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.48]); Tue, 30 Oct 2018 17:37:11 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL 3/7] char-socket: make 'fd' incompatible with 'reconnect' X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: peter.maydell@linaro.org, =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" A chardev socket created with the 'fd=3D' argument is not going to handle reconnection properly by recycling the same fd (or not in a supported way). Let's forbid this case. Signed-off-by: Marc-Andr=C3=A9 Lureau Reviewed-by: Daniel P. Berrang=C3=A9 --- chardev/char-socket.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/chardev/char-socket.c b/chardev/char-socket.c index 64e24cb2ab..e4137ccd3c 100644 --- a/chardev/char-socket.c +++ b/chardev/char-socket.c @@ -997,6 +997,10 @@ static void qmp_chardev_open_socket(Chardev *chr, =20 s->addr =3D addr =3D socket_address_flatten(sock->addr); =20 + if (sock->has_reconnect && addr->type =3D=3D SOCKET_ADDRESS_TYPE_FD) { + error_setg(errp, "'reconnect' option is incompatible with 'fd'"); + goto error; + } qemu_chr_set_feature(chr, QEMU_CHAR_FEATURE_RECONNECTABLE); /* TODO SOCKET_ADDRESS_FD where fd has AF_UNIX */ if (addr->type =3D=3D SOCKET_ADDRESS_TYPE_UNIX) { --=20 2.19.1.708.g4ede3d42df From nobody Thu Nov 6 10:36:47 2025 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; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1540921266212738.4879076241739; Tue, 30 Oct 2018 10:41:06 -0700 (PDT) Received: from localhost ([::1]:54687 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gHY0m-0004AK-Sl for importer@patchew.org; Tue, 30 Oct 2018 13:41:04 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:54128) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gHXx9-0008CR-R3 for qemu-devel@nongnu.org; Tue, 30 Oct 2018 13:37:20 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gHXx8-0000TI-Eu for qemu-devel@nongnu.org; Tue, 30 Oct 2018 13:37:19 -0400 Received: from mx1.redhat.com ([209.132.183.28]:35294) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gHXx8-0000SV-46 for qemu-devel@nongnu.org; Tue, 30 Oct 2018 13:37:18 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 373DE3001254; Tue, 30 Oct 2018 17:37:17 +0000 (UTC) Received: from localhost (ovpn-112-20.ams2.redhat.com [10.36.112.20]) by smtp.corp.redhat.com (Postfix) with ESMTP id 7CB6F600C5; Tue, 30 Oct 2018 17:37:15 +0000 (UTC) From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= To: qemu-devel@nongnu.org Date: Tue, 30 Oct 2018 21:36:24 +0400 Message-Id: <20181030173627.7711-5-marcandre.lureau@redhat.com> In-Reply-To: <20181030173627.7711-1-marcandre.lureau@redhat.com> References: <20181030173627.7711-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.45]); Tue, 30 Oct 2018 17:37:17 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL 4/7] chardev/char-socket: Function headers refactoring X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: peter.maydell@linaro.org, Julia Suvorova , Stefan Hajnoczi , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" From: Julia Suvorova via Qemu-devel Upcoming websocket support requires additional parameters in function headers that are already overloaded. This patch replaces the bunch of parameters with a single structure pointer. Signed-off-by: Julia Suvorova Message-Id: <20181018223501.21683-2-jusual@mail.ru> Reviewed-by: Daniel P. Berrang=C3=A9 Reviewed-by: Marc-Andr=C3=A9 Lureau Reviewed-by: Stefan Hajnoczi --- chardev/char-socket.c | 55 +++++++++++++++++++++++-------------------- 1 file changed, 30 insertions(+), 25 deletions(-) diff --git a/chardev/char-socket.c b/chardev/char-socket.c index e4137ccd3c..0bbeb83ceb 100644 --- a/chardev/char-socket.c +++ b/chardev/char-socket.c @@ -389,30 +389,37 @@ static void tcp_chr_free_connection(Chardev *chr) s->connected =3D 0; } =20 -static char *SocketAddress_to_str(const char *prefix, SocketAddress *addr, - bool is_listen, bool is_telnet) +static const char *qemu_chr_socket_protocol(SocketChardev *s) { - switch (addr->type) { + if (s->is_telnet) { + return "telnet"; + } + return "tcp"; +} + +static char *qemu_chr_socket_address(SocketChardev *s, const char *prefix) +{ + switch (s->addr->type) { case SOCKET_ADDRESS_TYPE_INET: return g_strdup_printf("%s%s:%s:%s%s", prefix, - is_telnet ? "telnet" : "tcp", - addr->u.inet.host, - addr->u.inet.port, - is_listen ? ",server" : ""); + qemu_chr_socket_protocol(s), + s->addr->u.inet.host, + s->addr->u.inet.port, + s->is_listen ? ",server" : ""); break; case SOCKET_ADDRESS_TYPE_UNIX: return g_strdup_printf("%sunix:%s%s", prefix, - addr->u.q_unix.path, - is_listen ? ",server" : ""); + s->addr->u.q_unix.path, + s->is_listen ? ",server" : ""); break; case SOCKET_ADDRESS_TYPE_FD: - return g_strdup_printf("%sfd:%s%s", prefix, addr->u.fd.str, - is_listen ? ",server" : ""); + return g_strdup_printf("%sfd:%s%s", prefix, s->addr->u.fd.str, + s->is_listen ? ",server" : ""); break; case SOCKET_ADDRESS_TYPE_VSOCK: return g_strdup_printf("%svsock:%s:%s", prefix, - addr->u.vsock.cid, - addr->u.vsock.port); + s->addr->u.vsock.cid, + s->addr->u.vsock.port); default: abort(); } @@ -424,8 +431,7 @@ static void update_disconnected_filename(SocketChardev = *s) =20 g_free(chr->filename); if (s->addr) { - chr->filename =3D SocketAddress_to_str("disconnected:", s->addr, - s->is_listen, s->is_telnet); + chr->filename =3D qemu_chr_socket_address(s, "disconnected:"); } else { chr->filename =3D g_strdup("disconnected:socket"); } @@ -514,10 +520,12 @@ static int tcp_chr_sync_read(Chardev *chr, const uint= 8_t *buf, int len) return size; } =20 -static char *sockaddr_to_str(struct sockaddr_storage *ss, socklen_t ss_len, - struct sockaddr_storage *ps, socklen_t ps_len, - bool is_listen, bool is_telnet) +static char *qemu_chr_compute_filename(SocketChardev *s) { + struct sockaddr_storage *ss =3D &s->sioc->localAddr; + struct sockaddr_storage *ps =3D &s->sioc->remoteAddr; + socklen_t ss_len =3D s->sioc->localAddrLen; + socklen_t ps_len =3D s->sioc->remoteAddrLen; char shost[NI_MAXHOST], sserv[NI_MAXSERV]; char phost[NI_MAXHOST], pserv[NI_MAXSERV]; const char *left =3D "", *right =3D ""; @@ -527,7 +535,7 @@ static char *sockaddr_to_str(struct sockaddr_storage *s= s, socklen_t ss_len, case AF_UNIX: return g_strdup_printf("unix:%s%s", ((struct sockaddr_un *)(ss))->sun_path, - is_listen ? ",server" : ""); + s->is_listen ? ",server" : ""); #endif case AF_INET6: left =3D "["; @@ -539,9 +547,9 @@ static char *sockaddr_to_str(struct sockaddr_storage *s= s, socklen_t ss_len, getnameinfo((struct sockaddr *) ps, ps_len, phost, sizeof(phost), pserv, sizeof(pserv), NI_NUMERICHOST | NI_NUMERICSERV); return g_strdup_printf("%s:%s%s%s:%s%s <-> %s%s%s:%s", - is_telnet ? "telnet" : "tcp", + qemu_chr_socket_protocol(s), left, shost, right, sserv, - is_listen ? ",server" : "", + s->is_listen ? ",server" : "", left, phost, right, pserv); =20 default: @@ -576,10 +584,7 @@ static void tcp_chr_connect(void *opaque) SocketChardev *s =3D SOCKET_CHARDEV(opaque); =20 g_free(chr->filename); - chr->filename =3D sockaddr_to_str( - &s->sioc->localAddr, s->sioc->localAddrLen, - &s->sioc->remoteAddr, s->sioc->remoteAddrLen, - s->is_listen, s->is_telnet); + chr->filename =3D qemu_chr_compute_filename(s); =20 s->connected =3D 1; update_ioc_handlers(s); --=20 2.19.1.708.g4ede3d42df From nobody Thu Nov 6 10:36:47 2025 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; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1540921704683579.2032759066113; Tue, 30 Oct 2018 10:48:24 -0700 (PDT) Received: from localhost ([::1]:54745 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gHY7r-00049W-IH for importer@patchew.org; Tue, 30 Oct 2018 13:48:23 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:54451) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gHXxn-0001my-PI for qemu-devel@nongnu.org; Tue, 30 Oct 2018 13:38:02 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gHXxl-00012z-82 for qemu-devel@nongnu.org; Tue, 30 Oct 2018 13:37:59 -0400 Received: from mx1.redhat.com ([209.132.183.28]:43660) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gHXxk-0000ar-Pi for qemu-devel@nongnu.org; Tue, 30 Oct 2018 13:37:57 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id D088F308624E; Tue, 30 Oct 2018 17:37:30 +0000 (UTC) Received: from localhost (ovpn-112-20.ams2.redhat.com [10.36.112.20]) by smtp.corp.redhat.com (Postfix) with ESMTP id 2DB9C5D75E; Tue, 30 Oct 2018 17:37:20 +0000 (UTC) From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= To: qemu-devel@nongnu.org Date: Tue, 30 Oct 2018 21:36:25 +0400 Message-Id: <20181030173627.7711-6-marcandre.lureau@redhat.com> In-Reply-To: <20181030173627.7711-1-marcandre.lureau@redhat.com> References: <20181030173627.7711-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.49]); Tue, 30 Oct 2018 17:37:31 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL 5/7] chardev: Add websocket support X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: peter.maydell@linaro.org, Julia Suvorova , Stefan Hajnoczi , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" From: Julia Suvorova via Qemu-devel New option "websocket" added to allow using WebSocket protocol for chardev socket backend. Example: -chardev socket,websocket,server,id=3D... Signed-off-by: Julia Suvorova Message-Id: <20181018223501.21683-3-jusual@mail.ru> Reviewed-by: Daniel P. Berrang=C3=A9 Reviewed-by: Stefan Hajnoczi Reviewed-by: Marc-Andr=C3=A9 Lureau --- qapi/char.json | 3 ++ chardev/char-socket.c | 64 ++++++++++++++++++++++++++++++++++++++----- chardev/char.c | 8 +++++- qemu-options.hx | 13 +++++++-- 4 files changed, 77 insertions(+), 11 deletions(-) diff --git a/qapi/char.json b/qapi/char.json index b7b2a05766..79bac598a0 100644 --- a/qapi/char.json +++ b/qapi/char.json @@ -251,6 +251,8 @@ # sockets (default: false) # @tn3270: enable tn3270 protocol on server # sockets (default: false) (Since: 2.10) +# @websocket: enable websocket protocol on server +# sockets (default: false) (Since: 3.1) # @reconnect: For a client socket, if a socket is disconnected, # then attempt a reconnect after the given number of seconds. # Setting this to zero disables this function. (default: 0) @@ -265,6 +267,7 @@ '*nodelay' : 'bool', '*telnet' : 'bool', '*tn3270' : 'bool', + '*websocket' : 'bool', '*reconnect' : 'int' }, 'base': 'ChardevCommon' } =20 diff --git a/chardev/char-socket.c b/chardev/char-socket.c index 0bbeb83ceb..eaa8e8b68f 100644 --- a/chardev/char-socket.c +++ b/chardev/char-socket.c @@ -26,6 +26,7 @@ #include "chardev/char.h" #include "io/channel-socket.h" #include "io/channel-tls.h" +#include "io/channel-websock.h" #include "io/net-listener.h" #include "qemu/error-report.h" #include "qemu/option.h" @@ -68,6 +69,8 @@ typedef struct { GSource *telnet_source; TCPChardevTelnetInit *telnet_init; =20 + bool is_websock; + GSource *reconnect_timer; int64_t reconnect_time; bool connect_err_reported; @@ -394,7 +397,7 @@ static const char *qemu_chr_socket_protocol(SocketChard= ev *s) if (s->is_telnet) { return "telnet"; } - return "tcp"; + return s->is_websock ? "websocket" : "tcp"; } =20 static char *qemu_chr_socket_address(SocketChardev *s, const char *prefix) @@ -714,6 +717,41 @@ cont: } =20 =20 +static void tcp_chr_websock_handshake(QIOTask *task, gpointer user_data) +{ + Chardev *chr =3D user_data; + SocketChardev *s =3D user_data; + + if (qio_task_propagate_error(task, NULL)) { + tcp_chr_disconnect(chr); + } else { + if (s->do_telnetopt) { + tcp_chr_telnet_init(chr); + } else { + tcp_chr_connect(chr); + } + } +} + + +static void tcp_chr_websock_init(Chardev *chr) +{ + SocketChardev *s =3D SOCKET_CHARDEV(chr); + QIOChannelWebsock *wioc =3D NULL; + gchar *name; + + wioc =3D qio_channel_websock_new_server(s->ioc); + + name =3D g_strdup_printf("chardev-websocket-server-%s", chr->label); + qio_channel_set_name(QIO_CHANNEL(wioc), name); + g_free(name); + object_unref(OBJECT(s->ioc)); + s->ioc =3D QIO_CHANNEL(wioc); + + qio_channel_websock_handshake(wioc, tcp_chr_websock_handshake, chr, NU= LL); +} + + static void tcp_chr_tls_handshake(QIOTask *task, gpointer user_data) { @@ -723,7 +761,9 @@ static void tcp_chr_tls_handshake(QIOTask *task, if (qio_task_propagate_error(task, NULL)) { tcp_chr_disconnect(chr); } else { - if (s->do_telnetopt) { + if (s->is_websock) { + tcp_chr_websock_init(chr); + } else if (s->do_telnetopt) { tcp_chr_telnet_init(chr); } else { tcp_chr_connect(chr); @@ -809,12 +849,12 @@ static int tcp_chr_new_client(Chardev *chr, QIOChanne= lSocket *sioc) =20 if (s->tls_creds) { tcp_chr_tls_init(chr); + } else if (s->is_websock) { + tcp_chr_websock_init(chr); + } else if (s->do_telnetopt) { + tcp_chr_telnet_init(chr); } else { - if (s->do_telnetopt) { - tcp_chr_telnet_init(chr); - } else { - tcp_chr_connect(chr); - } + tcp_chr_connect(chr); } =20 return 0; @@ -959,13 +999,20 @@ static void qmp_chardev_open_socket(Chardev *chr, bool is_telnet =3D sock->has_telnet ? sock->telnet : false; bool is_tn3270 =3D sock->has_tn3270 ? sock->tn3270 : false; bool is_waitconnect =3D sock->has_wait ? sock->wait : false; + bool is_websock =3D sock->has_websocket ? sock->websocket : false; int64_t reconnect =3D sock->has_reconnect ? sock->reconnect : 0; QIOChannelSocket *sioc =3D NULL; SocketAddress *addr; =20 + if (!is_listen && is_websock) { + error_setg(errp, "%s", "Websocket client is not implemented"); + goto error; + } + s->is_listen =3D is_listen; s->is_telnet =3D is_telnet; s->is_tn3270 =3D is_tn3270; + s->is_websock =3D is_websock; s->do_nodelay =3D do_nodelay; if (sock->tls_creds) { Object *creds; @@ -1076,6 +1123,7 @@ static void qemu_chr_parse_socket(QemuOpts *opts, Cha= rdevBackend *backend, bool is_waitconnect =3D is_listen && qemu_opt_get_bool(opts, "wait", t= rue); bool is_telnet =3D qemu_opt_get_bool(opts, "telnet", false); bool is_tn3270 =3D qemu_opt_get_bool(opts, "tn3270", false); + bool is_websock =3D qemu_opt_get_bool(opts, "websocket", false); bool do_nodelay =3D !qemu_opt_get_bool(opts, "delay", true); int64_t reconnect =3D qemu_opt_get_number(opts, "reconnect", 0); const char *path =3D qemu_opt_get(opts, "path"); @@ -1124,6 +1172,8 @@ static void qemu_chr_parse_socket(QemuOpts *opts, Cha= rdevBackend *backend, sock->telnet =3D is_telnet; sock->has_tn3270 =3D true; sock->tn3270 =3D is_tn3270; + sock->has_websocket =3D true; + sock->websocket =3D is_websock; sock->has_wait =3D true; sock->wait =3D is_waitconnect; sock->has_reconnect =3D qemu_opt_find(opts, "reconnect"); diff --git a/chardev/char.c b/chardev/char.c index 7f07a1bfbd..79b05fb7b7 100644 --- a/chardev/char.c +++ b/chardev/char.c @@ -409,7 +409,8 @@ QemuOpts *qemu_chr_parse_compat(const char *label, cons= t char *filename, } if (strstart(filename, "tcp:", &p) || strstart(filename, "telnet:", &p) || - strstart(filename, "tn3270:", &p)) { + strstart(filename, "tn3270:", &p) || + strstart(filename, "websocket:", &p)) { if (sscanf(p, "%64[^:]:%32[^,]%n", host, port, &pos) < 2) { host[0] =3D 0; if (sscanf(p, ":%32[^,]%n", port, &pos) < 1) @@ -429,6 +430,8 @@ QemuOpts *qemu_chr_parse_compat(const char *label, cons= t char *filename, qemu_opt_set(opts, "telnet", "on", &error_abort); } else if (strstart(filename, "tn3270:", &p)) { qemu_opt_set(opts, "tn3270", "on", &error_abort); + } else if (strstart(filename, "websocket:", &p)) { + qemu_opt_set(opts, "websocket", "on", &error_abort); } return opts; } @@ -860,6 +863,9 @@ QemuOptsList qemu_chardev_opts =3D { },{ .name =3D "tls-creds", .type =3D QEMU_OPT_STRING, + },{ + .name =3D "websocket", + .type =3D QEMU_OPT_BOOL, },{ .name =3D "width", .type =3D QEMU_OPT_NUMBER, diff --git a/qemu-options.hx b/qemu-options.hx index 08f8516a9a..38c7a978c1 100644 --- a/qemu-options.hx +++ b/qemu-options.hx @@ -2414,9 +2414,9 @@ DEF("chardev", HAS_ARG, QEMU_OPTION_chardev, "-chardev help\n" "-chardev null,id=3Did[,mux=3Don|off][,logfile=3DPATH][,logappend=3Don= |off]\n" "-chardev socket,id=3Did[,host=3Dhost],port=3Dport[,to=3Dto][,ipv4][,i= pv6][,nodelay][,reconnect=3Dseconds]\n" - " [,server][,nowait][,telnet][,reconnect=3Dseconds][,mux=3Don|= off]\n" + " [,server][,nowait][,telnet][,websocket][,reconnect=3Dseconds= ][,mux=3Don|off]\n" " [,logfile=3DPATH][,logappend=3Don|off][,tls-creds=3DID] (tcp= )\n" - "-chardev socket,id=3Did,path=3Dpath[,server][,nowait][,telnet][,recon= nect=3Dseconds]\n" + "-chardev socket,id=3Did,path=3Dpath[,server][,nowait][,telnet][,webso= cket][,reconnect=3Dseconds]\n" " [,mux=3Don|off][,logfile=3DPATH][,logappend=3Don|off] (unix)= \n" "-chardev udp,id=3Did[,host=3Dhost],port=3Dport[,localaddr=3Dlocaladdr= ]\n" " [,localport=3Dlocalport][,ipv4][,ipv6][,mux=3Don|off]\n" @@ -2544,7 +2544,7 @@ The available backends are: A void device. This device will not emit any data, and will drop any data = it receives. The null backend does not take any options. =20 -@item -chardev socket,id=3D@var{id}[,@var{TCP options} or @var{unix option= s}][,server][,nowait][,telnet][,reconnect=3D@var{seconds}][,tls-creds=3D@va= r{id}] +@item -chardev socket,id=3D@var{id}[,@var{TCP options} or @var{unix option= s}][,server][,nowait][,telnet][,websocket][,reconnect=3D@var{seconds}][,tls= -creds=3D@var{id}] =20 Create a two-way stream socket, which can be either a TCP or a unix socket= . A unix socket will be created if @option{path} is specified. Behaviour is @@ -2558,6 +2558,9 @@ connect to a listening socket. @option{telnet} specifies that traffic on the socket should interpret teln= et escape sequences. =20 +@option{websocket} specifies that the socket uses WebSocket protocol for +communication. + @option{reconnect} sets the timeout for reconnecting on non-server sockets= when the remote end goes away. qemu will delay this many seconds and then atte= mpt to reconnect. Zero disables reconnecting, and is the default. @@ -3106,6 +3109,10 @@ MAGIC_SYSRQ sequence if you use a telnet that suppor= ts sending the break sequence. Typically in unix telnet you do it with Control-] and then type "send break" followed by pressing the enter key. =20 +@item websocket:@var{host}:@var{port},server[,nowait][,nodelay] +The WebSocket protocol is used instead of raw tcp socket. The port acts as +a WebSocket server. Client mode is not supported. + @item unix:@var{path}[,server][,nowait][,reconnect=3D@var{seconds}] A unix domain socket is used instead of a tcp socket. The option works the same as if you had specified @code{-serial tcp} except the unix domain soc= ket --=20 2.19.1.708.g4ede3d42df From nobody Thu Nov 6 10:36:47 2025 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; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1540921442650118.00900306867175; Tue, 30 Oct 2018 10:44:02 -0700 (PDT) Received: from localhost ([::1]:54707 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gHY3d-0007vJ-6Q for importer@patchew.org; Tue, 30 Oct 2018 13:44:01 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:54359) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gHXxk-0001kE-S1 for qemu-devel@nongnu.org; Tue, 30 Oct 2018 13:37:58 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gHXxe-0000wR-3T for qemu-devel@nongnu.org; Tue, 30 Oct 2018 13:37:56 -0400 Received: from mx1.redhat.com ([209.132.183.28]:37214) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gHXxa-0000kA-74 for qemu-devel@nongnu.org; Tue, 30 Oct 2018 13:37:48 -0400 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 7F74830C754E; Tue, 30 Oct 2018 17:37:41 +0000 (UTC) Received: from localhost (ovpn-112-20.ams2.redhat.com [10.36.112.20]) by smtp.corp.redhat.com (Postfix) with ESMTP id 04BD810A394D; Tue, 30 Oct 2018 17:37:38 +0000 (UTC) From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= To: qemu-devel@nongnu.org Date: Tue, 30 Oct 2018 21:36:26 +0400 Message-Id: <20181030173627.7711-7-marcandre.lureau@redhat.com> In-Reply-To: <20181030173627.7711-1-marcandre.lureau@redhat.com> References: <20181030173627.7711-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.43]); Tue, 30 Oct 2018 17:37:41 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL 6/7] tests/test-char: Check websocket chardev functionality X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: peter.maydell@linaro.org, Julia Suvorova , Stefan Hajnoczi , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" From: Julia Suvorova via Qemu-devel Test order: Creating server websocket chardev Creating usual tcp chardev client Sending handshake message from client Receiving handshake reply Sending ping frame with "hello" payload Receiving pong reply Sending binary data "world" Checking the received data on server side Checking of closing handshake Signed-off-by: Julia Suvorova Message-Id: <20181018223501.21683-4-jusual@mail.ru> Reviewed-by: Daniel P. Berrang=C3=A9 Reviewed-by: Marc-Andr=C3=A9 Lureau Reviewed-by: Stefan Hajnoczi --- tests/test-char.c | 125 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 125 insertions(+) diff --git a/tests/test-char.c b/tests/test-char.c index 831e37fbf4..19c3efad72 100644 --- a/tests/test-char.c +++ b/tests/test-char.c @@ -420,6 +420,130 @@ static void char_socket_fdpass_test(void) } =20 =20 +static void websock_server_read(void *opaque, const uint8_t *buf, int size) +{ + g_assert_cmpint(size, =3D=3D, 5); + g_assert(memcmp(buf, "world", size) =3D=3D 0); + quit =3D true; +} + + +static int websock_server_can_read(void *opaque) +{ + return 10; +} + + +static bool websock_check_http_headers(char *buf, int size) +{ + int i; + const char *ans[] =3D { "HTTP/1.1 101 Switching Protocols\r\n", + "Server: QEMU VNC\r\n", + "Upgrade: websocket\r\n", + "Connection: Upgrade\r\n", + "Sec-WebSocket-Accept:", + "Sec-WebSocket-Protocol: binary\r\n" }; + + for (i =3D 0; i < 6; i++) { + if (g_strstr_len(buf, size, ans[i]) =3D=3D NULL) { + return false; + } + } + + return true; +} + + +static void websock_client_read(void *opaque, const uint8_t *buf, int size) +{ + const uint8_t ping[] =3D { 0x89, 0x85, /* Ping header= */ + 0x07, 0x77, 0x9e, 0xf9, /* Masking key */ + 0x6f, 0x12, 0xf2, 0x95, 0x68 /* "hello" */ }; + + const uint8_t binary[] =3D { 0x82, 0x85, /* Binary he= ader */ + 0x74, 0x90, 0xb9, 0xdf, /* Masking key= */ + 0x03, 0xff, 0xcb, 0xb3, 0x10 /* "world" */ = }; + Chardev *chr_client =3D opaque; + + if (websock_check_http_headers((char *) buf, size)) { + qemu_chr_fe_write(chr_client->be, ping, sizeof(ping)); + } else if (buf[0] =3D=3D 0x8a && buf[1] =3D=3D 0x05) { + g_assert(strncmp((char *) buf + 2, "hello", 5) =3D=3D 0); + qemu_chr_fe_write(chr_client->be, binary, sizeof(binary)); + } else { + g_assert(buf[0] =3D=3D 0x88 && buf[1] =3D=3D 0x16); + g_assert(strncmp((char *) buf + 4, "peer requested close", 10) =3D= =3D 0); + quit =3D true; + } +} + + +static int websock_client_can_read(void *opaque) +{ + return 4096; +} + + +static void char_websock_test(void) +{ + QObject *addr; + QDict *qdict; + const char *port; + char *tmp; + char *handshake_port; + CharBackend be; + CharBackend client_be; + Chardev *chr_client; + Chardev *chr =3D qemu_chr_new("server", + "websocket:127.0.0.1:0,server,nowait"); + const char handshake[] =3D "GET / HTTP/1.1\r\n" + "Upgrade: websocket\r\n" + "Connection: Upgrade\r\n" + "Host: localhost:%s\r\n" + "Origin: http://localhost:%s\r\n" + "Sec-WebSocket-Key: o9JHNiS3/0/0zYE1wa3yIw=3D= =3D\r\n" + "Sec-WebSocket-Version: 13\r\n" + "Sec-WebSocket-Protocol: binary\r\n\r\n"; + const uint8_t close[] =3D { 0x88, 0x82, /* Close header */ + 0xef, 0xaa, 0xc5, 0x97, /* Masking key */ + 0xec, 0x42 /* Status code */ }; + + addr =3D object_property_get_qobject(OBJECT(chr), "addr", &error_abort= ); + qdict =3D qobject_to(QDict, addr); + port =3D qdict_get_str(qdict, "port"); + tmp =3D g_strdup_printf("tcp:127.0.0.1:%s", port); + handshake_port =3D g_strdup_printf(handshake, port, port); + qobject_unref(qdict); + + qemu_chr_fe_init(&be, chr, &error_abort); + qemu_chr_fe_set_handlers(&be, websock_server_can_read, websock_server_= read, + NULL, NULL, chr, NULL, true); + + chr_client =3D qemu_chr_new("client", tmp); + qemu_chr_fe_init(&client_be, chr_client, &error_abort); + qemu_chr_fe_set_handlers(&client_be, websock_client_can_read, + websock_client_read, + NULL, NULL, chr_client, NULL, true); + g_free(tmp); + + qemu_chr_write_all(chr_client, + (uint8_t *) handshake_port, + strlen(handshake_port)); + g_free(handshake_port); + main_loop(); + + g_assert(object_property_get_bool(OBJECT(chr), "connected", &error_abo= rt)); + g_assert(object_property_get_bool(OBJECT(chr_client), + "connected", &error_abort)); + + qemu_chr_write_all(chr_client, close, sizeof(close)); + main_loop(); + + object_unparent(OBJECT(chr_client)); + object_unparent(OBJECT(chr)); +} + + #ifndef _WIN32 static void char_pipe_test(void) { @@ -842,6 +966,7 @@ int main(int argc, char **argv) g_test_add_func("/char/serial", char_serial_test); #endif g_test_add_func("/char/hotswap", char_hotswap_test); + g_test_add_func("/char/websocket", char_websock_test); =20 return g_test_run(); } --=20 2.19.1.708.g4ede3d42df From nobody Thu Nov 6 10:36:47 2025 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; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1540921358424661.1681775986655; Tue, 30 Oct 2018 10:42:38 -0700 (PDT) Received: from localhost ([::1]:54702 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gHY2H-0005Jo-9A for importer@patchew.org; Tue, 30 Oct 2018 13:42:37 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:54427) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gHXxn-0001mP-9U for qemu-devel@nongnu.org; Tue, 30 Oct 2018 13:38:00 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gHXxl-00013E-Dy for qemu-devel@nongnu.org; Tue, 30 Oct 2018 13:37:59 -0400 Received: from mx1.redhat.com ([209.132.183.28]:23090) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gHXxk-0000oW-Tw for qemu-devel@nongnu.org; Tue, 30 Oct 2018 13:37:57 -0400 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id C13FA3003949; Tue, 30 Oct 2018 17:37:46 +0000 (UTC) Received: from localhost (ovpn-112-20.ams2.redhat.com [10.36.112.20]) by smtp.corp.redhat.com (Postfix) with ESMTP id 4A5272B585; Tue, 30 Oct 2018 17:37:44 +0000 (UTC) From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= To: qemu-devel@nongnu.org Date: Tue, 30 Oct 2018 21:36:27 +0400 Message-Id: <20181030173627.7711-8-marcandre.lureau@redhat.com> In-Reply-To: <20181030173627.7711-1-marcandre.lureau@redhat.com> References: <20181030173627.7711-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.48]); Tue, 30 Oct 2018 17:37:46 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL 7/7] editorconfig: set emacs mode X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: peter.maydell@linaro.org, Markus Armbruster , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" Some time ago, I proposed to use an (eval) in .dir-locals.el to set the mode for all json files and Makefile. Unfortunately, this isn't safe, and emacs will prompt the user, which isn't very friendly. Fortunately, editorconfig provides a special config key which does allow to set the emacs mode. Add a few missing entries and set the emacs mode. Update top comment to provide a short summary about the file and the IDE plugins while at it. Signed-off-by: Marc-Andr=C3=A9 Lureau Acked-by: Markus Armbruster --- .editorconfig | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/.editorconfig b/.editorconfig index b2022e391a..1582883393 100644 --- a/.editorconfig +++ b/.editorconfig @@ -1,4 +1,10 @@ -# http://editorconfig.org +# EditorConfig is a file format and collection of text editor plugins +# for maintaining consistent coding styles between different editors +# and IDEs. Most popular editors support this either natively or via +# plugin. +# +# Check https://editorconfig.org for details. + root =3D true =20 [*] @@ -6,10 +12,23 @@ end_of_line =3D lf insert_final_newline =3D true charset =3D utf-8 =20 +[*.mak] +indent_style =3D tab +indent_size =3D 8 +file_type_emacs =3D makefile + [Makefile*] indent_style =3D tab indent_size =3D 8 +file_type_emacs =3D makefile =20 [*.{c,h}] indent_style =3D space indent_size =3D 4 + +[*.{vert,frag}] +file_type_emacs =3D glsl + +[*.json] +indent_style =3D space +file_type_emacs =3D python --=20 2.19.1.708.g4ede3d42df