From 4d37180f89d0eb6c91aa196b9e97af3eb38f9a99 Mon Sep 17 00:00:00 2001 From: Kevin Krakauer Date: Tue, 17 Sep 2024 14:32:30 -0700 Subject: [PATCH] netstack: remove sniffer.LogPacketsToPCAP This was always set to 1, with the deteriminant of whether to log PCAP output instead being whether `sniffer.Endpoint.writer` was non-nil. There's no reason to keep it around. PiperOrigin-RevId: 675712237 --- pkg/tcpip/link/sniffer/sniffer.go | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/pkg/tcpip/link/sniffer/sniffer.go b/pkg/tcpip/link/sniffer/sniffer.go index 583e7d899..5f20743c2 100644 --- a/pkg/tcpip/link/sniffer/sniffer.go +++ b/pkg/tcpip/link/sniffer/sniffer.go @@ -39,11 +39,6 @@ import ( // package. Valid values are 0 or 1. var LogPackets atomicbitops.Uint32 = atomicbitops.FromUint32(1) -// LogPacketsToPCAP is a flag used to enable or disable logging packets to a -// pcap writer. Valid values are 0 or 1. A writer must have been specified when the -// sniffer was created for this flag to have effect. -var LogPacketsToPCAP atomicbitops.Uint32 = atomicbitops.FromUint32(1) - // Endpoint is used to sniff and log network traffic. // // +stateify savable @@ -155,11 +150,10 @@ func (e *Endpoint) DeliverNetworkPacket(protocol tcpip.NetworkProtocolNumber, pk // DumpPacket logs a packet, depending on configuration, to stderr and/or a // pcap file. ts is an optional timestamp for the packet. func (e *Endpoint) DumpPacket(dir Direction, protocol tcpip.NetworkProtocolNumber, pkt *stack.PacketBuffer, ts *time.Time) { - writer := e.writer if LogPackets.Load() == 1 { LogPacket(e.logPrefix, dir, protocol, pkt) } - if writer != nil && LogPacketsToPCAP.Load() == 1 { + if e.writer != nil { packet := pcapPacket{ packet: pkt, maxCaptureLen: int(e.maxPCAPLen), @@ -173,7 +167,7 @@ func (e *Endpoint) DumpPacket(dir Direction, protocol tcpip.NetworkProtocolNumbe if err != nil { panic(err) } - if _, err := writer.Write(b); err != nil { + if _, err := e.writer.Write(b); err != nil { panic(err) } }