github.com/SagerNet/gvisor@v0.0.0-20210707092255-7731c139d75c/pkg/tcpip/stack/nic_stats.go (about)

     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  	"github.com/SagerNet/gvisor/pkg/tcpip"
    19  )
    20  
    21  type sharedStats struct {
    22  	local tcpip.NICStats
    23  	multiCounterNICStats
    24  }
    25  
    26  // LINT.IfChange(multiCounterNICPacketStats)
    27  
    28  type multiCounterNICPacketStats struct {
    29  	packets tcpip.MultiCounterStat
    30  	bytes   tcpip.MultiCounterStat
    31  }
    32  
    33  func (m *multiCounterNICPacketStats) init(a, b *tcpip.NICPacketStats) {
    34  	m.packets.Init(a.Packets, b.Packets)
    35  	m.bytes.Init(a.Bytes, b.Bytes)
    36  }
    37  
    38  // LINT.ThenChange(../../tcpip.go:NICPacketStats)
    39  
    40  // LINT.IfChange(multiCounterNICNeighborStats)
    41  
    42  type multiCounterNICNeighborStats struct {
    43  	unreachableEntryLookups tcpip.MultiCounterStat
    44  }
    45  
    46  func (m *multiCounterNICNeighborStats) init(a, b *tcpip.NICNeighborStats) {
    47  	m.unreachableEntryLookups.Init(a.UnreachableEntryLookups, b.UnreachableEntryLookups)
    48  }
    49  
    50  // LINT.ThenChange(../../tcpip.go:NICNeighborStats)
    51  
    52  // LINT.IfChange(multiCounterNICStats)
    53  
    54  type multiCounterNICStats struct {
    55  	unknownL3ProtocolRcvdPackets tcpip.MultiCounterStat
    56  	unknownL4ProtocolRcvdPackets tcpip.MultiCounterStat
    57  	malformedL4RcvdPackets       tcpip.MultiCounterStat
    58  	tx                           multiCounterNICPacketStats
    59  	rx                           multiCounterNICPacketStats
    60  	disabledRx                   multiCounterNICPacketStats
    61  	neighbor                     multiCounterNICNeighborStats
    62  }
    63  
    64  func (m *multiCounterNICStats) init(a, b *tcpip.NICStats) {
    65  	m.unknownL3ProtocolRcvdPackets.Init(a.UnknownL3ProtocolRcvdPackets, b.UnknownL3ProtocolRcvdPackets)
    66  	m.unknownL4ProtocolRcvdPackets.Init(a.UnknownL4ProtocolRcvdPackets, b.UnknownL4ProtocolRcvdPackets)
    67  	m.malformedL4RcvdPackets.Init(a.MalformedL4RcvdPackets, b.MalformedL4RcvdPackets)
    68  	m.tx.init(&a.Tx, &b.Tx)
    69  	m.rx.init(&a.Rx, &b.Rx)
    70  	m.disabledRx.init(&a.DisabledRx, &b.DisabledRx)
    71  	m.neighbor.init(&a.Neighbor, &b.Neighbor)
    72  }
    73  
    74  // LINT.ThenChange(../../tcpip.go:NICStats)