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>
30 #include <net/route.h>
32 #define ASSERT_READ_LOCK(x)
33 #define ASSERT_WRITE_LOCK(x)
35 #include <linux/netfilter_ipv4/ip_conntrack.h>
36 #include <linux/netfilter_ipv4/ip_conntrack_protocol.h>
37 #include <linux/netfilter_ipv4/ip_conntrack_core.h>
38 #include <linux/netfilter_ipv4/ip_conntrack_helper.h>
39 #include <linux/netfilter_ipv4/listhelp.h>
44 #define DEBUGP(format, args...)
47 MODULE_LICENSE("GPL");
49 extern atomic_t ip_conntrack_count;
50 DECLARE_PER_CPU(struct ip_conntrack_stat, ip_conntrack_stat);
52 static int kill_proto(struct ip_conntrack *i, void *data)
54 return (i->tuplehash[IP_CT_DIR_ORIGINAL].tuple.dst.protonum ==
55 *((u_int8_t *) data));
60 print_tuple(struct seq_file *s, const struct ip_conntrack_tuple *tuple,
61 struct ip_conntrack_protocol *proto)
63 seq_printf(s, "src=%u.%u.%u.%u dst=%u.%u.%u.%u ",
64 NIPQUAD(tuple->src.ip), NIPQUAD(tuple->dst.ip));
65 return proto->print_tuple(s, tuple);
68 #ifdef CONFIG_IP_NF_CT_ACCT
70 seq_print_counters(struct seq_file *s,
71 const struct ip_conntrack_counter *counter)
73 return seq_printf(s, "packets=%llu bytes=%llu ",
74 (unsigned long long)counter->packets,
75 (unsigned long long)counter->bytes);
78 #define seq_print_counters(x, y) 0
81 struct ct_iter_state {
85 static struct list_head *ct_get_first(struct seq_file *seq)
87 struct ct_iter_state *st = seq->private;
90 st->bucket < ip_conntrack_htable_size;
92 if (!list_empty(&ip_conntrack_hash[st->bucket]))
93 return ip_conntrack_hash[st->bucket].next;
98 static struct list_head *ct_get_next(struct seq_file *seq, struct list_head *head)
100 struct ct_iter_state *st = seq->private;
103 while (head == &ip_conntrack_hash[st->bucket]) {
104 if (++st->bucket >= ip_conntrack_htable_size)
106 head = ip_conntrack_hash[st->bucket].next;
111 static struct list_head *ct_get_idx(struct seq_file *seq, loff_t pos)
113 struct list_head *head = ct_get_first(seq);
116 while (pos && (head = ct_get_next(seq, head)))
118 return pos ? NULL : head;
121 static void *ct_seq_start(struct seq_file *seq, loff_t *pos)
123 read_lock_bh(&ip_conntrack_lock);
124 return ct_get_idx(seq, *pos);
127 static void *ct_seq_next(struct seq_file *s, void *v, loff_t *pos)
130 return ct_get_next(s, v);
133 static void ct_seq_stop(struct seq_file *s, void *v)
135 read_unlock_bh(&ip_conntrack_lock);
138 static int ct_seq_show(struct seq_file *s, void *v)
140 const struct ip_conntrack_tuple_hash *hash = v;
141 const struct ip_conntrack *conntrack = tuplehash_to_ctrack(hash);
142 struct ip_conntrack_protocol *proto;
144 ASSERT_READ_LOCK(&ip_conntrack_lock);
145 IP_NF_ASSERT(conntrack);
147 /* we only want to print DIR_ORIGINAL */
151 proto = __ip_conntrack_proto_find(conntrack->tuplehash[IP_CT_DIR_ORIGINAL].tuple.dst.protonum);
154 if (seq_printf(s, "%-8s %u %ld ",
156 conntrack->tuplehash[IP_CT_DIR_ORIGINAL].tuple.dst.protonum,
157 timer_pending(&conntrack->timeout)
158 ? (long)(conntrack->timeout.expires - jiffies)/HZ
162 if (proto->print_conntrack(s, conntrack))
165 if (print_tuple(s, &conntrack->tuplehash[IP_CT_DIR_ORIGINAL].tuple,
169 #if defined(CONFIG_VNET) || defined(CONFIG_VNET_MODULE)
170 if (seq_printf(s, "xid=%d\n", conntrack->xid[IP_CT_DIR_ORIGINAL]))
174 if (seq_print_counters(s, &conntrack->counters[IP_CT_DIR_ORIGINAL]))
177 if (!(test_bit(IPS_SEEN_REPLY_BIT, &conntrack->status)))
178 if (seq_printf(s, "[UNREPLIED] "))
181 if (print_tuple(s, &conntrack->tuplehash[IP_CT_DIR_REPLY].tuple,
185 #if defined(CONFIG_VNET) || defined(CONFIG_VNET_MODULE)
186 if (seq_printf(s, "xid=%d\n", conntrack->xid[IP_CT_DIR_REPLY]))
190 if (seq_print_counters(s, &conntrack->counters[IP_CT_DIR_REPLY]))
193 if (test_bit(IPS_ASSURED_BIT, &conntrack->status))
194 if (seq_printf(s, "[ASSURED] "))
197 #if defined(CONFIG_IP_NF_CONNTRACK_MARK)
198 if (seq_printf(s, "mark=%u ", conntrack->mark))
202 if (seq_printf(s, "use=%u\n", atomic_read(&conntrack->ct_general.use)))
208 static struct seq_operations ct_seq_ops = {
209 .start = ct_seq_start,
215 static int ct_open(struct inode *inode, struct file *file)
217 struct seq_file *seq;
218 struct ct_iter_state *st;
221 st = kmalloc(sizeof(struct ct_iter_state), GFP_KERNEL);
224 ret = seq_open(file, &ct_seq_ops);
227 seq = file->private_data;
229 memset(st, 0, sizeof(struct ct_iter_state));
236 static struct file_operations ct_file_ops = {
237 .owner = THIS_MODULE,
241 .release = seq_release_private,
245 static void *exp_seq_start(struct seq_file *s, loff_t *pos)
247 struct list_head *e = &ip_conntrack_expect_list;
250 /* strange seq_file api calls stop even if we fail,
251 * thus we need to grab lock since stop unlocks */
252 read_lock_bh(&ip_conntrack_lock);
257 for (i = 0; i <= *pos; i++) {
259 if (e == &ip_conntrack_expect_list)
265 static void *exp_seq_next(struct seq_file *s, void *v, loff_t *pos)
267 struct list_head *e = v;
272 if (e == &ip_conntrack_expect_list)
278 static void exp_seq_stop(struct seq_file *s, void *v)
280 read_unlock_bh(&ip_conntrack_lock);
283 static int exp_seq_show(struct seq_file *s, void *v)
285 struct ip_conntrack_expect *expect = v;
287 if (expect->timeout.function)
288 seq_printf(s, "%ld ", timer_pending(&expect->timeout)
289 ? (long)(expect->timeout.expires - jiffies)/HZ : 0);
293 seq_printf(s, "proto=%u ", expect->tuple.dst.protonum);
295 print_tuple(s, &expect->tuple,
296 __ip_conntrack_proto_find(expect->tuple.dst.protonum));
297 return seq_putc(s, '\n');
300 static struct seq_operations exp_seq_ops = {
301 .start = exp_seq_start,
302 .next = exp_seq_next,
303 .stop = exp_seq_stop,
307 static int exp_open(struct inode *inode, struct file *file)
309 return seq_open(file, &exp_seq_ops);
312 static struct file_operations exp_file_ops = {
313 .owner = THIS_MODULE,
317 .release = seq_release
320 static void *ct_cpu_seq_start(struct seq_file *seq, loff_t *pos)
325 return SEQ_START_TOKEN;
327 for (cpu = *pos-1; cpu < NR_CPUS; ++cpu) {
328 if (!cpu_possible(cpu))
331 return &per_cpu(ip_conntrack_stat, cpu);
337 static void *ct_cpu_seq_next(struct seq_file *seq, void *v, loff_t *pos)
341 for (cpu = *pos; cpu < NR_CPUS; ++cpu) {
342 if (!cpu_possible(cpu))
345 return &per_cpu(ip_conntrack_stat, cpu);
351 static void ct_cpu_seq_stop(struct seq_file *seq, void *v)
355 static int ct_cpu_seq_show(struct seq_file *seq, void *v)
357 unsigned int nr_conntracks = atomic_read(&ip_conntrack_count);
358 struct ip_conntrack_stat *st = v;
360 if (v == SEQ_START_TOKEN) {
361 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");
365 seq_printf(seq, "%08x %08x %08x %08x %08x %08x %08x %08x "
366 "%08x %08x %08x %08x %08x %08x %08x %08x \n",
388 static struct seq_operations ct_cpu_seq_ops = {
389 .start = ct_cpu_seq_start,
390 .next = ct_cpu_seq_next,
391 .stop = ct_cpu_seq_stop,
392 .show = ct_cpu_seq_show,
395 static int ct_cpu_seq_open(struct inode *inode, struct file *file)
397 return seq_open(file, &ct_cpu_seq_ops);
400 static struct file_operations ct_cpu_seq_fops = {
401 .owner = THIS_MODULE,
402 .open = ct_cpu_seq_open,
405 .release = seq_release_private,
409 static unsigned int ip_confirm(unsigned int hooknum,
410 struct sk_buff **pskb,
411 const struct net_device *in,
412 const struct net_device *out,
413 int (*okfn)(struct sk_buff *))
415 /* We've seen it coming out the other side: confirm it */
416 return ip_conntrack_confirm(pskb);
419 static unsigned int ip_conntrack_help(unsigned int hooknum,
420 struct sk_buff **pskb,
421 const struct net_device *in,
422 const struct net_device *out,
423 int (*okfn)(struct sk_buff *))
425 struct ip_conntrack *ct;
426 enum ip_conntrack_info ctinfo;
428 /* This is where we call the helper: as the packet goes out. */
429 ct = ip_conntrack_get(*pskb, &ctinfo);
430 if (ct && ct->helper) {
432 ret = ct->helper->help(pskb, ct, ctinfo);
433 if (ret != NF_ACCEPT)
439 static unsigned int ip_conntrack_defrag(unsigned int hooknum,
440 struct sk_buff **pskb,
441 const struct net_device *in,
442 const struct net_device *out,
443 int (*okfn)(struct sk_buff *))
445 #if !defined(CONFIG_IP_NF_NAT) && !defined(CONFIG_IP_NF_NAT_MODULE)
446 /* Previously seen (loopback)? Ignore. Do this before
452 /* Gather fragments. */
453 if ((*pskb)->nh.iph->frag_off & htons(IP_MF|IP_OFFSET)) {
454 *pskb = ip_ct_gather_frags(*pskb,
455 hooknum == NF_IP_PRE_ROUTING ?
456 IP_DEFRAG_CONNTRACK_IN :
457 IP_DEFRAG_CONNTRACK_OUT);
464 static unsigned int ip_conntrack_local(unsigned int hooknum,
465 struct sk_buff **pskb,
466 const struct net_device *in,
467 const struct net_device *out,
468 int (*okfn)(struct sk_buff *))
470 /* root is playing with raw sockets. */
471 if ((*pskb)->len < sizeof(struct iphdr)
472 || (*pskb)->nh.iph->ihl * 4 < sizeof(struct iphdr)) {
474 printk("ipt_hook: happy cracking.\n");
477 return ip_conntrack_in(hooknum, pskb, in, out, okfn);
480 /* Connection tracking may drop packets, but never alters them, so
481 make it the first hook. */
482 static struct nf_hook_ops ip_conntrack_defrag_ops = {
483 .hook = ip_conntrack_defrag,
484 .owner = THIS_MODULE,
486 .hooknum = NF_IP_PRE_ROUTING,
487 .priority = NF_IP_PRI_CONNTRACK_DEFRAG,
490 static struct nf_hook_ops ip_conntrack_in_ops = {
491 .hook = ip_conntrack_in,
492 .owner = THIS_MODULE,
494 .hooknum = NF_IP_PRE_ROUTING,
495 .priority = NF_IP_PRI_CONNTRACK,
498 static struct nf_hook_ops ip_conntrack_defrag_local_out_ops = {
499 .hook = ip_conntrack_defrag,
500 .owner = THIS_MODULE,
502 .hooknum = NF_IP_LOCAL_OUT,
503 .priority = NF_IP_PRI_CONNTRACK_DEFRAG,
506 static struct nf_hook_ops ip_conntrack_local_out_ops = {
507 .hook = ip_conntrack_local,
508 .owner = THIS_MODULE,
510 .hooknum = NF_IP_LOCAL_OUT,
511 .priority = NF_IP_PRI_CONNTRACK,
515 static struct nf_hook_ops ip_conntrack_helper_out_ops = {
516 .hook = ip_conntrack_help,
517 .owner = THIS_MODULE,
519 .hooknum = NF_IP_POST_ROUTING,
520 .priority = NF_IP_PRI_CONNTRACK_HELPER,
523 static struct nf_hook_ops ip_conntrack_helper_in_ops = {
524 .hook = ip_conntrack_help,
525 .owner = THIS_MODULE,
527 .hooknum = NF_IP_LOCAL_IN,
528 .priority = NF_IP_PRI_CONNTRACK_HELPER,
531 /* Refragmenter; last chance. */
532 static struct nf_hook_ops ip_conntrack_out_ops = {
534 .owner = THIS_MODULE,
536 .hooknum = NF_IP_POST_ROUTING,
537 .priority = NF_IP_PRI_CONNTRACK_CONFIRM,
540 static struct nf_hook_ops ip_conntrack_local_in_ops = {
542 .owner = THIS_MODULE,
544 .hooknum = NF_IP_LOCAL_IN,
545 .priority = NF_IP_PRI_CONNTRACK_CONFIRM,
552 /* From ip_conntrack_core.c */
553 extern int ip_conntrack_max;
554 extern unsigned int ip_conntrack_htable_size;
556 /* From ip_conntrack_proto_tcp.c */
557 extern unsigned int ip_ct_tcp_timeout_syn_sent;
558 extern unsigned int ip_ct_tcp_timeout_syn_recv;
559 extern unsigned int ip_ct_tcp_timeout_established;
560 extern unsigned int ip_ct_tcp_timeout_fin_wait;
561 extern unsigned int ip_ct_tcp_timeout_close_wait;
562 extern unsigned int ip_ct_tcp_timeout_last_ack;
563 extern unsigned int ip_ct_tcp_timeout_time_wait;
564 extern unsigned int ip_ct_tcp_timeout_close;
565 extern unsigned int ip_ct_tcp_timeout_max_retrans;
566 extern int ip_ct_tcp_loose;
567 extern int ip_ct_tcp_be_liberal;
568 extern int ip_ct_tcp_max_retrans;
570 /* From ip_conntrack_proto_udp.c */
571 extern unsigned int ip_ct_udp_timeout;
572 extern unsigned int ip_ct_udp_timeout_stream;
574 /* From ip_conntrack_proto_icmp.c */
575 extern unsigned int ip_ct_icmp_timeout;
577 /* From ip_conntrack_proto_icmp.c */
578 extern unsigned int ip_ct_generic_timeout;
580 /* Log invalid packets of a given protocol */
581 static int log_invalid_proto_min = 0;
582 static int log_invalid_proto_max = 255;
584 static struct ctl_table_header *ip_ct_sysctl_header;
586 static ctl_table ip_ct_sysctl_table[] = {
588 .ctl_name = NET_IPV4_NF_CONNTRACK_MAX,
589 .procname = "ip_conntrack_max",
590 .data = &ip_conntrack_max,
591 .maxlen = sizeof(int),
593 .proc_handler = &proc_dointvec,
596 .ctl_name = NET_IPV4_NF_CONNTRACK_COUNT,
597 .procname = "ip_conntrack_count",
598 .data = &ip_conntrack_count,
599 .maxlen = sizeof(int),
601 .proc_handler = &proc_dointvec,
604 .ctl_name = NET_IPV4_NF_CONNTRACK_BUCKETS,
605 .procname = "ip_conntrack_buckets",
606 .data = &ip_conntrack_htable_size,
607 .maxlen = sizeof(unsigned int),
609 .proc_handler = &proc_dointvec,
612 .ctl_name = NET_IPV4_NF_CONNTRACK_TCP_TIMEOUT_SYN_SENT,
613 .procname = "ip_conntrack_tcp_timeout_syn_sent",
614 .data = &ip_ct_tcp_timeout_syn_sent,
615 .maxlen = sizeof(unsigned int),
617 .proc_handler = &proc_dointvec_jiffies,
620 .ctl_name = NET_IPV4_NF_CONNTRACK_TCP_TIMEOUT_SYN_RECV,
621 .procname = "ip_conntrack_tcp_timeout_syn_recv",
622 .data = &ip_ct_tcp_timeout_syn_recv,
623 .maxlen = sizeof(unsigned int),
625 .proc_handler = &proc_dointvec_jiffies,
628 .ctl_name = NET_IPV4_NF_CONNTRACK_TCP_TIMEOUT_ESTABLISHED,
629 .procname = "ip_conntrack_tcp_timeout_established",
630 .data = &ip_ct_tcp_timeout_established,
631 .maxlen = sizeof(unsigned int),
633 .proc_handler = &proc_dointvec_jiffies,
636 .ctl_name = NET_IPV4_NF_CONNTRACK_TCP_TIMEOUT_FIN_WAIT,
637 .procname = "ip_conntrack_tcp_timeout_fin_wait",
638 .data = &ip_ct_tcp_timeout_fin_wait,
639 .maxlen = sizeof(unsigned int),
641 .proc_handler = &proc_dointvec_jiffies,
644 .ctl_name = NET_IPV4_NF_CONNTRACK_TCP_TIMEOUT_CLOSE_WAIT,
645 .procname = "ip_conntrack_tcp_timeout_close_wait",
646 .data = &ip_ct_tcp_timeout_close_wait,
647 .maxlen = sizeof(unsigned int),
649 .proc_handler = &proc_dointvec_jiffies,
652 .ctl_name = NET_IPV4_NF_CONNTRACK_TCP_TIMEOUT_LAST_ACK,
653 .procname = "ip_conntrack_tcp_timeout_last_ack",
654 .data = &ip_ct_tcp_timeout_last_ack,
655 .maxlen = sizeof(unsigned int),
657 .proc_handler = &proc_dointvec_jiffies,
660 .ctl_name = NET_IPV4_NF_CONNTRACK_TCP_TIMEOUT_TIME_WAIT,
661 .procname = "ip_conntrack_tcp_timeout_time_wait",
662 .data = &ip_ct_tcp_timeout_time_wait,
663 .maxlen = sizeof(unsigned int),
665 .proc_handler = &proc_dointvec_jiffies,
668 .ctl_name = NET_IPV4_NF_CONNTRACK_TCP_TIMEOUT_CLOSE,
669 .procname = "ip_conntrack_tcp_timeout_close",
670 .data = &ip_ct_tcp_timeout_close,
671 .maxlen = sizeof(unsigned int),
673 .proc_handler = &proc_dointvec_jiffies,
676 .ctl_name = NET_IPV4_NF_CONNTRACK_UDP_TIMEOUT,
677 .procname = "ip_conntrack_udp_timeout",
678 .data = &ip_ct_udp_timeout,
679 .maxlen = sizeof(unsigned int),
681 .proc_handler = &proc_dointvec_jiffies,
684 .ctl_name = NET_IPV4_NF_CONNTRACK_UDP_TIMEOUT_STREAM,
685 .procname = "ip_conntrack_udp_timeout_stream",
686 .data = &ip_ct_udp_timeout_stream,
687 .maxlen = sizeof(unsigned int),
689 .proc_handler = &proc_dointvec_jiffies,
692 .ctl_name = NET_IPV4_NF_CONNTRACK_ICMP_TIMEOUT,
693 .procname = "ip_conntrack_icmp_timeout",
694 .data = &ip_ct_icmp_timeout,
695 .maxlen = sizeof(unsigned int),
697 .proc_handler = &proc_dointvec_jiffies,
700 .ctl_name = NET_IPV4_NF_CONNTRACK_GENERIC_TIMEOUT,
701 .procname = "ip_conntrack_generic_timeout",
702 .data = &ip_ct_generic_timeout,
703 .maxlen = sizeof(unsigned int),
705 .proc_handler = &proc_dointvec_jiffies,
708 .ctl_name = NET_IPV4_NF_CONNTRACK_LOG_INVALID,
709 .procname = "ip_conntrack_log_invalid",
710 .data = &ip_ct_log_invalid,
711 .maxlen = sizeof(unsigned int),
713 .proc_handler = &proc_dointvec_minmax,
714 .strategy = &sysctl_intvec,
715 .extra1 = &log_invalid_proto_min,
716 .extra2 = &log_invalid_proto_max,
719 .ctl_name = NET_IPV4_NF_CONNTRACK_TCP_TIMEOUT_MAX_RETRANS,
720 .procname = "ip_conntrack_tcp_timeout_max_retrans",
721 .data = &ip_ct_tcp_timeout_max_retrans,
722 .maxlen = sizeof(unsigned int),
724 .proc_handler = &proc_dointvec_jiffies,
727 .ctl_name = NET_IPV4_NF_CONNTRACK_TCP_LOOSE,
728 .procname = "ip_conntrack_tcp_loose",
729 .data = &ip_ct_tcp_loose,
730 .maxlen = sizeof(unsigned int),
732 .proc_handler = &proc_dointvec,
735 .ctl_name = NET_IPV4_NF_CONNTRACK_TCP_BE_LIBERAL,
736 .procname = "ip_conntrack_tcp_be_liberal",
737 .data = &ip_ct_tcp_be_liberal,
738 .maxlen = sizeof(unsigned int),
740 .proc_handler = &proc_dointvec,
743 .ctl_name = NET_IPV4_NF_CONNTRACK_TCP_MAX_RETRANS,
744 .procname = "ip_conntrack_tcp_max_retrans",
745 .data = &ip_ct_tcp_max_retrans,
746 .maxlen = sizeof(unsigned int),
748 .proc_handler = &proc_dointvec,
753 #define NET_IP_CONNTRACK_MAX 2089
755 static ctl_table ip_ct_netfilter_table[] = {
757 .ctl_name = NET_IPV4_NETFILTER,
758 .procname = "netfilter",
760 .child = ip_ct_sysctl_table,
763 .ctl_name = NET_IP_CONNTRACK_MAX,
764 .procname = "ip_conntrack_max",
765 .data = &ip_conntrack_max,
766 .maxlen = sizeof(int),
768 .proc_handler = &proc_dointvec
773 static ctl_table ip_ct_ipv4_table[] = {
775 .ctl_name = NET_IPV4,
778 .child = ip_ct_netfilter_table,
783 static ctl_table ip_ct_net_table[] = {
788 .child = ip_ct_ipv4_table,
793 EXPORT_SYMBOL(ip_ct_log_invalid);
794 #endif /* CONFIG_SYSCTL */
796 static int init_or_cleanup(int init)
798 #ifdef CONFIG_PROC_FS
799 struct proc_dir_entry *proc, *proc_exp, *proc_stat;
803 if (!init) goto cleanup;
805 ret = ip_conntrack_init();
807 goto cleanup_nothing;
809 #ifdef CONFIG_PROC_FS
811 proc = proc_net_fops_create("ip_conntrack", 0440, &ct_file_ops);
812 if (!proc) goto cleanup_init;
814 proc_exp = proc_net_fops_create("ip_conntrack_expect", 0440,
816 if (!proc_exp) goto cleanup_proc;
818 proc_stat = create_proc_entry("ip_conntrack", S_IRUGO, proc_net_stat);
820 goto cleanup_proc_exp;
822 proc_stat->proc_fops = &ct_cpu_seq_fops;
823 proc_stat->owner = THIS_MODULE;
826 ret = nf_register_hook(&ip_conntrack_defrag_ops);
828 printk("ip_conntrack: can't register pre-routing defrag hook.\n");
829 goto cleanup_proc_stat;
831 ret = nf_register_hook(&ip_conntrack_defrag_local_out_ops);
833 printk("ip_conntrack: can't register local_out defrag hook.\n");
834 goto cleanup_defragops;
836 ret = nf_register_hook(&ip_conntrack_in_ops);
838 printk("ip_conntrack: can't register pre-routing hook.\n");
839 goto cleanup_defraglocalops;
841 ret = nf_register_hook(&ip_conntrack_local_out_ops);
843 printk("ip_conntrack: can't register local out hook.\n");
846 ret = nf_register_hook(&ip_conntrack_helper_in_ops);
848 printk("ip_conntrack: can't register local in helper hook.\n");
849 goto cleanup_inandlocalops;
851 ret = nf_register_hook(&ip_conntrack_helper_out_ops);
853 printk("ip_conntrack: can't register postrouting helper hook.\n");
854 goto cleanup_helperinops;
856 ret = nf_register_hook(&ip_conntrack_out_ops);
858 printk("ip_conntrack: can't register post-routing hook.\n");
859 goto cleanup_helperoutops;
861 ret = nf_register_hook(&ip_conntrack_local_in_ops);
863 printk("ip_conntrack: can't register local in hook.\n");
864 goto cleanup_inoutandlocalops;
867 ip_ct_sysctl_header = register_sysctl_table(ip_ct_net_table, 0);
868 if (ip_ct_sysctl_header == NULL) {
869 printk("ip_conntrack: can't register to sysctl.\n");
871 goto cleanup_localinops;
880 unregister_sysctl_table(ip_ct_sysctl_header);
883 nf_unregister_hook(&ip_conntrack_local_in_ops);
884 cleanup_inoutandlocalops:
885 nf_unregister_hook(&ip_conntrack_out_ops);
886 cleanup_helperoutops:
887 nf_unregister_hook(&ip_conntrack_helper_out_ops);
889 nf_unregister_hook(&ip_conntrack_helper_in_ops);
890 cleanup_inandlocalops:
891 nf_unregister_hook(&ip_conntrack_local_out_ops);
893 nf_unregister_hook(&ip_conntrack_in_ops);
894 cleanup_defraglocalops:
895 nf_unregister_hook(&ip_conntrack_defrag_local_out_ops);
897 nf_unregister_hook(&ip_conntrack_defrag_ops);
899 #ifdef CONFIG_PROC_FS
900 remove_proc_entry("ip_conntrack", proc_net_stat);
902 proc_net_remove("ip_conntrack_expect");
904 proc_net_remove("ip_conntrack");
906 #endif /* CONFIG_PROC_FS */
907 ip_conntrack_cleanup();
912 /* FIXME: Allow NULL functions and sub in pointers to generic for
914 int ip_conntrack_protocol_register(struct ip_conntrack_protocol *proto)
918 write_lock_bh(&ip_conntrack_lock);
919 if (ip_ct_protos[proto->proto] != &ip_conntrack_generic_protocol) {
923 ip_ct_protos[proto->proto] = proto;
925 write_unlock_bh(&ip_conntrack_lock);
929 void ip_conntrack_protocol_unregister(struct ip_conntrack_protocol *proto)
931 write_lock_bh(&ip_conntrack_lock);
932 ip_ct_protos[proto->proto] = &ip_conntrack_generic_protocol;
933 write_unlock_bh(&ip_conntrack_lock);
935 /* Somebody could be still looking at the proto in bh. */
938 /* Remove all contrack entries for this protocol */
939 ip_ct_iterate_cleanup(kill_proto, &proto->proto);
942 static int __init init(void)
944 return init_or_cleanup(1);
947 static void __exit fini(void)
955 /* Some modules need us, but don't depend directly on any symbol.
956 They should call this. */
957 void need_conntrack(void)
961 #ifdef CONFIG_IP_NF_CONNTRACK_EVENTS
962 EXPORT_SYMBOL_GPL(ip_conntrack_chain);
963 EXPORT_SYMBOL_GPL(ip_conntrack_expect_chain);
964 EXPORT_SYMBOL_GPL(ip_conntrack_register_notifier);
965 EXPORT_SYMBOL_GPL(ip_conntrack_unregister_notifier);
966 EXPORT_SYMBOL_GPL(__ip_ct_event_cache_init);
967 EXPORT_PER_CPU_SYMBOL_GPL(ip_conntrack_ecache);
969 EXPORT_SYMBOL(ip_conntrack_protocol_register);
970 EXPORT_SYMBOL(ip_conntrack_protocol_unregister);
971 EXPORT_SYMBOL(ip_ct_get_tuple);
972 EXPORT_SYMBOL(invert_tuplepr);
973 EXPORT_SYMBOL(ip_conntrack_alter_reply);
974 EXPORT_SYMBOL(ip_conntrack_destroyed);
975 EXPORT_SYMBOL(need_conntrack);
976 EXPORT_SYMBOL(ip_conntrack_helper_register);
977 EXPORT_SYMBOL(ip_conntrack_helper_unregister);
978 EXPORT_SYMBOL(ip_ct_iterate_cleanup);
979 EXPORT_SYMBOL(__ip_ct_refresh_acct);
981 EXPORT_SYMBOL(ip_conntrack_expect_alloc);
982 EXPORT_SYMBOL(ip_conntrack_expect_put);
983 EXPORT_SYMBOL_GPL(__ip_conntrack_expect_find);
984 EXPORT_SYMBOL_GPL(ip_conntrack_expect_find);
985 EXPORT_SYMBOL(ip_conntrack_expect_related);
986 EXPORT_SYMBOL(ip_conntrack_unexpect_related);
987 EXPORT_SYMBOL_GPL(ip_conntrack_expect_list);
988 EXPORT_SYMBOL_GPL(ip_ct_unlink_expect);
990 EXPORT_SYMBOL(ip_conntrack_tuple_taken);
991 EXPORT_SYMBOL(ip_ct_gather_frags);
992 EXPORT_SYMBOL(ip_conntrack_htable_size);
993 EXPORT_SYMBOL(ip_conntrack_lock);
994 EXPORT_SYMBOL(ip_conntrack_hash);
995 EXPORT_SYMBOL(ip_conntrack_untracked);
996 EXPORT_SYMBOL_GPL(ip_conntrack_find_get);
997 #ifdef CONFIG_IP_NF_NAT_NEEDED
998 EXPORT_SYMBOL(ip_conntrack_tcp_update);
1001 EXPORT_SYMBOL_GPL(ip_conntrack_flush);
1002 EXPORT_SYMBOL_GPL(__ip_conntrack_find);
1004 EXPORT_SYMBOL_GPL(ip_conntrack_alloc);
1005 EXPORT_SYMBOL_GPL(ip_conntrack_free);
1006 EXPORT_SYMBOL_GPL(ip_conntrack_hash_insert);
1008 EXPORT_SYMBOL_GPL(ip_ct_remove_expectations);
1010 EXPORT_SYMBOL_GPL(ip_conntrack_helper_find_get);
1011 EXPORT_SYMBOL_GPL(ip_conntrack_helper_put);
1012 EXPORT_SYMBOL_GPL(__ip_conntrack_helper_find_byname);
1014 EXPORT_SYMBOL_GPL(ip_conntrack_proto_find_get);
1015 EXPORT_SYMBOL_GPL(ip_conntrack_proto_put);
1016 EXPORT_SYMBOL_GPL(__ip_conntrack_proto_find);
1017 #if defined(CONFIG_IP_NF_CONNTRACK_NETLINK) || \
1018 defined(CONFIG_IP_NF_CONNTRACK_NETLINK_MODULE)
1019 EXPORT_SYMBOL_GPL(ip_ct_port_tuple_to_nfattr);
1020 EXPORT_SYMBOL_GPL(ip_ct_port_nfattr_to_tuple);