Skip to main content

Appendix: Protection against Old Duplicates in TCP

During the development of TCP, a great deal of effort was devoted to the problem of protecting a TCP connection from segments left from earlier incarnations of the same connection. Several different mechanisms were proposed for this purpose [Tomlinson74] [Dalal74] [Cerf76] [Garlick77].

The connection parameters that are required in this discussion are:

Tc = Connection duration in seconds.

Nc = Total number of bytes sent on connection.

B = Effective bandwidth of connection = Nc/Tc.

Tomlinson proposed a scheme with two parts: a clock-driven selection of ISN (Initial Sequence Number) for a connection, and a resynchronization procedure [Tomlinson74]. The clock-driven scheme chooses:

      ISN = (integer(R*t)) mod 2**32                 [2]

where t is the current time relative to an arbitrary origin, and R is a constant. R was intended to be chosen so that ISN will advance faster than sequence numbers will be used up on the connection. However, at high speeds this will not be true; the consequences of this will be discussed below.

The clock-driven choice of ISN in formula [2] guarantees freedom from old duplicates matching a reopened connection if the original connection was "short-lived" and "slow". By "short-lived", we mean a connection that stayed open for a time Tc less than the time to cycle the ISN, i.e., Tc < 2**32/R seconds. By "slow", we mean that the effective transfer rate B is less than R.

This is illustrated in Figure 1, where sequence numbers are plotted against time. The asterisks show the ISN lines from formula [2], while the circles represent the trajectories of several short-lived incarnations of the same connection, each terminating at the "x".

Note: allowing rapid reuse of connections was believed to be an important goal during the early TCP development. This requirement was driven by the hope that TCP would serve as a basis for user-level transaction protocols as well as connection-oriented protocols. The paradigm discussed was the "Christmas Tree" or "Kamikazee" segment that contained SYN and FIN bits as well as data. Enthusiasm for this was somewhat dampened when it was observed that the 3-way SYN handshake and the FIN handshake mean that 5 packets are required for a minimum exchange. Furthermore, the TIME-WAIT state delay implies that the same connection really cannot be reopened immediately. No further work has been done in this area, although existing applications (especially SMTP) often generate very short TCP sessions. The reuse problem is generally avoided by using a different port pair for each connection.

        |- 2**32       ISN             ISN
| * *
| * *
| * *
| *x *
| o *
^ | * *
| | * x *
| * o *
S | *o *
e | o *
q | * *
| * *
# | * x *
| *o *
|o_______________*____________
^ Time -->
4.55hrs
     Figure 1.  Clock-Driven ISN  avoiding duplication on
short-Lived, slow connections.

However, clock-driven ISN selection does not protect against old duplicate packets for a long-lived or fast connection: the connection may close (or crash) just as the ISN has cycled around and reached the same value again. If the connection is then reopened, a datagram still in transit from the old connection may fall into the current window. This is illustrated by Figure 2 for a slow, long-lived connection, and by Figures 3 and 4 for fast connections. In each case, the point "x" marks the place at which the original connection closes or crashes. The arrow in Figure 2 illustrates an old duplicate segment. Figure 3 shows a connection whose total byte count Nc < 232, while Figure 4 concerns Nc >= 232.

To prevent the duplication illustrated in Figure 2, Tomlinson proposed to "resynchronize" the connection sequence numbers if they came within an MSL of the ISN. Resynchronization might take the form of a delay (point "y") or the choice of a new sequence number (point "z").

        |- 2**32       ISN               ISN
| * *
| * *
| * *
| * *
| * *
^ | * *
| | * *
| * *
S | * *
e | * x* y
q | * o *
| * o *z
# | *o *
| * *
|*_________________*____________
^ Time -->
4.55hrs
        Figure 2.  Resynchronization to Avoid Duplication
on Slow, Long-Lived Connection
        |- 2**32       ISN               ISN
| * *
| x o * *
| * *
| o-->o* *
| * *
^ | o o *
| | * *
| o * *
S | * *
e | o * *
q | * *
| o* *
# | * *
| o *
|*_________________*____________
^ Time -->
4.55hrs
     Figure 3.  Duplication on Fast Connection: Nc < 2**32 bytes
        |- 2**32       ISN               ISN
