From nobody Thu May 2 02:59:17 2024 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=yandex-team.ru ARC-Seal: i=1; a=rsa-sha256; t=1604880336; cv=none; d=zohomail.com; s=zohoarc; b=nFHlEu6+TlEA0DFu+Z4apBU3s6cg0Xz72qwlot/WHbDBaFjl1Cot+ZV/R6E0ciX/ydgUpuAT5BJWmMNBXob2RP5PL4goRcoHx2VAnc3Q/OsHQleRpUSZ5wvd7dJhReoG7wNlJKneZs6ntYlymtzeJ9AcXgb49pqRaxokdy8U9vg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1604880336; h=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=6XMuXQANeZNQeEYpUeHlFOpliQv6NfAwA+bA1mnuD00=; b=X8Vonot0uCuTo7nr7hIqDrcamfDyqAMaPWKY16M3R/x98kvIdPtOB7jH3+PklLuV3s6RM/AFIOef7cU3Z2THIiTavqdY3ZdaTbP7VcAu6Zbi35jUl/YFpph15p1s2jk8R+Px1e+uiIS7mfRbz0mDpYWbZrkmBHV8TxCqnh4aXMU= 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 1604880336488644.8858452859246; Sun, 8 Nov 2020 16:05:36 -0800 (PST) Received: from localhost ([::1]:60800 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kbugh-0008Nj-6l for importer@patchew.org; Sun, 08 Nov 2020 19:05:35 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:49308) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kbubn-0003RZ-D3 for qemu-devel@nongnu.org; Sun, 08 Nov 2020 19:00:31 -0500 Received: from forwardcorp1p.mail.yandex.net ([77.88.29.217]:52334) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kbubj-0003uL-Kb for qemu-devel@nongnu.org; Sun, 08 Nov 2020 19:00:31 -0500 Received: from sas1-5717c3cea310.qloud-c.yandex.net (sas1-5717c3cea310.qloud-c.yandex.net [IPv6:2a02:6b8:c14:3616:0:640:5717:c3ce]) by forwardcorp1p.mail.yandex.net (Yandex) with ESMTP id 9AD682E037C; Mon, 9 Nov 2020 03:00:24 +0300 (MSK) Received: from sas2-c156b1cb922a.qloud-c.yandex.net (sas2-c156b1cb922a.qloud-c.yandex.net [2a02:6b8:c08:b78e:0:640:c156:b1cb]) by sas1-5717c3cea310.qloud-c.yandex.net (mxbackcorp/Yandex) with ESMTP id TOyGphYiF1-0NwuE4bn; Mon, 09 Nov 2020 03:00:24 +0300 Received: from dynamic-vpn.dhcp.yndx.net (dynamic-vpn.dhcp.yndx.net [2a02:6b8:b081:425::1:0]) by sas2-c156b1cb922a.qloud-c.yandex.net (smtpcorp/Yandex) with ESMTPSA id AEjcvNO5zB-05nCNlmg; Mon, 09 Nov 2020 03:00:23 +0300 (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (Client certificate not present) Precedence: bulk DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex-team.ru; s=default; t=1604880024; bh=6XMuXQANeZNQeEYpUeHlFOpliQv6NfAwA+bA1mnuD00=; h=In-Reply-To:Message-Id:References:Date:Subject:To:From:Cc; b=R6rlsiMgYC0YE+9STjP8pFqPM+/Qz7JAjlu/uCsLy3MLo0RImLyIDBNrk8X9ExPhT ll/dGNOM0+O642OlR0baRM5pTLq0rkr05p4x2gxIn9nB+YG1BvEVW+3RRnBBvjL8RB e9q9Nw3aETJ0Oqgp2MyVmqWQ0nf+tdX9DyYLcf0M= Authentication-Results: sas1-5717c3cea310.qloud-c.yandex.net; dkim=pass header.i=@yandex-team.ru From: Alexey Kirillov To: Jason Wang , Eric Blake , Markus Armbruster , Thomas Huth Subject: [PATCH v5 1/4] qapi: net: Add query-netdev command Date: Mon, 9 Nov 2020 02:59:49 +0300 Message-Id: <20201108235952.107961-2-lekiravi@yandex-team.ru> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20201108235952.107961-1-lekiravi@yandex-team.ru> References: <20201108235952.107961-1-lekiravi@yandex-team.ru> MIME-Version: 1.0 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=77.88.29.217; envelope-from=lekiravi@yandex-team.ru; helo=forwardcorp1p.mail.yandex.net X-detected-operating-system: by eggs.gnu.org: First seen = 2020/11/08 19:00:25 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Laurent Vivier , "Michael S. Tsirkin" , Stefan Weil , qemu-devel@nongnu.org, Vincenzo Maffione , yc-core@yandex-team.ru, Paolo Bonzini , Samuel Thibault , Giuseppe Lettieri , Luigi Rizzo Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Add a qmp command that provides information about currently attached backend network devices and their configuration. Signed-off-by: Alexey Kirillov Acked-by: Markus Armbruster --- include/net/net.h | 1 + net/l2tpv3.c | 19 +++++++ net/net.c | 32 ++++++++++++ net/netmap.c | 13 +++++ net/slirp.c | 126 ++++++++++++++++++++++++++++++++++++++++++++++ net/socket.c | 71 ++++++++++++++++++++++++++ net/tap-win32.c | 9 ++++ net/tap.c | 103 +++++++++++++++++++++++++++++++++++-- net/vde.c | 26 ++++++++++ net/vhost-user.c | 18 +++++-- net/vhost-vdpa.c | 14 ++++++ qapi/net.json | 80 +++++++++++++++++++++++++++++ 12 files changed, 504 insertions(+), 8 deletions(-) diff --git a/include/net/net.h b/include/net/net.h index 897b2d7595..16700f715e 100644 --- a/include/net/net.h +++ b/include/net/net.h @@ -92,6 +92,7 @@ struct NetClientState { char *model; char *name; char info_str[256]; + NetdevInfo *stored_config; unsigned receive_disabled : 1; NetClientDestructor *destructor; unsigned int queue_index; diff --git a/net/l2tpv3.c b/net/l2tpv3.c index 55fea17c0f..881fc6f7c1 100644 --- a/net/l2tpv3.c +++ b/net/l2tpv3.c @@ -535,6 +535,7 @@ int net_init_l2tpv3(const Netdev *netdev, struct addrinfo hints; struct addrinfo *result =3D NULL; char *srcport, *dstport; + NetdevL2TPv3Options *stored; =20 nc =3D qemu_new_net_client(&net_l2tpv3_info, peer, "l2tpv3", name); =20 @@ -726,6 +727,24 @@ int net_init_l2tpv3(const Netdev *netdev, =20 l2tpv3_read_poll(s, true); =20 + /* Store startup parameters */ + nc->stored_config =3D g_new0(NetdevInfo, 1); + nc->stored_config->type =3D NET_BACKEND_L2TPV3; + stored =3D &nc->stored_config->u.l2tpv3; + + memcpy(stored, l2tpv3, sizeof(NetdevL2TPv3Options)); + + stored->src =3D g_strdup(l2tpv3->src); + stored->dst =3D g_strdup(l2tpv3->dst); + + if (l2tpv3->has_srcport) { + stored->srcport =3D g_strdup(l2tpv3->srcport); + } + + if (l2tpv3->has_dstport) { + stored->dstport =3D g_strdup(l2tpv3->dstport); + } + snprintf(s->nc.info_str, sizeof(s->nc.info_str), "l2tpv3: connected"); return 0; diff --git a/net/net.c b/net/net.c index 794c652282..551acadabc 100644 --- a/net/net.c +++ b/net/net.c @@ -54,6 +54,7 @@ #include "sysemu/sysemu.h" #include "net/filter.h" #include "qapi/string-output-visitor.h" +#include "qapi/clone-visitor.h" =20 /* Net bridge is currently not supported for W32. */ #if !defined(_WIN32) @@ -351,6 +352,7 @@ static void qemu_free_net_client(NetClientState *nc) } g_free(nc->name); g_free(nc->model); + qapi_free_NetdevInfo(nc->stored_config); if (nc->destructor) { nc->destructor(nc); } @@ -1253,6 +1255,36 @@ RxFilterInfoList *qmp_query_rx_filter(bool has_name,= const char *name, return filter_list; } =20 +NetdevInfoList *qmp_query_netdev(Error **errp) +{ + NetdevInfoList *list =3D NULL; + NetClientState *nc; + + QTAILQ_FOREACH(nc, &net_clients, next) { + /* + * Only look at netdevs (backend network devices), not for each qu= eue + * or NIC / hubport + */ + if (nc->stored_config) { + NetdevInfoList *node =3D g_new0(NetdevInfoList, 1); + + node->value =3D QAPI_CLONE(NetdevInfo, nc->stored_config); + g_free(node->value->id); /* Need to dealloc default empty id */ + node->value->id =3D g_strdup(nc->name); + + node->value->has_peer_id =3D nc->peer !=3D NULL; + if (node->value->has_peer_id) { + node->value->peer_id =3D g_strdup(nc->peer->name); + } + + node->next =3D list; + list =3D node; + } + } + + return list; +} + void hmp_info_network(Monitor *mon, const QDict *qdict) { NetClientState *nc, *peer; diff --git a/net/netmap.c b/net/netmap.c index 350f097f91..b6087fdb7c 100644 --- a/net/netmap.c +++ b/net/netmap.c @@ -411,6 +411,7 @@ int net_init_netmap(const Netdev *netdev, NetClientState *nc; Error *err =3D NULL; NetmapState *s; + NetdevNetmapOptions *stored; =20 nmd =3D netmap_open(netmap_opts, &err); if (err) { @@ -427,6 +428,18 @@ int net_init_netmap(const Netdev *netdev, pstrcpy(s->ifname, sizeof(s->ifname), netmap_opts->ifname); netmap_read_poll(s, true); /* Initially only poll for reads. */ =20 + /* Store startup parameters */ + nc->stored_config =3D g_new0(NetdevInfo, 1); + nc->stored_config->type =3D NET_BACKEND_NETMAP; + stored =3D &nc->stored_config->u.netmap; + + stored->ifname =3D g_strdup(netmap_opts->ifname); + + if (netmap_opts->has_devname) { + stored->has_devname =3D true; + stored->devname =3D g_strdup(netmap_opts->devname); + } + return 0; } =20 diff --git a/net/slirp.c b/net/slirp.c index 77042e6df7..65d3f2639c 100644 --- a/net/slirp.c +++ b/net/slirp.c @@ -346,6 +346,14 @@ static SaveVMHandlers savevm_slirp_state =3D { .load_state =3D net_slirp_state_load, }; =20 +#define APPEND_STRINGLIST(tail, new_val) \ + do { \ + *(tail) =3D g_new0(StringList, 1); \ + (*(tail))->value =3D g_new0(String, 1); \ + (*(tail))->value->str =3D g_strdup((new_val)); \ + (tail) =3D &((*(tail))->next); \ + } while (0) + static int net_slirp_init(NetClientState *peer, const char *model, const char *name, int restricted, bool ipv4, const char *vnetwork, const char *vho= st, @@ -378,6 +386,9 @@ static int net_slirp_init(NetClientState *peer, const c= har *model, int shift; char *end; struct slirp_config_str *config; + NetdevUserOptions *stored; + StringList **stored_hostfwd; + StringList **stored_guestfwd; =20 if (!ipv4 && (vnetwork || vhost || vnameserver)) { error_setg(errp, "IPv4 disabled but netmask/host/dns provided"); @@ -553,6 +564,112 @@ static int net_slirp_init(NetClientState *peer, const= char *model, =20 nc =3D qemu_new_net_client(&net_slirp_info, peer, model, name); =20 + /* Store startup parameters */ + nc->stored_config =3D g_new0(NetdevInfo, 1); + nc->stored_config->type =3D NET_BACKEND_USER; + stored =3D &nc->stored_config->u.user; + + if (vhostname) { + stored->has_hostname =3D true; + stored->hostname =3D g_strdup(vhostname); + } + + stored->has_q_restrict =3D true; + stored->q_restrict =3D restricted; + + stored->has_ipv4 =3D true; + stored->ipv4 =3D ipv4; + + stored->has_ipv6 =3D true; + stored->ipv6 =3D ipv6; + + if (ipv4) { + uint8_t *net_bytes =3D (uint8_t *)&net; + uint8_t *mask_bytes =3D (uint8_t *)&mask; + + stored->has_net =3D true; + stored->net =3D g_strdup_printf("%d.%d.%d.%d/%d.%d.%d.%d", + net_bytes[0], net_bytes[1], + net_bytes[2], net_bytes[3], + mask_bytes[0], mask_bytes[1], + mask_bytes[2], mask_bytes[3]); + + stored->has_host =3D true; + stored->host =3D g_strdup(inet_ntoa(host)); + } + + if (tftp_export) { + stored->has_tftp =3D true; + stored->tftp =3D g_strdup(tftp_export); + } + + if (bootfile) { + stored->has_bootfile =3D true; + stored->bootfile =3D g_strdup(bootfile); + } + + if (vdhcp_start) { + stored->has_dhcpstart =3D true; + stored->dhcpstart =3D g_strdup(vdhcp_start); + } + + if (ipv4) { + stored->has_dns =3D true; + stored->dns =3D g_strdup(inet_ntoa(dns)); + } + + if (dnssearch) { + stored->has_dnssearch =3D true; + StringList **stored_list =3D &stored->dnssearch; + + for (int i =3D 0; dnssearch[i]; i++) { + APPEND_STRINGLIST(stored_list, dnssearch[i]); + } + } + + if (vdomainname) { + stored->has_domainname =3D true; + stored->domainname =3D g_strdup(vdomainname); + } + + if (ipv6) { + char addrstr[INET6_ADDRSTRLEN]; + const char *res; + + stored->has_ipv6_prefix =3D true; + stored->ipv6_prefix =3D g_strdup(vprefix6); + + stored->has_ipv6_prefixlen =3D true; + stored->ipv6_prefixlen =3D vprefix6_len; + + res =3D inet_ntop(AF_INET6, &ip6_host, + addrstr, sizeof(addrstr)); + + stored->has_ipv6_host =3D true; + stored->ipv6_host =3D g_strdup(res); + + res =3D inet_ntop(AF_INET6, &ip6_dns, + addrstr, sizeof(addrstr)); + + stored->has_ipv6_dns =3D true; + stored->ipv6_dns =3D g_strdup(res); + } + + if (smb_export) { + stored->has_smb =3D true; + stored->smb =3D g_strdup(smb_export); + } + + if (vsmbserver) { + stored->has_smbserver =3D true; + stored->smbserver =3D g_strdup(vsmbserver); + } + + if (tftp_server_name) { + stored->has_tftp_server_name =3D true; + stored->tftp_server_name =3D g_strdup(tftp_server_name); + } + snprintf(nc->info_str, sizeof(nc->info_str), "net=3D%s,restrict=3D%s", inet_ntoa(net), restricted ? "on" : "off"); @@ -582,14 +699,23 @@ static int net_slirp_init(NetClientState *peer, const= char *model, s->poll_notifier.notify =3D net_slirp_poll_notify; main_loop_poll_add_notifier(&s->poll_notifier); =20 + stored_hostfwd =3D &stored->hostfwd; + stored_guestfwd =3D &stored->guestfwd; + for (config =3D slirp_configs; config; config =3D config->next) { if (config->flags & SLIRP_CFG_HOSTFWD) { if (slirp_hostfwd(s, config->str, errp) < 0) { goto error; + } else { + stored->has_hostfwd =3D true; + APPEND_STRINGLIST(stored_hostfwd, config->str); } } else { if (slirp_guestfwd(s, config->str, errp) < 0) { goto error; + } else { + stored->has_guestfwd =3D true; + APPEND_STRINGLIST(stored_guestfwd, config->str); } } } diff --git a/net/socket.c b/net/socket.c index 15b410e8d8..1614523b82 100644 --- a/net/socket.c +++ b/net/socket.c @@ -342,6 +342,7 @@ static NetSocketState *net_socket_fd_init_dgram(NetClie= ntState *peer, NetSocketState *s; SocketAddress *sa; SocketAddressType sa_type; + NetdevSocketOptions *stored; =20 sa =3D socket_local_address(fd, errp); if (!sa) { @@ -385,8 +386,19 @@ static NetSocketState *net_socket_fd_init_dgram(NetCli= entState *peer, net_socket_rs_init(&s->rs, net_socket_rs_finalize, false); net_socket_read_poll(s, true); =20 + /* Store startup parameters */ + nc->stored_config =3D g_new0(NetdevInfo, 1); + nc->stored_config->type =3D NET_BACKEND_SOCKET; + stored =3D &nc->stored_config->u.socket; + + stored->has_fd =3D true; + stored->fd =3D g_strdup_printf("%d", fd); + /* mcast: save bound address as dst */ if (is_connected && mcast !=3D NULL) { + stored->has_mcast =3D true; + stored->mcast =3D g_strdup(mcast); + s->dgram_dst =3D saddr; snprintf(nc->info_str, sizeof(nc->info_str), "socket: fd=3D%d (cloned mcast=3D%s:%d)", @@ -428,6 +440,7 @@ static NetSocketState *net_socket_fd_init_stream(NetCli= entState *peer, { NetClientState *nc; NetSocketState *s; + NetdevSocketOptions *stored; =20 nc =3D qemu_new_net_client(&net_socket_info, peer, model, name); =20 @@ -447,6 +460,15 @@ static NetSocketState *net_socket_fd_init_stream(NetCl= ientState *peer, } else { qemu_set_fd_handler(s->fd, NULL, net_socket_connect, s); } + + /* Store startup parameters */ + nc->stored_config =3D g_new0(NetdevInfo, 1); + nc->stored_config->type =3D NET_BACKEND_SOCKET; + stored =3D &nc->stored_config->u.socket; + + stored->has_fd =3D true; + stored->fd =3D g_strdup_printf("%d", fd); + return s; } =20 @@ -483,6 +505,7 @@ static void net_socket_accept(void *opaque) struct sockaddr_in saddr; socklen_t len; int fd; + NetdevSocketOptions *stored; =20 for(;;) { len =3D sizeof(saddr); @@ -498,6 +521,13 @@ static void net_socket_accept(void *opaque) s->fd =3D fd; s->nc.link_down =3D false; net_socket_connect(s); + + /* Store additional startup parameters (extend net_socket_listen_init)= */ + stored =3D &s->nc.stored_config->u.socket; + + stored->has_fd =3D true; + stored->fd =3D g_strdup_printf("%d", fd); + snprintf(s->nc.info_str, sizeof(s->nc.info_str), "socket: connection from %s:%d", inet_ntoa(saddr.sin_addr), ntohs(saddr.sin_port)); @@ -513,6 +543,7 @@ static int net_socket_listen_init(NetClientState *peer, NetSocketState *s; struct sockaddr_in saddr; int fd, ret; + NetdevSocketOptions *stored; =20 if (parse_host_port(&saddr, host_str, errp) < 0) { return -1; @@ -549,6 +580,15 @@ static int net_socket_listen_init(NetClientState *peer, net_socket_rs_init(&s->rs, net_socket_rs_finalize, false); =20 qemu_set_fd_handler(s->listen_fd, net_socket_accept, NULL, s); + + /* Store startup parameters */ + nc->stored_config =3D g_new0(NetdevInfo, 1); + nc->stored_config->type =3D NET_BACKEND_SOCKET; + stored =3D &nc->stored_config->u.socket; + + stored->has_listen =3D true; + stored->listen =3D g_strdup(host_str); + return 0; } =20 @@ -561,6 +601,7 @@ static int net_socket_connect_init(NetClientState *peer, NetSocketState *s; int fd, connected, ret; struct sockaddr_in saddr; + NetdevSocketOptions *stored; =20 if (parse_host_port(&saddr, host_str, errp) < 0) { return -1; @@ -598,6 +639,12 @@ static int net_socket_connect_init(NetClientState *pee= r, return -1; } =20 + /* Store additional startup parameters (extend net_socket_fd_init) */ + stored =3D &s->nc.stored_config->u.socket; + + stored->has_connect =3D true; + stored->connect =3D g_strdup(host_str); + snprintf(s->nc.info_str, sizeof(s->nc.info_str), "socket: connect to %s:%d", inet_ntoa(saddr.sin_addr), ntohs(saddr.sin_port)); @@ -615,6 +662,7 @@ static int net_socket_mcast_init(NetClientState *peer, int fd; struct sockaddr_in saddr; struct in_addr localaddr, *param_localaddr; + NetdevSocketOptions *stored; =20 if (parse_host_port(&saddr, host_str, errp) < 0) { return -1; @@ -643,6 +691,19 @@ static int net_socket_mcast_init(NetClientState *peer, =20 s->dgram_dst =3D saddr; =20 + /* Store additional startup parameters (extend net_socket_fd_init) */ + stored =3D &s->nc.stored_config->u.socket; + + if (!stored->has_mcast) { + stored->has_mcast =3D true; + stored->mcast =3D g_strdup(host_str); + } + + if (localaddr_str) { + stored->has_localaddr =3D true; + stored->localaddr =3D g_strdup(localaddr_str); + } + snprintf(s->nc.info_str, sizeof(s->nc.info_str), "socket: mcast=3D%s:%d", inet_ntoa(saddr.sin_addr), ntohs(saddr.sin_port)); @@ -660,6 +721,7 @@ static int net_socket_udp_init(NetClientState *peer, NetSocketState *s; int fd, ret; struct sockaddr_in laddr, raddr; + NetdevSocketOptions *stored; =20 if (parse_host_port(&laddr, lhost, errp) < 0) { return -1; @@ -698,6 +760,15 @@ static int net_socket_udp_init(NetClientState *peer, =20 s->dgram_dst =3D raddr; =20 + /* Store additional startup parameters (extend net_socket_fd_init) */ + stored =3D &s->nc.stored_config->u.socket; + + stored->has_localaddr =3D true; + stored->localaddr =3D g_strdup(lhost); + + stored->has_udp =3D true; + stored->udp =3D g_strdup(rhost); + snprintf(s->nc.info_str, sizeof(s->nc.info_str), "socket: udp=3D%s:%d", inet_ntoa(raddr.sin_addr), ntohs(raddr.sin_port)); diff --git a/net/tap-win32.c b/net/tap-win32.c index 2b5dcda36e..b60933bd1a 100644 --- a/net/tap-win32.c +++ b/net/tap-win32.c @@ -768,6 +768,7 @@ static int tap_win32_init(NetClientState *peer, const c= har *model, NetClientState *nc; TAPState *s; tap_win32_overlapped_t *handle; + NetdevTapOptions *stored; =20 if (tap_win32_open(&handle, ifname) < 0) { printf("tap: Could not open '%s'\n", ifname); @@ -778,6 +779,14 @@ static int tap_win32_init(NetClientState *peer, const = char *model, =20 s =3D DO_UPCAST(TAPState, nc, nc); =20 + /* Store startup parameters */ + nc->stored_config =3D g_new0(NetdevInfo, 1); + nc->stored_config->type =3D NET_BACKEND_TAP; + stored =3D &nc->stored_config->u.tap; + + stored->has_ifname =3D true; + stored->ifname =3D g_strdup(ifname); + snprintf(s->nc.info_str, sizeof(s->nc.info_str), "tap: ifname=3D%s", ifname); =20 diff --git a/net/tap.c b/net/tap.c index c46ff66184..57af49ad51 100644 --- a/net/tap.c +++ b/net/tap.c @@ -590,6 +590,7 @@ int net_init_bridge(const Netdev *netdev, const char *n= ame, const char *helper, *br; TAPState *s; int fd, vnet_hdr; + NetdevBridgeOptions *stored; =20 assert(netdev->type =3D=3D NET_CLIENT_DRIVER_BRIDGE); bridge =3D &netdev->u.bridge; @@ -609,6 +610,21 @@ int net_init_bridge(const Netdev *netdev, const char *= name, } s =3D net_tap_fd_init(peer, "bridge", name, fd, vnet_hdr); =20 + /* Store startup parameters */ + s->nc.stored_config =3D g_new0(NetdevInfo, 1); + s->nc.stored_config->type =3D NET_BACKEND_BRIDGE; + stored =3D &s->nc.stored_config->u.bridge; + + if (br) { + stored->has_br =3D true; + stored->br =3D g_strdup(br); + } + + if (helper) { + stored->has_helper =3D true; + stored->helper =3D g_strdup(helper); + } + snprintf(s->nc.info_str, sizeof(s->nc.info_str), "helper=3D%s,br=3D%s"= , helper, br); =20 @@ -656,11 +672,13 @@ static void net_init_tap_one(const NetdevTapOptions *= tap, NetClientState *peer, const char *model, const char *name, const char *ifname, const char *script, const char *downscript, const char *vhostfdna= me, - int vnet_hdr, int fd, Error **errp) + int vnet_hdr, int fd, NetdevInfo **common_sto= red, + Error **errp) { Error *err =3D NULL; TAPState *s =3D net_tap_fd_init(peer, model, name, fd, vnet_hdr); int vhostfd; + NetdevTapOptions *stored; =20 tap_set_sndbuf(s->fd, tap, &err); if (err) { @@ -668,12 +686,65 @@ static void net_init_tap_one(const NetdevTapOptions *= tap, NetClientState *peer, return; } =20 + /* Store startup parameters */ + if (!*common_stored) { + *common_stored =3D g_new0(NetdevInfo, 1); + (*common_stored)->type =3D NET_BACKEND_TAP; + s->nc.stored_config =3D *common_stored; + } + stored =3D &(*common_stored)->u.tap; + + if (tap->has_sndbuf && !stored->has_sndbuf) { + stored->has_sndbuf =3D true; + stored->sndbuf =3D tap->sndbuf; + } + + if (vnet_hdr && !stored->has_vnet_hdr) { + stored->has_vnet_hdr =3D true; + stored->vnet_hdr =3D true; + } + if (tap->has_fd || tap->has_fds) { + if (!stored->has_fds) { + stored->has_fds =3D true; + stored->fds =3D g_strdup_printf("%d", fd); + } else { + char *tmp_s =3D stored->fds; + stored->fds =3D g_strdup_printf("%s:%d", stored->fds, fd); + g_free(tmp_s); + } + snprintf(s->nc.info_str, sizeof(s->nc.info_str), "fd=3D%d", fd); } else if (tap->has_helper) { + if (!stored->has_helper) { + stored->has_helper =3D true; + stored->helper =3D g_strdup(tap->helper); + } + + if (!stored->has_br) { + stored->has_br =3D true; + stored->br =3D tap->has_br ? g_strdup(tap->br) : + g_strdup(DEFAULT_BRIDGE_INTERFACE); + } + snprintf(s->nc.info_str, sizeof(s->nc.info_str), "helper=3D%s", tap->helper); } else { + if (ifname && !stored->has_ifname) { + stored->has_ifname =3D true; + stored->ifname =3D g_strdup(ifname); + } + + if (script && !stored->has_script) { + stored->has_script =3D true; + stored->script =3D g_strdup(script); + } + + if (downscript && !stored->has_downscript) { + stored->has_downscript =3D true; + stored->downscript =3D g_strdup(downscript); + } + snprintf(s->nc.info_str, sizeof(s->nc.info_str), "ifname=3D%s,script=3D%s,downscript=3D%s", ifname, script, downscript); @@ -689,9 +760,20 @@ static void net_init_tap_one(const NetdevTapOptions *t= ap, NetClientState *peer, vhostfdname || (tap->has_vhostforce && tap->vhostforce)) { VhostNetOptions options; =20 + stored->has_vhost =3D true; + stored->vhost =3D true; + + if (tap->has_vhostforce && tap->vhostforce) { + stored->has_vhostforce =3D true; + stored->vhostforce =3D true; + } + options.backend_type =3D VHOST_BACKEND_TYPE_KERNEL; options.net_backend =3D &s->nc; if (tap->has_poll_us) { + stored->has_poll_us =3D true; + stored->poll_us =3D tap->poll_us; + options.busyloop_timeout =3D tap->poll_us; } else { options.busyloop_timeout =3D 0; @@ -731,6 +813,15 @@ static void net_init_tap_one(const NetdevTapOptions *t= ap, NetClientState *peer, } options.opaque =3D (void *)(uintptr_t)vhostfd; =20 + if (!stored->has_vhostfds) { + stored->has_vhostfds =3D true; + stored->vhostfds =3D g_strdup_printf("%d", vhostfd); + } else { + char *tmp_s =3D stored->vhostfds; + stored->vhostfds =3D g_strdup_printf("%s:%d", stored->fds, vho= stfd); + g_free(tmp_s); + } + s->vhost_net =3D vhost_net_init(&options); if (!s->vhost_net) { if (tap->has_vhostforce && tap->vhostforce) { @@ -783,6 +874,7 @@ int net_init_tap(const Netdev *netdev, const char *name, const char *vhostfdname; char ifname[128]; int ret =3D 0; + NetdevInfo *common_stored =3D NULL; /* will store configuration */ =20 assert(netdev->type =3D=3D NET_CLIENT_DRIVER_TAP); tap =3D &netdev->u.tap; @@ -828,7 +920,7 @@ int net_init_tap(const Netdev *netdev, const char *name, =20 net_init_tap_one(tap, peer, "tap", name, NULL, script, downscript, - vhostfdname, vnet_hdr, fd, &err); + vhostfdname, vnet_hdr, fd, &common_stored, &err); if (err) { error_propagate(errp, err); return -1; @@ -890,7 +982,7 @@ int net_init_tap(const Netdev *netdev, const char *name, net_init_tap_one(tap, peer, "tap", name, ifname, script, downscript, tap->has_vhostfds ? vhost_fds[i] : NULL, - vnet_hdr, fd, &err); + vnet_hdr, fd, &common_stored, &err); if (err) { error_propagate(errp, err); ret =3D -1; @@ -933,7 +1025,7 @@ free_fail: =20 net_init_tap_one(tap, peer, "bridge", name, ifname, script, downscript, vhostfdname, - vnet_hdr, fd, &err); + vnet_hdr, fd, &common_stored, &err); if (err) { error_propagate(errp, err); close(fd); @@ -978,7 +1070,8 @@ free_fail: net_init_tap_one(tap, peer, "tap", name, ifname, i >=3D 1 ? "no" : script, i >=3D 1 ? "no" : downscript, - vhostfdname, vnet_hdr, fd, &err); + vhostfdname, vnet_hdr, fd, + &common_stored, &err); if (err) { error_propagate(errp, err); close(fd); diff --git a/net/vde.c b/net/vde.c index 99189cccb6..1af9175060 100644 --- a/net/vde.c +++ b/net/vde.c @@ -84,6 +84,7 @@ static int net_vde_init(NetClientState *peer, const char = *model, VDECONN *vde; char *init_group =3D (char *)group; char *init_sock =3D (char *)sock; + NetdevVdeOptions *stored; =20 struct vde_open_args args =3D { .port =3D port, @@ -108,6 +109,31 @@ static int net_vde_init(NetClientState *peer, const ch= ar *model, =20 qemu_set_fd_handler(vde_datafd(s->vde), vde_to_qemu, NULL, s); =20 + /* Store startup parameters */ + nc->stored_config =3D g_new0(NetdevInfo, 1); + nc->stored_config->type =3D NET_BACKEND_VDE; + stored =3D &nc->stored_config->u.vde; + + if (sock) { + stored->has_sock =3D true; + stored->sock =3D g_strdup(sock); + } + + if (port) { + stored->has_port =3D true; + stored->port =3D port; + } + + if (group) { + stored->has_group =3D true; + stored->group =3D g_strdup(group); + } + + if (mode) { + stored->has_mode =3D true; + stored->mode =3D mode; + } + return 0; } =20 diff --git a/net/vhost-user.c b/net/vhost-user.c index ffbd94d944..5b7056be25 100644 --- a/net/vhost-user.c +++ b/net/vhost-user.c @@ -311,14 +311,15 @@ static void net_vhost_user_event(void *opaque, QEMUCh= rEvent event) } =20 static int net_vhost_user_init(NetClientState *peer, const char *device, - const char *name, Chardev *chr, - int queues) + const char *name, const char *chardev, + Chardev *chr, int queues) { Error *err =3D NULL; NetClientState *nc, *nc0 =3D NULL; NetVhostUserState *s =3D NULL; VhostUserState *user; int i; + NetdevVhostUserOptions *stored; =20 assert(name); assert(queues > 0); @@ -355,6 +356,16 @@ static int net_vhost_user_init(NetClientState *peer, c= onst char *device, =20 assert(s->vhost_net); =20 + /* Store startup parameters */ + nc0->stored_config =3D g_new0(NetdevInfo, 1); + nc0->stored_config->type =3D NET_BACKEND_VHOST_USER; + stored =3D &nc0->stored_config->u.vhost_user; + + stored->chardev =3D g_strdup(chardev); + + stored->has_queues =3D true; + stored->queues =3D queues; + return 0; =20 err: @@ -446,5 +457,6 @@ int net_init_vhost_user(const Netdev *netdev, const cha= r *name, return -1; } =20 - return net_vhost_user_init(peer, "vhost_user", name, chr, queues); + return net_vhost_user_init(peer, "vhost_user", name, + vhost_user_opts->chardev, chr, queues); } diff --git a/net/vhost-vdpa.c b/net/vhost-vdpa.c index fe659ec9e2..8c27ea0142 100644 --- a/net/vhost-vdpa.c +++ b/net/vhost-vdpa.c @@ -184,8 +184,22 @@ static int net_vhost_vdpa_init(NetClientState *peer, c= onst char *device, VhostVDPAState *s; int vdpa_device_fd =3D -1; int ret =3D 0; + NetdevVhostVDPAOptions *stored; + assert(name); nc =3D qemu_new_net_client(&net_vhost_vdpa_info, peer, device, name); + + /* Store startup parameters */ + nc->stored_config =3D g_new0(NetdevInfo, 1); + nc->stored_config->type =3D NET_BACKEND_VHOST_VDPA; + stored =3D &nc->stored_config->u.vhost_vdpa; + + stored->has_vhostdev =3D true; + stored->vhostdev =3D g_strdup(vhostdev); + + stored->has_queues =3D true; + stored->queues =3D 1; /* TODO: change when support multiqueue */ + snprintf(nc->info_str, sizeof(nc->info_str), TYPE_VHOST_VDPA); nc->queue_index =3D 0; s =3D DO_UPCAST(VhostVDPAState, nc, nc); diff --git a/qapi/net.json b/qapi/net.json index a3a1336001..7f8261b042 100644 --- a/qapi/net.json +++ b/qapi/net.json @@ -714,3 +714,83 @@ ## { 'event': 'FAILOVER_NEGOTIATED', 'data': {'device-id': 'str'} } + +## +# @NetBackend: +# +# Available netdev backend drivers. +# +# Since: 6.0 +## +{ 'enum': 'NetBackend', + 'data': [ 'user', 'tap', 'l2tpv3', 'socket', 'vde', 'bridge', 'netmap', + 'vhost-user', 'vhost-vdpa' ] } + +## +# @NetdevInfo: +# +# Configuration of a network backend device (netdev). +# +# @id: Device identifier. +# +# @type: Specify the driver used for interpreting remaining arguments. +# +# @peer-id: The connected frontend network device name (absent if no front= end +# is connected). +# +# Since: 6.0 +## +{ 'union': 'NetdevInfo', + 'base': { 'id': 'str', + 'type': 'NetBackend', + '*peer-id': 'str' }, + 'discriminator': 'type', + 'data': { + 'user': 'NetdevUserOptions', + 'tap': 'NetdevTapOptions', + 'l2tpv3': 'NetdevL2TPv3Options', + 'socket': 'NetdevSocketOptions', + 'vde': 'NetdevVdeOptions', + 'bridge': 'NetdevBridgeOptions', + 'netmap': 'NetdevNetmapOptions', + 'vhost-user': 'NetdevVhostUserOptions', + 'vhost-vdpa': 'NetdevVhostVDPAOptions' } } + +## +# @query-netdev: +# +# Get a list of @NetdevInfo for all virtual network backend devices (netde= vs). +# +# Returns: a list of @NetdevInfo describing each netdev. +# +# Since: 6.0 +# +# Example: +# +# -> { "execute": "query-netdev" } +# <- { "return": [ +# { +# "ipv6": true, +# "ipv4": true, +# "host": "10.0.2.2", +# "ipv6-dns": "fec0::3", +# "ipv6-prefix": "fec0::", +# "net": "10.0.2.0/255.255.255.0", +# "ipv6-host": "fec0::2", +# "type": "user", +# "peer-id": "net0", +# "dns": "10.0.2.3", +# "hostfwd": [ +# { +# "str": "tcp::20004-:22" +# } +# ], +# "ipv6-prefixlen": 64, +# "id": "netdev0", +# "restrict": false +# } +# ] +# } +# +## +{ 'command': 'query-netdev', 'returns': ['NetdevInfo'] } --=20 2.25.1 From nobody Thu May 2 02:59:17 2024 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=yandex-team.ru ARC-Seal: i=1; a=rsa-sha256; t=1604880209; cv=none; d=zohomail.com; s=zohoarc; b=mUONnjAAL2h0e2FbBNkth7vdG6cqZd56U0qVnHZYfS9cBH04Rlwu29MOYOHTdRXlObZX/sqLhX24IoH+4G5m5ZK1muZCPZCgqixrG8xUZ3V6Dxz+DvUiDankKjU3RXsPSSv6tZd6HGjnmrlk/OM3fV1LhQLFdQycOzB3D6/XVjc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1604880209; h=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=wOcyKJ9lgUkHy9yO71mqgB4uNtYFJ3y9Jvn05znI9m8=; b=KhxIfMHUPAVW5m1ey/yTRhOI6CgHOY+qTuu4OI87rnHp1EUht31EWbxUYLMokFEJ0E0nvHzLMIZ2D5Q3ZvlcidOAvTHzak6js/rHhUw8qx8TMVgo3mnGNnrJV0V78zbYGwWqHiyOuUDRdSeeVKCGzcO0iHhNm3bMOwYH3o+8HjA= 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 1604880209477568.1273217463233; Sun, 8 Nov 2020 16:03:29 -0800 (PST) Received: from localhost ([::1]:55030 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kbuee-00062M-GD for importer@patchew.org; Sun, 08 Nov 2020 19:03:28 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:49320) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kbubv-0003Yc-JG for qemu-devel@nongnu.org; Sun, 08 Nov 2020 19:00:41 -0500 Received: from forwardcorp1p.mail.yandex.net ([2a02:6b8:0:1472:2741:0:8b6:217]:54146) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kbubs-0003ul-UE for qemu-devel@nongnu.org; Sun, 08 Nov 2020 19:00:39 -0500 Received: from sas1-5717c3cea310.qloud-c.yandex.net (sas1-5717c3cea310.qloud-c.yandex.net [IPv6:2a02:6b8:c14:3616:0:640:5717:c3ce]) by forwardcorp1p.mail.yandex.net (Yandex) with ESMTP id 7BEEA2E1481; Mon, 9 Nov 2020 03:00:34 +0300 (MSK) Received: from sas2-c156b1cb922a.qloud-c.yandex.net (sas2-c156b1cb922a.qloud-c.yandex.net [2a02:6b8:c08:b78e:0:640:c156:b1cb]) by sas1-5717c3cea310.qloud-c.yandex.net (mxbackcorp/Yandex) with ESMTP id DoN5motrwc-0Xw0JvIl; Mon, 09 Nov 2020 03:00:34 +0300 Received: from dynamic-vpn.dhcp.yndx.net (dynamic-vpn.dhcp.yndx.net [2a02:6b8:b081:425::1:0]) by sas2-c156b1cb922a.qloud-c.yandex.net (smtpcorp/Yandex) with ESMTPSA id AEjcvNO5zB-05nCNlmg; Mon, 09 Nov 2020 03:00:33 +0300 (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (Client certificate not present) Precedence: bulk DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex-team.ru; s=default; t=1604880034; bh=wOcyKJ9lgUkHy9yO71mqgB4uNtYFJ3y9Jvn05znI9m8=; h=In-Reply-To:Message-Id:References:Date:Subject:To:From:Cc; b=QE9J2dfPjr9hbpdxn1Nwwy1Mp2/sSZ1esAw0cKV29YYaHgUoaYkmPqy/wEgHsG7lJ kwo/fgt1lFyDgBFgyd9pV1SVT5gJIlNPaIzv1v4P4pthN1YLJpq6ahPtCgT1q14Hh/ mgJ7uPnN5nUJesL7k9gxG+L2wbOV/r+AlB2SKnn4= Authentication-Results: sas1-5717c3cea310.qloud-c.yandex.net; dkim=pass header.i=@yandex-team.ru From: Alexey Kirillov To: Jason Wang , Eric Blake , Markus Armbruster , Thomas Huth Subject: [PATCH v5 2/4] tests: Add tests for query-netdev command Date: Mon, 9 Nov 2020 02:59:50 +0300 Message-Id: <20201108235952.107961-3-lekiravi@yandex-team.ru> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20201108235952.107961-1-lekiravi@yandex-team.ru> References: <20201108235952.107961-1-lekiravi@yandex-team.ru> MIME-Version: 1.0 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=2a02:6b8:0:1472:2741:0:8b6:217; envelope-from=lekiravi@yandex-team.ru; helo=forwardcorp1p.mail.yandex.net X-detected-operating-system: by eggs.gnu.org: First seen = 2020/11/08 19:00:34 X-ACL-Warn: Detected OS = ??? 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, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Laurent Vivier , "Michael S. Tsirkin" , Stefan Weil , qemu-devel@nongnu.org, Vincenzo Maffione , yc-core@yandex-team.ru, Paolo Bonzini , Samuel Thibault , Giuseppe Lettieri , Luigi Rizzo Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Signed-off-by: Alexey Kirillov Acked-by: Thomas Huth --- tests/qtest/meson.build | 3 + tests/qtest/test-query-netdev.c | 120 ++++++++++++++++++++++++++++++++ 2 files changed, 123 insertions(+) create mode 100644 tests/qtest/test-query-netdev.c diff --git a/tests/qtest/meson.build b/tests/qtest/meson.build index c19f1c8503..2d2c597364 100644 --- a/tests/qtest/meson.build +++ b/tests/qtest/meson.build @@ -17,6 +17,9 @@ qtests_generic =3D [ if config_host.has_key('CONFIG_MODULES') qtests_generic +=3D [ 'modules-test' ] endif +if config_host.has_key('CONFIG_SLIRP') + qtests_generic +=3D [ 'test-query-netdev' ] +endif =20 qtests_pci =3D \ (config_all_devices.has_key('CONFIG_VGA') ? ['display-vga-test'] : []) += \ diff --git a/tests/qtest/test-query-netdev.c b/tests/qtest/test-query-netde= v.c new file mode 100644 index 0000000000..1118537a9f --- /dev/null +++ b/tests/qtest/test-query-netdev.c @@ -0,0 +1,120 @@ +/* + * QTest testcase for the query-netdev + * + * Copyright Yandex N.V., 2019 + * + * 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 "libqos/libqtest.h" +#include "qapi/qmp/qdict.h" +#include "qapi/qmp/qlist.h" + +/* + * Events can get in the way of responses we are actually waiting for. + */ +GCC_FMT_ATTR(2, 3) +static QObject *wait_command(QTestState *who, const char *command, ...) +{ + va_list ap; + QDict *response; + QObject *result; + + va_start(ap, command); + qtest_qmp_vsend(who, command, ap); + va_end(ap); + + response =3D qtest_qmp_receive(who); + + result =3D qdict_get(response, "return"); + g_assert(result); + qobject_ref(result); + qobject_unref(response); + + return result; +} + +static void qmp_query_netdev_no_error(QTestState *qts, size_t netdevs_coun= t) +{ + QObject *resp; + QList *netdevs; + + resp =3D wait_command(qts, "{'execute': 'query-netdev'}"); + + netdevs =3D qobject_to(QList, resp); + g_assert(netdevs); + g_assert(qlist_size(netdevs) =3D=3D netdevs_count); + + qobject_unref(resp); +} + +static void test_query_netdev(void) +{ + const char *arch =3D qtest_get_arch(); + QObject *resp; + QTestState *state; + + /* Choosing machine for platforms without default one */ + if (g_str_equal(arch, "arm") || + g_str_equal(arch, "aarch64")) { + state =3D qtest_init( + "-nodefaults " + "-M virt " + "-netdev user,id=3Dslirp0"); + } else if (g_str_equal(arch, "tricore")) { + state =3D qtest_init( + "-nodefaults " + "-M tricore_testboard " + "-netdev user,id=3Dslirp0"); + } else if (g_str_equal(arch, "avr")) { + state =3D qtest_init( + "-nodefaults " + "-M mega2560 " + "-netdev user,id=3Dslirp0"); + } else if (g_str_equal(arch, "rx")) { + state =3D qtest_init( + "-nodefaults " + "-M gdbsim-r5f562n8 " + "-netdev user,id=3Dslirp0"); + } else { + state =3D qtest_init( + "-nodefaults " + "-netdev user,id=3Dslirp0"); + } + g_assert(state); + + qmp_query_netdev_no_error(state, 1); + + resp =3D wait_command(state, + "{'execute': 'netdev_add', 'arguments': {" + " 'id': 'slirp1'," + " 'type': 'user'}}"); + qobject_unref(resp); + + qmp_query_netdev_no_error(state, 2); + + resp =3D wait_command(state, + "{'execute': 'netdev_del', 'arguments': {" + " 'id': 'slirp1'}}"); + qobject_unref(resp); + + qmp_query_netdev_no_error(state, 1); + + qtest_quit(state); +} + +int main(int argc, char **argv) +{ + int ret =3D 0; + g_test_init(&argc, &argv, NULL); + + qtest_add_func("/net/qapi/query_netdev", test_query_netdev); + + ret =3D g_test_run(); + + return ret; +} --=20 2.25.1 From nobody Thu May 2 02:59:17 2024 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=yandex-team.ru ARC-Seal: i=1; a=rsa-sha256; t=1604880443; cv=none; d=zohomail.com; s=zohoarc; b=K1pfVCzT1ICbQWTFvqJbktcH/ieHF8e0HLqgfg52v2wTAiapFMkavMKcCNJIGPuVrRORUemJ3kvQiV9WxHPgym6G4GrWX4T4B11FNWo/d7GX6oGAFgt1Fl8JKgNrwxy4F9ej5K3EFLa4VhNqglBQ6688BQDGkf4oK033/X5ZPCQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1604880443; h=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=//cdbs/HdJExa8nsAxw/6M2kRf2cAZj9PUuxtBNhFb0=; b=eOEdZPO3MMH+hH85lwI/vvYuaOHm7cLgoxssAbVhH7Fyxp2Z+shN5baIC3vatiL+jtauqbluN1MJbCNFT16DD9hwWF4zShd5kG3fBJn8pZlE8KB1dnbJqS1jw2yp7VnN8+qhkuiMnVCtDh+b463JhudJcDOLrPhbWaLKGwUTk2M= 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 16048804437545.942266454686205; Sun, 8 Nov 2020 16:07:23 -0800 (PST) Received: from localhost ([::1]:36164 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kbuiQ-0001Wl-Ir for importer@patchew.org; Sun, 08 Nov 2020 19:07:22 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:49366) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kbuc7-0003cW-3C for qemu-devel@nongnu.org; Sun, 08 Nov 2020 19:00:51 -0500 Received: from forwardcorp1j.mail.yandex.net ([2a02:6b8:0:1619::183]:47298) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kbuc2-0003v4-QT for qemu-devel@nongnu.org; Sun, 08 Nov 2020 19:00:50 -0500 Received: from sas1-ec30c78b6c5b.qloud-c.yandex.net (sas1-ec30c78b6c5b.qloud-c.yandex.net [IPv6:2a02:6b8:c14:2704:0:640:ec30:c78b]) by forwardcorp1j.mail.yandex.net (Yandex) with ESMTP id 7DFA12E14C1; Mon, 9 Nov 2020 03:00:42 +0300 (MSK) Received: from sas2-c156b1cb922a.qloud-c.yandex.net (sas2-c156b1cb922a.qloud-c.yandex.net [2a02:6b8:c08:b78e:0:640:c156:b1cb]) by sas1-ec30c78b6c5b.qloud-c.yandex.net (mxbackcorp/Yandex) with ESMTP id 02tw8KoPcl-0fwiJSrr; Mon, 09 Nov 2020 03:00:42 +0300 Received: from dynamic-vpn.dhcp.yndx.net (dynamic-vpn.dhcp.yndx.net [2a02:6b8:b081:425::1:0]) by sas2-c156b1cb922a.qloud-c.yandex.net (smtpcorp/Yandex) with ESMTPSA id AEjcvNO5zB-05nCNlmg; Mon, 09 Nov 2020 03:00:41 +0300 (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (Client certificate not present) Precedence: bulk DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex-team.ru; s=default; t=1604880042; bh=//cdbs/HdJExa8nsAxw/6M2kRf2cAZj9PUuxtBNhFb0=; h=In-Reply-To:Message-Id:References:Date:Subject:To:From:Cc; b=nFevnyHbl6MQB8DqiV00ahEBTGSmvmHvmKmFHAMYZL9sXa69n2OqnNdP/px0i/wph PBq3oVklW79QYMUH0H7RD8HbZel2uuzXSjE5pkA//RjwW8mHOv+8jEnaG6bmxiDHDD sY3GS6WwEj/HVa666dLD6hT2fVH48rIZDHRErPXE= Authentication-Results: sas1-ec30c78b6c5b.qloud-c.yandex.net; dkim=pass header.i=@yandex-team.ru From: Alexey Kirillov To: Jason Wang , Eric Blake , Markus Armbruster , Thomas Huth Subject: [PATCH v5 3/4] hmp: Use QMP query-netdev in hmp_info_network Date: Mon, 9 Nov 2020 02:59:51 +0300 Message-Id: <20201108235952.107961-4-lekiravi@yandex-team.ru> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20201108235952.107961-1-lekiravi@yandex-team.ru> References: <20201108235952.107961-1-lekiravi@yandex-team.ru> MIME-Version: 1.0 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=2a02:6b8:0:1619::183; envelope-from=lekiravi@yandex-team.ru; helo=forwardcorp1j.mail.yandex.net X-detected-operating-system: by eggs.gnu.org: No matching host in p0f cache. That's all we know. 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, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Laurent Vivier , "Michael S. Tsirkin" , Stefan Weil , qemu-devel@nongnu.org, Vincenzo Maffione , yc-core@yandex-team.ru, Paolo Bonzini , Samuel Thibault , Giuseppe Lettieri , Luigi Rizzo Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Replace usage of legacy field info_str of NetClientState for backend network devices with result of QMP command query-netdev. NIC and hubports still use legacy info_str field. Signed-off-by: Alexey Kirillov --- include/net/net.h | 3 +- net/clients.h | 1 + net/hub.c | 4 +- net/hub.h | 2 +- net/net.c | 181 ++++++++++++++++++++++++++++++++++++++++++++-- net/vde.c | 10 +++ 6 files changed, 192 insertions(+), 9 deletions(-) diff --git a/include/net/net.h b/include/net/net.h index 16700f715e..ed77f444de 100644 --- a/include/net/net.h +++ b/include/net/net.h @@ -172,7 +172,8 @@ void qemu_check_nic_model(NICInfo *nd, const char *mode= l); int qemu_find_nic_model(NICInfo *nd, const char * const *models, const char *default_model); =20 -void print_net_client(Monitor *mon, NetClientState *nc); +void print_net_client(Monitor *mon, NetClientState *nc, + NetdevInfoList *ni_list); void hmp_info_network(Monitor *mon, const QDict *qdict); void net_socket_rs_init(SocketReadState *rs, SocketReadStateFinalize *finalize, diff --git a/net/clients.h b/net/clients.h index 92f9b59aed..fdf257f641 100644 --- a/net/clients.h +++ b/net/clients.h @@ -51,6 +51,7 @@ int net_init_l2tpv3(const Netdev *netdev, const char *nam= e, #ifdef CONFIG_VDE int net_init_vde(const Netdev *netdev, const char *name, NetClientState *peer, Error **errp); +int net_vde_get_fd(const NetClientState *nc); #endif =20 #ifdef CONFIG_NETMAP diff --git a/net/hub.c b/net/hub.c index 1375738bf1..7815248650 100644 --- a/net/hub.c +++ b/net/hub.c @@ -221,7 +221,7 @@ NetClientState *net_hub_port_find(int hub_id) /** * Print hub configuration */ -void net_hub_info(Monitor *mon) +void net_hub_info(Monitor *mon, NetdevInfoList *ni_list) { NetHub *hub; NetHubPort *port; @@ -232,7 +232,7 @@ void net_hub_info(Monitor *mon) monitor_printf(mon, " \\ %s", port->nc.name); if (port->nc.peer) { monitor_printf(mon, ": "); - print_net_client(mon, port->nc.peer); + print_net_client(mon, port->nc.peer, ni_list); } else { monitor_printf(mon, "\n"); } diff --git a/net/hub.h b/net/hub.h index ce45f7b399..2c9a384077 100644 --- a/net/hub.h +++ b/net/hub.h @@ -17,7 +17,7 @@ =20 NetClientState *net_hub_add_port(int hub_id, const char *name, NetClientState *hubpeer); -void net_hub_info(Monitor *mon); +void net_hub_info(Monitor *mon, NetdevInfoList *ninfo); void net_hub_check_clients(void); bool net_hub_flush(NetClientState *nc); =20 diff --git a/net/net.c b/net/net.c index 551acadabc..4d3719434c 100644 --- a/net/net.c +++ b/net/net.c @@ -1178,14 +1178,182 @@ static void netfilter_print_info(Monitor *mon, Net= FilterState *nf) monitor_printf(mon, "\n"); } =20 -void print_net_client(Monitor *mon, NetClientState *nc) +static NetdevInfo *get_netdev_info(NetdevInfoList *ni_list, char *name) +{ + NetdevInfo *ni; + + while (ni_list) { + ni =3D ni_list->value; + if (g_str_equal(ni->id, name)) { + return ni; + } + ni_list =3D ni_list->next; + } + + return NULL; +} + +static char *generate_info_str(NetdevInfo *ni, NetClientState *nc) +{ + char *info_str; + + /* Use legacy field info_str for NIC and hubports */ + if ((nc->info->type =3D=3D NET_CLIENT_DRIVER_NIC) || + (nc->info->type =3D=3D NET_CLIENT_DRIVER_HUBPORT)) { + return g_strdup(nc->info_str); + } + + if (!ni) { + return g_malloc0(1); + } + + switch (ni->type) { +#ifdef CONFIG_SLIRP + case NET_BACKEND_USER: { + size_t len =3D strchr(ni->u.user.net, '/') - ni->u.user.net; + char *net =3D g_strndup(ni->u.user.net, len); + + info_str =3D g_strdup_printf("net=3D%s,restrict=3D%s", + net, + ni->u.user.q_restrict ? "on" : "off= "); + g_free(net); + break; + } +#endif /* CONFIG_SLIRP */ + case NET_BACKEND_TAP: { +#ifndef _WIN32 + if (ni->u.tap.has_fds) { + char **fds =3D g_strsplit(ni->u.tap.fds, ":", -1); + + info_str =3D g_strdup_printf("fd=3D%s", fds[nc->queue_inde= x]); + g_strfreev(fds); + } else if (ni->u.tap.has_helper) { + info_str =3D g_strdup_printf("helper=3D%s", ni->u.tap.help= er); + } else { + info_str =3D g_strdup_printf("ifname=3D%s,script=3D%s,down= script=3D%s", + ni->u.tap.ifname, + nc->queue_index =3D=3D 0 ? ni->u.tap.script : "no", + nc->queue_index =3D=3D 0 ? ni->u.tap.downscript : "no"= ); + } +#else + info_str =3D g_strdup_printf("tap: ifname=3D%s", ni->u.tap.ifn= ame); +#endif /* _WIN32 */ + break; + } +#ifdef CONFIG_L2TPV3 + case NET_BACKEND_L2TPV3: { + info_str =3D g_strdup_printf("l2tpv3: connected"); + break; + } +#endif /* CONFIG_L2TPV3 */ + case NET_BACKEND_SOCKET: { + if (ni->u.socket.has_listen) { + if (ni->u.socket.has_fd) { + info_str =3D g_strdup_printf("socket: connection from = %s", + ni->u.socket.listen); + } else { + info_str =3D g_strdup_printf("socket: wait from %s", + ni->u.socket.listen); + } + } else if (ni->u.socket.has_connect && ni->u.socket.has_fd) { + info_str =3D g_strdup_printf("socket: connect to %s", + ni->u.socket.connect); + } else if (ni->u.socket.has_mcast && ni->u.socket.has_fd) { + info_str =3D g_strdup_printf("socket: mcast=3D%s", + ni->u.socket.mcast); + } else if (ni->u.socket.has_udp && ni->u.socket.has_fd) { + info_str =3D g_strdup_printf("socket: udp=3D%s", ni->u.soc= ket.udp); + } else { + g_assert(ni->u.socket.has_fd); + int so_type =3D -1; + int optlen =3D sizeof(so_type); + int fd =3D atoi(ni->u.socket.fd); + + getsockopt(fd, SOL_SOCKET, SO_TYPE, (char *)&so_type, + (socklen_t *)&optlen); + if (so_type =3D=3D SOCK_STREAM) { + info_str =3D g_strdup_printf("socket: fd=3D%s", + ni->u.socket.fd); + } else { + if (ni->u.socket.has_mcast) { + /* + * This branch is unreachable, according to how it= is in + * net/socket.c at this moment + */ + info_str =3D g_strdup_printf("socket: fd=3D%s " + "(cloned mcast=3D%s)", + ni->u.socket.fd, + ni->u.socket.mcast); + } else { + SocketAddress *sa =3D socket_local_address(fd, NUL= L); + + info_str =3D g_strdup_printf("socket: fd=3D%s %s", + ni->u.socket.fd, + SocketAddressType_str(sa->type)); + qapi_free_SocketAddress(sa); + } + } + } + break; + } +#ifdef CONFIG_VDE + case NET_BACKEND_VDE: { + info_str =3D g_strdup_printf("sock=3D%s,fd=3D%d", + ni->u.vde.sock, + net_vde_get_fd(nc)); + break; + } +#endif /* CONFIG_VDE */ +#ifdef CONFIG_NET_BRIDGE + case NET_BACKEND_BRIDGE: { + info_str =3D g_strdup_printf("helper=3D%s,br=3D%s", + ni->u.bridge.helper, + ni->u.bridge.br); + break; + } +#endif /* CONFIG_NET_BRIDGE */ +#ifdef CONFIG_NETMAP + case NET_BACKEND_NETMAP: { + info_str =3D g_strdup_printf("netmap: ifname=3D%s", + ni->u.netmap.ifname); + break; + } +#endif /* CONFIG_NETMAP */ +#ifdef CONFIG_VHOST_NET_USER + case NET_BACKEND_VHOST_USER: { + info_str =3D g_strdup_printf("vhost-user%d to %s", + nc->queue_index, + ni->u.vhost_user.chardev); + break; + } +#endif /* CONFIG_VHOST_NET_USER */ +#ifdef CONFIG_VHOST_NET_VDPA + case NET_BACKEND_VHOST_VDPA: { + info_str =3D g_strdup("vhost-vdpa"); + break; + } +#endif /* CONFIG_VHOST_NET_VDPA */ + default: { + info_str =3D g_malloc0(1); + break; + } + } + + return info_str; +} + +void print_net_client(Monitor *mon, NetClientState *nc, NetdevInfoList *ni= _list) { NetFilterState *nf; + NetdevInfo *ni =3D get_netdev_info(ni_list, nc->name); + char *info_str =3D generate_info_str(ni, nc); =20 monitor_printf(mon, "%s: index=3D%d,type=3D%s,%s\n", nc->name, nc->queue_index, NetClientDriver_str(nc->info->type), - nc->info_str); + info_str); + g_free(info_str); + if (!QTAILQ_EMPTY(&nc->filters)) { monitor_printf(mon, "filters:\n"); } @@ -1289,8 +1457,9 @@ void hmp_info_network(Monitor *mon, const QDict *qdic= t) { NetClientState *nc, *peer; NetClientDriver type; + NetdevInfoList *ni_list =3D qmp_query_netdev(NULL); =20 - net_hub_info(mon); + net_hub_info(mon, ni_list); =20 QTAILQ_FOREACH(nc, &net_clients, next) { peer =3D nc->peer; @@ -1302,13 +1471,15 @@ void hmp_info_network(Monitor *mon, const QDict *qd= ict) } =20 if (!peer || type =3D=3D NET_CLIENT_DRIVER_NIC) { - print_net_client(mon, nc); + print_net_client(mon, nc, ni_list); } /* else it's a netdev connected to a NIC, printed with the NIC */ if (peer && type =3D=3D NET_CLIENT_DRIVER_NIC) { monitor_printf(mon, " \\ "); - print_net_client(mon, peer); + print_net_client(mon, peer, ni_list); } } + + qapi_free_NetdevInfoList(ni_list); } =20 void colo_notify_filters_event(int event, Error **errp) diff --git a/net/vde.c b/net/vde.c index 1af9175060..041eadbcf9 100644 --- a/net/vde.c +++ b/net/vde.c @@ -153,3 +153,13 @@ int net_init_vde(const Netdev *netdev, const char *nam= e, =20 return 0; } + +int net_vde_get_fd(const NetClientState *nc) +{ + VDEState *s; + assert(nc->info->type =3D=3D NET_CLIENT_DRIVER_VDE); + + s =3D DO_UPCAST(VDEState, nc, nc); + + return vde_datafd(s->vde); +} --=20 2.25.1 From nobody Thu May 2 02:59:17 2024 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=yandex-team.ru ARC-Seal: i=1; a=rsa-sha256; t=1604880340; cv=none; d=zohomail.com; s=zohoarc; b=e6MVdaA1ajDVso9C2X+M7XSsrwMg/ErdflFdYmVQIN863//Eqz4+z8Q9gzapln0b0gV5LYz4jZ+mu+hTULB7QQN79znXX+mFin69fXq3S1J5k4X3TdZzqWkMro69KAKh/lkiDMqrNLXIjxOxqQUtrD5164DDDnea4hvpUiOpQhg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1604880340; h=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=4UT9zLwR/HbyGJkWxMzsQ6xPZvU8eI6Qk1oOhho2jsQ=; b=jO+XNSxl4l5O1/NWv34soBWeu+Av9fUTbdXhb3ZW8d/HDysAbGOGto5ad5F2G2+lgHXn5r7gEFT4WfCTm/SD6iHCTSWFloxFIS0A36A1W+jFQ1qHcxyySyC6NlgqceaWDYteiBZdgQc+DqKQin/D2Rd7kCAG8SIT3JsaPryZSjI= 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 1604880340081160.47670659927724; Sun, 8 Nov 2020 16:05:40 -0800 (PST) Received: from localhost ([::1]:33032 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kbugk-00007L-W0 for importer@patchew.org; Sun, 08 Nov 2020 19:05:39 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:49394) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kbucE-0003nw-NO for qemu-devel@nongnu.org; Sun, 08 Nov 2020 19:00:58 -0500 Received: from forwardcorp1p.mail.yandex.net ([2a02:6b8:0:1472:2741:0:8b6:217]:54444) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kbucC-0003xn-Cy for qemu-devel@nongnu.org; Sun, 08 Nov 2020 19:00:58 -0500 Received: from sas1-ec30c78b6c5b.qloud-c.yandex.net (sas1-ec30c78b6c5b.qloud-c.yandex.net [IPv6:2a02:6b8:c14:2704:0:640:ec30:c78b]) by forwardcorp1p.mail.yandex.net (Yandex) with ESMTP id F1EED2E14A4; Mon, 9 Nov 2020 03:00:54 +0300 (MSK) Received: from sas2-c156b1cb922a.qloud-c.yandex.net (sas2-c156b1cb922a.qloud-c.yandex.net [2a02:6b8:c08:b78e:0:640:c156:b1cb]) by sas1-ec30c78b6c5b.qloud-c.yandex.net (mxbackcorp/Yandex) with ESMTP id PaDJTaGbEL-0pweK6v4; Mon, 09 Nov 2020 03:00:54 +0300 Received: from dynamic-vpn.dhcp.yndx.net (dynamic-vpn.dhcp.yndx.net [2a02:6b8:b081:425::1:0]) by sas2-c156b1cb922a.qloud-c.yandex.net (smtpcorp/Yandex) with ESMTPSA id AEjcvNO5zB-05nCNlmg; Mon, 09 Nov 2020 03:00:51 +0300 (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (Client certificate not present) Precedence: bulk DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex-team.ru; s=default; t=1604880054; bh=4UT9zLwR/HbyGJkWxMzsQ6xPZvU8eI6Qk1oOhho2jsQ=; h=In-Reply-To:Message-Id:References:Date:Subject:To:From:Cc; b=aDDXHfcdr1oyKmiIbGcfanR3c0rTx6s9cDeM6P4xhVjJQfhfyr2o79x6fZsOc/cjF 72uKG6uMwJXxIjLADNhfbPwA99ENqzpPC2//FNARc/C1E19sCSLVQUBfDLegN8xGD/ 7XgEKAxY3ZfGVCciPNVvB3uj5Y7Y2tuqbAoyr7X8= Authentication-Results: sas1-ec30c78b6c5b.qloud-c.yandex.net; dkim=pass header.i=@yandex-team.ru From: Alexey Kirillov To: Jason Wang , Eric Blake , Markus Armbruster , Thomas Huth Subject: [PATCH v5 4/4] net: Do not use legacy info_str for backends Date: Mon, 9 Nov 2020 02:59:52 +0300 Message-Id: <20201108235952.107961-5-lekiravi@yandex-team.ru> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20201108235952.107961-1-lekiravi@yandex-team.ru> References: <20201108235952.107961-1-lekiravi@yandex-team.ru> MIME-Version: 1.0 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=2a02:6b8:0:1472:2741:0:8b6:217; envelope-from=lekiravi@yandex-team.ru; helo=forwardcorp1p.mail.yandex.net X-detected-operating-system: by eggs.gnu.org: First seen = 2020/11/08 19:00:34 X-ACL-Warn: Detected OS = ??? 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, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Laurent Vivier , "Michael S. Tsirkin" , Stefan Weil , qemu-devel@nongnu.org, Vincenzo Maffione , yc-core@yandex-team.ru, Paolo Bonzini , Samuel Thibault , Giuseppe Lettieri , Luigi Rizzo Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" As we use QMP query-netdev to store and get information about backend network devices, we can drop usage legacy field info_str for them. We still use this field for NIC and hubports, so we can not completely remove it. Signed-off-by: Alexey Kirillov --- net/l2tpv3.c | 2 -- net/slirp.c | 4 ---- net/socket.c | 22 ---------------------- net/tap-win32.c | 3 --- net/tap.c | 12 ------------ net/vde.c | 3 --- net/vhost-user.c | 2 -- net/vhost-vdpa.c | 1 - 8 files changed, 49 deletions(-) diff --git a/net/l2tpv3.c b/net/l2tpv3.c index 881fc6f7c1..7f2a590155 100644 --- a/net/l2tpv3.c +++ b/net/l2tpv3.c @@ -745,8 +745,6 @@ int net_init_l2tpv3(const Netdev *netdev, stored->dstport =3D g_strdup(l2tpv3->dstport); } =20 - snprintf(s->nc.info_str, sizeof(s->nc.info_str), - "l2tpv3: connected"); return 0; outerr: qemu_del_net_client(nc); diff --git a/net/slirp.c b/net/slirp.c index 65d3f2639c..14fa64227d 100644 --- a/net/slirp.c +++ b/net/slirp.c @@ -670,10 +670,6 @@ static int net_slirp_init(NetClientState *peer, const = char *model, stored->tftp_server_name =3D g_strdup(tftp_server_name); } =20 - snprintf(nc->info_str, sizeof(nc->info_str), - "net=3D%s,restrict=3D%s", inet_ntoa(net), - restricted ? "on" : "off"); - s =3D DO_UPCAST(SlirpState, nc, nc); =20 s->slirp =3D slirp_init(restricted, ipv4, net, mask, host, diff --git a/net/socket.c b/net/socket.c index 1614523b82..93b5163f0e 100644 --- a/net/socket.c +++ b/net/socket.c @@ -180,7 +180,6 @@ static void net_socket_send(void *opaque) s->fd =3D -1; net_socket_rs_init(&s->rs, net_socket_rs_finalize, false); s->nc.link_down =3D true; - memset(s->nc.info_str, 0, sizeof(s->nc.info_str)); =20 return; } @@ -400,16 +399,10 @@ static NetSocketState *net_socket_fd_init_dgram(NetCl= ientState *peer, stored->mcast =3D g_strdup(mcast); =20 s->dgram_dst =3D saddr; - snprintf(nc->info_str, sizeof(nc->info_str), - "socket: fd=3D%d (cloned mcast=3D%s:%d)", - fd, inet_ntoa(saddr.sin_addr), ntohs(saddr.sin_port)); } else { if (sa_type =3D=3D SOCKET_ADDRESS_TYPE_UNIX) { s->dgram_dst.sin_family =3D AF_UNIX; } - - snprintf(nc->info_str, sizeof(nc->info_str), - "socket: fd=3D%d %s", fd, SocketAddressType_str(sa_type)); } =20 return s; @@ -444,8 +437,6 @@ static NetSocketState *net_socket_fd_init_stream(NetCli= entState *peer, =20 nc =3D qemu_new_net_client(&net_socket_info, peer, model, name); =20 - snprintf(nc->info_str, sizeof(nc->info_str), "socket: fd=3D%d", fd); - s =3D DO_UPCAST(NetSocketState, nc, nc); =20 s->fd =3D fd; @@ -527,10 +518,6 @@ static void net_socket_accept(void *opaque) =20 stored->has_fd =3D true; stored->fd =3D g_strdup_printf("%d", fd); - - snprintf(s->nc.info_str, sizeof(s->nc.info_str), - "socket: connection from %s:%d", - inet_ntoa(saddr.sin_addr), ntohs(saddr.sin_port)); } =20 static int net_socket_listen_init(NetClientState *peer, @@ -645,9 +632,6 @@ static int net_socket_connect_init(NetClientState *peer, stored->has_connect =3D true; stored->connect =3D g_strdup(host_str); =20 - snprintf(s->nc.info_str, sizeof(s->nc.info_str), - "socket: connect to %s:%d", - inet_ntoa(saddr.sin_addr), ntohs(saddr.sin_port)); return 0; } =20 @@ -704,9 +688,6 @@ static int net_socket_mcast_init(NetClientState *peer, stored->localaddr =3D g_strdup(localaddr_str); } =20 - snprintf(s->nc.info_str, sizeof(s->nc.info_str), - "socket: mcast=3D%s:%d", - inet_ntoa(saddr.sin_addr), ntohs(saddr.sin_port)); return 0; =20 } @@ -769,9 +750,6 @@ static int net_socket_udp_init(NetClientState *peer, stored->has_udp =3D true; stored->udp =3D g_strdup(rhost); =20 - snprintf(s->nc.info_str, sizeof(s->nc.info_str), - "socket: udp=3D%s:%d", - inet_ntoa(raddr.sin_addr), ntohs(raddr.sin_port)); return 0; } =20 diff --git a/net/tap-win32.c b/net/tap-win32.c index b60933bd1a..21e451107b 100644 --- a/net/tap-win32.c +++ b/net/tap-win32.c @@ -787,9 +787,6 @@ static int tap_win32_init(NetClientState *peer, const c= har *model, stored->has_ifname =3D true; stored->ifname =3D g_strdup(ifname); =20 - snprintf(s->nc.info_str, sizeof(s->nc.info_str), - "tap: ifname=3D%s", ifname); - s->handle =3D handle; =20 qemu_add_wait_object(s->handle->tap_semaphore, tap_win32_send, s); diff --git a/net/tap.c b/net/tap.c index 57af49ad51..908cb8e7bd 100644 --- a/net/tap.c +++ b/net/tap.c @@ -625,9 +625,6 @@ int net_init_bridge(const Netdev *netdev, const char *n= ame, stored->helper =3D g_strdup(helper); } =20 - snprintf(s->nc.info_str, sizeof(s->nc.info_str), "helper=3D%s,br=3D%s"= , helper, - br); - return 0; } =20 @@ -713,8 +710,6 @@ static void net_init_tap_one(const NetdevTapOptions *ta= p, NetClientState *peer, stored->fds =3D g_strdup_printf("%s:%d", stored->fds, fd); g_free(tmp_s); } - - snprintf(s->nc.info_str, sizeof(s->nc.info_str), "fd=3D%d", fd); } else if (tap->has_helper) { if (!stored->has_helper) { stored->has_helper =3D true; @@ -726,9 +721,6 @@ static void net_init_tap_one(const NetdevTapOptions *ta= p, NetClientState *peer, stored->br =3D tap->has_br ? g_strdup(tap->br) : g_strdup(DEFAULT_BRIDGE_INTERFACE); } - - snprintf(s->nc.info_str, sizeof(s->nc.info_str), "helper=3D%s", - tap->helper); } else { if (ifname && !stored->has_ifname) { stored->has_ifname =3D true; @@ -745,10 +737,6 @@ static void net_init_tap_one(const NetdevTapOptions *t= ap, NetClientState *peer, stored->downscript =3D g_strdup(downscript); } =20 - snprintf(s->nc.info_str, sizeof(s->nc.info_str), - "ifname=3D%s,script=3D%s,downscript=3D%s", ifname, script, - downscript); - if (strcmp(downscript, "no") !=3D 0) { snprintf(s->down_script, sizeof(s->down_script), "%s", downscr= ipt); snprintf(s->down_script_arg, sizeof(s->down_script_arg), diff --git a/net/vde.c b/net/vde.c index 041eadbcf9..bda8444d1a 100644 --- a/net/vde.c +++ b/net/vde.c @@ -100,9 +100,6 @@ static int net_vde_init(NetClientState *peer, const cha= r *model, =20 nc =3D qemu_new_net_client(&net_vde_info, peer, model, name); =20 - snprintf(nc->info_str, sizeof(nc->info_str), "sock=3D%s,fd=3D%d", - sock, vde_datafd(vde)); - s =3D DO_UPCAST(VDEState, nc, nc); =20 s->vde =3D vde; diff --git a/net/vhost-user.c b/net/vhost-user.c index 5b7056be25..e443c4b2b5 100644 --- a/net/vhost-user.c +++ b/net/vhost-user.c @@ -327,8 +327,6 @@ static int net_vhost_user_init(NetClientState *peer, co= nst char *device, user =3D g_new0(struct VhostUserState, 1); for (i =3D 0; i < queues; i++) { nc =3D qemu_new_net_client(&net_vhost_user_info, peer, device, nam= e); - snprintf(nc->info_str, sizeof(nc->info_str), "vhost-user%d to %s", - i, chr->label); nc->queue_index =3D i; if (!nc0) { nc0 =3D nc; diff --git a/net/vhost-vdpa.c b/net/vhost-vdpa.c index 8c27ea0142..5a28bbcd7b 100644 --- a/net/vhost-vdpa.c +++ b/net/vhost-vdpa.c @@ -200,7 +200,6 @@ static int net_vhost_vdpa_init(NetClientState *peer, co= nst char *device, stored->has_queues =3D true; stored->queues =3D 1; /* TODO: change when support multiqueue */ =20 - snprintf(nc->info_str, sizeof(nc->info_str), TYPE_VHOST_VDPA); nc->queue_index =3D 0; s =3D DO_UPCAST(VhostVDPAState, nc, nc); vdpa_device_fd =3D qemu_open_old(vhostdev, O_RDWR); --=20 2.25.1