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-2004 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) MUST_BE_READ_LOCKED(&ip_conntrack_lock)
32 #define ASSERT_WRITE_LOCK(x) MUST_BE_WRITE_LOCKED(&ip_conntrack_lock)
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(&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(&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 MUST_BE_READ_LOCKED(&ip_conntrack_lock);
144 IP_NF_ASSERT(conntrack);
146 /* we only want to print DIR_ORIGINAL */
150 proto = ip_ct_find_proto(conntrack->tuplehash[IP_CT_DIR_ORIGINAL]
151 .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=%lu ", 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(&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(&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_ct_find_proto(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 /* Gather fragments. */
436 if ((*pskb)->nh.iph->frag_off & htons(IP_MF|IP_OFFSET)) {
437 *pskb = ip_ct_gather_frags(*pskb,
438 hooknum == NF_IP_PRE_ROUTING ?
439 IP_DEFRAG_CONNTRACK_IN :
440 IP_DEFRAG_CONNTRACK_OUT);
447 static unsigned int ip_refrag(unsigned int hooknum,
448 struct sk_buff **pskb,
449 const struct net_device *in,
450 const struct net_device *out,
451 int (*okfn)(struct sk_buff *))
453 struct rtable *rt = (struct rtable *)(*pskb)->dst;
455 /* We've seen it coming out the other side: confirm */
456 if (ip_confirm(hooknum, pskb, in, out, okfn) != NF_ACCEPT)
459 /* Local packets are never produced too large for their
460 interface. We degfragment them at LOCAL_OUT, however,
461 so we have to refragment them here. */
462 if ((*pskb)->len > dst_mtu(&rt->u.dst) &&
463 !skb_shinfo(*pskb)->tso_size) {
464 /* No hook can be after us, so this should be OK. */
465 ip_fragment(*pskb, okfn);
471 static unsigned int ip_conntrack_local(unsigned int hooknum,
472 struct sk_buff **pskb,
473 const struct net_device *in,
474 const struct net_device *out,
475 int (*okfn)(struct sk_buff *))
477 /* root is playing with raw sockets. */
478 if ((*pskb)->len < sizeof(struct iphdr)
479 || (*pskb)->nh.iph->ihl * 4 < sizeof(struct iphdr)) {
481 printk("ipt_hook: happy cracking.\n");
484 return ip_conntrack_in(hooknum, pskb, in, out, okfn);
487 /* Connection tracking may drop packets, but never alters them, so
488 make it the first hook. */
489 static struct nf_hook_ops ip_conntrack_defrag_ops = {
490 .hook = ip_conntrack_defrag,
491 .owner = THIS_MODULE,
493 .hooknum = NF_IP_PRE_ROUTING,
494 .priority = NF_IP_PRI_CONNTRACK_DEFRAG,
497 static struct nf_hook_ops ip_conntrack_in_ops = {
498 .hook = ip_conntrack_in,
499 .owner = THIS_MODULE,
501 .hooknum = NF_IP_PRE_ROUTING,
502 .priority = NF_IP_PRI_CONNTRACK,
505 static struct nf_hook_ops ip_conntrack_defrag_local_out_ops = {
506 .hook = ip_conntrack_defrag,
507 .owner = THIS_MODULE,
509 .hooknum = NF_IP_LOCAL_OUT,
510 .priority = NF_IP_PRI_CONNTRACK_DEFRAG,
513 static struct nf_hook_ops ip_conntrack_local_out_ops = {
514 .hook = ip_conntrack_local,
515 .owner = THIS_MODULE,
517 .hooknum = NF_IP_LOCAL_OUT,
518 .priority = NF_IP_PRI_CONNTRACK,
522 static struct nf_hook_ops ip_conntrack_helper_out_ops = {
523 .hook = ip_conntrack_help,
524 .owner = THIS_MODULE,
526 .hooknum = NF_IP_POST_ROUTING,
527 .priority = NF_IP_PRI_CONNTRACK_HELPER,
530 static struct nf_hook_ops ip_conntrack_helper_in_ops = {
531 .hook = ip_conntrack_help,
532 .owner = THIS_MODULE,
534 .hooknum = NF_IP_LOCAL_IN,
535 .priority = NF_IP_PRI_CONNTRACK_HELPER,
538 /* Refragmenter; last chance. */
539 static struct nf_hook_ops ip_conntrack_out_ops = {
541 .owner = THIS_MODULE,
543 .hooknum = NF_IP_POST_ROUTING,
544 .priority = NF_IP_PRI_CONNTRACK_CONFIRM,
547 static struct nf_hook_ops ip_conntrack_local_in_ops = {
549 .owner = THIS_MODULE,
551 .hooknum = NF_IP_LOCAL_IN,
552 .priority = NF_IP_PRI_CONNTRACK_CONFIRM,
559 /* From ip_conntrack_core.c */
560 extern int ip_conntrack_max;
561 extern unsigned int ip_conntrack_htable_size;
563 /* From ip_conntrack_proto_tcp.c */
564 extern unsigned long ip_ct_tcp_timeout_syn_sent;
565 extern unsigned long ip_ct_tcp_timeout_syn_recv;
566 extern unsigned long ip_ct_tcp_timeout_established;
567 extern unsigned long ip_ct_tcp_timeout_fin_wait;
568 extern unsigned long ip_ct_tcp_timeout_close_wait;
569 extern unsigned long ip_ct_tcp_timeout_last_ack;
570 extern unsigned long ip_ct_tcp_timeout_time_wait;
571 extern unsigned long ip_ct_tcp_timeout_close;
572 extern unsigned long ip_ct_tcp_timeout_max_retrans;
573 extern int ip_ct_tcp_loose;
574 extern int ip_ct_tcp_be_liberal;
575 extern int ip_ct_tcp_max_retrans;
577 /* From ip_conntrack_proto_udp.c */
578 extern unsigned long ip_ct_udp_timeout;
579 extern unsigned long ip_ct_udp_timeout_stream;
581 /* From ip_conntrack_proto_icmp.c */
582 extern unsigned long ip_ct_icmp_timeout;
584 /* From ip_conntrack_proto_icmp.c */
585 extern unsigned long ip_ct_generic_timeout;
587 /* Log invalid packets of a given protocol */
588 static int log_invalid_proto_min = 0;
589 static int log_invalid_proto_max = 255;
591 static struct ctl_table_header *ip_ct_sysctl_header;
593 static ctl_table ip_ct_sysctl_table[] = {
595 .ctl_name = NET_IPV4_NF_CONNTRACK_MAX,
596 .procname = "ip_conntrack_max",
597 .data = &ip_conntrack_max,
598 .maxlen = sizeof(int),
600 .proc_handler = &proc_dointvec,
603 .ctl_name = NET_IPV4_NF_CONNTRACK_COUNT,
604 .procname = "ip_conntrack_count",
605 .data = &ip_conntrack_count,
606 .maxlen = sizeof(int),
608 .proc_handler = &proc_dointvec,
611 .ctl_name = NET_IPV4_NF_CONNTRACK_BUCKETS,
612 .procname = "ip_conntrack_buckets",
613 .data = &ip_conntrack_htable_size,
614 .maxlen = sizeof(unsigned int),
616 .proc_handler = &proc_dointvec,
619 .ctl_name = NET_IPV4_NF_CONNTRACK_TCP_TIMEOUT_SYN_SENT,
620 .procname = "ip_conntrack_tcp_timeout_syn_sent",
621 .data = &ip_ct_tcp_timeout_syn_sent,
622 .maxlen = sizeof(unsigned int),
624 .proc_handler = &proc_dointvec_jiffies,
627 .ctl_name = NET_IPV4_NF_CONNTRACK_TCP_TIMEOUT_SYN_RECV,
628 .procname = "ip_conntrack_tcp_timeout_syn_recv",
629 .data = &ip_ct_tcp_timeout_syn_recv,
630 .maxlen = sizeof(unsigned int),
632 .proc_handler = &proc_dointvec_jiffies,
635 .ctl_name = NET_IPV4_NF_CONNTRACK_TCP_TIMEOUT_ESTABLISHED,
636 .procname = "ip_conntrack_tcp_timeout_established",
637 .data = &ip_ct_tcp_timeout_established,
638 .maxlen = sizeof(unsigned int),
640 .proc_handler = &proc_dointvec_jiffies,
643 .ctl_name = NET_IPV4_NF_CONNTRACK_TCP_TIMEOUT_FIN_WAIT,
644 .procname = "ip_conntrack_tcp_timeout_fin_wait",
645 .data = &ip_ct_tcp_timeout_fin_wait,
646 .maxlen = sizeof(unsigned int),
648 .proc_handler = &proc_dointvec_jiffies,
651 .ctl_name = NET_IPV4_NF_CONNTRACK_TCP_TIMEOUT_CLOSE_WAIT,
652 .procname = "ip_conntrack_tcp_timeout_close_wait",
653 .data = &ip_ct_tcp_timeout_close_wait,
654 .maxlen = sizeof(unsigned int),
656 .proc_handler = &proc_dointvec_jiffies,
659 .ctl_name = NET_IPV4_NF_CONNTRACK_TCP_TIMEOUT_LAST_ACK,
660 .procname = "ip_conntrack_tcp_timeout_last_ack",
661 .data = &ip_ct_tcp_timeout_last_ack,
662 .maxlen = sizeof(unsigned int),
664 .proc_handler = &proc_dointvec_jiffies,
667 .ctl_name = NET_IPV4_NF_CONNTRACK_TCP_TIMEOUT_TIME_WAIT,
668 .procname = "ip_conntrack_tcp_timeout_time_wait",
669 .data = &ip_ct_tcp_timeout_time_wait,
670 .maxlen = sizeof(unsigned int),
672 .proc_handler = &proc_dointvec_jiffies,
675 .ctl_name = NET_IPV4_NF_CONNTRACK_TCP_TIMEOUT_CLOSE,
676 .procname = "ip_conntrack_tcp_timeout_close",
677 .data = &ip_ct_tcp_timeout_close,
678 .maxlen = sizeof(unsigned int),
680 .proc_handler = &proc_dointvec_jiffies,
683 .ctl_name = NET_IPV4_NF_CONNTRACK_UDP_TIMEOUT,
684 .procname = "ip_conntrack_udp_timeout",
685 .data = &ip_ct_udp_timeout,
686 .maxlen = sizeof(unsigned int),
688 .proc_handler = &proc_dointvec_jiffies,
691 .ctl_name = NET_IPV4_NF_CONNTRACK_UDP_TIMEOUT_STREAM,
692 .procname = "ip_conntrack_udp_timeout_stream",
693 .data = &ip_ct_udp_timeout_stream,
694 .maxlen = sizeof(unsigned int),
696 .proc_handler = &proc_dointvec_jiffies,
699 .ctl_name = NET_IPV4_NF_CONNTRACK_ICMP_TIMEOUT,
700 .procname = "ip_conntrack_icmp_timeout",
701 .data = &ip_ct_icmp_timeout,
702 .maxlen = sizeof(unsigned int),
704 .proc_handler = &proc_dointvec_jiffies,
707 .ctl_name = NET_IPV4_NF_CONNTRACK_GENERIC_TIMEOUT,
708 .procname = "ip_conntrack_generic_timeout",
709 .data = &ip_ct_generic_timeout,
710 .maxlen = sizeof(unsigned int),
712 .proc_handler = &proc_dointvec_jiffies,
715 .ctl_name = NET_IPV4_NF_CONNTRACK_LOG_INVALID,
716 .procname = "ip_conntrack_log_invalid",
717 .data = &ip_ct_log_invalid,
718 .maxlen = sizeof(unsigned int),
720 .proc_handler = &proc_dointvec_minmax,
721 .strategy = &sysctl_intvec,
722 .extra1 = &log_invalid_proto_min,
723 .extra2 = &log_invalid_proto_max,
726 .ctl_name = NET_IPV4_NF_CONNTRACK_TCP_TIMEOUT_MAX_RETRANS,
727 .procname = "ip_conntrack_tcp_timeout_max_retrans",
728 .data = &ip_ct_tcp_timeout_max_retrans,
729 .maxlen = sizeof(unsigned int),
731 .proc_handler = &proc_dointvec_jiffies,
734 .ctl_name = NET_IPV4_NF_CONNTRACK_TCP_LOOSE,
735 .procname = "ip_conntrack_tcp_loose",
736 .data = &ip_ct_tcp_loose,
737 .maxlen = sizeof(unsigned int),
739 .proc_handler = &proc_dointvec,
742 .ctl_name = NET_IPV4_NF_CONNTRACK_TCP_BE_LIBERAL,
743 .procname = "ip_conntrack_tcp_be_liberal",
744 .data = &ip_ct_tcp_be_liberal,
745 .maxlen = sizeof(unsigned int),
747 .proc_handler = &proc_dointvec,
750 .ctl_name = NET_IPV4_NF_CONNTRACK_TCP_MAX_RETRANS,
751 .procname = "ip_conntrack_tcp_max_retrans",
752 .data = &ip_ct_tcp_max_retrans,
753 .maxlen = sizeof(unsigned int),
755 .proc_handler = &proc_dointvec,
760 #define NET_IP_CONNTRACK_MAX 2089
762 static ctl_table ip_ct_netfilter_table[] = {
764 .ctl_name = NET_IPV4_NETFILTER,
765 .procname = "netfilter",
767 .child = ip_ct_sysctl_table,
770 .ctl_name = NET_IP_CONNTRACK_MAX,
771 .procname = "ip_conntrack_max",
772 .data = &ip_conntrack_max,
773 .maxlen = sizeof(int),
775 .proc_handler = &proc_dointvec
780 static ctl_table ip_ct_ipv4_table[] = {
782 .ctl_name = NET_IPV4,
785 .child = ip_ct_netfilter_table,
790 static ctl_table ip_ct_net_table[] = {
795 .child = ip_ct_ipv4_table,
800 EXPORT_SYMBOL(ip_ct_log_invalid);
801 #endif /* CONFIG_SYSCTL */
803 static int init_or_cleanup(int init)
805 #ifdef CONFIG_PROC_FS
806 struct proc_dir_entry *proc, *proc_exp, *proc_stat;
810 if (!init) goto cleanup;
812 ret = ip_conntrack_init();
814 goto cleanup_nothing;
816 #ifdef CONFIG_PROC_FS
818 proc = proc_net_fops_create("ip_conntrack", 0440, &ct_file_ops);
819 if (!proc) goto cleanup_init;
821 proc_exp = proc_net_fops_create("ip_conntrack_expect", 0440,
823 if (!proc_exp) goto cleanup_proc;
825 proc_stat = create_proc_entry("ip_conntrack", S_IRUGO, proc_net_stat);
827 goto cleanup_proc_exp;
829 proc_stat->proc_fops = &ct_cpu_seq_fops;
830 proc_stat->owner = THIS_MODULE;
833 ret = nf_register_hook(&ip_conntrack_defrag_ops);
835 printk("ip_conntrack: can't register pre-routing defrag hook.\n");
836 goto cleanup_proc_stat;
838 ret = nf_register_hook(&ip_conntrack_defrag_local_out_ops);
840 printk("ip_conntrack: can't register local_out defrag hook.\n");
841 goto cleanup_defragops;
843 ret = nf_register_hook(&ip_conntrack_in_ops);
845 printk("ip_conntrack: can't register pre-routing hook.\n");
846 goto cleanup_defraglocalops;
848 ret = nf_register_hook(&ip_conntrack_local_out_ops);
850 printk("ip_conntrack: can't register local out hook.\n");
853 ret = nf_register_hook(&ip_conntrack_helper_in_ops);
855 printk("ip_conntrack: can't register local in helper hook.\n");
856 goto cleanup_inandlocalops;
858 ret = nf_register_hook(&ip_conntrack_helper_out_ops);
860 printk("ip_conntrack: can't register postrouting helper hook.\n");
861 goto cleanup_helperinops;
863 ret = nf_register_hook(&ip_conntrack_out_ops);
865 printk("ip_conntrack: can't register post-routing hook.\n");
866 goto cleanup_helperoutops;
868 ret = nf_register_hook(&ip_conntrack_local_in_ops);
870 printk("ip_conntrack: can't register local in hook.\n");
871 goto cleanup_inoutandlocalops;
874 ip_ct_sysctl_header = register_sysctl_table(ip_ct_net_table, 0);
875 if (ip_ct_sysctl_header == NULL) {
876 printk("ip_conntrack: can't register to sysctl.\n");
878 goto cleanup_localinops;
886 unregister_sysctl_table(ip_ct_sysctl_header);
889 nf_unregister_hook(&ip_conntrack_local_in_ops);
890 cleanup_inoutandlocalops:
891 nf_unregister_hook(&ip_conntrack_out_ops);
892 cleanup_helperoutops:
893 nf_unregister_hook(&ip_conntrack_helper_out_ops);
895 nf_unregister_hook(&ip_conntrack_helper_in_ops);
896 cleanup_inandlocalops:
897 nf_unregister_hook(&ip_conntrack_local_out_ops);
899 nf_unregister_hook(&ip_conntrack_in_ops);
900 cleanup_defraglocalops:
901 nf_unregister_hook(&ip_conntrack_defrag_local_out_ops);
903 nf_unregister_hook(&ip_conntrack_defrag_ops);
905 #ifdef CONFIG_PROC_FS
906 remove_proc_entry("ip_conntrack", proc_net_stat);
908 proc_net_remove("ip_conntrack_expect");
910 proc_net_remove("ip_conntrack");
912 #endif /* CONFIG_PROC_FS */
913 ip_conntrack_cleanup();
918 /* FIXME: Allow NULL functions and sub in pointers to generic for
920 int ip_conntrack_protocol_register(struct ip_conntrack_protocol *proto)
924 WRITE_LOCK(&ip_conntrack_lock);
925 if (ip_ct_protos[proto->proto] != &ip_conntrack_generic_protocol) {
929 ip_ct_protos[proto->proto] = proto;
931 WRITE_UNLOCK(&ip_conntrack_lock);
935 void ip_conntrack_protocol_unregister(struct ip_conntrack_protocol *proto)
937 WRITE_LOCK(&ip_conntrack_lock);
938 ip_ct_protos[proto->proto] = &ip_conntrack_generic_protocol;
939 WRITE_UNLOCK(&ip_conntrack_lock);
941 /* Somebody could be still looking at the proto in bh. */
944 /* Remove all contrack entries for this protocol */
945 ip_ct_iterate_cleanup(kill_proto, &proto->proto);
948 static int __init init(void)
950 return init_or_cleanup(1);
953 static void __exit fini(void)
961 /* Some modules need us, but don't depend directly on any symbol.
962 They should call this. */
963 void need_ip_conntrack(void)
967 EXPORT_SYMBOL(ip_conntrack_protocol_register);
968 EXPORT_SYMBOL(ip_conntrack_protocol_unregister);
969 EXPORT_SYMBOL(ip_ct_get_tuple);
970 EXPORT_SYMBOL(invert_tuplepr);
971 EXPORT_SYMBOL(ip_conntrack_alter_reply);
972 EXPORT_SYMBOL(ip_conntrack_destroyed);
973 EXPORT_SYMBOL(need_ip_conntrack);
974 EXPORT_SYMBOL(ip_conntrack_helper_register);
975 EXPORT_SYMBOL(ip_conntrack_helper_unregister);
976 EXPORT_SYMBOL(ip_ct_iterate_cleanup);
977 EXPORT_SYMBOL(ip_ct_refresh_acct);
978 EXPORT_SYMBOL(ip_ct_protos);
979 EXPORT_SYMBOL(ip_ct_find_proto);
980 EXPORT_SYMBOL(ip_conntrack_expect_alloc);
981 EXPORT_SYMBOL(ip_conntrack_expect_free);
982 EXPORT_SYMBOL(ip_conntrack_expect_related);
983 EXPORT_SYMBOL(ip_conntrack_unexpect_related);
984 EXPORT_SYMBOL(ip_conntrack_tuple_taken);
985 EXPORT_SYMBOL(ip_ct_gather_frags);
986 EXPORT_SYMBOL(ip_conntrack_htable_size);
987 EXPORT_SYMBOL(ip_conntrack_lock);
988 EXPORT_SYMBOL(ip_conntrack_hash);
989 EXPORT_SYMBOL(ip_conntrack_untracked);
990 EXPORT_SYMBOL_GPL(ip_conntrack_find_get);
991 EXPORT_SYMBOL_GPL(ip_conntrack_put);
992 #ifdef CONFIG_IP_NF_NAT_NEEDED
993 EXPORT_SYMBOL(ip_conntrack_tcp_update);