3de0201f95547e9184f05a34712848d4c5c88462
[openwrt/staging/ldir.git] / target / linux / generic / pending-6.1 / 700-netfilter-nft_flow_offload-handle-netdevice-events-f.patch
1 From: Pablo Neira Ayuso <pablo@netfilter.org>
2 Date: Thu, 25 Jan 2018 12:58:55 +0100
3 Subject: [PATCH] netfilter: nft_flow_offload: handle netdevice events from
4 nf_flow_table
5
6 Move the code that deals with device events to the core.
7
8 Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
9 ---
10
11 --- a/net/netfilter/nf_flow_table_core.c
12 +++ b/net/netfilter/nf_flow_table_core.c
13 @@ -608,28 +608,52 @@ void nf_flow_table_free(struct nf_flowta
14 .exit_batch = nf_flow_table_pernet_exit,
15 };
16
17 +static int nf_flow_table_netdev_event(struct notifier_block *this,
18 + unsigned long event, void *ptr)
19 +{
20 + struct net_device *dev = netdev_notifier_info_to_dev(ptr);
21 +
22 + if (event != NETDEV_DOWN)
23 + return NOTIFY_DONE;
24 +
25 + nf_flow_table_cleanup(dev);
26 +
27 + return NOTIFY_DONE;
28 +}
29 +
30 +static struct notifier_block flow_offload_netdev_notifier = {
31 + .notifier_call = nf_flow_table_netdev_event,
32 +};
33 +
34 static int __init nf_flow_table_module_init(void)
35 {
36 int ret;
37
38 ret = register_pernet_subsys(&nf_flow_table_net_ops);
39 if (ret < 0)
40 return ret;
41
42 ret = nf_flow_table_offload_init();
43 if (ret)
44 goto out_offload;
45 +
46 + ret = register_netdevice_notifier(&flow_offload_netdev_notifier);
47 + if (ret)
48 + goto out_offload_init;
49
50 return 0;
51
52 +out_offload_init:
53 + nf_flow_table_offload_exit();
54 out_offload:
55 unregister_pernet_subsys(&nf_flow_table_net_ops);
56 return ret;
57 }
58
59 static void __exit nf_flow_table_module_exit(void)
60 {
61 + unregister_netdevice_notifier(&flow_offload_netdev_notifier);
62 nf_flow_table_offload_exit();
63 unregister_pernet_subsys(&nf_flow_table_net_ops);
64 }
65
66 --- a/net/netfilter/nft_flow_offload.c
67 +++ b/net/netfilter/nft_flow_offload.c
68 @@ -444,47 +444,14 @@ static struct nft_expr_type nft_flow_off
69 .owner = THIS_MODULE,
70 };
71
72 -static int flow_offload_netdev_event(struct notifier_block *this,
73 - unsigned long event, void *ptr)
74 -{
75 - struct net_device *dev = netdev_notifier_info_to_dev(ptr);
76 -
77 - if (event != NETDEV_DOWN)
78 - return NOTIFY_DONE;
79 -
80 - nf_flow_table_cleanup(dev);
81 -
82 - return NOTIFY_DONE;
83 -}
84 -
85 -static struct notifier_block flow_offload_netdev_notifier = {
86 - .notifier_call = flow_offload_netdev_event,
87 -};
88 -
89 static int __init nft_flow_offload_module_init(void)
90 {
91 - int err;
92 -
93 - err = register_netdevice_notifier(&flow_offload_netdev_notifier);
94 - if (err)
95 - goto err;
96 -
97 - err = nft_register_expr(&nft_flow_offload_type);
98 - if (err < 0)
99 - goto register_expr;
100 -
101 - return 0;
102 -
103 -register_expr:
104 - unregister_netdevice_notifier(&flow_offload_netdev_notifier);
105 -err:
106 - return err;
107 + return nft_register_expr(&nft_flow_offload_type);
108 }
109
110 static void __exit nft_flow_offload_module_exit(void)
111 {
112 nft_unregister_expr(&nft_flow_offload_type);
113 - unregister_netdevice_notifier(&flow_offload_netdev_notifier);
114 }
115
116 module_init(nft_flow_offload_module_init);