Skip to main content

3.9. SEGMENT ARRIVES (Part 1)

SEGMENT ARRIVES​

If the state is CLOSED (i.e., TCB does not exist) then

all data in the incoming segment is discarded. An incoming segment containing a RST is discarded. An incoming segment not containing a RST causes a RST to be sent in response. The acknowledgment and sequence field values are selected to make the reset sequence acceptable to the TCP that sent the offending segment.

If the ACK bit is off, sequence number zero is used,

<SEQ=0><ACK=SEG.SEQ+SEG.LEN><CTL=RST,ACK>

If the ACK bit is on,

<SEQ=SEG.ACK><CTL=RST>

Return.

If the state is LISTEN then

first check for an ACK

Any acknowledgment is bad if it arrives on a connection still in the LISTEN state. An acceptable reset segment should be formed for any arriving ACK-bearing segment, except another RST. The RST should be formatted as follows:

<SEQ=SEG.ACK><CTL=RST>

Return.

An incoming RST should be ignored. Return.

if there was no ACK then check for a SYN

If the SYN bit is set, check the security. If the security/compartment on the incoming segment does not exactly match the security/compartment in the TCB then send a reset and return. If the SEG.PRC is less than the TCB.PRC then send a reset and return. If the SEG.PRC is greater than the TCB.PRC then set TCB.PRC<-SEG.PRC. Now RCV.NXT and RCV.LBB are set to SEG.SEQ+1, IRS is set to SEG.SEQ and any other control or text should be queued for processing later. ISS should be selected and a SYN segment sent of the form:

<SEQ=ISS><ACK=RCV.NXT><CTL=SYN,ACK>

SND.NXT and SND.LBB are set to ISS+1 and SND.UNA to ISS. The connection state should be changed to SYN-RECEIVED. Note that any other incoming control or data (combined with SYN) will be processed in the SYN-RECEIVED state, but processing of SYN and ACK should not be repeated. If the listen was not fully specified (i.e., the foreign socket was not fully specified), then the unspecified fields should be filled in now.

if there was no SYN but there was other text or control

Any other control or text-bearing segment (not containing SYN) must have an ACK and thus would be discarded by the ACK processing. An incoming RST segment could not be valid, since it could not have been sent in response to anything sent by this incarnation of the connection. So you are unlikely to get here, but if you do, drop the segment, and return.

If the state is SYN-SENT then

first check for an ACK

If SEG.ACK =< ISS, or SEG.ACK > SND.NXT, or the security/compartment in the segment does not exactly match the security/compartment in the TCB, or the precedence in the segment is less than the precedence in the TCB, send a reset

<SEQ=SEG.ACK><CTL=RST>

and discard the segment. Return.

If SND.UNA =< SEG.ACK =< SND.NXT and the security/compartment and precedence are acceptable then the ACK is acceptable. SND.UNA should be advanced to equal SEG.ACK, and any segments on the retransmission queue which are thereby acknowledged should be removed.

if the ACK is ok (or there is no ACK), check the RST bit

If the RST bit is set then signal the user "error: connection reset", enter CLOSED state, drop the segment, delete TCB, and return.

if the ACK is ok (or there is no ACK) and it was not a RST, check the SYN bit

If the SYN bit is on and the security/compartment and precedence are acceptable then, RCV.NXT and RCV.LBB are set to SEG.SEQ+1, IRS is set to SEG.SEQ. If SND.UNA > ISS (our SYN has been ACKed), change the connection state to ESTABLISHED, otherwise enter SYN-RECEIVED. In any case, form an ACK segment:

<SEQ=SND.NXT><ACK=RCV.NXT><CTL=ACK>

and send it. Data or controls which were queued for transmission may be included.

If SEG.PRC is greater than TCB.PRC set TCB.PRC<-SEG.PRC.

If there are other controls or text in the segment then continue processing at the fifth step below where the URG bit is checked, otherwise return.