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 #include <linux/config.h>
  34 
  35 /* forward references */
  36 static int proc_readnet(struct inode * inode, struct file * file,
  37                          char * buf, int count);
  38 static int proc_readnetdir(struct inode *, struct file *,
  39                            struct dirent *, int);
  40 static int proc_lookupnet(struct inode *,const char *,int,struct inode **);
  41 
  42 /* the get_*_info() functions are in the net code, and are configured
  43    in via the standard mechanism... */
  44 extern int unix_get_info(char *, char **, off_t, int);
  45 #ifdef CONFIG_INET
  46 extern int tcp_get_info(char *, char **, off_t, int);
  47 extern int udp_get_info(char *, char **, off_t, int);
  48 extern int raw_get_info(char *, char **, off_t, int);
  49 extern int arp_get_info(char *, char **, off_t, int);
  50 extern int rarp_get_info(char *, char **, off_t, int);
  51 extern int dev_get_info(char *, char **, off_t, int);
  52 extern int rt_get_info(char *, char **, off_t, int);
  53 extern int snmp_get_info(char *, char **, off_t, int);
  54 extern int afinet_get_info(char *, char **, off_t, int);
  55 extern int ip_acct_procinfo(char *, char **, off_t, int);
  56 extern int ip_fw_blk_procinfo(char *, char **, off_t, int);
  57 extern int ip_fw_fwd_procinfo(char *, char **, off_t, int);
  58 extern int ip_mc_procinfo(char *, char **, off_t, int);
  59 #endif /* CONFIG_INET */
  60 #ifdef CONFIG_IPX
  61 extern int ipx_get_info(char *, char **, off_t, int);
  62 extern int ipx_rt_get_info(char *, char **, off_t, int);
  63 #endif /* CONFIG_IPX */
  64 #ifdef CONFIG_AX25
  65 extern int ax25_get_info(char *, char **, off_t, int);
  66 extern int ax25_rt_get_info(char *, char **, off_t, int);
  67 #ifdef CONFIG_NETROM
  68 extern int nr_get_info(char *, char **, off_t, int);
  69 extern int nr_nodes_get_info(char *, char **, off_t, int);
  70 extern int nr_neigh_get_info(char *, char **, off_t, int);
  71 #endif /* CONFIG_NETROM */
  72 #endif /* CONFIG_AX25 */
  73 
  74 
  75 static struct file_operations proc_net_operations = {
  76         NULL,                   /* lseek - default */
  77         proc_readnet,           /* read - bad */
  78         NULL,                   /* write - bad */
  79         proc_readnetdir,        /* readdir */
  80         NULL,                   /* select - default */
  81         NULL,                   /* ioctl - default */
  82         NULL,                   /* mmap */
  83         NULL,                   /* no special open code */
  84         NULL,                   /* no special release code */
  85         NULL                    /* can't fsync */
  86 };
  87 
  88 /*
  89  * proc directories can do almost nothing..
  90  */
  91 struct inode_operations proc_net_inode_operations = {
  92         &proc_net_operations,   /* default net directory file-ops */
  93         NULL,                   /* create */
  94         proc_lookupnet,         /* lookup */
  95         NULL,                   /* link */
  96         NULL,                   /* unlink */
  97         NULL,                   /* symlink */
  98         NULL,                   /* mkdir */
  99         NULL,                   /* rmdir */
 100         NULL,                   /* mknod */
 101         NULL,                   /* rename */
 102         NULL,                   /* readlink */
 103         NULL,                   /* follow_link */
 104         NULL,                   /* bmap */
 105         NULL,                   /* truncate */
 106         NULL                    /* permission */
 107 };
 108 
 109 static struct proc_dir_entry net_dir[] = {
 110         { PROC_NET,             1, "." },
 111         { PROC_ROOT_INO,        2, ".." },
 112         { PROC_NET_UNIX,        4, "unix" },
 113 #ifdef CONFIG_INET
 114         { PROC_NET_ARP,         3, "arp" },
 115         { PROC_NET_ROUTE,       5, "route" },
 116         { PROC_NET_DEV,         3, "dev" },
 117         { PROC_NET_RAW,         3, "raw" },
 118         { PROC_NET_TCP,         3, "tcp" },
 119         { PROC_NET_UDP,         3, "udp" },
 120         { PROC_NET_SNMP,        4, "snmp" },
 121         { PROC_NET_SOCKSTAT,    8, "sockstat" },
 122 #ifdef CONFIG_INET_RARP
 123         { PROC_NET_RARP,        4, "rarp"},
 124 #endif
 125 #ifdef CONFIG_IP_MULTICAST
 126         { PROC_NET_IGMP,        4, "igmp"},
 127 #endif
 128 #ifdef CONFIG_IP_FIREWALL
 129         { PROC_NET_IPFWFWD,     10, "ip_forward"},
 130         { PROC_NET_IPBLFWD,     8,  "ip_block"},
 131 #endif
 132 #ifdef CONFIG_IP_ACCT
 133         { PROC_NET_IPACCT,      7,  "ip_acct"},
 134 #endif
 135 #endif  /* CONFIG_INET */
 136 #ifdef CONFIG_IPX
 137         { PROC_NET_IPX_ROUTE,   9, "ipx_route" },
 138         { PROC_NET_IPX,         3, "ipx" },
 139 #endif /* CONFIG_IPX */
 140 #ifdef CONFIG_AX25
 141         { PROC_NET_AX25_ROUTE,  10, "ax25_route" },
 142         { PROC_NET_AX25,        4, "ax25" },
 143 #ifdef CONFIG_NETROM
 144         { PROC_NET_NR_NODES,    8, "nr_nodes" },
 145         { PROC_NET_NR_NEIGH,    8, "nr_neigh" },
 146         { PROC_NET_NR,          2, "nr" },
 147 #endif /* CONFIG_NETROM */
 148 #endif /* CONFIG_AX25 */
 149         { 0, 0, NULL }
 150 };
 151 
 152 #define NR_NET_DIRENTRY ((sizeof (net_dir))/(sizeof (net_dir[0])) - 1)
 153 
 154 static int proc_lookupnet(struct inode * dir,const char * name, int len,
     /* [previous][next][first][last][top][bottom][index][help] */
 155         struct inode ** result)
 156 {
 157         struct proc_dir_entry *de;
 158 
 159         *result = NULL;
 160         if (!dir)
 161                 return -ENOENT;
 162         if (!S_ISDIR(dir->i_mode)) {
 163                 iput(dir);
 164                 return -ENOENT;
 165         }
 166         for (de = net_dir ; de->name ; de++) {
 167                 if (!proc_match(len, name, de))
 168                         continue;
 169                 *result = iget(dir->i_sb, de->low_ino);
 170                 iput(dir);
 171                 if (!*result)
 172                         return -ENOENT;
 173                 return 0;
 174         }
 175         iput(dir);
 176         return -ENOENT;
 177 }
 178 
 179 static int proc_readnetdir(struct inode * inode, struct file * filp,
     /* [previous][next][first][last][top][bottom][index][help] */
 180         struct dirent * dirent, int count)
 181 {
 182         struct proc_dir_entry * de;
 183         unsigned int ino;
 184         int i,j;
 185 
 186         if (!inode || !S_ISDIR(inode->i_mode))
 187                 return -EBADF;
 188         ino = inode->i_ino;
 189         if (((unsigned) filp->f_pos) < NR_NET_DIRENTRY) {
 190                 de = net_dir + filp->f_pos;
 191                 filp->f_pos++;
 192                 i = de->namelen;
 193                 ino = de->low_ino;
 194                 put_fs_long(ino, &dirent->d_ino);
 195                 put_fs_word(i,&dirent->d_reclen);
 196                 put_fs_byte(0,i+dirent->d_name);
 197                 j = i;
 198                 while (i--)
 199                         put_fs_byte(de->name[i], i+dirent->d_name);
 200                 return j;
 201         }
 202         return 0;
 203 }
 204 
 205 
 206 #define PROC_BLOCK_SIZE (3*1024)                /* 4K page size but our output routines use some slack for overruns */
 207 
 208 static int proc_readnet(struct inode * inode, struct file * file,
     /* [previous][next][first][last][top][bottom][index][help] */
 209                         char * buf, int count)
 210 {
 211         char * page;
 212         int length;
 213         unsigned int ino;
 214         int bytes=count;
 215         int thistime;
 216         int copied=0;
 217         char *start;
 218 
 219         if (count < 0)
 220                 return -EINVAL;
 221         if (!(page = (char*) __get_free_page(GFP_KERNEL)))
 222                 return -ENOMEM;
 223         ino = inode->i_ino;
 224 
 225         while(bytes>0)
 226         {
 227                 thistime=bytes;
 228                 if(bytes>PROC_BLOCK_SIZE)
 229                         thistime=PROC_BLOCK_SIZE;
 230 
 231                 switch (ino) 
 232                 {
 233                         case PROC_NET_UNIX:
 234                                 length = unix_get_info(page,&start,file->f_pos,thistime);
 235                                 break;
 236 #ifdef CONFIG_INET
 237                         case PROC_NET_SOCKSTAT:
 238                                 length = afinet_get_info(page,&start,file->f_pos,thistime);
 239                                 break;
 240                         case PROC_NET_ARP:
 241                                 length = arp_get_info(page,&start,file->f_pos,thistime);
 242                                 break;
 243                         case PROC_NET_ROUTE:
 244                                 length = rt_get_info(page,&start,file->f_pos,thistime);
 245                                 break;
 246                         case PROC_NET_DEV:
 247                                 length = dev_get_info(page,&start,file->f_pos,thistime);
 248                                 break;
 249                         case PROC_NET_RAW:
 250                                 length = raw_get_info(page,&start,file->f_pos,thistime);
 251                                 break;
 252                         case PROC_NET_TCP:
 253                                 length = tcp_get_info(page,&start,file->f_pos,thistime);
 254                                 break;
 255                         case PROC_NET_UDP:
 256                                 length = udp_get_info(page,&start,file->f_pos,thistime);
 257                                 break;
 258                         case PROC_NET_SNMP:
 259                                 length = snmp_get_info(page, &start, file->f_pos,thistime);
 260                                 break;
 261 #ifdef CONFIG_IP_MULTICAST
 262                         case PROC_NET_IGMP:
 263                                 length = ip_mc_procinfo(page, &start, file->f_pos,thistime);
 264                                 break;
 265 #endif
 266 #ifdef CONFIG_IP_FIREWALL
 267                         case PROC_NET_IPFWFWD:
 268                                 length = ip_fw_fwd_procinfo(page, &start, file->f_pos,thistime);
 269                                 break;
 270                         case PROC_NET_IPBLFWD:
 271                                 length = ip_fw_blk_procinfo(page, &start, file->f_pos,thistime);
 272                                 break;
 273 #endif
 274 #ifdef CONFIG_IP_ACCT
 275                         case PROC_NET_IPACCT:
 276                                 length = ip_acct_procinfo(page, &start, file->f_pos,thistime);
 277                                 break;
 278 #endif
 279 #ifdef CONFIG_INET_RARP                         
 280                         case PROC_NET_RARP:
 281                                 length = rarp_get_info(page,&start,file->f_pos,thistime);
 282                                 break;
 283 #endif /* CONFIG_INET_RARP */                           
 284 #endif /* CONFIG_INET */
 285 #ifdef CONFIG_IPX
 286                         case PROC_NET_IPX_ROUTE:
 287                                 length = ipx_rt_get_info(page,&start,file->f_pos,thistime);
 288                                 break;
 289                         case PROC_NET_IPX:
 290                                 length = ipx_get_info(page,&start,file->f_pos,thistime);
 291                                 break;
 292 #endif /* CONFIG_IPX */
 293 #ifdef CONFIG_AX25
 294                         case PROC_NET_AX25_ROUTE:
 295                                 length = ax25_rt_get_info(page,&start,file->f_pos,thistime);
 296                                 break;
 297                         case PROC_NET_AX25:
 298                                 length = ax25_get_info(page,&start,file->f_pos,thistime);
 299                                 break;
 300 #ifdef CONFIG_NETROM
 301                         case PROC_NET_NR_NODES:
 302                                 length = nr_nodes_get_info(page,&start,file->f_pos,thistime);
 303                                 break;
 304                         case PROC_NET_NR_NEIGH:
 305                                 length = nr_neigh_get_info(page,&start,file->f_pos,thistime);
 306                                 break;
 307                         case PROC_NET_NR:
 308                                 length = nr_get_info(page,&start,file->f_pos,thistime);
 309                                 break;
 310 #endif /* CONFIG_NETROM */
 311 #endif /* CONFIG_AX25 */
 312 
 313                         default:
 314                                 free_page((unsigned long) page);
 315                                 return -EBADF;
 316                 }
 317                 
 318                 /*
 319                  *      We have been given a non page aligned block of
 320                  *      the data we asked for + a bit. We have been given
 321                  *      the start pointer and we know the length.. 
 322                  */
 323 
 324                 if (length <= 0)
 325                         break;
 326                 /*
 327                  *      Copy the bytes
 328                  */
 329                 memcpy_tofs(buf+copied, start, length);
 330                 file->f_pos+=length;    /* Move down the file */
 331                 bytes-=length;
 332                 copied+=length;
 333                 if(length<thistime)
 334                         break;  /* End of file */
 335         }
 336         free_page((unsigned long) page);
 337         return copied;
 338 
 339 }

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