github.com/MerlinKodo/gvisor@v0.0.0-20231110090155-957f62ecf90e/pkg/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 "github.com/MerlinKodo/gvisor/pkg/tcpip" 19 "github.com/MerlinKodo/gvisor/pkg/tcpip/network/internal/ip" 20 "github.com/MerlinKodo/gvisor/pkg/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 v3MembershipReport tcpip.MultiCounterStat 135 leaveGroup tcpip.MultiCounterStat 136 } 137 138 func (m *multiCounterIGMPPacketStats) init(a, b *tcpip.IGMPPacketStats) { 139 m.membershipQuery.Init(a.MembershipQuery, b.MembershipQuery) 140 m.v1MembershipReport.Init(a.V1MembershipReport, b.V1MembershipReport) 141 m.v2MembershipReport.Init(a.V2MembershipReport, b.V2MembershipReport) 142 m.v3MembershipReport.Init(a.V3MembershipReport, b.V3MembershipReport) 143 m.leaveGroup.Init(a.LeaveGroup, b.LeaveGroup) 144 } 145 146 // LINT.ThenChange(../../tcpip.go:IGMPPacketStats) 147 148 // LINT.IfChange(multiCounterIGMPSentPacketStats) 149 150 type multiCounterIGMPSentPacketStats struct { 151 multiCounterIGMPPacketStats 152 dropped tcpip.MultiCounterStat 153 } 154 155 func (m *multiCounterIGMPSentPacketStats) init(a, b *tcpip.IGMPSentPacketStats) { 156 m.multiCounterIGMPPacketStats.init(&a.IGMPPacketStats, &b.IGMPPacketStats) 157 m.dropped.Init(a.Dropped, b.Dropped) 158 } 159 160 // LINT.ThenChange(../../tcpip.go:IGMPSentPacketStats) 161 162 // LINT.IfChange(multiCounterIGMPReceivedPacketStats) 163 164 type multiCounterIGMPReceivedPacketStats struct { 165 multiCounterIGMPPacketStats 166 invalid tcpip.MultiCounterStat 167 checksumErrors tcpip.MultiCounterStat 168 unrecognized tcpip.MultiCounterStat 169 } 170 171 func (m *multiCounterIGMPReceivedPacketStats) init(a, b *tcpip.IGMPReceivedPacketStats) { 172 m.multiCounterIGMPPacketStats.init(&a.IGMPPacketStats, &b.IGMPPacketStats) 173 m.invalid.Init(a.Invalid, b.Invalid) 174 m.checksumErrors.Init(a.ChecksumErrors, b.ChecksumErrors) 175 m.unrecognized.Init(a.Unrecognized, b.Unrecognized) 176 } 177 178 // LINT.ThenChange(../../tcpip.go:IGMPReceivedPacketStats) 179 180 // LINT.IfChange(multiCounterIGMPStats) 181 182 type multiCounterIGMPStats struct { 183 packetsSent multiCounterIGMPSentPacketStats 184 packetsReceived multiCounterIGMPReceivedPacketStats 185 } 186 187 func (m *multiCounterIGMPStats) init(a, b *tcpip.IGMPStats) { 188 m.packetsSent.init(&a.PacketsSent, &b.PacketsSent) 189 m.packetsReceived.init(&a.PacketsReceived, &b.PacketsReceived) 190 } 191 192 // LINT.ThenChange(../../tcpip.go:IGMPStats)