blob: c4cd3226a053edfc174daf93daa1007a9ad718bb [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * X.25 Packet Layer release 002
3 *
4 * This is ALPHA test software. This code may break your machine,
5 * randomly fail to work with new releases, misbehave and/or generally
YOSHIFUJI Hideakif8e1d2012007-02-09 23:25:27 +09006 * screw up. It might even work.
Linus Torvalds1da177e2005-04-16 15:20:36 -07007 *
8 * This code REQUIRES 2.4 with seq_file support
9 *
10 * This module:
11 * This module is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU General Public License
13 * as published by the Free Software Foundation; either version
14 * 2 of the License, or (at your option) any later version.
15 *
16 * History
17 * 2002/10/06 Arnaldo Carvalho de Melo seq_file support
18 */
19
Linus Torvalds1da177e2005-04-16 15:20:36 -070020#include <linux/init.h>
21#include <linux/proc_fs.h>
22#include <linux/seq_file.h>
Eric W. Biederman457c4cb2007-09-12 12:01:34 +020023#include <net/net_namespace.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070024#include <net/sock.h>
25#include <net/x25.h>
26
27#ifdef CONFIG_PROC_FS
28static __inline__ struct x25_route *x25_get_route_idx(loff_t pos)
29{
30 struct list_head *route_entry;
31 struct x25_route *rt = NULL;
32
33 list_for_each(route_entry, &x25_route_list) {
34 rt = list_entry(route_entry, struct x25_route, node);
35 if (!pos--)
36 goto found;
37 }
38 rt = NULL;
39found:
40 return rt;
41}
42
43static void *x25_seq_route_start(struct seq_file *seq, loff_t *pos)
Eric Dumazet6bf15742008-01-13 22:27:52 -080044 __acquires(x25_route_list_lock)
Linus Torvalds1da177e2005-04-16 15:20:36 -070045{
46 loff_t l = *pos;
47
48 read_lock_bh(&x25_route_list_lock);
49 return l ? x25_get_route_idx(--l) : SEQ_START_TOKEN;
50}
51
52static void *x25_seq_route_next(struct seq_file *seq, void *v, loff_t *pos)
53{
54 struct x25_route *rt;
55
56 ++*pos;
57 if (v == SEQ_START_TOKEN) {
58 rt = NULL;
59 if (!list_empty(&x25_route_list))
60 rt = list_entry(x25_route_list.next,
61 struct x25_route, node);
62 goto out;
63 }
64 rt = v;
65 if (rt->node.next != &x25_route_list)
66 rt = list_entry(rt->node.next, struct x25_route, node);
YOSHIFUJI Hideakif8e1d2012007-02-09 23:25:27 +090067 else
Linus Torvalds1da177e2005-04-16 15:20:36 -070068 rt = NULL;
69out:
70 return rt;
71}
72
73static void x25_seq_route_stop(struct seq_file *seq, void *v)
Eric Dumazet6bf15742008-01-13 22:27:52 -080074 __releases(x25_route_list_lock)
Linus Torvalds1da177e2005-04-16 15:20:36 -070075{
76 read_unlock_bh(&x25_route_list_lock);
77}
78
79static int x25_seq_route_show(struct seq_file *seq, void *v)
80{
81 struct x25_route *rt;
82
83 if (v == SEQ_START_TOKEN) {
84 seq_puts(seq, "Address Digits Device\n");
85 goto out;
86 }
87
88 rt = v;
89 seq_printf(seq, "%-15s %-6d %-5s\n",
90 rt->address.x25_addr, rt->sigdigits,
91 rt->dev ? rt->dev->name : "???");
92out:
93 return 0;
YOSHIFUJI Hideakif8e1d2012007-02-09 23:25:27 +090094}
Linus Torvalds1da177e2005-04-16 15:20:36 -070095
Linus Torvalds1da177e2005-04-16 15:20:36 -070096static void *x25_seq_socket_start(struct seq_file *seq, loff_t *pos)
Eric Dumazet6bf15742008-01-13 22:27:52 -080097 __acquires(x25_list_lock)
Linus Torvalds1da177e2005-04-16 15:20:36 -070098{
Linus Torvalds1da177e2005-04-16 15:20:36 -070099 read_lock_bh(&x25_list_lock);
Li Zefan32d2e3a2010-02-08 23:19:04 +0000100 return seq_hlist_start_head(&x25_list, *pos);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700101}
102
103static void *x25_seq_socket_next(struct seq_file *seq, void *v, loff_t *pos)
104{
Li Zefan32d2e3a2010-02-08 23:19:04 +0000105 return seq_hlist_next(v, &x25_list, pos);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700106}
107
108static void x25_seq_socket_stop(struct seq_file *seq, void *v)
Eric Dumazet6bf15742008-01-13 22:27:52 -0800109 __releases(x25_list_lock)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700110{
111 read_unlock_bh(&x25_list_lock);
112}
113
114static int x25_seq_socket_show(struct seq_file *seq, void *v)
115{
116 struct sock *s;
117 struct x25_sock *x25;
118 struct net_device *dev;
119 const char *devname;
120
121 if (v == SEQ_START_TOKEN) {
122 seq_printf(seq, "dest_addr src_addr dev lci st vs vr "
123 "va t t2 t21 t22 t23 Snd-Q Rcv-Q inode\n");
124 goto out;
125 }
126
Li Zefan32d2e3a2010-02-08 23:19:04 +0000127 s = sk_entry(v);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700128 x25 = x25_sk(s);
129
130 if (!x25->neighbour || (dev = x25->neighbour->dev) == NULL)
131 devname = "???";
132 else
133 devname = x25->neighbour->dev->name;
134
135 seq_printf(seq, "%-10s %-10s %-5s %3.3X %d %d %d %d %3lu %3lu "
136 "%3lu %3lu %3lu %5d %5d %ld\n",
137 !x25->dest_addr.x25_addr[0] ? "*" : x25->dest_addr.x25_addr,
138 !x25->source_addr.x25_addr[0] ? "*" : x25->source_addr.x25_addr,
139 devname, x25->lci & 0x0FFF, x25->state, x25->vs, x25->vr,
140 x25->va, x25_display_timer(s) / HZ, x25->t2 / HZ,
141 x25->t21 / HZ, x25->t22 / HZ, x25->t23 / HZ,
Eric Dumazet31e6d362009-06-17 19:05:41 -0700142 sk_wmem_alloc_get(s),
143 sk_rmem_alloc_get(s),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700144 s->sk_socket ? SOCK_INODE(s->sk_socket)->i_ino : 0L);
145out:
146 return 0;
YOSHIFUJI Hideakif8e1d2012007-02-09 23:25:27 +0900147}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700148
Andrew Hendryc9c2e9d2007-02-08 13:35:18 -0800149static __inline__ struct x25_forward *x25_get_forward_idx(loff_t pos)
150{
151 struct x25_forward *f;
152 struct list_head *entry;
153
154 list_for_each(entry, &x25_forward_list) {
155 f = list_entry(entry, struct x25_forward, node);
156 if (!pos--)
157 goto found;
158 }
159
160 f = NULL;
161found:
162 return f;
163}
164
165static void *x25_seq_forward_start(struct seq_file *seq, loff_t *pos)
Eric Dumazet6bf15742008-01-13 22:27:52 -0800166 __acquires(x25_forward_list_lock)
Andrew Hendryc9c2e9d2007-02-08 13:35:18 -0800167{
168 loff_t l = *pos;
169
170 read_lock_bh(&x25_forward_list_lock);
171 return l ? x25_get_forward_idx(--l) : SEQ_START_TOKEN;
172}
173
174static void *x25_seq_forward_next(struct seq_file *seq, void *v, loff_t *pos)
175{
176 struct x25_forward *f;
177
178 ++*pos;
179 if (v == SEQ_START_TOKEN) {
180 f = NULL;
181 if (!list_empty(&x25_forward_list))
182 f = list_entry(x25_forward_list.next,
183 struct x25_forward, node);
184 goto out;
185 }
186 f = v;
187 if (f->node.next != &x25_forward_list)
188 f = list_entry(f->node.next, struct x25_forward, node);
189 else
190 f = NULL;
191out:
192 return f;
193
194}
195
196static void x25_seq_forward_stop(struct seq_file *seq, void *v)
Eric Dumazet6bf15742008-01-13 22:27:52 -0800197 __releases(x25_forward_list_lock)
Andrew Hendryc9c2e9d2007-02-08 13:35:18 -0800198{
199 read_unlock_bh(&x25_forward_list_lock);
200}
201
202static int x25_seq_forward_show(struct seq_file *seq, void *v)
203{
204 struct x25_forward *f;
205
206 if (v == SEQ_START_TOKEN) {
207 seq_printf(seq, "lci dev1 dev2\n");
208 goto out;
209 }
210
211 f = v;
212
213 seq_printf(seq, "%d %-10s %-10s\n",
214 f->lci, f->dev1->name, f->dev2->name);
215
216out:
217 return 0;
218}
219
Philippe De Muyter56b3d972007-07-10 23:07:31 -0700220static const struct seq_operations x25_seq_route_ops = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700221 .start = x25_seq_route_start,
222 .next = x25_seq_route_next,
223 .stop = x25_seq_route_stop,
224 .show = x25_seq_route_show,
225};
226
Philippe De Muyter56b3d972007-07-10 23:07:31 -0700227static const struct seq_operations x25_seq_socket_ops = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700228 .start = x25_seq_socket_start,
229 .next = x25_seq_socket_next,
230 .stop = x25_seq_socket_stop,
231 .show = x25_seq_socket_show,
232};
233
Philippe De Muyter56b3d972007-07-10 23:07:31 -0700234static const struct seq_operations x25_seq_forward_ops = {
Andrew Hendryc9c2e9d2007-02-08 13:35:18 -0800235 .start = x25_seq_forward_start,
236 .next = x25_seq_forward_next,
237 .stop = x25_seq_forward_stop,
238 .show = x25_seq_forward_show,
239};
240
Linus Torvalds1da177e2005-04-16 15:20:36 -0700241static int x25_seq_socket_open(struct inode *inode, struct file *file)
242{
243 return seq_open(file, &x25_seq_socket_ops);
244}
245
246static int x25_seq_route_open(struct inode *inode, struct file *file)
247{
248 return seq_open(file, &x25_seq_route_ops);
249}
250
Andrew Hendryc9c2e9d2007-02-08 13:35:18 -0800251static int x25_seq_forward_open(struct inode *inode, struct file *file)
252{
253 return seq_open(file, &x25_seq_forward_ops);
254}
255
Arjan van de Venda7071d2007-02-12 00:55:36 -0800256static const struct file_operations x25_seq_socket_fops = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700257 .owner = THIS_MODULE,
258 .open = x25_seq_socket_open,
259 .read = seq_read,
260 .llseek = seq_lseek,
261 .release = seq_release,
262};
263
Arjan van de Venda7071d2007-02-12 00:55:36 -0800264static const struct file_operations x25_seq_route_fops = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700265 .owner = THIS_MODULE,
266 .open = x25_seq_route_open,
267 .read = seq_read,
268 .llseek = seq_lseek,
269 .release = seq_release,
270};
271
Jan Engelhardta1f6f5a2008-01-22 18:30:06 -0800272static const struct file_operations x25_seq_forward_fops = {
Andrew Hendryc9c2e9d2007-02-08 13:35:18 -0800273 .owner = THIS_MODULE,
274 .open = x25_seq_forward_open,
275 .read = seq_read,
276 .llseek = seq_lseek,
277 .release = seq_release,
278};
279
Linus Torvalds1da177e2005-04-16 15:20:36 -0700280static struct proc_dir_entry *x25_proc_dir;
281
282int __init x25_proc_init(void)
283{
284 struct proc_dir_entry *p;
285 int rc = -ENOMEM;
286
Eric W. Biederman457c4cb2007-09-12 12:01:34 +0200287 x25_proc_dir = proc_mkdir("x25", init_net.proc_net);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700288 if (!x25_proc_dir)
289 goto out;
290
Wang Chen2335f8e2008-02-28 14:16:33 -0800291 p = proc_create("route", S_IRUGO, x25_proc_dir, &x25_seq_route_fops);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700292 if (!p)
293 goto out_route;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700294
Wang Chen2335f8e2008-02-28 14:16:33 -0800295 p = proc_create("socket", S_IRUGO, x25_proc_dir, &x25_seq_socket_fops);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700296 if (!p)
297 goto out_socket;
Andrew Hendryc9c2e9d2007-02-08 13:35:18 -0800298
Wang Chen2335f8e2008-02-28 14:16:33 -0800299 p = proc_create("forward", S_IRUGO, x25_proc_dir,
300 &x25_seq_forward_fops);
Andrew Hendryc9c2e9d2007-02-08 13:35:18 -0800301 if (!p)
302 goto out_forward;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700303 rc = 0;
Andrew Hendryc9c2e9d2007-02-08 13:35:18 -0800304
Linus Torvalds1da177e2005-04-16 15:20:36 -0700305out:
306 return rc;
Andrew Hendryc9c2e9d2007-02-08 13:35:18 -0800307out_forward:
308 remove_proc_entry("socket", x25_proc_dir);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700309out_socket:
310 remove_proc_entry("route", x25_proc_dir);
311out_route:
Eric W. Biederman457c4cb2007-09-12 12:01:34 +0200312 remove_proc_entry("x25", init_net.proc_net);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700313 goto out;
314}
315
316void __exit x25_proc_exit(void)
317{
Andrew Hendryc9c2e9d2007-02-08 13:35:18 -0800318 remove_proc_entry("forward", x25_proc_dir);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700319 remove_proc_entry("route", x25_proc_dir);
320 remove_proc_entry("socket", x25_proc_dir);
Eric W. Biederman457c4cb2007-09-12 12:01:34 +0200321 remove_proc_entry("x25", init_net.proc_net);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700322}
323
324#else /* CONFIG_PROC_FS */
325
326int __init x25_proc_init(void)
327{
328 return 0;
329}
330
331void __exit x25_proc_exit(void)
332{
333}
334#endif /* CONFIG_PROC_FS */