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 (seq_print_counters(s, &conntrack->counters[IP_CT_DIR_ORIGINAL]))
172 if (!(test_bit(IPS_SEEN_REPLY_BIT, &conntrack->status)))
173 if (seq_printf(s, "[UNREPLIED] "))
176 if (print_tuple(s, &conntrack->tuplehash[IP_CT_DIR_REPLY].tuple,
180 if (seq_print_counters(s, &conntrack->counters[IP_CT_DIR_REPLY]))
183 if (test_bit(IPS_ASSURED_BIT, &conntrack->status))
184 if (seq_printf(s, "[ASSURED] "))
187 #if defined(CONFIG_IP_NF_CONNTRACK_MARK)
188 if (seq_printf(s, "mark=%u ", conntrack->mark))
192 if (seq_printf(s, "use=%u\n", atomic_read(&conntrack->ct_general.use)))
198 static struct seq_operations ct_seq_ops = {
199 .start = ct_seq_start,
205 static int ct_open(struct inode *inode, struct file *file)
207 struct seq_file *seq;
208 struct ct_iter_state *st;
211 st = kmalloc(sizeof(struct ct_iter_state), GFP_KERNEL);
214 ret = seq_open(file, &ct_seq_ops);
217 seq = file->private_data;
219 memset(st, 0, sizeof(struct ct_iter_state));
226 static struct file_operations ct_file_ops = {
227 .owner = THIS_MODULE,
231 .release = seq_release_private,
235 static void *exp_seq_start(struct seq_file *s, loff_t *pos)
237 struct list_head *e = &ip_conntrack_expect_list;
240 /* strange seq_file api calls stop even if we fail,
241 * thus we need to grab lock since stop unlocks */
242 read_lock_bh(&ip_conntrack_lock);
247 for (i = 0; i <= *pos; i++) {
249 if (e == &ip_conntrack_expect_list)
255 static void *exp_seq_next(struct seq_file *s, void *v, loff_t *pos)
257 struct list_head *e = v;
262 if (e == &ip_conntrack_expect_list)
268 static void exp_seq_stop(struct seq_file *s, void *v)
270 read_unlock_bh(&ip_conntrack_lock);
273 static int exp_seq_show(struct seq_file *s, void *v)
275 struct ip_conntrack_expect *expect = v;
277 if (expect->timeout.function)
278 seq_printf(s, "%ld ", timer_pending(&expect->timeout)
279 ? (long)(expect->timeout.expires - jiffies)/HZ : 0);
283 seq_printf(s, "proto=%u ", expect->tuple.dst.protonum);
285 print_tuple(s, &expect->tuple,
286 __ip_conntrack_proto_find(expect->tuple.dst.protonum));
287 return seq_putc(s, '\n');
290 static struct seq_operations exp_seq_ops = {
291 .start = exp_seq_start,
292 .next = exp_seq_next,
293 .stop = exp_seq_stop,
297 static int exp_open(struct inode *inode, struct file *file)
299 return seq_open(file, &exp_seq_ops);
302 static struct file_operations exp_file_ops = {
303 .owner = THIS_MODULE,
307 .release = seq_release
310 static void *ct_cpu_seq_start(struct seq_file *seq, loff_t *pos)
315 return SEQ_START_TOKEN;
317 for (cpu = *pos-1; cpu < NR_CPUS; ++cpu) {
318 if (!cpu_possible(cpu))
321 return &per_cpu(ip_conntrack_stat, cpu);
327 static void *ct_cpu_seq_next(struct seq_file *seq, void *v, loff_t *pos)
331 for (cpu = *pos; cpu < NR_CPUS; ++cpu) {
332 if (!cpu_possible(cpu))
335 return &per_cpu(ip_conntrack_stat, cpu);
341 static void ct_cpu_seq_stop(struct seq_file *seq, void *v)
345 static int ct_cpu_seq_show(struct seq_file *seq, void *v)
347 unsigned int nr_conntracks = atomic_read(&ip_conntrack_count);
348 struct ip_conntrack_stat *st = v;
350 if (v == SEQ_START_TOKEN) {
351 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");
355 seq_printf(seq, "%08x %08x %08x %08x %08x %08x %08x %08x "
356 "%08x %08x %08x %08x %08x %08x %08x %08x \n",
378 static struct seq_operations ct_cpu_seq_ops = {
379 .start = ct_cpu_seq_start,
380 .next = ct_cpu_seq_next,
381 .stop = ct_cpu_seq_stop,
382 .show = ct_cpu_seq_show,
385 static int ct_cpu_seq_open(struct inode *inode, struct file *file)
387 return seq_open(file, &ct_cpu_seq_ops);
390 static struct file_operations ct_cpu_seq_fops = {
391 .owner = THIS_MODULE,
392 .open = ct_cpu_seq_open,
395 .release = seq_release_private,
399 static unsigned int ip_confirm(unsigned int hooknum,
400 struct sk_buff **pskb,
401 const struct net_device *in,
402 const struct net_device *out,
403 int (*okfn)(struct sk_buff *))
405 /* We've seen it coming out the other side: confirm it */
406 return ip_conntrack_confirm(pskb);
409 static unsigned int ip_conntrack_help(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 struct ip_conntrack *ct;
416 enum ip_conntrack_info ctinfo;
418 /* This is where we call the helper: as the packet goes out. */
419 ct = ip_conntrack_get(*pskb, &ctinfo);
420 if (ct && ct->helper) {
422 ret = ct->helper->help(pskb, ct, ctinfo);
423 if (ret != NF_ACCEPT)
429 static unsigned int ip_conntrack_defrag(unsigned int hooknum,
430 struct sk_buff **pskb,
431 const struct net_device *in,
432 const struct net_device *out,
433 int (*okfn)(struct sk_buff *))
435 #if !defined(CONFIG_IP_NF_NAT) && !defined(CONFIG_IP_NF_NAT_MODULE)
436 /* Previously seen (loopback)? Ignore. Do this before
442 /* Gather fragments. */
443 if ((*pskb)->nh.iph->frag_off & htons(IP_MF|IP_OFFSET)) {
444 *pskb = ip_ct_gather_frags(*pskb,
445 hooknum == NF_IP_PRE_ROUTING ?
446 IP_DEFRAG_CONNTRACK_IN :
447 IP_DEFRAG_CONNTRACK_OUT);
454 static unsigned int ip_conntrack_local(unsigned int hooknum,
455 struct sk_buff **pskb,
456 const struct net_device *in,
457 const struct net_device *out,
458 int (*okfn)(struct sk_buff *))
460 /* root is playing with raw sockets. */
461 if ((*pskb)->len < sizeof(struct iphdr)
462 || (*pskb)->nh.iph->ihl * 4 < sizeof(struct iphdr)) {
464 printk("ipt_hook: happy cracking.\n");
467 return ip_conntrack_in(hooknum, pskb, in, out, okfn);
470 /* Connection tracking may drop packets, but never alters them, so
471 make it the first hook. */
472 static struct nf_hook_ops ip_conntrack_defrag_ops = {
473 .hook = ip_conntrack_defrag,
474 .owner = THIS_MODULE,
476 .hooknum = NF_IP_PRE_ROUTING,
477 .priority = NF_IP_PRI_CONNTRACK_DEFRAG,
480 static struct nf_hook_ops ip_conntrack_in_ops = {
481 .hook = ip_conntrack_in,
482 .owner = THIS_MODULE,
484 .hooknum = NF_IP_PRE_ROUTING,
485 .priority = NF_IP_PRI_CONNTRACK,
488 static struct nf_hook_ops ip_conntrack_defrag_local_out_ops = {
489 .hook = ip_conntrack_defrag,
490 .owner = THIS_MODULE,
492 .hooknum = NF_IP_LOCAL_OUT,
493 .priority = NF_IP_PRI_CONNTRACK_DEFRAG,
496 static struct nf_hook_ops ip_conntrack_local_out_ops = {
497 .hook = ip_conntrack_local,
498 .owner = THIS_MODULE,
500 .hooknum = NF_IP_LOCAL_OUT,
501 .priority = NF_IP_PRI_CONNTRACK,
505 static struct nf_hook_ops ip_conntrack_helper_out_ops = {
506 .hook = ip_conntrack_help,
507 .owner = THIS_MODULE,
509 .hooknum = NF_IP_POST_ROUTING,
510 .priority = NF_IP_PRI_CONNTRACK_HELPER,
513 static struct nf_hook_ops ip_conntrack_helper_in_ops = {
514 .hook = ip_conntrack_help,
515 .owner = THIS_MODULE,
517 .hooknum = NF_IP_LOCAL_IN,
518 .priority = NF_IP_PRI_CONNTRACK_HELPER,
521 /* Refragmenter; last chance. */
522 static struct nf_hook_ops ip_conntrack_out_ops = {
524 .owner = THIS_MODULE,
526 .hooknum = NF_IP_POST_ROUTING,
527 .priority = NF_IP_PRI_CONNTRACK_CONFIRM,
530 static struct nf_hook_ops ip_conntrack_local_in_ops = {
532 .owner = THIS_MODULE,
534 .hooknum = NF_IP_LOCAL_IN,
535 .priority = NF_IP_PRI_CONNTRACK_CONFIRM,
542 /* From ip_conntrack_core.c */
543 extern int ip_conntrack_max;
544 extern unsigned int ip_conntrack_htable_size;
546 /* From ip_conntrack_proto_tcp.c */
547 extern unsigned long ip_ct_tcp_timeout_syn_sent;
548 extern unsigned long ip_ct_tcp_timeout_syn_recv;
549 extern unsigned long ip_ct_tcp_timeout_established;
550 extern unsigned long ip_ct_tcp_timeout_fin_wait;
551 extern unsigned long ip_ct_tcp_timeout_close_wait;
552 extern unsigned long ip_ct_tcp_timeout_last_ack;
553 extern unsigned long ip_ct_tcp_timeout_time_wait;
554 extern unsigned long ip_ct_tcp_timeout_close;
555 extern unsigned long ip_ct_tcp_timeout_max_retrans;
556 extern int ip_ct_tcp_loose;
557 extern int ip_ct_tcp_be_liberal;
558 extern int ip_ct_tcp_max_retrans;
560 /* From ip_conntrack_proto_udp.c */
561 extern unsigned long ip_ct_udp_timeout;
562 extern unsigned long ip_ct_udp_timeout_stream;
564 /* From ip_conntrack_proto_icmp.c */
565 extern unsigned long ip_ct_icmp_timeout;
567 /* From ip_conntrack_proto_icmp.c */
568 extern unsigned long ip_ct_generic_timeout;
570 /* Log invalid packets of a given protocol */
571 static int log_invalid_proto_min = 0;
572 static int log_invalid_proto_max = 255;
574 static struct ctl_table_header *ip_ct_sysctl_header;
576 static ctl_table ip_ct_sysctl_table[] = {
578 .ctl_name = NET_IPV4_NF_CONNTRACK_MAX,
579 .procname = "ip_conntrack_max",
580 .data = &ip_conntrack_max,
581 .maxlen = sizeof(int),
583 .proc_handler = &proc_dointvec,
586 .ctl_name = NET_IPV4_NF_CONNTRACK_COUNT,
587 .procname = "ip_conntrack_count",
588 .data = &ip_conntrack_count,
589 .maxlen = sizeof(int),
591 .proc_handler = &proc_dointvec,
594 .ctl_name = NET_IPV4_NF_CONNTRACK_BUCKETS,
595 .procname = "ip_conntrack_buckets",
596 .data = &ip_conntrack_htable_size,
597 .maxlen = sizeof(unsigned int),
599 .proc_handler = &proc_dointvec,
602 .ctl_name = NET_IPV4_NF_CONNTRACK_TCP_TIMEOUT_SYN_SENT,
603 .procname = "ip_conntrack_tcp_timeout_syn_sent",
604 .data = &ip_ct_tcp_timeout_syn_sent,
605 .maxlen = sizeof(unsigned int),
607 .proc_handler = &proc_dointvec_jiffies,
610 .ctl_name = NET_IPV4_NF_CONNTRACK_TCP_TIMEOUT_SYN_RECV,
611 .procname = "ip_conntrack_tcp_timeout_syn_recv",
612 .data = &ip_ct_tcp_timeout_syn_recv,
613 .maxlen = sizeof(unsigned int),
615 .proc_handler = &proc_dointvec_jiffies,
618 .ctl_name = NET_IPV4_NF_CONNTRACK_TCP_TIMEOUT_ESTABLISHED,
619 .procname = "ip_conntrack_tcp_timeout_established",
620 .data = &ip_ct_tcp_timeout_established,
621 .maxlen = sizeof(unsigned int),
623 .proc_handler = &proc_dointvec_jiffies,
626 .ctl_name = NET_IPV4_NF_CONNTRACK_TCP_TIMEOUT_FIN_WAIT,
627 .procname = "ip_conntrack_tcp_timeout_fin_wait",
628 .data = &ip_ct_tcp_timeout_fin_wait,
629 .maxlen = sizeof(unsigned int),
631 .proc_handler = &proc_dointvec_jiffies,
634 .ctl_name = NET_IPV4_NF_CONNTRACK_TCP_TIMEOUT_CLOSE_WAIT,
635 .procname = "ip_conntrack_tcp_timeout_close_wait",
636 .data = &ip_ct_tcp_timeout_close_wait,
637 .maxlen = sizeof(unsigned int),
639 .proc_handler = &proc_dointvec_jiffies,
642 .ctl_name = NET_IPV4_NF_CONNTRACK_TCP_TIMEOUT_LAST_ACK,
643 .procname = "ip_conntrack_tcp_timeout_last_ack",
644 .data = &ip_ct_tcp_timeout_last_ack,
645 .maxlen = sizeof(unsigned int),
647 .proc_handler = &proc_dointvec_jiffies,
650 .ctl_name = NET_IPV4_NF_CONNTRACK_TCP_TIMEOUT_TIME_WAIT,
651 .procname = "ip_conntrack_tcp_timeout_time_wait",
652 .data = &ip_ct_tcp_timeout_time_wait,
653 .maxlen = sizeof(unsigned int),
655 .proc_handler = &proc_dointvec_jiffies,
658 .ctl_name = NET_IPV4_NF_CONNTRACK_TCP_TIMEOUT_CLOSE,
659 .procname = "ip_conntrack_tcp_timeout_close",
660 .data = &ip_ct_tcp_timeout_close,
661 .maxlen = sizeof(unsigned int),
663 .proc_handler = &proc_dointvec_jiffies,
666 .ctl_name = NET_IPV4_NF_CONNTRACK_UDP_TIMEOUT,
667 .procname = "ip_conntrack_udp_timeout",
668 .data = &ip_ct_udp_timeout,
669 .maxlen = sizeof(unsigned int),
671 .proc_handler = &proc_dointvec_jiffies,
674 .ctl_name = NET_IPV4_NF_CONNTRACK_UDP_TIMEOUT_STREAM,
675 .procname = "ip_conntrack_udp_timeout_stream",
676 .data = &ip_ct_udp_timeout_stream,
677 .maxlen = sizeof(unsigned int),
679 .proc_handler = &proc_dointvec_jiffies,
682 .ctl_name = NET_IPV4_NF_CONNTRACK_ICMP_TIMEOUT,
683 .procname = "ip_conntrack_icmp_timeout",
684 .data = &ip_ct_icmp_timeout,
685 .maxlen = sizeof(unsigned int),
687 .proc_handler = &proc_dointvec_jiffies,
690 .ctl_name = NET_IPV4_NF_CONNTRACK_GENERIC_TIMEOUT,
691 .procname = "ip_conntrack_generic_timeout",
692 .data = &ip_ct_generic_timeout,
693 .maxlen = sizeof(unsigned int),
695 .proc_handler = &proc_dointvec_jiffies,
698 .ctl_name = NET_IPV4_NF_CONNTRACK_LOG_INVALID,
699 .procname = "ip_conntrack_log_invalid",
700 .data = &ip_ct_log_invalid,
701 .maxlen = sizeof(unsigned int),
703 .proc_handler = &proc_dointvec_minmax,
704 .strategy = &sysctl_intvec,
705 .extra1 = &log_invalid_proto_min,
706 .extra2 = &log_invalid_proto_max,
709 .ctl_name = NET_IPV4_NF_CONNTRACK_TCP_TIMEOUT_MAX_RETRANS,
710 .procname = "ip_conntrack_tcp_timeout_max_retrans",
711 .data = &ip_ct_tcp_timeout_max_retrans,
712 .maxlen = sizeof(unsigned int),
714 .proc_handler = &proc_dointvec_jiffies,
717 .ctl_name = NET_IPV4_NF_CONNTRACK_TCP_LOOSE,
718 .procname = "ip_conntrack_tcp_loose",
719 .data = &ip_ct_tcp_loose,
720 .maxlen = sizeof(unsigned int),
722 .proc_handler = &proc_dointvec,
725 .ctl_name = NET_IPV4_NF_CONNTRACK_TCP_BE_LIBERAL,
726 .procname = "ip_conntrack_tcp_be_liberal",
727 .data = &ip_ct_tcp_be_liberal,
728 .maxlen = sizeof(unsigned int),
730 .proc_handler = &proc_dointvec,
733 .ctl_name = NET_IPV4_NF_CONNTRACK_TCP_MAX_RETRANS,
734 .procname = "ip_conntrack_tcp_max_retrans",
735 .data = &ip_ct_tcp_max_retrans,
736 .maxlen = sizeof(unsigned int),
738 .proc_handler = &proc_dointvec,
743 #define NET_IP_CONNTRACK_MAX 2089
745 static ctl_table ip_ct_netfilter_table[] = {
747 .ctl_name = NET_IPV4_NETFILTER,
748 .procname = "netfilter",
750 .child = ip_ct_sysctl_table,
753 .ctl_name = NET_IP_CONNTRACK_MAX,
754 .procname = "ip_conntrack_max",
755 .data = &ip_conntrack_max,
756 .maxlen = sizeof(int),
758 .proc_handler = &proc_dointvec
763 static ctl_table ip_ct_ipv4_table[] = {
765 .ctl_name = NET_IPV4,
768 .child = ip_ct_netfilter_table,
773 static ctl_table ip_ct_net_table[] = {
778 .child = ip_ct_ipv4_table,
783 EXPORT_SYMBOL(ip_ct_log_invalid);
784 #endif /* CONFIG_SYSCTL */
786 static int init_or_cleanup(int init)
788 #ifdef CONFIG_PROC_FS
789 struct proc_dir_entry *proc, *proc_exp, *proc_stat;
793 if (!init) goto cleanup;
795 ret = ip_conntrack_init();
797 goto cleanup_nothing;
799 #ifdef CONFIG_PROC_FS
801 proc = proc_net_fops_create("ip_conntrack", 0440, &ct_file_ops);
802 if (!proc) goto cleanup_init;
804 proc_exp = proc_net_fops_create("ip_conntrack_expect", 0440,
806 if (!proc_exp) goto cleanup_proc;
808 proc_stat = create_proc_entry("ip_conntrack", S_IRUGO, proc_net_stat);
810 goto cleanup_proc_exp;
812 proc_stat->proc_fops = &ct_cpu_seq_fops;
813 proc_stat->owner = THIS_MODULE;
816 ret = nf_register_hook(&ip_conntrack_defrag_ops);
818 printk("ip_conntrack: can't register pre-routing defrag hook.\n");
819 goto cleanup_proc_stat;
821 ret = nf_register_hook(&ip_conntrack_defrag_local_out_ops);
823 printk("ip_conntrack: can't register local_out defrag hook.\n");
824 goto cleanup_defragops;
826 ret = nf_register_hook(&ip_conntrack_in_ops);
828 printk("ip_conntrack: can't register pre-routing hook.\n");
829 goto cleanup_defraglocalops;
831 ret = nf_register_hook(&ip_conntrack_local_out_ops);
833 printk("ip_conntrack: can't register local out hook.\n");
836 ret = nf_register_hook(&ip_conntrack_helper_in_ops);
838 printk("ip_conntrack: can't register local in helper hook.\n");
839 goto cleanup_inandlocalops;
841 ret = nf_register_hook(&ip_conntrack_helper_out_ops);
843 printk("ip_conntrack: can't register postrouting helper hook.\n");
844 goto cleanup_helperinops;
846 ret = nf_register_hook(&ip_conntrack_out_ops);
848 printk("ip_conntrack: can't register post-routing hook.\n");
849 goto cleanup_helperoutops;
851 ret = nf_register_hook(&ip_conntrack_local_in_ops);
853 printk("ip_conntrack: can't register local in hook.\n");
854 goto cleanup_inoutandlocalops;
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");
861 goto cleanup_localinops;
870 unregister_sysctl_table(ip_ct_sysctl_header);
873 nf_unregister_hook(&ip_conntrack_local_in_ops);
874 cleanup_inoutandlocalops:
875 nf_unregister_hook(&ip_conntrack_out_ops);
876 cleanup_helperoutops:
877 nf_unregister_hook(&ip_conntrack_helper_out_ops);
879 nf_unregister_hook(&ip_conntrack_helper_in_ops);
880 cleanup_inandlocalops:
881 nf_unregister_hook(&ip_conntrack_local_out_ops);
883 nf_unregister_hook(&ip_conntrack_in_ops);
884 cleanup_defraglocalops:
885 nf_unregister_hook(&ip_conntrack_defrag_local_out_ops);
887 nf_unregister_hook(&ip_conntrack_defrag_ops);
889 #ifdef CONFIG_PROC_FS
890 remove_proc_entry("ip_conntrack", proc_net_stat);
892 proc_net_remove("ip_conntrack_expect");
894 proc_net_remove("ip_conntrack");
896 #endif /* CONFIG_PROC_FS */
897 ip_conntrack_cleanup();
902 /* FIXME: Allow NULL functions and sub in pointers to generic for
904 int ip_conntrack_protocol_register(struct ip_conntrack_protocol *proto)
908 write_lock_bh(&ip_conntrack_lock);
909 if (ip_ct_protos[proto->proto] != &ip_conntrack_generic_protocol) {
913 ip_ct_protos[proto->proto] = proto;
915 write_unlock_bh(&ip_conntrack_lock);
919 void ip_conntrack_protocol_unregister(struct ip_conntrack_protocol *proto)
921 write_lock_bh(&ip_conntrack_lock);
922 ip_ct_protos[proto->proto] = &ip_conntrack_generic_protocol;
923 write_unlock_bh(&ip_conntrack_lock);
925 /* Somebody could be still looking at the proto in bh. */
928 /* Remove all contrack entries for this protocol */
929 ip_ct_iterate_cleanup(kill_proto, &proto->proto);
932 static int __init init(void)
934 return init_or_cleanup(1);
937 static void __exit fini(void)
945 /* Some modules need us, but don't depend directly on any symbol.
946 They should call this. */
947 void need_ip_conntrack(void)
951 #ifdef CONFIG_IP_NF_CONNTRACK_EVENTS
952 EXPORT_SYMBOL_GPL(ip_conntrack_chain);
953 EXPORT_SYMBOL_GPL(ip_conntrack_expect_chain);
954 EXPORT_SYMBOL_GPL(ip_conntrack_register_notifier);
955 EXPORT_SYMBOL_GPL(ip_conntrack_unregister_notifier);
956 EXPORT_SYMBOL_GPL(__ip_ct_event_cache_init);
957 EXPORT_PER_CPU_SYMBOL_GPL(ip_conntrack_ecache);
959 EXPORT_SYMBOL(ip_conntrack_protocol_register);
960 EXPORT_SYMBOL(ip_conntrack_protocol_unregister);
961 EXPORT_SYMBOL(ip_ct_get_tuple);
962 EXPORT_SYMBOL(invert_tuplepr);
963 EXPORT_SYMBOL(ip_conntrack_alter_reply);
964 EXPORT_SYMBOL(ip_conntrack_destroyed);
965 EXPORT_SYMBOL(need_ip_conntrack);
966 EXPORT_SYMBOL(ip_conntrack_helper_register);
967 EXPORT_SYMBOL(ip_conntrack_helper_unregister);
968 EXPORT_SYMBOL(ip_ct_iterate_cleanup);
969 EXPORT_SYMBOL(__ip_ct_refresh_acct);
971 EXPORT_SYMBOL(ip_conntrack_expect_alloc);
972 EXPORT_SYMBOL(ip_conntrack_expect_put);
973 EXPORT_SYMBOL_GPL(__ip_conntrack_expect_find);
974 EXPORT_SYMBOL_GPL(ip_conntrack_expect_find);
975 EXPORT_SYMBOL(ip_conntrack_expect_related);
976 EXPORT_SYMBOL(ip_conntrack_unexpect_related);
977 EXPORT_SYMBOL_GPL(ip_conntrack_expect_list);
978 EXPORT_SYMBOL_GPL(ip_ct_unlink_expect);
980 EXPORT_SYMBOL(ip_conntrack_tuple_taken);
981 EXPORT_SYMBOL(ip_ct_gather_frags);
982 EXPORT_SYMBOL(ip_conntrack_htable_size);
983 EXPORT_SYMBOL(ip_conntrack_lock);
984 EXPORT_SYMBOL(ip_conntrack_hash);
985 EXPORT_SYMBOL(ip_conntrack_untracked);
986 EXPORT_SYMBOL_GPL(ip_conntrack_find_get);
987 #ifdef CONFIG_IP_NF_NAT_NEEDED
988 EXPORT_SYMBOL(ip_conntrack_tcp_update);
991 EXPORT_SYMBOL_GPL(ip_conntrack_flush);
992 EXPORT_SYMBOL_GPL(__ip_conntrack_find);
994 EXPORT_SYMBOL_GPL(ip_conntrack_alloc);
995 EXPORT_SYMBOL_GPL(ip_conntrack_free);
996 EXPORT_SYMBOL_GPL(ip_conntrack_hash_insert);
998 EXPORT_SYMBOL_GPL(ip_ct_remove_expectations);
1000 EXPORT_SYMBOL_GPL(ip_conntrack_helper_find_get);
1001 EXPORT_SYMBOL_GPL(ip_conntrack_helper_put);
1002 EXPORT_SYMBOL_GPL(__ip_conntrack_helper_find_byname);
1004 EXPORT_SYMBOL_GPL(ip_conntrack_proto_find_get);
1005 EXPORT_SYMBOL_GPL(ip_conntrack_proto_put);
1006 EXPORT_SYMBOL_GPL(__ip_conntrack_proto_find);
1007 #if defined(CONFIG_IP_NF_CONNTRACK_NETLINK) || \
1008 defined(CONFIG_IP_NF_CONNTRACK_NETLINK_MODULE)
1009 EXPORT_SYMBOL_GPL(ip_ct_port_tuple_to_nfattr);
1010 EXPORT_SYMBOL_GPL(ip_ct_port_nfattr_to_tuple);