Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 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 Hideaki | f8e1d201 | 2007-02-09 23:25:27 +0900 | [diff] [blame] | 6 | * screw up. It might even work. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7 | * |
| 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 Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 20 | #include <linux/init.h> |
| 21 | #include <linux/proc_fs.h> |
| 22 | #include <linux/seq_file.h> |
Paul Gortmaker | bc3b2d7 | 2011-07-15 11:47:34 -0400 | [diff] [blame^] | 23 | #include <linux/export.h> |
Eric W. Biederman | 457c4cb | 2007-09-12 12:01:34 +0200 | [diff] [blame] | 24 | #include <net/net_namespace.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 25 | #include <net/sock.h> |
| 26 | #include <net/x25.h> |
| 27 | |
| 28 | #ifdef CONFIG_PROC_FS |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 29 | |
| 30 | 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] | 31 | __acquires(x25_route_list_lock) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 32 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 33 | read_lock_bh(&x25_route_list_lock); |
Li Zefan | 4f13420 | 2010-02-08 23:20:42 +0000 | [diff] [blame] | 34 | return seq_list_start_head(&x25_route_list, *pos); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 35 | } |
| 36 | |
| 37 | static void *x25_seq_route_next(struct seq_file *seq, void *v, loff_t *pos) |
| 38 | { |
Li Zefan | 4f13420 | 2010-02-08 23:20:42 +0000 | [diff] [blame] | 39 | return seq_list_next(v, &x25_route_list, pos); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 40 | } |
| 41 | |
| 42 | static void x25_seq_route_stop(struct seq_file *seq, void *v) |
Eric Dumazet | 6bf1574 | 2008-01-13 22:27:52 -0800 | [diff] [blame] | 43 | __releases(x25_route_list_lock) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 44 | { |
| 45 | read_unlock_bh(&x25_route_list_lock); |
| 46 | } |
| 47 | |
| 48 | static int x25_seq_route_show(struct seq_file *seq, void *v) |
| 49 | { |
Li Zefan | 4f13420 | 2010-02-08 23:20:42 +0000 | [diff] [blame] | 50 | struct x25_route *rt = list_entry(v, struct x25_route, node); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 51 | |
Li Zefan | 4f13420 | 2010-02-08 23:20:42 +0000 | [diff] [blame] | 52 | if (v == &x25_route_list) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 53 | 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 : "???"); |
| 61 | out: |
| 62 | return 0; |
YOSHIFUJI Hideaki | f8e1d201 | 2007-02-09 23:25:27 +0900 | [diff] [blame] | 63 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 64 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 65 | 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] | 66 | __acquires(x25_list_lock) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 67 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 68 | read_lock_bh(&x25_list_lock); |
Li Zefan | 32d2e3a | 2010-02-08 23:19:04 +0000 | [diff] [blame] | 69 | return seq_hlist_start_head(&x25_list, *pos); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 70 | } |
| 71 | |
| 72 | static void *x25_seq_socket_next(struct seq_file *seq, void *v, loff_t *pos) |
| 73 | { |
Li Zefan | 32d2e3a | 2010-02-08 23:19:04 +0000 | [diff] [blame] | 74 | return seq_hlist_next(v, &x25_list, pos); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 75 | } |
| 76 | |
| 77 | static void x25_seq_socket_stop(struct seq_file *seq, void *v) |
Eric Dumazet | 6bf1574 | 2008-01-13 22:27:52 -0800 | [diff] [blame] | 78 | __releases(x25_list_lock) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 79 | { |
| 80 | read_unlock_bh(&x25_list_lock); |
| 81 | } |
| 82 | |
| 83 | static 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 Zefan | 32d2e3a | 2010-02-08 23:19:04 +0000 | [diff] [blame] | 96 | s = sk_entry(v); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 97 | 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 Dumazet | 31e6d36 | 2009-06-17 19:05:41 -0700 | [diff] [blame] | 111 | sk_wmem_alloc_get(s), |
| 112 | sk_rmem_alloc_get(s), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 113 | s->sk_socket ? SOCK_INODE(s->sk_socket)->i_ino : 0L); |
| 114 | out: |
| 115 | return 0; |
YOSHIFUJI Hideaki | f8e1d201 | 2007-02-09 23:25:27 +0900 | [diff] [blame] | 116 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 117 | |
Andrew Hendry | c9c2e9d | 2007-02-08 13:35:18 -0800 | [diff] [blame] | 118 | 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] | 119 | __acquires(x25_forward_list_lock) |
Andrew Hendry | c9c2e9d | 2007-02-08 13:35:18 -0800 | [diff] [blame] | 120 | { |
Andrew Hendry | c9c2e9d | 2007-02-08 13:35:18 -0800 | [diff] [blame] | 121 | read_lock_bh(&x25_forward_list_lock); |
Li Zefan | 4f13420 | 2010-02-08 23:20:42 +0000 | [diff] [blame] | 122 | return seq_list_start_head(&x25_forward_list, *pos); |
Andrew Hendry | c9c2e9d | 2007-02-08 13:35:18 -0800 | [diff] [blame] | 123 | } |
| 124 | |
| 125 | static void *x25_seq_forward_next(struct seq_file *seq, void *v, loff_t *pos) |
| 126 | { |
Li Zefan | 4f13420 | 2010-02-08 23:20:42 +0000 | [diff] [blame] | 127 | return seq_list_next(v, &x25_forward_list, pos); |
Andrew Hendry | c9c2e9d | 2007-02-08 13:35:18 -0800 | [diff] [blame] | 128 | } |
| 129 | |
| 130 | static void x25_seq_forward_stop(struct seq_file *seq, void *v) |
Eric Dumazet | 6bf1574 | 2008-01-13 22:27:52 -0800 | [diff] [blame] | 131 | __releases(x25_forward_list_lock) |
Andrew Hendry | c9c2e9d | 2007-02-08 13:35:18 -0800 | [diff] [blame] | 132 | { |
| 133 | read_unlock_bh(&x25_forward_list_lock); |
| 134 | } |
| 135 | |
| 136 | static int x25_seq_forward_show(struct seq_file *seq, void *v) |
| 137 | { |
Li Zefan | 4f13420 | 2010-02-08 23:20:42 +0000 | [diff] [blame] | 138 | struct x25_forward *f = list_entry(v, struct x25_forward, node); |
Andrew Hendry | c9c2e9d | 2007-02-08 13:35:18 -0800 | [diff] [blame] | 139 | |
Li Zefan | 4f13420 | 2010-02-08 23:20:42 +0000 | [diff] [blame] | 140 | if (v == &x25_forward_list) { |
Andrew Hendry | c9c2e9d | 2007-02-08 13:35:18 -0800 | [diff] [blame] | 141 | 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 Hendry | c9c2e9d | 2007-02-08 13:35:18 -0800 | [diff] [blame] | 149 | out: |
| 150 | return 0; |
| 151 | } |
| 152 | |
Philippe De Muyter | 56b3d97 | 2007-07-10 23:07:31 -0700 | [diff] [blame] | 153 | static const struct seq_operations x25_seq_route_ops = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 154 | .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 Muyter | 56b3d97 | 2007-07-10 23:07:31 -0700 | [diff] [blame] | 160 | static const struct seq_operations x25_seq_socket_ops = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 161 | .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 Muyter | 56b3d97 | 2007-07-10 23:07:31 -0700 | [diff] [blame] | 167 | static const struct seq_operations x25_seq_forward_ops = { |
Andrew Hendry | c9c2e9d | 2007-02-08 13:35:18 -0800 | [diff] [blame] | 168 | .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 Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 174 | static int x25_seq_socket_open(struct inode *inode, struct file *file) |
| 175 | { |
| 176 | return seq_open(file, &x25_seq_socket_ops); |
| 177 | } |
| 178 | |
| 179 | static int x25_seq_route_open(struct inode *inode, struct file *file) |
| 180 | { |
| 181 | return seq_open(file, &x25_seq_route_ops); |
| 182 | } |
| 183 | |
Andrew Hendry | c9c2e9d | 2007-02-08 13:35:18 -0800 | [diff] [blame] | 184 | static 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 Ven | da7071d | 2007-02-12 00:55:36 -0800 | [diff] [blame] | 189 | static const struct file_operations x25_seq_socket_fops = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 190 | .owner = THIS_MODULE, |
| 191 | .open = x25_seq_socket_open, |
| 192 | .read = seq_read, |
| 193 | .llseek = seq_lseek, |
| 194 | .release = seq_release, |
| 195 | }; |
| 196 | |
Arjan van de Ven | da7071d | 2007-02-12 00:55:36 -0800 | [diff] [blame] | 197 | static const struct file_operations x25_seq_route_fops = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 198 | .owner = THIS_MODULE, |
| 199 | .open = x25_seq_route_open, |
| 200 | .read = seq_read, |
| 201 | .llseek = seq_lseek, |
| 202 | .release = seq_release, |
| 203 | }; |
| 204 | |
Jan Engelhardt | a1f6f5a | 2008-01-22 18:30:06 -0800 | [diff] [blame] | 205 | static const struct file_operations x25_seq_forward_fops = { |
Andrew Hendry | c9c2e9d | 2007-02-08 13:35:18 -0800 | [diff] [blame] | 206 | .owner = THIS_MODULE, |
| 207 | .open = x25_seq_forward_open, |
| 208 | .read = seq_read, |
| 209 | .llseek = seq_lseek, |
| 210 | .release = seq_release, |
| 211 | }; |
| 212 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 213 | static struct proc_dir_entry *x25_proc_dir; |
| 214 | |
| 215 | int __init x25_proc_init(void) |
| 216 | { |
| 217 | struct proc_dir_entry *p; |
| 218 | int rc = -ENOMEM; |
| 219 | |
Eric W. Biederman | 457c4cb | 2007-09-12 12:01:34 +0200 | [diff] [blame] | 220 | x25_proc_dir = proc_mkdir("x25", init_net.proc_net); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 221 | if (!x25_proc_dir) |
| 222 | goto out; |
| 223 | |
Wang Chen | 2335f8e | 2008-02-28 14:16:33 -0800 | [diff] [blame] | 224 | p = proc_create("route", S_IRUGO, x25_proc_dir, &x25_seq_route_fops); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 225 | if (!p) |
| 226 | goto out_route; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 227 | |
Wang Chen | 2335f8e | 2008-02-28 14:16:33 -0800 | [diff] [blame] | 228 | p = proc_create("socket", S_IRUGO, x25_proc_dir, &x25_seq_socket_fops); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 229 | if (!p) |
| 230 | goto out_socket; |
Andrew Hendry | c9c2e9d | 2007-02-08 13:35:18 -0800 | [diff] [blame] | 231 | |
Wang Chen | 2335f8e | 2008-02-28 14:16:33 -0800 | [diff] [blame] | 232 | p = proc_create("forward", S_IRUGO, x25_proc_dir, |
| 233 | &x25_seq_forward_fops); |
Andrew Hendry | c9c2e9d | 2007-02-08 13:35:18 -0800 | [diff] [blame] | 234 | if (!p) |
| 235 | goto out_forward; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 236 | rc = 0; |
Andrew Hendry | c9c2e9d | 2007-02-08 13:35:18 -0800 | [diff] [blame] | 237 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 238 | out: |
| 239 | return rc; |
Andrew Hendry | c9c2e9d | 2007-02-08 13:35:18 -0800 | [diff] [blame] | 240 | out_forward: |
| 241 | remove_proc_entry("socket", x25_proc_dir); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 242 | out_socket: |
| 243 | remove_proc_entry("route", x25_proc_dir); |
| 244 | out_route: |
Eric W. Biederman | 457c4cb | 2007-09-12 12:01:34 +0200 | [diff] [blame] | 245 | remove_proc_entry("x25", init_net.proc_net); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 246 | goto out; |
| 247 | } |
| 248 | |
| 249 | void __exit x25_proc_exit(void) |
| 250 | { |
Andrew Hendry | c9c2e9d | 2007-02-08 13:35:18 -0800 | [diff] [blame] | 251 | remove_proc_entry("forward", x25_proc_dir); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 252 | remove_proc_entry("route", x25_proc_dir); |
| 253 | remove_proc_entry("socket", x25_proc_dir); |
Eric W. Biederman | 457c4cb | 2007-09-12 12:01:34 +0200 | [diff] [blame] | 254 | remove_proc_entry("x25", init_net.proc_net); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 255 | } |
| 256 | |
| 257 | #else /* CONFIG_PROC_FS */ |
| 258 | |
| 259 | int __init x25_proc_init(void) |
| 260 | { |
| 261 | return 0; |
| 262 | } |
| 263 | |
| 264 | void __exit x25_proc_exit(void) |
| 265 | { |
| 266 | } |
| 267 | #endif /* CONFIG_PROC_FS */ |