Skip to content

Commit 028e045

Browse files
hbhaskergvisor-bot
authored andcommitted
Fix 1 zero window advertisement bug and a TCP test flake.
In TestReceiveBufferAutoTuning we now send a keep-alive packet to measure the current window rather than a 1 byte segment as the returned window value in the latter case is reduced due to the 1 byte segment now being held in the receive buffer and can cause the test to flake if the segment overheads were to change. In getSendParams in rcv.go we were advertising a non-zero window even if available window space was zero after we received the previous segment. In such a case newWnd and curWnd will be the same and we end up advertising a tiny but non-zero window and this can cause the next segment to be dropped. PiperOrigin-RevId: 334314070
1 parent ba44298 commit 028e045

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

pkg/tcpip/transport/tcp/rcv.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,13 @@ func (r *receiver) acceptable(segSeq seqnum.Value, segLen seqnum.Size) bool {
8888
// segments to send.
8989
func (r *receiver) getSendParams() (rcvNxt seqnum.Value, rcvWnd seqnum.Size) {
9090
avail := wndFromSpace(r.ep.receiveBufferAvailable())
91+
if avail == 0 {
92+
// We have no space available to accept any data, move to zero window
93+
// state.
94+
r.rcvWnd = 0
95+
return r.rcvNxt, 0
96+
}
97+
9198
acc := r.rcvNxt.Add(seqnum.Size(avail))
9299
newWnd := r.rcvNxt.Size(acc)
93100
curWnd := r.rcvNxt.Size(r.rcvAcc)

pkg/tcpip/transport/tcp/tcp_test.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5435,8 +5435,8 @@ func TestListenNoAcceptNonUnicastV4(t *testing.T) {
54355435
// TestListenNoAcceptMulticastBroadcastV6 makes sure that TCP segments with a
54365436
// non unicast IPv6 address are not accepted.
54375437
func TestListenNoAcceptNonUnicastV6(t *testing.T) {
5438-
multicastAddr := tcpip.Address("\xff\x0e\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01\x01")
5439-
otherMulticastAddr := tcpip.Address("\xff\x0e\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01\x02")
5438+
multicastAddr := tcpip.Address("\xff\x0e\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01\x01")
5439+
otherMulticastAddr := tcpip.Address("\xff\x0e\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01\x02")
54405440

54415441
tests := []struct {
54425442
name string
@@ -6182,7 +6182,9 @@ func TestReceiveBufferAutoTuning(t *testing.T) {
61826182

61836183
rawEP := c.CreateConnectedWithOptions(header.TCPSynOptions{TS: true, WS: 4})
61846184
tsVal := uint32(rawEP.TSVal)
6185-
rawEP.SendPacketWithTS([]byte{1}, tsVal)
6185+
rawEP.NextSeqNum--
6186+
rawEP.SendPacketWithTS(nil, tsVal)
6187+
rawEP.NextSeqNum++
61866188
pkt := rawEP.VerifyAndReturnACKWithTS(tsVal)
61876189
curRcvWnd := int(header.TCP(header.IPv4(pkt).Payload()).WindowSize()) << c.WindowScale
61886190
scaleRcvWnd := func(rcvWnd int) uint16 {

0 commit comments

Comments
 (0)