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