From: wenxu@ucloud.cn
To: pablo@netfilter.org, paulb@mellanox.com
Cc: netfilter-devel@vger.kernel.org, netdev@vger.kernel.org
Subject: [PATCH nf-next 1/3] netfilter: nf_flow_table: add nf_conn_acct for SW flowtable offload
Date: Sat, 21 Mar 2020 19:29:16 +0800 [thread overview]
Message-ID: <1584790158-9752-2-git-send-email-wenxu@ucloud.cn> (raw)
In-Reply-To: <1584790158-9752-1-git-send-email-wenxu@ucloud.cn>
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
next prev parent reply other threads:[~2020-03-21 11:29 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
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 [this message]
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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1584790158-9752-2-git-send-email-wenxu@ucloud.cn \
--to=wenxu@ucloud.cn \
--cc=netdev@vger.kernel.org \
--cc=netfilter-devel@vger.kernel.org \
--cc=pablo@netfilter.org \
--cc=paulb@mellanox.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).