root/fs/proc/net.c

/* [previous][next][first][last][top][bottom][index][help] */

DEFINITIONS

This source file includes following definitions.
  1. proc_lookupnet
  2. proc_readnetdir
  3. proc_readnet

   1 /*
   2  *  linux/fs/proc/net.c
   3  *
   4  *  Copyright (C) 1991, 1992 Linus Torvalds
   5  *
   6  *  gjh 3/'93 heim@peanuts.informatik.uni-tuebingen.de (Gerald J. Heim)
   7  *            most of this file is stolen from base.c
   8  *            it works, but you shouldn't use it as a guideline
   9  *            for new proc-fs entries. once i'll make it better.
  10  * fvk 3/'93  waltje@uwalt.nl.mugnet.org (Fred N. van Kempen)
  11  *            cleaned up the whole thing, moved "net" specific code to
  12  *            the NET kernel layer (where it belonged in the first place).
  13  * Michael K. Johnson (johnsonm@stolaf.edu) 3/93
  14  *            Added support from my previous inet.c.  Cleaned things up
  15  *            quite a bit, modularized the code.
  16  * fvk 4/'93  waltje@uwalt.nl.mugnet.org (Fred N. van Kempen)
  17  *            Renamed "route_get_info()" to "rt_get_info()" for consistency.
  18  * Alan Cox (gw4pts@gw4pts.ampr.org) 4/94
  19  *            Dusted off the code and added IPX. Fixed the 4K limit.
  20  * Erik Schoenfelder (schoenfr@ibr.cs.tu-bs.de)
  21  *            /proc/net/snmp.
  22  *
  23  *  proc net directory handling functions
  24  */
  25 #include <linux/autoconf.h>
  26 
  27 #include <asm/segment.h>
  28 
  29 #include <linux/errno.h>
  30 #include <linux/sched.h>
  31 #include <linux/proc_fs.h>
  32 #include <linux/stat.h>
  33 
  34 /* forward references */
  35 static int proc_readnet(struct inode * inode, struct file * file,
  36                          char * buf, int count);
  37 static int proc_readnetdir(struct inode *, struct file *,
  38                            struct dirent *, int);
  39 static int proc_lookupnet(struct inode *,const char *,int,struct inode **);
  40 
  41 /* the get_*_info() functions are in the net code, and are configured
  42    in via the standard mechanism... */
  43 extern int unix_get_info(char *, char **, off_t, int);
  44 #ifdef CONFIG_INET
  45 extern int tcp_get_info(char *, char **, off_t, int);
  46 extern int udp_get_info(char *, char **, off_t, int);
  47 extern int raw_get_info(char *, char **, off_t, int);
  48 extern int arp_get_info(char *, char **, off_t, int);
  49 extern int rarp_get_info(char *, char **, off_t, int);
  50 extern int dev_get_info(char *, char **, off_t, int);
  51 extern int rt_get_info(char *, char **, off_t, int);
  52 extern int snmp_get_info(char *, char **, off_t, int);
  53 #endif /* CONFIG_INET */
  54 #ifdef CONFIG_IPX
  55 extern int ipx_get_info(char *, char **, off_t, int);
  56 extern int ipx_rt_get_info(char *, char **, off_t, int);
  57 #endif /* CONFIG_IPX */
  58 #ifdef CONFIG_AX25
  59 extern int ax25_get_info(char *, char **, off_t, int);
  60 extern int ax25_rt_get_info(char *, char **, off_t, int);
  61 #ifdef CONFIG_NETROM
  62 extern int nr_get_info(char *, char **, off_t, int);
  63 extern int nr_nodes_get_info(char *, char **, off_t, int);
  64 extern int nr_neigh_get_info(char *, char **, off_t, int);
  65 #endif /* CONFIG_NETROM */
  66 #endif /* CONFIG_AX25 */
  67 
  68 
  69 static struct file_operations proc_net_operations = {
  70         NULL,                   /* lseek - default */
  71         proc_readnet,           /* read - bad */
  72         NULL,                   /* write - bad */
  73         proc_readnetdir,        /* readdir */
  74         NULL,                   /* select - default */
  75         NULL,                   /* ioctl - default */
  76         NULL,                   /* mmap */
  77         NULL,                   /* no special open code */
  78         NULL,                   /* no special release code */
  79         NULL                    /* can't fsync */
  80 };
  81 
  82 /*
  83  * proc directories can do almost nothing..
  84  */
  85 struct inode_operations proc_net_inode_operations = {
  86         &proc_net_operations,   /* default net directory file-ops */
  87         NULL,                   /* create */
  88         proc_lookupnet,         /* lookup */
  89         NULL,                   /* link */
  90         NULL,                   /* unlink */
  91         NULL,                   /* symlink */
  92         NULL,                   /* mkdir */
  93         NULL,                   /* rmdir */
  94         NULL,                   /* mknod */
  95         NULL,                   /* rename */
  96         NULL,                   /* readlink */
  97         NULL,                   /* follow_link */
  98         NULL,                   /* bmap */
  99         NULL,                   /* truncate */
 100         NULL                    /* permission */
 101 };
 102 
 103 static struct proc_dir_entry net_dir[] = {
 104         { PROC_NET,             1, "." },
 105         { PROC_ROOT_INO,        2, ".." },
 106         { PROC_NET_UNIX,        4, "unix" },
 107 #ifdef CONFIG_INET
 108         { PROC_NET_ARP,         3, "arp" },
 109         { PROC_NET_ROUTE,       5, "route" },
 110         { PROC_NET_DEV,         3, "dev" },
 111         { PROC_NET_RAW,         3, "raw" },
 112         { PROC_NET_TCP,         3, "tcp" },
 113         { PROC_NET_UDP,         3, "udp" },
 114         { PROC_NET_SNMP,        4, "snmp" },
 115 #ifdef CONFIG_INET_RARP
 116         { PROC_NET_RARP,        4, "rarp"},
 117 #endif
 118 #endif  /* CONFIG_INET */
 119 #ifdef CONFIG_IPX
 120         { PROC_NET_IPX_ROUTE,   9, "ipx_route" },
 121         { PROC_NET_IPX,         3, "ipx" },
 122 #endif /* CONFIG_IPX */
 123 #ifdef CONFIG_AX25
 124         { PROC_NET_AX25_ROUTE,  10, "ax25_route" },
 125         { PROC_NET_AX25,        4, "ax25" },
 126 #ifdef CONFIG_NETROM
 127         { PROC_NET_NR_NODES,    8, "nr_nodes" },
 128         { PROC_NET_NR_NEIGH,    8, "nr_neigh" },
 129         { PROC_NET_NR,          2, "nr" },
 130 #endif /* CONFIG_NETROM */
 131 #endif /* CONFIG_AX25 */
 132         { 0, 0, NULL }
 133 };
 134 
 135 #define NR_NET_DIRENTRY ((sizeof (net_dir))/(sizeof (net_dir[0])) - 1)
 136 
 137 static int proc_lookupnet(struct inode * dir,const char * name, int len,
     /* [previous][next][first][last][top][bottom][index][help] */
 138         struct inode ** result)
 139 {
 140         struct proc_dir_entry *de;
 141 
 142         *result = NULL;
 143         if (!dir)
 144                 return -ENOENT;
 145         if (!S_ISDIR(dir->i_mode)) {
 146                 iput(dir);
 147                 return -ENOENT;
 148         }
 149         for (de = net_dir ; de->name ; de++) {
 150                 if (!proc_match(len, name, de))
 151                         continue;
 152                 *result = iget(dir->i_sb, de->low_ino);
 153                 iput(dir);
 154                 if (!*result)
 155                         return -ENOENT;
 156                 return 0;
 157         }
 158         return -ENOENT;
 159 }
 160 
 161 static int proc_readnetdir(struct inode * inode, struct file * filp,
     /* [previous][next][first][last][top][bottom][index][help] */
 162         struct dirent * dirent, int count)
 163 {
 164         struct proc_dir_entry * de;
 165         unsigned int ino;
 166         int i,j;
 167 
 168         if (!inode || !S_ISDIR(inode->i_mode))
 169                 return -EBADF;
 170         ino = inode->i_ino;
 171         if (((unsigned) filp->f_pos) < NR_NET_DIRENTRY) {
 172                 de = net_dir + filp->f_pos;
 173                 filp->f_pos++;
 174                 i = de->namelen;
 175                 ino = de->low_ino;
 176                 put_fs_long(ino, &dirent->d_ino);
 177                 put_fs_word(i,&dirent->d_reclen);
 178                 put_fs_byte(0,i+dirent->d_name);
 179                 j = i;
 180                 while (i--)
 181                         put_fs_byte(de->name[i], i+dirent->d_name);
 182                 return j;
 183         }
 184         return 0;
 185 }
 186 
 187 
 188 #define PROC_BLOCK_SIZE (3*1024)                /* 4K page size but our output routines use some slack for overruns */
 189 
 190 static int proc_readnet(struct inode * inode, struct file * file,
     /* [previous][next][first][last][top][bottom][index][help] */
 191                         char * buf, int count)
 192 {
 193         char * page;
 194         int length;
 195         unsigned int ino;
 196         int bytes=count;
 197         int thistime;
 198         int copied=0;
 199         char *start;
 200 
 201         if (count < 0)
 202                 return -EINVAL;
 203         if (!(page = (char*) __get_free_page(GFP_KERNEL)))
 204                 return -ENOMEM;
 205         ino = inode->i_ino;
 206 
 207         while(bytes>0)
 208         {
 209                 thistime=bytes;
 210                 if(bytes>PROC_BLOCK_SIZE)
 211                         thistime=PROC_BLOCK_SIZE;
 212 
 213                 switch (ino) 
 214                 {
 215                         case PROC_NET_UNIX:
 216                                 length = unix_get_info(page,&start,file->f_pos,thistime);
 217                                 break;
 218 #ifdef CONFIG_INET
 219                         case PROC_NET_ARP:
 220                                 length = arp_get_info(page,&start,file->f_pos,thistime);
 221                                 break;
 222                         case PROC_NET_ROUTE:
 223                                 length = rt_get_info(page,&start,file->f_pos,thistime);
 224                                 break;
 225                         case PROC_NET_DEV:
 226                                 length = dev_get_info(page,&start,file->f_pos,thistime);
 227                                 break;
 228                         case PROC_NET_RAW:
 229                                 length = raw_get_info(page,&start,file->f_pos,thistime);
 230                                 break;
 231                         case PROC_NET_TCP:
 232                                 length = tcp_get_info(page,&start,file->f_pos,thistime);
 233                                 break;
 234                         case PROC_NET_UDP:
 235                                 length = udp_get_info(page,&start,file->f_pos,thistime);
 236                                 break;
 237                         case PROC_NET_SNMP:
 238                                 length = snmp_get_info(page, &start, file->f_pos,thistime);
 239                                 break;
 240 #ifdef CONFIG_INET_RARP                         
 241                         case PROC_NET_RARP:
 242                                 length = rarp_get_info(page,&start,file->f_pos,thistime);
 243                                 break;
 244 #endif /* CONFIG_INET_RARP */                           
 245 #endif /* CONFIG_INET */
 246 #ifdef CONFIG_IPX
 247                         case PROC_NET_IPX_ROUTE:
 248                                 length = ipx_rt_get_info(page,&start,file->f_pos,thistime);
 249                                 break;
 250                         case PROC_NET_IPX:
 251                                 length = ipx_get_info(page,&start,file->f_pos,thistime);
 252                                 break;
 253 #endif /* CONFIG_IPX */
 254 #ifdef CONFIG_AX25
 255                         case PROC_NET_AX25_ROUTE:
 256                                 length = ax25_rt_get_info(page,&start,file->f_pos,thistime);
 257                                 break;
 258                         case PROC_NET_AX25:
 259                                 length = ax25_get_info(page,&start,file->f_pos,thistime);
 260                                 break;
 261 #ifdef CONFIG_NETROM
 262                         case PROC_NET_NR_NODES:
 263                                 length = nr_nodes_get_info(page,&start,file->f_pos,thistime);
 264                                 break;
 265                         case PROC_NET_NR_NEIGH:
 266                                 length = nr_neigh_get_info(page,&start,file->f_pos,thistime);
 267                                 break;
 268                         case PROC_NET_NR:
 269                                 length = nr_get_info(page,&start,file->f_pos,thistime);
 270                                 break;
 271 #endif /* CONFIG_NETROM */
 272 #endif /* CONFIG_AX25 */
 273 
 274                         default:
 275                                 free_page((unsigned long) page);
 276                                 return -EBADF;
 277                 }
 278                 
 279                 /*
 280                  *      We have been given a non page aligned block of
 281                  *      the data we asked for + a bit. We have been given
 282                  *      the start pointer and we know the length.. 
 283                  */
 284 
 285                 if (length <= 0)
 286                         break;
 287                 /*
 288                  *      Copy the bytes
 289                  */
 290                 memcpy_tofs(buf+copied, start, length);
 291                 file->f_pos+=length;    /* Move down the file */
 292                 bytes-=length;
 293                 copied+=length;
 294                 if(length<thistime)
 295                         break;  /* End of file */
 296         }
 297         free_page((unsigned long) page);
 298         return copied;
 299 
 300 }

/* [previous][next][first][last][top][bottom][index][help] */