From nobody Fri Nov 14 19:22:17 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1589979773; cv=none; d=zohomail.com; s=zohoarc; b=Wk3wdTTFkAOpHYMQ3fkpuj5eCTmOcL+q5Pdx1uNaeZZmVadpXFuCR35WnGJc7PriFTQGIjqBMA7U9si9NBT/z3Wk28mE9H4tsu16oIahKpKrOh+vNAbVP7eNEcIbw/UQ6qiN07cXe6UznMT8o2u767F9I8FReqWb0EEfJMjUBjA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1589979773; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=RSzRBZSrDZvf3d/ItUX679rPGM/XJ9GTRQNRCZFD0kc=; b=Kua8V+kgFwnFy+d7aU9ynPHRQi/t1n0bh0ymnnwTPmocCLQEvntntd2otjrghQItxPe/1ivEwetBH1WeZEkCLv3Jfo7wz7vCCwpowif/2zSRF7OmBBQ4ZaeB/rD8ZdRsng026RfL0p4axZkQyLOwO/33P5tKwKnZqJxUpDvw14c= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1589979773449317.6671131159927; Wed, 20 May 2020 06:02:53 -0700 (PDT) Received: from localhost ([::1]:57202 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jbON2-0004fQ-4C for importer@patchew.org; Wed, 20 May 2020 09:02:52 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:44118) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jbOL6-0002QV-Sy for qemu-devel@nongnu.org; Wed, 20 May 2020 09:00:52 -0400 Received: from us-smtp-delivery-1.mimecast.com ([205.139.110.120]:37914 helo=us-smtp-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1jbOL5-0004rp-LQ for qemu-devel@nongnu.org; Wed, 20 May 2020 09:00:52 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-308-EW2o-uf1MhmcoO2buVZXng-1; Wed, 20 May 2020 09:00:39 -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 mimecast-mx01.redhat.com (Postfix) with ESMTPS id 2E4A58015D2; Wed, 20 May 2020 13:00:38 +0000 (UTC) Received: from localhost.localdomain.com (unknown [10.36.110.3]) by smtp.corp.redhat.com (Postfix) with ESMTP id 90E20101E678; Wed, 20 May 2020 13:00:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1589979650; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=RSzRBZSrDZvf3d/ItUX679rPGM/XJ9GTRQNRCZFD0kc=; b=iFcTB/f+8TtdOpGzo9kLW7/7dSFU3SPGQGr52xMHHyLR6iVpOtwTHfRbL/LEqyt+S64hXy ln5PHkSpm0Xk6dYp52j5G2f6HQzF5PI0xCQdgd4SmmmWvRmAqo8QCRGuEkglyhWthA4Ydb /sO9fmS24qcVpfwo7smbIK19Buencs0= X-MC-Unique: EW2o-uf1MhmcoO2buVZXng-1 From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: qemu-devel@nongnu.org Subject: [PULL 1/3] qemu-sockets: add abstract UNIX domain socket support Date: Wed, 20 May 2020 14:00:23 +0100 Message-Id: <20200520130025.2201467-2-berrange@redhat.com> In-Reply-To: <20200520130025.2201467-1-berrange@redhat.com> References: <20200520130025.2201467-1-berrange@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=205.139.110.120; envelope-from=berrange@redhat.com; helo=us-smtp-1.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/05/19 22:48:02 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_PASS=-0.001 autolearn=_AUTOLEARN X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , xiaoqiang zhao , Markus Armbruster , 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-DKIM: fail (Header signature does not verify) From: xiaoqiang zhao unix_listen/connect_saddr now support abstract address types two aditional BOOL switches are introduced: tight: whether to set @addrlen to the minimal string length, or the maximum sun_path length. default is TRUE abstract: whether we use abstract address. default is FALSE cli example: -monitor unix:/tmp/unix.socket,abstract,tight=3Doff OR -chardev socket,path=3D/tmp/unix.socket,id=3Dunix1,abstract,tight=3Don Signed-off-by: xiaoqiang zhao Signed-off-by: Daniel P. Berrang=C3=A9 --- chardev/char-socket.c | 4 ++++ chardev/char.c | 7 +++++++ qapi/sockets.json | 8 +++++++- util/qemu-sockets.c | 39 ++++++++++++++++++++++++++++++++------- 4 files changed, 50 insertions(+), 8 deletions(-) diff --git a/chardev/char-socket.c b/chardev/char-socket.c index 232e0a8604..e77699db48 100644 --- a/chardev/char-socket.c +++ b/chardev/char-socket.c @@ -1380,6 +1380,8 @@ static void qemu_chr_parse_socket(QemuOpts *opts, Cha= rdevBackend *backend, const char *host =3D qemu_opt_get(opts, "host"); const char *port =3D qemu_opt_get(opts, "port"); const char *fd =3D qemu_opt_get(opts, "fd"); + bool tight =3D qemu_opt_get_bool(opts, "tight", true); + bool abstract =3D qemu_opt_get_bool(opts, "abstract", false); SocketAddressLegacy *addr; ChardevSocket *sock; =20 @@ -1431,6 +1433,8 @@ static void qemu_chr_parse_socket(QemuOpts *opts, Cha= rdevBackend *backend, addr->type =3D SOCKET_ADDRESS_LEGACY_KIND_UNIX; q_unix =3D addr->u.q_unix.data =3D g_new0(UnixSocketAddress, 1); q_unix->path =3D g_strdup(path); + q_unix->tight =3D tight; + q_unix->abstract =3D abstract; } else if (host) { addr->type =3D SOCKET_ADDRESS_LEGACY_KIND_INET; addr->u.inet.data =3D g_new(InetSocketAddress, 1); diff --git a/chardev/char.c b/chardev/char.c index 0196e2887b..ea06c5ff4d 100644 --- a/chardev/char.c +++ b/chardev/char.c @@ -939,6 +939,13 @@ QemuOptsList qemu_chardev_opts =3D { },{ .name =3D "logappend", .type =3D QEMU_OPT_BOOL, + },{ + .name =3D "tight", + .type =3D QEMU_OPT_BOOL, + .def_value_str =3D "on", + },{ + .name =3D "abstract", + .type =3D QEMU_OPT_BOOL, }, { /* end of list */ } }, diff --git a/qapi/sockets.json b/qapi/sockets.json index ea933ed4b2..cbd6ef35d0 100644 --- a/qapi/sockets.json +++ b/qapi/sockets.json @@ -73,12 +73,18 @@ # Captures a socket address in the local ("Unix socket") namespace. # # @path: filesystem path to use +# @tight: pass a socket address length confined to the minimum length of t= he +# abstract string, rather than the full sockaddr_un record length +# (only matters for abstract sockets, default true). (Since 5.1) +# @abstract: whether this is an abstract address, default false. (Since 5.= 1) # # Since: 1.3 ## { 'struct': 'UnixSocketAddress', 'data': { - 'path': 'str' } } + 'path': 'str', + '*tight': 'bool', + '*abstract': 'bool' } } =20 ## # @VsockSocketAddress: diff --git a/util/qemu-sockets.c b/util/qemu-sockets.c index 86c48b9fa5..b37d288866 100644 --- a/util/qemu-sockets.c +++ b/util/qemu-sockets.c @@ -863,6 +863,7 @@ static int unix_listen_saddr(UnixSocketAddress *saddr, char *pathbuf =3D NULL; const char *path; size_t pathlen; + size_t addrlen; =20 sock =3D qemu_socket(PF_UNIX, SOCK_STREAM, 0); if (sock < 0) { @@ -879,9 +880,11 @@ static int unix_listen_saddr(UnixSocketAddress *saddr, } =20 pathlen =3D strlen(path); - if (pathlen > sizeof(un.sun_path)) { + if (pathlen > sizeof(un.sun_path) || + (saddr->abstract && pathlen > (sizeof(un.sun_path) - 1))) { error_setg(errp, "UNIX socket path '%s' is too long", path); error_append_hint(errp, "Path must be less than %zu bytes\n", + saddr->abstract ? sizeof(un.sun_path) - 1 : sizeof(un.sun_path)); goto err; } @@ -903,7 +906,7 @@ static int unix_listen_saddr(UnixSocketAddress *saddr, close(fd); } =20 - if (unlink(path) < 0 && errno !=3D ENOENT) { + if (!saddr->abstract && unlink(path) < 0 && errno !=3D ENOENT) { error_setg_errno(errp, errno, "Failed to unlink socket %s", path); goto err; @@ -911,9 +914,19 @@ static int unix_listen_saddr(UnixSocketAddress *saddr, =20 memset(&un, 0, sizeof(un)); un.sun_family =3D AF_UNIX; - memcpy(un.sun_path, path, pathlen); + addrlen =3D sizeof(un); =20 - if (bind(sock, (struct sockaddr*) &un, sizeof(un)) < 0) { + if (saddr->abstract) { + un.sun_path[0] =3D '\0'; + memcpy(&un.sun_path[1], path, pathlen); + if (saddr->tight) { + addrlen =3D offsetof(struct sockaddr_un, sun_path) + 1 + pathl= en; + } + } else { + memcpy(un.sun_path, path, pathlen); + } + + if (bind(sock, (struct sockaddr *) &un, addrlen) < 0) { error_setg_errno(errp, errno, "Failed to bind socket to %s", path); goto err; } @@ -936,6 +949,7 @@ static int unix_connect_saddr(UnixSocketAddress *saddr,= Error **errp) struct sockaddr_un un; int sock, rc; size_t pathlen; + size_t addrlen; =20 if (saddr->path =3D=3D NULL) { error_setg(errp, "unix connect: no path specified"); @@ -949,21 +963,32 @@ static int unix_connect_saddr(UnixSocketAddress *sadd= r, Error **errp) } =20 pathlen =3D strlen(saddr->path); - if (pathlen > sizeof(un.sun_path)) { + if (pathlen > sizeof(un.sun_path) || + (saddr->abstract && pathlen > (sizeof(un.sun_path) - 1))) { error_setg(errp, "UNIX socket path '%s' is too long", saddr->path); error_append_hint(errp, "Path must be less than %zu bytes\n", + saddr->abstract ? sizeof(un.sun_path) - 1 : sizeof(un.sun_path)); goto err; } =20 memset(&un, 0, sizeof(un)); un.sun_family =3D AF_UNIX; - memcpy(un.sun_path, saddr->path, pathlen); + addrlen =3D sizeof(un); =20 + if (saddr->abstract) { + un.sun_path[0] =3D '\0'; + memcpy(&un.sun_path[1], saddr->path, pathlen); + if (saddr->tight) { + addrlen =3D offsetof(struct sockaddr_un, sun_path) + 1 + pathl= en; + } + } else { + memcpy(un.sun_path, saddr->path, pathlen); + } /* connect to peer */ do { rc =3D 0; - if (connect(sock, (struct sockaddr *) &un, sizeof(un)) < 0) { + if (connect(sock, (struct sockaddr *) &un, addrlen) < 0) { rc =3D -errno; } } while (rc =3D=3D -EINTR); --=20 2.26.2 From nobody Fri Nov 14 19:22:17 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1589979770; cv=none; d=zohomail.com; s=zohoarc; b=iZ7gFAtwkMOGFQI0oJ5gBXMuuWu57QIEqyYymkryGcNxqmF2jYFSUf0I3p0Qk+yE6MZrD9REuqXbiUN9Yd0O5r2sAimVSMcH0MQmxEX4BoJinlKxLEo+Q6dOc2BsK8M3ydOGquI9OWbLxx9hVzn71YSxJQ62fItD7RKd0MTSQcs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1589979770; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=y0DGTd+YS1rJ35uWK7JwTQ+j527Kyn929jw0GYQAMEo=; b=RqQCzQZNj+Tw846NBXjpNgxLKIISzU34GVT+Is2r9YJ0BLu1zyq3BOWLkdAWoeBh3lgN0kkuDQy5uFxhbZ+u7RVVQ0CRcUu2630BGmhj5V3fDH0jjJGSVZG950iqef+/0of3jquzE+4o2b+4stOQ7/vRqMosib04Bat929m0wKw= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1589979770108278.9005575195497; Wed, 20 May 2020 06:02:50 -0700 (PDT) Received: from localhost ([::1]:56860 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jbOMy-0004X1-N1 for importer@patchew.org; Wed, 20 May 2020 09:02:48 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:44094) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jbOL4-0002LP-1G for qemu-devel@nongnu.org; Wed, 20 May 2020 09:00:50 -0400 Received: from us-smtp-delivery-1.mimecast.com ([207.211.31.120]:57288 helo=us-smtp-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1jbOL0-0004rH-A8 for qemu-devel@nongnu.org; Wed, 20 May 2020 09:00:49 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-349-kzlC-NSSMLWnlSrj7TYkWw-1; Wed, 20 May 2020 09:00:42 -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 mimecast-mx01.redhat.com (Postfix) with ESMTPS id D876B18FE867; Wed, 20 May 2020 13:00:41 +0000 (UTC) Received: from localhost.localdomain.com (unknown [10.36.110.3]) by smtp.corp.redhat.com (Postfix) with ESMTP id D77981024879; Wed, 20 May 2020 13:00:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1589979645; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=y0DGTd+YS1rJ35uWK7JwTQ+j527Kyn929jw0GYQAMEo=; b=ReleTagVS4UAdX6wYh5q6KOKYSsJ9wgZTL8S0Y68wJ6EXgU+1f+/vJB6KaKhTV3E+u8Oo4 fLrCoWU1PjstcHuixyn2UM0btgt3lBKip5Q0KhbJmT+NI/2822TJWdAlVcXIo4FCu73ssb b/uCtWUKQ+kNYCohMhPkRfp5hldQSr4= X-MC-Unique: kzlC-NSSMLWnlSrj7TYkWw-1 From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: qemu-devel@nongnu.org Subject: [PULL 2/3] tests/util-sockets: add abstract unix socket cases Date: Wed, 20 May 2020 14:00:24 +0100 Message-Id: <20200520130025.2201467-3-berrange@redhat.com> In-Reply-To: <20200520130025.2201467-1-berrange@redhat.com> References: <20200520130025.2201467-1-berrange@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=207.211.31.120; envelope-from=berrange@redhat.com; helo=us-smtp-1.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/05/20 01:34:51 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_PASS=-0.001 autolearn=_AUTOLEARN X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , xiaoqiang zhao , Markus Armbruster , 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-DKIM: fail (Header signature does not verify) From: xiaoqiang zhao add cases to test tight and non-tight for abstract address type Signed-off-by: xiaoqiang zhao Signed-off-by: Daniel P. Berrang=C3=A9 --- tests/test-util-sockets.c | 92 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 92 insertions(+) diff --git a/tests/test-util-sockets.c b/tests/test-util-sockets.c index 5fd947c7bf..2ca1e99f17 100644 --- a/tests/test-util-sockets.c +++ b/tests/test-util-sockets.c @@ -227,6 +227,93 @@ static void test_socket_fd_pass_num_nocli(void) g_free(addr.u.fd.str); } =20 +#ifdef __linux__ +static gchar *abstract_sock_name; + +static gpointer unix_server_thread_func(gpointer user_data) +{ + SocketAddress addr; + Error *err =3D NULL; + int fd =3D -1; + int connfd =3D -1; + struct sockaddr_un un; + socklen_t len =3D sizeof(un); + + addr.type =3D SOCKET_ADDRESS_TYPE_UNIX; + addr.u.q_unix.path =3D abstract_sock_name; + addr.u.q_unix.tight =3D user_data !=3D NULL; + addr.u.q_unix.abstract =3D true; + + fd =3D socket_listen(&addr, 1, &err); + g_assert_cmpint(fd, >=3D, 0); + g_assert(fd_is_socket(fd)); + + connfd =3D accept(fd, (struct sockaddr *)&un, &len); + g_assert_cmpint(connfd, !=3D, -1); + + close(fd); + + return NULL; +} + +static gpointer unix_client_thread_func(gpointer user_data) +{ + SocketAddress addr; + Error *err =3D NULL; + int fd =3D -1; + + addr.type =3D SOCKET_ADDRESS_TYPE_UNIX; + addr.u.q_unix.path =3D abstract_sock_name; + addr.u.q_unix.tight =3D user_data !=3D NULL; + addr.u.q_unix.abstract =3D true; + + fd =3D socket_connect(&addr, &err); + + g_assert_cmpint(fd, >=3D, 0); + + close(fd); + + return NULL; +} + +static void test_socket_unix_abstract_good(void) +{ + GRand *r =3D g_rand_new(); + + abstract_sock_name =3D g_strdup_printf("unix-%d-%d", getpid(), + g_rand_int_range(r, 100, 1000)); + + /* non tight socklen serv and cli */ + GThread *serv =3D g_thread_new("abstract_unix_server", + unix_server_thread_func, + NULL); + + sleep(1); + + GThread *cli =3D g_thread_new("abstract_unix_client", + unix_client_thread_func, + NULL); + + g_thread_join(cli); + g_thread_join(serv); + + /* tight socklen serv and cli */ + serv =3D g_thread_new("abstract_unix_server", + unix_server_thread_func, + (gpointer)1); + + sleep(1); + + cli =3D g_thread_new("abstract_unix_client", + unix_client_thread_func, + (gpointer)1); + + g_thread_join(cli); + g_thread_join(serv); + + g_free(abstract_sock_name); +} +#endif =20 int main(int argc, char **argv) { @@ -265,6 +352,11 @@ int main(int argc, char **argv) test_socket_fd_pass_num_nocli); } =20 +#ifdef __linux__ + g_test_add_func("/util/socket/unix-abstract/good", + test_socket_unix_abstract_good); +#endif + end: return g_test_run(); } --=20 2.26.2 From nobody Fri Nov 14 19:22:17 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1589979770; cv=none; d=zohomail.com; s=zohoarc; b=FyZHzkyHvci2FremW0yODcp8b3hCaBy5kCEiG0iPuAB7x4W90gGQbtUPtz/VpsceFIvoEUISoRZf3DETMUvznFV8tHHVd8IxH5/pZa9vrE/Xjc3a9k/YGLjHn1Ow/FWgaoTzg0vbM5B5zsEis5ah3BhKBuYcNnd6q9SJ7rPM81g= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1589979770; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=B9ZnP4tlZDYSDoaUAQh/MuI/l0EB+JyZh0JVk4VUu10=; b=dXbFEs2WCJH7qJZSyMeLKaV9ifMLc8NspI6BUrWUDxDSiXgwPf3OszWZx4TUrz8kvNBMDiu9N93os+QhtGEb/0SKyxMpmk9uLwjooRYRmiy+pXiQIU/OFuVtPUwISo7nTQ/VtL2ebBQ8UTy6TOeqv0VNG6oTnZH0pRKcbxZFYak= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1589979770428764.8324937751905; Wed, 20 May 2020 06:02:50 -0700 (PDT) Received: from localhost ([::1]:56946 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jbOMz-0004Z5-1r for importer@patchew.org; Wed, 20 May 2020 09:02:49 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:44104) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jbOL5-0002MP-1H for qemu-devel@nongnu.org; Wed, 20 May 2020 09:00:51 -0400 Received: from us-smtp-1.mimecast.com ([207.211.31.81]:39540 helo=us-smtp-delivery-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1jbOL3-0004rS-TJ for qemu-devel@nongnu.org; Wed, 20 May 2020 09:00:50 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-223-_Z_6zvZROvu9WKZWcYHCjA-1; Wed, 20 May 2020 09:00:46 -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 mimecast-mx01.redhat.com (Postfix) with ESMTPS id 5239FA0BDA; Wed, 20 May 2020 13:00:45 +0000 (UTC) Received: from localhost.localdomain.com (unknown [10.36.110.3]) by smtp.corp.redhat.com (Postfix) with ESMTP id 94A6A10429CB; Wed, 20 May 2020 13:00:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1589979648; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=B9ZnP4tlZDYSDoaUAQh/MuI/l0EB+JyZh0JVk4VUu10=; b=ABsizYvZ2rAo5MlAQSMmt2USkncvpDoai/sSmU8Ncyci2PMfgbnTAU221pfPhxT8uj/EXg 3Jcvf0Ru1tbiTxeb86LrMDyKr8E64a1MnkPnp9goCn5b1Y5DGedQhg9Nw/j35/rPvRVMXy oW2NIBhZml2gsqa83pYGVLalyheGEyc= X-MC-Unique: _Z_6zvZROvu9WKZWcYHCjA-1 From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: qemu-devel@nongnu.org Subject: [PULL 3/3] qemu-options: updates for abstract unix sockets Date: Wed, 20 May 2020 14:00:25 +0100 Message-Id: <20200520130025.2201467-4-berrange@redhat.com> In-Reply-To: <20200520130025.2201467-1-berrange@redhat.com> References: <20200520130025.2201467-1-berrange@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=207.211.31.81; envelope-from=berrange@redhat.com; helo=us-smtp-delivery-1.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/05/20 04:09:34 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_PASS=-0.001 autolearn=_AUTOLEARN X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , xiaoqiang zhao , Markus Armbruster , 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-DKIM: fail (Header signature does not verify) From: xiaoqiang zhao add options documents changes for -chardev Signed-off-by: xiaoqiang zhao Signed-off-by: Daniel P. Berrang=C3=A9 --- qemu-options.hx | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/qemu-options.hx b/qemu-options.hx index e2dca8a4e9..93bde2bbc8 100644 --- a/qemu-options.hx +++ b/qemu-options.hx @@ -2938,7 +2938,7 @@ DEF("chardev", HAS_ARG, QEMU_OPTION_chardev, " [,server][,nowait][,telnet][,websocket][,reconnect=3Dseconds= ][,mux=3Don|off]\n" " [,logfile=3DPATH][,logappend=3Don|off][,tls-creds=3DID][,tls= -authz=3DID] (tcp)\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" + " [,mux=3Don|off][,logfile=3DPATH][,logappend=3Don|off][,abstr= act=3Don|off][,tight=3Don|off] (unix)\n" "-chardev udp,id=3Did[,host=3Dhost],port=3Dport[,localaddr=3Dlocaladdr= ]\n" " [,localport=3Dlocalport][,ipv4][,ipv6][,mux=3Don|off]\n" " [,logfile=3DPATH][,logappend=3Don|off]\n" @@ -3105,9 +3105,13 @@ The available backends are: =20 ``nodelay`` disables the Nagle algorithm. =20 - ``unix options: path=3Dpath`` + ``unix options: path=3Dpath[,abstract=3Don|off][,tight=3Don|off]`` ``path`` specifies the local path of the unix socket. ``path`` is required. + ``abstract`` specifies the use of the abstract socket namespace, + rather than the filesystem. Optional, defaults to false. + ``tight`` sets the socket length of abstract sockets to their mini= mum, + rather than the full sun_path length. Optional, defaults to true. =20 ``-chardev udp,id=3Did[,host=3Dhost],port=3Dport[,localaddr=3Dlocaladdr][,= localport=3Dlocalport][,ipv4][,ipv6]`` Sends all traffic from the guest to a remote host over UDP. --=20 2.26.2