diff mbox series

[SRU,F:linux-bluefield,v1,2/2] netfilter: flowtable: add counter support in HW offload

Message ID 20230223181133.1262442-3-witu@nvidia.com
State New
Headers show
Series Add HW offloaded CT stats | expand

Commit Message

William Tu Feb. 23, 2023, 6:11 p.m. UTC
From: wenxu <wenxu@ucloud.cn>

BugLink: https://bugs.launchpad.net/bugs/2008136

Store the conntrack counters to the conntrack entry in the
HW flowtable offload.

Signed-off-by: wenxu <wenxu@ucloud.cn>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
(cherry picked from commit ef803b3cf96a26e2a601755b237585a23e6bc30c)
Signed-off-by: William Tu <witu@nvidia.com>
[William Tu: fix flow_offload_get_timeout]
---
 net/netfilter/nf_flow_table_offload.c | 12 ++++++++++++
 1 file changed, 12 insertions(+)
diff mbox series

Patch

diff --git a/net/netfilter/nf_flow_table_offload.c b/net/netfilter/nf_flow_table_offload.c
index 668bdb375205..bf786e5e516b 100644
--- a/net/netfilter/nf_flow_table_offload.c
+++ b/net/netfilter/nf_flow_table_offload.c
@@ -9,6 +9,7 @@ 
 #include <net/netfilter/nf_flow_table.h>
 #include <net/netfilter/nf_tables.h>
 #include <net/netfilter/nf_conntrack.h>
+#include <net/netfilter/nf_conntrack_acct.h>
 #include <net/netfilter/nf_conntrack_core.h>
 #include <net/netfilter/nf_conntrack_tuple.h>
 
@@ -802,6 +803,17 @@  static void flow_offload_work_stats(struct flow_offload_work *offload)
 	/* Clear HW_OFFLOAD right away when hw module is removed. */
 	if (!lastused)
 		clear_bit(IPS_HW_OFFLOAD_BIT, &offload->flow->ct->status);
+
+	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 void flow_offload_work_handler(struct work_struct *work)