Skip to content

Commit 49bfb48

Browse files
konstantin-s-bogomgvisor-bot
authored andcommitted
Account for endpoint header size when calculating Route MTU.
If r.mtu has been set, as it is after #11857, we skip calculating the proper MTU via endpoint.MTU and use r.mtu instead. However nothing in the callstack from tcpip/stack/stack.go:FindRoute to setting r.mtu actually adjusts the size to be able to hold the endpoint header. Hence we need to adjust it. PiperOrigin-RevId: 843416148
1 parent f77ef69 commit 49bfb48

File tree

6 files changed

+30
-0
lines changed

6 files changed

+30
-0
lines changed

pkg/tcpip/network/arp/arp.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,11 @@ func (e *endpoint) MTU() uint32 {
128128
return lmtu - uint32(e.MaxHeaderLength())
129129
}
130130

131+
// EndpointHeaderSize returns the size necessary for the ARP header.
132+
func (e *endpoint) EndpointHeaderSize() uint32 {
133+
return header.ARPSize
134+
}
135+
131136
func (e *endpoint) MaxHeaderLength() uint16 {
132137
return e.nic.MaxHeaderLength() + header.ARPSize
133138
}

pkg/tcpip/network/ipv4/ipv4.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -426,6 +426,11 @@ func (e *endpoint) MTU() uint32 {
426426
return networkMTU
427427
}
428428

429+
// EndpointHeaderSize returns the size necessary for the IPv4 header.
430+
func (e *endpoint) EndpointHeaderSize() uint32 {
431+
return header.IPv4MinimumSize
432+
}
433+
429434
// MaxHeaderLength returns the maximum length needed by ipv4 headers (and
430435
// underlying protocols).
431436
func (e *endpoint) MaxHeaderLength() uint16 {

pkg/tcpip/network/ipv6/ipv6.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -728,6 +728,11 @@ func (e *endpoint) MTU() uint32 {
728728
return networkMTU
729729
}
730730

731+
// EndpointHeaderSize returns the size necessary for the IPv6 header.
732+
func (e *endpoint) EndpointHeaderSize() uint32 {
733+
return header.IPv6MinimumSize
734+
}
735+
731736
// MaxHeaderLength returns the maximum length needed by ipv6 headers (and
732737
// underlying protocols).
733738
func (e *endpoint) MaxHeaderLength() uint16 {

pkg/tcpip/stack/registration.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -872,6 +872,9 @@ type NetworkEndpoint interface {
872872
// minus the network endpoint max header length.
873873
MTU() uint32
874874

875+
// EndpointHeaderSize returns the size of this endpoint header.
876+
EndpointHeaderSize() uint32
877+
875878
// MaxHeaderLength returns the maximum size the network (and lower
876879
// level layers combined) headers can have. Higher levels use this
877880
// information to reserve space in the front of the packets they're

pkg/tcpip/stack/route.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,14 @@ func makeRoute(netProto tcpip.NetworkProtocolNumber, gateway, localAddr, remoteA
245245
}
246246

247247
func makeRouteInner(netProto tcpip.NetworkProtocolNumber, localAddr, remoteAddr tcpip.Address, outgoingNIC, localAddressNIC *nic, localAddressEndpoint AssignableAddressEndpoint, loop PacketLooping, mtu uint32) *Route {
248+
if mtu != 0 {
249+
adjusted := mtu - outgoingNIC.getNetworkEndpoint(netProto).EndpointHeaderSize()
250+
if adjusted > mtu {
251+
mtu = 0
252+
} else {
253+
mtu = adjusted
254+
}
255+
}
248256
r := &Route{
249257
routeInfo: routeInfo{
250258
NetProto: netProto,

pkg/tcpip/stack/stack_test.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,10 @@ func (f *fakeNetworkEndpoint) HandlePacket(pkt *stack.PacketBuffer) {
169169
f.dispatcher.DeliverTransportPacket(transProtoNum, pkt)
170170
}
171171

172+
func (f *fakeNetworkEndpoint) EndpointHeaderSize() uint32 {
173+
return fakeNetHeaderLen
174+
}
175+
172176
func (f *fakeNetworkEndpoint) MaxHeaderLength() uint16 {
173177
return f.nic.MaxHeaderLength() + fakeNetHeaderLen
174178
}

0 commit comments

Comments
 (0)