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

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