Merge with Linux 2.5.48.
[linux-2.6/linux-mips.git] / net / ipv4 / proc.c
blob8869781ad6d6b97e836a1b47694fd3dc3c15f4a2
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.
6 * This file implements the various access functions for the
7 * PROC file system. It is mainly used for debugging and
8 * statistics.
10 * Version: $Id: proc.c,v 1.45 2001/05/16 16:45:35 davem Exp $
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>
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 * Andi Kleen : Add support for open_requests and
27 * split functions for more readibility.
28 * Andi Kleen : Add support for /proc/net/netstat
29 * Arnaldo C. Melo : Convert to seq_file
31 * This program is free software; you can redistribute it and/or
32 * modify it under the terms of the GNU General Public License
33 * as published by the Free Software Foundation; either version
34 * 2 of the License, or (at your option) any later version.
36 #include <linux/types.h>
37 #include <net/icmp.h>
38 #include <net/protocol.h>
39 #include <net/tcp.h>
40 #include <net/udp.h>
41 #include <linux/proc_fs.h>
42 #include <linux/seq_file.h>
43 #include <net/sock.h>
44 #include <net/raw.h>
46 static int fold_prot_inuse(struct proto *proto)
48 int res = 0;
49 int cpu;
51 for (cpu = 0; cpu < NR_CPUS; cpu++)
52 res += proto->stats[cpu].inuse;
54 return res;
58 * Report socket allocation statistics [mea@utu.fi]
60 static int sockstat_seq_show(struct seq_file *seq, void *v)
62 /* From net/socket.c */
63 extern void socket_seq_show(struct seq_file *seq);
65 socket_seq_show(seq);
66 seq_printf(seq, "TCP: inuse %d orphan %d tw %d alloc %d mem %d\n",
67 fold_prot_inuse(&tcp_prot), atomic_read(&tcp_orphan_count),
68 tcp_tw_count, atomic_read(&tcp_sockets_allocated),
69 atomic_read(&tcp_memory_allocated));
70 seq_printf(seq, "UDP: inuse %d\n", fold_prot_inuse(&udp_prot));
71 seq_printf(seq, "RAW: inuse %d\n", fold_prot_inuse(&raw_prot));
72 seq_printf(seq, "FRAG: inuse %d memory %d\n", ip_frag_nqueues,
73 atomic_read(&ip_frag_mem));
74 return 0;
77 static int sockstat_seq_open(struct inode *inode, struct file *file)
79 return single_open(file, sockstat_seq_show, NULL);
82 static struct file_operations sockstat_seq_fops = {
83 .open = sockstat_seq_open,
84 .read = seq_read,
85 .llseek = seq_lseek,
86 .release = single_release,
89 static unsigned long fold_field(unsigned long *begin, int sz, int nr)
91 unsigned long res = 0;
92 int i;
94 sz /= sizeof(unsigned long);
96 for (i = 0; i < NR_CPUS; i++) {
97 res += begin[2 * i * sz + nr];
98 res += begin[(2 * i + 1) * sz + nr];
100 return res;
104 * Called from the PROCfs module. This outputs /proc/net/snmp.
106 static int snmp_seq_show(struct seq_file *seq, void *v)
108 extern int sysctl_ip_default_ttl;
109 int i;
111 seq_printf(seq, "Ip: Forwarding DefaultTTL InReceives InHdrErrors "
112 "InAddrErrors ForwDatagrams InUnknownProtos "
113 "InDiscards InDelivers OutRequests OutDiscards "
114 "OutNoRoutes ReasmTimeout ReasmReqds ReasmOKs "
115 "ReasmFails FragOKs FragFails FragCreates\nIp: %d %d",
116 ipv4_devconf.forwarding ? 1 : 2, sysctl_ip_default_ttl);
118 for (i = 0;
119 i < offsetof(struct ip_mib, __pad) / sizeof(unsigned long); i++)
120 seq_printf(seq, " %lu",
121 fold_field((unsigned long *)ip_statistics,
122 sizeof(struct ip_mib), i));
124 seq_printf(seq, "\nIcmp: InMsgs InErrors InDestUnreachs InTimeExcds "
125 "InParmProbs InSrcQuenchs InRedirects InEchos "
126 "InEchoReps InTimestamps InTimestampReps InAddrMasks "
127 "InAddrMaskReps OutMsgs OutErrors OutDestUnreachs "
128 "OutTimeExcds OutParmProbs OutSrcQuenchs OutRedirects "
129 "OutEchos OutEchoReps OutTimestamps OutTimestampReps "
130 "OutAddrMasks OutAddrMaskReps\nIcmp:");
132 for (i = 0;
133 i < offsetof(struct icmp_mib, dummy) / sizeof(unsigned long); i++)
134 seq_printf(seq, " %lu",
135 fold_field((unsigned long *)icmp_statistics,
136 sizeof(struct icmp_mib), i));
138 seq_printf(seq, "\nTcp: RtoAlgorithm RtoMin RtoMax MaxConn ActiveOpens "
139 "PassiveOpens AttemptFails EstabResets CurrEstab "
140 "InSegs OutSegs RetransSegs InErrs OutRsts\nTcp:");
142 for (i = 0;
143 i < offsetof(struct tcp_mib, __pad) / sizeof(unsigned long); i++)
144 seq_printf(seq, " %lu",
145 fold_field((unsigned long *)tcp_statistics,
146 sizeof(struct tcp_mib), i));
148 seq_printf(seq, "\nUdp: InDatagrams NoPorts InErrors OutDatagrams\n"
149 "Udp:");
151 for (i = 0;
152 i < offsetof(struct udp_mib, __pad) / sizeof(unsigned long); i++)
153 seq_printf(seq, " %lu",
154 fold_field((unsigned long *)udp_statistics,
155 sizeof(struct udp_mib), i));
157 seq_putc(seq, '\n');
158 return 0;
161 static int snmp_seq_open(struct inode *inode, struct file *file)
163 return single_open(file, snmp_seq_show, NULL);
166 static struct file_operations snmp_seq_fops = {
167 .open = snmp_seq_open,
168 .read = seq_read,
169 .llseek = seq_lseek,
170 .release = single_release,
174 * Output /proc/net/netstat
176 static int netstat_seq_show(struct seq_file *seq, void *v)
178 int i;
180 seq_puts(seq, "TcpExt: SyncookiesSent SyncookiesRecv SyncookiesFailed"
181 " EmbryonicRsts PruneCalled RcvPruned OfoPruned"
182 " OutOfWindowIcmps LockDroppedIcmps ArpFilter"
183 " TW TWRecycled TWKilled"
184 " PAWSPassive PAWSActive PAWSEstab"
185 " DelayedACKs DelayedACKLocked DelayedACKLost"
186 " ListenOverflows ListenDrops"
187 " TCPPrequeued TCPDirectCopyFromBacklog"
188 " TCPDirectCopyFromPrequeue TCPPrequeueDropped"
189 " TCPHPHits TCPHPHitsToUser"
190 " TCPPureAcks TCPHPAcks"
191 " TCPRenoRecovery TCPSackRecovery"
192 " TCPSACKReneging"
193 " TCPFACKReorder TCPSACKReorder TCPRenoReorder"
194 " TCPTSReorder"
195 " TCPFullUndo TCPPartialUndo TCPDSACKUndo TCPLossUndo"
196 " TCPLoss TCPLostRetransmit"
197 " TCPRenoFailures TCPSackFailures TCPLossFailures"
198 " TCPFastRetrans TCPForwardRetrans TCPSlowStartRetrans"
199 " TCPTimeouts"
200 " TCPRenoRecoveryFail TCPSackRecoveryFail"
201 " TCPSchedulerFailed TCPRcvCollapsed"
202 " TCPDSACKOldSent TCPDSACKOfoSent TCPDSACKRecv"
203 " TCPDSACKOfoRecv"
204 " TCPAbortOnSyn TCPAbortOnData TCPAbortOnClose"
205 " TCPAbortOnMemory TCPAbortOnTimeout TCPAbortOnLinger"
206 " TCPAbortFailed TCPMemoryPressures\n"
207 "TcpExt:");
208 for (i = 0;
209 i < offsetof(struct linux_mib, __pad) / sizeof(unsigned long); i++)
210 seq_printf(seq, " %lu",
211 fold_field((unsigned long *)net_statistics,
212 sizeof(struct linux_mib), i));
213 seq_putc(seq, '\n');
214 return 0;
217 static int netstat_seq_open(struct inode *inode, struct file *file)
219 return single_open(file, netstat_seq_show, NULL);
222 static struct file_operations netstat_seq_fops = {
223 .open = netstat_seq_open,
224 .read = seq_read,
225 .llseek = seq_lseek,
226 .release = single_release,
229 int __init ip_misc_proc_init(void)
231 int rc = 0;
232 struct proc_dir_entry *p;
234 p = create_proc_entry("netstat", S_IRUGO, proc_net);
235 if (!p)
236 goto out_netstat;
237 p->proc_fops = &netstat_seq_fops;
239 p = create_proc_entry("snmp", S_IRUGO, proc_net);
240 if (!p)
241 goto out_snmp;
242 p->proc_fops = &snmp_seq_fops;
244 p = create_proc_entry("sockstat", S_IRUGO, proc_net);
245 if (!p)
246 goto out_sockstat;
247 p->proc_fops = &sockstat_seq_fops;
248 out:
249 return rc;
250 out_sockstat:
251 remove_proc_entry("snmp", proc_net);
252 out_snmp:
253 remove_proc_entry("netstat", proc_net);
254 out_netstat:
255 rc = -ENOMEM;
256 goto out;
259 int ip_seq_release(struct inode *inode, struct file *file)
261 struct seq_file *seq = (struct seq_file *)file->private_data;
263 kfree(seq->private);
264 seq->private = NULL;
265 return seq_release(inode, file);