netfilter: conntrack: disable generic tracking for known protocols
[pandora-kernel.git] / net / netfilter / nf_conntrack_proto_generic.c
1 /* (C) 1999-2001 Paul `Rusty' Russell
2  * (C) 2002-2004 Netfilter Core Team <coreteam@netfilter.org>
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License version 2 as
6  * published by the Free Software Foundation.
7  */
8
9 #include <linux/types.h>
10 #include <linux/jiffies.h>
11 #include <linux/timer.h>
12 #include <linux/netfilter.h>
13 #include <net/netfilter/nf_conntrack_l4proto.h>
14
15 static unsigned int nf_ct_generic_timeout __read_mostly = 600*HZ;
16
17 static bool nf_generic_should_process(u8 proto)
18 {
19         switch (proto) {
20 #ifdef CONFIG_NF_CT_PROTO_SCTP_MODULE
21         case IPPROTO_SCTP:
22                 return false;
23 #endif
24 #ifdef CONFIG_NF_CT_PROTO_DCCP_MODULE
25         case IPPROTO_DCCP:
26                 return false;
27 #endif
28 #ifdef CONFIG_NF_CT_PROTO_GRE_MODULE
29         case IPPROTO_GRE:
30                 return false;
31 #endif
32 #ifdef CONFIG_NF_CT_PROTO_UDPLITE_MODULE
33         case IPPROTO_UDPLITE:
34                 return false;
35 #endif
36         default:
37                 return true;
38         }
39 }
40
41 static bool generic_pkt_to_tuple(const struct sk_buff *skb,
42                                  unsigned int dataoff,
43                                  struct nf_conntrack_tuple *tuple)
44 {
45         tuple->src.u.all = 0;
46         tuple->dst.u.all = 0;
47
48         return true;
49 }
50
51 static bool generic_invert_tuple(struct nf_conntrack_tuple *tuple,
52                                  const struct nf_conntrack_tuple *orig)
53 {
54         tuple->src.u.all = 0;
55         tuple->dst.u.all = 0;
56
57         return true;
58 }
59
60 /* Print out the per-protocol part of the tuple. */
61 static int generic_print_tuple(struct seq_file *s,
62                                const struct nf_conntrack_tuple *tuple)
63 {
64         return 0;
65 }
66
67 /* Returns verdict for packet, or -1 for invalid. */
68 static int packet(struct nf_conn *ct,
69                   const struct sk_buff *skb,
70                   unsigned int dataoff,
71                   enum ip_conntrack_info ctinfo,
72                   u_int8_t pf,
73                   unsigned int hooknum)
74 {
75         nf_ct_refresh_acct(ct, ctinfo, skb, nf_ct_generic_timeout);
76         return NF_ACCEPT;
77 }
78
79 /* Called when a new connection for this protocol found. */
80 static bool new(struct nf_conn *ct, const struct sk_buff *skb,
81                 unsigned int dataoff)
82 {
83         return nf_generic_should_process(nf_ct_protonum(ct));
84 }
85
86 #ifdef CONFIG_SYSCTL
87 static struct ctl_table_header *generic_sysctl_header;
88 static struct ctl_table generic_sysctl_table[] = {
89         {
90                 .procname       = "nf_conntrack_generic_timeout",
91                 .data           = &nf_ct_generic_timeout,
92                 .maxlen         = sizeof(unsigned int),
93                 .mode           = 0644,
94                 .proc_handler   = proc_dointvec_jiffies,
95         },
96         { }
97 };
98 #ifdef CONFIG_NF_CONNTRACK_PROC_COMPAT
99 static struct ctl_table generic_compat_sysctl_table[] = {
100         {
101                 .procname       = "ip_conntrack_generic_timeout",
102                 .data           = &nf_ct_generic_timeout,
103                 .maxlen         = sizeof(unsigned int),
104                 .mode           = 0644,
105                 .proc_handler   = proc_dointvec_jiffies,
106         },
107         { }
108 };
109 #endif /* CONFIG_NF_CONNTRACK_PROC_COMPAT */
110 #endif /* CONFIG_SYSCTL */
111
112 struct nf_conntrack_l4proto nf_conntrack_l4proto_generic __read_mostly =
113 {
114         .l3proto                = PF_UNSPEC,
115         .l4proto                = 255,
116         .name                   = "unknown",
117         .pkt_to_tuple           = generic_pkt_to_tuple,
118         .invert_tuple           = generic_invert_tuple,
119         .print_tuple            = generic_print_tuple,
120         .packet                 = packet,
121         .new                    = new,
122 #ifdef CONFIG_SYSCTL
123         .ctl_table_header       = &generic_sysctl_header,
124         .ctl_table              = generic_sysctl_table,
125 #ifdef CONFIG_NF_CONNTRACK_PROC_COMPAT
126         .ctl_compat_table       = generic_compat_sysctl_table,
127 #endif
128 #endif
129 };