Netfilter-Devel Archive on lore.kernel.org
 help / color / Atom feed
* [PATCH nf-next 0/3] netfilter: nf_flow_table_offload: add nf_conn_acct for flowtable offload
@ 2020-03-21 11:29 wenxu
  2020-03-21 11:29 ` [PATCH nf-next 1/3] netfilter: nf_flow_table: add nf_conn_acct for SW " wenxu
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: wenxu @ 2020-03-21 11:29 UTC (permalink / raw)
  To: pablo, paulb; +Cc: netfilter-devel, netdev

From: wenxu <wenxu@ucloud.cn>

An offloaded conntrack in flowtable will never count the nf_conn_act
counter after the flow is offloaded in SW or HW.

wenxu (3):
  netfilter: nf_flow_table: add nf_conn_acct for SW flowtable offload
  netfilter: nf_flow_table: add nf_conn_acct for HW flowtable offload
  net/sched: act_ct: add nf_conn_acct for SW act_ct flowtable offload

 include/net/netfilter/nf_flow_table.h |  4 ++++
 net/netfilter/nf_flow_table_core.c    | 19 +++++++++++++++++++
 net/netfilter/nf_flow_table_ip.c      |  4 ++++
 net/netfilter/nf_flow_table_offload.c |  8 ++++++++
 net/sched/act_ct.c                    |  1 +
 5 files changed, 36 insertions(+)

-- 
1.8.3.1


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH nf-next 1/3] netfilter: nf_flow_table: add nf_conn_acct for SW flowtable offload
  2020-03-21 11:29 [PATCH nf-next 0/3] netfilter: nf_flow_table_offload: add nf_conn_acct for flowtable offload wenxu
@ 2020-03-21 11:29 ` " wenxu
  2020-03-21 11:29 ` [PATCH nf-next 2/3] netfilter: nf_flow_table: add nf_conn_acct for HW " wenxu
  2020-03-21 11:29 ` [PATCH nf-next 3/3] net/sched: act_ct: add nf_conn_acct for SW act_ct " wenxu
  2 siblings, 0 replies; 4+ messages in thread
From: wenxu @ 2020-03-21 11:29 UTC (permalink / raw)
  To: pablo, paulb; +Cc: netfilter-devel, netdev

From: wenxu <wenxu@ucloud.cn>

Add nf_conn_acct counter for the software flowtable offload

Signed-off-by: wenxu <wenxu@ucloud.cn>
---
 include/net/netfilter/nf_flow_table.h |  4 ++++
 net/netfilter/nf_flow_table_core.c    | 19 +++++++++++++++++++
 net/netfilter/nf_flow_table_ip.c      |  4 ++++
 3 files changed, 27 insertions(+)

diff --git a/include/net/netfilter/nf_flow_table.h b/include/net/netfilter/nf_flow_table.h
index f523ea8..11f9d50 100644
--- a/include/net/netfilter/nf_flow_table.h
+++ b/include/net/netfilter/nf_flow_table.h
@@ -180,6 +180,10 @@ struct flow_offload_tuple_rhash *flow_offload_lookup(struct nf_flowtable *flow_t
 
 void flow_offload_teardown(struct flow_offload *flow);
 
+void flow_offload_update_acct(struct flow_offload *flow, unsigned int pkts,
+			      unsigned int bytes,
+			      enum flow_offload_tuple_dir dir);
+
 int nf_flow_snat_port(const struct flow_offload *flow,
 		      struct sk_buff *skb, unsigned int thoff,
 		      u8 protocol, enum flow_offload_tuple_dir dir);
diff --git a/net/netfilter/nf_flow_table_core.c b/net/netfilter/nf_flow_table_core.c
index 9a477bd..8667e31 100644
--- a/net/netfilter/nf_flow_table_core.c
+++ b/net/netfilter/nf_flow_table_core.c
@@ -13,6 +13,7 @@
 #include <net/netfilter/nf_conntrack_core.h>
 #include <net/netfilter/nf_conntrack_l4proto.h>
 #include <net/netfilter/nf_conntrack_tuple.h>
+#include <net/netfilter/nf_conntrack_acct.h>
 
 static DEFINE_MUTEX(flowtable_lock);
 static LIST_HEAD(flowtables);
@@ -618,6 +619,24 @@ void nf_flow_table_free(struct nf_flowtable *flow_table)
 }
 EXPORT_SYMBOL_GPL(nf_flow_table_free);
 
