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 (seq_print_counters(s, &conntrack->counters[IP_CT_DIR_ORIGINAL]))
171 if (!(test_bit(IPS_SEEN_REPLY_BIT, &conntrack->status)))
172 if (seq_printf(s, "[UNREPLIED] "))
175 if (print_tuple(s, &conntrack->tuplehash[IP_CT_DIR_REPLY].tuple,
179 if (seq_print_counters(s, &conntrack->counters[IP_CT_DIR_REPLY]))
182 if (test_bit(IPS_ASSURED_BIT, &conntrack->status))
183 if (seq_printf(s, "[ASSURED] "))
186 #if defined(CONFIG_IP_NF_CONNTRACK_MARK)
187 if (seq_printf(s, "mark=%u ", conntrack->mark))
191 #ifdef CONFIG_IP_NF_CONNTRACK_SECMARK
192 if (seq_printf(s, "secmark=%u ", conntrack->secmark))
196 if (seq_printf(s, "use=%u\n", atomic_read(&conntrack->ct_general.use)))
202 static struct seq_operations ct_seq_ops = {
203 .start = ct_seq_start,
209 static int ct_open(struct inode *inode, struct file *file)
211 struct seq_file *seq;
212 struct ct_iter_state *st;
215 st = kmalloc(sizeof(struct ct_iter_state), GFP_KERNEL);
218 ret = seq_open(file, &ct_seq_ops);
221 seq = file->private_data;
223 memset(st, 0, sizeof(struct ct_iter_state));
230 static struct file_operations ct_file_ops = {
231 .owner = THIS_MODULE,
235 .release = seq_release_private,
239 static void *exp_seq_start(struct seq_file *s, loff_t *pos)
241 struct list_head *e = &ip_conntrack_expect_list;
244 /* strange seq_file api calls stop even if we fail,
245 * thus we need to grab lock since stop unlocks */
246 read_lock_bh(&ip_conntrack_lock);
251 for (i = 0; i <= *pos; i++) {
253 if (e == &ip_conntrack_expect_list)
259 static void *exp_seq_next(struct seq_file *s, void *v, loff_t *pos)
261 struct list_head *e = v;
266 if (e == &ip_conntrack_expect_list)
272 static void exp_seq_stop(struct seq_file *s, void *v)
274 read_unlock_bh(&ip_conntrack_lock);
277 static int exp_seq_show(struct seq_file *s, void *v)
279 struct ip_conntrack_expect *expect = v;
281 if (expect->timeout.function)
282 seq_printf(s, "%ld ", timer_pending(&expect->timeout)
283 ? (long)(expect->timeout.expires - jiffies)/HZ : 0);
287 seq_printf(s, "proto=%u ", expect->tuple.dst.protonum);
289 print_tuple(s, &expect->tuple,
290 __ip_conntrack_proto_find(expect->tuple.dst.protonum));
291 return seq_putc(s, '\n');
294 static struct seq_operations exp_seq_ops = {
295 .start = exp_seq_start,
296 .next = exp_seq_next,
297 .stop = exp_seq_stop,
301 static int exp_open(struct inode *inode, struct file *file)
303 return seq_open(file, &exp_seq_ops);
306 static struct file_operations exp_file_ops = {
307 .owner = THIS_MODULE,
311 .release = seq_release
314 static void *ct_cpu_seq_start(struct seq_file *seq, loff_t *pos)
319 return SEQ_START_TOKEN;
321 for (cpu = *pos-1; cpu < NR_CPUS; ++cpu) {
322 if (!cpu_possible(cpu))
325 return &per_cpu(ip_conntrack_stat, cpu);
331 static void *ct_cpu_seq_next(struct seq_file *seq, void *v, loff_t *pos)
335 for (cpu = *pos; cpu < NR_CPUS; ++cpu) {
336 if (!cpu_possible(cpu))
339 return &per_cpu(ip_conntrack_stat, cpu);
345 static void ct_cpu_seq_stop(struct seq_file *seq, void *v)
349 static int ct_cpu_seq_show(struct seq_file *seq, void *v)
351 unsigned int nr_conntracks = atomic_read(&ip_conntrack_count);
352 struct ip_conntrack_stat *st = v;
354 if (v == SEQ_START_TOKEN) {
355 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");
359 seq_printf(seq, "%08x %08x %08x %08x %08x %08x %08x %08x "
360 "%08x %08x %08x %08x %08x %08x %08x %08x \n",
382 static struct seq_operations ct_cpu_seq_ops = {
383 .start = ct_cpu_seq_start,
384 .next = ct_cpu_seq_next,
385 .stop = ct_cpu_seq_stop,
386 .show = ct_cpu_seq_show,
389 static int ct_cpu_seq_open(struct inode *inode, struct file *file)
391 return seq_open(file, &ct_cpu_seq_ops);
394 static struct file_operations ct_cpu_seq_fops = {
395 .owner = THIS_MODULE,
396 .open = ct_cpu_seq_open,
399 .release = seq_release_private,
403 static unsigned int ip_confirm(unsigned int hooknum,
404 struct sk_buff **pskb,
405 const struct net_device *in,
406 const struct net_device *out,
407 int (*okfn)(struct sk_buff *))
409 /* We've seen it coming out the other side: confirm it */
410 return ip_conntrack_confirm(pskb);
413 static unsigned int ip_conntrack_help(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 struct ip_conntrack *ct;
420 enum ip_conntrack_info ctinfo;
422 /* This is where we call the helper: as the packet goes out. */
423 ct = ip_conntrack_get(*pskb, &ctinfo);
424 if (ct && ct->helper && ctinfo != IP_CT_RELATED + IP_CT_IS_REPLY) {
426 ret = ct->helper->help(pskb, ct, ctinfo);
427 if (ret != NF_ACCEPT)
433 static unsigned int ip_conntrack_defrag(unsigned int hooknum,
434 struct sk_buff **pskb,
435 const struct net_device *in,
436 const struct net_device *out,
437 int (*okfn)(struct sk_buff *))
439 #if !defined(CONFIG_IP_NF_NAT) && !defined(CONFIG_IP_NF_NAT_MODULE)
440 /* Previously seen (loopback)? Ignore. Do this before
446 /* Gather fragments. */
447 if ((*pskb)->nh.iph->frag_off & htons(IP_MF|IP_OFFSET)) {
448 *pskb = ip_ct_gather_frags(*pskb,
449 hooknum == NF_IP_PRE_ROUTING ?
450 IP_DEFRAG_CONNTRACK_IN :
451 IP_DEFRAG_CONNTRACK_OUT);
458 static unsigned int ip_conntrack_local(unsigned int hooknum,
459 struct sk_buff **pskb,
460 const struct net_device *in,
461 const struct net_device *out,
462 int (*okfn)(struct sk_buff *))
464 /* root is playing with raw sockets. */
465 if ((*pskb)->len < sizeof(struct iphdr)
466 || (*pskb)->nh.iph->ihl * 4 < sizeof(struct iphdr)) {
468 printk("ipt_hook: happy cracking.\n");
471 return ip_conntrack_in(hooknum, pskb, in, out, okfn);
474 /* Connection tracking may drop packets, but never alters them, so
475 make it the first hook. */
476 static struct nf_hook_ops ip_conntrack_ops[] = {
478 .hook = ip_conntrack_defrag,
479 .owner = THIS_MODULE,
481 .hooknum = NF_IP_PRE_ROUTING,
482 .priority = NF_IP_PRI_CONNTRACK_DEFRAG,
485 .hook = ip_conntrack_in,
486 .owner = THIS_MODULE,
488 .hooknum = NF_IP_PRE_ROUTING,
489 .priority = NF_IP_PRI_CONNTRACK,
492 .hook = ip_conntrack_defrag,
493 .owner = THIS_MODULE,
495 .hooknum = NF_IP_LOCAL_OUT,
496 .priority = NF_IP_PRI_CONNTRACK_DEFRAG,
499 .hook = ip_conntrack_local,
500 .owner = THIS_MODULE,
502 .hooknum = NF_IP_LOCAL_OUT,
503 .priority = NF_IP_PRI_CONNTRACK,
506 .hook = ip_conntrack_help,
507 .owner = THIS_MODULE,
509 .hooknum = NF_IP_POST_ROUTING,
510 .priority = NF_IP_PRI_CONNTRACK_HELPER,
513 .hook = ip_conntrack_help,
514 .owner = THIS_MODULE,
516 .hooknum = NF_IP_LOCAL_IN,
517 .priority = NF_IP_PRI_CONNTRACK_HELPER,
521 .owner = THIS_MODULE,
523 .hooknum = NF_IP_POST_ROUTING,
524 .priority = NF_IP_PRI_CONNTRACK_CONFIRM,
528 .owner = THIS_MODULE,
530 .hooknum = NF_IP_LOCAL_IN,
531 .priority = NF_IP_PRI_CONNTRACK_CONFIRM,
537 int ip_conntrack_checksum = 1;
541 /* From ip_conntrack_core.c */
542 extern int ip_conntrack_max;
543 extern unsigned int ip_conntrack_htable_size;
545 /* From ip_conntrack_proto_tcp.c */
546 extern unsigned int ip_ct_tcp_timeout_syn_sent;
547 extern unsigned int ip_ct_tcp_timeout_syn_recv;
548 extern unsigned int ip_ct_tcp_timeout_established;
549 extern unsigned int ip_ct_tcp_timeout_fin_wait;
550 extern unsigned int ip_ct_tcp_timeout_close_wait;
551 extern unsigned int ip_ct_tcp_timeout_last_ack;
552 extern unsigned int ip_ct_tcp_timeout_time_wait;
553 extern unsigned int ip_ct_tcp_timeout_close;
554 extern unsigned int ip_ct_tcp_timeout_max_retrans;
555 extern int ip_ct_tcp_loose;
556 extern int ip_ct_tcp_be_liberal;
557 extern int ip_ct_tcp_max_retrans;
559 /* From ip_conntrack_proto_udp.c */
560 extern unsigned int ip_ct_udp_timeout;
561 extern unsigned int ip_ct_udp_timeout_stream;
563 /* From ip_conntrack_proto_icmp.c */
564 extern unsigned int ip_ct_icmp_timeout;
566 /* From ip_conntrack_proto_icmp.c */
567 extern unsigned int ip_ct_generic_timeout;
569 /* Log invalid packets of a given protocol */
570 static int log_invalid_proto_min = 0;
571 static int log_invalid_proto_max = 255;
573 static struct ctl_table_header *ip_ct_sysctl_header;
575 static ctl_table ip_ct_sysctl_table[] = {
577 .ctl_name = NET_IPV4_NF_CONNTRACK_MAX,
578 .procname = "ip_conntrack_max",
579 .data = &ip_conntrack_max,
580 .maxlen = sizeof(int),
582 .proc_handler = &proc_dointvec,
585 .ctl_name = NET_IPV4_NF_CONNTRACK_COUNT,
586 .procname = "ip_conntrack_count",
587 .data = &ip_conntrack_count,
588 .maxlen = sizeof(int),
590 .proc_handler = &proc_dointvec,
593 .ctl_name = NET_IPV4_NF_CONNTRACK_BUCKETS,
594 .procname = "ip_conntrack_buckets",
595 .data = &ip_conntrack_htable_size,
596 .maxlen = sizeof(unsigned int),
598 .proc_handler = &proc_dointvec,
601 .ctl_name = NET_IPV4_NF_CONNTRACK_CHECKSUM,
602 .procname = "ip_conntrack_checksum",
603 .data = &ip_conntrack_checksum,
604 .maxlen = sizeof(int),
606 .proc_handler = &proc_dointvec,
609 .ctl_name = NET_IPV4_NF_CONNTRACK_TCP_TIMEOUT_SYN_SENT,
610 .procname = "ip_conntrack_tcp_timeout_syn_sent",
611 .data = &ip_ct_tcp_timeout_syn_sent,
612 .maxlen = sizeof(unsigned int),
614 .proc_handler = &proc_dointvec_jiffies,
617 .ctl_name = NET_IPV4_NF_CONNTRACK_TCP_TIMEOUT_SYN_RECV,
618 .procname = "ip_conntrack_tcp_timeout_syn_recv",
619 .data = &ip_ct_tcp_timeout_syn_recv,
620 .maxlen = sizeof(unsigned int),
622 .proc_handler = &proc_dointvec_jiffies,
625 .ctl_name = NET_IPV4_NF_CONNTRACK_TCP_TIMEOUT_ESTABLISHED,
626 .procname = "ip_conntrack_tcp_timeout_established",
627 .data = &ip_ct_tcp_timeout_established,
628 .maxlen = sizeof(unsigned int),
630 .proc_handler = &proc_dointvec_jiffies,
633 .ctl_name = NET_IPV4_NF_CONNTRACK_TCP_TIMEOUT_FIN_WAIT,
634 .procname = "ip_conntrack_tcp_timeout_fin_wait",
635 .data = &ip_ct_tcp_timeout_fin_wait,
636 .maxlen = sizeof(unsigned int),
638 .proc_handler = &proc_dointvec_jiffies,
641 .ctl_name = NET_IPV4_NF_CONNTRACK_TCP_TIMEOUT_CLOSE_WAIT,
642 .procname = "ip_conntrack_tcp_timeout_close_wait",
643 .data = &ip_ct_tcp_timeout_close_wait,
644 .maxlen = sizeof(unsigned int),
646 .proc_handler = &proc_dointvec_jiffies,
649 .ctl_name = NET_IPV4_NF_CONNTRACK_TCP_TIMEOUT_LAST_ACK,
650 .procname = "ip_conntrack_tcp_timeout_last_ack",
651 .data = &ip_ct_tcp_timeout_last_ack,
652 .maxlen = sizeof(unsigned int),
654 .proc_handler = &proc_dointvec_jiffies,
657 .ctl_name = NET_IPV4_NF_CONNTRACK_TCP_TIMEOUT_TIME_WAIT,
658 .procname = "ip_conntrack_tcp_timeout_time_wait",
659 .data = &ip_ct_tcp_timeout_time_wait,
660 .maxlen = sizeof(unsigned int),
662 .proc_handler = &proc_dointvec_jiffies,
665 .ctl_name = NET_IPV4_NF_CONNTRACK_TCP_TIMEOUT_CLOSE,
666 .procname = "ip_conntrack_tcp_timeout_close",
667 .data = &ip_ct_tcp_timeout_close,
668 .maxlen = sizeof(unsigned int),
670 .proc_handler = &proc_dointvec_jiffies,
673 .ctl_name = NET_IPV4_NF_CONNTRACK_UDP_TIMEOUT,
674 .procname = "ip_conntrack_udp_timeout",
675 .data = &ip_ct_udp_timeout,
676 .maxlen = sizeof(unsigned int),
678 .proc_handler = &proc_dointvec_jiffies,
681 .ctl_name = NET_IPV4_NF_CONNTRACK_UDP_TIMEOUT_STREAM,
682 .procname = "ip_conntrack_udp_timeout_stream",
683 .data = &ip_ct_udp_timeout_stream,
684 .maxlen = sizeof(unsigned int),
686 .proc_handler = &proc_dointvec_jiffies,
689 .ctl_name = NET_IPV4_NF_CONNTRACK_ICMP_TIMEOUT,
690 .procname = "ip_conntrack_icmp_timeout",
691 .data = &ip_ct_icmp_timeout,
692 .maxlen = sizeof(unsigned int),
694 .proc_handler = &proc_dointvec_jiffies,
697 .ctl_name = NET_IPV4_NF_CONNTRACK_GENERIC_TIMEOUT,
698 .procname = "ip_conntrack_generic_timeout",
699 .data = &ip_ct_generic_timeout,
700 .maxlen = sizeof(unsigned int),
702 .proc_handler = &proc_dointvec_jiffies,
705 .ctl_name = NET_IPV4_NF_CONNTRACK_LOG_INVALID,
706 .procname = "ip_conntrack_log_invalid",
707 .data = &ip_ct_log_invalid,
708 .maxlen = sizeof(unsigned int),
710 .proc_handler = &proc_dointvec_minmax,
711 .strategy = &sysctl_intvec,
712 .extra1 = &log_invalid_proto_min,
713 .extra2 = &log_invalid_proto_max,
716 .ctl_name = NET_IPV4_NF_CONNTRACK_TCP_TIMEOUT_MAX_RETRANS,
717 .procname = "ip_conntrack_tcp_timeout_max_retrans",
718 .data = &ip_ct_tcp_timeout_max_retrans,
719 .maxlen = sizeof(unsigned int),
721 .proc_handler = &proc_dointvec_jiffies,
724 .ctl_name = NET_IPV4_NF_CONNTRACK_TCP_LOOSE,
725 .procname = "ip_conntrack_tcp_loose",
726 .data = &ip_ct_tcp_loose,
727 .maxlen = sizeof(unsigned int),
729 .proc_handler = &proc_dointvec,
732 .ctl_name = NET_IPV4_NF_CONNTRACK_TCP_BE_LIBERAL,
733 .procname = "ip_conntrack_tcp_be_liberal",
734 .data = &ip_ct_tcp_be_liberal,
735 .maxlen = sizeof(unsigned int),
737 .proc_handler = &proc_dointvec,
740 .ctl_name = NET_IPV4_NF_CONNTRACK_TCP_MAX_RETRANS,
741 .procname = "ip_conntrack_tcp_max_retrans",
742 .data = &ip_ct_tcp_max_retrans,
743 .maxlen = sizeof(unsigned int),
745 .proc_handler = &proc_dointvec,
750 #define NET_IP_CONNTRACK_MAX 2089
752 static ctl_table ip_ct_netfilter_table[] = {
754 .ctl_name = NET_IPV4_NETFILTER,
755 .procname = "netfilter",
757 .child = ip_ct_sysctl_table,
760 .ctl_name = NET_IP_CONNTRACK_MAX,
761 .procname = "ip_conntrack_max",
762 .data = &ip_conntrack_max,
763 .maxlen = sizeof(int),
765 .proc_handler = &proc_dointvec
770 static ctl_table ip_ct_ipv4_table[] = {
772 .ctl_name = NET_IPV4,
775 .child = ip_ct_netfilter_table,
780 static ctl_table ip_ct_net_table[] = {
785 .child = ip_ct_ipv4_table,
790 EXPORT_SYMBOL(ip_ct_log_invalid);
791 #endif /* CONFIG_SYSCTL */
793 /* FIXME: Allow NULL functions and sub in pointers to generic for
795 int ip_conntrack_protocol_register(struct ip_conntrack_protocol *proto)
799 write_lock_bh(&ip_conntrack_lock);
800 if (ip_ct_protos[proto->proto] != &ip_conntrack_generic_protocol) {
804 ip_ct_protos[proto->proto] = proto;
806 write_unlock_bh(&ip_conntrack_lock);
810 void ip_conntrack_protocol_unregister(struct ip_conntrack_protocol *proto)
812 write_lock_bh(&ip_conntrack_lock);
813 ip_ct_protos[proto->proto] = &ip_conntrack_generic_protocol;
814 write_unlock_bh(&ip_conntrack_lock);
816 /* Somebody could be still looking at the proto in bh. */
819 /* Remove all contrack entries for this protocol */
820 ip_ct_iterate_cleanup(kill_proto, &proto->proto);
823 static int __init ip_conntrack_standalone_init(void)
825 #ifdef CONFIG_PROC_FS
826 struct proc_dir_entry *proc, *proc_exp, *proc_stat;
830 ret = ip_conntrack_init();
834 #ifdef CONFIG_PROC_FS
836 proc = proc_net_fops_create("ip_conntrack", 0440, &ct_file_ops);
837 if (!proc) goto cleanup_init;
839 proc_exp = proc_net_fops_create("ip_conntrack_expect", 0440,
841 if (!proc_exp) goto cleanup_proc;
843 proc_stat = create_proc_entry("ip_conntrack", S_IRUGO, proc_net_stat);
845 goto cleanup_proc_exp;
847 proc_stat->proc_fops = &ct_cpu_seq_fops;
848 proc_stat->owner = THIS_MODULE;
851 ret = nf_register_hooks(ip_conntrack_ops, ARRAY_SIZE(ip_conntrack_ops));
853 printk("ip_conntrack: can't register hooks.\n");
854 goto cleanup_proc_stat;
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");
868 nf_unregister_hooks(ip_conntrack_ops, ARRAY_SIZE(ip_conntrack_ops));
871 #ifdef CONFIG_PROC_FS
872 remove_proc_entry("ip_conntrack", proc_net_stat);
874 proc_net_remove("ip_conntrack_expect");
876 proc_net_remove("ip_conntrack");
878 #endif /* CONFIG_PROC_FS */
879 ip_conntrack_cleanup();
883 static void __exit ip_conntrack_standalone_fini(void)
887 unregister_sysctl_table(ip_ct_sysctl_header);
889 nf_unregister_hooks(ip_conntrack_ops, ARRAY_SIZE(ip_conntrack_ops));
890 #ifdef CONFIG_PROC_FS
891 remove_proc_entry("ip_conntrack", proc_net_stat);
892 proc_net_remove("ip_conntrack_expect");
893 proc_net_remove("ip_conntrack");
894 #endif /* CONFIG_PROC_FS */
895 ip_conntrack_cleanup();
898 module_init(ip_conntrack_standalone_init);
899 module_exit(ip_conntrack_standalone_fini);
901 /* Some modules need us, but don't depend directly on any symbol.
902 They should call this. */
903 void need_conntrack(void)
907 #ifdef CONFIG_IP_NF_CONNTRACK_EVENTS
908 EXPORT_SYMBOL_GPL(ip_conntrack_chain);
909 EXPORT_SYMBOL_GPL(ip_conntrack_expect_chain);
910 EXPORT_SYMBOL_GPL(ip_conntrack_register_notifier);
911 EXPORT_SYMBOL_GPL(ip_conntrack_unregister_notifier);
912 EXPORT_SYMBOL_GPL(__ip_ct_event_cache_init);
913 EXPORT_PER_CPU_SYMBOL_GPL(ip_conntrack_ecache);
915 EXPORT_SYMBOL(ip_conntrack_protocol_register);
916 EXPORT_SYMBOL(ip_conntrack_protocol_unregister);
917 EXPORT_SYMBOL(ip_ct_get_tuple);
918 EXPORT_SYMBOL(invert_tuplepr);
919 EXPORT_SYMBOL(ip_conntrack_alter_reply);
920 EXPORT_SYMBOL(ip_conntrack_destroyed);
921 EXPORT_SYMBOL(need_conntrack);
922 EXPORT_SYMBOL(ip_conntrack_helper_register);
923 EXPORT_SYMBOL(ip_conntrack_helper_unregister);
924 EXPORT_SYMBOL(ip_ct_iterate_cleanup);
925 EXPORT_SYMBOL(__ip_ct_refresh_acct);
927 EXPORT_SYMBOL(ip_conntrack_expect_alloc);
928 EXPORT_SYMBOL(ip_conntrack_expect_put);
929 EXPORT_SYMBOL_GPL(__ip_conntrack_expect_find);
930 EXPORT_SYMBOL_GPL(ip_conntrack_expect_find);
931 EXPORT_SYMBOL(ip_conntrack_expect_related);
932 EXPORT_SYMBOL(ip_conntrack_unexpect_related);
933 EXPORT_SYMBOL_GPL(ip_conntrack_expect_list);
934 EXPORT_SYMBOL_GPL(ip_ct_unlink_expect);
936 EXPORT_SYMBOL(ip_conntrack_tuple_taken);
937 EXPORT_SYMBOL(ip_ct_gather_frags);
938 EXPORT_SYMBOL(ip_conntrack_htable_size);
939 EXPORT_SYMBOL(ip_conntrack_lock);
940 EXPORT_SYMBOL(ip_conntrack_hash);
941 EXPORT_SYMBOL(ip_conntrack_untracked);
942 EXPORT_SYMBOL_GPL(ip_conntrack_find_get);
943 #ifdef CONFIG_IP_NF_NAT_NEEDED
944 EXPORT_SYMBOL(ip_conntrack_tcp_update);
947 EXPORT_SYMBOL_GPL(ip_conntrack_flush);
948 EXPORT_SYMBOL_GPL(__ip_conntrack_find);
950 EXPORT_SYMBOL_GPL(ip_conntrack_alloc);
951 EXPORT_SYMBOL_GPL(ip_conntrack_free);
952 EXPORT_SYMBOL_GPL(ip_conntrack_hash_insert);
954 EXPORT_SYMBOL_GPL(ip_ct_remove_expectations);
956 EXPORT_SYMBOL_GPL(ip_conntrack_helper_find_get);
957 EXPORT_SYMBOL_GPL(ip_conntrack_helper_put);
958 EXPORT_SYMBOL_GPL(__ip_conntrack_helper_find_byname);
960 EXPORT_SYMBOL_GPL(ip_conntrack_proto_find_get);
961 EXPORT_SYMBOL_GPL(ip_conntrack_proto_put);
962 EXPORT_SYMBOL_GPL(__ip_conntrack_proto_find);
963 EXPORT_SYMBOL_GPL(ip_conntrack_checksum);
964 #if defined(CONFIG_IP_NF_CONNTRACK_NETLINK) || \
965 defined(CONFIG_IP_NF_CONNTRACK_NETLINK_MODULE)
966 EXPORT_SYMBOL_GPL(ip_ct_port_tuple_to_nfattr);
967 EXPORT_SYMBOL_GPL(ip_ct_port_nfattr_to_tuple);