diff options
author | Bhasker Hariharan <bhaskerh@google.com> | 2018-05-01 19:11:10 -0700 |
---|---|---|
committer | Shentubot <shentubot@google.com> | 2018-05-01 19:11:59 -0700 |
commit | 43256efb080915d92a17549d86ef4eaff9ab8ef8 (patch) | |
tree | 5fbc220444d48eb2436e94bf9f52719507a1a490 /pkg/tcpip | |
parent | 5eab7a41a3b5419fd0ee0e68116b50fd72b4cdec (diff) |
Write either packet logs or pcap file. But not both.
PiperOrigin-RevId: 195035056
Change-Id: Ib32188b62188ddc2059debd52610e7904e1438c6
Diffstat (limited to 'pkg/tcpip')
-rw-r--r-- | pkg/tcpip/link/sniffer/sniffer.go | 9 |
1 files changed, 5 insertions, 4 deletions
diff --git a/pkg/tcpip/link/sniffer/sniffer.go b/pkg/tcpip/link/sniffer/sniffer.go index da6969e94..72d9a0f1c 100644 --- a/pkg/tcpip/link/sniffer/sniffer.go +++ b/pkg/tcpip/link/sniffer/sniffer.go @@ -86,8 +86,9 @@ func writePCAPHeader(w io.Writer, maxLen uint32) error { // NewWithFile creates a new sniffer link-layer endpoint. It wraps around // another endpoint and logs packets and they traverse the endpoint. // -// Packets can be logged to file in the pcap format in addition to the standard -// human-readable logs. +// Packets can be logged to file in the pcap format. A sniffer created +// with this function will not emit packets using the standard log +// package. // // snapLen is the maximum amount of a packet to be saved. Packets with a length // less than or equal too snapLen will be saved in their entirety. Longer @@ -107,7 +108,7 @@ func NewWithFile(lower tcpip.LinkEndpointID, file *os.File, snapLen uint32) (tcp // called by the link-layer endpoint being wrapped when a packet arrives, and // logs the packet before forwarding to the actual dispatcher. func (e *endpoint) DeliverNetworkPacket(linkEP stack.LinkEndpoint, remoteLinkAddr tcpip.LinkAddress, protocol tcpip.NetworkProtocolNumber, vv *buffer.VectorisedView) { - if atomic.LoadUint32(&LogPackets) == 1 { + if atomic.LoadUint32(&LogPackets) == 1 && e.file == nil { LogPacket("recv", protocol, vv.First(), nil) } if e.file != nil && atomic.LoadUint32(&LogPacketsToFile) == 1 { @@ -168,7 +169,7 @@ func (e *endpoint) LinkAddress() tcpip.LinkAddress { // higher-level protocols to write packets; it just logs the packet and forwards // the request to the lower endpoint. func (e *endpoint) WritePacket(r *stack.Route, hdr *buffer.Prependable, payload buffer.View, protocol tcpip.NetworkProtocolNumber) *tcpip.Error { - if atomic.LoadUint32(&LogPackets) == 1 { + if atomic.LoadUint32(&LogPackets) == 1 && e.file == nil { LogPacket("send", protocol, hdr.UsedBytes(), payload) } if e.file != nil && atomic.LoadUint32(&LogPacketsToFile) == 1 { |