+void flow_offload_update_acct(struct flow_offload *flow, unsigned int pkts,
+			      unsigned int bytes,
+			      enum flow_offload_tuple_dir dir)
+{
+	struct nf_conn_acct *acct;
+
+	if (flow && flow->ct) {
+		acct = nf_conn_acct_find(flow->ct);
+		if (acct) {
+			struct nf_conn_counter *counter = acct->counter;
+
+			atomic64_add(pkts, &counter[dir].packets);
+			atomic64_add(bytes, &counter[dir].bytes);
+		}
+	}
+}
+EXPORT_SYMBOL_GPL(flow_offload_update_acct);
+
 static int __init nf_flow_table_module_init(void)
 {
 	return nf_flow_table_offload_init();
diff --git a/net/netfilter/nf_flow_table_ip.c b/net/netfilter/nf_flow_table_ip.c
index 5272721..53680a8 100644
--- a/net/netfilter/nf_flow_table_ip.c
+++ b/net/netfilter/nf_flow_table_ip.c
@@ -279,6 +279,8 @@ static unsigned int nf_flow_xmit_xfrm(struct sk_buff *skb,
 		return NF_ACCEPT;
 	}
 
+	flow_offload_update_acct(flow, 1, skb->len, dir);
+
 	if (nf_flow_nat_ip(flow, skb, thoff, dir) < 0)
 		return NF_DROP;
 
@@ -506,6 +508,8 @@ static int nf_flow_tuple_ipv6(struct sk_buff *skb, const struct net_device *dev,
 		return NF_ACCEPT;
 	}
 
+	flow_offload_update_acct(flow, 1, skb->len, dir);
+
 	if (skb_try_make_writable(skb, sizeof(*ip6h)))
 		return NF_DROP;
 
-- 
1.8.3.1


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH nf-next 2/3] netfilter: nf_flow_table: add nf_conn_acct for HW flowtable offload
  2020-03-21 11:29 [PATCH nf-next 0/3] netfilter: nf_flow_table_offload: add nf_conn_acct for flowtable offload wenxu
  2020-03-21 11:29 ` [PATCH nf-next 1/3] netfilter: nf_flow_table: add nf_conn_acct for SW " wenxu
@ 2020-03-21 11:29 ` " wenxu
  2020-03-21 11:29 ` [PATCH nf-next 3/3] net/sched: act_ct: add nf_conn_acct for SW act_ct " wenxu
  2 siblings, 0 replies; 4+ messages in thread
From: wenxu @ 2020-03-21 11:29 UTC (permalink / raw)
  To: pablo, paulb; +Cc: netfilter-devel, netdev

From: wenxu <wenxu@ucloud.cn>

Add nf_conn_acct counter for the hardware flowtable offload

Signed-off-by: wenxu <wenxu@ucloud.cn>
---
 net/netfilter/nf_flow_table_offload.c | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/net/netfilter/nf_flow_table_offload.c b/net/netfilter/nf_flow_table_offload.c
index a68136a..5b02bdd 100644
--- a/net/netfilter/nf_flow_table_offload.c
+++ b/net/netfilter/nf_flow_table_offload.c
@@ -784,6 +784,14 @@ static void flow_offload_work_stats(struct flow_offload_work *offload)
 	lastused = max_t(u64, stats[0].lastused, stats[1].lastused);
 	offload->flow->timeout = max_t(u64, offload->flow->timeout,
 				       lastused + NF_FLOW_TIMEOUT);
+	if (stats[0].pkts)
+		flow_offload_update_acct(offload->flow, stats[0].pkts,
+					 stats[0].bytes,
+					 FLOW_OFFLOAD_DIR_ORIGINAL);
+	if (stats[1].pkts)
+		flow_offload_update_acct(offload->flow, stats[1].pkts,
+					 stats[1].bytes,
+					 FLOW_OFFLOAD_DIR_REPLY);
 }
 
 static void flow_offload_work_handler(struct work_struct *work)
-- 
1.8.3.1


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH nf-next 3/3] net/sched: act_ct: add nf_conn_acct for SW act_ct flowtable offload
  2020-03-21 11:29 [PATCH nf-next 0/3] netfilter: nf_flow_table_offload: add nf_conn_acct for flowtable offload wenxu
  2020-03-21 11:29 ` [PATCH nf-next 1/3] netfilter: nf_flow_table: add nf_conn_acct for SW " wenxu
  2020-03-21 11:29 ` [PATCH nf-next 2/3] netfilter: nf_flow_table: add nf_conn_acct for HW " wenxu
@ 2020-03-21 11:29 ` " wenxu
  2 siblings, 0 replies; 4+ messages in thread
From: wenxu @ 2020-03-21 11:29 UTC (permalink / raw)
  To: pablo, paulb; +Cc: netfilter-devel, netdev

From: wenxu <wenxu@ucloud.cn>

Add nf_conn_acct counter for the software act_ct flowtable offload

Signed-off-by: wenxu <wenxu@ucloud.cn>
---
 net/sched/act_ct.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/net/sched/act_ct.c b/net/sched/act_ct.c
index 56b66d2..0386c6b 100644
--- a/net/sched/act_ct.c
+++ b/net/sched/act_ct.c
@@ -536,6 +536,7 @@ static bool tcf_ct_flow_table_lookup(struct tcf_ct_params *p,
 	flow_offload_refresh(nf_ft, flow);
 	nf_conntrack_get(&ct->ct_general);
 	nf_ct_set(skb, ct, ctinfo);
+	flow_offload_update_acct(flow, 1, skb->len, dir);
 
 	return true;
 }
-- 
1.8.3.1


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, back to index

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-03-21 11:29 [PATCH nf-next 0/3] netfilter: nf_flow_table_offload: add nf_conn_acct for flowtable offload wenxu
2020-03-21 11:29 ` [PATCH nf-next 1/3] netfilter: nf_flow_table: add nf_conn_acct for SW " wenxu
2020-03-21 11:29 ` [PATCH nf-next 2/3] netfilter: nf_flow_table: add nf_conn_acct for HW " wenxu
2020-03-21 11:29 ` [PATCH nf-next 3/3] net/sched: act_ct: add nf_conn_acct for SW act_ct " wenxu

Netfilter-Devel Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/netfilter-devel/0 netfilter-devel/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 netfilter-devel netfilter-devel/ https://lore.kernel.org/netfilter-devel \
		netfilter-devel@vger.kernel.org
	public-inbox-index netfilter-devel

Example config snippet for mirrors

Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.kernel.vger.netfilter-devel


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git