root/net/inet/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  *
  25  *              This program is free software; you can redistribute it and/or
  26  *              modify it under the terms of the GNU General Public License
  27  *              as published by the Free Software Foundation; either version
  28  *              2 of the License, or (at your option) any later version.
  29  */
  30 #include <asm/system.h>
  31 #include <linux/autoconf.h>
  32 #include <linux/sched.h>
  33 #include <linux/socket.h>
  34 #include <linux/net.h>
  35 #include <linux/un.h>
  36 #include <linux/in.h>
  37 #include <linux/param.h>
  38 #include <linux/inet.h>
  39 #include <linux/netdevice.h>
  40 #include "ip.h"
  41 #include "icmp.h"
  42 #include "protocol.h"
  43 #include "tcp.h"
  44 #include "udp.h"
  45 #include <linux/skbuff.h>
  46 #include "sock.h"
  47 #include "raw.h"
  48 
  49 /*
  50  * Get__netinfo returns the length of that string.
  51  *
  52  * KNOWN BUGS
  53  *  As in get_unix_netinfo, the buffer might be too small. If this
  54  *  happens, get__netinfo returns only part of the available infos.
  55  */
  56 static int
  57 get__netinfo(struct proto *pro, char *buffer, int format, char **start, off_t offset, int length)
     /* [previous][next][first][last][top][bottom][index][help] */
  58 {
  59         struct sock **s_array;
  60         struct sock *sp;
  61         int i;
  62         int timer_active;
  63         unsigned long  dest, src;
  64         unsigned short destp, srcp;
  65         int len=0;
  66         off_t pos=0;
  67         off_t begin=0;
  68   
  69         s_array = pro->sock_array;
  70         len+=sprintf(buffer, "sl  local_address rem_address   st tx_queue rx_queue tr tm->when uid\n");
  71 /*
  72  *      This was very pretty but didn't work when a socket is destroyed at the wrong moment
  73  *      (eg a syn recv socket getting a reset), or a memory timer destroy. Instead of playing
  74  *      with timers we just concede defeat and cli().
  75  */
  76         for(i = 0; i < SOCK_ARRAY_SIZE; i++) 
  77         {
  78                 cli();
  79                 sp = s_array[i];
  80                 while(sp != NULL) 
  81                 {
  82                         dest  = sp->daddr;
  83                         src   = sp->saddr;
  84                         destp = sp->dummy_th.dest;
  85                         srcp  = sp->dummy_th.source;
  86 
  87                         /* Since we are Little Endian we need to swap the bytes :-( */
  88                         destp = ntohs(destp);
  89                         srcp  = ntohs(srcp);
  90                         timer_active = del_timer(&sp->timer);
  91                         if (!timer_active)
  92                                 sp->timer.expires = 0;
  93                         len+=sprintf(buffer+len, "%2d: %08lX:%04X %08lX:%04X %02X %08lX:%08lX %02X:%08lX %08X %d %d\n",
  94                                 i, src, srcp, dest, destp, sp->state, 
  95                                 format==0?sp->write_seq-sp->rcv_ack_seq:sp->rmem_alloc, 
  96                                 format==0?sp->acked_seq-sp->copied_seq:sp->wmem_alloc,
  97                                 timer_active, sp->timer.expires, (unsigned) sp->retransmits,
  98                                 sp->socket?SOCK_INODE(sp->socket)->i_uid:0,
  99                                 timer_active?sp->timeout:0);
 100                         if (timer_active)
 101                                 add_timer(&sp->timer);
 102                         /*
 103                          * All sockets with (port mod SOCK_ARRAY_SIZE) = i
 104                          * are kept in sock_array[i], so we must follow the
 105                          * 'next' link to get them all.
 106                          */
 107                         sp = sp->next;
 108                         pos=begin+len;
 109                         if(pos<offset)
 110                         {
 111                                 len=0;
 112                                 begin=pos;
 113                         }
 114                         if(pos>offset+length)
 115                                 break;
 116                 }
 117                 sti();  /* We only turn interrupts back on for a moment, but because the interrupt queues anything built up
 118                            before this will clear before we jump back and cli, so it's not as bad as it looks */
 119                 if(pos>offset+length)
 120                         break;
 121         }
 122         *start=buffer+(offset-begin);
 123         len-=(offset-begin);
 124         if(len>length)
 125                 len=length;
 126         return len;
 127 } 
 128 
 129 
 130 int tcp_get_info(char *buffer, char **start, off_t offset, int length)
     /* [previous][next][first][last][top][bottom][index][help] */
 131 {
 132         return get__netinfo(&tcp_prot, buffer,0, start, offset, length);
 133 }
 134 
 135 
 136 int udp_get_info(char *buffer, char **start, off_t offset, int length)
     /* [previous][next][first][last][top][bottom][index][help] */
 137 {
 138         return get__netinfo(&udp_prot, buffer,1, start, offset, length);
 139 }
 140 
 141 
 142 int raw_get_info(char *buffer, char **start, off_t offset, int length)
     /* [previous][next][first][last][top][bottom][index][help] */
 143 {
 144         return get__netinfo(&raw_prot, buffer,1, start, offset, length);
 145 }
 146 
 147 
 148 /*
 149  *      Report socket allocation statistics [mea@utu.fi]
 150  */
 151 int afinet_get_info(char *buffer, char **start, off_t offset, int length)
     /* [previous][next][first][last][top][bottom][index][help] */
 152 {
 153         /* From  net/socket.c  */
 154         extern int socket_get_info(char *, char **, off_t, int);
 155         extern struct proto packet_prot;
 156 
 157         int len  = socket_get_info(buffer,start,offset,length);
 158 
 159         len += sprintf(buffer+len,"SOCK_ARRAY_SIZE=%d\n",SOCK_ARRAY_SIZE);
 160         len += sprintf(buffer+len,"TCP: inuse %d highest %d\n",
 161                        tcp_prot.inuse, tcp_prot.highestinuse);
 162         len += sprintf(buffer+len,"UDP: inuse %d highest %d\n",
 163                        udp_prot.inuse, udp_prot.highestinuse);
 164         len += sprintf(buffer+len,"RAW: inuse %d highest %d\n",
 165                        raw_prot.inuse, raw_prot.highestinuse);
 166         len += sprintf(buffer+len,"PAC: inuse %d highest %d\n",
 167                        packet_prot.inuse, packet_prot.highestinuse);
 168         *start = buffer + offset;
 169         len -= offset;
 170         if (len > length)
 171                 len = length;
 172         return len;
 173 }
 174 
 175 
 176 /* 
 177  *      Called from the PROCfs module. This outputs /proc/net/snmp.
 178  */
 179  
 180 int snmp_get_info(char *buffer, char **start, off_t offset, int length)
     /* [previous][next][first][last][top][bottom][index][help] */
 181 {
 182         extern struct tcp_mib tcp_statistics;
 183         extern struct udp_mib udp_statistics;
 184         int len;
 185 /*
 186   extern unsigned long tcp_rx_miss, tcp_rx_hit1,tcp_rx_hit2;
 187 */
 188 
 189         len = sprintf (buffer,
 190                 "Ip: Forwarding DefaultTTL InReceives InHdrErrors InAddrErrors ForwDatagrams InUnknownProtos InDiscards InDelivers OutRequests OutDiscards OutNoRoutes ReasmTimeout ReasmReqds ReasmOKs ReasmFails FragOKs FragFails FragCreates\n"
 191                 "Ip: %lu %lu %lu %lu %lu %lu %lu %lu %lu %lu %lu %lu %lu %lu %lu %lu %lu %lu %lu\n",
 192                     ip_statistics.IpForwarding, ip_statistics.IpDefaultTTL, 
 193                     ip_statistics.IpInReceives, ip_statistics.IpInHdrErrors, 
 194                     ip_statistics.IpInAddrErrors, ip_statistics.IpForwDatagrams, 
 195                     ip_statistics.IpInUnknownProtos, ip_statistics.IpInDiscards, 
 196                     ip_statistics.IpInDelivers, ip_statistics.IpOutRequests, 
 197                     ip_statistics.IpOutDiscards, ip_statistics.IpOutNoRoutes, 
 198                     ip_statistics.IpReasmTimeout, ip_statistics.IpReasmReqds, 
 199                     ip_statistics.IpReasmOKs, ip_statistics.IpReasmFails, 
 200                     ip_statistics.IpFragOKs, ip_statistics.IpFragFails, 
 201                     ip_statistics.IpFragCreates);
 202                                 
 203         len += sprintf (buffer + len,
 204                 "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"
 205                 "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",
 206                     icmp_statistics.IcmpInMsgs, icmp_statistics.IcmpInErrors,
 207                     icmp_statistics.IcmpInDestUnreachs, icmp_statistics.IcmpInTimeExcds,
 208                     icmp_statistics.IcmpInParmProbs, icmp_statistics.IcmpInSrcQuenchs,
 209                     icmp_statistics.IcmpInRedirects, icmp_statistics.IcmpInEchos,
 210                     icmp_statistics.IcmpInEchoReps, icmp_statistics.IcmpInTimestamps,
 211                     icmp_statistics.IcmpInTimestampReps, icmp_statistics.IcmpInAddrMasks,
 212                     icmp_statistics.IcmpInAddrMaskReps, icmp_statistics.IcmpOutMsgs,
 213                     icmp_statistics.IcmpOutErrors, icmp_statistics.IcmpOutDestUnreachs,
 214                     icmp_statistics.IcmpOutTimeExcds, icmp_statistics.IcmpOutParmProbs,
 215                     icmp_statistics.IcmpOutSrcQuenchs, icmp_statistics.IcmpOutRedirects,
 216                     icmp_statistics.IcmpOutEchos, icmp_statistics.IcmpOutEchoReps,
 217                     icmp_statistics.IcmpOutTimestamps, icmp_statistics.IcmpOutTimestampReps,
 218                     icmp_statistics.IcmpOutAddrMasks, icmp_statistics.IcmpOutAddrMaskReps);
 219         
 220         len += sprintf (buffer + len,
 221                 "Tcp: RtoAlgorithm RtoMin RtoMax MaxConn ActiveOpens PassiveOpens AttemptFails EstabResets CurrEstab InSegs OutSegs RetransSegs\n"
 222                 "Tcp: %lu %lu %lu %lu %lu %lu %lu %lu %lu %lu %lu %lu\n",
 223                     tcp_statistics.TcpRtoAlgorithm, tcp_statistics.TcpRtoMin,
 224                     tcp_statistics.TcpRtoMax, tcp_statistics.TcpMaxConn,
 225                     tcp_statistics.TcpActiveOpens, tcp_statistics.TcpPassiveOpens,
 226                     tcp_statistics.TcpAttemptFails, tcp_statistics.TcpEstabResets,
 227                     tcp_statistics.TcpCurrEstab, tcp_statistics.TcpInSegs,
 228                     tcp_statistics.TcpOutSegs, tcp_statistics.TcpRetransSegs);
 229                 
 230         len += sprintf (buffer + len,
 231                 "Udp: InDatagrams NoPorts InErrors OutDatagrams\nUdp: %lu %lu %lu %lu\n",
 232                     udp_statistics.UdpInDatagrams, udp_statistics.UdpNoPorts,
 233                     udp_statistics.UdpInErrors, udp_statistics.UdpOutDatagrams);            
 234 /*      
 235           len += sprintf( buffer + len,
 236                 "TCP fast path RX:  H2: %ul H1: %ul L: %ul\n",
 237                         tcp_rx_hit2,tcp_rx_hit1,tcp_rx_miss);
 238 */
 239         
 240         if (offset >= len)
 241         {
 242                 *start = buffer;
 243                 return 0;
 244         }
 245         *start = buffer + offset;
 246         len -= offset;
 247         if (len > length)
 248                 len = length;
 249         return len;
 250 }
 251 

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