summaryrefslogtreecommitdiffhomepage
path: root/pkg
diff options
context:
space:
mode:
authorKevin Krakauer <krakauer@google.com>2020-05-06 13:36:48 -0700
committergVisor bot <gvisor-bot@google.com>2020-05-06 13:38:36 -0700
commitb08222cf3a80a57e77ac4af7a410f188ba01e0f4 (patch)
tree5abbbda1333fc0ef675540e35ff066656dc8d8f3 /pkg
parent4631de620a2534f6f89f6252269f650e78d11b99 (diff)
sniffer: fix accidental logging of good packets as bad
We need to check vv.Size() instead of len(tcp), as tcp will always be 20 bytes long. PiperOrigin-RevId: 310218351
Diffstat (limited to 'pkg')
-rw-r--r--pkg/tcpip/link/sniffer/sniffer.go8
1 files changed, 4 insertions, 4 deletions
diff --git a/pkg/tcpip/link/sniffer/sniffer.go b/pkg/tcpip/link/sniffer/sniffer.go
index 0799c8f4d..da1c520ae 100644
--- a/pkg/tcpip/link/sniffer/sniffer.go
+++ b/pkg/tcpip/link/sniffer/sniffer.go
@@ -391,7 +391,7 @@ func logPacket(prefix string, protocol tcpip.NetworkProtocolNumber, pkt *stack.P
break
}
udp := header.UDP(hdr)
- if fragmentOffset == 0 && len(udp) >= header.UDPMinimumSize {
+ if fragmentOffset == 0 {
srcPort = udp.SourcePort()
dstPort = udp.DestinationPort()
details = fmt.Sprintf("xsum: 0x%x", udp.Checksum())
@@ -405,14 +405,14 @@ func logPacket(prefix string, protocol tcpip.NetworkProtocolNumber, pkt *stack.P
break
}
tcp := header.TCP(hdr)
- if fragmentOffset == 0 && len(tcp) >= header.TCPMinimumSize {
+ if fragmentOffset == 0 {
offset := int(tcp.DataOffset())
if offset < header.TCPMinimumSize {
details += fmt.Sprintf("invalid packet: tcp data offset too small %d", offset)
break
}
- if offset > len(tcp) && !moreFragments {
- details += fmt.Sprintf("invalid packet: tcp data offset %d larger than packet buffer length %d", offset, len(tcp))
+ if offset > vv.Size() && !moreFragments {
+ details += fmt.Sprintf("invalid packet: tcp data offset %d larger than packet buffer length %d", offset, vv.Size())
break
}