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