From nobody Tue Feb 10 15:03:00 2026 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=1600716223; cv=none; d=zohomail.com; s=zohoarc; b=R7srbGH+is25F5upXKDJS5mhGkuy3JyMhZvWC4LCHn1qW3iqtH8D7w7tv1nz4AarjXv3ejUrN/kE0Kx1JL09aihmoRHfG3LudTUM1Sw2MpmmZTWMsRN63cYDOanhMnSEpCPZjqUfb8M/C/ZYXcE/2jRZjf+op1UPcvolpthRct8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1600716223; 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=BTmtrd75GEuE48ijYcMfPLRlSXnWwBHKVEH8xsmvPWU=; b=Awz6uu3Ixzsf9m0EpGAqUJv3brH8b13EWjUVc/RfMlt6vWTDMmY/OL2X54Xy7JTuwPm6akc8x6vli+ixxPNv2KRcavNrFy8Dn7Q9aRbrnbf5/fW3ZicM5Ycy1SyQmPPMEDpme6NDE8i7uJH81LNrc9Do76MVliLw1mXC1BqW4iQ= 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 1600716223750101.06936169357027; Mon, 21 Sep 2020 12:23:43 -0700 (PDT) Received: from localhost ([::1]:55200 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kKRPa-0004iR-Da for importer@patchew.org; Mon, 21 Sep 2020 15:23:42 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:41304) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kKRLk-0001DO-MS for qemu-devel@nongnu.org; Mon, 21 Sep 2020 15:19:44 -0400 Received: from forwardcorp1o.mail.yandex.net ([2a02:6b8:0:1a2d::193]:44408) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kKRLi-0004J5-3d for qemu-devel@nongnu.org; Mon, 21 Sep 2020 15:19:44 -0400 Received: from myt5-23f0be3aa648.qloud-c.yandex.net (myt5-23f0be3aa648.qloud-c.yandex.net [IPv6:2a02:6b8:c12:3e29:0:640:23f0:be3a]) by forwardcorp1o.mail.yandex.net (Yandex) with ESMTP id D133F2E1556; Mon, 21 Sep 2020 22:19:38 +0300 (MSK) Received: from myt4-18a966dbd9be.qloud-c.yandex.net (myt4-18a966dbd9be.qloud-c.yandex.net [2a02:6b8:c00:12ad:0:640:18a9:66db]) by myt5-23f0be3aa648.qloud-c.yandex.net (mxbackcorp/Yandex) with ESMTP id QYPG6PUQhC-Javqfs6a; Mon, 21 Sep 2020 22:19:38 +0300 Received: from dynamic-vpn.dhcp.yndx.net (dynamic-vpn.dhcp.yndx.net [2a02:6b8:b080:6416::1:4]) by myt4-18a966dbd9be.qloud-c.yandex.net (smtpcorp/Yandex) with ESMTPSA id 3Nc4XKVFl3-Jal4b3tp; Mon, 21 Sep 2020 22:19:36 +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=1600715978; bh=BTmtrd75GEuE48ijYcMfPLRlSXnWwBHKVEH8xsmvPWU=; h=In-Reply-To:Message-Id:References:Date:Subject:To:From:Cc; b=NRWc+3XLBK2YLyApkb0YoMsFyaHM3qJd/Q3/rxqctUNacowpYRia7ozLXq9RNQwHQ cBB6XWF52X2clNiU84GIGz67XC5Ejw2SqKMn8QvGiUhbkZAMaPbPNOnbpUZX4j4JcF UPMGYpgTHn6BddS+GUZuLyj0o8DMS6HA5tgjcAXI= Authentication-Results: myt5-23f0be3aa648.qloud-c.yandex.net; dkim=pass header.i=@yandex-team.ru From: Alexey Kirillov To: Eric Blake , Markus Armbruster , Thomas Huth , Jason Wang Subject: [PATCH v4 3/4] hmp: Use QMP query-netdev in hmp_info_network Date: Mon, 21 Sep 2020 22:19:11 +0300 Message-Id: <20200921191912.105305-4-lekiravi@yandex-team.ru> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200921191912.105305-1-lekiravi@yandex-team.ru> References: <20200921191912.105305-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:1a2d::193; envelope-from=lekiravi@yandex-team.ru; helo=forwardcorp1o.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 04d51ac215..d6d3168a0d 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 ae4ca52c13..3b528428f4 100644 --- a/net/net.c +++ b/net/net.c @@ -1175,14 +1175,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"); } @@ -1286,8 +1454,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; @@ -1299,13 +1468,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