3.9. SEGMENT ARRIVES (Part 2)
Otherwise,
first check sequence number
SYN-RECEIVED STATE
ESTABLISHED STATE
FIN-WAIT-1 STATE
FIN-WAIT-2 STATE
TIME-WAIT STATE
CLOSE-WAIT STATE
CLOSING STATE
Segments are processed in sequence. Initial tests on arrival are used to discard old duplicates, but further processing is done in SEG.SEQ order. If a segment's contents straddle the boundary between old and new, only the new parts should be processed.
There are four cases for the acceptability test for an incoming segment:
Segment Receive Test
Length Window
------- ------- -------------------------------------------
0 0 SEG.SEQ = RCV.NXT
0 >0 RCV.NXT =< SEG.SEQ < RCV.NXT+RCV.WND
>0 0 not acceptable
>0 >0 RCV.NXT < SEG.SEQ+SEG.LEN =< RCV.NXT+RCV.WND
Note that the test above guarantees that the last sequence number used by the segment lies in the receive-window. If the RCV.WND is zero, no segments will be acceptable, but special allowance should be made to accept valid ACKs, URGs and RSTs.
If an incoming segment is not acceptable, an acknowledgment should be sent in reply:
<SEQ=SND.NXT><ACK=RCV.NXT><CTL=ACK>
If the incoming segment is unacceptable, drop it and return.
second check security and precedence
If the security/compartment and precedence in the segment do not exactly match the security/compartment and precedence in the TCB then form a reset and return.
Note this check is placed following the sequence check to prevent a segment from an old connection between these parts with a different security or precedence from causing an abort of the current connection.
third check the ACK field,
SYN-RECEIVED STATE
If the RST bit is off and SND.UNA < SEG.ACK =< SND.NXT then set SND.UNA <- SEG.ACK, remove any acknowledged segments from the retransmission queue, and enter ESTABLISHED state.
If the segment acknowledgment is not acceptable, form a reset segment,
<SEQ=SEG.ACK><CTL=RST>
and send it, unless the incoming segment is an RST (or there is no ACK), in which case, it should be discarded, then return.
ESTABLISHED STATE
If SND.UNA < SEG.ACK =< SND.NXT then, set SND.UNA <- SEG.ACK. Any segments on the retransmission queue which are thereby entirely acknowledged are removed. Users should receive positive acknowledgments for buffers which have been SENT and fully acknowledged (i.e., SEND buffer should be returned with "ok" response). If the ACK is a duplicate, it can be ignored.
If the segment passes the sequence number and acknowledgment number tests, the send window should be updated. If SND.WL =< SEG.SEQ, set SND.WND <- SEG.WND and set SND.WL <- SEG.SEQ.
If the remote buffer size is not one, then the end-of-letter/buffer-size adjustment to sequence numbers may have an effect on the next expected sequence number to be acknowledged. It is possible that the remote TCP will acknowledge with a SEG.ACK equal to a sequence number of an octet that was skipped over at the end of a letter. This a mild error on the remote TCPs part, but not cause for alarm.
FIN-WAIT-1 STATE
FIN-WAIT-2 STATE
In addition to the processing for the ESTABLISHED state, if the retransmission queue is empty, the user's CLOSE can be acknowledged ("ok") but do not delete the TCB.
TIME-WAIT STATE
The only thing that can arrive in this state is a retransmission of the remote FIN. Acknowledge it, and restart the 2 MSL timeout.
CLOSE-WAIT STATE
Do the same processing as for the ESTABLISHED state.
CLOSING STATE
If the ACK acknowledges our FIN then delete the TCB (enter the CLOSED state), otherwise ignore the segment.
fourth check the RST bit,
SYN-RECEIVED STATE
If the RST bit is set then, if the segment has passed sequence and acknowledgment tests, it is valid. If this connection was initiated with a passive OPEN (i.e., came from the LISTEN state), then return this connection to LISTEN state. The user need not be informed. If this connection was initiated with an active OPEN (i.e., came from SYN-SENT state) then the connection was refused, signal the user "connection refused". In either case, all segments on the retransmission queue should be removed.
ESTABLISHED
FIN-WAIT-1
FIN-WAIT-2
CLOSE-WAIT
CLOSING STATE
If the RST bit is set then, any outstanding RECEIVEs and SEND should receive "reset" responses. All segment queues should be flushed. Users should also receive an unsolicited general "connection reset" signal. Enter the CLOSED state, delete the TCB, and return.
TIME-WAIT
Enter the CLOSED state, delete the TCB, and return.