root/net/ipv4/proc.c

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

DEFINITIONS

This source file includes following definitions.
  1. get__netinfo
  2. tcp_get_info
  3. udp_get_info
  4. raw_get_info
  5. afinet_get_info
  6. snmp_get_info

   1 /*
   2  * INET         An implementation of the TCP/IP protocol suite for the LINUX
   3  *              operating system.  INET is implemented using the  BSD Socket
   4  *              interface as the means of communication with the user level.
   5  *
   6  *              This file implements the various access functions for the
   7  *              PROC file system.  It is mainly used for debugging and
   8  *              statistics.
   9  *
  10  * Version:     @(#)proc.c      1.0.5   05/27/93
  11  *
  12  * Authors:     Fred N. van Kempen, <waltje@uWalt.NL.Mugnet.ORG>
  13  *              Gerald J. Heim, <heim@peanuts.informatik.uni-tuebingen.de>
  14  *              Fred Baumgarten, <dc6iq@insu1.etec.uni-karlsruhe.de>
  15  *              Erik Schoenfelder, <schoenfr@ibr.cs.tu-bs.de>
  16  *
  17  * Fixes:
  18  *              Alan Cox        :       UDP sockets show the rxqueue/txqueue
  19  *                                      using hint flag for the netinfo.
  20  *      Pauline Middelink       :       identd support
  21  *              Alan Cox        :       Make /proc safer.
  22  *      Erik Schoenfelder       :       /proc/net/snmp
  23  *              Alan Cox        :       Handle dead sockets properly.
  24  *      Gerhard Koerting        :       Show both timers
  25  *              Alan Cox        :       Allow inode to be NULL (kernel socket)
  26  *
  27  *              This program is free software; you can redistribute it and/or
  28  *              modify it under the terms of the GNU General Public License
  29  *              as published by the Free Software Foundation; either version
  30  *              2 of the License, or (at your option) any later version.
  31  */
  32 #include <asm/system.h>
  33 #include <linux/sched.h>
  34 #include <linux/socket.h>
  35 #include <linux/net.h>
  36 #include <linux/un.h>
  37 #include <linux/in.h>
  38 #include <linux/param.h>
  39 #include <linux/inet.h>
  40 #include <linux/netdevice.h>
  41 #include <net/ip.h>
  42 #include <net/icmp.h>
  43 #include <net/protocol.h>
  44 #include <net/tcp.h>
  45 #include <net/udp.h>
  46 #include <linux/skbuff.h>
  47 #include <net/sock.h>
  48 #include <net/raw.h>
  49 
  50 /*
  51  * Get__netinfo returns the length of that string.
  52  *
  53  * KNOWN BUGS
  54  *  As in get_unix_netinfo, the buffer might be too small. If this
  55  *  happens, get__netinfo returns only part of the available infos.
  56  */
  57 static int
  58 get__netinfo(struct proto *pro, char *buffer, int format, char **start, off_t offset, int length)
     /* [previous][next][first][last][top][bottom][index][help] */
  59 {
  60         struct sock **s_array;
  61         struct sock *sp;
  62         int i;
  63         int timer_active;
  64         int timer_active1;
  65         int timer_active2;
  66         unsigned long timer_expires;
  67         unsigned long  dest, src;
  68         unsigned short destp, srcp;
  69         int len=0;
  70         off_t pos=0;
  71         off_t begin=0;
  72   
  73         s_array = pro->sock_array;
  74         len += sprintf(buffer, "sl  local_address rem_address   st tx_queue "
  75             "rx_queue tr tm->when uid inode\n");
  76 /*
  77  *      This was very pretty but didn't work when a socket is destroyed
  78  *      at the wrong moment (eg a syn recv socket getting a reset), or
  79  *      a memory timer destroy. Instead of playing with timers we just
  80  *      concede defeat and cli().
  81  */
  82         for(i = 0; i < SOCK_ARRAY_SIZE; i++) 
  83         {
  84                 cli();
  85                 sp = s_array[i];
  86                 while(sp != NULL) 
  87                 {
  88                         dest  = sp->daddr;
  89                         src   = sp->saddr;
  90                         destp = sp->dummy_th.dest;
  91                         srcp  = sp->dummy_th.source;
  92 
  93                         /* Since we are Little Endian we need to swap the bytes :-( */
  94                         destp = ntohs(destp);
  95                         srcp  = ntohs(srcp);
  96                         timer_active1 = del_timer(&sp->retransmit_timer);
  97                         timer_active2 = del_timer(&sp->timer);
  98                         if (!timer_active1) sp->retransmit_timer.expires=0;
  99                         if (!timer_active2) sp->timer.expires=0;
 100                         timer_active=0;
 101                         timer_expires=(unsigned)-1;
 102                         if (timer_active1 &&
 103                           sp->retransmit_timer.expires < timer_expires) {
 104                             timer_active=timer_active1;
 105                             timer_expires=sp->retransmit_timer.expires;
 106                         }
 107                         if (timer_active2 &&
 108                           sp->timer.expires < timer_expires) {
 109                             timer_active=timer_active2;
 110                             timer_expires=sp->timer.expires;
 111                         }
 112                         len += sprintf(buffer+len, "%2d: %08lX:%04X %08lX:%04X"
 113                             " %02X %08X:%08X %02X:%08lX %08X %d %d %ld\n",
 114                                 i, src, srcp, dest, destp, sp->state, 
 115                                 format==0?sp->write_seq-sp->rcv_ack_seq:sp->wmem_alloc, 
 116                                 format==0?sp->acked_seq-sp->copied_seq:sp->rmem_alloc,
 117                                 timer_active, timer_expires-jiffies, (unsigned) sp->retransmits,
 118                                 (sp->socket&&SOCK_INODE(sp->socket))?SOCK_INODE(sp->socket)->i_uid:0,
 119                                 timer_active?sp->timeout:0,
 120                                 sp->socket && SOCK_INODE(sp->socket) ?
 121                                 SOCK_INODE(sp->socket)->i_ino : 0);
 122                         if (timer_active1) add_timer(&sp->retransmit_timer);
 123                         if (timer_active2) add_timer(&sp->timer);
 124                         /*
 125                          * All sockets with (port mod SOCK_ARRAY_SIZE) = i
 126                          * are kept in sock_array[i], so we must follow the
 127                          * 'next' link to get them all.
 128                          */
 129                         sp = sp->next;
 130                         pos=begin+len;
 131                         if(pos<offset)
 132                         {
 133                                 len=0;
 134                                 begin=pos;
 135                         }
 136                         if(pos>offset+length)
 137                                 break;
 138                 }
 139                 sti();  /* We only turn interrupts back on for a moment,
 140                            but because the interrupt queues anything built
 141                            up before this will clear before we jump back
 142                            and cli(), so it's not as bad as it looks */
 143                 if(pos>offset+length)
 144                         break;
 145         }
 146         *start=buffer+(offset-begin);
 147         len-=(offset-begin);
 148         if(len>length)
 149                 len=length;
 150         return len;
 151 } 
 152 
 153 
 154 int tcp_get_info(char *buffer, char **start, off_t offset, int length, int dummy)
     /* [previous][next][first][last][top][bottom][index][help] */
 155 {
 156         return get__netinfo(&tcp_prot, buffer,0, start, offset, length);
 157 }
 158 
 159 
 160 int udp_get_info(char *buffer, char **start, off_t offset, int length, int dummy)
     /* [previous][next][first][last][top][bottom][index][help] */
 161 {
 162         return get__netinfo(&udp_prot, buffer,1, start, offset, length);
 163 }
 164 
 165 
 166 int raw_get_info(char *buffer, char **start, off_t offset, int length, int dummy)
     /* [previous][next][first][last][top][bottom][index][help] */
 167 {
 168         return get__netinfo(&raw_prot, buffer,1, start, offset, length);
 169 }
 170 
 171 
 172 /*
 173  *      Report socket allocation statistics [mea@utu.fi]
 174  */
 175 int afinet_get_info(char *buffer, char **start, off_t offset, int length, int dummy)
     /* [previous][next][first][last][top][bottom][index][help] */
 176 {
 177         /* From  net/socket.c  */
 178         extern int socket_get_info(char *, char **, off_t, int);
 179         extern struct proto packet_prot;
 180 
 181         int len  = socket_get_info(buffer,start,offset,length);
 182 
 183         len += sprintf(buffer+len,"SOCK_ARRAY_SIZE=%d\n",SOCK_ARRAY_SIZE);
 184         len += sprintf(buffer+len,"TCP: inuse %d highest %d\n",
 185                        tcp_prot.inuse, tcp_prot.highestinuse);
 186         len += sprintf(buffer+len,"UDP: inuse %d highest %d\n",
 187                        udp_prot.inuse, udp_prot.highestinuse);
 188         len += sprintf(buffer+len,"RAW: inuse %d highest %d\n",
 189                        raw_prot.inuse, raw_prot.highestinuse);
 190         len += sprintf(buffer+len,"PAC: inuse %d highest %d\n",
 191                        packet_prot.inuse, packet_prot.highestinuse);
 192         *start = buffer + offset;
 193         len -= offset;
 194         if (len > length)
 195                 len = length;
 196         return len;
 197 }
 198 
 199 
 200 /* 
 201  *      Called from the PROCfs module. This outputs /proc/net/snmp.
 202  */
 203  
 204 int snmp_get_info(char *buffer, char **start, off_t offset, int length, int dummy)
     /* [previous][next][first][last][top][bottom][index][help] */
 205 {
 206         extern struct tcp_mib tcp_statistics;
 207         extern struct udp_mib udp_statistics;
 208         int len;
 209 /*
 210   extern unsigned long tcp_rx_miss, tcp_rx_hit1,tcp_rx_hit2;
 211 */
 212 
 213         len = sprintf (buffer,
 214                 "Ip: Forwarding DefaultTTL InReceives InHdrErrors InAddrErrors ForwDatagrams InUnknownProtos InDiscards InDelivers OutRequests OutDiscards OutNoRoutes ReasmTimeout ReasmReqds ReasmOKs ReasmFails FragOKs FragFails FragCreates\n"
 215                 "Ip: %lu %lu %lu %lu %lu %lu %lu %lu %lu %lu %lu %lu %lu %lu %lu %lu %lu %lu %lu\n",
 216                     ip_statistics.IpForwarding, ip_statistics.IpDefaultTTL, 
 217                     ip_statistics.IpInReceives, ip_statistics.IpInHdrErrors, 
 218                     ip_statistics.IpInAddrErrors, ip_statistics.IpForwDatagrams, 
 219                     ip_statistics.IpInUnknownProtos, ip_statistics.IpInDiscards, 
 220                     ip_statistics.IpInDelivers, ip_statistics.IpOutRequests, 
 221                     ip_statistics.IpOutDiscards, ip_statistics.IpOutNoRoutes, 
 222                     ip_statistics.IpReasmTimeout, ip_statistics.IpReasmReqds, 
 223                     ip_statistics.IpReasmOKs, ip_statistics.IpReasmFails, 
 224                     ip_statistics.IpFragOKs, ip_statistics.IpFragFails, 
 225                     ip_statistics.IpFragCreates);
 226                                 
 227         len += sprintf (buffer + len,
 228                 "Icmp: InMsgs InErrors InDestUnreachs InTimeExcds InParmProbs InSrcQuenchs InRedirects InEchos InEchoReps InTimestamps InTimestampReps InAddrMasks InAddrMaskReps OutMsgs OutErrors OutDestUnreachs OutTimeExcds OutParmProbs OutSrcQuenchs OutRedirects OutEchos OutEchoReps OutTimestamps OutTimestampReps OutAddrMasks OutAddrMaskReps\n"
 229                 "Icmp: %lu %lu %lu %lu %lu %lu %lu %lu %lu %lu %lu %lu %lu %lu %lu %lu %lu %lu %lu %lu %lu %lu %lu %lu %lu %lu\n",
 230                     icmp_statistics.IcmpInMsgs, icmp_statistics.IcmpInErrors,
 231                     icmp_statistics.IcmpInDestUnreachs, icmp_statistics.IcmpInTimeExcds,
 232                     icmp_statistics.IcmpInParmProbs, icmp_statistics.IcmpInSrcQuenchs,
 233                     icmp_statistics.IcmpInRedirects, icmp_statistics.IcmpInEchos,
 234                     icmp_statistics.IcmpInEchoReps, icmp_statistics.IcmpInTimestamps,
 235                     icmp_statistics.IcmpInTimestampReps, icmp_statistics.IcmpInAddrMasks,
 236                     icmp_statistics.IcmpInAddrMaskReps, icmp_statistics.IcmpOutMsgs,
 237                     icmp_statistics.IcmpOutErrors, icmp_statistics.IcmpOutDestUnreachs,
 238                     icmp_statistics.IcmpOutTimeExcds, icmp_statistics.IcmpOutParmProbs,
 239                     icmp_statistics.IcmpOutSrcQuenchs, icmp_statistics.IcmpOutRedirects,
 240                     icmp_statistics.IcmpOutEchos, icmp_statistics.IcmpOutEchoReps,
 241                     icmp_statistics.IcmpOutTimestamps, icmp_statistics.IcmpOutTimestampReps,
 242                     icmp_statistics.IcmpOutAddrMasks, icmp_statistics.IcmpOutAddrMaskReps);
 243         
 244         len += sprintf (buffer + len,
 245                 "Tcp: RtoAlgorithm RtoMin RtoMax MaxConn ActiveOpens PassiveOpens AttemptFails EstabResets CurrEstab InSegs OutSegs RetransSegs\n"
 246                 "Tcp: %lu %lu %lu %lu %lu %lu %lu %lu %lu %lu %lu %lu\n",
 247                     tcp_statistics.TcpRtoAlgorithm, tcp_statistics.TcpRtoMin,
 248                     tcp_statistics.TcpRtoMax, tcp_statistics.TcpMaxConn,
 249                     tcp_statistics.TcpActiveOpens, tcp_statistics.TcpPassiveOpens,
 250                     tcp_statistics.TcpAttemptFails, tcp_statistics.TcpEstabResets,
 251                     tcp_statistics.TcpCurrEstab, tcp_statistics.TcpInSegs,
 252                     tcp_statistics.TcpOutSegs, tcp_statistics.TcpRetransSegs);
 253                 
 254         len += sprintf (buffer + len,
 255                 "Udp: InDatagrams NoPorts InErrors OutDatagrams\nUdp: %lu %lu %lu %lu\n",
 256                     udp_statistics.UdpInDatagrams, udp_statistics.UdpNoPorts,
 257                     udp_statistics.UdpInErrors, udp_statistics.UdpOutDatagrams);            
 258 /*      
 259           len += sprintf( buffer + len,
 260                 "TCP fast path RX:  H2: %ul H1: %ul L: %ul\n",
 261                         tcp_rx_hit2,tcp_rx_hit1,tcp_rx_miss);
 262 */
 263         
 264         if (offset >= len)
 265         {
 266                 *start = buffer;
 267                 return 0;
 268         }
 269         *start = buffer + offset;
 270         len -= offset;
 271         if (len > length)
 272                 len = length;
 273         return len;
 274 }

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