blob: 0917f047f2cfbf7e2ba86c453187b40db0e0146b [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>
Paul Gortmakerbc3b2d72011-07-15 11:47:34 -040023#include <linux/export.h>
Eric W. Biederman457c4cb2007-09-12 12:01:34 +020024#include <net/net_namespace.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070025#include <net/sock.h>
26#include <net/x25.h>
27
28#ifdef CONFIG_PROC_FS
Linus Torvalds1da177e2005-04-16 15:20:36 -070029
30static void *x25_seq_route_start(struct seq_file *seq, loff_t *pos)
Eric Dumazet6bf15742008-01-13 22:27:52 -080031 __acquires(x25_route_list_lock)
Linus Torvalds1da177e2005-04-16 15:20:36 -070032{
Linus Torvalds1da177e2005-04-16 15:20:36 -070033 read_lock_bh(&x25_route_list_lock);
Li Zefan4f134202010-02-08 23:20:42 +000034 return seq_list_start_head(&x25_route_list, *pos);
Linus Torvalds1da177e2005-04-16 15:20:36 -070035}
36
37static void *x25_seq_route_next(struct seq_file *seq, void *v, loff_t *pos)
38{
Li Zefan4f134202010-02-08 23:20:42 +000039 return seq_list_next(v, &x25_route_list, pos);
Linus Torvalds1da177e2005-04-16 15:20:36 -070040}
41
42static void x25_seq_route_stop(struct seq_file *seq, void *v)
Eric Dumazet6bf15742008-01-13 22:27:52 -080043 __releases(x25_route_list_lock)
Linus Torvalds1da177e2005-04-16 15:20:36 -070044{
45 read_unlock_bh(&x25_route_list_lock);
46}
47
48static int x25_seq_route_show(struct seq_file *seq, void *v)
49{
Li Zefan4f134202010-02-08 23:20:42 +000050 struct x25_route *rt = list_entry(v, struct x25_route, node);
Linus Torvalds1da177e2005-04-16 15:20:36 -070051
Li Zefan4f134202010-02-08 23:20:42 +000052 if (v == &x25_route_list) {
Linus Torvalds1da177e2005-04-16 15:20:36 -070053 seq_puts(seq, "Address Digits Device\n");
54 goto out;
55 }
56
57 rt = v;
58 seq_printf(seq, "%-15s %-6d %-5s\n",
59 rt->address.x25_addr, rt->sigdigits,
60 rt->dev ? rt->dev->name : "???");
61out:
62 return 0;
YOSHIFUJI Hideakif8e1d2012007-02-09 23:25:27 +090063}
Linus Torvalds1da177e2005-04-16 15:20:36 -070064
Linus Torvalds1da177e2005-04-16 15:20:36 -070065static void *x25_seq_socket_start(struct seq_file *seq, loff_t *pos)
Eric Dumazet6bf15742008-01-13 22:27:52 -080066 __acquires(x25_list_lock)
Linus Torvalds1da177e2005-04-16 15:20:36 -070067{
Linus Torvalds1da177e2005-04-16 15:20:36 -070068 read_lock_bh(&x25_list_lock);
Li Zefan32d2e3a2010-02-08 23:19:04 +000069 return seq_hlist_start_head(&x25_list, *pos);
Linus Torvalds1da177e2005-04-16 15:20:36 -070070}
71
72static void *x25_seq_socket_next(struct seq_file *seq, void *v, loff_t *pos)
73{
Li Zefan32d2e3a2010-02-08 23:19:04 +000074 return seq_hlist_next(v, &x25_list, pos);
Linus Torvalds1da177e2005-04-16 15:20:36 -070075}
76
77static void x25_seq_socket_stop(struct seq_file *seq, void *v)
Eric Dumazet6bf15742008-01-13 22:27:52 -080078 __releases(x25_list_lock)
Linus Torvalds1da177e2005-04-16 15:20:36 -070079{
80 read_unlock_bh(&x25_list_lock);
81}
82
83static int x25_seq_socket_show(struct seq_file *seq, void *v)
84{
85 struct sock *s;
86 struct x25_sock *x25;
87 struct net_device *dev;
88 const char *devname;
89
90 if (v == SEQ_START_TOKEN) {
91 seq_printf(seq, "dest_addr src_addr dev lci st vs vr "
92 "va t t2 t21 t22 t23 Snd-Q Rcv-Q inode\n");
93 goto out;
94 }
95
Li Zefan32d2e3a2010-02-08 23:19:04 +000096 s = sk_entry(v);
Linus Torvalds1da177e2005-04-16 15:20:36 -070097 x25 = x25_sk(s);
98
99 if (!x25->neighbour || (dev = x25->neighbour->dev) == NULL)
100 devname = "???";
101 else
102 devname = x25->neighbour->dev->name;
103
104 seq_printf(seq, "%-10s %-10s %-5s %3.3X %d %d %d %d %3lu %3lu "
105 "%3lu %3lu %3lu %5d %5d %ld\n",
106 !x25->dest_addr.x25_addr[0] ? "*" : x25->dest_addr.x25_addr,
107 !x25->source_addr.x25_addr[0] ? "*" : x25->source_addr.x25_addr,
108 devname, x25->lci & 0x0FFF, x25->state, x25->vs, x25->vr,
109 x25->va, x25_display_timer(s) / HZ, x25->t2 / HZ,
110 x25->t21 / HZ, x25->t22 / HZ, x25->t23 / HZ,
Eric Dumazet31e6d362009-06-17 19:05:41 -0700111 sk_wmem_alloc_get(s),
112 sk_rmem_alloc_get(s),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700113 s->sk_socket ? SOCK_INODE(s->sk_socket)->i_ino : 0L);
114out:
115 return 0;
YOSHIFUJI Hideakif8e1d2012007-02-09 23:25:27 +0900116}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700117
Andrew Hendryc9c2e9d2007-02-08 13:35:18 -0800118static void *x25_seq_forward_start(struct seq_file *seq, loff_t *pos)
Eric Dumazet6bf15742008-01-13 22:27:52 -0800119 __acquires(x25_forward_list_lock)
Andrew Hendryc9c2e9d2007-02-08 13:35:18 -0800120{
Andrew Hendryc9c2e9d2007-02-08 13:35:18 -0800121 read_lock_bh(&x25_forward_list_lock);
Li Zefan4f134202010-02-08 23:20:42 +0000122 return seq_list_start_head(&x25_forward_list, *pos);
Andrew Hendryc9c2e9d2007-02-08 13:35:18 -0800123}
124
125static void *x25_seq_forward_next(struct seq_file *seq, void *v, loff_t *pos)
126{
Li Zefan4f134202010-02-08 23:20:42 +0000127 return seq_list_next(v, &x25_forward_list, pos);
Andrew Hendryc9c2e9d2007-02-08 13:35:18 -0800128}
129
130static void x25_seq_forward_stop(struct seq_file *seq, void *v)
Eric Dumazet6bf15742008-01-13 22:27:52 -0800131 __releases(x25_forward_list_lock)
Andrew Hendryc9c2e9d2007-02-08 13:35:18 -0800132{
133 read_unlock_bh(&x25_forward_list_lock);
134}
135
136static int x25_seq_forward_show(struct seq_file *seq, void *v)
137{
Li Zefan4f134202010-02-08 23:20:42 +0000138 struct x25_forward *f = list_entry(v, struct x25_forward, node);
Andrew Hendryc9c2e9d2007-02-08 13:35:18 -0800139
Li Zefan4f134202010-02-08 23:20:42 +0000140 if (v == &x25_forward_list) {
Andrew Hendryc9c2e9d2007-02-08 13:35:18 -0800141 seq_printf(seq, "lci dev1 dev2\n");
142 goto out;
143 }
144
145 f = v;
146
147 seq_printf(seq, "%d %-10s %-10s\n",
148 f->lci, f->dev1->name, f->dev2->name);
Andrew Hendryc9c2e9d2007-02-08 13:35:18 -0800149out:
150 return 0;
151}
152
Philippe De Muyter56b3d972007-07-10 23:07:31 -0700153static const struct seq_operations x25_seq_route_ops = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700154 .start = x25_seq_route_start,
155 .next = x25_seq_route_next,
156 .stop = x25_seq_route_stop,
157 .show = x25_seq_route_show,
158};
159
Philippe De Muyter56b3d972007-07-10 23:07:31 -0700160static const struct seq_operations x25_seq_socket_ops = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700161 .start = x25_seq_socket_start,
162 .next = x25_seq_socket_next,
163 .stop = x25_seq_socket_stop,
164 .show = x25_seq_socket_show,
165};
166
Philippe De Muyter56b3d972007-07-10 23:07:31 -0700167static const struct seq_operations x25_seq_forward_ops = {
Andrew Hendryc9c2e9d2007-02-08 13:35:18 -0800168 .start = x25_seq_forward_start,
169 .next = x25_seq_forward_next,
170 .stop = x25_seq_forward_stop,
171 .show = x25_seq_forward_show,
172};
173
Linus Torvalds1da177e2005-04-16 15:20:36 -0700174static int x25_seq_socket_open(struct inode *inode, struct file *file)
175{
176 return seq_open(file, &x25_seq_socket_ops);
177}
178
179static int x25_seq_route_open(struct inode *inode, struct file *file)
180{
181 return seq_open(file, &x25_seq_route_ops);
182}
183
Andrew Hendryc9c2e9d2007-02-08 13:35:18 -0800184static int x25_seq_forward_open(struct inode *inode, struct file *file)
185{
186 return seq_open(file, &x25_seq_forward_ops);
187}
188
Arjan van de Venda7071d2007-02-12 00:55:36 -0800189static const struct file_operations x25_seq_socket_fops = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700190 .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 .open = x25_seq_route_open,
198 .read = seq_read,
199 .llseek = seq_lseek,
200 .release = seq_release,
201};
202
Jan Engelhardta1f6f5a2008-01-22 18:30:06 -0800203static const struct file_operations x25_seq_forward_fops = {
Andrew Hendryc9c2e9d2007-02-08 13:35:18 -0800204 .open = x25_seq_forward_open,
205 .read = seq_read,
206 .llseek = seq_lseek,
207 .release = seq_release,
208};
209
Linus Torvalds1da177e2005-04-16 15:20:36 -0700210int __init x25_proc_init(void)
211{
Al Viro345566b2013-04-03 00:04:51 -0400212 if (!proc_mkdir("x25", init_net.proc_net))
213 return -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700214
Al Viro345566b2013-04-03 00:04:51 -0400215 if (!proc_create("x25/route", S_IRUGO, init_net.proc_net,
216 &x25_seq_route_fops))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700217 goto out;
218
Al Viro345566b2013-04-03 00:04:51 -0400219 if (!proc_create("x25/socket", S_IRUGO, init_net.proc_net,
220 &x25_seq_socket_fops))
221 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700222
Al Viro345566b2013-04-03 00:04:51 -0400223 if (!proc_create("x25/forward", S_IRUGO, init_net.proc_net,
224 &x25_seq_forward_fops))
225 goto out;
226 return 0;
Andrew Hendryc9c2e9d2007-02-08 13:35:18 -0800227
Linus Torvalds1da177e2005-04-16 15:20:36 -0700228out:
Al Viro345566b2013-04-03 00:04:51 -0400229 remove_proc_subtree("x25", init_net.proc_net);
230 return -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700231}
232
233void __exit x25_proc_exit(void)
234{
Al Viro345566b2013-04-03 00:04:51 -0400235 remove_proc_subtree("x25", init_net.proc_net);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700236}
237
238#else /* CONFIG_PROC_FS */
239
240int __init x25_proc_init(void)
241{
242 return 0;
243}
244
245void __exit x25_proc_exit(void)
246{
247}
248#endif /* CONFIG_PROC_FS */