Skip to main content

5.3. State Behavior (Part 1: Procedures A - E)

This section discusses in detail the behavior of each state in response to the arrival of a packet. In what follows a packet is not considered to have arrived until it has passed a number of tests (see the chapter entitled: Packet Reception).

The method chosen to describe state behavior is tabular. Each state is listed opposite a sequence of named procedures to execute whenever a packet has arrived.

STATE                BEHAVIOR
=============+========================
LISTEN | A
-------------+------------------------
SYN-SENT | B
-------------+------------------------
SYN-RECEIVED | C1 D1 E F1 H1
-------------+------------------------
ESTABLISHED | C2 D2 E F2 H2 I1
-------------+------------------------
FIN-WAIT | C2 D2 E F3 H3
-------------+------------------------
LAST-ACK | C2 D3 E F3 H4
-------------+------------------------
CLOSING | C2 D3 E F3 H5
-------------+------------------------
TIME-WAIT | D3 E F3 H6
-------------+------------------------
CLOSED | G
-------------+------------------------

For example, in the ESTABLISHED state the arrival of a packet causes procedure C2 to be executed, then D2, then E, F2, H2, and finally I1. Any procedure may terminate the processing which occurs or cause a state change. Note that these procedures are executed in sequence, first C2, then D2, etc. The time ordering cannot be mixed.

The particular actions associated with each procedure are now described.

A​

This procedure details the behavior of the LISTEN state. First check the packet for the RST flag. If it is set then packet is discarded and ignored, return and continue the processing associated with this state.

We assume now that the RST flag was not set. Check the packet for the ACK flag. If it is set we have an illegal condition since no connection has yet been opened. Send a RST packet with the correct response SN value:

<SN=received AN><CTL=RST>

Return to the current state without any further processing.

We assume now that neither the RST nor the ACK flags were set. Check the packet for a SYN flag. If it is set then an attempt is being made to open a connection. Create a TCB for this connection. The sender has placed its MDL in the LENGTH field, also specified is the sender's initial SN value. Retrieve and place them into the TCB. Note that the presence of the SO flag is ignored since it has no meaning when either of the SYN, RST, or FIN flags are set.

Send a SYN packet which acknowledges the SYN received. Choose the initial SN value and the MDL for this end of the connection:

<SN=0><AN=received SN+1 modulo 2><CTL=SYN, ACK><LENGTH=MDL>

and go to the SYN-RECEIVED state without any further processing.

Any packet not satisfying the above tests is discarded and ignored. Return to the current state without any further processing.

B​

This procedure represents the behavior of the SYN-SENT state and is entered when this end of the connection decides to execute an active OPEN.

First, check the packet for the ACK flag. If the ACK flag is set then check to see if the AN value was as expected. If it was continue below. Otherwise the AN value was unexpected. If the RST flag was set then discard the packet and return to the current state without any further processing, else send a reset:

<SN=received AN><CTL=RST>

Discard the packet and return to the current state without any further processing.

At this point either the ACK flag was set and the AN value was as expected or ACK was not set. Second, check the RST flag. If the RST flag is set there are two cases:

  1. If the ACK flag is set then discard the packet, flush the retransmission queue, inform the user "Error: Connection refused", delete the TCB, and go to the CLOSED state without any further processing.

  2. If the ACK flag was not set then discard the packet and return to this state without any further processing.

At this point we assume the packet contained an ACK which was Ok, or there was no ACK, and there was no RST. Now check the packet for the SYN flag. If the ACK flag was set then our SYN has been acknowledged. Store MDL received in the TCB. At this point we are technically in the ESTABLISHED state. Send an acknowledgment packet and any initial data which is queued to send:

<SN=received AN><AN=received SN+1 modulo 2><CTL=ACK><DATA>

Go to the ESTABLISHED state without any further processing.

If the SYN flag was set but the ACK was not set then the other end of the connection has executed an active open also. Acknowledge the SYN, choose your MDL, and send:

<SN=0><AN=received SN+1 modulo 2><CTL=SYN, ACK><LENGTH=MDL>

Go to the SYN-RECEIVED state without any further processing.

Any packet not satisfying the above tests is discarded and ignored. Return to the current state without any further processing.

C1​

Examine the received SN field value. If the SN value was expected then return and continue the processing associated with this state.

We now assume the SN value was not what was expected.

If either RST or FIN were set discard the packet and return to the current state without any further processing.

If neither RST nor FIN flags were set it is assumed that this packet is a duplicate of one already received. Send an ACK back:

<SN=received AN><AN=received SN+1 modulo 2><CTL=ACK>

Discard the duplicate packet and return to the current state without any further processing.

C2​

Examine the received SN field value. If the SN value was expected then return and continue the processing associated with this state.

We now assume the SN value was not what was expected.

If either RST or FIN were set discard the packet and return to the current state without any further processing.

If SYN was set we assume that the other end crashed and has attempted to open a new connection. We respond by sending a legal reset:

<SN=received AN><AN=received SN+1 modulo 2><CTL=RST, ACK>

This will cause the other end, currently in the SYN-SENT state, to close. Flush the retransmission queue, inform the user "Error: Connection reset", discard the packet, delete the TCB, and go to the CLOSED state without any further processing.

If neither RST, FIN, nor SYN flags were set it is assumed that this packet is a duplicate of one already received. Send an ACK back:

<SN=received AN><AN=received SN+1 modulo 2><CTL=ACK>

Discard the duplicate packet and return to the current state without any further processing.

D1​

The packet is examined for a RST flag. If RST is not set then return and continue the processing associated with this state.

RST is now assumed to have been set. If the connection was originally initiated from the LISTEN state (it was passively opened) then flush the retransmission queue, discard the packet, and go to the LISTEN state without any further processing.

If instead the connection was initiated actively (came from the SYN-SENT state) then flush the retransmission queue, inform the user "Error: Connection refused", discard the packet, delete the TCB, and go to the CLOSED state without any further processing.

D2​

The packet is examined for a RST flag. If RST is not set then return and continue the processing associated with this state.

RST is now assumed to have been set. Any data remaining to be sent is flushed. The retransmission queue is flushed, the user is informed "Error: Connection reset.", discard the packet, delete the TCB, and go to the CLOSED state without any further processing.

D3​

The packet is examined for a RST flag. If RST is not set then return and continue the processing associated with this state.

RST is now assumed to have been set. Discard the packet, delete the TCB, and go to the CLOSED state without any further processing.

E​

Check the presence of the SYN flag. If the SYN flag is not set then return and continue the processing associated with this state.

We now assume that the SYN flag was set. The presence of a SYN here is an error. Flush the retransmission queue, send a legal RST packet.

If the ACK flag was set then send:

<SN=received AN><CTL=RST>

If the ACK flag was not set then send:

<SN=0><CTL=RST>

The user should receive the message "Error: Connection reset.", then delete the TCB and go to the CLOSED state without any further processing.