| o * *
| x * *
| * *
| o * *
| o *
^ | * *
| | o * *
| * o *
S | * *
e | o * *
q | * o *
| * *
# | o *
| * o *
|*_________________*____________
^ Time -->
4.55hrs
     Figure 4.  Duplication on Fast Connection: Nc > 2**32 bytes

In summary, Figures 1-4 illustrated four possible failure modes for old duplicate packets from an earlier incarnation. We will call these four modes F1 , F2, F3, and F4:

F1: B < R, Tc < 4.55 hrs. (Figure 1)

F2: B < R, Tc >= 4.55 hrs. (Figure 2)

F3: B >= R, Nc < 2**32 (Figure 3)

F4: B >= R, Nc >= 2**32 (Figure 4)

Another limitation of clock-driven ISN selection should be mentioned. Tomlinson assumed that the current time t in formula [2] is obtained from a clock that is persistent over a system crash. For his scheme to work correctly, the clock must be restarted with an accuracy of 1/R seconds (e.g, 4 microseconds in the case of TCP). While this may be possible for some hosts and some crashes, in most cases there will be an uncertainty in the clock after a crash that ranges from a second to several minutes.

As a result of this random clock offset after system reinitialization, there is a possibility that old segments sent before the crash may fall into the window of a new connection incarnation. The solution to this problem that was adopted in the final TCP spec is a "quiet time" of MSL seconds when the system is initialized [Postel81, p. 28]. No TCP connection can be opened until the expiration of this quiet time.

A different approach was suggested by Garlick, Rom, and Postel [Garlick77]. Rather than using clock-driven ISN selection, they proposed to maintain connection records containing the last ISN used on every connection. To immediately open a new incarnation of a connection, the ISN is taken to be greater than the last sequence number of the previous incarnation, so that the new incarnation will have unique sequence numbers. To handle a system crash, they proposed a quiet time, i.e., a delay at system startup time to allow old duplicates to expire. Note that the connection records need be kept only for MSL seconds; after that, no collision is possible, and a new connection can start with sequence number zero.

The scheme finally adopted for TCP combines features of both these proposals. TCP uses three mechanisms:

(A) ISN selection is clock-driven to handle short-lived connections. The parameter R = 250KBps, so that the ISN value cycles in 2**32/R = 4.55 hours.

(B) (One end of) a closed connection is left in a "busy" state, known as "TIME-WAIT" state, for a time of 2*MSL. TIME-WAIT state handles the proper close of a long-lived connection without resynchronization. It also allows reliable completion of the full-duplex close handshake.

(C) There is a quiet time of one MSL at system startup. This handles a crash of a long-lived connection and avoids time resynchronization problems in (A).

Notice that (B) and (C) together are logically sufficient to prevent accidental reuse of sequence numbers from a different incarnation, for any of the failure modes F1-F4. (A) is not logically necessary since the close delay (B) makes it impossible to reopen the same TCP connection immediately. However, the use of (A) does give additional assurance in a common case, perhaps compensating for a host that has set its TIME-WAIT state delay too short.

Some TCP implementations have permitted a connection in the TIME-WAIT state to be reopened immediately by the other side, thus short-circuiting mechanism (B). Specifically, a new SYN for the same socket pair is accepted when the earlier incarnation is still in TIME-WAIT state. Old duplicates in one direction can be avoided by choosing the ISN to be the next unused sequence number from the preceding connection (i.e., FIN+1); this is essentially an application of the scheme of Garlick, Rom, and Postel, using the connection block in TIME-WAIT state as the connection record.

However, the connection is still vulnerable to old duplicates in the other direction. Mechanism (A) prevents trouble in mode F1, but failures can arise in F2, F3, or F4; of these, F2, on short, fast connections, is the most dangerous.

Finally, we note TCP will operate reliably without any MSL-based mechanisms in the following restricted domain:

  • Total data sent is less then 2**32 octets, and

  • Effective sustained rate less than 250KBps, and

  • Connection duration less than 4.55 hours.

At the present time, the great majority of current TCP usage falls into this restricted domain. The third component, connection duration, is the most commonly violated.