kernel: backport netfilter NAT offload support to 4.14
[openwrt/openwrt.git] / target / linux / generic / backport-4.14 / 336-netfilter-exit_net-cleanup-check-added.patch
1 From: Vasily Averin <vvs@virtuozzo.com>
2 Date: Sun, 12 Nov 2017 14:32:37 +0300
3 Subject: [PATCH] netfilter: exit_net cleanup check added
4
5 Be sure that lists initialized in net_init hook was return to initial
6 state.
7
8 Signed-off-by: Vasily Averin <vvs@virtuozzo.com>
9 Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
10 ---
11
12 --- a/net/ipv4/netfilter/ipt_CLUSTERIP.c
13 +++ b/net/ipv4/netfilter/ipt_CLUSTERIP.c
14 @@ -819,6 +819,7 @@ static void clusterip_net_exit(struct ne
15 cn->procdir = NULL;
16 #endif
17 nf_unregister_net_hook(net, &cip_arp_ops);
18 + WARN_ON_ONCE(!list_empty(&cn->configs));
19 }
20
21 static struct pernet_operations clusterip_net_ops = {
22 --- a/net/netfilter/nf_tables_api.c
23 +++ b/net/netfilter/nf_tables_api.c
24 @@ -6468,6 +6468,12 @@ static int __net_init nf_tables_init_net
25 return 0;
26 }
27
28 +static void __net_exit nf_tables_exit_net(struct net *net)
29 +{
30 + WARN_ON_ONCE(!list_empty(&net->nft.af_info));
31 + WARN_ON_ONCE(!list_empty(&net->nft.commit_list));
32 +}
33 +
34 int __nft_release_basechain(struct nft_ctx *ctx)
35 {
36 struct nft_rule *rule, *nr;
37 @@ -6545,6 +6551,7 @@ static void __nft_release_afinfo(struct
38
39 static struct pernet_operations nf_tables_net_ops = {
40 .init = nf_tables_init_net,
41 + .exit = nf_tables_exit_net,
42 };
43
44 static int __init nf_tables_module_init(void)
45 --- a/net/netfilter/nfnetlink_log.c
46 +++ b/net/netfilter/nfnetlink_log.c
47 @@ -1093,10 +1093,15 @@ static int __net_init nfnl_log_net_init(
48
49 static void __net_exit nfnl_log_net_exit(struct net *net)
50 {
51 + struct nfnl_log_net *log = nfnl_log_pernet(net);
52 + unsigned int i;
53 +
54 #ifdef CONFIG_PROC_FS
55 remove_proc_entry("nfnetlink_log", net->nf.proc_netfilter);
56 #endif
57 nf_log_unset(net, &nfulnl_logger);
58 + for (i = 0; i < INSTANCE_BUCKETS; i++)
59 + WARN_ON_ONCE(!hlist_empty(&log->instance_table[i]));
60 }
61
62 static struct pernet_operations nfnl_log_net_ops = {
63 --- a/net/netfilter/nfnetlink_queue.c
64 +++ b/net/netfilter/nfnetlink_queue.c
65 @@ -1512,10 +1512,15 @@ static int __net_init nfnl_queue_net_ini
66
67 static void __net_exit nfnl_queue_net_exit(struct net *net)
68 {
69 + struct nfnl_queue_net *q = nfnl_queue_pernet(net);
70 + unsigned int i;
71 +
72 nf_unregister_queue_handler(net);
73 #ifdef CONFIG_PROC_FS
74 remove_proc_entry("nfnetlink_queue", net->nf.proc_netfilter);
75 #endif
76 + for (i = 0; i < INSTANCE_BUCKETS; i++)
77 + WARN_ON_ONCE(!hlist_empty(&q->instance_table[i]));
78 }
79
80 static void nfnl_queue_net_exit_batch(struct list_head *net_exit_list)
81 --- a/net/netfilter/x_tables.c
82 +++ b/net/netfilter/x_tables.c
83 @@ -1714,8 +1714,17 @@ static int __net_init xt_net_init(struct
84 return 0;
85 }
86
87 +static void __net_exit xt_net_exit(struct net *net)
88 +{
89 + int i;
90 +
91 + for (i = 0; i < NFPROTO_NUMPROTO; i++)
92 + WARN_ON_ONCE(!list_empty(&net->xt.tables[i]));
93 +}
94 +
95 static struct pernet_operations xt_net_ops = {
96 .init = xt_net_init,
97 + .exit = xt_net_exit,
98 };
99
100 static int __init xt_init(void)