blob: f0dfe92a00d66a6a58301a94b238baa5cae32fb7 [file] [log] [blame]
Patrick McHardye4bd8bc2006-11-29 02:35:22 +01001/* ip_conntrack proc compat - based on ip_conntrack_standalone.c
2 *
3 * (C) 1999-2001 Paul `Rusty' Russell
4 * (C) 2002-2006 Netfilter Core Team <coreteam@netfilter.org>
Patrick McHardyf229f6c2013-04-06 15:24:29 +02005 * (C) 2006-2010 Patrick McHardy <kaber@trash.net>
Patrick McHardye4bd8bc2006-11-29 02:35:22 +01006 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 as
9 * published by the Free Software Foundation.
10 */
11#include <linux/types.h>
12#include <linux/proc_fs.h>
13#include <linux/seq_file.h>
14#include <linux/percpu.h>
Eric Paris1ae4de02010-10-13 16:25:00 -040015#include <linux/security.h>
Eric W. Biederman457c4cb2007-09-12 12:01:34 +020016#include <net/net_namespace.h>
Patrick McHardye4bd8bc2006-11-29 02:35:22 +010017
18#include <linux/netfilter.h>
19#include <net/netfilter/nf_conntrack_core.h>
20#include <net/netfilter/nf_conntrack_l3proto.h>
21#include <net/netfilter/nf_conntrack_l4proto.h>
22#include <net/netfilter/nf_conntrack_expect.h>
Krzysztof Piotr Oledzki58401572008-07-21 10:01:34 -070023#include <net/netfilter/nf_conntrack_acct.h>
Eric Dumazeteb733162010-11-15 18:43:59 +010024#include <linux/rculist_nulls.h>
Paul Gortmakerbc3b2d72011-07-15 11:47:34 -040025#include <linux/export.h>
Patrick McHardye4bd8bc2006-11-29 02:35:22 +010026
27struct ct_iter_state {
Alexey Dobriyan5e6b2992008-10-08 11:35:06 +020028 struct seq_net_private p;
Patrick McHardye4bd8bc2006-11-29 02:35:22 +010029 unsigned int bucket;
30};
31
Eric Dumazetea781f12009-03-25 21:05:46 +010032static struct hlist_nulls_node *ct_get_first(struct seq_file *seq)
Patrick McHardye4bd8bc2006-11-29 02:35:22 +010033{
Alexey Dobriyan5e6b2992008-10-08 11:35:06 +020034 struct net *net = seq_file_net(seq);
Patrick McHardye4bd8bc2006-11-29 02:35:22 +010035 struct ct_iter_state *st = seq->private;
Eric Dumazetea781f12009-03-25 21:05:46 +010036 struct hlist_nulls_node *n;
Patrick McHardye4bd8bc2006-11-29 02:35:22 +010037
38 for (st->bucket = 0;
Patrick McHardyd696c7b2010-02-08 11:18:07 -080039 st->bucket < net->ct.htable_size;
Patrick McHardye4bd8bc2006-11-29 02:35:22 +010040 st->bucket++) {
Eric Dumazeteb733162010-11-15 18:43:59 +010041 n = rcu_dereference(
42 hlist_nulls_first_rcu(&net->ct.hash[st->bucket]));
Eric Dumazetea781f12009-03-25 21:05:46 +010043 if (!is_a_nulls(n))
Patrick McHardy76507f62008-01-31 04:38:38 -080044 return n;
Patrick McHardye4bd8bc2006-11-29 02:35:22 +010045 }
46 return NULL;
47}
48
Eric Dumazetea781f12009-03-25 21:05:46 +010049static struct hlist_nulls_node *ct_get_next(struct seq_file *seq,
50 struct hlist_nulls_node *head)
Patrick McHardye4bd8bc2006-11-29 02:35:22 +010051{
Alexey Dobriyan5e6b2992008-10-08 11:35:06 +020052 struct net *net = seq_file_net(seq);
Patrick McHardye4bd8bc2006-11-29 02:35:22 +010053 struct ct_iter_state *st = seq->private;
54
Eric Dumazeteb733162010-11-15 18:43:59 +010055 head = rcu_dereference(hlist_nulls_next_rcu(head));
Eric Dumazetea781f12009-03-25 21:05:46 +010056 while (is_a_nulls(head)) {
57 if (likely(get_nulls_value(head) == st->bucket)) {
Patrick McHardyd696c7b2010-02-08 11:18:07 -080058 if (++st->bucket >= net->ct.htable_size)
Eric Dumazetea781f12009-03-25 21:05:46 +010059 return NULL;
60 }
Eric Dumazeteb733162010-11-15 18:43:59 +010061 head = rcu_dereference(
62 hlist_nulls_first_rcu(&net->ct.hash[st->bucket]));
Patrick McHardye4bd8bc2006-11-29 02:35:22 +010063 }
64 return head;
65}
66
Eric Dumazetea781f12009-03-25 21:05:46 +010067static struct hlist_nulls_node *ct_get_idx(struct seq_file *seq, loff_t pos)
Patrick McHardye4bd8bc2006-11-29 02:35:22 +010068{
Eric Dumazetea781f12009-03-25 21:05:46 +010069 struct hlist_nulls_node *head = ct_get_first(seq);
Patrick McHardye4bd8bc2006-11-29 02:35:22 +010070
71 if (head)
72 while (pos && (head = ct_get_next(seq, head)))
73 pos--;
74 return pos ? NULL : head;
75}
76
77static void *ct_seq_start(struct seq_file *seq, loff_t *pos)
Patrick McHardy76507f62008-01-31 04:38:38 -080078 __acquires(RCU)
Patrick McHardye4bd8bc2006-11-29 02:35:22 +010079{
Patrick McHardy76507f62008-01-31 04:38:38 -080080 rcu_read_lock();
Patrick McHardye4bd8bc2006-11-29 02:35:22 +010081 return ct_get_idx(seq, *pos);
82}
83
84static void *ct_seq_next(struct seq_file *s, void *v, loff_t *pos)
85{
86 (*pos)++;
87 return ct_get_next(s, v);
88}
89
90static void ct_seq_stop(struct seq_file *s, void *v)
Patrick McHardy76507f62008-01-31 04:38:38 -080091 __releases(RCU)
Patrick McHardye4bd8bc2006-11-29 02:35:22 +010092{
Patrick McHardy76507f62008-01-31 04:38:38 -080093 rcu_read_unlock();
Patrick McHardye4bd8bc2006-11-29 02:35:22 +010094}
95
Eric Paris1ae4de02010-10-13 16:25:00 -040096#ifdef CONFIG_NF_CONNTRACK_SECMARK
Steven Rostedt (Red Hat)e71456a2014-10-27 17:43:45 -040097static void ct_show_secctx(struct seq_file *s, const struct nf_conn *ct)
Eric Paris1ae4de02010-10-13 16:25:00 -040098{
99 int ret;
100 u32 len;
101 char *secctx;
102
103 ret = security_secid_to_secctx(ct->secmark, &secctx, &len);
104 if (ret)
Steven Rostedt (Red Hat)e71456a2014-10-27 17:43:45 -0400105 return;
Eric Paris1ae4de02010-10-13 16:25:00 -0400106
Steven Rostedt (Red Hat)e71456a2014-10-27 17:43:45 -0400107 seq_printf(s, "secctx=%s ", secctx);
Eric Paris1ae4de02010-10-13 16:25:00 -0400108
109 security_release_secctx(secctx, len);
Eric Paris1ae4de02010-10-13 16:25:00 -0400110}
111#else
Steven Rostedt (Red Hat)e71456a2014-10-27 17:43:45 -0400112static inline void ct_show_secctx(struct seq_file *s, const struct nf_conn *ct)
Eric Paris1ae4de02010-10-13 16:25:00 -0400113{
Eric Paris1ae4de02010-10-13 16:25:00 -0400114}
115#endif
116
Patrick McHardye4bd8bc2006-11-29 02:35:22 +0100117static int ct_seq_show(struct seq_file *s, void *v)
118{
Eric Dumazetea781f12009-03-25 21:05:46 +0100119 struct nf_conntrack_tuple_hash *hash = v;
120 struct nf_conn *ct = nf_ct_tuplehash_to_ctrack(hash);
Jan Engelhardt32948582008-01-31 04:53:24 -0800121 const struct nf_conntrack_l3proto *l3proto;
122 const struct nf_conntrack_l4proto *l4proto;
Eric Dumazetea781f12009-03-25 21:05:46 +0100123 int ret = 0;
Patrick McHardye4bd8bc2006-11-29 02:35:22 +0100124
125 NF_CT_ASSERT(ct);
Eric Dumazetea781f12009-03-25 21:05:46 +0100126 if (unlikely(!atomic_inc_not_zero(&ct->ct_general.use)))
127 return 0;
128
Patrick McHardye4bd8bc2006-11-29 02:35:22 +0100129
130 /* we only want to print DIR_ORIGINAL */
131 if (NF_CT_DIRECTION(hash))
Eric Dumazetea781f12009-03-25 21:05:46 +0100132 goto release;
Patrick McHardy5e8fbe22008-04-14 11:15:52 +0200133 if (nf_ct_l3num(ct) != AF_INET)
Eric Dumazetea781f12009-03-25 21:05:46 +0100134 goto release;
Patrick McHardye4bd8bc2006-11-29 02:35:22 +0100135
Patrick McHardy5e8fbe22008-04-14 11:15:52 +0200136 l3proto = __nf_ct_l3proto_find(nf_ct_l3num(ct));
Patrick McHardye4bd8bc2006-11-29 02:35:22 +0100137 NF_CT_ASSERT(l3proto);
Patrick McHardy5e8fbe22008-04-14 11:15:52 +0200138 l4proto = __nf_ct_l4proto_find(nf_ct_l3num(ct), nf_ct_protonum(ct));
Patrick McHardye4bd8bc2006-11-29 02:35:22 +0100139 NF_CT_ASSERT(l4proto);
140
Eric Dumazetea781f12009-03-25 21:05:46 +0100141 ret = -ENOSPC;
Steven Rostedt (Red Hat)e71456a2014-10-27 17:43:45 -0400142 seq_printf(s, "%-8s %u %ld ",
143 l4proto->name, nf_ct_protonum(ct),
144 timer_pending(&ct->timeout)
145 ? (long)(ct->timeout.expires - jiffies)/HZ : 0);
Patrick McHardye4bd8bc2006-11-29 02:35:22 +0100146
Steven Rostedt (Red Hat)37246a52014-10-27 16:02:47 -0400147 if (l4proto->print_conntrack)
148 l4proto->print_conntrack(s, ct);
149
150 if (seq_has_overflowed(s))
Eric Dumazetea781f12009-03-25 21:05:46 +0100151 goto release;
Patrick McHardye4bd8bc2006-11-29 02:35:22 +0100152
Joe Perches824f1fb2014-09-29 16:08:22 -0700153 print_tuple(s, &ct->tuplehash[IP_CT_DIR_ORIGINAL].tuple,
154 l3proto, l4proto);
155
156 if (seq_has_overflowed(s))
Eric Dumazetea781f12009-03-25 21:05:46 +0100157 goto release;
Patrick McHardye4bd8bc2006-11-29 02:35:22 +0100158
Krzysztof Piotr Oledzki58401572008-07-21 10:01:34 -0700159 if (seq_print_acct(s, ct, IP_CT_DIR_ORIGINAL))
Eric Dumazetea781f12009-03-25 21:05:46 +0100160 goto release;
Patrick McHardye4bd8bc2006-11-29 02:35:22 +0100161
162 if (!(test_bit(IPS_SEEN_REPLY_BIT, &ct->status)))
Steven Rostedt (Red Hat)e71456a2014-10-27 17:43:45 -0400163 seq_printf(s, "[UNREPLIED] ");
Patrick McHardye4bd8bc2006-11-29 02:35:22 +0100164
Joe Perches824f1fb2014-09-29 16:08:22 -0700165 print_tuple(s, &ct->tuplehash[IP_CT_DIR_REPLY].tuple,
166 l3proto, l4proto);
167
168 if (seq_has_overflowed(s))
Eric Dumazetea781f12009-03-25 21:05:46 +0100169 goto release;
Patrick McHardye4bd8bc2006-11-29 02:35:22 +0100170
Krzysztof Piotr Oledzki58401572008-07-21 10:01:34 -0700171 if (seq_print_acct(s, ct, IP_CT_DIR_REPLY))
Eric Dumazetea781f12009-03-25 21:05:46 +0100172 goto release;
Patrick McHardye4bd8bc2006-11-29 02:35:22 +0100173
174 if (test_bit(IPS_ASSURED_BIT, &ct->status))
Steven Rostedt (Red Hat)e71456a2014-10-27 17:43:45 -0400175 seq_printf(s, "[ASSURED] ");
Patrick McHardye4bd8bc2006-11-29 02:35:22 +0100176
177#ifdef CONFIG_NF_CONNTRACK_MARK
Steven Rostedt (Red Hat)e71456a2014-10-27 17:43:45 -0400178 seq_printf(s, "mark=%u ", ct->mark);
Patrick McHardye4bd8bc2006-11-29 02:35:22 +0100179#endif
180
Steven Rostedt (Red Hat)e71456a2014-10-27 17:43:45 -0400181 ct_show_secctx(s, ct);
182
183 seq_printf(s, "use=%u\n", atomic_read(&ct->ct_general.use));
184
185 if (seq_has_overflowed(s))
Eric Dumazetea781f12009-03-25 21:05:46 +0100186 goto release;
Patrick McHardye4bd8bc2006-11-29 02:35:22 +0100187
Eric Dumazetea781f12009-03-25 21:05:46 +0100188 ret = 0;
189release:
190 nf_ct_put(ct);
191 return ret;
Patrick McHardye4bd8bc2006-11-29 02:35:22 +0100192}
193
Philippe De Muyter56b3d972007-07-10 23:07:31 -0700194static const struct seq_operations ct_seq_ops = {
Patrick McHardye4bd8bc2006-11-29 02:35:22 +0100195 .start = ct_seq_start,
196 .next = ct_seq_next,
197 .stop = ct_seq_stop,
198 .show = ct_seq_show
199};
200
201static int ct_open(struct inode *inode, struct file *file)
202{
Alexey Dobriyan5e6b2992008-10-08 11:35:06 +0200203 return seq_open_net(inode, file, &ct_seq_ops,
204 sizeof(struct ct_iter_state));
Patrick McHardye4bd8bc2006-11-29 02:35:22 +0100205}
206
Arjan van de Ven9a321442007-02-12 00:55:35 -0800207static const struct file_operations ct_file_ops = {
Patrick McHardye4bd8bc2006-11-29 02:35:22 +0100208 .owner = THIS_MODULE,
209 .open = ct_open,
210 .read = seq_read,
211 .llseek = seq_lseek,
Alexey Dobriyan5e6b2992008-10-08 11:35:06 +0200212 .release = seq_release_net,
Patrick McHardye4bd8bc2006-11-29 02:35:22 +0100213};
214
215/* expects */
Patrick McHardy5d08ad42007-07-07 22:34:07 -0700216struct ct_expect_iter_state {
Alexey Dobriyan5e6b2992008-10-08 11:35:06 +0200217 struct seq_net_private p;
Patrick McHardy5d08ad42007-07-07 22:34:07 -0700218 unsigned int bucket;
219};
220
221static struct hlist_node *ct_expect_get_first(struct seq_file *seq)
Patrick McHardye4bd8bc2006-11-29 02:35:22 +0100222{
Alexey Dobriyan5e6b2992008-10-08 11:35:06 +0200223 struct net *net = seq_file_net(seq);
Patrick McHardy5d08ad42007-07-07 22:34:07 -0700224 struct ct_expect_iter_state *st = seq->private;
Patrick McHardy7d0742d2008-01-31 04:38:19 -0800225 struct hlist_node *n;
Patrick McHardye4bd8bc2006-11-29 02:35:22 +0100226
Patrick McHardy5d08ad42007-07-07 22:34:07 -0700227 for (st->bucket = 0; st->bucket < nf_ct_expect_hsize; st->bucket++) {
Eric Dumazeteb733162010-11-15 18:43:59 +0100228 n = rcu_dereference(
229 hlist_first_rcu(&net->ct.expect_hash[st->bucket]));
Patrick McHardy7d0742d2008-01-31 04:38:19 -0800230 if (n)
231 return n;
Patrick McHardye4bd8bc2006-11-29 02:35:22 +0100232 }
Patrick McHardy5d08ad42007-07-07 22:34:07 -0700233 return NULL;
Patrick McHardye4bd8bc2006-11-29 02:35:22 +0100234}
235
Patrick McHardy5d08ad42007-07-07 22:34:07 -0700236static struct hlist_node *ct_expect_get_next(struct seq_file *seq,
237 struct hlist_node *head)
Patrick McHardye4bd8bc2006-11-29 02:35:22 +0100238{
Alexey Dobriyan5e6b2992008-10-08 11:35:06 +0200239 struct net *net = seq_file_net(seq);
Patrick McHardy5d08ad42007-07-07 22:34:07 -0700240 struct ct_expect_iter_state *st = seq->private;
Patrick McHardye4bd8bc2006-11-29 02:35:22 +0100241
Eric Dumazeteb733162010-11-15 18:43:59 +0100242 head = rcu_dereference(hlist_next_rcu(head));
Patrick McHardy5d08ad42007-07-07 22:34:07 -0700243 while (head == NULL) {
244 if (++st->bucket >= nf_ct_expect_hsize)
245 return NULL;
Eric Dumazeteb733162010-11-15 18:43:59 +0100246 head = rcu_dereference(
247 hlist_first_rcu(&net->ct.expect_hash[st->bucket]));
Patrick McHardy5d08ad42007-07-07 22:34:07 -0700248 }
249 return head;
Patrick McHardye4bd8bc2006-11-29 02:35:22 +0100250}
251
Patrick McHardy5d08ad42007-07-07 22:34:07 -0700252static struct hlist_node *ct_expect_get_idx(struct seq_file *seq, loff_t pos)
253{
254 struct hlist_node *head = ct_expect_get_first(seq);
255
256 if (head)
257 while (pos && (head = ct_expect_get_next(seq, head)))
258 pos--;
259 return pos ? NULL : head;
260}
261
262static void *exp_seq_start(struct seq_file *seq, loff_t *pos)
Patrick McHardy76507f62008-01-31 04:38:38 -0800263 __acquires(RCU)
Patrick McHardy5d08ad42007-07-07 22:34:07 -0700264{
Patrick McHardy7d0742d2008-01-31 04:38:19 -0800265 rcu_read_lock();
Patrick McHardy5d08ad42007-07-07 22:34:07 -0700266 return ct_expect_get_idx(seq, *pos);
267}
268
269static void *exp_seq_next(struct seq_file *seq, void *v, loff_t *pos)
270{
271 (*pos)++;
272 return ct_expect_get_next(seq, v);
273}
274
275static void exp_seq_stop(struct seq_file *seq, void *v)
Patrick McHardy76507f62008-01-31 04:38:38 -0800276 __releases(RCU)
Patrick McHardye4bd8bc2006-11-29 02:35:22 +0100277{
Patrick McHardy7d0742d2008-01-31 04:38:19 -0800278 rcu_read_unlock();
Patrick McHardye4bd8bc2006-11-29 02:35:22 +0100279}
280
281static int exp_seq_show(struct seq_file *s, void *v)
282{
Patrick McHardy5d08ad42007-07-07 22:34:07 -0700283 struct nf_conntrack_expect *exp;
Jan Engelhardt32948582008-01-31 04:53:24 -0800284 const struct hlist_node *n = v;
Patrick McHardy5d08ad42007-07-07 22:34:07 -0700285
286 exp = hlist_entry(n, struct nf_conntrack_expect, hnode);
Patrick McHardye4bd8bc2006-11-29 02:35:22 +0100287
288 if (exp->tuple.src.l3num != AF_INET)
289 return 0;
290
291 if (exp->timeout.function)
292 seq_printf(s, "%ld ", timer_pending(&exp->timeout)
293 ? (long)(exp->timeout.expires - jiffies)/HZ : 0);
294 else
295 seq_printf(s, "- ");
296
297 seq_printf(s, "proto=%u ", exp->tuple.dst.protonum);
298
299 print_tuple(s, &exp->tuple,
300 __nf_ct_l3proto_find(exp->tuple.src.l3num),
301 __nf_ct_l4proto_find(exp->tuple.src.l3num,
YOSHIFUJI Hideakie905a9e2007-02-09 23:24:47 +0900302 exp->tuple.dst.protonum));
Joe Perches1ca9e412015-03-16 11:25:17 -0700303 seq_putc(s, '\n');
304
305 return 0;
Patrick McHardye4bd8bc2006-11-29 02:35:22 +0100306}
307
Philippe De Muyter56b3d972007-07-10 23:07:31 -0700308static const struct seq_operations exp_seq_ops = {
Patrick McHardye4bd8bc2006-11-29 02:35:22 +0100309 .start = exp_seq_start,
310 .next = exp_seq_next,
311 .stop = exp_seq_stop,
312 .show = exp_seq_show
313};
314
315static int exp_open(struct inode *inode, struct file *file)
316{
Alexey Dobriyan5e6b2992008-10-08 11:35:06 +0200317 return seq_open_net(inode, file, &exp_seq_ops,
318 sizeof(struct ct_expect_iter_state));
Patrick McHardye4bd8bc2006-11-29 02:35:22 +0100319}
320
Arjan van de Ven9a321442007-02-12 00:55:35 -0800321static const struct file_operations ip_exp_file_ops = {
Patrick McHardye4bd8bc2006-11-29 02:35:22 +0100322 .owner = THIS_MODULE,
323 .open = exp_open,
324 .read = seq_read,
325 .llseek = seq_lseek,
Alexey Dobriyan5e6b2992008-10-08 11:35:06 +0200326 .release = seq_release_net,
Patrick McHardye4bd8bc2006-11-29 02:35:22 +0100327};
328
329static void *ct_cpu_seq_start(struct seq_file *seq, loff_t *pos)
330{
Alexey Dobriyan8e9df802008-10-08 11:35:08 +0200331 struct net *net = seq_file_net(seq);
Patrick McHardye4bd8bc2006-11-29 02:35:22 +0100332 int cpu;
333
334 if (*pos == 0)
335 return SEQ_START_TOKEN;
336
Rusty Russell0f23174a2008-12-29 12:23:42 +0000337 for (cpu = *pos-1; cpu < nr_cpu_ids; ++cpu) {
Patrick McHardye4bd8bc2006-11-29 02:35:22 +0100338 if (!cpu_possible(cpu))
339 continue;
340 *pos = cpu+1;
Alexey Dobriyan8e9df802008-10-08 11:35:08 +0200341 return per_cpu_ptr(net->ct.stat, cpu);
Patrick McHardye4bd8bc2006-11-29 02:35:22 +0100342 }
343
344 return NULL;
345}
346
347static void *ct_cpu_seq_next(struct seq_file *seq, void *v, loff_t *pos)
348{
Alexey Dobriyan8e9df802008-10-08 11:35:08 +0200349 struct net *net = seq_file_net(seq);
Patrick McHardye4bd8bc2006-11-29 02:35:22 +0100350 int cpu;
351
Rusty Russell0f23174a2008-12-29 12:23:42 +0000352 for (cpu = *pos; cpu < nr_cpu_ids; ++cpu) {
Patrick McHardye4bd8bc2006-11-29 02:35:22 +0100353 if (!cpu_possible(cpu))
354 continue;
355 *pos = cpu+1;
Alexey Dobriyan8e9df802008-10-08 11:35:08 +0200356 return per_cpu_ptr(net->ct.stat, cpu);
Patrick McHardye4bd8bc2006-11-29 02:35:22 +0100357 }
358
359 return NULL;
360}
361
362static void ct_cpu_seq_stop(struct seq_file *seq, void *v)
363{
364}
365
366static int ct_cpu_seq_show(struct seq_file *seq, void *v)
367{
Alexey Dobriyan8e9df802008-10-08 11:35:08 +0200368 struct net *net = seq_file_net(seq);
369 unsigned int nr_conntracks = atomic_read(&net->ct.count);
Jan Engelhardt32948582008-01-31 04:53:24 -0800370 const struct ip_conntrack_stat *st = v;
Patrick McHardye4bd8bc2006-11-29 02:35:22 +0100371
372 if (v == SEQ_START_TOKEN) {
Jesper Dangaard Broueraf740b22010-04-23 12:34:56 +0200373 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 search_restart\n");
Patrick McHardye4bd8bc2006-11-29 02:35:22 +0100374 return 0;
375 }
376
377 seq_printf(seq, "%08x %08x %08x %08x %08x %08x %08x %08x "
Jesper Dangaard Broueraf740b22010-04-23 12:34:56 +0200378 "%08x %08x %08x %08x %08x %08x %08x %08x %08x\n",
Patrick McHardye4bd8bc2006-11-29 02:35:22 +0100379 nr_conntracks,
380 st->searched,
381 st->found,
382 st->new,
383 st->invalid,
384 st->ignore,
385 st->delete,
386 st->delete_list,
387 st->insert,
388 st->insert_failed,
389 st->drop,
390 st->early_drop,
391 st->error,
392
393 st->expect_new,
394 st->expect_create,
Jesper Dangaard Broueraf740b22010-04-23 12:34:56 +0200395 st->expect_delete,
396 st->search_restart
Patrick McHardye4bd8bc2006-11-29 02:35:22 +0100397 );
398 return 0;
399}
400
Philippe De Muyter56b3d972007-07-10 23:07:31 -0700401static const struct seq_operations ct_cpu_seq_ops = {
Patrick McHardye4bd8bc2006-11-29 02:35:22 +0100402 .start = ct_cpu_seq_start,
403 .next = ct_cpu_seq_next,
404 .stop = ct_cpu_seq_stop,
405 .show = ct_cpu_seq_show,
406};
407
408static int ct_cpu_seq_open(struct inode *inode, struct file *file)
409{
Alexey Dobriyan8e9df802008-10-08 11:35:08 +0200410 return seq_open_net(inode, file, &ct_cpu_seq_ops,
411 sizeof(struct seq_net_private));
Patrick McHardye4bd8bc2006-11-29 02:35:22 +0100412}
413
Arjan van de Ven9a321442007-02-12 00:55:35 -0800414static const struct file_operations ct_cpu_seq_fops = {
Patrick McHardye4bd8bc2006-11-29 02:35:22 +0100415 .owner = THIS_MODULE,
416 .open = ct_cpu_seq_open,
417 .read = seq_read,
418 .llseek = seq_lseek,
Alexey Dobriyan8e9df802008-10-08 11:35:08 +0200419 .release = seq_release_net,
Patrick McHardye4bd8bc2006-11-29 02:35:22 +0100420};
421
Alexey Dobriyan5e6b2992008-10-08 11:35:06 +0200422static int __net_init ip_conntrack_net_init(struct net *net)
Patrick McHardye4bd8bc2006-11-29 02:35:22 +0100423{
424 struct proc_dir_entry *proc, *proc_exp, *proc_stat;
425
Gao fengd4beaa62013-02-18 01:34:54 +0000426 proc = proc_create("ip_conntrack", 0440, net->proc_net, &ct_file_ops);
Patrick McHardye4bd8bc2006-11-29 02:35:22 +0100427 if (!proc)
428 goto err1;
429
Gao fengd4beaa62013-02-18 01:34:54 +0000430 proc_exp = proc_create("ip_conntrack_expect", 0440, net->proc_net,
431 &ip_exp_file_ops);
Patrick McHardye4bd8bc2006-11-29 02:35:22 +0100432 if (!proc_exp)
433 goto err2;
434
Denis V. Lunev8eeee8b2008-03-27 16:55:53 -0700435 proc_stat = proc_create("ip_conntrack", S_IRUGO,
Alexey Dobriyan5e6b2992008-10-08 11:35:06 +0200436 net->proc_net_stat, &ct_cpu_seq_fops);
Patrick McHardye4bd8bc2006-11-29 02:35:22 +0100437 if (!proc_stat)
438 goto err3;
Patrick McHardye4bd8bc2006-11-29 02:35:22 +0100439 return 0;
440
441err3:
Gao fengece31ff2013-02-18 01:34:56 +0000442 remove_proc_entry("ip_conntrack_expect", net->proc_net);
Patrick McHardye4bd8bc2006-11-29 02:35:22 +0100443err2:
Gao fengece31ff2013-02-18 01:34:56 +0000444 remove_proc_entry("ip_conntrack", net->proc_net);
Patrick McHardye4bd8bc2006-11-29 02:35:22 +0100445err1:
446 return -ENOMEM;
447}
448
Alexey Dobriyan5e6b2992008-10-08 11:35:06 +0200449static void __net_exit ip_conntrack_net_exit(struct net *net)
450{
451 remove_proc_entry("ip_conntrack", net->proc_net_stat);
Gao fengece31ff2013-02-18 01:34:56 +0000452 remove_proc_entry("ip_conntrack_expect", net->proc_net);
453 remove_proc_entry("ip_conntrack", net->proc_net);
Alexey Dobriyan5e6b2992008-10-08 11:35:06 +0200454}
455
456static struct pernet_operations ip_conntrack_net_ops = {
457 .init = ip_conntrack_net_init,
458 .exit = ip_conntrack_net_exit,
459};
460
461int __init nf_conntrack_ipv4_compat_init(void)
462{
463 return register_pernet_subsys(&ip_conntrack_net_ops);
464}
465
Patrick McHardye4bd8bc2006-11-29 02:35:22 +0100466void __exit nf_conntrack_ipv4_compat_fini(void)
467{
Alexey Dobriyan5e6b2992008-10-08 11:35:06 +0200468 unregister_pernet_subsys(&ip_conntrack_net_ops);
Patrick McHardye4bd8bc2006-11-29 02:35:22 +0100469}