Patch Detail
get:
Show a patch.
patch:
Update a patch.
put:
Update a patch.
GET /api/patches/2194225/?format=api
{ "id": 2194225, "url": "http://patchwork.ozlabs.org/api/patches/2194225/?format=api", "web_url": "http://patchwork.ozlabs.org/project/qemu-devel/patch/20260207134728.1495932-3-lulu@redhat.com/", "project": { "id": 14, "url": "http://patchwork.ozlabs.org/api/projects/14/?format=api", "name": "QEMU Development", "link_name": "qemu-devel", "list_id": "qemu-devel.nongnu.org", "list_email": "qemu-devel@nongnu.org", "web_url": "", "scm_url": "", "webscm_url": "", "list_archive_url": "", "list_archive_url_format": "", "commit_url_format": "" }, "msgid": "<20260207134728.1495932-3-lulu@redhat.com>", "list_archive_url": null, "date": "2026-02-07T13:47:19", "name": "[03/12] net/filter: add statistics counters for netfilters", "commit_ref": null, "pull_url": null, "state": "new", "archived": false, "hash": "6d6530e3b4822d83cdbcbab19c9357cdd4c8ea8e", "submitter": { "id": 78960, "url": "http://patchwork.ozlabs.org/api/people/78960/?format=api", "name": "Cindy Lu", "email": "lulu@redhat.com" }, "delegate": null, "mbox": "http://patchwork.ozlabs.org/project/qemu-devel/patch/20260207134728.1495932-3-lulu@redhat.com/mbox/", "series": [ { "id": 491379, "url": "http://patchwork.ozlabs.org/api/series/491379/?format=api", "web_url": "http://patchwork.ozlabs.org/project/qemu-devel/list/?series=491379", "date": "2026-02-07T13:47:17", "name": "[01/12] net: introduce read_poll/write_poll", "version": 1, "mbox": "http://patchwork.ozlabs.org/series/491379/mbox/" } ], "comments": "http://patchwork.ozlabs.org/api/patches/2194225/comments/", "check": "pending", "checks": "http://patchwork.ozlabs.org/api/patches/2194225/checks/", "tags": {}, "related": [], "headers": { "Return-Path": "<qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org>", "X-Original-To": "incoming@patchwork.ozlabs.org", "Delivered-To": "patchwork-incoming@legolas.ozlabs.org", "Authentication-Results": [ "legolas.ozlabs.org;\n\tdkim=pass (1024-bit key;\n unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256\n header.s=mimecast20190719 header.b=YDvQbrNG;\n\tdkim-atps=neutral", "legolas.ozlabs.org;\n spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org\n (client-ip=209.51.188.17; helo=lists.gnu.org;\n envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org;\n receiver=patchwork.ozlabs.org)" ], "Received": [ "from lists.gnu.org (lists.gnu.org [209.51.188.17])\n\t(using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits))\n\t(No client certificate requested)\n\tby legolas.ozlabs.org (Postfix) with ESMTPS id 4f7XPq5ZRXz1xtV\n\tfor <incoming@patchwork.ozlabs.org>; Sun, 08 Feb 2026 00:49:35 +1100 (AEDT)", "from localhost ([::1] helo=lists1p.gnu.org)\n\tby lists.gnu.org with esmtp (Exim 4.90_1)\n\t(envelope-from <qemu-devel-bounces@nongnu.org>)\n\tid 1voifZ-00038v-9O; Sat, 07 Feb 2026 08:48:18 -0500", "from eggs.gnu.org ([2001:470:142:3::10])\n by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)\n (Exim 4.90_1) (envelope-from <lulu@redhat.com>) id 1voifK-00030Z-Bx\n for qemu-devel@nongnu.org; Sat, 07 Feb 2026 08:48:06 -0500", "from us-smtp-delivery-124.mimecast.com ([170.10.133.124])\n by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)\n (Exim 4.90_1) (envelope-from <lulu@redhat.com>) id 1voifH-0003DH-Gs\n for qemu-devel@nongnu.org; Sat, 07 Feb 2026 08:48:01 -0500", "from mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com\n (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by\n relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3,\n cipher=TLS_AES_256_GCM_SHA384) id us-mta-512-xkSe72syPeWh7WO8y79lEA-1; Sat,\n 07 Feb 2026 08:47:54 -0500", "from mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com\n (mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.93])\n (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)\n key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest\n SHA256)\n (No client certificate requested)\n by mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS\n id BDEE419560A3; Sat, 7 Feb 2026 13:47:53 +0000 (UTC)", "from S2.redhat.com (unknown [10.72.112.15])\n by mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP\n id 80FA818004AD; Sat, 7 Feb 2026 13:47:50 +0000 (UTC)" ], "DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com;\n s=mimecast20190719; t=1770472078;\n h=from:from:reply-to:subject:subject:date:date:message-id:message-id:\n to:to:cc:mime-version:mime-version:\n content-transfer-encoding:content-transfer-encoding:\n in-reply-to:in-reply-to:references:references;\n bh=2fVgskyzccHmmwLOE9RNrMOJNpK9tOSvkgw1i8lrKc8=;\n b=YDvQbrNGvWWnNP83ceLST0PATVFaG7iDqPW6MroomCizufMRY9uUNeKB2G05dpztNWCYKz\n qn40bnJoBMfAgW4gZvTeriXyzYKpFG3Plga76wbqOqokCcF4qqljYrbn/aijzQKTca32JO\n IuIYVrGLQiODRYJWuWaNT1ZMjib164A=", "X-MC-Unique": "xkSe72syPeWh7WO8y79lEA-1", "X-Mimecast-MFC-AGG-ID": "xkSe72syPeWh7WO8y79lEA_1770472074", "From": "Cindy Lu <lulu@redhat.com>", "To": "lulu@redhat.com, mst@redhat.com, jasowang@redhat.com, zhangckid@gmail.com,\n lizhijian@fujitsu.com, qemu-devel@nongnu.org", "Subject": "[PATCH 03/12] net/filter: add statistics counters for netfilters", "Date": "Sat, 7 Feb 2026 21:47:19 +0800", "Message-ID": "<20260207134728.1495932-3-lulu@redhat.com>", "In-Reply-To": "<20260207134728.1495932-1-lulu@redhat.com>", "References": "<20260207134728.1495932-1-lulu@redhat.com>", "MIME-Version": "1.0", "Content-Transfer-Encoding": "8bit", "X-Scanned-By": "MIMEDefang 3.4.1 on 10.30.177.93", "Received-SPF": "pass client-ip=170.10.133.124; envelope-from=lulu@redhat.com;\n helo=us-smtp-delivery-124.mimecast.com", "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, DKIMWL_WL_HIGH=-0.001,\n DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1,\n RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=0.001,\n RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001,\n SPF_HELO_PASS=-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.29", "Precedence": "list", "List-Id": "qemu development <qemu-devel.nongnu.org>", "List-Unsubscribe": "<https://lists.nongnu.org/mailman/options/qemu-devel>,\n <mailto:qemu-devel-request@nongnu.org?subject=unsubscribe>", "List-Archive": "<https://lists.nongnu.org/archive/html/qemu-devel>", "List-Post": "<mailto:qemu-devel@nongnu.org>", "List-Help": "<mailto:qemu-devel-request@nongnu.org?subject=help>", "List-Subscribe": "<https://lists.nongnu.org/mailman/listinfo/qemu-devel>,\n <mailto:qemu-devel-request@nongnu.org?subject=subscribe>", "Errors-To": "qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org", "Sender": "qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org" }, "content": "From: Jason Wang <jasowang@redhat.com>\n\nAdd packet and byte counters to NetFilterState to track traffic\npassing through netfilters. The counters are updated in\nqemu_netfilter_receive() for both TX and RX directions.\n\nNew QMP command 'query-netfilter-stats' and HMP command\n'info netfilter-stats' are added to query the statistics.\n\nThe NetFilterStats structure includes:\n- name: filter name\n- netdev: attached netdev id\n- type: filter type (e.g., filter-mirror)\n- packets-tx/rx: packet counters\n- bytes-tx/rx: byte counters\n\nExample QMP usage:\n {\"execute\": \"query-netfilter-stats\"}\n\nExample HMP usage:\n (qemu) info netfilter-stats\n\nSigned-off-by: Jason Wang <jasowang@redhat.com>\nSigned-off-by: Cindy Lu <lulu@redhat.com>\n---\n hmp-commands-info.hx | 13 +++++++++\n include/monitor/hmp.h | 1 +\n include/net/filter.h | 6 +++++\n net/filter.c | 16 ++++++++++-\n net/net-hmp-cmds.c | 28 +++++++++++++++++++\n net/net.c | 42 +++++++++++++++++++++++++++++\n qapi/net.json | 63 +++++++++++++++++++++++++++++++++++++++++++\n 7 files changed, 168 insertions(+), 1 deletion(-)", "diff": "diff --git a/hmp-commands-info.hx b/hmp-commands-info.hx\nindex 41674dcbe1..d67df3f98a 100644\n--- a/hmp-commands-info.hx\n+++ b/hmp-commands-info.hx\n@@ -44,6 +44,19 @@ SRST\n Show the network state.\n ERST\n \n+ {\n+ .name = \"netfilter-stats\",\n+ .args_type = \"\",\n+ .params = \"\",\n+ .help = \"show netfilter statistics\",\n+ .cmd = hmp_info_netfilter_stats,\n+ },\n+\n+SRST\n+ ``info netfilter-stats``\n+ Show netfilter statistics (packets and bytes counters).\n+ERST\n+\n {\n .name = \"chardev\",\n .args_type = \"\",\ndiff --git a/include/monitor/hmp.h b/include/monitor/hmp.h\nindex 83721b5ffc..7150ca8514 100644\n--- a/include/monitor/hmp.h\n+++ b/include/monitor/hmp.h\n@@ -56,6 +56,7 @@ void hmp_cont(Monitor *mon, const QDict *qdict);\n void hmp_system_wakeup(Monitor *mon, const QDict *qdict);\n void hmp_nmi(Monitor *mon, const QDict *qdict);\n void hmp_info_network(Monitor *mon, const QDict *qdict);\n+void hmp_info_netfilter_stats(Monitor *mon, const QDict *qdict);\n void hmp_set_link(Monitor *mon, const QDict *qdict);\n void hmp_balloon(Monitor *mon, const QDict *qdict);\n void hmp_loadvm(Monitor *mon, const QDict *qdict);\ndiff --git a/include/net/filter.h b/include/net/filter.h\nindex f15f7932b2..04786e4e87 100644\n--- a/include/net/filter.h\n+++ b/include/net/filter.h\n@@ -60,6 +60,12 @@ struct NetFilterState {\n char *position;\n bool insert_before_flag;\n QTAILQ_ENTRY(NetFilterState) next;\n+\n+ /* statistics */\n+ uint64_t bytes_tx;\n+ uint64_t bytes_rx;\n+ uint64_t packets_tx;\n+ uint64_t packets_rx;\n };\n \n ssize_t qemu_netfilter_receive(NetFilterState *nf,\ndiff --git a/net/filter.c b/net/filter.c\nindex c7cc6615dc..76345c1a9d 100644\n--- a/net/filter.c\n+++ b/net/filter.c\n@@ -33,13 +33,27 @@ ssize_t qemu_netfilter_receive(NetFilterState *nf,\n int iovcnt,\n NetPacketSent *sent_cb)\n {\n+ ssize_t ret;\n+ size_t size;\n+\n if (qemu_can_skip_netfilter(nf)) {\n return 0;\n }\n if (nf->direction == direction ||\n nf->direction == NET_FILTER_DIRECTION_ALL) {\n- return NETFILTER_GET_CLASS(OBJECT(nf))->receive_iov(\n+ /* Update statistics */\n+ size = iov_size(iov, iovcnt);\n+ if (direction == NET_FILTER_DIRECTION_TX) {\n+ nf->packets_tx++;\n+ nf->bytes_tx += size;\n+ } else {\n+ nf->packets_rx++;\n+ nf->bytes_rx += size;\n+ }\n+\n+ ret = NETFILTER_GET_CLASS(OBJECT(nf))->receive_iov(\n nf, sender, flags, iov, iovcnt, sent_cb);\n+ return ret;\n }\n \n return 0;\ndiff --git a/net/net-hmp-cmds.c b/net/net-hmp-cmds.c\nindex e7c55d2787..9bdd6d233f 100644\n--- a/net/net-hmp-cmds.c\n+++ b/net/net-hmp-cmds.c\n@@ -168,3 +168,31 @@ void netdev_del_completion(ReadLineState *rs, int nb_args, const char *str)\n }\n }\n }\n+\n+void hmp_info_netfilter_stats(Monitor *mon, const QDict *qdict)\n+{\n+ NetFilterStatsList *stats_list, *entry;\n+ Error *err = NULL;\n+\n+ stats_list = qmp_query_netfilter_stats(NULL, &err);\n+ if (hmp_handle_error(mon, err)) {\n+ return;\n+ }\n+\n+ if (!stats_list) {\n+ monitor_printf(mon, \"No netfilters found\\n\");\n+ return;\n+ }\n+\n+ for (entry = stats_list; entry; entry = entry->next) {\n+ NetFilterStats *stats = entry->value;\n+ monitor_printf(mon, \"%s: netdev=%s type=%s\\n\",\n+ stats->name, stats->netdev, stats->type);\n+ monitor_printf(mon, \" tx: %\" PRIu64 \" packets, %\" PRIu64 \" bytes\\n\",\n+ stats->packets_tx, stats->bytes_tx);\n+ monitor_printf(mon, \" rx: %\" PRIu64 \" packets, %\" PRIu64 \" bytes\\n\",\n+ stats->packets_rx, stats->bytes_rx);\n+ }\n+\n+ qapi_free_NetFilterStatsList(stats_list);\n+}\ndiff --git a/net/net.c b/net/net.c\nindex 27e0d27807..40966fbf8a 100644\n--- a/net/net.c\n+++ b/net/net.c\n@@ -1604,6 +1604,48 @@ RxFilterInfoList *qmp_query_rx_filter(const char *name, Error **errp)\n return filter_list;\n }\n \n+NetFilterStatsList *qmp_query_netfilter_stats(const char *name, Error **errp)\n+{\n+ NetClientState *nc;\n+ NetFilterState *nf;\n+ NetFilterStatsList *stats_list = NULL, **tail = &stats_list;\n+ bool found = false;\n+\n+ QTAILQ_FOREACH(nc, &net_clients, next) {\n+ QTAILQ_FOREACH(nf, &nc->filters, next) {\n+ NetFilterStats *stats;\n+ const char *filter_name;\n+\n+ filter_name = object_get_canonical_path_component(OBJECT(nf));\n+ if (name && strcmp(filter_name, name) != 0) {\n+ continue;\n+ }\n+\n+ found = true;\n+ stats = g_new0(NetFilterStats, 1);\n+ stats->name = g_strdup(filter_name);\n+ stats->netdev = g_strdup(nf->netdev_id);\n+ stats->type = g_strdup(object_get_typename(OBJECT(nf)));\n+ stats->packets_tx = nf->packets_tx;\n+ stats->packets_rx = nf->packets_rx;\n+ stats->bytes_tx = nf->bytes_tx;\n+ stats->bytes_rx = nf->bytes_rx;\n+\n+ QAPI_LIST_APPEND(tail, stats);\n+\n+ if (name) {\n+ return stats_list;\n+ }\n+ }\n+ }\n+\n+ if (name && !found) {\n+ error_setg(errp, \"netfilter '%s' not found\", name);\n+ }\n+\n+ return stats_list;\n+}\n+\n void colo_notify_filters_event(int event, Error **errp)\n {\n NetClientState *nc;\ndiff --git a/qapi/net.json b/qapi/net.json\nindex 118bd34965..277cdd9e32 100644\n--- a/qapi/net.json\n+++ b/qapi/net.json\n@@ -1191,3 +1191,66 @@\n ##\n { 'event': 'NETDEV_VHOST_USER_DISCONNECTED',\n 'data': { 'netdev-id': 'str' } }\n+\n+##\n+# @NetFilterStats:\n+#\n+# Statistics for a network filter.\n+#\n+# @name: the name of the network filter\n+#\n+# @netdev: the netdev id attached to\n+#\n+# @type: the filter type\n+#\n+# @packets-tx: number of transmitted packets\n+#\n+# @packets-rx: number of received packets\n+#\n+# @bytes-tx: number of transmitted bytes\n+#\n+# @bytes-rx: number of received bytes\n+#\n+# Since: 10.1\n+##\n+{ 'struct': 'NetFilterStats',\n+ 'data': {\n+ 'name': 'str',\n+ 'netdev': 'str',\n+ 'type': 'str',\n+ 'packets-tx': 'uint64',\n+ 'packets-rx': 'uint64',\n+ 'bytes-tx': 'uint64',\n+ 'bytes-rx': 'uint64' } }\n+\n+##\n+# @query-netfilter-stats:\n+#\n+# Return statistics for network filters.\n+#\n+# @name: Optional filter name to query. If not specified, returns\n+# stats for all filters.\n+#\n+# Returns: A list of @NetFilterStats for each filter.\n+#\n+# Since: 10.1\n+#\n+# .. qmp-example::\n+#\n+# -> { \"execute\": \"query-netfilter-stats\" }\n+# <- { \"return\": [\n+# {\n+# \"name\": \"f0\",\n+# \"netdev\": \"net0\",\n+# \"type\": \"filter-mirror\",\n+# \"packets-tx\": 12345,\n+# \"packets-rx\": 0,\n+# \"bytes-tx\": 1234567,\n+# \"bytes-rx\": 0\n+# }\n+# ]\n+# }\n+##\n+{ 'command': 'query-netfilter-stats',\n+ 'data': { '*name': 'str' },\n+ 'returns': ['NetFilterStats'] }\n", "prefixes": [ "03/12" ] }