summaryrefslogtreecommitdiffhomepage
path: root/pkg/tcpip/network/ipv4
diff options
context:
space:
mode:
authorJulian Elischer <jrelis@google.com>2021-01-25 20:48:20 -0800
committergVisor bot <gvisor-bot@google.com>2021-01-25 20:50:02 -0800
commit3731ebb3fe69dc2d7fb6d6602845a378c530379b (patch)
tree10390371e4dc7825ed9d7aac9b0e2482a0c49a7a /pkg/tcpip/network/ipv4
parent39db3b93554ea74611602ad4c20dfa5c08e748f2 (diff)
Adjust included data size on icmp errors
The RFC for icmpv6 specifies that an errant packet should be included in the returned ICMP packet, and that it should include up to the amount needed to fill the minimum MTU (1280 bytes) if possible. The current code included the Link header in that calculation but the RFC is referring to the IP MTU not the link MTU. Some conformance tests check this and report an error agains the stack for this. The full header length shoudl however continue to be used when allocating header space. Make the same change for IPv4 for consistency. Add a test for icmp payload sizing. Test that the included data in an ICMP error packet conforms to the requirements of RFC 972, RFC 4443 section 2.4 and RFC 1812 Section 4.3.2.3. Fixes #5311 PiperOrigin-RevId: 353790203
Diffstat (limited to 'pkg/tcpip/network/ipv4')
-rw-r--r--pkg/tcpip/network/ipv4/icmp.go12
1 files changed, 6 insertions, 6 deletions
diff --git a/pkg/tcpip/network/ipv4/icmp.go b/pkg/tcpip/network/ipv4/icmp.go
index 284ad89cf..6bb97c46a 100644
--- a/pkg/tcpip/network/ipv4/icmp.go
+++ b/pkg/tcpip/network/ipv4/icmp.go
@@ -436,13 +436,13 @@ func (p *protocol) returnError(reason icmpReason, pkt *stack.PacketBuffer) *tcpi
// systems implement the RFC 1812 definition and not the original
// requirement. We treat 8 bytes as the minimum but will try send more.
mtu := int(route.MTU())
- if mtu > header.IPv4MinimumProcessableDatagramSize {
- mtu = header.IPv4MinimumProcessableDatagramSize
+ const maxIPData = header.IPv4MinimumProcessableDatagramSize - header.IPv4MinimumSize
+ if mtu > maxIPData {
+ mtu = maxIPData
}
- headerLen := int(route.MaxHeaderLength()) + header.ICMPv4MinimumSize
- available := int(mtu) - headerLen
+ available := mtu - header.ICMPv4MinimumSize
- if available < header.IPv4MinimumSize+header.ICMPv4MinimumErrorPayloadSize {
+ if available < len(origIPHdr)+header.ICMPv4MinimumErrorPayloadSize {
return nil
}
@@ -465,7 +465,7 @@ func (p *protocol) returnError(reason icmpReason, pkt *stack.PacketBuffer) *tcpi
payload.CapLength(payloadLen)
icmpPkt := stack.NewPacketBuffer(stack.PacketBufferOptions{
- ReserveHeaderBytes: headerLen,
+ ReserveHeaderBytes: int(route.MaxHeaderLength()) + header.ICMPv4MinimumSize,
Data: payload,
})