diff options
author | Ghanan Gowripalan <ghanan@google.com> | 2020-11-06 15:59:02 -0800 |
---|---|---|
committer | gVisor bot <gvisor-bot@google.com> | 2020-11-06 16:01:19 -0800 |
commit | 5288e194156a72a3efae7794e46e44f1dd0d7427 (patch) | |
tree | 9ca4e4d3a56be3f9946413294fd2db0451b31001 /pkg/tcpip/link | |
parent | 6c93dc970f0acc110ae4f941574defa4aa113116 (diff) |
Trim link headers from buffer clone when sniffing
PiperOrigin-RevId: 341135083
Diffstat (limited to 'pkg/tcpip/link')
-rw-r--r-- | pkg/tcpip/link/sniffer/sniffer.go | 7 |
1 files changed, 6 insertions, 1 deletions
diff --git a/pkg/tcpip/link/sniffer/sniffer.go b/pkg/tcpip/link/sniffer/sniffer.go index 560477926..b3e8c4b92 100644 --- a/pkg/tcpip/link/sniffer/sniffer.go +++ b/pkg/tcpip/link/sniffer/sniffer.go @@ -205,7 +205,12 @@ func logPacket(prefix string, protocol tcpip.NetworkProtocolNumber, pkt *stack.P // // We don't clone the original packet buffer so that the new packet buffer // does not have any of its headers set. - pkt = stack.NewPacketBuffer(stack.PacketBufferOptions{Data: buffer.NewVectorisedView(pkt.Size(), pkt.Views())}) + // + // We trim the link headers from the cloned buffer as the sniffer doesn't + // handle link headers. + vv := buffer.NewVectorisedView(pkt.Size(), pkt.Views()) + vv.TrimFront(len(pkt.LinkHeader().View())) + pkt = stack.NewPacketBuffer(stack.PacketBufferOptions{Data: vv}) switch protocol { case header.IPv4ProtocolNumber: if ok := parse.IPv4(pkt); !ok { |