Resynchronization, Closing and Connection State
4.3.4 RESYNCHRONIZING A CONNECTION
Details of resynchronization have not yet been specified since the need for this should be infrequent in the initial testing stages.
4.3.5 CLOSING A CONNECTION
There are essentially three cases:
a) The user initiates by telling the TCP to CLOSE the connection
b) The remote TCP initiates by sending a FIN control signal
c) Both users CLOSE simultaneously
Two bits are used to maintain control over the closing of a connection: these are called the "FIN sent" bit [F] and the "USER Closed" bit, [C] respectively. The control procedure uses these two bits to assure that the connection is properly closed.
Case 1: Local user initiates the close
In this case, both the F and C bits are initially zero, but the C bit is set immediately upon receipt of the user call "CLOSE." When the FIN is sent out by the TCP, the F bit is set. All pending RECEIVES are terminated and the user is told that they have been prematurely terminated ("connection closing"} without data. Similarly, any pending SENDS are terminated with the same response, "connection closing."
Several responses may arrive as the result of sending a FIN. The one which is generally expected is a matching FIN. When this is received, the TCB CAN BE ELIMINATED. If a "connection does not exist at foreign TCP" message comes in response to the FIN, then the TCB can likewise be eliminated. If no response is forthcoming, or if "Foreign TCP inaccessible" arrives then the resolution is moot. One might simply timeout and discard the TCB. Since the local user wants to CLOSE anyway, this is probably satisfactory, although it will leave a potential "half-open" connection at the other side. We deal with half open connections in section 4.3.3.
When the acknowledging FIN arrives after the connection state bits are set (F=1, C=1), then the TCB can be deleted.
Case 2: TCP receives a FIN from the network
First of all, a FIN must have a sequence number which lies in the valid receive window. If not, it is discarded and the left window edge is sent as acknowledgment. If the FIN can be processed, it is handled (possibly out of order, since it is taken as an imperative to shut down the connection). All pending RECEIVES and SENDS are responded to by showing that they were terminated by the other side's close request (i.e. "connection closing"). The user is also told by an unsolicited event or signal that the connection has been closed (in some systems, the user might have to request STATUS to get this information). Finally, the TCP sends FIN in response.
Thus, because a FIN arrived, a FIN is sent back, so the F bit is set. However, the TCB stays around until the local user does a CLOSE in acknowledgment of the unsolicited signal that the connection has been closed by the other side. Thus, the C bit remains unset until this happens. If the C and F bits go from (F=1 C=O) to (F=l, C=1), then the connection is closed and the TCB can be removed.
Case 3: both users close simultaneously
If this happens, both connections will be in the (F=1, C=1) state. When the FINs arrive, the connections w11i be shut down. If one FIN fails to arrive, we have two choices. One is to insist on acknowledgments for FINs, in which case the missing one will be retransmitted. Another is merely to permit the half-open connection to remain (we prefer this solution}. It can timeout independently and go away after a while. If an attempt is made to reestablish the connection, the initiator will discover the existence of the open connection since an "inappropriate SYN received" message will be sent by the TCP which holds the "half- open" connection. The receiver of this message can tell the other TCP to reset the connection. We cannot permit the holder of the half-open connection to reset automatically on receipt of the SYN since its receipt is not necessarily prima facie evidence of a half open connection. (The SYN could be a delayed duplicate.)
4.3.6. CONNECTION STATE and its relation to USER and INCOMING CONTROL REQUESTS
In order to formalize the action taken by the TCP when it receives commands from the User, or Control information from the network, we define a connection to be in one of 7 states at any instant. These are known as the TCB Major States. Each Major State is simply a convenient name for a particular setting or group of settings of the state bits, as follows:
S1 S2 R U F C # name
- - - - - - 0 no TCB
0 0 0 0/1 0 0 1 unsync
1 0 0 0 0 0 2 SYN sent
1 0 1 0/1 0 0 3 SYN received
1 1 1 0 0 0 4 established
1 0/1 1 0/1 1 1 5 FIN wait
1 1 1 0 1 0 6 FIN received
The connection moves from state to state as shown below. The transition from one state to another will be represented as
[X, Y]<cause><action>
which means that there is a transition from state X to state Y owing to <cause>. The action taken by the TCP is specified as <action>. We use this notation to give the important state transitions, often simplifying the cause and action fields to take into account a number of situations. Figure 1 illustrates these transitions in traditional state diagram form. Section 4.4.6 and section 4.4.7 fully specify the effect of all User commands and Control information arriving from the network.
[0,l] <OPEN> <create TCB>
[1,2] <SEND,INTERRUPT, or collision timeout> <send SYN>
[1,3] <SYN arrives> <send SYN,ACK>
[1,0] <CLOSE> <remove TCB>
[2,1] <SYN arrives (collision)> <set timeout, forget SYNs>
[2,0] <CLOSE> <remove TCB>
[2,4] <appropriate SYN,ACK arrives> <send ACK>
[3,4] <appropriate ACK arrives> <none>
[3,1] <error arrives or timeout> <(forget SYN)>
[3,5] <CLOSE> <send FIN>
[4,5] <CLOSE> <send FIN>
[4,6] <appropriate FIN arrives> <send FIN, inform user>
[5,0] <FIN or error arrives, or timeout> <remove TCB>
[6,0] <CLOSE> <remove TCB>