1 From: Pablo Neira Ayuso <pablo@netfilter.org>
2 Date: Tue, 23 Jan 2018 17:46:09 +0100
3 Subject: [PATCH] netfilter: nft_flow_offload: move flowtable cleanup
4 routines to nf_flow_table
6 Move the flowtable cleanup routines to nf_flow_table and expose the
7 nf_flow_table_cleanup() helper function.
9 Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
12 --- a/include/net/netfilter/nf_flow_table.h
13 +++ b/include/net/netfilter/nf_flow_table.h
14 @@ -95,6 +95,9 @@ struct flow_offload_tuple_rhash *flow_of
15 int nf_flow_table_iterate(struct nf_flowtable *flow_table,
16 void (*iter)(struct flow_offload *flow, void *data),
19 +void nf_flow_table_cleanup(struct net *net, struct net_device *dev);
21 void nf_flow_offload_work_gc(struct work_struct *work);
22 extern const struct rhashtable_params nf_flow_offload_rhash_params;
24 --- a/net/netfilter/nf_flow_table.c
25 +++ b/net/netfilter/nf_flow_table.c
27 #include <linux/netfilter.h>
28 #include <linux/rhashtable.h>
29 #include <linux/netdevice.h>
30 +#include <net/netfilter/nf_tables.h>
31 #include <net/netfilter/nf_flow_table.h>
32 #include <net/netfilter/nf_conntrack.h>
33 #include <net/netfilter/nf_conntrack_core.h>
34 @@ -425,5 +426,28 @@ int nf_flow_dnat_port(const struct flow_
36 EXPORT_SYMBOL_GPL(nf_flow_dnat_port);
38 +static void nf_flow_table_do_cleanup(struct flow_offload *flow, void *data)
40 + struct net_device *dev = data;
42 + if (dev && flow->tuplehash[0].tuple.iifidx != dev->ifindex)
45 + flow_offload_dead(flow);
48 +static void nf_flow_table_iterate_cleanup(struct nf_flowtable *flowtable,
51 + nf_flow_table_iterate(flowtable, nf_flow_table_do_cleanup, data);
52 + flush_delayed_work(&flowtable->gc_work);
55 +void nf_flow_table_cleanup(struct net *net, struct net_device *dev)
57 + nft_flow_table_iterate(net, nf_flow_table_iterate_cleanup, dev);
59 +EXPORT_SYMBOL_GPL(nf_flow_table_cleanup);
61 MODULE_LICENSE("GPL");
62 MODULE_AUTHOR("Pablo Neira Ayuso <pablo@netfilter.org>");
63 --- a/net/netfilter/nft_flow_offload.c
64 +++ b/net/netfilter/nft_flow_offload.c
65 @@ -194,23 +194,6 @@ static struct nft_expr_type nft_flow_off
69 -static void flow_offload_iterate_cleanup(struct flow_offload *flow, void *data)
71 - struct net_device *dev = data;
73 - if (dev && flow->tuplehash[0].tuple.iifidx != dev->ifindex)
76 - flow_offload_dead(flow);
79 -static void nft_flow_offload_iterate_cleanup(struct nf_flowtable *flowtable,
82 - nf_flow_table_iterate(flowtable, flow_offload_iterate_cleanup, data);
83 - flush_delayed_work(&flowtable->gc_work);
86 static int flow_offload_netdev_event(struct notifier_block *this,
87 unsigned long event, void *ptr)
89 @@ -219,7 +202,7 @@ static int flow_offload_netdev_event(str
90 if (event != NETDEV_DOWN)
93 - nft_flow_table_iterate(dev_net(dev), nft_flow_offload_iterate_cleanup, dev);
94 + nf_flow_table_cleanup(dev_net(dev), dev);