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/types.h>
17 #include <linux/netfilter.h>
18 #include <linux/netfilter_ipv4.h>
19 #include <linux/module.h>
20 #include <linux/skbuff.h>
21 #include <linux/proc_fs.h>
22 #include <linux/seq_file.h>
23 #include <linux/percpu.h>
25 #include <linux/sysctl.h>
27 #include <net/checksum.h>
29 #include <net/route.h>
31 #define ASSERT_READ_LOCK(x)
32 #define ASSERT_WRITE_LOCK(x)
34 #include <linux/netfilter_ipv4/ip_conntrack.h>
35 #include <linux/netfilter_ipv4/ip_conntrack_protocol.h>
36 #include <linux/netfilter_ipv4/ip_conntrack_core.h>
37 #include <linux/netfilter_ipv4/ip_conntrack_helper.h>
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 defined(CONFIG_VNET) || defined(CONFIG_VNET_MODULE)
169 if (seq_printf(s, "xid=%d\n", conntrack->xid[IP_CT_DIR_ORIGINAL]))
173 if (seq_print_counters(s, &conntrack->counters[IP_CT_DIR_ORIGINAL]))
176 if (!(test_bit(IPS_SEEN_REPLY_BIT, &conntrack->status)))
177 if (seq_printf(s, "[UNREPLIED] "))
180 if (print_tuple(s, &conntrack->tuplehash[IP_CT_DIR_REPLY].tuple,
184 #if defined(CONFIG_VNET) || defined(CONFIG_VNET_MODULE)
185 if (seq_printf(s, "xid=%d\n", conntrack->xid[IP_CT_DIR_REPLY]))
189 if (seq_print_counters(s, &conntrack->counters[IP_CT_DIR_REPLY]))
192 if (test_bit(IPS_ASSURED_BIT, &conntrack->status))
193 if (seq_printf(s, "[ASSURED] "))
196 #if defined(CONFIG_IP_NF_CONNTRACK_MARK)
197 if (seq_printf(s, "mark=%u ", conntrack->mark))
201 #ifdef CONFIG_IP_NF_CONNTRACK_SECMARK
202 if (seq_printf(s, "secmark=%u ", conntrack->secmark))
206 if (seq_printf(s, "use=%u\n", atomic_read(&conntrack->ct_general.use)))
212 static struct seq_operations ct_seq_ops = {
213 .start = ct_seq_start,
219 static int ct_open(struct inode *inode, struct file *file)
221 struct seq_file *seq;
222 struct ct_iter_state *st;
225 st = kmalloc(sizeof(struct ct_iter_state), GFP_KERNEL);
228 ret = seq_open(file, &ct_seq_ops);
231 seq = file->private_data;
233 memset(st, 0, sizeof(struct ct_iter_state));
240 static struct file_operations ct_file_ops = {
241 .owner = THIS_MODULE,
245 .release = seq_release_private,
249 static void *exp_seq_start(struct seq_file *s, loff_t *pos)
251 struct list_head *e = &ip_conntrack_expect_list;
254 /* strange seq_file api calls stop even if we fail,
255 * thus we need to grab lock since stop unlocks */
256 read_lock_bh(&ip_conntrack_lock);
261 for (i = 0; i <= *pos; i++) {
263 if (e == &ip_conntrack_expect_list)
269 static void *exp_seq_next(struct seq_file *s, void *v, loff_t *pos)
271 struct list_head *e = v;
276 if (e == &ip_conntrack_expect_list)
282 static void exp_seq_stop(struct seq_file *s, void *v)
284 read_unlock_bh(&ip_conntrack_lock);
287 static int exp_seq_show(struct seq_file *s, void *v)
289 struct ip_conntrack_expect *expect = v;
291 if (expect->timeout.function)
292 seq_printf(s, "%ld ", timer_pending(&expect->timeout)
293 ? (long)(expect->timeout.expires - jiffies)/HZ : 0);
297 seq_printf(s, "proto=%u ", expect->tuple.dst.protonum);
299 print_tuple(s, &expect->tuple,
300 __ip_conntrack_proto_find(expect->tuple.dst.protonum));
301 return seq_putc(s, '\n');
304 static struct seq_operations exp_seq_ops = {
305 .start = exp_seq_start,
306 .next = exp_seq_next,
307 .stop = exp_seq_stop,
311 static int exp_open(struct inode *inode, struct file *file)
313 return seq_open(file, &exp_seq_ops);
316 static struct file_operations exp_file_ops = {
317 .owner = THIS_MODULE,
321 .release = seq_release
324 static void *ct_cpu_seq_start(struct seq_file *seq, loff_t *pos)
329 return SEQ_START_TOKEN;
331 for (cpu = *pos-1; cpu < NR_CPUS; ++cpu) {
332 if (!cpu_possible(cpu))
335 return &per_cpu(ip_conntrack_stat, cpu);
341 static void *ct_cpu_seq_next(struct seq_file *seq, void *v, loff_t *pos)
345 for (cpu = *pos; cpu < NR_CPUS; ++cpu) {
346 if (!cpu_possible(cpu))
349 return &per_cpu(ip_conntrack_stat, cpu);
355 static void ct_cpu_seq_stop(struct seq_file *seq, void *v)
359 static int ct_cpu_seq_show(struct seq_file *seq, void *v)
361 unsigned int nr_conntracks = atomic_read(&ip_conntrack_count);
362 struct ip_conntrack_stat *st = v;
364 if (v == SEQ_START_TOKEN) {
365 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");
369 seq_printf(seq, "%08x %08x %08x %08x %08x %08x %08x %08x "
370 "%08x %08x %08x %08x %08x %08x %08x %08x \n",
392 static struct seq_operations ct_cpu_seq_ops = {
393 .start = ct_cpu_seq_start,
394 .next = ct_cpu_seq_next,
395 .stop = ct_cpu_seq_stop,
396 .show = ct_cpu_seq_show,
399 static int ct_cpu_seq_open(struct inode *inode, struct file *file)
401 return seq_open(file, &ct_cpu_seq_ops);
404 static struct file_operations ct_cpu_seq_fops = {
405 .owner = THIS_MODULE,
406 .open = ct_cpu_seq_open,
409 .release = seq_release_private,
413 static unsigned int ip_confirm(unsigned int hooknum,
414 struct sk_buff **pskb,
415 const struct net_device *in,
416 const struct net_device *out,
417 int (*okfn)(struct sk_buff *))
419 /* We've seen it coming out the other side: confirm it */
420 return ip_conntrack_confirm(pskb);
423 static unsigned int ip_conntrack_help(unsigned int hooknum,
424 struct sk_buff **pskb,
425 const struct net_device *in,
426 const struct net_device *out,
427 int (*okfn)(struct sk_buff *))
429 struct ip_conntrack *ct;
430 enum ip_conntrack_info ctinfo;
432 /* This is where we call the helper: as the packet goes out. */
433 ct = ip_conntrack_get(*pskb, &ctinfo);
434 if (ct && ct->helper && ctinfo != IP_CT_RELATED + IP_CT_IS_REPLY) {
436 ret = ct->helper->help(pskb, ct, ctinfo);
437 if (ret != NF_ACCEPT)
443 static unsigned int ip_conntrack_defrag(unsigned int hooknum,
444 struct sk_buff **pskb,
445 const struct net_device *in,
446 const struct net_device *out,
447 int (*okfn)(struct sk_buff *))
449 #if !defined(CONFIG_IP_NF_NAT) && !defined(CONFIG_IP_NF_NAT_MODULE)
450 /* Previously seen (loopback)? Ignore. Do this before
456 /* Gather fragments. */
457 if ((*pskb)->nh.iph->frag_off & htons(IP_MF|IP_OFFSET)) {
458 *pskb = ip_ct_gather_frags(*pskb,
459 hooknum == NF_IP_PRE_ROUTING ?
460 IP_DEFRAG_CONNTRACK_IN :
461 IP_DEFRAG_CONNTRACK_OUT);
468 static unsigned int ip_conntrack_local(unsigned int hooknum,
469 struct sk_buff **pskb,
470 const struct net_device *in,
471 const struct net_device *out,
472 int (*okfn)(struct sk_buff *))
474 /* root is playing with raw sockets. */
475 if ((*pskb)->len < sizeof(struct iphdr)
476 || (*pskb)->nh.iph->ihl * 4 < sizeof(struct iphdr)) {
478 printk("ipt_hook: happy cracking.\n");
481 return ip_conntrack_in(hooknum, pskb, in, out, okfn);
484 /* Connection tracking may drop packets, but never alters them, so
485 make it the first hook. */
486 static struct nf_hook_ops ip_conntrack_ops[] = {
488 .hook = ip_conntrack_defrag,
489 .owner = THIS_MODULE,
491 .hooknum = NF_IP_PRE_ROUTING,
492 .priority = NF_IP_PRI_CONNTRACK_DEFRAG,
495 .hook = ip_conntrack_in,
496 .owner = THIS_MODULE,
498 .hooknum = NF_IP_PRE_ROUTING,
499 .priority = NF_IP_PRI_CONNTRACK,
502 .hook = ip_conntrack_defrag,
503 .owner = THIS_MODULE,
505 .hooknum = NF_IP_LOCAL_OUT,
506 .priority = NF_IP_PRI_CONNTRACK_DEFRAG,
509 .hook = ip_conntrack_local,
510 .owner = THIS_MODULE,
512 .hooknum = NF_IP_LOCAL_OUT,
513 .priority = NF_IP_PRI_CONNTRACK,
516 .hook = ip_conntrack_help,
517 .owner = THIS_MODULE,
519 .hooknum = NF_IP_POST_ROUTING,
520 .priority = NF_IP_PRI_CONNTRACK_HELPER,
523 .hook = ip_conntrack_help,
524 .owner = THIS_MODULE,
526 .hooknum = NF_IP_LOCAL_IN,
527 .priority = NF_IP_PRI_CONNTRACK_HELPER,
531 .owner = THIS_MODULE,
533 .hooknum = NF_IP_POST_ROUTING,
534 .priority = NF_IP_PRI_CONNTRACK_CONFIRM,
538 .owner = THIS_MODULE,
540 .hooknum = NF_IP_LOCAL_IN,
541 .priority = NF_IP_PRI_CONNTRACK_CONFIRM,
547 int ip_conntrack_checksum = 1;
551 /* From ip_conntrack_core.c */
552 extern int ip_conntrack_max;
553 extern unsigned int ip_conntrack_htable_size;
555 /* From ip_conntrack_proto_tcp.c */
556 extern unsigned int ip_ct_tcp_timeout_syn_sent;
557 extern unsigned int ip_ct_tcp_timeout_syn_recv;
558 extern unsigned int ip_ct_tcp_timeout_established;
559 extern unsigned int ip_ct_tcp_timeout_fin_wait;
560 extern unsigned int ip_ct_tcp_timeout_close_wait;
561 extern unsigned int ip_ct_tcp_timeout_last_ack;
562 extern unsigned int ip_ct_tcp_timeout_time_wait;
563 extern unsigned int ip_ct_tcp_timeout_close;
564 extern unsigned int ip_ct_tcp_timeout_max_retrans;
565 extern int ip_ct_tcp_loose;
566 extern int ip_ct_tcp_be_liberal;
567 extern int ip_ct_tcp_max_retrans;
569 /* From ip_conntrack_proto_udp.c */
570 extern unsigned int ip_ct_udp_timeout;
571 extern unsigned int ip_ct_udp_timeout_stream;
573 /* From ip_conntrack_proto_icmp.c */
574 extern unsigned int ip_ct_icmp_timeout;
576 /* From ip_conntrack_proto_icmp.c */
577 extern unsigned int ip_ct_generic_timeout;
579 /* Log invalid packets of a given protocol */
580 static int log_invalid_proto_min = 0;
581 static int log_invalid_proto_max = 255;
583 static struct ctl_table_header *ip_ct_sysctl_header;
585 static ctl_table ip_ct_sysctl_table[] = {
587 .ctl_name = NET_IPV4_NF_CONNTRACK_MAX,
588 .procname = "ip_conntrack_max",
589 .data = &ip_conntrack_max,
590 .maxlen = sizeof(int),
592 .proc_handler = &proc_dointvec,
595 .ctl_name = NET_IPV4_NF_CONNTRACK_COUNT,
596 .procname = "ip_conntrack_count",
597 .data = &ip_conntrack_count,
598 .maxlen = sizeof(int),
600 .proc_handler = &proc_dointvec,
603 .ctl_name = NET_IPV4_NF_CONNTRACK_BUCKETS,
604 .procname = "ip_conntrack_buckets",
605 .data = &ip_conntrack_htable_size,
606 .maxlen = sizeof(unsigned int),
608 .proc_handler = &proc_dointvec,
611 .ctl_name = NET_IPV4_NF_CONNTRACK_CHECKSUM,
612 .procname = "ip_conntrack_checksum",
613 .data = &ip_conntrack_checksum,
614 .maxlen = sizeof(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 /* FIXME: Allow NULL functions and sub in pointers to generic for
805 int ip_conntrack_protocol_register(struct ip_conntrack_protocol *proto)
809 write_lock_bh(&ip_conntrack_lock);
810 if (ip_ct_protos[proto->proto] != &ip_conntrack_generic_protocol) {
814 ip_ct_protos[proto->proto] = proto;
816 write_unlock_bh(&ip_conntrack_lock);
820 void ip_conntrack_protocol_unregister(struct ip_conntrack_protocol *proto)
822 write_lock_bh(&ip_conntrack_lock);
823 ip_ct_protos[proto->proto] = &ip_conntrack_generic_protocol;
824 write_unlock_bh(&ip_conntrack_lock);
826 /* Somebody could be still looking at the proto in bh. */
829 /* Remove all contrack entries for this protocol */
830 ip_ct_iterate_cleanup(kill_proto, &proto->proto);
833 static int __init ip_conntrack_standalone_init(void)
835 #ifdef CONFIG_PROC_FS
836 struct proc_dir_entry *proc, *proc_exp, *proc_stat;
840 ret = ip_conntrack_init();
844 #ifdef CONFIG_PROC_FS
846 proc = proc_net_fops_create("ip_conntrack", 0440, &ct_file_ops);
847 if (!proc) goto cleanup_init;
849 proc_exp = proc_net_fops_create("ip_conntrack_expect", 0440,
851 if (!proc_exp) goto cleanup_proc;
853 proc_stat = create_proc_entry("ip_conntrack", S_IRUGO, proc_net_stat);
855 goto cleanup_proc_exp;
857 proc_stat->proc_fops = &ct_cpu_seq_fops;
858 proc_stat->owner = THIS_MODULE;
861 ret = nf_register_hooks(ip_conntrack_ops, ARRAY_SIZE(ip_conntrack_ops));
863 printk("ip_conntrack: can't register hooks.\n");
864 goto cleanup_proc_stat;
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");
878 nf_unregister_hooks(ip_conntrack_ops, ARRAY_SIZE(ip_conntrack_ops));
881 #ifdef CONFIG_PROC_FS
882 remove_proc_entry("ip_conntrack", proc_net_stat);
884 proc_net_remove("ip_conntrack_expect");
886 proc_net_remove("ip_conntrack");
888 #endif /* CONFIG_PROC_FS */
889 ip_conntrack_cleanup();
893 static void __exit ip_conntrack_standalone_fini(void)
897 unregister_sysctl_table(ip_ct_sysctl_header);
899 nf_unregister_hooks(ip_conntrack_ops, ARRAY_SIZE(ip_conntrack_ops));
900 #ifdef CONFIG_PROC_FS
901 remove_proc_entry("ip_conntrack", proc_net_stat);
902 proc_net_remove("ip_conntrack_expect");
903 proc_net_remove("ip_conntrack");
904 #endif /* CONFIG_PROC_FS */
905 ip_conntrack_cleanup();
908 module_init(ip_conntrack_standalone_init);
909 module_exit(ip_conntrack_standalone_fini);
911 /* Some modules need us, but don't depend directly on any symbol.
912 They should call this. */
913 void need_conntrack(void)
917 #ifdef CONFIG_IP_NF_CONNTRACK_EVENTS
918 EXPORT_SYMBOL_GPL(ip_conntrack_chain);
919 EXPORT_SYMBOL_GPL(ip_conntrack_expect_chain);
920 EXPORT_SYMBOL_GPL(ip_conntrack_register_notifier);
921 EXPORT_SYMBOL_GPL(ip_conntrack_unregister_notifier);
922 EXPORT_SYMBOL_GPL(__ip_ct_event_cache_init);
923 EXPORT_PER_CPU_SYMBOL_GPL(ip_conntrack_ecache);
925 EXPORT_SYMBOL(ip_conntrack_protocol_register);
926 EXPORT_SYMBOL(ip_conntrack_protocol_unregister);
927 EXPORT_SYMBOL(ip_ct_get_tuple);
928 EXPORT_SYMBOL(invert_tuplepr);
929 EXPORT_SYMBOL(ip_conntrack_alter_reply);
930 EXPORT_SYMBOL(ip_conntrack_destroyed);
931 EXPORT_SYMBOL(need_conntrack);
932 EXPORT_SYMBOL(ip_conntrack_helper_register);
933 EXPORT_SYMBOL(ip_conntrack_helper_unregister);
934 EXPORT_SYMBOL(ip_ct_iterate_cleanup);
935 EXPORT_SYMBOL(__ip_ct_refresh_acct);
937 EXPORT_SYMBOL(ip_conntrack_expect_alloc);
938 EXPORT_SYMBOL(ip_conntrack_expect_put);
939 EXPORT_SYMBOL_GPL(__ip_conntrack_expect_find);
940 EXPORT_SYMBOL_GPL(ip_conntrack_expect_find);
941 EXPORT_SYMBOL(ip_conntrack_expect_related);
942 EXPORT_SYMBOL(ip_conntrack_unexpect_related);
943 EXPORT_SYMBOL_GPL(ip_conntrack_expect_list);
944 EXPORT_SYMBOL_GPL(ip_ct_unlink_expect);
946 EXPORT_SYMBOL(ip_conntrack_tuple_taken);
947 EXPORT_SYMBOL(ip_ct_gather_frags);
948 EXPORT_SYMBOL(ip_conntrack_htable_size);
949 EXPORT_SYMBOL(ip_conntrack_lock);
950 EXPORT_SYMBOL(ip_conntrack_hash);
951 EXPORT_SYMBOL(ip_conntrack_untracked);
952 EXPORT_SYMBOL_GPL(ip_conntrack_find_get);
953 #ifdef CONFIG_IP_NF_NAT_NEEDED
954 EXPORT_SYMBOL(ip_conntrack_tcp_update);
957 EXPORT_SYMBOL_GPL(ip_conntrack_flush);
958 EXPORT_SYMBOL_GPL(__ip_conntrack_find);
960 EXPORT_SYMBOL_GPL(ip_conntrack_alloc);
961 EXPORT_SYMBOL_GPL(ip_conntrack_free);
962 EXPORT_SYMBOL_GPL(ip_conntrack_hash_insert);
964 EXPORT_SYMBOL_GPL(ip_ct_remove_expectations);
966 EXPORT_SYMBOL_GPL(ip_conntrack_helper_find_get);
967 EXPORT_SYMBOL_GPL(ip_conntrack_helper_put);
968 EXPORT_SYMBOL_GPL(__ip_conntrack_helper_find_byname);
970 EXPORT_SYMBOL_GPL(ip_conntrack_proto_find_get);
971 EXPORT_SYMBOL_GPL(ip_conntrack_proto_put);
972 EXPORT_SYMBOL_GPL(__ip_conntrack_proto_find);
973 EXPORT_SYMBOL_GPL(ip_conntrack_checksum);
974 #if defined(CONFIG_IP_NF_CONNTRACK_NETLINK) || \
975 defined(CONFIG_IP_NF_CONNTRACK_NETLINK_MODULE)
976 EXPORT_SYMBOL_GPL(ip_ct_port_tuple_to_nfattr);
977 EXPORT_SYMBOL_GPL(ip_ct_port_nfattr_to_tuple);