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