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