MOXA linux-2.6.x / linux-2.6.19-uc1 from UC-7110-LX-BOOTLOADER-1.9_VERSION-4.2.tgz
[linux-2.6.19-moxart.git] / net / ipv4 / netfilter / ip_conntrack_standalone.c
blobbdd1b7da5c94e3046a6e395a49d521653a8ab6f3
1 /* This file contains all the functions required for the standalone
2 ip_conntrack module.
4 These are not required by the compatibility layer.
5 */
7 /* (C) 1999-2001 Paul `Rusty' Russell
8 * (C) 2002-2005 Netfilter Core Team <coreteam@netfilter.org>
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.
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>
31 #define ASSERT_READ_LOCK(x)
32 #define ASSERT_WRITE_LOCK(x)
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>
39 #if 0
40 #define DEBUGP printk
41 #else
42 #define DEBUGP(format, args...)
43 #endif
45 MODULE_LICENSE("GPL");
47 extern atomic_t ip_conntrack_count;
48 DECLARE_PER_CPU(struct ip_conntrack_stat, ip_conntrack_stat);
50 static int kill_proto(struct ip_conntrack *i, void *data)
52 return (i->tuplehash[IP_CT_DIR_ORIGINAL].tuple.dst.protonum ==
53 *((u_int8_t *) data));
56 #ifdef CONFIG_PROC_FS
57 static int
58 print_tuple(struct seq_file *s, const struct ip_conntrack_tuple *tuple,
59 struct ip_conntrack_protocol *proto)
61 seq_printf(s, "src=%u.%u.%u.%u dst=%u.%u.%u.%u ",
62 NIPQUAD(tuple->src.ip), NIPQUAD(tuple->dst.ip));
63 return proto->print_tuple(s, tuple);
66 #ifdef CONFIG_IP_NF_CT_ACCT
67 static unsigned int
68 seq_print_counters(struct seq_file *s,
69 const struct ip_conntrack_counter *counter)
71 return seq_printf(s, "packets=%llu bytes=%llu ",
72 (unsigned long long)counter->packets,
73 (unsigned long long)counter->bytes);
75 #else
76 #define seq_print_counters(x, y) 0
77 #endif
79 struct ct_iter_state {
80 unsigned int bucket;
83 static struct list_head *ct_get_first(struct seq_file *seq)
85 struct ct_iter_state *st = seq->private;
87 for (st->bucket = 0;
88 st->bucket < ip_conntrack_htable_size;
89 st->bucket++) {
90 if (!list_empty(&ip_conntrack_hash[st->bucket]))
91 return ip_conntrack_hash[st->bucket].next;
93 return NULL;
96 static struct list_head *ct_get_next(struct seq_file *seq, struct list_head *head)
98 struct ct_iter_state *st = seq->private;
100 head = head->next;
101 while (head == &ip_conntrack_hash[st->bucket]) {
102 if (++st->bucket >= ip_conntrack_htable_size)
103 return NULL;
104 head = ip_conntrack_hash[st->bucket].next;
106 return head;
109 static struct list_head *ct_get_idx(struct seq_file *seq, loff_t pos)
111 struct list_head *head = ct_get_first(seq);
113 if (head)
114 while (pos && (head = ct_get_next(seq, head)))
115 pos--;
116 return pos ? NULL : head;
119 static void *ct_seq_start(struct seq_file *seq, loff_t *pos)
121 read_lock_bh(&ip_conntrack_lock);
122 return ct_get_idx(seq, *pos);
125 static void *ct_seq_next(struct seq_file *s, void *v, loff_t *pos)
127 (*pos)++;
128 return ct_get_next(s, v);
131 static void ct_seq_stop(struct seq_file *s, void *v)
133 read_unlock_bh(&ip_conntrack_lock);
136 static int ct_seq_show(struct seq_file *s, void *v)
138 const struct ip_conntrack_tuple_hash *hash = v;
139 const struct ip_conntrack *conntrack = tuplehash_to_ctrack(hash);
140 struct ip_conntrack_protocol *proto;
142 ASSERT_READ_LOCK(&ip_conntrack_lock);
143 IP_NF_ASSERT(conntrack);
145 /* we only want to print DIR_ORIGINAL */
146 if (DIRECTION(hash))
147 return 0;
149 proto = __ip_conntrack_proto_find(conntrack->tuplehash[IP_CT_DIR_ORIGINAL].tuple.dst.protonum);
150 IP_NF_ASSERT(proto);
152 if (seq_printf(s, "%-8s %u %ld ",
153 proto->name,
154 conntrack->tuplehash[IP_CT_DIR_ORIGINAL].tuple.dst.protonum,
155 timer_pending(&conntrack->timeout)
156 ? (long)(conntrack->timeout.expires - jiffies)/HZ
157 : 0) != 0)
158 return -ENOSPC;
160 if (proto->print_conntrack(s, conntrack))
161 return -ENOSPC;
163 if (print_tuple(s, &conntrack->tuplehash[IP_CT_DIR_ORIGINAL].tuple,
164 proto))
165 return -ENOSPC;
167 if (seq_print_counters(s, &conntrack->counters[IP_CT_DIR_ORIGINAL]))
168 return -ENOSPC;
170 if (!(test_bit(IPS_SEEN_REPLY_BIT, &conntrack->status)))
171 if (seq_printf(s, "[UNREPLIED] "))
172 return -ENOSPC;
174 if (print_tuple(s, &conntrack->tuplehash[IP_CT_DIR_REPLY].tuple,
175 proto))
176 return -ENOSPC;
178 if (seq_print_counters(s, &conntrack->counters[IP_CT_DIR_REPLY]))
179 return -ENOSPC;
181 if (test_bit(IPS_ASSURED_BIT, &conntrack->status))
182 if (seq_printf(s, "[ASSURED] "))
183 return -ENOSPC;
185 #if defined(CONFIG_IP_NF_CONNTRACK_MARK)
186 if (seq_printf(s, "mark=%u ", conntrack->mark))
187 return -ENOSPC;
188 #endif
190 #ifdef CONFIG_IP_NF_CONNTRACK_SECMARK
191 if (seq_printf(s, "secmark=%u ", conntrack->secmark))
192 return -ENOSPC;
193 #endif
195 #if defined(CONFIG_IP_NF_MATCH_LAYER7) || defined(CONFIG_IP_NF_MATCH_LAYER7_MODULE)
196 if(conntrack->layer7.app_proto)
197 if (seq_printf(s, "l7proto=%s ",conntrack->layer7.app_proto))
198 return 1;
199 #endif
201 if (seq_printf(s, "use=%u\n", atomic_read(&conntrack->ct_general.use)))
202 return -ENOSPC;
204 return 0;
207 static struct seq_operations ct_seq_ops = {
208 .start = ct_seq_start,
209 .next = ct_seq_next,
210 .stop = ct_seq_stop,
211 .show = ct_seq_show
214 static int ct_open(struct inode *inode, struct file *file)
216 struct seq_file *seq;
217 struct ct_iter_state *st;
218 int ret;
220 st = kmalloc(sizeof(struct ct_iter_state), GFP_KERNEL);
221 if (st == NULL)
222 return -ENOMEM;
223 ret = seq_open(file, &ct_seq_ops);
224 if (ret)
225 goto out_free;
226 seq = file->private_data;
227 seq->private = st;
228 memset(st, 0, sizeof(struct ct_iter_state));
229 return ret;
230 out_free:
231 kfree(st);
232 return ret;
235 static struct file_operations ct_file_ops = {
236 .owner = THIS_MODULE,
237 .open = ct_open,
238 .read = seq_read,
239 .llseek = seq_lseek,
240 .release = seq_release_private,
243 /* expects */
244 static void *exp_seq_start(struct seq_file *s, loff_t *pos)
246 struct list_head *e = &ip_conntrack_expect_list;
247 loff_t i;
249 /* strange seq_file api calls stop even if we fail,
250 * thus we need to grab lock since stop unlocks */
251 read_lock_bh(&ip_conntrack_lock);
253 if (list_empty(e))
254 return NULL;
256 for (i = 0; i <= *pos; i++) {
257 e = e->next;
258 if (e == &ip_conntrack_expect_list)
259 return NULL;
261 return e;
264 static void *exp_seq_next(struct seq_file *s, void *v, loff_t *pos)
266 struct list_head *e = v;
268 ++*pos;
269 e = e->next;
271 if (e == &ip_conntrack_expect_list)
272 return NULL;
274 return e;
277 static void exp_seq_stop(struct seq_file *s, void *v)
279 read_unlock_bh(&ip_conntrack_lock);
282 static int exp_seq_show(struct seq_file *s, void *v)
284 struct ip_conntrack_expect *expect = v;
286 if (expect->timeout.function)
287 seq_printf(s, "%ld ", timer_pending(&expect->timeout)
288 ? (long)(expect->timeout.expires - jiffies)/HZ : 0);
289 else
290 seq_printf(s, "- ");
292 seq_printf(s, "proto=%u ", expect->tuple.dst.protonum);
294 print_tuple(s, &expect->tuple,
295 __ip_conntrack_proto_find(expect->tuple.dst.protonum));
296 return seq_putc(s, '\n');
299 static struct seq_operations exp_seq_ops = {
300 .start = exp_seq_start,
301 .next = exp_seq_next,
302 .stop = exp_seq_stop,
303 .show = exp_seq_show
306 static int exp_open(struct inode *inode, struct file *file)
308 return seq_open(file, &exp_seq_ops);
311 static struct file_operations exp_file_ops = {
312 .owner = THIS_MODULE,
313 .open = exp_open,
314 .read = seq_read,
315 .llseek = seq_lseek,
316 .release = seq_release
319 static void *ct_cpu_seq_start(struct seq_file *seq, loff_t *pos)
321 int cpu;
323 if (*pos == 0)
324 return SEQ_START_TOKEN;
326 for (cpu = *pos-1; cpu < NR_CPUS; ++cpu) {
327 if (!cpu_possible(cpu))
328 continue;
329 *pos = cpu+1;
330 return &per_cpu(ip_conntrack_stat, cpu);
333 return NULL;
336 static void *ct_cpu_seq_next(struct seq_file *seq, void *v, loff_t *pos)
338 int cpu;
340 for (cpu = *pos; cpu < NR_CPUS; ++cpu) {
341 if (!cpu_possible(cpu))
342 continue;
343 *pos = cpu+1;
344 return &per_cpu(ip_conntrack_stat, cpu);
347 return NULL;
350 static void ct_cpu_seq_stop(struct seq_file *seq, void *v)
354 static int ct_cpu_seq_show(struct seq_file *seq, void *v)
356 unsigned int nr_conntracks = atomic_read(&ip_conntrack_count);
357 struct ip_conntrack_stat *st = v;
359 if (v == SEQ_START_TOKEN) {
360 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");
361 return 0;
364 seq_printf(seq, "%08x %08x %08x %08x %08x %08x %08x %08x "
365 "%08x %08x %08x %08x %08x %08x %08x %08x \n",
366 nr_conntracks,
367 st->searched,
368 st->found,
369 st->new,
370 st->invalid,
371 st->ignore,
372 st->delete,
373 st->delete_list,
374 st->insert,
375 st->insert_failed,
376 st->drop,
377 st->early_drop,
378 st->error,
380 st->expect_new,
381 st->expect_create,
382 st->expect_delete
384 return 0;
387 static struct seq_operations ct_cpu_seq_ops = {
388 .start = ct_cpu_seq_start,
389 .next = ct_cpu_seq_next,
390 .stop = ct_cpu_seq_stop,
391 .show = ct_cpu_seq_show,
394 static int ct_cpu_seq_open(struct inode *inode, struct file *file)
396 return seq_open(file, &ct_cpu_seq_ops);
399 static struct file_operations ct_cpu_seq_fops = {
400 .owner = THIS_MODULE,
401 .open = ct_cpu_seq_open,
402 .read = seq_read,
403 .llseek = seq_lseek,
404 .release = seq_release_private,
406 #endif
408 static unsigned int ip_confirm(unsigned int hooknum,
409 struct sk_buff **pskb,
410 const struct net_device *in,
411 const struct net_device *out,
412 int (*okfn)(struct sk_buff *))
414 /* We've seen it coming out the other side: confirm it */
415 return ip_conntrack_confirm(pskb);
418 static unsigned int ip_conntrack_help(unsigned int hooknum,
419 struct sk_buff **pskb,
420 const struct net_device *in,
421 const struct net_device *out,
422 int (*okfn)(struct sk_buff *))
424 struct ip_conntrack *ct;
425 enum ip_conntrack_info ctinfo;
427 /* This is where we call the helper: as the packet goes out. */
428 ct = ip_conntrack_get(*pskb, &ctinfo);
429 if (ct && ct->helper && ctinfo != IP_CT_RELATED + IP_CT_IS_REPLY) {
430 unsigned int ret;
431 ret = ct->helper->help(pskb, ct, ctinfo);
432 if (ret != NF_ACCEPT)
433 return ret;
435 return NF_ACCEPT;
438 static unsigned int ip_conntrack_defrag(unsigned int hooknum,
439 struct sk_buff **pskb,
440 const struct net_device *in,
441 const struct net_device *out,
442 int (*okfn)(struct sk_buff *))
444 #if !defined(CONFIG_IP_NF_NAT) && !defined(CONFIG_IP_NF_NAT_MODULE)
445 /* Previously seen (loopback)? Ignore. Do this before
446 fragment check. */
447 if ((*pskb)->nfct)
448 return NF_ACCEPT;
449 #endif
451 /* Gather fragments. */
452 if ((*pskb)->nh.iph->frag_off & htons(IP_MF|IP_OFFSET)) {
453 *pskb = ip_ct_gather_frags(*pskb,
454 hooknum == NF_IP_PRE_ROUTING ?
455 IP_DEFRAG_CONNTRACK_IN :
456 IP_DEFRAG_CONNTRACK_OUT);
457 if (!*pskb)
458 return NF_STOLEN;
460 return NF_ACCEPT;
463 static unsigned int ip_conntrack_local(unsigned int hooknum,
464 struct sk_buff **pskb,
465 const struct net_device *in,
466 const struct net_device *out,
467 int (*okfn)(struct sk_buff *))
469 /* root is playing with raw sockets. */
470 if ((*pskb)->len < sizeof(struct iphdr)
471 || (*pskb)->nh.iph->ihl * 4 < sizeof(struct iphdr)) {
472 if (net_ratelimit())
473 printk("ipt_hook: happy cracking.\n");
474 return NF_ACCEPT;
476 return ip_conntrack_in(hooknum, pskb, in, out, okfn);
479 /* Connection tracking may drop packets, but never alters them, so
480 make it the first hook. */
481 static struct nf_hook_ops ip_conntrack_ops[] = {
483 .hook = ip_conntrack_defrag,
484 .owner = THIS_MODULE,
485 .pf = PF_INET,
486 .hooknum = NF_IP_PRE_ROUTING,
487 .priority = NF_IP_PRI_CONNTRACK_DEFRAG,
490 .hook = ip_conntrack_in,
491 .owner = THIS_MODULE,
492 .pf = PF_INET,
493 .hooknum = NF_IP_PRE_ROUTING,
494 .priority = NF_IP_PRI_CONNTRACK,
497 .hook = ip_conntrack_defrag,
498 .owner = THIS_MODULE,
499 .pf = PF_INET,
500 .hooknum = NF_IP_LOCAL_OUT,
501 .priority = NF_IP_PRI_CONNTRACK_DEFRAG,
504 .hook = ip_conntrack_local,
505 .owner = THIS_MODULE,
506 .pf = PF_INET,
507 .hooknum = NF_IP_LOCAL_OUT,
508 .priority = NF_IP_PRI_CONNTRACK,
511 .hook = ip_conntrack_help,
512 .owner = THIS_MODULE,
513 .pf = PF_INET,
514 .hooknum = NF_IP_POST_ROUTING,
515 .priority = NF_IP_PRI_CONNTRACK_HELPER,
518 .hook = ip_conntrack_help,
519 .owner = THIS_MODULE,
520 .pf = PF_INET,
521 .hooknum = NF_IP_LOCAL_IN,
522 .priority = NF_IP_PRI_CONNTRACK_HELPER,
525 .hook = ip_confirm,
526 .owner = THIS_MODULE,
527 .pf = PF_INET,
528 .hooknum = NF_IP_POST_ROUTING,
529 .priority = NF_IP_PRI_CONNTRACK_CONFIRM,
532 .hook = ip_confirm,
533 .owner = THIS_MODULE,
534 .pf = PF_INET,
535 .hooknum = NF_IP_LOCAL_IN,
536 .priority = NF_IP_PRI_CONNTRACK_CONFIRM,
540 /* Sysctl support */
542 int ip_conntrack_checksum __read_mostly = 1;
544 #ifdef CONFIG_SYSCTL
546 /* From ip_conntrack_core.c */
547 extern int ip_conntrack_max;
548 extern unsigned int ip_conntrack_htable_size;
550 /* From ip_conntrack_proto_tcp.c */
551 extern unsigned int ip_ct_tcp_timeout_syn_sent;
552 extern unsigned int ip_ct_tcp_timeout_syn_recv;
553 extern unsigned int ip_ct_tcp_timeout_established;
554 extern unsigned int ip_ct_tcp_timeout_fin_wait;
555 extern unsigned int ip_ct_tcp_timeout_close_wait;
556 extern unsigned int ip_ct_tcp_timeout_last_ack;
557 extern unsigned int ip_ct_tcp_timeout_time_wait;
558 extern unsigned int ip_ct_tcp_timeout_close;
559 extern unsigned int ip_ct_tcp_timeout_max_retrans;
560 extern int ip_ct_tcp_loose;
561 extern int ip_ct_tcp_be_liberal;
562 extern int ip_ct_tcp_max_retrans;
564 /* From ip_conntrack_proto_udp.c */
565 extern unsigned int ip_ct_udp_timeout;
566 extern unsigned int ip_ct_udp_timeout_stream;
568 /* From ip_conntrack_proto_icmp.c */
569 extern unsigned int ip_ct_icmp_timeout;
571 /* From ip_conntrack_proto_generic.c */
572 extern unsigned int ip_ct_generic_timeout;
574 /* Log invalid packets of a given protocol */
575 static int log_invalid_proto_min = 0;
576 static int log_invalid_proto_max = 255;
578 static struct ctl_table_header *ip_ct_sysctl_header;
580 static ctl_table ip_ct_sysctl_table[] = {
582 .ctl_name = NET_IPV4_NF_CONNTRACK_MAX,
583 .procname = "ip_conntrack_max",
584 .data = &ip_conntrack_max,
585 .maxlen = sizeof(int),
586 .mode = 0644,
587 .proc_handler = &proc_dointvec,
590 .ctl_name = NET_IPV4_NF_CONNTRACK_COUNT,
591 .procname = "ip_conntrack_count",
592 .data = &ip_conntrack_count,
593 .maxlen = sizeof(int),
594 .mode = 0444,
595 .proc_handler = &proc_dointvec,
598 .ctl_name = NET_IPV4_NF_CONNTRACK_BUCKETS,
599 .procname = "ip_conntrack_buckets",
600 .data = &ip_conntrack_htable_size,
601 .maxlen = sizeof(unsigned int),
602 .mode = 0444,
603 .proc_handler = &proc_dointvec,
606 .ctl_name = NET_IPV4_NF_CONNTRACK_CHECKSUM,
607 .procname = "ip_conntrack_checksum",
608 .data = &ip_conntrack_checksum,
609 .maxlen = sizeof(int),
610 .mode = 0644,
611 .proc_handler = &proc_dointvec,
614 .ctl_name = NET_IPV4_NF_CONNTRACK_TCP_TIMEOUT_SYN_SENT,
615 .procname = "ip_conntrack_tcp_timeout_syn_sent",
616 .data = &ip_ct_tcp_timeout_syn_sent,
617 .maxlen = sizeof(unsigned int),
618 .mode = 0644,
619 .proc_handler = &proc_dointvec_jiffies,
622 .ctl_name = NET_IPV4_NF_CONNTRACK_TCP_TIMEOUT_SYN_RECV,
623 .procname = "ip_conntrack_tcp_timeout_syn_recv",
624 .data = &ip_ct_tcp_timeout_syn_recv,
625 .maxlen = sizeof(unsigned int),
626 .mode = 0644,
627 .proc_handler = &proc_dointvec_jiffies,
630 .ctl_name = NET_IPV4_NF_CONNTRACK_TCP_TIMEOUT_ESTABLISHED,
631 .procname = "ip_conntrack_tcp_timeout_established",
632 .data = &ip_ct_tcp_timeout_established,
633 .maxlen = sizeof(unsigned int),
634 .mode = 0644,
635 .proc_handler = &proc_dointvec_jiffies,
638 .ctl_name = NET_IPV4_NF_CONNTRACK_TCP_TIMEOUT_FIN_WAIT,
639 .procname = "ip_conntrack_tcp_timeout_fin_wait",
640 .data = &ip_ct_tcp_timeout_fin_wait,
641 .maxlen = sizeof(unsigned int),
642 .mode = 0644,
643 .proc_handler = &proc_dointvec_jiffies,
646 .ctl_name = NET_IPV4_NF_CONNTRACK_TCP_TIMEOUT_CLOSE_WAIT,
647 .procname = "ip_conntrack_tcp_timeout_close_wait",
648 .data = &ip_ct_tcp_timeout_close_wait,
649 .maxlen = sizeof(unsigned int),
650 .mode = 0644,
651 .proc_handler = &proc_dointvec_jiffies,
654 .ctl_name = NET_IPV4_NF_CONNTRACK_TCP_TIMEOUT_LAST_ACK,
655 .procname = "ip_conntrack_tcp_timeout_last_ack",
656 .data = &ip_ct_tcp_timeout_last_ack,
657 .maxlen = sizeof(unsigned int),
658 .mode = 0644,
659 .proc_handler = &proc_dointvec_jiffies,
662 .ctl_name = NET_IPV4_NF_CONNTRACK_TCP_TIMEOUT_TIME_WAIT,
663 .procname = "ip_conntrack_tcp_timeout_time_wait",
664 .data = &ip_ct_tcp_timeout_time_wait,
665 .maxlen = sizeof(unsigned int),
666 .mode = 0644,
667 .proc_handler = &proc_dointvec_jiffies,
670 .ctl_name = NET_IPV4_NF_CONNTRACK_TCP_TIMEOUT_CLOSE,
671 .procname = "ip_conntrack_tcp_timeout_close",
672 .data = &ip_ct_tcp_timeout_close,
673 .maxlen = sizeof(unsigned int),
674 .mode = 0644,
675 .proc_handler = &proc_dointvec_jiffies,
678 .ctl_name = NET_IPV4_NF_CONNTRACK_UDP_TIMEOUT,
679 .procname = "ip_conntrack_udp_timeout",
680 .data = &ip_ct_udp_timeout,
681 .maxlen = sizeof(unsigned int),
682 .mode = 0644,
683 .proc_handler = &proc_dointvec_jiffies,
686 .ctl_name = NET_IPV4_NF_CONNTRACK_UDP_TIMEOUT_STREAM,
687 .procname = "ip_conntrack_udp_timeout_stream",
688 .data = &ip_ct_udp_timeout_stream,
689 .maxlen = sizeof(unsigned int),
690 .mode = 0644,
691 .proc_handler = &proc_dointvec_jiffies,
694 .ctl_name = NET_IPV4_NF_CONNTRACK_ICMP_TIMEOUT,
695 .procname = "ip_conntrack_icmp_timeout",
696 .data = &ip_ct_icmp_timeout,
697 .maxlen = sizeof(unsigned int),
698 .mode = 0644,
699 .proc_handler = &proc_dointvec_jiffies,
702 .ctl_name = NET_IPV4_NF_CONNTRACK_GENERIC_TIMEOUT,
703 .procname = "ip_conntrack_generic_timeout",
704 .data = &ip_ct_generic_timeout,
705 .maxlen = sizeof(unsigned int),
706 .mode = 0644,
707 .proc_handler = &proc_dointvec_jiffies,
710 .ctl_name = NET_IPV4_NF_CONNTRACK_LOG_INVALID,
711 .procname = "ip_conntrack_log_invalid",
712 .data = &ip_ct_log_invalid,
713 .maxlen = sizeof(unsigned int),
714 .mode = 0644,
715 .proc_handler = &proc_dointvec_minmax,
716 .strategy = &sysctl_intvec,
717 .extra1 = &log_invalid_proto_min,
718 .extra2 = &log_invalid_proto_max,
721 .ctl_name = NET_IPV4_NF_CONNTRACK_TCP_TIMEOUT_MAX_RETRANS,
722 .procname = "ip_conntrack_tcp_timeout_max_retrans",
723 .data = &ip_ct_tcp_timeout_max_retrans,
724 .maxlen = sizeof(unsigned int),
725 .mode = 0644,
726 .proc_handler = &proc_dointvec_jiffies,
729 .ctl_name = NET_IPV4_NF_CONNTRACK_TCP_LOOSE,
730 .procname = "ip_conntrack_tcp_loose",
731 .data = &ip_ct_tcp_loose,
732 .maxlen = sizeof(unsigned int),
733 .mode = 0644,
734 .proc_handler = &proc_dointvec,
737 .ctl_name = NET_IPV4_NF_CONNTRACK_TCP_BE_LIBERAL,
738 .procname = "ip_conntrack_tcp_be_liberal",
739 .data = &ip_ct_tcp_be_liberal,
740 .maxlen = sizeof(unsigned int),
741 .mode = 0644,
742 .proc_handler = &proc_dointvec,
745 .ctl_name = NET_IPV4_NF_CONNTRACK_TCP_MAX_RETRANS,
746 .procname = "ip_conntrack_tcp_max_retrans",
747 .data = &ip_ct_tcp_max_retrans,
748 .maxlen = sizeof(unsigned int),
749 .mode = 0644,
750 .proc_handler = &proc_dointvec,
752 { .ctl_name = 0 }
755 #define NET_IP_CONNTRACK_MAX 2089
757 static ctl_table ip_ct_netfilter_table[] = {
759 .ctl_name = NET_IPV4_NETFILTER,
760 .procname = "netfilter",
761 .mode = 0555,
762 .child = ip_ct_sysctl_table,
765 .ctl_name = NET_IP_CONNTRACK_MAX,
766 .procname = "ip_conntrack_max",
767 .data = &ip_conntrack_max,
768 .maxlen = sizeof(int),
769 .mode = 0644,
770 .proc_handler = &proc_dointvec
772 { .ctl_name = 0 }
775 static ctl_table ip_ct_ipv4_table[] = {
777 .ctl_name = NET_IPV4,
778 .procname = "ipv4",
779 .mode = 0555,
780 .child = ip_ct_netfilter_table,
782 { .ctl_name = 0 }
785 static ctl_table ip_ct_net_table[] = {
787 .ctl_name = CTL_NET,
788 .procname = "net",
789 .mode = 0555,
790 .child = ip_ct_ipv4_table,
792 { .ctl_name = 0 }
795 EXPORT_SYMBOL(ip_ct_log_invalid);
796 #endif /* CONFIG_SYSCTL */
798 /* FIXME: Allow NULL functions and sub in pointers to generic for
799 them. --RR */
800 int ip_conntrack_protocol_register(struct ip_conntrack_protocol *proto)
802 int ret = 0;
804 write_lock_bh(&ip_conntrack_lock);
805 if (ip_ct_protos[proto->proto] != &ip_conntrack_generic_protocol) {
806 ret = -EBUSY;
807 goto out;
809 ip_ct_protos[proto->proto] = proto;
810 out:
811 write_unlock_bh(&ip_conntrack_lock);
812 return ret;
815 void ip_conntrack_protocol_unregister(struct ip_conntrack_protocol *proto)
817 write_lock_bh(&ip_conntrack_lock);
818 ip_ct_protos[proto->proto] = &ip_conntrack_generic_protocol;
819 write_unlock_bh(&ip_conntrack_lock);
821 /* Somebody could be still looking at the proto in bh. */
822 synchronize_net();
824 /* Remove all contrack entries for this protocol */
825 ip_ct_iterate_cleanup(kill_proto, &proto->proto);
828 static int __init ip_conntrack_standalone_init(void)
830 #ifdef CONFIG_PROC_FS
831 struct proc_dir_entry *proc, *proc_exp, *proc_stat;
832 #endif
833 int ret = 0;
835 ret = ip_conntrack_init();
836 if (ret < 0)
837 return ret;
839 #ifdef CONFIG_PROC_FS
840 ret = -ENOMEM;
841 proc = proc_net_fops_create("ip_conntrack", 0440, &ct_file_ops);
842 if (!proc) goto cleanup_init;
844 proc_exp = proc_net_fops_create("ip_conntrack_expect", 0440,
845 &exp_file_ops);
846 if (!proc_exp) goto cleanup_proc;
848 proc_stat = create_proc_entry("ip_conntrack", S_IRUGO, proc_net_stat);
849 if (!proc_stat)
850 goto cleanup_proc_exp;
852 proc_stat->proc_fops = &ct_cpu_seq_fops;
853 proc_stat->owner = THIS_MODULE;
854 #endif
856 ret = nf_register_hooks(ip_conntrack_ops, ARRAY_SIZE(ip_conntrack_ops));
857 if (ret < 0) {
858 printk("ip_conntrack: can't register hooks.\n");
859 goto cleanup_proc_stat;
861 #ifdef CONFIG_SYSCTL
862 ip_ct_sysctl_header = register_sysctl_table(ip_ct_net_table, 0);
863 if (ip_ct_sysctl_header == NULL) {
864 printk("ip_conntrack: can't register to sysctl.\n");
865 ret = -ENOMEM;
866 goto cleanup_hooks;
868 #endif
869 return ret;
871 #ifdef CONFIG_SYSCTL
872 cleanup_hooks:
873 nf_unregister_hooks(ip_conntrack_ops, ARRAY_SIZE(ip_conntrack_ops));
874 #endif
875 cleanup_proc_stat:
876 #ifdef CONFIG_PROC_FS
877 remove_proc_entry("ip_conntrack", proc_net_stat);
878 cleanup_proc_exp:
879 proc_net_remove("ip_conntrack_expect");
880 cleanup_proc:
881 proc_net_remove("ip_conntrack");
882 cleanup_init:
883 #endif /* CONFIG_PROC_FS */
884 ip_conntrack_cleanup();
885 return ret;
888 static void __exit ip_conntrack_standalone_fini(void)
890 synchronize_net();
891 #ifdef CONFIG_SYSCTL
892 unregister_sysctl_table(ip_ct_sysctl_header);
893 #endif
894 nf_unregister_hooks(ip_conntrack_ops, ARRAY_SIZE(ip_conntrack_ops));
895 #ifdef CONFIG_PROC_FS
896 remove_proc_entry("ip_conntrack", proc_net_stat);
897 proc_net_remove("ip_conntrack_expect");
898 proc_net_remove("ip_conntrack");
899 #endif /* CONFIG_PROC_FS */
900 ip_conntrack_cleanup();
903 module_init(ip_conntrack_standalone_init);
904 module_exit(ip_conntrack_standalone_fini);
906 /* Some modules need us, but don't depend directly on any symbol.
907 They should call this. */
908 void need_conntrack(void)
912 #ifdef CONFIG_IP_NF_CONNTRACK_EVENTS
913 EXPORT_SYMBOL_GPL(ip_conntrack_chain);
914 EXPORT_SYMBOL_GPL(ip_conntrack_expect_chain);
915 EXPORT_SYMBOL_GPL(ip_conntrack_register_notifier);
916 EXPORT_SYMBOL_GPL(ip_conntrack_unregister_notifier);
917 EXPORT_SYMBOL_GPL(__ip_ct_event_cache_init);
918 EXPORT_PER_CPU_SYMBOL_GPL(ip_conntrack_ecache);
919 #endif
920 EXPORT_SYMBOL(ip_conntrack_protocol_register);
921 EXPORT_SYMBOL(ip_conntrack_protocol_unregister);
922 EXPORT_SYMBOL(ip_ct_get_tuple);
923 EXPORT_SYMBOL(invert_tuplepr);
924 EXPORT_SYMBOL(ip_conntrack_alter_reply);
925 EXPORT_SYMBOL(ip_conntrack_destroyed);
926 EXPORT_SYMBOL(need_conntrack);
927 EXPORT_SYMBOL(ip_conntrack_helper_register);
928 EXPORT_SYMBOL(ip_conntrack_helper_unregister);
929 EXPORT_SYMBOL(ip_ct_iterate_cleanup);
930 EXPORT_SYMBOL(__ip_ct_refresh_acct);
932 EXPORT_SYMBOL(ip_conntrack_expect_alloc);
933 EXPORT_SYMBOL(ip_conntrack_expect_put);
934 EXPORT_SYMBOL_GPL(__ip_conntrack_expect_find);
935 EXPORT_SYMBOL_GPL(ip_conntrack_expect_find);
936 EXPORT_SYMBOL(ip_conntrack_expect_related);
937 EXPORT_SYMBOL(ip_conntrack_unexpect_related);
938 EXPORT_SYMBOL_GPL(ip_conntrack_expect_list);
939 EXPORT_SYMBOL_GPL(ip_ct_unlink_expect);
941 EXPORT_SYMBOL(ip_conntrack_tuple_taken);
942 EXPORT_SYMBOL(ip_ct_gather_frags);
943 EXPORT_SYMBOL(ip_conntrack_htable_size);
944 EXPORT_SYMBOL(ip_conntrack_lock);
945 EXPORT_SYMBOL(ip_conntrack_hash);
946 EXPORT_SYMBOL(ip_conntrack_untracked);
947 EXPORT_SYMBOL_GPL(ip_conntrack_find_get);
948 #ifdef CONFIG_IP_NF_NAT_NEEDED
949 EXPORT_SYMBOL(ip_conntrack_tcp_update);
950 #endif
952 EXPORT_SYMBOL_GPL(ip_conntrack_flush);
953 EXPORT_SYMBOL_GPL(__ip_conntrack_find);
955 EXPORT_SYMBOL_GPL(ip_conntrack_alloc);
956 EXPORT_SYMBOL_GPL(ip_conntrack_free);
957 EXPORT_SYMBOL_GPL(ip_conntrack_hash_insert);
959 EXPORT_SYMBOL_GPL(ip_ct_remove_expectations);
961 EXPORT_SYMBOL_GPL(ip_conntrack_helper_find_get);
962 EXPORT_SYMBOL_GPL(ip_conntrack_helper_put);
963 EXPORT_SYMBOL_GPL(__ip_conntrack_helper_find_byname);
965 EXPORT_SYMBOL_GPL(ip_conntrack_proto_find_get);
966 EXPORT_SYMBOL_GPL(ip_conntrack_proto_put);
967 EXPORT_SYMBOL_GPL(__ip_conntrack_proto_find);
968 EXPORT_SYMBOL_GPL(ip_conntrack_checksum);
969 #if defined(CONFIG_IP_NF_CONNTRACK_NETLINK) || \
970 defined(CONFIG_IP_NF_CONNTRACK_NETLINK_MODULE)
971 EXPORT_SYMBOL_GPL(ip_ct_port_tuple_to_nfattr);
972 EXPORT_SYMBOL_GPL(ip_ct_port_nfattr_to_tuple);
973 #endif