]> git.ipfire.org Git - people/arne_f/kernel.git/blame - net/atm/proc.c
License cleanup: add SPDX GPL-2.0 license identifier to files with no license
[people/arne_f/kernel.git] / net / atm / proc.c
CommitLineData
b2441318 1// SPDX-License-Identifier: GPL-2.0
1da177e4
LT
2/* net/atm/proc.c - ATM /proc interface
3 *
4 * Written 1995-2000 by Werner Almesberger, EPFL LRC/ICA
5 *
6 * seq_file api usage by romieu@fr.zoreil.com
7 *
8 * Evaluating the efficiency of the whole thing if left as an exercise to
9 * the reader.
10 */
11
1da177e4
LT
12#include <linux/module.h> /* for EXPORT_SYMBOL */
13#include <linux/string.h>
14#include <linux/types.h>
15#include <linux/mm.h>
16#include <linux/fs.h>
17#include <linux/stat.h>
18#include <linux/proc_fs.h>
19#include <linux/seq_file.h>
20#include <linux/errno.h>
21#include <linux/atm.h>
22#include <linux/atmdev.h>
23#include <linux/netdevice.h>
24#include <linux/atmclip.h>
25#include <linux/init.h> /* for __init */
5a0e3ad6 26#include <linux/slab.h>
457c4cbc 27#include <net/net_namespace.h>
1da177e4 28#include <net/atmclip.h>
07367adb
JP
29#include <linux/uaccess.h>
30#include <linux/param.h> /* for HZ */
60063497 31#include <linux/atomic.h>
1da177e4
LT
32#include "resources.h"
33#include "common.h" /* atm_proc_init prototype */
34#include "signaling.h" /* to get sigd - ugly too */
35
07367adb
JP
36static ssize_t proc_dev_atm_read(struct file *file, char __user *buf,
37 size_t count, loff_t *pos);
1da177e4 38
9a32144e 39static const struct file_operations proc_atm_dev_ops = {
1da177e4
LT
40 .owner = THIS_MODULE,
41 .read = proc_dev_atm_read,
6038f373 42 .llseek = noop_llseek,
1da177e4
LT
43};
44
45static void add_stats(struct seq_file *seq, const char *aal,
46 const struct k_atm_aal_stats *stats)
47{
48 seq_printf(seq, "%s ( %d %d %d %d %d )", aal,
07367adb
JP
49 atomic_read(&stats->tx), atomic_read(&stats->tx_err),
50 atomic_read(&stats->rx), atomic_read(&stats->rx_err),
51 atomic_read(&stats->rx_drop));
1da177e4
LT
52}
53
54static void atm_dev_info(struct seq_file *seq, const struct atm_dev *dev)
55{
56 int i;
57
58 seq_printf(seq, "%3d %-8s", dev->number, dev->type);
59 for (i = 0; i < ESI_LEN; i++)
60 seq_printf(seq, "%02x", dev->esi[i]);
61 seq_puts(seq, " ");
62 add_stats(seq, "0", &dev->stats.aal0);
63 seq_puts(seq, " ");
64 add_stats(seq, "5", &dev->stats.aal5);
458bc30c 65 seq_printf(seq, "\t[%d]", refcount_read(&dev->refcnt));
1da177e4
LT
66 seq_putc(seq, '\n');
67}
68
69struct vcc_state {
70 int bucket;
71 struct sock *sk;
72 int family;
73};
74
75static inline int compare_family(struct sock *sk, int family)
76{
77 return !family || (sk->sk_family == family);
78}
79
80static int __vcc_walk(struct sock **sock, int family, int *bucket, loff_t l)
81{
82 struct sock *sk = *sock;
83
2e1e9848 84 if (sk == SEQ_START_TOKEN) {
1da177e4
LT
85 for (*bucket = 0; *bucket < VCC_HTABLE_SIZE; ++*bucket) {
86 struct hlist_head *head = &vcc_hash[*bucket];
87
88 sk = hlist_empty(head) ? NULL : __sk_head(head);
89 if (sk)
90 break;
91 }
92 l--;
f7d57453 93 }
1da177e4
LT
94try_again:
95 for (; sk; sk = sk_next(sk)) {
96 l -= compare_family(sk, family);
97 if (l < 0)
98 goto out;
99 }
100 if (!sk && ++*bucket < VCC_HTABLE_SIZE) {
101 sk = sk_head(&vcc_hash[*bucket]);
102 goto try_again;
103 }
2e1e9848 104 sk = SEQ_START_TOKEN;
1da177e4
LT
105out:
106 *sock = sk;
107 return (l < 0);
108}
109
110static inline void *vcc_walk(struct vcc_state *state, loff_t l)
111{
112 return __vcc_walk(&state->sk, state->family, &state->bucket, l) ?
113 state : NULL;
114}
115
116static int __vcc_seq_open(struct inode *inode, struct file *file,
ececfdee 117 int family, const struct seq_operations *ops)
1da177e4
LT
118{
119 struct vcc_state *state;
1da177e4 120
9a8c09e7
PE
121 state = __seq_open_private(file, ops, sizeof(*state));
122 if (state == NULL)
123 return -ENOMEM;
1da177e4
LT
124
125 state->family = family;
9a8c09e7 126 return 0;
1da177e4
LT
127}
128
129static void *vcc_seq_start(struct seq_file *seq, loff_t *pos)
5c17d5f1 130 __acquires(vcc_sklist_lock)
1da177e4
LT
131{
132 struct vcc_state *state = seq->private;
133 loff_t left = *pos;
134
135 read_lock(&vcc_sklist_lock);
2e1e9848
JP
136 state->sk = SEQ_START_TOKEN;
137 return left ? vcc_walk(state, left) : SEQ_START_TOKEN;
1da177e4
LT
138}
139
140static void vcc_seq_stop(struct seq_file *seq, void *v)
5c17d5f1 141 __releases(vcc_sklist_lock)
1da177e4
LT
142{
143 read_unlock(&vcc_sklist_lock);
144}
145
146static void *vcc_seq_next(struct seq_file *seq, void *v, loff_t *pos)
147{
148 struct vcc_state *state = seq->private;
149
150 v = vcc_walk(state, 1);
151 *pos += !!PTR_ERR(v);
152 return v;
153}
154
155static void pvc_info(struct seq_file *seq, struct atm_vcc *vcc)
156{
07367adb
JP
157 static const char *const class_name[] = {
158 "off", "UBR", "CBR", "VBR", "ABR"};
36cbd3dc 159 static const char *const aal_name[] = {
1da177e4
LT
160 "---", "1", "2", "3/4", /* 0- 3 */
161 "???", "5", "???", "???", /* 4- 7 */
162 "???", "???", "???", "???", /* 8-11 */
163 "???", "0", "???", "???"}; /* 12-15 */
164
165 seq_printf(seq, "%3d %3d %5d %-3s %7d %-5s %7d %-6s",
07367adb
JP
166 vcc->dev->number, vcc->vpi, vcc->vci,
167 vcc->qos.aal >= ARRAY_SIZE(aal_name) ? "err" :
168 aal_name[vcc->qos.aal], vcc->qos.rxtp.min_pcr,
169 class_name[vcc->qos.rxtp.traffic_class],
170 vcc->qos.txtp.min_pcr,
171 class_name[vcc->qos.txtp.traffic_class]);
1da177e4
LT
172 if (test_bit(ATM_VF_IS_CLIP, &vcc->flags)) {
173 struct clip_vcc *clip_vcc = CLIP_VCC(vcc);
174 struct net_device *dev;
175
176 dev = clip_vcc->entry ? clip_vcc->entry->neigh->dev : NULL;
177 seq_printf(seq, "CLIP, Itf:%s, Encap:",
178 dev ? dev->name : "none?");
179 seq_printf(seq, "%s", clip_vcc->encap ? "LLC/SNAP" : "None");
180 }
181 seq_putc(seq, '\n');
182}
183
184static const char *vcc_state(struct atm_vcc *vcc)
185{
36cbd3dc 186 static const char *const map[] = { ATM_VS2TXT_MAP };
1da177e4
LT
187
188 return map[ATM_VF2VS(vcc->flags)];
189}
190
191static void vcc_info(struct seq_file *seq, struct atm_vcc *vcc)
192{
193 struct sock *sk = sk_atm(vcc);
194
71338aa7 195 seq_printf(seq, "%pK ", vcc);
1da177e4
LT
196 if (!vcc->dev)
197 seq_printf(seq, "Unassigned ");
f7d57453 198 else
1da177e4
LT
199 seq_printf(seq, "%3d %3d %5d ", vcc->dev->number, vcc->vpi,
200 vcc->vci);
201 switch (sk->sk_family) {
07367adb
JP
202 case AF_ATMPVC:
203 seq_printf(seq, "PVC");
204 break;
205 case AF_ATMSVC:
206 seq_printf(seq, "SVC");
207 break;
208 default:
209 seq_printf(seq, "%3d", sk->sk_family);
1da177e4 210 }
07367adb
JP
211 seq_printf(seq, " %04lx %5d %7d/%7d %7d/%7d [%d]\n",
212 vcc->flags, sk->sk_err,
213 sk_wmem_alloc_get(sk), sk->sk_sndbuf,
214 sk_rmem_alloc_get(sk), sk->sk_rcvbuf,
41c6d650 215 refcount_read(&sk->sk_refcnt));
1da177e4
LT
216}
217
218static void svc_info(struct seq_file *seq, struct atm_vcc *vcc)
219{
220 if (!vcc->dev)
221 seq_printf(seq, sizeof(void *) == 4 ?
71338aa7 222 "N/A@%pK%10s" : "N/A@%pK%2s", vcc, "");
1da177e4
LT
223 else
224 seq_printf(seq, "%3d %3d %5d ",
225 vcc->dev->number, vcc->vpi, vcc->vci);
226 seq_printf(seq, "%-10s ", vcc_state(vcc));
227 seq_printf(seq, "%s%s", vcc->remote.sas_addr.pub,
228 *vcc->remote.sas_addr.pub && *vcc->remote.sas_addr.prv ? "+" : "");
229 if (*vcc->remote.sas_addr.prv) {
230 int i;
231
232 for (i = 0; i < ATM_ESA_LEN; i++)
233 seq_printf(seq, "%02x", vcc->remote.sas_addr.prv[i]);
234 }
235 seq_putc(seq, '\n');
236}
237
238static int atm_dev_seq_show(struct seq_file *seq, void *v)
239{
240 static char atm_dev_banner[] =
241 "Itf Type ESI/\"MAC\"addr "
242 "AAL(TX,err,RX,err,drop) ... [refcnt]\n";
f7d57453 243
67de7924 244 if (v == &atm_devs)
1da177e4
LT
245 seq_puts(seq, atm_dev_banner);
246 else {
247 struct atm_dev *dev = list_entry(v, struct atm_dev, dev_list);
248
249 atm_dev_info(seq, dev);
250 }
f7d57453 251 return 0;
1da177e4 252}
f7d57453 253
56b3d975 254static const struct seq_operations atm_dev_seq_ops = {
1da177e4
LT
255 .start = atm_dev_seq_start,
256 .next = atm_dev_seq_next,
257 .stop = atm_dev_seq_stop,
258 .show = atm_dev_seq_show,
259};
f7d57453 260
1da177e4
LT
261static int atm_dev_seq_open(struct inode *inode, struct file *file)
262{
263 return seq_open(file, &atm_dev_seq_ops);
264}
f7d57453 265
9a32144e 266static const struct file_operations devices_seq_fops = {
1da177e4
LT
267 .open = atm_dev_seq_open,
268 .read = seq_read,
269 .llseek = seq_lseek,
270 .release = seq_release,
271};
272
273static int pvc_seq_show(struct seq_file *seq, void *v)
274{
f7d57453 275 static char atm_pvc_banner[] =
1da177e4
LT
276 "Itf VPI VCI AAL RX(PCR,Class) TX(PCR,Class)\n";
277
2e1e9848 278 if (v == SEQ_START_TOKEN)
1da177e4
LT
279 seq_puts(seq, atm_pvc_banner);
280 else {
281 struct vcc_state *state = seq->private;
282 struct atm_vcc *vcc = atm_sk(state->sk);
283
284 pvc_info(seq, vcc);
285 }
286 return 0;
287}
288
56b3d975 289static const struct seq_operations pvc_seq_ops = {
1da177e4
LT
290 .start = vcc_seq_start,
291 .next = vcc_seq_next,
292 .stop = vcc_seq_stop,
293 .show = pvc_seq_show,
294};
295
296static int pvc_seq_open(struct inode *inode, struct file *file)
297{
298 return __vcc_seq_open(inode, file, PF_ATMPVC, &pvc_seq_ops);
299}
300
9a32144e 301static const struct file_operations pvc_seq_fops = {
1da177e4
LT
302 .open = pvc_seq_open,
303 .read = seq_read,
304 .llseek = seq_lseek,
9a8c09e7 305 .release = seq_release_private,
1da177e4
LT
306};
307
308static int vcc_seq_show(struct seq_file *seq, void *v)
309{
2e1e9848 310 if (v == SEQ_START_TOKEN) {
f7d57453
YH
311 seq_printf(seq, sizeof(void *) == 4 ? "%-8s%s" : "%-16s%s",
312 "Address ", "Itf VPI VCI Fam Flags Reply "
313 "Send buffer Recv buffer [refcnt]\n");
314 } else {
315 struct vcc_state *state = seq->private;
316 struct atm_vcc *vcc = atm_sk(state->sk);
317
318 vcc_info(seq, vcc);
319 }
320 return 0;
1da177e4 321}
f7d57453 322
56b3d975 323static const struct seq_operations vcc_seq_ops = {
f7d57453
YH
324 .start = vcc_seq_start,
325 .next = vcc_seq_next,
326 .stop = vcc_seq_stop,
327 .show = vcc_seq_show,
1da177e4 328};
f7d57453 329
1da177e4
LT
330static int vcc_seq_open(struct inode *inode, struct file *file)
331{
f7d57453 332 return __vcc_seq_open(inode, file, 0, &vcc_seq_ops);
1da177e4 333}
f7d57453 334
9a32144e 335static const struct file_operations vcc_seq_fops = {
1da177e4
LT
336 .open = vcc_seq_open,
337 .read = seq_read,
338 .llseek = seq_lseek,
9a8c09e7 339 .release = seq_release_private,
1da177e4
LT
340};
341
342static int svc_seq_show(struct seq_file *seq, void *v)
343{
36cbd3dc 344 static const char atm_svc_banner[] =
1da177e4
LT
345 "Itf VPI VCI State Remote\n";
346
2e1e9848 347 if (v == SEQ_START_TOKEN)
1da177e4
LT
348 seq_puts(seq, atm_svc_banner);
349 else {
350 struct vcc_state *state = seq->private;
351 struct atm_vcc *vcc = atm_sk(state->sk);
352
353 svc_info(seq, vcc);
354 }
355 return 0;
356}
357
56b3d975 358static const struct seq_operations svc_seq_ops = {
1da177e4
LT
359 .start = vcc_seq_start,
360 .next = vcc_seq_next,
361 .stop = vcc_seq_stop,
362 .show = svc_seq_show,
363};
364
365static int svc_seq_open(struct inode *inode, struct file *file)
366{
367 return __vcc_seq_open(inode, file, PF_ATMSVC, &svc_seq_ops);
368}
369
9a32144e 370static const struct file_operations svc_seq_fops = {
1da177e4
LT
371 .open = svc_seq_open,
372 .read = seq_read,
373 .llseek = seq_lseek,
9a8c09e7 374 .release = seq_release_private,
1da177e4
LT
375};
376
377static ssize_t proc_dev_atm_read(struct file *file, char __user *buf,
378 size_t count, loff_t *pos)
379{
380 struct atm_dev *dev;
381 unsigned long page;
382 int length;
383
07367adb
JP
384 if (count == 0)
385 return 0;
1da177e4 386 page = get_zeroed_page(GFP_KERNEL);
07367adb
JP
387 if (!page)
388 return -ENOMEM;
d9dda78b 389 dev = PDE_DATA(file_inode(file));
1da177e4
LT
390 if (!dev->ops->proc_read)
391 length = -EINVAL;
392 else {
07367adb
JP
393 length = dev->ops->proc_read(dev, pos, (char *)page);
394 if (length > count)
395 length = -EINVAL;
1da177e4
LT
396 }
397 if (length >= 0) {
07367adb
JP
398 if (copy_to_user(buf, (char *)page, length))
399 length = -EFAULT;
1da177e4
LT
400 (*pos)++;
401 }
402 free_page(page);
403 return length;
404}
405
1da177e4
LT
406struct proc_dir_entry *atm_proc_root;
407EXPORT_SYMBOL(atm_proc_root);
408
409
410int atm_proc_dev_register(struct atm_dev *dev)
411{
1da177e4
LT
412 int error;
413
414 /* No proc info */
415 if (!dev->ops->proc_read)
416 return 0;
417
418 error = -ENOMEM;
62c97ac0 419 dev->proc_name = kasprintf(GFP_KERNEL, "%s:%d", dev->type, dev->number);
1da177e4
LT
420 if (!dev->proc_name)
421 goto err_out;
1da177e4 422
0c89652a
DL
423 dev->proc_entry = proc_create_data(dev->proc_name, 0, atm_proc_root,
424 &proc_atm_dev_ops, dev);
1da177e4
LT
425 if (!dev->proc_entry)
426 goto err_free_name;
1da177e4 427 return 0;
07367adb 428
1da177e4
LT
429err_free_name:
430 kfree(dev->proc_name);
431err_out:
432 return error;
433}
434
1da177e4
LT
435void atm_proc_dev_deregister(struct atm_dev *dev)
436{
437 if (!dev->ops->proc_read)
438 return;
439
440 remove_proc_entry(dev->proc_name, atm_proc_root);
441 kfree(dev->proc_name);
442}
443
444static struct atm_proc_entry {
445 char *name;
9a32144e 446 const struct file_operations *proc_fops;
1da177e4
LT
447 struct proc_dir_entry *dirent;
448} atm_proc_ents[] = {
449 { .name = "devices", .proc_fops = &devices_seq_fops },
450 { .name = "pvc", .proc_fops = &pvc_seq_fops },
451 { .name = "svc", .proc_fops = &svc_seq_fops },
452 { .name = "vc", .proc_fops = &vcc_seq_fops },
453 { .name = NULL, .proc_fops = NULL }
454};
455
456static void atm_proc_dirs_remove(void)
457{
458 static struct atm_proc_entry *e;
459
460 for (e = atm_proc_ents; e->name; e++) {
f7d57453 461 if (e->dirent)
1da177e4
LT
462 remove_proc_entry(e->name, atm_proc_root);
463 }
ece31ffd 464 remove_proc_entry("atm", init_net.proc_net);
1da177e4
LT
465}
466
467int __init atm_proc_init(void)
468{
469 static struct atm_proc_entry *e;
470 int ret;
471
e5d69b9f 472 atm_proc_root = proc_net_mkdir(&init_net, "atm", init_net.proc_net);
1da177e4
LT
473 if (!atm_proc_root)
474 goto err_out;
475 for (e = atm_proc_ents; e->name; e++) {
476 struct proc_dir_entry *dirent;
477
16e297b3
WC
478 dirent = proc_create(e->name, S_IRUGO,
479 atm_proc_root, e->proc_fops);
1da177e4
LT
480 if (!dirent)
481 goto err_out_remove;
1da177e4
LT
482 e->dirent = dirent;
483 }
484 ret = 0;
485out:
486 return ret;
487
488err_out_remove:
489 atm_proc_dirs_remove();
490err_out:
491 ret = -ENOMEM;
492 goto out;
493}
494
b9c6e3e9 495void atm_proc_exit(void)
1da177e4
LT
496{
497 atm_proc_dirs_remove();
498}