From 22a6a37079c69129d10abfbdd6fdfdf7a9d4a68d Mon Sep 17 00:00:00 2001 From: Nick Brown Date: Wed, 27 Oct 2021 10:03:11 -0700 Subject: Record counts of packets with unknown L3/L4 numbers Previously, we recorded a single aggregated count. These per-protocol counts can help us debug field issues when frames are dropped for this reason. PiperOrigin-RevId: 405913911 --- pkg/tcpip/stack/nic.go | 4 ++-- pkg/tcpip/stack/nic_stats.go | 24 ++++++++++++------------ pkg/tcpip/stack/nic_test.go | 44 +++++++++++++++++++++++++++++++++++++++++++- 3 files changed, 57 insertions(+), 15 deletions(-) (limited to 'pkg/tcpip/stack') 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/stack/nic_test.go b/pkg/tcpip/stack/nic_test.go index c8ad93f29..88ca9b076 100644 --- a/pkg/tcpip/stack/nic_test.go +++ b/pkg/tcpip/stack/nic_test.go @@ -206,6 +206,45 @@ func TestDisabledRxStatsWhenNICDisabled(t *testing.T) { } } +func TestPacketWithUnknownNetworkProtocolNumber(t *testing.T) { + nic := nic{ + stats: makeNICStats(tcpip.NICStats{}.FillIn()), + enabled: 1, + } + // IPv4 isn't recognized since we haven't initialized the NIC with an IPv4 + // endpoint. + nic.DeliverNetworkPacket("", "", header.IPv4ProtocolNumber, NewPacketBuffer(PacketBufferOptions{ + Data: buffer.View([]byte{1, 2, 3, 4}).ToVectorisedView(), + })) + var count uint64 + if got, ok := nic.stats.local.UnknownL3ProtocolRcvdPacketCounts.Get(uint64(header.IPv4ProtocolNumber)); ok { + count = got.Value() + } + if count != 1 { + t.Errorf("got UnknownL3ProtocolRcvdPacketCounts[header.IPv4ProtocolNumber] = %d, want = 1", count) + } +} + +func TestPacketWithUnknownTransportProtocolNumber(t *testing.T) { + nic := nic{ + stack: &Stack{}, + stats: makeNICStats(tcpip.NICStats{}.FillIn()), + enabled: 1, + } + // UDP isn't recognized since we haven't initialized the NIC with a UDP + // protocol. + nic.DeliverTransportPacket(header.UDPProtocolNumber, NewPacketBuffer(PacketBufferOptions{ + Data: buffer.View([]byte{1, 2, 3, 4}).ToVectorisedView(), + })) + var count uint64 + if got, ok := nic.stats.local.UnknownL4ProtocolRcvdPacketCounts.Get(uint64(header.UDPProtocolNumber)); ok { + count = got.Value() + } + if count != 1 { + t.Errorf("got UnknownL4ProtocolRcvdPacketCounts[header.UDPProtocolNumber] = %d, want = 1", count) + } +} + func TestMultiCounterStatsInitialization(t *testing.T) { global := tcpip.NICStats{}.FillIn() nic := nic{ @@ -213,7 +252,10 @@ func TestMultiCounterStatsInitialization(t *testing.T) { } multi := nic.stats.multiCounterNICStats local := nic.stats.local - if err := testutil.ValidateMultiCounterStats(reflect.ValueOf(&multi).Elem(), []reflect.Value{reflect.ValueOf(&local).Elem(), reflect.ValueOf(&global).Elem()}); err != nil { + if err := testutil.ValidateMultiCounterStats(reflect.ValueOf(&multi).Elem(), []reflect.Value{reflect.ValueOf(&local).Elem(), reflect.ValueOf(&global).Elem()}, testutil.ValidateMultiCounterStatsOptions{ + ExpectMultiCounterStat: true, + ExpectMultiIntegralStatCounterMap: true, + }); err != nil { t.Error(err) } } -- cgit v1.2.3