[NETFILTER]: kill listhelp.h
[safe/jmp/linux-2.6] / net / ipv4 / netfilter / ip_conntrack_standalone.c
1 /* This file contains all the functions required for the standalone
2    ip_conntrack module.
3
4    These are not required by the compatibility layer.
5 */
6
7 /* (C) 1999-2001 Paul `Rusty' Russell
8  * (C) 2002-2005 Netfilter Core Team <coreteam@netfilter.org>
9  *
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.
13  */
14
15 #include <linux/types.h>
16 #include <linux/ip.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>
24 #ifdef CONFIG_SYSCTL
25 #include <linux/sysctl.h>
26 #endif
27 #include <net/checksum.h>
28 #include <net/ip.h>
29 #include <net/route.h>
30
31 #define ASSERT_READ_LOCK(x)
32 #define ASSERT_WRITE_LOCK(x)
33
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
39 #if 0
40 #define DEBUGP printk
41 #else
42 #define DEBUGP(format, args...)
43 #endif
44
45 MODULE_LICENSE("GPL");
46
47 extern atomic_t ip_conntrack_count;
48 DECLARE_PER_CPU(struct ip_conntrack_stat, ip_conntrack_stat);
49
50 static int kill_proto(struct ip_conntrack *i, void *data)
51 {
52         return (i->tuplehash[IP_CT_DIR_ORIGINAL].tuple.dst.protonum == 
53                         *((u_int8_t *) data));
54 }
55
56 #ifdef CONFIG_PROC_FS
57 static int
58 print_tuple(struct seq_file *s, const struct ip_conntrack_tuple *tuple,
59             struct ip_conntrack_protocol *proto)
60 {
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);
64 }
65
66 #ifdef CONFIG_IP_NF_CT_ACCT
67 static unsigned int
68 seq_print_counters(struct seq_file *s,
69                    const struct ip_conntrack_counter *counter)
70 {
71         return seq_printf(s, "packets=%llu bytes=%llu ",
72                           (unsigned long long)counter->packets,
73                           (unsigned long long)counter->bytes);
74 }
75 #else
76 #define seq_print_counters(x, y)        0
77 #endif
78
79 struct ct_iter_state {
80         unsigned int bucket;
81 };
82
83 static struct list_head *ct_get_first(struct seq_file *seq)
84 {
85         struct ct_iter_state *st = seq->private;
86
87         for (st->bucket = 0;
88              st->bucket < ip_conntrack_htable_size;
89              st->bucket++) {
90                 if (!list_empty(&ip_conntrack_hash[st->bucket]))
91                         return ip_conntrack_hash[st->bucket].next;
92         }
93         return NULL;
94 }
95
96 static struct list_head *ct_get_next(struct seq_file *seq, struct list_head *head)
97 {
98         struct ct_iter_state *st = seq->private;
99
100         head = head->next;
101         while (head == &ip_conntrack_hash[st->bucket]) {
102                 if (++st->bucket >= ip_conntrack_htable_size)
103                         return NULL;
104                 head = ip_conntrack_hash[st->bucket].next;
105         }
106         return head;
107 }
108
109 static struct list_head *ct_get_idx(struct seq_file *seq, loff_t pos)
110 {
111         struct list_head *head = ct_get_first(seq);
112
113         if (head)
114                 while (pos && (head = ct_get_next(seq, head)))
115                         pos--;
116         return pos ? NULL : head;
117 }
118
119 static void *ct_seq_start(struct seq_file *seq, loff_t *pos)
120 {
121         read_lock_bh(&ip_conntrack_lock);
122         return ct_get_idx(seq, *pos);
123 }
124
125 static void *ct_seq_next(struct seq_file *s, void *v, loff_t *pos)
126 {
127         (*pos)++;
128         return ct_get_next(s, v);
129 }
130   
131 static void ct_seq_stop(struct seq_file *s, void *v)
132 {
133         read_unlock_bh(&ip_conntrack_lock);
134 }
135  
136 static int ct_seq_show(struct seq_file *s, void *v)
137 {
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;
141
142         ASSERT_READ_LOCK(&ip_conntrack_lock);
143         IP_NF_ASSERT(conntrack);
144
145         /* we only want to print DIR_ORIGINAL */
146         if (DIRECTION(hash))
147                 return 0;
148
149         proto = __ip_conntrack_proto_find(conntrack->tuplehash[IP_CT_DIR_ORIGINAL].tuple.dst.protonum);
150         IP_NF_ASSERT(proto);
151
152         if (seq_printf(s, "%-8s %u %ld ",
153                       proto->name,
154                       conntrack->tuplehash[IP_CT_DIR_ORIGINAL].tuple.dst.protonum,
155                       timer_pending(&conntrack->timeout)
156                       ? (long)(conntrack->timeout.expires - jiffies)/HZ
157                       : 0) != 0)
158                 return -ENOSPC;
159
160         if (proto->print_conntrack(s, conntrack))
161                 return -ENOSPC;
162   
163         if (print_tuple(s, &conntrack->tuplehash[IP_CT_DIR_ORIGINAL].tuple,
164                         proto))
165                 return -ENOSPC;
166
167         if (seq_print_counters(s, &conntrack->counters[IP_CT_DIR_ORIGINAL]))
168                 return -ENOSPC;
169
170         if (!(test_bit(IPS_SEEN_REPLY_BIT, &conntrack->status)))
171                 if (seq_printf(s, "[UNREPLIED] "))
172                         return -ENOSPC;
173
174         if (print_tuple(s, &conntrack->tuplehash[IP_CT_DIR_REPLY].tuple,
175                         proto))
176                 return -ENOSPC;
177
178         if (seq_print_counters(s, &conntrack->counters[IP_CT_DIR_REPLY]))
179                 return -ENOSPC;
180
181         if (test_bit(IPS_ASSURED_BIT, &conntrack->status))
182                 if (seq_printf(s, "[ASSURED] "))
183                         return -ENOSPC;
184
185 #if defined(CONFIG_IP_NF_CONNTRACK_MARK)
186         if (seq_printf(s, "mark=%u ", conntrack->mark))
187                 return -ENOSPC;
188 #endif
189
190 #ifdef CONFIG_IP_NF_CONNTRACK_SECMARK
191         if (seq_printf(s, "secmark=%u ", conntrack->secmark))
192                 return -ENOSPC;
193 #endif
194
195         if (seq_printf(s, "use=%u\n", atomic_read(&conntrack->ct_general.use)))
196                 return -ENOSPC;
197
198         return 0;
199 }
200
201 static struct seq_operations ct_seq_ops = {
202         .start = ct_seq_start,
203         .next  = ct_seq_next,
204         .stop  = ct_seq_stop,
205         .show  = ct_seq_show
206 };
207   
208 static int ct_open(struct inode *inode, struct file *file)
209 {
210         struct seq_file *seq;
211         struct ct_iter_state *st;
212         int ret;
213
214         st = kmalloc(sizeof(struct ct_iter_state), GFP_KERNEL);
215         if (st == NULL)
216                 return -ENOMEM;
217         ret = seq_open(file, &ct_seq_ops);
218         if (ret)
219                 goto out_free;
220         seq          = file->private_data;
221         seq->private = st;
222         memset(st, 0, sizeof(struct ct_iter_state));
223         return ret;
224 out_free:
225         kfree(st);
226         return ret;
227 }
228
229 static struct file_operations ct_file_ops = {
230         .owner   = THIS_MODULE,
231         .open    = ct_open,
232         .read    = seq_read,
233         .llseek  = seq_lseek,
234         .release = seq_release_private,
235 };
236   
237 /* expects */
238 static void *exp_seq_start(struct seq_file *s, loff_t *pos)
239 {
240         struct list_head *e = &ip_conntrack_expect_list;
241         loff_t i;
242
243         /* strange seq_file api calls stop even if we fail,
244          * thus we need to grab lock since stop unlocks */
245         read_lock_bh(&ip_conntrack_lock);
246
247         if (list_empty(e))
248                 return NULL;
249
250         for (i = 0; i <= *pos; i++) {
251                 e = e->next;
252                 if (e == &ip_conntrack_expect_list)
253                         return NULL;
254         }
255         return e;
256 }
257
258 static void *exp_seq_next(struct seq_file *s, void *v, loff_t *pos)
259 {
260         struct list_head *e = v;
261
262         ++*pos;
263         e = e->next;
264
265         if (e == &ip_conntrack_expect_list)
266                 return NULL;
267
268         return e;
269 }
270
271 static void exp_seq_stop(struct seq_file *s, void *v)
272 {
273         read_unlock_bh(&ip_conntrack_lock);
274 }
275
276 static int exp_seq_show(struct seq_file *s, void *v)
277 {
278         struct ip_conntrack_expect *expect = v;
279
280         if (expect->timeout.function)
281                 seq_printf(s, "%ld ", timer_pending(&expect->timeout)
282                            ? (long)(expect->timeout.expires - jiffies)/HZ : 0);
283         else
284                 seq_printf(s, "- ");
285
286         seq_printf(s, "proto=%u ", expect->tuple.dst.protonum);
287
288         print_tuple(s, &expect->tuple,
289                     __ip_conntrack_proto_find(expect->tuple.dst.protonum));
290         return seq_putc(s, '\n');
291 }
292
293 static struct seq_operations exp_seq_ops = {
294         .start = exp_seq_start,
295         .next = exp_seq_next,
296         .stop = exp_seq_stop,
297         .show = exp_seq_show
298 };
299
300 static int exp_open(struct inode *inode, struct file *file)
301 {
302         return seq_open(file, &exp_seq_ops);
303 }
304   
305 static struct file_operations exp_file_ops = {
306         .owner   = THIS_MODULE,
307         .open    = exp_open,
308         .read    = seq_read,
309         .llseek  = seq_lseek,
310         .release = seq_release
311 };
312
313 static void *ct_cpu_seq_start(struct seq_file *seq, loff_t *pos)
314 {
315         int cpu;
316
317         if (*pos == 0)
318                 return SEQ_START_TOKEN;
319
320         for (cpu = *pos-1; cpu < NR_CPUS; ++cpu) {
321                 if (!cpu_possible(cpu))
322                         continue;
323                 *pos = cpu+1;
324                 return &per_cpu(ip_conntrack_stat, cpu);
325         }
326
327         return NULL;
328 }
329
330 static void *ct_cpu_seq_next(struct seq_file *seq, void *v, loff_t *pos)
331 {
332         int cpu;
333
334         for (cpu = *pos; cpu < NR_CPUS; ++cpu) {
335                 if (!cpu_possible(cpu))
336                         continue;
337                 *pos = cpu+1;
338                 return &per_cpu(ip_conntrack_stat, cpu);
339         }
340
341         return NULL;
342 }
343
344 static void ct_cpu_seq_stop(struct seq_file *seq, void *v)
345 {
346 }
347
348 static int ct_cpu_seq_show(struct seq_file *seq, void *v)
349 {
350         unsigned int nr_conntracks = atomic_read(&ip_conntrack_count);
351         struct ip_conntrack_stat *st = v;
352
353         if (v == SEQ_START_TOKEN) {
354                 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");
355                 return 0;
356         }
357
358         seq_printf(seq, "%08x  %08x %08x %08x %08x %08x %08x %08x "
359                         "%08x %08x %08x %08x %08x  %08x %08x %08x \n",
360                    nr_conntracks,
361                    st->searched,
362                    st->found,
363                    st->new,
364                    st->invalid,
365                    st->ignore,
366                    st->delete,
367                    st->delete_list,
368                    st->insert,
369                    st->insert_failed,
370                    st->drop,
371                    st->early_drop,
372                    st->error,
373
374                    st->expect_new,
375                    st->expect_create,
376                    st->expect_delete
377                 );
378         return 0;
379 }
380
381 static struct seq_operations ct_cpu_seq_ops = {
382         .start  = ct_cpu_seq_start,
383         .next   = ct_cpu_seq_next,
384         .stop   = ct_cpu_seq_stop,
385         .show   = ct_cpu_seq_show,
386 };
387
388 static int ct_cpu_seq_open(struct inode *inode, struct file *file)
389 {
390         return seq_open(file, &ct_cpu_seq_ops);
391 }
392
393 static struct file_operations ct_cpu_seq_fops = {
394         .owner   = THIS_MODULE,
395         .open    = ct_cpu_seq_open,
396         .read    = seq_read,
397         .llseek  = seq_lseek,
398         .release = seq_release_private,
399 };
400 #endif
401
402 static unsigned int ip_confirm(unsigned int hooknum,
403                                struct sk_buff **pskb,
404                                const struct net_device *in,
405                                const struct net_device *out,
406                                int (*okfn)(struct sk_buff *))
407 {
408         /* We've seen it coming out the other side: confirm it */
409         return ip_conntrack_confirm(pskb);
410 }
411
412 static unsigned int ip_conntrack_help(unsigned int hooknum,
413                                       struct sk_buff **pskb,
414                                       const struct net_device *in,
415                                       const struct net_device *out,
416                                       int (*okfn)(struct sk_buff *))
417 {
418         struct ip_conntrack *ct;
419         enum ip_conntrack_info ctinfo;
420
421         /* This is where we call the helper: as the packet goes out. */
422         ct = ip_conntrack_get(*pskb, &ctinfo);
423         if (ct && ct->helper && ctinfo != IP_CT_RELATED + IP_CT_IS_REPLY) {
424                 unsigned int ret;
425                 ret = ct->helper->help(pskb, ct, ctinfo);
426                 if (ret != NF_ACCEPT)
427                         return ret;
428         }
429         return NF_ACCEPT;
430 }
431
432 static unsigned int ip_conntrack_defrag(unsigned int hooknum,
433                                         struct sk_buff **pskb,
434                                         const struct net_device *in,
435                                         const struct net_device *out,
436                                         int (*okfn)(struct sk_buff *))
437 {
438 #if !defined(CONFIG_IP_NF_NAT) && !defined(CONFIG_IP_NF_NAT_MODULE)
439         /* Previously seen (loopback)?  Ignore.  Do this before
440            fragment check. */
441         if ((*pskb)->nfct)
442                 return NF_ACCEPT;
443 #endif
444
445         /* Gather fragments. */
446         if ((*pskb)->nh.iph->frag_off & htons(IP_MF|IP_OFFSET)) {
447                 *pskb = ip_ct_gather_frags(*pskb,
448                                            hooknum == NF_IP_PRE_ROUTING ? 
449                                            IP_DEFRAG_CONNTRACK_IN :
450                                            IP_DEFRAG_CONNTRACK_OUT);
451                 if (!*pskb)
452                         return NF_STOLEN;
453         }
454         return NF_ACCEPT;
455 }
456
457 static unsigned int ip_conntrack_local(unsigned int hooknum,
458                                        struct sk_buff **pskb,
459                                        const struct net_device *in,
460                                        const struct net_device *out,
461                                        int (*okfn)(struct sk_buff *))
462 {
463         /* root is playing with raw sockets. */
464         if ((*pskb)->len < sizeof(struct iphdr)
465             || (*pskb)->nh.iph->ihl * 4 < sizeof(struct iphdr)) {
466                 if (net_ratelimit())
467                         printk("ipt_hook: happy cracking.\n");
468                 return NF_ACCEPT;
469         }
470         return ip_conntrack_in(hooknum, pskb, in, out, okfn);
471 }
472
473 /* Connection tracking may drop packets, but never alters them, so
474    make it the first hook. */
475 static struct nf_hook_ops ip_conntrack_ops[] = {
476         {
477                 .hook           = ip_conntrack_defrag,
478                 .owner          = THIS_MODULE,
479                 .pf             = PF_INET,
480                 .hooknum        = NF_IP_PRE_ROUTING,
481                 .priority       = NF_IP_PRI_CONNTRACK_DEFRAG,
482         },
483         {
484                 .hook           = ip_conntrack_in,
485                 .owner          = THIS_MODULE,
486                 .pf             = PF_INET,
487                 .hooknum        = NF_IP_PRE_ROUTING,
488                 .priority       = NF_IP_PRI_CONNTRACK,
489         },
490         {
491                 .hook           = ip_conntrack_defrag,
492                 .owner          = THIS_MODULE,
493                 .pf             = PF_INET,
494                 .hooknum        = NF_IP_LOCAL_OUT,
495                 .priority       = NF_IP_PRI_CONNTRACK_DEFRAG,
496         },
497         {
498                 .hook           = ip_conntrack_local,
499                 .owner          = THIS_MODULE,
500                 .pf             = PF_INET,
501                 .hooknum        = NF_IP_LOCAL_OUT,
502                 .priority       = NF_IP_PRI_CONNTRACK,
503         },
504         {
505                 .hook           = ip_conntrack_help,
506                 .owner          = THIS_MODULE,
507                 .pf             = PF_INET,
508                 .hooknum        = NF_IP_POST_ROUTING,
509                 .priority       = NF_IP_PRI_CONNTRACK_HELPER,
510         },
511         {
512                 .hook           = ip_conntrack_help,
513                 .owner          = THIS_MODULE,
514                 .pf             = PF_INET,
515                 .hooknum        = NF_IP_LOCAL_IN,
516                 .priority       = NF_IP_PRI_CONNTRACK_HELPER,
517         },
518         {
519                 .hook           = ip_confirm,
520                 .owner          = THIS_MODULE,
521                 .pf             = PF_INET,
522                 .hooknum        = NF_IP_POST_ROUTING,
523                 .priority       = NF_IP_PRI_CONNTRACK_CONFIRM,
524         },
525         {
526                 .hook           = ip_confirm,
527                 .owner          = THIS_MODULE,
528                 .pf             = PF_INET,
529                 .hooknum        = NF_IP_LOCAL_IN,
530                 .priority       = NF_IP_PRI_CONNTRACK_CONFIRM,
531         },
532 };
533
534 /* Sysctl support */
535
536 int ip_conntrack_checksum __read_mostly = 1;
537
538 #ifdef CONFIG_SYSCTL
539
540 /* From ip_conntrack_core.c */
541 extern int ip_conntrack_max;
542 extern unsigned int ip_conntrack_htable_size;
543
544 /* From ip_conntrack_proto_tcp.c */
545 extern unsigned int ip_ct_tcp_timeout_syn_sent;
546 extern unsigned int ip_ct_tcp_timeout_syn_recv;
547 extern unsigned int ip_ct_tcp_timeout_established;
548 extern unsigned int ip_ct_tcp_timeout_fin_wait;
549 extern unsigned int ip_ct_tcp_timeout_close_wait;
550 extern unsigned int ip_ct_tcp_timeout_last_ack;
551 extern unsigned int ip_ct_tcp_timeout_time_wait;
552 extern unsigned int ip_ct_tcp_timeout_close;
553 extern unsigned int 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;
557
558 /* From ip_conntrack_proto_udp.c */
559 extern unsigned int ip_ct_udp_timeout;
560 extern unsigned int ip_ct_udp_timeout_stream;
561
562 /* From ip_conntrack_proto_icmp.c */
563 extern unsigned int ip_ct_icmp_timeout;
564
565 /* From ip_conntrack_proto_generic.c */
566 extern unsigned int ip_ct_generic_timeout;
567
568 /* Log invalid packets of a given protocol */
569 static int log_invalid_proto_min = 0;
570 static int log_invalid_proto_max = 255;
571
572 static struct ctl_table_header *ip_ct_sysctl_header;
573
574 static ctl_table ip_ct_sysctl_table[] = {
575         {
576                 .ctl_name       = NET_IPV4_NF_CONNTRACK_MAX,
577                 .procname       = "ip_conntrack_max",
578                 .data           = &ip_conntrack_max,
579                 .maxlen         = sizeof(int),
580                 .mode           = 0644,
581                 .proc_handler   = &proc_dointvec,
582         },
583         {
584                 .ctl_name       = NET_IPV4_NF_CONNTRACK_COUNT,
585                 .procname       = "ip_conntrack_count",
586                 .data           = &ip_conntrack_count,
587                 .maxlen         = sizeof(int),
588                 .mode           = 0444,
589                 .proc_handler   = &proc_dointvec,
590         },
591         {
592                 .ctl_name       = NET_IPV4_NF_CONNTRACK_BUCKETS,
593                 .procname       = "ip_conntrack_buckets",
594                 .data           = &ip_conntrack_htable_size,
595                 .maxlen         = sizeof(unsigned int),
596                 .mode           = 0444,
597                 .proc_handler   = &proc_dointvec,
598         },
599         {
600                 .ctl_name       = NET_IPV4_NF_CONNTRACK_CHECKSUM,
601                 .procname       = "ip_conntrack_checksum",
602                 .data           = &ip_conntrack_checksum,
603                 .maxlen         = sizeof(int),
604                 .mode           = 0644,
605                 .proc_handler   = &proc_dointvec,
606         },
607         {
608                 .ctl_name       = NET_IPV4_NF_CONNTRACK_TCP_TIMEOUT_SYN_SENT,
609                 .procname       = "ip_conntrack_tcp_timeout_syn_sent",
610                 .data           = &ip_ct_tcp_timeout_syn_sent,
611                 .maxlen         = sizeof(unsigned int),
612                 .mode           = 0644,
613                 .proc_handler   = &proc_dointvec_jiffies,
614         },
615         {
616                 .ctl_name       = NET_IPV4_NF_CONNTRACK_TCP_TIMEOUT_SYN_RECV,
617                 .procname       = "ip_conntrack_tcp_timeout_syn_recv",
618                 .data           = &ip_ct_tcp_timeout_syn_recv,
619                 .maxlen         = sizeof(unsigned int),
620                 .mode           = 0644,
621                 .proc_handler   = &proc_dointvec_jiffies,
622         },
623         {
624                 .ctl_name       = NET_IPV4_NF_CONNTRACK_TCP_TIMEOUT_ESTABLISHED,
625                 .procname       = "ip_conntrack_tcp_timeout_established",
626                 .data           = &ip_ct_tcp_timeout_established,
627                 .maxlen         = sizeof(unsigned int),
628                 .mode           = 0644,
629                 .proc_handler   = &proc_dointvec_jiffies,
630         },
631         {
632                 .ctl_name       = NET_IPV4_NF_CONNTRACK_TCP_TIMEOUT_FIN_WAIT,
633                 .procname       = "ip_conntrack_tcp_timeout_fin_wait",
634                 .data           = &ip_ct_tcp_timeout_fin_wait,
635                 .maxlen         = sizeof(unsigned int),
636                 .mode           = 0644,
637                 .proc_handler   = &proc_dointvec_jiffies,
638         },
639         {
640                 .ctl_name       = NET_IPV4_NF_CONNTRACK_TCP_TIMEOUT_CLOSE_WAIT,
641                 .procname       = "ip_conntrack_tcp_timeout_close_wait",
642                 .data           = &ip_ct_tcp_timeout_close_wait,
643                 .maxlen         = sizeof(unsigned int),
644                 .mode           = 0644,
645                 .proc_handler   = &proc_dointvec_jiffies,
646         },
647         {
648                 .ctl_name       = NET_IPV4_NF_CONNTRACK_TCP_TIMEOUT_LAST_ACK,
649                 .procname       = "ip_conntrack_tcp_timeout_last_ack",
650                 .data           = &ip_ct_tcp_timeout_last_ack,
651                 .maxlen         = sizeof(unsigned int),
652                 .mode           = 0644,
653                 .proc_handler   = &proc_dointvec_jiffies,
654         },
655         {
656                 .ctl_name       = NET_IPV4_NF_CONNTRACK_TCP_TIMEOUT_TIME_WAIT,
657                 .procname       = "ip_conntrack_tcp_timeout_time_wait",
658                 .data           = &ip_ct_tcp_timeout_time_wait,
659                 .maxlen         = sizeof(unsigned int),
660                 .mode           = 0644,
661                 .proc_handler   = &proc_dointvec_jiffies,
662         },
663         {
664                 .ctl_name       = NET_IPV4_NF_CONNTRACK_TCP_TIMEOUT_CLOSE,
665                 .procname       = "ip_conntrack_tcp_timeout_close",
666                 .data           = &ip_ct_tcp_timeout_close,
667                 .maxlen         = sizeof(unsigned int),
668                 .mode           = 0644,
669                 .proc_handler   = &proc_dointvec_jiffies,
670         },
671         {
672                 .ctl_name       = NET_IPV4_NF_CONNTRACK_UDP_TIMEOUT,
673                 .procname       = "ip_conntrack_udp_timeout",
674                 .data           = &ip_ct_udp_timeout,
675                 .maxlen         = sizeof(unsigned int),
676                 .mode           = 0644,
677                 .proc_handler   = &proc_dointvec_jiffies,
678         },
679         {
680                 .ctl_name       = NET_IPV4_NF_CONNTRACK_UDP_TIMEOUT_STREAM,
681                 .procname       = "ip_conntrack_udp_timeout_stream",
682                 .data           = &ip_ct_udp_timeout_stream,
683                 .maxlen         = sizeof(unsigned int),
684                 .mode           = 0644,
685                 .proc_handler   = &proc_dointvec_jiffies,
686         },
687         {
688                 .ctl_name       = NET_IPV4_NF_CONNTRACK_ICMP_TIMEOUT,
689                 .procname       = "ip_conntrack_icmp_timeout",
690                 .data           = &ip_ct_icmp_timeout,
691                 .maxlen         = sizeof(unsigned int),
692                 .mode           = 0644,
693                 .proc_handler   = &proc_dointvec_jiffies,
694         },
695         {
696                 .ctl_name       = NET_IPV4_NF_CONNTRACK_GENERIC_TIMEOUT,
697                 .procname       = "ip_conntrack_generic_timeout",
698                 .data           = &ip_ct_generic_timeout,
699                 .maxlen         = sizeof(unsigned int),
700                 .mode           = 0644,
701                 .proc_handler   = &proc_dointvec_jiffies,
702         },
703         {
704                 .ctl_name       = NET_IPV4_NF_CONNTRACK_LOG_INVALID,
705                 .procname       = "ip_conntrack_log_invalid",
706                 .data           = &ip_ct_log_invalid,
707                 .maxlen         = sizeof(unsigned int),
708                 .mode           = 0644,
709                 .proc_handler   = &proc_dointvec_minmax,
710                 .strategy       = &sysctl_intvec,
711                 .extra1         = &log_invalid_proto_min,
712                 .extra2         = &log_invalid_proto_max,
713         },
714         {
715                 .ctl_name       = NET_IPV4_NF_CONNTRACK_TCP_TIMEOUT_MAX_RETRANS,
716                 .procname       = "ip_conntrack_tcp_timeout_max_retrans",
717                 .data           = &ip_ct_tcp_timeout_max_retrans,
718                 .maxlen         = sizeof(unsigned int),
719                 .mode           = 0644,
720                 .proc_handler   = &proc_dointvec_jiffies,
721         },
722         {
723                 .ctl_name       = NET_IPV4_NF_CONNTRACK_TCP_LOOSE,
724                 .procname       = "ip_conntrack_tcp_loose",
725                 .data           = &ip_ct_tcp_loose,
726                 .maxlen         = sizeof(unsigned int),
727                 .mode           = 0644,
728                 .proc_handler   = &proc_dointvec,
729         },
730         {
731                 .ctl_name       = NET_IPV4_NF_CONNTRACK_TCP_BE_LIBERAL,
732                 .procname       = "ip_conntrack_tcp_be_liberal",
733                 .data           = &ip_ct_tcp_be_liberal,
734                 .maxlen         = sizeof(unsigned int),
735                 .mode           = 0644,
736                 .proc_handler   = &proc_dointvec,
737         },
738         {
739                 .ctl_name       = NET_IPV4_NF_CONNTRACK_TCP_MAX_RETRANS,
740                 .procname       = "ip_conntrack_tcp_max_retrans",
741                 .data           = &ip_ct_tcp_max_retrans,
742                 .maxlen         = sizeof(unsigned int),
743                 .mode           = 0644,
744                 .proc_handler   = &proc_dointvec,
745         },
746         { .ctl_name = 0 }
747 };
748
749 #define NET_IP_CONNTRACK_MAX 2089
750
751 static ctl_table ip_ct_netfilter_table[] = {
752         {
753                 .ctl_name       = NET_IPV4_NETFILTER,
754                 .procname       = "netfilter",
755                 .mode           = 0555,
756                 .child          = ip_ct_sysctl_table,
757         },
758         {
759                 .ctl_name       = NET_IP_CONNTRACK_MAX,
760                 .procname       = "ip_conntrack_max",
761                 .data           = &ip_conntrack_max,
762                 .maxlen         = sizeof(int),
763                 .mode           = 0644,
764                 .proc_handler   = &proc_dointvec
765         },
766         { .ctl_name = 0 }
767 };
768
769 static ctl_table ip_ct_ipv4_table[] = {
770         {
771                 .ctl_name       = NET_IPV4,
772                 .procname       = "ipv4",
773                 .mode           = 0555,
774                 .child          = ip_ct_netfilter_table,
775         },
776         { .ctl_name = 0 }
777 };
778
779 static ctl_table ip_ct_net_table[] = {
780         {
781                 .ctl_name       = CTL_NET,
782                 .procname       = "net",
783                 .mode           = 0555, 
784                 .child          = ip_ct_ipv4_table,
785         },
786         { .ctl_name = 0 }
787 };
788
789 EXPORT_SYMBOL(ip_ct_log_invalid);
790 #endif /* CONFIG_SYSCTL */
791
792 /* FIXME: Allow NULL functions and sub in pointers to generic for
793    them. --RR */
794 int ip_conntrack_protocol_register(struct ip_conntrack_protocol *proto)
795 {
796         int ret = 0;
797
798         write_lock_bh(&ip_conntrack_lock);
799         if (ip_ct_protos[proto->proto] != &ip_conntrack_generic_protocol) {
800                 ret = -EBUSY;
801                 goto out;
802         }
803         ip_ct_protos[proto->proto] = proto;
804  out:
805         write_unlock_bh(&ip_conntrack_lock);
806         return ret;
807 }
808
809 void ip_conntrack_protocol_unregister(struct ip_conntrack_protocol *proto)
810 {
811         write_lock_bh(&ip_conntrack_lock);
812         ip_ct_protos[proto->proto] = &ip_conntrack_generic_protocol;
813         write_unlock_bh(&ip_conntrack_lock);
814
815         /* Somebody could be still looking at the proto in bh. */
816         synchronize_net();
817
818         /* Remove all contrack entries for this protocol */
819         ip_ct_iterate_cleanup(kill_proto, &proto->proto);
820 }
821
822 static int __init ip_conntrack_standalone_init(void)
823 {
824 #ifdef CONFIG_PROC_FS
825         struct proc_dir_entry *proc, *proc_exp, *proc_stat;
826 #endif
827         int ret = 0;
828
829         ret = ip_conntrack_init();
830         if (ret < 0)
831                 return ret;
832
833 #ifdef CONFIG_PROC_FS
834         ret = -ENOMEM;
835         proc = proc_net_fops_create("ip_conntrack", 0440, &ct_file_ops);
836         if (!proc) goto cleanup_init;
837
838         proc_exp = proc_net_fops_create("ip_conntrack_expect", 0440,
839                                         &exp_file_ops);
840         if (!proc_exp) goto cleanup_proc;
841
842         proc_stat = create_proc_entry("ip_conntrack", S_IRUGO, proc_net_stat);
843         if (!proc_stat)
844                 goto cleanup_proc_exp;
845
846         proc_stat->proc_fops = &ct_cpu_seq_fops;
847         proc_stat->owner = THIS_MODULE;
848 #endif
849
850         ret = nf_register_hooks(ip_conntrack_ops, ARRAY_SIZE(ip_conntrack_ops));
851         if (ret < 0) {
852                 printk("ip_conntrack: can't register hooks.\n");
853                 goto cleanup_proc_stat;
854         }
855 #ifdef CONFIG_SYSCTL
856         ip_ct_sysctl_header = register_sysctl_table(ip_ct_net_table, 0);
857         if (ip_ct_sysctl_header == NULL) {
858                 printk("ip_conntrack: can't register to sysctl.\n");
859                 ret = -ENOMEM;
860                 goto cleanup_hooks;
861         }
862 #endif
863         return ret;
864
865 #ifdef CONFIG_SYSCTL
866  cleanup_hooks:
867         nf_unregister_hooks(ip_conntrack_ops, ARRAY_SIZE(ip_conntrack_ops));
868 #endif
869  cleanup_proc_stat:
870 #ifdef CONFIG_PROC_FS
871         remove_proc_entry("ip_conntrack", proc_net_stat);
872  cleanup_proc_exp:
873         proc_net_remove("ip_conntrack_expect");
874  cleanup_proc:
875         proc_net_remove("ip_conntrack");
876  cleanup_init:
877 #endif /* CONFIG_PROC_FS */
878         ip_conntrack_cleanup();
879         return ret;
880 }
881
882 static void __exit ip_conntrack_standalone_fini(void)
883 {
884         synchronize_net();
885 #ifdef CONFIG_SYSCTL
886         unregister_sysctl_table(ip_ct_sysctl_header);
887 #endif
888         nf_unregister_hooks(ip_conntrack_ops, ARRAY_SIZE(ip_conntrack_ops));
889 #ifdef CONFIG_PROC_FS
890         remove_proc_entry("ip_conntrack", proc_net_stat);
891         proc_net_remove("ip_conntrack_expect");
892         proc_net_remove("ip_conntrack");
893 #endif /* CONFIG_PROC_FS */
894         ip_conntrack_cleanup();
895 }
896
897 module_init(ip_conntrack_standalone_init);
898 module_exit(ip_conntrack_standalone_fini);
899
900 /* Some modules need us, but don't depend directly on any symbol.
901    They should call this. */
902 void need_conntrack(void)
903 {
904 }
905
906 #ifdef CONFIG_IP_NF_CONNTRACK_EVENTS
907 EXPORT_SYMBOL_GPL(ip_conntrack_chain);
908 EXPORT_SYMBOL_GPL(ip_conntrack_expect_chain);
909 EXPORT_SYMBOL_GPL(ip_conntrack_register_notifier);
910 EXPORT_SYMBOL_GPL(ip_conntrack_unregister_notifier);
911 EXPORT_SYMBOL_GPL(__ip_ct_event_cache_init);
912 EXPORT_PER_CPU_SYMBOL_GPL(ip_conntrack_ecache);
913 #endif
914 EXPORT_SYMBOL(ip_conntrack_protocol_register);
915 EXPORT_SYMBOL(ip_conntrack_protocol_unregister);
916 EXPORT_SYMBOL(ip_ct_get_tuple);
917 EXPORT_SYMBOL(invert_tuplepr);
918 EXPORT_SYMBOL(ip_conntrack_alter_reply);
919 EXPORT_SYMBOL(ip_conntrack_destroyed);
920 EXPORT_SYMBOL(need_conntrack);
921 EXPORT_SYMBOL(ip_conntrack_helper_register);
922 EXPORT_SYMBOL(ip_conntrack_helper_unregister);
923 EXPORT_SYMBOL(ip_ct_iterate_cleanup);
924 EXPORT_SYMBOL(__ip_ct_refresh_acct);
925
926 EXPORT_SYMBOL(ip_conntrack_expect_alloc);
927 EXPORT_SYMBOL(ip_conntrack_expect_put);
928 EXPORT_SYMBOL_GPL(__ip_conntrack_expect_find);
929 EXPORT_SYMBOL_GPL(ip_conntrack_expect_find);
930 EXPORT_SYMBOL(ip_conntrack_expect_related);
931 EXPORT_SYMBOL(ip_conntrack_unexpect_related);
932 EXPORT_SYMBOL_GPL(ip_conntrack_expect_list);
933 EXPORT_SYMBOL_GPL(ip_ct_unlink_expect);
934
935 EXPORT_SYMBOL(ip_conntrack_tuple_taken);
936 EXPORT_SYMBOL(ip_ct_gather_frags);
937 EXPORT_SYMBOL(ip_conntrack_htable_size);
938 EXPORT_SYMBOL(ip_conntrack_lock);
939 EXPORT_SYMBOL(ip_conntrack_hash);
940 EXPORT_SYMBOL(ip_conntrack_untracked);
941 EXPORT_SYMBOL_GPL(ip_conntrack_find_get);
942 #ifdef CONFIG_IP_NF_NAT_NEEDED
943 EXPORT_SYMBOL(ip_conntrack_tcp_update);
944 #endif
945
946 EXPORT_SYMBOL_GPL(ip_conntrack_flush);
947 EXPORT_SYMBOL_GPL(__ip_conntrack_find);
948
949 EXPORT_SYMBOL_GPL(ip_conntrack_alloc);
950 EXPORT_SYMBOL_GPL(ip_conntrack_free);
951 EXPORT_SYMBOL_GPL(ip_conntrack_hash_insert);
952
953 EXPORT_SYMBOL_GPL(ip_ct_remove_expectations);
954
955 EXPORT_SYMBOL_GPL(ip_conntrack_helper_find_get);
956 EXPORT_SYMBOL_GPL(ip_conntrack_helper_put);
957 EXPORT_SYMBOL_GPL(__ip_conntrack_helper_find_byname);
958
959 EXPORT_SYMBOL_GPL(ip_conntrack_proto_find_get);
960 EXPORT_SYMBOL_GPL(ip_conntrack_proto_put);
961 EXPORT_SYMBOL_GPL(__ip_conntrack_proto_find);
962 EXPORT_SYMBOL_GPL(ip_conntrack_checksum);
963 #if defined(CONFIG_IP_NF_CONNTRACK_NETLINK) || \
964     defined(CONFIG_IP_NF_CONNTRACK_NETLINK_MODULE)
965 EXPORT_SYMBOL_GPL(ip_ct_port_tuple_to_nfattr);
966 EXPORT_SYMBOL_GPL(ip_ct_port_nfattr_to_tuple);
967 #endif