7a9fa04a467a2b807c7fed4d16245fa7201dab04
[deliverable/linux.git] / net / ipv4 / netfilter / ip_conntrack_standalone.c
1 /* This file contains all the functions required for the standalone
2 ip_conntrack module.
3
4 These are not required by the compatibility layer.
5 */
6
7 /* (C) 1999-2001 Paul `Rusty' Russell
8 * (C) 2002-2005 Netfilter Core Team <coreteam@netfilter.org>
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License version 2 as
12 * published by the Free Software Foundation.
13 */
14
15 #include <linux/types.h>
16 #include <linux/ip.h>
17 #include <linux/netfilter.h>
18 #include <linux/netfilter_ipv4.h>
19 #include <linux/module.h>
20 #include <linux/skbuff.h>
21 #include <linux/proc_fs.h>
22 #include <linux/seq_file.h>
23 #include <linux/percpu.h>
24 #ifdef CONFIG_SYSCTL
25 #include <linux/sysctl.h>
26 #endif
27 #include <net/checksum.h>
28 #include <net/ip.h>
29 #include <net/route.h>
30
31 #define ASSERT_READ_LOCK(x)
32 #define ASSERT_WRITE_LOCK(x)
33
34 #include <linux/netfilter_ipv4/ip_conntrack.h>
35 #include <linux/netfilter_ipv4/ip_conntrack_protocol.h>
36 #include <linux/netfilter_ipv4/ip_conntrack_core.h>
37 #include <linux/netfilter_ipv4/ip_conntrack_helper.h>
38 #include <linux/netfilter_ipv4/listhelp.h>
39
40 #if 0
41 #define DEBUGP printk
42 #else
43 #define DEBUGP(format, args...)
44 #endif
45
46 MODULE_LICENSE("GPL");
47
48 extern atomic_t ip_conntrack_count;
49 DECLARE_PER_CPU(struct ip_conntrack_stat, ip_conntrack_stat);
50
51 static int kill_proto(struct ip_conntrack *i, void *data)
52 {
53 return (i->tuplehash[IP_CT_DIR_ORIGINAL].tuple.dst.protonum ==
54 *((u_int8_t *) data));
55 }
56
57 #ifdef CONFIG_PROC_FS
58 static int
59 print_tuple(struct seq_file *s, const struct ip_conntrack_tuple *tuple,
60 struct ip_conntrack_protocol *proto)
61 {
62 seq_printf(s, "src=%u.%u.%u.%u dst=%u.%u.%u.%u ",
63 NIPQUAD(tuple->src.ip), NIPQUAD(tuple->dst.ip));
64 return proto->print_tuple(s, tuple);
65 }
66
67 #ifdef CONFIG_IP_NF_CT_ACCT
68 static unsigned int
69 seq_print_counters(struct seq_file *s,
70 const struct ip_conntrack_counter *counter)
71 {
72 return seq_printf(s, "packets=%llu bytes=%llu ",
73 (unsigned long long)counter->packets,
74 (unsigned long long)counter->bytes);
75 }
76 #else
77 #define seq_print_counters(x, y) 0
78 #endif
79
80 struct ct_iter_state {
81 unsigned int bucket;
82 };
83
84 static struct list_head *ct_get_first(struct seq_file *seq)
85 {
86 struct ct_iter_state *st = seq->private;
87
88 for (st->bucket = 0;
89 st->bucket < ip_conntrack_htable_size;
90 st->bucket++) {
91 if (!list_empty(&ip_conntrack_hash[st->bucket]))
92 return ip_conntrack_hash[st->bucket].next;
93 }
94 return NULL;
95 }
96
97 static struct list_head *ct_get_next(struct seq_file *seq, struct list_head *head)
98 {
99 struct ct_iter_state *st = seq->private;
100
101 head = head->next;
102 while (head == &ip_conntrack_hash[st->bucket]) {
103 if (++st->bucket >= ip_conntrack_htable_size)
104 return NULL;
105 head = ip_conntrack_hash[st->bucket].next;
106 }
107 return head;
108 }
109
110 static struct list_head *ct_get_idx(struct seq_file *seq, loff_t pos)
111 {
112 struct list_head *head = ct_get_first(seq);
113
114 if (head)
115 while (pos && (head = ct_get_next(seq, head)))
116 pos--;
117 return pos ? NULL : head;
118 }
119
120 static void *ct_seq_start(struct seq_file *seq, loff_t *pos)
121 {
122 read_lock_bh(&ip_conntrack_lock);
123 return ct_get_idx(seq, *pos);
124 }
125
126 static void *ct_seq_next(struct seq_file *s, void *v, loff_t *pos)
127 {
128 (*pos)++;
129 return ct_get_next(s, v);
130 }
131
132 static void ct_seq_stop(struct seq_file *s, void *v)
133 {
134 read_unlock_bh(&ip_conntrack_lock);
135 }
136
137 static int ct_seq_show(struct seq_file *s, void *v)
138 {
139 const struct ip_conntrack_tuple_hash *hash = v;
140 const struct ip_conntrack *conntrack = tuplehash_to_ctrack(hash);
141 struct ip_conntrack_protocol *proto;
142
143 ASSERT_READ_LOCK(&ip_conntrack_lock);
144 IP_NF_ASSERT(conntrack);
145
146 /* we only want to print DIR_ORIGINAL */
147 if (DIRECTION(hash))
148 return 0;
149
150 proto = __ip_conntrack_proto_find(conntrack->tuplehash[IP_CT_DIR_ORIGINAL].tuple.dst.protonum);
151 IP_NF_ASSERT(proto);
152
153 if (seq_printf(s, "%-8s %u %ld ",
154 proto->name,
155 conntrack->tuplehash[IP_CT_DIR_ORIGINAL].tuple.dst.protonum,
156 timer_pending(&conntrack->timeout)
157 ? (long)(conntrack->timeout.expires - jiffies)/HZ
158 : 0) != 0)
159 return -ENOSPC;
160
161 if (proto->print_conntrack(s, conntrack))
162 return -ENOSPC;
163
164 if (print_tuple(s, &conntrack->tuplehash[IP_CT_DIR_ORIGINAL].tuple,
165 proto))
166 return -ENOSPC;
167
168 if (seq_print_counters(s, &conntrack->counters[IP_CT_DIR_ORIGINAL]))
169 return -ENOSPC;
170
171 if (!(test_bit(IPS_SEEN_REPLY_BIT, &conntrack->status)))
172 if (seq_printf(s, "[UNREPLIED] "))
173 return -ENOSPC;
174
175 if (print_tuple(s, &conntrack->tuplehash[IP_CT_DIR_REPLY].tuple,
176 proto))
177 return -ENOSPC;
178
179 if (seq_print_counters(s, &conntrack->counters[IP_CT_DIR_REPLY]))
180 return -ENOSPC;
181
182 if (test_bit(IPS_ASSURED_BIT, &conntrack->status))
183 if (seq_printf(s, "[ASSURED] "))
184 return -ENOSPC;
185
186 #if defined(CONFIG_IP_NF_CONNTRACK_MARK)
187 if (seq_printf(s, "mark=%u ", conntrack->mark))
188 return -ENOSPC;
189 #endif
190
191 #ifdef CONFIG_IP_NF_CONNTRACK_SECMARK
192 if (seq_printf(s, "secmark=%u ", conntrack->secmark))
193 return -ENOSPC;
194 #endif
195
196 if (seq_printf(s, "use=%u\n", atomic_read(&conntrack->ct_general.use)))
197 return -ENOSPC;
198
199 return 0;
200 }
201
202 static struct seq_operations ct_seq_ops = {
203 .start = ct_seq_start,
204 .next = ct_seq_next,
205 .stop = ct_seq_stop,
206 .show = ct_seq_show
207 };
208
209 static int ct_open(struct inode *inode, struct file *file)
210 {
211 struct seq_file *seq;
212 struct ct_iter_state *st;
213 int ret;
214
215 st = kmalloc(sizeof(struct ct_iter_state), GFP_KERNEL);
216 if (st == NULL)
217 return -ENOMEM;
218 ret = seq_open(file, &ct_seq_ops);
219 if (ret)
220 goto out_free;
221 seq = file->private_data;
222 seq->private = st;
223 memset(st, 0, sizeof(struct ct_iter_state));
224 return ret;
225 out_free:
226 kfree(st);
227 return ret;
228 }
229
230 static struct file_operations ct_file_ops = {
231 .owner = THIS_MODULE,
232 .open = ct_open,
233 .read = seq_read,
234 .llseek = seq_lseek,
235 .release = seq_release_private,
236 };
237
238 /* expects */
239 static void *exp_seq_start(struct seq_file *s, loff_t *pos)
240 {
241 struct list_head *e = &ip_conntrack_expect_list;
242 loff_t i;
243
244 /* strange seq_file api calls stop even if we fail,
245 * thus we need to grab lock since stop unlocks */
246 read_lock_bh(&ip_conntrack_lock);
247
248 if (list_empty(e))
249 return NULL;
250
251 for (i = 0; i <= *pos; i++) {
252 e = e->next;
253 if (e == &ip_conntrack_expect_list)
254 return NULL;
255 }
256 return e;
257 }
258
259 static void *exp_seq_next(struct seq_file *s, void *v, loff_t *pos)
260 {
261 struct list_head *e = v;
262
263 ++*pos;
264 e = e->next;
265
266 if (e == &ip_conntrack_expect_list)
267 return NULL;
268
269 return e;
270 }
271
272 static void exp_seq_stop(struct seq_file *s, void *v)
273 {
274 read_unlock_bh(&ip_conntrack_lock);
275 }
276
277 static int exp_seq_show(struct seq_file *s, void *v)
278 {
279 struct ip_conntrack_expect *expect = v;
280
281 if (expect->timeout.function)
282 seq_printf(s, "%ld ", timer_pending(&expect->timeout)
283 ? (long)(expect->timeout.expires - jiffies)/HZ : 0);
284 else
285 seq_printf(s, "- ");
286
287 seq_printf(s, "proto=%u ", expect->tuple.dst.protonum);
288
289 print_tuple(s, &expect->tuple,
290 __ip_conntrack_proto_find(expect->tuple.dst.protonum));
291 return seq_putc(s, '\n');
292 }
293
294 static struct seq_operations exp_seq_ops = {
295 .start = exp_seq_start,
296 .next = exp_seq_next,
297 .stop = exp_seq_stop,
298 .show = exp_seq_show
299 };
300
301 static int exp_open(struct inode *inode, struct file *file)
302 {
303 return seq_open(file, &exp_seq_ops);
304 }
305
306 static struct file_operations exp_file_ops = {
307 .owner = THIS_MODULE,
308 .open = exp_open,
309 .read = seq_read,
310 .llseek = seq_lseek,
311 .release = seq_release
312 };
313
314 static void *ct_cpu_seq_start(struct seq_file *seq, loff_t *pos)
315 {
316 int cpu;
317
318 if (*pos == 0)
319 return SEQ_START_TOKEN;
320
321 for (cpu = *pos-1; cpu < NR_CPUS; ++cpu) {
322 if (!cpu_possible(cpu))
323 continue;
324 *pos = cpu+1;
325 return &per_cpu(ip_conntrack_stat, cpu);
326 }
327
328 return NULL;
329 }
330
331 static void *ct_cpu_seq_next(struct seq_file *seq, void *v, loff_t *pos)
332 {
333 int cpu;
334
335 for (cpu = *pos; cpu < NR_CPUS; ++cpu) {
336 if (!cpu_possible(cpu))
337 continue;
338 *pos = cpu+1;
339 return &per_cpu(ip_conntrack_stat, cpu);
340 }
341
342 return NULL;
343 }
344
345 static void ct_cpu_seq_stop(struct seq_file *seq, void *v)
346 {
347 }
348
349 static int ct_cpu_seq_show(struct seq_file *seq, void *v)
350 {
351 unsigned int nr_conntracks = atomic_read(&ip_conntrack_count);
352 struct ip_conntrack_stat *st = v;
353
354 if (v == SEQ_START_TOKEN) {
355 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\n");
356 return 0;
357 }
358
359 seq_printf(seq, "%08x %08x %08x %08x %08x %08x %08x %08x "
360 "%08x %08x %08x %08x %08x %08x %08x %08x \n",
361 nr_conntracks,
362 st->searched,
363 st->found,
364 st->new,
365 st->invalid,
366 st->ignore,
367 st->delete,
368 st->delete_list,
369 st->insert,
370 st->insert_failed,
371 st->drop,
372 st->early_drop,
373 st->error,
374
375 st->expect_new,
376 st->expect_create,
377 st->expect_delete
378 );
379 return 0;
380 }
381
382 static struct seq_operations ct_cpu_seq_ops = {
383 .start = ct_cpu_seq_start,
384 .next = ct_cpu_seq_next,
385 .stop = ct_cpu_seq_stop,
386 .show = ct_cpu_seq_show,
387 };
388
389 static int ct_cpu_seq_open(struct inode *inode, struct file *file)
390 {
391 return seq_open(file, &ct_cpu_seq_ops);
392 }
393
394 static struct file_operations ct_cpu_seq_fops = {
395 .owner = THIS_MODULE,
396 .open = ct_cpu_seq_open,
397 .read = seq_read,
398 .llseek = seq_lseek,
399 .release = seq_release_private,
400 };
401 #endif
402
403 static unsigned int ip_confirm(unsigned int hooknum,
404 struct sk_buff **pskb,
405 const struct net_device *in,
406 const struct net_device *out,
407 int (*okfn)(struct sk_buff *))
408 {
409 /* We've seen it coming out the other side: confirm it */
410 return ip_conntrack_confirm(pskb);
411 }
412
413 static unsigned int ip_conntrack_help(unsigned int hooknum,
414 struct sk_buff **pskb,
415 const struct net_device *in,
416 const struct net_device *out,
417 int (*okfn)(struct sk_buff *))
418 {
419 struct ip_conntrack *ct;
420 enum ip_conntrack_info ctinfo;
421
422 /* This is where we call the helper: as the packet goes out. */
423 ct = ip_conntrack_get(*pskb, &ctinfo);
424 if (ct && ct->helper && ctinfo != IP_CT_RELATED + IP_CT_IS_REPLY) {
425 unsigned int ret;
426 ret = ct->helper->help(pskb, ct, ctinfo);
427 if (ret != NF_ACCEPT)
428 return ret;
429 }
430 return NF_ACCEPT;
431 }
432
433 static unsigned int ip_conntrack_defrag(unsigned int hooknum,
434 struct sk_buff **pskb,
435 const struct net_device *in,
436 const struct net_device *out,
437 int (*okfn)(struct sk_buff *))
438 {
439 #if !defined(CONFIG_IP_NF_NAT) && !defined(CONFIG_IP_NF_NAT_MODULE)
440 /* Previously seen (loopback)? Ignore. Do this before
441 fragment check. */
442 if ((*pskb)->nfct)
443 return NF_ACCEPT;
444 #endif
445
446 /* Gather fragments. */
447 if ((*pskb)->nh.iph->frag_off & htons(IP_MF|IP_OFFSET)) {
448 *pskb = ip_ct_gather_frags(*pskb,
449 hooknum == NF_IP_PRE_ROUTING ?
450 IP_DEFRAG_CONNTRACK_IN :
451 IP_DEFRAG_CONNTRACK_OUT);
452 if (!*pskb)
453 return NF_STOLEN;
454 }
455 return NF_ACCEPT;
456 }
457
458 static unsigned int ip_conntrack_local(unsigned int hooknum,
459 struct sk_buff **pskb,
460 const struct net_device *in,
461 const struct net_device *out,
462 int (*okfn)(struct sk_buff *))
463 {
464 /* root is playing with raw sockets. */
465 if ((*pskb)->len < sizeof(struct iphdr)
466 || (*pskb)->nh.iph->ihl * 4 < sizeof(struct iphdr)) {
467 if (net_ratelimit())
468 printk("ipt_hook: happy cracking.\n");
469 return NF_ACCEPT;
470 }
471 return ip_conntrack_in(hooknum, pskb, in, out, okfn);
472 }
473
474 /* Connection tracking may drop packets, but never alters them, so
475 make it the first hook. */
476 static struct nf_hook_ops ip_conntrack_ops[] = {
477 {
478 .hook = ip_conntrack_defrag,
479 .owner = THIS_MODULE,
480 .pf = PF_INET,
481 .hooknum = NF_IP_PRE_ROUTING,
482 .priority = NF_IP_PRI_CONNTRACK_DEFRAG,
483 },
484 {
485 .hook = ip_conntrack_in,
486 .owner = THIS_MODULE,
487 .pf = PF_INET,
488 .hooknum = NF_IP_PRE_ROUTING,
489 .priority = NF_IP_PRI_CONNTRACK,
490 },
491 {
492 .hook = ip_conntrack_defrag,
493 .owner = THIS_MODULE,
494 .pf = PF_INET,
495 .hooknum = NF_IP_LOCAL_OUT,
496 .priority = NF_IP_PRI_CONNTRACK_DEFRAG,
497 },
498 {
499 .hook = ip_conntrack_local,
500 .owner = THIS_MODULE,
501 .pf = PF_INET,
502 .hooknum = NF_IP_LOCAL_OUT,
503 .priority = NF_IP_PRI_CONNTRACK,
504 },
505 {
506 .hook = ip_conntrack_help,
507 .owner = THIS_MODULE,
508 .pf = PF_INET,
509 .hooknum = NF_IP_POST_ROUTING,
510 .priority = NF_IP_PRI_CONNTRACK_HELPER,
511 },
512 {
513 .hook = ip_conntrack_help,
514 .owner = THIS_MODULE,
515 .pf = PF_INET,
516 .hooknum = NF_IP_LOCAL_IN,
517 .priority = NF_IP_PRI_CONNTRACK_HELPER,
518 },
519 {
520 .hook = ip_confirm,
521 .owner = THIS_MODULE,
522 .pf = PF_INET,
523 .hooknum = NF_IP_POST_ROUTING,
524 .priority = NF_IP_PRI_CONNTRACK_CONFIRM,
525 },
526 {
527 .hook = ip_confirm,
528 .owner = THIS_MODULE,
529 .pf = PF_INET,
530 .hooknum = NF_IP_LOCAL_IN,
531 .priority = NF_IP_PRI_CONNTRACK_CONFIRM,
532 },
533 };
534
535 /* Sysctl support */
536
537 int ip_conntrack_checksum = 1;
538
539 #ifdef CONFIG_SYSCTL
540
541 /* From ip_conntrack_core.c */
542 extern int ip_conntrack_max;
543 extern unsigned int ip_conntrack_htable_size;
544
545 /* From ip_conntrack_proto_tcp.c */
546 extern unsigned int ip_ct_tcp_timeout_syn_sent;
547 extern unsigned int ip_ct_tcp_timeout_syn_recv;
548 extern unsigned int ip_ct_tcp_timeout_established;
549 extern unsigned int ip_ct_tcp_timeout_fin_wait;
550 extern unsigned int ip_ct_tcp_timeout_close_wait;
551 extern unsigned int ip_ct_tcp_timeout_last_ack;
552 extern unsigned int ip_ct_tcp_timeout_time_wait;
553 extern unsigned int ip_ct_tcp_timeout_close;
554 extern unsigned int ip_ct_tcp_timeout_max_retrans;
555 extern int ip_ct_tcp_loose;
556 extern int ip_ct_tcp_be_liberal;
557 extern int ip_ct_tcp_max_retrans;
558
559 /* From ip_conntrack_proto_udp.c */
560 extern unsigned int ip_ct_udp_timeout;
561 extern unsigned int ip_ct_udp_timeout_stream;
562
563 /* From ip_conntrack_proto_icmp.c */
564 extern unsigned int ip_ct_icmp_timeout;
565
566 /* From ip_conntrack_proto_icmp.c */
567 extern unsigned int ip_ct_generic_timeout;
568
569 /* Log invalid packets of a given protocol */
570 static int log_invalid_proto_min = 0;
571 static int log_invalid_proto_max = 255;
572
573 static struct ctl_table_header *ip_ct_sysctl_header;
574
575 static ctl_table ip_ct_sysctl_table[] = {
576 {
577 .ctl_name = NET_IPV4_NF_CONNTRACK_MAX,
578 .procname = "ip_conntrack_max",
579 .data = &ip_conntrack_max,
580 .maxlen = sizeof(int),
581 .mode = 0644,
582 .proc_handler = &proc_dointvec,
583 },
584 {
585 .ctl_name = NET_IPV4_NF_CONNTRACK_COUNT,
586 .procname = "ip_conntrack_count",
587 .data = &ip_conntrack_count,
588 .maxlen = sizeof(int),
589 .mode = 0444,
590 .proc_handler = &proc_dointvec,
591 },
592 {
593 .ctl_name = NET_IPV4_NF_CONNTRACK_BUCKETS,
594 .procname = "ip_conntrack_buckets",
595 .data = &ip_conntrack_htable_size,
596 .maxlen = sizeof(unsigned int),
597 .mode = 0444,
598 .proc_handler = &proc_dointvec,
599 },
600 {
601 .ctl_name = NET_IPV4_NF_CONNTRACK_CHECKSUM,
602 .procname = "ip_conntrack_checksum",
603 .data = &ip_conntrack_checksum,
604 .maxlen = sizeof(int),
605 .mode = 0644,
606 .proc_handler = &proc_dointvec,
607 },
608 {
609 .ctl_name = NET_IPV4_NF_CONNTRACK_TCP_TIMEOUT_SYN_SENT,
610 .procname = "ip_conntrack_tcp_timeout_syn_sent",
611 .data = &ip_ct_tcp_timeout_syn_sent,
612 .maxlen = sizeof(unsigned int),
613 .mode = 0644,
614 .proc_handler = &proc_dointvec_jiffies,
615 },
616 {
617 .ctl_name = NET_IPV4_NF_CONNTRACK_TCP_TIMEOUT_SYN_RECV,
618 .procname = "ip_conntrack_tcp_timeout_syn_recv",
619 .data = &ip_ct_tcp_timeout_syn_recv,
620 .maxlen = sizeof(unsigned int),
621 .mode = 0644,
622 .proc_handler = &proc_dointvec_jiffies,
623 },
624 {
625 .ctl_name = NET_IPV4_NF_CONNTRACK_TCP_TIMEOUT_ESTABLISHED,
626 .procname = "ip_conntrack_tcp_timeout_established",
627 .data = &ip_ct_tcp_timeout_established,
628 .maxlen = sizeof(unsigned int),
629 .mode = 0644,
630 .proc_handler = &proc_dointvec_jiffies,
631 },
632 {
633 .ctl_name = NET_IPV4_NF_CONNTRACK_TCP_TIMEOUT_FIN_WAIT,
634 .procname = "ip_conntrack_tcp_timeout_fin_wait",
635 .data = &ip_ct_tcp_timeout_fin_wait,
636 .maxlen = sizeof(unsigned int),
637 .mode = 0644,
638 .proc_handler = &proc_dointvec_jiffies,
639 },
640 {
641 .ctl_name = NET_IPV4_NF_CONNTRACK_TCP_TIMEOUT_CLOSE_WAIT,
642 .procname = "ip_conntrack_tcp_timeout_close_wait",
643 .data = &ip_ct_tcp_timeout_close_wait,
644 .maxlen = sizeof(unsigned int),
645 .mode = 0644,
646 .proc_handler = &proc_dointvec_jiffies,
647 },
648 {
649 .ctl_name = NET_IPV4_NF_CONNTRACK_TCP_TIMEOUT_LAST_ACK,
650 .procname = "ip_conntrack_tcp_timeout_last_ack",
651 .data = &ip_ct_tcp_timeout_last_ack,
652 .maxlen = sizeof(unsigned int),
653 .mode = 0644,
654 .proc_handler = &proc_dointvec_jiffies,
655 },
656 {
657 .ctl_name = NET_IPV4_NF_CONNTRACK_TCP_TIMEOUT_TIME_WAIT,
658 .procname = "ip_conntrack_tcp_timeout_time_wait",
659 .data = &ip_ct_tcp_timeout_time_wait,
660 .maxlen = sizeof(unsigned int),
661 .mode = 0644,
662 .proc_handler = &proc_dointvec_jiffies,
663 },
664 {
665 .ctl_name = NET_IPV4_NF_CONNTRACK_TCP_TIMEOUT_CLOSE,
666 .procname = "ip_conntrack_tcp_timeout_close",
667 .data = &ip_ct_tcp_timeout_close,
668 .maxlen = sizeof(unsigned int),
669 .mode = 0644,
670 .proc_handler = &proc_dointvec_jiffies,
671 },
672 {
673 .ctl_name = NET_IPV4_NF_CONNTRACK_UDP_TIMEOUT,
674 .procname = "ip_conntrack_udp_timeout",
675 .data = &ip_ct_udp_timeout,
676 .maxlen = sizeof(unsigned int),
677 .mode = 0644,
678 .proc_handler = &proc_dointvec_jiffies,
679 },
680 {
681 .ctl_name = NET_IPV4_NF_CONNTRACK_UDP_TIMEOUT_STREAM,
682 .procname = "ip_conntrack_udp_timeout_stream",
683 .data = &ip_ct_udp_timeout_stream,
684 .maxlen = sizeof(unsigned int),
685 .mode = 0644,
686 .proc_handler = &proc_dointvec_jiffies,
687 },
688 {
689 .ctl_name = NET_IPV4_NF_CONNTRACK_ICMP_TIMEOUT,
690 .procname = "ip_conntrack_icmp_timeout",
691 .data = &ip_ct_icmp_timeout,
692 .maxlen = sizeof(unsigned int),
693 .mode = 0644,
694 .proc_handler = &proc_dointvec_jiffies,
695 },
696 {
697 .ctl_name = NET_IPV4_NF_CONNTRACK_GENERIC_TIMEOUT,
698 .procname = "ip_conntrack_generic_timeout",
699 .data = &ip_ct_generic_timeout,
700 .maxlen = sizeof(unsigned int),
701 .mode = 0644,
702 .proc_handler = &proc_dointvec_jiffies,
703 },
704 {
705 .ctl_name = NET_IPV4_NF_CONNTRACK_LOG_INVALID,
706 .procname = "ip_conntrack_log_invalid",
707 .data = &ip_ct_log_invalid,
708 .maxlen = sizeof(unsigned int),
709 .mode = 0644,
710 .proc_handler = &proc_dointvec_minmax,
711 .strategy = &sysctl_intvec,
712 .extra1 = &log_invalid_proto_min,
713 .extra2 = &log_invalid_proto_max,
714 },
715 {
716 .ctl_name = NET_IPV4_NF_CONNTRACK_TCP_TIMEOUT_MAX_RETRANS,
717 .procname = "ip_conntrack_tcp_timeout_max_retrans",
718 .data = &ip_ct_tcp_timeout_max_retrans,
719 .maxlen = sizeof(unsigned int),
720 .mode = 0644,
721 .proc_handler = &proc_dointvec_jiffies,
722 },
723 {
724 .ctl_name = NET_IPV4_NF_CONNTRACK_TCP_LOOSE,
725 .procname = "ip_conntrack_tcp_loose",
726 .data = &ip_ct_tcp_loose,
727 .maxlen = sizeof(unsigned int),
728 .mode = 0644,
729 .proc_handler = &proc_dointvec,
730 },
731 {
732 .ctl_name = NET_IPV4_NF_CONNTRACK_TCP_BE_LIBERAL,
733 .procname = "ip_conntrack_tcp_be_liberal",
734 .data = &ip_ct_tcp_be_liberal,
735 .maxlen = sizeof(unsigned int),
736 .mode = 0644,
737 .proc_handler = &proc_dointvec,
738 },
739 {
740 .ctl_name = NET_IPV4_NF_CONNTRACK_TCP_MAX_RETRANS,
741 .procname = "ip_conntrack_tcp_max_retrans",
742 .data = &ip_ct_tcp_max_retrans,
743 .maxlen = sizeof(unsigned int),
744 .mode = 0644,
745 .proc_handler = &proc_dointvec,
746 },
747 { .ctl_name = 0 }
748 };
749
750 #define NET_IP_CONNTRACK_MAX 2089
751
752 static ctl_table ip_ct_netfilter_table[] = {
753 {
754 .ctl_name = NET_IPV4_NETFILTER,
755 .procname = "netfilter",
756 .mode = 0555,
757 .child = ip_ct_sysctl_table,
758 },
759 {
760 .ctl_name = NET_IP_CONNTRACK_MAX,
761 .procname = "ip_conntrack_max",
762 .data = &ip_conntrack_max,
763 .maxlen = sizeof(int),
764 .mode = 0644,
765 .proc_handler = &proc_dointvec
766 },
767 { .ctl_name = 0 }
768 };
769
770 static ctl_table ip_ct_ipv4_table[] = {
771 {
772 .ctl_name = NET_IPV4,
773 .procname = "ipv4",
774 .mode = 0555,
775 .child = ip_ct_netfilter_table,
776 },
777 { .ctl_name = 0 }
778 };
779
780 static ctl_table ip_ct_net_table[] = {
781 {
782 .ctl_name = CTL_NET,
783 .procname = "net",
784 .mode = 0555,
785 .child = ip_ct_ipv4_table,
786 },
787 { .ctl_name = 0 }
788 };
789
790 EXPORT_SYMBOL(ip_ct_log_invalid);
791 #endif /* CONFIG_SYSCTL */
792
793 /* FIXME: Allow NULL functions and sub in pointers to generic for
794 them. --RR */
795 int ip_conntrack_protocol_register(struct ip_conntrack_protocol *proto)
796 {
797 int ret = 0;
798
799 write_lock_bh(&ip_conntrack_lock);
800 if (ip_ct_protos[proto->proto] != &ip_conntrack_generic_protocol) {
801 ret = -EBUSY;
802 goto out;
803 }
804 ip_ct_protos[proto->proto] = proto;
805 out:
806 write_unlock_bh(&ip_conntrack_lock);
807 return ret;
808 }
809
810 void ip_conntrack_protocol_unregister(struct ip_conntrack_protocol *proto)
811 {
812 write_lock_bh(&ip_conntrack_lock);
813 ip_ct_protos[proto->proto] = &ip_conntrack_generic_protocol;
814 write_unlock_bh(&ip_conntrack_lock);
815
816 /* Somebody could be still looking at the proto in bh. */
817 synchronize_net();
818
819 /* Remove all contrack entries for this protocol */
820 ip_ct_iterate_cleanup(kill_proto, &proto->proto);
821 }
822
823 static int __init ip_conntrack_standalone_init(void)
824 {
825 #ifdef CONFIG_PROC_FS
826 struct proc_dir_entry *proc, *proc_exp, *proc_stat;
827 #endif
828 int ret = 0;
829
830 ret = ip_conntrack_init();
831 if (ret < 0)
832 return ret;
833
834 #ifdef CONFIG_PROC_FS
835 ret = -ENOMEM;
836 proc = proc_net_fops_create("ip_conntrack", 0440, &ct_file_ops);
837 if (!proc) goto cleanup_init;
838
839 proc_exp = proc_net_fops_create("ip_conntrack_expect", 0440,
840 &exp_file_ops);
841 if (!proc_exp) goto cleanup_proc;
842
843 proc_stat = create_proc_entry("ip_conntrack", S_IRUGO, proc_net_stat);
844 if (!proc_stat)
845 goto cleanup_proc_exp;
846
847 proc_stat->proc_fops = &ct_cpu_seq_fops;
848 proc_stat->owner = THIS_MODULE;
849 #endif
850
851 ret = nf_register_hooks(ip_conntrack_ops, ARRAY_SIZE(ip_conntrack_ops));
852 if (ret < 0) {
853 printk("ip_conntrack: can't register hooks.\n");
854 goto cleanup_proc_stat;
855 }
856 #ifdef CONFIG_SYSCTL
857 ip_ct_sysctl_header = register_sysctl_table(ip_ct_net_table, 0);
858 if (ip_ct_sysctl_header == NULL) {
859 printk("ip_conntrack: can't register to sysctl.\n");
860 ret = -ENOMEM;
861 goto cleanup_hooks;
862 }
863 #endif
864 return ret;
865
866 #ifdef CONFIG_SYSCTL
867 cleanup_hooks:
868 nf_unregister_hooks(ip_conntrack_ops, ARRAY_SIZE(ip_conntrack_ops));
869 #endif
870 cleanup_proc_stat:
871 #ifdef CONFIG_PROC_FS
872 remove_proc_entry("ip_conntrack", proc_net_stat);
873 cleanup_proc_exp:
874 proc_net_remove("ip_conntrack_expect");
875 cleanup_proc:
876 proc_net_remove("ip_conntrack");
877 cleanup_init:
878 #endif /* CONFIG_PROC_FS */
879 ip_conntrack_cleanup();
880 return ret;
881 }
882
883 static void __exit ip_conntrack_standalone_fini(void)
884 {
885 synchronize_net();
886 #ifdef CONFIG_SYSCTL
887 unregister_sysctl_table(ip_ct_sysctl_header);
888 #endif
889 nf_unregister_hooks(ip_conntrack_ops, ARRAY_SIZE(ip_conntrack_ops));
890 #ifdef CONFIG_PROC_FS
891 remove_proc_entry("ip_conntrack", proc_net_stat);
892 proc_net_remove("ip_conntrack_expect");
893 proc_net_remove("ip_conntrack");
894 #endif /* CONFIG_PROC_FS */
895 ip_conntrack_cleanup();
896 }
897
898 module_init(ip_conntrack_standalone_init);
899 module_exit(ip_conntrack_standalone_fini);
900
901 /* Some modules need us, but don't depend directly on any symbol.
902 They should call this. */
903 void need_conntrack(void)
904 {
905 }
906
907 #ifdef CONFIG_IP_NF_CONNTRACK_EVENTS
908 EXPORT_SYMBOL_GPL(ip_conntrack_chain);
909 EXPORT_SYMBOL_GPL(ip_conntrack_expect_chain);
910 EXPORT_SYMBOL_GPL(ip_conntrack_register_notifier);
911 EXPORT_SYMBOL_GPL(ip_conntrack_unregister_notifier);
912 EXPORT_SYMBOL_GPL(__ip_ct_event_cache_init);
913 EXPORT_PER_CPU_SYMBOL_GPL(ip_conntrack_ecache);
914 #endif
915 EXPORT_SYMBOL(ip_conntrack_protocol_register);
916 EXPORT_SYMBOL(ip_conntrack_protocol_unregister);
917 EXPORT_SYMBOL(ip_ct_get_tuple);
918 EXPORT_SYMBOL(invert_tuplepr);
919 EXPORT_SYMBOL(ip_conntrack_alter_reply);
920 EXPORT_SYMBOL(ip_conntrack_destroyed);
921 EXPORT_SYMBOL(need_conntrack);
922 EXPORT_SYMBOL(ip_conntrack_helper_register);
923 EXPORT_SYMBOL(ip_conntrack_helper_unregister);
924 EXPORT_SYMBOL(ip_ct_iterate_cleanup);
925 EXPORT_SYMBOL(__ip_ct_refresh_acct);
926
927 EXPORT_SYMBOL(ip_conntrack_expect_alloc);
928 EXPORT_SYMBOL(ip_conntrack_expect_put);
929 EXPORT_SYMBOL_GPL(__ip_conntrack_expect_find);
930 EXPORT_SYMBOL_GPL(ip_conntrack_expect_find);
931 EXPORT_SYMBOL(ip_conntrack_expect_related);
932 EXPORT_SYMBOL(ip_conntrack_unexpect_related);
933 EXPORT_SYMBOL_GPL(ip_conntrack_expect_list);
934 EXPORT_SYMBOL_GPL(ip_ct_unlink_expect);
935
936 EXPORT_SYMBOL(ip_conntrack_tuple_taken);
937 EXPORT_SYMBOL(ip_ct_gather_frags);
938 EXPORT_SYMBOL(ip_conntrack_htable_size);
939 EXPORT_SYMBOL(ip_conntrack_lock);
940 EXPORT_SYMBOL(ip_conntrack_hash);
941 EXPORT_SYMBOL(ip_conntrack_untracked);
942 EXPORT_SYMBOL_GPL(ip_conntrack_find_get);
943 #ifdef CONFIG_IP_NF_NAT_NEEDED
944 EXPORT_SYMBOL(ip_conntrack_tcp_update);
945 #endif
946
947 EXPORT_SYMBOL_GPL(ip_conntrack_flush);
948 EXPORT_SYMBOL_GPL(__ip_conntrack_find);
949
950 EXPORT_SYMBOL_GPL(ip_conntrack_alloc);
951 EXPORT_SYMBOL_GPL(ip_conntrack_free);
952 EXPORT_SYMBOL_GPL(ip_conntrack_hash_insert);
953
954 EXPORT_SYMBOL_GPL(ip_ct_remove_expectations);
955
956 EXPORT_SYMBOL_GPL(ip_conntrack_helper_find_get);
957 EXPORT_SYMBOL_GPL(ip_conntrack_helper_put);
958 EXPORT_SYMBOL_GPL(__ip_conntrack_helper_find_byname);
959
960 EXPORT_SYMBOL_GPL(ip_conntrack_proto_find_get);
961 EXPORT_SYMBOL_GPL(ip_conntrack_proto_put);
962 EXPORT_SYMBOL_GPL(__ip_conntrack_proto_find);
963 EXPORT_SYMBOL_GPL(ip_conntrack_checksum);
964 #if defined(CONFIG_IP_NF_CONNTRACK_NETLINK) || \
965 defined(CONFIG_IP_NF_CONNTRACK_NETLINK_MODULE)
966 EXPORT_SYMBOL_GPL(ip_ct_port_tuple_to_nfattr);
967 EXPORT_SYMBOL_GPL(ip_ct_port_nfattr_to_tuple);
968 #endif
This page took 0.048685 seconds and 4 git commands to generate.