netfilter: ipv6: avoid nf_iterate recursion
[deliverable/linux.git] / net / netfilter / nf_conntrack_standalone.c
CommitLineData
9fb9cbb1
YK
1/* (C) 1999-2001 Paul `Rusty' Russell
2 * (C) 2002-2004 Netfilter Core Team <coreteam@netfilter.org>
f229f6ce 3 * (C) 2005-2012 Patrick McHardy <kaber@trash.net>
9fb9cbb1
YK
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 2 as
7 * published by the Free Software Foundation.
9fb9cbb1
YK
8 */
9
9fb9cbb1
YK
10#include <linux/types.h>
11#include <linux/netfilter.h>
5a0e3ad6 12#include <linux/slab.h>
9fb9cbb1
YK
13#include <linux/module.h>
14#include <linux/skbuff.h>
15#include <linux/proc_fs.h>
16#include <linux/seq_file.h>
17#include <linux/percpu.h>
18#include <linux/netdevice.h>
1ae4de0c 19#include <linux/security.h>
457c4cbc 20#include <net/net_namespace.h>
9fb9cbb1
YK
21#ifdef CONFIG_SYSCTL
22#include <linux/sysctl.h>
23#endif
24
9fb9cbb1 25#include <net/netfilter/nf_conntrack.h>
f6180121 26#include <net/netfilter/nf_conntrack_core.h>
9fb9cbb1 27#include <net/netfilter/nf_conntrack_l3proto.h>
605dcad6 28#include <net/netfilter/nf_conntrack_l4proto.h>
77ab9cff 29#include <net/netfilter/nf_conntrack_expect.h>
9fb9cbb1 30#include <net/netfilter/nf_conntrack_helper.h>
58401572 31#include <net/netfilter/nf_conntrack_acct.h>
5d0aa2cc 32#include <net/netfilter/nf_conntrack_zones.h>
a992ca2a 33#include <net/netfilter/nf_conntrack_timestamp.h>
0e60ebe0 34#include <linux/rculist_nulls.h>
9fb9cbb1 35
9fb9cbb1
YK
36MODULE_LICENSE("GPL");
37
54b07dca 38#ifdef CONFIG_NF_CONNTRACK_PROCFS
824f1fbe 39void
9fb9cbb1 40print_tuple(struct seq_file *s, const struct nf_conntrack_tuple *tuple,
32948588
JE
41 const struct nf_conntrack_l3proto *l3proto,
42 const struct nf_conntrack_l4proto *l4proto)
9fb9cbb1 43{
824f1fbe
JP
44 l3proto->print_tuple(s, tuple);
45 l4proto->print_tuple(s, tuple);
9fb9cbb1 46}
e4bd8bce 47EXPORT_SYMBOL_GPL(print_tuple);
9fb9cbb1 48
9fb9cbb1 49struct ct_iter_state {
b2ce2c74 50 struct seq_net_private p;
9fb9cbb1 51 unsigned int bucket;
a992ca2a 52 u_int64_t time_now;
9fb9cbb1
YK
53};
54
ea781f19 55static struct hlist_nulls_node *ct_get_first(struct seq_file *seq)
9fb9cbb1 56{
b2ce2c74 57 struct net *net = seq_file_net(seq);
9fb9cbb1 58 struct ct_iter_state *st = seq->private;
ea781f19 59 struct hlist_nulls_node *n;
9fb9cbb1
YK
60
61 for (st->bucket = 0;
d696c7bd 62 st->bucket < net->ct.htable_size;
9fb9cbb1 63 st->bucket++) {
0e60ebe0 64 n = rcu_dereference(hlist_nulls_first_rcu(&net->ct.hash[st->bucket]));
ea781f19 65 if (!is_a_nulls(n))
76507f69 66 return n;
9fb9cbb1
YK
67 }
68 return NULL;
69}
70
ea781f19
ED
71static struct hlist_nulls_node *ct_get_next(struct seq_file *seq,
72 struct hlist_nulls_node *head)
9fb9cbb1 73{
b2ce2c74 74 struct net *net = seq_file_net(seq);
9fb9cbb1
YK
75 struct ct_iter_state *st = seq->private;
76
0e60ebe0 77 head = rcu_dereference(hlist_nulls_next_rcu(head));
ea781f19
ED
78 while (is_a_nulls(head)) {
79 if (likely(get_nulls_value(head) == st->bucket)) {
d696c7bd 80 if (++st->bucket >= net->ct.htable_size)
ea781f19
ED
81 return NULL;
82 }
0e60ebe0
ED
83 head = rcu_dereference(
84 hlist_nulls_first_rcu(
85 &net->ct.hash[st->bucket]));
9fb9cbb1
YK
86 }
87 return head;
88}
89
ea781f19 90static struct hlist_nulls_node *ct_get_idx(struct seq_file *seq, loff_t pos)
9fb9cbb1 91{
ea781f19 92 struct hlist_nulls_node *head = ct_get_first(seq);
9fb9cbb1
YK
93
94 if (head)
95 while (pos && (head = ct_get_next(seq, head)))
96 pos--;
97 return pos ? NULL : head;
98}
99
100static void *ct_seq_start(struct seq_file *seq, loff_t *pos)
76507f69 101 __acquires(RCU)
9fb9cbb1 102{
a992ca2a
PNA
103 struct ct_iter_state *st = seq->private;
104
d2de875c 105 st->time_now = ktime_get_real_ns();
76507f69 106 rcu_read_lock();
9fb9cbb1
YK
107 return ct_get_idx(seq, *pos);
108}
109
110static void *ct_seq_next(struct seq_file *s, void *v, loff_t *pos)
111{
112 (*pos)++;
113 return ct_get_next(s, v);
114}
115
116static void ct_seq_stop(struct seq_file *s, void *v)
76507f69 117 __releases(RCU)
9fb9cbb1 118{
76507f69 119 rcu_read_unlock();
9fb9cbb1
YK
120}
121
1ae4de0c 122#ifdef CONFIG_NF_CONNTRACK_SECMARK
e71456ae 123static void ct_show_secctx(struct seq_file *s, const struct nf_conn *ct)
1ae4de0c
EP
124{
125 int ret;
126 u32 len;
127 char *secctx;
128
129 ret = security_secid_to_secctx(ct->secmark, &secctx, &len);
130 if (ret)
e71456ae 131 return;
1ae4de0c 132
e71456ae 133 seq_printf(s, "secctx=%s ", secctx);
1ae4de0c
EP
134
135 security_release_secctx(secctx, len);
1ae4de0c
EP
136}
137#else
e71456ae 138static inline void ct_show_secctx(struct seq_file *s, const struct nf_conn *ct)
1ae4de0c 139{
1ae4de0c
EP
140}
141#endif
142
308ac914 143#ifdef CONFIG_NF_CONNTRACK_ZONES
deedb590
DB
144static void ct_show_zone(struct seq_file *s, const struct nf_conn *ct,
145 int dir)
308ac914 146{
deedb590
DB
147 const struct nf_conntrack_zone *zone = nf_ct_zone(ct);
148
149 if (zone->dir != dir)
150 return;
151 switch (zone->dir) {
152 case NF_CT_DEFAULT_ZONE_DIR:
153 seq_printf(s, "zone=%u ", zone->id);
154 break;
155 case NF_CT_ZONE_DIR_ORIG:
156 seq_printf(s, "zone-orig=%u ", zone->id);
157 break;
158 case NF_CT_ZONE_DIR_REPL:
159 seq_printf(s, "zone-reply=%u ", zone->id);
160 break;
161 default:
162 break;
163 }
308ac914
DB
164}
165#else
deedb590
DB
166static inline void ct_show_zone(struct seq_file *s, const struct nf_conn *ct,
167 int dir)
308ac914
DB
168{
169}
170#endif
171
a992ca2a 172#ifdef CONFIG_NF_CONNTRACK_TIMESTAMP
e71456ae 173static void ct_show_delta_time(struct seq_file *s, const struct nf_conn *ct)
a992ca2a 174{
f5c88f56 175 struct ct_iter_state *st = s->private;
a992ca2a 176 struct nf_conn_tstamp *tstamp;
f5c88f56 177 s64 delta_time;
a992ca2a
PNA
178
179 tstamp = nf_conn_tstamp_find(ct);
180 if (tstamp) {
f5c88f56
PM
181 delta_time = st->time_now - tstamp->start;
182 if (delta_time > 0)
183 delta_time = div_s64(delta_time, NSEC_PER_SEC);
184 else
185 delta_time = 0;
186
e71456ae
SRRH
187 seq_printf(s, "delta-time=%llu ",
188 (unsigned long long)delta_time);
a992ca2a 189 }
e71456ae 190 return;
a992ca2a
PNA
191}
192#else
e71456ae 193static inline void
a992ca2a
PNA
194ct_show_delta_time(struct seq_file *s, const struct nf_conn *ct)
195{
a992ca2a
PNA
196}
197#endif
198
9fb9cbb1
YK
199/* return 0 on success, 1 in case of error */
200static int ct_seq_show(struct seq_file *s, void *v)
201{
ea781f19
ED
202 struct nf_conntrack_tuple_hash *hash = v;
203 struct nf_conn *ct = nf_ct_tuplehash_to_ctrack(hash);
32948588
JE
204 const struct nf_conntrack_l3proto *l3proto;
205 const struct nf_conntrack_l4proto *l4proto;
ea781f19 206 int ret = 0;
9fb9cbb1 207
c88130bc 208 NF_CT_ASSERT(ct);
ea781f19
ED
209 if (unlikely(!atomic_inc_not_zero(&ct->ct_general.use)))
210 return 0;
9fb9cbb1
YK
211
212 /* we only want to print DIR_ORIGINAL */
213 if (NF_CT_DIRECTION(hash))
ea781f19 214 goto release;
9fb9cbb1 215
5e8fbe2a 216 l3proto = __nf_ct_l3proto_find(nf_ct_l3num(ct));
9fb9cbb1 217 NF_CT_ASSERT(l3proto);
5e8fbe2a 218 l4proto = __nf_ct_l4proto_find(nf_ct_l3num(ct), nf_ct_protonum(ct));
605dcad6 219 NF_CT_ASSERT(l4proto);
9fb9cbb1 220
ea781f19 221 ret = -ENOSPC;
e71456ae
SRRH
222 seq_printf(s, "%-8s %u %-8s %u %ld ",
223 l3proto->name, nf_ct_l3num(ct),
224 l4proto->name, nf_ct_protonum(ct),
225 timer_pending(&ct->timeout)
226 ? (long)(ct->timeout.expires - jiffies)/HZ : 0);
9fb9cbb1 227
37246a58
SRRH
228 if (l4proto->print_conntrack)
229 l4proto->print_conntrack(s, ct);
9fb9cbb1 230
824f1fbe
JP
231 print_tuple(s, &ct->tuplehash[IP_CT_DIR_ORIGINAL].tuple,
232 l3proto, l4proto);
9fb9cbb1 233
deedb590
DB
234 ct_show_zone(s, ct, NF_CT_ZONE_DIR_ORIG);
235
e71456ae
SRRH
236 if (seq_has_overflowed(s))
237 goto release;
238
58401572 239 if (seq_print_acct(s, ct, IP_CT_DIR_ORIGINAL))
ea781f19 240 goto release;
9fb9cbb1 241
c88130bc 242 if (!(test_bit(IPS_SEEN_REPLY_BIT, &ct->status)))
e71456ae 243 seq_printf(s, "[UNREPLIED] ");
9fb9cbb1 244
824f1fbe
JP
245 print_tuple(s, &ct->tuplehash[IP_CT_DIR_REPLY].tuple,
246 l3proto, l4proto);
9fb9cbb1 247
deedb590
DB
248 ct_show_zone(s, ct, NF_CT_ZONE_DIR_REPL);
249
58401572 250 if (seq_print_acct(s, ct, IP_CT_DIR_REPLY))
ea781f19 251 goto release;
9fb9cbb1 252
c88130bc 253 if (test_bit(IPS_ASSURED_BIT, &ct->status))
e71456ae 254 seq_printf(s, "[ASSURED] ");
9fb9cbb1 255
e71456ae 256 if (seq_has_overflowed(s))
ea781f19 257 goto release;
e71456ae
SRRH
258
259#if defined(CONFIG_NF_CONNTRACK_MARK)
260 seq_printf(s, "mark=%u ", ct->mark);
9fb9cbb1
YK
261#endif
262
e71456ae 263 ct_show_secctx(s, ct);
deedb590 264 ct_show_zone(s, ct, NF_CT_DEFAULT_ZONE_DIR);
e71456ae
SRRH
265 ct_show_delta_time(s, ct);
266
267 seq_printf(s, "use=%u\n", atomic_read(&ct->ct_general.use));
a992ca2a 268
e71456ae 269 if (seq_has_overflowed(s))
ea781f19 270 goto release;
a5d29264 271
ea781f19
ED
272 ret = 0;
273release:
274 nf_ct_put(ct);
d88d7de0 275 return ret;
9fb9cbb1
YK
276}
277
56b3d975 278static const struct seq_operations ct_seq_ops = {
9fb9cbb1
YK
279 .start = ct_seq_start,
280 .next = ct_seq_next,
281 .stop = ct_seq_stop,
282 .show = ct_seq_show
283};
284
285static int ct_open(struct inode *inode, struct file *file)
286{
b2ce2c74 287 return seq_open_net(inode, file, &ct_seq_ops,
e2da5913 288 sizeof(struct ct_iter_state));
9fb9cbb1
YK
289}
290
da7071d7 291static const struct file_operations ct_file_ops = {
9fb9cbb1
YK
292 .owner = THIS_MODULE,
293 .open = ct_open,
294 .read = seq_read,
295 .llseek = seq_lseek,
b2ce2c74 296 .release = seq_release_net,
9fb9cbb1
YK
297};
298
9fb9cbb1
YK
299static void *ct_cpu_seq_start(struct seq_file *seq, loff_t *pos)
300{
8e9df801 301 struct net *net = seq_file_net(seq);
9fb9cbb1
YK
302 int cpu;
303
304 if (*pos == 0)
305 return SEQ_START_TOKEN;
306
0f23174a 307 for (cpu = *pos-1; cpu < nr_cpu_ids; ++cpu) {
9fb9cbb1
YK
308 if (!cpu_possible(cpu))
309 continue;
310 *pos = cpu + 1;
8e9df801 311 return per_cpu_ptr(net->ct.stat, cpu);
9fb9cbb1
YK
312 }
313
314 return NULL;
315}
316
317static void *ct_cpu_seq_next(struct seq_file *seq, void *v, loff_t *pos)
318{
8e9df801 319 struct net *net = seq_file_net(seq);
9fb9cbb1
YK
320 int cpu;
321
0f23174a 322 for (cpu = *pos; cpu < nr_cpu_ids; ++cpu) {
9fb9cbb1
YK
323 if (!cpu_possible(cpu))
324 continue;
325 *pos = cpu + 1;
8e9df801 326 return per_cpu_ptr(net->ct.stat, cpu);
9fb9cbb1
YK
327 }
328
329 return NULL;
330}
331
332static void ct_cpu_seq_stop(struct seq_file *seq, void *v)
333{
334}
335
336static int ct_cpu_seq_show(struct seq_file *seq, void *v)
337{
8e9df801
AD
338 struct net *net = seq_file_net(seq);
339 unsigned int nr_conntracks = atomic_read(&net->ct.count);
32948588 340 const struct ip_conntrack_stat *st = v;
9fb9cbb1
YK
341
342 if (v == SEQ_START_TOKEN) {
af740b2c 343 seq_printf(seq, "entries searched found new invalid ignore delete delete_list insert insert_failed drop early_drop icmp_error expect_new expect_create expect_delete search_restart\n");
9fb9cbb1
YK
344 return 0;
345 }
346
347 seq_printf(seq, "%08x %08x %08x %08x %08x %08x %08x %08x "
af740b2c 348 "%08x %08x %08x %08x %08x %08x %08x %08x %08x\n",
9fb9cbb1
YK
349 nr_conntracks,
350 st->searched,
351 st->found,
352 st->new,
353 st->invalid,
354 st->ignore,
355 st->delete,
356 st->delete_list,
357 st->insert,
358 st->insert_failed,
359 st->drop,
360 st->early_drop,
361 st->error,
362
363 st->expect_new,
364 st->expect_create,
af740b2c
JDB
365 st->expect_delete,
366 st->search_restart
9fb9cbb1
YK
367 );
368 return 0;
369}
370
56b3d975 371static const struct seq_operations ct_cpu_seq_ops = {
9fb9cbb1
YK
372 .start = ct_cpu_seq_start,
373 .next = ct_cpu_seq_next,
374 .stop = ct_cpu_seq_stop,
375 .show = ct_cpu_seq_show,
376};
377
378static int ct_cpu_seq_open(struct inode *inode, struct file *file)
379{
8e9df801
AD
380 return seq_open_net(inode, file, &ct_cpu_seq_ops,
381 sizeof(struct seq_net_private));
9fb9cbb1
YK
382}
383
da7071d7 384static const struct file_operations ct_cpu_seq_fops = {
9fb9cbb1
YK
385 .owner = THIS_MODULE,
386 .open = ct_cpu_seq_open,
387 .read = seq_read,
388 .llseek = seq_lseek,
8e9df801 389 .release = seq_release_net,
9fb9cbb1 390};
b916f7d4 391
b2ce2c74 392static int nf_conntrack_standalone_init_proc(struct net *net)
b916f7d4
AD
393{
394 struct proc_dir_entry *pde;
395
d4beaa66 396 pde = proc_create("nf_conntrack", 0440, net->proc_net, &ct_file_ops);
b916f7d4
AD
397 if (!pde)
398 goto out_nf_conntrack;
52c0e111 399
b2ce2c74 400 pde = proc_create("nf_conntrack", S_IRUGO, net->proc_net_stat,
52c0e111 401 &ct_cpu_seq_fops);
b916f7d4
AD
402 if (!pde)
403 goto out_stat_nf_conntrack;
b916f7d4
AD
404 return 0;
405
406out_stat_nf_conntrack:
ece31ffd 407 remove_proc_entry("nf_conntrack", net->proc_net);
b916f7d4
AD
408out_nf_conntrack:
409 return -ENOMEM;
410}
411
b2ce2c74 412static void nf_conntrack_standalone_fini_proc(struct net *net)
b916f7d4 413{
b2ce2c74 414 remove_proc_entry("nf_conntrack", net->proc_net_stat);
ece31ffd 415 remove_proc_entry("nf_conntrack", net->proc_net);
b916f7d4
AD
416}
417#else
b2ce2c74 418static int nf_conntrack_standalone_init_proc(struct net *net)
b916f7d4
AD
419{
420 return 0;
421}
422
b2ce2c74 423static void nf_conntrack_standalone_fini_proc(struct net *net)
b916f7d4
AD
424{
425}
54b07dca 426#endif /* CONFIG_NF_CONNTRACK_PROCFS */
9fb9cbb1
YK
427
428/* Sysctl support */
429
430#ifdef CONFIG_SYSCTL
9fb9cbb1
YK
431/* Log invalid packets of a given protocol */
432static int log_invalid_proto_min = 0;
433static int log_invalid_proto_max = 255;
434
9714be7d 435static struct ctl_table_header *nf_ct_netfilter_header;
9fb9cbb1 436
fe2c6338 437static struct ctl_table nf_ct_sysctl_table[] = {
9fb9cbb1 438 {
9fb9cbb1
YK
439 .procname = "nf_conntrack_max",
440 .data = &nf_conntrack_max,
441 .maxlen = sizeof(int),
442 .mode = 0644,
6d9f239a 443 .proc_handler = proc_dointvec,
9fb9cbb1
YK
444 },
445 {
9fb9cbb1 446 .procname = "nf_conntrack_count",
49ac8713 447 .data = &init_net.ct.count,
9fb9cbb1
YK
448 .maxlen = sizeof(int),
449 .mode = 0444,
6d9f239a 450 .proc_handler = proc_dointvec,
9fb9cbb1
YK
451 },
452 {
9fb9cbb1 453 .procname = "nf_conntrack_buckets",
d696c7bd 454 .data = &init_net.ct.htable_size,
9fb9cbb1
YK
455 .maxlen = sizeof(unsigned int),
456 .mode = 0444,
6d9f239a 457 .proc_handler = proc_dointvec,
9fb9cbb1 458 },
39a27a35 459 {
39a27a35 460 .procname = "nf_conntrack_checksum",
c04d0552 461 .data = &init_net.ct.sysctl_checksum,
39a27a35
PM
462 .maxlen = sizeof(unsigned int),
463 .mode = 0644,
6d9f239a 464 .proc_handler = proc_dointvec,
39a27a35 465 },
9fb9cbb1 466 {
9fb9cbb1 467 .procname = "nf_conntrack_log_invalid",
c2a2c7e0 468 .data = &init_net.ct.sysctl_log_invalid,
9fb9cbb1
YK
469 .maxlen = sizeof(unsigned int),
470 .mode = 0644,
6d9f239a 471 .proc_handler = proc_dointvec_minmax,
9fb9cbb1
YK
472 .extra1 = &log_invalid_proto_min,
473 .extra2 = &log_invalid_proto_max,
474 },
f264a7df 475 {
f264a7df
PM
476 .procname = "nf_conntrack_expect_max",
477 .data = &nf_ct_expect_max,
478 .maxlen = sizeof(int),
479 .mode = 0644,
6d9f239a 480 .proc_handler = proc_dointvec,
f264a7df 481 },
f8572d8f 482 { }
9fb9cbb1
YK
483};
484
485#define NET_NF_CONNTRACK_MAX 2089
486
fe2c6338 487static struct ctl_table nf_ct_netfilter_table[] = {
9fb9cbb1 488 {
9fb9cbb1
YK
489 .procname = "nf_conntrack_max",
490 .data = &nf_conntrack_max,
491 .maxlen = sizeof(int),
492 .mode = 0644,
6d9f239a 493 .proc_handler = proc_dointvec,
9fb9cbb1 494 },
f8572d8f 495 { }
9fb9cbb1
YK
496};
497
80250707 498static int nf_conntrack_standalone_init_sysctl(struct net *net)
b916f7d4 499{
80250707
AD
500 struct ctl_table *table;
501
80250707
AD
502 table = kmemdup(nf_ct_sysctl_table, sizeof(nf_ct_sysctl_table),
503 GFP_KERNEL);
504 if (!table)
505 goto out_kmemdup;
506
507 table[1].data = &net->ct.count;
d696c7bd 508 table[2].data = &net->ct.htable_size;
c04d0552 509 table[3].data = &net->ct.sysctl_checksum;
c2a2c7e0 510 table[4].data = &net->ct.sysctl_log_invalid;
80250707 511
464dc801
EB
512 /* Don't export sysctls to unprivileged users */
513 if (net->user_ns != &init_user_ns)
514 table[0].procname = NULL;
515
ec8f23ce 516 net->ct.sysctl_header = register_net_sysctl(net, "net/netfilter", table);
80250707 517 if (!net->ct.sysctl_header)
9714be7d
KPO
518 goto out_unregister_netfilter;
519
b916f7d4
AD
520 return 0;
521
9714be7d 522out_unregister_netfilter:
80250707
AD
523 kfree(table);
524out_kmemdup:
9714be7d 525 return -ENOMEM;
b916f7d4
AD
526}
527
80250707 528static void nf_conntrack_standalone_fini_sysctl(struct net *net)
b916f7d4 529{
80250707
AD
530 struct ctl_table *table;
531
80250707
AD
532 table = net->ct.sysctl_header->ctl_table_arg;
533 unregister_net_sysctl_table(net->ct.sysctl_header);
534 kfree(table);
b916f7d4
AD
535}
536#else
80250707 537static int nf_conntrack_standalone_init_sysctl(struct net *net)
b916f7d4
AD
538{
539 return 0;
540}
541
80250707 542static void nf_conntrack_standalone_fini_sysctl(struct net *net)
b916f7d4
AD
543{
544}
9fb9cbb1
YK
545#endif /* CONFIG_SYSCTL */
546
f94161c1 547static int nf_conntrack_pernet_init(struct net *net)
dfdb8d79 548{
b2ce2c74
AD
549 int ret;
550
f94161c1 551 ret = nf_conntrack_init_net(net);
b2ce2c74
AD
552 if (ret < 0)
553 goto out_init;
f94161c1 554
b2ce2c74
AD
555 ret = nf_conntrack_standalone_init_proc(net);
556 if (ret < 0)
557 goto out_proc;
f94161c1 558
c04d0552 559 net->ct.sysctl_checksum = 1;
c2a2c7e0 560 net->ct.sysctl_log_invalid = 0;
80250707
AD
561 ret = nf_conntrack_standalone_init_sysctl(net);
562 if (ret < 0)
563 goto out_sysctl;
f94161c1 564
b2ce2c74
AD
565 return 0;
566
80250707
AD
567out_sysctl:
568 nf_conntrack_standalone_fini_proc(net);
b2ce2c74 569out_proc:
f94161c1 570 nf_conntrack_cleanup_net(net);
b2ce2c74
AD
571out_init:
572 return ret;
dfdb8d79
AD
573}
574
dece40e8 575static void nf_conntrack_pernet_exit(struct list_head *net_exit_list)
dfdb8d79 576{
dece40e8
VD
577 struct net *net;
578
579 list_for_each_entry(net, net_exit_list, exit_list) {
580 nf_conntrack_standalone_fini_sysctl(net);
581 nf_conntrack_standalone_fini_proc(net);
582 }
583 nf_conntrack_cleanup_net_list(net_exit_list);
dfdb8d79
AD
584}
585
586static struct pernet_operations nf_conntrack_net_ops = {
dece40e8
VD
587 .init = nf_conntrack_pernet_init,
588 .exit_batch = nf_conntrack_pernet_exit,
dfdb8d79
AD
589};
590
65b4b4e8 591static int __init nf_conntrack_standalone_init(void)
9fb9cbb1 592{
f94161c1
G
593 int ret = nf_conntrack_init_start();
594 if (ret < 0)
595 goto out_start;
596
5f9f946b 597#ifdef CONFIG_SYSCTL
f94161c1
G
598 nf_ct_netfilter_header =
599 register_net_sysctl(&init_net, "net", nf_ct_netfilter_table);
5f9f946b
PNA
600 if (!nf_ct_netfilter_header) {
601 pr_err("nf_conntrack: can't register to sysctl.\n");
5389090b 602 ret = -ENOMEM;
f94161c1 603 goto out_sysctl;
5f9f946b
PNA
604 }
605#endif
f94161c1
G
606
607 ret = register_pernet_subsys(&nf_conntrack_net_ops);
608 if (ret < 0)
609 goto out_pernet;
610
611 nf_conntrack_init_end();
612 return 0;
613
614out_pernet:
5f9f946b 615#ifdef CONFIG_SYSCTL
f94161c1
G
616 unregister_net_sysctl_table(nf_ct_netfilter_header);
617out_sysctl:
5f9f946b 618#endif
f94161c1
G
619 nf_conntrack_cleanup_end();
620out_start:
621 return ret;
9fb9cbb1
YK
622}
623
65b4b4e8 624static void __exit nf_conntrack_standalone_fini(void)
9fb9cbb1 625{
f94161c1 626 nf_conntrack_cleanup_start();
dfdb8d79 627 unregister_pernet_subsys(&nf_conntrack_net_ops);
5f9f946b 628#ifdef CONFIG_SYSCTL
f94161c1 629 unregister_net_sysctl_table(nf_ct_netfilter_header);
5f9f946b 630#endif
1e47ee83 631 nf_conntrack_cleanup_end();
9fb9cbb1
YK
632}
633
65b4b4e8
AM
634module_init(nf_conntrack_standalone_init);
635module_exit(nf_conntrack_standalone_fini);
9fb9cbb1
YK
636
637/* Some modules need us, but don't depend directly on any symbol.
638 They should call this. */
2e4e6a17 639void need_conntrack(void)
9fb9cbb1
YK
640{
641}
13b18339 642EXPORT_SYMBOL_GPL(need_conntrack);
This page took 0.845645 seconds and 5 git commands to generate.