github.com/ttpreport/gvisor-ligolo@v0.0.0-20240123134145-a858404967ba/pkg/tcpip/network/ipv6/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 ipv6 16 17 import ( 18 "github.com/ttpreport/gvisor-ligolo/pkg/tcpip" 19 "github.com/ttpreport/gvisor-ligolo/pkg/tcpip/network/internal/ip" 20 "github.com/ttpreport/gvisor-ligolo/pkg/tcpip/stack" 21 ) 22 23 var _ stack.IPNetworkEndpointStats = (*Stats)(nil) 24 25 // Stats holds statistics related to the IPv6 protocol family. 26 type Stats struct { 27 // IP holds IPv6 statistics. 28 IP tcpip.IPStats 29 30 // ICMP holds ICMPv6 statistics. 31 ICMP tcpip.ICMPv6Stats 32 33 // UnhandledRouterAdvertisements is the number of Router Advertisements that 34 // were observed but not handled. 35 UnhandledRouterAdvertisements *tcpip.StatCounter 36 } 37 38 // IsNetworkEndpointStats implements stack.NetworkEndpointStats. 39 func (*Stats) IsNetworkEndpointStats() {} 40 41 // IPStats implements stack.IPNetworkEndointStats 42 func (s *Stats) IPStats() *tcpip.IPStats { 43 return &s.IP 44 } 45 46 type sharedStats struct { 47 localStats Stats 48 ip ip.MultiCounterIPStats 49 icmp multiCounterICMPv6Stats 50 } 51 52 // LINT.IfChange(multiCounterICMPv6PacketStats) 53 54 type multiCounterICMPv6PacketStats struct { 55 echoRequest tcpip.MultiCounterStat 56 echoReply tcpip.MultiCounterStat 57 dstUnreachable tcpip.MultiCounterStat 58 packetTooBig tcpip.MultiCounterStat 59 timeExceeded tcpip.MultiCounterStat 60 paramProblem tcpip.MultiCounterStat 61 routerSolicit tcpip.MultiCounterStat 62 routerAdvert tcpip.MultiCounterStat 63 neighborSolicit tcpip.MultiCounterStat 64 neighborAdvert tcpip.MultiCounterStat 65 redirectMsg tcpip.MultiCounterStat 66 multicastListenerQuery tcpip.MultiCounterStat 67 multicastListenerReport tcpip.MultiCounterStat 68 multicastListenerReportV2 tcpip.MultiCounterStat 69 multicastListenerDone tcpip.MultiCounterStat 70 } 71 72 func (m *multiCounterICMPv6PacketStats) init(a, b *tcpip.ICMPv6PacketStats) { 73 m.echoRequest.Init(a.EchoRequest, b.EchoRequest) 74 m.echoReply.Init(a.EchoReply, b.EchoReply) 75 m.dstUnreachable.Init(a.DstUnreachable, b.DstUnreachable) 76 m.packetTooBig.Init(a.PacketTooBig, b.PacketTooBig) 77 m.timeExceeded.Init(a.TimeExceeded, b.TimeExceeded) 78 m.paramProblem.Init(a.ParamProblem, b.ParamProblem) 79 m.routerSolicit.Init(a.RouterSolicit, b.RouterSolicit) 80 m.routerAdvert.Init(a.RouterAdvert, b.RouterAdvert) 81 m.neighborSolicit.Init(a.NeighborSolicit, b.NeighborSolicit) 82 m.neighborAdvert.Init(a.NeighborAdvert, b.NeighborAdvert) 83 m.redirectMsg.Init(a.RedirectMsg, b.RedirectMsg) 84 m.multicastListenerQuery.Init(a.MulticastListenerQuery, b.MulticastListenerQuery) 85 m.multicastListenerReport.Init(a.MulticastListenerReport, b.MulticastListenerReport) 86 m.multicastListenerReportV2.Init(a.MulticastListenerReportV2, b.MulticastListenerReportV2) 87 m.multicastListenerDone.Init(a.MulticastListenerDone, b.MulticastListenerDone) 88 } 89 90 // LINT.ThenChange(../../tcpip.go:ICMPv6PacketStats) 91 92 // LINT.IfChange(multiCounterICMPv6SentPacketStats) 93 94 type multiCounterICMPv6SentPacketStats struct { 95 multiCounterICMPv6PacketStats 96 dropped tcpip.MultiCounterStat 97 rateLimited tcpip.MultiCounterStat 98 } 99 100 func (m *multiCounterICMPv6SentPacketStats) init(a, b *tcpip.ICMPv6SentPacketStats) { 101 m.multiCounterICMPv6PacketStats.init(&a.ICMPv6PacketStats, &b.ICMPv6PacketStats) 102 m.dropped.Init(a.Dropped, b.Dropped) 103 m.rateLimited.Init(a.RateLimited, b.RateLimited) 104 } 105 106 // LINT.ThenChange(../../tcpip.go:ICMPv6SentPacketStats) 107 108 // LINT.IfChange(multiCounterICMPv6ReceivedPacketStats) 109 110 type multiCounterICMPv6ReceivedPacketStats struct { 111 multiCounterICMPv6PacketStats 112 unrecognized tcpip.MultiCounterStat 113 invalid tcpip.MultiCounterStat 114 routerOnlyPacketsDroppedByHost tcpip.MultiCounterStat 115 } 116 117 func (m *multiCounterICMPv6ReceivedPacketStats) init(a, b *tcpip.ICMPv6ReceivedPacketStats) { 118 m.multiCounterICMPv6PacketStats.init(&a.ICMPv6PacketStats, &b.ICMPv6PacketStats) 119 m.unrecognized.Init(a.Unrecognized, b.Unrecognized) 120 m.invalid.Init(a.Invalid, b.Invalid) 121 m.routerOnlyPacketsDroppedByHost.Init(a.RouterOnlyPacketsDroppedByHost, b.RouterOnlyPacketsDroppedByHost) 122 } 123 124 // LINT.ThenChange(../../tcpip.go:ICMPv6ReceivedPacketStats) 125 126 // LINT.IfChange(multiCounterICMPv6Stats) 127 128 type multiCounterICMPv6Stats struct { 129 packetsSent multiCounterICMPv6SentPacketStats 130 packetsReceived multiCounterICMPv6ReceivedPacketStats 131 } 132 133 func (m *multiCounterICMPv6Stats) init(a, b *tcpip.ICMPv6Stats) { 134 m.packetsSent.init(&a.PacketsSent, &b.PacketsSent) 135 m.packetsReceived.init(&a.PacketsReceived, &b.PacketsReceived) 136 } 137 138 // LINT.ThenChange(../../tcpip.go:ICMPv6Stats)