gvisor.dev/gvisor@v0.0.0-20240520182842-f9d4d51c7e0f/pkg/tcpip/network/internal/ip/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 ip 16 17 import "gvisor.dev/gvisor/pkg/tcpip" 18 19 // LINT.IfChange(MultiCounterIPForwardingStats) 20 21 // MultiCounterIPForwardingStats holds IP forwarding statistics. Each counter 22 // may have several versions. 23 type MultiCounterIPForwardingStats struct { 24 // Unrouteable is the number of IP packets received which were dropped 25 // because the netstack could not construct a route to their 26 // destination. 27 Unrouteable tcpip.MultiCounterStat 28 29 // ExhaustedTTL is the number of IP packets received which were dropped 30 // because their TTL was exhausted. 31 ExhaustedTTL tcpip.MultiCounterStat 32 33 // InitializingSource is the number of IP packets which were dropped 34 // because they contained a source address that may only be used on the local 35 // network as part of initialization work. 36 InitializingSource tcpip.MultiCounterStat 37 38 // LinkLocalSource is the number of IP packets which were dropped 39 // because they contained a link-local source address. 40 LinkLocalSource tcpip.MultiCounterStat 41 42 // LinkLocalDestination is the number of IP packets which were dropped 43 // because they contained a link-local destination address. 44 LinkLocalDestination tcpip.MultiCounterStat 45 46 // PacketTooBig is the number of IP packets which were dropped because they 47 // were too big for the outgoing MTU. 48 PacketTooBig tcpip.MultiCounterStat 49 50 // HostUnreachable is the number of IP packets received which could not be 51 // successfully forwarded due to an unresolvable next hop. 52 HostUnreachable tcpip.MultiCounterStat 53 54 // ExtensionHeaderProblem is the number of IP packets which were dropped 55 // because of a problem encountered when processing an IPv6 extension 56 // header. 57 ExtensionHeaderProblem tcpip.MultiCounterStat 58 59 // UnexpectedMulticastInputInterface is the number of multicast packets that 60 // were received on an interface that did not match the corresponding route's 61 // expected input interface. 62 UnexpectedMulticastInputInterface tcpip.MultiCounterStat 63 64 // UnknownOutputEndpoint is the number of packets that could not be forwarded 65 // because the output endpoint could not be found. 66 UnknownOutputEndpoint tcpip.MultiCounterStat 67 68 // NoMulticastPendingQueueBufferSpace is the number of multicast packets that 69 // were dropped due to insufficient buffer space in the pending packet queue. 70 NoMulticastPendingQueueBufferSpace tcpip.MultiCounterStat 71 72 // OutgoingDeviceNoBufferSpace is the number of packets that were dropped due 73 // to insufficient space in the outgoing device. 74 OutgoingDeviceNoBufferSpace tcpip.MultiCounterStat 75 76 // Errors is the number of IP packets received which could not be 77 // successfully forwarded. 78 Errors tcpip.MultiCounterStat 79 } 80 81 // Init sets internal counters to track a and b counters. 82 func (m *MultiCounterIPForwardingStats) Init(a, b *tcpip.IPForwardingStats) { 83 m.Unrouteable.Init(a.Unrouteable, b.Unrouteable) 84 m.Errors.Init(a.Errors, b.Errors) 85 m.InitializingSource.Init(a.InitializingSource, b.InitializingSource) 86 m.LinkLocalSource.Init(a.LinkLocalSource, b.LinkLocalSource) 87 m.LinkLocalDestination.Init(a.LinkLocalDestination, b.LinkLocalDestination) 88 m.ExtensionHeaderProblem.Init(a.ExtensionHeaderProblem, b.ExtensionHeaderProblem) 89 m.PacketTooBig.Init(a.PacketTooBig, b.PacketTooBig) 90 m.ExhaustedTTL.Init(a.ExhaustedTTL, b.ExhaustedTTL) 91 m.HostUnreachable.Init(a.HostUnreachable, b.HostUnreachable) 92 m.UnexpectedMulticastInputInterface.Init(a.UnexpectedMulticastInputInterface, b.UnexpectedMulticastInputInterface) 93 m.UnknownOutputEndpoint.Init(a.UnknownOutputEndpoint, b.UnknownOutputEndpoint) 94 m.NoMulticastPendingQueueBufferSpace.Init(a.NoMulticastPendingQueueBufferSpace, b.NoMulticastPendingQueueBufferSpace) 95 m.OutgoingDeviceNoBufferSpace.Init(a.OutgoingDeviceNoBufferSpace, b.OutgoingDeviceNoBufferSpace) 96 } 97 98 // LINT.ThenChange(:MultiCounterIPForwardingStats, ../../../tcpip.go:IPForwardingStats) 99 100 // LINT.IfChange(MultiCounterIPStats) 101 102 // MultiCounterIPStats holds IP statistics, each counter may have several 103 // versions. 104 type MultiCounterIPStats struct { 105 // PacketsReceived is the number of IP packets received from the link 106 // layer. 107 PacketsReceived tcpip.MultiCounterStat 108 109 // ValidPacketsReceived is the number of valid IP packets that reached the IP 110 // layer. 111 ValidPacketsReceived tcpip.MultiCounterStat 112 113 // DisabledPacketsReceived is the number of IP packets received from 114 // the link layer when the IP layer is disabled. 115 DisabledPacketsReceived tcpip.MultiCounterStat 116 117 // InvalidDestinationAddressesReceived is the number of IP packets 118 // received with an unknown or invalid destination address. 119 InvalidDestinationAddressesReceived tcpip.MultiCounterStat 120 121 // InvalidSourceAddressesReceived is the number of IP packets received 122 // with a source address that should never have been received on the 123 // wire. 124 InvalidSourceAddressesReceived tcpip.MultiCounterStat 125 126 // PacketsDelivered is the number of incoming IP packets successfully 127 // delivered to the transport layer. 128 PacketsDelivered tcpip.MultiCounterStat 129 130 // PacketsSent is the number of IP packets sent via WritePacket. 131 PacketsSent tcpip.MultiCounterStat 132 133 // OutgoingPacketErrors is the number of IP packets which failed to 134 // write to a link-layer endpoint. 135 OutgoingPacketErrors tcpip.MultiCounterStat 136 137 // MalformedPacketsReceived is the number of IP Packets that were 138 // dropped due to the IP packet header failing validation checks. 139 MalformedPacketsReceived tcpip.MultiCounterStat 140 141 // MalformedFragmentsReceived is the number of IP Fragments that were 142 // dropped due to the fragment failing validation checks. 143 MalformedFragmentsReceived tcpip.MultiCounterStat 144 145 // IPTablesPreroutingDropped is the number of IP packets dropped in the 146 // Prerouting chain. 147 IPTablesPreroutingDropped tcpip.MultiCounterStat 148 149 // IPTablesInputDropped is the number of IP packets dropped in the 150 // Input chain. 151 IPTablesInputDropped tcpip.MultiCounterStat 152 153 // IPTablesForwardDropped is the number of IP packets dropped in the 154 // Forward chain. 155 IPTablesForwardDropped tcpip.MultiCounterStat 156 157 // IPTablesOutputDropped is the number of IP packets dropped in the 158 // Output chain. 159 IPTablesOutputDropped tcpip.MultiCounterStat 160 161 // IPTablesPostroutingDropped is the number of IP packets dropped in 162 // the Postrouting chain. 163 IPTablesPostroutingDropped tcpip.MultiCounterStat 164 165 // TODO(https://gvisor.dev/issues/5529): Move the IPv4-only option 166 // stats out of IPStats. 167 168 // OptionTimestampReceived is the number of Timestamp options seen. 169 OptionTimestampReceived tcpip.MultiCounterStat 170 171 // OptionRecordRouteReceived is the number of Record Route options 172 // seen. 173 OptionRecordRouteReceived tcpip.MultiCounterStat 174 175 // OptionRouterAlertReceived is the number of Router Alert options 176 // seen. 177 OptionRouterAlertReceived tcpip.MultiCounterStat 178 179 // OptionUnknownReceived is the number of unknown IP options seen. 180 OptionUnknownReceived tcpip.MultiCounterStat 181 182 // Forwarding collects stats related to IP forwarding. 183 Forwarding MultiCounterIPForwardingStats 184 } 185 186 // Init sets internal counters to track a and b counters. 187 func (m *MultiCounterIPStats) Init(a, b *tcpip.IPStats) { 188 m.PacketsReceived.Init(a.PacketsReceived, b.PacketsReceived) 189 m.ValidPacketsReceived.Init(a.ValidPacketsReceived, b.ValidPacketsReceived) 190 m.DisabledPacketsReceived.Init(a.DisabledPacketsReceived, b.DisabledPacketsReceived) 191 m.InvalidDestinationAddressesReceived.Init(a.InvalidDestinationAddressesReceived, b.InvalidDestinationAddressesReceived) 192 m.InvalidSourceAddressesReceived.Init(a.InvalidSourceAddressesReceived, b.InvalidSourceAddressesReceived) 193 m.PacketsDelivered.Init(a.PacketsDelivered, b.PacketsDelivered) 194 m.PacketsSent.Init(a.PacketsSent, b.PacketsSent) 195 m.OutgoingPacketErrors.Init(a.OutgoingPacketErrors, b.OutgoingPacketErrors) 196 m.MalformedPacketsReceived.Init(a.MalformedPacketsReceived, b.MalformedPacketsReceived) 197 m.MalformedFragmentsReceived.Init(a.MalformedFragmentsReceived, b.MalformedFragmentsReceived) 198 m.IPTablesPreroutingDropped.Init(a.IPTablesPreroutingDropped, b.IPTablesPreroutingDropped) 199 m.IPTablesInputDropped.Init(a.IPTablesInputDropped, b.IPTablesInputDropped) 200 m.IPTablesForwardDropped.Init(a.IPTablesForwardDropped, b.IPTablesForwardDropped) 201 m.IPTablesOutputDropped.Init(a.IPTablesOutputDropped, b.IPTablesOutputDropped) 202 m.IPTablesPostroutingDropped.Init(a.IPTablesPostroutingDropped, b.IPTablesPostroutingDropped) 203 m.OptionTimestampReceived.Init(a.OptionTimestampReceived, b.OptionTimestampReceived) 204 m.OptionRecordRouteReceived.Init(a.OptionRecordRouteReceived, b.OptionRecordRouteReceived) 205 m.OptionRouterAlertReceived.Init(a.OptionRouterAlertReceived, b.OptionRouterAlertReceived) 206 m.OptionUnknownReceived.Init(a.OptionUnknownReceived, b.OptionUnknownReceived) 207 m.Forwarding.Init(&a.Forwarding, &b.Forwarding) 208 } 209 210 // LINT.ThenChange(:MultiCounterIPStats, ../../../tcpip.go:IPStats)