182a0cbc6a76b601a278833cf447b75d889045a4
[openwrt/staging/jow.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 @@ -659,6 +659,23 @@ static struct pernet_operations nf_flow_
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 @@ -671,8 +688,14 @@ static int __init nf_flow_table_module_i
38 if (ret)
39 goto out_offload;
40
41 + ret = register_netdevice_notifier(&flow_offload_netdev_notifier);
42 + if (ret)
43 + goto out_offload_init;
44 +
45 return 0;
46
47 +out_offload_init:
48 + nf_flow_table_offload_exit();
49 out_offload:
50 unregister_pernet_subsys(&nf_flow_table_net_ops);
51 return ret;
52 @@ -680,6 +703,7 @@ out_offload:
53
54 static void __exit nf_flow_table_module_exit(void)
55 {
56 + unregister_netdevice_notifier(&flow_offload_netdev_notifier);
57 nf_flow_table_offload_exit();
58 unregister_pernet_subsys(&nf_flow_table_net_ops);
59 }
60 --- a/net/netfilter/nft_flow_offload.c
61 +++ b/net/netfilter/nft_flow_offload.c
62 @@ -468,47 +468,14 @@ static struct nft_expr_type nft_flow_off
63 .owner = THIS_MODULE,
64 };
65
66 -static int flow_offload_netdev_event(struct notifier_block *this,
67 - unsigned long event, void *ptr)
68 -{
69 - struct net_device *dev = netdev_notifier_info_to_dev(ptr);
70 -
71 - if (event != NETDEV_DOWN)
72 - return NOTIFY_DONE;
73 -
74 - nf_flow_table_cleanup(dev);
75 -
76 - return NOTIFY_DONE;
77 -}
78 -
79 -static struct notifier_block flow_offload_netdev_notifier = {
80 - .notifier_call = flow_offload_netdev_event,
81 -};
82 -
83 static int __init nft_flow_offload_module_init(void)
84 {
85 - int err;
86 -
87 - err = register_netdevice_notifier(&flow_offload_netdev_notifier);
88 - if (err)
89 - goto err;
90 -
91 - err = nft_register_expr(&nft_flow_offload_type);
92 - if (err < 0)
93 - goto register_expr;
94 -
95 - return 0;
96 -
97 -register_expr:
98 - unregister_netdevice_notifier(&flow_offload_netdev_notifier);
99 -err:
100 - return err;
101 + return nft_register_expr(&nft_flow_offload_type);
102 }
103
104 static void __exit nft_flow_offload_module_exit(void)
105 {
106 nft_unregister_expr(&nft_flow_offload_type);
107 - unregister_netdevice_notifier(&flow_offload_netdev_notifier);
108 }
109
110 module_init(nft_flow_offload_module_init);