tcp: correctly crypto_alloc_hash return check
[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;
f13f2aee
PW
395 kuid_t root_uid;
396 kgid_t root_gid;
b916f7d4 397
d4beaa66 398 pde = proc_create("nf_conntrack", 0440, net->proc_net, &ct_file_ops);
b916f7d4
AD
399 if (!pde)
400 goto out_nf_conntrack;
52c0e111 401
f13f2aee
PW
402 root_uid = make_kuid(net->user_ns, 0);
403 root_gid = make_kgid(net->user_ns, 0);
404 if (uid_valid(root_uid) && gid_valid(root_gid))
405 proc_set_user(pde, root_uid, root_gid);
406
b2ce2c74 407 pde = proc_create("nf_conntrack", S_IRUGO, net->proc_net_stat,
52c0e111 408 &ct_cpu_seq_fops);
b916f7d4
AD
409 if (!pde)
410 goto out_stat_nf_conntrack;
b916f7d4
AD
411 return 0;
412
413out_stat_nf_conntrack:
ece31ffd 414 remove_proc_entry("nf_conntrack", net->proc_net);
b916f7d4
AD
415out_nf_conntrack:
416 return -ENOMEM;
417}
418
b2ce2c74 419static void nf_conntrack_standalone_fini_proc(struct net *net)
b916f7d4 420{
b2ce2c74 421 remove_proc_entry("nf_conntrack", net->proc_net_stat);
ece31ffd 422 remove_proc_entry("nf_conntrack", net->proc_net);
b916f7d4
AD
423}
424#else
b2ce2c74 425static int nf_conntrack_standalone_init_proc(struct net *net)
b916f7d4
AD
426{
427 return 0;
428}
429
b2ce2c74 430static void nf_conntrack_standalone_fini_proc(struct net *net)
b916f7d4
AD
431{
432}
54b07dca 433#endif /* CONFIG_NF_CONNTRACK_PROCFS */
9fb9cbb1
YK
434
435/* Sysctl support */
436
437#ifdef CONFIG_SYSCTL
9fb9cbb1
YK
438/* Log invalid packets of a given protocol */
439static int log_invalid_proto_min = 0;
440static int log_invalid_proto_max = 255;
441
9714be7d 442static struct ctl_table_header *nf_ct_netfilter_header;
9fb9cbb1 443
fe2c6338 444static struct ctl_table nf_ct_sysctl_table[] = {
9fb9cbb1 445 {
9fb9cbb1
YK
446 .procname = "nf_conntrack_max",
447 .data = &nf_conntrack_max,
448 .maxlen = sizeof(int),
449 .mode = 0644,
6d9f239a 450 .proc_handler = proc_dointvec,
9fb9cbb1
YK
451 },
452 {
9fb9cbb1 453 .procname = "nf_conntrack_count",
49ac8713 454 .data = &init_net.ct.count,
9fb9cbb1
YK
455 .maxlen = sizeof(int),
456 .mode = 0444,
6d9f239a 457 .proc_handler = proc_dointvec,
9fb9cbb1
YK
458 },
459 {
9fb9cbb1 460 .procname = "nf_conntrack_buckets",
d696c7bd 461 .data = &init_net.ct.htable_size,
9fb9cbb1
YK
462 .maxlen = sizeof(unsigned int),
463 .mode = 0444,
6d9f239a 464 .proc_handler = proc_dointvec,
9fb9cbb1 465 },
39a27a35 466 {
39a27a35 467 .procname = "nf_conntrack_checksum",
c04d0552 468 .data = &init_net.ct.sysctl_checksum,
39a27a35
PM
469 .maxlen = sizeof(unsigned int),
470 .mode = 0644,
6d9f239a 471 .proc_handler = proc_dointvec,
39a27a35 472 },
9fb9cbb1 473 {
9fb9cbb1 474 .procname = "nf_conntrack_log_invalid",
c2a2c7e0 475 .data = &init_net.ct.sysctl_log_invalid,
9fb9cbb1
YK
476 .maxlen = sizeof(unsigned int),
477 .mode = 0644,
6d9f239a 478 .proc_handler = proc_dointvec_minmax,
9fb9cbb1
YK
479 .extra1 = &log_invalid_proto_min,
480 .extra2 = &log_invalid_proto_max,
481 },
f264a7df 482 {
f264a7df
PM
483 .procname = "nf_conntrack_expect_max",
484 .data = &nf_ct_expect_max,
485 .maxlen = sizeof(int),
486 .mode = 0644,
6d9f239a 487 .proc_handler = proc_dointvec,
f264a7df 488 },
f8572d8f 489 { }
9fb9cbb1
YK
490};
491
492#define NET_NF_CONNTRACK_MAX 2089
493
fe2c6338 494static struct ctl_table nf_ct_netfilter_table[] = {
9fb9cbb1 495 {
9fb9cbb1
YK
496 .procname = "nf_conntrack_max",
497 .data = &nf_conntrack_max,
498 .maxlen = sizeof(int),
499 .mode = 0644,
6d9f239a 500 .proc_handler = proc_dointvec,
9fb9cbb1 501 },
f8572d8f 502 { }
9fb9cbb1
YK
503};
504
80250707 505static int nf_conntrack_standalone_init_sysctl(struct net *net)
b916f7d4 506{
80250707
AD
507 struct ctl_table *table;
508
80250707
AD
509 table = kmemdup(nf_ct_sysctl_table, sizeof(nf_ct_sysctl_table),
510 GFP_KERNEL);
511 if (!table)
512 goto out_kmemdup;
513
514 table[1].data = &net->ct.count;
d696c7bd 515 table[2].data = &net->ct.htable_size;
c04d0552 516 table[3].data = &net->ct.sysctl_checksum;
c2a2c7e0 517 table[4].data = &net->ct.sysctl_log_invalid;
80250707 518
464dc801
EB
519 /* Don't export sysctls to unprivileged users */
520 if (net->user_ns != &init_user_ns)
521 table[0].procname = NULL;
522
ec8f23ce 523 net->ct.sysctl_header = register_net_sysctl(net, "net/netfilter", table);
80250707 524 if (!net->ct.sysctl_header)
9714be7d
KPO
525 goto out_unregister_netfilter;
526
b916f7d4
AD
527 return 0;
528
9714be7d 529out_unregister_netfilter:
80250707
AD
530 kfree(table);
531out_kmemdup:
9714be7d 532 return -ENOMEM;
b916f7d4
AD
533}
534
80250707 535static void nf_conntrack_standalone_fini_sysctl(struct net *net)
b916f7d4 536{
80250707
AD
537 struct ctl_table *table;
538
80250707
AD
539 table = net->ct.sysctl_header->ctl_table_arg;
540 unregister_net_sysctl_table(net->ct.sysctl_header);
541 kfree(table);
b916f7d4
AD
542}
543#else
80250707 544static int nf_conntrack_standalone_init_sysctl(struct net *net)
b916f7d4
AD
545{
546 return 0;
547}
548
80250707 549static void nf_conntrack_standalone_fini_sysctl(struct net *net)
b916f7d4
AD
550{
551}
9fb9cbb1
YK
552#endif /* CONFIG_SYSCTL */
553
f94161c1 554static int nf_conntrack_pernet_init(struct net *net)
dfdb8d79 555{
b2ce2c74
AD
556 int ret;
557
f94161c1 558 ret = nf_conntrack_init_net(net);
b2ce2c74
AD
559 if (ret < 0)
560 goto out_init;
f94161c1 561
b2ce2c74
AD
562 ret = nf_conntrack_standalone_init_proc(net);
563 if (ret < 0)
564 goto out_proc;
f94161c1 565
c04d0552 566 net->ct.sysctl_checksum = 1;
c2a2c7e0 567 net->ct.sysctl_log_invalid = 0;
80250707
AD
568 ret = nf_conntrack_standalone_init_sysctl(net);
569 if (ret < 0)
570 goto out_sysctl;
f94161c1 571
b2ce2c74
AD
572 return 0;
573
80250707
AD
574out_sysctl:
575 nf_conntrack_standalone_fini_proc(net);
b2ce2c74 576out_proc:
f94161c1 577 nf_conntrack_cleanup_net(net);
b2ce2c74
AD
578out_init:
579 return ret;
dfdb8d79
AD
580}
581
dece40e8 582static void nf_conntrack_pernet_exit(struct list_head *net_exit_list)
dfdb8d79 583{
dece40e8
VD
584 struct net *net;
585
586 list_for_each_entry(net, net_exit_list, exit_list) {
587 nf_conntrack_standalone_fini_sysctl(net);
588 nf_conntrack_standalone_fini_proc(net);
589 }
590 nf_conntrack_cleanup_net_list(net_exit_list);
dfdb8d79
AD
591}
592
593static struct pernet_operations nf_conntrack_net_ops = {
dece40e8
VD
594 .init = nf_conntrack_pernet_init,
595 .exit_batch = nf_conntrack_pernet_exit,
dfdb8d79
AD
596};
597
65b4b4e8 598static int __init nf_conntrack_standalone_init(void)
9fb9cbb1 599{
f94161c1
G
600 int ret = nf_conntrack_init_start();
601 if (ret < 0)
602 goto out_start;
603
5f9f946b 604#ifdef CONFIG_SYSCTL
f94161c1
G
605 nf_ct_netfilter_header =
606 register_net_sysctl(&init_net, "net", nf_ct_netfilter_table);
5f9f946b
PNA
607 if (!nf_ct_netfilter_header) {
608 pr_err("nf_conntrack: can't register to sysctl.\n");
5389090b 609 ret = -ENOMEM;
f94161c1 610 goto out_sysctl;
5f9f946b
PNA
611 }
612#endif
f94161c1
G
613
614 ret = register_pernet_subsys(&nf_conntrack_net_ops);
615 if (ret < 0)
616 goto out_pernet;
617
618 nf_conntrack_init_end();
619 return 0;
620
621out_pernet:
5f9f946b 622#ifdef CONFIG_SYSCTL
f94161c1
G
623 unregister_net_sysctl_table(nf_ct_netfilter_header);
624out_sysctl:
5f9f946b 625#endif
f94161c1
G
626 nf_conntrack_cleanup_end();
627out_start:
628 return ret;
9fb9cbb1
YK
629}
630
65b4b4e8 631static void __exit nf_conntrack_standalone_fini(void)
9fb9cbb1 632{
f94161c1 633 nf_conntrack_cleanup_start();
dfdb8d79 634 unregister_pernet_subsys(&nf_conntrack_net_ops);
5f9f946b 635#ifdef CONFIG_SYSCTL
f94161c1 636 unregister_net_sysctl_table(nf_ct_netfilter_header);
5f9f946b 637#endif
1e47ee83 638 nf_conntrack_cleanup_end();
9fb9cbb1
YK
639}
640
65b4b4e8
AM
641module_init(nf_conntrack_standalone_init);
642module_exit(nf_conntrack_standalone_fini);
9fb9cbb1
YK
643
644/* Some modules need us, but don't depend directly on any symbol.
645 They should call this. */
2e4e6a17 646void need_conntrack(void)
9fb9cbb1
YK
647{
648}
13b18339 649EXPORT_SYMBOL_GPL(need_conntrack);
This page took 0.787911 seconds and 5 git commands to generate.