blob: 3bddcbdf2e4060840a915e6a84f97c1a4cb98f61 [file] [log] [blame]
Thomas Gleixneree5d8f42019-05-20 19:08:06 +02001// SPDX-License-Identifier: GPL-2.0-or-later
Linus Torvalds1da177e2005-04-16 15:20:36 -07002/*
3 * X.25 Packet Layer release 002
4 *
5 * This is ALPHA test software. This code may break your machine,
6 * randomly fail to work with new releases, misbehave and/or generally
YOSHIFUJI Hideakif8e1d2012007-02-09 23:25:27 +09007 * screw up. It might even work.
Linus Torvalds1da177e2005-04-16 15:20:36 -07008 *
9 * This code REQUIRES 2.4 with seq_file support
10 *
Linus Torvalds1da177e2005-04-16 15:20:36 -070011 * History
12 * 2002/10/06 Arnaldo Carvalho de Melo seq_file support
13 */
14
Linus Torvalds1da177e2005-04-16 15:20:36 -070015#include <linux/init.h>
16#include <linux/proc_fs.h>
17#include <linux/seq_file.h>
Paul Gortmakerbc3b2d72011-07-15 11:47:34 -040018#include <linux/export.h>
Eric W. Biederman457c4cb2007-09-12 12:01:34 +020019#include <net/net_namespace.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070020#include <net/sock.h>
21#include <net/x25.h>
22
23#ifdef CONFIG_PROC_FS
Linus Torvalds1da177e2005-04-16 15:20:36 -070024
25static void *x25_seq_route_start(struct seq_file *seq, loff_t *pos)
Eric Dumazet6bf15742008-01-13 22:27:52 -080026 __acquires(x25_route_list_lock)
Linus Torvalds1da177e2005-04-16 15:20:36 -070027{
Linus Torvalds1da177e2005-04-16 15:20:36 -070028 read_lock_bh(&x25_route_list_lock);
Li Zefan4f134202010-02-08 23:20:42 +000029 return seq_list_start_head(&x25_route_list, *pos);
Linus Torvalds1da177e2005-04-16 15:20:36 -070030}
31
32static void *x25_seq_route_next(struct seq_file *seq, void *v, loff_t *pos)
33{
Li Zefan4f134202010-02-08 23:20:42 +000034 return seq_list_next(v, &x25_route_list, pos);
Linus Torvalds1da177e2005-04-16 15:20:36 -070035}
36
37static void x25_seq_route_stop(struct seq_file *seq, void *v)
Eric Dumazet6bf15742008-01-13 22:27:52 -080038 __releases(x25_route_list_lock)
Linus Torvalds1da177e2005-04-16 15:20:36 -070039{
40 read_unlock_bh(&x25_route_list_lock);
41}
42
43static int x25_seq_route_show(struct seq_file *seq, void *v)
44{
Li Zefan4f134202010-02-08 23:20:42 +000045 struct x25_route *rt = list_entry(v, struct x25_route, node);
Linus Torvalds1da177e2005-04-16 15:20:36 -070046
Li Zefan4f134202010-02-08 23:20:42 +000047 if (v == &x25_route_list) {
Linus Torvalds1da177e2005-04-16 15:20:36 -070048 seq_puts(seq, "Address Digits Device\n");
49 goto out;
50 }
51
52 rt = v;
53 seq_printf(seq, "%-15s %-6d %-5s\n",
54 rt->address.x25_addr, rt->sigdigits,
55 rt->dev ? rt->dev->name : "???");
56out:
57 return 0;
YOSHIFUJI Hideakif8e1d2012007-02-09 23:25:27 +090058}
Linus Torvalds1da177e2005-04-16 15:20:36 -070059
Linus Torvalds1da177e2005-04-16 15:20:36 -070060static void *x25_seq_socket_start(struct seq_file *seq, loff_t *pos)
Eric Dumazet6bf15742008-01-13 22:27:52 -080061 __acquires(x25_list_lock)
Linus Torvalds1da177e2005-04-16 15:20:36 -070062{
Linus Torvalds1da177e2005-04-16 15:20:36 -070063 read_lock_bh(&x25_list_lock);
Li Zefan32d2e3a2010-02-08 23:19:04 +000064 return seq_hlist_start_head(&x25_list, *pos);
Linus Torvalds1da177e2005-04-16 15:20:36 -070065}
66
67static void *x25_seq_socket_next(struct seq_file *seq, void *v, loff_t *pos)
68{
Li Zefan32d2e3a2010-02-08 23:19:04 +000069 return seq_hlist_next(v, &x25_list, pos);
Linus Torvalds1da177e2005-04-16 15:20:36 -070070}
71
72static void x25_seq_socket_stop(struct seq_file *seq, void *v)
Eric Dumazet6bf15742008-01-13 22:27:52 -080073 __releases(x25_list_lock)
Linus Torvalds1da177e2005-04-16 15:20:36 -070074{
75 read_unlock_bh(&x25_list_lock);
76}
77
78static int x25_seq_socket_show(struct seq_file *seq, void *v)
79{
80 struct sock *s;
81 struct x25_sock *x25;
82 struct net_device *dev;
83 const char *devname;
84
85 if (v == SEQ_START_TOKEN) {
86 seq_printf(seq, "dest_addr src_addr dev lci st vs vr "
87 "va t t2 t21 t22 t23 Snd-Q Rcv-Q inode\n");
88 goto out;
89 }
90
Li Zefan32d2e3a2010-02-08 23:19:04 +000091 s = sk_entry(v);
Linus Torvalds1da177e2005-04-16 15:20:36 -070092 x25 = x25_sk(s);
93
94 if (!x25->neighbour || (dev = x25->neighbour->dev) == NULL)
95 devname = "???";
96 else
97 devname = x25->neighbour->dev->name;
98
99 seq_printf(seq, "%-10s %-10s %-5s %3.3X %d %d %d %d %3lu %3lu "
100 "%3lu %3lu %3lu %5d %5d %ld\n",
101 !x25->dest_addr.x25_addr[0] ? "*" : x25->dest_addr.x25_addr,
102 !x25->source_addr.x25_addr[0] ? "*" : x25->source_addr.x25_addr,
103 devname, x25->lci & 0x0FFF, x25->state, x25->vs, x25->vr,
104 x25->va, x25_display_timer(s) / HZ, x25->t2 / HZ,
105 x25->t21 / HZ, x25->t22 / HZ, x25->t23 / HZ,
Eric Dumazet31e6d362009-06-17 19:05:41 -0700106 sk_wmem_alloc_get(s),
107 sk_rmem_alloc_get(s),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700108 s->sk_socket ? SOCK_INODE(s->sk_socket)->i_ino : 0L);
109out:
110 return 0;
YOSHIFUJI Hideakif8e1d2012007-02-09 23:25:27 +0900111}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700112
Andrew Hendryc9c2e9d2007-02-08 13:35:18 -0800113static void *x25_seq_forward_start(struct seq_file *seq, loff_t *pos)
Eric Dumazet6bf15742008-01-13 22:27:52 -0800114 __acquires(x25_forward_list_lock)
Andrew Hendryc9c2e9d2007-02-08 13:35:18 -0800115{
Andrew Hendryc9c2e9d2007-02-08 13:35:18 -0800116 read_lock_bh(&x25_forward_list_lock);
Li Zefan4f134202010-02-08 23:20:42 +0000117 return seq_list_start_head(&x25_forward_list, *pos);
Andrew Hendryc9c2e9d2007-02-08 13:35:18 -0800118}
119
120static void *x25_seq_forward_next(struct seq_file *seq, void *v, loff_t *pos)
121{
Li Zefan4f134202010-02-08 23:20:42 +0000122 return seq_list_next(v, &x25_forward_list, pos);
Andrew Hendryc9c2e9d2007-02-08 13:35:18 -0800123}
124
125static void x25_seq_forward_stop(struct seq_file *seq, void *v)
Eric Dumazet6bf15742008-01-13 22:27:52 -0800126 __releases(x25_forward_list_lock)
Andrew Hendryc9c2e9d2007-02-08 13:35:18 -0800127{
128 read_unlock_bh(&x25_forward_list_lock);
129}
130
131static int x25_seq_forward_show(struct seq_file *seq, void *v)
132{
Li Zefan4f134202010-02-08 23:20:42 +0000133 struct x25_forward *f = list_entry(v, struct x25_forward, node);
Andrew Hendryc9c2e9d2007-02-08 13:35:18 -0800134
Li Zefan4f134202010-02-08 23:20:42 +0000135 if (v == &x25_forward_list) {
Andrew Hendryc9c2e9d2007-02-08 13:35:18 -0800136 seq_printf(seq, "lci dev1 dev2\n");
137 goto out;
138 }
139
140 f = v;
141
142 seq_printf(seq, "%d %-10s %-10s\n",
143 f->lci, f->dev1->name, f->dev2->name);
Andrew Hendryc9c2e9d2007-02-08 13:35:18 -0800144out:
145 return 0;
146}
147
Philippe De Muyter56b3d972007-07-10 23:07:31 -0700148static const struct seq_operations x25_seq_route_ops = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700149 .start = x25_seq_route_start,
150 .next = x25_seq_route_next,
151 .stop = x25_seq_route_stop,
152 .show = x25_seq_route_show,
153};
154
Philippe De Muyter56b3d972007-07-10 23:07:31 -0700155static const struct seq_operations x25_seq_socket_ops = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700156 .start = x25_seq_socket_start,
157 .next = x25_seq_socket_next,
158 .stop = x25_seq_socket_stop,
159 .show = x25_seq_socket_show,
160};
161
Philippe De Muyter56b3d972007-07-10 23:07:31 -0700162static const struct seq_operations x25_seq_forward_ops = {
Andrew Hendryc9c2e9d2007-02-08 13:35:18 -0800163 .start = x25_seq_forward_start,
164 .next = x25_seq_forward_next,
165 .stop = x25_seq_forward_stop,
166 .show = x25_seq_forward_show,
167};
168
Linus Torvalds1da177e2005-04-16 15:20:36 -0700169int __init x25_proc_init(void)
170{
Al Viro345566b2013-04-03 00:04:51 -0400171 if (!proc_mkdir("x25", init_net.proc_net))
172 return -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700173
Christoph Hellwigfddda2b2018-04-13 19:44:18 +0200174 if (!proc_create_seq("x25/route", 0444, init_net.proc_net,
175 &x25_seq_route_ops))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700176 goto out;
177
Christoph Hellwigfddda2b2018-04-13 19:44:18 +0200178 if (!proc_create_seq("x25/socket", 0444, init_net.proc_net,
179 &x25_seq_socket_ops))
Al Viro345566b2013-04-03 00:04:51 -0400180 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700181
Christoph Hellwigfddda2b2018-04-13 19:44:18 +0200182 if (!proc_create_seq("x25/forward", 0444, init_net.proc_net,
183 &x25_seq_forward_ops))
Al Viro345566b2013-04-03 00:04:51 -0400184 goto out;
185 return 0;
Andrew Hendryc9c2e9d2007-02-08 13:35:18 -0800186
Linus Torvalds1da177e2005-04-16 15:20:36 -0700187out:
Al Viro345566b2013-04-03 00:04:51 -0400188 remove_proc_subtree("x25", init_net.proc_net);
189 return -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700190}
191
192void __exit x25_proc_exit(void)
193{
Al Viro345566b2013-04-03 00:04:51 -0400194 remove_proc_subtree("x25", init_net.proc_net);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700195}
196
197#else /* CONFIG_PROC_FS */
198
199int __init x25_proc_init(void)
200{
201 return 0;
202}
203
204void __exit x25_proc_exit(void)
205{
206}
207#endif /* CONFIG_PROC_FS */