home *** CD-ROM | disk | FTP | other *** search
/ Hackers Toolkit 2.0 / Hackers_Toolkit_v2.0.iso / HTML / archive / Texts / Rfc / RFC793.TXT < prev    next >
Encoding:
Text File  |  1999-11-04  |  143.5 KB  |  4,325 lines

  1. RFC: 793
  2.                                     
  3.                                     
  4.                                     
  5.                                     
  6.                                     
  7.                                     
  8.                                     
  9.                      TRANSMISSION CONTROL PROTOCOL
  10.                                     
  11.                                     
  12.                          DARPA INTERNET PROGRAM
  13.                                     
  14.                          PROTOCOL SPECIFICATION
  15.                                     
  16.                                     
  17.                                     
  18.                              September 1981
  19.  
  20.  
  21.  
  22.  
  23.  
  24.  
  25.  
  26.  
  27.  
  28.  
  29.  
  30.  
  31.  
  32.                               prepared for
  33.                                     
  34.                Defense Advanced Research Projects Agency
  35.                 Information Processing Techniques Office
  36.                          1400 Wilson Boulevard
  37.                        Arlington, Virginia  22209
  38.  
  39.  
  40.  
  41.  
  42.  
  43.  
  44.  
  45.                                    by
  46.  
  47.                      Information Sciences Institute
  48.                    University of Southern California
  49.                            4676 Admiralty Way
  50.                    Marina del Rey, California  90291
  51.  
  52.  
  53.  
  54.  
  55.  
  56. September 1981                                                          
  57.                                            Transmission Control Protocol
  58.  
  59.  
  60.  
  61.                            TABLE OF CONTENTS
  62.  
  63.     PREFACE ........................................................ iii
  64.  
  65. 1.  INTRODUCTION ..................................................... 1
  66.  
  67.   1.1  Motivation .................................................... 1
  68.   1.2  Scope ......................................................... 2
  69.   1.3  About This Document ........................................... 2
  70.   1.4  Interfaces .................................................... 3
  71.   1.5  Operation ..................................................... 3
  72.  
  73. 2.  PHILOSOPHY ....................................................... 7
  74.  
  75.   2.1  Elements of the Internetwork System ........................... 7
  76.   2.2  Model of Operation ............................................ 7
  77.   2.3  The Host Environment .......................................... 8
  78.   2.4  Interfaces .................................................... 9
  79.   2.5  Relation to Other Protocols ................................... 9
  80.   2.6  Reliable Communication ........................................ 9
  81.   2.7  Connection Establishment and Clearing ........................ 10
  82.   2.8  Data Communication ........................................... 12
  83.   2.9  Precedence and Security ...................................... 13
  84.   2.10 Robustness Principle ......................................... 13
  85.  
  86. 3.  FUNCTIONAL SPECIFICATION ........................................ 15
  87.  
  88.   3.1  Header Format ................................................ 15
  89.   3.2  Terminology .................................................. 19
  90.   3.3  Sequence Numbers ............................................. 24
  91.   3.4  Establishing a connection .................................... 30
  92.   3.5  Closing a Connection ......................................... 37
  93.   3.6  Precedence and Security ...................................... 40
  94.   3.7  Data Communication ........................................... 40
  95.   3.8  Interfaces ................................................... 44
  96.   3.9  Event Processing ............................................. 52
  97.  
  98. GLOSSARY ............................................................ 79
  99.  
  100. REFERENCES .......................................................... 85
  101.  
  102.  
  103.  
  104.  
  105.  
  106.  
  107.  
  108.  
  109.  
  110.  
  111.  
  112.                                                                 [Page i]
  113.  
  114.  
  115.  
  116.                                                           September 1981
  117. Transmission Control Protocol
  118.  
  119.  
  120.  
  121.  
  122.  
  123.  
  124.  
  125.  
  126.  
  127.  
  128.  
  129.  
  130.  
  131.  
  132.  
  133.  
  134.  
  135.  
  136.  
  137.  
  138.  
  139.  
  140.  
  141.  
  142.  
  143.  
  144.  
  145.  
  146.  
  147.  
  148.  
  149.  
  150.  
  151.  
  152.  
  153.  
  154.  
  155.  
  156.  
  157.  
  158.  
  159.  
  160.  
  161.  
  162.  
  163.  
  164.  
  165.  
  166.  
  167.  
  168.  
  169.  
  170.  
  171.  
  172. [Page ii]                                                               
  173.  
  174.  
  175.  
  176. September 1981                                                          
  177.                                            Transmission Control Protocol
  178.  
  179.  
  180.  
  181.                                 PREFACE
  182.  
  183.  
  184.  
  185. This document describes the DoD Standard Transmission Control Protocol
  186. (TCP).  There have been nine earlier editions of the ARPA TCP
  187. specification on which this standard is based, and the present text
  188. draws heavily from them.  There have been many contributors to this work
  189. both in terms of concepts and in terms of text.  This edition clarifies
  190. several details and removes the end-of-letter buffer-size adjustments,
  191. and redescribes the letter mechanism as a push function.
  192.  
  193.                                                            Jon Postel
  194.  
  195.                                                            Editor
  196.  
  197.  
  198.  
  199.  
  200.  
  201.  
  202.  
  203.  
  204.  
  205.  
  206.  
  207.  
  208.  
  209.  
  210.  
  211.  
  212.  
  213.  
  214.  
  215.  
  216.  
  217.  
  218.  
  219.  
  220.  
  221.  
  222.  
  223.  
  224.  
  225.  
  226.  
  227.  
  228.  
  229.  
  230.  
  231.  
  232.                                                               [Page iii]
  233.  
  234.  
  235.  
  236.  
  237.  
  238.  
  239. RFC:  793
  240. Replaces: RFC 761
  241. IENs:  129, 124, 112, 81,
  242. 55, 44, 40, 27, 21, 5
  243.  
  244.                      TRANSMISSION CONTROL PROTOCOL
  245.  
  246.                          DARPA INTERNET PROGRAM
  247.                          PROTOCOL SPECIFICATION
  248.  
  249.  
  250.  
  251.                             1.  INTRODUCTION
  252.  
  253. The Transmission Control Protocol (TCP) is intended for use as a highly
  254. reliable host-to-host protocol between hosts in packet-switched computer
  255. communication networks, and in interconnected systems of such networks.
  256.  
  257. This document describes the functions to be performed by the
  258. Transmission Control Protocol, the program that implements it, and its
  259. interface to programs or users that require its services.
  260.  
  261. 1.1.  Motivation
  262.  
  263.   Computer communication systems are playing an increasingly important
  264.   role in military, government, and civilian environments.  This
  265.   document focuses its attention primarily on military computer
  266.   communication requirements, especially robustness in the presence of
  267.   communication unreliability and availability in the presence of
  268.   congestion, but many of these problems are found in the civilian and
  269.   government sector as well.
  270.  
  271.   As strategic and tactical computer communication networks are
  272.   developed and deployed, it is essential to provide means of
  273.   interconnecting them and to provide standard interprocess
  274.   communication protocols which can support a broad range of
  275.   applications.  In anticipation of the need for such standards, the
  276.   Deputy Undersecretary of Defense for Research and Engineering has
  277.   declared the Transmission Control Protocol (TCP) described herein to
  278.   be a basis for DoD-wide inter-process communication protocol
  279.   standardization.
  280.  
  281.   TCP is a connection-oriented, end-to-end reliable protocol designed to
  282.   fit into a layered hierarchy of protocols which support multi-network
  283.   applications.  The TCP provides for reliable inter-process
  284.   communication between pairs of processes in host computers attached to
  285.   distinct but interconnected computer communication networks.  Very few
  286.   assumptions are made as to the reliability of the communication
  287.   protocols below the TCP layer.  TCP assumes it can obtain a simple,
  288.   potentially unreliable datagram service from the lower level
  289.   protocols.  In principle, the TCP should be able to operate above a
  290.   wide spectrum of communication systems ranging from hard-wired
  291.   connections to packet-switched or circuit-switched networks.
  292.  
  293.  
  294.                                                                 [Page 1]
  295.  
  296.  
  297.  
  298.                                                           September 1981
  299. Transmission Control Protocol
  300. Introduction
  301.  
  302.  
  303.  
  304.   TCP is based on concepts first described by Cerf and Kahn in [1].  The
  305.   TCP fits into a layered protocol architecture just above a basic
  306.   Internet Protocol [2] which provides a way for the TCP to send and
  307.   receive variable-length segments of information enclosed in internet
  308.   datagram "envelopes".  The internet datagram provides a means for
  309.   addressing source and destination TCPs in different networks.  The
  310.   internet protocol also deals with any fragmentation or reassembly of
  311.   the TCP segments required to achieve transport and delivery through
  312.   multiple networks and interconnecting gateways.  The internet protocol
  313.   also carries information on the precedence, security classification
  314.   and compartmentation of the TCP segments, so this information can be
  315.   communicated end-to-end across multiple networks.
  316.  
  317.                            Protocol Layering
  318.  
  319.                         +---------------------+
  320.                         |     higher-level    |
  321.                         +---------------------+
  322.                         |        TCP          |
  323.                         +---------------------+
  324.                         |  internet protocol  |
  325.                         +---------------------+
  326.                         |communication network|
  327.                         +---------------------+
  328.  
  329.                                 Figure 1
  330.  
  331.   Much of this document is written in the context of TCP implementations
  332.   which are co-resident with higher level protocols in the host
  333.   computer.  Some computer systems will be connected to networks via
  334.   front-end computers which house the TCP and internet protocol layers,
  335.   as well as network specific software.  The TCP specification describes
  336.   an interface to the higher level protocols which appears to be
  337.   implementable even for the front-end case, as long as a suitable
  338.   host-to-front end protocol is implemented.
  339.  
  340. 1.2.  Scope
  341.  
  342.   The TCP is intended to provide a reliable process-to-process
  343.   communication service in a multinetwork environment.  The TCP is
  344.   intended to be a host-to-host protocol in common use in multiple
  345.   networks.
  346.  
  347. 1.3.  About this Document
  348.  
  349.   This document represents a specification of the behavior required of
  350.   any TCP implementation, both in its interactions with higher level
  351.   protocols and in its interactions with other TCPs.  The rest of this
  352.  
  353.  
  354. [Page 2]                                                                
  355.  
  356.  
  357.  
  358. September 1981                                                          
  359.                                            Transmission Control Protocol
  360.                                                             Introduction
  361.  
  362.  
  363.  
  364.   section offers a very brief view of the protocol interfaces and
  365.   operation.  Section 2 summarizes the philosophical basis for the TCP
  366.   design.  Section 3 offers both a detailed description of the actions
  367.   required of TCP when various events occur (arrival of new segments,
  368.   user calls, errors, etc.) and the details of the formats of TCP
  369.   segments.
  370.  
  371. 1.4.  Interfaces
  372.  
  373.   The TCP interfaces on one side to user or application processes and on
  374.   the other side to a lower level protocol such as Internet Protocol.
  375.  
  376.   The interface between an application process and the TCP is
  377.   illustrated in reasonable detail.  This interface consists of a set of
  378.   calls much like the calls an operating system provides to an
  379.   application process for manipulating files.  For example, there are
  380.   calls to open and close connections and to send and receive data on
  381.   established connections.  It is also expected that the TCP can
  382.   asynchronously communicate with application programs.  Although
  383.   considerable freedom is permitted to TCP implementors to design
  384.   interfaces which are appropriate to a particular operating system
  385.   environment, a minimum functionality is required at the TCP/user
  386.   interface for any valid implementation.
  387.  
  388.   The interface between TCP and lower level protocol is essentially
  389.   unspecified except that it is assumed there is a mechanism whereby the
  390.   two levels can asynchronously pass information to each other.
  391.   Typically, one expects the lower level protocol to specify this
  392.   interface.  TCP is designed to work in a very general environment of
  393.   interconnected networks.  The lower level protocol which is assumed
  394.   throughout this document is the Internet Protocol [2].
  395.  
  396. 1.5.  Operation
  397.  
  398.   As noted above, the primary purpose of the TCP is to provide reliable,
  399.   securable logical circuit or connection service between pairs of
  400.   processes.  To provide this service on top of a less reliable internet
  401.   communication system requires facilities in the following areas:
  402.  
  403.     Basic Data Transfer
  404.     Reliability
  405.     Flow Control
  406.     Multiplexing
  407.     Connections
  408.     Precedence and Security
  409.  
  410.   The basic operation of the TCP in each of these areas is described in
  411.   the following paragraphs.
  412.  
  413.  
  414.                                                                 [Page 3]
  415.  
  416.  
  417.  
  418.                                                           September 1981
  419. Transmission Control Protocol
  420. Introduction
  421.  
  422.  
  423.  
  424.   Basic Data Transfer:
  425.  
  426.     The TCP is able to transfer a continuous stream of octets in each
  427.     direction between its users by packaging some number of octets into
  428.     segments for transmission through the internet system.  In general,
  429.     the TCPs decide when to block and forward data at their own
  430.     convenience.
  431.  
  432.     Sometimes users need to be sure that all the data they have
  433.     submitted to the TCP has been transmitted.  For this purpose a push
  434.     function is defined.  To assure that data submitted to a TCP is
  435.     actually transmitted the sending user indicates that it should be
  436.     pushed through to the receiving user.  A push causes the TCPs to
  437.     promptly forward and deliver data up to that point to the receiver.
  438.     The exact push point might not be visible to the receiving user and
  439.     the push function does not supply a record boundary marker.
  440.  
  441.   Reliability:
  442.  
  443.     The TCP must recover from data that is damaged, lost, duplicated, or
  444.     delivered out of order by the internet communication system.  This
  445.     is achieved by assigning a sequence number to each octet
  446.     transmitted, and requiring a positive acknowledgment (ACK) from the
  447.     receiving TCP.  If the ACK is not received within a timeout
  448.     interval, the data is retransmitted.  At the receiver, the sequence
  449.     numbers are used to correctly order segments that may be received
  450.     out of order and to eliminate duplicates.  Damage is handled by
  451.     adding a checksum to each segment transmitted, checking it at the
  452.     receiver, and discarding damaged segments.
  453.  
  454.     As long as the TCPs continue to function properly and the internet
  455.     system does not become completely partitioned, no transmission
  456.     errors will affect the correct delivery of data.  TCP recovers from
  457.     internet communication system errors.
  458.  
  459.   Flow Control:
  460.  
  461.     TCP provides a means for the receiver to govern the amount of data
  462.     sent by the sender.  This is achieved by returning a "window" with
  463.     every ACK indicating a range of acceptable sequence numbers beyond
  464.     the last segment successfully received.  The window indicates an
  465.     allowed number of octets that the sender may transmit before
  466.     receiving further permission.
  467.  
  468.  
  469.  
  470.  
  471.  
  472.  
  473.  
  474. [Page 4]                                                                
  475.  
  476.  
  477.  
  478. September 1981                                                          
  479.                                            Transmission Control Protocol
  480.                                                             Introduction
  481.  
  482.  
  483.  
  484.   Multiplexing:
  485.  
  486.     To allow for many processes within a single Host to use TCP
  487.     communication facilities simultaneously, the TCP provides a set of
  488.     addresses or ports within each host.  Concatenated with the network
  489.     and host addresses from the internet communication layer, this forms
  490.     a socket.  A pair of sockets uniquely identifies each connection.
  491.     That is, a socket may be simultaneously used in multiple
  492.     connections.
  493.  
  494.     The binding of ports to processes is handled independently by each
  495.     Host.  However, it proves useful to attach frequently used processes
  496.     (e.g., a "logger" or timesharing service) to fixed sockets which are
  497.     made known to the public.  These services can then be accessed
  498.     through the known addresses.  Establishing and learning the port
  499.     addresses of other processes may involve more dynamic mechanisms.
  500.  
  501.   Connections:
  502.  
  503.     The reliability and flow control mechanisms described above require
  504.     that TCPs initialize and maintain certain status information for
  505.     each data stream.  The combination of this information, including
  506.     sockets, sequence numbers, and window sizes, is called a connection.
  507.     Each connection is uniquely specified by a pair of sockets
  508.     identifying its two sides.
  509.  
  510.     When two processes wish to communicate, their TCP's must first
  511.     establish a connection (initialize the status information on each
  512.     side).  When their communication is complete, the connection is
  513.     terminated or closed to free the resources for other uses.
  514.  
  515.     Since connections must be established between unreliable hosts and
  516.     over the unreliable internet communication system, a handshake
  517.     mechanism with clock-based sequence numbers is used to avoid
  518.     erroneous initialization of connections.
  519.  
  520.   Precedence and Security:
  521.  
  522.     The users of TCP may indicate the security and precedence of their
  523.     communication.  Provision is made for default values to be used when
  524.     these features are not needed.
  525.  
  526.     
  527.  
  528.  
  529.  
  530.  
  531.  
  532.  
  533.  
  534.                                                                 [Page 5]
  535.  
  536.  
  537.  
  538.                                                           September 1981
  539. Transmission Control Protocol
  540.  
  541.  
  542.  
  543.  
  544.  
  545.  
  546.  
  547.  
  548.  
  549.  
  550.  
  551.  
  552.  
  553.  
  554.  
  555.  
  556.  
  557.  
  558.  
  559.  
  560.  
  561.  
  562.  
  563.  
  564.  
  565.  
  566.  
  567.  
  568.  
  569.  
  570.  
  571.  
  572.  
  573.  
  574.  
  575.  
  576.  
  577.  
  578.  
  579.  
  580.  
  581.  
  582.  
  583.  
  584.  
  585.  
  586.  
  587.  
  588.  
  589.  
  590.  
  591.  
  592.  
  593.  
  594. [Page 6]                                                                
  595.  
  596.  
  597.  
  598. September 1981                                                          
  599.                                            Transmission Control Protocol
  600.  
  601.  
  602.  
  603.                              2.  PHILOSOPHY
  604.  
  605. 2.1.  Elements of the Internetwork System
  606.  
  607.   The internetwork environment consists of hosts connected to networks
  608.   which are in turn interconnected via gateways.  It is assumed here
  609.   that the networks may be either local networks (e.g., the ETHERNET) or
  610.   large networks (e.g., the ARPANET), but in any case are based on
  611.   packet switching technology.  The active agents that produce and
  612.   consume messages are processes.  Various levels of protocols in the
  613.   networks, the gateways, and the hosts support an interprocess
  614.   communication system that provides two-way data flow on logical
  615.   connections between process ports.
  616.  
  617.   The term packet is used generically here to mean the data of one
  618.   transaction between a host and its network.  The format of data blocks
  619.   exchanged within the a network will generally not be of concern to us.
  620.  
  621.   Hosts are computers attached to a network, and from the communication
  622.   network's point of view, are the sources and destinations of packets.
  623.   Processes are viewed as the active elements in host computers (in
  624.   accordance with the fairly common definition of a process as a program
  625.   in execution).  Even terminals and files or other I/O devices are
  626.   viewed as communicating with each other through the use of processes.
  627.   Thus, all communication is viewed as inter-process communication.
  628.  
  629.   Since a process may need to distinguish among several communication
  630.   streams between itself and another process (or processes), we imagine
  631.   that each process may have a number of ports through which it
  632.   communicates with the ports of other processes.
  633.  
  634. 2.2.  Model of Operation
  635.  
  636.   Processes transmit data by calling on the TCP and passing buffers of
  637.   data as arguments.  The TCP packages the data from these buffers into
  638.   segments and calls on the internet module to transmit each segment to
  639.   the destination TCP.  The receiving TCP places the data from a segment
  640.   into the receiving user's buffer and notifies the receiving user.  The
  641.   TCPs include control information in the segments which they use to
  642.   ensure reliable ordered data transmission.
  643.  
  644.   The model of internet communication is that there is an internet
  645.   protocol module associated with each TCP which provides an interface
  646.   to the local network.  This internet module packages TCP segments
  647.   inside internet datagrams and routes these datagrams to a destination
  648.   internet module or intermediate gateway.  To transmit the datagram
  649.   through the local network, it is embedded in a local network packet.
  650.  
  651.   The packet switches may perform further packaging, fragmentation, or
  652.  
  653.  
  654.                                                                 [Page 7]
  655.  
  656.  
  657.  
  658.                                                           September 1981
  659. Transmission Control Protocol
  660. Philosophy
  661.  
  662.  
  663.  
  664.   other operations to achieve the delivery of the local packet to the
  665.   destination internet module.
  666.  
  667.   At a gateway between networks, the internet datagram is "unwrapped"
  668.   from its local packet and examined to determine through which network
  669.   the internet datagram should travel next.  The internet datagram is
  670.   then "wrapped" in a local packet suitable to the next network and
  671.   routed to the next gateway, or to the final destination.
  672.  
  673.   A gateway is permitted to break up an internet datagram into smaller
  674.   internet datagram fragments if this is necessary for transmission
  675.   through the next network.  To do this, the gateway produces a set of
  676.   internet datagrams; each carrying a fragment.  Fragments may be
  677.   further broken into smaller fragments at subsequent gateways.  The
  678.   internet datagram fragment format is designed so that the destination
  679.   internet module can reassemble fragments into internet datagrams.
  680.  
  681.   A destination internet module unwraps the segment from the datagram
  682.   (after reassembling the datagram, if necessary) and passes it to the
  683.   destination TCP.
  684.  
  685.   This simple model of the operation glosses over many details.  One
  686.   important feature is the type of service.  This provides information
  687.   to the gateway (or internet module) to guide it in selecting the
  688.   service parameters to be used in traversing the next network.
  689.   Included in the type of service information is the precedence of the
  690.   datagram.  Datagrams may also carry security information to permit
  691.   host and gateways that operate in multilevel secure environments to
  692.   properly segregate datagrams for security considerations.
  693.  
  694. 2.3.  The Host Environment
  695.  
  696.   The TCP is assumed to be a module in an operating system.  The users
  697.   access the TCP much like they would access the file system.  The TCP
  698.   may call on other operating system functions, for example, to manage
  699.   data structures.  The actual interface to the network is assumed to be
  700.   controlled by a device driver module.  The TCP does not call on the
  701.   network device driver directly, but rather calls on the internet
  702.   datagram protocol module which may in turn call on the device driver.
  703.  
  704.   The mechanisms of TCP do not preclude implementation of the TCP in a
  705.   front-end processor.  However, in such an implementation, a
  706.   host-to-front-end protocol must provide the functionality to support
  707.   the type of TCP-user interface described in this document.
  708.  
  709.  
  710.  
  711.  
  712.  
  713.  
  714. [Page 8]                                                                
  715.  
  716.  
  717.  
  718. September 1981                                                          
  719.                                            Transmission Control Protocol
  720.                                                               Philosophy
  721.  
  722.  
  723.  
  724. 2.4.  Interfaces
  725.  
  726.   The TCP/user interface provides for calls made by the user on the TCP
  727.   to OPEN or CLOSE a connection, to SEND or RECEIVE data, or to obtain
  728.   STATUS about a connection.  These calls are like other calls from user
  729.   programs on the operating system, for example, the calls to open, read
  730.   from, and close a file.
  731.  
  732.   The TCP/internet interface provides calls to send and receive
  733.   datagrams addressed to TCP modules in hosts anywhere in the internet
  734.   system.  These calls have parameters for passing the address, type of
  735.   service, precedence, security, and other control information.
  736.  
  737. 2.5.  Relation to Other Protocols
  738.  
  739.   The following diagram illustrates the place of the TCP in the protocol
  740.   hierarchy:
  741.  
  742.                                     
  743.        +------+ +-----+ +-----+       +-----+                    
  744.        |Telnet| | FTP | |Voice|  ...  |     |  Application Level 
  745.        +------+ +-----+ +-----+       +-----+                    
  746.              |   |         |             |                       
  747.             +-----+     +-----+       +-----+                    
  748.             | TCP |     | RTP |  ...  |     |  Host Level        
  749.             +-----+     +-----+       +-----+                    
  750.                |           |             |                       
  751.             +-------------------------------+                    
  752.             |    Internet Protocol & ICMP   |  Gateway Level     
  753.             +-------------------------------+                    
  754.                            |                                     
  755.               +---------------------------+                      
  756.               |   Local Network Protocol  |    Network Level     
  757.               +---------------------------+                      
  758.  
  759.                          Protocol Relationships
  760.  
  761.                                Figure 2.
  762.  
  763.   It is expected that the TCP will be able to support higher level
  764.   protocols efficiently.  It should be easy to interface higher level
  765.   protocols like the ARPANET Telnet or AUTODIN II THP to the TCP.
  766.  
  767. 2.6.  Reliable Communication
  768.  
  769.   A stream of data sent on a TCP connection is delivered reliably and in
  770.   order at the destination.
  771.  
  772.  
  773.  
  774.                                                                 [Page 9]
  775.  
  776.  
  777.  
  778.                                                           September 1981
  779. Transmission Control Protocol
  780. Philosophy
  781.  
  782.  
  783.  
  784.   Transmission is made reliable via the use of sequence numbers and
  785.   acknowledgments.  Conceptually, each octet of data is assigned a
  786.   sequence number.  The sequence number of the first octet of data in a
  787.   segment is transmitted with that segment and is called the segment
  788.   sequence number.  Segments also carry an acknowledgment number which
  789.   is the sequence number of the next expected data octet of
  790.   transmissions in the reverse direction.  When the TCP transmits a
  791.   segment containing data, it puts a copy on a retransmission queue and
  792.   starts a timer; when the acknowledgment for that data is received, the
  793.   segment is deleted from the queue.  If the acknowledgment is not
  794.   received before the timer runs out, the segment is retransmitted.
  795.  
  796.   An acknowledgment by TCP does not guarantee that the data has been
  797.   delivered to the end user, but only that the receiving TCP has taken
  798.   the responsibility to do so.
  799.  
  800.   To govern the flow of data between TCPs, a flow control mechanism is
  801.   employed.  The receiving TCP reports a "window" to the sending TCP.
  802.   This window specifies the number of octets, starting with the
  803.   acknowledgment number, that the receiving TCP is currently prepared to
  804.   receive.
  805.  
  806. 2.7.  Connection Establishment and Clearing
  807.  
  808.   To identify the separate data streams that a TCP may handle, the TCP
  809.   provides a port identifier.  Since port identifiers are selected
  810.   independently by each TCP they might not be unique.  To provide for
  811.   unique addresses within each TCP, we concatenate an internet address
  812.   identifying the TCP with a port identifier to create a socket which
  813.   will be unique throughout all networks connected together.
  814.  
  815.   A connection is fully specified by the pair of sockets at the ends.  A
  816.   local socket may participate in many connections to different foreign
  817.   sockets.  A connection can be used to carry data in both directions,
  818.   that is, it is "full duplex".
  819.  
  820.   TCPs are free to associate ports with processes however they choose.
  821.   However, several basic concepts are necessary in any implementation.
  822.   There must be well-known sockets which the TCP associates only with
  823.   the "appropriate" processes by some means.  We envision that processes
  824.   may "own" ports, and that processes can initiate connections only on
  825.   the ports they own.  (Means for implementing ownership is a local
  826.   issue, but we envision a Request Port user command, or a method of
  827.   uniquely allocating a group of ports to a given process, e.g., by
  828.   associating the high order bits of a port name with a given process.)
  829.  
  830.   A connection is specified in the OPEN call by the local port and
  831.   foreign socket arguments.  In return, the TCP supplies a (short) local
  832.  
  833.  
  834. [Page 10]                                                               
  835.  
  836.  
  837.  
  838. September 1981                                                          
  839.                                            Transmission Control Protocol
  840.                                                               Philosophy
  841.  
  842.  
  843.  
  844.   connection name by which the user refers to the connection in
  845.   subsequent calls.  There are several things that must be remembered
  846.   about a connection.  To store this information we imagine that there
  847.   is a data structure called a Transmission Control Block (TCB).  One
  848.   implementation strategy would have the local connection name be a
  849.   pointer to the TCB for this connection.  The OPEN call also specifies
  850.   whether the connection establishment is to be actively pursued, or to
  851.   be passively waited for.
  852.  
  853.   A passive OPEN request means that the process wants to accept incoming
  854.   connection requests rather than attempting to initiate a connection.
  855.   Often the process requesting a passive OPEN will accept a connection
  856.   request from any caller.  In this case a foreign socket of all zeros
  857.   is used to denote an unspecified socket.  Unspecified foreign sockets
  858.   are allowed only on passive OPENs.
  859.  
  860.   A service process that wished to provide services for unknown other
  861.   processes would issue a passive OPEN request with an unspecified
  862.   foreign socket.  Then a connection could be made with any process that
  863.   requested a connection to this local socket.  It would help if this
  864.   local socket were known to be associated with this service.
  865.  
  866.   Well-known sockets are a convenient mechanism for a priori associating
  867.   a socket address with a standard service.  For instance, the
  868.   "Telnet-Server" process is permanently assigned to a particular
  869.   socket, and other sockets are reserved for File Transfer, Remote Job
  870.   Entry, Text Generator, Echoer, and Sink processes (the last three
  871.   being for test purposes).  A socket address might be reserved for
  872.   access to a "Look-Up" service which would return the specific socket
  873.   at which a newly created service would be provided.  The concept of a
  874.   well-known socket is part of the TCP specification, but the assignment
  875.   of sockets to services is outside this specification.  (See [4].)
  876.  
  877.   Processes can issue passive OPENs and wait for matching active OPENs
  878.   from other processes and be informed by the TCP when connections have
  879.   been established.  Two processes which issue active OPENs to each
  880.   other at the same time will be correctly connected.  This flexibility
  881.   is critical for the support of distributed computing in which
  882.   components act asynchronously with respect to each other.
  883.  
  884.   There are two principal cases for matching the sockets in the local
  885.   passive OPENs and an foreign active OPENs.  In the first case, the
  886.   local passive OPENs has fully specified the foreign socket.  In this
  887.   case, the match must be exact.  In the second case, the local passive
  888.   OPENs has left the foreign socket unspecified.  In this case, any
  889.   foreign socket is acceptable as long as the local sockets match.
  890.   Other possibilities include partially restricted matches.
  891.  
  892.  
  893.  
  894.                                                                [Page 11]
  895.  
  896.  
  897.  
  898.                                                           September 1981
  899. Transmission Control Protocol
  900. Philosophy
  901.  
  902.  
  903.  
  904.   If there are several pending passive OPENs (recorded in TCBs) with the
  905.   same local socket, an foreign active OPEN will be matched to a TCB
  906.   with the specific foreign socket in the foreign active OPEN, if such a
  907.   TCB exists, before selecting a TCB with an unspecified foreign socket.
  908.  
  909.   The procedures to establish connections utilize the synchronize (SYN)
  910.   control flag and involves an exchange of three messages.  This
  911.   exchange has been termed a three-way hand shake [3].
  912.  
  913.   A connection is initiated by the rendezvous of an arriving segment
  914.   containing a SYN and a waiting TCB entry each created by a user OPEN
  915.   command.  The matching of local and foreign sockets determines when a
  916.   connection has been initiated.  The connection becomes "established"
  917.   when sequence numbers have been synchronized in both directions.
  918.  
  919.   The clearing of a connection also involves the exchange of segments,
  920.   in this case carrying the FIN control flag.
  921.  
  922. 2.8.  Data Communication
  923.  
  924.   The data that flows on a connection may be thought of as a stream of
  925.   octets.  The sending user indicates in each SEND call whether the data
  926.   in that call (and any preceeding calls) should be immediately pushed
  927.   through to the receiving user by the setting of the PUSH flag.
  928.  
  929.   A sending TCP is allowed to collect data from the sending user and to
  930.   send that data in segments at its own convenience, until the push
  931.   function is signaled, then it must send all unsent data.  When a
  932.   receiving TCP sees the PUSH flag, it must not wait for more data from
  933.   the sending TCP before passing the data to the receiving process.
  934.  
  935.   There is no necessary relationship between push functions and segment
  936.   boundaries.  The data in any particular segment may be the result of a
  937.   single SEND call, in whole or part, or of multiple SEND calls.
  938.  
  939.   The purpose of push function and the PUSH flag is to push data through
  940.   from the sending user to the receiving user.  It does not provide a
  941.   record service.
  942.  
  943.   There is a coupling between the push function and the use of buffers
  944.   of data that cross the TCP/user interface.  Each time a PUSH flag is
  945.   associated with data placed into the receiving user's buffer, the
  946.   buffer is returned to the user for processing even if the buffer is
  947.   not filled.  If data arrives that fills the user's buffer before a
  948.   PUSH is seen, the data is passed to the user in buffer size units.
  949.  
  950.   TCP also provides a means to communicate to the receiver of data that
  951.   at some point further along in the data stream than the receiver is
  952.  
  953.  
  954. [Page 12]                                                               
  955.  
  956.  
  957.  
  958. September 1981                                                          
  959.                                            Transmission Control Protocol
  960.                                                               Philosophy
  961.  
  962.  
  963.  
  964.   currently reading there is urgent data.  TCP does not attempt to
  965.   define what the user specifically does upon being notified of pending
  966.   urgent data, but the general notion is that the receiving process will
  967.   take action to process the urgent data quickly.
  968.  
  969. 2.9.  Precedence and Security
  970.  
  971.   The TCP makes use of the internet protocol type of service field and
  972.   security option to provide precedence and security on a per connection
  973.   basis to TCP users.  Not all TCP modules will necessarily function in
  974.   a multilevel secure environment; some may be limited to unclassified
  975.   use only, and others may operate at only one security level and
  976.   compartment.  Consequently, some TCP implementations and services to
  977.   users may be limited to a subset of the multilevel secure case.
  978.  
  979.   TCP modules which operate in a multilevel secure environment must
  980.   properly mark outgoing segments with the security, compartment, and
  981.   precedence.  Such TCP modules must also provide to their users or
  982.   higher level protocols such as Telnet or THP an interface to allow
  983.   them to specify the desired security level, compartment, and
  984.   precedence of connections.
  985.  
  986. 2.10.  Robustness Principle
  987.  
  988.   TCP implementations will follow a general principle of robustness:  be
  989.   conservative in what you do, be liberal in what you accept from
  990.   others.
  991.  
  992.   
  993.  
  994.  
  995.  
  996.  
  997.  
  998.  
  999.  
  1000.  
  1001.  
  1002.  
  1003.  
  1004.  
  1005.  
  1006.  
  1007.  
  1008.  
  1009.  
  1010.  
  1011.  
  1012.  
  1013.  
  1014.                                                                [Page 13]
  1015.  
  1016.  
  1017.  
  1018.                                                           September 1981
  1019. Transmission Control Protocol
  1020.  
  1021.  
  1022.  
  1023.  
  1024.  
  1025.  
  1026.  
  1027.  
  1028.  
  1029.  
  1030.  
  1031.  
  1032.  
  1033.  
  1034.  
  1035.  
  1036.  
  1037.  
  1038.  
  1039.  
  1040.  
  1041.  
  1042.  
  1043.  
  1044.  
  1045.  
  1046.  
  1047.  
  1048.  
  1049.  
  1050.  
  1051.  
  1052.  
  1053.  
  1054.  
  1055.  
  1056.  
  1057.  
  1058.  
  1059.  
  1060.  
  1061.  
  1062.  
  1063.  
  1064.  
  1065.  
  1066.  
  1067.  
  1068.  
  1069.  
  1070.  
  1071.  
  1072.  
  1073.  
  1074. [Page 14]                                                               
  1075.  
  1076.  
  1077.  
  1078. September 1981                                                          
  1079.                                            Transmission Control Protocol
  1080.  
  1081.  
  1082.  
  1083.                       3.  FUNCTIONAL SPECIFICATION
  1084.  
  1085. 3.1.  Header Format
  1086.  
  1087.   TCP segments are sent as internet datagrams.  The Internet Protocol
  1088.   header carries several information fields, including the source and
  1089.   destination host addresses [2].  A TCP header follows the internet
  1090.   header, supplying information specific to the TCP protocol.  This
  1091.   division allows for the existence of host level protocols other than
  1092.   TCP.
  1093.  
  1094.   TCP Header Format
  1095.  
  1096.                                     
  1097.     0                   1                   2                   3   
  1098.     0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 
  1099.    +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  1100.    |          Source Port          |       Destination Port        |
  1101.    +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  1102.    |                        Sequence Number                        |
  1103.    +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  1104.    |                    Acknowledgment Number                      |
  1105.    +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  1106.    |  Data |           |U|A|P|R|S|F|                               |
  1107.    | Offset| Reserved  |R|C|S|S|Y|I|            Window             |
  1108.    |       |           |G|K|H|T|N|N|                               |
  1109.    +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  1110.    |           Checksum            |         Urgent Pointer        |
  1111.    +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  1112.    |                    Options                    |    Padding    |
  1113.    +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  1114.    |                             data                              |
  1115.    +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  1116.  
  1117.                             TCP Header Format
  1118.  
  1119.           Note that one tick mark represents one bit position.
  1120.  
  1121.                                Figure 3.
  1122.  
  1123.   Source Port:  16 bits
  1124.  
  1125.     The source port number.
  1126.  
  1127.   Destination Port:  16 bits
  1128.  
  1129.     The destination port number.
  1130.  
  1131.  
  1132.  
  1133.  
  1134.                                                                [Page 15]
  1135.  
  1136.  
  1137.  
  1138.                                                           September 1981
  1139. Transmission Control Protocol
  1140. Functional Specification
  1141.  
  1142.  
  1143.  
  1144.   Sequence Number:  32 bits
  1145.  
  1146.     The sequence number of the first data octet in this segment (except
  1147.     when SYN is present). If SYN is present the sequence number is the
  1148.     initial sequence number (ISN) and the first data octet is ISN+1.
  1149.  
  1150.   Acknowledgment Number:  32 bits
  1151.  
  1152.     If the ACK control bit is set this field contains the value of the
  1153.     next sequence number the sender of the segment is expecting to
  1154.     receive.  Once a connection is established this is always sent.
  1155.  
  1156.   Data Offset:  4 bits
  1157.  
  1158.     The number of 32 bit words in the TCP Header.  This indicates where
  1159.     the data begins.  The TCP header (even one including options) is an
  1160.     integral number of 32 bits long.
  1161.  
  1162.   Reserved:  6 bits
  1163.  
  1164.     Reserved for future use.  Must be zero.
  1165.  
  1166.   Control Bits:  6 bits (from left to right):
  1167.  
  1168.     URG:  Urgent Pointer field significant
  1169.     ACK:  Acknowledgment field significant
  1170.     PSH:  Push Function
  1171.     RST:  Reset the connection
  1172.     SYN:  Synchronize sequence numbers
  1173.     FIN:  No more data from sender
  1174.  
  1175.   Window:  16 bits
  1176.  
  1177.     The number of data octets beginning with the one indicated in the
  1178.     acknowledgment field which the sender of this segment is willing to
  1179.     accept.
  1180.  
  1181.   Checksum:  16 bits
  1182.  
  1183.     The checksum field is the 16 bit one's complement of the one's
  1184.     complement sum of all 16 bit words in the header and text.  If a
  1185.     segment contains an odd number of header and text octets to be
  1186.     checksummed, the last octet is padded on the right with zeros to
  1187.     form a 16 bit word for checksum purposes.  The pad is not
  1188.     transmitted as part of the segment.  While computing the checksum,
  1189.     the checksum field itself is replaced with zeros.
  1190.  
  1191.     The checksum also covers a 96 bit pseudo header conceptually
  1192.  
  1193.  
  1194. [Page 16]                                                               
  1195.  
  1196.  
  1197.  
  1198. September 1981                                                          
  1199.                                            Transmission Control Protocol
  1200.                                                 Functional Specification
  1201.  
  1202.  
  1203.  
  1204.     prefixed to the TCP header.  This pseudo header contains the Source
  1205.     Address, the Destination Address, the Protocol, and TCP length.
  1206.     This gives the TCP protection against misrouted segments.  This
  1207.     information is carried in the Internet Protocol and is transferred
  1208.     across the TCP/Network interface in the arguments or results of
  1209.     calls by the TCP on the IP.
  1210.  
  1211.                      +--------+--------+--------+--------+
  1212.                      |           Source Address          |
  1213.                      +--------+--------+--------+--------+
  1214.                      |         Destination Address       |
  1215.                      +--------+--------+--------+--------+
  1216.                      |  zero  |  PTCL  |    TCP Length   |
  1217.                      +--------+--------+--------+--------+
  1218.  
  1219.       The TCP Length is the TCP header length plus the data length in
  1220.       octets (this is not an explicitly transmitted quantity, but is
  1221.       computed), and it does not count the 12 octets of the pseudo
  1222.       header.
  1223.  
  1224.   Urgent Pointer:  16 bits
  1225.  
  1226.     This field communicates the current value of the urgent pointer as a
  1227.     positive offset from the sequence number in this segment.  The
  1228.     urgent pointer points to the sequence number of the octet following
  1229.     the urgent data.  This field is only be interpreted in segments with
  1230.     the URG control bit set.
  1231.  
  1232.   Options:  variable
  1233.  
  1234.     Options may occupy space at the end of the TCP header and are a
  1235.     multiple of 8 bits in length.  All options are included in the
  1236.     checksum.  An option may begin on any octet boundary.  There are two
  1237.     cases for the format of an option:
  1238.  
  1239.       Case 1:  A single octet of option-kind.
  1240.  
  1241.       Case 2:  An octet of option-kind, an octet of option-length, and
  1242.                the actual option-data octets.
  1243.  
  1244.     The option-length counts the two octets of option-kind and
  1245.     option-length as well as the option-data octets.
  1246.  
  1247.     Note that the list of options may be shorter than the data offset
  1248.     field might imply.  The content of the header beyond the
  1249.     End-of-Option option must be header padding (i.e., zero).
  1250.  
  1251.     A TCP must implement all options.
  1252.  
  1253.  
  1254.                                                                [Page 17]
  1255.  
  1256.  
  1257.  
  1258.                                                           September 1981
  1259. Transmission Control Protocol
  1260. Functional Specification
  1261.  
  1262.  
  1263.  
  1264.     Currently defined options include (kind indicated in octal):
  1265.  
  1266.       Kind     Length    Meaning
  1267.       ----     ------    -------
  1268.        0         -       End of option list.
  1269.        1         -       No-Operation.
  1270.        2         4       Maximum Segment Size.
  1271.       
  1272.  
  1273.     Specific Option Definitions
  1274.  
  1275.       End of Option List
  1276.  
  1277.         +--------+
  1278.         |00000000|
  1279.         +--------+
  1280.          Kind=0
  1281.  
  1282.         This option code indicates the end of the option list.  This
  1283.         might not coincide with the end of the TCP header according to
  1284.         the Data Offset field.  This is used at the end of all options,
  1285.         not the end of each option, and need only be used if the end of
  1286.         the options would not otherwise coincide with the end of the TCP
  1287.         header.
  1288.  
  1289.       No-Operation
  1290.  
  1291.         +--------+
  1292.         |00000001|
  1293.         +--------+
  1294.          Kind=1
  1295.  
  1296.         This option code may be used between options, for example, to
  1297.         align the beginning of a subsequent option on a word boundary.
  1298.         There is no guarantee that senders will use this option, so
  1299.         receivers must be prepared to process options even if they do
  1300.         not begin on a word boundary.
  1301.  
  1302.       Maximum Segment Size
  1303.  
  1304.         +--------+--------+---------+--------+
  1305.         |00000010|00000100|   max seg size   |
  1306.         +--------+--------+---------+--------+
  1307.          Kind=2   Length=4
  1308.  
  1309.  
  1310.  
  1311.  
  1312.  
  1313.  
  1314. [Page 18]                                                               
  1315.  
  1316.  
  1317.  
  1318. September 1981                                                          
  1319.                                            Transmission Control Protocol
  1320.                                                 Functional Specification
  1321.  
  1322.  
  1323.  
  1324.         Maximum Segment Size Option Data:  16 bits
  1325.  
  1326.           If this option is present, then it communicates the maximum
  1327.           receive segment size at the TCP which sends this segment.
  1328.           This field must only be sent in the initial connection request
  1329.           (i.e., in segments with the SYN control bit set).  If this
  1330.           option is not used, any segment size is allowed.
  1331.  
  1332.   Padding:  variable
  1333.  
  1334.     The TCP header padding is used to ensure that the TCP header ends
  1335.     and data begins on a 32 bit boundary.  The padding is composed of
  1336.     zeros.
  1337.  
  1338. 3.2.  Terminology
  1339.  
  1340.   Before we can discuss very much about the operation of the TCP we need
  1341.   to introduce some detailed terminology.  The maintenance of a TCP
  1342.   connection requires the remembering of several variables.  We conceive
  1343.   of these variables being stored in a connection record called a
  1344.   Transmission Control Block or TCB.  Among the variables stored in the
  1345.   TCB are the local and remote socket numbers, the security and
  1346.   precedence of the connection, pointers to the user's send and receive
  1347.   buffers, pointers to the retransmit queue and to the current segment.
  1348.   In addition several variables relating to the send and receive
  1349.   sequence numbers are stored in the TCB.
  1350.  
  1351.     Send Sequence Variables
  1352.  
  1353.       SND.UNA - send unacknowledged
  1354.       SND.NXT - send next
  1355.       SND.WND - send window
  1356.       SND.UP  - send urgent pointer
  1357.       SND.WL1 - segment sequence number used for last window update
  1358.       SND.WL2 - segment acknowledgment number used for last window
  1359.                 update
  1360.       ISS     - initial send sequence number
  1361.  
  1362.     Receive Sequence Variables
  1363.  
  1364.       RCV.NXT - receive next
  1365.       RCV.WND - receive window
  1366.       RCV.UP  - receive urgent pointer
  1367.       IRS     - initial receive sequence number
  1368.  
  1369.  
  1370.  
  1371.  
  1372.  
  1373.  
  1374.                                                                [Page 19]
  1375.  
  1376.  
  1377.  
  1378.                                                           September 1981
  1379. Transmission Control Protocol
  1380. Functional Specification
  1381.  
  1382.  
  1383.  
  1384.   The following diagrams may help to relate some of these variables to
  1385.   the sequence space.
  1386.  
  1387.   Send Sequence Space
  1388.  
  1389.                    1         2          3          4      
  1390.               ----------|----------|----------|---------- 
  1391.                      SND.UNA    SND.NXT    SND.UNA        
  1392.                                           +SND.WND        
  1393.  
  1394.         1 - old sequence numbers which have been acknowledged  
  1395.         2 - sequence numbers of unacknowledged data            
  1396.         3 - sequence numbers allowed for new data transmission 
  1397.         4 - future sequence numbers which are not yet allowed  
  1398.  
  1399.                           Send Sequence Space
  1400.  
  1401.                                Figure 4.
  1402.     
  1403.     
  1404.  
  1405.   The send window is the portion of the sequence space labeled 3 in
  1406.   figure 4.
  1407.  
  1408.   Receive Sequence Space
  1409.  
  1410.                        1          2          3      
  1411.                    ----------|----------|---------- 
  1412.                           RCV.NXT    RCV.NXT        
  1413.                                     +RCV.WND        
  1414.  
  1415.         1 - old sequence numbers which have been acknowledged  
  1416.         2 - sequence numbers allowed for new reception         
  1417.         3 - future sequence numbers which are not yet allowed  
  1418.  
  1419.                          Receive Sequence Space
  1420.  
  1421.                                Figure 5.
  1422.     
  1423.     
  1424.  
  1425.   The receive window is the portion of the sequence space labeled 2 in
  1426.   figure 5.
  1427.  
  1428.   There are also some variables used frequently in the discussion that
  1429.   take their values from the fields of the current segment.
  1430.  
  1431.  
  1432.  
  1433.  
  1434. [Page 20]                                                               
  1435.  
  1436.  
  1437.  
  1438. September 1981                                                          
  1439.                                            Transmission Control Protocol
  1440.                                                 Functional Specification
  1441.  
  1442.  
  1443.  
  1444.     Current Segment Variables
  1445.  
  1446.       SEG.SEQ - segment sequence number
  1447.       SEG.ACK - segment acknowledgment number
  1448.       SEG.LEN - segment length
  1449.       SEG.WND - segment window
  1450.       SEG.UP  - segment urgent pointer
  1451.       SEG.PRC - segment precedence value
  1452.  
  1453.   A connection progresses through a series of states during its
  1454.   lifetime.  The states are:  LISTEN, SYN-SENT, SYN-RECEIVED,
  1455.   ESTABLISHED, FIN-WAIT-1, FIN-WAIT-2, CLOSE-WAIT, CLOSING, LAST-ACK,
  1456.   TIME-WAIT, and the fictional state CLOSED.  CLOSED is fictional
  1457.   because it represents the state when there is no TCB, and therefore,
  1458.   no connection.  Briefly the meanings of the states are:
  1459.  
  1460.     LISTEN - represents waiting for a connection request from any remote
  1461.     TCP and port.
  1462.  
  1463.     SYN-SENT - represents waiting for a matching connection request
  1464.     after having sent a connection request.
  1465.  
  1466.     SYN-RECEIVED - represents waiting for a confirming connection
  1467.     request acknowledgment after having both received and sent a
  1468.     connection request.
  1469.  
  1470.     ESTABLISHED - represents an open connection, data received can be
  1471.     delivered to the user.  The normal state for the data transfer phase
  1472.     of the connection.
  1473.  
  1474.     FIN-WAIT-1 - represents waiting for a connection termination request
  1475.     from the remote TCP, or an acknowledgment of the connection
  1476.     termination request previously sent.
  1477.  
  1478.     FIN-WAIT-2 - represents waiting for a connection termination request
  1479.     from the remote TCP.
  1480.  
  1481.     CLOSE-WAIT - represents waiting for a connection termination request
  1482.     from the local user.
  1483.  
  1484.     CLOSING - represents waiting for a connection termination request
  1485.     acknowledgment from the remote TCP.
  1486.  
  1487.     LAST-ACK - represents waiting for an acknowledgment of the
  1488.     connection termination request previously sent to the remote TCP
  1489.     (which includes an acknowledgment of its connection termination
  1490.     request).
  1491.  
  1492.  
  1493.  
  1494.                                                                [Page 21]
  1495.  
  1496.  
  1497.  
  1498.                                                           September 1981
  1499. Transmission Control Protocol
  1500. Functional Specification
  1501.  
  1502.  
  1503.  
  1504.     TIME-WAIT - represents waiting for enough time to pass to be sure
  1505.     the remote TCP received the acknowledgment of its connection
  1506.     termination request.
  1507.  
  1508.     CLOSED - represents no connection state at all.
  1509.  
  1510.   A TCP connection progresses from one state to another in response to
  1511.   events.  The events are the user calls, OPEN, SEND, RECEIVE, CLOSE,
  1512.   ABORT, and STATUS; the incoming segments, particularly those
  1513.   containing the SYN, ACK, RST and FIN flags; and timeouts.
  1514.  
  1515.   The state diagram in figure 6 illustrates only state changes, together
  1516.   with the causing events and resulting actions, but addresses neither
  1517.   error conditions nor actions which are not connected with state
  1518.   changes.  In a later section, more detail is offered with respect to
  1519.   the reaction of the TCP to events.
  1520.  
  1521.   NOTE BENE:  this diagram is only a summary and must not be taken as
  1522.   the total specification.
  1523.  
  1524.  
  1525.  
  1526.  
  1527.  
  1528.  
  1529.  
  1530.  
  1531.  
  1532.  
  1533.  
  1534.  
  1535.  
  1536.  
  1537.  
  1538.  
  1539.  
  1540.  
  1541.  
  1542.  
  1543.  
  1544.  
  1545.  
  1546.  
  1547.  
  1548.  
  1549.  
  1550.  
  1551.  
  1552.  
  1553.  
  1554. [Page 22]                                                               
  1555.  
  1556.  
  1557.  
  1558. September 1981                                                          
  1559.                                            Transmission Control Protocol
  1560.                                                 Functional Specification
  1561.  
  1562.  
  1563.  
  1564.                                     
  1565.                               +---------+ ---------\      active OPEN  
  1566.                               |  CLOSED |            \    -----------  
  1567.                               +---------+<---------\   \   create TCB  
  1568.                                 |     ^              \   \  snd SYN    
  1569.                    passive OPEN |     |   CLOSE        \   \           
  1570.                    ------------ |     | ----------       \   \         
  1571.                     create TCB  |     | delete TCB         \   \       
  1572.                                 V     |                      \   \     
  1573.                               +---------+            CLOSE    |    \   
  1574.                               |  LISTEN |          ---------- |     |  
  1575.                               +---------+          delete TCB |     |  
  1576.                    rcv SYN      |     |     SEND              |     |  
  1577.                   -----------   |     |    -------            |     V  
  1578.  +---------+      snd SYN,ACK  /       \   snd SYN          +---------+
  1579.  |         |<-----------------           ------------------>|         |
  1580.  |   SYN   |                    rcv SYN                     |   SYN   |
  1581.  |   RCVD  |<-----------------------------------------------|   SENT  |
  1582.  |         |                    snd ACK                     |         |
  1583.  |         |------------------           -------------------|         |
  1584.  +---------+   rcv ACK of SYN  \       /  rcv SYN,ACK       +---------+
  1585.    |           --------------   |     |   -----------                  
  1586.    |                  x         |     |     snd ACK                    
  1587.    |                            V     V                                
  1588.    |  CLOSE                   +---------+                              
  1589.    | -------                  |  ESTAB  |                              
  1590.    | snd FIN                  +---------+                              
  1591.    |                   CLOSE    |     |    rcv FIN                     
  1592.    V                  -------   |     |    -------                     
  1593.  +---------+          snd FIN  /       \   snd ACK          +---------+
  1594.  |  FIN    |<-----------------           ------------------>|  CLOSE  |
  1595.  | WAIT-1  |------------------                              |   WAIT  |
  1596.  +---------+          rcv FIN  \                            +---------+
  1597.    | rcv ACK of FIN   -------   |                            CLOSE  |  
  1598.    | --------------   snd ACK   |                           ------- |  
  1599.    V        x                   V                           snd FIN V  
  1600.  +---------+                  +---------+                   +---------+
  1601.  |FINWAIT-2|                  | CLOSING |                   | LAST-ACK|
  1602.  +---------+                  +---------+                   +---------+
  1603.    |                rcv ACK of FIN |                 rcv ACK of FIN |  
  1604.    |  rcv FIN       -------------- |    Timeout=2MSL -------------- |  
  1605.    |  -------              x       V    ------------        x       V  
  1606.     \ snd ACK                 +---------+delete TCB         +---------+
  1607.      ------------------------>|TIME WAIT|------------------>| CLOSED  |
  1608.                               +---------+                   +---------+
  1609.  
  1610.                       TCP Connection State Diagram
  1611.                                Figure 6.
  1612.  
  1613.  
  1614.                                                                [Page 23]
  1615.  
  1616.  
  1617.  
  1618.                                                           September 1981
  1619. Transmission Control Protocol
  1620. Functional Specification
  1621.  
  1622.  
  1623.  
  1624. 3.3.  Sequence Numbers
  1625.  
  1626.   A fundamental notion in the design is that every octet of data sent
  1627.   over a TCP connection has a sequence number.  Since every octet is
  1628.   sequenced, each of them can be acknowledged.  The acknowledgment
  1629.   mechanism employed is cumulative so that an acknowledgment of sequence
  1630.   number X indicates that all octets up to but not including X have been
  1631.   received.  This mechanism allows for straight-forward duplicate
  1632.   detection in the presence of retransmission.  Numbering of octets
  1633.   within a segment is that the first data octet immediately following
  1634.   the header is the lowest numbered, and the following octets are
  1635.   numbered consecutively.
  1636.  
  1637.   It is essential to remember that the actual sequence number space is
  1638.   finite, though very large.  This space ranges from 0 to 2**32 - 1.
  1639.   Since the space is finite, all arithmetic dealing with sequence
  1640.   numbers must be performed modulo 2**32.  This unsigned arithmetic
  1641.   preserves the relationship of sequence numbers as they cycle from
  1642.   2**32 - 1 to 0 again.  There are some subtleties to computer modulo
  1643.   arithmetic, so great care should be taken in programming the
  1644.   comparison of such values.  The symbol "=<" means "less than or equal"
  1645.   (modulo 2**32).
  1646.  
  1647.   The typical kinds of sequence number comparisons which the TCP must
  1648.   perform include:
  1649.  
  1650.     (a)  Determining that an acknowledgment refers to some sequence
  1651.          number sent but not yet acknowledged.
  1652.  
  1653.     (b)  Determining that all sequence numbers occupied by a segment
  1654.          have been acknowledged (e.g., to remove the segment from a
  1655.          retransmission queue).
  1656.  
  1657.     (c)  Determining that an incoming segment contains sequence numbers
  1658.          which are expected (i.e., that the segment "overlaps" the
  1659.          receive window).
  1660.  
  1661.  
  1662.  
  1663.  
  1664.  
  1665.  
  1666.  
  1667.  
  1668.  
  1669.  
  1670.  
  1671.  
  1672.  
  1673.  
  1674. [Page 24]                                                               
  1675.  
  1676.  
  1677.  
  1678. September 1981                                                          
  1679.                                            Transmission Control Protocol
  1680.                                                 Functional Specification
  1681.  
  1682.  
  1683.  
  1684.   In response to sending data the TCP will receive acknowledgments.  The
  1685.   following comparisons are needed to process the acknowledgments.
  1686.  
  1687.     SND.UNA = oldest unacknowledged sequence number
  1688.  
  1689.     SND.NXT = next sequence number to be sent
  1690.  
  1691.     SEG.ACK = acknowledgment from the receiving TCP (next sequence
  1692.               number expected by the receiving TCP)
  1693.  
  1694.     SEG.SEQ = first sequence number of a segment
  1695.  
  1696.     SEG.LEN = the number of octets occupied by the data in the segment
  1697.               (counting SYN and FIN)
  1698.  
  1699.     SEG.SEQ+SEG.LEN-1 = last sequence number of a segment
  1700.  
  1701.   A new acknowledgment (called an "acceptable ack"), is one for which
  1702.   the inequality below holds:
  1703.  
  1704.     SND.UNA < SEG.ACK =< SND.NXT
  1705.  
  1706.   A segment on the retransmission queue is fully acknowledged if the sum
  1707.   of its sequence number and length is less or equal than the
  1708.   acknowledgment value in the incoming segment.
  1709.  
  1710.   When data is received the following comparisons are needed:
  1711.  
  1712.     RCV.NXT = next sequence number expected on an incoming segments, and
  1713.         is the left or lower edge of the receive window
  1714.  
  1715.     RCV.NXT+RCV.WND-1 = last sequence number expected on an incoming
  1716.         segment, and is the right or upper edge of the receive window
  1717.  
  1718.     SEG.SEQ = first sequence number occupied by the incoming segment
  1719.  
  1720.     SEG.SEQ+SEG.LEN-1 = last sequence number occupied by the incoming
  1721.         segment
  1722.  
  1723.   A segment is judged to occupy a portion of valid receive sequence
  1724.   space if
  1725.  
  1726.     RCV.NXT =< SEG.SEQ < RCV.NXT+RCV.WND
  1727.  
  1728.   or
  1729.  
  1730.     RCV.NXT =< SEG.SEQ+SEG.LEN-1 < RCV.NXT+RCV.WND
  1731.  
  1732.  
  1733.  
  1734.                                                                [Page 25]
  1735.  
  1736.  
  1737.  
  1738.                                                           September 1981
  1739. Transmission Control Protocol
  1740. Functional Specification
  1741.  
  1742.  
  1743.  
  1744.   The first part of this test checks to see if the beginning of the
  1745.   segment falls in the window, the second part of the test checks to see
  1746.   if the end of the segment falls in the window; if the segment passes
  1747.   either part of the test it contains data in the window.
  1748.  
  1749.   Actually, it is a little more complicated than this.  Due to zero
  1750.   windows and zero length segments, we have four cases for the
  1751.   acceptability of an incoming segment:
  1752.  
  1753.     Segment Receive  Test
  1754.     Length  Window
  1755.     ------- -------  -------------------------------------------
  1756.  
  1757.        0       0     SEG.SEQ = RCV.NXT
  1758.  
  1759.        0      >0     RCV.NXT =< SEG.SEQ < RCV.NXT+RCV.WND
  1760.  
  1761.       >0       0     not acceptable
  1762.  
  1763.       >0      >0     RCV.NXT =< SEG.SEQ < RCV.NXT+RCV.WND
  1764.                   or RCV.NXT =< SEG.SEQ+SEG.LEN-1 < RCV.NXT+RCV.WND
  1765.  
  1766.   Note that when the receive window is zero no segments should be
  1767.   acceptable except ACK segments.  Thus, it is be possible for a TCP to
  1768.   maintain a zero receive window while transmitting data and receiving
  1769.   ACKs.  However, even when the receive window is zero, a TCP must
  1770.   process the RST and URG fields of all incoming segments.
  1771.  
  1772.   We have taken advantage of the numbering scheme to protect certain
  1773.   control information as well.  This is achieved by implicitly including
  1774.   some control flags in the sequence space so they can be retransmitted
  1775.   and acknowledged without confusion (i.e., one and only one copy of the
  1776.   control will be acted upon).  Control information is not physically
  1777.   carried in the segment data space.  Consequently, we must adopt rules
  1778.   for implicitly assigning sequence numbers to control.  The SYN and FIN
  1779.   are the only controls requiring this protection, and these controls
  1780.   are used only at connection opening and closing.  For sequence number
  1781.   purposes, the SYN is considered to occur before the first actual data
  1782.   octet of the segment in which it occurs, while the FIN is considered
  1783.   to occur after the last actual data octet in a segment in which it
  1784.   occurs.  The segment length (SEG.LEN) includes both data and sequence
  1785.   space occupying controls.  When a SYN is present then SEG.SEQ is the
  1786.   sequence number of the SYN.
  1787.  
  1788.  
  1789.  
  1790.  
  1791.  
  1792.  
  1793.  
  1794. [Page 26]                                                               
  1795.  
  1796.  
  1797.  
  1798. September 1981                                                          
  1799.                                            Transmission Control Protocol
  1800.                                                 Functional Specification
  1801.  
  1802.  
  1803.  
  1804.   Initial Sequence Number Selection
  1805.  
  1806.   The protocol places no restriction on a particular connection being
  1807.   used over and over again.  A connection is defined by a pair of
  1808.   sockets.  New instances of a connection will be referred to as
  1809.   incarnations of the connection.  The problem that arises from this is
  1810.   -- "how does the TCP identify duplicate segments from previous
  1811.   incarnations of the connection?"  This problem becomes apparent if the
  1812.   connection is being opened and closed in quick succession, or if the
  1813.   connection breaks with loss of memory and is then reestablished.
  1814.  
  1815.   To avoid confusion we must prevent segments from one incarnation of a
  1816.   connection from being used while the same sequence numbers may still
  1817.   be present in the network from an earlier incarnation.  We want to
  1818.   assure this, even if a TCP crashes and loses all knowledge of the
  1819.   sequence numbers it has been using.  When new connections are created,
  1820.   an initial sequence number (ISN) generator is employed which selects a
  1821.   new 32 bit ISN.  The generator is bound to a (possibly fictitious) 32
  1822.   bit clock whose low order bit is incremented roughly every 4
  1823.   microseconds.  Thus, the ISN cycles approximately every 4.55 hours.
  1824.   Since we assume that segments will stay in the network no more than
  1825.   the Maximum Segment Lifetime (MSL) and that the MSL is less than 4.55
  1826.   hours we can reasonably assume that ISN's will be unique.
  1827.  
  1828.   For each connection there is a send sequence number and a receive
  1829.   sequence number.  The initial send sequence number (ISS) is chosen by
  1830.   the data sending TCP, and the initial receive sequence number (IRS) is
  1831.   learned during the connection establishing procedure.
  1832.  
  1833.   For a connection to be established or initialized, the two TCPs must
  1834.   synchronize on each other's initial sequence numbers.  This is done in
  1835.   an exchange of connection establishing segments carrying a control bit
  1836.   called "SYN" (for synchronize) and the initial sequence numbers.  As a
  1837.   shorthand, segments carrying the SYN bit are also called "SYNs".
  1838.   Hence, the solution requires a suitable mechanism for picking an
  1839.   initial sequence number and a slightly involved handshake to exchange
  1840.   the ISN's.
  1841.  
  1842.   The synchronization requires each side to send it's own initial
  1843.   sequence number and to receive a confirmation of it in acknowledgment
  1844.   from the other side.  Each side must also receive the other side's
  1845.   initial sequence number and send a confirming acknowledgment.
  1846.  
  1847.     1) A --> B  SYN my sequence number is X
  1848.     2) A <-- B  ACK your sequence number is X
  1849.     3) A <-- B  SYN my sequence number is Y
  1850.     4) A --> B  ACK your sequence number is Y
  1851.  
  1852.  
  1853.  
  1854.                                                                [Page 27]
  1855.  
  1856.  
  1857.  
  1858.                                                           September 1981
  1859. Transmission Control Protocol
  1860. Functional Specification
  1861.  
  1862.  
  1863.  
  1864.   Because steps 2 and 3 can be combined in a single message this is
  1865.   called the three way (or three message) handshake.
  1866.  
  1867.   A three way handshake is necessary because sequence numbers are not
  1868.   tied to a global clock in the network, and TCPs may have different
  1869.   mechanisms for picking the ISN's.  The receiver of the first SYN has
  1870.   no way of knowing whether the segment was an old delayed one or not,
  1871.   unless it remembers the last sequence number used on the connection
  1872.   (which is not always possible), and so it must ask the sender to
  1873.   verify this SYN.  The three way handshake and the advantages of a
  1874.   clock-driven scheme are discussed in [3].
  1875.  
  1876.   Knowing When to Keep Quiet
  1877.  
  1878.   To be sure that a TCP does not create a segment that carries a
  1879.   sequence number which may be duplicated by an old segment remaining in
  1880.   the network, the TCP must keep quiet for a maximum segment lifetime
  1881.   (MSL) before assigning any sequence numbers upon starting up or
  1882.   recovering from a crash in which memory of sequence numbers in use was
  1883.   lost.  For this specification the MSL is taken to be 2 minutes.  This
  1884.   is an engineering choice, and may be changed if experience indicates
  1885.   it is desirable to do so.  Note that if a TCP is reinitialized in some
  1886.   sense, yet retains its memory of sequence numbers in use, then it need
  1887.   not wait at all; it must only be sure to use sequence numbers larger
  1888.   than those recently used.
  1889.  
  1890.   The TCP Quiet Time Concept
  1891.  
  1892.     This specification provides that hosts which "crash" without
  1893.     retaining any knowledge of the last sequence numbers transmitted on
  1894.     each active (i.e., not closed) connection shall delay emitting any
  1895.     TCP segments for at least the agreed Maximum Segment Lifetime (MSL)
  1896.     in the internet system of which the host is a part.  In the
  1897.     paragraphs below, an explanation for this specification is given.
  1898.     TCP implementors may violate the "quiet time" restriction, but only
  1899.     at the risk of causing some old data to be accepted as new or new
  1900.     data rejected as old duplicated by some receivers in the internet
  1901.     system.
  1902.  
  1903.     TCPs consume sequence number space each time a segment is formed and
  1904.     entered into the network output queue at a source host. The
  1905.     duplicate detection and sequencing algorithm in the TCP protocol
  1906.     relies on the unique binding of segment data to sequence space to
  1907.     the extent that sequence numbers will not cycle through all 2**32
  1908.     values before the segment data bound to those sequence numbers has
  1909.     been delivered and acknowledged by the receiver and all duplicate
  1910.     copies of the segments have "drained" from the internet.  Without
  1911.     such an assumption, two distinct TCP segments could conceivably be
  1912.  
  1913.  
  1914. [Page 28]                                                               
  1915.  
  1916.  
  1917.  
  1918. September 1981                                                          
  1919.                                            Transmission Control Protocol
  1920.                                                 Functional Specification
  1921.  
  1922.  
  1923.  
  1924.     assigned the same or overlapping sequence numbers, causing confusion
  1925.     at the receiver as to which data is new and which is old.  Remember
  1926.     that each segment is bound to as many consecutive sequence numbers
  1927.     as there are octets of data in the segment.
  1928.  
  1929.     Under normal conditions, TCPs keep track of the next sequence number
  1930.     to emit and the oldest awaiting acknowledgment so as to avoid
  1931.     mistakenly using a sequence number over before its first use has
  1932.     been acknowledged.  This alone does not guarantee that old duplicate
  1933.     data is drained from the net, so the sequence space has been made
  1934.     very large to reduce the probability that a wandering duplicate will
  1935.     cause trouble upon arrival.  At 2 megabits/sec. it takes 4.5 hours
  1936.     to use up 2**32 octets of sequence space.  Since the maximum segment
  1937.     lifetime in the net is not likely to exceed a few tens of seconds,
  1938.     this is deemed ample protection for foreseeable nets, even if data
  1939.     rates escalate to l0's of megabits/sec.  At 100 megabits/sec, the
  1940.     cycle time is 5.4 minutes which may be a little short, but still
  1941.     within reason.
  1942.  
  1943.     The basic duplicate detection and sequencing algorithm in TCP can be
  1944.     defeated, however, if a source TCP does not have any memory of the
  1945.     sequence numbers it last used on a given connection. For example, if
  1946.     the TCP were to start all connections with sequence number 0, then
  1947.     upon crashing and restarting, a TCP might re-form an earlier
  1948.     connection (possibly after half-open connection resolution) and emit
  1949.     packets with sequence numbers identical to or overlapping with
  1950.     packets still in the network which were emitted on an earlier
  1951.     incarnation of the same connection.  In the absence of knowledge
  1952.     about the sequence numbers used on a particular connection, the TCP
  1953.     specification recommends that the source delay for MSL seconds
  1954.     before emitting segments on the connection, to allow time for
  1955.     segments from the earlier connection incarnation to drain from the
  1956.     system.
  1957.  
  1958.     Even hosts which can remember the time of day and used it to select
  1959.     initial sequence number values are not immune from this problem
  1960.     (i.e., even if time of day is used to select an initial sequence
  1961.     number for each new connection incarnation).
  1962.  
  1963.     Suppose, for example, that a connection is opened starting with
  1964.     sequence number S.  Suppose that this connection is not used much
  1965.     and that eventually the initial sequence number function (ISN(t))
  1966.     takes on a value equal to the sequence number, say S1, of the last
  1967.     segment sent by this TCP on a particular connection.  Now suppose,
  1968.     at this instant, the host crashes, recovers, and establishes a new
  1969.     incarnation of the connection. The initial sequence number chosen is
  1970.     S1 = ISN(t) -- last used sequence number on old incarnation of
  1971.     connection!  If the recovery occurs quickly enough, any old
  1972.  
  1973.  
  1974.                                                                [Page 29]
  1975.  
  1976.  
  1977.  
  1978.                                                           September 1981
  1979. Transmission Control Protocol
  1980. Functional Specification
  1981.  
  1982.  
  1983.  
  1984.     duplicates in the net bearing sequence numbers in the neighborhood
  1985.     of S1 may arrive and be treated as new packets by the receiver of
  1986.     the new incarnation of the connection.
  1987.  
  1988.     The problem is that the recovering host may not know for how long it
  1989.     crashed nor does it know whether there are still old duplicates in
  1990.     the system from earlier connection incarnations.
  1991.  
  1992.     One way to deal with this problem is to deliberately delay emitting
  1993.     segments for one MSL after recovery from a crash- this is the "quite
  1994.     time" specification.  Hosts which prefer to avoid waiting are
  1995.     willing to risk possible confusion of old and new packets at a given
  1996.     destination may choose not to wait for the "quite time".
  1997.     Implementors may provide TCP users with the ability to select on a
  1998.     connection by connection basis whether to wait after a crash, or may
  1999.     informally implement the "quite time" for all connections.
  2000.     Obviously, even where a user selects to "wait," this is not
  2001.     necessary after the host has been "up" for at least MSL seconds.
  2002.  
  2003.     To summarize: every segment emitted occupies one or more sequence
  2004.     numbers in the sequence space, the numbers occupied by a segment are
  2005.     "busy" or "in use" until MSL seconds have passed, upon crashing a
  2006.     block of space-time is occupied by the octets of the last emitted
  2007.     segment, if a new connection is started too soon and uses any of the
  2008.     sequence numbers in the space-time footprint of the last segment of
  2009.     the previous connection incarnation, there is a potential sequence
  2010.     number overlap area which could cause confusion at the receiver.
  2011.  
  2012. 3.4.  Establishing a connection
  2013.  
  2014.   The "three-way handshake" is the procedure used to establish a
  2015.   connection.  This procedure normally is initiated by one TCP and
  2016.   responded to by another TCP.  The procedure also works if two TCP
  2017.   simultaneously initiate the procedure.  When simultaneous attempt
  2018.   occurs, each TCP receives a "SYN" segment which carries no
  2019.   acknowledgment after it has sent a "SYN".  Of course, the arrival of
  2020.   an old duplicate "SYN" segment can potentially make it appear, to the
  2021.   recipient, that a simultaneous connection initiation is in progress.
  2022.   Proper use of "reset" segments can disambiguate these cases.
  2023.  
  2024.   Several examples of connection initiation follow.  Although these
  2025.   examples do not show connection synchronization using data-carrying
  2026.   segments, this is perfectly legitimate, so long as the receiving TCP
  2027.   doesn't deliver the data to the user until it is clear the data is
  2028.   valid (i.e., the data must be buffered at the receiver until the
  2029.   connection reaches the ESTABLISHED state).  The three-way handshake
  2030.   reduces the possibility of false connections.  It is the
  2031.  
  2032.  
  2033.  
  2034. [Page 30]                                                               
  2035.  
  2036.  
  2037.  
  2038. September 1981                                                          
  2039.                                            Transmission Control Protocol
  2040.                                                 Functional Specification
  2041.  
  2042.  
  2043.  
  2044.   implementation of a trade-off between memory and messages to provide
  2045.   information for this checking.
  2046.  
  2047.   The simplest three-way handshake is shown in figure 7 below.  The
  2048.   figures should be interpreted in the following way.  Each line is
  2049.   numbered for reference purposes.  Right arrows (-->) indicate
  2050.   departure of a TCP segment from TCP A to TCP B, or arrival of a
  2051.   segment at B from A.  Left arrows (<--), indicate the reverse.
  2052.   Ellipsis (...) indicates a segment which is still in the network
  2053.   (delayed).  An "XXX" indicates a segment which is lost or rejected.
  2054.   Comments appear in parentheses.  TCP states represent the state AFTER
  2055.   the departure or arrival of the segment (whose contents are shown in
  2056.   the center of each line).  Segment contents are shown in abbreviated
  2057.   form, with sequence number, control flags, and ACK field.  Other
  2058.   fields such as window, addresses, lengths, and text have been left out
  2059.   in the interest of clarity.
  2060.  
  2061.   
  2062.  
  2063.       TCP A                                                TCP B
  2064.  
  2065.   1.  CLOSED                                               LISTEN
  2066.  
  2067.   2.  SYN-SENT    --> <SEQ=100><CTL=SYN>               --> SYN-RECEIVED
  2068.  
  2069.   3.  ESTABLISHED <-- <SEQ=300><ACK=101><CTL=SYN,ACK>  <-- SYN-RECEIVED
  2070.  
  2071.   4.  ESTABLISHED --> <SEQ=101><ACK=301><CTL=ACK>       --> ESTABLISHED
  2072.  
  2073.   5.  ESTABLISHED --> <SEQ=101><ACK=301><CTL=ACK><DATA> --> ESTABLISHED
  2074.  
  2075.           Basic 3-Way Handshake for Connection Synchronization
  2076.  
  2077.                                 Figure 7.
  2078.  
  2079.   In line 2 of figure 7, TCP A begins by sending a SYN segment
  2080.   indicating that it will use sequence numbers starting with sequence
  2081.   number 100.  In line 3, TCP B sends a SYN and acknowledges the SYN it
  2082.   received from TCP A.  Note that the acknowledgment field indicates TCP
  2083.   B is now expecting to hear sequence 101, acknowledging the SYN which
  2084.   occupied sequence 100.
  2085.  
  2086.   At line 4, TCP A responds with an empty segment containing an ACK for
  2087.   TCP B's SYN; and in line 5, TCP A sends some data.  Note that the
  2088.   sequence number of the segment in line 5 is the same as in line 4
  2089.   because the ACK does not occupy sequence number space (if it did, we
  2090.   would wind up ACKing ACK's!).
  2091.  
  2092.  
  2093.  
  2094.                                                                [Page 31]
  2095.  
  2096.  
  2097.  
  2098.                                                           September 1981
  2099. Transmission Control Protocol
  2100. Functional Specification
  2101.  
  2102.  
  2103.  
  2104.   Simultaneous initiation is only slightly more complex, as is shown in
  2105.   figure 8.  Each TCP cycles from CLOSED to SYN-SENT to SYN-RECEIVED to
  2106.   ESTABLISHED.
  2107.  
  2108.   
  2109.  
  2110.       TCP A                                            TCP B
  2111.  
  2112.   1.  CLOSED                                           CLOSED
  2113.  
  2114.   2.  SYN-SENT     --> <SEQ=100><CTL=SYN>              ...
  2115.  
  2116.   3.  SYN-RECEIVED <-- <SEQ=300><CTL=SYN>              <-- SYN-SENT
  2117.  
  2118.   4.               ... <SEQ=100><CTL=SYN>              --> SYN-RECEIVED
  2119.  
  2120.   5.  SYN-RECEIVED --> <SEQ=100><ACK=301><CTL=SYN,ACK> ...
  2121.  
  2122.   6.  ESTABLISHED  <-- <SEQ=300><ACK=101><CTL=SYN,ACK> <-- SYN-RECEIVED
  2123.  
  2124.   7.               ... <SEQ=101><ACK=301><CTL=ACK>     --> ESTABLISHED
  2125.  
  2126.                 Simultaneous Connection Synchronization
  2127.  
  2128.                                Figure 8.
  2129.  
  2130.   The principle reason for the three-way handshake is to prevent old
  2131.   duplicate connection initiations from causing confusion.  To deal with
  2132.   this, a special control message, reset, has been devised.  If the
  2133.   receiving TCP is in a  non-synchronized state (i.e., SYN-SENT,
  2134.   SYN-RECEIVED), it returns to LISTEN on receiving an acceptable reset.
  2135.   If the TCP is in one of the synchronized states (ESTABLISHED,
  2136.   FIN-WAIT-1, FIN-WAIT-2, CLOSE-WAIT, CLOSING, LAST-ACK, TIME-WAIT), it
  2137.   aborts the connection and informs its user.  We discuss this latter
  2138.   case under "half-open" connections below.
  2139.  
  2140.  
  2141.  
  2142.  
  2143.  
  2144.  
  2145.  
  2146.  
  2147.  
  2148.  
  2149.  
  2150.  
  2151.  
  2152.  
  2153.  
  2154. [Page 32]                                                               
  2155.  
  2156.  
  2157.  
  2158. September 1981                                                          
  2159.                                            Transmission Control Protocol
  2160.                                                 Functional Specification
  2161.  
  2162.  
  2163.  
  2164.   
  2165.  
  2166.       TCP A                                                TCP B
  2167.  
  2168.   1.  CLOSED                                               LISTEN
  2169.  
  2170.   2.  SYN-SENT    --> <SEQ=100><CTL=SYN>               ...
  2171.  
  2172.   3.  (duplicate) ... <SEQ=90><CTL=SYN>               --> SYN-RECEIVED
  2173.  
  2174.   4.  SYN-SENT    <-- <SEQ=300><ACK=91><CTL=SYN,ACK>  <-- SYN-RECEIVED
  2175.  
  2176.   5.  SYN-SENT    --> <SEQ=91><CTL=RST>               --> LISTEN
  2177.   
  2178.  
  2179.   6.              ... <SEQ=100><CTL=SYN>               --> SYN-RECEIVED
  2180.  
  2181.   7.  SYN-SENT    <-- <SEQ=400><ACK=101><CTL=SYN,ACK>  <-- SYN-RECEIVED
  2182.  
  2183.   8.  ESTABLISHED --> <SEQ=101><ACK=401><CTL=ACK>      --> ESTABLISHED
  2184.  
  2185.                     Recovery from Old Duplicate SYN
  2186.  
  2187.                                Figure 9.
  2188.  
  2189.   As a simple example of recovery from old duplicates, consider
  2190.   figure 9.  At line 3, an old duplicate SYN arrives at TCP B.  TCP B
  2191.   cannot tell that this is an old duplicate, so it responds normally
  2192.   (line 4).  TCP A detects that the ACK field is incorrect and returns a
  2193.   RST (reset) with its SEQ field selected to make the segment
  2194.   believable.  TCP B, on receiving the RST, returns to the LISTEN state.
  2195.   When the original SYN (pun intended) finally arrives at line 6, the
  2196.   synchronization proceeds normally.  If the SYN at line 6 had arrived
  2197.   before the RST, a more complex exchange might have occurred with RST's
  2198.   sent in both directions.
  2199.  
  2200.   Half-Open Connections and Other Anomalies
  2201.  
  2202.   An established connection is said to be  "half-open" if one of the
  2203.   TCPs has closed or aborted the connection at its end without the
  2204.   knowledge of the other, or if the two ends of the connection have
  2205.   become desynchronized owing to a crash that resulted in loss of
  2206.   memory.  Such connections will automatically become reset if an
  2207.   attempt is made to send data in either direction.  However, half-open
  2208.   connections are expected to be unusual, and the recovery procedure is
  2209.   mildly involved.
  2210.  
  2211.   If at site A the connection no longer exists, then an attempt by the
  2212.  
  2213.  
  2214.                                                                [Page 33]
  2215.  
  2216.  
  2217.  
  2218.                                                           September 1981
  2219. Transmission Control Protocol
  2220. Functional Specification
  2221.  
  2222.  
  2223.  
  2224.   user at site B to send any data on it will result in the site B TCP
  2225.   receiving a reset control message.  Such a message indicates to the
  2226.   site B TCP that something is wrong, and it is expected to abort the
  2227.   connection.
  2228.  
  2229.   Assume that two user processes A and B are communicating with one
  2230.   another when a crash occurs causing loss of memory to A's TCP.
  2231.   Depending on the operating system supporting A's TCP, it is likely
  2232.   that some error recovery mechanism exists.  When the TCP is up again,
  2233.   A is likely to start again from the beginning or from a recovery
  2234.   point.  As a result, A will probably try to OPEN the connection again
  2235.   or try to SEND on the connection it believes open.  In the latter
  2236.   case, it receives the error message "connection not open" from the
  2237.   local (A's) TCP.  In an attempt to establish the connection, A's TCP
  2238.   will send a segment containing SYN.  This scenario leads to the
  2239.   example shown in figure 10.  After TCP A crashes, the user attempts to
  2240.   re-open the connection.  TCP B, in the meantime, thinks the connection
  2241.   is open.
  2242.  
  2243.   
  2244.  
  2245.       TCP A                                           TCP B
  2246.  
  2247.   1.  (CRASH)                               (send 300,receive 100)
  2248.  
  2249.   2.  CLOSED                                           ESTABLISHED
  2250.  
  2251.   3.  SYN-SENT --> <SEQ=400><CTL=SYN>              --> (??)
  2252.  
  2253.   4.  (!!)     <-- <SEQ=300><ACK=100><CTL=ACK>     <-- ESTABLISHED
  2254.  
  2255.   5.  SYN-SENT --> <SEQ=100><CTL=RST>              --> (Abort!!)
  2256.  
  2257.   6.  SYN-SENT                                         CLOSED
  2258.  
  2259.   7.  SYN-SENT --> <SEQ=400><CTL=SYN>              -->
  2260.  
  2261.                      Half-Open Connection Discovery
  2262.  
  2263.                                Figure 10.
  2264.  
  2265.   When the SYN arrives at line 3, TCP B, being in a synchronized state,
  2266.   and the incoming segment outside the window, responds with an
  2267.   acknowledgment indicating what sequence it next expects to hear (ACK
  2268.   100).  TCP A sees that this segment does not acknowledge anything it
  2269.   sent and, being unsynchronized, sends a reset (RST) because it has
  2270.   detected a half-open connection.  TCP B aborts at line 5.  TCP A will
  2271.  
  2272.  
  2273.  
  2274. [Page 34]                                                               
  2275.  
  2276.  
  2277.  
  2278. September 1981                                                          
  2279.                                            Transmission Control Protocol
  2280.                                                 Functional Specification
  2281.  
  2282.  
  2283.  
  2284.   continue to try to establish the connection; the problem is now
  2285.   reduced to the basic 3-way handshake of figure 7.
  2286.  
  2287.   An interesting alternative case occurs when TCP A crashes and TCP B
  2288.   tries to send data on what it thinks is a synchronized connection.
  2289.   This is illustrated in figure 11.  In this case, the data arriving at
  2290.   TCP A from TCP B (line 2) is unacceptable because no such connection
  2291.   exists, so TCP A sends a RST.  The RST is acceptable so TCP B
  2292.   processes it and aborts the connection.
  2293.  
  2294.   
  2295.  
  2296.         TCP A                                              TCP B
  2297.  
  2298.   1.  (CRASH)                                   (send 300,receive 100)
  2299.  
  2300.   2.  (??)    <-- <SEQ=300><ACK=100><DATA=10><CTL=ACK> <-- ESTABLISHED
  2301.  
  2302.   3.          --> <SEQ=100><CTL=RST>                   --> (ABORT!!)
  2303.  
  2304.            Active Side Causes Half-Open Connection Discovery
  2305.  
  2306.                                Figure 11.
  2307.  
  2308.   In figure 12, we find the two TCPs A and B with passive connections
  2309.   waiting for SYN.  An old duplicate arriving at TCP B (line 2) stirs B
  2310.   into action.  A SYN-ACK is returned (line 3) and causes TCP A to
  2311.   generate a RST (the ACK in line 3 is not acceptable).  TCP B accepts
  2312.   the reset and returns to its passive LISTEN state.
  2313.  
  2314.   
  2315.  
  2316.       TCP A                                         TCP B
  2317.  
  2318.   1.  LISTEN                                        LISTEN
  2319.  
  2320.   2.       ... <SEQ=Z><CTL=SYN>                -->  SYN-RECEIVED
  2321.  
  2322.   3.  (??) <-- <SEQ=X><ACK=Z+1><CTL=SYN,ACK>   <--  SYN-RECEIVED
  2323.  
  2324.   4.       --> <SEQ=Z+1><CTL=RST>              -->  (return to LISTEN!)
  2325.  
  2326.   5.  LISTEN                                        LISTEN
  2327.  
  2328.        Old Duplicate SYN Initiates a Reset on two Passive Sockets
  2329.  
  2330.                                Figure 12.
  2331.  
  2332.  
  2333.  
  2334.                                                                [Page 35]
  2335.  
  2336.  
  2337.  
  2338.                                                           September 1981
  2339. Transmission Control Protocol
  2340. Functional Specification
  2341.  
  2342.  
  2343.  
  2344.   A variety of other cases are possible, all of which are accounted for
  2345.   by the following rules for RST generation and processing.
  2346.  
  2347.   Reset Generation
  2348.  
  2349.   As a general rule, reset (RST) must be sent whenever a segment arrives
  2350.   which apparently is not intended for the current connection.  A reset
  2351.   must not be sent if it is not clear that this is the case.
  2352.  
  2353.   There are three groups of states:
  2354.  
  2355.     1.  If the connection does not exist (CLOSED) then a reset is sent
  2356.     in response to any incoming segment except another reset.  In
  2357.     particular, SYNs addressed to a non-existent connection are rejected
  2358.     by this means.
  2359.  
  2360.     If the incoming segment has an ACK field, the reset takes its
  2361.     sequence number from the ACK field of the segment, otherwise the
  2362.     reset has sequence number zero and the ACK field is set to the sum
  2363.     of the sequence number and segment length of the incoming segment.
  2364.     The connection remains in the CLOSED state.
  2365.  
  2366.     2.  If the connection is in any non-synchronized state (LISTEN,
  2367.     SYN-SENT, SYN-RECEIVED), and the incoming segment acknowledges
  2368.     something not yet sent (the segment carries an unacceptable ACK), or
  2369.     if an incoming segment has a security level or compartment which
  2370.     does not exactly match the level and compartment requested for the
  2371.     connection, a reset is sent.
  2372.  
  2373.     If our SYN has not been acknowledged and the precedence level of the
  2374.     incoming segment is higher than the precedence level requested then
  2375.     either raise the local precedence level (if allowed by the user and
  2376.     the system) or send a reset; or if the precedence level of the
  2377.     incoming segment is lower than the precedence level requested then
  2378.     continue as if the precedence matched exactly (if the remote TCP
  2379.     cannot raise the precedence level to match ours this will be
  2380.     detected in the next segment it sends, and the connection will be
  2381.     terminated then).  If our SYN has been acknowledged (perhaps in this
  2382.     incoming segment) the precedence level of the incoming segment must
  2383.     match the local precedence level exactly, if it does not a reset
  2384.     must be sent.
  2385.  
  2386.     If the incoming segment has an ACK field, the reset takes its
  2387.     sequence number from the ACK field of the segment, otherwise the
  2388.     reset has sequence number zero and the ACK field is set to the sum
  2389.     of the sequence number and segment length of the incoming segment.
  2390.     The connection remains in the same state.
  2391.  
  2392.  
  2393.  
  2394. [Page 36]                                                               
  2395.  
  2396.  
  2397.  
  2398. September 1981                                                          
  2399.                                            Transmission Control Protocol
  2400.                                                 Functional Specification
  2401.  
  2402.  
  2403.  
  2404.     3.  If the connection is in a synchronized state (ESTABLISHED,
  2405.     FIN-WAIT-1, FIN-WAIT-2, CLOSE-WAIT, CLOSING, LAST-ACK, TIME-WAIT),
  2406.     any unacceptable segment (out of window sequence number or
  2407.     unacceptible acknowledgment number) must elicit only an empty
  2408.     acknowledgment segment containing the current send-sequence number
  2409.     and an acknowledgment indicating the next sequence number expected
  2410.     to be received, and the connection remains in the same state.
  2411.  
  2412.     If an incoming segment has a security level, or compartment, or
  2413.     precedence which does not exactly match the level, and compartment,
  2414.     and precedence requested for the connection,a reset is sent and
  2415.     connection goes to the CLOSED state.  The reset takes its sequence
  2416.     number from the ACK field of the incoming segment.
  2417.  
  2418.   Reset Processing
  2419.  
  2420.   In all states except SYN-SENT, all reset (RST) segments are validated
  2421.   by checking their SEQ-fields.  A reset is valid if its sequence number
  2422.   is in the window.  In the SYN-SENT state (a RST received in response
  2423.   to an initial SYN), the RST is acceptable if the ACK field
  2424.   acknowledges the SYN.
  2425.  
  2426.   The receiver of a RST first validates it, then changes state.  If the
  2427.   receiver was in the LISTEN state, it ignores it.  If the receiver was
  2428.   in SYN-RECEIVED state and had previously been in the LISTEN state,
  2429.   then the receiver returns to the LISTEN state, otherwise the receiver
  2430.   aborts the connection and goes to the CLOSED state.  If the receiver
  2431.   was in any other state, it aborts the connection and advises the user
  2432.   and goes to the CLOSED state.
  2433.  
  2434. 3.5.  Closing a Connection
  2435.  
  2436.   CLOSE is an operation meaning "I have no more data to send."  The
  2437.   notion of closing a full-duplex connection is subject to ambiguous
  2438.   interpretation, of course, since it may not be obvious how to treat
  2439.   the receiving side of the connection.  We have chosen to treat CLOSE
  2440.   in a simplex fashion.  The user who CLOSEs may continue to RECEIVE
  2441.   until he is told that the other side has CLOSED also.  Thus, a program
  2442.   could initiate several SENDs followed by a CLOSE, and then continue to
  2443.   RECEIVE until signaled that a RECEIVE failed because the other side
  2444.   has CLOSED.  We assume that the TCP will signal a user, even if no
  2445.   RECEIVEs are outstanding, that the other side has closed, so the user
  2446.   can terminate his side gracefully.  A TCP will reliably deliver all
  2447.   buffers SENT before the connection was CLOSED so a user who expects no
  2448.   data in return need only wait to hear the connection was CLOSED
  2449.   successfully to know that all his data was received at the destination
  2450.   TCP.  Users must keep reading connections they close for sending until
  2451.   the TCP says no more data.
  2452.  
  2453.  
  2454.                                                                [Page 37]
  2455.  
  2456.  
  2457.  
  2458.                                                           September 1981
  2459. Transmission Control Protocol
  2460. Functional Specification
  2461.  
  2462.  
  2463.  
  2464.   There are essentially three cases:
  2465.  
  2466.     1) The user initiates by telling the TCP to CLOSE the connection
  2467.  
  2468.     2) The remote TCP initiates by sending a FIN control signal
  2469.  
  2470.     3) Both users CLOSE simultaneously
  2471.  
  2472.   Case 1:  Local user initiates the close
  2473.  
  2474.     In this case, a FIN segment can be constructed and placed on the
  2475.     outgoing segment queue.  No further SENDs from the user will be
  2476.     accepted by the TCP, and it enters the FIN-WAIT-1 state.  RECEIVEs
  2477.     are allowed in this state.  All segments preceding and including FIN
  2478.     will be retransmitted until acknowledged.  When the other TCP has
  2479.     both acknowledged the FIN and sent a FIN of its own, the first TCP
  2480.     can ACK this FIN.  Note that a TCP receiving a FIN will ACK but not
  2481.     send its own FIN until its user has CLOSED the connection also.
  2482.  
  2483.   Case 2:  TCP receives a FIN from the network
  2484.  
  2485.     If an unsolicited FIN arrives from the network, the receiving TCP
  2486.     can ACK it and tell the user that the connection is closing.  The
  2487.     user will respond with a CLOSE, upon which the TCP can send a FIN to
  2488.     the other TCP after sending any remaining data.  The TCP then waits
  2489.     until its own FIN is acknowledged whereupon it deletes the
  2490.     connection.  If an ACK is not forthcoming, after the user timeout
  2491.     the connection is aborted and the user is told.
  2492.  
  2493.   Case 3:  both users close simultaneously
  2494.  
  2495.     A simultaneous CLOSE by users at both ends of a connection causes
  2496.     FIN segments to be exchanged.  When all segments preceding the FINs
  2497.     have been processed and acknowledged, each TCP can ACK the FIN it
  2498.     has received.  Both will, upon receiving these ACKs, delete the
  2499.     connection.
  2500.  
  2501.  
  2502.  
  2503.  
  2504.  
  2505.  
  2506.  
  2507.  
  2508.  
  2509.  
  2510.  
  2511.  
  2512.  
  2513.  
  2514. [Page 38]                                                               
  2515.  
  2516.  
  2517.  
  2518. September 1981                                                          
  2519.                                            Transmission Control Protocol
  2520.                                                 Functional Specification
  2521.  
  2522.  
  2523.  
  2524.   
  2525.  
  2526.       TCP A                                                TCP B
  2527.  
  2528.   1.  ESTABLISHED                                          ESTABLISHED
  2529.  
  2530.   2.  (Close)
  2531.       FIN-WAIT-1  --> <SEQ=100><ACK=300><CTL=FIN,ACK>  --> CLOSE-WAIT
  2532.  
  2533.   3.  FIN-WAIT-2  <-- <SEQ=300><ACK=101><CTL=ACK>      <-- CLOSE-WAIT
  2534.  
  2535.   4.                                                       (Close)
  2536.       TIME-WAIT   <-- <SEQ=300><ACK=101><CTL=FIN,ACK>  <-- LAST-ACK
  2537.  
  2538.   5.  TIME-WAIT   --> <SEQ=101><ACK=301><CTL=ACK>      --> CLOSED
  2539.  
  2540.   6.  (2 MSL)
  2541.       CLOSED                                                      
  2542.  
  2543.                          Normal Close Sequence
  2544.  
  2545.                                Figure 13.
  2546.  
  2547.   
  2548.  
  2549.       TCP A                                                TCP B
  2550.  
  2551.   1.  ESTABLISHED                                          ESTABLISHED
  2552.  
  2553.   2.  (Close)                                              (Close)
  2554.       FIN-WAIT-1  --> <SEQ=100><ACK=300><CTL=FIN,ACK>  ... FIN-WAIT-1
  2555.                   <-- <SEQ=300><ACK=100><CTL=FIN,ACK>  <--
  2556.                   ... <SEQ=100><ACK=300><CTL=FIN,ACK>  -->
  2557.  
  2558.   3.  CLOSING     --> <SEQ=101><ACK=301><CTL=ACK>      ... CLOSING
  2559.                   <-- <SEQ=301><ACK=101><CTL=ACK>      <--
  2560.                   ... <SEQ=101><ACK=301><CTL=ACK>      -->
  2561.  
  2562.   4.  TIME-WAIT                                            TIME-WAIT
  2563.       (2 MSL)                                              (2 MSL)
  2564.       CLOSED                                               CLOSED
  2565.  
  2566.                       Simultaneous Close Sequence
  2567.  
  2568.                                Figure 14.
  2569.  
  2570.  
  2571.  
  2572.  
  2573.  
  2574.                                                                [Page 39]
  2575.  
  2576.  
  2577.  
  2578.                                                           September 1981
  2579. Transmission Control Protocol
  2580. Functional Specification
  2581.  
  2582.  
  2583.  
  2584. 3.6.  Precedence and Security
  2585.  
  2586.   The intent is that connection be allowed only between ports operating
  2587.   with exactly the same security and compartment values and at the
  2588.   higher of the precedence level requested by the two ports.
  2589.  
  2590.   The precedence and security parameters used in TCP are exactly those
  2591.   defined in the Internet Protocol (IP) [2].  Throughout this TCP
  2592.   specification the term "security/compartment" is intended to indicate
  2593.   the security parameters used in IP including security, compartment,
  2594.   user group, and handling restriction.
  2595.  
  2596.   A connection attempt with mismatched security/compartment values or a
  2597.   lower precedence value must be rejected by sending a reset.  Rejecting
  2598.   a connection due to too low a precedence only occurs after an
  2599.   acknowledgment of the SYN has been received.
  2600.  
  2601.   Note that TCP modules which operate only at the default value of
  2602.   precedence will still have to check the precedence of incoming
  2603.   segments and possibly raise the precedence level they use on the
  2604.   connection.
  2605.  
  2606.   The security paramaters may be used even in a non-secure environment
  2607.   (the values would indicate unclassified data), thus hosts in
  2608.   non-secure environments must be prepared to receive the security
  2609.   parameters, though they need not send them.
  2610.  
  2611. 3.7.  Data Communication
  2612.  
  2613.   Once the connection is established data is communicated by the
  2614.   exchange of segments.  Because segments may be lost due to errors
  2615.   (checksum test failure), or network congestion, TCP uses
  2616.   retransmission (after a timeout) to ensure delivery of every segment.
  2617.   Duplicate segments may arrive due to network or TCP retransmission.
  2618.   As discussed in the section on sequence numbers the TCP performs
  2619.   certain tests on the sequence and acknowledgment numbers in the
  2620.   segments to verify their acceptability.
  2621.  
  2622.   The sender of data keeps track of the next sequence number to use in
  2623.   the variable SND.NXT.  The receiver of data keeps track of the next
  2624.   sequence number to expect in the variable RCV.NXT.  The sender of data
  2625.   keeps track of the oldest unacknowledged sequence number in the
  2626.   variable SND.UNA.  If the data flow is momentarily idle and all data
  2627.   sent has been acknowledged then the three variables will be equal.
  2628.  
  2629.   When the sender creates a segment and transmits it the sender advances
  2630.   SND.NXT.  When the receiver accepts a segment it advances RCV.NXT and
  2631.   sends an acknowledgment.  When the data sender receives an
  2632.  
  2633.  
  2634. [Page 40]                                                               
  2635.  
  2636.  
  2637.  
  2638. September 1981                                                          
  2639.                                            Transmission Control Protocol
  2640.                                                 Functional Specification
  2641.  
  2642.  
  2643.  
  2644.   acknowledgment it advances SND.UNA.  The extent to which the values of
  2645.   these variables differ is a measure of the delay in the communication.
  2646.   The amount by which the variables are advanced is the length of the
  2647.   data in the segment.  Note that once in the ESTABLISHED state all
  2648.   segments must carry current acknowledgment information.
  2649.  
  2650.   The CLOSE user call implies a push function, as does the FIN control
  2651.   flag in an incoming segment.
  2652.  
  2653.   Retransmission Timeout
  2654.  
  2655.   Because of the variability of the networks that compose an
  2656.   internetwork system and the wide range of uses of TCP connections the
  2657.   retransmission timeout must be dynamically determined.  One procedure
  2658.   for determining a retransmission time out is given here as an
  2659.   illustration.
  2660.  
  2661.     An Example Retransmission Timeout Procedure
  2662.  
  2663.       Measure the elapsed time between sending a data octet with a
  2664.       particular sequence number and receiving an acknowledgment that
  2665.       covers that sequence number (segments sent do not have to match
  2666.       segments received).  This measured elapsed time is the Round Trip
  2667.       Time (RTT).  Next compute a Smoothed Round Trip Time (SRTT) as:
  2668.  
  2669.         SRTT = ( ALPHA * SRTT ) + ((1-ALPHA) * RTT)
  2670.  
  2671.       and based on this, compute the retransmission timeout (RTO) as:
  2672.  
  2673.         RTO = min[UBOUND,max[LBOUND,(BETA*SRTT)]]
  2674.  
  2675.       where UBOUND is an upper bound on the timeout (e.g., 1 minute),
  2676.       LBOUND is a lower bound on the timeout (e.g., 1 second), ALPHA is
  2677.       a smoothing factor (e.g., .8 to .9), and BETA is a delay variance
  2678.       factor (e.g., 1.3 to 2.0).
  2679.  
  2680.   The Communication of Urgent Information
  2681.  
  2682.   The objective of the TCP urgent mechanism is to allow the sending user
  2683.   to stimulate the receiving user to accept some urgent data and to
  2684.   permit the receiving TCP to indicate to the receiving user when all
  2685.   the currently known urgent data has been received by the user.
  2686.  
  2687.   This mechanism permits a point in the data stream to be designated as
  2688.   the end of urgent information.  Whenever this point is in advance of
  2689.   the receive sequence number (RCV.NXT) at the receiving TCP, that TCP
  2690.   must tell the user to go into "urgent mode"; when the receive sequence
  2691.   number catches up to the urgent pointer, the TCP must tell user to go
  2692.  
  2693.  
  2694.                                                                [Page 41]
  2695.  
  2696.  
  2697.  
  2698.                                                           September 1981
  2699. Transmission Control Protocol
  2700. Functional Specification
  2701.  
  2702.  
  2703.  
  2704.   into "normal mode".  If the urgent pointer is updated while the user
  2705.   is in "urgent mode", the update will be invisible to the user.
  2706.  
  2707.   The method employs a urgent field which is carried in all segments
  2708.   transmitted.  The URG control flag indicates that the urgent field is
  2709.   meaningful and must be added to the segment sequence number to yield
  2710.   the urgent pointer.  The absence of this flag indicates that there is
  2711.   no urgent data outstanding.
  2712.  
  2713.   To send an urgent indication the user must also send at least one data
  2714.   octet.  If the sending user also indicates a push, timely delivery of
  2715.   the urgent information to the destination process is enhanced.
  2716.  
  2717.   Managing the Window
  2718.  
  2719.   The window sent in each segment indicates the range of sequence
  2720.   numbers the sender of the window (the data receiver) is currently
  2721.   prepared to accept.  There is an assumption that this is related to
  2722.   the currently available data buffer space available for this
  2723.   connection.
  2724.  
  2725.   Indicating a large window encourages transmissions.  If more data
  2726.   arrives than can be accepted, it will be discarded.  This will result
  2727.   in excessive retransmissions, adding unnecessarily to the load on the
  2728.   network and the TCPs.  Indicating a small window may restrict the
  2729.   transmission of data to the point of introducing a round trip delay
  2730.   between each new segment transmitted.
  2731.  
  2732.   The mechanisms provided allow a TCP to advertise a large window and to
  2733.   subsequently advertise a much smaller window without having accepted
  2734.   that much data.  This, so called "shrinking the window," is strongly
  2735.   discouraged.  The robustness principle dictates that TCPs will not
  2736.   shrink the window themselves, but will be prepared for such behavior
  2737.   on the part of other TCPs.
  2738.  
  2739.   The sending TCP must be prepared to accept from the user and send at
  2740.   least one octet of new data even if the send window is zero.  The
  2741.   sending TCP must regularly retransmit to the receiving TCP even when
  2742.   the window is zero.  Two minutes is recommended for the retransmission
  2743.   interval when the window is zero.  This retransmission is essential to
  2744.   guarantee that when either TCP has a zero window the re-opening of the
  2745.   window will be reliably reported to the other.
  2746.  
  2747.   When the receiving TCP has a zero window and a segment arrives it must
  2748.   still send an acknowledgment showing its next expected sequence number
  2749.   and current window (zero).
  2750.  
  2751.   The sending TCP packages the data to be transmitted into segments
  2752.  
  2753.  
  2754. [Page 42]                                                               
  2755.  
  2756.  
  2757.  
  2758. September 1981                                                          
  2759.                                            Transmission Control Protocol
  2760.                                                 Functional Specification
  2761.  
  2762.  
  2763.  
  2764.   which fit the current window, and may repackage segments on the
  2765.   retransmission queue.  Such repackaging is not required, but may be
  2766.   helpful.
  2767.  
  2768.   In a connection with a one-way data flow, the window information will
  2769.   be carried in acknowledgment segments that all have the same sequence
  2770.   number so there will be no way to reorder them if they arrive out of
  2771.   order.  This is not a serious problem, but it will allow the window
  2772.   information to be on occasion temporarily based on old reports from
  2773.   the data receiver.  A refinement to avoid this problem is to act on
  2774.   the window information from segments that carry the highest
  2775.   acknowledgment number (that is segments with acknowledgment number
  2776.   equal or greater than the highest previously received).
  2777.  
  2778.   The window management procedure has significant influence on the
  2779.   communication performance.  The following comments are suggestions to
  2780.   implementers.
  2781.  
  2782.     Window Management Suggestions
  2783.  
  2784.       Allocating a very small window causes data to be transmitted in
  2785.       many small segments when better performance is achieved using
  2786.       fewer large segments.
  2787.  
  2788.       One suggestion for avoiding small windows is for the receiver to
  2789.       defer updating a window until the additional allocation is at
  2790.       least X percent of the maximum allocation possible for the
  2791.       connection (where X might be 20 to 40).
  2792.  
  2793.       Another suggestion is for the sender to avoid sending small
  2794.       segments by waiting until the window is large enough before
  2795.       sending data.  If the the user signals a push function then the
  2796.       data must be sent even if it is a small segment.
  2797.  
  2798.       Note that the acknowledgments should not be delayed or unnecessary
  2799.       retransmissions will result.  One strategy would be to send an
  2800.       acknowledgment when a small segment arrives (with out updating the
  2801.       window information), and then to send another acknowledgment with
  2802.       new window information when the window is larger.
  2803.  
  2804.       The segment sent to probe a zero window may also begin a break up
  2805.       of transmitted data into smaller and smaller segments.  If a
  2806.       segment containing a single data octet sent to probe a zero window
  2807.       is accepted, it consumes one octet of the window now available.
  2808.       If the sending TCP simply sends as much as it can whenever the
  2809.       window is non zero, the transmitted data will be broken into
  2810.       alternating big and small segments.  As time goes on, occasional
  2811.       pauses in the receiver making window allocation available will
  2812.  
  2813.  
  2814.                                                                [Page 43]
  2815.  
  2816.  
  2817.  
  2818.                                                           September 1981
  2819. Transmission Control Protocol
  2820. Functional Specification
  2821.  
  2822.  
  2823.  
  2824.       result in breaking the big segments into a small and not quite so
  2825.       big pair. And after a while the data transmission will be in
  2826.       mostly small segments.
  2827.  
  2828.       The suggestion here is that the TCP implementations need to
  2829.       actively attempt to combine small window allocations into larger
  2830.       windows, since the mechanisms for managing the window tend to lead
  2831.       to many small windows in the simplest minded implementations.
  2832.  
  2833. 3.8.  Interfaces
  2834.  
  2835.   There are of course two interfaces of concern:  the user/TCP interface
  2836.   and the TCP/lower-level interface.  We have a fairly elaborate model
  2837.   of the user/TCP interface, but the interface to the lower level
  2838.   protocol module is left unspecified here, since it will be specified
  2839.   in detail by the specification of the lowel level protocol.  For the
  2840.   case that the lower level is IP we note some of the parameter values
  2841.   that TCPs might use.
  2842.  
  2843.   User/TCP Interface
  2844.  
  2845.     The following functional description of user commands to the TCP is,
  2846.     at best, fictional, since every operating system will have different
  2847.     facilities.  Consequently, we must warn readers that different TCP
  2848.     implementations may have different user interfaces.  However, all
  2849.     TCPs must provide a certain minimum set of services to guarantee
  2850.     that all TCP implementations can support the same protocol
  2851.     hierarchy.  This section specifies the functional interfaces
  2852.     required of all TCP implementations.
  2853.  
  2854.     TCP User Commands
  2855.  
  2856.       The following sections functionally characterize a USER/TCP
  2857.       interface.  The notation used is similar to most procedure or
  2858.       function calls in high level languages, but this usage is not
  2859.       meant to rule out trap type service calls (e.g., SVCs, UUOs,
  2860.       EMTs).
  2861.  
  2862.       The user commands described below specify the basic functions the
  2863.       TCP must perform to support interprocess communication.
  2864.       Individual implementations must define their own exact format, and
  2865.       may provide combinations or subsets of the basic functions in
  2866.       single calls.  In particular, some implementations may wish to
  2867.       automatically OPEN a connection on the first SEND or RECEIVE
  2868.       issued by the user for a given connection.
  2869.  
  2870.  
  2871.  
  2872.  
  2873.  
  2874. [Page 44]                                                               
  2875.  
  2876.  
  2877.  
  2878. September 1981                                                          
  2879.                                            Transmission Control Protocol
  2880.                                                 Functional Specification
  2881.  
  2882.  
  2883.  
  2884.       In providing interprocess communication facilities, the TCP must
  2885.       not only accept commands, but must also return information to the
  2886.       processes it serves.  The latter consists of:
  2887.  
  2888.         (a) general information about a connection (e.g., interrupts,
  2889.         remote close, binding of unspecified foreign socket).
  2890.  
  2891.         (b) replies to specific user commands indicating success or
  2892.         various types of failure.
  2893.  
  2894.       Open
  2895.  
  2896.         Format:  OPEN (local port, foreign socket, active/passive
  2897.         [, timeout] [, precedence] [, security/compartment] [, options])
  2898.         -> local connection name
  2899.  
  2900.         We assume that the local TCP is aware of the identity of the
  2901.         processes it serves and will check the authority of the process
  2902.         to use the connection specified.  Depending upon the
  2903.         implementation of the TCP, the local network and TCP identifiers
  2904.         for the source address will either be supplied by the TCP or the
  2905.         lower level protocol (e.g., IP).  These considerations are the
  2906.         result of concern about security, to the extent that no TCP be
  2907.         able to masquerade as another one, and so on.  Similarly, no
  2908.         process can masquerade as another without the collusion of the
  2909.         TCP.
  2910.  
  2911.         If the active/passive flag is set to passive, then this is a
  2912.         call to LISTEN for an incoming connection.  A passive open may
  2913.         have either a fully specified foreign socket to wait for a
  2914.         particular connection or an unspecified foreign socket to wait
  2915.         for any call.  A fully specified passive call can be made active
  2916.         by the subsequent execution of a SEND.
  2917.  
  2918.         A transmission control block (TCB) is created and partially
  2919.         filled in with data from the OPEN command parameters.
  2920.  
  2921.         On an active OPEN command, the TCP will begin the procedure to
  2922.         synchronize (i.e., establish) the connection at once.
  2923.  
  2924.         The timeout, if present, permits the caller to set up a timeout
  2925.         for all data submitted to TCP.  If data is not successfully
  2926.         delivered to the destination within the timeout period, the TCP
  2927.         will abort the connection.  The present global default is five
  2928.         minutes.
  2929.  
  2930.         The TCP or some component of the operating system will verify
  2931.         the users authority to open a connection with the specified
  2932.  
  2933.  
  2934.                                                                [Page 45]
  2935.  
  2936.  
  2937.  
  2938.                                                           September 1981
  2939. Transmission Control Protocol
  2940. Functional Specification
  2941.  
  2942.  
  2943.  
  2944.         precedence or security/compartment.  The absence of precedence
  2945.         or security/compartment specification in the OPEN call indicates
  2946.         the default values must be used.
  2947.  
  2948.         TCP will accept incoming requests as matching only if the
  2949.         security/compartment information is exactly the same and only if
  2950.         the precedence is equal to or higher than the precedence
  2951.         requested in the OPEN call.
  2952.  
  2953.         The precedence for the connection is the higher of the values
  2954.         requested in the OPEN call and received from the incoming
  2955.         request, and fixed at that value for the life of the
  2956.         connection.Implementers may want to give the user control of
  2957.         this precedence negotiation.  For example, the user might be
  2958.         allowed to specify that the precedence must be exactly matched,
  2959.         or that any attempt to raise the precedence be confirmed by the
  2960.         user.
  2961.  
  2962.         A local connection name will be returned to the user by the TCP.
  2963.         The local connection name can then be used as a short hand term
  2964.         for the connection defined by the <local socket, foreign socket>
  2965.         pair.
  2966.  
  2967.       Send
  2968.  
  2969.         Format:  SEND (local connection name, buffer address, byte
  2970.         count, PUSH flag, URGENT flag [,timeout])
  2971.  
  2972.         This call causes the data contained in the indicated user buffer
  2973.         to be sent on the indicated connection.  If the connection has
  2974.         not been opened, the SEND is considered an error.  Some
  2975.         implementations may allow users to SEND first; in which case, an
  2976.         automatic OPEN would be done.  If the calling process is not
  2977.         authorized to use this connection, an error is returned.
  2978.  
  2979.         If the PUSH flag is set, the data must be transmitted promptly
  2980.         to the receiver, and the PUSH bit will be set in the last TCP
  2981.         segment created from the buffer.  If the PUSH flag is not set,
  2982.         the data may be combined with data from subsequent SENDs for
  2983.         transmission efficiency.
  2984.  
  2985.         If the URGENT flag is set, segments sent to the destination TCP
  2986.         will have the urgent pointer set.  The receiving TCP will signal
  2987.         the urgent condition to the receiving process if the urgent
  2988.         pointer indicates that data preceding the urgent pointer has not
  2989.         been consumed by the receiving process.  The purpose of urgent
  2990.         is to stimulate the receiver to process the urgent data and to
  2991.         indicate to the receiver when all the currently known urgent
  2992.  
  2993.  
  2994. [Page 46]                                                               
  2995.  
  2996.  
  2997.  
  2998. September 1981                                                          
  2999.                                            Transmission Control Protocol
  3000.                                                 Functional Specification
  3001.  
  3002.  
  3003.  
  3004.         data has been received.  The number of times the sending user's
  3005.         TCP signals urgent will not necessarily be equal to the number
  3006.         of times the receiving user will be notified of the presence of
  3007.         urgent data.
  3008.  
  3009.         If no foreign socket was specified in the OPEN, but the
  3010.         connection is established (e.g., because a LISTENing connection
  3011.         has become specific due to a foreign segment arriving for the
  3012.         local socket), then the designated buffer is sent to the implied
  3013.         foreign socket.  Users who make use of OPEN with an unspecified
  3014.         foreign socket can make use of SEND without ever explicitly
  3015.         knowing the foreign socket address.
  3016.  
  3017.         However, if a SEND is attempted before the foreign socket
  3018.         becomes specified, an error will be returned.  Users can use the
  3019.         STATUS call to determine the status of the connection.  In some
  3020.         implementations the TCP may notify the user when an unspecified
  3021.         socket is bound.
  3022.  
  3023.         If a timeout is specified, the current user timeout for this
  3024.         connection is changed to the new one.
  3025.  
  3026.         In the simplest implementation, SEND would not return control to
  3027.         the sending process until either the transmission was complete
  3028.         or the timeout had been exceeded.  However, this simple method
  3029.         is both subject to deadlocks (for example, both sides of the
  3030.         connection might try to do SENDs before doing any RECEIVEs) and
  3031.         offers poor performance, so it is not recommended.  A more
  3032.         sophisticated implementation would return immediately to allow
  3033.         the process to run concurrently with network I/O, and,
  3034.         furthermore, to allow multiple SENDs to be in progress.
  3035.         Multiple SENDs are served in first come, first served order, so
  3036.         the TCP will queue those it cannot service immediately.
  3037.  
  3038.         We have implicitly assumed an asynchronous user interface in
  3039.         which a SEND later elicits some kind of SIGNAL or
  3040.         pseudo-interrupt from the serving TCP.  An alternative is to
  3041.         return a response immediately.  For instance, SENDs might return
  3042.         immediate local acknowledgment, even if the segment sent had not
  3043.         been acknowledged by the distant TCP.  We could optimistically
  3044.         assume eventual success.  If we are wrong, the connection will
  3045.         close anyway due to the timeout.  In implementations of this
  3046.         kind (synchronous), there will still be some asynchronous
  3047.         signals, but these will deal with the connection itself, and not
  3048.         with specific segments or buffers.
  3049.  
  3050.         In order for the process to distinguish among error or success
  3051.         indications for different SENDs, it might be appropriate for the
  3052.  
  3053.  
  3054.                                                                [Page 47]
  3055.  
  3056.  
  3057.  
  3058.                                                           September 1981
  3059. Transmission Control Protocol
  3060. Functional Specification
  3061.  
  3062.  
  3063.  
  3064.         buffer address to be returned along with the coded response to
  3065.         the SEND request.  TCP-to-user signals are discussed below,
  3066.         indicating the information which should be returned to the
  3067.         calling process.
  3068.  
  3069.       Receive
  3070.  
  3071.         Format:  RECEIVE (local connection name, buffer address, byte
  3072.         count) -> byte count, urgent flag, push flag
  3073.  
  3074.         This command allocates a receiving buffer associated with the
  3075.         specified connection.  If no OPEN precedes this command or the
  3076.         calling process is not authorized to use this connection, an
  3077.         error is returned.
  3078.  
  3079.         In the simplest implementation, control would not return to the
  3080.         calling program until either the buffer was filled, or some
  3081.         error occurred, but this scheme is highly subject to deadlocks.
  3082.         A more sophisticated implementation would permit several
  3083.         RECEIVEs to be outstanding at once.  These would be filled as
  3084.         segments arrive.  This strategy permits increased throughput at
  3085.         the cost of a more elaborate scheme (possibly asynchronous) to
  3086.         notify the calling program that a PUSH has been seen or a buffer
  3087.         filled.
  3088.  
  3089.         If enough data arrive to fill the buffer before a PUSH is seen,
  3090.         the PUSH flag will not be set in the response to the RECEIVE.
  3091.         The buffer will be filled with as much data as it can hold.  If
  3092.         a PUSH is seen before the buffer is filled the buffer will be
  3093.         returned partially filled and PUSH indicated.
  3094.  
  3095.         If there is urgent data the user will have been informed as soon
  3096.         as it arrived via a TCP-to-user signal.  The receiving user
  3097.         should thus be in "urgent mode".  If the URGENT flag is on,
  3098.         additional urgent data remains.  If the URGENT flag is off, this
  3099.         call to RECEIVE has returned all the urgent data, and the user
  3100.         may now leave "urgent mode".  Note that data following the
  3101.         urgent pointer (non-urgent data) cannot be delivered to the user
  3102.         in the same buffer with preceeding urgent data unless the
  3103.         boundary is clearly marked for the user.
  3104.  
  3105.         To distinguish among several outstanding RECEIVEs and to take
  3106.         care of the case that a buffer is not completely filled, the
  3107.         return code is accompanied by both a buffer pointer and a byte
  3108.         count indicating the actual length of the data received.
  3109.  
  3110.         Alternative implementations of RECEIVE might have the TCP
  3111.  
  3112.  
  3113.  
  3114. [Page 48]                                                               
  3115.  
  3116.  
  3117.  
  3118. September 1981                                                          
  3119.                                            Transmission Control Protocol
  3120.                                                 Functional Specification
  3121.  
  3122.  
  3123.  
  3124.         allocate buffer storage, or the TCP might share a ring buffer
  3125.         with the user.
  3126.  
  3127.       Close
  3128.  
  3129.         Format:  CLOSE (local connection name)
  3130.  
  3131.         This command causes the connection specified to be closed.  If
  3132.         the connection is not open or the calling process is not
  3133.         authorized to use this connection, an error is returned.
  3134.         Closing connections is intended to be a graceful operation in
  3135.         the sense that outstanding SENDs will be transmitted (and
  3136.         retransmitted), as flow control permits, until all have been
  3137.         serviced.  Thus, it should be acceptable to make several SEND
  3138.         calls, followed by a CLOSE, and expect all the data to be sent
  3139.         to the destination.  It should also be clear that users should
  3140.         continue to RECEIVE on CLOSING connections, since the other side
  3141.         may be trying to transmit the last of its data.  Thus, CLOSE
  3142.         means "I have no more to send" but does not mean "I will not
  3143.         receive any more."  It may happen (if the user level protocol is
  3144.         not well thought out) that the closing side is unable to get rid
  3145.         of all its data before timing out.  In this event, CLOSE turns
  3146.         into ABORT, and the closing TCP gives up.
  3147.  
  3148.         The user may CLOSE the connection at any time on his own
  3149.         initiative, or in response to various prompts from the TCP
  3150.         (e.g., remote close executed, transmission timeout exceeded,
  3151.         destination inaccessible).
  3152.  
  3153.         Because closing a connection requires communication with the
  3154.         foreign TCP, connections may remain in the closing state for a
  3155.         short time.  Attempts to reopen the connection before the TCP
  3156.         replies to the CLOSE command will result in error responses.
  3157.  
  3158.         Close also implies push function.
  3159.  
  3160.       Status
  3161.  
  3162.         Format:  STATUS (local connection name) -> status data
  3163.  
  3164.         This is an implementation dependent user command and could be
  3165.         excluded without adverse effect.  Information returned would
  3166.         typically come from the TCB associated with the connection.
  3167.  
  3168.         This command returns a data block containing the following
  3169.         information:
  3170.  
  3171.           local socket,
  3172.  
  3173.  
  3174.                                                                [Page 49]
  3175.  
  3176.  
  3177.  
  3178.                                                           September 1981
  3179. Transmission Control Protocol
  3180. Functional Specification
  3181.  
  3182.  
  3183.  
  3184.           foreign socket,
  3185.           local connection name,
  3186.           receive window,
  3187.           send window,
  3188.           connection state,
  3189.           number of buffers awaiting acknowledgment,
  3190.           number of buffers pending receipt,
  3191.           urgent state,
  3192.           precedence,
  3193.           security/compartment,
  3194.           and transmission timeout.
  3195.  
  3196.         Depending on the state of the connection, or on the
  3197.         implementation itself, some of this information may not be
  3198.         available or meaningful.  If the calling process is not
  3199.         authorized to use this connection, an error is returned.  This
  3200.         prevents unauthorized processes from gaining information about a
  3201.         connection.
  3202.  
  3203.       Abort
  3204.  
  3205.         Format:  ABORT (local connection name)
  3206.  
  3207.         This command causes all pending SENDs and RECEIVES to be
  3208.         aborted, the TCB to be removed, and a special RESET message to
  3209.         be sent to the TCP on the other side of the connection.
  3210.         Depending on the implementation, users may receive abort
  3211.         indications for each outstanding SEND or RECEIVE, or may simply
  3212.         receive an ABORT-acknowledgment.
  3213.  
  3214.     TCP-to-User Messages
  3215.  
  3216.       It is assumed that the operating system environment provides a
  3217.       means for the TCP to asynchronously signal the user program.  When
  3218.       the TCP does signal a user program, certain information is passed
  3219.       to the user.  Often in the specification the information will be
  3220.       an error message.  In other cases there will be information
  3221.       relating to the completion of processing a SEND or RECEIVE or
  3222.       other user call.
  3223.  
  3224.       The following information is provided:
  3225.  
  3226.         Local Connection Name                    Always
  3227.         Response String                          Always
  3228.         Buffer Address                           Send & Receive
  3229.         Byte count (counts bytes received)       Receive
  3230.         Push flag                                Receive
  3231.         Urgent flag                              Receive
  3232.  
  3233.  
  3234. [Page 50]                                                               
  3235.  
  3236.  
  3237.  
  3238. September 1981                                                          
  3239.                                            Transmission Control Protocol
  3240.                                                 Functional Specification
  3241.  
  3242.  
  3243.  
  3244.   TCP/Lower-Level Interface
  3245.  
  3246.     The TCP calls on a lower level protocol module to actually send and
  3247.     receive information over a network.  One case is that of the ARPA
  3248.     internetwork system where the lower level module is the Internet
  3249.     Protocol (IP) [2].
  3250.  
  3251.     If the lower level protocol is IP it provides arguments for a type
  3252.     of service and for a time to live.  TCP uses the following settings
  3253.     for these parameters:
  3254.  
  3255.       Type of Service = Precedence: routine, Delay: normal, Throughput:
  3256.       normal, Reliability: normal; or 00000000.
  3257.  
  3258.       Time to Live    = one minute, or 00111100.
  3259.  
  3260.         Note that the assumed maximum segment lifetime is two minutes.
  3261.         Here we explicitly ask that a segment be destroyed if it cannot
  3262.         be delivered by the internet system within one minute.
  3263.  
  3264.     If the lower level is IP (or other protocol that provides this
  3265.     feature) and source routing is used, the interface must allow the
  3266.     route information to be communicated.  This is especially important
  3267.     so that the source and destination addresses used in the TCP
  3268.     checksum be the originating source and ultimate destination. It is
  3269.     also important to preserve the return route to answer connection
  3270.     requests.
  3271.  
  3272.     Any lower level protocol will have to provide the source address,
  3273.     destination address, and protocol fields, and some way to determine
  3274.     the "TCP length", both to provide the functional equivlent service
  3275.     of IP and to be used in the TCP checksum.
  3276.  
  3277.  
  3278.  
  3279.  
  3280.  
  3281.  
  3282.  
  3283.  
  3284.  
  3285.  
  3286.  
  3287.  
  3288.  
  3289.  
  3290.  
  3291.  
  3292.  
  3293.  
  3294.                                                                [Page 51]
  3295.  
  3296.  
  3297.  
  3298.                                                           September 1981
  3299. Transmission Control Protocol
  3300. Functional Specification
  3301.  
  3302.  
  3303.  
  3304. 3.9.  Event Processing
  3305.  
  3306.   The processing depicted in this section is an example of one possible
  3307.   implementation.  Other implementations may have slightly different
  3308.   processing sequences, but they should differ from those in this
  3309.   section only in detail, not in substance.
  3310.  
  3311.   The activity of the TCP can be characterized as responding to events.
  3312.   The events that occur can be cast into three categories:  user calls,
  3313.   arriving segments, and timeouts.  This section describes the
  3314.   processing the TCP does in response to each of the events.  In many
  3315.   cases the processing required depends on the state of the connection.
  3316.  
  3317.     Events that occur:
  3318.  
  3319.       User Calls
  3320.  
  3321.         OPEN
  3322.         SEND
  3323.         RECEIVE
  3324.         CLOSE
  3325.         ABORT
  3326.         STATUS
  3327.  
  3328.       Arriving Segments
  3329.  
  3330.         SEGMENT ARRIVES
  3331.  
  3332.       Timeouts
  3333.  
  3334.         USER TIMEOUT
  3335.         RETRANSMISSION TIMEOUT
  3336.         TIME-WAIT TIMEOUT
  3337.  
  3338.   The model of the TCP/user interface is that user commands receive an
  3339.   immediate return and possibly a delayed response via an event or
  3340.   pseudo interrupt.  In the following descriptions, the term "signal"
  3341.   means cause a delayed response.
  3342.  
  3343.   Error responses are given as character strings.  For example, user
  3344.   commands referencing connections that do not exist receive "error:
  3345.   connection not open".
  3346.  
  3347.   Please note in the following that all arithmetic on sequence numbers,
  3348.   acknowledgment numbers, windows, et cetera, is modulo 2**32 the size
  3349.   of the sequence number space.  Also note that "=<" means less than or
  3350.   equal to (modulo 2**32).
  3351.  
  3352.  
  3353.  
  3354. [Page 52]                                                               
  3355.  
  3356.  
  3357.  
  3358. September 1981                                                          
  3359.                                            Transmission Control Protocol
  3360.                                                 Functional Specification
  3361.  
  3362.  
  3363.  
  3364.   A natural way to think about processing incoming segments is to
  3365.   imagine that they are first tested for proper sequence number (i.e.,
  3366.   that their contents lie in the range of the expected "receive window"
  3367.   in the sequence number space) and then that they are generally queued
  3368.   and processed in sequence number order.
  3369.  
  3370.   When a segment overlaps other already received segments we reconstruct
  3371.   the segment to contain just the new data, and adjust the header fields
  3372.   to be consistent.
  3373.  
  3374.   Note that if no state change is mentioned the TCP stays in the same
  3375.   state.
  3376.  
  3377.  
  3378.  
  3379.  
  3380.  
  3381.  
  3382.  
  3383.  
  3384.  
  3385.  
  3386.  
  3387.  
  3388.  
  3389.  
  3390.  
  3391.  
  3392.  
  3393.  
  3394.  
  3395.  
  3396.  
  3397.  
  3398.  
  3399.  
  3400.  
  3401.  
  3402.  
  3403.  
  3404.  
  3405.  
  3406.  
  3407.  
  3408.  
  3409.  
  3410.  
  3411.  
  3412.  
  3413.  
  3414.                                                                [Page 53]
  3415.  
  3416.  
  3417.  
  3418.                                                           September 1981
  3419. Transmission Control Protocol
  3420. Functional Specification
  3421.                                                                OPEN Call
  3422.  
  3423.  
  3424.  
  3425.   OPEN Call
  3426.  
  3427.     CLOSED STATE (i.e., TCB does not exist)
  3428.  
  3429.       Create a new transmission control block (TCB) to hold connection
  3430.       state information.  Fill in local socket identifier, foreign
  3431.       socket, precedence, security/compartment, and user timeout
  3432.       information.  Note that some parts of the foreign socket may be
  3433.       unspecified in a passive OPEN and are to be filled in by the
  3434.       parameters of the incoming SYN segment.  Verify the security and
  3435.       precedence requested are allowed for this user, if not return
  3436.       "error:  precedence not allowed" or "error:  security/compartment
  3437.       not allowed."  If passive enter the LISTEN state and return.  If
  3438.       active and the foreign socket is unspecified, return "error:
  3439.       foreign socket unspecified"; if active and the foreign socket is
  3440.       specified, issue a SYN segment.  An initial send sequence number
  3441.       (ISS) is selected.  A SYN segment of the form <SEQ=ISS><CTL=SYN>
  3442.       is sent.  Set SND.UNA to ISS, SND.NXT to ISS+1, enter SYN-SENT
  3443.       state, and return.
  3444.  
  3445.       If the caller does not have access to the local socket specified,
  3446.       return "error:  connection illegal for this process".  If there is
  3447.       no room to create a new connection, return "error:  insufficient
  3448.       resources".
  3449.  
  3450.     LISTEN STATE
  3451.  
  3452.       If active and the foreign socket is specified, then change the
  3453.       connection from passive to active, select an ISS.  Send a SYN
  3454.       segment, set SND.UNA to ISS, SND.NXT to ISS+1.  Enter SYN-SENT
  3455.       state.  Data associated with SEND may be sent with SYN segment or
  3456.       queued for transmission after entering ESTABLISHED state.  The
  3457.       urgent bit if requested in the command must be sent with the data
  3458.       segments sent as a result of this command.  If there is no room to
  3459.       queue the request, respond with "error:  insufficient resources".
  3460.       If Foreign socket was not specified, then return "error:  foreign
  3461.       socket unspecified".
  3462.  
  3463.  
  3464.  
  3465.  
  3466.  
  3467.  
  3468.  
  3469.  
  3470.  
  3471.  
  3472.  
  3473.  
  3474. [Page 54]                                                               
  3475.  
  3476.  
  3477.  
  3478. September 1981                                                          
  3479.                                            Transmission Control Protocol
  3480.                                                 Functional Specification
  3481. OPEN Call
  3482.  
  3483.  
  3484.  
  3485.     SYN-SENT STATE
  3486.     SYN-RECEIVED STATE
  3487.     ESTABLISHED STATE
  3488.     FIN-WAIT-1 STATE
  3489.     FIN-WAIT-2 STATE
  3490.     CLOSE-WAIT STATE
  3491.     CLOSING STATE
  3492.     LAST-ACK STATE
  3493.     TIME-WAIT STATE
  3494.  
  3495.       Return "error:  connection already exists".
  3496.  
  3497.  
  3498.  
  3499.  
  3500.  
  3501.  
  3502.  
  3503.  
  3504.  
  3505.  
  3506.  
  3507.  
  3508.  
  3509.  
  3510.  
  3511.  
  3512.  
  3513.  
  3514.  
  3515.  
  3516.  
  3517.  
  3518.  
  3519.  
  3520.  
  3521.  
  3522.  
  3523.  
  3524.  
  3525.  
  3526.  
  3527.  
  3528.  
  3529.  
  3530.  
  3531.  
  3532.  
  3533.  
  3534.                                                                [Page 55]
  3535.  
  3536.  
  3537.  
  3538.                                                           September 1981
  3539. Transmission Control Protocol
  3540. Functional Specification
  3541.                                                                SEND Call
  3542.  
  3543.  
  3544.  
  3545.   SEND Call
  3546.  
  3547.     CLOSED STATE (i.e., TCB does not exist)
  3548.  
  3549.       If the user does not have access to such a connection, then return
  3550.       "error:  connection illegal for this process".
  3551.  
  3552.       Otherwise, return "error:  connection does not exist".
  3553.  
  3554.     LISTEN STATE
  3555.  
  3556.       If the foreign socket is specified, then change the connection
  3557.       from passive to active, select an ISS.  Send a SYN segment, set
  3558.       SND.UNA to ISS, SND.NXT to ISS+1.  Enter SYN-SENT state.  Data
  3559.       associated with SEND may be sent with SYN segment or queued for
  3560.       transmission after entering ESTABLISHED state.  The urgent bit if
  3561.       requested in the command must be sent with the data segments sent
  3562.       as a result of this command.  If there is no room to queue the
  3563.       request, respond with "error:  insufficient resources".  If
  3564.       Foreign socket was not specified, then return "error:  foreign
  3565.       socket unspecified".
  3566.  
  3567.     SYN-SENT STATE
  3568.     SYN-RECEIVED STATE
  3569.  
  3570.       Queue the data for transmission after entering ESTABLISHED state.
  3571.       If no space to queue, respond with "error:  insufficient
  3572.       resources".
  3573.  
  3574.     ESTABLISHED STATE
  3575.     CLOSE-WAIT STATE
  3576.  
  3577.       Segmentize the buffer and send it with a piggybacked
  3578.       acknowledgment (acknowledgment value = RCV.NXT).  If there is
  3579.       insufficient space to remember this buffer, simply return "error:
  3580.       insufficient resources".
  3581.  
  3582.       If the urgent flag is set, then SND.UP <- SND.NXT-1 and set the
  3583.       urgent pointer in the outgoing segments.
  3584.  
  3585.  
  3586.  
  3587.  
  3588.  
  3589.  
  3590.  
  3591.  
  3592.  
  3593.  
  3594. [Page 56]                                                               
  3595.  
  3596.  
  3597.  
  3598. September 1981                                                          
  3599.                                            Transmission Control Protocol
  3600.                                                 Functional Specification
  3601. SEND Call
  3602.  
  3603.  
  3604.  
  3605.     FIN-WAIT-1 STATE
  3606.     FIN-WAIT-2 STATE
  3607.     CLOSING STATE
  3608.     LAST-ACK STATE
  3609.     TIME-WAIT STATE
  3610.  
  3611.       Return "error:  connection closing" and do not service request.
  3612.  
  3613.  
  3614.  
  3615.  
  3616.  
  3617.  
  3618.  
  3619.  
  3620.  
  3621.  
  3622.  
  3623.  
  3624.  
  3625.  
  3626.  
  3627.  
  3628.  
  3629.  
  3630.  
  3631.  
  3632.  
  3633.  
  3634.  
  3635.  
  3636.  
  3637.  
  3638.  
  3639.  
  3640.  
  3641.  
  3642.  
  3643.  
  3644.  
  3645.  
  3646.  
  3647.  
  3648.  
  3649.  
  3650.  
  3651.  
  3652.  
  3653.  
  3654.                                                                [Page 57]
  3655.  
  3656.  
  3657.  
  3658.                                                           September 1981
  3659. Transmission Control Protocol
  3660. Functional Specification
  3661.                                                             RECEIVE Call
  3662.  
  3663.  
  3664.  
  3665.   RECEIVE Call
  3666.  
  3667.     CLOSED STATE (i.e., TCB does not exist)
  3668.  
  3669.       If the user does not have access to such a connection, return
  3670.       "error:  connection illegal for this process".
  3671.  
  3672.       Otherwise return "error:  connection does not exist".
  3673.  
  3674.     LISTEN STATE
  3675.     SYN-SENT STATE
  3676.     SYN-RECEIVED STATE
  3677.  
  3678.       Queue for processing after entering ESTABLISHED state.  If there
  3679.       is no room to queue this request, respond with "error:
  3680.       insufficient resources".
  3681.  
  3682.     ESTABLISHED STATE
  3683.     FIN-WAIT-1 STATE
  3684.     FIN-WAIT-2 STATE
  3685.  
  3686.       If insufficient incoming segments are queued to satisfy the
  3687.       request, queue the request.  If there is no queue space to
  3688.       remember the RECEIVE, respond with "error:  insufficient
  3689.       resources".
  3690.  
  3691.       Reassemble queued incoming segments into receive buffer and return
  3692.       to user.  Mark "push seen" (PUSH) if this is the case.
  3693.  
  3694.       If RCV.UP is in advance of the data currently being passed to the
  3695.       user notify the user of the presence of urgent data.
  3696.  
  3697.       When the TCP takes responsibility for delivering data to the user
  3698.       that fact must be communicated to the sender via an
  3699.       acknowledgment.  The formation of such an acknowledgment is
  3700.       described below in the discussion of processing an incoming
  3701.       segment.
  3702.  
  3703.  
  3704.  
  3705.  
  3706.  
  3707.  
  3708.  
  3709.  
  3710.  
  3711.  
  3712.  
  3713.  
  3714. [Page 58]                                                               
  3715.  
  3716.  
  3717.  
  3718. September 1981                                                          
  3719.                                            Transmission Control Protocol
  3720.                                                 Functional Specification
  3721. RECEIVE Call
  3722.  
  3723.  
  3724.  
  3725.     CLOSE-WAIT STATE
  3726.  
  3727.       Since the remote side has already sent FIN, RECEIVEs must be
  3728.       satisfied by text already on hand, but not yet delivered to the
  3729.       user.  If no text is awaiting delivery, the RECEIVE will get a
  3730.       "error:  connection closing" response.  Otherwise, any remaining
  3731.       text can be used to satisfy the RECEIVE.
  3732.  
  3733.     CLOSING STATE
  3734.     LAST-ACK STATE
  3735.     TIME-WAIT STATE
  3736.  
  3737.       Return "error:  connection closing".
  3738.  
  3739.  
  3740.  
  3741.  
  3742.  
  3743.  
  3744.  
  3745.  
  3746.  
  3747.  
  3748.  
  3749.  
  3750.  
  3751.  
  3752.  
  3753.  
  3754.  
  3755.  
  3756.  
  3757.  
  3758.  
  3759.  
  3760.  
  3761.  
  3762.  
  3763.  
  3764.  
  3765.  
  3766.  
  3767.  
  3768.  
  3769.  
  3770.  
  3771.  
  3772.  
  3773.  
  3774.                                                                [Page 59]
  3775.  
  3776.  
  3777.  
  3778.                                                           September 1981
  3779. Transmission Control Protocol
  3780. Functional Specification
  3781.                                                               CLOSE Call
  3782.  
  3783.  
  3784.  
  3785.   CLOSE Call
  3786.  
  3787.     CLOSED STATE (i.e., TCB does not exist)
  3788.  
  3789.       If the user does not have access to such a connection, return
  3790.       "error:  connection illegal for this process".
  3791.  
  3792.       Otherwise, return "error:  connection does not exist".
  3793.  
  3794.     LISTEN STATE
  3795.  
  3796.       Any outstanding RECEIVEs are returned with "error:  closing"
  3797.       responses.  Delete TCB, enter CLOSED state, and return.
  3798.  
  3799.     SYN-SENT STATE
  3800.  
  3801.       Delete the TCB and return "error:  closing" responses to any
  3802.       queued SENDs, or RECEIVEs.
  3803.  
  3804.     SYN-RECEIVED STATE
  3805.  
  3806.       If no SENDs have been issued and there is no pending data to send,
  3807.       then form a FIN segment and send it, and enter FIN-WAIT-1 state;
  3808.       otherwise queue for processing after entering ESTABLISHED state.
  3809.  
  3810.     ESTABLISHED STATE
  3811.  
  3812.       Queue this until all preceding SENDs have been segmentized, then
  3813.       form a FIN segment and send it.  In any case, enter FIN-WAIT-1
  3814.       state.
  3815.  
  3816.     FIN-WAIT-1 STATE
  3817.     FIN-WAIT-2 STATE
  3818.  
  3819.       Strictly speaking, this is an error and should receive a "error:
  3820.       connection closing" response.  An "ok" response would be
  3821.       acceptable, too, as long as a second FIN is not emitted (the first
  3822.       FIN may be retransmitted though).
  3823.  
  3824.  
  3825.  
  3826.  
  3827.  
  3828.  
  3829.  
  3830.  
  3831.  
  3832.  
  3833.  
  3834. [Page 60]                                                               
  3835.  
  3836.  
  3837.  
  3838. September 1981                                                          
  3839.                                            Transmission Control Protocol
  3840.                                                 Functional Specification
  3841. CLOSE Call
  3842.  
  3843.  
  3844.  
  3845.     CLOSE-WAIT STATE
  3846.  
  3847.       Queue this request until all preceding SENDs have been
  3848.       segmentized; then send a FIN segment, enter CLOSING state.
  3849.  
  3850.     CLOSING STATE
  3851.     LAST-ACK STATE
  3852.     TIME-WAIT STATE
  3853.  
  3854.       Respond with "error:  connection closing".
  3855.  
  3856.  
  3857.  
  3858.  
  3859.  
  3860.  
  3861.  
  3862.  
  3863.  
  3864.  
  3865.  
  3866.  
  3867.  
  3868.  
  3869.  
  3870.  
  3871.  
  3872.  
  3873.  
  3874.  
  3875.  
  3876.  
  3877.  
  3878.  
  3879.  
  3880.  
  3881.  
  3882.  
  3883.  
  3884.  
  3885.  
  3886.  
  3887.  
  3888.  
  3889.  
  3890.  
  3891.  
  3892.  
  3893.  
  3894.                                                                [Page 61]
  3895.  
  3896.  
  3897.  
  3898.                                                           September 1981
  3899. Transmission Control Protocol
  3900. Functional Specification
  3901.                                                               ABORT Call
  3902.  
  3903.  
  3904.  
  3905.   ABORT Call
  3906.  
  3907.     CLOSED STATE (i.e., TCB does not exist)
  3908.  
  3909.       If the user should not have access to such a connection, return
  3910.       "error:  connection illegal for this process".
  3911.  
  3912.       Otherwise return "error:  connection does not exist".
  3913.  
  3914.     LISTEN STATE
  3915.  
  3916.       Any outstanding RECEIVEs should be returned with "error:
  3917.       connection reset" responses.  Delete TCB, enter CLOSED state, and
  3918.       return.
  3919.  
  3920.     SYN-SENT STATE
  3921.  
  3922.       All queued SENDs and RECEIVEs should be given "connection reset"
  3923.       notification, delete the TCB, enter CLOSED state, and return.
  3924.  
  3925.     SYN-RECEIVED STATE
  3926.     ESTABLISHED STATE
  3927.     FIN-WAIT-1 STATE
  3928.     FIN-WAIT-2 STATE
  3929.     CLOSE-WAIT STATE
  3930.  
  3931.       Send a reset segment:
  3932.  
  3933.         <SEQ=SND.NXT><CTL=RST>
  3934.  
  3935.       All queued SENDs and RECEIVEs should be given "connection reset"
  3936.       notification; all segments queued for transmission (except for the
  3937.       RST formed above) or retransmission should be flushed, delete the
  3938.       TCB, enter CLOSED state, and return.
  3939.  
  3940.     CLOSING STATE
  3941.     LAST-ACK STATE
  3942.     TIME-WAIT STATE
  3943.  
  3944.       Respond with "ok" and delete the TCB, enter CLOSED state, and
  3945.       return.
  3946.  
  3947.  
  3948.  
  3949.  
  3950.  
  3951.  
  3952.  
  3953.  
  3954. [Page 62]                                                               
  3955.  
  3956.  
  3957.  
  3958. September 1981                                                          
  3959.                                            Transmission Control Protocol
  3960.                                                 Functional Specification
  3961. STATUS Call
  3962.  
  3963.  
  3964.  
  3965.   STATUS Call
  3966.  
  3967.     CLOSED STATE (i.e., TCB does not exist)
  3968.  
  3969.       If the user should not have access to such a connection, return
  3970.       "error:  connection illegal for this process".
  3971.  
  3972.       Otherwise return "error:  connection does not exist".
  3973.  
  3974.     LISTEN STATE
  3975.  
  3976.       Return "state = LISTEN", and the TCB pointer.
  3977.  
  3978.     SYN-SENT STATE
  3979.  
  3980.       Return "state = SYN-SENT", and the TCB pointer.
  3981.  
  3982.     SYN-RECEIVED STATE
  3983.  
  3984.       Return "state = SYN-RECEIVED", and the TCB pointer.
  3985.  
  3986.     ESTABLISHED STATE
  3987.  
  3988.       Return "state = ESTABLISHED", and the TCB pointer.
  3989.  
  3990.     FIN-WAIT-1 STATE
  3991.  
  3992.       Return "state = FIN-WAIT-1", and the TCB pointer.
  3993.  
  3994.     FIN-WAIT-2 STATE
  3995.  
  3996.       Return "state = FIN-WAIT-2", and the TCB pointer.
  3997.  
  3998.     CLOSE-WAIT STATE
  3999.  
  4000.       Return "state = CLOSE-WAIT", and the TCB pointer.
  4001.  
  4002.     CLOSING STATE
  4003.  
  4004.       Return "state = CLOSING", and the TCB pointer.
  4005.  
  4006.     LAST-ACK STATE
  4007.  
  4008.       Return "state = LAST-ACK", and the TCB pointer.
  4009.  
  4010.  
  4011.  
  4012.  
  4013.  
  4014.                                                                [Page 63]
  4015.  
  4016.  
  4017.  
  4018.                                                           September 1981
  4019. Transmission Control Protocol
  4020. Functional Specification
  4021.                                                              STATUS Call
  4022.  
  4023.  
  4024.  
  4025.     TIME-WAIT STATE
  4026.  
  4027.       Return "state = TIME-WAIT", and the TCB pointer.
  4028.  
  4029.  
  4030.  
  4031.  
  4032.  
  4033.  
  4034.  
  4035.  
  4036.  
  4037.  
  4038.  
  4039.  
  4040.  
  4041.  
  4042.  
  4043.  
  4044.  
  4045.  
  4046.  
  4047.  
  4048.  
  4049.  
  4050.  
  4051.  
  4052.  
  4053.  
  4054.  
  4055.  
  4056.  
  4057.  
  4058.  
  4059.  
  4060.  
  4061.  
  4062.  
  4063.  
  4064.  
  4065.  
  4066.  
  4067.  
  4068.  
  4069.  
  4070.  
  4071.  
  4072.  
  4073.  
  4074. [Page 64]                                                               
  4075.  
  4076.  
  4077.  
  4078. September 1981                                                          
  4079.                                            Transmission Control Protocol
  4080.                                                 Functional Specification
  4081. SEGMENT ARRIVES
  4082.  
  4083.  
  4084.  
  4085.   SEGMENT ARRIVES
  4086.  
  4087.     If the state is CLOSED (i.e., TCB does not exist) then
  4088.  
  4089.       all data in the incoming segment is discarded.  An incoming
  4090.       segment containing a RST is discarded.  An incoming segment not
  4091.       containing a RST causes a RST to be sent in response.  The
  4092.       acknowledgment and sequence field values are selected to make the
  4093.       reset sequence acceptable to the TCP that sent the offending
  4094.       segment.
  4095.  
  4096.       If the ACK bit is off, sequence number zero is used,
  4097.  
  4098.         <SEQ=0><ACK=SEG.SEQ+SEG.LEN><CTL=RST,ACK>
  4099.  
  4100.       If the ACK bit is on,
  4101.  
  4102.         <SEQ=SEG.ACK><CTL=RST>
  4103.  
  4104.       Return.
  4105.  
  4106.     If the state is LISTEN then
  4107.  
  4108.       first check for an RST
  4109.  
  4110.         An incoming RST should be ignored.  Return.
  4111.  
  4112.       second check for an ACK
  4113.  
  4114.         Any acknowledgment is bad if it arrives on a connection still in
  4115.         the LISTEN state.  An acceptable reset segment should be formed
  4116.         for any arriving ACK-bearing segment.  The RST should be
  4117.         formatted as follows:
  4118.  
  4119.           <SEQ=SEG.ACK><CTL=RST>
  4120.  
  4121.         Return.
  4122.  
  4123.       third check for a SYN
  4124.  
  4125.         If the SYN bit is set, check the security.  If the
  4126.         security/compartment on the incoming segment does not exactly
  4127.         match the security/compartment in the TCB then send a reset and
  4128.         return.
  4129.  
  4130.           <SEQ=SEG.ACK><CTL=RST>
  4131.  
  4132.  
  4133.  
  4134.                                                                [Page 65]
  4135.  
  4136.  
  4137.  
  4138.                                                           September 1981
  4139. Transmission Control Protocol
  4140. Functional Specification
  4141.                                                          SEGMENT ARRIVES
  4142.  
  4143.  
  4144.  
  4145.         If the SEG.PRC is greater than the TCB.PRC then if allowed by
  4146.         the user and the system set TCB.PRC<-SEG.PRC, if not allowed
  4147.         send a reset and return.
  4148.  
  4149.           <SEQ=SEG.ACK><CTL=RST>
  4150.  
  4151.         If the SEG.PRC is less than the TCB.PRC then continue.
  4152.  
  4153.         Set RCV.NXT to SEG.SEQ+1, IRS is set to SEG.SEQ and any other
  4154.         control or text should be queued for processing later.  ISS
  4155.         should be selected and a SYN segment sent of the form:
  4156.  
  4157.           <SEQ=ISS><ACK=RCV.NXT><CTL=SYN,ACK>
  4158.  
  4159.         SND.NXT is set to ISS+1 and SND.UNA to ISS.  The connection
  4160.         state should be changed to SYN-RECEIVED.  Note that any other
  4161.         incoming control or data (combined with SYN) will be processed
  4162.         in the SYN-RECEIVED state, but processing of SYN and ACK should
  4163.         not be repeated.  If the listen was not fully specified (i.e.,
  4164.         the foreign socket was not fully specified), then the
  4165.         unspecified fields should be filled in now.
  4166.  
  4167.       fourth other text or control
  4168.  
  4169.         Any other control or text-bearing segment (not containing SYN)
  4170.         must have an ACK and thus would be discarded by the ACK
  4171.         processing.  An incoming RST segment could not be valid, since
  4172.         it could not have been sent in response to anything sent by this
  4173.         incarnation of the connection.  So you are unlikely to get here,
  4174.         but if you do, drop the segment, and return.
  4175.  
  4176.     If the state is SYN-SENT then
  4177.  
  4178.       first check the ACK bit
  4179.  
  4180.         If the ACK bit is set
  4181.  
  4182.           If SEG.ACK =< ISS, or SEG.ACK > SND.NXT, send a reset (unless
  4183.           the RST bit is set, if so drop the segment and return)
  4184.  
  4185.             <SEQ=SEG.ACK><CTL=RST>
  4186.  
  4187.           and discard the segment.  Return.
  4188.  
  4189.           If SND.UNA =< SEG.ACK =< SND.NXT then the ACK is acceptable.
  4190.  
  4191.       second check the RST bit
  4192.  
  4193.  
  4194. [Page 66]                                                               
  4195.  
  4196.  
  4197.  
  4198. September 1981                                                          
  4199.                                            Transmission Control Protocol
  4200.                                                 Functional Specification
  4201. SEGMENT ARRIVES
  4202.  
  4203.  
  4204.  
  4205.         If the RST bit is set
  4206.  
  4207.           If the ACK was acceptable then signal the user "error:
  4208.           connection reset", drop the segment, enter CLOSED state,
  4209.           delete TCB, and return.  Otherwise (no ACK) drop the segment
  4210.           and return.
  4211.  
  4212.       third check the security and precedence
  4213.  
  4214.         If the security/compartment in the segment does not exactly
  4215.         match the security/compartment in the TCB, send a reset
  4216.  
  4217.           If there is an ACK
  4218.  
  4219.             <SEQ=SEG.ACK><CTL=RST>
  4220.  
  4221.           Otherwise
  4222.  
  4223.             <SEQ=0><ACK=SEG.SEQ+SEG.LEN><CTL=RST,ACK>
  4224.  
  4225.         If there is an ACK
  4226.  
  4227.           The precedence in the segment must match the precedence in the
  4228.           TCB, if not, send a reset
  4229.  
  4230.             <SEQ=SEG.ACK><CTL=RST>
  4231.  
  4232.         If there is no ACK
  4233.  
  4234.           If the precedence in the segment is higher than the precedence
  4235.           in the TCB then if allowed by the user and the system raise
  4236.           the precedence in the TCB to that in the segment, if not
  4237.           allowed to raise the prec then send a reset.
  4238.  
  4239.             <SEQ=0><ACK=SEG.SEQ+SEG.LEN><CTL=RST,ACK>
  4240.  
  4241.           If the precedence in the segment is lower than the precedence
  4242.           in the TCB continue.
  4243.  
  4244.         If a reset was sent, discard the segment and return.
  4245.  
  4246.       fourth check the SYN bit
  4247.  
  4248.         This step should be reached only if the ACK is ok, or there is
  4249.         no ACK, and it the segment did not contain a RST.
  4250.  
  4251.         If the SYN bit is on and the security/compartment and precedence
  4252.  
  4253.  
  4254.                                                                [Page 67]
  4255.  
  4256.  
  4257.  
  4258.                                                           September 1981
  4259. Transmission Control Protocol
  4260. Functional Specification
  4261.                                                          SEGMENT ARRIVES
  4262.  
  4263.  
  4264.  
  4265.         are acceptable then, RCV.NXT is set to SEG.SEQ+1, IRS is set to
  4266.         SEG.SEQ.  SND.UNA should be advanced to equal SEG.ACK (if there
  4267.         is an ACK), and any segments on the retransmission queue which
  4268.         are thereby acknowledged should be removed.
  4269.  
  4270.         If SND.UNA > ISS (our SYN has been ACKed), change the connection
  4271.         state to ESTABLISHED, form an ACK segment
  4272.  
  4273.           <SEQ=SND.NXT><ACK=RCV.NXT><CTL=ACK>
  4274.  
  4275.         and send it.  Data or controls which were queued for
  4276.         transmission may be included.  If there are other controls or
  4277.         text in the segment then continue processing at the sixth step
  4278.         below where the URG bit is checked, otherwise return.
  4279.  
  4280.         Otherwise enter SYN-RECEIVED, form a SYN,ACK segment
  4281.  
  4282.           <SEQ=ISS><ACK=RCV.NXT><CTL=SYN,ACK>
  4283.  
  4284.         and send it.  If there are other controls or text in the
  4285.         segment, queue them for processing after the ESTABLISHED state
  4286.         has been reached, return.
  4287.  
  4288.       fifth, if neither of the SYN or RST bits is set then drop the
  4289.       segment and return.
  4290.  
  4291.  
  4292.  
  4293.  
  4294.  
  4295.  
  4296.  
  4297.  
  4298.  
  4299.  
  4300.  
  4301.  
  4302.  
  4303.  
  4304.  
  4305.  
  4306.  
  4307.  
  4308.  
  4309.  
  4310.  
  4311.  
  4312.  
  4313.  
  4314. [Page 68]                                                               
  4315.  
  4316.  
  4317.  
  4318. September 1981                                                          
  4319.                                            Transmission Control Protocol
  4320.                                                 Functional Specification
  4321. SEGMENT ARRIVES
  4322.  
  4323.  
  4324.  
  4325.