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

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