]>
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 | 143 | #ifdef CONFIG_NF_CONNTRACK_TIMESTAMP |
f5c88f56 | 144 | static 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 | |
164 | static inline int | |
165 | ct_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 */ |
172 | static 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; |
246 | release: | |
247 | nf_ct_put(ct); | |
9fb9cbb1 YK |
248 | return 0; |
249 | } | |
250 | ||
56b3d975 | 251 | static 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 | ||
258 | static 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 | 264 | static 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 |
272 | static 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 | ||
290 | static 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 | ||
305 | static void ct_cpu_seq_stop(struct seq_file *seq, void *v) | |
306 | { | |
307 | } | |
308 | ||
309 | static 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 | 344 | static 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 | ||
351 | static 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 | 357 | static 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 | 365 | static int nf_conntrack_standalone_init_proc(struct net *net) |
b916f7d4 AD |
366 | { |
367 | struct proc_dir_entry *pde; | |
368 | ||
b2ce2c74 | 369 | pde = proc_net_fops_create(net, "nf_conntrack", 0440, &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 | ||
379 | out_stat_nf_conntrack: | |
b2ce2c74 | 380 | proc_net_remove(net, "nf_conntrack"); |
b916f7d4 AD |
381 | out_nf_conntrack: |
382 | return -ENOMEM; | |
383 | } | |
384 | ||
b2ce2c74 | 385 | static 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 | 391 | static int nf_conntrack_standalone_init_proc(struct net *net) |
b916f7d4 AD |
392 | { |
393 | return 0; | |
394 | } | |
395 | ||
b2ce2c74 | 396 | static void nf_conntrack_standalone_fini_proc(struct net *net) |
b916f7d4 AD |
397 | { |
398 | } | |
9fb9cbb1 YK |
399 | #endif /* CONFIG_PROC_FS */ |
400 | ||
401 | /* Sysctl support */ | |
402 | ||
403 | #ifdef CONFIG_SYSCTL | |
9fb9cbb1 YK |
404 | /* Log invalid packets of a given protocol */ |
405 | static int log_invalid_proto_min = 0; | |
406 | static int log_invalid_proto_max = 255; | |
407 | ||
9714be7d | 408 | static struct ctl_table_header *nf_ct_netfilter_header; |
9fb9cbb1 YK |
409 | |
410 | static 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 | ||
460 | static 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 | ||
9e232495 | 471 | static struct ctl_path nf_ct_path[] = { |
f8572d8f | 472 | { .procname = "net", }, |
3d7cc2ba | 473 | { } |
9fb9cbb1 | 474 | }; |
3d7cc2ba | 475 | |
80250707 | 476 | static int nf_conntrack_standalone_init_sysctl(struct net *net) |
b916f7d4 | 477 | { |
80250707 AD |
478 | struct ctl_table *table; |
479 | ||
480 | if (net_eq(net, &init_net)) { | |
481 | nf_ct_netfilter_header = | |
482 | register_sysctl_paths(nf_ct_path, nf_ct_netfilter_table); | |
483 | if (!nf_ct_netfilter_header) | |
484 | goto out; | |
485 | } | |
486 | ||
487 | table = kmemdup(nf_ct_sysctl_table, sizeof(nf_ct_sysctl_table), | |
488 | GFP_KERNEL); | |
489 | if (!table) | |
490 | goto out_kmemdup; | |
491 | ||
492 | table[1].data = &net->ct.count; | |
d696c7bd | 493 | table[2].data = &net->ct.htable_size; |
c04d0552 | 494 | table[3].data = &net->ct.sysctl_checksum; |
c2a2c7e0 | 495 | table[4].data = &net->ct.sysctl_log_invalid; |
80250707 AD |
496 | |
497 | net->ct.sysctl_header = register_net_sysctl_table(net, | |
498 | nf_net_netfilter_sysctl_path, table); | |
499 | if (!net->ct.sysctl_header) | |
9714be7d KPO |
500 | goto out_unregister_netfilter; |
501 | ||
b916f7d4 AD |
502 | return 0; |
503 | ||
9714be7d | 504 | out_unregister_netfilter: |
80250707 AD |
505 | kfree(table); |
506 | out_kmemdup: | |
507 | if (net_eq(net, &init_net)) | |
508 | unregister_sysctl_table(nf_ct_netfilter_header); | |
9714be7d | 509 | out: |
654d0fbd | 510 | printk(KERN_ERR "nf_conntrack: can't register to sysctl.\n"); |
9714be7d | 511 | return -ENOMEM; |
b916f7d4 AD |
512 | } |
513 | ||
80250707 | 514 | static void nf_conntrack_standalone_fini_sysctl(struct net *net) |
b916f7d4 | 515 | { |
80250707 AD |
516 | struct ctl_table *table; |
517 | ||
518 | if (net_eq(net, &init_net)) | |
519 | unregister_sysctl_table(nf_ct_netfilter_header); | |
520 | table = net->ct.sysctl_header->ctl_table_arg; | |
521 | unregister_net_sysctl_table(net->ct.sysctl_header); | |
522 | kfree(table); | |
b916f7d4 AD |
523 | } |
524 | #else | |
80250707 | 525 | static int nf_conntrack_standalone_init_sysctl(struct net *net) |
b916f7d4 AD |
526 | { |
527 | return 0; | |
528 | } | |
529 | ||
80250707 | 530 | static void nf_conntrack_standalone_fini_sysctl(struct net *net) |
b916f7d4 AD |
531 | { |
532 | } | |
9fb9cbb1 YK |
533 | #endif /* CONFIG_SYSCTL */ |
534 | ||
dfdb8d79 AD |
535 | static int nf_conntrack_net_init(struct net *net) |
536 | { | |
b2ce2c74 AD |
537 | int ret; |
538 | ||
539 | ret = nf_conntrack_init(net); | |
540 | if (ret < 0) | |
541 | goto out_init; | |
542 | ret = nf_conntrack_standalone_init_proc(net); | |
543 | if (ret < 0) | |
544 | goto out_proc; | |
c04d0552 | 545 | net->ct.sysctl_checksum = 1; |
c2a2c7e0 | 546 | net->ct.sysctl_log_invalid = 0; |
80250707 AD |
547 | ret = nf_conntrack_standalone_init_sysctl(net); |
548 | if (ret < 0) | |
549 | goto out_sysctl; | |
b2ce2c74 AD |
550 | return 0; |
551 | ||
80250707 AD |
552 | out_sysctl: |
553 | nf_conntrack_standalone_fini_proc(net); | |
b2ce2c74 AD |
554 | out_proc: |
555 | nf_conntrack_cleanup(net); | |
556 | out_init: | |
557 | return ret; | |
dfdb8d79 AD |
558 | } |
559 | ||
560 | static void nf_conntrack_net_exit(struct net *net) | |
561 | { | |
80250707 | 562 | nf_conntrack_standalone_fini_sysctl(net); |
b2ce2c74 | 563 | nf_conntrack_standalone_fini_proc(net); |
dfdb8d79 AD |
564 | nf_conntrack_cleanup(net); |
565 | } | |
566 | ||
567 | static struct pernet_operations nf_conntrack_net_ops = { | |
568 | .init = nf_conntrack_net_init, | |
569 | .exit = nf_conntrack_net_exit, | |
570 | }; | |
571 | ||
65b4b4e8 | 572 | static int __init nf_conntrack_standalone_init(void) |
9fb9cbb1 | 573 | { |
80250707 | 574 | return register_pernet_subsys(&nf_conntrack_net_ops); |
9fb9cbb1 YK |
575 | } |
576 | ||
65b4b4e8 | 577 | static void __exit nf_conntrack_standalone_fini(void) |
9fb9cbb1 | 578 | { |
dfdb8d79 | 579 | unregister_pernet_subsys(&nf_conntrack_net_ops); |
9fb9cbb1 YK |
580 | } |
581 | ||
65b4b4e8 AM |
582 | module_init(nf_conntrack_standalone_init); |
583 | module_exit(nf_conntrack_standalone_fini); | |
9fb9cbb1 YK |
584 | |
585 | /* Some modules need us, but don't depend directly on any symbol. | |
586 | They should call this. */ | |
2e4e6a17 | 587 | void need_conntrack(void) |
9fb9cbb1 YK |
588 | { |
589 | } | |
13b18339 | 590 | EXPORT_SYMBOL_GPL(need_conntrack); |