From nobody Thu Nov 14 23:44:30 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; 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 Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1666347151610267.9453327699597; Fri, 21 Oct 2022 03:12:31 -0700 (PDT) Received: from localhost ([::1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1olp0u-00074g-SE for importer@patchew.org; Fri, 21 Oct 2022 06:12:29 -0400 Received: from [::1] (helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1olo3K-0005s4-7E for importer@patchew.org; Fri, 21 Oct 2022 05:10:54 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1olo2e-00044g-2F for qemu-devel@nongnu.org; Fri, 21 Oct 2022 05:10:12 -0400 Received: from mout.kundenserver.de ([212.227.17.24]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1olo2N-0001xu-Mu for qemu-devel@nongnu.org; Fri, 21 Oct 2022 05:10:11 -0400 Received: from lenovo-t14s.redhat.com ([82.142.8.70]) by mrelayeu.kundenserver.de (mreue106 [212.227.15.183]) with ESMTPSA (Nemesis) id 1MiZof-1pHaXg30Zr-00ffBX; Fri, 21 Oct 2022 11:09:43 +0200 From: Laurent Vivier To: qemu-devel@nongnu.org Cc: Thomas Huth , xen-devel@lists.xenproject.org, "Dr. David Alan Gilbert" , Laurent Vivier , Anthony Perard , Stefan Weil , David Gibson , Stefano Stabellini , Paul Durrant , Eric Blake , "Michael S. Tsirkin" , Jason Wang , Paolo Bonzini , Markus Armbruster , Samuel Thibault , Greg Kurz , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Stefano Brivio Subject: [PATCH v14 12/17] net: dgram: add unix socket Date: Fri, 21 Oct 2022 11:09:17 +0200 Message-Id: <20221021090922.170074-13-lvivier@redhat.com> X-Mailer: git-send-email 2.37.3 In-Reply-To: <20221021090922.170074-1-lvivier@redhat.com> References: <20221021090922.170074-1-lvivier@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Provags-ID: V03:K1:plAtbOq7N1vqh85nD7nLk6P7PLf2d34vKgInHBtGPREI/Tar53b 0MN6/T5us3//M++U/mCcZ29HpvkdndwotX17ipWj9nGm7gZvuKVzX27IHeeJ26FnSFWpTXt PrWcriYhtMuU4jmr5rpJ6RIxnRmzUlN23SSZ9izZtjNnuxgJdwUZAAszeEJ2j1wAEMBMIM9 0hFOwrJtw5VUlWGUDx1Mg== X-UI-Out-Filterresults: notjunk:1;V03:K0:MBe1IeTIDoU=:LB4a1GVaMy39FnOeTHMlas BBckVBiRGEM1soJUdAGmoQHyHnhBw6meiupphkkHYmOI/+sfL0Jwe3MGmhCiqiIz6yweXKNAr PC23pfzgIozdb8vdV8H5G24Mi3ChQKFsRmo4FYoAwi85pUzvx/epwMNw4v7sZbKl/6yvVzG0b eGZsvtaxXge+rac9/tBcTRFXYmZd+fz1t8loGkXepcdRd8iNSnGA+XB35dB5hiZOoUbR3PnkK GyQTtDpmWiQ0CXoHyYFg0nLLK5srM5QyNW19a4huYwe52KrfvmqiIDKaf/SMw1dTnjXvpRc3H JiH6Nmue8dCQ9HxlqBCzTrD1tqFSZEMV9vJpecNbDPDre80XmK+9HB+Of1b8JU34SGk1K/4KS aTrxF8xfU+6xJ9QNysMLy7aKm5c+Z3pekc/z2MulDI88QKBF0jBJJllyHimlDQRql8dMhmheZ o+/DZpObwPOHnKodueLuAUYMu8oFmIyBAoI7k+Bfod7NX/ry0/gRU6APVXQhRu1WhXC2JEv3k eTB+KR4lXH/IRLAV2gsVAKQfSiWkfU2VfaFVcIKUum24zeO2rkc1yuLHLCAxzVasEZyFnRyxC 3pCwABY+gAvyvC5XhA1daYkFGsXGJME3YtabfB4E+wmItG5cs0xTaCM1xluYeHzHhSbHoBIHl 4rIr2EfLjbQE4Kc0j7ES9Lyx3odwja0X8LyOwnK/GeG0ohekZXR9avGsXmn81/hXsyeIP50IC n5TuOspfnRuUFMGKnMmYmAbgh6F844AZAut2Vplp2I/hGvX1rdjR0yn3g3EhWpsDzc6PGqFVN qvUR39p 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: permerror client-ip=212.227.17.24; envelope-from=lvivier@redhat.com; helo=mout.kundenserver.de X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, SPF_FAIL=0.001, SPF_HELO_NONE=0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZM-MESSAGEID: 1666347153765100003 Content-Type: text/plain; charset="utf-8" Signed-off-by: Laurent Vivier Reviewed-by: Stefano Brivio Reviewed-by: David Gibson Acked-by: Michael S. Tsirkin Acked-by: Markus Armbruster (QAPI schema) --- net/dgram.c | 55 ++++++++++++++++++++++++++++++++++++++++++++++++- qapi/net.json | 2 +- qemu-options.hx | 1 + 3 files changed, 56 insertions(+), 2 deletions(-) diff --git a/net/dgram.c b/net/dgram.c index e581cc62f39f..9f7bf3837653 100644 --- a/net/dgram.c +++ b/net/dgram.c @@ -426,6 +426,7 @@ int net_init_dgram(const Netdev *netdev, const char *na= me, SocketAddress *remote, *local; struct sockaddr *dest_addr; struct sockaddr_in laddr_in, raddr_in; + struct sockaddr_un laddr_un, raddr_un; socklen_t dest_len; =20 assert(netdev->type =3D=3D NET_CLIENT_DRIVER_DGRAM); @@ -465,7 +466,8 @@ int net_init_dgram(const Netdev *netdev, const char *na= me, } } else { if (local->type !=3D SOCKET_ADDRESS_TYPE_FD) { - error_setg(errp, "type=3Dinet requires remote parameter"); + error_setg(errp, + "type=3Dinet or type=3Dunix requires remote paramet= er"); return -1; } } @@ -508,6 +510,53 @@ int net_init_dgram(const Netdev *netdev, const char *n= ame, dest_addr =3D g_malloc(dest_len); memcpy(dest_addr, &raddr_in, dest_len); break; + case SOCKET_ADDRESS_TYPE_UNIX: + ret =3D unlink(local->u.q_unix.path); + if (ret < 0 && errno !=3D ENOENT) { + error_setg_errno(errp, errno, "failed to unlink socket %s", + local->u.q_unix.path); + return -1; + } + + laddr_un.sun_family =3D PF_UNIX; + ret =3D snprintf(laddr_un.sun_path, sizeof(laddr_un.sun_path), "%s= ", + local->u.q_unix.path); + if (ret < 0 || ret >=3D sizeof(laddr_un.sun_path)) { + error_setg(errp, "UNIX socket path '%s' is too long", + local->u.q_unix.path); + error_append_hint(errp, "Path must be less than %zu bytes\n", + sizeof(laddr_un.sun_path)); + } + + raddr_un.sun_family =3D PF_UNIX; + ret =3D snprintf(raddr_un.sun_path, sizeof(raddr_un.sun_path), "%s= ", + remote->u.q_unix.path); + if (ret < 0 || ret >=3D sizeof(raddr_un.sun_path)) { + error_setg(errp, "UNIX socket path '%s' is too long", + remote->u.q_unix.path); + error_append_hint(errp, "Path must be less than %zu bytes\n", + sizeof(raddr_un.sun_path)); + } + + fd =3D qemu_socket(PF_UNIX, SOCK_DGRAM, 0); + if (fd < 0) { + error_setg_errno(errp, errno, "can't create datagram socket"); + return -1; + } + + ret =3D bind(fd, (struct sockaddr *)&laddr_un, sizeof(laddr_un)); + if (ret < 0) { + error_setg_errno(errp, errno, "can't bind unix=3D%s to socket", + laddr_un.sun_path); + closesocket(fd); + return -1; + } + qemu_socket_set_nonblock(fd); + + dest_len =3D sizeof(raddr_un); + dest_addr =3D g_malloc(dest_len); + memcpy(dest_addr, &raddr_un, dest_len); + break; case SOCKET_ADDRESS_TYPE_FD: fd =3D monitor_fd_param(monitor_cur(), local->u.fd.str, errp); if (fd =3D=3D -1) { @@ -546,6 +595,10 @@ int net_init_dgram(const Netdev *netdev, const char *n= ame, inet_ntoa(raddr_in.sin_addr), ntohs(raddr_in.sin_port)); break; + case SOCKET_ADDRESS_TYPE_UNIX: + qemu_set_info_str(&s->nc, "udp=3D%s:%s", + laddr_un.sun_path, raddr_un.sun_path); + break; case SOCKET_ADDRESS_TYPE_FD: { SocketAddress *sa; SocketAddressType sa_type; diff --git a/qapi/net.json b/qapi/net.json index aed4ce1a97ff..39388b1b6c41 100644 --- a/qapi/net.json +++ b/qapi/net.json @@ -600,7 +600,7 @@ # @remote: remote address # @local: local address # -# Only SocketAddress types 'inet' and 'fd' are supported. +# Only SocketAddress types 'unix', 'inet' and 'fd' are supported. # # If remote address is present and it's a multicast address, local address # is optional. Otherwise local address is required and remote address is diff --git a/qemu-options.hx b/qemu-options.hx index 98e2595df93b..fafb214cb89f 100644 --- a/qemu-options.hx +++ b/qemu-options.hx @@ -2782,6 +2782,7 @@ DEF("netdev", HAS_ARG, QEMU_OPTION_netdev, " configure a network backend to connect to a multicast= maddr and port\n" " use ``local.host=3Daddr`` to specify the host address= to send packets from\n" "-netdev dgram,id=3Dstr,local.type=3Dinet,local.host=3Daddr,local.port= =3Dport[,remote.type=3Dinet,remote.host=3Daddr,remote.port=3Dport]\n" + "-netdev dgram,id=3Dstr,local.type=3Dunix,local.path=3Dpath[,remote.ty= pe=3Dunix,remote.path=3Dpath]\n" "-netdev dgram,id=3Dstr,local.type=3Dfd,local.str=3Dfile-descriptor\n" " configure a network backend to connect to another net= work\n" " using an UDP tunnel\n" --=20 2.37.3