blob: 7d55e50c936f9a2fe11daeba85ece6099815b858 [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)
44{
45 loff_t l = *pos;
46
47 read_lock_bh(&x25_route_list_lock);
48 return l ? x25_get_route_idx(--l) : SEQ_START_TOKEN;
49}
50
51static void *x25_seq_route_next(struct seq_file *seq, void *v, loff_t *pos)
52{
53 struct x25_route *rt;
54
55 ++*pos;
56 if (v == SEQ_START_TOKEN) {
57 rt = NULL;
58 if (!list_empty(&x25_route_list))
59 rt = list_entry(x25_route_list.next,
60 struct x25_route, node);
61 goto out;
62 }
63 rt = v;
64 if (rt->node.next != &x25_route_list)
65 rt = list_entry(rt->node.next, struct x25_route, node);
YOSHIFUJI Hideakif8e1d2012007-02-09 23:25:27 +090066 else
Linus Torvalds1da177e2005-04-16 15:20:36 -070067 rt = NULL;
68out:
69 return rt;
70}
71
72static void x25_seq_route_stop(struct seq_file *seq, void *v)
73{
74 read_unlock_bh(&x25_route_list_lock);
75}
76
77static int x25_seq_route_show(struct seq_file *seq, void *v)
78{
79 struct x25_route *rt;
80
81 if (v == SEQ_START_TOKEN) {
82 seq_puts(seq, "Address Digits Device\n");
83 goto out;
84 }
85
86 rt = v;
87 seq_printf(seq, "%-15s %-6d %-5s\n",
88 rt->address.x25_addr, rt->sigdigits,
89 rt->dev ? rt->dev->name : "???");
90out:
91 return 0;
YOSHIFUJI Hideakif8e1d2012007-02-09 23:25:27 +090092}
Linus Torvalds1da177e2005-04-16 15:20:36 -070093
94static __inline__ struct sock *x25_get_socket_idx(loff_t pos)
95{
96 struct sock *s;
97 struct hlist_node *node;
98
99 sk_for_each(s, node, &x25_list)
100 if (!pos--)
101 goto found;
102 s = NULL;
103found:
104 return s;
105}
106
107static void *x25_seq_socket_start(struct seq_file *seq, loff_t *pos)
108{
109 loff_t l = *pos;
110
111 read_lock_bh(&x25_list_lock);
112 return l ? x25_get_socket_idx(--l) : SEQ_START_TOKEN;
113}
114
115static void *x25_seq_socket_next(struct seq_file *seq, void *v, loff_t *pos)
116{
117 struct sock *s;
118
119 ++*pos;
120 if (v == SEQ_START_TOKEN) {
121 s = sk_head(&x25_list);
122 goto out;
123 }
124 s = sk_next(v);
125out:
126 return s;
127}
128
129static void x25_seq_socket_stop(struct seq_file *seq, void *v)
130{
131 read_unlock_bh(&x25_list_lock);
132}
133
134static int x25_seq_socket_show(struct seq_file *seq, void *v)
135{
136 struct sock *s;
137 struct x25_sock *x25;
138 struct net_device *dev;
139 const char *devname;
140
141 if (v == SEQ_START_TOKEN) {
142 seq_printf(seq, "dest_addr src_addr dev lci st vs vr "
143 "va t t2 t21 t22 t23 Snd-Q Rcv-Q inode\n");
144 goto out;
145 }
146
147 s = v;
148 x25 = x25_sk(s);
149
150 if (!x25->neighbour || (dev = x25->neighbour->dev) == NULL)
151 devname = "???";
152 else
153 devname = x25->neighbour->dev->name;
154
155 seq_printf(seq, "%-10s %-10s %-5s %3.3X %d %d %d %d %3lu %3lu "
156 "%3lu %3lu %3lu %5d %5d %ld\n",
157 !x25->dest_addr.x25_addr[0] ? "*" : x25->dest_addr.x25_addr,
158 !x25->source_addr.x25_addr[0] ? "*" : x25->source_addr.x25_addr,
159 devname, x25->lci & 0x0FFF, x25->state, x25->vs, x25->vr,
160 x25->va, x25_display_timer(s) / HZ, x25->t2 / HZ,
161 x25->t21 / HZ, x25->t22 / HZ, x25->t23 / HZ,
162 atomic_read(&s->sk_wmem_alloc),
163 atomic_read(&s->sk_rmem_alloc),
164 s->sk_socket ? SOCK_INODE(s->sk_socket)->i_ino : 0L);
165out:
166 return 0;
YOSHIFUJI Hideakif8e1d2012007-02-09 23:25:27 +0900167}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700168
Andrew Hendryc9c2e9d2007-02-08 13:35:18 -0800169static __inline__ struct x25_forward *x25_get_forward_idx(loff_t pos)
170{
171 struct x25_forward *f;
172 struct list_head *entry;
173
174 list_for_each(entry, &x25_forward_list) {
175 f = list_entry(entry, struct x25_forward, node);
176 if (!pos--)
177 goto found;
178 }
179
180 f = NULL;
181found:
182 return f;
183}
184
185static void *x25_seq_forward_start(struct seq_file *seq, loff_t *pos)
186{
187 loff_t l = *pos;
188
189 read_lock_bh(&x25_forward_list_lock);
190 return l ? x25_get_forward_idx(--l) : SEQ_START_TOKEN;
191}
192
193static void *x25_seq_forward_next(struct seq_file *seq, void *v, loff_t *pos)
194{
195 struct x25_forward *f;
196
197 ++*pos;
198 if (v == SEQ_START_TOKEN) {
199 f = NULL;
200 if (!list_empty(&x25_forward_list))
201 f = list_entry(x25_forward_list.next,
202 struct x25_forward, node);
203 goto out;
204 }
205 f = v;
206 if (f->node.next != &x25_forward_list)
207 f = list_entry(f->node.next, struct x25_forward, node);
208 else
209 f = NULL;
210out:
211 return f;
212
213}
214
215static void x25_seq_forward_stop(struct seq_file *seq, void *v)
216{
217 read_unlock_bh(&x25_forward_list_lock);
218}
219
220static int x25_seq_forward_show(struct seq_file *seq, void *v)
221{
222 struct x25_forward *f;
223
224 if (v == SEQ_START_TOKEN) {
225 seq_printf(seq, "lci dev1 dev2\n");
226 goto out;
227 }
228
229 f = v;
230
231 seq_printf(seq, "%d %-10s %-10s\n",
232 f->lci, f->dev1->name, f->dev2->name);
233
234out:
235 return 0;
236}
237
Philippe De Muyter56b3d972007-07-10 23:07:31 -0700238static const struct seq_operations x25_seq_route_ops = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700239 .start = x25_seq_route_start,
240 .next = x25_seq_route_next,
241 .stop = x25_seq_route_stop,
242 .show = x25_seq_route_show,
243};
244
Philippe De Muyter56b3d972007-07-10 23:07:31 -0700245static const struct seq_operations x25_seq_socket_ops = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700246 .start = x25_seq_socket_start,
247 .next = x25_seq_socket_next,
248 .stop = x25_seq_socket_stop,
249 .show = x25_seq_socket_show,
250};
251
Philippe De Muyter56b3d972007-07-10 23:07:31 -0700252static const struct seq_operations x25_seq_forward_ops = {
Andrew Hendryc9c2e9d2007-02-08 13:35:18 -0800253 .start = x25_seq_forward_start,
254 .next = x25_seq_forward_next,
255 .stop = x25_seq_forward_stop,
256 .show = x25_seq_forward_show,
257};
258
Linus Torvalds1da177e2005-04-16 15:20:36 -0700259static int x25_seq_socket_open(struct inode *inode, struct file *file)
260{
261 return seq_open(file, &x25_seq_socket_ops);
262}
263
264static int x25_seq_route_open(struct inode *inode, struct file *file)
265{
266 return seq_open(file, &x25_seq_route_ops);
267}
268
Andrew Hendryc9c2e9d2007-02-08 13:35:18 -0800269static int x25_seq_forward_open(struct inode *inode, struct file *file)
270{
271 return seq_open(file, &x25_seq_forward_ops);
272}
273
Arjan van de Venda7071d2007-02-12 00:55:36 -0800274static const struct file_operations x25_seq_socket_fops = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700275 .owner = THIS_MODULE,
276 .open = x25_seq_socket_open,
277 .read = seq_read,
278 .llseek = seq_lseek,
279 .release = seq_release,
280};
281
Arjan van de Venda7071d2007-02-12 00:55:36 -0800282static const struct file_operations x25_seq_route_fops = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700283 .owner = THIS_MODULE,
284 .open = x25_seq_route_open,
285 .read = seq_read,
286 .llseek = seq_lseek,
287 .release = seq_release,
288};
289
Andrew Hendryc9c2e9d2007-02-08 13:35:18 -0800290static struct file_operations x25_seq_forward_fops = {
291 .owner = THIS_MODULE,
292 .open = x25_seq_forward_open,
293 .read = seq_read,
294 .llseek = seq_lseek,
295 .release = seq_release,
296};
297
Linus Torvalds1da177e2005-04-16 15:20:36 -0700298static struct proc_dir_entry *x25_proc_dir;
299
300int __init x25_proc_init(void)
301{
302 struct proc_dir_entry *p;
303 int rc = -ENOMEM;
304
Eric W. Biederman457c4cb2007-09-12 12:01:34 +0200305 x25_proc_dir = proc_mkdir("x25", init_net.proc_net);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700306 if (!x25_proc_dir)
307 goto out;
308
309 p = create_proc_entry("route", S_IRUGO, x25_proc_dir);
310 if (!p)
311 goto out_route;
312 p->proc_fops = &x25_seq_route_fops;
313
314 p = create_proc_entry("socket", S_IRUGO, x25_proc_dir);
315 if (!p)
316 goto out_socket;
317 p->proc_fops = &x25_seq_socket_fops;
Andrew Hendryc9c2e9d2007-02-08 13:35:18 -0800318
319 p = create_proc_entry("forward", S_IRUGO, x25_proc_dir);
320 if (!p)
321 goto out_forward;
322 p->proc_fops = &x25_seq_forward_fops;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700323 rc = 0;
Andrew Hendryc9c2e9d2007-02-08 13:35:18 -0800324
Linus Torvalds1da177e2005-04-16 15:20:36 -0700325out:
326 return rc;
Andrew Hendryc9c2e9d2007-02-08 13:35:18 -0800327out_forward:
328 remove_proc_entry("socket", x25_proc_dir);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700329out_socket:
330 remove_proc_entry("route", x25_proc_dir);
331out_route:
Eric W. Biederman457c4cb2007-09-12 12:01:34 +0200332 remove_proc_entry("x25", init_net.proc_net);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700333 goto out;
334}
335
336void __exit x25_proc_exit(void)
337{
Andrew Hendryc9c2e9d2007-02-08 13:35:18 -0800338 remove_proc_entry("forward", x25_proc_dir);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700339 remove_proc_entry("route", x25_proc_dir);
340 remove_proc_entry("socket", x25_proc_dir);
Eric W. Biederman457c4cb2007-09-12 12:01:34 +0200341 remove_proc_entry("x25", init_net.proc_net);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700342}
343
344#else /* CONFIG_PROC_FS */
345
346int __init x25_proc_init(void)
347{
348 return 0;
349}
350
351void __exit x25_proc_exit(void)
352{
353}
354#endif /* CONFIG_PROC_FS */