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
;
261 if (e
== &ip_conntrack_expect_list
)
267 static void exp_seq_stop(struct seq_file
*s
, void *v
)
269 READ_UNLOCK(&ip_conntrack_lock
);
272 static int exp_seq_show(struct seq_file
*s
, void *v
)
274 struct ip_conntrack_expect
*expect
= v
;
276 if (expect
->timeout
.function
)
277 seq_printf(s
, "%ld ", timer_pending(&expect
->timeout
)
278 ? (long)(expect
->timeout
.expires
- jiffies
)/HZ
: 0);
282 seq_printf(s
, "proto=%u ", expect
->tuple
.dst
.protonum
);
284 print_tuple(s
, &expect
->tuple
,
285 ip_ct_find_proto(expect
->tuple
.dst
.protonum
));
286 return seq_putc(s
, '\n');
289 static struct seq_operations exp_seq_ops
= {
290 .start
= exp_seq_start
,
291 .next
= exp_seq_next
,
292 .stop
= exp_seq_stop
,
296 static int exp_open(struct inode
*inode
, struct file
*file
)
298 return seq_open(file
, &exp_seq_ops
);
301 static struct file_operations exp_file_ops
= {
302 .owner
= THIS_MODULE
,
306 .release
= seq_release
309 static void *ct_cpu_seq_start(struct seq_file
*seq
, loff_t
*pos
)
314 return SEQ_START_TOKEN
;
316 for (cpu
= *pos
-1; cpu
< NR_CPUS
; ++cpu
) {
317 if (!cpu_possible(cpu
))
320 return &per_cpu(ip_conntrack_stat
, cpu
);
326 static void *ct_cpu_seq_next(struct seq_file
*seq
, void *v
, loff_t
*pos
)
330 for (cpu
= *pos
; cpu
< NR_CPUS
; ++cpu
) {
331 if (!cpu_possible(cpu
))
334 return &per_cpu(ip_conntrack_stat
, cpu
);
340 static void ct_cpu_seq_stop(struct seq_file
*seq
, void *v
)
344 static int ct_cpu_seq_show(struct seq_file
*seq
, void *v
)
346 unsigned int nr_conntracks
= atomic_read(&ip_conntrack_count
);
347 struct ip_conntrack_stat
*st
= v
;
349 if (v
== SEQ_START_TOKEN
) {
350 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");
354 seq_printf(seq
, "%08x %08x %08x %08x %08x %08x %08x %08x "
355 "%08x %08x %08x %08x %08x %08x %08x %08x \n",
377 static struct seq_operations ct_cpu_seq_ops
= {
378 .start
= ct_cpu_seq_start
,
379 .next
= ct_cpu_seq_next
,
380 .stop
= ct_cpu_seq_stop
,
381 .show
= ct_cpu_seq_show
,
384 static int ct_cpu_seq_open(struct inode
*inode
, struct file
*file
)
386 return seq_open(file
, &ct_cpu_seq_ops
);
389 static struct file_operations ct_cpu_seq_fops
= {
390 .owner
= THIS_MODULE
,
391 .open
= ct_cpu_seq_open
,
394 .release
= seq_release_private
,
398 static unsigned int ip_confirm(unsigned int hooknum
,
399 struct sk_buff
**pskb
,
400 const struct net_device
*in
,
401 const struct net_device
*out
,
402 int (*okfn
)(struct sk_buff
*))
404 struct ip_conntrack
*ct
;
405 enum ip_conntrack_info ctinfo
;
407 /* This is where we call the helper: as the packet goes out. */
408 ct
= ip_conntrack_get(*pskb
, &ctinfo
);
409 if (ct
&& ct
->helper
) {
411 ret
= ct
->helper
->help(pskb
, ct
, ctinfo
);
412 if (ret
!= NF_ACCEPT
)
416 /* We've seen it coming out the other side: confirm it */
417 return ip_conntrack_confirm(pskb
);
420 static unsigned int ip_conntrack_defrag(unsigned int hooknum
,
421 struct sk_buff
**pskb
,
422 const struct net_device
*in
,
423 const struct net_device
*out
,
424 int (*okfn
)(struct sk_buff
*))
426 #if !defined(CONFIG_IP_NF_NAT) && !defined(CONFIG_IP_NF_NAT_MODULE)
427 /* Previously seen (loopback)? Ignore. Do this before
433 /* Gather fragments. */
434 if ((*pskb
)->nh
.iph
->frag_off
& htons(IP_MF
|IP_OFFSET
)) {
435 *pskb
= ip_ct_gather_frags(*pskb
,
436 hooknum
== NF_IP_PRE_ROUTING
?
437 IP_DEFRAG_CONNTRACK_IN
:
438 IP_DEFRAG_CONNTRACK_OUT
);
445 static unsigned int ip_refrag(unsigned int hooknum
,
446 struct sk_buff
**pskb
,
447 const struct net_device
*in
,
448 const struct net_device
*out
,
449 int (*okfn
)(struct sk_buff
*))
451 struct rtable
*rt
= (struct rtable
*)(*pskb
)->dst
;
453 /* We've seen it coming out the other side: confirm */
454 if (ip_confirm(hooknum
, pskb
, in
, out
, okfn
) != NF_ACCEPT
)
457 /* Local packets are never produced too large for their
458 interface. We degfragment them at LOCAL_OUT, however,
459 so we have to refragment them here. */
460 if ((*pskb
)->len
> dst_mtu(&rt
->u
.dst
) &&
461 !skb_shinfo(*pskb
)->tso_size
) {
462 /* No hook can be after us, so this should be OK. */
463 ip_fragment(*pskb
, okfn
);
469 static unsigned int ip_conntrack_local(unsigned int hooknum
,
470 struct sk_buff
**pskb
,
471 const struct net_device
*in
,
472 const struct net_device
*out
,
473 int (*okfn
)(struct sk_buff
*))
475 /* root is playing with raw sockets. */
476 if ((*pskb
)->len
< sizeof(struct iphdr
)
477 || (*pskb
)->nh
.iph
->ihl
* 4 < sizeof(struct iphdr
)) {
479 printk("ipt_hook: happy cracking.\n");
482 return ip_conntrack_in(hooknum
, pskb
, in
, out
, okfn
);
485 /* Connection tracking may drop packets, but never alters them, so
486 make it the first hook. */
487 static struct nf_hook_ops ip_conntrack_defrag_ops
= {
488 .hook
= ip_conntrack_defrag
,
489 .owner
= THIS_MODULE
,
491 .hooknum
= NF_IP_PRE_ROUTING
,
492 .priority
= NF_IP_PRI_CONNTRACK_DEFRAG
,
495 static struct nf_hook_ops ip_conntrack_in_ops
= {
496 .hook
= ip_conntrack_in
,
497 .owner
= THIS_MODULE
,
499 .hooknum
= NF_IP_PRE_ROUTING
,
500 .priority
= NF_IP_PRI_CONNTRACK
,
503 static struct nf_hook_ops ip_conntrack_defrag_local_out_ops
= {
504 .hook
= ip_conntrack_defrag
,
505 .owner
= THIS_MODULE
,
507 .hooknum
= NF_IP_LOCAL_OUT
,
508 .priority
= NF_IP_PRI_CONNTRACK_DEFRAG
,
511 static struct nf_hook_ops ip_conntrack_local_out_ops
= {
512 .hook
= ip_conntrack_local
,
513 .owner
= THIS_MODULE
,
515 .hooknum
= NF_IP_LOCAL_OUT
,
516 .priority
= NF_IP_PRI_CONNTRACK
,
519 /* Refragmenter; last chance. */
520 static struct nf_hook_ops ip_conntrack_out_ops
= {
522 .owner
= THIS_MODULE
,
524 .hooknum
= NF_IP_POST_ROUTING
,
525 .priority
= NF_IP_PRI_LAST
,
528 static struct nf_hook_ops ip_conntrack_local_in_ops
= {
530 .owner
= THIS_MODULE
,
532 .hooknum
= NF_IP_LOCAL_IN
,
533 .priority
= NF_IP_PRI_LAST
-1,
540 /* From ip_conntrack_core.c */
541 extern int ip_conntrack_max
;
542 extern unsigned int ip_conntrack_htable_size
;
544 /* From ip_conntrack_proto_tcp.c */
545 extern unsigned long ip_ct_tcp_timeout_syn_sent
;
546 extern unsigned long ip_ct_tcp_timeout_syn_recv
;
547 extern unsigned long ip_ct_tcp_timeout_established
;
548 extern unsigned long ip_ct_tcp_timeout_fin_wait
;
549 extern unsigned long ip_ct_tcp_timeout_close_wait
;
550 extern unsigned long ip_ct_tcp_timeout_last_ack
;
551 extern unsigned long ip_ct_tcp_timeout_time_wait
;
552 extern unsigned long ip_ct_tcp_timeout_close
;
553 extern unsigned long ip_ct_tcp_timeout_max_retrans
;
554 extern int ip_ct_tcp_loose
;
555 extern int ip_ct_tcp_be_liberal
;
556 extern int ip_ct_tcp_max_retrans
;
558 /* From ip_conntrack_proto_udp.c */
559 extern unsigned long ip_ct_udp_timeout
;
560 extern unsigned long ip_ct_udp_timeout_stream
;
562 /* From ip_conntrack_proto_icmp.c */
563 extern unsigned long ip_ct_icmp_timeout
;
565 /* From ip_conntrack_proto_icmp.c */
566 extern unsigned long ip_ct_generic_timeout
;
568 /* Log invalid packets of a given protocol */
569 static int log_invalid_proto_min
= 0;
570 static int log_invalid_proto_max
= 255;
572 static struct ctl_table_header
*ip_ct_sysctl_header
;
574 static ctl_table ip_ct_sysctl_table
[] = {
576 .ctl_name
= NET_IPV4_NF_CONNTRACK_MAX
,
577 .procname
= "ip_conntrack_max",
578 .data
= &ip_conntrack_max
,
579 .maxlen
= sizeof(int),
581 .proc_handler
= &proc_dointvec
,
584 .ctl_name
= NET_IPV4_NF_CONNTRACK_COUNT
,
585 .procname
= "ip_conntrack_count",
586 .data
= &ip_conntrack_count
,
587 .maxlen
= sizeof(int),
589 .proc_handler
= &proc_dointvec
,
592 .ctl_name
= NET_IPV4_NF_CONNTRACK_BUCKETS
,
593 .procname
= "ip_conntrack_buckets",
594 .data
= &ip_conntrack_htable_size
,
595 .maxlen
= sizeof(unsigned int),
597 .proc_handler
= &proc_dointvec
,
600 .ctl_name
= NET_IPV4_NF_CONNTRACK_TCP_TIMEOUT_SYN_SENT
,
601 .procname
= "ip_conntrack_tcp_timeout_syn_sent",
602 .data
= &ip_ct_tcp_timeout_syn_sent
,
603 .maxlen
= sizeof(unsigned int),
605 .proc_handler
= &proc_dointvec_jiffies
,
608 .ctl_name
= NET_IPV4_NF_CONNTRACK_TCP_TIMEOUT_SYN_RECV
,
609 .procname
= "ip_conntrack_tcp_timeout_syn_recv",
610 .data
= &ip_ct_tcp_timeout_syn_recv
,
611 .maxlen
= sizeof(unsigned int),
613 .proc_handler
= &proc_dointvec_jiffies
,
616 .ctl_name
= NET_IPV4_NF_CONNTRACK_TCP_TIMEOUT_ESTABLISHED
,
617 .procname
= "ip_conntrack_tcp_timeout_established",
618 .data
= &ip_ct_tcp_timeout_established
,
619 .maxlen
= sizeof(unsigned int),
621 .proc_handler
= &proc_dointvec_jiffies
,
624 .ctl_name
= NET_IPV4_NF_CONNTRACK_TCP_TIMEOUT_FIN_WAIT
,
625 .procname
= "ip_conntrack_tcp_timeout_fin_wait",
626 .data
= &ip_ct_tcp_timeout_fin_wait
,
627 .maxlen
= sizeof(unsigned int),
629 .proc_handler
= &proc_dointvec_jiffies
,
632 .ctl_name
= NET_IPV4_NF_CONNTRACK_TCP_TIMEOUT_CLOSE_WAIT
,
633 .procname
= "ip_conntrack_tcp_timeout_close_wait",
634 .data
= &ip_ct_tcp_timeout_close_wait
,
635 .maxlen
= sizeof(unsigned int),
637 .proc_handler
= &proc_dointvec_jiffies
,
640 .ctl_name
= NET_IPV4_NF_CONNTRACK_TCP_TIMEOUT_LAST_ACK
,
641 .procname
= "ip_conntrack_tcp_timeout_last_ack",
642 .data
= &ip_ct_tcp_timeout_last_ack
,
643 .maxlen
= sizeof(unsigned int),
645 .proc_handler
= &proc_dointvec_jiffies
,
648 .ctl_name
= NET_IPV4_NF_CONNTRACK_TCP_TIMEOUT_TIME_WAIT
,
649 .procname
= "ip_conntrack_tcp_timeout_time_wait",
650 .data
= &ip_ct_tcp_timeout_time_wait
,
651 .maxlen
= sizeof(unsigned int),
653 .proc_handler
= &proc_dointvec_jiffies
,
656 .ctl_name
= NET_IPV4_NF_CONNTRACK_TCP_TIMEOUT_CLOSE
,
657 .procname
= "ip_conntrack_tcp_timeout_close",
658 .data
= &ip_ct_tcp_timeout_close
,
659 .maxlen
= sizeof(unsigned int),
661 .proc_handler
= &proc_dointvec_jiffies
,
664 .ctl_name
= NET_IPV4_NF_CONNTRACK_UDP_TIMEOUT
,
665 .procname
= "ip_conntrack_udp_timeout",
666 .data
= &ip_ct_udp_timeout
,
667 .maxlen
= sizeof(unsigned int),
669 .proc_handler
= &proc_dointvec_jiffies
,
672 .ctl_name
= NET_IPV4_NF_CONNTRACK_UDP_TIMEOUT_STREAM
,
673 .procname
= "ip_conntrack_udp_timeout_stream",
674 .data
= &ip_ct_udp_timeout_stream
,
675 .maxlen
= sizeof(unsigned int),
677 .proc_handler
= &proc_dointvec_jiffies
,
680 .ctl_name
= NET_IPV4_NF_CONNTRACK_ICMP_TIMEOUT
,
681 .procname
= "ip_conntrack_icmp_timeout",
682 .data
= &ip_ct_icmp_timeout
,
683 .maxlen
= sizeof(unsigned int),
685 .proc_handler
= &proc_dointvec_jiffies
,
688 .ctl_name
= NET_IPV4_NF_CONNTRACK_GENERIC_TIMEOUT
,
689 .procname
= "ip_conntrack_generic_timeout",
690 .data
= &ip_ct_generic_timeout
,
691 .maxlen
= sizeof(unsigned int),
693 .proc_handler
= &proc_dointvec_jiffies
,
696 .ctl_name
= NET_IPV4_NF_CONNTRACK_LOG_INVALID
,
697 .procname
= "ip_conntrack_log_invalid",
698 .data
= &ip_ct_log_invalid
,
699 .maxlen
= sizeof(unsigned int),
701 .proc_handler
= &proc_dointvec_minmax
,
702 .strategy
= &sysctl_intvec
,
703 .extra1
= &log_invalid_proto_min
,
704 .extra2
= &log_invalid_proto_max
,
707 .ctl_name
= NET_IPV4_NF_CONNTRACK_TCP_TIMEOUT_MAX_RETRANS
,
708 .procname
= "ip_conntrack_tcp_timeout_max_retrans",
709 .data
= &ip_ct_tcp_timeout_max_retrans
,
710 .maxlen
= sizeof(unsigned int),
712 .proc_handler
= &proc_dointvec_jiffies
,
715 .ctl_name
= NET_IPV4_NF_CONNTRACK_TCP_LOOSE
,
716 .procname
= "ip_conntrack_tcp_loose",
717 .data
= &ip_ct_tcp_loose
,
718 .maxlen
= sizeof(unsigned int),
720 .proc_handler
= &proc_dointvec
,
723 .ctl_name
= NET_IPV4_NF_CONNTRACK_TCP_BE_LIBERAL
,
724 .procname
= "ip_conntrack_tcp_be_liberal",
725 .data
= &ip_ct_tcp_be_liberal
,
726 .maxlen
= sizeof(unsigned int),
728 .proc_handler
= &proc_dointvec
,
731 .ctl_name
= NET_IPV4_NF_CONNTRACK_TCP_MAX_RETRANS
,
732 .procname
= "ip_conntrack_tcp_max_retrans",
733 .data
= &ip_ct_tcp_max_retrans
,
734 .maxlen
= sizeof(unsigned int),
736 .proc_handler
= &proc_dointvec
,
741 #define NET_IP_CONNTRACK_MAX 2089
743 static ctl_table ip_ct_netfilter_table
[] = {
745 .ctl_name
= NET_IPV4_NETFILTER
,
746 .procname
= "netfilter",
748 .child
= ip_ct_sysctl_table
,
751 .ctl_name
= NET_IP_CONNTRACK_MAX
,
752 .procname
= "ip_conntrack_max",
753 .data
= &ip_conntrack_max
,
754 .maxlen
= sizeof(int),
756 .proc_handler
= &proc_dointvec
761 static ctl_table ip_ct_ipv4_table
[] = {
763 .ctl_name
= NET_IPV4
,
766 .child
= ip_ct_netfilter_table
,
771 static ctl_table ip_ct_net_table
[] = {
776 .child
= ip_ct_ipv4_table
,
781 EXPORT_SYMBOL(ip_ct_log_invalid
);
782 #endif /* CONFIG_SYSCTL */
784 static int init_or_cleanup(int init
)
786 #ifdef CONFIG_PROC_FS
787 struct proc_dir_entry
*proc
, *proc_exp
, *proc_stat
;
791 if (!init
) goto cleanup
;
793 ret
= ip_conntrack_init();
795 goto cleanup_nothing
;
797 #ifdef CONFIG_PROC_FS
799 proc
= proc_net_fops_create("ip_conntrack", 0440, &ct_file_ops
);
800 if (!proc
) goto cleanup_init
;
802 proc_exp
= proc_net_fops_create("ip_conntrack_expect", 0440,
804 if (!proc_exp
) goto cleanup_proc
;
806 proc_stat
= create_proc_entry("ip_conntrack", S_IRUGO
, proc_net_stat
);
808 goto cleanup_proc_exp
;
810 proc_stat
->proc_fops
= &ct_cpu_seq_fops
;
811 proc_stat
->owner
= THIS_MODULE
;
814 ret
= nf_register_hook(&ip_conntrack_defrag_ops
);
816 printk("ip_conntrack: can't register pre-routing defrag hook.\n");
817 goto cleanup_proc_stat
;
819 ret
= nf_register_hook(&ip_conntrack_defrag_local_out_ops
);
821 printk("ip_conntrack: can't register local_out defrag hook.\n");
822 goto cleanup_defragops
;
824 ret
= nf_register_hook(&ip_conntrack_in_ops
);
826 printk("ip_conntrack: can't register pre-routing hook.\n");
827 goto cleanup_defraglocalops
;
829 ret
= nf_register_hook(&ip_conntrack_local_out_ops
);
831 printk("ip_conntrack: can't register local out hook.\n");
834 ret
= nf_register_hook(&ip_conntrack_out_ops
);
836 printk("ip_conntrack: can't register post-routing hook.\n");
837 goto cleanup_inandlocalops
;
839 ret
= nf_register_hook(&ip_conntrack_local_in_ops
);
841 printk("ip_conntrack: can't register local in hook.\n");
842 goto cleanup_inoutandlocalops
;
845 ip_ct_sysctl_header
= register_sysctl_table(ip_ct_net_table
, 0);
846 if (ip_ct_sysctl_header
== NULL
) {
847 printk("ip_conntrack: can't register to sysctl.\n");
849 goto cleanup_localinops
;
857 unregister_sysctl_table(ip_ct_sysctl_header
);
860 nf_unregister_hook(&ip_conntrack_local_in_ops
);
861 cleanup_inoutandlocalops
:
862 nf_unregister_hook(&ip_conntrack_out_ops
);
863 cleanup_inandlocalops
:
864 nf_unregister_hook(&ip_conntrack_local_out_ops
);
866 nf_unregister_hook(&ip_conntrack_in_ops
);
867 cleanup_defraglocalops
:
868 nf_unregister_hook(&ip_conntrack_defrag_local_out_ops
);
870 nf_unregister_hook(&ip_conntrack_defrag_ops
);
872 #ifdef CONFIG_PROC_FS
873 remove_proc_entry("ip_conntrack", proc_net_stat
);
875 proc_net_remove("ip_conntrack_expect");
877 proc_net_remove("ip_conntrack");
879 #endif /* CONFIG_PROC_FS */
880 ip_conntrack_cleanup();
885 /* FIXME: Allow NULL functions and sub in pointers to generic for
887 int ip_conntrack_protocol_register(struct ip_conntrack_protocol
*proto
)
891 WRITE_LOCK(&ip_conntrack_lock
);
892 if (ip_ct_protos
[proto
->proto
] != &ip_conntrack_generic_protocol
) {
896 ip_ct_protos
[proto
->proto
] = proto
;
898 WRITE_UNLOCK(&ip_conntrack_lock
);
902 void ip_conntrack_protocol_unregister(struct ip_conntrack_protocol
*proto
)
904 WRITE_LOCK(&ip_conntrack_lock
);
905 ip_ct_protos
[proto
->proto
] = &ip_conntrack_generic_protocol
;
906 WRITE_UNLOCK(&ip_conntrack_lock
);
908 /* Somebody could be still looking at the proto in bh. */
911 /* Remove all contrack entries for this protocol */
912 ip_ct_iterate_cleanup(kill_proto
, &proto
->proto
);
915 static int __init
init(void)
917 return init_or_cleanup(1);
920 static void __exit
fini(void)
928 /* Some modules need us, but don't depend directly on any symbol.
929 They should call this. */
930 void need_ip_conntrack(void)
934 EXPORT_SYMBOL(ip_conntrack_protocol_register
);
935 EXPORT_SYMBOL(ip_conntrack_protocol_unregister
);
936 EXPORT_SYMBOL(ip_ct_get_tuple
);
937 EXPORT_SYMBOL(invert_tuplepr
);
938 EXPORT_SYMBOL(ip_conntrack_alter_reply
);
939 EXPORT_SYMBOL(ip_conntrack_destroyed
);
940 EXPORT_SYMBOL(need_ip_conntrack
);
941 EXPORT_SYMBOL(ip_conntrack_helper_register
);
942 EXPORT_SYMBOL(ip_conntrack_helper_unregister
);
943 EXPORT_SYMBOL(ip_ct_iterate_cleanup
);
944 EXPORT_SYMBOL(ip_ct_refresh_acct
);
945 EXPORT_SYMBOL(ip_ct_protos
);
946 EXPORT_SYMBOL(ip_ct_find_proto
);
947 EXPORT_SYMBOL(ip_conntrack_expect_alloc
);
948 EXPORT_SYMBOL(ip_conntrack_expect_free
);
949 EXPORT_SYMBOL(ip_conntrack_expect_related
);
950 EXPORT_SYMBOL(ip_conntrack_unexpect_related
);
951 EXPORT_SYMBOL(ip_conntrack_tuple_taken
);
952 EXPORT_SYMBOL(ip_ct_gather_frags
);
953 EXPORT_SYMBOL(ip_conntrack_htable_size
);
954 EXPORT_SYMBOL(ip_conntrack_lock
);
955 EXPORT_SYMBOL(ip_conntrack_hash
);
956 EXPORT_SYMBOL(ip_conntrack_untracked
);
957 EXPORT_SYMBOL_GPL(ip_conntrack_find_get
);
958 EXPORT_SYMBOL_GPL(ip_conntrack_put
);
959 #ifdef CONFIG_IP_NF_NAT_NEEDED
960 EXPORT_SYMBOL(ip_conntrack_tcp_update
);