lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date:   Sat, 21 Mar 2020 19:29:16 +0800
From:   wenxu@...oud.cn
To:     pablo@...filter.org, paulb@...lanox.com
Cc:     netfilter-devel@...r.kernel.org, netdev@...r.kernel.org
Subject: [PATCH nf-next 1/3] netfilter: nf_flow_table: add nf_conn_acct for SW flowtable offload

From: wenxu <wenxu@...oud.cn>

Add nf_conn_acct counter for the software flowtable offload

Signed-off-by: wenxu <wenxu@...oud.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

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