github.com/SagerNet/gvisor@v0.0.0-20210707092255-7731c139d75c/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 "github.com/SagerNet/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 // LinkLocalSource is the number of IP packets which were dropped 34 // because they contained a link-local source address. 35 LinkLocalSource tcpip.MultiCounterStat 36 37 // LinkLocalDestination is the number of IP packets which were dropped 38 // because they contained a link-local destination address. 39 LinkLocalDestination tcpip.MultiCounterStat 40 41 // PacketTooBig is the number of IP packets which were dropped because they 42 // were too big for the outgoing MTU. 43 PacketTooBig tcpip.MultiCounterStat 44 45 // HostUnreachable is the number of IP packets received which could not be 46 // successfully forwarded due to an unresolvable next hop. 47 HostUnreachable tcpip.MultiCounterStat 48 49 // ExtensionHeaderProblem is the number of IP packets which were dropped 50 // because of a problem encountered when processing an IPv6 extension 51 // header. 52 ExtensionHeaderProblem tcpip.MultiCounterStat 53 54 // Errors is the number of IP packets received which could not be 55 // successfully forwarded. 56 Errors tcpip.MultiCounterStat 57 } 58 59 // Init sets internal counters to track a and b counters. 60 func (m *MultiCounterIPForwardingStats) Init(a, b *tcpip.IPForwardingStats) { 61 m.Unrouteable.Init(a.Unrouteable, b.Unrouteable) 62 m.Errors.Init(a.Errors, b.Errors) 63 m.LinkLocalSource.Init(a.LinkLocalSource, b.LinkLocalSource) 64 m.LinkLocalDestination.Init(a.LinkLocalDestination, b.LinkLocalDestination) 65 m.ExtensionHeaderProblem.Init(a.ExtensionHeaderProblem, b.ExtensionHeaderProblem) 66 m.PacketTooBig.Init(a.PacketTooBig, b.PacketTooBig) 67 m.ExhaustedTTL.Init(a.ExhaustedTTL, b.ExhaustedTTL) 68 m.HostUnreachable.Init(a.HostUnreachable, b.HostUnreachable) 69 } 70 71 // LINT.ThenChange(:MultiCounterIPForwardingStats, ../../../tcpip.go:IPForwardingStats) 72 73 // LINT.IfChange(MultiCounterIPStats) 74 75 // MultiCounterIPStats holds IP statistics, each counter may have several 76 // versions. 77 type MultiCounterIPStats struct { 78 // PacketsReceived is the number of IP packets received from the link 79 // layer. 80 PacketsReceived tcpip.MultiCounterStat 81 82 // ValidPacketsReceived is the number of valid IP packets that reached the IP 83 // layer. 84 ValidPacketsReceived tcpip.MultiCounterStat 85 86 // DisabledPacketsReceived is the number of IP packets received from 87 // the link layer when the IP layer is disabled. 88 DisabledPacketsReceived tcpip.MultiCounterStat 89 90 // InvalidDestinationAddressesReceived is the number of IP packets 91 // received with an unknown or invalid destination address. 92 InvalidDestinationAddressesReceived tcpip.MultiCounterStat 93 94 // InvalidSourceAddressesReceived is the number of IP packets received 95 // with a source address that should never have been received on the 96 // wire. 97 InvalidSourceAddressesReceived tcpip.MultiCounterStat 98 99 // PacketsDelivered is the number of incoming IP packets successfully 100 // delivered to the transport layer. 101 PacketsDelivered tcpip.MultiCounterStat 102 103 // PacketsSent is the number of IP packets sent via WritePacket. 104 PacketsSent tcpip.MultiCounterStat 105 106 // OutgoingPacketErrors is the number of IP packets which failed to 107 // write to a link-layer endpoint. 108 OutgoingPacketErrors tcpip.MultiCounterStat 109 110 // MalformedPacketsReceived is the number of IP Packets that were 111 // dropped due to the IP packet header failing validation checks. 112 MalformedPacketsReceived tcpip.MultiCounterStat 113 114 // MalformedFragmentsReceived is the number of IP Fragments that were 115 // dropped due to the fragment failing validation checks. 116 MalformedFragmentsReceived tcpip.MultiCounterStat 117 118 // IPTablesPreroutingDropped is the number of IP packets dropped in the 119 // Prerouting chain. 120 IPTablesPreroutingDropped tcpip.MultiCounterStat 121 122 // IPTablesInputDropped is the number of IP packets dropped in the 123 // Input chain. 124 IPTablesInputDropped tcpip.MultiCounterStat 125 126 // IPTablesForwardDropped is the number of IP packets dropped in the 127 // Forward chain. 128 IPTablesForwardDropped tcpip.MultiCounterStat 129 130 // IPTablesOutputDropped is the number of IP packets dropped in the 131 // Output chain. 132 IPTablesOutputDropped tcpip.MultiCounterStat 133 134 // IPTablesPostroutingDropped is the number of IP packets dropped in 135 // the Postrouting chain. 136 IPTablesPostroutingDropped tcpip.MultiCounterStat 137 138 // TODO(https://github.com/SagerNet/issues/5529): Move the IPv4-only option 139 // stats out of IPStats. 140 141 // OptionTimestampReceived is the number of Timestamp options seen. 142 OptionTimestampReceived tcpip.MultiCounterStat 143 144 // OptionRecordRouteReceived is the number of Record Route options 145 // seen. 146 OptionRecordRouteReceived tcpip.MultiCounterStat 147 148 // OptionRouterAlertReceived is the number of Router Alert options 149 // seen. 150 OptionRouterAlertReceived tcpip.MultiCounterStat 151 152 // OptionUnknownReceived is the number of unknown IP options seen. 153 OptionUnknownReceived tcpip.MultiCounterStat 154 155 // Forwarding collects stats related to IP forwarding. 156 Forwarding MultiCounterIPForwardingStats 157 } 158 159 // Init sets internal counters to track a and b counters. 160 func (m *MultiCounterIPStats) Init(a, b *tcpip.IPStats) { 161 m.PacketsReceived.Init(a.PacketsReceived, b.PacketsReceived) 162 m.ValidPacketsReceived.Init(a.ValidPacketsReceived, b.ValidPacketsReceived) 163 m.DisabledPacketsReceived.Init(a.DisabledPacketsReceived, b.DisabledPacketsReceived) 164 m.InvalidDestinationAddressesReceived.Init(a.InvalidDestinationAddressesReceived, b.InvalidDestinationAddressesReceived) 165 m.InvalidSourceAddressesReceived.Init(a.InvalidSourceAddressesReceived, b.InvalidSourceAddressesReceived) 166 m.PacketsDelivered.Init(a.PacketsDelivered, b.PacketsDelivered) 167 m.PacketsSent.Init(a.PacketsSent, b.PacketsSent) 168 m.OutgoingPacketErrors.Init(a.OutgoingPacketErrors, b.OutgoingPacketErrors) 169 m.MalformedPacketsReceived.Init(a.MalformedPacketsReceived, b.MalformedPacketsReceived) 170 m.MalformedFragmentsReceived.Init(a.MalformedFragmentsReceived, b.MalformedFragmentsReceived) 171 m.IPTablesPreroutingDropped.Init(a.IPTablesPreroutingDropped, b.IPTablesPreroutingDropped) 172 m.IPTablesInputDropped.Init(a.IPTablesInputDropped, b.IPTablesInputDropped) 173 m.IPTablesForwardDropped.Init(a.IPTablesForwardDropped, b.IPTablesForwardDropped) 174 m.IPTablesOutputDropped.Init(a.IPTablesOutputDropped, b.IPTablesOutputDropped) 175 m.IPTablesPostroutingDropped.Init(a.IPTablesPostroutingDropped, b.IPTablesPostroutingDropped) 176 m.OptionTimestampReceived.Init(a.OptionTimestampReceived, b.OptionTimestampReceived) 177 m.OptionRecordRouteReceived.Init(a.OptionRecordRouteReceived, b.OptionRecordRouteReceived) 178 m.OptionRouterAlertReceived.Init(a.OptionRouterAlertReceived, b.OptionRouterAlertReceived) 179 m.OptionUnknownReceived.Init(a.OptionUnknownReceived, b.OptionUnknownReceived) 180 m.Forwarding.Init(&a.Forwarding, &b.Forwarding) 181 } 182 183 // LINT.ThenChange(:MultiCounterIPStats, ../../../tcpip.go:IPStats)