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

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