Thomas Gleixner | ee5d8f4 | 2019-05-20 19:08:06 +0200 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0-or-later |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2 | /* |
| 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 Hideaki | f8e1d201 | 2007-02-09 23:25:27 +0900 | [diff] [blame] | 7 | * screw up. It might even work. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8 | * |
| 9 | * This code REQUIRES 2.4 with seq_file support |
| 10 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11 | * History |
| 12 | * 2002/10/06 Arnaldo Carvalho de Melo seq_file support |
| 13 | */ |
| 14 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15 | #include <linux/init.h> |
| 16 | #include <linux/proc_fs.h> |
| 17 | #include <linux/seq_file.h> |
Paul Gortmaker | bc3b2d7 | 2011-07-15 11:47:34 -0400 | [diff] [blame] | 18 | #include <linux/export.h> |
Eric W. Biederman | 457c4cb | 2007-09-12 12:01:34 +0200 | [diff] [blame] | 19 | #include <net/net_namespace.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 20 | #include <net/sock.h> |
| 21 | #include <net/x25.h> |
| 22 | |
| 23 | #ifdef CONFIG_PROC_FS |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 24 | |
| 25 | static void *x25_seq_route_start(struct seq_file *seq, loff_t *pos) |
Eric Dumazet | 6bf1574 | 2008-01-13 22:27:52 -0800 | [diff] [blame] | 26 | __acquires(x25_route_list_lock) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 27 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 28 | read_lock_bh(&x25_route_list_lock); |
Li Zefan | 4f13420 | 2010-02-08 23:20:42 +0000 | [diff] [blame] | 29 | return seq_list_start_head(&x25_route_list, *pos); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 30 | } |
| 31 | |
| 32 | static void *x25_seq_route_next(struct seq_file *seq, void *v, loff_t *pos) |
| 33 | { |
Li Zefan | 4f13420 | 2010-02-08 23:20:42 +0000 | [diff] [blame] | 34 | return seq_list_next(v, &x25_route_list, pos); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 35 | } |
| 36 | |
| 37 | static void x25_seq_route_stop(struct seq_file *seq, void *v) |
Eric Dumazet | 6bf1574 | 2008-01-13 22:27:52 -0800 | [diff] [blame] | 38 | __releases(x25_route_list_lock) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 39 | { |
| 40 | read_unlock_bh(&x25_route_list_lock); |
| 41 | } |
| 42 | |
| 43 | static int x25_seq_route_show(struct seq_file *seq, void *v) |
| 44 | { |
Li Zefan | 4f13420 | 2010-02-08 23:20:42 +0000 | [diff] [blame] | 45 | struct x25_route *rt = list_entry(v, struct x25_route, node); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 46 | |
Li Zefan | 4f13420 | 2010-02-08 23:20:42 +0000 | [diff] [blame] | 47 | if (v == &x25_route_list) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 48 | 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 : "???"); |
| 56 | out: |
| 57 | return 0; |
YOSHIFUJI Hideaki | f8e1d201 | 2007-02-09 23:25:27 +0900 | [diff] [blame] | 58 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 59 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 60 | static void *x25_seq_socket_start(struct seq_file *seq, loff_t *pos) |
Eric Dumazet | 6bf1574 | 2008-01-13 22:27:52 -0800 | [diff] [blame] | 61 | __acquires(x25_list_lock) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 62 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 63 | read_lock_bh(&x25_list_lock); |
Li Zefan | 32d2e3a | 2010-02-08 23:19:04 +0000 | [diff] [blame] | 64 | return seq_hlist_start_head(&x25_list, *pos); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 65 | } |
| 66 | |
| 67 | static void *x25_seq_socket_next(struct seq_file *seq, void *v, loff_t *pos) |
| 68 | { |
Li Zefan | 32d2e3a | 2010-02-08 23:19:04 +0000 | [diff] [blame] | 69 | return seq_hlist_next(v, &x25_list, pos); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 70 | } |
| 71 | |
| 72 | static void x25_seq_socket_stop(struct seq_file *seq, void *v) |
Eric Dumazet | 6bf1574 | 2008-01-13 22:27:52 -0800 | [diff] [blame] | 73 | __releases(x25_list_lock) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 74 | { |
| 75 | read_unlock_bh(&x25_list_lock); |
| 76 | } |
| 77 | |
| 78 | static 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 Zefan | 32d2e3a | 2010-02-08 23:19:04 +0000 | [diff] [blame] | 91 | s = sk_entry(v); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 92 | 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 Dumazet | 31e6d36 | 2009-06-17 19:05:41 -0700 | [diff] [blame] | 106 | sk_wmem_alloc_get(s), |
| 107 | sk_rmem_alloc_get(s), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 108 | s->sk_socket ? SOCK_INODE(s->sk_socket)->i_ino : 0L); |
| 109 | out: |
| 110 | return 0; |
YOSHIFUJI Hideaki | f8e1d201 | 2007-02-09 23:25:27 +0900 | [diff] [blame] | 111 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 112 | |
Andrew Hendry | c9c2e9d | 2007-02-08 13:35:18 -0800 | [diff] [blame] | 113 | static void *x25_seq_forward_start(struct seq_file *seq, loff_t *pos) |
Eric Dumazet | 6bf1574 | 2008-01-13 22:27:52 -0800 | [diff] [blame] | 114 | __acquires(x25_forward_list_lock) |
Andrew Hendry | c9c2e9d | 2007-02-08 13:35:18 -0800 | [diff] [blame] | 115 | { |
Andrew Hendry | c9c2e9d | 2007-02-08 13:35:18 -0800 | [diff] [blame] | 116 | read_lock_bh(&x25_forward_list_lock); |
Li Zefan | 4f13420 | 2010-02-08 23:20:42 +0000 | [diff] [blame] | 117 | return seq_list_start_head(&x25_forward_list, *pos); |
Andrew Hendry | c9c2e9d | 2007-02-08 13:35:18 -0800 | [diff] [blame] | 118 | } |
| 119 | |
| 120 | static void *x25_seq_forward_next(struct seq_file *seq, void *v, loff_t *pos) |
| 121 | { |
Li Zefan | 4f13420 | 2010-02-08 23:20:42 +0000 | [diff] [blame] | 122 | return seq_list_next(v, &x25_forward_list, pos); |
Andrew Hendry | c9c2e9d | 2007-02-08 13:35:18 -0800 | [diff] [blame] | 123 | } |
| 124 | |
| 125 | static void x25_seq_forward_stop(struct seq_file *seq, void *v) |
Eric Dumazet | 6bf1574 | 2008-01-13 22:27:52 -0800 | [diff] [blame] | 126 | __releases(x25_forward_list_lock) |
Andrew Hendry | c9c2e9d | 2007-02-08 13:35:18 -0800 | [diff] [blame] | 127 | { |
| 128 | read_unlock_bh(&x25_forward_list_lock); |
| 129 | } |
| 130 | |
| 131 | static int x25_seq_forward_show(struct seq_file *seq, void *v) |
| 132 | { |
Li Zefan | 4f13420 | 2010-02-08 23:20:42 +0000 | [diff] [blame] | 133 | struct x25_forward *f = list_entry(v, struct x25_forward, node); |
Andrew Hendry | c9c2e9d | 2007-02-08 13:35:18 -0800 | [diff] [blame] | 134 | |
Li Zefan | 4f13420 | 2010-02-08 23:20:42 +0000 | [diff] [blame] | 135 | if (v == &x25_forward_list) { |
Andrew Hendry | c9c2e9d | 2007-02-08 13:35:18 -0800 | [diff] [blame] | 136 | 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 Hendry | c9c2e9d | 2007-02-08 13:35:18 -0800 | [diff] [blame] | 144 | out: |
| 145 | return 0; |
| 146 | } |
| 147 | |
Philippe De Muyter | 56b3d97 | 2007-07-10 23:07:31 -0700 | [diff] [blame] | 148 | static const struct seq_operations x25_seq_route_ops = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 149 | .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 Muyter | 56b3d97 | 2007-07-10 23:07:31 -0700 | [diff] [blame] | 155 | static const struct seq_operations x25_seq_socket_ops = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 156 | .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 Muyter | 56b3d97 | 2007-07-10 23:07:31 -0700 | [diff] [blame] | 162 | static const struct seq_operations x25_seq_forward_ops = { |
Andrew Hendry | c9c2e9d | 2007-02-08 13:35:18 -0800 | [diff] [blame] | 163 | .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 Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 169 | int __init x25_proc_init(void) |
| 170 | { |
Al Viro | 345566b | 2013-04-03 00:04:51 -0400 | [diff] [blame] | 171 | if (!proc_mkdir("x25", init_net.proc_net)) |
| 172 | return -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 173 | |
Christoph Hellwig | fddda2b | 2018-04-13 19:44:18 +0200 | [diff] [blame] | 174 | if (!proc_create_seq("x25/route", 0444, init_net.proc_net, |
| 175 | &x25_seq_route_ops)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 176 | goto out; |
| 177 | |
Christoph Hellwig | fddda2b | 2018-04-13 19:44:18 +0200 | [diff] [blame] | 178 | if (!proc_create_seq("x25/socket", 0444, init_net.proc_net, |
| 179 | &x25_seq_socket_ops)) |
Al Viro | 345566b | 2013-04-03 00:04:51 -0400 | [diff] [blame] | 180 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 181 | |
Christoph Hellwig | fddda2b | 2018-04-13 19:44:18 +0200 | [diff] [blame] | 182 | if (!proc_create_seq("x25/forward", 0444, init_net.proc_net, |
| 183 | &x25_seq_forward_ops)) |
Al Viro | 345566b | 2013-04-03 00:04:51 -0400 | [diff] [blame] | 184 | goto out; |
| 185 | return 0; |
Andrew Hendry | c9c2e9d | 2007-02-08 13:35:18 -0800 | [diff] [blame] | 186 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 187 | out: |
Al Viro | 345566b | 2013-04-03 00:04:51 -0400 | [diff] [blame] | 188 | remove_proc_subtree("x25", init_net.proc_net); |
| 189 | return -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 190 | } |
| 191 | |
| 192 | void __exit x25_proc_exit(void) |
| 193 | { |
Al Viro | 345566b | 2013-04-03 00:04:51 -0400 | [diff] [blame] | 194 | remove_proc_subtree("x25", init_net.proc_net); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 195 | } |
| 196 | |
| 197 | #else /* CONFIG_PROC_FS */ |
| 198 | |
| 199 | int __init x25_proc_init(void) |
| 200 | { |
| 201 | return 0; |
| 202 | } |
| 203 | |
| 204 | void __exit x25_proc_exit(void) |
| 205 | { |
| 206 | } |
| 207 | #endif /* CONFIG_PROC_FS */ |