From 94e83c674e656acd60ca0cbfa5b33a2338662e24 Mon Sep 17 00:00:00 2001 From: Lucas Manning Date: Wed, 10 Jan 2024 11:17:02 -0800 Subject: [PATCH] Properly account for all lower level headers when setting GSO limit. Tested on gVNIC VM, PUT 10MB to GCS (3 run mean): ``` --gso=false: 1.05s --gso=true: 0.45s ``` Fixes #9816 PiperOrigin-RevId: 597304748 --- pkg/tcpip/header/eth.go | 3 +++ pkg/tcpip/header/tcp.go | 5 +++++ pkg/tcpip/transport/tcp/snd.go | 2 +- 3 files changed, 9 insertions(+), 1 deletion(-) diff --git a/pkg/tcpip/header/eth.go b/pkg/tcpip/header/eth.go index c29d930bf..d45757308 100644 --- a/pkg/tcpip/header/eth.go +++ b/pkg/tcpip/header/eth.go @@ -46,6 +46,9 @@ const ( // EthernetMinimumSize is the minimum size of a valid ethernet frame. EthernetMinimumSize = 14 + // EthernetMaximumSize is the maximum size of a valid ethernet frame. + EthernetMaximumSize = 18 + // EthernetAddressSize is the size, in bytes, of an ethernet address. EthernetAddressSize = 6 diff --git a/pkg/tcpip/header/tcp.go b/pkg/tcpip/header/tcp.go index 709a43d1e..cb9257ad6 100644 --- a/pkg/tcpip/header/tcp.go +++ b/pkg/tcpip/header/tcp.go @@ -216,6 +216,11 @@ const ( // TCPHeaderMaximumSize is the maximum header size of a TCP packet. TCPHeaderMaximumSize = TCPMinimumSize + TCPOptionsMaximumSize + // TCPTotalHeaderMaximumSize is the maximum size of headers from all layers in + // a TCP packet. This will need to be updated if we decide to support more + // layer 2 protocols or features like IP tunneling. + TCPTotalHeaderMaximumSize = TCPHeaderMaximumSize + IPv4MaximumHeaderSize + EthernetMaximumSize + // TCPProtocolNumber is TCP's transport protocol number. TCPProtocolNumber tcpip.TransportProtocolNumber = 6 diff --git a/pkg/tcpip/transport/tcp/snd.go b/pkg/tcpip/transport/tcp/snd.go index 891c1bed9..78abc07d4 100644 --- a/pkg/tcpip/transport/tcp/snd.go +++ b/pkg/tcpip/transport/tcp/snd.go @@ -953,7 +953,7 @@ func (s *sender) postXmit(dataSent bool, shouldScheduleProbe bool) { func (s *sender) sendData() { limit := s.MaxPayloadSize if s.gso { - limit = int(s.ep.gso.MaxSize - header.TCPHeaderMaximumSize) + limit = int(s.ep.gso.MaxSize - header.TCPTotalHeaderMaximumSize - 1) } end := s.SndUna.Add(s.SndWnd)