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

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