blob: 7ff373792324f69b0937a5e3ce5f9fb273771f63 [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
Linus Torvalds1da177e2005-04-16 15:20:36 -070028
29static void *x25_seq_route_start(struct seq_file *seq, loff_t *pos)
Eric Dumazet6bf15742008-01-13 22:27:52 -080030 __acquires(x25_route_list_lock)
Linus Torvalds1da177e2005-04-16 15:20:36 -070031{
Linus Torvalds1da177e2005-04-16 15:20:36 -070032 read_lock_bh(&x25_route_list_lock);
Li Zefan4f134202010-02-08 23:20:42 +000033 return seq_list_start_head(&x25_route_list, *pos);
Linus Torvalds1da177e2005-04-16 15:20:36 -070034}
35
36static void *x25_seq_route_next(struct seq_file *seq, void *v, loff_t *pos)
37{
Li Zefan4f134202010-02-08 23:20:42 +000038 return seq_list_next(v, &x25_route_list, pos);
Linus Torvalds1da177e2005-04-16 15:20:36 -070039}
40
41static void x25_seq_route_stop(struct seq_file *seq, void *v)
Eric Dumazet6bf15742008-01-13 22:27:52 -080042 __releases(x25_route_list_lock)
Linus Torvalds1da177e2005-04-16 15:20:36 -070043{
44 read_unlock_bh(&x25_route_list_lock);
45}
46
47static int x25_seq_route_show(struct seq_file *seq, void *v)
48{
Li Zefan4f134202010-02-08 23:20:42 +000049 struct x25_route *rt = list_entry(v, struct x25_route, node);
Linus Torvalds1da177e2005-04-16 15:20:36 -070050
Li Zefan4f134202010-02-08 23:20:42 +000051 if (v == &x25_route_list) {
Linus Torvalds1da177e2005-04-16 15:20:36 -070052 seq_puts(seq, "Address Digits Device\n");
53 goto out;
54 }
55
56 rt = v;
57 seq_printf(seq, "%-15s %-6d %-5s\n",
58 rt->address.x25_addr, rt->sigdigits,
59 rt->dev ? rt->dev->name : "???");
60out:
61 return 0;
YOSHIFUJI Hideakif8e1d2012007-02-09 23:25:27 +090062}
Linus Torvalds1da177e2005-04-16 15:20:36 -070063
Linus Torvalds1da177e2005-04-16 15:20:36 -070064static void *x25_seq_socket_start(struct seq_file *seq, loff_t *pos)
Eric Dumazet6bf15742008-01-13 22:27:52 -080065 __acquires(x25_list_lock)
Linus Torvalds1da177e2005-04-16 15:20:36 -070066{
Linus Torvalds1da177e2005-04-16 15:20:36 -070067 read_lock_bh(&x25_list_lock);
Li Zefan32d2e3a2010-02-08 23:19:04 +000068 return seq_hlist_start_head(&x25_list, *pos);
Linus Torvalds1da177e2005-04-16 15:20:36 -070069}
70
71static void *x25_seq_socket_next(struct seq_file *seq, void *v, loff_t *pos)
72{
Li Zefan32d2e3a2010-02-08 23:19:04 +000073 return seq_hlist_next(v, &x25_list, pos);
Linus Torvalds1da177e2005-04-16 15:20:36 -070074}
75
76static void x25_seq_socket_stop(struct seq_file *seq, void *v)
Eric Dumazet6bf15742008-01-13 22:27:52 -080077 __releases(x25_list_lock)
Linus Torvalds1da177e2005-04-16 15:20:36 -070078{
79 read_unlock_bh(&x25_list_lock);
80}
81
82static int x25_seq_socket_show(struct seq_file *seq, void *v)
83{
84 struct sock *s;
85 struct x25_sock *x25;
86 struct net_device *dev;
87 const char *devname;
88
89 if (v == SEQ_START_TOKEN) {
90 seq_printf(seq, "dest_addr src_addr dev lci st vs vr "
91 "va t t2 t21 t22 t23 Snd-Q Rcv-Q inode\n");
92 goto out;
93 }
94
Li Zefan32d2e3a2010-02-08 23:19:04 +000095 s = sk_entry(v);
Linus Torvalds1da177e2005-04-16 15:20:36 -070096 x25 = x25_sk(s);
97
98 if (!x25->neighbour || (dev = x25->neighbour->dev) == NULL)
99 devname = "???";
100 else
101 devname = x25->neighbour->dev->name;
102
103 seq_printf(seq, "%-10s %-10s %-5s %3.3X %d %d %d %d %3lu %3lu "
104 "%3lu %3lu %3lu %5d %5d %ld\n",
105 !x25->dest_addr.x25_addr[0] ? "*" : x25->dest_addr.x25_addr,
106 !x25->source_addr.x25_addr[0] ? "*" : x25->source_addr.x25_addr,
107 devname, x25->lci & 0x0FFF, x25->state, x25->vs, x25->vr,
108 x25->va, x25_display_timer(s) / HZ, x25->t2 / HZ,
109 x25->t21 / HZ, x25->t22 / HZ, x25->t23 / HZ,
Eric Dumazet31e6d362009-06-17 19:05:41 -0700110 sk_wmem_alloc_get(s),
111 sk_rmem_alloc_get(s),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700112 s->sk_socket ? SOCK_INODE(s->sk_socket)->i_ino : 0L);
113out:
114 return 0;
YOSHIFUJI Hideakif8e1d2012007-02-09 23:25:27 +0900115}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700116
Andrew Hendryc9c2e9d2007-02-08 13:35:18 -0800117static void *x25_seq_forward_start(struct seq_file *seq, loff_t *pos)
Eric Dumazet6bf15742008-01-13 22:27:52 -0800118 __acquires(x25_forward_list_lock)
Andrew Hendryc9c2e9d2007-02-08 13:35:18 -0800119{
Andrew Hendryc9c2e9d2007-02-08 13:35:18 -0800120 read_lock_bh(&x25_forward_list_lock);
Li Zefan4f134202010-02-08 23:20:42 +0000121 return seq_list_start_head(&x25_forward_list, *pos);
Andrew Hendryc9c2e9d2007-02-08 13:35:18 -0800122}
123
124static void *x25_seq_forward_next(struct seq_file *seq, void *v, loff_t *pos)
125{
Li Zefan4f134202010-02-08 23:20:42 +0000126 return seq_list_next(v, &x25_forward_list, pos);
Andrew Hendryc9c2e9d2007-02-08 13:35:18 -0800127}
128
129static void x25_seq_forward_stop(struct seq_file *seq, void *v)
Eric Dumazet6bf15742008-01-13 22:27:52 -0800130 __releases(x25_forward_list_lock)
Andrew Hendryc9c2e9d2007-02-08 13:35:18 -0800131{
132 read_unlock_bh(&x25_forward_list_lock);
133}
134
135static int x25_seq_forward_show(struct seq_file *seq, void *v)
136{
Li Zefan4f134202010-02-08 23:20:42 +0000137 struct x25_forward *f = list_entry(v, struct x25_forward, node);
Andrew Hendryc9c2e9d2007-02-08 13:35:18 -0800138
Li Zefan4f134202010-02-08 23:20:42 +0000139 if (v == &x25_forward_list) {
Andrew Hendryc9c2e9d2007-02-08 13:35:18 -0800140 seq_printf(seq, "lci dev1 dev2\n");
141 goto out;
142 }
143
144 f = v;
145
146 seq_printf(seq, "%d %-10s %-10s\n",
147 f->lci, f->dev1->name, f->dev2->name);
Andrew Hendryc9c2e9d2007-02-08 13:35:18 -0800148out:
149 return 0;
150}
151
Philippe De Muyter56b3d972007-07-10 23:07:31 -0700152static const struct seq_operations x25_seq_route_ops = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700153 .start = x25_seq_route_start,
154 .next = x25_seq_route_next,
155 .stop = x25_seq_route_stop,
156 .show = x25_seq_route_show,
157};
158
Philippe De Muyter56b3d972007-07-10 23:07:31 -0700159static const struct seq_operations x25_seq_socket_ops = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700160 .start = x25_seq_socket_start,
161 .next = x25_seq_socket_next,
162 .stop = x25_seq_socket_stop,
163 .show = x25_seq_socket_show,
164};
165
Philippe De Muyter56b3d972007-07-10 23:07:31 -0700166static const struct seq_operations x25_seq_forward_ops = {
Andrew Hendryc9c2e9d2007-02-08 13:35:18 -0800167 .start = x25_seq_forward_start,
168 .next = x25_seq_forward_next,
169 .stop = x25_seq_forward_stop,
170 .show = x25_seq_forward_show,
171};
172
Linus Torvalds1da177e2005-04-16 15:20:36 -0700173static int x25_seq_socket_open(struct inode *inode, struct file *file)
174{
175 return seq_open(file, &x25_seq_socket_ops);
176}
177
178static int x25_seq_route_open(struct inode *inode, struct file *file)
179{
180 return seq_open(file, &x25_seq_route_ops);
181}
182
Andrew Hendryc9c2e9d2007-02-08 13:35:18 -0800183static int x25_seq_forward_open(struct inode *inode, struct file *file)
184{
185 return seq_open(file, &x25_seq_forward_ops);
186}
187
Arjan van de Venda7071d2007-02-12 00:55:36 -0800188static const struct file_operations x25_seq_socket_fops = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700189 .owner = THIS_MODULE,
190 .open = x25_seq_socket_open,
191 .read = seq_read,
192 .llseek = seq_lseek,
193 .release = seq_release,
194};
195
Arjan van de Venda7071d2007-02-12 00:55:36 -0800196static const struct file_operations x25_seq_route_fops = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700197 .owner = THIS_MODULE,
198 .open = x25_seq_route_open,
199 .read = seq_read,
200 .llseek = seq_lseek,
201 .release = seq_release,
202};
203
Jan Engelhardta1f6f5a2008-01-22 18:30:06 -0800204static const struct file_operations x25_seq_forward_fops = {
Andrew Hendryc9c2e9d2007-02-08 13:35:18 -0800205 .owner = THIS_MODULE,
206 .open = x25_seq_forward_open,
207 .read = seq_read,
208 .llseek = seq_lseek,
209 .release = seq_release,
210};
211
Linus Torvalds1da177e2005-04-16 15:20:36 -0700212static struct proc_dir_entry *x25_proc_dir;
213
214int __init x25_proc_init(void)
215{
216 struct proc_dir_entry *p;
217 int rc = -ENOMEM;
218
Eric W. Biederman457c4cb2007-09-12 12:01:34 +0200219 x25_proc_dir = proc_mkdir("x25", init_net.proc_net);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700220 if (!x25_proc_dir)
221 goto out;
222
Wang Chen2335f8e2008-02-28 14:16:33 -0800223 p = proc_create("route", S_IRUGO, x25_proc_dir, &x25_seq_route_fops);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700224 if (!p)
225 goto out_route;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700226
Wang Chen2335f8e2008-02-28 14:16:33 -0800227 p = proc_create("socket", S_IRUGO, x25_proc_dir, &x25_seq_socket_fops);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700228 if (!p)
229 goto out_socket;
Andrew Hendryc9c2e9d2007-02-08 13:35:18 -0800230
Wang Chen2335f8e2008-02-28 14:16:33 -0800231 p = proc_create("forward", S_IRUGO, x25_proc_dir,
232 &x25_seq_forward_fops);
Andrew Hendryc9c2e9d2007-02-08 13:35:18 -0800233 if (!p)
234 goto out_forward;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700235 rc = 0;
Andrew Hendryc9c2e9d2007-02-08 13:35:18 -0800236
Linus Torvalds1da177e2005-04-16 15:20:36 -0700237out:
238 return rc;
Andrew Hendryc9c2e9d2007-02-08 13:35:18 -0800239out_forward:
240 remove_proc_entry("socket", x25_proc_dir);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700241out_socket:
242 remove_proc_entry("route", x25_proc_dir);
243out_route:
Eric W. Biederman457c4cb2007-09-12 12:01:34 +0200244 remove_proc_entry("x25", init_net.proc_net);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700245 goto out;
246}
247
248void __exit x25_proc_exit(void)
249{
Andrew Hendryc9c2e9d2007-02-08 13:35:18 -0800250 remove_proc_entry("forward", x25_proc_dir);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700251 remove_proc_entry("route", x25_proc_dir);
252 remove_proc_entry("socket", x25_proc_dir);
Eric W. Biederman457c4cb2007-09-12 12:01:34 +0200253 remove_proc_entry("x25", init_net.proc_net);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700254}
255
256#else /* CONFIG_PROC_FS */
257
258int __init x25_proc_init(void)
259{
260 return 0;
261}
262
263void __exit x25_proc_exit(void)
264{
265}
266#endif /* CONFIG_PROC_FS */