From eb7b1903e00eda9248da59991d80594590c9aab6 Mon Sep 17 00:00:00 2001 From: gVisor bot Date: Thu, 16 Apr 2020 12:21:06 -0700 Subject: Test TCP behavior when receiving unacceptable segment in CLOSE_WAIT TCP, in CLOSE-WAIT state, MUST return ACK with proper SEQ and ACK numbers after recv a seg with OTW SEQ or unacc ACK number, and remain in same state. If the connection is in a synchronized state, any unacceptable segment (out of window sequence number or unacceptable acknowledgment number) must elicit only an empty acknowledgment segment containing the current send-sequence number and an acknowledgment indicating the next sequence number expected to be received, and the connection remains in the same state. PiperOrigin-RevId: 306897984 --- test/packetimpact/testbench/connections.go | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) (limited to 'test/packetimpact/testbench/connections.go') diff --git a/test/packetimpact/testbench/connections.go b/test/packetimpact/testbench/connections.go index be62d051d..c1b3c4380 100644 --- a/test/packetimpact/testbench/connections.go +++ b/test/packetimpact/testbench/connections.go @@ -189,6 +189,7 @@ type tcpState struct { localSeqNum, remoteSeqNum *seqnum.Value synAck *TCP portPickerFD int + finSent bool } var _ layerState = (*tcpState)(nil) @@ -210,6 +211,7 @@ func newTCPState(out, in TCP) (*tcpState, error) { in: TCP{DstPort: &localPort}, localSeqNum: SeqNumValue(seqnum.Value(rand.Uint32())), portPickerFD: portPickerFD, + finSent: false, } if err := s.out.merge(&out); err != nil { return nil, err @@ -254,12 +256,18 @@ func (s *tcpState) sent(sent Layer) error { if !ok { return fmt.Errorf("can't update tcpState with %T Layer", sent) } - for current := tcp.next(); current != nil; current = current.next() { - s.localSeqNum.UpdateForward(seqnum.Size(current.length())) + if !s.finSent { + // update localSeqNum by the payload only when FIN is not yet sent by us + for current := tcp.next(); current != nil; current = current.next() { + s.localSeqNum.UpdateForward(seqnum.Size(current.length())) + } } if tcp.Flags != nil && *tcp.Flags&(header.TCPFlagSyn|header.TCPFlagFin) != 0 { s.localSeqNum.UpdateForward(1) } + if *tcp.Flags&(header.TCPFlagFin) != 0 { + s.finSent = true + } return nil } @@ -590,7 +598,7 @@ func (conn *TCPIPv4) RemoteSeqNum() *seqnum.Value { return conn.state().remoteSeqNum } -// LocalSeqNum returns the next expected sequence number from the DUT. +// LocalSeqNum returns the next sequence number to send from the testbench. func (conn *TCPIPv4) LocalSeqNum() *seqnum.Value { return conn.state().localSeqNum } -- cgit v1.2.3