From nobody Wed Aug 26 05:56:02 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1779313997; cv=none; d=zohomail.com; s=zohoarc; b=CUG1Q73c3PV1XW411E6uxWQiJxt9Qd2fl5S+ZiDXn3xyMjc2sk801PwhtfJqCub2bannjxehSLR4HwpZKUtwiU181ohu6owx4IH4bMrleCNY5ZsogayMAV6FRR1iaCIPtbQuF7wPE2vDm4m20iWDKMEhVs4qxPRx3AKdYwe5VSE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1779313997; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=Ny5pfaZzFGmnGeeLq+0zzagTdWAYo/ZKZR1hucXAr/o=; b=KQWycfTgw4+SCYn6ZtnYZARdJKCkJm05iTdFmCpXb+K8OQT/uxx4xIJmEfFr0x5tjGLn/fseLB8gk8fNHegeiCsHeD9cs3vEAp8B4bpm/3G8dAP96GWKBFH7TLl9Sbe/GAJYBr8yLlHHp1XESH3c/nJbKVxS3MjzDzgpD1YLCDM= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1779313997940161.2698063008479; Wed, 20 May 2026 14:53:17 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wPoqa-0007LN-NZ; Wed, 20 May 2026 17:53:04 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wPoqK-0006c4-Dn for qemu-devel@nongnu.org; Wed, 20 May 2026 17:52:46 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wPoqG-0004rb-4R for qemu-devel@nongnu.org; Wed, 20 May 2026 17:52:43 -0400 Received: from mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-224-oncClGRANt69-Zel-2WzbQ-1; Wed, 20 May 2026 17:52:37 -0400 Received: from mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.111]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id E78BC1956056 for ; Wed, 20 May 2026 21:52:35 +0000 (UTC) Received: from localhost (unknown [10.44.24.26]) by mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 596051800576; Wed, 20 May 2026 21:52:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1779313959; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Ny5pfaZzFGmnGeeLq+0zzagTdWAYo/ZKZR1hucXAr/o=; b=KGTEECm9fbrZpdi43/WzYt3fwS/vo+chXEY/Eb5ZVHm6UP+03HMWBmK5rB53HRVU/zJRli WTIrkGH656GCLvpoaonUH3aUFi8XUWlpYSMiQ6ZQxHkGBytiFTUHkt4GGAfc7xEGRQEQpA zKSnqnVIAgdiO5875cddfkyb0ipnEC4= X-MC-Unique: oncClGRANt69-Zel-2WzbQ-1 X-Mimecast-MFC-AGG-ID: oncClGRANt69-Zel-2WzbQ_1779313956 From: =?utf-8?q?Marc-Andr=C3=A9_Lureau?= Date: Thu, 21 May 2026 01:49:26 +0400 Subject: [PATCH 25/40] net: add x-query-network QMP command MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260521-qemu-no-hmp-v1-25-d104f809e145@redhat.com> References: <20260521-qemu-no-hmp-v1-0-d104f809e145@redhat.com> In-Reply-To: <20260521-qemu-no-hmp-v1-0-d104f809e145@redhat.com> To: qemu-devel@nongnu.org Cc: =?utf-8?q?Marc-Andr=C3=A9_Lureau?= X-Developer-Signature: v=1; a=openpgp-sha256; l=13500; i=marcandre.lureau@redhat.com; h=from:subject:message-id; bh=mEYVeOV2ZIGJyvEI9qKJs0uDZEiQSgRpNCpRgeV0SYg=; b=owEBbQKS/ZANAwAKAdro4Ql1lpzlAcsmYgBqDiyDZ9dFwU7PunqOG9JNerHTuFYG07M1DSFRV P8HOZzmcAyJAjMEAAEKAB0WIQSHqb2TP4fGBtJ29i3a6OEJdZac5QUCag4sgwAKCRDa6OEJdZac 5UpQD/4tPB7DHYGVp567/uAXS15rfJCwTZ8zl44urI0FbtK/yKpl7VLpDAOaEHCdBu/ZOTZiAGq a97IyTqd/ANNClY8ktaQAT1E/b0G7nm8Ka4AAPPIJnSrK2KAyS7+xhx5rfPFgxgJ3edUwOWd0MF EXrnOK9qg+EoO34fCRAdo737L08kMNt6DXLx2e2JlU+9sbI4XEjOLssao+2eS3muNnA2uGpIYgb /b398oGmhqbwgeOj4LzvfT/H1TGIlcqvfBm+boSx/K0O3K+/Q6vod29TiBDA7AdrMelt1EwoLCz C527cCxZ2Intp2+h33C+55To/gTMOF2gbbkUtq4mHIileeahSgBw2y/mIU4C/zaC8qeH2mSV+im 7IBJ3+DP0k/+jqCYFIMESuCQLxakr45CvkwDgNINwzwEMTTMmdrY1RWouLj9h65qKDDyoIZxZ5p gAIJn5Lq8t7MKRdZhV0X70J5JGRoqtAIT+Qs50U67kM6iEX9vqTxl6kpVkuQ6eaJdTg2kK2ZId3 p6MEpV56NcBePV0mjSNjsLkNZpUPyDd9mKXGteraxFcij9KJfzZPtRMEJ2gkJY/gbM1QmrUbAJ0 JKqjENMMbenFBknMM+lHPWy9kVvNFYVLnPLEfEmM/1xGZfedHxhq5KYUe4DXXWf1GPhzRjKLjmj QYNk8Q3kIaa5SqA== X-Developer-Key: i=marcandre.lureau@redhat.com; a=openpgp; fpr=87A9BD933F87C606D276F62DDAE8E10975969CE5 X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.111 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=lists1p.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=marcandre.lureau@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: 8 X-Spam_score: 0.8 X-Spam_bar: / X-Spam_report: (0.8 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.445, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_SBL_CSS=3.335, SPF_HELO_PASS=-0.001, SPF_PASS=-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: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1779313999051158500 Add a structured x-query-network QMP command that returns network configuration as a NetworkInfo struct with pre-grouped hub information and a flat list of non-hub clients. Each hub includes its ports with inlined peer client info, and each client includes attached netfilter details. Refactor hmp_info_network() to consume only the QMP result instead of directly accessing internal net_clients state. This decouples HMP from internal data structures, making it possible to remove HMP support without losing programmatic network introspection. Signed-off-by: Marc-Andr=C3=A9 Lureau --- qapi/net.json | 122 +++++++++++++++++++++++++++++++++++++++++++++++++= ++++ include/net/net.h | 3 +- net/hub.h | 4 +- net/hub.c | 29 +++++++------ net/net-hmp-cmds.c | 59 +++++++++++++++++++------- net/net.c | 70 +++++++++++++++++++++++------- 6 files changed, 243 insertions(+), 44 deletions(-) diff --git a/qapi/net.json b/qapi/net.json index dd56215fd15..c329da9cec8 100644 --- a/qapi/net.json +++ b/qapi/net.json @@ -1235,3 +1235,125 @@ 'returns': ['UsernetInfo'], 'if': 'CONFIG_SLIRP', 'features': [ 'unstable' ] } + +## +# @NetFilterInfo: +# +# Information about a netfilter attached to a network client. +# +# @name: filter object name (QOM path component) +# +# @type: QOM type name (e.g. "filter-mirror") +# +# @info: filter properties as comma-separated key=3Dvalue pairs +# (excluding @type) +# +# Since: 11.1 +## +{ 'struct': 'NetFilterInfo', + 'data': { + 'name': 'str', + 'type': 'str', + 'info': 'str' } } + +## +# @NetworkClientInfo: +# +# Information about a network client. +# +# @name: unique network client identifier +# +# @queue-index: index of this queue (0 for single-queue clients) +# +# @type: network client driver type +# +# @info-str: driver-specific formatted information string (e.g. +# "model=3De1000,macaddr=3D52:54:00:12:34:56") +# +# @peer: the connected peer client (always a leaf; the peer's own +# peer field is never populated) +# +# @filters: attached netfilters +# +# Since: 11.1 +## +{ 'struct': 'NetworkClientInfo', + 'data': { + 'name': 'str', + 'queue-index': 'uint32', + 'type': 'NetClientDriver', + 'info-str': 'str', + '*peer': 'NetworkClientInfo', + 'filters': ['NetFilterInfo'] } } + +## +# @NetHubPortInfo: +# +# Information about a hub port. +# +# @name: hub port identifier +# +# @peer: the network client connected through this port +# +# Since: 11.1 +## +{ 'struct': 'NetHubPortInfo', + 'data': { + 'name': 'str', + '*peer': 'NetworkClientInfo' } } + +## +# @NetHubInfo: +# +# Information about a network hub. +# +# @id: hub identifier +# +# @ports: list of ports on this hub +# +# Since: 11.1 +## +{ 'struct': 'NetHubInfo', + 'data': { + 'id': 'int', + 'ports': ['NetHubPortInfo'] } } + +## +# @NetworkInfo: +# +# Information about the network configuration. +# +# @hubs: network hubs and their ports +# +# @clients: network clients not associated with a hub +# +# Since: 11.1 +## +{ 'struct': 'NetworkInfo', + 'data': { + 'hubs': ['NetHubInfo'], + 'clients': ['NetworkClientInfo'] } } + +## +# @x-query-network: +# +# Query the network configuration including hubs and clients. +# +# Features: +# +# @unstable: This command is meant for debugging. +# +# Returns: @NetworkInfo describing hubs and clients. +# +# Since: 11.1 +# +# .. qmp-example:: +# +# -> { "execute": "x-query-network" } +# <- { "return": { "clients": [ { "name": "st0", +# "queue-index": 0, "type": "stream", +# "info-str": "listening" } ] } } +## +{ 'command': 'x-query-network', + 'returns': 'NetworkInfo', + 'features': [ 'unstable' ] } diff --git a/include/net/net.h b/include/net/net.h index 45bc86fc86b..0f0b524df00 100644 --- a/include/net/net.h +++ b/include/net/net.h @@ -274,7 +274,6 @@ DeviceState *qemu_create_nic_device(const char *typenam= e, bool match_default, void qemu_create_nic_bus_devices(BusState *bus, const char *parent_type, const char *default_model, const char *alias, const char *alias_targ= et); -void print_net_client(Monitor *mon, NetClientState *nc); void net_socket_rs_init(SocketReadState *rs, SocketReadStateFinalize *finalize, bool vnet_hdr); @@ -325,6 +324,8 @@ void netdev_add(QemuOpts *opts, Error **errp); =20 int net_hub_id_for_client(NetClientState *nc, int *id); =20 +NetworkClientInfo *net_client_info(NetClientState *nc); + #define DEFAULT_NETWORK_SCRIPT CONFIG_SYSCONFDIR "/qemu-ifup" #define DEFAULT_NETWORK_DOWN_SCRIPT CONFIG_SYSCONFDIR "/qemu-ifdown" #define DEFAULT_BRIDGE_HELPER CONFIG_QEMU_HELPERDIR "/qemu-bridge-helper" diff --git a/net/hub.h b/net/hub.h index ce45f7b399d..cab6b1459b1 100644 --- a/net/hub.h +++ b/net/hub.h @@ -15,10 +15,12 @@ #ifndef NET_HUB_H #define NET_HUB_H =20 +#include "qapi/qapi-types-net.h" + NetClientState *net_hub_add_port(int hub_id, const char *name, NetClientState *hubpeer); -void net_hub_info(Monitor *mon); void net_hub_check_clients(void); bool net_hub_flush(NetClientState *nc); +NetHubInfoList *net_hub_query_info(void); =20 #endif /* NET_HUB_H */ diff --git a/net/hub.c b/net/hub.c index ee5881f6d5c..b53a4cc872c 100644 --- a/net/hub.c +++ b/net/hub.c @@ -14,7 +14,7 @@ =20 #include "qemu/osdep.h" #include "qapi/error.h" -#include "monitor/monitor.h" +#include "qapi/util.h" #include "net/net.h" #include "clients.h" #include "hub.h" @@ -199,26 +199,31 @@ NetClientState *net_hub_add_port(int hub_id, const ch= ar *name, return &port->nc; } =20 -/** - * Print hub configuration - */ -void net_hub_info(Monitor *mon) +NetHubInfoList *net_hub_query_info(void) { + NetHubInfoList *head =3D NULL, **tail =3D &head; NetHub *hub; - NetHubPort *port; =20 QLIST_FOREACH(hub, &hubs, next) { - monitor_printf(mon, "hub %d\n", hub->id); + NetHubInfo *hi =3D g_new0(NetHubInfo, 1); + NetHubPortInfoList **ptail =3D &hi->ports; + NetHubPort *port; + + hi->id =3D hub->id; + QLIST_FOREACH(port, &hub->ports, next) { - monitor_printf(mon, " \\ %s", port->nc.name); + NetHubPortInfo *pi =3D g_new0(NetHubPortInfo, 1); + pi->name =3D g_strdup(port->nc.name); if (port->nc.peer) { - monitor_printf(mon, ": "); - print_net_client(mon, port->nc.peer); - } else { - monitor_printf(mon, "\n"); + pi->peer =3D net_client_info(port->nc.peer); } + QAPI_LIST_APPEND(ptail, pi); } + + QAPI_LIST_APPEND(tail, hi); } + + return head; } =20 /** diff --git a/net/net-hmp-cmds.c b/net/net-hmp-cmds.c index 2b24c9e6049..52ac8da770d 100644 --- a/net/net-hmp-cmds.c +++ b/net/net-hmp-cmds.c @@ -19,37 +19,66 @@ #include "monitor/hmp-completion.h" #include "monitor/monitor.h" #include "net/net.h" -#include "net/hub.h" #include "qapi/clone-visitor.h" #include "qapi/qapi-commands-net.h" #include "qapi/qapi-visit-net.h" +#include "qapi/error.h" #include "qobject/qdict.h" #include "qemu/config-file.h" #include "qemu/help_option.h" #include "qemu/option.h" =20 -void hmp_info_network(Monitor *mon, const QDict *qdict) +static void hmp_print_client_info(Monitor *mon, NetworkClientInfo *ci) { - NetClientState *nc, *peer; - NetClientDriver type; + NetFilterInfoList *f; + + monitor_printf(mon, "%s: index=3D%" PRIu32 ",type=3D%s,%s\n", + ci->name, ci->queue_index, + NetClientDriver_str(ci->type), ci->info_str); + if (ci->filters) { + monitor_printf(mon, "filters:\n"); + for (f =3D ci->filters; f; f =3D f->next) { + monitor_printf(mon, " - %s: type=3D%s%s%s\n", + f->value->name, f->value->type, + f->value->info[0] ? "," : "", f->value->info); + } + } +} =20 - net_hub_info(mon); +void hmp_info_network(Monitor *mon, const QDict *qdict) +{ + Error *err =3D NULL; + g_autoptr(NetworkInfo) info =3D qmp_x_query_network(&err); + NetHubInfoList *h; + NetworkClientInfoList *entry; =20 - QTAILQ_FOREACH(nc, &net_clients, next) { - peer =3D nc->peer; - type =3D nc->info->type; + if (hmp_handle_error(mon, err)) { + return; + } =20 - /* Skip if already printed in hub info */ - if (net_hub_id_for_client(nc, NULL) =3D=3D 0) { - continue; + for (h =3D info->hubs; h; h =3D h->next) { + NetHubPortInfoList *p; + + monitor_printf(mon, "hub %d\n", (int)h->value->id); + for (p =3D h->value->ports; p; p =3D p->next) { + if (p->value->peer) { + monitor_printf(mon, " \\ %s: ", p->value->name); + hmp_print_client_info(mon, p->value->peer); + } else { + monitor_printf(mon, " \\ %s\n", p->value->name); + } } + } + + for (entry =3D info->clients; entry; entry =3D entry->next) { + NetworkClientInfo *ci =3D entry->value; =20 - if (!peer || type =3D=3D NET_CLIENT_DRIVER_NIC) { - print_net_client(mon, nc); + if (!ci->peer || ci->type =3D=3D NET_CLIENT_DRIVER_NIC) { + hmp_print_client_info(mon, ci); } /* else it's a netdev connected to a NIC, printed with the NIC */ - if (peer && type =3D=3D NET_CLIENT_DRIVER_NIC) { + if (ci->peer && ci->type =3D=3D NET_CLIENT_DRIVER_NIC) { monitor_printf(mon, " \\ "); - print_net_client(mon, peer); + hmp_print_client_info(mon, ci->peer); } } } diff --git a/net/net.c b/net/net.c index 2892f1730d1..2bcd229cd9d 100644 --- a/net/net.c +++ b/net/net.c @@ -1523,14 +1523,14 @@ void qmp_netdev_del(const char *id, Error **errp) } } =20 -static void netfilter_print_info(Monitor *mon, NetFilterState *nf) +static char *netfilter_get_info_str(NetFilterState *nf) { char *str; ObjectProperty *prop; ObjectPropertyIterator iter; Visitor *v; + GString *buf =3D g_string_new(NULL); =20 - /* generate info str */ object_property_iter_init(&iter, OBJECT(nf)); while ((prop =3D object_property_iter_next(&iter))) { if (!strcmp(prop->name, "type")) { @@ -1540,29 +1540,69 @@ static void netfilter_print_info(Monitor *mon, NetF= ilterState *nf) object_property_get(OBJECT(nf), prop->name, v, NULL); visit_complete(v, &str); visit_free(v); - monitor_printf(mon, ",%s=3D%s", prop->name, str); + if (buf->len > 0) { + g_string_append_c(buf, ','); + } + g_string_append_printf(buf, "%s=3D%s", prop->name, str); g_free(str); } - monitor_printf(mon, "\n"); + + return g_string_free(buf, false); } =20 -void print_net_client(Monitor *mon, NetClientState *nc) +static NetworkClientInfo *net_client_info_no_peer(NetClientState *nc) { + NetworkClientInfo *info =3D g_new0(NetworkClientInfo, 1); NetFilterState *nf; =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->name =3D g_strdup(nc->name); + info->queue_index =3D nc->queue_index; + info->type =3D nc->info->type; + info->info_str =3D g_strdup(nc->info_str); + if (!QTAILQ_EMPTY(&nc->filters)) { - monitor_printf(mon, "filters:\n"); + NetFilterInfoList **ftail =3D &info->filters; + QTAILQ_FOREACH(nf, &nc->filters, next) { + NetFilterInfo *fi =3D g_new0(NetFilterInfo, 1); + fi->name =3D g_strdup( + object_get_canonical_path_component(OBJECT(nf))); + fi->type =3D g_strdup(object_get_typename(OBJECT(nf))); + fi->info =3D netfilter_get_info_str(nf); + QAPI_LIST_APPEND(ftail, fi); + } } - QTAILQ_FOREACH(nf, &nc->filters, next) { - monitor_printf(mon, " - %s: type=3D%s", - object_get_canonical_path_component(OBJECT(nf)), - object_get_typename(OBJECT(nf))); - netfilter_print_info(mon, nf); + + return info; +} + +NetworkClientInfo *net_client_info(NetClientState *nc) +{ + NetworkClientInfo *info =3D net_client_info_no_peer(nc); + + if (nc->peer) { + info->peer =3D net_client_info_no_peer(nc->peer); } + + return info; +} + +NetworkInfo *qmp_x_query_network(Error **errp) +{ + NetworkInfo *info =3D g_new0(NetworkInfo, 1); + NetworkClientInfoList **tail =3D &info->clients; + NetClientState *nc; + + info->hubs =3D net_hub_query_info(); + + QTAILQ_FOREACH(nc, &net_clients, next) { + /* Skip if already gathered in hub info */ + if (net_hub_id_for_client(nc, NULL) =3D=3D 0) { + continue; + } + QAPI_LIST_APPEND(tail, net_client_info(nc)); + } + + return info; } =20 RxFilterInfoList *qmp_query_rx_filter(const char *name, Error **errp) --=20 2.54.0