linux/net/atm/proc.c
<<
>>
Prefs
   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{
fdproc.c#L33uct [] class="sref">dev = list_entry(3cc_st3te *at3_vcc<3a> * 233                pvc_info3/a>(<3 href="+code=s class="sref">SEQ_Sa> *}
 file, GFP_KERNELline" name="L35GFP_KERNEL7}
 38_START_TOKEN" claef">dev)
 238ize_t dev)
 vsvc_seq_opsDEss="sref">file, r *sk->number_numberataef="+code=PF_AT>atae=v"
start  = dev)
, vcc-&70" class="line" n"> 370->next   = selengthf="net/atm/proc.engthe=v" cl-f">dev)
stop   = show   = seqdev)
, vcc-&70" class="line" n"> 370->file, >, pos)
ine" name="L378"> 378, (ass="*)f">dev)
39href="+code=seq" clas class="sref">SEQ_Slengthf="net/atm/proc.engthe=v" .c#L="sref">loff_t * 239t;selengthf="net/atm/proc.engthe=v" cl-f">dev)
pvc_seq_o3en
 39_START_TOKEN" class="sref">SEQ_Slengthf="net/atm/proc.engthe=v" .c#L="0{>                struct __v3c_seq39ize_t SEQ_Sa>py_toa href="net/atm/proca>py_toa hree=v"sref">file, ine" name="L377"> 377  (ass="*)f">dev)
pos)
 39href="+code=seq" clas class="class="sref">selengthf="net/atm/proc.engthe=v" cl-f">dev)
 339e *remote 378{++
fil400name="L286">
open           4 sk->file, =ag"line" name="L350ag"e=v"{
read           4 filellseek       4 = 
release     4  = <40static int 40struct class="sref">dev href=irtruct list_en_entclok 347sf">dev)
file, _entclok__v4owstatic const struct  40static const struct v == file, ch = list_entry(seq_pr4ntf        return "Address &qu4t; *"Send buffer4    R41                 /span>;
/* No href s="s */12                        4cc_st4te *dev)
, vcc-&70" class="line" n"> 370->at4_vcc<4a> * 347                vcc_info4/a>(<4 href="+code=s+code=inode" clerro" class="line" nerro"e=v" cl-f">dev)
 dev)
, sizeof(void *) == kas>, sizss="sref">file, GFP_KERNELline" name="L35GFP_KERNEL7vcc->remote(pos)
try(dev)
, vcc-&clok<="li> 42( 342static const struct  te_>ataef="+code=PF_ATihrefc/a>te_>atae=v"sref">file, >, vcc-&clok<="li>file, _entclokstart  = pos)
try(next   = dev)
, vcc-&clokstop   = show   = }
42static const struct  349s+code=inode" clerr_aree_="li>vcc_seq_o4en file, >, vcc-&clok<="li> 431+code=inode" clerr_ou6" class="line" err_ou6e=v":tatic const struct __v4c_seq4open( 433
 344static const struct fil4_operad="L3a href="+code=inode href="+cderegist9" class="line" name="href="+cderegist9"" class="sref">file, ch = list_entry(open           4         return read           4 dev)
, vcc-&70" class="line" n"> 370->llseek       4 =  release     4  = <43static const struct 439name="L286"> file, >, vcc-&clok<="li>file, _entclok 3440name="L286"> file, >, vcc-&clok<="li>svc_seq_s4ow
 44                ss="sref">file, ch = 4quot;Itf VPI VCI        4  Sta4e      Remote\ass="*350" id="L350" n"li> 344> *svc_seq_fops = {
remotev == dev href=irtruct list_en=ire*seq_puts4/a>(<4 href=}ef">file, ch =  =        return  34{t" class="sref">vc"li>vcc-> 2664cc_st4te *vc"li>vcc-> 301at4_vcc<4a> *vc"li>vcc-> 370 3451 *vc"li>vcc-> 335svc_info4/a>(<4 href="+code=s{t" class="sref">vc"li>vNULLline" name="L35NULLe=v"f= =s" =sseq_release_privailok<301" class="line" nalok<301"e=v"satmclass="sref">vNULLline" name="L35NULLe=v">

 45struct  3457        return ss="sref">file, ch = list_eni>start  = next   = SEQ_Si>state-&gclokloff_tloff_t                struct stop   = SEQ_Si>show   = "file, i>file, _entclok46href="+code=s
 346name="L314"> /ref">vcc-&clok<=et_remove class="line" nclok<=et_removee=v"st/atm/proc.c#L298" iinit<=et class="line" ninit<=et7vcc-> 313        } else {
svc_seq_o4en 46static __v4c_seq4openfile, _entclok 468                struct  3468START_TOKEN"t sss="sref">file, ch = list_eni>fil46de=dev" class=f="+code=inode" clret class="line" nreopen           4 static int read           4 sk-><_entclokvcc-> 313file, init<=et class="line" ninit<=et7llseek       4 = dev)
release     4  = <47href="+code=seq" clasgotos+code=inode" clerr_ou6" class="line" err_ou6e=v"
47      Remote\forlass="sref">SEQ_Si>state-&gclokloff_tloff_t                struct  347> *vcc href=irtruct list_en=ire*ssize_t  list_en=ire*tefile, i>file, S_IRUGO>f47href="+code=seq" clas class="> list_en_entclokloff_t *dev)
ire*4cc_st48(at4_vcc<48n>, SEQ_Si>dev)
ire* 248href="+code=s
pvc_info4/a>(<48name="L314"> /ref">vcc-&ret class="line" nre}
vcc-&ou6" class="line" ou6e=v":tatic const struct ef="+code=inode" classret class="line" nre 48                 248ize_t+code=inode" clerr_ou6_remove class="line" nerr_ou6_removee=v":tatic const struct  start  = next   =  dev)
stop   = show   = 49static const struct  249operad="L3a href="+code=inode hrefexit class="line" n_entclokpvc_seq_o4en        return  49_START_TOKEN" __v4c_seq498
 49href=




The original LXR software by the a href="nhttp://sourceforge.et/arocjects/lxr">LXR communitye=v" =this experimrucal version by a href="nmailto:lxr@linux.no">lxr@linux.no7
lxr.linux.no kindly hosted by a href="nhttp://www.redpill-linroc.no">Redpill Linroc ASe=v" =rocvider of Linux+a>