nic_stats.go raw

   1  // Copyright 2021 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 stack
  16  
  17  import (
  18  	"gvisor.dev/gvisor/pkg/tcpip"
  19  )
  20  
  21  // +stateify savable
  22  type sharedStats struct {
  23  	local tcpip.NICStats
  24  	multiCounterNICStats
  25  }
  26  
  27  // LINT.IfChange(multiCounterNICPacketStats)
  28  
  29  // +stateify savable
  30  type multiCounterNICPacketStats struct {
  31  	packets tcpip.MultiCounterStat
  32  	bytes   tcpip.MultiCounterStat
  33  }
  34  
  35  func (m *multiCounterNICPacketStats) init(a, b *tcpip.NICPacketStats) {
  36  	m.packets.Init(a.Packets, b.Packets)
  37  	m.bytes.Init(a.Bytes, b.Bytes)
  38  }
  39  
  40  // LINT.ThenChange(../tcpip.go:NICPacketStats)
  41  
  42  // LINT.IfChange(multiCounterNICNeighborStats)
  43  
  44  // +stateify savable
  45  type multiCounterNICNeighborStats struct {
  46  	unreachableEntryLookups                    tcpip.MultiCounterStat
  47  	droppedConfirmationForNoninitiatedNeighbor tcpip.MultiCounterStat
  48  	droppedInvalidLinkAddressConfirmations     tcpip.MultiCounterStat
  49  }
  50  
  51  func (m *multiCounterNICNeighborStats) init(a, b *tcpip.NICNeighborStats) {
  52  	m.unreachableEntryLookups.Init(a.UnreachableEntryLookups, b.UnreachableEntryLookups)
  53  	m.droppedConfirmationForNoninitiatedNeighbor.Init(a.DroppedConfirmationForNoninitiatedNeighbor, b.DroppedConfirmationForNoninitiatedNeighbor)
  54  	m.droppedInvalidLinkAddressConfirmations.Init(a.DroppedInvalidLinkAddressConfirmations, b.DroppedInvalidLinkAddressConfirmations)
  55  }
  56  
  57  // LINT.ThenChange(../tcpip.go:NICNeighborStats)
  58  
  59  // LINT.IfChange(multiCounterNICStats)
  60  
  61  // +stateify savable
  62  type multiCounterNICStats struct {
  63  	unknownL3ProtocolRcvdPacketCounts tcpip.MultiIntegralStatCounterMap
  64  	unknownL4ProtocolRcvdPacketCounts tcpip.MultiIntegralStatCounterMap
  65  	malformedL4RcvdPackets            tcpip.MultiCounterStat
  66  	tx                                multiCounterNICPacketStats
  67  	txPacketsDroppedNoBufferSpace     tcpip.MultiCounterStat
  68  	rx                                multiCounterNICPacketStats
  69  	disabledRx                        multiCounterNICPacketStats
  70  	neighbor                          multiCounterNICNeighborStats
  71  }
  72  
  73  func (m *multiCounterNICStats) init(a, b *tcpip.NICStats) {
  74  	m.unknownL3ProtocolRcvdPacketCounts.Init(a.UnknownL3ProtocolRcvdPacketCounts, b.UnknownL3ProtocolRcvdPacketCounts)
  75  	m.unknownL4ProtocolRcvdPacketCounts.Init(a.UnknownL4ProtocolRcvdPacketCounts, b.UnknownL4ProtocolRcvdPacketCounts)
  76  	m.malformedL4RcvdPackets.Init(a.MalformedL4RcvdPackets, b.MalformedL4RcvdPackets)
  77  	m.tx.init(&a.Tx, &b.Tx)
  78  	m.txPacketsDroppedNoBufferSpace.Init(a.TxPacketsDroppedNoBufferSpace, b.TxPacketsDroppedNoBufferSpace)
  79  	m.rx.init(&a.Rx, &b.Rx)
  80  	m.disabledRx.init(&a.DisabledRx, &b.DisabledRx)
  81  	m.neighbor.init(&a.Neighbor, &b.Neighbor)
  82  }
  83  
  84  // LINT.ThenChange(../tcpip.go:NICStats)
  85