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

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