blob: 193515381970f0a996a960efffe5d75dd2a65af0 [file] [log] [blame]
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -08001/* (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.
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -08007 */
8
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -08009#include <linux/types.h>
10#include <linux/netfilter.h>
11#include <linux/module.h>
12#include <linux/skbuff.h>
13#include <linux/proc_fs.h>
14#include <linux/seq_file.h>
15#include <linux/percpu.h>
16#include <linux/netdevice.h>
Eric W. Biederman457c4cb2007-09-12 12:01:34 +020017#include <net/net_namespace.h>
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -080018#ifdef CONFIG_SYSCTL
19#include <linux/sysctl.h>
20#endif
21
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -080022#include <net/netfilter/nf_conntrack.h>
Martin Josefssonf6180122006-11-29 02:35:01 +010023#include <net/netfilter/nf_conntrack_core.h>
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -080024#include <net/netfilter/nf_conntrack_l3proto.h>
Martin Josefsson605dcad2006-11-29 02:35:06 +010025#include <net/netfilter/nf_conntrack_l4proto.h>
Martin Josefsson77ab9cf2006-11-29 02:34:58 +010026#include <net/netfilter/nf_conntrack_expect.h>
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -080027#include <net/netfilter/nf_conntrack_helper.h>
Krzysztof Piotr Oledzki58401572008-07-21 10:01:34 -070028#include <net/netfilter/nf_conntrack_acct.h>
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -080029
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -080030MODULE_LICENSE("GPL");
31
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -080032#ifdef CONFIG_PROC_FS
Martin Josefsson77ab9cf2006-11-29 02:34:58 +010033int
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -080034print_tuple(struct seq_file *s, const struct nf_conntrack_tuple *tuple,
Jan Engelhardt32948582008-01-31 04:53:24 -080035 const struct nf_conntrack_l3proto *l3proto,
36 const struct nf_conntrack_l4proto *l4proto)
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -080037{
Martin Josefsson605dcad2006-11-29 02:35:06 +010038 return l3proto->print_tuple(s, tuple) || l4proto->print_tuple(s, tuple);
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -080039}
Patrick McHardye4bd8bc2006-11-29 02:35:22 +010040EXPORT_SYMBOL_GPL(print_tuple);
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -080041
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -080042struct ct_iter_state {
Alexey Dobriyanb2ce2c72008-10-08 11:35:05 +020043 struct seq_net_private p;
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -080044 unsigned int bucket;
45};
46
Eric Dumazetea781f12009-03-25 21:05:46 +010047static struct hlist_nulls_node *ct_get_first(struct seq_file *seq)
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -080048{
Alexey Dobriyanb2ce2c72008-10-08 11:35:05 +020049 struct net *net = seq_file_net(seq);
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -080050 struct ct_iter_state *st = seq->private;
Eric Dumazetea781f12009-03-25 21:05:46 +010051 struct hlist_nulls_node *n;
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -080052
53 for (st->bucket = 0;
54 st->bucket < nf_conntrack_htable_size;
55 st->bucket++) {
Alexey Dobriyanb2ce2c72008-10-08 11:35:05 +020056 n = rcu_dereference(net->ct.hash[st->bucket].first);
Eric Dumazetea781f12009-03-25 21:05:46 +010057 if (!is_a_nulls(n))
Patrick McHardy76507f62008-01-31 04:38:38 -080058 return n;
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -080059 }
60 return NULL;
61}
62
Eric Dumazetea781f12009-03-25 21:05:46 +010063static struct hlist_nulls_node *ct_get_next(struct seq_file *seq,
64 struct hlist_nulls_node *head)
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -080065{
Alexey Dobriyanb2ce2c72008-10-08 11:35:05 +020066 struct net *net = seq_file_net(seq);
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -080067 struct ct_iter_state *st = seq->private;
68
Patrick McHardy76507f62008-01-31 04:38:38 -080069 head = rcu_dereference(head->next);
Eric Dumazetea781f12009-03-25 21:05:46 +010070 while (is_a_nulls(head)) {
71 if (likely(get_nulls_value(head) == st->bucket)) {
72 if (++st->bucket >= nf_conntrack_htable_size)
73 return NULL;
74 }
Alexey Dobriyanb2ce2c72008-10-08 11:35:05 +020075 head = rcu_dereference(net->ct.hash[st->bucket].first);
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -080076 }
77 return head;
78}
79
Eric Dumazetea781f12009-03-25 21:05:46 +010080static struct hlist_nulls_node *ct_get_idx(struct seq_file *seq, loff_t pos)
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -080081{
Eric Dumazetea781f12009-03-25 21:05:46 +010082 struct hlist_nulls_node *head = ct_get_first(seq);
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -080083
84 if (head)
85 while (pos && (head = ct_get_next(seq, head)))
86 pos--;
87 return pos ? NULL : head;
88}
89
90static void *ct_seq_start(struct seq_file *seq, loff_t *pos)
Patrick McHardy76507f62008-01-31 04:38:38 -080091 __acquires(RCU)
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -080092{
Patrick McHardy76507f62008-01-31 04:38:38 -080093 rcu_read_lock();
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -080094 return ct_get_idx(seq, *pos);
95}
96
97static void *ct_seq_next(struct seq_file *s, void *v, loff_t *pos)
98{
99 (*pos)++;
100 return ct_get_next(s, v);
101}
102
103static void ct_seq_stop(struct seq_file *s, void *v)
Patrick McHardy76507f62008-01-31 04:38:38 -0800104 __releases(RCU)
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -0800105{
Patrick McHardy76507f62008-01-31 04:38:38 -0800106 rcu_read_unlock();
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -0800107}
108
109/* return 0 on success, 1 in case of error */
110static int ct_seq_show(struct seq_file *s, void *v)
111{
Eric Dumazetea781f12009-03-25 21:05:46 +0100112 struct nf_conntrack_tuple_hash *hash = v;
113 struct nf_conn *ct = nf_ct_tuplehash_to_ctrack(hash);
Jan Engelhardt32948582008-01-31 04:53:24 -0800114 const struct nf_conntrack_l3proto *l3proto;
115 const struct nf_conntrack_l4proto *l4proto;
Eric Dumazetea781f12009-03-25 21:05:46 +0100116 int ret = 0;
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -0800117
Patrick McHardyc88130b2008-01-31 04:42:11 -0800118 NF_CT_ASSERT(ct);
Eric Dumazetea781f12009-03-25 21:05:46 +0100119 if (unlikely(!atomic_inc_not_zero(&ct->ct_general.use)))
120 return 0;
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -0800121
122 /* we only want to print DIR_ORIGINAL */
123 if (NF_CT_DIRECTION(hash))
Eric Dumazetea781f12009-03-25 21:05:46 +0100124 goto release;
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -0800125
Patrick McHardy5e8fbe22008-04-14 11:15:52 +0200126 l3proto = __nf_ct_l3proto_find(nf_ct_l3num(ct));
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -0800127 NF_CT_ASSERT(l3proto);
Patrick McHardy5e8fbe22008-04-14 11:15:52 +0200128 l4proto = __nf_ct_l4proto_find(nf_ct_l3num(ct), nf_ct_protonum(ct));
Martin Josefsson605dcad2006-11-29 02:35:06 +0100129 NF_CT_ASSERT(l4proto);
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -0800130
Eric Dumazetea781f12009-03-25 21:05:46 +0100131 ret = -ENOSPC;
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -0800132 if (seq_printf(s, "%-8s %u %-8s %u %ld ",
Patrick McHardy5e8fbe22008-04-14 11:15:52 +0200133 l3proto->name, nf_ct_l3num(ct),
134 l4proto->name, nf_ct_protonum(ct),
Patrick McHardyc88130b2008-01-31 04:42:11 -0800135 timer_pending(&ct->timeout)
136 ? (long)(ct->timeout.expires - jiffies)/HZ : 0) != 0)
Eric Dumazetea781f12009-03-25 21:05:46 +0100137 goto release;
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -0800138
Patrick McHardyc88130b2008-01-31 04:42:11 -0800139 if (l4proto->print_conntrack && l4proto->print_conntrack(s, ct))
Eric Dumazetea781f12009-03-25 21:05:46 +0100140 goto release;
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -0800141
Patrick McHardyc88130b2008-01-31 04:42:11 -0800142 if (print_tuple(s, &ct->tuplehash[IP_CT_DIR_ORIGINAL].tuple,
Martin Josefsson605dcad2006-11-29 02:35:06 +0100143 l3proto, l4proto))
Eric Dumazetea781f12009-03-25 21:05:46 +0100144 goto release;
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -0800145
Krzysztof Piotr Oledzki58401572008-07-21 10:01:34 -0700146 if (seq_print_acct(s, ct, IP_CT_DIR_ORIGINAL))
Eric Dumazetea781f12009-03-25 21:05:46 +0100147 goto release;
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -0800148
Patrick McHardyc88130b2008-01-31 04:42:11 -0800149 if (!(test_bit(IPS_SEEN_REPLY_BIT, &ct->status)))
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -0800150 if (seq_printf(s, "[UNREPLIED] "))
Eric Dumazetea781f12009-03-25 21:05:46 +0100151 goto release;
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -0800152
Patrick McHardyc88130b2008-01-31 04:42:11 -0800153 if (print_tuple(s, &ct->tuplehash[IP_CT_DIR_REPLY].tuple,
Martin Josefsson605dcad2006-11-29 02:35:06 +0100154 l3proto, l4proto))
Eric Dumazetea781f12009-03-25 21:05:46 +0100155 goto release;
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -0800156
Krzysztof Piotr Oledzki58401572008-07-21 10:01:34 -0700157 if (seq_print_acct(s, ct, IP_CT_DIR_REPLY))
Eric Dumazetea781f12009-03-25 21:05:46 +0100158 goto release;
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -0800159
Patrick McHardyc88130b2008-01-31 04:42:11 -0800160 if (test_bit(IPS_ASSURED_BIT, &ct->status))
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -0800161 if (seq_printf(s, "[ASSURED] "))
Eric Dumazetea781f12009-03-25 21:05:46 +0100162 goto release;
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -0800163
164#if defined(CONFIG_NF_CONNTRACK_MARK)
Patrick McHardyc88130b2008-01-31 04:42:11 -0800165 if (seq_printf(s, "mark=%u ", ct->mark))
Eric Dumazetea781f12009-03-25 21:05:46 +0100166 goto release;
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -0800167#endif
168
James Morris7c9728c2006-06-09 00:31:46 -0700169#ifdef CONFIG_NF_CONNTRACK_SECMARK
Patrick McHardyc88130b2008-01-31 04:42:11 -0800170 if (seq_printf(s, "secmark=%u ", ct->secmark))
Eric Dumazetea781f12009-03-25 21:05:46 +0100171 goto release;
James Morris7c9728c2006-06-09 00:31:46 -0700172#endif
173
Patrick McHardyc88130b2008-01-31 04:42:11 -0800174 if (seq_printf(s, "use=%u\n", atomic_read(&ct->ct_general.use)))
Eric Dumazetea781f12009-03-25 21:05:46 +0100175 goto release;
YOSHIFUJI Hideakia5d29262007-07-19 10:44:21 +0900176
Eric Dumazetea781f12009-03-25 21:05:46 +0100177 ret = 0;
178release:
179 nf_ct_put(ct);
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -0800180 return 0;
181}
182
Philippe De Muyter56b3d972007-07-10 23:07:31 -0700183static const struct seq_operations ct_seq_ops = {
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -0800184 .start = ct_seq_start,
185 .next = ct_seq_next,
186 .stop = ct_seq_stop,
187 .show = ct_seq_show
188};
189
190static int ct_open(struct inode *inode, struct file *file)
191{
Alexey Dobriyanb2ce2c72008-10-08 11:35:05 +0200192 return seq_open_net(inode, file, &ct_seq_ops,
Pavel Emelyanove2da5912007-10-10 02:29:58 -0700193 sizeof(struct ct_iter_state));
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -0800194}
195
Arjan van de Venda7071d2007-02-12 00:55:36 -0800196static const struct file_operations ct_file_ops = {
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -0800197 .owner = THIS_MODULE,
198 .open = ct_open,
199 .read = seq_read,
200 .llseek = seq_lseek,
Alexey Dobriyanb2ce2c72008-10-08 11:35:05 +0200201 .release = seq_release_net,
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -0800202};
203
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -0800204static void *ct_cpu_seq_start(struct seq_file *seq, loff_t *pos)
205{
Alexey Dobriyan8e9df802008-10-08 11:35:08 +0200206 struct net *net = seq_file_net(seq);
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -0800207 int cpu;
208
209 if (*pos == 0)
210 return SEQ_START_TOKEN;
211
Rusty Russell0f23174a2008-12-29 12:23:42 +0000212 for (cpu = *pos-1; cpu < nr_cpu_ids; ++cpu) {
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -0800213 if (!cpu_possible(cpu))
214 continue;
215 *pos = cpu + 1;
Alexey Dobriyan8e9df802008-10-08 11:35:08 +0200216 return per_cpu_ptr(net->ct.stat, cpu);
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -0800217 }
218
219 return NULL;
220}
221
222static void *ct_cpu_seq_next(struct seq_file *seq, void *v, loff_t *pos)
223{
Alexey Dobriyan8e9df802008-10-08 11:35:08 +0200224 struct net *net = seq_file_net(seq);
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -0800225 int cpu;
226
Rusty Russell0f23174a2008-12-29 12:23:42 +0000227 for (cpu = *pos; cpu < nr_cpu_ids; ++cpu) {
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -0800228 if (!cpu_possible(cpu))
229 continue;
230 *pos = cpu + 1;
Alexey Dobriyan8e9df802008-10-08 11:35:08 +0200231 return per_cpu_ptr(net->ct.stat, cpu);
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -0800232 }
233
234 return NULL;
235}
236
237static void ct_cpu_seq_stop(struct seq_file *seq, void *v)
238{
239}
240
241static int ct_cpu_seq_show(struct seq_file *seq, void *v)
242{
Alexey Dobriyan8e9df802008-10-08 11:35:08 +0200243 struct net *net = seq_file_net(seq);
244 unsigned int nr_conntracks = atomic_read(&net->ct.count);
Jan Engelhardt32948582008-01-31 04:53:24 -0800245 const struct ip_conntrack_stat *st = v;
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -0800246
247 if (v == SEQ_START_TOKEN) {
248 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");
249 return 0;
250 }
251
252 seq_printf(seq, "%08x %08x %08x %08x %08x %08x %08x %08x "
253 "%08x %08x %08x %08x %08x %08x %08x %08x \n",
254 nr_conntracks,
255 st->searched,
256 st->found,
257 st->new,
258 st->invalid,
259 st->ignore,
260 st->delete,
261 st->delete_list,
262 st->insert,
263 st->insert_failed,
264 st->drop,
265 st->early_drop,
266 st->error,
267
268 st->expect_new,
269 st->expect_create,
270 st->expect_delete
271 );
272 return 0;
273}
274
Philippe De Muyter56b3d972007-07-10 23:07:31 -0700275static const struct seq_operations ct_cpu_seq_ops = {
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -0800276 .start = ct_cpu_seq_start,
277 .next = ct_cpu_seq_next,
278 .stop = ct_cpu_seq_stop,
279 .show = ct_cpu_seq_show,
280};
281
282static int ct_cpu_seq_open(struct inode *inode, struct file *file)
283{
Alexey Dobriyan8e9df802008-10-08 11:35:08 +0200284 return seq_open_net(inode, file, &ct_cpu_seq_ops,
285 sizeof(struct seq_net_private));
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -0800286}
287
Arjan van de Venda7071d2007-02-12 00:55:36 -0800288static const struct file_operations ct_cpu_seq_fops = {
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -0800289 .owner = THIS_MODULE,
290 .open = ct_cpu_seq_open,
291 .read = seq_read,
292 .llseek = seq_lseek,
Alexey Dobriyan8e9df802008-10-08 11:35:08 +0200293 .release = seq_release_net,
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -0800294};
Alexey Dobriyanb916f7d2008-03-20 15:15:43 +0100295
Alexey Dobriyanb2ce2c72008-10-08 11:35:05 +0200296static int nf_conntrack_standalone_init_proc(struct net *net)
Alexey Dobriyanb916f7d2008-03-20 15:15:43 +0100297{
298 struct proc_dir_entry *pde;
299
Alexey Dobriyanb2ce2c72008-10-08 11:35:05 +0200300 pde = proc_net_fops_create(net, "nf_conntrack", 0440, &ct_file_ops);
Alexey Dobriyanb916f7d2008-03-20 15:15:43 +0100301 if (!pde)
302 goto out_nf_conntrack;
Denis V. Lunev52c0e112008-05-02 04:10:57 -0700303
Alexey Dobriyanb2ce2c72008-10-08 11:35:05 +0200304 pde = proc_create("nf_conntrack", S_IRUGO, net->proc_net_stat,
Denis V. Lunev52c0e112008-05-02 04:10:57 -0700305 &ct_cpu_seq_fops);
Alexey Dobriyanb916f7d2008-03-20 15:15:43 +0100306 if (!pde)
307 goto out_stat_nf_conntrack;
Alexey Dobriyanb916f7d2008-03-20 15:15:43 +0100308 return 0;
309
310out_stat_nf_conntrack:
Alexey Dobriyanb2ce2c72008-10-08 11:35:05 +0200311 proc_net_remove(net, "nf_conntrack");
Alexey Dobriyanb916f7d2008-03-20 15:15:43 +0100312out_nf_conntrack:
313 return -ENOMEM;
314}
315
Alexey Dobriyanb2ce2c72008-10-08 11:35:05 +0200316static void nf_conntrack_standalone_fini_proc(struct net *net)
Alexey Dobriyanb916f7d2008-03-20 15:15:43 +0100317{
Alexey Dobriyanb2ce2c72008-10-08 11:35:05 +0200318 remove_proc_entry("nf_conntrack", net->proc_net_stat);
319 proc_net_remove(net, "nf_conntrack");
Alexey Dobriyanb916f7d2008-03-20 15:15:43 +0100320}
321#else
Alexey Dobriyanb2ce2c72008-10-08 11:35:05 +0200322static int nf_conntrack_standalone_init_proc(struct net *net)
Alexey Dobriyanb916f7d2008-03-20 15:15:43 +0100323{
324 return 0;
325}
326
Alexey Dobriyanb2ce2c72008-10-08 11:35:05 +0200327static void nf_conntrack_standalone_fini_proc(struct net *net)
Alexey Dobriyanb916f7d2008-03-20 15:15:43 +0100328{
329}
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -0800330#endif /* CONFIG_PROC_FS */
331
332/* Sysctl support */
333
334#ifdef CONFIG_SYSCTL
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -0800335/* Log invalid packets of a given protocol */
336static int log_invalid_proto_min = 0;
337static int log_invalid_proto_max = 255;
338
Krzysztof Piotr Oledzki9714be72008-08-06 02:35:44 -0700339static struct ctl_table_header *nf_ct_netfilter_header;
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -0800340
341static ctl_table nf_ct_sysctl_table[] = {
342 {
343 .ctl_name = NET_NF_CONNTRACK_MAX,
344 .procname = "nf_conntrack_max",
345 .data = &nf_conntrack_max,
346 .maxlen = sizeof(int),
347 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800348 .proc_handler = proc_dointvec,
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -0800349 },
350 {
351 .ctl_name = NET_NF_CONNTRACK_COUNT,
352 .procname = "nf_conntrack_count",
Alexey Dobriyan49ac8712008-10-08 11:35:03 +0200353 .data = &init_net.ct.count,
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -0800354 .maxlen = sizeof(int),
355 .mode = 0444,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800356 .proc_handler = proc_dointvec,
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -0800357 },
358 {
359 .ctl_name = NET_NF_CONNTRACK_BUCKETS,
360 .procname = "nf_conntrack_buckets",
361 .data = &nf_conntrack_htable_size,
362 .maxlen = sizeof(unsigned int),
363 .mode = 0444,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800364 .proc_handler = proc_dointvec,
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -0800365 },
366 {
Patrick McHardy39a27a32006-05-29 18:23:54 -0700367 .ctl_name = NET_NF_CONNTRACK_CHECKSUM,
368 .procname = "nf_conntrack_checksum",
Alexey Dobriyanc04d0552008-10-08 11:35:08 +0200369 .data = &init_net.ct.sysctl_checksum,
Patrick McHardy39a27a32006-05-29 18:23:54 -0700370 .maxlen = sizeof(unsigned int),
371 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800372 .proc_handler = proc_dointvec,
Patrick McHardy39a27a32006-05-29 18:23:54 -0700373 },
374 {
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -0800375 .ctl_name = NET_NF_CONNTRACK_LOG_INVALID,
376 .procname = "nf_conntrack_log_invalid",
Alexey Dobriyanc2a2c7e2008-10-08 11:35:08 +0200377 .data = &init_net.ct.sysctl_log_invalid,
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -0800378 .maxlen = sizeof(unsigned int),
379 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800380 .proc_handler = proc_dointvec_minmax,
381 .strategy = sysctl_intvec,
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -0800382 .extra1 = &log_invalid_proto_min,
383 .extra2 = &log_invalid_proto_max,
384 },
Patrick McHardyf264a7d2007-07-07 22:36:24 -0700385 {
386 .ctl_name = CTL_UNNUMBERED,
387 .procname = "nf_conntrack_expect_max",
388 .data = &nf_ct_expect_max,
389 .maxlen = sizeof(int),
390 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800391 .proc_handler = proc_dointvec,
Patrick McHardyf264a7d2007-07-07 22:36:24 -0700392 },
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -0800393 { .ctl_name = 0 }
394};
395
396#define NET_NF_CONNTRACK_MAX 2089
397
398static ctl_table nf_ct_netfilter_table[] = {
399 {
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -0800400 .ctl_name = NET_NF_CONNTRACK_MAX,
401 .procname = "nf_conntrack_max",
402 .data = &nf_conntrack_max,
403 .maxlen = sizeof(int),
404 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800405 .proc_handler = proc_dointvec,
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -0800406 },
407 { .ctl_name = 0 }
408};
409
Patrick McHardy9e232492008-01-31 04:54:45 -0800410static struct ctl_path nf_ct_path[] = {
Pavel Emelyanov3d7cc2b2008-01-09 00:33:11 -0800411 { .procname = "net", .ctl_name = CTL_NET, },
412 { }
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -0800413};
Pavel Emelyanov3d7cc2b2008-01-09 00:33:11 -0800414
Alexey Dobriyan80250702008-10-08 11:35:08 +0200415static int nf_conntrack_standalone_init_sysctl(struct net *net)
Alexey Dobriyanb916f7d2008-03-20 15:15:43 +0100416{
Alexey Dobriyan80250702008-10-08 11:35:08 +0200417 struct ctl_table *table;
Krzysztof Piotr Oledzki9714be72008-08-06 02:35:44 -0700418
Alexey Dobriyan80250702008-10-08 11:35:08 +0200419 if (net_eq(net, &init_net)) {
420 nf_ct_netfilter_header =
421 register_sysctl_paths(nf_ct_path, nf_ct_netfilter_table);
422 if (!nf_ct_netfilter_header)
423 goto out;
424 }
425
426 table = kmemdup(nf_ct_sysctl_table, sizeof(nf_ct_sysctl_table),
427 GFP_KERNEL);
428 if (!table)
429 goto out_kmemdup;
430
431 table[1].data = &net->ct.count;
Alexey Dobriyanc04d0552008-10-08 11:35:08 +0200432 table[3].data = &net->ct.sysctl_checksum;
Alexey Dobriyanc2a2c7e2008-10-08 11:35:08 +0200433 table[4].data = &net->ct.sysctl_log_invalid;
Alexey Dobriyan80250702008-10-08 11:35:08 +0200434
435 net->ct.sysctl_header = register_net_sysctl_table(net,
436 nf_net_netfilter_sysctl_path, table);
437 if (!net->ct.sysctl_header)
Krzysztof Piotr Oledzki9714be72008-08-06 02:35:44 -0700438 goto out_unregister_netfilter;
439
Alexey Dobriyanb916f7d2008-03-20 15:15:43 +0100440 return 0;
441
Krzysztof Piotr Oledzki9714be72008-08-06 02:35:44 -0700442out_unregister_netfilter:
Alexey Dobriyan80250702008-10-08 11:35:08 +0200443 kfree(table);
444out_kmemdup:
445 if (net_eq(net, &init_net))
446 unregister_sysctl_table(nf_ct_netfilter_header);
Krzysztof Piotr Oledzki9714be72008-08-06 02:35:44 -0700447out:
448 printk("nf_conntrack: can't register to sysctl.\n");
449 return -ENOMEM;
Alexey Dobriyanb916f7d2008-03-20 15:15:43 +0100450}
451
Alexey Dobriyan80250702008-10-08 11:35:08 +0200452static void nf_conntrack_standalone_fini_sysctl(struct net *net)
Alexey Dobriyanb916f7d2008-03-20 15:15:43 +0100453{
Alexey Dobriyan80250702008-10-08 11:35:08 +0200454 struct ctl_table *table;
455
456 if (net_eq(net, &init_net))
457 unregister_sysctl_table(nf_ct_netfilter_header);
458 table = net->ct.sysctl_header->ctl_table_arg;
459 unregister_net_sysctl_table(net->ct.sysctl_header);
460 kfree(table);
Alexey Dobriyanb916f7d2008-03-20 15:15:43 +0100461}
462#else
Alexey Dobriyan80250702008-10-08 11:35:08 +0200463static int nf_conntrack_standalone_init_sysctl(struct net *net)
Alexey Dobriyanb916f7d2008-03-20 15:15:43 +0100464{
465 return 0;
466}
467
Alexey Dobriyan80250702008-10-08 11:35:08 +0200468static void nf_conntrack_standalone_fini_sysctl(struct net *net)
Alexey Dobriyanb916f7d2008-03-20 15:15:43 +0100469{
470}
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -0800471#endif /* CONFIG_SYSCTL */
472
Alexey Dobriyandfdb8d72008-10-08 11:35:02 +0200473static int nf_conntrack_net_init(struct net *net)
474{
Alexey Dobriyanb2ce2c72008-10-08 11:35:05 +0200475 int ret;
476
477 ret = nf_conntrack_init(net);
478 if (ret < 0)
479 goto out_init;
480 ret = nf_conntrack_standalone_init_proc(net);
481 if (ret < 0)
482 goto out_proc;
Alexey Dobriyanc04d0552008-10-08 11:35:08 +0200483 net->ct.sysctl_checksum = 1;
Alexey Dobriyanc2a2c7e2008-10-08 11:35:08 +0200484 net->ct.sysctl_log_invalid = 0;
Alexey Dobriyan80250702008-10-08 11:35:08 +0200485 ret = nf_conntrack_standalone_init_sysctl(net);
486 if (ret < 0)
487 goto out_sysctl;
Alexey Dobriyanb2ce2c72008-10-08 11:35:05 +0200488 return 0;
489
Alexey Dobriyan80250702008-10-08 11:35:08 +0200490out_sysctl:
491 nf_conntrack_standalone_fini_proc(net);
Alexey Dobriyanb2ce2c72008-10-08 11:35:05 +0200492out_proc:
493 nf_conntrack_cleanup(net);
494out_init:
495 return ret;
Alexey Dobriyandfdb8d72008-10-08 11:35:02 +0200496}
497
498static void nf_conntrack_net_exit(struct net *net)
499{
Alexey Dobriyan80250702008-10-08 11:35:08 +0200500 nf_conntrack_standalone_fini_sysctl(net);
Alexey Dobriyanb2ce2c72008-10-08 11:35:05 +0200501 nf_conntrack_standalone_fini_proc(net);
Alexey Dobriyandfdb8d72008-10-08 11:35:02 +0200502 nf_conntrack_cleanup(net);
503}
504
505static struct pernet_operations nf_conntrack_net_ops = {
506 .init = nf_conntrack_net_init,
507 .exit = nf_conntrack_net_exit,
508};
509
Andrew Morton65b4b4e2006-03-28 16:37:06 -0800510static int __init nf_conntrack_standalone_init(void)
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -0800511{
Alexey Dobriyan80250702008-10-08 11:35:08 +0200512 return register_pernet_subsys(&nf_conntrack_net_ops);
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -0800513}
514
Andrew Morton65b4b4e2006-03-28 16:37:06 -0800515static void __exit nf_conntrack_standalone_fini(void)
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -0800516{
Alexey Dobriyandfdb8d72008-10-08 11:35:02 +0200517 unregister_pernet_subsys(&nf_conntrack_net_ops);
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -0800518}
519
Andrew Morton65b4b4e2006-03-28 16:37:06 -0800520module_init(nf_conntrack_standalone_init);
521module_exit(nf_conntrack_standalone_fini);
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -0800522
523/* Some modules need us, but don't depend directly on any symbol.
524 They should call this. */
Harald Welte2e4e6a12006-01-12 13:30:04 -0800525void need_conntrack(void)
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -0800526{
527}
Patrick McHardy13b18332006-12-02 22:11:25 -0800528EXPORT_SYMBOL_GPL(need_conntrack);