netfilter: flowtable: purge entries immediately when destroying the flowtable
Subsystems (2)
Pablo Neira Ayuso
maintainerPATCH v3 1/1 netfilter: flowtable: purge entries immediately when destroying the flowtable
Do not use hardware offload workqueue to purge the remaining flow entries when the flowtable is being destroyed. Instead, iterate over the flowtable to purge the remaining flow offload entries. Work memory allocations can fail, leaving us with either waiting indefinitely until work can be allocated or leaving entries in the hardware.
Fixes c921ffe85333 ("netfilter: flowtable: Fix flushing of offloaded flows on free")
Signed-off-by Pablo Neira Ayuso <[email protected]>
---
v3: - do not call flow_offload_del() from free_and_destroy(), release flow instead.
- skip reply direction free_and_destroy() free_fn callback.
- skip hardware release if NF_FLOW_HW_DEAD is set on.
include/net/netfilter/nf_flow_table.h | 3 ++- net/netfilter/nf_flow_table_core.c | 27 +++++++++++++++++++++++---- net/netfilter/nf_flow_table_offload.c | 23 +++++++++++++++-------- 3 files changed, 40 insertions(+), 13 deletions(-)
include/net/netfilter/nf_flow_table.h +2 -1
@@ -375,7 +375,8 @@ void nf_flow_offload_stats(struct nf_flowtable *flowtable, struct flow_offload *flow);void nf_flow_table_offload_flush (struct nf_flowtable *flowtable); -void nf_flow_table_offload_flush_cleanup (struct nf_flowtable *flowtable); +void nf_flow_table_offload_purge (struct nf_flowtable *flowtable, +struct flow_offload *flow); int nf_flow_table_offload_setup(struct nf_flowtable *flowtable, struct net_device *dev,
net/netfilter/nf_flow_table_core.c +23 -4
@@ -769,6 +769,27 @@ void nf_flow_table_cleanup(struct net_device *dev) }EXPORT_SYMBOL_GPL (nf_flow_table_cleanup); +static void nf_flow_table_do_purge (void *ptr,void *arg) +{ +struct flow_offload_tuple_rhash *tuplehash = ptr; +struct nf_flowtable *flow_table = arg; +struct flow_offload *flow; +int dir; + + dir = tuplehash->tuple.dir; +if (dir !=FLOW_OFFLOAD_DIR_ORIGINAL ) +return ; + + flow = container_of(tuplehash, struct flow_offload, tuplehash[dir]); +flow_offload_teardown (flow); + +if (nf_flowtable_hw_offload (flow_table) && + !test_bit (NF_FLOW_HW_DEAD , &flow->flags)) +nf_flow_table_offload_purge (flow_table, flow); + +flow_offload_free (flow); +} +void nf_flow_table_free (struct nf_flowtable *flow_table) {mutex_lock (&flowtable_lock);
@@ -778,10 +799,8 @@ void nf_flow_table_free(struct nf_flowtable *flow_table)cancel_delayed_work_sync (&flow_table->gc_work);nf_flow_table_offload_flush (flow_table);/* ... no more pending work after this stage ... */ -nf_flow_table_iterate (flow_table, nf_flow_table_do_cleanup,NULL ); -nf_flow_table_gc_run (flow_table); -nf_flow_table_offload_flush_cleanup (flow_table); -rhashtable_destroy (&flow_table->rhashtable); +rhashtable_free_and_destroy (&flow_table->rhashtable, + nf_flow_table_do_purge, flow_table); }EXPORT_SYMBOL_GPL (nf_flow_table_free);
net/netfilter/nf_flow_table_offload.c +15 -8
@@ -1175,14 +1175,6 @@ void nf_flow_offload_stats(struct nf_flowtable *flowtable,flow_offload_queue_work (offload); } -void nf_flow_table_offload_flush_cleanup (struct nf_flowtable *flowtable) -{ -if (nf_flowtable_hw_offload (flowtable)) { -flush_workqueue (nf_flow_offload_del_wq); -nf_flow_table_gc_run (flowtable); - } -} -void nf_flow_table_offload_flush (struct nf_flowtable *flowtable) {if (nf_flowtable_hw_offload (flowtable)) {
@@ -1192,6 +1184,21 @@ void nf_flow_table_offload_flush(struct nf_flowtable *flowtable) } } +void nf_flow_table_offload_purge (struct nf_flowtable *flowtable, +struct flow_offload *flow) +{ +struct flow_offload_work offload = { + .cmd =FLOW_CLS_DESTROY , + .flowtable = flowtable, + .flow = flow, + }; + +if (nf_flow_offload_unsupported (flow)) +return ; + +flow_offload_work_del (&offload); +} +static int nf_flow_table_block_setup (struct nf_flowtable *flowtable,struct flow_block_offload *bo,enum flow_block_command cmd)
Signature · 1 line
2.47.3