From nobody Mon Feb 9 20:30:30 2026 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 (208.118.235.17 [208.118.235.17]) by mx.zohomail.com with SMTPS id 1513950670728702.8771711978686; Fri, 22 Dec 2017 05:51:10 -0800 (PST) Received: from localhost ([::1]:51203 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eSNj6-0001VS-Jh for importer@patchew.org; Fri, 22 Dec 2017 08:51:04 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:47788) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eSNeM-0006Wm-8x for qemu-devel@nongnu.org; Fri, 22 Dec 2017 08:46:11 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eSNeL-00034B-BV for qemu-devel@nongnu.org; Fri, 22 Dec 2017 08:46:10 -0500 Received: from mx1.redhat.com ([209.132.183.28]:48972) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1eSNeL-00033U-2e for qemu-devel@nongnu.org; Fri, 22 Dec 2017 08:46:09 -0500 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 2D14C4B9A for ; Fri, 22 Dec 2017 13:46:08 +0000 (UTC) Received: from t460.redhat.com (unknown [10.33.36.43]) by smtp.corp.redhat.com (Postfix) with ESMTP id F41CA17CF4; Fri, 22 Dec 2017 13:46:05 +0000 (UTC) From: "Daniel P. Berrange" To: qemu-devel@nongnu.org Date: Fri, 22 Dec 2017 13:45:26 +0000 Message-Id: <20171222134527.14467-8-berrange@redhat.com> In-Reply-To: <20171222134527.14467-1-berrange@redhat.com> References: <20171222134527.14467-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]); Fri, 22 Dec 2017 13:46: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 v3 7/8] char: refactor parsing of socket address information 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: "Dr. David Alan Gilbert" , Markus Armbruster , =?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" To prepare for handling more address types, refactor the parsing of socket address information to make it more robust and extensible. Signed-off-by: Daniel P. Berrange Reviewed-by: Marc-Andr=C3=A9 Lureau --- chardev/char-socket.c | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/chardev/char-socket.c b/chardev/char-socket.c index 6013972f72..9113ea0169 100644 --- a/chardev/char-socket.c +++ b/chardev/char-socket.c @@ -987,21 +987,25 @@ static void qemu_chr_parse_socket(QemuOpts *opts, Cha= rdevBackend *backend, SocketAddressLegacy *addr; ChardevSocket *sock; =20 + if ((!!path + !!host) !=3D 1) { + error_setg(errp, + "Exactly one of 'path' or 'host' required"); + return; + } + backend->type =3D CHARDEV_BACKEND_KIND_SOCKET; - if (!path) { - if (!host) { - error_setg(errp, "chardev: socket: no host given"); + if (path) { + if (tls_creds) { + error_setg(errp, "TLS can only be used over TCP socket"); return; } + } else if (host) { if (!port) { error_setg(errp, "chardev: socket: no port given"); return; } } else { - if (tls_creds) { - error_setg(errp, "TLS can only be used over TCP socket"); - return; - } + g_assert_not_reached(); } =20 sock =3D backend->u.socket.data =3D g_new0(ChardevSocket, 1); @@ -1027,7 +1031,7 @@ 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); - } else { + } else if (host) { addr->type =3D SOCKET_ADDRESS_LEGACY_KIND_INET; addr->u.inet.data =3D g_new(InetSocketAddress, 1); *addr->u.inet.data =3D (InetSocketAddress) { @@ -1040,6 +1044,8 @@ static void qemu_chr_parse_socket(QemuOpts *opts, Cha= rdevBackend *backend, .has_ipv6 =3D qemu_opt_get(opts, "ipv6"), .ipv6 =3D qemu_opt_get_bool(opts, "ipv6", 0), }; + } else { + g_assert_not_reached(); } sock->addr =3D addr; } --=20 2.14.3