* [PATCH nf-next,v2 1/2] netfilter: flowtable: retrieve stats on flow deletion
@ 2026-10-29 11:34 Pablo Neira Ayuso
2026-10-29 11:34 ` [PATCH nf-next,v2 2/2] net: ethernet: mtk_ppe: update " Pablo Neira Ayuso
2026-10-29 11:39 ` [PATCH nf-next,v2 1/2] netfilter: flowtable: retrieve " Lorenzo Bianconi
0 siblings, 2 replies; 4+ messages in thread
From: Pablo Neira Ayuso @ 2026-10-29 11:34 UTC (permalink / raw)
To: netfilter-devel; +Cc: lorenzo, nbd
Retrieve stats too when deleting a flow from hardware. Apparently, the
existing approach is missing last stats sync with the conntrack entry.
Pass the stats object to the driver so it has a chance to populate it
at deletion time. Drivers need to be updated to use this new approach.
Reported-by: Valentin Berezhnoy <dreyksmail@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
---
v2: missing copy of stats to cls_flow.stats for FLOW_CLS_DESTROY
net/netfilter/nf_flow_table_offload.c | 46 ++++++++++++++++-----------
1 file changed, 28 insertions(+), 18 deletions(-)
diff --git a/net/netfilter/nf_flow_table_offload.c b/net/netfilter/nf_flow_table_offload.c
index 4365859220e6..63b557633f3e 100644
--- a/net/netfilter/nf_flow_table_offload.c
+++ b/net/netfilter/nf_flow_table_offload.c
@@ -928,12 +928,34 @@ static int nf_flow_offload_tuple(struct nf_flowtable *flowtable,
}
up_read(&flowtable->flow_block_lock);
- if (cmd == FLOW_CLS_STATS)
+ if (cmd == FLOW_CLS_STATS ||
+ cmd == FLOW_CLS_DESTROY)
memcpy(stats, &cls_flow.stats, sizeof(*stats));
return i;
}
+static void flow_offload_update_stats(struct flow_offload_work *offload,
+ struct flow_stats *stats)
+{
+ u64 lastused;
+
+ lastused = max_t(u64, stats[0].lastused, stats[1].lastused);
+ offload->flow->timeout = max_t(u64, offload->flow->timeout,
+ lastused + flow_offload_get_timeout(offload->flow));
+
+ if (offload->flowtable->flags & NF_FLOWTABLE_COUNTER) {
+ if (stats[0].pkts)
+ nf_ct_acct_add(offload->flow->ct,
+ FLOW_OFFLOAD_DIR_ORIGINAL,
+ stats[0].pkts, stats[0].bytes);
+ if (stats[1].pkts)
+ nf_ct_acct_add(offload->flow->ct,
+ FLOW_OFFLOAD_DIR_REPLY,
+ stats[1].pkts, stats[1].bytes);
+ }
+}
+
static int flow_offload_tuple_add(struct flow_offload_work *offload,
struct nf_flow_rule *flow_rule,
enum flow_offload_tuple_dir dir)
@@ -948,10 +970,13 @@ static int flow_offload_tuple_add(struct flow_offload_work *offload,
static void flow_offload_tuple_del(struct flow_offload_work *offload,
enum flow_offload_tuple_dir dir)
{
+ struct flow_stats stats[FLOW_OFFLOAD_DIR_MAX] = {};
+
nf_flow_offload_tuple(offload->flowtable, offload->flow, NULL, dir,
offload->flowtable->priority,
- FLOW_CLS_DESTROY, NULL,
+ FLOW_CLS_DESTROY, stats,
&offload->flowtable->flow_block.cb_list);
+ flow_offload_update_stats(offload, stats);
}
static int flow_offload_rule_add(struct flow_offload_work *offload,
@@ -1011,27 +1036,12 @@ static void flow_offload_tuple_stats(struct flow_offload_work *offload,
static void flow_offload_work_stats(struct flow_offload_work *offload)
{
struct flow_stats stats[FLOW_OFFLOAD_DIR_MAX] = {};
- u64 lastused;
flow_offload_tuple_stats(offload, FLOW_OFFLOAD_DIR_ORIGINAL, &stats[0]);
if (test_bit(NF_FLOW_HW_BIDIRECTIONAL, &offload->flow->flags))
flow_offload_tuple_stats(offload, FLOW_OFFLOAD_DIR_REPLY,
&stats[1]);
-
- lastused = max_t(u64, stats[0].lastused, stats[1].lastused);
- offload->flow->timeout = max_t(u64, offload->flow->timeout,
- lastused + flow_offload_get_timeout(offload->flow));
-
- if (offload->flowtable->flags & NF_FLOWTABLE_COUNTER) {
- if (stats[0].pkts)
- nf_ct_acct_add(offload->flow->ct,
- FLOW_OFFLOAD_DIR_ORIGINAL,
- stats[0].pkts, stats[0].bytes);
- if (stats[1].pkts)
- nf_ct_acct_add(offload->flow->ct,
- FLOW_OFFLOAD_DIR_REPLY,
- stats[1].pkts, stats[1].bytes);
- }
+ flow_offload_update_stats(offload, stats);
}
static void flow_offload_work_handler(struct work_struct *work)
--
2.47.3
^ permalink raw reply related [flat|nested] 4+ messages in thread
* [PATCH nf-next,v2 2/2] net: ethernet: mtk_ppe: update stats on flow deletion
2026-10-29 11:34 [PATCH nf-next,v2 1/2] netfilter: flowtable: retrieve stats on flow deletion Pablo Neira Ayuso
@ 2026-10-29 11:34 ` Pablo Neira Ayuso
2026-10-29 11:39 ` [PATCH nf-next,v2 1/2] netfilter: flowtable: retrieve " Lorenzo Bianconi
1 sibling, 0 replies; 4+ messages in thread
From: Pablo Neira Ayuso @ 2026-10-29 11:34 UTC (permalink / raw)
To: netfilter-devel; +Cc: lorenzo, nbd
Update this driver to use the new approach to fetch stats on flow
deletion, introduced by ("netfilter: flowtable: retrieve stats on flow
deletion").
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
---
v2: no changes
.../net/ethernet/mediatek/mtk_ppe_offload.c | 32 ++++++++++++-------
1 file changed, 21 insertions(+), 11 deletions(-)
diff --git a/drivers/net/ethernet/mediatek/mtk_ppe_offload.c b/drivers/net/ethernet/mediatek/mtk_ppe_offload.c
index 99b28aaa7cc4..8ca694bb5e1b 100644
--- a/drivers/net/ethernet/mediatek/mtk_ppe_offload.c
+++ b/drivers/net/ethernet/mediatek/mtk_ppe_offload.c
@@ -526,6 +526,24 @@ mtk_flow_offload_replace(struct mtk_eth *eth, struct flow_cls_offload *f,
return err;
}
+static void
+mtk_flow_offload_update_stats(struct mtk_eth *eth, struct flow_cls_offload *f,
+ struct mtk_flow_entry *entry)
+{
+ struct mtk_foe_accounting diff;
+ u32 idle;
+
+ idle = mtk_foe_entry_idle_time(eth->ppe[entry->ppe_index], entry);
+ f->stats.lastused = jiffies - idle * HZ;
+
+ if (entry->hash != 0xFFFF &&
+ mtk_foe_entry_get_mib(eth->ppe[entry->ppe_index], entry->hash,
+ &diff)) {
+ f->stats.pkts += diff.packets;
+ f->stats.bytes += diff.bytes;
+ }
+}
+
static int
mtk_flow_offload_destroy(struct mtk_eth *eth, struct flow_cls_offload *f)
{
@@ -536,6 +554,8 @@ mtk_flow_offload_destroy(struct mtk_eth *eth, struct flow_cls_offload *f)
if (!entry)
return -ENOENT;
+ mtk_flow_offload_update_stats(eth, f, entry);
+
mtk_foe_entry_clear(eth->ppe[entry->ppe_index], entry);
rhashtable_remove_fast(ð->flow_table, &entry->node,
mtk_flow_ht_params);
@@ -550,23 +570,13 @@ static int
mtk_flow_offload_stats(struct mtk_eth *eth, struct flow_cls_offload *f)
{
struct mtk_flow_entry *entry;
- struct mtk_foe_accounting diff;
- u32 idle;
entry = rhashtable_lookup(ð->flow_table, &f->cookie,
mtk_flow_ht_params);
if (!entry)
return -ENOENT;
- idle = mtk_foe_entry_idle_time(eth->ppe[entry->ppe_index], entry);
- f->stats.lastused = jiffies - idle * HZ;
-
- if (entry->hash != 0xFFFF &&
- mtk_foe_entry_get_mib(eth->ppe[entry->ppe_index], entry->hash,
- &diff)) {
- f->stats.pkts += diff.packets;
- f->stats.bytes += diff.bytes;
- }
+ mtk_flow_offload_update_stats(eth, f, entry);
return 0;
}
--
2.47.3
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH nf-next,v2 1/2] netfilter: flowtable: retrieve stats on flow deletion
2026-10-29 11:34 [PATCH nf-next,v2 1/2] netfilter: flowtable: retrieve stats on flow deletion Pablo Neira Ayuso
2026-10-29 11:34 ` [PATCH nf-next,v2 2/2] net: ethernet: mtk_ppe: update " Pablo Neira Ayuso
@ 2026-10-29 11:39 ` Lorenzo Bianconi
2026-10-29 11:40 ` Pablo Neira Ayuso
1 sibling, 1 reply; 4+ messages in thread
From: Lorenzo Bianconi @ 2026-10-29 11:39 UTC (permalink / raw)
To: Pablo Neira Ayuso; +Cc: netfilter-devel, nbd
[-- Attachment #1: Type: text/plain, Size: 6843 bytes --]
> Retrieve stats too when deleting a flow from hardware. Apparently, the
> existing approach is missing last stats sync with the conntrack entry.
> Pass the stats object to the driver so it has a chance to populate it
> at deletion time. Drivers need to be updated to use this new approach.
>
> Reported-by: Valentin Berezhnoy <dreyksmail@gmail.com>
> Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
> ---
> v2: missing copy of stats to cls_flow.stats for FLOW_CLS_DESTROY
>
> net/netfilter/nf_flow_table_offload.c | 46 ++++++++++++++++-----------
> 1 file changed, 28 insertions(+), 18 deletions(-)
>
> diff --git a/net/netfilter/nf_flow_table_offload.c b/net/netfilter/nf_flow_table_offload.c
> index 4365859220e6..63b557633f3e 100644
> --- a/net/netfilter/nf_flow_table_offload.c
> +++ b/net/netfilter/nf_flow_table_offload.c
> @@ -928,12 +928,34 @@ static int nf_flow_offload_tuple(struct nf_flowtable *flowtable,
> }
> up_read(&flowtable->flow_block_lock);
>
> - if (cmd == FLOW_CLS_STATS)
> + if (cmd == FLOW_CLS_STATS ||
> + cmd == FLOW_CLS_DESTROY)
> memcpy(stats, &cls_flow.stats, sizeof(*stats));
>
> return i;
> }
>
> +static void flow_offload_update_stats(struct flow_offload_work *offload,
> + struct flow_stats *stats)
> +{
> + u64 lastused;
> +
> + lastused = max_t(u64, stats[0].lastused, stats[1].lastused);
> + offload->flow->timeout = max_t(u64, offload->flow->timeout,
> + lastused + flow_offload_get_timeout(offload->flow));
> +
> + if (offload->flowtable->flags & NF_FLOWTABLE_COUNTER) {
> + if (stats[0].pkts)
> + nf_ct_acct_add(offload->flow->ct,
> + FLOW_OFFLOAD_DIR_ORIGINAL,
> + stats[0].pkts, stats[0].bytes);
> + if (stats[1].pkts)
> + nf_ct_acct_add(offload->flow->ct,
> + FLOW_OFFLOAD_DIR_REPLY,
> + stats[1].pkts, stats[1].bytes);
> + }
> +}
> +
> static int flow_offload_tuple_add(struct flow_offload_work *offload,
> struct nf_flow_rule *flow_rule,
> enum flow_offload_tuple_dir dir)
> @@ -948,10 +970,13 @@ static int flow_offload_tuple_add(struct flow_offload_work *offload,
> static void flow_offload_tuple_del(struct flow_offload_work *offload,
> enum flow_offload_tuple_dir dir)
> {
> + struct flow_stats stats[FLOW_OFFLOAD_DIR_MAX] = {};
> +
> nf_flow_offload_tuple(offload->flowtable, offload->flow, NULL, dir,
> offload->flowtable->priority,
> - FLOW_CLS_DESTROY, NULL,
> + FLOW_CLS_DESTROY, stats,
> &offload->flowtable->flow_block.cb_list);
> + flow_offload_update_stats(offload, stats);
> }
>
> static int flow_offload_rule_add(struct flow_offload_work *offload,
> @@ -1011,27 +1036,12 @@ static void flow_offload_tuple_stats(struct flow_offload_work *offload,
> static void flow_offload_work_stats(struct flow_offload_work *offload)
> {
> struct flow_stats stats[FLOW_OFFLOAD_DIR_MAX] = {};
> - u64 lastused;
>
> flow_offload_tuple_stats(offload, FLOW_OFFLOAD_DIR_ORIGINAL, &stats[0]);
> if (test_bit(NF_FLOW_HW_BIDIRECTIONAL, &offload->flow->flags))
> flow_offload_tuple_stats(offload, FLOW_OFFLOAD_DIR_REPLY,
> &stats[1]);
> -
> - lastused = max_t(u64, stats[0].lastused, stats[1].lastused);
> - offload->flow->timeout = max_t(u64, offload->flow->timeout,
> - lastused + flow_offload_get_timeout(offload->flow));
> -
> - if (offload->flowtable->flags & NF_FLOWTABLE_COUNTER) {
> - if (stats[0].pkts)
> - nf_ct_acct_add(offload->flow->ct,
> - FLOW_OFFLOAD_DIR_ORIGINAL,
> - stats[0].pkts, stats[0].bytes);
> - if (stats[1].pkts)
> - nf_ct_acct_add(offload->flow->ct,
> - FLOW_OFFLOAD_DIR_REPLY,
> - stats[1].pkts, stats[1].bytes);
> - }
> + flow_offload_update_stats(offload, stats);
> }
>
> static void flow_offload_work_handler(struct work_struct *work)
> --
> 2.47.3
>
Acked-by: Lorenzo Bianconi <lorenzo@kernel.org>
I guess you can add even the patch below.
Regards,
Lorenzo
From c13752f12d74e35685f427f28659e8cd632d028b Mon Sep 17 00:00:00 2001
Message-ID: <c13752f12d74e35685f427f28659e8cd632d028b.1793273803.git.lorenzo.bianconi@oss.qualcomm.com>
From: Lorenzo Bianconi <lorenzo.bianconi@oss.qualcomm.com>
Date: Thu, 29 Oct 2026 12:35:23 +0100
Subject: [PATCH] net: airoha: update stats on flow deletion
Update this driver to use the new approach to fetch stats on flow
deletion, introduced by ("netfilter: flowtable: retrieve stats on flow
deletion").
Signed-off-by: Lorenzo Bianconi <lorenzo.bianconi@oss.qualcomm.com>
---
drivers/net/ethernet/airoha/airoha_ppe.c | 31 +++++++++++++++---------
1 file changed, 19 insertions(+), 12 deletions(-)
diff --git a/drivers/net/ethernet/airoha/airoha_ppe.c b/drivers/net/ethernet/airoha/airoha_ppe.c
index 92611802801e..35750b61028b 100644
--- a/drivers/net/ethernet/airoha/airoha_ppe.c
+++ b/drivers/net/ethernet/airoha/airoha_ppe.c
@@ -1285,6 +1285,23 @@ static int airoha_ppe_flow_offload_replace(struct airoha_eth *eth,
return err;
}
+static void airoha_ppe_flow_update_stats(struct airoha_eth *eth,
+ struct flow_cls_offload *f,
+ struct airoha_flow_table_entry *e)
+{
+ u32 idle = airoha_ppe_entry_idle_time(eth->ppe, e);
+
+ f->stats.lastused = jiffies - idle * HZ;
+ if (e->hash != 0xffff) {
+ struct airoha_foe_stats64 stats = {};
+
+ airoha_ppe_foe_entry_get_stats(eth->ppe, e->hash, &stats);
+ f->stats.pkts += (stats.packets - e->stats.packets);
+ f->stats.bytes += (stats.bytes - e->stats.bytes);
+ e->stats = stats;
+ }
+}
+
static int airoha_ppe_flow_offload_destroy(struct airoha_eth *eth,
struct flow_cls_offload *f)
{
@@ -1295,6 +1312,7 @@ static int airoha_ppe_flow_offload_destroy(struct airoha_eth *eth,
if (!e)
return -ENOENT;
+ airoha_ppe_flow_update_stats(eth, f, e);
airoha_ppe_foe_flow_remove_entry(eth->ppe, e);
rhashtable_remove_fast(ð->flow_table, &e->node,
airoha_flow_table_params);
@@ -1342,24 +1360,13 @@ static int airoha_ppe_flow_offload_stats(struct airoha_eth *eth,
struct flow_cls_offload *f)
{
struct airoha_flow_table_entry *e;
- u32 idle;
e = rhashtable_lookup(ð->flow_table, &f->cookie,
airoha_flow_table_params);
if (!e)
return -ENOENT;
- idle = airoha_ppe_entry_idle_time(eth->ppe, e);
- f->stats.lastused = jiffies - idle * HZ;
-
- if (e->hash != 0xffff) {
- struct airoha_foe_stats64 stats = {};
-
- airoha_ppe_foe_entry_get_stats(eth->ppe, e->hash, &stats);
- f->stats.pkts += (stats.packets - e->stats.packets);
- f->stats.bytes += (stats.bytes - e->stats.bytes);
- e->stats = stats;
- }
+ airoha_ppe_flow_update_stats(eth, f, e);
return 0;
}
--
2.56.0
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 228 bytes --]
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH nf-next,v2 1/2] netfilter: flowtable: retrieve stats on flow deletion
2026-10-29 11:39 ` [PATCH nf-next,v2 1/2] netfilter: flowtable: retrieve " Lorenzo Bianconi
@ 2026-10-29 11:40 ` Pablo Neira Ayuso
0 siblings, 0 replies; 4+ messages in thread
From: Pablo Neira Ayuso @ 2026-10-29 11:40 UTC (permalink / raw)
To: Lorenzo Bianconi; +Cc: netfilter-devel, nbd
On Thu, Oct 29, 2026 at 12:39:07PM +0100, Lorenzo Bianconi wrote:
> I guess you can add even the patch below.
Thanks, more driver updates are good :-)
>
> Regards,
> Lorenzo
>
> From c13752f12d74e35685f427f28659e8cd632d028b Mon Sep 17 00:00:00 2001
> Message-ID: <c13752f12d74e35685f427f28659e8cd632d028b.1793273803.git.lorenzo.bianconi@oss.qualcomm.com>
> From: Lorenzo Bianconi <lorenzo.bianconi@oss.qualcomm.com>
> Date: Thu, 29 Oct 2026 12:35:23 +0100
> Subject: [PATCH] net: airoha: update stats on flow deletion
>
> Update this driver to use the new approach to fetch stats on flow
> deletion, introduced by ("netfilter: flowtable: retrieve stats on flow
> deletion").
>
> Signed-off-by: Lorenzo Bianconi <lorenzo.bianconi@oss.qualcomm.com>
> ---
> drivers/net/ethernet/airoha/airoha_ppe.c | 31 +++++++++++++++---------
> 1 file changed, 19 insertions(+), 12 deletions(-)
>
> diff --git a/drivers/net/ethernet/airoha/airoha_ppe.c b/drivers/net/ethernet/airoha/airoha_ppe.c
> index 92611802801e..35750b61028b 100644
> --- a/drivers/net/ethernet/airoha/airoha_ppe.c
> +++ b/drivers/net/ethernet/airoha/airoha_ppe.c
> @@ -1285,6 +1285,23 @@ static int airoha_ppe_flow_offload_replace(struct airoha_eth *eth,
> return err;
> }
>
> +static void airoha_ppe_flow_update_stats(struct airoha_eth *eth,
> + struct flow_cls_offload *f,
> + struct airoha_flow_table_entry *e)
> +{
> + u32 idle = airoha_ppe_entry_idle_time(eth->ppe, e);
> +
> + f->stats.lastused = jiffies - idle * HZ;
> + if (e->hash != 0xffff) {
> + struct airoha_foe_stats64 stats = {};
> +
> + airoha_ppe_foe_entry_get_stats(eth->ppe, e->hash, &stats);
> + f->stats.pkts += (stats.packets - e->stats.packets);
> + f->stats.bytes += (stats.bytes - e->stats.bytes);
> + e->stats = stats;
> + }
> +}
> +
> static int airoha_ppe_flow_offload_destroy(struct airoha_eth *eth,
> struct flow_cls_offload *f)
> {
> @@ -1295,6 +1312,7 @@ static int airoha_ppe_flow_offload_destroy(struct airoha_eth *eth,
> if (!e)
> return -ENOENT;
>
> + airoha_ppe_flow_update_stats(eth, f, e);
> airoha_ppe_foe_flow_remove_entry(eth->ppe, e);
> rhashtable_remove_fast(ð->flow_table, &e->node,
> airoha_flow_table_params);
> @@ -1342,24 +1360,13 @@ static int airoha_ppe_flow_offload_stats(struct airoha_eth *eth,
> struct flow_cls_offload *f)
> {
> struct airoha_flow_table_entry *e;
> - u32 idle;
>
> e = rhashtable_lookup(ð->flow_table, &f->cookie,
> airoha_flow_table_params);
> if (!e)
> return -ENOENT;
>
> - idle = airoha_ppe_entry_idle_time(eth->ppe, e);
> - f->stats.lastused = jiffies - idle * HZ;
> -
> - if (e->hash != 0xffff) {
> - struct airoha_foe_stats64 stats = {};
> -
> - airoha_ppe_foe_entry_get_stats(eth->ppe, e->hash, &stats);
> - f->stats.pkts += (stats.packets - e->stats.packets);
> - f->stats.bytes += (stats.bytes - e->stats.bytes);
> - e->stats = stats;
> - }
> + airoha_ppe_flow_update_stats(eth, f, e);
>
> return 0;
> }
> --
> 2.56.0
>
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2026-10-29 11:40 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-10-29 11:34 [PATCH nf-next,v2 1/2] netfilter: flowtable: retrieve stats on flow deletion Pablo Neira Ayuso
2026-10-29 11:34 ` [PATCH nf-next,v2 2/2] net: ethernet: mtk_ppe: update " Pablo Neira Ayuso
2026-10-29 11:39 ` [PATCH nf-next,v2 1/2] netfilter: flowtable: retrieve " Lorenzo Bianconi
2026-10-29 11:40 ` Pablo Neira Ayuso
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.