diff mbox series

[net-next,3/6] netfilter: flowtable: add cleanup callback from garbage collector

Message ID 1582458307-17067-4-git-send-email-paulb@mellanox.com
State Changes Requested
Delegated to: David Miller
Headers show
Series None | expand

Commit Message

Paul Blakey Feb. 23, 2020, 11:45 a.m. UTC
From: Pablo Neira Ayuso <pablo@netfilter.org>

This new cleanup callback is called whenever garbage collector counts
no entries in the flowtable. This patch is useful for the act_tc
infrastructure which releases the flowtable if it gets empty.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
Signed-off-by: Paul Blakey <paulb@mellanox.com>
---
 include/net/netfilter/nf_flow_table.h | 1 +
 net/netfilter/nf_flow_table_core.c    | 8 +++++++-
 2 files changed, 8 insertions(+), 1 deletion(-)
diff mbox series

Patch

diff --git a/include/net/netfilter/nf_flow_table.h b/include/net/netfilter/nf_flow_table.h
index e0f709d9..ba65cf0 100644
--- a/include/net/netfilter/nf_flow_table.h
+++ b/include/net/netfilter/nf_flow_table.h
@@ -27,6 +27,7 @@  struct nf_flowtable_type {
 						  const struct flow_offload *flow,
 						  enum flow_offload_tuple_dir dir,
 						  struct nf_flow_rule *flow_rule);
+	int				(*cleanup)(struct nf_flowtable *ft);
 	void				(*free)(struct nf_flowtable *ft);
 	nf_hookfn			*hook;
 	struct module			*owner;
diff --git a/net/netfilter/nf_flow_table_core.c b/net/netfilter/nf_flow_table_core.c
index 83bc456..e209bbe 100644
--- a/net/netfilter/nf_flow_table_core.c
+++ b/net/netfilter/nf_flow_table_core.c
@@ -367,9 +367,15 @@  static void nf_flow_offload_gc_step(struct nf_flowtable *flow_table,
 static void nf_flow_offload_work_gc(struct work_struct *work)
 {
 	struct nf_flowtable *flow_table;
+	int err, cnt;
 
 	flow_table = container_of(work, struct nf_flowtable, gc_work.work);
-	nf_flow_table_iterate(flow_table, nf_flow_offload_gc_step, NULL);
+	cnt = nf_flow_table_iterate(flow_table, nf_flow_offload_gc_step, NULL);
+	if (cnt == 0 && flow_table->type->cleanup) {
+		err = flow_table->type->cleanup(flow_table);
+		if (!err)
+			return;
+	}
 	queue_delayed_work(system_power_efficient_wq, &flow_table->gc_work, HZ);
 }