1 /* This file contains all the functions required for the standalone
4 These are not required by the compatibility layer.
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/config.h>
16 #include <linux/types.h>
18 #include <linux/netfilter.h>
19 #include <linux/netfilter_ipv4.h>
20 #include <linux/module.h>
21 #include <linux/skbuff.h>
22 #include <linux/proc_fs.h>
23 #include <linux/seq_file.h>
24 #include <linux/percpu.h>
26 #include <linux/sysctl.h>
28 #include <net/checksum.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>
38 #include <linux/netfilter_ipv4/listhelp.h>
43 #define DEBUGP(format, args...)
46 MODULE_LICENSE("GPL");
48 extern atomic_t ip_conntrack_count;
49 DECLARE_PER_CPU(struct ip_conntrack_stat, ip_conntrack_stat);
51 static int kill_proto(struct ip_conntrack *i, void *data)
53 return (i->tuplehash[IP_CT_DIR_ORIGINAL].tuple.dst.protonum ==
54 *((u_int8_t *) data));
59 print_tuple(struct seq_file *s, const struct ip_conntrack_tuple *tuple,
60 struct ip_conntrack_protocol *proto)
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);
67 #ifdef CONFIG_IP_NF_CT_ACCT
69 seq_print_counters(struct seq_file *s,
70 const struct ip_conntrack_counter *counter)
72 return seq_printf(s, "packets=%llu bytes=%llu ",
73 (unsigned long long)counter->packets,
74 (unsigned long long)counter->bytes);
77 #define seq_print_counters(x, y) 0
80 struct ct_iter_state {
84 static struct list_head *ct_get_first(struct seq_file *seq)
86 struct ct_iter_state *st = seq->private;
89 st->bucket < ip_conntrack_htable_size;
91 if (!list_empty(&ip_conntrack_hash[st->bucket]))
92 return ip_conntrack_hash[st->bucket].next;
97 static struct list_head *ct_get_next(struct seq_file *seq, struct list_head *head)
99 struct ct_iter_state *st = seq->private;
102 while (head == &ip_conntrack_hash[st->bucket]) {
103 if (++st->bucket >= ip_conntrack_htable_size)
105 head = ip_conntrack_hash[st->bucket].next;
110 static struct list_head *ct_get_idx(struct seq_file *seq, loff_t pos)
112 struct list_head *head = ct_get_first(seq);
115 while (pos && (head = ct_get_next(seq, head)))
117 return pos ? NULL : head;
120 static void *ct_seq_start(struct seq_file *seq, loff_t *pos)
122 read_lock_bh(&ip_conntrack_lock);
123 return ct_get_idx(seq, *pos);
126 static void *ct_seq_next(struct seq_file *s, void *v, loff_t *pos)
129 return ct_get_next(s, v);
132 static void ct_seq_stop(struct seq_file *s, void *v)
134 read_unlock_bh(&ip_conntrack_lock);
137 static int ct_seq_show(struct seq_file *s, void *v)
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;
143 ASSERT_READ_LOCK(&ip_conntrack_lock);
144 IP_NF_ASSERT(conntrack);
146 /* we only want to print DIR_ORIGINAL */
150 proto = __ip_conntrack_proto_find(conntrack->tuplehash[IP_CT_DIR_ORIGINAL].tuple.dst.protonum);
153 if (seq_printf(s, "%-8s %u %ld ",
155 conntrack->tuplehash[IP_CT_DIR_ORIGINAL].tuple.dst.protonum,
156 timer_pending(&conntrack->timeout)
157 ? (long)(conntrack->timeout.expires - jiffies)/HZ
161 if (proto->print_conntrack(s, conntrack))
164 if (print_tuple(s, &conntrack->tuplehash[IP_CT_DIR_ORIGINAL].tuple,
168 if (seq_print_counters(s, &conntrack->counters[IP_CT_DIR_ORIGINAL]))
171 if (!(test_bit(IPS_SEEN_REPLY_BIT, &conntrack->status)))
172 if (seq_printf(s, "[UNREPLIED] "))
175 if (print_tuple(s, &conntrack->tuplehash[IP_CT_DIR_REPLY].tuple,
179 if (seq_print_counters(s, &conntrack->counters[IP_CT_DIR_REPLY]))
182 if (test_bit(IPS_ASSURED_BIT, &conntrack->status))
183 if (seq_printf(s, "[ASSURED] "))
186 #if defined(CONFIG_IP_NF_CONNTRACK_MARK)
187 if (seq_printf(s, "mark=%u ", conntrack->mark))
191 if (seq_printf(s, "use=%u\n", atomic_read(&conntrack->ct_general.use)))
197 static struct seq_operations ct_seq_ops = {
198 .start = ct_seq_start,
204 static int ct_open(struct inode *inode, struct file *file)
206 struct seq_file *seq;
207 struct ct_iter_state *st;
210 st = kmalloc(sizeof(struct ct_iter_state), GFP_KERNEL);
213 ret = seq_open(file, &ct_seq_ops);
216 seq = file->private_data;
218 memset(st, 0, sizeof(struct ct_iter_state));
225 static struct file_operations ct_file_ops = {
226 .owner = THIS_MODULE,
230 .release = seq_release_private,
234 static void *exp_seq_start(struct seq_file *s, loff_t *pos)
236 struct list_head *e = &ip_conntrack_expect_list;
239 /* strange seq_file api calls stop even if we fail,
240 * thus we need to grab lock since stop unlocks */
241 read_lock_bh(&ip_conntrack_lock);
246 for (i = 0; i <= *pos; i++) {
248 if (e == &ip_conntrack_expect_list)
254 static void *exp_seq_next(struct seq_file *s, void *v, loff_t *pos)
256 struct list_head *e = v;
261 if (e == &ip_conntrack_expect_list)
267 static void exp_seq_stop(struct seq_file *s, void *v)
269 read_unlock_bh(&ip_conntrack_lock);
272 static int exp_seq_show(struct seq_file *s, void *v)
274 struct ip_conntrack_expect *expect = v;
276 if (expect->timeout.function)
277 seq_printf(s, "%ld ", timer_pending(&expect->timeout)
278 ? (long)(expect->timeout.expires - jiffies)/HZ : 0);
282 seq_printf(s, "proto=%u ", expect->tuple.dst.protonum);
284 print_tuple(s, &expect->tuple,
285 __ip_conntrack_proto_find(expect->tuple.dst.protonum));
286 return seq_putc(s, '\n');
289 static struct seq_operations exp_seq_ops = {
290 .start = exp_seq_start,
291 .next = exp_seq_next,
292 .stop = exp_seq_stop,
296 static int exp_open(struct inode *inode, struct file *file)
298 return seq_open(file, &exp_seq_ops);
301 static struct file_operations exp_file_ops = {
302 .owner = THIS_MODULE,
306 .release = seq_release
309 static void *ct_cpu_seq_start(struct seq_file *seq, loff_t *pos)
314 return SEQ_START_TOKEN;
316 for (cpu = *pos-1; cpu < NR_CPUS; ++cpu) {
317 if (!cpu_possible(cpu))
320 return &per_cpu(ip_conntrack_stat, cpu);
326 static void *ct_cpu_seq_next(struct seq_file *seq, void *v, loff_t *pos)
330 for (cpu = *pos; cpu < NR_CPUS; ++cpu) {
331 if (!cpu_possible(cpu))
334 return &per_cpu(ip_conntrack_stat, cpu);
340 static void ct_cpu_seq_stop(struct seq_file *seq, void *v)
344 static int ct_cpu_seq_show(struct seq_file *seq, void *v)
346 unsigned int nr_conntracks = atomic_read(&ip_conntrack_count);
347 struct ip_conntrack_stat *st = v;
349 if (v == SEQ_START_TOKEN) {
350 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");
354 seq_printf(seq, "%08x %08x %08x %08x %08x %08x %08x %08x "
355 "%08x %08x %08x %08x %08x %08x %08x %08x \n",
377 static struct seq_operations ct_cpu_seq_ops = {
378 .start = ct_cpu_seq_start,
379 .next = ct_cpu_seq_next,
380 .stop = ct_cpu_seq_stop,
381 .show = ct_cpu_seq_show,
384 static int ct_cpu_seq_open(struct inode *inode, struct file *file)
386 return seq_open(file, &ct_cpu_seq_ops);
389 static struct file_operations ct_cpu_seq_fops = {
390 .owner = THIS_MODULE,
391 .open = ct_cpu_seq_open,
394 .release = seq_release_private,
398 static unsigned int ip_confirm(unsigned int hooknum,
399 struct sk_buff **pskb,
400 const struct net_device *in,
401 const struct net_device *out,
402 int (*okfn)(struct sk_buff *))
404 /* We've seen it coming out the other side: confirm it */
405 return ip_conntrack_confirm(pskb);
408 static unsigned int ip_conntrack_help(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 struct ip_conntrack *ct;
415 enum ip_conntrack_info ctinfo;
417 /* This is where we call the helper: as the packet goes out. */
418 ct = ip_conntrack_get(*pskb, &ctinfo);
419 if (ct && ct->helper) {
421 ret = ct->helper->help(pskb, ct, ctinfo);
422 if (ret != NF_ACCEPT)
428 static unsigned int ip_conntrack_defrag(unsigned int hooknum,
429 struct sk_buff **pskb,
430 const struct net_device *in,
431 const struct net_device *out,
432 int (*okfn)(struct sk_buff *))
434 #if !defined(CONFIG_IP_NF_NAT) && !defined(CONFIG_IP_NF_NAT_MODULE)
435 /* Previously seen (loopback)? Ignore. Do this before
441 /* Gather fragments. */
442 if ((*pskb)->nh.iph->frag_off & htons(IP_MF|IP_OFFSET)) {
443 *pskb = ip_ct_gather_frags(*pskb,
444 hooknum == NF_IP_PRE_ROUTING ?
445 IP_DEFRAG_CONNTRACK_IN :
446 IP_DEFRAG_CONNTRACK_OUT);
453 static unsigned int ip_refrag(unsigned int hooknum,
454 struct sk_buff **pskb,
455 const struct net_device *in,
456 const struct net_device *out,
457 int (*okfn)(struct sk_buff *))
459 struct rtable *rt = (struct rtable *)(*pskb)->dst;
461 /* We've seen it coming out the other side: confirm */
462 if (ip_confirm(hooknum, pskb, in, out, okfn) != NF_ACCEPT)
465 /* Local packets are never produced too large for their
466 interface. We degfragment them at LOCAL_OUT, however,
467 so we have to refragment them here. */
468 if ((*pskb)->len > dst_mtu(&rt->u.dst) &&
469 !skb_shinfo(*pskb)->tso_size) {
470 /* No hook can be after us, so this should be OK. */
471 ip_fragment(*pskb, okfn);
477 static unsigned int ip_conntrack_local(unsigned int hooknum,
478 struct sk_buff **pskb,
479 const struct net_device *in,
480 const struct net_device *out,
481 int (*okfn)(struct sk_buff *))
483 /* root is playing with raw sockets. */
484 if ((*pskb)->len < sizeof(struct iphdr)
485 || (*pskb)->nh.iph->ihl * 4 < sizeof(struct iphdr)) {
487 printk("ipt_hook: happy cracking.\n");
490 return ip_conntrack_in(hooknum, pskb, in, out, okfn);
493 /* Connection tracking may drop packets, but never alters them, so
494 make it the first hook. */
495 static struct nf_hook_ops ip_conntrack_defrag_ops = {
496 .hook = ip_conntrack_defrag,
497 .owner = THIS_MODULE,
499 .hooknum = NF_IP_PRE_ROUTING,
500 .priority = NF_IP_PRI_CONNTRACK_DEFRAG,
503 static struct nf_hook_ops ip_conntrack_in_ops = {
504 .hook = ip_conntrack_in,
505 .owner = THIS_MODULE,
507 .hooknum = NF_IP_PRE_ROUTING,
508 .priority = NF_IP_PRI_CONNTRACK,
511 static struct nf_hook_ops ip_conntrack_defrag_local_out_ops = {
512 .hook = ip_conntrack_defrag,
513 .owner = THIS_MODULE,
515 .hooknum = NF_IP_LOCAL_OUT,
516 .priority = NF_IP_PRI_CONNTRACK_DEFRAG,
519 static struct nf_hook_ops ip_conntrack_local_out_ops = {
520 .hook = ip_conntrack_local,
521 .owner = THIS_MODULE,
523 .hooknum = NF_IP_LOCAL_OUT,
524 .priority = NF_IP_PRI_CONNTRACK,
528 static struct nf_hook_ops ip_conntrack_helper_out_ops = {
529 .hook = ip_conntrack_help,
530 .owner = THIS_MODULE,
532 .hooknum = NF_IP_POST_ROUTING,
533 .priority = NF_IP_PRI_CONNTRACK_HELPER,
536 static struct nf_hook_ops ip_conntrack_helper_in_ops = {
537 .hook = ip_conntrack_help,
538 .owner = THIS_MODULE,
540 .hooknum = NF_IP_LOCAL_IN,
541 .priority = NF_IP_PRI_CONNTRACK_HELPER,
544 /* Refragmenter; last chance. */
545 static struct nf_hook_ops ip_conntrack_out_ops = {
547 .owner = THIS_MODULE,
549 .hooknum = NF_IP_POST_ROUTING,
550 .priority = NF_IP_PRI_CONNTRACK_CONFIRM,
553 static struct nf_hook_ops ip_conntrack_local_in_ops = {
555 .owner = THIS_MODULE,
557 .hooknum = NF_IP_LOCAL_IN,
558 .priority = NF_IP_PRI_CONNTRACK_CONFIRM,
565 /* From ip_conntrack_core.c */
566 extern int ip_conntrack_max;
567 extern unsigned int ip_conntrack_htable_size;
569 /* From ip_conntrack_proto_tcp.c */
570 extern unsigned long ip_ct_tcp_timeout_syn_sent;
571 extern unsigned long ip_ct_tcp_timeout_syn_recv;
572 extern unsigned long ip_ct_tcp_timeout_established;
573 extern unsigned long ip_ct_tcp_timeout_fin_wait;
574 extern unsigned long ip_ct_tcp_timeout_close_wait;
575 extern unsigned long ip_ct_tcp_timeout_last_ack;
576 extern unsigned long ip_ct_tcp_timeout_time_wait;
577 extern unsigned long ip_ct_tcp_timeout_close;
578 extern unsigned long ip_ct_tcp_timeout_max_retrans;
579 extern int ip_ct_tcp_loose;
580 extern int ip_ct_tcp_be_liberal;
581 extern int ip_ct_tcp_max_retrans;
583 /* From ip_conntrack_proto_udp.c */
584 extern unsigned long ip_ct_udp_timeout;
585 extern unsigned long ip_ct_udp_timeout_stream;
587 /* From ip_conntrack_proto_icmp.c */
588 extern unsigned long ip_ct_icmp_timeout;
590 /* From ip_conntrack_proto_icmp.c */
591 extern unsigned long ip_ct_generic_timeout;
593 /* Log invalid packets of a given protocol */
594 static int log_invalid_proto_min = 0;
595 static int log_invalid_proto_max = 255;
597 static struct ctl_table_header *ip_ct_sysctl_header;
599 static ctl_table ip_ct_sysctl_table[] = {
601 .ctl_name = NET_IPV4_NF_CONNTRACK_MAX,
602 .procname = "ip_conntrack_max",
603 .data = &ip_conntrack_max,
604 .maxlen = sizeof(int),
606 .proc_handler = &proc_dointvec,
609 .ctl_name = NET_IPV4_NF_CONNTRACK_COUNT,
610 .procname = "ip_conntrack_count",
611 .data = &ip_conntrack_count,
612 .maxlen = sizeof(int),
614 .proc_handler = &proc_dointvec,
617 .ctl_name = NET_IPV4_NF_CONNTRACK_BUCKETS,
618 .procname = "ip_conntrack_buckets",
619 .data = &ip_conntrack_htable_size,
620 .maxlen = sizeof(unsigned int),
622 .proc_handler = &proc_dointvec,
625 .ctl_name = NET_IPV4_NF_CONNTRACK_TCP_TIMEOUT_SYN_SENT,
626 .procname = "ip_conntrack_tcp_timeout_syn_sent",
627 .data = &ip_ct_tcp_timeout_syn_sent,
628 .maxlen = sizeof(unsigned int),
630 .proc_handler = &proc_dointvec_jiffies,
633 .ctl_name = NET_IPV4_NF_CONNTRACK_TCP_TIMEOUT_SYN_RECV,
634 .procname = "ip_conntrack_tcp_timeout_syn_recv",
635 .data = &ip_ct_tcp_timeout_syn_recv,
636 .maxlen = sizeof(unsigned int),
638 .proc_handler = &proc_dointvec_jiffies,
641 .ctl_name = NET_IPV4_NF_CONNTRACK_TCP_TIMEOUT_ESTABLISHED,
642 .procname = "ip_conntrack_tcp_timeout_established",
643 .data = &ip_ct_tcp_timeout_established,
644 .maxlen = sizeof(unsigned int),
646 .proc_handler = &proc_dointvec_jiffies,
649 .ctl_name = NET_IPV4_NF_CONNTRACK_TCP_TIMEOUT_FIN_WAIT,
650 .procname = "ip_conntrack_tcp_timeout_fin_wait",
651 .data = &ip_ct_tcp_timeout_fin_wait,
652 .maxlen = sizeof(unsigned int),
654 .proc_handler = &proc_dointvec_jiffies,
657 .ctl_name = NET_IPV4_NF_CONNTRACK_TCP_TIMEOUT_CLOSE_WAIT,
658 .procname = "ip_conntrack_tcp_timeout_close_wait",
659 .data = &ip_ct_tcp_timeout_close_wait,
660 .maxlen = sizeof(unsigned int),
662 .proc_handler = &proc_dointvec_jiffies,
665 .ctl_name = NET_IPV4_NF_CONNTRACK_TCP_TIMEOUT_LAST_ACK,
666 .procname = "ip_conntrack_tcp_timeout_last_ack",
667 .data = &ip_ct_tcp_timeout_last_ack,
668 .maxlen = sizeof(unsigned int),
670 .proc_handler = &proc_dointvec_jiffies,
673 .ctl_name = NET_IPV4_NF_CONNTRACK_TCP_TIMEOUT_TIME_WAIT,
674 .procname = "ip_conntrack_tcp_timeout_time_wait",
675 .data = &ip_ct_tcp_timeout_time_wait,
676 .maxlen = sizeof(unsigned int),
678 .proc_handler = &proc_dointvec_jiffies,
681 .ctl_name = NET_IPV4_NF_CONNTRACK_TCP_TIMEOUT_CLOSE,
682 .procname = "ip_conntrack_tcp_timeout_close",
683 .data = &ip_ct_tcp_timeout_close,
684 .maxlen = sizeof(unsigned int),
686 .proc_handler = &proc_dointvec_jiffies,
689 .ctl_name = NET_IPV4_NF_CONNTRACK_UDP_TIMEOUT,
690 .procname = "ip_conntrack_udp_timeout",
691 .data = &ip_ct_udp_timeout,
692 .maxlen = sizeof(unsigned int),
694 .proc_handler = &proc_dointvec_jiffies,
697 .ctl_name = NET_IPV4_NF_CONNTRACK_UDP_TIMEOUT_STREAM,
698 .procname = "ip_conntrack_udp_timeout_stream",
699 .data = &ip_ct_udp_timeout_stream,
700 .maxlen = sizeof(unsigned int),
702 .proc_handler = &proc_dointvec_jiffies,
705 .ctl_name = NET_IPV4_NF_CONNTRACK_ICMP_TIMEOUT,
706 .procname = "ip_conntrack_icmp_timeout",
707 .data = &ip_ct_icmp_timeout,
708 .maxlen = sizeof(unsigned int),
710 .proc_handler = &proc_dointvec_jiffies,
713 .ctl_name = NET_IPV4_NF_CONNTRACK_GENERIC_TIMEOUT,
714 .procname = "ip_conntrack_generic_timeout",
715 .data = &ip_ct_generic_timeout,
716 .maxlen = sizeof(unsigned int),
718 .proc_handler = &proc_dointvec_jiffies,
721 .ctl_name = NET_IPV4_NF_CONNTRACK_LOG_INVALID,
722 .procname = "ip_conntrack_log_invalid",
723 .data = &ip_ct_log_invalid,
724 .maxlen = sizeof(unsigned int),
726 .proc_handler = &proc_dointvec_minmax,
727 .strategy = &sysctl_intvec,
728 .extra1 = &log_invalid_proto_min,
729 .extra2 = &log_invalid_proto_max,
732 .ctl_name = NET_IPV4_NF_CONNTRACK_TCP_TIMEOUT_MAX_RETRANS,
733 .procname = "ip_conntrack_tcp_timeout_max_retrans",
734 .data = &ip_ct_tcp_timeout_max_retrans,
735 .maxlen = sizeof(unsigned int),
737 .proc_handler = &proc_dointvec_jiffies,
740 .ctl_name = NET_IPV4_NF_CONNTRACK_TCP_LOOSE,
741 .procname = "ip_conntrack_tcp_loose",
742 .data = &ip_ct_tcp_loose,
743 .maxlen = sizeof(unsigned int),
745 .proc_handler = &proc_dointvec,
748 .ctl_name = NET_IPV4_NF_CONNTRACK_TCP_BE_LIBERAL,
749 .procname = "ip_conntrack_tcp_be_liberal",
750 .data = &ip_ct_tcp_be_liberal,
751 .maxlen = sizeof(unsigned int),
753 .proc_handler = &proc_dointvec,
756 .ctl_name = NET_IPV4_NF_CONNTRACK_TCP_MAX_RETRANS,
757 .procname = "ip_conntrack_tcp_max_retrans",
758 .data = &ip_ct_tcp_max_retrans,
759 .maxlen = sizeof(unsigned int),
761 .proc_handler = &proc_dointvec,
766 #define NET_IP_CONNTRACK_MAX 2089
768 static ctl_table ip_ct_netfilter_table[] = {
770 .ctl_name = NET_IPV4_NETFILTER,
771 .procname = "netfilter",
773 .child = ip_ct_sysctl_table,
776 .ctl_name = NET_IP_CONNTRACK_MAX,
777 .procname = "ip_conntrack_max",
778 .data = &ip_conntrack_max,
779 .maxlen = sizeof(int),
781 .proc_handler = &proc_dointvec
786 static ctl_table ip_ct_ipv4_table[] = {
788 .ctl_name = NET_IPV4,
791 .child = ip_ct_netfilter_table,
796 static ctl_table ip_ct_net_table[] = {
801 .child = ip_ct_ipv4_table,
806 EXPORT_SYMBOL(ip_ct_log_invalid);
807 #endif /* CONFIG_SYSCTL */
809 static int init_or_cleanup(int init)
811 #ifdef CONFIG_PROC_FS
812 struct proc_dir_entry *proc, *proc_exp, *proc_stat;
816 if (!init) goto cleanup;
818 ret = ip_conntrack_init();
820 goto cleanup_nothing;
822 #ifdef CONFIG_PROC_FS
824 proc = proc_net_fops_create("ip_conntrack", 0440, &ct_file_ops);
825 if (!proc) goto cleanup_init;
827 proc_exp = proc_net_fops_create("ip_conntrack_expect", 0440,
829 if (!proc_exp) goto cleanup_proc;
831 proc_stat = create_proc_entry("ip_conntrack", S_IRUGO, proc_net_stat);
833 goto cleanup_proc_exp;
835 proc_stat->proc_fops = &ct_cpu_seq_fops;
836 proc_stat->owner = THIS_MODULE;
839 ret = nf_register_hook(&ip_conntrack_defrag_ops);
841 printk("ip_conntrack: can't register pre-routing defrag hook.\n");
842 goto cleanup_proc_stat;
844 ret = nf_register_hook(&ip_conntrack_defrag_local_out_ops);
846 printk("ip_conntrack: can't register local_out defrag hook.\n");
847 goto cleanup_defragops;
849 ret = nf_register_hook(&ip_conntrack_in_ops);
851 printk("ip_conntrack: can't register pre-routing hook.\n");
852 goto cleanup_defraglocalops;
854 ret = nf_register_hook(&ip_conntrack_local_out_ops);
856 printk("ip_conntrack: can't register local out hook.\n");
859 ret = nf_register_hook(&ip_conntrack_helper_in_ops);
861 printk("ip_conntrack: can't register local in helper hook.\n");
862 goto cleanup_inandlocalops;
864 ret = nf_register_hook(&ip_conntrack_helper_out_ops);
866 printk("ip_conntrack: can't register postrouting helper hook.\n");
867 goto cleanup_helperinops;
869 ret = nf_register_hook(&ip_conntrack_out_ops);
871 printk("ip_conntrack: can't register post-routing hook.\n");
872 goto cleanup_helperoutops;
874 ret = nf_register_hook(&ip_conntrack_local_in_ops);
876 printk("ip_conntrack: can't register local in hook.\n");
877 goto cleanup_inoutandlocalops;
880 ip_ct_sysctl_header = register_sysctl_table(ip_ct_net_table, 0);
881 if (ip_ct_sysctl_header == NULL) {
882 printk("ip_conntrack: can't register to sysctl.\n");
884 goto cleanup_localinops;
893 unregister_sysctl_table(ip_ct_sysctl_header);
896 nf_unregister_hook(&ip_conntrack_local_in_ops);
897 cleanup_inoutandlocalops:
898 nf_unregister_hook(&ip_conntrack_out_ops);
899 cleanup_helperoutops:
900 nf_unregister_hook(&ip_conntrack_helper_out_ops);
902 nf_unregister_hook(&ip_conntrack_helper_in_ops);
903 cleanup_inandlocalops:
904 nf_unregister_hook(&ip_conntrack_local_out_ops);
906 nf_unregister_hook(&ip_conntrack_in_ops);
907 cleanup_defraglocalops:
908 nf_unregister_hook(&ip_conntrack_defrag_local_out_ops);
910 nf_unregister_hook(&ip_conntrack_defrag_ops);
912 #ifdef CONFIG_PROC_FS
913 remove_proc_entry("ip_conntrack", proc_net_stat);
915 proc_net_remove("ip_conntrack_expect");
917 proc_net_remove("ip_conntrack");
919 #endif /* CONFIG_PROC_FS */
920 ip_conntrack_cleanup();
925 /* FIXME: Allow NULL functions and sub in pointers to generic for
927 int ip_conntrack_protocol_register(struct ip_conntrack_protocol *proto)
931 write_lock_bh(&ip_conntrack_lock);
932 if (ip_ct_protos[proto->proto] != &ip_conntrack_generic_protocol) {
936 ip_ct_protos[proto->proto] = proto;
938 write_unlock_bh(&ip_conntrack_lock);
942 void ip_conntrack_protocol_unregister(struct ip_conntrack_protocol *proto)
944 write_lock_bh(&ip_conntrack_lock);
945 ip_ct_protos[proto->proto] = &ip_conntrack_generic_protocol;
946 write_unlock_bh(&ip_conntrack_lock);
948 /* Somebody could be still looking at the proto in bh. */
951 /* Remove all contrack entries for this protocol */
952 ip_ct_iterate_cleanup(kill_proto, &proto->proto);
955 static int __init init(void)
957 return init_or_cleanup(1);
960 static void __exit fini(void)
968 /* Some modules need us, but don't depend directly on any symbol.
969 They should call this. */
970 void need_ip_conntrack(void)
974 #ifdef CONFIG_IP_NF_CONNTRACK_EVENTS
975 EXPORT_SYMBOL_GPL(ip_conntrack_chain);
976 EXPORT_SYMBOL_GPL(ip_conntrack_expect_chain);
977 EXPORT_SYMBOL_GPL(ip_conntrack_register_notifier);
978 EXPORT_SYMBOL_GPL(ip_conntrack_unregister_notifier);
979 EXPORT_SYMBOL_GPL(__ip_ct_event_cache_init);
980 EXPORT_PER_CPU_SYMBOL_GPL(ip_conntrack_ecache);
982 EXPORT_SYMBOL(ip_conntrack_protocol_register);
983 EXPORT_SYMBOL(ip_conntrack_protocol_unregister);
984 EXPORT_SYMBOL(ip_ct_get_tuple);
985 EXPORT_SYMBOL(invert_tuplepr);
986 EXPORT_SYMBOL(ip_conntrack_alter_reply);
987 EXPORT_SYMBOL(ip_conntrack_destroyed);
988 EXPORT_SYMBOL(need_ip_conntrack);
989 EXPORT_SYMBOL(ip_conntrack_helper_register);
990 EXPORT_SYMBOL(ip_conntrack_helper_unregister);
991 EXPORT_SYMBOL(ip_ct_iterate_cleanup);
992 EXPORT_SYMBOL(__ip_ct_refresh_acct);
994 EXPORT_SYMBOL(ip_conntrack_expect_alloc);
995 EXPORT_SYMBOL(ip_conntrack_expect_put);
996 EXPORT_SYMBOL_GPL(__ip_conntrack_expect_find);
997 EXPORT_SYMBOL_GPL(ip_conntrack_expect_find);
998 EXPORT_SYMBOL(ip_conntrack_expect_related);
999 EXPORT_SYMBOL(ip_conntrack_unexpect_related);
1000 EXPORT_SYMBOL_GPL(ip_conntrack_expect_list);
1001 EXPORT_SYMBOL_GPL(ip_ct_unlink_expect);
1003 EXPORT_SYMBOL(ip_conntrack_tuple_taken);
1004 EXPORT_SYMBOL(ip_ct_gather_frags);
1005 EXPORT_SYMBOL(ip_conntrack_htable_size);
1006 EXPORT_SYMBOL(ip_conntrack_lock);
1007 EXPORT_SYMBOL(ip_conntrack_hash);
1008 EXPORT_SYMBOL(ip_conntrack_untracked);
1009 EXPORT_SYMBOL_GPL(ip_conntrack_find_get);
1010 #ifdef CONFIG_IP_NF_NAT_NEEDED
1011 EXPORT_SYMBOL(ip_conntrack_tcp_update);
1014 EXPORT_SYMBOL_GPL(ip_conntrack_flush);
1015 EXPORT_SYMBOL_GPL(__ip_conntrack_find);
1017 EXPORT_SYMBOL_GPL(ip_conntrack_alloc);
1018 EXPORT_SYMBOL_GPL(ip_conntrack_free);
1019 EXPORT_SYMBOL_GPL(ip_conntrack_hash_insert);
1021 EXPORT_SYMBOL_GPL(ip_ct_remove_expectations);
1023 EXPORT_SYMBOL_GPL(ip_conntrack_helper_find_get);
1024 EXPORT_SYMBOL_GPL(ip_conntrack_helper_put);
1025 EXPORT_SYMBOL_GPL(__ip_conntrack_helper_find_byname);
1027 EXPORT_SYMBOL_GPL(ip_conntrack_proto_find_get);
1028 EXPORT_SYMBOL_GPL(ip_conntrack_proto_put);
1029 EXPORT_SYMBOL_GPL(__ip_conntrack_proto_find);
1030 #if defined(CONFIG_IP_NF_CONNTRACK_NETLINK) || \
1031 defined(CONFIG_IP_NF_CONNTRACK_NETLINK_MODULE)
1032 EXPORT_SYMBOL_GPL(ip_ct_port_tuple_to_nfattr);
1033 EXPORT_SYMBOL_GPL(ip_ct_port_nfattr_to_tuple);