* [PATCH 1/2] netfilter: conntrack: add nf_ct_acct_add()
@ 2020-03-28 0:57 wenxu
2020-03-28 0:57 ` [PATCH 2/2] netfilter: flowtable: add counter support in HW offload wenxu
2020-03-29 15:58 ` [PATCH 1/2] netfilter: conntrack: add nf_ct_acct_add() Pablo Neira Ayuso
0 siblings, 2 replies; 4+ messages in thread
From: wenxu @ 2020-03-28 0:57 UTC (permalink / raw)
To: pablo; +Cc: netfilter-devel
From: wenxu <wenxu@ucloud.cn>
Add nf_ct_acct_add function to update the conntrack counter
with packets and bytes.
Signed-off-by: wenxu <wenxu@ucloud.cn>
---
include/net/netfilter/nf_conntrack_acct.h | 11 ++++++++++-
net/netfilter/nf_conntrack_core.c | 7 ++++---
2 files changed, 14 insertions(+), 4 deletions(-)
diff --git a/include/net/netfilter/nf_conntrack_acct.h b/include/net/netfilter/nf_conntrack_acct.h
index df198c5..7f44a77 100644
--- a/include/net/netfilter/nf_conntrack_acct.h
+++ b/include/net/netfilter/nf_conntrack_acct.h
@@ -65,7 +65,16 @@ static inline void nf_ct_set_acct(struct net *net, bool enable)
#endif
}
-void nf_ct_acct_update(struct nf_conn *ct, u32 dir, unsigned int bytes);
+void nf_ct_acct_add(struct nf_conn *ct, u32 dir, unsigned int packets,
+ unsigned int bytes);
+
+static inline void nf_ct_acct_update(struct nf_conn *ct, u32 dir,
+ unsigned int bytes)
+{
+#if IS_ENABLED(CONFIG_NF_CONNTRACK)
+ nf_ct_acct_add(ct, dir, 1, bytes);
+#endif
+}
void nf_conntrack_acct_pernet_init(struct net *net);
diff --git a/net/netfilter/nf_conntrack_core.c b/net/netfilter/nf_conntrack_core.c
index 7ded6d2..c4582eb 100644
--- a/net/netfilter/nf_conntrack_core.c
+++ b/net/netfilter/nf_conntrack_core.c
@@ -865,7 +865,8 @@ static void __nf_conntrack_hash_insert(struct nf_conn *ct,
}
EXPORT_SYMBOL_GPL(nf_conntrack_hash_check_insert);
-void nf_ct_acct_update(struct nf_conn *ct, u32 dir, unsigned int bytes)
+void nf_ct_acct_add(struct nf_conn *ct, u32 dir, unsigned int packets,
+ unsigned int bytes)
{
struct nf_conn_acct *acct;
@@ -873,11 +874,11 @@ void nf_ct_acct_update(struct nf_conn *ct, u32 dir, unsigned int bytes)
if (acct) {
struct nf_conn_counter *counter = acct->counter;
- atomic64_inc(&counter[dir].packets);
+ atomic64_add(packets, &counter[dir].packets);
atomic64_add(bytes, &counter[dir].bytes);
}
}
-EXPORT_SYMBOL_GPL(nf_ct_acct_update);
+EXPORT_SYMBOL_GPL(nf_ct_acct_add);
static void nf_ct_acct_merge(struct nf_conn *ct, enum ip_conntrack_info ctinfo,
const struct nf_conn *loser_ct)
--
1.8.3.1
^ permalink raw reply related [flat|nested] 4+ messages in thread
* [PATCH 2/2] netfilter: flowtable: add counter support in HW offload
2020-03-28 0:57 [PATCH 1/2] netfilter: conntrack: add nf_ct_acct_add() wenxu
@ 2020-03-28 0:57 ` wenxu
2020-03-29 15:58 ` Pablo Neira Ayuso
2020-03-29 15:58 ` [PATCH 1/2] netfilter: conntrack: add nf_ct_acct_add() Pablo Neira Ayuso
1 sibling, 1 reply; 4+ messages in thread
From: wenxu @ 2020-03-28 0:57 UTC (permalink / raw)
To: pablo; +Cc: netfilter-devel
From: wenxu <wenxu@ucloud.cn>
Store the conntrack counters to the conntrack entry in the
HW flowtable offload.
Signed-off-by: wenxu <wenxu@ucloud.cn>
---
net/netfilter/nf_flow_table_offload.c | 12 ++++++++++++
1 file changed, 12 insertions(+)
diff --git a/net/netfilter/nf_flow_table_offload.c b/net/netfilter/nf_flow_table_offload.c
index 60ad597..85ee941 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>
@@ -783,6 +784,17 @@ 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 (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)
--
1.8.3.1
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH 1/2] netfilter: conntrack: add nf_ct_acct_add()
2020-03-28 0:57 [PATCH 1/2] netfilter: conntrack: add nf_ct_acct_add() wenxu
2020-03-28 0:57 ` [PATCH 2/2] netfilter: flowtable: add counter support in HW offload wenxu
@ 2020-03-29 15:58 ` Pablo Neira Ayuso
1 sibling, 0 replies; 4+ messages in thread
From: Pablo Neira Ayuso @ 2020-03-29 15:58 UTC (permalink / raw)
To: wenxu; +Cc: netfilter-devel
On Sat, Mar 28, 2020 at 08:57:53AM +0800, wenxu@ucloud.cn wrote:
> From: wenxu <wenxu@ucloud.cn>
>
> Add nf_ct_acct_add function to update the conntrack counter
> with packets and bytes.
Applied.
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH 2/2] netfilter: flowtable: add counter support in HW offload
2020-03-28 0:57 ` [PATCH 2/2] netfilter: flowtable: add counter support in HW offload wenxu
@ 2020-03-29 15:58 ` Pablo Neira Ayuso
0 siblings, 0 replies; 4+ messages in thread
From: Pablo Neira Ayuso @ 2020-03-29 15:58 UTC (permalink / raw)
To: wenxu; +Cc: netfilter-devel
On Sat, Mar 28, 2020 at 08:57:54AM +0800, wenxu@ucloud.cn wrote:
> From: wenxu <wenxu@ucloud.cn>
>
> Store the conntrack counters to the conntrack entry in the
> HW flowtable offload.
Applied.
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2020-03-29 15:58 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-03-28 0:57 [PATCH 1/2] netfilter: conntrack: add nf_ct_acct_add() wenxu
2020-03-28 0:57 ` [PATCH 2/2] netfilter: flowtable: add counter support in HW offload wenxu
2020-03-29 15:58 ` Pablo Neira Ayuso
2020-03-29 15:58 ` [PATCH 1/2] netfilter: conntrack: add nf_ct_acct_add() Pablo Neira Ayuso
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).