summaryrefslogtreecommitdiffhomepage
path: root/pkg/tcpip/link/sniffer/sniffer.go
diff options
context:
space:
mode:
authorgVisor bot <gvisor-bot@google.com>2021-07-29 05:50:30 +0000
committergVisor bot <gvisor-bot@google.com>2021-07-29 05:50:30 +0000
commit904163540563b2d9c1069ae348a1a4e05efc675c (patch)
treeb4aca4141a0f38a8decca32df6e0cd68e95ca312 /pkg/tcpip/link/sniffer/sniffer.go
parent39be53091c3b9d7542360aee159fda2f59fdfc07 (diff)
parent095b0d8348531b96f1b40885c00d6cd7f07ecf80 (diff)
Merge release-20210720.0-45-g095b0d834 (automated)
Diffstat (limited to 'pkg/tcpip/link/sniffer/sniffer.go')
-rw-r--r--pkg/tcpip/link/sniffer/sniffer.go33
1 files changed, 8 insertions, 25 deletions
diff --git a/pkg/tcpip/link/sniffer/sniffer.go b/pkg/tcpip/link/sniffer/sniffer.go
index 3df826f3c..28a172e71 100644
--- a/pkg/tcpip/link/sniffer/sniffer.go
+++ b/pkg/tcpip/link/sniffer/sniffer.go
@@ -151,33 +151,16 @@ func (e *endpoint) dumpPacket(dir direction, protocol tcpip.NetworkProtocolNumbe
logPacket(e.logPrefix, dir, protocol, pkt)
}
if writer != nil && atomic.LoadUint32(&LogPacketsToPCAP) == 1 {
- totalLength := pkt.Size()
- length := totalLength
- if max := int(e.maxPCAPLen); length > max {
- length = max
+ packet := pcapPacket{
+ timestamp: time.Now(),
+ packet: pkt,
+ maxCaptureLen: int(e.maxPCAPLen),
}
- packetHeader := newPCAPPacketHeader(time.Now(), uint32(length), uint32(totalLength))
- packet := make([]byte, binary.Size(packetHeader)+length)
- {
- writer := tcpip.SliceWriter(packet)
- if err := binary.Write(&writer, binary.BigEndian, packetHeader); err != nil {
- panic(err)
- }
- for _, b := range pkt.Views() {
- if length == 0 {
- break
- }
- if len(b) > length {
- b = b[:length]
- }
- n, err := writer.Write(b)
- if err != nil {
- panic(err)
- }
- length -= n
- }
+ b, err := packet.MarshalBinary()
+ if err != nil {
+ panic(err)
}
- if _, err := writer.Write(packet); err != nil {
+ if _, err := writer.Write(b); err != nil {
panic(err)
}
}