/* * INET An implementation of the TCP/IP protocol suite for the LINUX * operating system. INET is implemented using the BSD Socket * interface as the means of communication with the user level. * * This file implements the various access functions for the * PROC file system. It is mainly used for debugging and * statistics. * * Version: $Id: proc.c,v 1.41 2000/01/21 23:45:57 davem Exp $ * * Authors: Fred N. van Kempen, * Gerald J. Heim, * Fred Baumgarten, * Erik Schoenfelder, * * Fixes: * Alan Cox : UDP sockets show the rxqueue/txqueue * using hint flag for the netinfo. * Pauline Middelink : identd support * Alan Cox : Make /proc safer. * Erik Schoenfelder : /proc/net/snmp * Alan Cox : Handle dead sockets properly. * Gerhard Koerting : Show both timers * Alan Cox : Allow inode to be NULL (kernel socket) * Andi Kleen : Add support for open_requests and * split functions for more readibility. * Andi Kleen : Add support for /proc/net/netstat * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version * 2 of the License, or (at your option) any later version. */ #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include static int fold_prot_inuse(struct proto *proto) { int res = 0; int cpu; for (cpu=0; cpustats[cpu].inuse; return res; } /* * Report socket allocation statistics [mea@utu.fi] */ int afinet_get_info(char *buffer, char **start, off_t offset, int length) { /* From net/socket.c */ extern int socket_get_info(char *, char **, off_t, int); int len = socket_get_info(buffer,start,offset,length); len += sprintf(buffer+len,"TCP: inuse %d orphan %d tw %d\n", fold_prot_inuse(&tcp_prot), atomic_read(&tcp_orphan_count), tcp_tw_count); len += sprintf(buffer+len,"UDP: inuse %d\n", fold_prot_inuse(&udp_prot)); len += sprintf(buffer+len,"RAW: inuse %d\n", fold_prot_inuse(&raw_prot)); if (offset >= len) { *start = buffer; return 0; } *start = buffer + offset; len -= offset; if (len > length) len = length; if (len < 0) len = 0; return len; } static unsigned long fold_field(unsigned long *begin, int sz, int nr) { unsigned long res = 0; int i; sz /= sizeof(unsigned long); for (i=0; i<2*smp_num_cpus; i++) res += begin[i*sz + nr]; return res; } /* * Called from the PROCfs module. This outputs /proc/net/snmp. */ int snmp_get_info(char *buffer, char **start, off_t offset, int length) { extern int sysctl_ip_default_ttl; int len, i; len = sprintf (buffer, "Ip: Forwarding DefaultTTL InReceives InHdrErrors InAddrErrors ForwDatagrams InUnknownProtos InDiscards InDelivers OutRequests OutDiscards OutNoRoutes ReasmTimeout ReasmReqds ReasmOKs ReasmFails FragOKs FragFails FragCreates\n" "Ip: %d %d", ipv4_devconf.forwarding ? 1 : 2, sysctl_ip_default_ttl); for (i=0; i= len) { *start = buffer; return 0; } *start = buffer + offset; len -= offset; if (len > length) len = length; if (len < 0) len = 0; return len; } /* * Output /proc/net/netstat */ int netstat_get_info(char *buffer, char **start, off_t offset, int length) { int len, i; len = sprintf(buffer, "TcpExt: SyncookiesSent SyncookiesRecv SyncookiesFailed" " EmbryonicRsts PruneCalled RcvPruned OfoPruned" " OutOfWindowIcmps LockDroppedIcmps" " TW TWRecycled TWKilled" " PAWSPassive PAWSActive PAWSEstab" " DelayedACKs DelayedACKLocked DelayedACKLost" " ListenOverflows ListenDrops" " TCPPrequeued TCPDirectCopyFromBacklog" " TCPDirectCopyFromPrequeue TCPPrequeueDropped" " TCPHPHits TCPHPHitsToUser\n" "TcpExt:"); for (i=0; i= len) { *start = buffer; return 0; } *start = buffer + offset; len -= offset; if (len > length) len = length; if (len < 0) len = 0; return len; }