1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * X.25 Packet Layer release 002
5 * This is ALPHA test software. This code may break your machine,
6 * randomly fail to work with new releases, misbehave and/or generally
7 * screw up. It might even work.
9 * This code REQUIRES 2.4 with seq_file support
12 * 2002/10/06 Arnaldo Carvalho de Melo seq_file support
15 #include <linux/init.h>
16 #include <linux/proc_fs.h>
17 #include <linux/seq_file.h>
18 #include <linux/export.h>
19 #include <net/net_namespace.h>
25 static void *x25_seq_route_start(struct seq_file *seq, loff_t *pos)
26 __acquires(x25_route_list_lock)
28 read_lock_bh(&x25_route_list_lock);
29 return seq_list_start_head(&x25_route_list, *pos);
32 static void *x25_seq_route_next(struct seq_file *seq, void *v, loff_t *pos)
34 return seq_list_next(v, &x25_route_list, pos);
37 static void x25_seq_route_stop(struct seq_file *seq, void *v)
38 __releases(x25_route_list_lock)
40 read_unlock_bh(&x25_route_list_lock);
43 static int x25_seq_route_show(struct seq_file *seq, void *v)
45 struct x25_route *rt = list_entry(v, struct x25_route, node);
47 if (v == &x25_route_list) {
48 seq_puts(seq, "Address Digits Device\n");
53 seq_printf(seq, "%-15s %-6d %-5s\n",
54 rt->address.x25_addr, rt->sigdigits,
55 rt->dev ? rt->dev->name : "???");
60 static void *x25_seq_socket_start(struct seq_file *seq, loff_t *pos)
61 __acquires(x25_list_lock)
63 read_lock_bh(&x25_list_lock);
64 return seq_hlist_start_head(&x25_list, *pos);
67 static void *x25_seq_socket_next(struct seq_file *seq, void *v, loff_t *pos)
69 return seq_hlist_next(v, &x25_list, pos);
72 static void x25_seq_socket_stop(struct seq_file *seq, void *v)
73 __releases(x25_list_lock)
75 read_unlock_bh(&x25_list_lock);
78 static int x25_seq_socket_show(struct seq_file *seq, void *v)
82 struct net_device *dev;
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");
94 if (!x25->neighbour || (dev = x25->neighbour->dev) == NULL)
97 devname = x25->neighbour->dev->name;
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,
106 sk_wmem_alloc_get(s),
107 sk_rmem_alloc_get(s),
108 s->sk_socket ? SOCK_INODE(s->sk_socket)->i_ino : 0L);
113 static void *x25_seq_forward_start(struct seq_file *seq, loff_t *pos)
114 __acquires(x25_forward_list_lock)
116 read_lock_bh(&x25_forward_list_lock);
117 return seq_list_start_head(&x25_forward_list, *pos);
120 static void *x25_seq_forward_next(struct seq_file *seq, void *v, loff_t *pos)
122 return seq_list_next(v, &x25_forward_list, pos);
125 static void x25_seq_forward_stop(struct seq_file *seq, void *v)
126 __releases(x25_forward_list_lock)
128 read_unlock_bh(&x25_forward_list_lock);
131 static int x25_seq_forward_show(struct seq_file *seq, void *v)
133 struct x25_forward *f = list_entry(v, struct x25_forward, node);
135 if (v == &x25_forward_list) {
136 seq_printf(seq, "lci dev1 dev2\n");
142 seq_printf(seq, "%d %-10s %-10s\n",
143 f->lci, f->dev1->name, f->dev2->name);
148 static const struct seq_operations x25_seq_route_ops = {
149 .start = x25_seq_route_start,
150 .next = x25_seq_route_next,
151 .stop = x25_seq_route_stop,
152 .show = x25_seq_route_show,
155 static const struct seq_operations x25_seq_socket_ops = {
156 .start = x25_seq_socket_start,
157 .next = x25_seq_socket_next,
158 .stop = x25_seq_socket_stop,
159 .show = x25_seq_socket_show,
162 static const struct seq_operations x25_seq_forward_ops = {
163 .start = x25_seq_forward_start,
164 .next = x25_seq_forward_next,
165 .stop = x25_seq_forward_stop,
166 .show = x25_seq_forward_show,
169 int __init x25_proc_init(void)
171 if (!proc_mkdir("x25", init_net.proc_net))
174 if (!proc_create_seq("x25/route", 0444, init_net.proc_net,
178 if (!proc_create_seq("x25/socket", 0444, init_net.proc_net,
179 &x25_seq_socket_ops))
182 if (!proc_create_seq("x25/forward", 0444, init_net.proc_net,
183 &x25_seq_forward_ops))
188 remove_proc_subtree("x25", init_net.proc_net);
192 void __exit x25_proc_exit(void)
194 remove_proc_subtree("x25", init_net.proc_net);
197 #else /* CONFIG_PROC_FS */
199 int __init x25_proc_init(void)
204 void __exit x25_proc_exit(void)
207 #endif /* CONFIG_PROC_FS */