1 |
1629 |
jcastillo |
/*
|
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 <linux/config.h>
|
33 |
|
|
#include <asm/system.h>
|
34 |
|
|
#include <linux/sched.h>
|
35 |
|
|
#include <linux/socket.h>
|
36 |
|
|
#include <linux/net.h>
|
37 |
|
|
#include <linux/un.h>
|
38 |
|
|
#include <linux/in.h>
|
39 |
|
|
#include <linux/param.h>
|
40 |
|
|
#include <linux/inet.h>
|
41 |
|
|
#include <linux/netdevice.h>
|
42 |
|
|
#include <net/ip.h>
|
43 |
|
|
#include <net/icmp.h>
|
44 |
|
|
#include <net/protocol.h>
|
45 |
|
|
#include <net/tcp.h>
|
46 |
|
|
#include <net/udp.h>
|
47 |
|
|
#include <linux/skbuff.h>
|
48 |
|
|
#include <net/sock.h>
|
49 |
|
|
#include <net/raw.h>
|
50 |
|
|
|
51 |
|
|
/*
|
52 |
|
|
* Get__netinfo returns the length of that string.
|
53 |
|
|
*
|
54 |
|
|
* KNOWN BUGS
|
55 |
|
|
* As in get_unix_netinfo, the buffer might be too small. If this
|
56 |
|
|
* happens, get__netinfo returns only part of the available infos.
|
57 |
|
|
*/
|
58 |
|
|
static int
|
59 |
|
|
get__netinfo(struct proto *pro, char *buffer, int format, char **start, off_t offset, int length)
|
60 |
|
|
{
|
61 |
|
|
struct sock *sp;
|
62 |
|
|
int timer_active, timer_active1, timer_active2;
|
63 |
|
|
unsigned long timer_expires;
|
64 |
|
|
unsigned long dest, src;
|
65 |
|
|
unsigned short destp, srcp;
|
66 |
|
|
int len=0, i = 0;
|
67 |
|
|
off_t pos=0;
|
68 |
|
|
off_t begin;
|
69 |
|
|
char tmpbuf[129];
|
70 |
|
|
|
71 |
|
|
if (offset < 128)
|
72 |
|
|
len += sprintf(buffer, "%-127s\n",
|
73 |
|
|
" sl local_address rem_address st tx_queue "
|
74 |
|
|
"rx_queue tr tm->when retrnsmt uid timeout inode");
|
75 |
|
|
pos = 128;
|
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 |
|
|
start_bh_atomic();
|
83 |
|
|
sp = pro->sklist_next;
|
84 |
|
|
while(sp != (struct sock *)pro) {
|
85 |
|
|
pos += 128;
|
86 |
|
|
if (pos < offset)
|
87 |
|
|
goto next;
|
88 |
|
|
|
89 |
|
|
dest = sp->daddr;
|
90 |
|
|
src = sp->saddr;
|
91 |
|
|
destp = sp->dummy_th.dest;
|
92 |
|
|
srcp = sp->dummy_th.source;
|
93 |
|
|
|
94 |
|
|
/* Since we are Little Endian we need to swap the bytes :-( */
|
95 |
|
|
destp = ntohs(destp);
|
96 |
|
|
srcp = ntohs(srcp);
|
97 |
|
|
timer_active1 = del_timer(&sp->retransmit_timer);
|
98 |
|
|
timer_active2 = del_timer(&sp->timer);
|
99 |
|
|
if (!timer_active1) sp->retransmit_timer.expires=0;
|
100 |
|
|
if (!timer_active2) sp->timer.expires=0;
|
101 |
|
|
timer_active=0;
|
102 |
|
|
timer_expires=(unsigned)-1;
|
103 |
|
|
if (timer_active1 &&
|
104 |
|
|
sp->retransmit_timer.expires < timer_expires) {
|
105 |
|
|
timer_active=timer_active1;
|
106 |
|
|
timer_expires=sp->retransmit_timer.expires;
|
107 |
|
|
}
|
108 |
|
|
if (timer_active2 &&
|
109 |
|
|
sp->timer.expires < timer_expires) {
|
110 |
|
|
timer_active=timer_active2;
|
111 |
|
|
timer_expires=sp->timer.expires;
|
112 |
|
|
}
|
113 |
|
|
sprintf(tmpbuf, "%4d: %08lX:%04X %08lX:%04X"
|
114 |
|
|
" %02X %08X:%08X %02X:%08lX %08X %5d %8d %ld",
|
115 |
|
|
i, src, srcp, dest, destp, sp->state,
|
116 |
|
|
format==0?sp->write_seq-sp->rcv_ack_seq:sp->wmem_alloc,
|
117 |
|
|
format==0?sp->acked_seq-sp->copied_seq:sp->rmem_alloc,
|
118 |
|
|
timer_active, timer_expires-jiffies, (unsigned) sp->retransmits,
|
119 |
|
|
(sp->socket&&SOCK_INODE(sp->socket))?SOCK_INODE(sp->socket)->i_uid:0,
|
120 |
|
|
timer_active?sp->timeout:0,
|
121 |
|
|
sp->socket && SOCK_INODE(sp->socket) ?
|
122 |
|
|
SOCK_INODE(sp->socket)->i_ino : 0);
|
123 |
|
|
if (timer_active1) add_timer(&sp->retransmit_timer);
|
124 |
|
|
if (timer_active2) add_timer(&sp->timer);
|
125 |
|
|
len += sprintf(buffer+len, "%-127s\n", tmpbuf);
|
126 |
|
|
/*
|
127 |
|
|
* All sockets are kept in the protocols sklist, so we
|
128 |
|
|
* follow the 'next' link to get them all.
|
129 |
|
|
*/
|
130 |
|
|
if(len >= length)
|
131 |
|
|
break;
|
132 |
|
|
next:
|
133 |
|
|
sp = sp->sklist_next;
|
134 |
|
|
i++;
|
135 |
|
|
}
|
136 |
|
|
end_bh_atomic();
|
137 |
|
|
|
138 |
|
|
begin = len - (pos - offset);
|
139 |
|
|
*start = buffer + begin;
|
140 |
|
|
len -= begin;
|
141 |
|
|
if(len>length)
|
142 |
|
|
len = length;
|
143 |
|
|
return len;
|
144 |
|
|
}
|
145 |
|
|
|
146 |
|
|
|
147 |
|
|
int tcp_get_info(char *buffer, char **start, off_t offset, int length, int dummy)
|
148 |
|
|
{
|
149 |
|
|
return get__netinfo(&tcp_prot, buffer,0, start, offset, length);
|
150 |
|
|
}
|
151 |
|
|
|
152 |
|
|
|
153 |
|
|
int udp_get_info(char *buffer, char **start, off_t offset, int length, int dummy)
|
154 |
|
|
{
|
155 |
|
|
return get__netinfo(&udp_prot, buffer,1, start, offset, length);
|
156 |
|
|
}
|
157 |
|
|
|
158 |
|
|
|
159 |
|
|
int raw_get_info(char *buffer, char **start, off_t offset, int length, int dummy)
|
160 |
|
|
{
|
161 |
|
|
return get__netinfo(&raw_prot, buffer,1, start, offset, length);
|
162 |
|
|
}
|
163 |
|
|
|
164 |
|
|
|
165 |
|
|
/*
|
166 |
|
|
* Report socket allocation statistics [mea@utu.fi]
|
167 |
|
|
*/
|
168 |
|
|
int afinet_get_info(char *buffer, char **start, off_t offset, int length, int dummy)
|
169 |
|
|
{
|
170 |
|
|
#ifdef CONFIG_SYN_COOKIES
|
171 |
|
|
extern unsigned int ui_c_send_cookies;
|
172 |
|
|
static unsigned int ui_c_last_send_cookies = 0;
|
173 |
|
|
#endif
|
174 |
|
|
/* From net/socket.c */
|
175 |
|
|
extern int socket_get_info(char *, char **, off_t, int);
|
176 |
|
|
extern struct proto packet_prot;
|
177 |
|
|
|
178 |
|
|
int len = socket_get_info(buffer,start,offset,length);
|
179 |
|
|
|
180 |
|
|
len += sprintf(buffer+len,"TCP: inuse %d highest %d\n",
|
181 |
|
|
tcp_prot.inuse, tcp_prot.highestinuse);
|
182 |
|
|
len += sprintf(buffer+len,"UDP: inuse %d highest %d\n",
|
183 |
|
|
udp_prot.inuse, udp_prot.highestinuse);
|
184 |
|
|
len += sprintf(buffer+len,"RAW: inuse %d highest %d\n",
|
185 |
|
|
raw_prot.inuse, raw_prot.highestinuse);
|
186 |
|
|
len += sprintf(buffer+len,"PAC: inuse %d highest %d\n",
|
187 |
|
|
packet_prot.inuse, packet_prot.highestinuse);
|
188 |
|
|
|
189 |
|
|
#if defined(CONFIG_SYN_COOKIES)
|
190 |
|
|
len += sprintf(buffer+len,"SYN_COOKIES: count %u since_last_check %u\n",
|
191 |
|
|
ui_c_send_cookies, (ui_c_send_cookies - ui_c_last_send_cookies));
|
192 |
|
|
|
193 |
|
|
ui_c_last_send_cookies = ui_c_send_cookies;
|
194 |
|
|
#endif
|
195 |
|
|
*start = buffer + offset;
|
196 |
|
|
len -= offset;
|
197 |
|
|
if (len > length)
|
198 |
|
|
len = length;
|
199 |
|
|
return len;
|
200 |
|
|
}
|
201 |
|
|
|
202 |
|
|
|
203 |
|
|
/*
|
204 |
|
|
* Called from the PROCfs module. This outputs /proc/net/snmp.
|
205 |
|
|
*/
|
206 |
|
|
|
207 |
|
|
int snmp_get_info(char *buffer, char **start, off_t offset, int length, int dummy)
|
208 |
|
|
{
|
209 |
|
|
extern struct tcp_mib tcp_statistics;
|
210 |
|
|
extern struct udp_mib udp_statistics;
|
211 |
|
|
int len;
|
212 |
|
|
/*
|
213 |
|
|
extern unsigned long tcp_rx_miss, tcp_rx_hit1,tcp_rx_hit2;
|
214 |
|
|
*/
|
215 |
|
|
|
216 |
|
|
len = sprintf (buffer,
|
217 |
|
|
"Ip: Forwarding DefaultTTL InReceives InHdrErrors InAddrErrors ForwDatagrams InUnknownProtos InDiscards InDelivers OutRequests OutDiscards OutNoRoutes ReasmTimeout ReasmReqds ReasmOKs ReasmFails FragOKs FragFails FragCreates\n"
|
218 |
|
|
"Ip: %lu %lu %lu %lu %lu %lu %lu %lu %lu %lu %lu %lu %lu %lu %lu %lu %lu %lu %lu\n",
|
219 |
|
|
ip_statistics.IpForwarding, ip_statistics.IpDefaultTTL,
|
220 |
|
|
ip_statistics.IpInReceives, ip_statistics.IpInHdrErrors,
|
221 |
|
|
ip_statistics.IpInAddrErrors, ip_statistics.IpForwDatagrams,
|
222 |
|
|
ip_statistics.IpInUnknownProtos, ip_statistics.IpInDiscards,
|
223 |
|
|
ip_statistics.IpInDelivers, ip_statistics.IpOutRequests,
|
224 |
|
|
ip_statistics.IpOutDiscards, ip_statistics.IpOutNoRoutes,
|
225 |
|
|
ip_statistics.IpReasmTimeout, ip_statistics.IpReasmReqds,
|
226 |
|
|
ip_statistics.IpReasmOKs, ip_statistics.IpReasmFails,
|
227 |
|
|
ip_statistics.IpFragOKs, ip_statistics.IpFragFails,
|
228 |
|
|
ip_statistics.IpFragCreates);
|
229 |
|
|
|
230 |
|
|
len += sprintf (buffer + len,
|
231 |
|
|
"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"
|
232 |
|
|
"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",
|
233 |
|
|
icmp_statistics.IcmpInMsgs, icmp_statistics.IcmpInErrors,
|
234 |
|
|
icmp_statistics.IcmpInDestUnreachs, icmp_statistics.IcmpInTimeExcds,
|
235 |
|
|
icmp_statistics.IcmpInParmProbs, icmp_statistics.IcmpInSrcQuenchs,
|
236 |
|
|
icmp_statistics.IcmpInRedirects, icmp_statistics.IcmpInEchos,
|
237 |
|
|
icmp_statistics.IcmpInEchoReps, icmp_statistics.IcmpInTimestamps,
|
238 |
|
|
icmp_statistics.IcmpInTimestampReps, icmp_statistics.IcmpInAddrMasks,
|
239 |
|
|
icmp_statistics.IcmpInAddrMaskReps, icmp_statistics.IcmpOutMsgs,
|
240 |
|
|
icmp_statistics.IcmpOutErrors, icmp_statistics.IcmpOutDestUnreachs,
|
241 |
|
|
icmp_statistics.IcmpOutTimeExcds, icmp_statistics.IcmpOutParmProbs,
|
242 |
|
|
icmp_statistics.IcmpOutSrcQuenchs, icmp_statistics.IcmpOutRedirects,
|
243 |
|
|
icmp_statistics.IcmpOutEchos, icmp_statistics.IcmpOutEchoReps,
|
244 |
|
|
icmp_statistics.IcmpOutTimestamps, icmp_statistics.IcmpOutTimestampReps,
|
245 |
|
|
icmp_statistics.IcmpOutAddrMasks, icmp_statistics.IcmpOutAddrMaskReps);
|
246 |
|
|
|
247 |
|
|
len += sprintf (buffer + len,
|
248 |
|
|
"Tcp: RtoAlgorithm RtoMin RtoMax MaxConn ActiveOpens PassiveOpens AttemptFails EstabResets CurrEstab InSegs OutSegs RetransSegs\n"
|
249 |
|
|
"Tcp: %lu %lu %lu %lu %lu %lu %lu %lu %lu %lu %lu %lu\n",
|
250 |
|
|
tcp_statistics.TcpRtoAlgorithm, tcp_statistics.TcpRtoMin,
|
251 |
|
|
tcp_statistics.TcpRtoMax, tcp_statistics.TcpMaxConn,
|
252 |
|
|
tcp_statistics.TcpActiveOpens, tcp_statistics.TcpPassiveOpens,
|
253 |
|
|
tcp_statistics.TcpAttemptFails, tcp_statistics.TcpEstabResets,
|
254 |
|
|
tcp_statistics.TcpCurrEstab, tcp_statistics.TcpInSegs,
|
255 |
|
|
tcp_statistics.TcpOutSegs, tcp_statistics.TcpRetransSegs);
|
256 |
|
|
|
257 |
|
|
len += sprintf (buffer + len,
|
258 |
|
|
"Udp: InDatagrams NoPorts InErrors OutDatagrams\nUdp: %lu %lu %lu %lu\n",
|
259 |
|
|
udp_statistics.UdpInDatagrams, udp_statistics.UdpNoPorts,
|
260 |
|
|
udp_statistics.UdpInErrors, udp_statistics.UdpOutDatagrams);
|
261 |
|
|
/*
|
262 |
|
|
len += sprintf( buffer + len,
|
263 |
|
|
"TCP fast path RX: H2: %ul H1: %ul L: %ul\n",
|
264 |
|
|
tcp_rx_hit2,tcp_rx_hit1,tcp_rx_miss);
|
265 |
|
|
*/
|
266 |
|
|
|
267 |
|
|
if (offset >= len)
|
268 |
|
|
{
|
269 |
|
|
*start = buffer;
|
270 |
|
|
return 0;
|
271 |
|
|
}
|
272 |
|
|
*start = buffer + offset;
|
273 |
|
|
len -= offset;
|
274 |
|
|
if (len > length)
|
275 |
|
|
len = length;
|
276 |
|
|
return len;
|
277 |
|
|
}
|