summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorgVisor bot <gvisor-bot@google.com>2021-10-27 17:11:49 +0000
committergVisor bot <gvisor-bot@google.com>2021-10-27 17:11:49 +0000
commit9893e2a4f8ee379b719a9ab783cdb1867d1191ad (patch)
tree93482f3e55995ec256508d130892d35aeeb82f8f
parent4a42e7524518af56e34a922ddc717e963594f9a3 (diff)
parent22a6a37079c69129d10abfbdd6fdfdf7a9d4a68d (diff)
Merge release-20211019.0-45-g22a6a3707 (automated)
-rw-r--r--pkg/sentry/socket/netstack/netstack.go4
-rw-r--r--pkg/tcpip/stack/nic.go4
-rw-r--r--pkg/tcpip/stack/nic_stats.go24
-rw-r--r--pkg/tcpip/tcpip.go92
4 files changed, 100 insertions, 24 deletions
diff --git a/pkg/sentry/socket/netstack/netstack.go b/pkg/sentry/socket/netstack/netstack.go
index 030c6c8e4..2a1c2f246 100644
--- a/pkg/sentry/socket/netstack/netstack.go
+++ b/pkg/sentry/socket/netstack/netstack.go
@@ -81,9 +81,7 @@ func mustCreateGauge(name, description string) *tcpip.StatCounter {
var Metrics = tcpip.Stats{
DroppedPackets: mustCreateMetric("/netstack/dropped_packets", "Number of packets dropped at the transport layer."),
NICs: tcpip.NICStats{
- UnknownL3ProtocolRcvdPackets: mustCreateMetric("/netstack/nic/unknown_l3_protocol_received_packets", "Number of packets received that were for an unknown or unsupported L3 protocol."),
- UnknownL4ProtocolRcvdPackets: mustCreateMetric("/netstack/nic/unknown_l4_protocol_received_packets", "Number of packets received that were for an unknown or unsupported L4 protocol."),
- MalformedL4RcvdPackets: mustCreateMetric("/netstack/nic/malformed_l4_received_packets", "Number of packets received that failed L4 header parsing."),
+ MalformedL4RcvdPackets: mustCreateMetric("/netstack/nic/malformed_l4_received_packets", "Number of packets received that failed L4 header parsing."),
Tx: tcpip.NICPacketStats{
Packets: mustCreateMetric("/netstack/nic/tx/packets", "Number of packets transmitted."),
Bytes: mustCreateMetric("/netstack/nic/tx/bytes", "Number of bytes transmitted."),
diff --git a/pkg/tcpip/stack/nic.go b/pkg/tcpip/stack/nic.go
index e251e3b24..b9b5c35c8 100644
--- a/pkg/tcpip/stack/nic.go
+++ b/pkg/tcpip/stack/nic.go
@@ -727,7 +727,7 @@ func (n *nic) DeliverNetworkPacket(remote, local tcpip.LinkAddress, protocol tcp
networkEndpoint, ok := n.networkEndpoints[protocol]
if !ok {
- n.stats.unknownL3ProtocolRcvdPackets.Increment()
+ n.stats.unknownL3ProtocolRcvdPacketCounts.Increment(uint64(protocol))
return
}
@@ -827,7 +827,7 @@ func (n *nic) deliverOutboundPacket(remote tcpip.LinkAddress, pkt *PacketBuffer)
func (n *nic) DeliverTransportPacket(protocol tcpip.TransportProtocolNumber, pkt *PacketBuffer) TransportPacketDisposition {
state, ok := n.stack.transportProtocols[protocol]
if !ok {
- n.stats.unknownL4ProtocolRcvdPackets.Increment()
+ n.stats.unknownL4ProtocolRcvdPacketCounts.Increment(uint64(protocol))
return TransportPacketProtocolUnreachable
}
diff --git a/pkg/tcpip/stack/nic_stats.go b/pkg/tcpip/stack/nic_stats.go
index 1773d5e8d..89aa95131 100644
--- a/pkg/tcpip/stack/nic_stats.go
+++ b/pkg/tcpip/stack/nic_stats.go
@@ -35,7 +35,7 @@ func (m *multiCounterNICPacketStats) init(a, b *tcpip.NICPacketStats) {
m.bytes.Init(a.Bytes, b.Bytes)
}
-// LINT.ThenChange(../../tcpip.go:NICPacketStats)
+// LINT.ThenChange(../tcpip.go:NICPacketStats)
// LINT.IfChange(multiCounterNICNeighborStats)
@@ -47,23 +47,23 @@ func (m *multiCounterNICNeighborStats) init(a, b *tcpip.NICNeighborStats) {
m.unreachableEntryLookups.Init(a.UnreachableEntryLookups, b.UnreachableEntryLookups)
}
-// LINT.ThenChange(../../tcpip.go:NICNeighborStats)
+// LINT.ThenChange(../tcpip.go:NICNeighborStats)
// LINT.IfChange(multiCounterNICStats)
type multiCounterNICStats struct {
- unknownL3ProtocolRcvdPackets tcpip.MultiCounterStat
- unknownL4ProtocolRcvdPackets tcpip.MultiCounterStat
- malformedL4RcvdPackets tcpip.MultiCounterStat
- tx multiCounterNICPacketStats
- rx multiCounterNICPacketStats
- disabledRx multiCounterNICPacketStats
- neighbor multiCounterNICNeighborStats
+ unknownL3ProtocolRcvdPacketCounts tcpip.MultiIntegralStatCounterMap
+ unknownL4ProtocolRcvdPacketCounts tcpip.MultiIntegralStatCounterMap
+ malformedL4RcvdPackets tcpip.MultiCounterStat
+ tx multiCounterNICPacketStats
+ rx multiCounterNICPacketStats
+ disabledRx multiCounterNICPacketStats
+ neighbor multiCounterNICNeighborStats
}
func (m *multiCounterNICStats) init(a, b *tcpip.NICStats) {
- m.unknownL3ProtocolRcvdPackets.Init(a.UnknownL3ProtocolRcvdPackets, b.UnknownL3ProtocolRcvdPackets)
- m.unknownL4ProtocolRcvdPackets.Init(a.UnknownL4ProtocolRcvdPackets, b.UnknownL4ProtocolRcvdPackets)
+ m.unknownL3ProtocolRcvdPacketCounts.Init(a.UnknownL3ProtocolRcvdPacketCounts, b.UnknownL3ProtocolRcvdPacketCounts)
+ m.unknownL4ProtocolRcvdPacketCounts.Init(a.UnknownL4ProtocolRcvdPacketCounts, b.UnknownL4ProtocolRcvdPacketCounts)
m.malformedL4RcvdPackets.Init(a.MalformedL4RcvdPackets, b.MalformedL4RcvdPackets)
m.tx.init(&a.Tx, &b.Tx)
m.rx.init(&a.Rx, &b.Rx)
@@ -71,4 +71,4 @@ func (m *multiCounterNICStats) init(a, b *tcpip.NICStats) {
m.neighbor.init(&a.Neighbor, &b.Neighbor)
}
-// LINT.ThenChange(../../tcpip.go:NICStats)
+// LINT.ThenChange(../tcpip.go:NICStats)
diff --git a/pkg/tcpip/tcpip.go b/pkg/tcpip/tcpip.go
index 460a6afaf..d20dd495c 100644
--- a/pkg/tcpip/tcpip.go
+++ b/pkg/tcpip/tcpip.go
@@ -1301,7 +1301,8 @@ func (s *StatCounter) String() string {
// A MultiCounterStat keeps track of two counters at once.
type MultiCounterStat struct {
- a, b *StatCounter
+ a *StatCounter
+ b *StatCounter
}
// Init sets both internal counters to point to a and b.
@@ -1923,17 +1924,89 @@ type NICPacketStats struct {
// LINT.ThenChange(stack/nic_stats.go:multiCounterNICPacketStats)
}
+// IntegralStatCounterMap holds a map associating integral keys with
+// StatCounters.
+type IntegralStatCounterMap struct {
+ mu sync.RWMutex
+ // +checklocks:mu
+ counterMap map[uint64]*StatCounter
+}
+
+// Keys returns all keys present in the map.
+func (m *IntegralStatCounterMap) Keys() []uint64 {
+ m.mu.RLock()
+ defer m.mu.RUnlock()
+ var keys []uint64
+ for k := range m.counterMap {
+ keys = append(keys, k)
+ }
+ return keys
+}
+
+// Get returns the counter mapped by the provided key.
+func (m *IntegralStatCounterMap) Get(key uint64) (*StatCounter, bool) {
+ m.mu.RLock()
+ defer m.mu.RUnlock()
+ counter, ok := m.counterMap[key]
+ return counter, ok
+}
+
+// Init initializes the map.
+func (m *IntegralStatCounterMap) Init() {
+ m.mu.Lock()
+ defer m.mu.Unlock()
+ m.counterMap = make(map[uint64]*StatCounter)
+}
+
+// Increment increments the counter associated with the provided key.
+func (m *IntegralStatCounterMap) Increment(key uint64) {
+ m.mu.RLock()
+ counter, ok := m.counterMap[key]
+ m.mu.RUnlock()
+
+ if !ok {
+ m.mu.Lock()
+ counter, ok = m.counterMap[key]
+ if !ok {
+ counter = new(StatCounter)
+ m.counterMap[key] = counter
+ }
+ m.mu.Unlock()
+ }
+ counter.Increment()
+}
+
+// A MultiIntegralStatCounterMap keeps track of two integral counter maps at
+// once.
+type MultiIntegralStatCounterMap struct {
+ a *IntegralStatCounterMap
+ b *IntegralStatCounterMap
+}
+
+// Init sets the internal integral counter maps to point to a and b.
+func (m *MultiIntegralStatCounterMap) Init(a, b *IntegralStatCounterMap) {
+ m.a = a
+ m.b = b
+}
+
+// Increment increments the counter in each map corresponding to the
+// provided key.
+func (m *MultiIntegralStatCounterMap) Increment(key uint64) {
+ m.a.Increment(key)
+ m.b.Increment(key)
+}
+
// NICStats holds NIC statistics.
type NICStats struct {
// LINT.IfChange(NICStats)
- // UnknownL3ProtocolRcvdPackets is the number of packets received that were
- // for an unknown or unsupported network protocol.
- UnknownL3ProtocolRcvdPackets *StatCounter
+ // UnknownL3ProtocolRcvdPacketCounts records the number of packets recieved
+ // for each unknown or unsupported netowrk protocol number.
+ UnknownL3ProtocolRcvdPacketCounts *IntegralStatCounterMap
- // UnknownL4ProtocolRcvdPackets is the number of packets received that were
- // for an unknown or unsupported transport protocol.
- UnknownL4ProtocolRcvdPackets *StatCounter
+ // UnknownL4ProtocolRcvdPacketCounts records the number of packets recieved
+ // for each unknown or unsupported transport protocol number.
+ UnknownL4ProtocolRcvdPacketCounts *IntegralStatCounterMap
// MalformedL4RcvdPackets is the number of packets received by a NIC that
// could not be delivered to a transport endpoint because the L4 header could
@@ -2103,6 +2176,11 @@ func InitStatCounters(v reflect.Value) {
if *s == nil {
*s = new(StatCounter)
}
+ } else if s, ok := v.Addr().Interface().(**IntegralStatCounterMap); ok {
+ if *s == nil {
+ *s = new(IntegralStatCounterMap)
+ (*s).Init()
+ }
} else {
InitStatCounters(v)
}