12874c5fdSThomas Gleixner // SPDX-License-Identifier: GPL-2.0-or-later
21da177e4SLinus Torvalds /*
31da177e4SLinus Torvalds * INET An implementation of the TCP/IP protocol suite for the LINUX
41da177e4SLinus Torvalds * operating system. INET is implemented using the BSD Socket
51da177e4SLinus Torvalds * interface as the means of communication with the user level.
61da177e4SLinus Torvalds *
71da177e4SLinus Torvalds * This file implements the various access functions for the
81da177e4SLinus Torvalds * PROC file system. It is mainly used for debugging and
91da177e4SLinus Torvalds * statistics.
101da177e4SLinus Torvalds *
111da177e4SLinus Torvalds * Authors: Fred N. van Kempen, <waltje@uWalt.NL.Mugnet.ORG>
121da177e4SLinus Torvalds * Gerald J. Heim, <heim@peanuts.informatik.uni-tuebingen.de>
131da177e4SLinus Torvalds * Fred Baumgarten, <dc6iq@insu1.etec.uni-karlsruhe.de>
141da177e4SLinus Torvalds * Erik Schoenfelder, <schoenfr@ibr.cs.tu-bs.de>
151da177e4SLinus Torvalds *
161da177e4SLinus Torvalds * Fixes:
171da177e4SLinus Torvalds * Alan Cox : UDP sockets show the rxqueue/txqueue
181da177e4SLinus Torvalds * using hint flag for the netinfo.
191da177e4SLinus Torvalds * Pauline Middelink : identd support
201da177e4SLinus Torvalds * Alan Cox : Make /proc safer.
211da177e4SLinus Torvalds * Erik Schoenfelder : /proc/net/snmp
221da177e4SLinus Torvalds * Alan Cox : Handle dead sockets properly.
231da177e4SLinus Torvalds * Gerhard Koerting : Show both timers
241da177e4SLinus Torvalds * Alan Cox : Allow inode to be NULL (kernel socket)
251da177e4SLinus Torvalds * Andi Kleen : Add support for open_requests and
261da177e4SLinus Torvalds * split functions for more readibility.
271da177e4SLinus Torvalds * Andi Kleen : Add support for /proc/net/netstat
281da177e4SLinus Torvalds * Arnaldo C. Melo : Convert to seq_file
291da177e4SLinus Torvalds */
301da177e4SLinus Torvalds #include <linux/types.h>
31457c4cbcSEric W. Biederman #include <net/net_namespace.h>
321da177e4SLinus Torvalds #include <net/icmp.h>
331da177e4SLinus Torvalds #include <net/protocol.h>
341da177e4SLinus Torvalds #include <net/tcp.h>
35fc518953SFlorian Westphal #include <net/mptcp.h>
361da177e4SLinus Torvalds #include <net/udp.h>
37ba4e58ecSGerrit Renker #include <net/udplite.h>
38eb4dea58SHerbert Xu #include <linux/bottom_half.h>
3914c85021SArnaldo Carvalho de Melo #include <linux/inetdevice.h>
401da177e4SLinus Torvalds #include <linux/proc_fs.h>
411da177e4SLinus Torvalds #include <linux/seq_file.h>
42bc3b2d7fSPaul Gortmaker #include <linux/export.h>
431da177e4SLinus Torvalds #include <net/sock.h>
441da177e4SLinus Torvalds #include <net/raw.h>
451da177e4SLinus Torvalds
46f22d5c49SJia He #define TCPUDP_MIB_MAX max_t(u32, UDP_MIB_MAX, TCP_MIB_MAX)
47f22d5c49SJia He
481da177e4SLinus Torvalds /*
491da177e4SLinus Torvalds * Report socket allocation statistics [mea@utu.fi]
501da177e4SLinus Torvalds */
sockstat_seq_show(struct seq_file * seq,void * v)511da177e4SLinus Torvalds static int sockstat_seq_show(struct seq_file *seq, void *v)
521da177e4SLinus Torvalds {
53fd4e7b50SPavel Emelyanov struct net *net = seq->private;
54eb4dea58SHerbert Xu int orphans, sockets;
55eb4dea58SHerbert Xu
5619757cebSEric Dumazet orphans = tcp_orphan_count_sum();
57180d8cd9SGlauber Costa sockets = proto_sockets_allocated_sum_positive(&tcp_prot);
58fd4e7b50SPavel Emelyanov
591da177e4SLinus Torvalds socket_seq_show(seq);
608d987e5cSEric Dumazet seq_printf(seq, "TCP: inuse %d orphan %d tw %d alloc %d mem %ld\n",
61eb4dea58SHerbert Xu sock_prot_inuse_get(net, &tcp_prot), orphans,
62e9bd0ccaSKuniyuki Iwashima refcount_read(&net->ipv4.tcp_death_row.tw_refcount) - 1,
63fbb82952SEric Dumazet sockets, proto_memory_allocated(&tcp_prot));
648d987e5cSEric Dumazet seq_printf(seq, "UDP: inuse %d mem %ld\n",
65fd4e7b50SPavel Emelyanov sock_prot_inuse_get(net, &udp_prot),
66180d8cd9SGlauber Costa proto_memory_allocated(&udp_prot));
67c29a0bc4SPavel Emelyanov seq_printf(seq, "UDPLITE: inuse %d\n",
68fd4e7b50SPavel Emelyanov sock_prot_inuse_get(net, &udplite_prot));
69c29a0bc4SPavel Emelyanov seq_printf(seq, "RAW: inuse %d\n",
70fd4e7b50SPavel Emelyanov sock_prot_inuse_get(net, &raw_prot));
713e67f106SEric Dumazet seq_printf(seq, "FRAG: inuse %u memory %lu\n",
724907abc6SEric Dumazet atomic_read(&net->ipv4.fqdir->rhashtable.nelems),
734907abc6SEric Dumazet frag_mem_limit(net->ipv4.fqdir));
741da177e4SLinus Torvalds return 0;
751da177e4SLinus Torvalds }
761da177e4SLinus Torvalds
771da177e4SLinus Torvalds /* snmp items */
789b5b5cffSArjan van de Ven static const struct snmp_mib snmp4_ipstats_list[] = {
79edf391ffSNeil Horman SNMP_MIB_ITEM("InReceives", IPSTATS_MIB_INPKTS),
801da177e4SLinus Torvalds SNMP_MIB_ITEM("InHdrErrors", IPSTATS_MIB_INHDRERRORS),
811da177e4SLinus Torvalds SNMP_MIB_ITEM("InAddrErrors", IPSTATS_MIB_INADDRERRORS),
821da177e4SLinus Torvalds SNMP_MIB_ITEM("ForwDatagrams", IPSTATS_MIB_OUTFORWDATAGRAMS),
831da177e4SLinus Torvalds SNMP_MIB_ITEM("InUnknownProtos", IPSTATS_MIB_INUNKNOWNPROTOS),
841da177e4SLinus Torvalds SNMP_MIB_ITEM("InDiscards", IPSTATS_MIB_INDISCARDS),
851da177e4SLinus Torvalds SNMP_MIB_ITEM("InDelivers", IPSTATS_MIB_INDELIVERS),
86*56712f74SHeng Guo SNMP_MIB_ITEM("OutRequests", IPSTATS_MIB_OUTREQUESTS),
871da177e4SLinus Torvalds SNMP_MIB_ITEM("OutDiscards", IPSTATS_MIB_OUTDISCARDS),
881da177e4SLinus Torvalds SNMP_MIB_ITEM("OutNoRoutes", IPSTATS_MIB_OUTNOROUTES),
891da177e4SLinus Torvalds SNMP_MIB_ITEM("ReasmTimeout", IPSTATS_MIB_REASMTIMEOUT),
901da177e4SLinus Torvalds SNMP_MIB_ITEM("ReasmReqds", IPSTATS_MIB_REASMREQDS),
911da177e4SLinus Torvalds SNMP_MIB_ITEM("ReasmOKs", IPSTATS_MIB_REASMOKS),
921da177e4SLinus Torvalds SNMP_MIB_ITEM("ReasmFails", IPSTATS_MIB_REASMFAILS),
931da177e4SLinus Torvalds SNMP_MIB_ITEM("FragOKs", IPSTATS_MIB_FRAGOKS),
941da177e4SLinus Torvalds SNMP_MIB_ITEM("FragFails", IPSTATS_MIB_FRAGFAILS),
951da177e4SLinus Torvalds SNMP_MIB_ITEM("FragCreates", IPSTATS_MIB_FRAGCREATES),
96*56712f74SHeng Guo SNMP_MIB_ITEM("OutTransmits", IPSTATS_MIB_OUTPKTS),
971da177e4SLinus Torvalds SNMP_MIB_SENTINEL
981da177e4SLinus Torvalds };
991da177e4SLinus Torvalds
1001f07d03eSEric Dumazet /* Following items are displayed in /proc/net/netstat */
101d831666eSMitsuru Chinen static const struct snmp_mib snmp4_ipextstats_list[] = {
102d831666eSMitsuru Chinen SNMP_MIB_ITEM("InNoRoutes", IPSTATS_MIB_INNOROUTES),
103d831666eSMitsuru Chinen SNMP_MIB_ITEM("InTruncatedPkts", IPSTATS_MIB_INTRUNCATEDPKTS),
104d831666eSMitsuru Chinen SNMP_MIB_ITEM("InMcastPkts", IPSTATS_MIB_INMCASTPKTS),
105d831666eSMitsuru Chinen SNMP_MIB_ITEM("OutMcastPkts", IPSTATS_MIB_OUTMCASTPKTS),
106d831666eSMitsuru Chinen SNMP_MIB_ITEM("InBcastPkts", IPSTATS_MIB_INBCASTPKTS),
107d831666eSMitsuru Chinen SNMP_MIB_ITEM("OutBcastPkts", IPSTATS_MIB_OUTBCASTPKTS),
108edf391ffSNeil Horman SNMP_MIB_ITEM("InOctets", IPSTATS_MIB_INOCTETS),
109edf391ffSNeil Horman SNMP_MIB_ITEM("OutOctets", IPSTATS_MIB_OUTOCTETS),
110edf391ffSNeil Horman SNMP_MIB_ITEM("InMcastOctets", IPSTATS_MIB_INMCASTOCTETS),
111edf391ffSNeil Horman SNMP_MIB_ITEM("OutMcastOctets", IPSTATS_MIB_OUTMCASTOCTETS),
112edf391ffSNeil Horman SNMP_MIB_ITEM("InBcastOctets", IPSTATS_MIB_INBCASTOCTETS),
113edf391ffSNeil Horman SNMP_MIB_ITEM("OutBcastOctets", IPSTATS_MIB_OUTBCASTOCTETS),
1141f07d03eSEric Dumazet /* Non RFC4293 fields */
1156a5dc9e5SEric Dumazet SNMP_MIB_ITEM("InCsumErrors", IPSTATS_MIB_CSUMERRORS),
1161f07d03eSEric Dumazet SNMP_MIB_ITEM("InNoECTPkts", IPSTATS_MIB_NOECTPKTS),
1171f07d03eSEric Dumazet SNMP_MIB_ITEM("InECT1Pkts", IPSTATS_MIB_ECT1PKTS),
1181f07d03eSEric Dumazet SNMP_MIB_ITEM("InECT0Pkts", IPSTATS_MIB_ECT0PKTS),
1191f07d03eSEric Dumazet SNMP_MIB_ITEM("InCEPkts", IPSTATS_MIB_CEPKTS),
1207969e5c4SPeter Oskolkov SNMP_MIB_ITEM("ReasmOverlaps", IPSTATS_MIB_REASM_OVERLAPS),
121d831666eSMitsuru Chinen SNMP_MIB_SENTINEL
122d831666eSMitsuru Chinen };
123d831666eSMitsuru Chinen
1245833929cSAlexey Dobriyan static const struct {
1255833929cSAlexey Dobriyan const char *name;
12696793b48SDavid L Stevens int index;
12796793b48SDavid L Stevens } icmpmibmap[] = {
12896793b48SDavid L Stevens { "DestUnreachs", ICMP_DEST_UNREACH },
12996793b48SDavid L Stevens { "TimeExcds", ICMP_TIME_EXCEEDED },
13096793b48SDavid L Stevens { "ParmProbs", ICMP_PARAMETERPROB },
13196793b48SDavid L Stevens { "SrcQuenchs", ICMP_SOURCE_QUENCH },
13296793b48SDavid L Stevens { "Redirects", ICMP_REDIRECT },
13396793b48SDavid L Stevens { "Echos", ICMP_ECHO },
13496793b48SDavid L Stevens { "EchoReps", ICMP_ECHOREPLY },
13596793b48SDavid L Stevens { "Timestamps", ICMP_TIMESTAMP },
13696793b48SDavid L Stevens { "TimestampReps", ICMP_TIMESTAMPREPLY },
13796793b48SDavid L Stevens { "AddrMasks", ICMP_ADDRESS },
13896793b48SDavid L Stevens { "AddrMaskReps", ICMP_ADDRESSREPLY },
139cfcabdccSStephen Hemminger { NULL, 0 }
14096793b48SDavid L Stevens };
14196793b48SDavid L Stevens
14296793b48SDavid L Stevens
1439b5b5cffSArjan van de Ven static const struct snmp_mib snmp4_tcp_list[] = {
1441da177e4SLinus Torvalds SNMP_MIB_ITEM("RtoAlgorithm", TCP_MIB_RTOALGORITHM),
1451da177e4SLinus Torvalds SNMP_MIB_ITEM("RtoMin", TCP_MIB_RTOMIN),
1461da177e4SLinus Torvalds SNMP_MIB_ITEM("RtoMax", TCP_MIB_RTOMAX),
1471da177e4SLinus Torvalds SNMP_MIB_ITEM("MaxConn", TCP_MIB_MAXCONN),
1481da177e4SLinus Torvalds SNMP_MIB_ITEM("ActiveOpens", TCP_MIB_ACTIVEOPENS),
1491da177e4SLinus Torvalds SNMP_MIB_ITEM("PassiveOpens", TCP_MIB_PASSIVEOPENS),
1501da177e4SLinus Torvalds SNMP_MIB_ITEM("AttemptFails", TCP_MIB_ATTEMPTFAILS),
1511da177e4SLinus Torvalds SNMP_MIB_ITEM("EstabResets", TCP_MIB_ESTABRESETS),
1521da177e4SLinus Torvalds SNMP_MIB_ITEM("CurrEstab", TCP_MIB_CURRESTAB),
1531da177e4SLinus Torvalds SNMP_MIB_ITEM("InSegs", TCP_MIB_INSEGS),
1541da177e4SLinus Torvalds SNMP_MIB_ITEM("OutSegs", TCP_MIB_OUTSEGS),
1551da177e4SLinus Torvalds SNMP_MIB_ITEM("RetransSegs", TCP_MIB_RETRANSSEGS),
1561da177e4SLinus Torvalds SNMP_MIB_ITEM("InErrs", TCP_MIB_INERRS),
1571da177e4SLinus Torvalds SNMP_MIB_ITEM("OutRsts", TCP_MIB_OUTRSTS),
1586a5dc9e5SEric Dumazet SNMP_MIB_ITEM("InCsumErrors", TCP_MIB_CSUMERRORS),
1591da177e4SLinus Torvalds SNMP_MIB_SENTINEL
1601da177e4SLinus Torvalds };
1611da177e4SLinus Torvalds
1629b5b5cffSArjan van de Ven static const struct snmp_mib snmp4_udp_list[] = {
1631da177e4SLinus Torvalds SNMP_MIB_ITEM("InDatagrams", UDP_MIB_INDATAGRAMS),
1641da177e4SLinus Torvalds SNMP_MIB_ITEM("NoPorts", UDP_MIB_NOPORTS),
1651da177e4SLinus Torvalds SNMP_MIB_ITEM("InErrors", UDP_MIB_INERRORS),
1661da177e4SLinus Torvalds SNMP_MIB_ITEM("OutDatagrams", UDP_MIB_OUTDATAGRAMS),
16781aa646cSMartin Bligh SNMP_MIB_ITEM("RcvbufErrors", UDP_MIB_RCVBUFERRORS),
16881aa646cSMartin Bligh SNMP_MIB_ITEM("SndbufErrors", UDP_MIB_SNDBUFERRORS),
1696a5dc9e5SEric Dumazet SNMP_MIB_ITEM("InCsumErrors", UDP_MIB_CSUMERRORS),
17036cbb245SRick Jones SNMP_MIB_ITEM("IgnoredMulti", UDP_MIB_IGNOREDMULTI),
171a3ce2b10SMenglong Dong SNMP_MIB_ITEM("MemErrors", UDP_MIB_MEMERRORS),
1721da177e4SLinus Torvalds SNMP_MIB_SENTINEL
1731da177e4SLinus Torvalds };
1741da177e4SLinus Torvalds
1759b5b5cffSArjan van de Ven static const struct snmp_mib snmp4_net_list[] = {
1761da177e4SLinus Torvalds SNMP_MIB_ITEM("SyncookiesSent", LINUX_MIB_SYNCOOKIESSENT),
1771da177e4SLinus Torvalds SNMP_MIB_ITEM("SyncookiesRecv", LINUX_MIB_SYNCOOKIESRECV),
1781da177e4SLinus Torvalds SNMP_MIB_ITEM("SyncookiesFailed", LINUX_MIB_SYNCOOKIESFAILED),
1791da177e4SLinus Torvalds SNMP_MIB_ITEM("EmbryonicRsts", LINUX_MIB_EMBRYONICRSTS),
1801da177e4SLinus Torvalds SNMP_MIB_ITEM("PruneCalled", LINUX_MIB_PRUNECALLED),
1811da177e4SLinus Torvalds SNMP_MIB_ITEM("RcvPruned", LINUX_MIB_RCVPRUNED),
1821da177e4SLinus Torvalds SNMP_MIB_ITEM("OfoPruned", LINUX_MIB_OFOPRUNED),
1831da177e4SLinus Torvalds SNMP_MIB_ITEM("OutOfWindowIcmps", LINUX_MIB_OUTOFWINDOWICMPS),
1841da177e4SLinus Torvalds SNMP_MIB_ITEM("LockDroppedIcmps", LINUX_MIB_LOCKDROPPEDICMPS),
1851da177e4SLinus Torvalds SNMP_MIB_ITEM("ArpFilter", LINUX_MIB_ARPFILTER),
1861da177e4SLinus Torvalds SNMP_MIB_ITEM("TW", LINUX_MIB_TIMEWAITED),
1871da177e4SLinus Torvalds SNMP_MIB_ITEM("TWRecycled", LINUX_MIB_TIMEWAITRECYCLED),
1881da177e4SLinus Torvalds SNMP_MIB_ITEM("TWKilled", LINUX_MIB_TIMEWAITKILLED),
1891da177e4SLinus Torvalds SNMP_MIB_ITEM("PAWSActive", LINUX_MIB_PAWSACTIVEREJECTED),
1901da177e4SLinus Torvalds SNMP_MIB_ITEM("PAWSEstab", LINUX_MIB_PAWSESTABREJECTED),
1911da177e4SLinus Torvalds SNMP_MIB_ITEM("DelayedACKs", LINUX_MIB_DELAYEDACKS),
1921da177e4SLinus Torvalds SNMP_MIB_ITEM("DelayedACKLocked", LINUX_MIB_DELAYEDACKLOCKED),
1931da177e4SLinus Torvalds SNMP_MIB_ITEM("DelayedACKLost", LINUX_MIB_DELAYEDACKLOST),
1941da177e4SLinus Torvalds SNMP_MIB_ITEM("ListenOverflows", LINUX_MIB_LISTENOVERFLOWS),
1951da177e4SLinus Torvalds SNMP_MIB_ITEM("ListenDrops", LINUX_MIB_LISTENDROPS),
19631770e34SFlorian Westphal SNMP_MIB_ITEM("TCPHPHits", LINUX_MIB_TCPHPHITS),
1971da177e4SLinus Torvalds SNMP_MIB_ITEM("TCPPureAcks", LINUX_MIB_TCPPUREACKS),
19831770e34SFlorian Westphal SNMP_MIB_ITEM("TCPHPAcks", LINUX_MIB_TCPHPACKS),
1991da177e4SLinus Torvalds SNMP_MIB_ITEM("TCPRenoRecovery", LINUX_MIB_TCPRENORECOVERY),
2001da177e4SLinus Torvalds SNMP_MIB_ITEM("TCPSackRecovery", LINUX_MIB_TCPSACKRECOVERY),
2011da177e4SLinus Torvalds SNMP_MIB_ITEM("TCPSACKReneging", LINUX_MIB_TCPSACKRENEGING),
2021da177e4SLinus Torvalds SNMP_MIB_ITEM("TCPSACKReorder", LINUX_MIB_TCPSACKREORDER),
2031da177e4SLinus Torvalds SNMP_MIB_ITEM("TCPRenoReorder", LINUX_MIB_TCPRENOREORDER),
2041da177e4SLinus Torvalds SNMP_MIB_ITEM("TCPTSReorder", LINUX_MIB_TCPTSREORDER),
2051da177e4SLinus Torvalds SNMP_MIB_ITEM("TCPFullUndo", LINUX_MIB_TCPFULLUNDO),
2061da177e4SLinus Torvalds SNMP_MIB_ITEM("TCPPartialUndo", LINUX_MIB_TCPPARTIALUNDO),
2071da177e4SLinus Torvalds SNMP_MIB_ITEM("TCPDSACKUndo", LINUX_MIB_TCPDSACKUNDO),
2081da177e4SLinus Torvalds SNMP_MIB_ITEM("TCPLossUndo", LINUX_MIB_TCPLOSSUNDO),
2091da177e4SLinus Torvalds SNMP_MIB_ITEM("TCPLostRetransmit", LINUX_MIB_TCPLOSTRETRANSMIT),
2101da177e4SLinus Torvalds SNMP_MIB_ITEM("TCPRenoFailures", LINUX_MIB_TCPRENOFAILURES),
2111da177e4SLinus Torvalds SNMP_MIB_ITEM("TCPSackFailures", LINUX_MIB_TCPSACKFAILURES),
2121da177e4SLinus Torvalds SNMP_MIB_ITEM("TCPLossFailures", LINUX_MIB_TCPLOSSFAILURES),
2131da177e4SLinus Torvalds SNMP_MIB_ITEM("TCPFastRetrans", LINUX_MIB_TCPFASTRETRANS),
2141da177e4SLinus Torvalds SNMP_MIB_ITEM("TCPSlowStartRetrans", LINUX_MIB_TCPSLOWSTARTRETRANS),
2151da177e4SLinus Torvalds SNMP_MIB_ITEM("TCPTimeouts", LINUX_MIB_TCPTIMEOUTS),
2166ba8a3b1SNandita Dukkipati SNMP_MIB_ITEM("TCPLossProbes", LINUX_MIB_TCPLOSSPROBES),
2179b717a8dSNandita Dukkipati SNMP_MIB_ITEM("TCPLossProbeRecovery", LINUX_MIB_TCPLOSSPROBERECOVERY),
2181da177e4SLinus Torvalds SNMP_MIB_ITEM("TCPRenoRecoveryFail", LINUX_MIB_TCPRENORECOVERYFAIL),
2191da177e4SLinus Torvalds SNMP_MIB_ITEM("TCPSackRecoveryFail", LINUX_MIB_TCPSACKRECOVERYFAIL),
2201da177e4SLinus Torvalds SNMP_MIB_ITEM("TCPRcvCollapsed", LINUX_MIB_TCPRCVCOLLAPSED),
2214f693b55SEric Dumazet SNMP_MIB_ITEM("TCPBacklogCoalesce", LINUX_MIB_TCPBACKLOGCOALESCE),
2221da177e4SLinus Torvalds SNMP_MIB_ITEM("TCPDSACKOldSent", LINUX_MIB_TCPDSACKOLDSENT),
2231da177e4SLinus Torvalds SNMP_MIB_ITEM("TCPDSACKOfoSent", LINUX_MIB_TCPDSACKOFOSENT),
2241da177e4SLinus Torvalds SNMP_MIB_ITEM("TCPDSACKRecv", LINUX_MIB_TCPDSACKRECV),
2251da177e4SLinus Torvalds SNMP_MIB_ITEM("TCPDSACKOfoRecv", LINUX_MIB_TCPDSACKOFORECV),
2261da177e4SLinus Torvalds SNMP_MIB_ITEM("TCPAbortOnData", LINUX_MIB_TCPABORTONDATA),
2271da177e4SLinus Torvalds SNMP_MIB_ITEM("TCPAbortOnClose", LINUX_MIB_TCPABORTONCLOSE),
2281da177e4SLinus Torvalds SNMP_MIB_ITEM("TCPAbortOnMemory", LINUX_MIB_TCPABORTONMEMORY),
2291da177e4SLinus Torvalds SNMP_MIB_ITEM("TCPAbortOnTimeout", LINUX_MIB_TCPABORTONTIMEOUT),
2301da177e4SLinus Torvalds SNMP_MIB_ITEM("TCPAbortOnLinger", LINUX_MIB_TCPABORTONLINGER),
2311da177e4SLinus Torvalds SNMP_MIB_ITEM("TCPAbortFailed", LINUX_MIB_TCPABORTFAILED),
2321da177e4SLinus Torvalds SNMP_MIB_ITEM("TCPMemoryPressures", LINUX_MIB_TCPMEMORYPRESSURES),
23306044751SEric Dumazet SNMP_MIB_ITEM("TCPMemoryPressuresChrono", LINUX_MIB_TCPMEMORYPRESSURESCHRONO),
23418f02545SIlpo Järvinen SNMP_MIB_ITEM("TCPSACKDiscard", LINUX_MIB_TCPSACKDISCARD),
23518f02545SIlpo Järvinen SNMP_MIB_ITEM("TCPDSACKIgnoredOld", LINUX_MIB_TCPDSACKIGNOREDOLD),
23618f02545SIlpo Järvinen SNMP_MIB_ITEM("TCPDSACKIgnoredNoUndo", LINUX_MIB_TCPDSACKIGNOREDNOUNDO),
237912d8f0bSIlpo Järvinen SNMP_MIB_ITEM("TCPSpuriousRTOs", LINUX_MIB_TCPSPURIOUSRTOS),
238785957d3SDavid S. Miller SNMP_MIB_ITEM("TCPMD5NotFound", LINUX_MIB_TCPMD5NOTFOUND),
239785957d3SDavid S. Miller SNMP_MIB_ITEM("TCPMD5Unexpected", LINUX_MIB_TCPMD5UNEXPECTED),
24072145a68SEric Dumazet SNMP_MIB_ITEM("TCPMD5Failure", LINUX_MIB_TCPMD5FAILURE),
241111cc8b9SIlpo Järvinen SNMP_MIB_ITEM("TCPSackShifted", LINUX_MIB_SACKSHIFTED),
242111cc8b9SIlpo Järvinen SNMP_MIB_ITEM("TCPSackMerged", LINUX_MIB_SACKMERGED),
243111cc8b9SIlpo Järvinen SNMP_MIB_ITEM("TCPSackShiftFallback", LINUX_MIB_SACKSHIFTFALLBACK),
2446cce09f8SEric Dumazet SNMP_MIB_ITEM("TCPBacklogDrop", LINUX_MIB_TCPBACKLOGDROP),
2458fe809a9SEric Dumazet SNMP_MIB_ITEM("PFMemallocDrop", LINUX_MIB_PFMEMALLOCDROP),
2466cce09f8SEric Dumazet SNMP_MIB_ITEM("TCPMinTTLDrop", LINUX_MIB_TCPMINTTLDROP),
247907cdda5SEric Dumazet SNMP_MIB_ITEM("TCPDeferAcceptDrop", LINUX_MIB_TCPDEFERACCEPTDROP),
248b5f7e755SEric Dumazet SNMP_MIB_ITEM("IPReversePathFilter", LINUX_MIB_IPRPFILTER),
24967631510STom Herbert SNMP_MIB_ITEM("TCPTimeWaitOverflow", LINUX_MIB_TCPTIMEWAITOVERFLOW),
250946cedccSEric Dumazet SNMP_MIB_ITEM("TCPReqQFullDoCookies", LINUX_MIB_TCPREQQFULLDOCOOKIES),
251946cedccSEric Dumazet SNMP_MIB_ITEM("TCPReqQFullDrop", LINUX_MIB_TCPREQQFULLDROP),
25209e9b813SEric Dumazet SNMP_MIB_ITEM("TCPRetransFail", LINUX_MIB_TCPRETRANSFAIL),
253c8628155SEric Dumazet SNMP_MIB_ITEM("TCPRcvCoalesce", LINUX_MIB_TCPRCVCOALESCE),
254a6df1ae9SEric Dumazet SNMP_MIB_ITEM("TCPOFOQueue", LINUX_MIB_TCPOFOQUEUE),
255a6df1ae9SEric Dumazet SNMP_MIB_ITEM("TCPOFODrop", LINUX_MIB_TCPOFODROP),
256a6df1ae9SEric Dumazet SNMP_MIB_ITEM("TCPOFOMerge", LINUX_MIB_TCPOFOMERGE),
257282f23c6SEric Dumazet SNMP_MIB_ITEM("TCPChallengeACK", LINUX_MIB_TCPCHALLENGEACK),
2580c24604bSEric Dumazet SNMP_MIB_ITEM("TCPSYNChallenge", LINUX_MIB_TCPSYNCHALLENGE),
259783237e8SYuchung Cheng SNMP_MIB_ITEM("TCPFastOpenActive", LINUX_MIB_TCPFASTOPENACTIVE),
260f19c29e3SYuchung Cheng SNMP_MIB_ITEM("TCPFastOpenActiveFail", LINUX_MIB_TCPFASTOPENACTIVEFAIL),
26110467163SJerry Chu SNMP_MIB_ITEM("TCPFastOpenPassive", LINUX_MIB_TCPFASTOPENPASSIVE),
26210467163SJerry Chu SNMP_MIB_ITEM("TCPFastOpenPassiveFail", LINUX_MIB_TCPFASTOPENPASSIVEFAIL),
26310467163SJerry Chu SNMP_MIB_ITEM("TCPFastOpenListenOverflow", LINUX_MIB_TCPFASTOPENLISTENOVERFLOW),
26410467163SJerry Chu SNMP_MIB_ITEM("TCPFastOpenCookieReqd", LINUX_MIB_TCPFASTOPENCOOKIEREQD),
26546c2fa39SWei Wang SNMP_MIB_ITEM("TCPFastOpenBlackhole", LINUX_MIB_TCPFASTOPENBLACKHOLE),
2660e280af0SEric Dumazet SNMP_MIB_ITEM("TCPSpuriousRtxHostQueues", LINUX_MIB_TCPSPURIOUS_RTX_HOSTQUEUES),
267288a9376SEliezer Tamir SNMP_MIB_ITEM("BusyPollRxPackets", LINUX_MIB_BUSYPOLLRXPACKETS),
268f54b3111SEric Dumazet SNMP_MIB_ITEM("TCPAutoCorking", LINUX_MIB_TCPAUTOCORKING),
2698e165e20SFlorian Westphal SNMP_MIB_ITEM("TCPFromZeroWindowAdv", LINUX_MIB_TCPFROMZEROWINDOWADV),
2708e165e20SFlorian Westphal SNMP_MIB_ITEM("TCPToZeroWindowAdv", LINUX_MIB_TCPTOZEROWINDOWADV),
2718e165e20SFlorian Westphal SNMP_MIB_ITEM("TCPWantZeroWindowAdv", LINUX_MIB_TCPWANTZEROWINDOWADV),
272f19c29e3SYuchung Cheng SNMP_MIB_ITEM("TCPSynRetrans", LINUX_MIB_TCPSYNRETRANS),
273f19c29e3SYuchung Cheng SNMP_MIB_ITEM("TCPOrigDataSent", LINUX_MIB_TCPORIGDATASENT),
2746e3a8a93SEric Dumazet SNMP_MIB_ITEM("TCPHystartTrainDetect", LINUX_MIB_TCPHYSTARTTRAINDETECT),
2756e3a8a93SEric Dumazet SNMP_MIB_ITEM("TCPHystartTrainCwnd", LINUX_MIB_TCPHYSTARTTRAINCWND),
2766e3a8a93SEric Dumazet SNMP_MIB_ITEM("TCPHystartDelayDetect", LINUX_MIB_TCPHYSTARTDELAYDETECT),
2776e3a8a93SEric Dumazet SNMP_MIB_ITEM("TCPHystartDelayCwnd", LINUX_MIB_TCPHYSTARTDELAYCWND),
278032ee423SNeal Cardwell SNMP_MIB_ITEM("TCPACKSkippedSynRecv", LINUX_MIB_TCPACKSKIPPEDSYNRECV),
279032ee423SNeal Cardwell SNMP_MIB_ITEM("TCPACKSkippedPAWS", LINUX_MIB_TCPACKSKIPPEDPAWS),
280032ee423SNeal Cardwell SNMP_MIB_ITEM("TCPACKSkippedSeq", LINUX_MIB_TCPACKSKIPPEDSEQ),
281032ee423SNeal Cardwell SNMP_MIB_ITEM("TCPACKSkippedFinWait2", LINUX_MIB_TCPACKSKIPPEDFINWAIT2),
282032ee423SNeal Cardwell SNMP_MIB_ITEM("TCPACKSkippedTimeWait", LINUX_MIB_TCPACKSKIPPEDTIMEWAIT),
283032ee423SNeal Cardwell SNMP_MIB_ITEM("TCPACKSkippedChallenge", LINUX_MIB_TCPACKSKIPPEDCHALLENGE),
284e520af48SEric Dumazet SNMP_MIB_ITEM("TCPWinProbe", LINUX_MIB_TCPWINPROBE),
285e520af48SEric Dumazet SNMP_MIB_ITEM("TCPKeepAlive", LINUX_MIB_TCPKEEPALIVE),
286b56ea298SRick Jones SNMP_MIB_ITEM("TCPMTUPFail", LINUX_MIB_TCPMTUPFAIL),
287b56ea298SRick Jones SNMP_MIB_ITEM("TCPMTUPSuccess", LINUX_MIB_TCPMTUPSUCCESS),
288feb5f2ecSYuchung Cheng SNMP_MIB_ITEM("TCPDelivered", LINUX_MIB_TCPDELIVERED),
289feb5f2ecSYuchung Cheng SNMP_MIB_ITEM("TCPDeliveredCE", LINUX_MIB_TCPDELIVEREDCE),
290200d95f4SEric Dumazet SNMP_MIB_ITEM("TCPAckCompressed", LINUX_MIB_TCPACKCOMPRESSED),
291fb223502SYafang Shao SNMP_MIB_ITEM("TCPZeroWindowDrop", LINUX_MIB_TCPZEROWINDOWDROP),
292ea5d0c32SYafang Shao SNMP_MIB_ITEM("TCPRcvQDrop", LINUX_MIB_TCPRCVQDROP),
293f070ef2aSEric Dumazet SNMP_MIB_ITEM("TCPWqueueTooBig", LINUX_MIB_TCPWQUEUETOOBIG),
2949092a76dSJason Baron SNMP_MIB_ITEM("TCPFastOpenPassiveAltKey", LINUX_MIB_TCPFASTOPENPASSIVEALTKEY),
29532efcc06SAbdul Kabbani SNMP_MIB_ITEM("TcpTimeoutRehash", LINUX_MIB_TCPTIMEOUTREHASH),
29632efcc06SAbdul Kabbani SNMP_MIB_ITEM("TcpDuplicateDataRehash", LINUX_MIB_TCPDUPLICATEDATAREHASH),
297e3a5a1e8SPriyaranjan Jha SNMP_MIB_ITEM("TCPDSACKRecvSegs", LINUX_MIB_TCPDSACKRECVSEGS),
298ad2b9b0fSPriyaranjan Jha SNMP_MIB_ITEM("TCPDSACKIgnoredDubious", LINUX_MIB_TCPDSACKIGNOREDDUBIOUS),
29955d444b3SKuniyuki Iwashima SNMP_MIB_ITEM("TCPMigrateReqSuccess", LINUX_MIB_TCPMIGRATEREQSUCCESS),
30055d444b3SKuniyuki Iwashima SNMP_MIB_ITEM("TCPMigrateReqFailure", LINUX_MIB_TCPMIGRATEREQFAILURE),
30129c1c446SMubashir Adnan Qureshi SNMP_MIB_ITEM("TCPPLBRehash", LINUX_MIB_TCPPLBREHASH),
3021da177e4SLinus Torvalds SNMP_MIB_SENTINEL
3031da177e4SLinus Torvalds };
3041da177e4SLinus Torvalds
icmpmsg_put_line(struct seq_file * seq,unsigned long * vals,unsigned short * type,int count)305b971e7acSEric Dumazet static void icmpmsg_put_line(struct seq_file *seq, unsigned long *vals,
306b971e7acSEric Dumazet unsigned short *type, int count)
307b971e7acSEric Dumazet {
308b971e7acSEric Dumazet int j;
309b971e7acSEric Dumazet
310b971e7acSEric Dumazet if (count) {
311c9f503b0SFabian Frederick seq_puts(seq, "\nIcmpMsg:");
312b971e7acSEric Dumazet for (j = 0; j < count; ++j)
313b971e7acSEric Dumazet seq_printf(seq, " %sType%u",
314b971e7acSEric Dumazet type[j] & 0x100 ? "Out" : "In",
315b971e7acSEric Dumazet type[j] & 0xff);
316c9f503b0SFabian Frederick seq_puts(seq, "\nIcmpMsg:");
317b971e7acSEric Dumazet for (j = 0; j < count; ++j)
318b971e7acSEric Dumazet seq_printf(seq, " %lu", vals[j]);
319b971e7acSEric Dumazet }
320b971e7acSEric Dumazet }
321b971e7acSEric Dumazet
icmpmsg_put(struct seq_file * seq)32296793b48SDavid L Stevens static void icmpmsg_put(struct seq_file *seq)
32396793b48SDavid L Stevens {
32496793b48SDavid L Stevens #define PERLINE 16
32596793b48SDavid L Stevens
326b971e7acSEric Dumazet int i, count;
327b971e7acSEric Dumazet unsigned short type[PERLINE];
328b971e7acSEric Dumazet unsigned long vals[PERLINE], val;
329229bf0cbSPavel Emelyanov struct net *net = seq->private;
33096793b48SDavid L Stevens
33196793b48SDavid L Stevens count = 0;
33296793b48SDavid L Stevens for (i = 0; i < ICMPMSG_MIB_MAX; i++) {
333acb32ba3SEric Dumazet val = atomic_long_read(&net->mib.icmpmsg_statistics->mibs[i]);
334b971e7acSEric Dumazet if (val) {
335b971e7acSEric Dumazet type[count] = i;
336b971e7acSEric Dumazet vals[count++] = val;
33796793b48SDavid L Stevens }
338b971e7acSEric Dumazet if (count == PERLINE) {
339b971e7acSEric Dumazet icmpmsg_put_line(seq, vals, type, count);
340b971e7acSEric Dumazet count = 0;
34196793b48SDavid L Stevens }
342b971e7acSEric Dumazet }
343b971e7acSEric Dumazet icmpmsg_put_line(seq, vals, type, count);
34496793b48SDavid L Stevens
34596793b48SDavid L Stevens #undef PERLINE
34696793b48SDavid L Stevens }
34796793b48SDavid L Stevens
icmp_put(struct seq_file * seq)34896793b48SDavid L Stevens static void icmp_put(struct seq_file *seq)
34996793b48SDavid L Stevens {
35096793b48SDavid L Stevens int i;
351229bf0cbSPavel Emelyanov struct net *net = seq->private;
352acb32ba3SEric Dumazet atomic_long_t *ptr = net->mib.icmpmsg_statistics->mibs;
35396793b48SDavid L Stevens
3546a5dc9e5SEric Dumazet seq_puts(seq, "\nIcmp: InMsgs InErrors InCsumErrors");
3556d4a741cSJia He for (i = 0; icmpmibmap[i].name; i++)
35696793b48SDavid L Stevens seq_printf(seq, " In%s", icmpmibmap[i].name);
357d0941130SJamie Bainbridge seq_puts(seq, " OutMsgs OutErrors OutRateLimitGlobal OutRateLimitHost");
3586d4a741cSJia He for (i = 0; icmpmibmap[i].name; i++)
35996793b48SDavid L Stevens seq_printf(seq, " Out%s", icmpmibmap[i].name);
3606a5dc9e5SEric Dumazet seq_printf(seq, "\nIcmp: %lu %lu %lu",
361698365faSWANG Cong snmp_fold_field(net->mib.icmp_statistics, ICMP_MIB_INMSGS),
362698365faSWANG Cong snmp_fold_field(net->mib.icmp_statistics, ICMP_MIB_INERRORS),
363698365faSWANG Cong snmp_fold_field(net->mib.icmp_statistics, ICMP_MIB_CSUMERRORS));
3646d4a741cSJia He for (i = 0; icmpmibmap[i].name; i++)
36596793b48SDavid L Stevens seq_printf(seq, " %lu",
366acb32ba3SEric Dumazet atomic_long_read(ptr + icmpmibmap[i].index));
367d0941130SJamie Bainbridge seq_printf(seq, " %lu %lu %lu %lu",
368698365faSWANG Cong snmp_fold_field(net->mib.icmp_statistics, ICMP_MIB_OUTMSGS),
369d0941130SJamie Bainbridge snmp_fold_field(net->mib.icmp_statistics, ICMP_MIB_OUTERRORS),
370d0941130SJamie Bainbridge snmp_fold_field(net->mib.icmp_statistics, ICMP_MIB_RATELIMITGLOBAL),
371d0941130SJamie Bainbridge snmp_fold_field(net->mib.icmp_statistics, ICMP_MIB_RATELIMITHOST));
3726d4a741cSJia He for (i = 0; icmpmibmap[i].name; i++)
37396793b48SDavid L Stevens seq_printf(seq, " %lu",
374acb32ba3SEric Dumazet atomic_long_read(ptr + (icmpmibmap[i].index | 0x100)));
37596793b48SDavid L Stevens }
37696793b48SDavid L Stevens
3771da177e4SLinus Torvalds /*
3781da177e4SLinus Torvalds * Called from the PROCfs module. This outputs /proc/net/snmp.
3791da177e4SLinus Torvalds */
snmp_seq_show_ipstats(struct seq_file * seq,void * v)380f22d5c49SJia He static int snmp_seq_show_ipstats(struct seq_file *seq, void *v)
3811da177e4SLinus Torvalds {
382229bf0cbSPavel Emelyanov struct net *net = seq->private;
383f22d5c49SJia He u64 buff64[IPSTATS_MIB_MAX];
384f22d5c49SJia He int i;
385f22d5c49SJia He
386f22d5c49SJia He memset(buff64, 0, IPSTATS_MIB_MAX * sizeof(u64));
3871da177e4SLinus Torvalds
3881da177e4SLinus Torvalds seq_puts(seq, "Ip: Forwarding DefaultTTL");
3896d4a741cSJia He for (i = 0; snmp4_ipstats_list[i].name; i++)
3901da177e4SLinus Torvalds seq_printf(seq, " %s", snmp4_ipstats_list[i].name);
3911da177e4SLinus Torvalds
3921da177e4SLinus Torvalds seq_printf(seq, "\nIp: %d %d",
3938e3461d0SPavel Emelyanov IPV4_DEVCONF_ALL(net, FORWARDING) ? 1 : 2,
3948281b7ecSKuniyuki Iwashima READ_ONCE(net->ipv4.sysctl_ip_default_ttl));
3951da177e4SLinus Torvalds
3964ce3c183SEric Dumazet BUILD_BUG_ON(offsetof(struct ipstats_mib, mibs) != 0);
397f22d5c49SJia He snmp_get_cpu_field64_batch(buff64, snmp4_ipstats_list,
398f22d5c49SJia He net->mib.ip_statistics,
399f22d5c49SJia He offsetof(struct ipstats_mib, syncp));
4006d4a741cSJia He for (i = 0; snmp4_ipstats_list[i].name; i++)
401f22d5c49SJia He seq_printf(seq, " %llu", buff64[i]);
4021da177e4SLinus Torvalds
403f22d5c49SJia He return 0;
404f22d5c49SJia He }
405f22d5c49SJia He
snmp_seq_show_tcp_udp(struct seq_file * seq,void * v)406f22d5c49SJia He static int snmp_seq_show_tcp_udp(struct seq_file *seq, void *v)
407f22d5c49SJia He {
408f22d5c49SJia He unsigned long buff[TCPUDP_MIB_MAX];
409f22d5c49SJia He struct net *net = seq->private;
410f22d5c49SJia He int i;
411f22d5c49SJia He
412f22d5c49SJia He memset(buff, 0, TCPUDP_MIB_MAX * sizeof(unsigned long));
4131da177e4SLinus Torvalds
4141da177e4SLinus Torvalds seq_puts(seq, "\nTcp:");
4156d4a741cSJia He for (i = 0; snmp4_tcp_list[i].name; i++)
4161da177e4SLinus Torvalds seq_printf(seq, " %s", snmp4_tcp_list[i].name);
4171da177e4SLinus Torvalds
4181da177e4SLinus Torvalds seq_puts(seq, "\nTcp:");
419f22d5c49SJia He snmp_get_cpu_field_batch(buff, snmp4_tcp_list,
420f22d5c49SJia He net->mib.tcp_statistics);
4216d4a741cSJia He for (i = 0; snmp4_tcp_list[i].name; i++) {
4221da177e4SLinus Torvalds /* MaxConn field is signed, RFC 2012 */
4231da177e4SLinus Torvalds if (snmp4_tcp_list[i].entry == TCP_MIB_MAXCONN)
424f22d5c49SJia He seq_printf(seq, " %ld", buff[i]);
4251da177e4SLinus Torvalds else
426f22d5c49SJia He seq_printf(seq, " %lu", buff[i]);
4271da177e4SLinus Torvalds }
4281da177e4SLinus Torvalds
429f22d5c49SJia He memset(buff, 0, TCPUDP_MIB_MAX * sizeof(unsigned long));
430f22d5c49SJia He
431f22d5c49SJia He snmp_get_cpu_field_batch(buff, snmp4_udp_list,
432f22d5c49SJia He net->mib.udp_statistics);
4331da177e4SLinus Torvalds seq_puts(seq, "\nUdp:");
4346d4a741cSJia He for (i = 0; snmp4_udp_list[i].name; i++)
4351da177e4SLinus Torvalds seq_printf(seq, " %s", snmp4_udp_list[i].name);
4361da177e4SLinus Torvalds seq_puts(seq, "\nUdp:");
4376d4a741cSJia He for (i = 0; snmp4_udp_list[i].name; i++)
438f22d5c49SJia He seq_printf(seq, " %lu", buff[i]);
439f22d5c49SJia He
440f22d5c49SJia He memset(buff, 0, TCPUDP_MIB_MAX * sizeof(unsigned long));
4411da177e4SLinus Torvalds
442ba4e58ecSGerrit Renker /* the UDP and UDP-Lite MIBs are the same */
443ba4e58ecSGerrit Renker seq_puts(seq, "\nUdpLite:");
444f22d5c49SJia He snmp_get_cpu_field_batch(buff, snmp4_udp_list,
445f22d5c49SJia He net->mib.udplite_statistics);
4466d4a741cSJia He for (i = 0; snmp4_udp_list[i].name; i++)
447ba4e58ecSGerrit Renker seq_printf(seq, " %s", snmp4_udp_list[i].name);
448ba4e58ecSGerrit Renker seq_puts(seq, "\nUdpLite:");
4496d4a741cSJia He for (i = 0; snmp4_udp_list[i].name; i++)
450f22d5c49SJia He seq_printf(seq, " %lu", buff[i]);
451db8dac20SDavid S. Miller
4521da177e4SLinus Torvalds seq_putc(seq, '\n');
4531da177e4SLinus Torvalds return 0;
4541da177e4SLinus Torvalds }
4551da177e4SLinus Torvalds
snmp_seq_show(struct seq_file * seq,void * v)456f22d5c49SJia He static int snmp_seq_show(struct seq_file *seq, void *v)
457f22d5c49SJia He {
458f22d5c49SJia He snmp_seq_show_ipstats(seq, v);
459f22d5c49SJia He
460f22d5c49SJia He icmp_put(seq); /* RFC 2011 compatibility */
461f22d5c49SJia He icmpmsg_put(seq);
462f22d5c49SJia He
463f22d5c49SJia He snmp_seq_show_tcp_udp(seq, v);
464f22d5c49SJia He
465f22d5c49SJia He return 0;
466f22d5c49SJia He }
467f22d5c49SJia He
4681da177e4SLinus Torvalds /*
4691da177e4SLinus Torvalds * Output /proc/net/netstat
4701da177e4SLinus Torvalds */
netstat_seq_show(struct seq_file * seq,void * v)4711da177e4SLinus Torvalds static int netstat_seq_show(struct seq_file *seq, void *v)
4721da177e4SLinus Torvalds {
4730d6cd689SEric Dumazet const int ip_cnt = ARRAY_SIZE(snmp4_ipextstats_list) - 1;
4740d6cd689SEric Dumazet const int tcp_cnt = ARRAY_SIZE(snmp4_net_list) - 1;
4757b7a9dfdSPavel Emelyanov struct net *net = seq->private;
4760d6cd689SEric Dumazet unsigned long *buff;
4770d6cd689SEric Dumazet int i;
4781da177e4SLinus Torvalds
4791da177e4SLinus Torvalds seq_puts(seq, "TcpExt:");
4800d6cd689SEric Dumazet for (i = 0; i < tcp_cnt; i++)
4811da177e4SLinus Torvalds seq_printf(seq, " %s", snmp4_net_list[i].name);
4821da177e4SLinus Torvalds
4831da177e4SLinus Torvalds seq_puts(seq, "\nTcpExt:");
4840d6cd689SEric Dumazet buff = kzalloc(max(tcp_cnt * sizeof(long), ip_cnt * sizeof(u64)),
4850d6cd689SEric Dumazet GFP_KERNEL);
4860d6cd689SEric Dumazet if (buff) {
4870d6cd689SEric Dumazet snmp_get_cpu_field_batch(buff, snmp4_net_list,
4880d6cd689SEric Dumazet net->mib.net_statistics);
4890d6cd689SEric Dumazet for (i = 0; i < tcp_cnt; i++)
4900d6cd689SEric Dumazet seq_printf(seq, " %lu", buff[i]);
4910d6cd689SEric Dumazet } else {
4920d6cd689SEric Dumazet for (i = 0; i < tcp_cnt; i++)
4931da177e4SLinus Torvalds seq_printf(seq, " %lu",
494698365faSWANG Cong snmp_fold_field(net->mib.net_statistics,
4951da177e4SLinus Torvalds snmp4_net_list[i].entry));
4960d6cd689SEric Dumazet }
497d831666eSMitsuru Chinen seq_puts(seq, "\nIpExt:");
4980d6cd689SEric Dumazet for (i = 0; i < ip_cnt; i++)
499d831666eSMitsuru Chinen seq_printf(seq, " %s", snmp4_ipextstats_list[i].name);
500d831666eSMitsuru Chinen
501d831666eSMitsuru Chinen seq_puts(seq, "\nIpExt:");
5020d6cd689SEric Dumazet if (buff) {
5030d6cd689SEric Dumazet u64 *buff64 = (u64 *)buff;
5040d6cd689SEric Dumazet
5050d6cd689SEric Dumazet memset(buff64, 0, ip_cnt * sizeof(u64));
5060d6cd689SEric Dumazet snmp_get_cpu_field64_batch(buff64, snmp4_ipextstats_list,
5070d6cd689SEric Dumazet net->mib.ip_statistics,
5080d6cd689SEric Dumazet offsetof(struct ipstats_mib, syncp));
5090d6cd689SEric Dumazet for (i = 0; i < ip_cnt; i++)
5100d6cd689SEric Dumazet seq_printf(seq, " %llu", buff64[i]);
5110d6cd689SEric Dumazet } else {
5120d6cd689SEric Dumazet for (i = 0; i < ip_cnt; i++)
5134ce3c183SEric Dumazet seq_printf(seq, " %llu",
514698365faSWANG Cong snmp_fold_field64(net->mib.ip_statistics,
5154ce3c183SEric Dumazet snmp4_ipextstats_list[i].entry,
5164ce3c183SEric Dumazet offsetof(struct ipstats_mib, syncp)));
5170d6cd689SEric Dumazet }
5180d6cd689SEric Dumazet kfree(buff);
5191da177e4SLinus Torvalds seq_putc(seq, '\n');
520fc518953SFlorian Westphal mptcp_seq_show(seq);
5211da177e4SLinus Torvalds return 0;
5221da177e4SLinus Torvalds }
5231da177e4SLinus Torvalds
ip_proc_init_net(struct net * net)524d0538ca3SPavel Emelyanov static __net_init int ip_proc_init_net(struct net *net)
525d0538ca3SPavel Emelyanov {
5263617d949SChristoph Hellwig if (!proc_create_net_single("sockstat", 0444, net->proc_net,
5273617d949SChristoph Hellwig sockstat_seq_show, NULL))
52860bdde95SPavel Emelyanov goto out_sockstat;
5293617d949SChristoph Hellwig if (!proc_create_net_single("netstat", 0444, net->proc_net,
5303617d949SChristoph Hellwig netstat_seq_show, NULL))
5317b7a9dfdSPavel Emelyanov goto out_netstat;
5323617d949SChristoph Hellwig if (!proc_create_net_single("snmp", 0444, net->proc_net, snmp_seq_show,
5333617d949SChristoph Hellwig NULL))
534229bf0cbSPavel Emelyanov goto out_snmp;
5357b7a9dfdSPavel Emelyanov
536d0538ca3SPavel Emelyanov return 0;
5377b7a9dfdSPavel Emelyanov
538229bf0cbSPavel Emelyanov out_snmp:
539ece31ffdSGao feng remove_proc_entry("netstat", net->proc_net);
5407b7a9dfdSPavel Emelyanov out_netstat:
541ece31ffdSGao feng remove_proc_entry("sockstat", net->proc_net);
54260bdde95SPavel Emelyanov out_sockstat:
5437b7a9dfdSPavel Emelyanov return -ENOMEM;
544d0538ca3SPavel Emelyanov }
545d0538ca3SPavel Emelyanov
ip_proc_exit_net(struct net * net)546d0538ca3SPavel Emelyanov static __net_exit void ip_proc_exit_net(struct net *net)
547d0538ca3SPavel Emelyanov {
548ece31ffdSGao feng remove_proc_entry("snmp", net->proc_net);
549ece31ffdSGao feng remove_proc_entry("netstat", net->proc_net);
550ece31ffdSGao feng remove_proc_entry("sockstat", net->proc_net);
551d0538ca3SPavel Emelyanov }
552d0538ca3SPavel Emelyanov
553d0538ca3SPavel Emelyanov static __net_initdata struct pernet_operations ip_proc_ops = {
554d0538ca3SPavel Emelyanov .init = ip_proc_init_net,
555d0538ca3SPavel Emelyanov .exit = ip_proc_exit_net,
556d0538ca3SPavel Emelyanov };
557d0538ca3SPavel Emelyanov
ip_misc_proc_init(void)5581da177e4SLinus Torvalds int __init ip_misc_proc_init(void)
5591da177e4SLinus Torvalds {
56060bdde95SPavel Emelyanov return register_pernet_subsys(&ip_proc_ops);
5611da177e4SLinus Torvalds }
562