xref: /openbmc/linux/net/ipv4/proc.c (revision 111cc8b913b42ef07793648b1699288332f273e1)
11da177e4SLinus Torvalds /*
21da177e4SLinus Torvalds  * INET		An implementation of the TCP/IP protocol suite for the LINUX
31da177e4SLinus Torvalds  *		operating system.  INET is implemented using the  BSD Socket
41da177e4SLinus Torvalds  *		interface as the means of communication with the user level.
51da177e4SLinus Torvalds  *
61da177e4SLinus Torvalds  *		This file implements the various access functions for the
71da177e4SLinus Torvalds  *		PROC file system.  It is mainly used for debugging and
81da177e4SLinus Torvalds  *		statistics.
91da177e4SLinus Torvalds  *
101da177e4SLinus Torvalds  * Authors:	Fred N. van Kempen, <waltje@uWalt.NL.Mugnet.ORG>
111da177e4SLinus Torvalds  *		Gerald J. Heim, <heim@peanuts.informatik.uni-tuebingen.de>
121da177e4SLinus Torvalds  *		Fred Baumgarten, <dc6iq@insu1.etec.uni-karlsruhe.de>
131da177e4SLinus Torvalds  *		Erik Schoenfelder, <schoenfr@ibr.cs.tu-bs.de>
141da177e4SLinus Torvalds  *
151da177e4SLinus Torvalds  * Fixes:
161da177e4SLinus Torvalds  *		Alan Cox	:	UDP sockets show the rxqueue/txqueue
171da177e4SLinus Torvalds  *					using hint flag for the netinfo.
181da177e4SLinus Torvalds  *	Pauline Middelink	:	identd support
191da177e4SLinus Torvalds  *		Alan Cox	:	Make /proc safer.
201da177e4SLinus Torvalds  *	Erik Schoenfelder	:	/proc/net/snmp
211da177e4SLinus Torvalds  *		Alan Cox	:	Handle dead sockets properly.
221da177e4SLinus Torvalds  *	Gerhard Koerting	:	Show both timers
231da177e4SLinus Torvalds  *		Alan Cox	:	Allow inode to be NULL (kernel socket)
241da177e4SLinus Torvalds  *	Andi Kleen		:	Add support for open_requests and
251da177e4SLinus Torvalds  *					split functions for more readibility.
261da177e4SLinus Torvalds  *	Andi Kleen		:	Add support for /proc/net/netstat
271da177e4SLinus Torvalds  *	Arnaldo C. Melo		:	Convert to seq_file
281da177e4SLinus Torvalds  *
291da177e4SLinus Torvalds  *		This program is free software; you can redistribute it and/or
301da177e4SLinus Torvalds  *		modify it under the terms of the GNU General Public License
311da177e4SLinus Torvalds  *		as published by the Free Software Foundation; either version
321da177e4SLinus Torvalds  *		2 of the License, or (at your option) any later version.
331da177e4SLinus Torvalds  */
341da177e4SLinus Torvalds #include <linux/types.h>
35457c4cbcSEric W. Biederman #include <net/net_namespace.h>
361da177e4SLinus Torvalds #include <net/icmp.h>
371da177e4SLinus Torvalds #include <net/protocol.h>
381da177e4SLinus Torvalds #include <net/tcp.h>
391da177e4SLinus Torvalds #include <net/udp.h>
40ba4e58ecSGerrit Renker #include <net/udplite.h>
4114c85021SArnaldo Carvalho de Melo #include <linux/inetdevice.h>
421da177e4SLinus Torvalds #include <linux/proc_fs.h>
431da177e4SLinus Torvalds #include <linux/seq_file.h>
441da177e4SLinus Torvalds #include <net/sock.h>
451da177e4SLinus Torvalds #include <net/raw.h>
461da177e4SLinus Torvalds 
471da177e4SLinus Torvalds /*
481da177e4SLinus Torvalds  *	Report socket allocation statistics [mea@utu.fi]
491da177e4SLinus Torvalds  */
501da177e4SLinus Torvalds static int sockstat_seq_show(struct seq_file *seq, void *v)
511da177e4SLinus Torvalds {
52fd4e7b50SPavel Emelyanov 	struct net *net = seq->private;
53fd4e7b50SPavel Emelyanov 
541da177e4SLinus Torvalds 	socket_seq_show(seq);
551da177e4SLinus Torvalds 	seq_printf(seq, "TCP: inuse %d orphan %d tw %d alloc %d mem %d\n",
56fd4e7b50SPavel Emelyanov 		   sock_prot_inuse_get(net, &tcp_prot),
5765f76517SEric Dumazet 		   atomic_read(&tcp_orphan_count),
58295ff7edSArnaldo Carvalho de Melo 		   tcp_death_row.tw_count, atomic_read(&tcp_sockets_allocated),
591da177e4SLinus Torvalds 		   atomic_read(&tcp_memory_allocated));
60c29a0bc4SPavel Emelyanov 	seq_printf(seq, "UDP: inuse %d mem %d\n",
61fd4e7b50SPavel Emelyanov 		   sock_prot_inuse_get(net, &udp_prot),
6295766fffSHideo Aoki 		   atomic_read(&udp_memory_allocated));
63c29a0bc4SPavel Emelyanov 	seq_printf(seq, "UDPLITE: inuse %d\n",
64fd4e7b50SPavel Emelyanov 		   sock_prot_inuse_get(net, &udplite_prot));
65c29a0bc4SPavel Emelyanov 	seq_printf(seq, "RAW: inuse %d\n",
66fd4e7b50SPavel Emelyanov 		   sock_prot_inuse_get(net, &raw_prot));
677eb95156SPavel Emelyanov 	seq_printf(seq,  "FRAG: inuse %d memory %d\n",
68fd4e7b50SPavel Emelyanov 			ip_frag_nqueues(net), ip_frag_mem(net));
691da177e4SLinus Torvalds 	return 0;
701da177e4SLinus Torvalds }
711da177e4SLinus Torvalds 
721da177e4SLinus Torvalds static int sockstat_seq_open(struct inode *inode, struct file *file)
731da177e4SLinus Torvalds {
74de05c557SPavel Emelyanov 	return single_open_net(inode, file, sockstat_seq_show);
75fd4e7b50SPavel Emelyanov }
76fd4e7b50SPavel Emelyanov 
779a32144eSArjan van de Ven static const struct file_operations sockstat_seq_fops = {
781da177e4SLinus Torvalds 	.owner	 = THIS_MODULE,
791da177e4SLinus Torvalds 	.open	 = sockstat_seq_open,
801da177e4SLinus Torvalds 	.read	 = seq_read,
811da177e4SLinus Torvalds 	.llseek	 = seq_lseek,
82b6fcbdb4SPavel Emelyanov 	.release = single_release_net,
831da177e4SLinus Torvalds };
841da177e4SLinus Torvalds 
851da177e4SLinus Torvalds /* snmp items */
869b5b5cffSArjan van de Ven static const struct snmp_mib snmp4_ipstats_list[] = {
871da177e4SLinus Torvalds 	SNMP_MIB_ITEM("InReceives", IPSTATS_MIB_INRECEIVES),
881da177e4SLinus Torvalds 	SNMP_MIB_ITEM("InHdrErrors", IPSTATS_MIB_INHDRERRORS),
891da177e4SLinus Torvalds 	SNMP_MIB_ITEM("InAddrErrors", IPSTATS_MIB_INADDRERRORS),
901da177e4SLinus Torvalds 	SNMP_MIB_ITEM("ForwDatagrams", IPSTATS_MIB_OUTFORWDATAGRAMS),
911da177e4SLinus Torvalds 	SNMP_MIB_ITEM("InUnknownProtos", IPSTATS_MIB_INUNKNOWNPROTOS),
921da177e4SLinus Torvalds 	SNMP_MIB_ITEM("InDiscards", IPSTATS_MIB_INDISCARDS),
931da177e4SLinus Torvalds 	SNMP_MIB_ITEM("InDelivers", IPSTATS_MIB_INDELIVERS),
941da177e4SLinus Torvalds 	SNMP_MIB_ITEM("OutRequests", IPSTATS_MIB_OUTREQUESTS),
951da177e4SLinus Torvalds 	SNMP_MIB_ITEM("OutDiscards", IPSTATS_MIB_OUTDISCARDS),
961da177e4SLinus Torvalds 	SNMP_MIB_ITEM("OutNoRoutes", IPSTATS_MIB_OUTNOROUTES),
971da177e4SLinus Torvalds 	SNMP_MIB_ITEM("ReasmTimeout", IPSTATS_MIB_REASMTIMEOUT),
981da177e4SLinus Torvalds 	SNMP_MIB_ITEM("ReasmReqds", IPSTATS_MIB_REASMREQDS),
991da177e4SLinus Torvalds 	SNMP_MIB_ITEM("ReasmOKs", IPSTATS_MIB_REASMOKS),
1001da177e4SLinus Torvalds 	SNMP_MIB_ITEM("ReasmFails", IPSTATS_MIB_REASMFAILS),
1011da177e4SLinus Torvalds 	SNMP_MIB_ITEM("FragOKs", IPSTATS_MIB_FRAGOKS),
1021da177e4SLinus Torvalds 	SNMP_MIB_ITEM("FragFails", IPSTATS_MIB_FRAGFAILS),
1031da177e4SLinus Torvalds 	SNMP_MIB_ITEM("FragCreates", IPSTATS_MIB_FRAGCREATES),
1041da177e4SLinus Torvalds 	SNMP_MIB_SENTINEL
1051da177e4SLinus Torvalds };
1061da177e4SLinus Torvalds 
107d831666eSMitsuru Chinen /* Following RFC4293 items are displayed in /proc/net/netstat */
108d831666eSMitsuru Chinen static const struct snmp_mib snmp4_ipextstats_list[] = {
109d831666eSMitsuru Chinen 	SNMP_MIB_ITEM("InNoRoutes", IPSTATS_MIB_INNOROUTES),
110d831666eSMitsuru Chinen 	SNMP_MIB_ITEM("InTruncatedPkts", IPSTATS_MIB_INTRUNCATEDPKTS),
111d831666eSMitsuru Chinen 	SNMP_MIB_ITEM("InMcastPkts", IPSTATS_MIB_INMCASTPKTS),
112d831666eSMitsuru Chinen 	SNMP_MIB_ITEM("OutMcastPkts", IPSTATS_MIB_OUTMCASTPKTS),
113d831666eSMitsuru Chinen 	SNMP_MIB_ITEM("InBcastPkts", IPSTATS_MIB_INBCASTPKTS),
114d831666eSMitsuru Chinen 	SNMP_MIB_ITEM("OutBcastPkts", IPSTATS_MIB_OUTBCASTPKTS),
115d831666eSMitsuru Chinen 	SNMP_MIB_SENTINEL
116d831666eSMitsuru Chinen };
117d831666eSMitsuru Chinen 
11896793b48SDavid L Stevens static struct {
11996793b48SDavid L Stevens 	char *name;
12096793b48SDavid L Stevens 	int index;
12196793b48SDavid L Stevens } icmpmibmap[] = {
12296793b48SDavid L Stevens 	{ "DestUnreachs", ICMP_DEST_UNREACH },
12396793b48SDavid L Stevens 	{ "TimeExcds", ICMP_TIME_EXCEEDED },
12496793b48SDavid L Stevens 	{ "ParmProbs", ICMP_PARAMETERPROB },
12596793b48SDavid L Stevens 	{ "SrcQuenchs", ICMP_SOURCE_QUENCH },
12696793b48SDavid L Stevens 	{ "Redirects", ICMP_REDIRECT },
12796793b48SDavid L Stevens 	{ "Echos", ICMP_ECHO },
12896793b48SDavid L Stevens 	{ "EchoReps", ICMP_ECHOREPLY },
12996793b48SDavid L Stevens 	{ "Timestamps", ICMP_TIMESTAMP },
13096793b48SDavid L Stevens 	{ "TimestampReps", ICMP_TIMESTAMPREPLY },
13196793b48SDavid L Stevens 	{ "AddrMasks", ICMP_ADDRESS },
13296793b48SDavid L Stevens 	{ "AddrMaskReps", ICMP_ADDRESSREPLY },
133cfcabdccSStephen Hemminger 	{ NULL, 0 }
13496793b48SDavid L Stevens };
13596793b48SDavid L Stevens 
13696793b48SDavid L Stevens 
1379b5b5cffSArjan van de Ven static const struct snmp_mib snmp4_tcp_list[] = {
1381da177e4SLinus Torvalds 	SNMP_MIB_ITEM("RtoAlgorithm", TCP_MIB_RTOALGORITHM),
1391da177e4SLinus Torvalds 	SNMP_MIB_ITEM("RtoMin", TCP_MIB_RTOMIN),
1401da177e4SLinus Torvalds 	SNMP_MIB_ITEM("RtoMax", TCP_MIB_RTOMAX),
1411da177e4SLinus Torvalds 	SNMP_MIB_ITEM("MaxConn", TCP_MIB_MAXCONN),
1421da177e4SLinus Torvalds 	SNMP_MIB_ITEM("ActiveOpens", TCP_MIB_ACTIVEOPENS),
1431da177e4SLinus Torvalds 	SNMP_MIB_ITEM("PassiveOpens", TCP_MIB_PASSIVEOPENS),
1441da177e4SLinus Torvalds 	SNMP_MIB_ITEM("AttemptFails", TCP_MIB_ATTEMPTFAILS),
1451da177e4SLinus Torvalds 	SNMP_MIB_ITEM("EstabResets", TCP_MIB_ESTABRESETS),
1461da177e4SLinus Torvalds 	SNMP_MIB_ITEM("CurrEstab", TCP_MIB_CURRESTAB),
1471da177e4SLinus Torvalds 	SNMP_MIB_ITEM("InSegs", TCP_MIB_INSEGS),
1481da177e4SLinus Torvalds 	SNMP_MIB_ITEM("OutSegs", TCP_MIB_OUTSEGS),
1491da177e4SLinus Torvalds 	SNMP_MIB_ITEM("RetransSegs", TCP_MIB_RETRANSSEGS),
1501da177e4SLinus Torvalds 	SNMP_MIB_ITEM("InErrs", TCP_MIB_INERRS),
1511da177e4SLinus Torvalds 	SNMP_MIB_ITEM("OutRsts", TCP_MIB_OUTRSTS),
1521da177e4SLinus Torvalds 	SNMP_MIB_SENTINEL
1531da177e4SLinus Torvalds };
1541da177e4SLinus Torvalds 
1559b5b5cffSArjan van de Ven static const struct snmp_mib snmp4_udp_list[] = {
1561da177e4SLinus Torvalds 	SNMP_MIB_ITEM("InDatagrams", UDP_MIB_INDATAGRAMS),
1571da177e4SLinus Torvalds 	SNMP_MIB_ITEM("NoPorts", UDP_MIB_NOPORTS),
1581da177e4SLinus Torvalds 	SNMP_MIB_ITEM("InErrors", UDP_MIB_INERRORS),
1591da177e4SLinus Torvalds 	SNMP_MIB_ITEM("OutDatagrams", UDP_MIB_OUTDATAGRAMS),
16081aa646cSMartin Bligh 	SNMP_MIB_ITEM("RcvbufErrors", UDP_MIB_RCVBUFERRORS),
16181aa646cSMartin Bligh 	SNMP_MIB_ITEM("SndbufErrors", UDP_MIB_SNDBUFERRORS),
1621da177e4SLinus Torvalds 	SNMP_MIB_SENTINEL
1631da177e4SLinus Torvalds };
1641da177e4SLinus Torvalds 
1659b5b5cffSArjan van de Ven static const struct snmp_mib snmp4_net_list[] = {
1661da177e4SLinus Torvalds 	SNMP_MIB_ITEM("SyncookiesSent", LINUX_MIB_SYNCOOKIESSENT),
1671da177e4SLinus Torvalds 	SNMP_MIB_ITEM("SyncookiesRecv", LINUX_MIB_SYNCOOKIESRECV),
1681da177e4SLinus Torvalds 	SNMP_MIB_ITEM("SyncookiesFailed", LINUX_MIB_SYNCOOKIESFAILED),
1691da177e4SLinus Torvalds 	SNMP_MIB_ITEM("EmbryonicRsts", LINUX_MIB_EMBRYONICRSTS),
1701da177e4SLinus Torvalds 	SNMP_MIB_ITEM("PruneCalled", LINUX_MIB_PRUNECALLED),
1711da177e4SLinus Torvalds 	SNMP_MIB_ITEM("RcvPruned", LINUX_MIB_RCVPRUNED),
1721da177e4SLinus Torvalds 	SNMP_MIB_ITEM("OfoPruned", LINUX_MIB_OFOPRUNED),
1731da177e4SLinus Torvalds 	SNMP_MIB_ITEM("OutOfWindowIcmps", LINUX_MIB_OUTOFWINDOWICMPS),
1741da177e4SLinus Torvalds 	SNMP_MIB_ITEM("LockDroppedIcmps", LINUX_MIB_LOCKDROPPEDICMPS),
1751da177e4SLinus Torvalds 	SNMP_MIB_ITEM("ArpFilter", LINUX_MIB_ARPFILTER),
1761da177e4SLinus Torvalds 	SNMP_MIB_ITEM("TW", LINUX_MIB_TIMEWAITED),
1771da177e4SLinus Torvalds 	SNMP_MIB_ITEM("TWRecycled", LINUX_MIB_TIMEWAITRECYCLED),
1781da177e4SLinus Torvalds 	SNMP_MIB_ITEM("TWKilled", LINUX_MIB_TIMEWAITKILLED),
1791da177e4SLinus Torvalds 	SNMP_MIB_ITEM("PAWSPassive", LINUX_MIB_PAWSPASSIVEREJECTED),
1801da177e4SLinus Torvalds 	SNMP_MIB_ITEM("PAWSActive", LINUX_MIB_PAWSACTIVEREJECTED),
1811da177e4SLinus Torvalds 	SNMP_MIB_ITEM("PAWSEstab", LINUX_MIB_PAWSESTABREJECTED),
1821da177e4SLinus Torvalds 	SNMP_MIB_ITEM("DelayedACKs", LINUX_MIB_DELAYEDACKS),
1831da177e4SLinus Torvalds 	SNMP_MIB_ITEM("DelayedACKLocked", LINUX_MIB_DELAYEDACKLOCKED),
1841da177e4SLinus Torvalds 	SNMP_MIB_ITEM("DelayedACKLost", LINUX_MIB_DELAYEDACKLOST),
1851da177e4SLinus Torvalds 	SNMP_MIB_ITEM("ListenOverflows", LINUX_MIB_LISTENOVERFLOWS),
1861da177e4SLinus Torvalds 	SNMP_MIB_ITEM("ListenDrops", LINUX_MIB_LISTENDROPS),
1871da177e4SLinus Torvalds 	SNMP_MIB_ITEM("TCPPrequeued", LINUX_MIB_TCPPREQUEUED),
1881da177e4SLinus Torvalds 	SNMP_MIB_ITEM("TCPDirectCopyFromBacklog", LINUX_MIB_TCPDIRECTCOPYFROMBACKLOG),
1891da177e4SLinus Torvalds 	SNMP_MIB_ITEM("TCPDirectCopyFromPrequeue", LINUX_MIB_TCPDIRECTCOPYFROMPREQUEUE),
1901da177e4SLinus Torvalds 	SNMP_MIB_ITEM("TCPPrequeueDropped", LINUX_MIB_TCPPREQUEUEDROPPED),
1911da177e4SLinus Torvalds 	SNMP_MIB_ITEM("TCPHPHits", LINUX_MIB_TCPHPHITS),
1921da177e4SLinus Torvalds 	SNMP_MIB_ITEM("TCPHPHitsToUser", LINUX_MIB_TCPHPHITSTOUSER),
1931da177e4SLinus Torvalds 	SNMP_MIB_ITEM("TCPPureAcks", LINUX_MIB_TCPPUREACKS),
1941da177e4SLinus Torvalds 	SNMP_MIB_ITEM("TCPHPAcks", LINUX_MIB_TCPHPACKS),
1951da177e4SLinus Torvalds 	SNMP_MIB_ITEM("TCPRenoRecovery", LINUX_MIB_TCPRENORECOVERY),
1961da177e4SLinus Torvalds 	SNMP_MIB_ITEM("TCPSackRecovery", LINUX_MIB_TCPSACKRECOVERY),
1971da177e4SLinus Torvalds 	SNMP_MIB_ITEM("TCPSACKReneging", LINUX_MIB_TCPSACKRENEGING),
1981da177e4SLinus Torvalds 	SNMP_MIB_ITEM("TCPFACKReorder", LINUX_MIB_TCPFACKREORDER),
1991da177e4SLinus Torvalds 	SNMP_MIB_ITEM("TCPSACKReorder", LINUX_MIB_TCPSACKREORDER),
2001da177e4SLinus Torvalds 	SNMP_MIB_ITEM("TCPRenoReorder", LINUX_MIB_TCPRENOREORDER),
2011da177e4SLinus Torvalds 	SNMP_MIB_ITEM("TCPTSReorder", LINUX_MIB_TCPTSREORDER),
2021da177e4SLinus Torvalds 	SNMP_MIB_ITEM("TCPFullUndo", LINUX_MIB_TCPFULLUNDO),
2031da177e4SLinus Torvalds 	SNMP_MIB_ITEM("TCPPartialUndo", LINUX_MIB_TCPPARTIALUNDO),
2041da177e4SLinus Torvalds 	SNMP_MIB_ITEM("TCPDSACKUndo", LINUX_MIB_TCPDSACKUNDO),
2051da177e4SLinus Torvalds 	SNMP_MIB_ITEM("TCPLossUndo", LINUX_MIB_TCPLOSSUNDO),
2061da177e4SLinus Torvalds 	SNMP_MIB_ITEM("TCPLoss", LINUX_MIB_TCPLOSS),
2071da177e4SLinus Torvalds 	SNMP_MIB_ITEM("TCPLostRetransmit", LINUX_MIB_TCPLOSTRETRANSMIT),
2081da177e4SLinus Torvalds 	SNMP_MIB_ITEM("TCPRenoFailures", LINUX_MIB_TCPRENOFAILURES),
2091da177e4SLinus Torvalds 	SNMP_MIB_ITEM("TCPSackFailures", LINUX_MIB_TCPSACKFAILURES),
2101da177e4SLinus Torvalds 	SNMP_MIB_ITEM("TCPLossFailures", LINUX_MIB_TCPLOSSFAILURES),
2111da177e4SLinus Torvalds 	SNMP_MIB_ITEM("TCPFastRetrans", LINUX_MIB_TCPFASTRETRANS),
2121da177e4SLinus Torvalds 	SNMP_MIB_ITEM("TCPForwardRetrans", LINUX_MIB_TCPFORWARDRETRANS),
2131da177e4SLinus Torvalds 	SNMP_MIB_ITEM("TCPSlowStartRetrans", LINUX_MIB_TCPSLOWSTARTRETRANS),
2141da177e4SLinus Torvalds 	SNMP_MIB_ITEM("TCPTimeouts", LINUX_MIB_TCPTIMEOUTS),
2151da177e4SLinus Torvalds 	SNMP_MIB_ITEM("TCPRenoRecoveryFail", LINUX_MIB_TCPRENORECOVERYFAIL),
2161da177e4SLinus Torvalds 	SNMP_MIB_ITEM("TCPSackRecoveryFail", LINUX_MIB_TCPSACKRECOVERYFAIL),
2171da177e4SLinus Torvalds 	SNMP_MIB_ITEM("TCPSchedulerFailed", LINUX_MIB_TCPSCHEDULERFAILED),
2181da177e4SLinus Torvalds 	SNMP_MIB_ITEM("TCPRcvCollapsed", LINUX_MIB_TCPRCVCOLLAPSED),
2191da177e4SLinus Torvalds 	SNMP_MIB_ITEM("TCPDSACKOldSent", LINUX_MIB_TCPDSACKOLDSENT),
2201da177e4SLinus Torvalds 	SNMP_MIB_ITEM("TCPDSACKOfoSent", LINUX_MIB_TCPDSACKOFOSENT),
2211da177e4SLinus Torvalds 	SNMP_MIB_ITEM("TCPDSACKRecv", LINUX_MIB_TCPDSACKRECV),
2221da177e4SLinus Torvalds 	SNMP_MIB_ITEM("TCPDSACKOfoRecv", LINUX_MIB_TCPDSACKOFORECV),
2231da177e4SLinus Torvalds 	SNMP_MIB_ITEM("TCPAbortOnSyn", LINUX_MIB_TCPABORTONSYN),
2241da177e4SLinus Torvalds 	SNMP_MIB_ITEM("TCPAbortOnData", LINUX_MIB_TCPABORTONDATA),
2251da177e4SLinus Torvalds 	SNMP_MIB_ITEM("TCPAbortOnClose", LINUX_MIB_TCPABORTONCLOSE),
2261da177e4SLinus Torvalds 	SNMP_MIB_ITEM("TCPAbortOnMemory", LINUX_MIB_TCPABORTONMEMORY),
2271da177e4SLinus Torvalds 	SNMP_MIB_ITEM("TCPAbortOnTimeout", LINUX_MIB_TCPABORTONTIMEOUT),
2281da177e4SLinus Torvalds 	SNMP_MIB_ITEM("TCPAbortOnLinger", LINUX_MIB_TCPABORTONLINGER),
2291da177e4SLinus Torvalds 	SNMP_MIB_ITEM("TCPAbortFailed", LINUX_MIB_TCPABORTFAILED),
2301da177e4SLinus Torvalds 	SNMP_MIB_ITEM("TCPMemoryPressures", LINUX_MIB_TCPMEMORYPRESSURES),
23118f02545SIlpo Järvinen 	SNMP_MIB_ITEM("TCPSACKDiscard", LINUX_MIB_TCPSACKDISCARD),
23218f02545SIlpo Järvinen 	SNMP_MIB_ITEM("TCPDSACKIgnoredOld", LINUX_MIB_TCPDSACKIGNOREDOLD),
23318f02545SIlpo Järvinen 	SNMP_MIB_ITEM("TCPDSACKIgnoredNoUndo", LINUX_MIB_TCPDSACKIGNOREDNOUNDO),
234912d8f0bSIlpo Järvinen 	SNMP_MIB_ITEM("TCPSpuriousRTOs", LINUX_MIB_TCPSPURIOUSRTOS),
235785957d3SDavid S. Miller 	SNMP_MIB_ITEM("TCPMD5NotFound", LINUX_MIB_TCPMD5NOTFOUND),
236785957d3SDavid S. Miller 	SNMP_MIB_ITEM("TCPMD5Unexpected", LINUX_MIB_TCPMD5UNEXPECTED),
237*111cc8b9SIlpo Järvinen 	SNMP_MIB_ITEM("TCPSackShifted", LINUX_MIB_SACKSHIFTED),
238*111cc8b9SIlpo Järvinen 	SNMP_MIB_ITEM("TCPSackMerged", LINUX_MIB_SACKMERGED),
239*111cc8b9SIlpo Järvinen 	SNMP_MIB_ITEM("TCPSackShiftFallback", LINUX_MIB_SACKSHIFTFALLBACK),
2401da177e4SLinus Torvalds 	SNMP_MIB_SENTINEL
2411da177e4SLinus Torvalds };
2421da177e4SLinus Torvalds 
243b971e7acSEric Dumazet static void icmpmsg_put_line(struct seq_file *seq, unsigned long *vals,
244b971e7acSEric Dumazet 			     unsigned short *type, int count)
245b971e7acSEric Dumazet {
246b971e7acSEric Dumazet 	int j;
247b971e7acSEric Dumazet 
248b971e7acSEric Dumazet 	if (count) {
249b971e7acSEric Dumazet 		seq_printf(seq, "\nIcmpMsg:");
250b971e7acSEric Dumazet 		for (j = 0; j < count; ++j)
251b971e7acSEric Dumazet 			seq_printf(seq, " %sType%u",
252b971e7acSEric Dumazet 				type[j] & 0x100 ? "Out" : "In",
253b971e7acSEric Dumazet 				type[j] & 0xff);
254b971e7acSEric Dumazet 		seq_printf(seq, "\nIcmpMsg:");
255b971e7acSEric Dumazet 		for (j = 0; j < count; ++j)
256b971e7acSEric Dumazet 			seq_printf(seq, " %lu", vals[j]);
257b971e7acSEric Dumazet 	}
258b971e7acSEric Dumazet }
259b971e7acSEric Dumazet 
26096793b48SDavid L Stevens static void icmpmsg_put(struct seq_file *seq)
26196793b48SDavid L Stevens {
26296793b48SDavid L Stevens #define PERLINE	16
26396793b48SDavid L Stevens 
264b971e7acSEric Dumazet 	int i, count;
265b971e7acSEric Dumazet 	unsigned short type[PERLINE];
266b971e7acSEric Dumazet 	unsigned long vals[PERLINE], val;
267229bf0cbSPavel Emelyanov 	struct net *net = seq->private;
26896793b48SDavid L Stevens 
26996793b48SDavid L Stevens 	count = 0;
27096793b48SDavid L Stevens 	for (i = 0; i < ICMPMSG_MIB_MAX; i++) {
271b971e7acSEric Dumazet 		val = snmp_fold_field((void **) net->mib.icmpmsg_statistics, i);
272b971e7acSEric Dumazet 		if (val) {
273b971e7acSEric Dumazet 			type[count] = i;
274b971e7acSEric Dumazet 			vals[count++] = val;
27596793b48SDavid L Stevens 		}
276b971e7acSEric Dumazet 		if (count == PERLINE) {
277b971e7acSEric Dumazet 			icmpmsg_put_line(seq, vals, type, count);
278b971e7acSEric Dumazet 			count = 0;
27996793b48SDavid L Stevens 		}
280b971e7acSEric Dumazet 	}
281b971e7acSEric Dumazet 	icmpmsg_put_line(seq, vals, type, count);
28296793b48SDavid L Stevens 
28396793b48SDavid L Stevens #undef PERLINE
28496793b48SDavid L Stevens }
28596793b48SDavid L Stevens 
28696793b48SDavid L Stevens static void icmp_put(struct seq_file *seq)
28796793b48SDavid L Stevens {
28896793b48SDavid L Stevens 	int i;
289229bf0cbSPavel Emelyanov 	struct net *net = seq->private;
29096793b48SDavid L Stevens 
29196793b48SDavid L Stevens 	seq_puts(seq, "\nIcmp: InMsgs InErrors");
29296793b48SDavid L Stevens 	for (i=0; icmpmibmap[i].name != NULL; i++)
29396793b48SDavid L Stevens 		seq_printf(seq, " In%s", icmpmibmap[i].name);
29496793b48SDavid L Stevens 	seq_printf(seq, " OutMsgs OutErrors");
29596793b48SDavid L Stevens 	for (i=0; icmpmibmap[i].name != NULL; i++)
29696793b48SDavid L Stevens 		seq_printf(seq, " Out%s", icmpmibmap[i].name);
29796793b48SDavid L Stevens 	seq_printf(seq, "\nIcmp: %lu %lu",
298229bf0cbSPavel Emelyanov 		snmp_fold_field((void **) net->mib.icmp_statistics, ICMP_MIB_INMSGS),
299229bf0cbSPavel Emelyanov 		snmp_fold_field((void **) net->mib.icmp_statistics, ICMP_MIB_INERRORS));
30096793b48SDavid L Stevens 	for (i=0; icmpmibmap[i].name != NULL; i++)
30196793b48SDavid L Stevens 		seq_printf(seq, " %lu",
302229bf0cbSPavel Emelyanov 			snmp_fold_field((void **) net->mib.icmpmsg_statistics,
30396793b48SDavid L Stevens 				icmpmibmap[i].index));
30496793b48SDavid L Stevens 	seq_printf(seq, " %lu %lu",
305229bf0cbSPavel Emelyanov 		snmp_fold_field((void **) net->mib.icmp_statistics, ICMP_MIB_OUTMSGS),
306229bf0cbSPavel Emelyanov 		snmp_fold_field((void **) net->mib.icmp_statistics, ICMP_MIB_OUTERRORS));
30796793b48SDavid L Stevens 	for (i=0; icmpmibmap[i].name != NULL; i++)
30896793b48SDavid L Stevens 		seq_printf(seq, " %lu",
309229bf0cbSPavel Emelyanov 			snmp_fold_field((void **) net->mib.icmpmsg_statistics,
310064f3605SMitsuru Chinen 				icmpmibmap[i].index | 0x100));
31196793b48SDavid L Stevens }
31296793b48SDavid L Stevens 
3131da177e4SLinus Torvalds /*
3141da177e4SLinus Torvalds  *	Called from the PROCfs module. This outputs /proc/net/snmp.
3151da177e4SLinus Torvalds  */
3161da177e4SLinus Torvalds static int snmp_seq_show(struct seq_file *seq, void *v)
3171da177e4SLinus Torvalds {
3181da177e4SLinus Torvalds 	int i;
319229bf0cbSPavel Emelyanov 	struct net *net = seq->private;
3201da177e4SLinus Torvalds 
3211da177e4SLinus Torvalds 	seq_puts(seq, "Ip: Forwarding DefaultTTL");
3221da177e4SLinus Torvalds 
3231da177e4SLinus Torvalds 	for (i = 0; snmp4_ipstats_list[i].name != NULL; i++)
3241da177e4SLinus Torvalds 		seq_printf(seq, " %s", snmp4_ipstats_list[i].name);
3251da177e4SLinus Torvalds 
3261da177e4SLinus Torvalds 	seq_printf(seq, "\nIp: %d %d",
3278e3461d0SPavel Emelyanov 		   IPV4_DEVCONF_ALL(net, FORWARDING) ? 1 : 2,
328586f1211SPavel Emelyanov 		   sysctl_ip_default_ttl);
3291da177e4SLinus Torvalds 
3301da177e4SLinus Torvalds 	for (i = 0; snmp4_ipstats_list[i].name != NULL; i++)
3311da177e4SLinus Torvalds 		seq_printf(seq, " %lu",
332229bf0cbSPavel Emelyanov 			   snmp_fold_field((void **)net->mib.ip_statistics,
3331da177e4SLinus Torvalds 					   snmp4_ipstats_list[i].entry));
3341da177e4SLinus Torvalds 
33596793b48SDavid L Stevens 	icmp_put(seq);	/* RFC 2011 compatibility */
33696793b48SDavid L Stevens 	icmpmsg_put(seq);
3371da177e4SLinus Torvalds 
3381da177e4SLinus Torvalds 	seq_puts(seq, "\nTcp:");
3391da177e4SLinus Torvalds 	for (i = 0; snmp4_tcp_list[i].name != NULL; i++)
3401da177e4SLinus Torvalds 		seq_printf(seq, " %s", snmp4_tcp_list[i].name);
3411da177e4SLinus Torvalds 
3421da177e4SLinus Torvalds 	seq_puts(seq, "\nTcp:");
3431da177e4SLinus Torvalds 	for (i = 0; snmp4_tcp_list[i].name != NULL; i++) {
3441da177e4SLinus Torvalds 		/* MaxConn field is signed, RFC 2012 */
3451da177e4SLinus Torvalds 		if (snmp4_tcp_list[i].entry == TCP_MIB_MAXCONN)
3461da177e4SLinus Torvalds 			seq_printf(seq, " %ld",
347229bf0cbSPavel Emelyanov 				   snmp_fold_field((void **)net->mib.tcp_statistics,
3481da177e4SLinus Torvalds 						   snmp4_tcp_list[i].entry));
3491da177e4SLinus Torvalds 		else
3501da177e4SLinus Torvalds 			seq_printf(seq, " %lu",
351229bf0cbSPavel Emelyanov 				   snmp_fold_field((void **)net->mib.tcp_statistics,
3521da177e4SLinus Torvalds 						   snmp4_tcp_list[i].entry));
3531da177e4SLinus Torvalds 	}
3541da177e4SLinus Torvalds 
3551da177e4SLinus Torvalds 	seq_puts(seq, "\nUdp:");
3561da177e4SLinus Torvalds 	for (i = 0; snmp4_udp_list[i].name != NULL; i++)
3571da177e4SLinus Torvalds 		seq_printf(seq, " %s", snmp4_udp_list[i].name);
3581da177e4SLinus Torvalds 
3591da177e4SLinus Torvalds 	seq_puts(seq, "\nUdp:");
3601da177e4SLinus Torvalds 	for (i = 0; snmp4_udp_list[i].name != NULL; i++)
3611da177e4SLinus Torvalds 		seq_printf(seq, " %lu",
362229bf0cbSPavel Emelyanov 			   snmp_fold_field((void **)net->mib.udp_statistics,
3631da177e4SLinus Torvalds 					   snmp4_udp_list[i].entry));
3641da177e4SLinus Torvalds 
365ba4e58ecSGerrit Renker 	/* the UDP and UDP-Lite MIBs are the same */
366ba4e58ecSGerrit Renker 	seq_puts(seq, "\nUdpLite:");
367ba4e58ecSGerrit Renker 	for (i = 0; snmp4_udp_list[i].name != NULL; i++)
368ba4e58ecSGerrit Renker 		seq_printf(seq, " %s", snmp4_udp_list[i].name);
369ba4e58ecSGerrit Renker 
370ba4e58ecSGerrit Renker 	seq_puts(seq, "\nUdpLite:");
371ba4e58ecSGerrit Renker 	for (i = 0; snmp4_udp_list[i].name != NULL; i++)
372ba4e58ecSGerrit Renker 		seq_printf(seq, " %lu",
373229bf0cbSPavel Emelyanov 			   snmp_fold_field((void **)net->mib.udplite_statistics,
374ba4e58ecSGerrit Renker 					   snmp4_udp_list[i].entry));
375db8dac20SDavid S. Miller 
3761da177e4SLinus Torvalds 	seq_putc(seq, '\n');
3771da177e4SLinus Torvalds 	return 0;
3781da177e4SLinus Torvalds }
3791da177e4SLinus Torvalds 
3801da177e4SLinus Torvalds static int snmp_seq_open(struct inode *inode, struct file *file)
3811da177e4SLinus Torvalds {
382de05c557SPavel Emelyanov 	return single_open_net(inode, file, snmp_seq_show);
383229bf0cbSPavel Emelyanov }
384229bf0cbSPavel Emelyanov 
3859a32144eSArjan van de Ven static const struct file_operations snmp_seq_fops = {
3861da177e4SLinus Torvalds 	.owner	 = THIS_MODULE,
3871da177e4SLinus Torvalds 	.open	 = snmp_seq_open,
3881da177e4SLinus Torvalds 	.read	 = seq_read,
3891da177e4SLinus Torvalds 	.llseek	 = seq_lseek,
390b6fcbdb4SPavel Emelyanov 	.release = single_release_net,
3911da177e4SLinus Torvalds };
3921da177e4SLinus Torvalds 
39396793b48SDavid L Stevens 
39496793b48SDavid L Stevens 
3951da177e4SLinus Torvalds /*
3961da177e4SLinus Torvalds  *	Output /proc/net/netstat
3971da177e4SLinus Torvalds  */
3981da177e4SLinus Torvalds static int netstat_seq_show(struct seq_file *seq, void *v)
3991da177e4SLinus Torvalds {
4001da177e4SLinus Torvalds 	int i;
4017b7a9dfdSPavel Emelyanov 	struct net *net = seq->private;
4021da177e4SLinus Torvalds 
4031da177e4SLinus Torvalds 	seq_puts(seq, "TcpExt:");
4041da177e4SLinus Torvalds 	for (i = 0; snmp4_net_list[i].name != NULL; i++)
4051da177e4SLinus Torvalds 		seq_printf(seq, " %s", snmp4_net_list[i].name);
4061da177e4SLinus Torvalds 
4071da177e4SLinus Torvalds 	seq_puts(seq, "\nTcpExt:");
4081da177e4SLinus Torvalds 	for (i = 0; snmp4_net_list[i].name != NULL; i++)
4091da177e4SLinus Torvalds 		seq_printf(seq, " %lu",
4107b7a9dfdSPavel Emelyanov 			   snmp_fold_field((void **)net->mib.net_statistics,
4111da177e4SLinus Torvalds 					   snmp4_net_list[i].entry));
4121da177e4SLinus Torvalds 
413d831666eSMitsuru Chinen 	seq_puts(seq, "\nIpExt:");
414d831666eSMitsuru Chinen 	for (i = 0; snmp4_ipextstats_list[i].name != NULL; i++)
415d831666eSMitsuru Chinen 		seq_printf(seq, " %s", snmp4_ipextstats_list[i].name);
416d831666eSMitsuru Chinen 
417d831666eSMitsuru Chinen 	seq_puts(seq, "\nIpExt:");
418d831666eSMitsuru Chinen 	for (i = 0; snmp4_ipextstats_list[i].name != NULL; i++)
419d831666eSMitsuru Chinen 		seq_printf(seq, " %lu",
4207b7a9dfdSPavel Emelyanov 			   snmp_fold_field((void **)net->mib.ip_statistics,
421d831666eSMitsuru Chinen 					   snmp4_ipextstats_list[i].entry));
422d831666eSMitsuru Chinen 
4231da177e4SLinus Torvalds 	seq_putc(seq, '\n');
4241da177e4SLinus Torvalds 	return 0;
4251da177e4SLinus Torvalds }
4261da177e4SLinus Torvalds 
4271da177e4SLinus Torvalds static int netstat_seq_open(struct inode *inode, struct file *file)
4281da177e4SLinus Torvalds {
429de05c557SPavel Emelyanov 	return single_open_net(inode, file, netstat_seq_show);
4307b7a9dfdSPavel Emelyanov }
4317b7a9dfdSPavel Emelyanov 
4329a32144eSArjan van de Ven static const struct file_operations netstat_seq_fops = {
4331da177e4SLinus Torvalds 	.owner	 = THIS_MODULE,
4341da177e4SLinus Torvalds 	.open	 = netstat_seq_open,
4351da177e4SLinus Torvalds 	.read	 = seq_read,
4361da177e4SLinus Torvalds 	.llseek	 = seq_lseek,
437b6fcbdb4SPavel Emelyanov 	.release = single_release_net,
4381da177e4SLinus Torvalds };
4391da177e4SLinus Torvalds 
440d0538ca3SPavel Emelyanov static __net_init int ip_proc_init_net(struct net *net)
441d0538ca3SPavel Emelyanov {
442d0538ca3SPavel Emelyanov 	if (!proc_net_fops_create(net, "sockstat", S_IRUGO, &sockstat_seq_fops))
44360bdde95SPavel Emelyanov 		goto out_sockstat;
4447b7a9dfdSPavel Emelyanov 	if (!proc_net_fops_create(net, "netstat", S_IRUGO, &netstat_seq_fops))
4457b7a9dfdSPavel Emelyanov 		goto out_netstat;
446229bf0cbSPavel Emelyanov 	if (!proc_net_fops_create(net, "snmp", S_IRUGO, &snmp_seq_fops))
447229bf0cbSPavel Emelyanov 		goto out_snmp;
4487b7a9dfdSPavel Emelyanov 
449d0538ca3SPavel Emelyanov 	return 0;
4507b7a9dfdSPavel Emelyanov 
451229bf0cbSPavel Emelyanov out_snmp:
452229bf0cbSPavel Emelyanov 	proc_net_remove(net, "netstat");
4537b7a9dfdSPavel Emelyanov out_netstat:
4547b7a9dfdSPavel Emelyanov 	proc_net_remove(net, "sockstat");
45560bdde95SPavel Emelyanov out_sockstat:
4567b7a9dfdSPavel Emelyanov 	return -ENOMEM;
457d0538ca3SPavel Emelyanov }
458d0538ca3SPavel Emelyanov 
459d0538ca3SPavel Emelyanov static __net_exit void ip_proc_exit_net(struct net *net)
460d0538ca3SPavel Emelyanov {
461229bf0cbSPavel Emelyanov 	proc_net_remove(net, "snmp");
4627b7a9dfdSPavel Emelyanov 	proc_net_remove(net, "netstat");
463d0538ca3SPavel Emelyanov 	proc_net_remove(net, "sockstat");
464d0538ca3SPavel Emelyanov }
465d0538ca3SPavel Emelyanov 
466d0538ca3SPavel Emelyanov static __net_initdata struct pernet_operations ip_proc_ops = {
467d0538ca3SPavel Emelyanov 	.init = ip_proc_init_net,
468d0538ca3SPavel Emelyanov 	.exit = ip_proc_exit_net,
469d0538ca3SPavel Emelyanov };
470d0538ca3SPavel Emelyanov 
4711da177e4SLinus Torvalds int __init ip_misc_proc_init(void)
4721da177e4SLinus Torvalds {
47360bdde95SPavel Emelyanov 	return register_pernet_subsys(&ip_proc_ops);
4741da177e4SLinus Torvalds }
47533490170SYOSHIFUJI Hideaki 
476