blob: f37b9b74c6a8c78ea372569d4ffba09f69be9f9d [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
Patrick McHardyf205c5e2007-07-07 22:28:14 -070047static struct hlist_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;
Patrick McHardy76507f62008-01-31 04:38:38 -080051 struct hlist_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);
Patrick McHardy76507f62008-01-31 04:38:38 -080057 if (n)
58 return n;
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -080059 }
60 return NULL;
61}
62
Patrick McHardyf205c5e2007-07-07 22:28:14 -070063static struct hlist_node *ct_get_next(struct seq_file *seq,
64 struct hlist_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);
Patrick McHardyf205c5e2007-07-07 22:28:14 -070070 while (head == NULL) {
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -080071 if (++st->bucket >= nf_conntrack_htable_size)
72 return NULL;
Alexey Dobriyanb2ce2c72008-10-08 11:35:05 +020073 head = rcu_dereference(net->ct.hash[st->bucket].first);
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -080074 }
75 return head;
76}
77
Patrick McHardyf205c5e2007-07-07 22:28:14 -070078static struct hlist_node *ct_get_idx(struct seq_file *seq, loff_t pos)
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -080079{
Patrick McHardyf205c5e2007-07-07 22:28:14 -070080 struct hlist_node *head = ct_get_first(seq);
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -080081
82 if (head)
83 while (pos && (head = ct_get_next(seq, head)))
84 pos--;
85 return pos ? NULL : head;
86}
87
88static void *ct_seq_start(struct seq_file *seq, loff_t *pos)
Patrick McHardy76507f62008-01-31 04:38:38 -080089 __acquires(RCU)
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -080090{
Patrick McHardy76507f62008-01-31 04:38:38 -080091 rcu_read_lock();
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -080092 return ct_get_idx(seq, *pos);
93}
94
95static void *ct_seq_next(struct seq_file *s, void *v, loff_t *pos)
96{
97 (*pos)++;
98 return ct_get_next(s, v);
99}
100
101static void ct_seq_stop(struct seq_file *s, void *v)
Patrick McHardy76507f62008-01-31 04:38:38 -0800102 __releases(RCU)
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -0800103{
Patrick McHardy76507f62008-01-31 04:38:38 -0800104 rcu_read_unlock();
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -0800105}
106
107/* return 0 on success, 1 in case of error */
108static int ct_seq_show(struct seq_file *s, void *v)
109{
110 const struct nf_conntrack_tuple_hash *hash = v;
Patrick McHardyc88130b2008-01-31 04:42:11 -0800111 const struct nf_conn *ct = nf_ct_tuplehash_to_ctrack(hash);
Jan Engelhardt32948582008-01-31 04:53:24 -0800112 const struct nf_conntrack_l3proto *l3proto;
113 const struct nf_conntrack_l4proto *l4proto;
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -0800114
Patrick McHardyc88130b2008-01-31 04:42:11 -0800115 NF_CT_ASSERT(ct);
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -0800116
117 /* we only want to print DIR_ORIGINAL */
118 if (NF_CT_DIRECTION(hash))
119 return 0;
120
Patrick McHardy5e8fbe22008-04-14 11:15:52 +0200121 l3proto = __nf_ct_l3proto_find(nf_ct_l3num(ct));
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -0800122 NF_CT_ASSERT(l3proto);
Patrick McHardy5e8fbe22008-04-14 11:15:52 +0200123 l4proto = __nf_ct_l4proto_find(nf_ct_l3num(ct), nf_ct_protonum(ct));
Martin Josefsson605dcad2006-11-29 02:35:06 +0100124 NF_CT_ASSERT(l4proto);
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -0800125
126 if (seq_printf(s, "%-8s %u %-8s %u %ld ",
Patrick McHardy5e8fbe22008-04-14 11:15:52 +0200127 l3proto->name, nf_ct_l3num(ct),
128 l4proto->name, nf_ct_protonum(ct),
Patrick McHardyc88130b2008-01-31 04:42:11 -0800129 timer_pending(&ct->timeout)
130 ? (long)(ct->timeout.expires - jiffies)/HZ : 0) != 0)
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -0800131 return -ENOSPC;
132
Patrick McHardyc88130b2008-01-31 04:42:11 -0800133 if (l4proto->print_conntrack && l4proto->print_conntrack(s, ct))
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -0800134 return -ENOSPC;
135
Patrick McHardyc88130b2008-01-31 04:42:11 -0800136 if (print_tuple(s, &ct->tuplehash[IP_CT_DIR_ORIGINAL].tuple,
Martin Josefsson605dcad2006-11-29 02:35:06 +0100137 l3proto, l4proto))
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -0800138 return -ENOSPC;
139
Krzysztof Piotr Oledzki58401572008-07-21 10:01:34 -0700140 if (seq_print_acct(s, ct, IP_CT_DIR_ORIGINAL))
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -0800141 return -ENOSPC;
142
Patrick McHardyc88130b2008-01-31 04:42:11 -0800143 if (!(test_bit(IPS_SEEN_REPLY_BIT, &ct->status)))
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -0800144 if (seq_printf(s, "[UNREPLIED] "))
145 return -ENOSPC;
146
Patrick McHardyc88130b2008-01-31 04:42:11 -0800147 if (print_tuple(s, &ct->tuplehash[IP_CT_DIR_REPLY].tuple,
Martin Josefsson605dcad2006-11-29 02:35:06 +0100148 l3proto, l4proto))
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -0800149 return -ENOSPC;
150
Krzysztof Piotr Oledzki58401572008-07-21 10:01:34 -0700151 if (seq_print_acct(s, ct, IP_CT_DIR_REPLY))
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -0800152 return -ENOSPC;
153
Patrick McHardyc88130b2008-01-31 04:42:11 -0800154 if (test_bit(IPS_ASSURED_BIT, &ct->status))
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -0800155 if (seq_printf(s, "[ASSURED] "))
156 return -ENOSPC;
157
158#if defined(CONFIG_NF_CONNTRACK_MARK)
Patrick McHardyc88130b2008-01-31 04:42:11 -0800159 if (seq_printf(s, "mark=%u ", ct->mark))
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -0800160 return -ENOSPC;
161#endif
162
James Morris7c9728c2006-06-09 00:31:46 -0700163#ifdef CONFIG_NF_CONNTRACK_SECMARK
Patrick McHardyc88130b2008-01-31 04:42:11 -0800164 if (seq_printf(s, "secmark=%u ", ct->secmark))
James Morris7c9728c2006-06-09 00:31:46 -0700165 return -ENOSPC;
166#endif
167
Patrick McHardyc88130b2008-01-31 04:42:11 -0800168 if (seq_printf(s, "use=%u\n", atomic_read(&ct->ct_general.use)))
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -0800169 return -ENOSPC;
YOSHIFUJI Hideakia5d29262007-07-19 10:44:21 +0900170
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -0800171 return 0;
172}
173
Philippe De Muyter56b3d972007-07-10 23:07:31 -0700174static const struct seq_operations ct_seq_ops = {
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -0800175 .start = ct_seq_start,
176 .next = ct_seq_next,
177 .stop = ct_seq_stop,
178 .show = ct_seq_show
179};
180
181static int ct_open(struct inode *inode, struct file *file)
182{
Alexey Dobriyanb2ce2c72008-10-08 11:35:05 +0200183 return seq_open_net(inode, file, &ct_seq_ops,
Pavel Emelyanove2da5912007-10-10 02:29:58 -0700184 sizeof(struct ct_iter_state));
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -0800185}
186
Arjan van de Venda7071d2007-02-12 00:55:36 -0800187static const struct file_operations ct_file_ops = {
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -0800188 .owner = THIS_MODULE,
189 .open = ct_open,
190 .read = seq_read,
191 .llseek = seq_lseek,
Alexey Dobriyanb2ce2c72008-10-08 11:35:05 +0200192 .release = seq_release_net,
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -0800193};
194
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -0800195static void *ct_cpu_seq_start(struct seq_file *seq, loff_t *pos)
196{
Alexey Dobriyan8e9df802008-10-08 11:35:08 +0200197 struct net *net = seq_file_net(seq);
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -0800198 int cpu;
199
200 if (*pos == 0)
201 return SEQ_START_TOKEN;
202
203 for (cpu = *pos-1; cpu < NR_CPUS; ++cpu) {
204 if (!cpu_possible(cpu))
205 continue;
206 *pos = cpu + 1;
Alexey Dobriyan8e9df802008-10-08 11:35:08 +0200207 return per_cpu_ptr(net->ct.stat, cpu);
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -0800208 }
209
210 return NULL;
211}
212
213static void *ct_cpu_seq_next(struct seq_file *seq, void *v, loff_t *pos)
214{
Alexey Dobriyan8e9df802008-10-08 11:35:08 +0200215 struct net *net = seq_file_net(seq);
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -0800216 int cpu;
217
218 for (cpu = *pos; cpu < NR_CPUS; ++cpu) {
219 if (!cpu_possible(cpu))
220 continue;
221 *pos = cpu + 1;
Alexey Dobriyan8e9df802008-10-08 11:35:08 +0200222 return per_cpu_ptr(net->ct.stat, cpu);
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -0800223 }
224
225 return NULL;
226}
227
228static void ct_cpu_seq_stop(struct seq_file *seq, void *v)
229{
230}
231
232static int ct_cpu_seq_show(struct seq_file *seq, void *v)
233{
Alexey Dobriyan8e9df802008-10-08 11:35:08 +0200234 struct net *net = seq_file_net(seq);
235 unsigned int nr_conntracks = atomic_read(&net->ct.count);
Jan Engelhardt32948582008-01-31 04:53:24 -0800236 const struct ip_conntrack_stat *st = v;
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -0800237
238 if (v == SEQ_START_TOKEN) {
239 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");
240 return 0;
241 }
242
243 seq_printf(seq, "%08x %08x %08x %08x %08x %08x %08x %08x "
244 "%08x %08x %08x %08x %08x %08x %08x %08x \n",
245 nr_conntracks,
246 st->searched,
247 st->found,
248 st->new,
249 st->invalid,
250 st->ignore,
251 st->delete,
252 st->delete_list,
253 st->insert,
254 st->insert_failed,
255 st->drop,
256 st->early_drop,
257 st->error,
258
259 st->expect_new,
260 st->expect_create,
261 st->expect_delete
262 );
263 return 0;
264}
265
Philippe De Muyter56b3d972007-07-10 23:07:31 -0700266static const struct seq_operations ct_cpu_seq_ops = {
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -0800267 .start = ct_cpu_seq_start,
268 .next = ct_cpu_seq_next,
269 .stop = ct_cpu_seq_stop,
270 .show = ct_cpu_seq_show,
271};
272
273static int ct_cpu_seq_open(struct inode *inode, struct file *file)
274{
Alexey Dobriyan8e9df802008-10-08 11:35:08 +0200275 return seq_open_net(inode, file, &ct_cpu_seq_ops,
276 sizeof(struct seq_net_private));
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -0800277}
278
Arjan van de Venda7071d2007-02-12 00:55:36 -0800279static const struct file_operations ct_cpu_seq_fops = {
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -0800280 .owner = THIS_MODULE,
281 .open = ct_cpu_seq_open,
282 .read = seq_read,
283 .llseek = seq_lseek,
Alexey Dobriyan8e9df802008-10-08 11:35:08 +0200284 .release = seq_release_net,
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -0800285};
Alexey Dobriyanb916f7d2008-03-20 15:15:43 +0100286
Alexey Dobriyanb2ce2c72008-10-08 11:35:05 +0200287static int nf_conntrack_standalone_init_proc(struct net *net)
Alexey Dobriyanb916f7d2008-03-20 15:15:43 +0100288{
289 struct proc_dir_entry *pde;
290
Alexey Dobriyanb2ce2c72008-10-08 11:35:05 +0200291 pde = proc_net_fops_create(net, "nf_conntrack", 0440, &ct_file_ops);
Alexey Dobriyanb916f7d2008-03-20 15:15:43 +0100292 if (!pde)
293 goto out_nf_conntrack;
Denis V. Lunev52c0e112008-05-02 04:10:57 -0700294
Alexey Dobriyanb2ce2c72008-10-08 11:35:05 +0200295 pde = proc_create("nf_conntrack", S_IRUGO, net->proc_net_stat,
Denis V. Lunev52c0e112008-05-02 04:10:57 -0700296 &ct_cpu_seq_fops);
Alexey Dobriyanb916f7d2008-03-20 15:15:43 +0100297 if (!pde)
298 goto out_stat_nf_conntrack;
Alexey Dobriyanb916f7d2008-03-20 15:15:43 +0100299 return 0;
300
301out_stat_nf_conntrack:
Alexey Dobriyanb2ce2c72008-10-08 11:35:05 +0200302 proc_net_remove(net, "nf_conntrack");
Alexey Dobriyanb916f7d2008-03-20 15:15:43 +0100303out_nf_conntrack:
304 return -ENOMEM;
305}
306
Alexey Dobriyanb2ce2c72008-10-08 11:35:05 +0200307static void nf_conntrack_standalone_fini_proc(struct net *net)
Alexey Dobriyanb916f7d2008-03-20 15:15:43 +0100308{
Alexey Dobriyanb2ce2c72008-10-08 11:35:05 +0200309 remove_proc_entry("nf_conntrack", net->proc_net_stat);
310 proc_net_remove(net, "nf_conntrack");
Alexey Dobriyanb916f7d2008-03-20 15:15:43 +0100311}
312#else
Alexey Dobriyanb2ce2c72008-10-08 11:35:05 +0200313static int nf_conntrack_standalone_init_proc(struct net *net)
Alexey Dobriyanb916f7d2008-03-20 15:15:43 +0100314{
315 return 0;
316}
317
Alexey Dobriyanb2ce2c72008-10-08 11:35:05 +0200318static void nf_conntrack_standalone_fini_proc(struct net *net)
Alexey Dobriyanb916f7d2008-03-20 15:15:43 +0100319{
320}
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -0800321#endif /* CONFIG_PROC_FS */
322
323/* Sysctl support */
324
325#ifdef CONFIG_SYSCTL
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -0800326/* Log invalid packets of a given protocol */
327static int log_invalid_proto_min = 0;
328static int log_invalid_proto_max = 255;
329
Krzysztof Piotr Oledzki9714be72008-08-06 02:35:44 -0700330static struct ctl_table_header *nf_ct_netfilter_header;
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -0800331
332static ctl_table nf_ct_sysctl_table[] = {
333 {
334 .ctl_name = NET_NF_CONNTRACK_MAX,
335 .procname = "nf_conntrack_max",
336 .data = &nf_conntrack_max,
337 .maxlen = sizeof(int),
338 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800339 .proc_handler = proc_dointvec,
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -0800340 },
341 {
342 .ctl_name = NET_NF_CONNTRACK_COUNT,
343 .procname = "nf_conntrack_count",
Alexey Dobriyan49ac8712008-10-08 11:35:03 +0200344 .data = &init_net.ct.count,
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -0800345 .maxlen = sizeof(int),
346 .mode = 0444,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800347 .proc_handler = proc_dointvec,
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -0800348 },
349 {
350 .ctl_name = NET_NF_CONNTRACK_BUCKETS,
351 .procname = "nf_conntrack_buckets",
352 .data = &nf_conntrack_htable_size,
353 .maxlen = sizeof(unsigned int),
354 .mode = 0444,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800355 .proc_handler = proc_dointvec,
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -0800356 },
357 {
Patrick McHardy39a27a32006-05-29 18:23:54 -0700358 .ctl_name = NET_NF_CONNTRACK_CHECKSUM,
359 .procname = "nf_conntrack_checksum",
Alexey Dobriyanc04d0552008-10-08 11:35:08 +0200360 .data = &init_net.ct.sysctl_checksum,
Patrick McHardy39a27a32006-05-29 18:23:54 -0700361 .maxlen = sizeof(unsigned int),
362 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800363 .proc_handler = proc_dointvec,
Patrick McHardy39a27a32006-05-29 18:23:54 -0700364 },
365 {
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -0800366 .ctl_name = NET_NF_CONNTRACK_LOG_INVALID,
367 .procname = "nf_conntrack_log_invalid",
Alexey Dobriyanc2a2c7e2008-10-08 11:35:08 +0200368 .data = &init_net.ct.sysctl_log_invalid,
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -0800369 .maxlen = sizeof(unsigned int),
370 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800371 .proc_handler = proc_dointvec_minmax,
372 .strategy = sysctl_intvec,
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -0800373 .extra1 = &log_invalid_proto_min,
374 .extra2 = &log_invalid_proto_max,
375 },
Patrick McHardyf264a7d2007-07-07 22:36:24 -0700376 {
377 .ctl_name = CTL_UNNUMBERED,
378 .procname = "nf_conntrack_expect_max",
379 .data = &nf_ct_expect_max,
380 .maxlen = sizeof(int),
381 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800382 .proc_handler = proc_dointvec,
Patrick McHardyf264a7d2007-07-07 22:36:24 -0700383 },
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -0800384 { .ctl_name = 0 }
385};
386
387#define NET_NF_CONNTRACK_MAX 2089
388
389static ctl_table nf_ct_netfilter_table[] = {
390 {
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -0800391 .ctl_name = NET_NF_CONNTRACK_MAX,
392 .procname = "nf_conntrack_max",
393 .data = &nf_conntrack_max,
394 .maxlen = sizeof(int),
395 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800396 .proc_handler = proc_dointvec,
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -0800397 },
398 { .ctl_name = 0 }
399};
400
Patrick McHardy9e232492008-01-31 04:54:45 -0800401static struct ctl_path nf_ct_path[] = {
Pavel Emelyanov3d7cc2b2008-01-09 00:33:11 -0800402 { .procname = "net", .ctl_name = CTL_NET, },
403 { }
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -0800404};
Pavel Emelyanov3d7cc2b2008-01-09 00:33:11 -0800405
Alexey Dobriyan80250702008-10-08 11:35:08 +0200406static int nf_conntrack_standalone_init_sysctl(struct net *net)
Alexey Dobriyanb916f7d2008-03-20 15:15:43 +0100407{
Alexey Dobriyan80250702008-10-08 11:35:08 +0200408 struct ctl_table *table;
Krzysztof Piotr Oledzki9714be72008-08-06 02:35:44 -0700409
Alexey Dobriyan80250702008-10-08 11:35:08 +0200410 if (net_eq(net, &init_net)) {
411 nf_ct_netfilter_header =
412 register_sysctl_paths(nf_ct_path, nf_ct_netfilter_table);
413 if (!nf_ct_netfilter_header)
414 goto out;
415 }
416
417 table = kmemdup(nf_ct_sysctl_table, sizeof(nf_ct_sysctl_table),
418 GFP_KERNEL);
419 if (!table)
420 goto out_kmemdup;
421
422 table[1].data = &net->ct.count;
Alexey Dobriyanc04d0552008-10-08 11:35:08 +0200423 table[3].data = &net->ct.sysctl_checksum;
Alexey Dobriyanc2a2c7e2008-10-08 11:35:08 +0200424 table[4].data = &net->ct.sysctl_log_invalid;
Alexey Dobriyan80250702008-10-08 11:35:08 +0200425
426 net->ct.sysctl_header = register_net_sysctl_table(net,
427 nf_net_netfilter_sysctl_path, table);
428 if (!net->ct.sysctl_header)
Krzysztof Piotr Oledzki9714be72008-08-06 02:35:44 -0700429 goto out_unregister_netfilter;
430
Alexey Dobriyanb916f7d2008-03-20 15:15:43 +0100431 return 0;
432
Krzysztof Piotr Oledzki9714be72008-08-06 02:35:44 -0700433out_unregister_netfilter:
Alexey Dobriyan80250702008-10-08 11:35:08 +0200434 kfree(table);
435out_kmemdup:
436 if (net_eq(net, &init_net))
437 unregister_sysctl_table(nf_ct_netfilter_header);
Krzysztof Piotr Oledzki9714be72008-08-06 02:35:44 -0700438out:
439 printk("nf_conntrack: can't register to sysctl.\n");
440 return -ENOMEM;
Alexey Dobriyanb916f7d2008-03-20 15:15:43 +0100441}
442
Alexey Dobriyan80250702008-10-08 11:35:08 +0200443static void nf_conntrack_standalone_fini_sysctl(struct net *net)
Alexey Dobriyanb916f7d2008-03-20 15:15:43 +0100444{
Alexey Dobriyan80250702008-10-08 11:35:08 +0200445 struct ctl_table *table;
446
447 if (net_eq(net, &init_net))
448 unregister_sysctl_table(nf_ct_netfilter_header);
449 table = net->ct.sysctl_header->ctl_table_arg;
450 unregister_net_sysctl_table(net->ct.sysctl_header);
451 kfree(table);
Alexey Dobriyanb916f7d2008-03-20 15:15:43 +0100452}
453#else
Alexey Dobriyan80250702008-10-08 11:35:08 +0200454static int nf_conntrack_standalone_init_sysctl(struct net *net)
Alexey Dobriyanb916f7d2008-03-20 15:15:43 +0100455{
456 return 0;
457}
458
Alexey Dobriyan80250702008-10-08 11:35:08 +0200459static void nf_conntrack_standalone_fini_sysctl(struct net *net)
Alexey Dobriyanb916f7d2008-03-20 15:15:43 +0100460{
461}
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -0800462#endif /* CONFIG_SYSCTL */
463
Alexey Dobriyandfdb8d72008-10-08 11:35:02 +0200464static int nf_conntrack_net_init(struct net *net)
465{
Alexey Dobriyanb2ce2c72008-10-08 11:35:05 +0200466 int ret;
467
468 ret = nf_conntrack_init(net);
469 if (ret < 0)
470 goto out_init;
471 ret = nf_conntrack_standalone_init_proc(net);
472 if (ret < 0)
473 goto out_proc;
Alexey Dobriyanc04d0552008-10-08 11:35:08 +0200474 net->ct.sysctl_checksum = 1;
Alexey Dobriyanc2a2c7e2008-10-08 11:35:08 +0200475 net->ct.sysctl_log_invalid = 0;
Alexey Dobriyan80250702008-10-08 11:35:08 +0200476 ret = nf_conntrack_standalone_init_sysctl(net);
477 if (ret < 0)
478 goto out_sysctl;
Alexey Dobriyanb2ce2c72008-10-08 11:35:05 +0200479 return 0;
480
Alexey Dobriyan80250702008-10-08 11:35:08 +0200481out_sysctl:
482 nf_conntrack_standalone_fini_proc(net);
Alexey Dobriyanb2ce2c72008-10-08 11:35:05 +0200483out_proc:
484 nf_conntrack_cleanup(net);
485out_init:
486 return ret;
Alexey Dobriyandfdb8d72008-10-08 11:35:02 +0200487}
488
489static void nf_conntrack_net_exit(struct net *net)
490{
Alexey Dobriyan80250702008-10-08 11:35:08 +0200491 nf_conntrack_standalone_fini_sysctl(net);
Alexey Dobriyanb2ce2c72008-10-08 11:35:05 +0200492 nf_conntrack_standalone_fini_proc(net);
Alexey Dobriyandfdb8d72008-10-08 11:35:02 +0200493 nf_conntrack_cleanup(net);
494}
495
496static struct pernet_operations nf_conntrack_net_ops = {
497 .init = nf_conntrack_net_init,
498 .exit = nf_conntrack_net_exit,
499};
500
Andrew Morton65b4b4e2006-03-28 16:37:06 -0800501static int __init nf_conntrack_standalone_init(void)
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -0800502{
Alexey Dobriyan80250702008-10-08 11:35:08 +0200503 return register_pernet_subsys(&nf_conntrack_net_ops);
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -0800504}
505
Andrew Morton65b4b4e2006-03-28 16:37:06 -0800506static void __exit nf_conntrack_standalone_fini(void)
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -0800507{
Alexey Dobriyandfdb8d72008-10-08 11:35:02 +0200508 unregister_pernet_subsys(&nf_conntrack_net_ops);
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -0800509}
510
Andrew Morton65b4b4e2006-03-28 16:37:06 -0800511module_init(nf_conntrack_standalone_init);
512module_exit(nf_conntrack_standalone_fini);
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -0800513
514/* Some modules need us, but don't depend directly on any symbol.
515 They should call this. */
Harald Welte2e4e6a12006-01-12 13:30:04 -0800516void need_conntrack(void)
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -0800517{
518}
Patrick McHardy13b18332006-12-02 22:11:25 -0800519EXPORT_SYMBOL_GPL(need_conntrack);