blob: 6ebac7d9ee697f905d678a1d9063895879e894e3 [file] [log] [blame]
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -08001/* This file contains all the functions required for the standalone
2 nf_conntrack module.
3
4 These are not required by the compatibility layer.
5*/
6
7/* (C) 1999-2001 Paul `Rusty' Russell
8 * (C) 2002-2004 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 * 16 Dec 2003: Yasuyuki Kozakai @USAGI <yasuyuki.kozakai@toshiba.co.jp>
15 * - generalize L3 protocol dependent part.
16 *
17 * Derived from net/ipv4/netfilter/ip_conntrack_standalone.c
18 */
19
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -080020#include <linux/types.h>
21#include <linux/netfilter.h>
22#include <linux/module.h>
23#include <linux/skbuff.h>
24#include <linux/proc_fs.h>
25#include <linux/seq_file.h>
26#include <linux/percpu.h>
27#include <linux/netdevice.h>
28#ifdef CONFIG_SYSCTL
29#include <linux/sysctl.h>
30#endif
31
32#define ASSERT_READ_LOCK(x)
33#define ASSERT_WRITE_LOCK(x)
34
35#include <net/netfilter/nf_conntrack.h>
Martin Josefssonf6180122006-11-29 02:35:01 +010036#include <net/netfilter/nf_conntrack_core.h>
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -080037#include <net/netfilter/nf_conntrack_l3proto.h>
Martin Josefsson605dcad2006-11-29 02:35:06 +010038#include <net/netfilter/nf_conntrack_l4proto.h>
Martin Josefsson77ab9cf2006-11-29 02:34:58 +010039#include <net/netfilter/nf_conntrack_expect.h>
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -080040#include <net/netfilter/nf_conntrack_helper.h>
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -080041
42#if 0
43#define DEBUGP printk
44#else
45#define DEBUGP(format, args...)
46#endif
47
48MODULE_LICENSE("GPL");
49
50extern atomic_t nf_conntrack_count;
51DECLARE_PER_CPU(struct ip_conntrack_stat, nf_conntrack_stat);
52
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -080053#ifdef CONFIG_PROC_FS
Martin Josefsson77ab9cf2006-11-29 02:34:58 +010054int
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -080055print_tuple(struct seq_file *s, const struct nf_conntrack_tuple *tuple,
56 struct nf_conntrack_l3proto *l3proto,
Martin Josefsson605dcad2006-11-29 02:35:06 +010057 struct nf_conntrack_l4proto *l4proto)
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -080058{
Martin Josefsson605dcad2006-11-29 02:35:06 +010059 return l3proto->print_tuple(s, tuple) || l4proto->print_tuple(s, tuple);
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -080060}
61
62#ifdef CONFIG_NF_CT_ACCT
63static unsigned int
64seq_print_counters(struct seq_file *s,
65 const struct ip_conntrack_counter *counter)
66{
67 return seq_printf(s, "packets=%llu bytes=%llu ",
68 (unsigned long long)counter->packets,
69 (unsigned long long)counter->bytes);
70}
71#else
72#define seq_print_counters(x, y) 0
73#endif
74
75struct ct_iter_state {
76 unsigned int bucket;
77};
78
79static struct list_head *ct_get_first(struct seq_file *seq)
80{
81 struct ct_iter_state *st = seq->private;
82
83 for (st->bucket = 0;
84 st->bucket < nf_conntrack_htable_size;
85 st->bucket++) {
86 if (!list_empty(&nf_conntrack_hash[st->bucket]))
87 return nf_conntrack_hash[st->bucket].next;
88 }
89 return NULL;
90}
91
92static struct list_head *ct_get_next(struct seq_file *seq, struct list_head *head)
93{
94 struct ct_iter_state *st = seq->private;
95
96 head = head->next;
97 while (head == &nf_conntrack_hash[st->bucket]) {
98 if (++st->bucket >= nf_conntrack_htable_size)
99 return NULL;
100 head = nf_conntrack_hash[st->bucket].next;
101 }
102 return head;
103}
104
105static struct list_head *ct_get_idx(struct seq_file *seq, loff_t pos)
106{
107 struct list_head *head = ct_get_first(seq);
108
109 if (head)
110 while (pos && (head = ct_get_next(seq, head)))
111 pos--;
112 return pos ? NULL : head;
113}
114
115static void *ct_seq_start(struct seq_file *seq, loff_t *pos)
116{
117 read_lock_bh(&nf_conntrack_lock);
118 return ct_get_idx(seq, *pos);
119}
120
121static void *ct_seq_next(struct seq_file *s, void *v, loff_t *pos)
122{
123 (*pos)++;
124 return ct_get_next(s, v);
125}
126
127static void ct_seq_stop(struct seq_file *s, void *v)
128{
129 read_unlock_bh(&nf_conntrack_lock);
130}
131
132/* return 0 on success, 1 in case of error */
133static int ct_seq_show(struct seq_file *s, void *v)
134{
135 const struct nf_conntrack_tuple_hash *hash = v;
136 const struct nf_conn *conntrack = nf_ct_tuplehash_to_ctrack(hash);
137 struct nf_conntrack_l3proto *l3proto;
Martin Josefsson605dcad2006-11-29 02:35:06 +0100138 struct nf_conntrack_l4proto *l4proto;
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -0800139
140 ASSERT_READ_LOCK(&nf_conntrack_lock);
141 NF_CT_ASSERT(conntrack);
142
143 /* we only want to print DIR_ORIGINAL */
144 if (NF_CT_DIRECTION(hash))
145 return 0;
146
Pablo Neira Ayusoc1d10ad2006-01-05 12:19:05 -0800147 l3proto = __nf_ct_l3proto_find(conntrack->tuplehash[IP_CT_DIR_ORIGINAL]
148 .tuple.src.l3num);
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -0800149
150 NF_CT_ASSERT(l3proto);
Martin Josefsson605dcad2006-11-29 02:35:06 +0100151 l4proto = __nf_ct_l4proto_find(conntrack->tuplehash[IP_CT_DIR_ORIGINAL]
Pablo Neira Ayusoc1d10ad2006-01-05 12:19:05 -0800152 .tuple.src.l3num,
153 conntrack->tuplehash[IP_CT_DIR_ORIGINAL]
154 .tuple.dst.protonum);
Martin Josefsson605dcad2006-11-29 02:35:06 +0100155 NF_CT_ASSERT(l4proto);
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -0800156
157 if (seq_printf(s, "%-8s %u %-8s %u %ld ",
158 l3proto->name,
159 conntrack->tuplehash[IP_CT_DIR_ORIGINAL].tuple.src.l3num,
Martin Josefsson605dcad2006-11-29 02:35:06 +0100160 l4proto->name,
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -0800161 conntrack->tuplehash[IP_CT_DIR_ORIGINAL].tuple.dst.protonum,
162 timer_pending(&conntrack->timeout)
163 ? (long)(conntrack->timeout.expires - jiffies)/HZ : 0) != 0)
164 return -ENOSPC;
165
166 if (l3proto->print_conntrack(s, conntrack))
167 return -ENOSPC;
168
Martin Josefsson605dcad2006-11-29 02:35:06 +0100169 if (l4proto->print_conntrack(s, conntrack))
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -0800170 return -ENOSPC;
171
172 if (print_tuple(s, &conntrack->tuplehash[IP_CT_DIR_ORIGINAL].tuple,
Martin Josefsson605dcad2006-11-29 02:35:06 +0100173 l3proto, l4proto))
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -0800174 return -ENOSPC;
175
176 if (seq_print_counters(s, &conntrack->counters[IP_CT_DIR_ORIGINAL]))
177 return -ENOSPC;
178
179 if (!(test_bit(IPS_SEEN_REPLY_BIT, &conntrack->status)))
180 if (seq_printf(s, "[UNREPLIED] "))
181 return -ENOSPC;
182
183 if (print_tuple(s, &conntrack->tuplehash[IP_CT_DIR_REPLY].tuple,
Martin Josefsson605dcad2006-11-29 02:35:06 +0100184 l3proto, l4proto))
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -0800185 return -ENOSPC;
186
187 if (seq_print_counters(s, &conntrack->counters[IP_CT_DIR_REPLY]))
188 return -ENOSPC;
189
190 if (test_bit(IPS_ASSURED_BIT, &conntrack->status))
191 if (seq_printf(s, "[ASSURED] "))
192 return -ENOSPC;
193
194#if defined(CONFIG_NF_CONNTRACK_MARK)
195 if (seq_printf(s, "mark=%u ", conntrack->mark))
196 return -ENOSPC;
197#endif
198
James Morris7c9728c2006-06-09 00:31:46 -0700199#ifdef CONFIG_NF_CONNTRACK_SECMARK
200 if (seq_printf(s, "secmark=%u ", conntrack->secmark))
201 return -ENOSPC;
202#endif
203
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -0800204 if (seq_printf(s, "use=%u\n", atomic_read(&conntrack->ct_general.use)))
205 return -ENOSPC;
206
207 return 0;
208}
209
210static struct seq_operations ct_seq_ops = {
211 .start = ct_seq_start,
212 .next = ct_seq_next,
213 .stop = ct_seq_stop,
214 .show = ct_seq_show
215};
216
217static int ct_open(struct inode *inode, struct file *file)
218{
219 struct seq_file *seq;
220 struct ct_iter_state *st;
221 int ret;
222
223 st = kmalloc(sizeof(struct ct_iter_state), GFP_KERNEL);
224 if (st == NULL)
225 return -ENOMEM;
226 ret = seq_open(file, &ct_seq_ops);
227 if (ret)
228 goto out_free;
229 seq = file->private_data;
230 seq->private = st;
231 memset(st, 0, sizeof(struct ct_iter_state));
232 return ret;
233out_free:
234 kfree(st);
235 return ret;
236}
237
238static struct file_operations ct_file_ops = {
239 .owner = THIS_MODULE,
240 .open = ct_open,
241 .read = seq_read,
242 .llseek = seq_lseek,
243 .release = seq_release_private,
244};
245
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -0800246static void *ct_cpu_seq_start(struct seq_file *seq, loff_t *pos)
247{
248 int cpu;
249
250 if (*pos == 0)
251 return SEQ_START_TOKEN;
252
253 for (cpu = *pos-1; cpu < NR_CPUS; ++cpu) {
254 if (!cpu_possible(cpu))
255 continue;
256 *pos = cpu + 1;
257 return &per_cpu(nf_conntrack_stat, cpu);
258 }
259
260 return NULL;
261}
262
263static void *ct_cpu_seq_next(struct seq_file *seq, void *v, loff_t *pos)
264{
265 int cpu;
266
267 for (cpu = *pos; cpu < NR_CPUS; ++cpu) {
268 if (!cpu_possible(cpu))
269 continue;
270 *pos = cpu + 1;
271 return &per_cpu(nf_conntrack_stat, cpu);
272 }
273
274 return NULL;
275}
276
277static void ct_cpu_seq_stop(struct seq_file *seq, void *v)
278{
279}
280
281static int ct_cpu_seq_show(struct seq_file *seq, void *v)
282{
283 unsigned int nr_conntracks = atomic_read(&nf_conntrack_count);
284 struct ip_conntrack_stat *st = v;
285
286 if (v == SEQ_START_TOKEN) {
287 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");
288 return 0;
289 }
290
291 seq_printf(seq, "%08x %08x %08x %08x %08x %08x %08x %08x "
292 "%08x %08x %08x %08x %08x %08x %08x %08x \n",
293 nr_conntracks,
294 st->searched,
295 st->found,
296 st->new,
297 st->invalid,
298 st->ignore,
299 st->delete,
300 st->delete_list,
301 st->insert,
302 st->insert_failed,
303 st->drop,
304 st->early_drop,
305 st->error,
306
307 st->expect_new,
308 st->expect_create,
309 st->expect_delete
310 );
311 return 0;
312}
313
314static struct seq_operations ct_cpu_seq_ops = {
315 .start = ct_cpu_seq_start,
316 .next = ct_cpu_seq_next,
317 .stop = ct_cpu_seq_stop,
318 .show = ct_cpu_seq_show,
319};
320
321static int ct_cpu_seq_open(struct inode *inode, struct file *file)
322{
323 return seq_open(file, &ct_cpu_seq_ops);
324}
325
326static struct file_operations ct_cpu_seq_fops = {
327 .owner = THIS_MODULE,
328 .open = ct_cpu_seq_open,
329 .read = seq_read,
330 .llseek = seq_lseek,
331 .release = seq_release_private,
332};
333#endif /* CONFIG_PROC_FS */
334
335/* Sysctl support */
336
Brian Haley94aec082006-09-18 00:05:22 -0700337int nf_conntrack_checksum __read_mostly = 1;
Adrian Bunk72b55822006-07-24 22:53:12 -0700338
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -0800339#ifdef CONFIG_SYSCTL
340
341/* From nf_conntrack_core.c */
342extern int nf_conntrack_max;
343extern unsigned int nf_conntrack_htable_size;
344
345/* From nf_conntrack_proto_tcp.c */
Patrick McHardybabbdb12006-01-09 17:48:09 -0800346extern unsigned int nf_ct_tcp_timeout_syn_sent;
347extern unsigned int nf_ct_tcp_timeout_syn_recv;
348extern unsigned int nf_ct_tcp_timeout_established;
349extern unsigned int nf_ct_tcp_timeout_fin_wait;
350extern unsigned int nf_ct_tcp_timeout_close_wait;
351extern unsigned int nf_ct_tcp_timeout_last_ack;
352extern unsigned int nf_ct_tcp_timeout_time_wait;
353extern unsigned int nf_ct_tcp_timeout_close;
354extern unsigned int nf_ct_tcp_timeout_max_retrans;
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -0800355extern int nf_ct_tcp_loose;
356extern int nf_ct_tcp_be_liberal;
357extern int nf_ct_tcp_max_retrans;
358
359/* From nf_conntrack_proto_udp.c */
Patrick McHardybabbdb12006-01-09 17:48:09 -0800360extern unsigned int nf_ct_udp_timeout;
361extern unsigned int nf_ct_udp_timeout_stream;
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -0800362
363/* From nf_conntrack_proto_generic.c */
Patrick McHardybabbdb12006-01-09 17:48:09 -0800364extern unsigned int nf_ct_generic_timeout;
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -0800365
366/* Log invalid packets of a given protocol */
367static int log_invalid_proto_min = 0;
368static int log_invalid_proto_max = 255;
369
370static struct ctl_table_header *nf_ct_sysctl_header;
371
372static ctl_table nf_ct_sysctl_table[] = {
373 {
374 .ctl_name = NET_NF_CONNTRACK_MAX,
375 .procname = "nf_conntrack_max",
376 .data = &nf_conntrack_max,
377 .maxlen = sizeof(int),
378 .mode = 0644,
379 .proc_handler = &proc_dointvec,
380 },
381 {
382 .ctl_name = NET_NF_CONNTRACK_COUNT,
383 .procname = "nf_conntrack_count",
384 .data = &nf_conntrack_count,
385 .maxlen = sizeof(int),
386 .mode = 0444,
387 .proc_handler = &proc_dointvec,
388 },
389 {
390 .ctl_name = NET_NF_CONNTRACK_BUCKETS,
391 .procname = "nf_conntrack_buckets",
392 .data = &nf_conntrack_htable_size,
393 .maxlen = sizeof(unsigned int),
394 .mode = 0444,
395 .proc_handler = &proc_dointvec,
396 },
397 {
Patrick McHardy39a27a32006-05-29 18:23:54 -0700398 .ctl_name = NET_NF_CONNTRACK_CHECKSUM,
399 .procname = "nf_conntrack_checksum",
400 .data = &nf_conntrack_checksum,
401 .maxlen = sizeof(unsigned int),
402 .mode = 0644,
403 .proc_handler = &proc_dointvec,
404 },
405 {
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -0800406 .ctl_name = NET_NF_CONNTRACK_TCP_TIMEOUT_SYN_SENT,
407 .procname = "nf_conntrack_tcp_timeout_syn_sent",
408 .data = &nf_ct_tcp_timeout_syn_sent,
409 .maxlen = sizeof(unsigned int),
410 .mode = 0644,
411 .proc_handler = &proc_dointvec_jiffies,
412 },
413 {
414 .ctl_name = NET_NF_CONNTRACK_TCP_TIMEOUT_SYN_RECV,
415 .procname = "nf_conntrack_tcp_timeout_syn_recv",
416 .data = &nf_ct_tcp_timeout_syn_recv,
417 .maxlen = sizeof(unsigned int),
418 .mode = 0644,
419 .proc_handler = &proc_dointvec_jiffies,
420 },
421 {
422 .ctl_name = NET_NF_CONNTRACK_TCP_TIMEOUT_ESTABLISHED,
423 .procname = "nf_conntrack_tcp_timeout_established",
424 .data = &nf_ct_tcp_timeout_established,
425 .maxlen = sizeof(unsigned int),
426 .mode = 0644,
427 .proc_handler = &proc_dointvec_jiffies,
428 },
429 {
430 .ctl_name = NET_NF_CONNTRACK_TCP_TIMEOUT_FIN_WAIT,
431 .procname = "nf_conntrack_tcp_timeout_fin_wait",
432 .data = &nf_ct_tcp_timeout_fin_wait,
433 .maxlen = sizeof(unsigned int),
434 .mode = 0644,
435 .proc_handler = &proc_dointvec_jiffies,
436 },
437 {
438 .ctl_name = NET_NF_CONNTRACK_TCP_TIMEOUT_CLOSE_WAIT,
439 .procname = "nf_conntrack_tcp_timeout_close_wait",
440 .data = &nf_ct_tcp_timeout_close_wait,
441 .maxlen = sizeof(unsigned int),
442 .mode = 0644,
443 .proc_handler = &proc_dointvec_jiffies,
444 },
445 {
446 .ctl_name = NET_NF_CONNTRACK_TCP_TIMEOUT_LAST_ACK,
447 .procname = "nf_conntrack_tcp_timeout_last_ack",
448 .data = &nf_ct_tcp_timeout_last_ack,
449 .maxlen = sizeof(unsigned int),
450 .mode = 0644,
451 .proc_handler = &proc_dointvec_jiffies,
452 },
453 {
454 .ctl_name = NET_NF_CONNTRACK_TCP_TIMEOUT_TIME_WAIT,
455 .procname = "nf_conntrack_tcp_timeout_time_wait",
456 .data = &nf_ct_tcp_timeout_time_wait,
457 .maxlen = sizeof(unsigned int),
458 .mode = 0644,
459 .proc_handler = &proc_dointvec_jiffies,
460 },
461 {
462 .ctl_name = NET_NF_CONNTRACK_TCP_TIMEOUT_CLOSE,
463 .procname = "nf_conntrack_tcp_timeout_close",
464 .data = &nf_ct_tcp_timeout_close,
465 .maxlen = sizeof(unsigned int),
466 .mode = 0644,
467 .proc_handler = &proc_dointvec_jiffies,
468 },
469 {
470 .ctl_name = NET_NF_CONNTRACK_UDP_TIMEOUT,
471 .procname = "nf_conntrack_udp_timeout",
472 .data = &nf_ct_udp_timeout,
473 .maxlen = sizeof(unsigned int),
474 .mode = 0644,
475 .proc_handler = &proc_dointvec_jiffies,
476 },
477 {
478 .ctl_name = NET_NF_CONNTRACK_UDP_TIMEOUT_STREAM,
479 .procname = "nf_conntrack_udp_timeout_stream",
480 .data = &nf_ct_udp_timeout_stream,
481 .maxlen = sizeof(unsigned int),
482 .mode = 0644,
483 .proc_handler = &proc_dointvec_jiffies,
484 },
485 {
486 .ctl_name = NET_NF_CONNTRACK_GENERIC_TIMEOUT,
487 .procname = "nf_conntrack_generic_timeout",
488 .data = &nf_ct_generic_timeout,
489 .maxlen = sizeof(unsigned int),
490 .mode = 0644,
491 .proc_handler = &proc_dointvec_jiffies,
492 },
493 {
494 .ctl_name = NET_NF_CONNTRACK_LOG_INVALID,
495 .procname = "nf_conntrack_log_invalid",
496 .data = &nf_ct_log_invalid,
497 .maxlen = sizeof(unsigned int),
498 .mode = 0644,
499 .proc_handler = &proc_dointvec_minmax,
500 .strategy = &sysctl_intvec,
501 .extra1 = &log_invalid_proto_min,
502 .extra2 = &log_invalid_proto_max,
503 },
504 {
505 .ctl_name = NET_NF_CONNTRACK_TCP_TIMEOUT_MAX_RETRANS,
506 .procname = "nf_conntrack_tcp_timeout_max_retrans",
507 .data = &nf_ct_tcp_timeout_max_retrans,
508 .maxlen = sizeof(unsigned int),
509 .mode = 0644,
510 .proc_handler = &proc_dointvec_jiffies,
511 },
512 {
513 .ctl_name = NET_NF_CONNTRACK_TCP_LOOSE,
514 .procname = "nf_conntrack_tcp_loose",
515 .data = &nf_ct_tcp_loose,
516 .maxlen = sizeof(unsigned int),
517 .mode = 0644,
518 .proc_handler = &proc_dointvec,
519 },
520 {
521 .ctl_name = NET_NF_CONNTRACK_TCP_BE_LIBERAL,
522 .procname = "nf_conntrack_tcp_be_liberal",
523 .data = &nf_ct_tcp_be_liberal,
524 .maxlen = sizeof(unsigned int),
525 .mode = 0644,
526 .proc_handler = &proc_dointvec,
527 },
528 {
529 .ctl_name = NET_NF_CONNTRACK_TCP_MAX_RETRANS,
530 .procname = "nf_conntrack_tcp_max_retrans",
531 .data = &nf_ct_tcp_max_retrans,
532 .maxlen = sizeof(unsigned int),
533 .mode = 0644,
534 .proc_handler = &proc_dointvec,
535 },
536
537 { .ctl_name = 0 }
538};
539
540#define NET_NF_CONNTRACK_MAX 2089
541
542static ctl_table nf_ct_netfilter_table[] = {
543 {
544 .ctl_name = NET_NETFILTER,
545 .procname = "netfilter",
546 .mode = 0555,
547 .child = nf_ct_sysctl_table,
548 },
549 {
550 .ctl_name = NET_NF_CONNTRACK_MAX,
551 .procname = "nf_conntrack_max",
552 .data = &nf_conntrack_max,
553 .maxlen = sizeof(int),
554 .mode = 0644,
555 .proc_handler = &proc_dointvec,
556 },
557 { .ctl_name = 0 }
558};
559
560static ctl_table nf_ct_net_table[] = {
561 {
562 .ctl_name = CTL_NET,
563 .procname = "net",
564 .mode = 0555,
565 .child = nf_ct_netfilter_table,
566 },
567 { .ctl_name = 0 }
568};
569EXPORT_SYMBOL(nf_ct_log_invalid);
570#endif /* CONFIG_SYSCTL */
571
Andrew Morton65b4b4e2006-03-28 16:37:06 -0800572static int __init nf_conntrack_standalone_init(void)
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -0800573{
Patrick McHardy32292a72006-04-06 14:11:30 -0700574#ifdef CONFIG_PROC_FS
575 struct proc_dir_entry *proc, *proc_exp, *proc_stat;
576#endif
577 int ret = 0;
578
579 ret = nf_conntrack_init();
580 if (ret < 0)
581 return ret;
582
583#ifdef CONFIG_PROC_FS
584 proc = proc_net_fops_create("nf_conntrack", 0440, &ct_file_ops);
585 if (!proc) goto cleanup_init;
586
587 proc_exp = proc_net_fops_create("nf_conntrack_expect", 0440,
588 &exp_file_ops);
589 if (!proc_exp) goto cleanup_proc;
590
591 proc_stat = create_proc_entry("nf_conntrack", S_IRUGO, proc_net_stat);
592 if (!proc_stat)
593 goto cleanup_proc_exp;
594
595 proc_stat->proc_fops = &ct_cpu_seq_fops;
596 proc_stat->owner = THIS_MODULE;
597#endif
598#ifdef CONFIG_SYSCTL
599 nf_ct_sysctl_header = register_sysctl_table(nf_ct_net_table, 0);
600 if (nf_ct_sysctl_header == NULL) {
601 printk("nf_conntrack: can't register to sysctl.\n");
602 ret = -ENOMEM;
603 goto cleanup_proc_stat;
604 }
605#endif
606 return ret;
607
608#ifdef CONFIG_SYSCTL
609 cleanup_proc_stat:
610#endif
611#ifdef CONFIG_PROC_FS
612 remove_proc_entry("nf_conntrack", proc_net_stat);
613 cleanup_proc_exp:
614 proc_net_remove("nf_conntrack_expect");
615 cleanup_proc:
616 proc_net_remove("nf_conntrack");
617 cleanup_init:
618#endif /* CNFIG_PROC_FS */
619 nf_conntrack_cleanup();
620 return ret;
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -0800621}
622
Andrew Morton65b4b4e2006-03-28 16:37:06 -0800623static void __exit nf_conntrack_standalone_fini(void)
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -0800624{
Patrick McHardy32292a72006-04-06 14:11:30 -0700625#ifdef CONFIG_SYSCTL
626 unregister_sysctl_table(nf_ct_sysctl_header);
627#endif
628#ifdef CONFIG_PROC_FS
629 remove_proc_entry("nf_conntrack", proc_net_stat);
630 proc_net_remove("nf_conntrack_expect");
631 proc_net_remove("nf_conntrack");
632#endif /* CNFIG_PROC_FS */
633 nf_conntrack_cleanup();
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -0800634}
635
Andrew Morton65b4b4e2006-03-28 16:37:06 -0800636module_init(nf_conntrack_standalone_init);
637module_exit(nf_conntrack_standalone_fini);
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -0800638
639/* Some modules need us, but don't depend directly on any symbol.
640 They should call this. */
Harald Welte2e4e6a12006-01-12 13:30:04 -0800641void need_conntrack(void)
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -0800642{
643}
644
645#ifdef CONFIG_NF_CONNTRACK_EVENTS
646EXPORT_SYMBOL_GPL(nf_conntrack_chain);
647EXPORT_SYMBOL_GPL(nf_conntrack_expect_chain);
648EXPORT_SYMBOL_GPL(nf_conntrack_register_notifier);
649EXPORT_SYMBOL_GPL(nf_conntrack_unregister_notifier);
650EXPORT_SYMBOL_GPL(__nf_ct_event_cache_init);
651EXPORT_PER_CPU_SYMBOL_GPL(nf_conntrack_ecache);
652EXPORT_SYMBOL_GPL(nf_ct_deliver_cached_events);
653#endif
Pablo Neira Ayusob9f78f92006-03-22 13:56:08 -0800654EXPORT_SYMBOL(nf_ct_l3proto_try_module_get);
655EXPORT_SYMBOL(nf_ct_l3proto_module_put);
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -0800656EXPORT_SYMBOL(nf_conntrack_l3proto_register);
657EXPORT_SYMBOL(nf_conntrack_l3proto_unregister);
Martin Josefsson605dcad2006-11-29 02:35:06 +0100658EXPORT_SYMBOL(nf_conntrack_l4proto_register);
659EXPORT_SYMBOL(nf_conntrack_l4proto_unregister);
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -0800660EXPORT_SYMBOL(nf_ct_invert_tuplepr);
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -0800661EXPORT_SYMBOL(nf_conntrack_destroyed);
Harald Welte2e4e6a12006-01-12 13:30:04 -0800662EXPORT_SYMBOL(need_conntrack);
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -0800663EXPORT_SYMBOL(nf_conntrack_helper_register);
664EXPORT_SYMBOL(nf_conntrack_helper_unregister);
665EXPORT_SYMBOL(nf_ct_iterate_cleanup);
666EXPORT_SYMBOL(__nf_ct_refresh_acct);
667EXPORT_SYMBOL(nf_ct_protos);
Martin Josefsson605dcad2006-11-29 02:35:06 +0100668EXPORT_SYMBOL(__nf_ct_l4proto_find);
669EXPORT_SYMBOL(nf_ct_l4proto_find_get);
670EXPORT_SYMBOL(nf_ct_l4proto_put);
Pablo Neira Ayusoc1d10ad2006-01-05 12:19:05 -0800671EXPORT_SYMBOL(nf_ct_l3proto_find_get);
672EXPORT_SYMBOL(nf_ct_l3proto_put);
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -0800673EXPORT_SYMBOL(nf_ct_l3protos);
Patrick McHardy39a27a32006-05-29 18:23:54 -0700674EXPORT_SYMBOL_GPL(nf_conntrack_checksum);
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -0800675EXPORT_SYMBOL(nf_conntrack_expect_alloc);
676EXPORT_SYMBOL(nf_conntrack_expect_put);
677EXPORT_SYMBOL(nf_conntrack_expect_related);
678EXPORT_SYMBOL(nf_conntrack_unexpect_related);
679EXPORT_SYMBOL(nf_conntrack_tuple_taken);
680EXPORT_SYMBOL(nf_conntrack_htable_size);
681EXPORT_SYMBOL(nf_conntrack_lock);
682EXPORT_SYMBOL(nf_conntrack_hash);
683EXPORT_SYMBOL(nf_conntrack_untracked);
684EXPORT_SYMBOL_GPL(nf_conntrack_find_get);
685#ifdef CONFIG_IP_NF_NAT_NEEDED
686EXPORT_SYMBOL(nf_conntrack_tcp_update);
687#endif
688EXPORT_SYMBOL(__nf_conntrack_confirm);
689EXPORT_SYMBOL(nf_ct_get_tuple);
690EXPORT_SYMBOL(nf_ct_invert_tuple);
691EXPORT_SYMBOL(nf_conntrack_in);
692EXPORT_SYMBOL(__nf_conntrack_attach);
Pablo Neira Ayusoc1d10ad2006-01-05 12:19:05 -0800693EXPORT_SYMBOL(nf_conntrack_alloc);
694EXPORT_SYMBOL(nf_conntrack_free);
695EXPORT_SYMBOL(nf_conntrack_flush);
696EXPORT_SYMBOL(nf_ct_remove_expectations);
697EXPORT_SYMBOL(nf_ct_helper_find_get);
698EXPORT_SYMBOL(nf_ct_helper_put);
699EXPORT_SYMBOL(__nf_conntrack_helper_find_byname);
700EXPORT_SYMBOL(__nf_conntrack_find);
701EXPORT_SYMBOL(nf_ct_unlink_expect);
702EXPORT_SYMBOL(nf_conntrack_hash_insert);
703EXPORT_SYMBOL(__nf_conntrack_expect_find);
704EXPORT_SYMBOL(nf_conntrack_expect_find);
705EXPORT_SYMBOL(nf_conntrack_expect_list);
706#if defined(CONFIG_NF_CT_NETLINK) || \
707 defined(CONFIG_NF_CT_NETLINK_MODULE)
708EXPORT_SYMBOL(nf_ct_port_tuple_to_nfattr);
709EXPORT_SYMBOL(nf_ct_port_nfattr_to_tuple);
710#endif