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>
42 #define DEBUGP(format, args...)
45 MODULE_LICENSE("GPL");
47 extern atomic_t ip_conntrack_count
;
48 DECLARE_PER_CPU(struct ip_conntrack_stat
, ip_conntrack_stat
);
50 static int kill_proto(struct ip_conntrack
*i
, void *data
)
52 return (i
->tuplehash
[IP_CT_DIR_ORIGINAL
].tuple
.dst
.protonum
==
53 *((u_int8_t
*) data
));
58 print_tuple(struct seq_file
*s
, const struct ip_conntrack_tuple
*tuple
,
59 struct ip_conntrack_protocol
*proto
)
61 seq_printf(s
, "src=%u.%u.%u.%u dst=%u.%u.%u.%u ",
62 NIPQUAD(tuple
->src
.ip
), NIPQUAD(tuple
->dst
.ip
));
63 return proto
->print_tuple(s
, tuple
);
66 #ifdef CONFIG_IP_NF_CT_ACCT
68 seq_print_counters(struct seq_file
*s
,
69 const struct ip_conntrack_counter
*counter
)
71 return seq_printf(s
, "packets=%llu bytes=%llu ",
72 (unsigned long long)counter
->packets
,
73 (unsigned long long)counter
->bytes
);
76 #define seq_print_counters(x, y) 0
79 struct ct_iter_state
{
83 static struct list_head
*ct_get_first(struct seq_file
*seq
)
85 struct ct_iter_state
*st
= seq
->private;
88 st
->bucket
< ip_conntrack_htable_size
;
90 if (!list_empty(&ip_conntrack_hash
[st
->bucket
]))
91 return ip_conntrack_hash
[st
->bucket
].next
;
96 static struct list_head
*ct_get_next(struct seq_file
*seq
, struct list_head
*head
)
98 struct ct_iter_state
*st
= seq
->private;
101 while (head
== &ip_conntrack_hash
[st
->bucket
]) {
102 if (++st
->bucket
>= ip_conntrack_htable_size
)
104 head
= ip_conntrack_hash
[st
->bucket
].next
;
109 static struct list_head
*ct_get_idx(struct seq_file
*seq
, loff_t pos
)
111 struct list_head
*head
= ct_get_first(seq
);
114 while (pos
&& (head
= ct_get_next(seq
, head
)))
116 return pos
? NULL
: head
;
119 static void *ct_seq_start(struct seq_file
*seq
, loff_t
*pos
)
121 read_lock_bh(&ip_conntrack_lock
);
122 return ct_get_idx(seq
, *pos
);
125 static void *ct_seq_next(struct seq_file
*s
, void *v
, loff_t
*pos
)
128 return ct_get_next(s
, v
);
131 static void ct_seq_stop(struct seq_file
*s
, void *v
)
133 read_unlock_bh(&ip_conntrack_lock
);
136 static int ct_seq_show(struct seq_file
*s
, void *v
)
138 const struct ip_conntrack_tuple_hash
*hash
= v
;
139 const struct ip_conntrack
*conntrack
= tuplehash_to_ctrack(hash
);
140 struct ip_conntrack_protocol
*proto
;
142 ASSERT_READ_LOCK(&ip_conntrack_lock
);
143 IP_NF_ASSERT(conntrack
);
145 /* we only want to print DIR_ORIGINAL */
149 proto
= __ip_conntrack_proto_find(conntrack
->tuplehash
[IP_CT_DIR_ORIGINAL
].tuple
.dst
.protonum
);
152 if (seq_printf(s
, "%-8s %u %ld ",
154 conntrack
->tuplehash
[IP_CT_DIR_ORIGINAL
].tuple
.dst
.protonum
,
155 timer_pending(&conntrack
->timeout
)
156 ? (long)(conntrack
->timeout
.expires
- jiffies
)/HZ
160 if (proto
->print_conntrack(s
, conntrack
))
163 if (print_tuple(s
, &conntrack
->tuplehash
[IP_CT_DIR_ORIGINAL
].tuple
,
167 if (seq_print_counters(s
, &conntrack
->counters
[IP_CT_DIR_ORIGINAL
]))
170 if (!(test_bit(IPS_SEEN_REPLY_BIT
, &conntrack
->status
)))
171 if (seq_printf(s
, "[UNREPLIED] "))
174 if (print_tuple(s
, &conntrack
->tuplehash
[IP_CT_DIR_REPLY
].tuple
,
178 if (seq_print_counters(s
, &conntrack
->counters
[IP_CT_DIR_REPLY
]))
181 if (test_bit(IPS_ASSURED_BIT
, &conntrack
->status
))
182 if (seq_printf(s
, "[ASSURED] "))
185 #if defined(CONFIG_IP_NF_CONNTRACK_MARK)
186 if (seq_printf(s
, "mark=%u ", conntrack
->mark
))
190 #ifdef CONFIG_IP_NF_CONNTRACK_SECMARK
191 if (seq_printf(s
, "secmark=%u ", conntrack
->secmark
))
195 #if defined(CONFIG_IP_NF_MATCH_LAYER7) || defined(CONFIG_IP_NF_MATCH_LAYER7_MODULE)
196 if(conntrack
->layer7
.app_proto
)
197 if (seq_printf(s
, "l7proto=%s ",conntrack
->layer7
.app_proto
))
201 if (seq_printf(s
, "use=%u\n", atomic_read(&conntrack
->ct_general
.use
)))
207 static struct seq_operations ct_seq_ops
= {
208 .start
= ct_seq_start
,
214 static int ct_open(struct inode
*inode
, struct file
*file
)
216 struct seq_file
*seq
;
217 struct ct_iter_state
*st
;
220 st
= kmalloc(sizeof(struct ct_iter_state
), GFP_KERNEL
);
223 ret
= seq_open(file
, &ct_seq_ops
);
226 seq
= file
->private_data
;
228 memset(st
, 0, sizeof(struct ct_iter_state
));
235 static struct file_operations ct_file_ops
= {
236 .owner
= THIS_MODULE
,
240 .release
= seq_release_private
,
244 static void *exp_seq_start(struct seq_file
*s
, loff_t
*pos
)
246 struct list_head
*e
= &ip_conntrack_expect_list
;
249 /* strange seq_file api calls stop even if we fail,
250 * thus we need to grab lock since stop unlocks */
251 read_lock_bh(&ip_conntrack_lock
);
256 for (i
= 0; i
<= *pos
; i
++) {
258 if (e
== &ip_conntrack_expect_list
)
264 static void *exp_seq_next(struct seq_file
*s
, void *v
, loff_t
*pos
)
266 struct list_head
*e
= v
;
271 if (e
== &ip_conntrack_expect_list
)
277 static void exp_seq_stop(struct seq_file
*s
, void *v
)
279 read_unlock_bh(&ip_conntrack_lock
);
282 static int exp_seq_show(struct seq_file
*s
, void *v
)
284 struct ip_conntrack_expect
*expect
= v
;
286 if (expect
->timeout
.function
)
287 seq_printf(s
, "%ld ", timer_pending(&expect
->timeout
)
288 ? (long)(expect
->timeout
.expires
- jiffies
)/HZ
: 0);
292 seq_printf(s
, "proto=%u ", expect
->tuple
.dst
.protonum
);
294 print_tuple(s
, &expect
->tuple
,
295 __ip_conntrack_proto_find(expect
->tuple
.dst
.protonum
));
296 return seq_putc(s
, '\n');
299 static struct seq_operations exp_seq_ops
= {
300 .start
= exp_seq_start
,
301 .next
= exp_seq_next
,
302 .stop
= exp_seq_stop
,
306 static int exp_open(struct inode
*inode
, struct file
*file
)
308 return seq_open(file
, &exp_seq_ops
);
311 static struct file_operations exp_file_ops
= {
312 .owner
= THIS_MODULE
,
316 .release
= seq_release
319 static void *ct_cpu_seq_start(struct seq_file
*seq
, loff_t
*pos
)
324 return SEQ_START_TOKEN
;
326 for (cpu
= *pos
-1; cpu
< NR_CPUS
; ++cpu
) {
327 if (!cpu_possible(cpu
))
330 return &per_cpu(ip_conntrack_stat
, cpu
);
336 static void *ct_cpu_seq_next(struct seq_file
*seq
, void *v
, loff_t
*pos
)
340 for (cpu
= *pos
; cpu
< NR_CPUS
; ++cpu
) {
341 if (!cpu_possible(cpu
))
344 return &per_cpu(ip_conntrack_stat
, cpu
);
350 static void ct_cpu_seq_stop(struct seq_file
*seq
, void *v
)
354 static int ct_cpu_seq_show(struct seq_file
*seq
, void *v
)
356 unsigned int nr_conntracks
= atomic_read(&ip_conntrack_count
);
357 struct ip_conntrack_stat
*st
= v
;
359 if (v
== SEQ_START_TOKEN
) {
360 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");
364 seq_printf(seq
, "%08x %08x %08x %08x %08x %08x %08x %08x "
365 "%08x %08x %08x %08x %08x %08x %08x %08x \n",
387 static struct seq_operations ct_cpu_seq_ops
= {
388 .start
= ct_cpu_seq_start
,
389 .next
= ct_cpu_seq_next
,
390 .stop
= ct_cpu_seq_stop
,
391 .show
= ct_cpu_seq_show
,
394 static int ct_cpu_seq_open(struct inode
*inode
, struct file
*file
)
396 return seq_open(file
, &ct_cpu_seq_ops
);
399 static struct file_operations ct_cpu_seq_fops
= {
400 .owner
= THIS_MODULE
,
401 .open
= ct_cpu_seq_open
,
404 .release
= seq_release_private
,
408 static unsigned int ip_confirm(unsigned int hooknum
,
409 struct sk_buff
**pskb
,
410 const struct net_device
*in
,
411 const struct net_device
*out
,
412 int (*okfn
)(struct sk_buff
*))
414 /* We've seen it coming out the other side: confirm it */
415 return ip_conntrack_confirm(pskb
);
418 static unsigned int ip_conntrack_help(unsigned int hooknum
,
419 struct sk_buff
**pskb
,
420 const struct net_device
*in
,
421 const struct net_device
*out
,
422 int (*okfn
)(struct sk_buff
*))
424 struct ip_conntrack
*ct
;
425 enum ip_conntrack_info ctinfo
;
427 /* This is where we call the helper: as the packet goes out. */
428 ct
= ip_conntrack_get(*pskb
, &ctinfo
);
429 if (ct
&& ct
->helper
&& ctinfo
!= IP_CT_RELATED
+ IP_CT_IS_REPLY
) {
431 ret
= ct
->helper
->help(pskb
, ct
, ctinfo
);
432 if (ret
!= NF_ACCEPT
)
438 static unsigned int ip_conntrack_defrag(unsigned int hooknum
,
439 struct sk_buff
**pskb
,
440 const struct net_device
*in
,
441 const struct net_device
*out
,
442 int (*okfn
)(struct sk_buff
*))
444 #if !defined(CONFIG_IP_NF_NAT) && !defined(CONFIG_IP_NF_NAT_MODULE)
445 /* Previously seen (loopback)? Ignore. Do this before
451 /* Gather fragments. */
452 if ((*pskb
)->nh
.iph
->frag_off
& htons(IP_MF
|IP_OFFSET
)) {
453 *pskb
= ip_ct_gather_frags(*pskb
,
454 hooknum
== NF_IP_PRE_ROUTING
?
455 IP_DEFRAG_CONNTRACK_IN
:
456 IP_DEFRAG_CONNTRACK_OUT
);
463 static unsigned int ip_conntrack_local(unsigned int hooknum
,
464 struct sk_buff
**pskb
,
465 const struct net_device
*in
,
466 const struct net_device
*out
,
467 int (*okfn
)(struct sk_buff
*))
469 /* root is playing with raw sockets. */
470 if ((*pskb
)->len
< sizeof(struct iphdr
)
471 || (*pskb
)->nh
.iph
->ihl
* 4 < sizeof(struct iphdr
)) {
473 printk("ipt_hook: happy cracking.\n");
476 return ip_conntrack_in(hooknum
, pskb
, in
, out
, okfn
);
479 /* Connection tracking may drop packets, but never alters them, so
480 make it the first hook. */
481 static struct nf_hook_ops ip_conntrack_ops
[] = {
483 .hook
= ip_conntrack_defrag
,
484 .owner
= THIS_MODULE
,
486 .hooknum
= NF_IP_PRE_ROUTING
,
487 .priority
= NF_IP_PRI_CONNTRACK_DEFRAG
,
490 .hook
= ip_conntrack_in
,
491 .owner
= THIS_MODULE
,
493 .hooknum
= NF_IP_PRE_ROUTING
,
494 .priority
= NF_IP_PRI_CONNTRACK
,
497 .hook
= ip_conntrack_defrag
,
498 .owner
= THIS_MODULE
,
500 .hooknum
= NF_IP_LOCAL_OUT
,
501 .priority
= NF_IP_PRI_CONNTRACK_DEFRAG
,
504 .hook
= ip_conntrack_local
,
505 .owner
= THIS_MODULE
,
507 .hooknum
= NF_IP_LOCAL_OUT
,
508 .priority
= NF_IP_PRI_CONNTRACK
,
511 .hook
= ip_conntrack_help
,
512 .owner
= THIS_MODULE
,
514 .hooknum
= NF_IP_POST_ROUTING
,
515 .priority
= NF_IP_PRI_CONNTRACK_HELPER
,
518 .hook
= ip_conntrack_help
,
519 .owner
= THIS_MODULE
,
521 .hooknum
= NF_IP_LOCAL_IN
,
522 .priority
= NF_IP_PRI_CONNTRACK_HELPER
,
526 .owner
= THIS_MODULE
,
528 .hooknum
= NF_IP_POST_ROUTING
,
529 .priority
= NF_IP_PRI_CONNTRACK_CONFIRM
,
533 .owner
= THIS_MODULE
,
535 .hooknum
= NF_IP_LOCAL_IN
,
536 .priority
= NF_IP_PRI_CONNTRACK_CONFIRM
,
542 int ip_conntrack_checksum __read_mostly
= 1;
546 /* From ip_conntrack_core.c */
547 extern int ip_conntrack_max
;
548 extern unsigned int ip_conntrack_htable_size
;
550 /* From ip_conntrack_proto_tcp.c */
551 extern unsigned int ip_ct_tcp_timeout_syn_sent
;
552 extern unsigned int ip_ct_tcp_timeout_syn_recv
;
553 extern unsigned int ip_ct_tcp_timeout_established
;
554 extern unsigned int ip_ct_tcp_timeout_fin_wait
;
555 extern unsigned int ip_ct_tcp_timeout_close_wait
;
556 extern unsigned int ip_ct_tcp_timeout_last_ack
;
557 extern unsigned int ip_ct_tcp_timeout_time_wait
;
558 extern unsigned int ip_ct_tcp_timeout_close
;
559 extern unsigned int ip_ct_tcp_timeout_max_retrans
;
560 extern int ip_ct_tcp_loose
;
561 extern int ip_ct_tcp_be_liberal
;
562 extern int ip_ct_tcp_max_retrans
;
564 /* From ip_conntrack_proto_udp.c */
565 extern unsigned int ip_ct_udp_timeout
;
566 extern unsigned int ip_ct_udp_timeout_stream
;
568 /* From ip_conntrack_proto_icmp.c */
569 extern unsigned int ip_ct_icmp_timeout
;
571 /* From ip_conntrack_proto_generic.c */
572 extern unsigned int ip_ct_generic_timeout
;
574 /* Log invalid packets of a given protocol */
575 static int log_invalid_proto_min
= 0;
576 static int log_invalid_proto_max
= 255;
578 static struct ctl_table_header
*ip_ct_sysctl_header
;
580 static ctl_table ip_ct_sysctl_table
[] = {
582 .ctl_name
= NET_IPV4_NF_CONNTRACK_MAX
,
583 .procname
= "ip_conntrack_max",
584 .data
= &ip_conntrack_max
,
585 .maxlen
= sizeof(int),
587 .proc_handler
= &proc_dointvec
,
590 .ctl_name
= NET_IPV4_NF_CONNTRACK_COUNT
,
591 .procname
= "ip_conntrack_count",
592 .data
= &ip_conntrack_count
,
593 .maxlen
= sizeof(int),
595 .proc_handler
= &proc_dointvec
,
598 .ctl_name
= NET_IPV4_NF_CONNTRACK_BUCKETS
,
599 .procname
= "ip_conntrack_buckets",
600 .data
= &ip_conntrack_htable_size
,
601 .maxlen
= sizeof(unsigned int),
603 .proc_handler
= &proc_dointvec
,
606 .ctl_name
= NET_IPV4_NF_CONNTRACK_CHECKSUM
,
607 .procname
= "ip_conntrack_checksum",
608 .data
= &ip_conntrack_checksum
,
609 .maxlen
= sizeof(int),
611 .proc_handler
= &proc_dointvec
,
614 .ctl_name
= NET_IPV4_NF_CONNTRACK_TCP_TIMEOUT_SYN_SENT
,
615 .procname
= "ip_conntrack_tcp_timeout_syn_sent",
616 .data
= &ip_ct_tcp_timeout_syn_sent
,
617 .maxlen
= sizeof(unsigned int),
619 .proc_handler
= &proc_dointvec_jiffies
,
622 .ctl_name
= NET_IPV4_NF_CONNTRACK_TCP_TIMEOUT_SYN_RECV
,
623 .procname
= "ip_conntrack_tcp_timeout_syn_recv",
624 .data
= &ip_ct_tcp_timeout_syn_recv
,
625 .maxlen
= sizeof(unsigned int),
627 .proc_handler
= &proc_dointvec_jiffies
,
630 .ctl_name
= NET_IPV4_NF_CONNTRACK_TCP_TIMEOUT_ESTABLISHED
,
631 .procname
= "ip_conntrack_tcp_timeout_established",
632 .data
= &ip_ct_tcp_timeout_established
,
633 .maxlen
= sizeof(unsigned int),
635 .proc_handler
= &proc_dointvec_jiffies
,
638 .ctl_name
= NET_IPV4_NF_CONNTRACK_TCP_TIMEOUT_FIN_WAIT
,
639 .procname
= "ip_conntrack_tcp_timeout_fin_wait",
640 .data
= &ip_ct_tcp_timeout_fin_wait
,
641 .maxlen
= sizeof(unsigned int),
643 .proc_handler
= &proc_dointvec_jiffies
,
646 .ctl_name
= NET_IPV4_NF_CONNTRACK_TCP_TIMEOUT_CLOSE_WAIT
,
647 .procname
= "ip_conntrack_tcp_timeout_close_wait",
648 .data
= &ip_ct_tcp_timeout_close_wait
,
649 .maxlen
= sizeof(unsigned int),
651 .proc_handler
= &proc_dointvec_jiffies
,
654 .ctl_name
= NET_IPV4_NF_CONNTRACK_TCP_TIMEOUT_LAST_ACK
,
655 .procname
= "ip_conntrack_tcp_timeout_last_ack",
656 .data
= &ip_ct_tcp_timeout_last_ack
,
657 .maxlen
= sizeof(unsigned int),
659 .proc_handler
= &proc_dointvec_jiffies
,
662 .ctl_name
= NET_IPV4_NF_CONNTRACK_TCP_TIMEOUT_TIME_WAIT
,
663 .procname
= "ip_conntrack_tcp_timeout_time_wait",
664 .data
= &ip_ct_tcp_timeout_time_wait
,
665 .maxlen
= sizeof(unsigned int),
667 .proc_handler
= &proc_dointvec_jiffies
,
670 .ctl_name
= NET_IPV4_NF_CONNTRACK_TCP_TIMEOUT_CLOSE
,
671 .procname
= "ip_conntrack_tcp_timeout_close",
672 .data
= &ip_ct_tcp_timeout_close
,
673 .maxlen
= sizeof(unsigned int),
675 .proc_handler
= &proc_dointvec_jiffies
,
678 .ctl_name
= NET_IPV4_NF_CONNTRACK_UDP_TIMEOUT
,
679 .procname
= "ip_conntrack_udp_timeout",
680 .data
= &ip_ct_udp_timeout
,
681 .maxlen
= sizeof(unsigned int),
683 .proc_handler
= &proc_dointvec_jiffies
,
686 .ctl_name
= NET_IPV4_NF_CONNTRACK_UDP_TIMEOUT_STREAM
,
687 .procname
= "ip_conntrack_udp_timeout_stream",
688 .data
= &ip_ct_udp_timeout_stream
,
689 .maxlen
= sizeof(unsigned int),
691 .proc_handler
= &proc_dointvec_jiffies
,
694 .ctl_name
= NET_IPV4_NF_CONNTRACK_ICMP_TIMEOUT
,
695 .procname
= "ip_conntrack_icmp_timeout",
696 .data
= &ip_ct_icmp_timeout
,
697 .maxlen
= sizeof(unsigned int),
699 .proc_handler
= &proc_dointvec_jiffies
,
702 .ctl_name
= NET_IPV4_NF_CONNTRACK_GENERIC_TIMEOUT
,
703 .procname
= "ip_conntrack_generic_timeout",
704 .data
= &ip_ct_generic_timeout
,
705 .maxlen
= sizeof(unsigned int),
707 .proc_handler
= &proc_dointvec_jiffies
,
710 .ctl_name
= NET_IPV4_NF_CONNTRACK_LOG_INVALID
,
711 .procname
= "ip_conntrack_log_invalid",
712 .data
= &ip_ct_log_invalid
,
713 .maxlen
= sizeof(unsigned int),
715 .proc_handler
= &proc_dointvec_minmax
,
716 .strategy
= &sysctl_intvec
,
717 .extra1
= &log_invalid_proto_min
,
718 .extra2
= &log_invalid_proto_max
,
721 .ctl_name
= NET_IPV4_NF_CONNTRACK_TCP_TIMEOUT_MAX_RETRANS
,
722 .procname
= "ip_conntrack_tcp_timeout_max_retrans",
723 .data
= &ip_ct_tcp_timeout_max_retrans
,
724 .maxlen
= sizeof(unsigned int),
726 .proc_handler
= &proc_dointvec_jiffies
,
729 .ctl_name
= NET_IPV4_NF_CONNTRACK_TCP_LOOSE
,
730 .procname
= "ip_conntrack_tcp_loose",
731 .data
= &ip_ct_tcp_loose
,
732 .maxlen
= sizeof(unsigned int),
734 .proc_handler
= &proc_dointvec
,
737 .ctl_name
= NET_IPV4_NF_CONNTRACK_TCP_BE_LIBERAL
,
738 .procname
= "ip_conntrack_tcp_be_liberal",
739 .data
= &ip_ct_tcp_be_liberal
,
740 .maxlen
= sizeof(unsigned int),
742 .proc_handler
= &proc_dointvec
,
745 .ctl_name
= NET_IPV4_NF_CONNTRACK_TCP_MAX_RETRANS
,
746 .procname
= "ip_conntrack_tcp_max_retrans",
747 .data
= &ip_ct_tcp_max_retrans
,
748 .maxlen
= sizeof(unsigned int),
750 .proc_handler
= &proc_dointvec
,
755 #define NET_IP_CONNTRACK_MAX 2089
757 static ctl_table ip_ct_netfilter_table
[] = {
759 .ctl_name
= NET_IPV4_NETFILTER
,
760 .procname
= "netfilter",
762 .child
= ip_ct_sysctl_table
,
765 .ctl_name
= NET_IP_CONNTRACK_MAX
,
766 .procname
= "ip_conntrack_max",
767 .data
= &ip_conntrack_max
,
768 .maxlen
= sizeof(int),
770 .proc_handler
= &proc_dointvec
775 static ctl_table ip_ct_ipv4_table
[] = {
777 .ctl_name
= NET_IPV4
,
780 .child
= ip_ct_netfilter_table
,
785 static ctl_table ip_ct_net_table
[] = {
790 .child
= ip_ct_ipv4_table
,
795 EXPORT_SYMBOL(ip_ct_log_invalid
);
796 #endif /* CONFIG_SYSCTL */
798 /* FIXME: Allow NULL functions and sub in pointers to generic for
800 int ip_conntrack_protocol_register(struct ip_conntrack_protocol
*proto
)
804 write_lock_bh(&ip_conntrack_lock
);
805 if (ip_ct_protos
[proto
->proto
] != &ip_conntrack_generic_protocol
) {
809 ip_ct_protos
[proto
->proto
] = proto
;
811 write_unlock_bh(&ip_conntrack_lock
);
815 void ip_conntrack_protocol_unregister(struct ip_conntrack_protocol
*proto
)
817 write_lock_bh(&ip_conntrack_lock
);
818 ip_ct_protos
[proto
->proto
] = &ip_conntrack_generic_protocol
;
819 write_unlock_bh(&ip_conntrack_lock
);
821 /* Somebody could be still looking at the proto in bh. */
824 /* Remove all contrack entries for this protocol */
825 ip_ct_iterate_cleanup(kill_proto
, &proto
->proto
);
828 static int __init
ip_conntrack_standalone_init(void)
830 #ifdef CONFIG_PROC_FS
831 struct proc_dir_entry
*proc
, *proc_exp
, *proc_stat
;
835 ret
= ip_conntrack_init();
839 #ifdef CONFIG_PROC_FS
841 proc
= proc_net_fops_create("ip_conntrack", 0440, &ct_file_ops
);
842 if (!proc
) goto cleanup_init
;
844 proc_exp
= proc_net_fops_create("ip_conntrack_expect", 0440,
846 if (!proc_exp
) goto cleanup_proc
;
848 proc_stat
= create_proc_entry("ip_conntrack", S_IRUGO
, proc_net_stat
);
850 goto cleanup_proc_exp
;
852 proc_stat
->proc_fops
= &ct_cpu_seq_fops
;
853 proc_stat
->owner
= THIS_MODULE
;
856 ret
= nf_register_hooks(ip_conntrack_ops
, ARRAY_SIZE(ip_conntrack_ops
));
858 printk("ip_conntrack: can't register hooks.\n");
859 goto cleanup_proc_stat
;
862 ip_ct_sysctl_header
= register_sysctl_table(ip_ct_net_table
, 0);
863 if (ip_ct_sysctl_header
== NULL
) {
864 printk("ip_conntrack: can't register to sysctl.\n");
873 nf_unregister_hooks(ip_conntrack_ops
, ARRAY_SIZE(ip_conntrack_ops
));
876 #ifdef CONFIG_PROC_FS
877 remove_proc_entry("ip_conntrack", proc_net_stat
);
879 proc_net_remove("ip_conntrack_expect");
881 proc_net_remove("ip_conntrack");
883 #endif /* CONFIG_PROC_FS */
884 ip_conntrack_cleanup();
888 static void __exit
ip_conntrack_standalone_fini(void)
892 unregister_sysctl_table(ip_ct_sysctl_header
);
894 nf_unregister_hooks(ip_conntrack_ops
, ARRAY_SIZE(ip_conntrack_ops
));
895 #ifdef CONFIG_PROC_FS
896 remove_proc_entry("ip_conntrack", proc_net_stat
);
897 proc_net_remove("ip_conntrack_expect");
898 proc_net_remove("ip_conntrack");
899 #endif /* CONFIG_PROC_FS */
900 ip_conntrack_cleanup();
903 module_init(ip_conntrack_standalone_init
);
904 module_exit(ip_conntrack_standalone_fini
);
906 /* Some modules need us, but don't depend directly on any symbol.
907 They should call this. */
908 void need_conntrack(void)
912 #ifdef CONFIG_IP_NF_CONNTRACK_EVENTS
913 EXPORT_SYMBOL_GPL(ip_conntrack_chain
);
914 EXPORT_SYMBOL_GPL(ip_conntrack_expect_chain
);
915 EXPORT_SYMBOL_GPL(ip_conntrack_register_notifier
);
916 EXPORT_SYMBOL_GPL(ip_conntrack_unregister_notifier
);
917 EXPORT_SYMBOL_GPL(__ip_ct_event_cache_init
);
918 EXPORT_PER_CPU_SYMBOL_GPL(ip_conntrack_ecache
);
920 EXPORT_SYMBOL(ip_conntrack_protocol_register
);
921 EXPORT_SYMBOL(ip_conntrack_protocol_unregister
);
922 EXPORT_SYMBOL(ip_ct_get_tuple
);
923 EXPORT_SYMBOL(invert_tuplepr
);
924 EXPORT_SYMBOL(ip_conntrack_alter_reply
);
925 EXPORT_SYMBOL(ip_conntrack_destroyed
);
926 EXPORT_SYMBOL(need_conntrack
);
927 EXPORT_SYMBOL(ip_conntrack_helper_register
);
928 EXPORT_SYMBOL(ip_conntrack_helper_unregister
);
929 EXPORT_SYMBOL(ip_ct_iterate_cleanup
);
930 EXPORT_SYMBOL(__ip_ct_refresh_acct
);
932 EXPORT_SYMBOL(ip_conntrack_expect_alloc
);
933 EXPORT_SYMBOL(ip_conntrack_expect_put
);
934 EXPORT_SYMBOL_GPL(__ip_conntrack_expect_find
);
935 EXPORT_SYMBOL_GPL(ip_conntrack_expect_find
);
936 EXPORT_SYMBOL(ip_conntrack_expect_related
);
937 EXPORT_SYMBOL(ip_conntrack_unexpect_related
);
938 EXPORT_SYMBOL_GPL(ip_conntrack_expect_list
);
939 EXPORT_SYMBOL_GPL(ip_ct_unlink_expect
);
941 EXPORT_SYMBOL(ip_conntrack_tuple_taken
);
942 EXPORT_SYMBOL(ip_ct_gather_frags
);
943 EXPORT_SYMBOL(ip_conntrack_htable_size
);
944 EXPORT_SYMBOL(ip_conntrack_lock
);
945 EXPORT_SYMBOL(ip_conntrack_hash
);
946 EXPORT_SYMBOL(ip_conntrack_untracked
);
947 EXPORT_SYMBOL_GPL(ip_conntrack_find_get
);
948 #ifdef CONFIG_IP_NF_NAT_NEEDED
949 EXPORT_SYMBOL(ip_conntrack_tcp_update
);
952 EXPORT_SYMBOL_GPL(ip_conntrack_flush
);
953 EXPORT_SYMBOL_GPL(__ip_conntrack_find
);
955 EXPORT_SYMBOL_GPL(ip_conntrack_alloc
);
956 EXPORT_SYMBOL_GPL(ip_conntrack_free
);
957 EXPORT_SYMBOL_GPL(ip_conntrack_hash_insert
);
959 EXPORT_SYMBOL_GPL(ip_ct_remove_expectations
);
961 EXPORT_SYMBOL_GPL(ip_conntrack_helper_find_get
);
962 EXPORT_SYMBOL_GPL(ip_conntrack_helper_put
);
963 EXPORT_SYMBOL_GPL(__ip_conntrack_helper_find_byname
);
965 EXPORT_SYMBOL_GPL(ip_conntrack_proto_find_get
);
966 EXPORT_SYMBOL_GPL(ip_conntrack_proto_put
);
967 EXPORT_SYMBOL_GPL(__ip_conntrack_proto_find
);
968 EXPORT_SYMBOL_GPL(ip_conntrack_checksum
);
969 #if defined(CONFIG_IP_NF_CONNTRACK_NETLINK) || \
970 defined(CONFIG_IP_NF_CONNTRACK_NETLINK_MODULE)
971 EXPORT_SYMBOL_GPL(ip_ct_port_tuple_to_nfattr
);
972 EXPORT_SYMBOL_GPL(ip_ct_port_nfattr_to_tuple
);