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