inet.af/netstack@v0.0.0-20220214151720-7585b01ddccf/tcpip/network/ipv4/stats.go (about) 1 // Copyright 2020 The gVisor Authors. 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 package ipv4 16 17 import ( 18 "inet.af/netstack/tcpip" 19 "inet.af/netstack/tcpip/network/internal/ip" 20 "inet.af/netstack/tcpip/stack" 21 ) 22 23 var _ stack.IPNetworkEndpointStats = (*Stats)(nil) 24 25 // Stats holds statistics related to the IPv4 protocol family. 26 type Stats struct { 27 // IP holds IPv4 statistics. 28 IP tcpip.IPStats 29 30 // IGMP holds IGMP statistics. 31 IGMP tcpip.IGMPStats 32 33 // ICMP holds ICMPv4 statistics. 34 ICMP tcpip.ICMPv4Stats 35 } 36 37 // IsNetworkEndpointStats implements stack.NetworkEndpointStats. 38 func (*Stats) IsNetworkEndpointStats() {} 39 40 // IPStats implements stack.IPNetworkEndointStats 41 func (s *Stats) IPStats() *tcpip.IPStats { 42 return &s.IP 43 } 44 45 type sharedStats struct { 46 localStats Stats 47 ip ip.MultiCounterIPStats 48 icmp multiCounterICMPv4Stats 49 igmp multiCounterIGMPStats 50 } 51 52 // LINT.IfChange(multiCounterICMPv4PacketStats) 53 54 type multiCounterICMPv4PacketStats struct { 55 echoRequest tcpip.MultiCounterStat 56 echoReply tcpip.MultiCounterStat 57 dstUnreachable tcpip.MultiCounterStat 58 srcQuench tcpip.MultiCounterStat 59 redirect tcpip.MultiCounterStat 60 timeExceeded tcpip.MultiCounterStat 61 paramProblem tcpip.MultiCounterStat 62 timestamp tcpip.MultiCounterStat 63 timestampReply tcpip.MultiCounterStat 64 infoRequest tcpip.MultiCounterStat 65 infoReply tcpip.MultiCounterStat 66 } 67 68 func (m *multiCounterICMPv4PacketStats) init(a, b *tcpip.ICMPv4PacketStats) { 69 m.echoRequest.Init(a.EchoRequest, b.EchoRequest) 70 m.echoReply.Init(a.EchoReply, b.EchoReply) 71 m.dstUnreachable.Init(a.DstUnreachable, b.DstUnreachable) 72 m.srcQuench.Init(a.SrcQuench, b.SrcQuench) 73 m.redirect.Init(a.Redirect, b.Redirect) 74 m.timeExceeded.Init(a.TimeExceeded, b.TimeExceeded) 75 m.paramProblem.Init(a.ParamProblem, b.ParamProblem) 76 m.timestamp.Init(a.Timestamp, b.Timestamp) 77 m.timestampReply.Init(a.TimestampReply, b.TimestampReply) 78 m.infoRequest.Init(a.InfoRequest, b.InfoRequest) 79 m.infoReply.Init(a.InfoReply, b.InfoReply) 80 } 81 82 // LINT.ThenChange(../../tcpip.go:ICMPv4PacketStats) 83 84 // LINT.IfChange(multiCounterICMPv4SentPacketStats) 85 86 type multiCounterICMPv4SentPacketStats struct { 87 multiCounterICMPv4PacketStats 88 dropped tcpip.MultiCounterStat 89 rateLimited tcpip.MultiCounterStat 90 } 91 92 func (m *multiCounterICMPv4SentPacketStats) init(a, b *tcpip.ICMPv4SentPacketStats) { 93 m.multiCounterICMPv4PacketStats.init(&a.ICMPv4PacketStats, &b.ICMPv4PacketStats) 94 m.dropped.Init(a.Dropped, b.Dropped) 95 m.rateLimited.Init(a.RateLimited, b.RateLimited) 96 } 97 98 // LINT.ThenChange(../../tcpip.go:ICMPv4SentPacketStats) 99 100 // LINT.IfChange(multiCounterICMPv4ReceivedPacketStats) 101 102 type multiCounterICMPv4ReceivedPacketStats struct { 103 multiCounterICMPv4PacketStats 104 invalid tcpip.MultiCounterStat 105 } 106 107 func (m *multiCounterICMPv4ReceivedPacketStats) init(a, b *tcpip.ICMPv4ReceivedPacketStats) { 108 m.multiCounterICMPv4PacketStats.init(&a.ICMPv4PacketStats, &b.ICMPv4PacketStats) 109 m.invalid.Init(a.Invalid, b.Invalid) 110 } 111 112 // LINT.ThenChange(../../tcpip.go:ICMPv4ReceivedPacketStats) 113 114 // LINT.IfChange(multiCounterICMPv4Stats) 115 116 type multiCounterICMPv4Stats struct { 117 packetsSent multiCounterICMPv4SentPacketStats 118 packetsReceived multiCounterICMPv4ReceivedPacketStats 119 } 120 121 func (m *multiCounterICMPv4Stats) init(a, b *tcpip.ICMPv4Stats) { 122 m.packetsSent.init(&a.PacketsSent, &b.PacketsSent) 123 m.packetsReceived.init(&a.PacketsReceived, &b.PacketsReceived) 124 } 125 126 // LINT.ThenChange(../../tcpip.go:ICMPv4Stats) 127 128 // LINT.IfChange(multiCounterIGMPPacketStats) 129 130 type multiCounterIGMPPacketStats struct { 131 membershipQuery tcpip.MultiCounterStat 132 v1MembershipReport tcpip.MultiCounterStat 133 v2MembershipReport tcpip.MultiCounterStat 134 leaveGroup tcpip.MultiCounterStat 135 } 136 137 func (m *multiCounterIGMPPacketStats) init(a, b *tcpip.IGMPPacketStats) { 138 m.membershipQuery.Init(a.MembershipQuery, b.MembershipQuery) 139 m.v1MembershipReport.Init(a.V1MembershipReport, b.V1MembershipReport) 140 m.v2MembershipReport.Init(a.V2MembershipReport, b.V2MembershipReport) 141 m.leaveGroup.Init(a.LeaveGroup, b.LeaveGroup) 142 } 143 144 // LINT.ThenChange(../../tcpip.go:IGMPPacketStats) 145 146 // LINT.IfChange(multiCounterIGMPSentPacketStats) 147 148 type multiCounterIGMPSentPacketStats struct { 149 multiCounterIGMPPacketStats 150 dropped tcpip.MultiCounterStat 151 } 152 153 func (m *multiCounterIGMPSentPacketStats) init(a, b *tcpip.IGMPSentPacketStats) { 154 m.multiCounterIGMPPacketStats.init(&a.IGMPPacketStats, &b.IGMPPacketStats) 155 m.dropped.Init(a.Dropped, b.Dropped) 156 } 157 158 // LINT.ThenChange(../../tcpip.go:IGMPSentPacketStats) 159 160 // LINT.IfChange(multiCounterIGMPReceivedPacketStats) 161 162 type multiCounterIGMPReceivedPacketStats struct { 163 multiCounterIGMPPacketStats 164 invalid tcpip.MultiCounterStat 165 checksumErrors tcpip.MultiCounterStat 166 unrecognized tcpip.MultiCounterStat 167 } 168 169 func (m *multiCounterIGMPReceivedPacketStats) init(a, b *tcpip.IGMPReceivedPacketStats) { 170 m.multiCounterIGMPPacketStats.init(&a.IGMPPacketStats, &b.IGMPPacketStats) 171 m.invalid.Init(a.Invalid, b.Invalid) 172 m.checksumErrors.Init(a.ChecksumErrors, b.ChecksumErrors) 173 m.unrecognized.Init(a.Unrecognized, b.Unrecognized) 174 } 175 176 // LINT.ThenChange(../../tcpip.go:IGMPReceivedPacketStats) 177 178 // LINT.IfChange(multiCounterIGMPStats) 179 180 type multiCounterIGMPStats struct { 181 packetsSent multiCounterIGMPSentPacketStats 182 packetsReceived multiCounterIGMPReceivedPacketStats 183 } 184 185 func (m *multiCounterIGMPStats) init(a, b *tcpip.IGMPStats) { 186 m.packetsSent.init(&a.PacketsSent, &b.PacketsSent) 187 m.packetsReceived.init(&a.PacketsReceived, &b.PacketsReceived) 188 } 189 190 // LINT.ThenChange(../../tcpip.go:IGMPStats)