idnits 2.17.1 draft-ietf-tcpm-rfc793bis-08.txt: Checking boilerplate required by RFC 5378 and the IETF Trust (see https://trustee.ietf.org/license-info): ---------------------------------------------------------------------------- No issues found here. Checking nits according to https://www.ietf.org/id-info/1id-guidelines.txt: ---------------------------------------------------------------------------- No issues found here. Checking nits according to https://www.ietf.org/id-info/checklist : ---------------------------------------------------------------------------- ** The document seems to lack a Security Considerations section. == There are 3 instances of lines with non-RFC2606-compliant FQDNs in the document. -- The draft header indicates that this document obsoletes RFC6093, but the abstract doesn't seem to mention this, which it should. -- The draft header indicates that this document obsoletes RFC2873, but the abstract doesn't seem to mention this, which it should. -- The draft header indicates that this document obsoletes RFC6429, but the abstract doesn't seem to mention this, which it should. -- The draft header indicates that this document obsoletes RFC879, but the abstract doesn't seem to mention this, which it should. Miscellaneous warnings: ---------------------------------------------------------------------------- == The copyright year in the IETF Trust and authors Copyright Line does not match the current year (Using the creation date from RFC1122, updated by this document, for RFC5378 checks: 1989-10-01) -- The document seems to contain a disclaimer for pre-RFC5378 work, and may have content which was first submitted before 10 November 2008. The disclaimer is necessary when there are original authors that you have been unable to contact, or if some do not wish to grant the BCP78 rights to the IETF Trust. If you are able to get all authors (current and original) to grant those rights, you can and should remove the disclaimer; otherwise, the disclaimer is needed and you can ignore this comment. (See the Legal Provisions document at https://trustee.ietf.org/license-info for more information.) -- The document date (March 28, 2018) is 2214 days in the past. Is this intentional? Checking references for intended status: Proposed Standard ---------------------------------------------------------------------------- (See RFCs 3967 and 4897 for information about using normative references to lower-maturity documents in RFCs) == Unused Reference: '43' is defined on line 4327, but no explicit reference was found in the text ** Obsolete normative reference: RFC 1981 (ref. '3') (Obsoleted by RFC 8201) ** Obsolete normative reference: RFC 2460 (ref. '5') (Obsoleted by RFC 8200) ** Downref: Normative reference to an Informational RFC: RFC 2923 (ref. '8') -- Obsolete informational reference (is this intentional?): RFC 793 (ref. '12') (Obsoleted by RFC 9293) -- Obsolete informational reference (is this intentional?): RFC 896 (ref. '13') (Obsoleted by RFC 7805) -- Obsolete informational reference (is this intentional?): RFC 1349 (ref. '15') (Obsoleted by RFC 2474) -- Obsolete informational reference (is this intentional?): RFC 1644 (ref. '16') (Obsoleted by RFC 6247) -- Obsolete informational reference (is this intentional?): RFC 2873 (ref. '17') (Obsoleted by RFC 9293) -- Obsolete informational reference (is this intentional?): RFC 6093 (ref. '28') (Obsoleted by RFC 9293) -- Obsolete informational reference (is this intentional?): RFC 6429 (ref. '30') (Obsoleted by RFC 9293) -- Obsolete informational reference (is this intentional?): RFC 6528 (ref. '31') (Obsoleted by RFC 9293) -- Obsolete informational reference (is this intentional?): RFC 6691 (ref. '32') (Obsoleted by RFC 9293) == Outdated reference: A later version (-04) exists of draft-gont-tcpm-tcp-seq-validation-02 == Outdated reference: A later version (-15) exists of draft-ietf-tcpinc-tcpcrypt-09 Summary: 4 errors (**), 0 flaws (~~), 5 warnings (==), 15 comments (--). Run idnits with the --verbose option for more detailed information about the items above. -------------------------------------------------------------------------------- 2 Internet Engineering Task Force W. Eddy, Ed. 3 Internet-Draft MTI Systems 4 Obsoletes: 793, 879, 2873, 6093, 6429, March 28, 2018 5 6528, 6691 (if approved) 6 Updates: 5961, 1122 (if approved) 7 Intended status: Standards Track 8 Expires: September 29, 2018 10 Transmission Control Protocol Specification 11 draft-ietf-tcpm-rfc793bis-08 13 Abstract 15 This document specifies the Internet's Transmission Control Protocol 16 (TCP). TCP is an important transport layer protocol in the Internet 17 stack, and has continuously evolved over decades of use and growth of 18 the Internet. Over this time, a number of changes have been made to 19 TCP as it was specified in RFC 793, though these have only been 20 documented in a piecemeal fashion. This document collects and brings 21 those changes together with the protocol specification from RFC 793. 22 This document obsoletes RFC 793, as well as 879, 2873, 6093, 6429, 23 6528, and 6691 that updated parts of RFC 793. It updates RFC 1122, 24 and should be considered as a replacement for the portions of that 25 document dealing with TCP requirements. It updates RFC 5961 due to a 26 small clarification in reset handling while in the SYN-RECEIVED 27 state. 29 RFC EDITOR NOTE: If approved for publication as an RFC, this should 30 be marked additionally as "STD: 7" and replace RFC 793 in that role. 32 Requirements Language 34 The key words "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT", 35 "SHOULD", "SHOULD NOT", "RECOMMENDED", "MAY", and "OPTIONAL" in this 36 document are to be interpreted as described in RFC 2119 [4]. 38 Status of This Memo 40 This Internet-Draft is submitted in full conformance with the 41 provisions of BCP 78 and BCP 79. 43 Internet-Drafts are working documents of the Internet Engineering 44 Task Force (IETF). Note that other groups may also distribute 45 working documents as Internet-Drafts. The list of current Internet- 46 Drafts is at https://datatracker.ietf.org/drafts/current/. 48 Internet-Drafts are draft documents valid for a maximum of six months 49 and may be updated, replaced, or obsoleted by other documents at any 50 time. It is inappropriate to use Internet-Drafts as reference 51 material or to cite them other than as "work in progress." 53 This Internet-Draft will expire on September 29, 2018. 55 Copyright Notice 57 Copyright (c) 2018 IETF Trust and the persons identified as the 58 document authors. All rights reserved. 60 This document is subject to BCP 78 and the IETF Trust's Legal 61 Provisions Relating to IETF Documents 62 (https://trustee.ietf.org/license-info) in effect on the date of 63 publication of this document. Please review these documents 64 carefully, as they describe your rights and restrictions with respect 65 to this document. Code Components extracted from this document must 66 include Simplified BSD License text as described in Section 4.e of 67 the Trust Legal Provisions and are provided without warranty as 68 described in the Simplified BSD License. 70 This document may contain material from IETF Documents or IETF 71 Contributions published or made publicly available before November 72 10, 2008. The person(s) controlling the copyright in some of this 73 material may not have granted the IETF Trust the right to allow 74 modifications of such material outside the IETF Standards Process. 75 Without obtaining an adequate license from the person(s) controlling 76 the copyright in such materials, this document may not be modified 77 outside the IETF Standards Process, and derivative works of it may 78 not be created outside the IETF Standards Process, except to format 79 it for publication as an RFC or to translate it into languages other 80 than English. 82 Table of Contents 84 1. Purpose and Scope . . . . . . . . . . . . . . . . . . . . . . 3 85 2. Introduction . . . . . . . . . . . . . . . . . . . . . . . . 4 86 2.1. Key TCP Concepts . . . . . . . . . . . . . . . . . . . . 5 87 3. Functional Specification . . . . . . . . . . . . . . . . . . 6 88 3.1. Header Format . . . . . . . . . . . . . . . . . . . . . . 6 89 3.2. Terminology . . . . . . . . . . . . . . . . . . . . . . . 11 90 3.3. Sequence Numbers . . . . . . . . . . . . . . . . . . . . 16 91 3.4. Establishing a connection . . . . . . . . . . . . . . . . 22 92 4. Closing a Connection . . . . . . . . . . . . . . . . . . . . 29 93 4.1. Half-Closed Connections . . . . . . . . . . . . . . . . . 31 94 5. Precedence and Security . . . . . . . . . . . . . . . . . . . 32 95 6. Segmentation . . . . . . . . . . . . . . . . . . . . . . . . 33 96 6.1. Maximum Segment Size Option . . . . . . . . . . . . . . . 34 97 6.2. Path MTU Discovery . . . . . . . . . . . . . . . . . . . 35 98 6.3. Interfaces with Variable MTU Values . . . . . . . . . . . 36 99 6.4. Nagle Algorithm . . . . . . . . . . . . . . . . . . . . . 36 100 6.5. IPv6 Jumbograms . . . . . . . . . . . . . . . . . . . . . 37 101 7. Data Communication . . . . . . . . . . . . . . . . . . . . . 37 102 7.1. Retransmission Timeout . . . . . . . . . . . . . . . . . 38 103 7.2. TCP Congestion Control . . . . . . . . . . . . . . . . . 38 104 7.3. TCP Connection Failures . . . . . . . . . . . . . . . . . 38 105 7.4. TCP Keep-Alives . . . . . . . . . . . . . . . . . . . . . 39 106 7.5. The Communication of Urgent Information . . . . . . . . . 40 107 7.6. Managing the Window . . . . . . . . . . . . . . . . . . . 41 108 7.6.1. Zero Window Probing . . . . . . . . . . . . . . . . . 42 109 7.6.2. Silly Window Syndrome Avoidance . . . . . . . . . . . 42 110 7.6.3. Delayed Acknowledgements - When to Send an ACK 111 Segment . . . . . . . . . . . . . . . . . . . . . . . 45 112 8. Interfaces . . . . . . . . . . . . . . . . . . . . . . . . . 45 113 8.1. User/TCP Interface . . . . . . . . . . . . . . . . . . . 45 114 8.2. TCP/Lower-Level Interface . . . . . . . . . . . . . . . . 53 115 8.2.1. Source Routing . . . . . . . . . . . . . . . . . . . 54 116 8.2.2. ICMP Messages . . . . . . . . . . . . . . . . . . . . 55 117 8.2.3. Remote Address Validation . . . . . . . . . . . . . . 56 118 8.3. Event Processing . . . . . . . . . . . . . . . . . . . . 56 119 8.4. Glossary . . . . . . . . . . . . . . . . . . . . . . . . 81 120 9. Changes from RFC 793 . . . . . . . . . . . . . . . . . . . . 86 121 10. IANA Considerations . . . . . . . . . . . . . . . . . . . . . 91 122 11. Security and Privacy Considerations . . . . . . . . . . . . . 91 123 12. Acknowledgements . . . . . . . . . . . . . . . . . . . . . . 92 124 13. References . . . . . . . . . . . . . . . . . . . . . . . . . 92 125 13.1. Normative References . . . . . . . . . . . . . . . . . . 92 126 13.2. Informative References . . . . . . . . . . . . . . . . . 94 127 Appendix A. Other Implementation Notes . . . . . . . . . . . . . 97 128 A.1. IP Security Compartment and Precedence . . . . . . . . . 97 129 A.2. Sequence Number Validation . . . . . . . . . . . . . . . 97 130 A.3. Nagle Modification . . . . . . . . . . . . . . . . . . . 98 131 A.4. Low Water Mark . . . . . . . . . . . . . . . . . . . . . 98 132 Appendix B. TCP Requirement Summary . . . . . . . . . . . . . . 98 133 Author's Address . . . . . . . . . . . . . . . . . . . . . . . . 102 135 1. Purpose and Scope 137 In 1981, RFC 793 [12] was released, documenting the Transmission 138 Control Protocol (TCP), and replacing earlier specifications for TCP 139 that had been published in the past. 141 Since then, TCP has been implemented many times, and has been used as 142 a transport protocol for numerous applications on the Internet. 144 For several decades, RFC 793 plus a number of other documents have 145 combined to serve as the specification for TCP [36]. Over time, a 146 number of errata have been identified on RFC 793, as well as 147 deficiencies in security, performance, and other aspects. A number 148 of enhancements has grown and been documented separately. These were 149 never accumulated together into an update to the base specification. 151 The purpose of this document is to bring together all of the IETF 152 Standards Track changes that have been made to the basic TCP 153 functional specification and unify them into an update of the RFC 793 154 protocol specification. Some companion documents are referenced for 155 important algorithms that TCP uses (e.g. for congestion control), but 156 have not been attempted to include in this document. This is a 157 conscious choice, as this base specification can be used with 158 multiple additional algorithms that are developed and incorporated 159 separately, but all TCP implementations need to implement this 160 specification as a common basis in order to interoperate. As some 161 additional TCP features have become quite complicated themselves 162 (e.g. advanced loss recovery and congestion control), future 163 companion documents may attempt to similarly bring these together. 165 In addition to the protocol specification that descibes the TCP 166 segment format, generation, and processing rules that are to be 167 implemented in code, RFC 793 and other updates also contain 168 informative and descriptive text for human readers to understand 169 aspects of the protocol design and operation. This document does not 170 attempt to alter or update this informative text, and is focused only 171 on updating the normative protocol specification. We preserve 172 references to the documentation containing the important explanations 173 and rationale, where appropriate. 175 This document is intended to be useful both in checking existing TCP 176 implementations for conformance, as well as in writing new 177 implementations. 179 2. Introduction 181 RFC 793 contains a discussion of the TCP design goals and provides 182 examples of its operation, including examples of connection 183 establishment, closing connections, and retransmitting packets to 184 repair losses. 186 This document describes the basic functionality expected in modern 187 implementations of TCP, and replaces the protocol specification in 188 RFC 793. It does not replicate or attempt to update the examples and 189 other discussion in RFC 793. Other documents are referenced to 190 provide explanation of the theory of operation, rationale, and 191 detailed discussion of design decisions. This document only focuses 192 on the normative behavior of the protocol. 194 The "TCP Roadmap" [36] provides a more extensive guide to the RFCs 195 that define TCP and describe various important algorithms. The TCP 196 Roadmap contains sections on strongly encouraged enhancements that 197 improve performance and other aspects of TCP beyond the basic 198 operation specified in this document. As one example, implementing 199 congestion control (e.g. [24]) is a TCP requirement, but is a complex 200 topic on its own, and not described in detail in this document, as 201 there are many options and possibilities that do not impact basic 202 interoperability. Similarly, most common TCP implementations today 203 include the high-performance extensions in [34], but these are not 204 strictly required or discussed in this document. 206 TEMPORARY EDITOR'S NOTE: This is an early revision in the process of 207 updating RFC 793. Many planned changes are not yet incorporated. 209 ***Please do not use this revision as a basis for any work or 210 reference.*** 212 A list of changes from RFC 793 is contained in Section 9. 214 TEMPORARY EDITOR'S NOTE: the current revision of this document does 215 not yet collect all of the changes that will be in the final version. 216 The set of content changes planned for future revisions is kept in 217 Section 9. 219 2.1. Key TCP Concepts 221 TCP provides a reliable, in-order, byte-stream service to 222 applications. 224 The application byte-stream is conveyed over the network via TCP 225 segments, with each TCP segment sent as an Internet Protocol (IP) 226 datagram. 228 TCP reliability consists of detecting packet losses (via sequence 229 numbers) and errors (via per-segment checksums), as well as 230 correction of losses and errors via retransmission. 232 TCP supports unicast delivery of data. Anycast applications exist 233 that successfully use TCP without modifications, though there is some 234 risk of instability due to rerouting. 236 TCP is connection-oriented, though does not inherently include a 237 liveness detection capability. 239 Data flow is supported bidirectionally over TCP connections, though 240 applications are free to flow data only unidirectionally, if they so 241 choose. 243 TCP uses port numbers to identify application services and to 244 multiplex multiple flows between hosts. 246 A more detailed description of TCP's features compared to other 247 transport protocols can be found in Section 3.1 of [39]. Further 248 description of the motivations for developing TCP and its role in the 249 Internet stack can be found in Section 2 of [12] and earlier versions 250 of the TCP specification. 252 3. Functional Specification 254 3.1. Header Format 256 TCP segments are sent as internet datagrams. The Internet Protocol 257 (IP) header carries several information fields, including the source 258 and destination host addresses [1] [5]. A TCP header follows the 259 Internet header, supplying information specific to the TCP protocol. 260 This division allows for the existence of host level protocols other 261 than TCP. In early development of the Internet suite of protocols, 262 the IP header fields had been a part of TCP. 264 TCP Header Format 265 0 1 2 3 266 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 267 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 268 | Source Port | Destination Port | 269 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 270 | Sequence Number | 271 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 272 | Acknowledgment Number | 273 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 274 | Data | |C|E|U|A|P|R|S|F| | 275 | Offset| Rsrvd |W|C|R|C|S|S|Y|I| Window | 276 | | |R|E|G|K|H|T|N|N| | 277 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 278 | Checksum | Urgent Pointer | 279 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 280 | Options | Padding | 281 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 282 | data | 283 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 285 TCP Header Format 287 Note that one tick mark represents one bit position. 289 Figure 1 291 Source Port: 16 bits 293 The source port number. 295 Destination Port: 16 bits 297 The destination port number. 299 Sequence Number: 32 bits 301 The sequence number of the first data octet in this segment (except 302 when SYN is present). If SYN is present the sequence number is the 303 initial sequence number (ISN) and the first data octet is ISN+1. 305 Acknowledgment Number: 32 bits 307 If the ACK control bit is set this field contains the value of the 308 next sequence number the sender of the segment is expecting to 309 receive. Once a connection is established this is always sent. 311 Data Offset: 4 bits 312 The number of 32 bit words in the TCP Header. This indicates where 313 the data begins. The TCP header (even one including options) is an 314 integral number of 32 bits long. 316 Rsrvd - Reserved: 4 bits 318 Reserved for future use. Must be zero in generated segments and 319 must be ignored in received segments, if corresponding future 320 features are unimplemented by the sending or receiving host. 322 Control Bits: 8 bits (from left to right): 324 CWR: Congestion Window Reduced (see [9]) 325 ECE: ECN-Echo (see [9]) 326 URG: Urgent Pointer field significant 327 ACK: Acknowledgment field significant 328 PSH: Push Function 329 RST: Reset the connection 330 SYN: Synchronize sequence numbers 331 FIN: No more data from sender 333 Window: 16 bits 335 The number of data octets beginning with the one indicated in the 336 acknowledgment field which the sender of this segment is willing to 337 accept. 339 The window size MUST be treated as an unsigned number, or else 340 large window sizes will appear like negative windows and TCP will 341 now work. It is RECOMMENDED that implementations will reserve 342 32-bit fields for the send and receive window sizes in the 343 connection record and do all window computations with 32 bits. 345 Checksum: 16 bits 347 The checksum field is the 16 bit one's complement of the one's 348 complement sum of all 16 bit words in the header and text. If a 349 segment contains an odd number of header and text octets to be 350 checksummed, the last octet is padded on the right with zeros to 351 form a 16 bit word for checksum purposes. The pad is not 352 transmitted as part of the segment. While computing the checksum, 353 the checksum field itself is replaced with zeros. 355 The checksum also covers a pseudo header conceptually prefixed to 356 the TCP header. The pseudo header is 96 bits for IPv4 and 320 bits 357 for IPv6. For IPv4, this pseudo header contains the Source 358 Address, the Destination Address, the Protocol, and TCP length. 359 This gives the TCP protection against misrouted segments. This 360 information is carried in IPv4 and is transferred across the TCP/ 361 Network interface in the arguments or results of calls by the TCP 362 on the IP. 364 +--------+--------+--------+--------+ 365 | Source Address | 366 +--------+--------+--------+--------+ 367 | Destination Address | 368 +--------+--------+--------+--------+ 369 | zero | PTCL | TCP Length | 370 +--------+--------+--------+--------+ 372 The TCP Length is the TCP header length plus the data length in 373 octets (this is not an explicitly transmitted quantity, but is 374 computed), and it does not count the 12 octets of the pseudo 375 header. 377 For IPv6, the pseudo header is contained in section 8.1 of RFC 2460 378 [5], and contains the IPv6 Source Address and Destination Address, 379 an Upper Layer Packet Length (a 32-bit value otherwise equivalent 380 to TCP Length in the IPv4 pseudo header), three bytes of zero- 381 padding, and a Next Header value (differing from the IPv6 header 382 value in the case of extension headers present in between IPv6 and 383 TCP). 385 The TCP checksum is never optional. The sender MUST generate it 386 and the receiver MUST check it. 388 Urgent Pointer: 16 bits 390 This field communicates the current value of the urgent pointer as 391 a positive offset from the sequence number in this segment. The 392 urgent pointer points to the sequence number of the octet following 393 the urgent data. This field is only be interpreted in segments 394 with the URG control bit set. 396 Options: variable 398 Options may occupy space at the end of the TCP header and are a 399 multiple of 8 bits in length. All options are included in the 400 checksum. An option may begin on any octet boundary. There are 401 two cases for the format of an option: 403 Case 1: A single octet of option-kind. 405 Case 2: An octet of option-kind, an octet of option-length, and 406 the actual option-data octets. 408 The option-length counts the two octets of option-kind and option- 409 length as well as the option-data octets. 411 Note that the list of options may be shorter than the data offset 412 field might imply. The content of the header beyond the End-of- 413 Option option must be header padding (i.e., zero). 415 The list of all currently defined options is managed by IANA [40], 416 and each option is defined in other RFCs, as indicated there. That 417 set includes experimental options that can be extended to support 418 multiple concurrent uses [33]. 420 A given TCP implementation can support any currently defined 421 options, but the following options MUST be supported (kind 422 indicated in octal): 424 Kind Length Meaning 425 ---- ------ ------- 426 0 - End of option list. 427 1 - No-Operation. 428 2 4 Maximum Segment Size. 430 A TCP MUST be able to receive a TCP option in any segment. 431 A TCP MUST ignore without error any TCP option it does not 432 implement, assuming that the option has a length field (all TCP 433 options except End of option list and No-Operation have length 434 fields). TCP MUST be prepared to handle an illegal option length 435 (e.g., zero) without crashing; a suggested procedure is to reset 436 the connection and log the reason. 438 Specific Option Definitions 440 End of Option List 442 +--------+ 443 |00000000| 444 +--------+ 445 Kind=0 447 This option code indicates the end of the option list. This 448 might not coincide with the end of the TCP header according to 449 the Data Offset field. This is used at the end of all options, 450 not the end of each option, and need only be used if the end of 451 the options would not otherwise coincide with the end of the TCP 452 header. 454 No-Operation 456 +--------+ 457 |00000001| 458 +--------+ 459 Kind=1 461 This option code may be used between options, for example, to 462 align the beginning of a subsequent option on a word boundary. 463 There is no guarantee that senders will use this option, so 464 receivers must be prepared to process options even if they do 465 not begin on a word boundary. 467 Maximum Segment Size (MSS) 469 +--------+--------+---------+--------+ 470 |00000010|00000100| max seg size | 471 +--------+--------+---------+--------+ 472 Kind=2 Length=4 474 Maximum Segment Size Option Data: 16 bits 476 If this option is present, then it communicates the maximum 477 receive segment size at the TCP which sends this segment. This 478 value is limited by the IP reassembly limit. This field may be 479 sent in the initial connection request (i.e., in segments with 480 the SYN control bit set) and must not be sent in other segments. 481 If this option is not used, any segment size is allowed. A more 482 complete description of this option is in Section 6.1. 484 Padding: variable 486 The TCP header padding is used to ensure that the TCP header ends 487 and data begins on a 32 bit boundary. The padding is composed of 488 zeros. 490 3.2. Terminology 492 Before we can discuss very much about the operation of the TCP we 493 need to introduce some detailed terminology. The maintenance of a 494 TCP connection requires the remembering of several variables. We 495 conceive of these variables being stored in a connection record 496 called a Transmission Control Block or TCB. Among the variables 497 stored in the TCB are the local and remote socket numbers, the IP 498 security level and compartment of the connection, pointers to the 499 user's send and receive buffers, pointers to the retransmit queue and 500 to the current segment. In addition several variables relating to 501 the send and receive sequence numbers are stored in the TCB. 503 Send Sequence Variables 505 SND.UNA - send unacknowledged 506 SND.NXT - send next 507 SND.WND - send window 508 SND.UP - send urgent pointer 509 SND.WL1 - segment sequence number used for last window update 510 SND.WL2 - segment acknowledgment number used for last window 511 update 512 ISS - initial send sequence number 514 Receive Sequence Variables 516 RCV.NXT - receive next 517 RCV.WND - receive window 518 RCV.UP - receive urgent pointer 519 IRS - initial receive sequence number 521 The following diagrams may help to relate some of these variables to 522 the sequence space. 524 Send Sequence Space 526 1 2 3 4 527 ----------|----------|----------|---------- 528 SND.UNA SND.NXT SND.UNA 529 +SND.WND 531 1 - old sequence numbers which have been acknowledged 532 2 - sequence numbers of unacknowledged data 533 3 - sequence numbers allowed for new data transmission 534 4 - future sequence numbers which are not yet allowed 536 Send Sequence Space 538 Figure 2 540 The send window is the portion of the sequence space labeled 3 in 541 Figure 2. 543 Receive Sequence Space 545 1 2 3 546 ----------|----------|---------- 547 RCV.NXT RCV.NXT 548 +RCV.WND 550 1 - old sequence numbers which have been acknowledged 551 2 - sequence numbers allowed for new reception 552 3 - future sequence numbers which are not yet allowed 554 Receive Sequence Space 556 Figure 3 558 The receive window is the portion of the sequence space labeled 2 in 559 Figure 3. 561 There are also some variables used frequently in the discussion that 562 take their values from the fields of the current segment. 564 Current Segment Variables 566 SEG.SEQ - segment sequence number 567 SEG.ACK - segment acknowledgment number 568 SEG.LEN - segment length 569 SEG.WND - segment window 570 SEG.UP - segment urgent pointer 572 A connection progresses through a series of states during its 573 lifetime. The states are: LISTEN, SYN-SENT, SYN-RECEIVED, 574 ESTABLISHED, FIN-WAIT-1, FIN-WAIT-2, CLOSE-WAIT, CLOSING, LAST-ACK, 575 TIME-WAIT, and the fictional state CLOSED. CLOSED is fictional 576 because it represents the state when there is no TCB, and therefore, 577 no connection. Briefly the meanings of the states are: 579 LISTEN - represents waiting for a connection request from any 580 remote TCP and port. 582 SYN-SENT - represents waiting for a matching connection request 583 after having sent a connection request. 585 SYN-RECEIVED - represents waiting for a confirming connection 586 request acknowledgment after having both received and sent a 587 connection request. 589 ESTABLISHED - represents an open connection, data received can be 590 delivered to the user. The normal state for the data transfer 591 phase of the connection. 593 FIN-WAIT-1 - represents waiting for a connection termination 594 request from the remote TCP, or an acknowledgment of the 595 connection termination request previously sent. 597 FIN-WAIT-2 - represents waiting for a connection termination 598 request from the remote TCP. 600 CLOSE-WAIT - represents waiting for a connection termination 601 request from the local user. 603 CLOSING - represents waiting for a connection termination request 604 acknowledgment from the remote TCP. 606 LAST-ACK - represents waiting for an acknowledgment of the 607 connection termination request previously sent to the remote TCP 608 (this termination request sent to the remote TCP already included 609 an acknowledgment of the termination request sent from the remote 610 TCP). 612 TIME-WAIT - represents waiting for enough time to pass to be sure 613 the remote TCP received the acknowledgment of its connection 614 termination request. 616 CLOSED - represents no connection state at all. 618 A TCP connection progresses from one state to another in response to 619 events. The events are the user calls, OPEN, SEND, RECEIVE, CLOSE, 620 ABORT, and STATUS; the incoming segments, particularly those 621 containing the SYN, ACK, RST and FIN flags; and timeouts. 623 The state diagram in Figure 4 illustrates only state changes, 624 together with the causing events and resulting actions, but addresses 625 neither error conditions nor actions which are not connected with 626 state changes. In a later section, more detail is offered with 627 respect to the reaction of the TCP to events. Some state names are 628 abbreviated or hyphenated differently in the diagram from how they 629 appear elsewhere in the document. 631 NOTA BENE: This diagram is only a summary and must not be taken as 632 the total specification. Many details are not included. 634 +---------+ ---------\ active OPEN 635 | CLOSED | \ ----------- 636 +---------+<---------\ \ create TCB 637 | ^ \ \ snd SYN 638 passive OPEN | | CLOSE \ \ 639 ------------ | | ---------- \ \ 640 create TCB | | delete TCB \ \ 641 V | \ \ 642 rcv RST (note 1) +---------+ CLOSE | \ 643 -------------------->| LISTEN | ---------- | | 644 / +---------+ delete TCB | | 645 / rcv SYN | | SEND | | 646 / ----------- | | ------- | V 647 +--------+ snd SYN,ACK / \ snd SYN +--------+ 648 | |<----------------- ------------------>| | 649 | SYN | rcv SYN | SYN | 650 | RCVD |<-----------------------------------------------| SENT | 651 | | snd SYN,ACK | | 652 | |------------------ -------------------| | 653 +--------+ rcv ACK of SYN \ / rcv SYN,ACK +--------+ 654 | -------------- | | ----------- 655 | x | | snd ACK 656 | V V 657 | CLOSE +---------+ 658 | ------- | ESTAB | 659 | snd FIN +---------+ 660 | CLOSE | | rcv FIN 661 V ------- | | ------- 662 +---------+ snd FIN / \ snd ACK +---------+ 663 | FIN |<----------------- ------------------>| CLOSE | 664 | WAIT-1 |------------------ | WAIT | 665 +---------+ rcv FIN \ +---------+ 666 | rcv ACK of FIN ------- | CLOSE | 667 | -------------- snd ACK | ------- | 668 V x V snd FIN V 669 +---------+ +---------+ +---------+ 670 |FINWAIT-2| | CLOSING | | LAST-ACK| 671 +---------+ +---------+ +---------+ 672 | rcv ACK of FIN | rcv ACK of FIN | 673 | rcv FIN -------------- | Timeout=2MSL -------------- | 674 | ------- x V ------------ x V 675 \ snd ACK +---------+delete TCB +---------+ 676 ------------------------>|TIME WAIT|------------------>| CLOSED | 677 +---------+ +---------+ 679 note 1: The transition from SYN-RECEIVED to LISTEN on receiving a RST is 680 conditional on having reached SYN-RECEIVED after a passive open. 682 note 2: An unshown transition exists from FIN-WAIT-1 to TIME-WAIT if 683 a FIN is received and the local FIN is also acknowledged. 685 TCP Connection State Diagram 687 Figure 4 689 3.3. Sequence Numbers 691 A fundamental notion in the design is that every octet of data sent 692 over a TCP connection has a sequence number. Since every octet is 693 sequenced, each of them can be acknowledged. The acknowledgment 694 mechanism employed is cumulative so that an acknowledgment of 695 sequence number X indicates that all octets up to but not including X 696 have been received. This mechanism allows for straight-forward 697 duplicate detection in the presence of retransmission. Numbering of 698 octets within a segment is that the first data octet immediately 699 following the header is the lowest numbered, and the following octets 700 are numbered consecutively. 702 It is essential to remember that the actual sequence number space is 703 finite, though very large. This space ranges from 0 to 2**32 - 1. 704 Since the space is finite, all arithmetic dealing with sequence 705 numbers must be performed modulo 2**32. This unsigned arithmetic 706 preserves the relationship of sequence numbers as they cycle from 707 2**32 - 1 to 0 again. There are some subtleties to computer modulo 708 arithmetic, so great care should be taken in programming the 709 comparison of such values. The symbol "=<" means "less than or 710 equal" (modulo 2**32). 712 The typical kinds of sequence number comparisons which the TCP must 713 perform include: 715 (a) Determining that an acknowledgment refers to some sequence 716 number sent but not yet acknowledged. 718 (b) Determining that all sequence numbers occupied by a segment 719 have been acknowledged (e.g., to remove the segment from a 720 retransmission queue). 722 (c) Determining that an incoming segment contains sequence numbers 723 which are expected (i.e., that the segment "overlaps" the receive 724 window). 726 In response to sending data the TCP will receive acknowledgments. 727 The following comparisons are needed to process the acknowledgments. 729 SND.UNA = oldest unacknowledged sequence number 731 SND.NXT = next sequence number to be sent 732 SEG.ACK = acknowledgment from the receiving TCP (next sequence 733 number expected by the receiving TCP) 735 SEG.SEQ = first sequence number of a segment 737 SEG.LEN = the number of octets occupied by the data in the segment 738 (counting SYN and FIN) 740 SEG.SEQ+SEG.LEN-1 = last sequence number of a segment 742 A new acknowledgment (called an "acceptable ack"), is one for which 743 the inequality below holds: 745 SND.UNA < SEG.ACK =< SND.NXT 747 A segment on the retransmission queue is fully acknowledged if the 748 sum of its sequence number and length is less or equal than the 749 acknowledgment value in the incoming segment. 751 When data is received the following comparisons are needed: 753 RCV.NXT = next sequence number expected on an incoming segments, 754 and is the left or lower edge of the receive window 756 RCV.NXT+RCV.WND-1 = last sequence number expected on an incoming 757 segment, and is the right or upper edge of the receive window 759 SEG.SEQ = first sequence number occupied by the incoming segment 761 SEG.SEQ+SEG.LEN-1 = last sequence number occupied by the incoming 762 segment 764 A segment is judged to occupy a portion of valid receive sequence 765 space if 767 RCV.NXT =< SEG.SEQ < RCV.NXT+RCV.WND 769 or 771 RCV.NXT =< SEG.SEQ+SEG.LEN-1 < RCV.NXT+RCV.WND 773 The first part of this test checks to see if the beginning of the 774 segment falls in the window, the second part of the test checks to 775 see if the end of the segment falls in the window; if the segment 776 passes either part of the test it contains data in the window. 778 Actually, it is a little more complicated than this. Due to zero 779 windows and zero length segments, we have four cases for the 780 acceptability of an incoming segment: 782 Segment Receive Test 783 Length Window 784 ------- ------- ------------------------------------------- 786 0 0 SEG.SEQ = RCV.NXT 788 0 >0 RCV.NXT =< SEG.SEQ < RCV.NXT+RCV.WND 790 >0 0 not acceptable 792 >0 >0 RCV.NXT =< SEG.SEQ < RCV.NXT+RCV.WND 793 or RCV.NXT =< SEG.SEQ+SEG.LEN-1 < RCV.NXT+RCV.WND 795 Note that when the receive window is zero no segments should be 796 acceptable except ACK segments. Thus, it is be possible for a TCP to 797 maintain a zero receive window while transmitting data and receiving 798 ACKs. However, even when the receive window is zero, a TCP must 799 process the RST and URG fields of all incoming segments. 801 We have taken advantage of the numbering scheme to protect certain 802 control information as well. This is achieved by implicitly 803 including some control flags in the sequence space so they can be 804 retransmitted and acknowledged without confusion (i.e., one and only 805 one copy of the control will be acted upon). Control information is 806 not physically carried in the segment data space. Consequently, we 807 must adopt rules for implicitly assigning sequence numbers to 808 control. The SYN and FIN are the only controls requiring this 809 protection, and these controls are used only at connection opening 810 and closing. For sequence number purposes, the SYN is considered to 811 occur before the first actual data octet of the segment in which it 812 occurs, while the FIN is considered to occur after the last actual 813 data octet in a segment in which it occurs. The segment length 814 (SEG.LEN) includes both data and sequence space occupying controls. 815 When a SYN is present then SEG.SEQ is the sequence number of the SYN. 817 Initial Sequence Number Selection 819 The protocol places no restriction on a particular connection being 820 used over and over again. A connection is defined by a pair of 821 sockets. New instances of a connection will be referred to as 822 incarnations of the connection. The problem that arises from this is 823 -- "how does the TCP identify duplicate segments from previous 824 incarnations of the connection?" This problem becomes apparent if 825 the connection is being opened and closed in quick succession, or if 826 the connection breaks with loss of memory and is then reestablished. 828 To avoid confusion we must prevent segments from one incarnation of a 829 connection from being used while the same sequence numbers may still 830 be present in the network from an earlier incarnation. We want to 831 assure this, even if a TCP crashes and loses all knowledge of the 832 sequence numbers it has been using. When new connections are 833 created, an initial sequence number (ISN) generator is employed which 834 selects a new 32 bit ISN. There are security issues that result if 835 an off-path attacker is able to predict or guess ISN values. 837 The recommended ISN generator is based on the combination of a 838 (possibly fictitious) 32 bit clock whose low order bit is incremented 839 roughly every 4 microseconds, and a pseudorandom hash function (PRF). 840 The clock component is intended to insure that with a Maximum Segment 841 Lifetime (MSL), generated ISNs will be unique, since it cycles 842 approximately every 4.55 hours, which is much longer than the MSL. 843 This recommended algorithm is further described in RFC 1948 and 844 builds on the basic clock-driven algorithm from RFC 793. 846 A TCP MUST use a clock-driven selection of initial sequence numbers, 847 and SHOULD generate its Initial Sequence Numbers with the expression: 849 ISN = M + F(localip, localport, remoteip, remoteport, secretkey) 851 where M is the 4 microsecond timer, and F() is a pseudorandom 852 function (PRF) of the connection's identifying parameters ("localip, 853 localport, remoteip, remoteport") and a secret key ("secretkey"). 854 F() MUST NOT be computable from the outside, or an attacker could 855 still guess at sequence numbers from the ISN used for some other 856 connection. The PRF could be implemented as a cryptographic has of 857 the concatenation of the TCP connection parameters and some secret 858 data. For discussion of the selection of a specific hash algorithm 859 and management of the secret key data, please see Section 3 of [31]. 861 For each connection there is a send sequence number and a receive 862 sequence number. The initial send sequence number (ISS) is chosen by 863 the data sending TCP, and the initial receive sequence number (IRS) 864 is learned during the connection establishing procedure. 866 For a connection to be established or initialized, the two TCPs must 867 synchronize on each other's initial sequence numbers. This is done 868 in an exchange of connection establishing segments carrying a control 869 bit called "SYN" (for synchronize) and the initial sequence numbers. 870 As a shorthand, segments carrying the SYN bit are also called "SYNs". 871 Hence, the solution requires a suitable mechanism for picking an 872 initial sequence number and a slightly involved handshake to exchange 873 the ISN's. 875 The synchronization requires each side to send it's own initial 876 sequence number and to receive a confirmation of it in acknowledgment 877 from the other side. Each side must also receive the other side's 878 initial sequence number and send a confirming acknowledgment. 880 1) A --> B SYN my sequence number is X 881 2) A <-- B ACK your sequence number is X 882 3) A <-- B SYN my sequence number is Y 883 4) A --> B ACK your sequence number is Y 885 Because steps 2 and 3 can be combined in a single message this is 886 called the three way (or three message) handshake. 888 A three way handshake is necessary because sequence numbers are not 889 tied to a global clock in the network, and TCPs may have different 890 mechanisms for picking the ISN's. The receiver of the first SYN has 891 no way of knowing whether the segment was an old delayed one or not, 892 unless it remembers the last sequence number used on the connection 893 (which is not always possible), and so it must ask the sender to 894 verify this SYN. The three way handshake and the advantages of a 895 clock-driven scheme are discussed in [3]. 897 Knowing When to Keep Quiet 899 To be sure that a TCP does not create a segment that carries a 900 sequence number which may be duplicated by an old segment remaining 901 in the network, the TCP must keep quiet for an MSL before assigning 902 any sequence numbers upon starting up or recovering from a crash in 903 which memory of sequence numbers in use was lost. For this 904 specification the MSL is taken to be 2 minutes. This is an 905 engineering choice, and may be changed if experience indicates it is 906 desirable to do so. Note that if a TCP is reinitialized in some 907 sense, yet retains its memory of sequence numbers in use, then it 908 need not wait at all; it must only be sure to use sequence numbers 909 larger than those recently used. 911 The TCP Quiet Time Concept 913 This specification provides that hosts which "crash" without 914 retaining any knowledge of the last sequence numbers transmitted on 915 each active (i.e., not closed) connection shall delay emitting any 916 TCP segments for at least the agreed MSL in the internet system of 917 which the host is a part. In the paragraphs below, an explanation 918 for this specification is given. TCP implementors may violate the 919 "quiet time" restriction, but only at the risk of causing some old 920 data to be accepted as new or new data rejected as old duplicated by 921 some receivers in the internet system. 923 TCPs consume sequence number space each time a segment is formed and 924 entered into the network output queue at a source host. The 925 duplicate detection and sequencing algorithm in the TCP protocol 926 relies on the unique binding of segment data to sequence space to the 927 extent that sequence numbers will not cycle through all 2**32 values 928 before the segment data bound to those sequence numbers has been 929 delivered and acknowledged by the receiver and all duplicate copies 930 of the segments have "drained" from the internet. Without such an 931 assumption, two distinct TCP segments could conceivably be assigned 932 the same or overlapping sequence numbers, causing confusion at the 933 receiver as to which data is new and which is old. Remember that 934 each segment is bound to as many consecutive sequence numbers as 935 there are octets of data and SYN or FIN flags in the segment. 937 Under normal conditions, TCPs keep track of the next sequence number 938 to emit and the oldest awaiting acknowledgment so as to avoid 939 mistakenly using a sequence number over before its first use has been 940 acknowledged. This alone does not guarantee that old duplicate data 941 is drained from the net, so the sequence space has been made very 942 large to reduce the probability that a wandering duplicate will cause 943 trouble upon arrival. At 2 megabits/sec. it takes 4.5 hours to use 944 up 2**32 octets of sequence space. Since the maximum segment 945 lifetime in the net is not likely to exceed a few tens of seconds, 946 this is deemed ample protection for foreseeable nets, even if data 947 rates escalate to l0's of megabits/sec. At 100 megabits/sec, the 948 cycle time is 5.4 minutes which may be a little short, but still 949 within reason. 951 The basic duplicate detection and sequencing algorithm in TCP can be 952 defeated, however, if a source TCP does not have any memory of the 953 sequence numbers it last used on a given connection. For example, if 954 the TCP were to start all connections with sequence number 0, then 955 upon crashing and restarting, a TCP might re-form an earlier 956 connection (possibly after half-open connection resolution) and emit 957 packets with sequence numbers identical to or overlapping with 958 packets still in the network which were emitted on an earlier 959 incarnation of the same connection. In the absence of knowledge 960 about the sequence numbers used on a particular connection, the TCP 961 specification recommends that the source delay for MSL seconds before 962 emitting segments on the connection, to allow time for segments from 963 the earlier connection incarnation to drain from the system. 965 Even hosts which can remember the time of day and used it to select 966 initial sequence number values are not immune from this problem 967 (i.e., even if time of day is used to select an initial sequence 968 number for each new connection incarnation). 970 Suppose, for example, that a connection is opened starting with 971 sequence number S. Suppose that this connection is not used much and 972 that eventually the initial sequence number function (ISN(t)) takes 973 on a value equal to the sequence number, say S1, of the last segment 974 sent by this TCP on a particular connection. Now suppose, at this 975 instant, the host crashes, recovers, and establishes a new 976 incarnation of the connection. The initial sequence number chosen is 977 S1 = ISN(t) -- last used sequence number on old incarnation of 978 connection! If the recovery occurs quickly enough, any old 979 duplicates in the net bearing sequence numbers in the neighborhood of 980 S1 may arrive and be treated as new packets by the receiver of the 981 new incarnation of the connection. 983 The problem is that the recovering host may not know for how long it 984 crashed nor does it know whether there are still old duplicates in 985 the system from earlier connection incarnations. 987 One way to deal with this problem is to deliberately delay emitting 988 segments for one MSL after recovery from a crash- this is the "quiet 989 time" specification. Hosts which prefer to avoid waiting are willing 990 to risk possible confusion of old and new packets at a given 991 destination may choose not to wait for the "quite time". 992 Implementors may provide TCP users with the ability to select on a 993 connection by connection basis whether to wait after a crash, or may 994 informally implement the "quite time" for all connections. 995 Obviously, even where a user selects to "wait," this is not necessary 996 after the host has been "up" for at least MSL seconds. 998 To summarize: every segment emitted occupies one or more sequence 999 numbers in the sequence space, the numbers occupied by a segment are 1000 "busy" or "in use" until MSL seconds have passed, upon crashing a 1001 block of space-time is occupied by the octets and SYN or FIN flags of 1002 the last emitted segment, if a new connection is started too soon and 1003 uses any of the sequence numbers in the space-time footprint of the 1004 last segment of the previous connection incarnation, there is a 1005 potential sequence number overlap area which could cause confusion at 1006 the receiver. 1008 3.4. Establishing a connection 1010 The "three-way handshake" is the procedure used to establish a 1011 connection. This procedure normally is initiated by one TCP and 1012 responded to by another TCP. The procedure also works if two TCP 1013 simultaneously initiate the procedure. When simultaneous attempt 1014 occurs, each TCP receives a "SYN" segment which carries no 1015 acknowledgment after it has sent a "SYN". Of course, the arrival of 1016 an old duplicate "SYN" segment can potentially make it appear, to the 1017 recipient, that a simultaneous connection initiation is in progress. 1018 Proper use of "reset" segments can disambiguate these cases. 1020 Several examples of connection initiation follow. Although these 1021 examples do not show connection synchronization using data-carrying 1022 segments, this is perfectly legitimate, so long as the receiving TCP 1023 doesn't deliver the data to the user until it is clear the data is 1024 valid (i.e., the data must be buffered at the receiver until the 1025 connection reaches the ESTABLISHED state). The three-way handshake 1026 reduces the possibility of false connections. It is the 1027 implementation of a trade-off between memory and messages to provide 1028 information for this checking. 1030 The simplest three-way handshake is shown in Figure 5 below. The 1031 figures should be interpreted in the following way. Each line is 1032 numbered for reference purposes. Right arrows (-->) indicate 1033 departure of a TCP segment from TCP A to TCP B, or arrival of a 1034 segment at B from A. Left arrows (<--), indicate the reverse. 1035 Ellipsis (...) indicates a segment which is still in the network 1036 (delayed). An "XXX" indicates a segment which is lost or rejected. 1037 Comments appear in parentheses. TCP states represent the state AFTER 1038 the departure or arrival of the segment (whose contents are shown in 1039 the center of each line). Segment contents are shown in abbreviated 1040 form, with sequence number, control flags, and ACK field. Other 1041 fields such as window, addresses, lengths, and text have been left 1042 out in the interest of clarity. 1044 TCP A TCP B 1046 1. CLOSED LISTEN 1048 2. SYN-SENT --> --> SYN-RECEIVED 1050 3. ESTABLISHED <-- <-- SYN-RECEIVED 1052 4. ESTABLISHED --> --> ESTABLISHED 1054 5. ESTABLISHED --> --> ESTABLISHED 1056 Basic 3-Way Handshake for Connection Synchronization 1058 Figure 5 1060 In line 2 of Figure 5, TCP A begins by sending a SYN segment 1061 indicating that it will use sequence numbers starting with sequence 1062 number 100. In line 3, TCP B sends a SYN and acknowledges the SYN it 1063 received from TCP A. Note that the acknowledgment field indicates 1064 TCP B is now expecting to hear sequence 101, acknowledging the SYN 1065 which occupied sequence 100. 1067 At line 4, TCP A responds with an empty segment containing an ACK for 1068 TCP B's SYN; and in line 5, TCP A sends some data. Note that the 1069 sequence number of the segment in line 5 is the same as in line 4 1070 because the ACK does not occupy sequence number space (if it did, we 1071 would wind up ACKing ACK's!). 1073 Simultaneous initiation is only slightly more complex, as is shown in 1074 Figure 6. Each TCP cycles from CLOSED to SYN-SENT to SYN-RECEIVED to 1075 ESTABLISHED. 1077 TCP A TCP B 1079 1. CLOSED CLOSED 1081 2. SYN-SENT --> ... 1083 3. SYN-RECEIVED <-- <-- SYN-SENT 1085 4. ... --> SYN-RECEIVED 1087 5. SYN-RECEIVED --> ... 1089 6. ESTABLISHED <-- <-- SYN-RECEIVED 1091 7. ... --> ESTABLISHED 1093 Simultaneous Connection Synchronization 1095 Figure 6 1097 A TCP MUST support simultaneous open attempts. 1099 Note that a TCP implementation MUST keep track of whether a 1100 connection has reached SYN-RECEIVED state as the result of a passive 1101 OPEN or an active OPEN. 1103 The principle reason for the three-way handshake is to prevent old 1104 duplicate connection initiations from causing confusion. To deal 1105 with this, a special control message, reset, has been devised. If 1106 the receiving TCP is in a non-synchronized state (i.e., SYN-SENT, 1107 SYN-RECEIVED), it returns to LISTEN on receiving an acceptable reset. 1108 If the TCP is in one of the synchronized states (ESTABLISHED, FIN- 1109 WAIT-1, FIN-WAIT-2, CLOSE-WAIT, CLOSING, LAST-ACK, TIME-WAIT), it 1110 aborts the connection and informs its user. We discuss this latter 1111 case under "half-open" connections below. 1113 TCP A TCP B 1115 1. CLOSED LISTEN 1117 2. SYN-SENT --> ... 1119 3. (duplicate) ... --> SYN-RECEIVED 1121 4. SYN-SENT <-- <-- SYN-RECEIVED 1123 5. SYN-SENT --> --> LISTEN 1125 6. ... --> SYN-RECEIVED 1127 7. SYN-SENT <-- <-- SYN-RECEIVED 1129 8. ESTABLISHED --> --> ESTABLISHED 1131 Recovery from Old Duplicate SYN 1133 Figure 7 1135 As a simple example of recovery from old duplicates, consider 1136 Figure 7. At line 3, an old duplicate SYN arrives at TCP B. TCP B 1137 cannot tell that this is an old duplicate, so it responds normally 1138 (line 4). TCP A detects that the ACK field is incorrect and returns 1139 a RST (reset) with its SEQ field selected to make the segment 1140 believable. TCP B, on receiving the RST, returns to the LISTEN 1141 state. When the original SYN (pun intended) finally arrives at line 1142 6, the synchronization proceeds normally. If the SYN at line 6 had 1143 arrived before the RST, a more complex exchange might have occurred 1144 with RST's sent in both directions. 1146 Half-Open Connections and Other Anomalies 1148 An established connection is said to be "half-open" if one of the 1149 TCPs has closed or aborted the connection at its end without the 1150 knowledge of the other, or if the two ends of the connection have 1151 become desynchronized owing to a crash that resulted in loss of 1152 memory. Such connections will automatically become reset if an 1153 attempt is made to send data in either direction. However, half-open 1154 connections are expected to be unusual, and the recovery procedure is 1155 mildly involved. 1157 If at site A the connection no longer exists, then an attempt by the 1158 user at site B to send any data on it will result in the site B TCP 1159 receiving a reset control message. Such a message indicates to the 1160 site B TCP that something is wrong, and it is expected to abort the 1161 connection. 1163 Assume that two user processes A and B are communicating with one 1164 another when a crash occurs causing loss of memory to A's TCP. 1165 Depending on the operating system supporting A's TCP, it is likely 1166 that some error recovery mechanism exists. When the TCP is up again, 1167 A is likely to start again from the beginning or from a recovery 1168 point. As a result, A will probably try to OPEN the connection again 1169 or try to SEND on the connection it believes open. In the latter 1170 case, it receives the error message "connection not open" from the 1171 local (A's) TCP. In an attempt to establish the connection, A's TCP 1172 will send a segment containing SYN. This scenario leads to the 1173 example shown in Figure 8. After TCP A crashes, the user attempts to 1174 re-open the connection. TCP B, in the meantime, thinks the 1175 connection is open. 1177 TCP A TCP B 1179 1. (CRASH) (send 300,receive 100) 1181 2. CLOSED ESTABLISHED 1183 3. SYN-SENT --> --> (??) 1185 4. (!!) <-- <-- ESTABLISHED 1187 5. SYN-SENT --> --> (Abort!!) 1189 6. SYN-SENT CLOSED 1191 7. SYN-SENT --> --> 1193 Half-Open Connection Discovery 1195 Figure 8 1197 When the SYN arrives at line 3, TCP B, being in a synchronized state, 1198 and the incoming segment outside the window, responds with an 1199 acknowledgment indicating what sequence it next expects to hear (ACK 1200 100). TCP A sees that this segment does not acknowledge anything it 1201 sent and, being unsynchronized, sends a reset (RST) because it has 1202 detected a half-open connection. TCP B aborts at line 5. TCP A will 1203 continue to try to establish the connection; the problem is now 1204 reduced to the basic 3-way handshake of Figure 5. 1206 An interesting alternative case occurs when TCP A crashes and TCP B 1207 tries to send data on what it thinks is a synchronized connection. 1208 This is illustrated in Figure 9. In this case, the data arriving at 1209 TCP A from TCP B (line 2) is unacceptable because no such connection 1210 exists, so TCP A sends a RST. The RST is acceptable so TCP B 1211 processes it and aborts the connection. 1213 TCP A TCP B 1215 1. (CRASH) (send 300,receive 100) 1217 2. (??) <-- <-- ESTABLISHED 1219 3. --> --> (ABORT!!) 1221 Active Side Causes Half-Open Connection Discovery 1223 Figure 9 1225 In Figure 10, we find the two TCPs A and B with passive connections 1226 waiting for SYN. An old duplicate arriving at TCP B (line 2) stirs B 1227 into action. A SYN-ACK is returned (line 3) and causes TCP A to 1228 generate a RST (the ACK in line 3 is not acceptable). TCP B accepts 1229 the reset and returns to its passive LISTEN state. 1231 TCP A TCP B 1233 1. LISTEN LISTEN 1235 2. ... --> SYN-RECEIVED 1237 3. (??) <-- <-- SYN-RECEIVED 1239 4. --> --> (return to LISTEN!) 1241 5. LISTEN LISTEN 1243 Old Duplicate SYN Initiates a Reset on two Passive Sockets 1245 Figure 10 1247 A variety of other cases are possible, all of which are accounted for 1248 by the following rules for RST generation and processing. 1250 Reset Generation 1251 As a general rule, reset (RST) must be sent whenever a segment 1252 arrives which apparently is not intended for the current connection. 1253 A reset must not be sent if it is not clear that this is the case. 1255 There are three groups of states: 1257 1. If the connection does not exist (CLOSED) then a reset is sent 1258 in response to any incoming segment except another reset. In 1259 particular, SYNs addressed to a non-existent connection are 1260 rejected by this means. 1262 If the incoming segment has the ACK bit set, the reset takes its 1263 sequence number from the ACK field of the segment, otherwise the 1264 reset has sequence number zero and the ACK field is set to the sum 1265 of the sequence number and segment length of the incoming segment. 1266 The connection remains in the CLOSED state. 1268 2. If the connection is in any non-synchronized state (LISTEN, 1269 SYN-SENT, SYN-RECEIVED), and the incoming segment acknowledges 1270 something not yet sent (the segment carries an unacceptable ACK), 1271 or if an incoming segment has a security level or compartment 1272 which does not exactly match the level and compartment requested 1273 for the connection, a reset is sent. 1275 If the incoming segment has an ACK field, the reset takes its 1276 sequence number from the ACK field of the segment, otherwise the 1277 reset has sequence number zero and the ACK field is set to the sum 1278 of the sequence number and segment length of the incoming segment. 1279 The connection remains in the same state. 1281 3. If the connection is in a synchronized state (ESTABLISHED, 1282 FIN-WAIT-1, FIN-WAIT-2, CLOSE-WAIT, CLOSING, LAST-ACK, TIME-WAIT), 1283 any unacceptable segment (out of window sequence number or 1284 unacceptable acknowledgment number) must elicit only an empty 1285 acknowledgment segment containing the current send-sequence number 1286 and an acknowledgment indicating the next sequence number expected 1287 to be received, and the connection remains in the same state. 1289 If an incoming segment has a security level, or compartment which 1290 does not exactly match the level and compartment requested for the 1291 connection, a reset is sent and the connection goes to the CLOSED 1292 state. The reset takes its sequence number from the ACK field of 1293 the incoming segment. 1295 Reset Processing 1297 In all states except SYN-SENT, all reset (RST) segments are validated 1298 by checking their SEQ-fields. A reset is valid if its sequence 1299 number is in the window. In the SYN-SENT state (a RST received in 1300 response to an initial SYN), the RST is acceptable if the ACK field 1301 acknowledges the SYN. 1303 The receiver of a RST first validates it, then changes state. If the 1304 receiver was in the LISTEN state, it ignores it. If the receiver was 1305 in SYN-RECEIVED state and had previously been in the LISTEN state, 1306 then the receiver returns to the LISTEN state, otherwise the receiver 1307 aborts the connection and goes to the CLOSED state. If the receiver 1308 was in any other state, it aborts the connection and advises the user 1309 and goes to the CLOSED state. 1311 TCP SHOULD allow a received RST segment to include data. 1313 4. Closing a Connection 1315 CLOSE is an operation meaning "I have no more data to send." The 1316 notion of closing a full-duplex connection is subject to ambiguous 1317 interpretation, of course, since it may not be obvious how to treat 1318 the receiving side of the connection. We have chosen to treat CLOSE 1319 in a simplex fashion. The user who CLOSEs may continue to RECEIVE 1320 until he is told that the other side has CLOSED also. Thus, a 1321 program could initiate several SENDs followed by a CLOSE, and then 1322 continue to RECEIVE until signaled that a RECEIVE failed because the 1323 other side has CLOSED. We assume that the TCP will signal a user, 1324 even if no RECEIVEs are outstanding, that the other side has closed, 1325 so the user can terminate his side gracefully. A TCP will reliably 1326 deliver all buffers SENT before the connection was CLOSED so a user 1327 who expects no data in return need only wait to hear the connection 1328 was CLOSED successfully to know that all his data was received at the 1329 destination TCP. Users must keep reading connections they close for 1330 sending until the TCP says no more data. 1332 There are essentially three cases: 1334 1) The user initiates by telling the TCP to CLOSE the connection 1336 2) The remote TCP initiates by sending a FIN control signal 1338 3) Both users CLOSE simultaneously 1340 Case 1: Local user initiates the close 1342 In this case, a FIN segment can be constructed and placed on the 1343 outgoing segment queue. No further SENDs from the user will be 1344 accepted by the TCP, and it enters the FIN-WAIT-1 state. RECEIVEs 1345 are allowed in this state. All segments preceding and including 1346 FIN will be retransmitted until acknowledged. When the other TCP 1347 has both acknowledged the FIN and sent a FIN of its own, the first 1348 TCP can ACK this FIN. Note that a TCP receiving a FIN will ACK 1349 but not send its own FIN until its user has CLOSED the connection 1350 also. 1352 Case 2: TCP receives a FIN from the network 1354 If an unsolicited FIN arrives from the network, the receiving TCP 1355 can ACK it and tell the user that the connection is closing. The 1356 user will respond with a CLOSE, upon which the TCP can send a FIN 1357 to the other TCP after sending any remaining data. The TCP then 1358 waits until its own FIN is acknowledged whereupon it deletes the 1359 connection. If an ACK is not forthcoming, after the user timeout 1360 the connection is aborted and the user is told. 1362 Case 3: both users close simultaneously 1364 A simultaneous CLOSE by users at both ends of a connection causes 1365 FIN segments to be exchanged. When all segments preceding the 1366 FINs have been processed and acknowledged, each TCP can ACK the 1367 FIN it has received. Both will, upon receiving these ACKs, delete 1368 the connection. 1370 TCP A TCP B 1372 1. ESTABLISHED ESTABLISHED 1374 2. (Close) 1375 FIN-WAIT-1 --> --> CLOSE-WAIT 1377 3. FIN-WAIT-2 <-- <-- CLOSE-WAIT 1379 4. (Close) 1380 TIME-WAIT <-- <-- LAST-ACK 1382 5. TIME-WAIT --> --> CLOSED 1384 6. (2 MSL) 1385 CLOSED 1387 Normal Close Sequence 1389 Figure 11 1391 TCP A TCP B 1393 1. ESTABLISHED ESTABLISHED 1395 2. (Close) (Close) 1396 FIN-WAIT-1 --> ... FIN-WAIT-1 1397 <-- <-- 1398 ... --> 1400 3. CLOSING --> ... CLOSING 1401 <-- <-- 1402 ... --> 1404 4. TIME-WAIT TIME-WAIT 1405 (2 MSL) (2 MSL) 1406 CLOSED CLOSED 1408 Simultaneous Close Sequence 1410 Figure 12 1412 A TCP connection may terminate in two ways: (1) the normal TCP close 1413 sequence using a FIN handshake, and (2) an "abort" in which one or 1414 more RST segments are sent and the connection state is immediately 1415 discarded. If a TCP connection is closed by the remote site, the 1416 local application MUST be informed whether it closed normally or was 1417 aborted. 1419 4.1. Half-Closed Connections 1421 The normal TCP close sequence delivers buffered data reliably in both 1422 directions. Since the two directions of a TCP connection are closed 1423 independently, it is possible for a connection to be "half closed," 1424 i.e., closed in only one direction, and a host is permitted to 1425 continue sending data in the open direction on a half-closed 1426 connection. 1428 A host MAY implement a "half-duplex" TCP close sequence, so that an 1429 application that has called CLOSE cannot continue to read data from 1430 the connection. If such a host issues a CLOSE call while received 1431 data is still pending in TCP, or if new data is received after CLOSE 1432 is called, its TCP SHOULD send a RST to show that data was lost. 1434 When a connection is closed actively, it MUST linger in TIME-WAIT 1435 state for a time 2xMSL (Maximum Segment Lifetime). However, it MAY 1436 accept a new SYN from the remote TCP to reopen the connection 1437 directly from TIME-WAIT state, if it: 1439 (1) assigns its initial sequence number for the new connection to 1440 be larger than the largest sequence number it used on the previous 1441 connection incarnation, and 1443 (2) returns to TIME-WAIT state if the SYN turns out to be an old 1444 duplicate. 1446 When the TCP Timestamp options are available, an improved algorithm 1447 is described in [29] in order to support higher connection 1448 establishment rates. This algorithm for reducing TIME-WAIT is a Best 1449 Current Practice that SHOULD be implemented, since timestamp options 1450 are commonly used, and using them to reduce TIME-WAIT provides 1451 benefits for busy Internet servers. 1453 5. Precedence and Security 1455 The IPv4 specification [1] includes a precedence value in the Type of 1456 Service field (TOS), that was also modified in [15], and then 1457 obsoleted by the definition of Differentiated Services (DiffServ) 1458 [6]. In DiffServ the former precedence values are treated as Class 1459 Selector codepoints, and methods for compatible treatment are 1460 described in the DiffServ architecture. The RFC 793/1122 TCP 1461 specification includes logic intending to have connections use the 1462 highest precedence requested by either endpoint application, and to 1463 keep the precedence consistent throughout a connection. There is an 1464 assumption of bidirectional/symmetric precedence values, however, the 1465 DiffServ architecture is asymmetric. Problems were described in [17] 1466 and the solution described is to ignore IP precedence in TCP. Since 1467 RFC 2873 is a Standards Track document (although not marked as 1468 updating RFC 793), these checks are no longer a part of the TCP 1469 standard defined in this document, though the DiffServ field value is 1470 still is a part of the interface between TCP and the network layer, 1471 and values can be indicated both ways between TCP and the 1472 application. 1474 The IP security option (IPSO) and compartment defined in [1] was 1475 refined in RFC 1038 that was later obsoleted by RFC 1108. The 1476 Commercial IP Security Option (CIPSO) is defined in FIPS-188, and is 1477 supported by some vendors and operating systems. RFC 1108 is now 1478 Historic, though RFC 791 itself has not been updated to remove the IP 1479 security option. For IPv6, a similar option (CALIPSO) has been 1480 defined [23]. RFC 793 includes logic that includes the IP security/ 1481 compartment information in treatment of TCP segments. References to 1482 the IP "security/compartment" in this document may be relevant for 1483 Multi-Level Secure (MLS) system implementers, but can be ignored for 1484 non-MLS implementations, consistent with running code on the 1485 Internet. See Appendix A.1 for further discussion. Note that RFC 1486 5570 describes some MLS networking scenarios where IPSO, CIPSO, or 1487 CALIPSO may be used. In these special cases, TCP implementers should 1488 see section 7.3.1 of RFC 5570, and follow the guidance in that 1489 document on the relation between IP security. 1491 6. Segmentation 1493 The term "segmentation" refers to the activity TCP performs when 1494 ingesting a stream of bytes from a sending application and 1495 packetizing that stream of bytes into TCP segments. Individual TCP 1496 segments often do not correspond one-for-one to individual send (or 1497 socket write) calls from the application. Applications may perform 1498 writes at the granularity of messages in the upper layer protocol, 1499 but TCP guarantees no boundary coherence between the TCP segments 1500 sent and received versus user application data read or write buffer 1501 boundaries. In some specific protocols, such as RDMA using DDP and 1502 MPA [21], there are performance optimizations possible when the 1503 relation between TCP segments and application data units can be 1504 controlled, and MPA includes a specific mechanism for detecting and 1505 verifying this relationship between TCP segments and application 1506 message data strcutures, but this is specific to applications like 1507 RDMA. In general, multiple goals influence the sizing of TCP 1508 segments created by a TCP implementation. 1510 Goals driving the sending of larger segments include: 1512 o Reducing the number of packets in flight within the network. 1514 o Increasing processing efficiency and potential performance by 1515 enabling a smaller number of interrupts and inter-layer 1516 interactions. 1518 o Limiting the overhead of TCP headers. 1520 Note that the performance benefits of sending larger segments may 1521 decrease as the size increases, and there may be boundaries where 1522 advantages are reversed. For instance, on some machines 1025 bytes 1523 within a segment could lead to worse performance than 1024 bytes, due 1524 purely to data alignment on copy operations. 1526 Goals driving the sending of smaller segments include: 1528 o Avoiding sending segments larger than the smallest MTU within an 1529 IP network path, because this results in either packet loss or 1530 fragmentation. Making matters worse, some firewalls or 1531 middleboxes may drop fragmented packets or ICMP messages related 1532 related to fragmentation. 1534 o Preventing delays to the application data stream, especially when 1535 TCP is waiting on the application to generate more data, or when 1536 the application is waiting on an event or input from its peer in 1537 order to generate more data. 1539 o Enabling "fate sharing" between TCP segments and lower-layer data 1540 units (e.g. below IP, for links with cell or frame sizes smaller 1541 than the IP MTU). 1543 Towards meeting these competing sets of goals, TCP includes several 1544 mechanisms, including the Maximum Segment Size option, Path MTU 1545 Discovery, the Nagle algorithm, and support for IPv6 Jumbograms, as 1546 discussed in the following subsections. 1548 6.1. Maximum Segment Size Option 1550 TCP MUST implement both sending and receiving the MSS option. 1552 TCP SHOULD send an MSS option in every SYN segment when its receive 1553 MSS differs from the default 536 for IPv4 or 1220 for IPv6, and MAY 1554 send it always. 1556 If an MSS option is not received at connection setup, TCP MUST assume 1557 a default send MSS of 536 (576-40) for IPv4 or 1220 (1280 - 60) for 1558 IPv6. 1560 The maximum size of a segment that TCP really sends, the "effective 1561 send MSS," MUST be the smaller of the send MSS (which reflects the 1562 available reassembly buffer size at the remote host, the EMTU_R [14]) 1563 and the largest transmission size permitted by the IP layer (EMTU_S 1564 [14]): 1566 Eff.snd.MSS = 1568 min(SendMSS+20, MMS_S) - TCPhdrsize - IPoptionsize 1570 where: 1572 o SendMSS is the MSS value received from the remote host, or the 1573 default 536 for IPv4 or 1220 for IPv6, if no MSS option is 1574 received. 1576 o MMS_S is the maximum size for a transport-layer message that TCP 1577 may send. 1579 o TCPhdrsize is the size of the fixed TCP header and any options. 1580 This is 20 in the (rare) case that no options are present, but may 1581 be larger if TCP options are to be sent. Note that some options 1582 may not be included on all segments, but that for each segment 1583 sent, the sender should adjust the data length accordingly, within 1584 the Eff.snd.MSS. 1586 o IPoptionsize is the size of any IP options associated with a TCP 1587 connection. Note that some options may not be included on all 1588 packets, but that for each segment sent, the sender should adjust 1589 the data length accordingly, within the Eff.snd.MSS. 1591 The MSS value to be sent in an MSS option should be equal to the 1592 effective MTU minus the fixed IP and TCP headers. By ignoring both 1593 IP and TCP options when calculating the value for the MSS option, if 1594 there are any IP or TCP options to be sent in a packet, then the 1595 sender must decrease the size of the TCP data accordingly. RFC 6691 1596 [32] discusses this in greater detail. 1598 The MSS value to be sent in an MSS option must be less than or equal 1599 to: 1601 MMS_R - 20 1603 where MMS_R is the maximum size for a transport-layer message that 1604 can be received (and reassembled at the IP layer). TCP obtains MMS_R 1605 and MMS_S from the IP layer; see the generic call GET_MAXSIZES in 1606 Section 3.4 of RFC 1122. These are defined in terms of their IP MTU 1607 equivalents, EMTU_R and EMTU_S [14]. 1609 When TCP is used in a situation where either the IP or TCP headers 1610 are not fixed, the sender must reduce the amount of TCP data in any 1611 given packet by the number of octets used by the IP and TCP options. 1612 This has been a point of confusion historically, as explained in RFC 1613 6691, Section 3.1. 1615 6.2. Path MTU Discovery 1617 A TCP implementation may be aware of the MTU on directly connected 1618 links, but will rarely have insight about MTUs across an entire 1619 network path. For IPv4, RFC 1122 provides an IP-layer recommendation 1620 on the default effective MTU for sending to be less than or equal to 1621 576 for destinations not directly connected. For IPv6, this would be 1622 1280. In all cases, however, implementation of Path MTU Discovery 1623 (PMTUD) and Packetization Layer Path MTU Discovery (PLPMTUD) is 1624 strongly recommended in order for TCP to improve segmentation 1625 decisions. Both PMTUD and PLPMTUD help TCP choose segment sizes that 1626 avoid both on-path (for IPv4) and source fragmentation (IPv4 and 1627 IPv6). 1629 PMTUD for IPv4 [2] or IPv6 [3] is implemented in conjunction between 1630 TCP, IP, and ICMP protocols. It relies both on avoiding source 1631 fragmentation and setting the IPv4 DF (don't fragment) flag, the 1632 latter to inhibit on-path fragmentation. It relies on ICMP errors 1633 from routers along the path, whenever a segment is too large to 1634 traverse a link. Several adjustments to a TCP implementation with 1635 PMTUD are described in RFC 2923 in order to deal with problems 1636 experienced in practice [8]. PLPMTUD [18] is a Standards Track 1637 improvement to PMTUD that relaxes the requirement for ICMP support 1638 across a path, and improves performance in cases where ICMP is not 1639 consistently conveyed, but still tries to avoid source fragmentation. 1640 The mechanisms in all four of these RFCs are recommended to be 1641 included in TCP implementations. 1643 The TCP MSS option specifies an upper bound for the size of packets 1644 that can be received. Hence, setting the value in the MSS option too 1645 small can impact the ability for PMTUD or PLPMTUD to find a larger 1646 path MTU. RFC 1191 discusses this implication of many older TCP 1647 implementations setting MSS to 536 for non-local destinations, rather 1648 than deriving it from the MTUs of connected interfaces as 1649 recommended. 1651 6.3. Interfaces with Variable MTU Values 1653 The effective MTU can sometimes vary, as when used with variable 1654 compression, e.g., RObust Header Compression (ROHC) [25]. It is 1655 tempting for TCP to want to advertise the largest possible MSS, to 1656 support the most efficient use of compressed payloads. 1657 Unfortunately, some compression schemes occasionally need to transmit 1658 full headers (and thus smaller payloads) to resynchronize state at 1659 their endpoint compressors/decompressors. If the largest MTU is used 1660 to calculate the value to advertise in the MSS option, TCP 1661 retransmission may interfere with compressor resynchronization. 1663 As a result, when the effective MTU of an interface varies, TCP 1664 SHOULD use the smallest effective MTU of the interface to calculate 1665 the value to advertise in the MSS option. 1667 6.4. Nagle Algorithm 1669 The "Nagle algorithm" was described in RFC 896 [13] and was 1670 recommended in RFC 1122 [14] for mitigation of an early problem of 1671 too many small packets being generated. It has been implemented in 1672 most current TCP code bases, sometimes with minor variations (see 1673 Appendix A.3). 1675 If there is unacknowledged data (i.e., SND.NXT > SND.UNA), then the 1676 sending TCP buffers all user data (regardless of the PSH bit), until 1677 the outstanding data has been acknowledged or until the TCP can send 1678 a full-sized segment (Eff.snd.MSS bytes). 1680 A TCP SHOULD implement the Nagle Algorithm to coalesce short 1681 segments. However, there MUST be a way for an application to disable 1682 the Nagle algorithm on an individual connection. In all cases, 1683 sending data is also subject to the limitation imposed by the Slow 1684 Start algorithm [24]. 1686 6.5. IPv6 Jumbograms 1688 In order to support TCP over IPv6 jumbograms, implementations need to 1689 be able to send TCP segments larger than the 64KB limit that the MSS 1690 option can convey. RFC 2675 [7] defines that an MSS value of 65,535 1691 bytes is to be treated as infinity, and Path MTU Discovery [3] is 1692 used to determine the actual MSS. 1694 7. Data Communication 1696 Once the connection is established data is communicated by the 1697 exchange of segments. Because segments may be lost due to errors 1698 (checksum test failure), or network congestion, TCP uses 1699 retransmission (after a timeout) to ensure delivery of every segment. 1700 Duplicate segments may arrive due to network or TCP retransmission. 1701 As discussed in the section on sequence numbers the TCP performs 1702 certain tests on the sequence and acknowledgment numbers in the 1703 segments to verify their acceptability. 1705 The sender of data keeps track of the next sequence number to use in 1706 the variable SND.NXT. The receiver of data keeps track of the next 1707 sequence number to expect in the variable RCV.NXT. The sender of 1708 data keeps track of the oldest unacknowledged sequence number in the 1709 variable SND.UNA. If the data flow is momentarily idle and all data 1710 sent has been acknowledged then the three variables will be equal. 1712 When the sender creates a segment and transmits it the sender 1713 advances SND.NXT. When the receiver accepts a segment it advances 1714 RCV.NXT and sends an acknowledgment. When the data sender receives 1715 an acknowledgment it advances SND.UNA. The extent to which the 1716 values of these variables differ is a measure of the delay in the 1717 communication. The amount by which the variables are advanced is the 1718 length of the data and SYN or FIN flags in the segment. Note that 1719 once in the ESTABLISHED state all segments must carry current 1720 acknowledgment information. 1722 The CLOSE user call implies a push function, as does the FIN control 1723 flag in an incoming segment. 1725 7.1. Retransmission Timeout 1727 Because of the variability of the networks that compose an 1728 internetwork system and the wide range of uses of TCP connections the 1729 retransmission timeout (RTO) must be dynamically determined. 1731 The RTO MUST be computed according to the algorithm in [10], 1732 including Karn's algorithm for taking RTT samples. 1734 RFC 793 contains an early example procedure for computing the RTO. 1735 This was then replaced by the algorithm described in RFC 1122, and 1736 subsequently updated in RFC 2988, and then again in RFC 6298. 1738 If a retransmitted packet is identical to the original packet (which 1739 implies not only that the data boundaries have not changed, but also 1740 that the window and acknowledgment fields of the header have not 1741 changed), then the same IP Identification field MAY be used (see 1742 Section 3.2.1.5 of RFC 1122). 1744 7.2. TCP Congestion Control 1746 RFC 1122 required implementation of Van Jacobson's congestion control 1747 algorithm combining slow start with congestion avoidance. RFC 2581 1748 provided IETF Standards Track description of this, along with fast 1749 retransmit and fast recovery. RFC 5681 is the current description of 1750 these algorithms and is the current standard for TCP congestion 1751 control. 1753 A TCP MUST implement RFC 5681. 1755 Explicit Congestion Notification (ECN) was defined in RFC 3168 and is 1756 an IETF Standards Track enhancement that has many benefits [38]. 1758 A TCP SHOULD implement ECN as described in RFC 3168. 1760 7.3. TCP Connection Failures 1762 Excessive retransmission of the same segment by TCP indicates some 1763 failure of the remote host or the Internet path. This failure may be 1764 of short or long duration. The following procedure MUST be used to 1765 handle excessive retransmissions of data segments: 1767 (a) There are two thresholds R1 and R2 measuring the amount of 1768 retransmission that has occurred for the same segment. R1 and R2 1769 might be measured in time units or as a count of retransmissions. 1771 (b) When the number of transmissions of the same segment reaches 1772 or exceeds threshold R1, pass negative advice (see [14] 1773 Section 3.3.1.4) to the IP layer, to trigger dead-gateway 1774 diagnosis. 1776 (c) When the number of transmissions of the same segment reaches a 1777 threshold R2 greater than R1, close the connection. 1779 (d) An application MUST be able to set the value for R2 for a 1780 particular connection. For example, an interactive application 1781 might set R2 to "infinity," giving the user control over when to 1782 disconnect. 1784 (d) TCP SHOULD inform the application of the delivery problem 1785 (unless such information has been disabled by the application; see 1786 Asynchronous Reports section), when R1 is reached and before R2. 1787 This will allow a remote login (User Telnet) application program 1788 to inform the user, for example. 1790 The value of R1 SHOULD correspond to at least 3 retransmissions, at 1791 the current RTO. The value of R2 SHOULD correspond to at least 100 1792 seconds. 1794 An attempt to open a TCP connection could fail with excessive 1795 retransmissions of the SYN segment or by receipt of a RST segment or 1796 an ICMP Port Unreachable. SYN retransmissions MUST be handled in the 1797 general way just described for data retransmissions, including 1798 notification of the application layer. 1800 However, the values of R1 and R2 may be different for SYN and data 1801 segments. In particular, R2 for a SYN segment MUST be set large 1802 enough to provide retransmission of the segment for at least 3 1803 minutes. The application can close the connection (i.e., give up on 1804 the open attempt) sooner, of course. 1806 7.4. TCP Keep-Alives 1808 Implementors MAY include "keep-alives" in their TCP implementations, 1809 although this practice is not universally accepted. If keep-alives 1810 are included, the application MUST be able to turn them on or off for 1811 each TCP connection, and they MUST default to off. 1813 Keep-alive packets MUST only be sent when no data or acknowledgement 1814 packets have been received for the connection within an interval. 1815 This interval MUST be configurable and MUST default to no less than 1816 two hours. 1818 It is extremely important to remember that ACK segments that contain 1819 no data are not reliably transmitted by TCP. Consequently, if a 1820 keep-alive mechanism is implemented it MUST NOT interpret failure to 1821 respond to any specific probe as a dead connection. 1823 An implementation SHOULD send a keep-alive segment with no data; 1824 however, it MAY be configurable to send a keep-alive segment 1825 containing one garbage octet, for compatibility with erroneous TCP 1826 implementations. 1828 7.5. The Communication of Urgent Information 1830 As a result of implementation differences and middlebox interactions, 1831 new applications SHOULD NOT employ the TCP urgent mechanism. 1832 However, TCP implementations MUST still include support for the 1833 urgent mechanism. Details can be found in RFC 6093 [28]. 1835 The objective of the TCP urgent mechanism is to allow the sending 1836 user to stimulate the receiving user to accept some urgent data and 1837 to permit the receiving TCP to indicate to the receiving user when 1838 all the currently known urgent data has been received by the user. 1840 This mechanism permits a point in the data stream to be designated as 1841 the end of urgent information. Whenever this point is in advance of 1842 the receive sequence number (RCV.NXT) at the receiving TCP, that TCP 1843 must tell the user to go into "urgent mode"; when the receive 1844 sequence number catches up to the urgent pointer, the TCP must tell 1845 user to go into "normal mode". If the urgent pointer is updated 1846 while the user is in "urgent mode", the update will be invisible to 1847 the user. 1849 The method employs a urgent field which is carried in all segments 1850 transmitted. The URG control flag indicates that the urgent field is 1851 meaningful and must be added to the segment sequence number to yield 1852 the urgent pointer. The absence of this flag indicates that there is 1853 no urgent data outstanding. 1855 To send an urgent indication the user must also send at least one 1856 data octet. If the sending user also indicates a push, timely 1857 delivery of the urgent information to the destination process is 1858 enhanced. 1860 A TCP MUST support a sequence of urgent data of any length. [14] 1862 A TCP MUST inform the application layer asynchronously whenever it 1863 receives an Urgent pointer and there was previously no pending urgent 1864 data, or whenvever the Urgent pointer advances in the data stream. 1865 There MUST be a way for the application to learn how much urgent data 1866 remains to be read from the connection, or at least to determine 1867 whether or not more urgent data remains to be read. [14] 1869 7.6. Managing the Window 1871 The window sent in each segment indicates the range of sequence 1872 numbers the sender of the window (the data receiver) is currently 1873 prepared to accept. There is an assumption that this is related to 1874 the currently available data buffer space available for this 1875 connection. 1877 The sending TCP packages the data to be transmitted into segments 1878 which fit the current window, and may repackage segments on the 1879 retransmission queue. Such repackaging is not required, but may be 1880 helpful. 1882 In a connection with a one-way data flow, the window information will 1883 be carried in acknowledgment segments that all have the same sequence 1884 number so there will be no way to reorder them if they arrive out of 1885 order. This is not a serious problem, but it will allow the window 1886 information to be on occasion temporarily based on old reports from 1887 the data receiver. A refinement to avoid this problem is to act on 1888 the window information from segments that carry the highest 1889 acknowledgment number (that is segments with acknowledgment number 1890 equal or greater than the highest previously received). 1892 Indicating a large window encourages transmissions. If more data 1893 arrives than can be accepted, it will be discarded. This will result 1894 in excessive retransmissions, adding unnecessarily to the load on the 1895 network and the TCPs. Indicating a small window may restrict the 1896 transmission of data to the point of introducing a round trip delay 1897 between each new segment transmitted. 1899 The mechanisms provided allow a TCP to advertise a large window and 1900 to subsequently advertise a much smaller window without having 1901 accepted that much data. This, so called "shrinking the window," is 1902 strongly discouraged. The robustness principle dictates that TCPs 1903 will not shrink the window themselves, but will be prepared for such 1904 behavior on the part of other TCPs. 1906 A TCP receiver SHOULD NOT shrink the window, i.e., move the right 1907 window edge to the left. However, a sending TCP MUST be robust 1908 against window shrinking, which may cause the "useable window" (see 1909 Section 7.6.2.1) to become negative. 1911 If this happens, the sender SHOULD NOT send new data, but SHOULD 1912 retransmit normally the old unacknowledged data between SND.UNA and 1913 SND.UNA+SND.WND. The sender MAY also retransmit old data beyond 1914 SND.UNA+SND.WND, but SHOULD NOT time out the connection if data 1915 beyond the right window edge is not acknowledged. If the window 1916 shrinks to zero, the TCP MUST probe it in the standard way (described 1917 below). 1919 7.6.1. Zero Window Probing 1921 The sending TCP must be prepared to accept from the user and send at 1922 least one octet of new data even if the send window is zero. The 1923 sending TCP must regularly retransmit to the receiving TCP even when 1924 the window is zero, in order to "probe" the window. Two minutes is 1925 recommended for the retransmission interval when the window is zero. 1926 This retransmission is essential to guarantee that when either TCP 1927 has a zero window the re-opening of the window will be reliably 1928 reported to the other. This is referred to as Zero-Window Probing 1929 (ZWP) in other documents. 1931 Probing of zero (offered) windows MUST be supported. 1933 A TCP MAY keep its offered receive window closed indefinitely. As 1934 long as the receiving TCP continues to send acknowledgments in 1935 response to the probe segments, the sending TCP MUST allow the 1936 connection to stay open. This enables TCP to function in scenarios 1937 such as the "printer ran out of paper" situation described in 1938 Section 4.2.2.17 of RFC1122. The behavior is subject to the 1939 implementation's resource management concerns, as noted in [30]. 1941 When the receiving TCP has a zero window and a segment arrives it 1942 must still send an acknowledgment showing its next expected sequence 1943 number and current window (zero). 1945 7.6.2. Silly Window Syndrome Avoidance 1947 The "Silly Window Syndrome" (SWS) is a stable pattern of small 1948 incremental window movements resulting in extremely poor TCP 1949 performance. Algorithms to avoid SWS are described below for both 1950 the sending side and the receiving side. RFC 1122 contains more 1951 detailed discussion of the SWS problem. Note that the Nagle 1952 algorithm and the sender SWS avoidance algorithm play complementary 1953 roles in improving performance. The Nagle algorithm discourages 1954 sending tiny segments when the data to be sent increases in small 1955 increments, while the SWS avoidance algorithm discourages small 1956 segments resulting from the right window edge advancing in small 1957 increments. 1959 7.6.2.1. Sender's Algorithm - When to Send Data 1961 A TCP MUST include a SWS avoidance algorithm in the sender. 1963 A TCP SHOULD implement the Nagle Algorithm to coalesce short 1964 segments. However, there MUST be a way for an application to disable 1965 the Nagle algorithm on an individual connection. In all cases, 1966 sending data is also subject to the limitation imposed by the Slow 1967 Start algorithm. 1969 The sender's SWS avoidance algorithm is more difficult than the 1970 receivers's, because the sender does not know (directly) the 1971 receiver's total buffer space RCV.BUFF. An approach which has been 1972 found to work well is for the sender to calculate Max(SND.WND), the 1973 maximum send window it has seen so far on the connection, and to use 1974 this value as an estimate of RCV.BUFF. Unfortunately, this can only 1975 be an estimate; the receiver may at any time reduce the size of 1976 RCV.BUFF. To avoid a resulting deadlock, it is necessary to have a 1977 timeout to force transmission of data, overriding the SWS avoidance 1978 algorithm. In practice, this timeout should seldom occur. 1980 The "useable window" is: 1982 U = SND.UNA + SND.WND - SND.NXT 1984 i.e., the offered window less the amount of data sent but not 1985 acknowledged. If D is the amount of data queued in the sending TCP 1986 but not yet sent, then the following set of rules is recommended. 1988 Send data: 1990 (1) if a maximum-sized segment can be sent, i.e, if: 1992 min(D,U) >= Eff.snd.MSS; 1994 (2) or if the data is pushed and all queued data can be sent now, 1995 i.e., if: 1997 [SND.NXT = SND.UNA and] PUSHED and D <= U 1999 (the bracketed condition is imposed by the Nagle algorithm); 2001 (3) or if at least a fraction Fs of the maximum window can be sent, 2002 i.e., if: 2004 [SND.NXT = SND.UNA and] 2006 min(D.U) >= Fs * Max(SND.WND); 2008 (4) or if data is PUSHed and the override timeout occurs. 2010 Here Fs is a fraction whose recommended value is 1/2. The override 2011 timeout should be in the range 0.1 - 1.0 seconds. It may be 2012 convenient to combine this timer with the timer used to probe zero 2013 windows (Section Section 7.6.1). 2015 7.6.2.2. Receiver's Algorithm - When to Send a Window Update 2017 A TCP MUST include a SWS avoidance algorithm in the receiver. 2019 The receiver's SWS avoidance algorithm determines when the right 2020 window edge may be advanced; this is customarily known as "updating 2021 the window". This algorithm combines with the delayed ACK algorithm 2022 (see Section 7.6.3) to determine when an ACK segment containing the 2023 current window will really be sent to the receiver. 2025 The solution to receiver SWS is to avoid advancing the right window 2026 edge RCV.NXT+RCV.WND in small increments, even if data is received 2027 from the network in small segments. 2029 Suppose the total receive buffer space is RCV.BUFF. At any given 2030 moment, RCV.USER octets of this total may be tied up with data that 2031 has been received and acknowledged but which the user process has not 2032 yet consumed. When the connection is quiescent, RCV.WND = RCV.BUFF 2033 and RCV.USER = 0. 2035 Keeping the right window edge fixed as data arrives and is 2036 acknowledged requires that the receiver offer less than its full 2037 buffer space, i.e., the receiver must specify a RCV.WND that keeps 2038 RCV.NXT+RCV.WND constant as RCV.NXT increases. Thus, the total 2039 buffer space RCV.BUFF is generally divided into three parts: 2041 |<------- RCV.BUFF ---------------->| 2042 1 2 3 2043 ----|---------|------------------|------|---- 2044 RCV.NXT ^ 2045 (Fixed) 2047 1 - RCV.USER = data received but not yet consumed; 2048 2 - RCV.WND = space advertised to sender; 2049 3 - Reduction = space available but not yet 2050 advertised. 2052 The suggested SWS avoidance algorithm for the receiver is to keep 2053 RCV.NXT+RCV.WND fixed until the reduction satisfies: 2055 RCV.BUFF - RCV.USER - RCV.WND >= 2057 min( Fr * RCV.BUFF, Eff.snd.MSS ) 2059 where Fr is a fraction whose recommended value is 1/2, and 2060 Eff.snd.MSS is the effective send MSS for the connection (see 2061 Section 6.1). When the inequality is satisfied, RCV.WND is set to 2062 RCV.BUFF-RCV.USER. 2064 Note that the general effect of this algorithm is to advance RCV.WND 2065 in increments of Eff.snd.MSS (for realistic receive buffers: 2066 Eff.snd.MSS < RCV.BUFF/2). Note also that the receiver must use its 2067 own Eff.snd.MSS, assuming it is the same as the sender's. 2069 7.6.3. Delayed Acknowledgements - When to Send an ACK Segment 2071 A host that is receiving a stream of TCP data segments can increase 2072 efficiency in both the Internet and the hosts by sending fewer than 2073 one ACK (acknowledgment) segment per data segment received; this is 2074 known as a "delayed ACK". 2076 A TCP SHOULD implement a delayed ACK, but an ACK should not be 2077 excessively delayed; in particular, the delay MUST be less than 0.5 2078 seconds, and in a stream of full-sized segments there SHOULD be an 2079 ACK for at least every second segment. Excessive delays on ACK's can 2080 disturb the round-trip timing and packet "clocking" algorithms. 2082 8. Interfaces 2084 There are of course two interfaces of concern: the user/TCP interface 2085 and the TCP/lower-level interface. We have a fairly elaborate model 2086 of the user/TCP interface, but the interface to the lower level 2087 protocol module is left unspecified here, since it will be specified 2088 in detail by the specification of the lower level protocol. For the 2089 case that the lower level is IP we note some of the parameter values 2090 that TCPs might use. 2092 8.1. User/TCP Interface 2094 The following functional description of user commands to the TCP is, 2095 at best, fictional, since every operating system will have different 2096 facilities. Consequently, we must warn readers that different TCP 2097 implementations may have different user interfaces. However, all 2098 TCPs must provide a certain minimum set of services to guarantee that 2099 all TCP implementations can support the same protocol hierarchy. 2100 This section specifies the functional interfaces required of all TCP 2101 implementations. 2103 TCP User Commands 2105 The following sections functionally characterize a USER/TCP 2106 interface. The notation used is similar to most procedure or 2107 function calls in high level languages, but this usage is not 2108 meant to rule out trap type service calls (e.g., SVCs, UUOs, 2109 EMTs). 2111 The user commands described below specify the basic functions the 2112 TCP must perform to support interprocess communication. 2113 Individual implementations must define their own exact format, and 2114 may provide combinations or subsets of the basic functions in 2115 single calls. In particular, some implementations may wish to 2116 automatically OPEN a connection on the first SEND or RECEIVE 2117 issued by the user for a given connection. 2119 In providing interprocess communication facilities, the TCP must 2120 not only accept commands, but must also return information to the 2121 processes it serves. The latter consists of: 2123 (a) general information about a connection (e.g., interrupts, 2124 remote close, binding of unspecified foreign socket). 2126 (b) replies to specific user commands indicating success or 2127 various types of failure. 2129 Open 2131 Format: OPEN (local port, foreign socket, active/passive [, 2132 timeout] [, DiffServ field] [, security/compartment] [local IP 2133 address,] [, options]) -> local connection name 2135 We assume that the local TCP is aware of the identity of the 2136 processes it serves and will check the authority of the process 2137 to use the connection specified. Depending upon the 2138 implementation of the TCP, the local network and TCP 2139 identifiers for the source address will either be supplied by 2140 the TCP or the lower level protocol (e.g., IP). These 2141 considerations are the result of concern about security, to the 2142 extent that no TCP be able to masquerade as another one, and so 2143 on. Similarly, no process can masquerade as another without 2144 the collusion of the TCP. 2146 If the active/passive flag is set to passive, then this is a 2147 call to LISTEN for an incoming connection. A passive open may 2148 have either a fully specified foreign socket to wait for a 2149 particular connection or an unspecified foreign socket to wait 2150 for any call. A fully specified passive call can be made 2151 active by the subsequent execution of a SEND. 2153 A transmission control block (TCB) is created and partially 2154 filled in with data from the OPEN command parameters. 2156 Every passive OPEN call either creates a new connection record 2157 in LISTEN state, or it returns an error; it MUST NOT affect any 2158 previously created connection record. 2160 A TCP that supports multiple concurrent users MUST provide an 2161 OPEN call that will functionally allow an application to LISTEN 2162 on a port while a connection block with the same local port is 2163 in SYN-SENT or SYN-RECEIVED state. 2165 On an active OPEN command, the TCP will begin the procedure to 2166 synchronize (i.e., establish) the connection at once. 2168 The timeout, if present, permits the caller to set up a timeout 2169 for all data submitted to TCP. If data is not successfully 2170 delivered to the destination within the timeout period, the TCP 2171 will abort the connection. The present global default is five 2172 minutes. 2174 The TCP or some component of the operating system will verify 2175 the users authority to open a connection with the specified 2176 DiffServ field value or security/compartment. The absence of a 2177 DiffServ field value or security/compartment specification in 2178 the OPEN call indicates the default values must be used. 2180 TCP will accept incoming requests as matching only if the 2181 security/compartment information is exactly the same as that 2182 requested in the OPEN call. 2184 The DiffServ field value indicated by the user only impacts 2185 outgoing packets, may be altered en route through the network, 2186 and has no direct bearing or relation to received packets. 2188 A local connection name will be returned to the user by the 2189 TCP. The local connection name can then be used as a short 2190 hand term for the connection defined by the pair. 2193 The optional "local IP address" parameter MUST be supported to 2194 allow the specification of the local IP address. This enables 2195 applications that need to select the local IP address used when 2196 multihoming is present. 2198 A passive OPEN call with a specified "local IP address" 2199 parameter will await an incoming connection request to that 2200 address. If the parameter is unspecified, a passive OPEN will 2201 await an incoming connection request to any local IP address, 2202 and then bind the local IP address of the connection to the 2203 particular address that is used. 2205 For an active OPEN call, a specified "local IP address" 2206 parameter MUST be used for opening the connection. If the 2207 parameter is unspecified, the host will choose an appropriate 2208 local IP address (see RFC 1122 section 3.3.4.2). 2210 If an application on a multihomed host does not specify the 2211 local IP address when actively opening a TCP connection, then 2212 the TCP MUST ask the IP layer to select a local IP address 2213 before sending the (first) SYN. See the function GET_SRCADDR() 2214 in Section 3.4 of RFC 1122. 2216 At all other times, a previous segment has either been sent or 2217 received on this connection, and TCP MUST use the same local 2218 address is used that was used in those previous segments. 2220 A TCP implementation MUST reject as an error a local OPEN call 2221 for an invalid remote IP address (e.g., a broadcast or 2222 multicast address). 2224 Send 2226 Format: SEND (local connection name, buffer address, byte 2227 count, PUSH flag, URGENT flag [,timeout]) 2229 This call causes the data contained in the indicated user 2230 buffer to be sent on the indicated connection. If the 2231 connection has not been opened, the SEND is considered an 2232 error. Some implementations may allow users to SEND first; in 2233 which case, an automatic OPEN would be done. For example, this 2234 might be one way for application data to be included in SYN 2235 segments. If the calling process is not authorized to use this 2236 connection, an error is returned. 2238 If the PUSH flag is set, the data must be transmitted promptly 2239 to the receiver, and the PUSH bit will be set in the last TCP 2240 segment created from the buffer. If the PUSH flag is not set, 2241 the data may be combined with data from subsequent SENDs for 2242 transmission efficiency. Note that when the Nagle algorithm is 2243 in use, TCP may be buffer the data before sending, without 2244 regard to the PUSH flag (see Section 6.4). 2246 New applications SHOULD NOT set the URGENT flag [28] due to 2247 implementation differences and middlebox issues. 2249 If the URGENT flag is set, segments sent to the destination TCP 2250 will have the urgent pointer set. The receiving TCP will 2251 signal the urgent condition to the receiving process if the 2252 urgent pointer indicates that data preceding the urgent pointer 2253 has not been consumed by the receiving process. The purpose of 2254 urgent is to stimulate the receiver to process the urgent data 2255 and to indicate to the receiver when all the currently known 2256 urgent data has been received. The number of times the sending 2257 user's TCP signals urgent will not necessarily be equal to the 2258 number of times the receiving user will be notified of the 2259 presence of urgent data. 2261 If no foreign socket was specified in the OPEN, but the 2262 connection is established (e.g., because a LISTENing connection 2263 has become specific due to a foreign segment arriving for the 2264 local socket), then the designated buffer is sent to the 2265 implied foreign socket. Users who make use of OPEN with an 2266 unspecified foreign socket can make use of SEND without ever 2267 explicitly knowing the foreign socket address. 2269 However, if a SEND is attempted before the foreign socket 2270 becomes specified, an error will be returned. Users can use 2271 the STATUS call to determine the status of the connection. In 2272 some implementations the TCP may notify the user when an 2273 unspecified socket is bound. 2275 If a timeout is specified, the current user timeout for this 2276 connection is changed to the new one. 2278 In the simplest implementation, SEND would not return control 2279 to the sending process until either the transmission was 2280 complete or the timeout had been exceeded. However, this 2281 simple method is both subject to deadlocks (for example, both 2282 sides of the connection might try to do SENDs before doing any 2283 RECEIVEs) and offers poor performance, so it is not 2284 recommended. A more sophisticated implementation would return 2285 immediately to allow the process to run concurrently with 2286 network I/O, and, furthermore, to allow multiple SENDs to be in 2287 progress. Multiple SENDs are served in first come, first 2288 served order, so the TCP will queue those it cannot service 2289 immediately. 2291 We have implicitly assumed an asynchronous user interface in 2292 which a SEND later elicits some kind of SIGNAL or pseudo- 2293 interrupt from the serving TCP. An alternative is to return a 2294 response immediately. For instance, SENDs might return 2295 immediate local acknowledgment, even if the segment sent had 2296 not been acknowledged by the distant TCP. We could 2297 optimistically assume eventual success. If we are wrong, the 2298 connection will close anyway due to the timeout. In 2299 implementations of this kind (synchronous), there will still be 2300 some asynchronous signals, but these will deal with the 2301 connection itself, and not with specific segments or buffers. 2303 In order for the process to distinguish among error or success 2304 indications for different SENDs, it might be appropriate for 2305 the buffer address to be returned along with the coded response 2306 to the SEND request. TCP-to-user signals are discussed below, 2307 indicating the information which should be returned to the 2308 calling process. 2310 Receive 2312 Format: RECEIVE (local connection name, buffer address, byte 2313 count) -> byte count, urgent flag, push flag 2315 This command allocates a receiving buffer associated with the 2316 specified connection. If no OPEN precedes this command or the 2317 calling process is not authorized to use this connection, an 2318 error is returned. 2320 In the simplest implementation, control would not return to the 2321 calling program until either the buffer was filled, or some 2322 error occurred, but this scheme is highly subject to deadlocks. 2323 A more sophisticated implementation would permit several 2324 RECEIVEs to be outstanding at once. These would be filled as 2325 segments arrive. This strategy permits increased throughput at 2326 the cost of a more elaborate scheme (possibly asynchronous) to 2327 notify the calling program that a PUSH has been seen or a 2328 buffer filled. 2330 If enough data arrive to fill the buffer before a PUSH is seen, 2331 the PUSH flag will not be set in the response to the RECEIVE. 2332 The buffer will be filled with as much data as it can hold. If 2333 a PUSH is seen before the buffer is filled the buffer will be 2334 returned partially filled and PUSH indicated. 2336 If there is urgent data the user will have been informed as 2337 soon as it arrived via a TCP-to-user signal. The receiving 2338 user should thus be in "urgent mode". If the URGENT flag is 2339 on, additional urgent data remains. If the URGENT flag is off, 2340 this call to RECEIVE has returned all the urgent data, and the 2341 user may now leave "urgent mode". Note that data following the 2342 urgent pointer (non-urgent data) cannot be delivered to the 2343 user in the same buffer with preceding urgent data unless the 2344 boundary is clearly marked for the user. 2346 To distinguish among several outstanding RECEIVEs and to take 2347 care of the case that a buffer is not completely filled, the 2348 return code is accompanied by both a buffer pointer and a byte 2349 count indicating the actual length of the data received. 2351 Alternative implementations of RECEIVE might have the TCP 2352 allocate buffer storage, or the TCP might share a ring buffer 2353 with the user. 2355 Close 2357 Format: CLOSE (local connection name) 2359 This command causes the connection specified to be closed. If 2360 the connection is not open or the calling process is not 2361 authorized to use this connection, an error is returned. 2362 Closing connections is intended to be a graceful operation in 2363 the sense that outstanding SENDs will be transmitted (and 2364 retransmitted), as flow control permits, until all have been 2365 serviced. Thus, it should be acceptable to make several SEND 2366 calls, followed by a CLOSE, and expect all the data to be sent 2367 to the destination. It should also be clear that users should 2368 continue to RECEIVE on CLOSING connections, since the other 2369 side may be trying to transmit the last of its data. Thus, 2370 CLOSE means "I have no more to send" but does not mean "I will 2371 not receive any more." It may happen (if the user level 2372 protocol is not well thought out) that the closing side is 2373 unable to get rid of all its data before timing out. In this 2374 event, CLOSE turns into ABORT, and the closing TCP gives up. 2376 The user may CLOSE the connection at any time on his own 2377 initiative, or in response to various prompts from the TCP 2378 (e.g., remote close executed, transmission timeout exceeded, 2379 destination inaccessible). 2381 Because closing a connection requires communication with the 2382 foreign TCP, connections may remain in the closing state for a 2383 short time. Attempts to reopen the connection before the TCP 2384 replies to the CLOSE command will result in error responses. 2386 Close also implies push function. 2388 Status 2389 Format: STATUS (local connection name) -> status data 2391 This is an implementation dependent user command and could be 2392 excluded without adverse effect. Information returned would 2393 typically come from the TCB associated with the connection. 2395 This command returns a data block containing the following 2396 information: 2398 local socket, 2399 foreign socket, 2400 local connection name, 2401 receive window, 2402 send window, 2403 connection state, 2404 number of buffers awaiting acknowledgment, 2405 number of buffers pending receipt, 2406 urgent state, 2407 DiffServ field value, 2408 security/compartment, 2409 and transmission timeout. 2411 Depending on the state of the connection, or on the 2412 implementation itself, some of this information may not be 2413 available or meaningful. If the calling process is not 2414 authorized to use this connection, an error is returned. This 2415 prevents unauthorized processes from gaining information about 2416 a connection. 2418 Abort 2420 Format: ABORT (local connection name) 2422 This command causes all pending SENDs and RECEIVES to be 2423 aborted, the TCB to be removed, and a special RESET message to 2424 be sent to the TCP on the other side of the connection. 2425 Depending on the implementation, users may receive abort 2426 indications for each outstanding SEND or RECEIVE, or may simply 2427 receive an ABORT-acknowledgment. 2429 Flush 2431 Some TCP implementations have included a FLUSH call, which will 2432 empty the TCP send queue of any data for which the user has 2433 issued SEND calls but which is still to the right of the 2434 current send window. That is, it flushes as much queued send 2435 data as possible without losing sequence number 2436 synchronization. 2438 Asynchronous Reports 2440 There MUST be a mechanism for reporting soft TCP error 2441 conditions to the application. Generically, we assume this 2442 takes the form of an application-supplied ERROR_REPORT routine 2443 that may be upcalled asynchronously from the transport layer: 2445 ERROR_REPORT(local connection name, reason, subreason) 2447 The precise encoding of the reason and subreason parameters is 2448 not specified here. However, the conditions that are reported 2449 asynchronously to the application MUST include: 2451 * ICMP error message arrived (see Section 8.2.2) 2453 * Excessive retransmissions (see Section 7.3) 2455 * Urgent pointer advance (see Section 7.5). 2457 However, an application program that does not want to receive 2458 such ERROR_REPORT calls SHOULD be able to effectively disable 2459 these calls. 2461 Set Differentiated Services Field (IPv4 TOS or IPv6 Traffic Class) 2463 The application layer MUST be able to specify the 2464 Differentiated Services field for segments that are sent on a 2465 connection. The Differentiated Services field includes the 2466 6-bit Differentiated Services Code Point (DSCP) value. It is 2467 not required, but the application SHOULD be able to change the 2468 Differentiated Services field during the connection lifetime. 2469 TCP SHOULD pass the current Differentiated Services field value 2470 without change to the IP layer, when it sends segments on the 2471 connection. 2473 The Differentiated Services field will be specified 2474 independently in each direction on the connection, so that the 2475 receiver application will specify the Differentiated Services 2476 field used for ACK segments. 2478 TCP MAY pass the most recently received Differentiated Services 2479 field up to the application. 2481 8.2. TCP/Lower-Level Interface 2483 The TCP calls on a lower level protocol module to actually send and 2484 receive information over a network. The two current standard 2485 Internet Protocol (IP) versions layered below TCP are IPv4 [1] and 2486 IPv6 [5]. 2488 If the lower level protocol is IPv4 it provides arguments for a type 2489 of service (used within the Differentiated Services field) and for a 2490 time to live. TCP uses the following settings for these parameters: 2492 DiffServ field: The IP header value for the DiffServ field is 2493 given by the user. This includes the bits of the DiffServ Code 2494 Point (DSCP). 2496 Time to Live (TTL): The TTL value used to send TCP segments MUST 2497 be configurable. 2499 Note that RFC 793 specified one minute (60 seconds) as a 2500 constant for the TTL, because the assumed maximum segment 2501 lifetime was two minutes. This was intended to explicitly ask 2502 that a segment be destroyed if it cannot be delivered by the 2503 internet system within one minute. RFC 1122 changed this 2504 specification to require that the TTL be configurable. 2506 Note that the DiffServ field is permitted to change during a 2507 connection (section 4.2.4.2 of RFC 1122). However, the 2508 application interface might not support this ability, and the 2509 application does not have knowledge about individual TCP 2510 segments, so this can only be done on a coarse granularity, at 2511 best. This limitation is further discussed in RFC 7657 (sec 2512 5.1, 5.3, and 6) [37]. Generally, an application SHOULD NOT 2513 change the DiffServ field value during the course of a 2514 connection. 2516 Any lower level protocol will have to provide the source address, 2517 destination address, and protocol fields, and some way to determine 2518 the "TCP length", both to provide the functional equivalent service 2519 of IP and to be used in the TCP checksum. 2521 When received options are passed up to TCP from the IP layer, TCP 2522 MUST ignore options that it does not understand. 2524 A TCP MAY support the Time Stamp and Record Route options. 2526 8.2.1. Source Routing 2528 If the lower level is IP (or other protocol that provides this 2529 feature) and source routing is used, the interface must allow the 2530 route information to be communicated. This is especially important 2531 so that the source and destination addresses used in the TCP checksum 2532 be the originating source and ultimate destination. It is also 2533 important to preserve the return route to answer connection requests. 2535 An application MUST be able to specify a source route when it 2536 actively opens a TCP connection, and this MUST take precedence over a 2537 source route received in a datagram. 2539 When a TCP connection is OPENed passively and a packet arrives with a 2540 completed IP Source Route option (containing a return route), TCP 2541 MUST save the return route and use it for all segments sent on this 2542 connection. If a different source route arrives in a later segment, 2543 the later definition SHOULD override the earlier one. 2545 8.2.2. ICMP Messages 2547 TCP MUST act on an ICMP error message passed up from the IP layer, 2548 directing it to the connection that created the error. The necessary 2549 demultiplexing information can be found in the IP header contained 2550 within the ICMP message. 2552 This applies to ICMPv6 in addition to IPv4 ICMP. 2554 [22] contains discussion of specific ICMP and ICMPv6 messages 2555 classified as either "soft" or "hard" errors that may bear different 2556 responses. Treatment for classes of ICMP messages is described 2557 below: 2559 Source Quench 2560 TCP MUST silently discard any received ICMP Source Quench messages. 2561 See [11] for discussion. 2563 Soft Errors 2564 For ICMP these include: Destination Unreachable -- codes 0, 1, 5, 2565 Time Exceeded -- codes 0, 1, and Parameter Problem. 2566 For ICMPv6 these include: Destination Unreachable -- codes 0 and 3, 2567 Time Exceeded -- codes 0, 1, and Parameter Problem -- codes 0, 1, 2 2568 Since these Unreachable messages indicate soft error conditions, 2569 TCP MUST NOT abort the connection, and it SHOULD make the 2570 information available to the application. 2572 Hard Errors 2573 For ICMP these include Destination Unreachable -- codes 2-4"> 2574 These are hard error conditions, so TCP SHOULD abort the 2575 connection. [22] notes that some implementations do not abort 2576 connections when an ICMP hard error is received for a connection 2577 that is in any of the synchronized states. 2579 Note that [22] section 4 describes widespread implementation behavior 2580 that treats soft errors as hard errors during connection 2581 establishment. 2583 8.2.3. Remote Address Validation 2585 RFC 1122 requires addresses to be validated in incoming SYN packets: 2587 An incoming SYN with an invalid source address must be ignored 2588 either by TCP or by the IP layer (see Section 3.2.1.3 of [14]). 2590 A TCP implementation MUST silently discard an incoming SYN segment 2591 that is addressed to a broadcast or multicast address. 2593 This prevents connection state and replies from being erroneously 2594 generated, and implementers should note that this guidance is 2595 applicable to all incoming segments, not just SYNs, as specifically 2596 indicated in RFC 1122. 2598 8.3. Event Processing 2600 The processing depicted in this section is an example of one possible 2601 implementation. Other implementations may have slightly different 2602 processing sequences, but they should differ from those in this 2603 section only in detail, not in substance. 2605 The activity of the TCP can be characterized as responding to events. 2606 The events that occur can be cast into three categories: user calls, 2607 arriving segments, and timeouts. This section describes the 2608 processing the TCP does in response to each of the events. In many 2609 cases the processing required depends on the state of the connection. 2611 Events that occur: 2613 User Calls 2615 OPEN 2616 SEND 2617 RECEIVE 2618 CLOSE 2619 ABORT 2620 STATUS 2622 Arriving Segments 2624 SEGMENT ARRIVES 2626 Timeouts 2627 USER TIMEOUT 2628 RETRANSMISSION TIMEOUT 2629 TIME-WAIT TIMEOUT 2631 The model of the TCP/user interface is that user commands receive an 2632 immediate return and possibly a delayed response via an event or 2633 pseudo interrupt. In the following descriptions, the term "signal" 2634 means cause a delayed response. 2636 Error responses are given as character strings. For example, user 2637 commands referencing connections that do not exist receive "error: 2638 connection not open". 2640 Please note in the following that all arithmetic on sequence numbers, 2641 acknowledgment numbers, windows, et cetera, is modulo 2**32 the size 2642 of the sequence number space. Also note that "=<" means less than or 2643 equal to (modulo 2**32). 2645 A natural way to think about processing incoming segments is to 2646 imagine that they are first tested for proper sequence number (i.e., 2647 that their contents lie in the range of the expected "receive window" 2648 in the sequence number space) and then that they are generally queued 2649 and processed in sequence number order. 2651 When a segment overlaps other already received segments we 2652 reconstruct the segment to contain just the new data, and adjust the 2653 header fields to be consistent. 2655 Note that if no state change is mentioned the TCP stays in the same 2656 state. 2658 OPEN Call 2660 CLOSED STATE (i.e., TCB does not exist) 2662 Create a new transmission control block (TCB) to hold 2663 connection state information. Fill in local socket identifier, 2664 foreign socket, DiffServ field, security/compartment, and user 2665 timeout information. Note that some parts of the foreign 2666 socket may be unspecified in a passive OPEN and are to be 2667 filled in by the parameters of the incoming SYN segment. 2668 Verify the security and DiffServ value requested are allowed 2669 for this user, if not return "error: precedence not allowed" or 2670 "error: security/compartment not allowed." If passive enter 2671 the LISTEN state and return. If active and the foreign socket 2672 is unspecified, return "error: foreign socket unspecified"; if 2673 active and the foreign socket is specified, issue a SYN 2674 segment. An initial send sequence number (ISS) is selected. A 2675 SYN segment of the form is sent. Set 2676 SND.UNA to ISS, SND.NXT to ISS+1, enter SYN-SENT state, and 2677 return. 2679 If the caller does not have access to the local socket 2680 specified, return "error: connection illegal for this process". 2681 If there is no room to create a new connection, return "error: 2682 insufficient resources". 2684 LISTEN STATE 2686 If active and the foreign socket is specified, then change the 2687 connection from passive to active, select an ISS. Send a SYN 2688 segment, set SND.UNA to ISS, SND.NXT to ISS+1. Enter SYN-SENT 2689 state. Data associated with SEND may be sent with SYN segment 2690 or queued for transmission after entering ESTABLISHED state. 2691 The urgent bit if requested in the command must be sent with 2692 the data segments sent as a result of this command. If there 2693 is no room to queue the request, respond with "error: 2694 insufficient resources". If Foreign socket was not specified, 2695 then return "error: foreign socket unspecified". 2697 SYN-SENT STATE 2698 SYN-RECEIVED STATE 2699 ESTABLISHED STATE 2700 FIN-WAIT-1 STATE 2701 FIN-WAIT-2 STATE 2702 CLOSE-WAIT STATE 2703 CLOSING STATE 2704 LAST-ACK STATE 2705 TIME-WAIT STATE 2707 Return "error: connection already exists". 2709 SEND Call 2711 CLOSED STATE (i.e., TCB does not exist) 2713 If the user does not have access to such a connection, then 2714 return "error: connection illegal for this process". 2716 Otherwise, return "error: connection does not exist". 2718 LISTEN STATE 2720 If the foreign socket is specified, then change the connection 2721 from passive to active, select an ISS. Send a SYN segment, set 2722 SND.UNA to ISS, SND.NXT to ISS+1. Enter SYN-SENT state. Data 2723 associated with SEND may be sent with SYN segment or queued for 2724 transmission after entering ESTABLISHED state. The urgent bit 2725 if requested in the command must be sent with the data segments 2726 sent as a result of this command. If there is no room to queue 2727 the request, respond with "error: insufficient resources". If 2728 Foreign socket was not specified, then return "error: foreign 2729 socket unspecified". 2731 SYN-SENT STATE 2732 SYN-RECEIVED STATE 2734 Queue the data for transmission after entering ESTABLISHED 2735 state. If no space to queue, respond with "error: insufficient 2736 resources". 2738 ESTABLISHED STATE 2739 CLOSE-WAIT STATE 2741 Segmentize the buffer and send it with a piggybacked 2742 acknowledgment (acknowledgment value = RCV.NXT). If there is 2743 insufficient space to remember this buffer, simply return 2744 "error: insufficient resources". 2746 If the urgent flag is set, then SND.UP <- SND.NXT and set the 2747 urgent pointer in the outgoing segments. 2749 FIN-WAIT-1 STATE 2750 FIN-WAIT-2 STATE 2751 CLOSING STATE 2752 LAST-ACK STATE 2753 TIME-WAIT STATE 2755 Return "error: connection closing" and do not service request. 2757 RECEIVE Call 2759 CLOSED STATE (i.e., TCB does not exist) 2761 If the user does not have access to such a connection, return 2762 "error: connection illegal for this process". 2764 Otherwise return "error: connection does not exist". 2766 LISTEN STATE 2767 SYN-SENT STATE 2768 SYN-RECEIVED STATE 2770 Queue for processing after entering ESTABLISHED state. If 2771 there is no room to queue this request, respond with "error: 2772 insufficient resources". 2774 ESTABLISHED STATE 2775 FIN-WAIT-1 STATE 2776 FIN-WAIT-2 STATE 2778 If insufficient incoming segments are queued to satisfy the 2779 request, queue the request. If there is no queue space to 2780 remember the RECEIVE, respond with "error: insufficient 2781 resources". 2783 Reassemble queued incoming segments into receive buffer and 2784 return to user. Mark "push seen" (PUSH) if this is the case. 2786 If RCV.UP is in advance of the data currently being passed to 2787 the user notify the user of the presence of urgent data. 2789 When the TCP takes responsibility for delivering data to the 2790 user that fact must be communicated to the sender via an 2791 acknowledgment. The formation of such an acknowledgment is 2792 described below in the discussion of processing an incoming 2793 segment. 2795 CLOSE-WAIT STATE 2797 Since the remote side has already sent FIN, RECEIVEs must be 2798 satisfied by text already on hand, but not yet delivered to the 2799 user. If no text is awaiting delivery, the RECEIVE will get a 2800 "error: connection closing" response. Otherwise, any remaining 2801 text can be used to satisfy the RECEIVE. 2803 CLOSING STATE 2804 LAST-ACK STATE 2805 TIME-WAIT STATE 2807 Return "error: connection closing". 2809 CLOSE Call 2811 CLOSED STATE (i.e., TCB does not exist) 2813 If the user does not have access to such a connection, return 2814 "error: connection illegal for this process". 2816 Otherwise, return "error: connection does not exist". 2818 LISTEN STATE 2820 Any outstanding RECEIVEs are returned with "error: closing" 2821 responses. Delete TCB, enter CLOSED state, and return. 2823 SYN-SENT STATE 2825 Delete the TCB and return "error: closing" responses to any 2826 queued SENDs, or RECEIVEs. 2828 SYN-RECEIVED STATE 2830 If no SENDs have been issued and there is no pending data to 2831 send, then form a FIN segment and send it, and enter FIN-WAIT-1 2832 state; otherwise queue for processing after entering 2833 ESTABLISHED state. 2835 ESTABLISHED STATE 2837 Queue this until all preceding SENDs have been segmentized, 2838 then form a FIN segment and send it. In any case, enter FIN- 2839 WAIT-1 state. 2841 FIN-WAIT-1 STATE 2842 FIN-WAIT-2 STATE 2844 Strictly speaking, this is an error and should receive a 2845 "error: connection closing" response. An "ok" response would 2846 be acceptable, too, as long as a second FIN is not emitted (the 2847 first FIN may be retransmitted though). 2849 CLOSE-WAIT STATE 2851 Queue this request until all preceding SENDs have been 2852 segmentized; then send a FIN segment, enter LAST-ACK state. 2854 CLOSING STATE 2855 LAST-ACK STATE 2856 TIME-WAIT STATE 2857 Respond with "error: connection closing". 2859 ABORT Call 2861 CLOSED STATE (i.e., TCB does not exist) 2863 If the user should not have access to such a connection, return 2864 "error: connection illegal for this process". 2866 Otherwise return "error: connection does not exist". 2868 LISTEN STATE 2870 Any outstanding RECEIVEs should be returned with "error: 2871 connection reset" responses. Delete TCB, enter CLOSED state, 2872 and return. 2874 SYN-SENT STATE 2876 All queued SENDs and RECEIVEs should be given "connection 2877 reset" notification, delete the TCB, enter CLOSED state, and 2878 return. 2880 SYN-RECEIVED STATE 2881 ESTABLISHED STATE 2882 FIN-WAIT-1 STATE 2883 FIN-WAIT-2 STATE 2884 CLOSE-WAIT STATE 2886 Send a reset segment: 2888 2890 All queued SENDs and RECEIVEs should be given "connection 2891 reset" notification; all segments queued for transmission 2892 (except for the RST formed above) or retransmission should be 2893 flushed, delete the TCB, enter CLOSED state, and return. 2895 CLOSING STATE LAST-ACK STATE TIME-WAIT STATE 2897 Respond with "ok" and delete the TCB, enter CLOSED state, and 2898 return. 2900 STATUS Call 2902 CLOSED STATE (i.e., TCB does not exist) 2904 If the user should not have access to such a connection, return 2905 "error: connection illegal for this process". 2907 Otherwise return "error: connection does not exist". 2909 LISTEN STATE 2911 Return "state = LISTEN", and the TCB pointer. 2913 SYN-SENT STATE 2915 Return "state = SYN-SENT", and the TCB pointer. 2917 SYN-RECEIVED STATE 2919 Return "state = SYN-RECEIVED", and the TCB pointer. 2921 ESTABLISHED STATE 2923 Return "state = ESTABLISHED", and the TCB pointer. 2925 FIN-WAIT-1 STATE 2927 Return "state = FIN-WAIT-1", and the TCB pointer. 2929 FIN-WAIT-2 STATE 2931 Return "state = FIN-WAIT-2", and the TCB pointer. 2933 CLOSE-WAIT STATE 2935 Return "state = CLOSE-WAIT", and the TCB pointer. 2937 CLOSING STATE 2939 Return "state = CLOSING", and the TCB pointer. 2941 LAST-ACK STATE 2943 Return "state = LAST-ACK", and the TCB pointer. 2945 TIME-WAIT STATE 2947 Return "state = TIME-WAIT", and the TCB pointer. 2949 SEGMENT ARRIVES 2951 If the state is CLOSED (i.e., TCB does not exist) then 2953 all data in the incoming segment is discarded. An incoming 2954 segment containing a RST is discarded. An incoming segment not 2955 containing a RST causes a RST to be sent in response. The 2956 acknowledgment and sequence field values are selected to make 2957 the reset sequence acceptable to the TCP that sent the 2958 offending segment. 2960 If the ACK bit is off, sequence number zero is used, 2962 2964 If the ACK bit is on, 2966 2968 Return. 2970 If the state is LISTEN then 2972 first check for an RST 2974 An incoming RST should be ignored. Return. 2976 second check for an ACK 2978 Any acknowledgment is bad if it arrives on a connection 2979 still in the LISTEN state. An acceptable reset segment 2980 should be formed for any arriving ACK-bearing segment. The 2981 RST should be formatted as follows: 2983 2985 Return. 2987 third check for a SYN 2989 If the SYN bit is set, check the security. If the security/ 2990 compartment on the incoming segment does not exactly match 2991 the security/compartment in the TCB then send a reset and 2992 return. 2994 2996 Set RCV.NXT to SEG.SEQ+1, IRS is set to SEG.SEQ and any 2997 other control or text should be queued for processing later. 2998 ISS should be selected and a SYN segment sent of the form: 3000 3002 SND.NXT is set to ISS+1 and SND.UNA to ISS. The connection 3003 state should be changed to SYN-RECEIVED. Note that any 3004 other incoming control or data (combined with SYN) will be 3005 processed in the SYN-RECEIVED state, but processing of SYN 3006 and ACK should not be repeated. If the listen was not fully 3007 specified (i.e., the foreign socket was not fully 3008 specified), then the unspecified fields should be filled in 3009 now. 3011 fourth other text or control 3013 Any other control or text-bearing segment (not containing 3014 SYN) must have an ACK and thus would be discarded by the ACK 3015 processing. An incoming RST segment could not be valid, 3016 since it could not have been sent in response to anything 3017 sent by this incarnation of the connection. So you are 3018 unlikely to get here, but if you do, drop the segment, and 3019 return. 3021 If the state is SYN-SENT then 3023 first check the ACK bit 3025 If the ACK bit is set 3027 If SEG.ACK =< ISS, or SEG.ACK > SND.NXT, send a reset 3028 (unless the RST bit is set, if so drop the segment and 3029 return) 3031 3033 and discard the segment. Return. 3035 If SND.UNA < SEG.ACK =< SND.NXT then the ACK is 3036 acceptable. Some deployed TCP code has used the check 3037 SEG.ACK == SND.NEXT (using "==" rather than "=<", but 3038 this is not appropriate when the stack is capable of 3039 sending data on the SYN, because the peer TCP may not 3040 accept and acknowledge all of the data on the SYN. 3042 second check the RST bit 3043 If the RST bit is set 3045 A potential blind reset attack is described in RFC 5961 3046 [27], with the mitigation that a TCP implementation 3047 SHOULD first check that the sequence number exactly 3048 matches RCV.NXT prior to executing the action in the next 3049 paragraph. 3051 If the ACK was acceptable then signal the user "error: 3052 connection reset", drop the segment, enter CLOSED state, 3053 delete TCB, and return. Otherwise (no ACK) drop the 3054 segment and return. 3056 third check the security 3058 If the security/compartment in the segment does not exactly 3059 match the security/compartment in the TCB, send a reset 3061 If there is an ACK 3063 3065 Otherwise 3067 3069 If a reset was sent, discard the segment and return. 3071 fourth check the SYN bit 3073 This step should be reached only if the ACK is ok, or there 3074 is no ACK, and it the segment did not contain a RST. 3076 If the SYN bit is on and the security/compartment is 3077 acceptable then, RCV.NXT is set to SEG.SEQ+1, IRS is set to 3078 SEG.SEQ. SND.UNA should be advanced to equal SEG.ACK (if 3079 there is an ACK), and any segments on the retransmission 3080 queue which are thereby acknowledged should be removed. 3082 If SND.UNA > ISS (our SYN has been ACKed), change the 3083 connection state to ESTABLISHED, form an ACK segment 3085 3087 and send it. Data or controls which were queued for 3088 transmission may be included. If there are other controls 3089 or text in the segment then continue processing at the sixth 3090 step below where the URG bit is checked, otherwise return. 3092 Otherwise enter SYN-RECEIVED, form a SYN,ACK segment 3094 3096 and send it. Set the variables: 3098 SND.WND <- SEG.WND 3099 SND.WL1 <- SEG.SEQ 3100 SND.WL2 <- SEG.ACK 3102 If there are other controls or text in the segment, queue 3103 them for processing after the ESTABLISHED state has been 3104 reached, return. 3106 Note that it is legal to send and receive application data 3107 on SYN segments (this is the "text in the segment" mentioned 3108 above. There has been significant misinformation and 3109 misunderstanding of this topic historically. Some firewalls 3110 and security devices consider this suspicious. However, the 3111 capability was used in T/TCP [16] and is used in TCP Fast 3112 Open (TFO) [35], so is important for implementations and 3113 network devices to permit. 3115 fifth, if neither of the SYN or RST bits is set then drop the 3116 segment and return. 3118 Otherwise, 3120 first check sequence number 3122 SYN-RECEIVED STATE 3123 ESTABLISHED STATE 3124 FIN-WAIT-1 STATE 3125 FIN-WAIT-2 STATE 3126 CLOSE-WAIT STATE 3127 CLOSING STATE 3128 LAST-ACK STATE 3129 TIME-WAIT STATE 3131 Segments are processed in sequence. Initial tests on 3132 arrival are used to discard old duplicates, but further 3133 processing is done in SEG.SEQ order. If a segment's 3134 contents straddle the boundary between old and new, only the 3135 new parts should be processed. 3137 In general, the processing of received segments MUST be 3138 implemented to aggregate ACK segments whenever possible. 3139 For example, if the TCP is processing a series of queued 3140 segments, it MUST process them all before sending any ACK 3141 segments. 3143 There are four cases for the acceptability test for an 3144 incoming segment: 3146 Segment Receive Test 3147 Length Window 3148 ------- ------- ------------------------------------------- 3150 0 0 SEG.SEQ = RCV.NXT 3152 0 >0 RCV.NXT =< SEG.SEQ < RCV.NXT+RCV.WND 3154 >0 0 not acceptable 3156 >0 >0 RCV.NXT =< SEG.SEQ < RCV.NXT+RCV.WND 3157 or RCV.NXT =< SEG.SEQ+SEG.LEN-1 < RCV.NXT+RCV.WND 3159 In implementing sequence number validation as described 3160 here, please note Appendix A.2. 3162 If the RCV.WND is zero, no segments will be acceptable, but 3163 special allowance should be made to accept valid ACKs, URGs 3164 and RSTs. 3166 If an incoming segment is not acceptable, an acknowledgment 3167 should be sent in reply (unless the RST bit is set, if so 3168 drop the segment and return): 3170 3172 After sending the acknowledgment, drop the unacceptable 3173 segment and return. 3175 Note that for the TIME-WAIT state, there is an improved 3176 algorithm described in [29] for handling incoming SYN 3177 segments, that utilizes timestamps rather than relying on 3178 the sequence number check described here. When the improved 3179 algorithm is implemented, the logic above is not applicable 3180 for incoming SYN segments with timestamp options, received 3181 on a connection in the TIME-WAIT state. 3183 In the following it is assumed that the segment is the 3184 idealized segment that begins at RCV.NXT and does not exceed 3185 the window. One could tailor actual segments to fit this 3186 assumption by trimming off any portions that lie outside the 3187 window (including SYN and FIN), and only processing further 3188 if the segment then begins at RCV.NXT. Segments with higher 3189 beginning sequence numbers should be held for later 3190 processing. 3192 second check the RST bit, 3194 RFC 5961 section 3 describes a potential blind reset attack 3195 and optional mitigation approach that SHOULD be implemented. 3196 For stacks implementing RFC 5961, the three checks below 3197 apply, otherwise processesing for these states is indicated 3198 further below. 3200 1) If the RST bit is set and the sequence number is 3201 outside the current receive window, silently drop the 3202 segment. 3204 2) If the RST bit is set and the sequence number exactly 3205 matches the next expected sequence number (RCV.NXT), then 3206 TCP MUST reset the connection in the manner prescribed 3207 below according to the connection state. 3209 3) If the RST bit is set and the sequence number does not 3210 exactly match the next expected sequence value, yet is 3211 within the current receive window, TCP MUST send an 3212 acknowledgement (challenge ACK): 3214 3216 After sending the challenge ACK, TCP MUST drop the 3217 unacceptable segment and stop processing the incoming 3218 packet further. Note that RFC 5961 and Errata ID 4772 3219 contain additional considerations for ACK throttling in 3220 an implementation. 3222 SYN-RECEIVED STATE 3224 If the RST bit is set 3226 If this connection was initiated with a passive OPEN 3227 (i.e., came from the LISTEN state), then return this 3228 connection to LISTEN state and return. The user need 3229 not be informed. If this connection was initiated 3230 with an active OPEN (i.e., came from SYN-SENT state) 3231 then the connection was refused, signal the user 3232 "connection refused". In either case, all segments on 3233 the retransmission queue should be removed. And in 3234 the active OPEN case, enter the CLOSED state and 3235 delete the TCB, and return. 3237 ESTABLISHED 3238 FIN-WAIT-1 3239 FIN-WAIT-2 3240 CLOSE-WAIT 3242 If the RST bit is set then, any outstanding RECEIVEs and 3243 SEND should receive "reset" responses. All segment 3244 queues should be flushed. Users should also receive an 3245 unsolicited general "connection reset" signal. Enter the 3246 CLOSED state, delete the TCB, and return. 3248 CLOSING STATE 3249 LAST-ACK STATE 3250 TIME-WAIT 3252 If the RST bit is set then, enter the CLOSED state, 3253 delete the TCB, and return. 3255 third check security 3257 SYN-RECEIVED 3259 If the security/compartment in the segment does not 3260 exactly match the security/compartment in the TCB then 3261 send a reset, and return. 3263 ESTABLISHED 3264 FIN-WAIT-1 3265 FIN-WAIT-2 3266 CLOSE-WAIT 3267 CLOSING 3268 LAST-ACK 3269 TIME-WAIT 3271 If the security/compartment in the segment does not 3272 exactly match the security/compartment in the TCB then 3273 send a reset, any outstanding RECEIVEs and SEND should 3274 receive "reset" responses. All segment queues should be 3275 flushed. Users should also receive an unsolicited 3276 general "connection reset" signal. Enter the CLOSED 3277 state, delete the TCB, and return. 3279 Note this check is placed following the sequence check to 3280 prevent a segment from an old connection between these ports 3281 with a different security from causing an abort of the 3282 current connection. 3284 fourth, check the SYN bit, 3286 SYN-RECEIVED 3288 If the connection was initiated with a passive OPEN, then 3289 return this connection to the LISTEN state and return. 3290 Otherwise, handle per the directions for synchronized 3291 states below. 3293 ESTABLISHED STATE 3294 FIN-WAIT STATE-1 3295 FIN-WAIT STATE-2 3296 CLOSE-WAIT STATE 3297 CLOSING STATE 3298 LAST-ACK STATE 3299 TIME-WAIT STATE 3301 If the SYN bit is set in these synchronized states, it 3302 may be either a legitimate new connection attempt (e.g. 3303 in the case of TIME-WAIT), an error where the connection 3304 should be reset, or the result of an attack attempt, as 3305 described in RFC 5961 [27]. For the TIME-WAIT state, new 3306 connections can be accepted if the timestamp option is 3307 used and meets expectations (per [29]). For all other 3308 caess, RFC 5961 provides a mitigation that SHOULD be 3309 implemented, though there are alternatives (see 3310 Section 11). RFC 5961 recommends that in these 3311 synchronized states, if the SYN bit is set, irrespective 3312 of the sequence number, TCP MUST send a "challenge ACK" 3313 to the remote peer: 3315 3317 After sending the acknowledgement, TCP MUST drop the 3318 unacceptable segment and stop processing further. Note 3319 that RFC 5961 and Errata ID 4772 contain additional ACK 3320 throttling notes for an implementation. 3322 For implementations that do not follow RFC 5961, the 3323 original RFC 793 behavior follows in this paragraph. If 3324 the SYN is in the window it is an error, send a reset, 3325 any outstanding RECEIVEs and SEND should receive "reset" 3326 responses, all segment queues should be flushed, the user 3327 should also receive an unsolicited general "connection 3328 reset" signal, enter the CLOSED state, delete the TCB, 3329 and return. 3331 If the SYN is not in the window this step would not be 3332 reached and an ack would have been sent in the first step 3333 (sequence number check). 3335 fifth check the ACK field, 3337 if the ACK bit is off drop the segment and return 3339 if the ACK bit is on 3341 RFC 5961 section 5 describes a potential blind data 3342 injection attack, and mitigation that implementations MAY 3343 choose to include. TCP stacks that implement RFC 5961 3344 MUST add an input check that the ACK value is acceptable 3345 only if it is in the range of ((SND.UNA - MAX.SND.WND) =< 3346 SEG.ACK =< SND.NXT). All incoming segments whose ACK 3347 value doesn't satisfy the above condition MUST be 3348 discarded and an ACK sent back. The new state variable 3349 MAX.SND.WND is defined as the largest window that the 3350 local sender has ever received from its peer (subject to 3351 window scaling) or may be hard-coded to a maximum 3352 permissible window value. When the ACK value is 3353 acceptable, the processing per-state below applies: 3355 SYN-RECEIVED STATE 3357 If SND.UNA < SEG.ACK =< SND.NXT then enter ESTABLISHED 3358 state and continue processing with variables below set 3359 to: 3361 SND.WND <- SEG.WND 3362 SND.WL1 <- SEG.SEQ 3363 SND.WL2 <- SEG.ACK 3365 If the segment acknowledgment is not acceptable, 3366 form a reset segment, 3368 3370 and send it. 3372 ESTABLISHED STATE 3374 If SND.UNA < SEG.ACK =< SND.NXT then, set SND.UNA <- 3375 SEG.ACK. Any segments on the retransmission queue 3376 which are thereby entirely acknowledged are removed. 3377 Users should receive positive acknowledgments for 3378 buffers which have been SENT and fully acknowledged 3379 (i.e., SEND buffer should be returned with "ok" 3380 response). If the ACK is a duplicate (SEG.ACK =< 3381 SND.UNA), it can be ignored. If the ACK acks 3382 something not yet sent (SEG.ACK > SND.NXT) then send 3383 an ACK, drop the segment, and return. 3385 If SND.UNA =< SEG.ACK =< SND.NXT, the send window 3386 should be updated. If (SND.WL1 < SEG.SEQ or (SND.WL1 3387 = SEG.SEQ and SND.WL2 =< SEG.ACK)), set SND.WND <- 3388 SEG.WND, set SND.WL1 <- SEG.SEQ, and set SND.WL2 <- 3389 SEG.ACK. 3391 Note that SND.WND is an offset from SND.UNA, that 3392 SND.WL1 records the sequence number of the last 3393 segment used to update SND.WND, and that SND.WL2 3394 records the acknowledgment number of the last segment 3395 used to update SND.WND. The check here prevents using 3396 old segments to update the window. 3398 FIN-WAIT-1 STATE 3400 In addition to the processing for the ESTABLISHED 3401 state, if our FIN is now acknowledged then enter FIN- 3402 WAIT-2 and continue processing in that state. 3404 FIN-WAIT-2 STATE 3406 In addition to the processing for the ESTABLISHED 3407 state, if the retransmission queue is empty, the 3408 user's CLOSE can be acknowledged ("ok") but do not 3409 delete the TCB. 3411 CLOSE-WAIT STATE 3413 Do the same processing as for the ESTABLISHED state. 3415 CLOSING STATE 3417 In addition to the processing for the ESTABLISHED 3418 state, if the ACK acknowledges our FIN then enter the 3419 TIME-WAIT state, otherwise ignore the segment. 3421 LAST-ACK STATE 3422 The only thing that can arrive in this state is an 3423 acknowledgment of our FIN. If our FIN is now 3424 acknowledged, delete the TCB, enter the CLOSED state, 3425 and return. 3427 TIME-WAIT STATE 3429 The only thing that can arrive in this state is a 3430 retransmission of the remote FIN. Acknowledge it, and 3431 restart the 2 MSL timeout. 3433 sixth, check the URG bit, 3435 ESTABLISHED STATE 3436 FIN-WAIT-1 STATE 3437 FIN-WAIT-2 STATE 3439 If the URG bit is set, RCV.UP <- max(RCV.UP,SEG.UP), and 3440 signal the user that the remote side has urgent data if 3441 the urgent pointer (RCV.UP) is in advance of the data 3442 consumed. If the user has already been signaled (or is 3443 still in the "urgent mode") for this continuous sequence 3444 of urgent data, do not signal the user again. 3446 CLOSE-WAIT STATE 3447 CLOSING STATE 3448 LAST-ACK STATE 3449 TIME-WAIT 3451 This should not occur, since a FIN has been received from 3452 the remote side. Ignore the URG. 3454 seventh, process the segment text, 3456 ESTABLISHED STATE 3457 FIN-WAIT-1 STATE 3458 FIN-WAIT-2 STATE 3460 Once in the ESTABLISHED state, it is possible to deliver 3461 segment text to user RECEIVE buffers. Text from segments 3462 can be moved into buffers until either the buffer is full 3463 or the segment is empty. If the segment empties and 3464 carries an PUSH flag, then the user is informed, when the 3465 buffer is returned, that a PUSH has been received. 3467 When the TCP takes responsibility for delivering the data 3468 to the user it must also acknowledge the receipt of the 3469 data. 3471 Once the TCP takes responsibility for the data it 3472 advances RCV.NXT over the data accepted, and adjusts 3473 RCV.WND as appropriate to the current buffer 3474 availability. The total of RCV.NXT and RCV.WND should 3475 not be reduced. 3477 A TCP MAY send an ACK segment acknowledging RCV.NXT when 3478 a valid segment arrives that is in the window but not at 3479 the left window edge. 3481 Please note the window management suggestions in section 3482 3.7. 3484 Send an acknowledgment of the form: 3486 3488 This acknowledgment should be piggybacked on a segment 3489 being transmitted if possible without incurring undue 3490 delay. 3492 CLOSE-WAIT STATE 3493 CLOSING STATE 3494 LAST-ACK STATE 3495 TIME-WAIT STATE 3497 This should not occur, since a FIN has been received from 3498 the remote side. Ignore the segment text. 3500 eighth, check the FIN bit, 3502 Do not process the FIN if the state is CLOSED, LISTEN or 3503 SYN-SENT since the SEG.SEQ cannot be validated; drop the 3504 segment and return. 3506 If the FIN bit is set, signal the user "connection closing" 3507 and return any pending RECEIVEs with same message, advance 3508 RCV.NXT over the FIN, and send an acknowledgment for the 3509 FIN. Note that FIN implies PUSH for any segment text not 3510 yet delivered to the user. 3512 SYN-RECEIVED STATE 3513 ESTABLISHED STATE 3515 Enter the CLOSE-WAIT state. 3517 FIN-WAIT-1 STATE 3518 If our FIN has been ACKed (perhaps in this segment), 3519 then enter TIME-WAIT, start the time-wait timer, turn 3520 off the other timers; otherwise enter the CLOSING 3521 state. 3523 FIN-WAIT-2 STATE 3525 Enter the TIME-WAIT state. Start the time-wait timer, 3526 turn off the other timers. 3528 CLOSE-WAIT STATE 3530 Remain in the CLOSE-WAIT state. 3532 CLOSING STATE 3534 Remain in the CLOSING state. 3536 LAST-ACK STATE 3538 Remain in the LAST-ACK state. 3540 TIME-WAIT STATE 3542 Remain in the TIME-WAIT state. Restart the 2 MSL 3543 time-wait timeout. 3545 and return. 3547 USER TIMEOUT 3549 USER TIMEOUT 3551 For any state if the user timeout expires, flush all queues, 3552 signal the user "error: connection aborted due to user timeout" 3553 in general and for any outstanding calls, delete the TCB, enter 3554 the CLOSED state and return. 3556 RETRANSMISSION TIMEOUT 3558 For any state if the retransmission timeout expires on a 3559 segment in the retransmission queue, send the segment at the 3560 front of the retransmission queue again, reinitialize the 3561 retransmission timer, and return. 3563 TIME-WAIT TIMEOUT 3565 If the time-wait timeout expires on a connection delete the 3566 TCB, enter the CLOSED state and return. 3568 8.4. Glossary 3570 1822 BBN Report 1822, "The Specification of the Interconnection of 3571 a Host and an IMP". The specification of interface between a 3572 host and the ARPANET. 3574 ACK 3575 A control bit (acknowledge) occupying no sequence space, 3576 which indicates that the acknowledgment field of this segment 3577 specifies the next sequence number the sender of this segment 3578 is expecting to receive, hence acknowledging receipt of all 3579 previous sequence numbers. 3581 ARPANET message 3582 The unit of transmission between a host and an IMP in the 3583 ARPANET. The maximum size is about 1012 octets (8096 bits). 3585 ARPANET packet 3586 A unit of transmission used internally in the ARPANET between 3587 IMPs. The maximum size is about 126 octets (1008 bits). 3589 connection 3590 A logical communication path identified by a pair of sockets. 3592 datagram 3593 A message sent in a packet switched computer communications 3594 network. 3596 Destination Address 3597 The destination address, usually the network and host 3598 identifiers. 3600 FIN 3601 A control bit (finis) occupying one sequence number, which 3602 indicates that the sender will send no more data or control 3603 occupying sequence space. 3605 fragment 3606 A portion of a logical unit of data, in particular an 3607 internet fragment is a portion of an internet datagram. 3609 FTP 3610 A file transfer protocol. 3612 header 3613 Control information at the beginning of a message, segment, 3614 fragment, packet or block of data. 3616 host 3617 A computer. In particular a source or destination of 3618 messages from the point of view of the communication network. 3620 Identification 3621 An Internet Protocol field. This identifying value assigned 3622 by the sender aids in assembling the fragments of a datagram. 3624 IMP 3625 The Interface Message Processor, the packet switch of the 3626 ARPANET. 3628 internet address 3629 A source or destination address specific to the host level. 3631 internet datagram 3632 The unit of data exchanged between an internet module and the 3633 higher level protocol together with the internet header. 3635 internet fragment 3636 A portion of the data of an internet datagram with an 3637 internet header. 3639 IP 3640 Internet Protocol. 3642 IRS 3643 The Initial Receive Sequence number. The first sequence 3644 number used by the sender on a connection. 3646 ISN 3647 The Initial Sequence Number. The first sequence number used 3648 on a connection, (either ISS or IRS). Selected in a way that 3649 is unique within a given period of time and is unpredictable 3650 to attackers. 3652 ISS 3653 The Initial Send Sequence number. The first sequence number 3654 used by the sender on a connection. 3656 leader 3657 Control information at the beginning of a message or block of 3658 data. In particular, in the ARPANET, the control information 3659 on an ARPANET message at the host-IMP interface. 3661 left sequence 3662 This is the next sequence number to be acknowledged by the 3663 data receiving TCP (or the lowest currently unacknowledged 3664 sequence number) and is sometimes referred to as the left 3665 edge of the send window. 3667 local packet 3668 The unit of transmission within a local network. 3670 module 3671 An implementation, usually in software, of a protocol or 3672 other procedure. 3674 MSL 3675 Maximum Segment Lifetime, the time a TCP segment can exist in 3676 the internetwork system. Arbitrarily defined to be 2 3677 minutes. 3679 octet 3680 An eight bit byte. 3682 Options 3683 An Option field may contain several options, and each option 3684 may be several octets in length. 3686 packet 3687 A package of data with a header which may or may not be 3688 logically complete. More often a physical packaging than a 3689 logical packaging of data. 3691 port 3692 The portion of a socket that specifies which logical input or 3693 output channel of a process is associated with the data. 3695 process 3696 A program in execution. A source or destination of data from 3697 the point of view of the TCP or other host-to-host protocol. 3699 PUSH 3700 A control bit occupying no sequence space, indicating that 3701 this segment contains data that must be pushed through to the 3702 receiving user. 3704 RCV.NXT 3705 receive next sequence number 3707 RCV.UP 3708 receive urgent pointer 3710 RCV.WND 3711 receive window 3713 receive next sequence number 3714 This is the next sequence number the local TCP is expecting 3715 to receive. 3717 receive window 3718 This represents the sequence numbers the local (receiving) 3719 TCP is willing to receive. Thus, the local TCP considers 3720 that segments overlapping the range RCV.NXT to RCV.NXT + 3721 RCV.WND - 1 carry acceptable data or control. Segments 3722 containing sequence numbers entirely outside of this range 3723 are considered duplicates and discarded. 3725 RST 3726 A control bit (reset), occupying no sequence space, 3727 indicating that the receiver should delete the connection 3728 without further interaction. The receiver can determine, 3729 based on the sequence number and acknowledgment fields of the 3730 incoming segment, whether it should honor the reset command 3731 or ignore it. In no case does receipt of a segment 3732 containing RST give rise to a RST in response. 3734 RTP 3735 Real Time Protocol: A host-to-host protocol for communication 3736 of time critical information. 3738 SEG.ACK 3739 segment acknowledgment 3741 SEG.LEN 3742 segment length 3744 SEG.SEQ 3745 segment sequence 3747 SEG.UP 3748 segment urgent pointer field 3750 SEG.WND 3751 segment window field 3753 segment 3754 A logical unit of data, in particular a TCP segment is the 3755 unit of data transfered between a pair of TCP modules. 3757 segment acknowledgment 3758 The sequence number in the acknowledgment field of the 3759 arriving segment. 3761 segment length 3762 The amount of sequence number space occupied by a segment, 3763 including any controls which occupy sequence space. 3765 segment sequence 3766 The number in the sequence field of the arriving segment. 3768 send sequence 3769 This is the next sequence number the local (sending) TCP will 3770 use on the connection. It is initially selected from an 3771 initial sequence number curve (ISN) and is incremented for 3772 each octet of data or sequenced control transmitted. 3774 send window 3775 This represents the sequence numbers which the remote 3776 (receiving) TCP is willing to receive. It is the value of 3777 the window field specified in segments from the remote (data 3778 receiving) TCP. The range of new sequence numbers which may 3779 be emitted by a TCP lies between SND.NXT and SND.UNA + 3780 SND.WND - 1. (Retransmissions of sequence numbers between 3781 SND.UNA and SND.NXT are expected, of course.) 3783 SND.NXT 3784 send sequence 3786 SND.UNA 3787 left sequence 3789 SND.UP 3790 send urgent pointer 3792 SND.WL1 3793 segment sequence number at last window update 3795 SND.WL2 3796 segment acknowledgment number at last window update 3798 SND.WND 3799 send window 3801 socket 3802 An address which specifically includes a port identifier, 3803 that is, the concatenation of an Internet Address with a TCP 3804 port. 3806 Source Address 3807 The source address, usually the network and host identifiers. 3809 SYN 3810 A control bit in the incoming segment, occupying one sequence 3811 number, used at the initiation of a connection, to indicate 3812 where the sequence numbering will start. 3814 TCB 3815 Transmission control block, the data structure that records 3816 the state of a connection. 3818 TCP 3819 Transmission Control Protocol: A host-to-host protocol for 3820 reliable communication in internetwork environments. 3822 TOS 3823 Type of Service, an IPv4 field, that currently carries the 3824 Differentiated Services field [6] containing the 3825 Differentiated Services Code Point (DSCP) value and two 3826 unused bits. 3828 Type of Service 3829 An Internet Protocol field which indicates the type of 3830 service for this internet fragment. 3832 URG 3833 A control bit (urgent), occupying no sequence space, used to 3834 indicate that the receiving user should be notified to do 3835 urgent processing as long as there is data to be consumed 3836 with sequence numbers less than the value indicated in the 3837 urgent pointer. 3839 urgent pointer 3840 A control field meaningful only when the URG bit is on. This 3841 field communicates the value of the urgent pointer which 3842 indicates the data octet associated with the sending user's 3843 urgent call. 3845 9. Changes from RFC 793 3847 This document obsoletes RFC 793 as well as RFC 6093 and 6528, which 3848 updated 793. In all cases, only the normative protocol specification 3849 and requirements have been incorporated into this document, and the 3850 informational text with background and rationale has not been carried 3851 in. The informational content of those documents is still valuable 3852 in learning about and understanding TCP, and they are valid 3853 Informational references, even though their normative content has 3854 been incorporated into this document. 3856 The main body of this document was adapted from RFC 793's Section 3, 3857 titled "FUNCTIONAL SPECIFICATION", with an attempt to keep formatting 3858 and layout as close as possible. 3860 The collection of applicable RFC Errata that have been reported and 3861 either accepted or held for an update to RFC 793 were incorporated 3862 (Errata IDs: 573, 574, 700, 701, 1283, 1561, 1562, 1564, 1565, 1571, 3863 1572, 2296, 2297, 2298, 2748, 2749, 2934, 3213, 3300, 3301). Some 3864 errata were not applicable due to other changes (Errata IDs: 572, 3865 575, 1569, 3305, 3602). 3867 Changes to the specification of the Urgent Pointer described in RFC 3868 1122 and 6093 were incorporated. See RFC 6093 for detailed 3869 discussion of why these changes were necessary. 3871 The discussion of the RTO from RFC 793 was updated to refer to RFC 3872 6298. The RFC 1122 text on the RTO originally replaced the 793 text, 3873 however, RFC 2988 should have updated 1122, and has subsequently been 3874 obsoleted by 6298. 3876 RFC 1122 contains a collection of other changes and clarifications to 3877 RFC 793. The normative items impacting the protocol have been 3878 incorporated here, though some historically useful implementation 3879 advice and informative discussion from RFC 1122 is not included here. 3881 RFC 1122 contains more than just TCP requirements, so this document 3882 can't obsolete RFC 1122 entirely. It is only marked as "updating" 3883 1122, however, it should be understood to effectively obsolete all of 3884 the RFC 1122 material on TCP. 3886 The more secure Initial Sequence Number generation algorithm from RFC 3887 6528 was incorporated. See RFC 6528 for discussion of the attacks 3888 that this mitigates, as well as advice on selecting PRF algorithms 3889 and managing secret key data. 3891 A note based on RFC 6429 was added to explicitly clarify that system 3892 resource mangement concerns allow connection resources to be 3893 reclaimed. RFC 6429 is obsoleted in the sense that this 3894 clarification has been reflected in this update to the base TCP 3895 specification now. 3897 RFC EDITOR'S NOTE: the content below is for detailed change tracking 3898 and planning, and not to be included with the final revision of the 3899 document. 3901 This document started as draft-eddy-rfc793bis-00, that was merely a 3902 proposal and rough plan for updating RFC 793. 3904 The -01 revision of this draft-eddy-rfc793bis incorporates the 3905 content of RFC 793 Section 3 titled "FUNCTIONAL SPECIFICATION". 3906 Other content from RFC 793 has not been incorporated. The -01 3907 revision of this document makes some minor formatting changes to the 3908 RFC 793 content in order to convert the content into XML2RFC format 3909 and account for left-out parts of RFC 793. For instance, figure 3910 numbering differs and some indentation is not exactly the same. 3912 The -02 revision of draft-eddy-rfc793bis incorporates errata that 3913 have been verified: 3915 Errata ID 573: Reported by Bob Braden (note: This errata basically 3916 is just a reminder that RFC 1122 updates 793. Some of the 3917 associated changes are left pending to a separate revision that 3918 incorporates 1122. Bob's mention of PUSH in 793 section 2.8 was 3919 not applicable here because that section was not part of the 3920 "functional specification". Also the 1122 text on the 3921 retransmission timeout also has been updated by subsequent RFCs, 3922 so the change here deviates from Bob's suggestion to apply the 3923 1122 text.) 3924 Errata ID 574: Reported by Yin Shuming 3925 Errata ID 700: Reported by Yin Shuming 3926 Errata ID 701: Reported by Yin Shuming 3927 Errata ID 1283: Reported by Pei-chun Cheng 3928 Errata ID 1561: Reported by Constantin Hagemeier 3929 Errata ID 1562: Reported by Constantin Hagemeier 3930 Errata ID 1564: Reported by Constantin Hagemeier 3931 Errata ID 1565: Reported by Constantin Hagemeier 3932 Errata ID 1571: Reported by Constantin Hagemeier 3933 Errata ID 1572: Reported by Constantin Hagemeier 3934 Errata ID 2296: Reported by Vishwas Manral 3935 Errata ID 2297: Reported by Vishwas Manral 3936 Errata ID 2298: Reported by Vishwas Manral 3937 Errata ID 2748: Reported by Mykyta Yevstifeyev 3938 Errata ID 2749: Reported by Mykyta Yevstifeyev 3939 Errata ID 2934: Reported by Constantin Hagemeier 3940 Errata ID 3213: Reported by EugnJun Yi 3941 Errata ID 3300: Reported by Botong Huang 3942 Errata ID 3301: Reported by Botong Huang 3943 Errata ID 3305: Reported by Botong Huang 3944 Note: Some verified errata were not used in this update, as they 3945 relate to sections of RFC 793 elided from this document. These 3946 include Errata ID 572, 575, and 1569. 3947 Note: Errata ID 3602 was not applied in this revision as it is 3948 duplicative of the 1122 corrections. 3950 Not related to RFC 793 content, this revision also makes small tweaks 3951 to the introductory text, fixes indentation of the pseudoheader 3952 diagram, and notes that the Security Considerations should also 3953 include privacy, when this section is written. 3955 The -03 revision of draft-eddy-rfc793bis revises all discussion of 3956 the urgent pointer in order to comply with RFC 6093, 1122, and 1011. 3957 Since 1122 held requirements on the urgent pointer, the full list of 3958 requirements was brought into an appendix of this document, so that 3959 it can be updated as-needed. 3961 The -04 revision of draft-eddy-rfc793bis includes the ISN generation 3962 changes from RFC 6528. 3964 The -05 revision of draft-eddy-rfc793bis incorporates MSS 3965 requirements and definitions from RFC 879, 1122, and 6691, as well as 3966 option-handling requirements from RFC 1122. 3968 The -00 revision of draft-ietf-tcpm-rfc793bis incorporates several 3969 additional clarifications and updates to the section on segmentation, 3970 many of which are based on feedback from Joe Touch improving from the 3971 initial text on this in the previous revision. 3973 The -01 revision incorporates the change to Reserved bits due to ECN, 3974 as well as many other changes that come from RFC 1122. 3976 The -02 revision has small formating modifications in order to 3977 address xml2rfc warnings about long lines. It was a quick update to 3978 avoid document expiration. TCPM working group discussion in 2015 3979 also indicated that that we should not try to add sections on 3980 implementation advice or similar non-normative information. 3982 The -03 revision incorporates more content from RFC 1122: Passive 3983 OPEN Calls, Time-To-Live, Multihoming, IP Options, ICMP messages, 3984 Data Communications, When to Send Data, When to Send a Window Update, 3985 Managing the Window, Probing Zero Windows, When to Send an ACK 3986 Segment. The section on data communications was re-organized into 3987 clearer subsections (previously headings were embedded in the 793 3988 text), and windows management advice from 793 was removed (as 3989 reviewed by TCPM working group) in favor of the 1122 additions on 3990 SWS, ZWP, and related topics. 3992 The -04 revision includes reference to RFC 6429 on the ZWP condition, 3993 RFC1122 material on TCP Connection Failures, TCP Keep-Alives, 3994 Acknowledging Queued Segments, and Remote Address Validation. RTO 3995 computation is referenced from RFC 6298 rather than RFC 1122. 3997 The -05 revision includes the requirement to implement TCP congestion 3998 control with recommendation to implemente ECN, the RFC 6633 update to 3999 1122, which changed the requirement on responding to source quench 4000 ICMP messages, and discussion of ICMP (and ICMPv6) soft and hard 4001 errors per RFC 5461 (ICMPv6 handling for TCP doesn't seem to be 4002 mentioned elsewhere in standards track). 4004 The -06 revision includes an appendix on "Other Implementation Notes" 4005 to capture widely-deployed fundamental features that are not 4006 contained in the RFC series yet. It also added mention of RFC 6994 4007 and the IANA TCP parameters registry as a reference. It includes 4008 references to RFC 5961 in appropriate places. The references to TOS 4009 were changed to DiffServ field, based on reflecting RFC 2474 as well 4010 as the IPv6 presence of traffic class (carrying DiffServ field) 4011 rather than TOS. 4013 The -07 revision includes reference to RFC 6191, updated security 4014 considerations, discussion of additional implementation 4015 considerations, and clarification of data on the SYN. 4017 The -08 revision includes changes based on: 4019 describing treatment of reserved bits (following TCPM mailing list 4020 thread from July 2014 on "793bis item - reserved bit behavior" 4021 addition a brief TCP key concepts section to make up for not 4022 including the outdated section 2 of RFC 793 4023 changed "TCP" to "host" to resolve conflict between 1122 wording 4024 on whether TCP or the network layer chooses an address when 4025 multihomed 4026 fixed/updated definition of options in glossary 4027 moved note on aggregating ACKs from 1122 to a more appropriate 4028 location 4029 resolved notes on IP precedence and security/compartment 4030 added implementation note on sequence number validation 4031 added note that PUSH does not apply when Nagle is active 4032 added 1122 content on asynchronous reports to replace 793 section 4033 on TCP to user messages 4035 Some other suggested changes that will not be incorporated in this 4036 793 update unless TCPM consensus changes with regard to scope are: 4038 1. look at Tony Sabatini suggestion for describing DO field 4039 2. per discussion with Joe Touch (TAPS list, 6/20/2015), the 4040 description of the API could be revisited 4042 Early in the process of updating RFC 793, Scott Brim mentioned that 4043 this should include a PERPASS/privacy review. This may be something 4044 for the chairs or AD to request during WGLC or IETF LC. 4046 10. IANA Considerations 4048 This memo includes no request to IANA. Existing IANA registries for 4049 TCP parameters are sufficient. 4051 TODO: check whether entries pointing to 793 and other documents 4052 obsoleted by this one should be updated to point to this one instead. 4054 11. Security and Privacy Considerations 4056 The TCP design includes only rudimentary security features that 4057 improve the robustness and reliability of connections and application 4058 data transfer, but there are no built-in capabilities to support any 4059 form of privacy, authentication, or other typical security functions. 4060 Applications typically utilize lower-layer (e.g. IPsec) and upper- 4061 layer (e.g. TLS) protocols to provide security and privacy for TCP 4062 connections and application data carried in TCP. TCP options are 4063 available as well, to support some security capabilities. 4065 Applications using long-lived TCP flows have been vulnerable to 4066 attacks that exploit the processing of control flags described in 4067 earlier TCP specifications [20]. TCP-MD5 was a commonly implemented 4068 TCP option to support authentication for some of these connections, 4069 but had flaws and is now deprecated. The TCP Authentication Option 4070 (TCP AO) [26] provides a capability to protect long-lived TCP 4071 connections from attacks, and has superior properties to TCP-MD5. It 4072 does not provide any privacy for application data, nor for the TCP 4073 headers. 4075 The "tcpcrypt" [43]Experimental extension to TCP provides the ability 4076 to cryptographically protect connection data. Metadata aspects of 4077 the TCP flow are still visible, but the application stream is well- 4078 protected. Within the TCP header, only the urgent pointer and FIN 4079 flag are protected through tcpcrypt. 4081 The TCP Roadmap [36] includes notes about several RFCs related to TCP 4082 security. Many of the enhancements provided by these RFCs have been 4083 integrated into the present document, including ISN generation, 4084 mitigating blind in-window attacks, and improving handling of soft 4085 errors and ICMP packets. These are all discussed in greater detail 4086 in the referenced RFCs that originally described the changes needed 4087 to earlier TCP specifications. Additionally, see RFC 6093 [28] for 4088 discussion of security considerations related to the urgent pointer 4089 field, that has been deprecated. 4091 Since TCP is often used for bulk transfer flows, some attacks are 4092 possible that abuse the TCP congestion control logic. An example is 4093 "ACK-division" attacks. Updates that have been made to the TCP 4094 congestion control specifications include mechanisms like Appropriate 4095 Byte Counting (ABC) that act as mitigations to these attacks. 4097 Other attacks are focused on exhausting the resources of a TCP 4098 server. Examples include SYN flooding [19] or wasting resources on 4099 non-progressing connections [30]. Operating systems commonly 4100 implement mitigations for these attacks. Some common defenses also 4101 utilize proxies, stateful firewalls, and other technologies outside 4102 of the end-host TCP implementation. 4104 12. Acknowledgements 4106 This document is largely a revision of RFC 793, which Jon Postel was 4107 the editor of. Due to his excellent work, it was able to last for 4108 three decades before we felt the need to revise it. 4110 Andre Oppermann was a contributor and helped to edit the first 4111 revision of this document. 4113 We are thankful for the assistance of the IETF TCPM working group 4114 chairs: 4116 Michael Scharf 4117 Yoshifumi Nishida 4118 Pasi Sarolahti 4120 During early discussion of this work on the TCPM mailing list, and at 4121 the IETF 88 meeting in Vancouver, helpful comments, critiques, and 4122 reviews were received from (listed alphebetically): David Borman, 4123 Yuchung Cheng, Martin Duke, Kevin Lahey, Kevin Mason, Matt Mathis, 4124 Hagen Paul Pfeifer, Anthony Sabatini, Joe Touch, Reji Varghese, Lloyd 4125 Wood, and Alex Zimmermann. Joe Touch provided help in clarifying the 4126 description of segment size parameters and PMTUD/PLPMTUD 4127 recommendations. 4129 This document includes content from errata that were reported by 4130 (listed chronologically): Yin Shuming, Bob Braden, Morris M. Keesan, 4131 Pei-chun Cheng, Constantin Hagemeier, Vishwas Manral, Mykyta 4132 Yevstifeyev, EungJun Yi, Botong Huang. 4134 13. References 4136 13.1. Normative References 4138 [1] Postel, J., "Internet Protocol", STD 5, RFC 791, 4139 DOI 10.17487/RFC0791, September 1981, 4140 . 4142 [2] Mogul, J. and S. Deering, "Path MTU discovery", RFC 1191, 4143 DOI 10.17487/RFC1191, November 1990, 4144 . 4146 [3] McCann, J., Deering, S., and J. Mogul, "Path MTU Discovery 4147 for IP version 6", RFC 1981, DOI 10.17487/RFC1981, August 4148 1996, . 4150 [4] Bradner, S., "Key words for use in RFCs to Indicate 4151 Requirement Levels", BCP 14, RFC 2119, 4152 DOI 10.17487/RFC2119, March 1997, 4153 . 4155 [5] Deering, S. and R. Hinden, "Internet Protocol, Version 6 4156 (IPv6) Specification", RFC 2460, DOI 10.17487/RFC2460, 4157 December 1998, . 4159 [6] Nichols, K., Blake, S., Baker, F., and D. Black, 4160 "Definition of the Differentiated Services Field (DS 4161 Field) in the IPv4 and IPv6 Headers", RFC 2474, 4162 DOI 10.17487/RFC2474, December 1998, 4163 . 4165 [7] Borman, D., Deering, S., and R. Hinden, "IPv6 Jumbograms", 4166 RFC 2675, DOI 10.17487/RFC2675, August 1999, 4167 . 4169 [8] Lahey, K., "TCP Problems with Path MTU Discovery", 4170 RFC 2923, DOI 10.17487/RFC2923, September 2000, 4171 . 4173 [9] Ramakrishnan, K., Floyd, S., and D. Black, "The Addition 4174 of Explicit Congestion Notification (ECN) to IP", 4175 RFC 3168, DOI 10.17487/RFC3168, September 2001, 4176 . 4178 [10] Paxson, V., Allman, M., Chu, J., and M. Sargent, 4179 "Computing TCP's Retransmission Timer", RFC 6298, 4180 DOI 10.17487/RFC6298, June 2011, 4181 . 4183 [11] Gont, F., "Deprecation of ICMP Source Quench Messages", 4184 RFC 6633, DOI 10.17487/RFC6633, May 2012, 4185 . 4187 13.2. Informative References 4189 [12] Postel, J., "Transmission Control Protocol", STD 7, 4190 RFC 793, DOI 10.17487/RFC0793, September 1981, 4191 . 4193 [13] Nagle, J., "Congestion Control in IP/TCP Internetworks", 4194 RFC 896, DOI 10.17487/RFC0896, January 1984, 4195 . 4197 [14] Braden, R., Ed., "Requirements for Internet Hosts - 4198 Communication Layers", STD 3, RFC 1122, 4199 DOI 10.17487/RFC1122, October 1989, 4200 . 4202 [15] Almquist, P., "Type of Service in the Internet Protocol 4203 Suite", RFC 1349, DOI 10.17487/RFC1349, July 1992, 4204 . 4206 [16] Braden, R., "T/TCP -- TCP Extensions for Transactions 4207 Functional Specification", RFC 1644, DOI 10.17487/RFC1644, 4208 July 1994, . 4210 [17] Xiao, X., Hannan, A., Paxson, V., and E. Crabbe, "TCP 4211 Processing of the IPv4 Precedence Field", RFC 2873, 4212 DOI 10.17487/RFC2873, June 2000, 4213 . 4215 [18] Mathis, M. and J. Heffner, "Packetization Layer Path MTU 4216 Discovery", RFC 4821, DOI 10.17487/RFC4821, March 2007, 4217 . 4219 [19] Eddy, W., "TCP SYN Flooding Attacks and Common 4220 Mitigations", RFC 4987, DOI 10.17487/RFC4987, August 2007, 4221 . 4223 [20] Touch, J., "Defending TCP Against Spoofing Attacks", 4224 RFC 4953, DOI 10.17487/RFC4953, July 2007, 4225 . 4227 [21] Culley, P., Elzur, U., Recio, R., Bailey, S., and J. 4228 Carrier, "Marker PDU Aligned Framing for TCP 4229 Specification", RFC 5044, DOI 10.17487/RFC5044, October 4230 2007, . 4232 [22] Gont, F., "TCP's Reaction to Soft Errors", RFC 5461, 4233 DOI 10.17487/RFC5461, February 2009, 4234 . 4236 [23] StJohns, M., Atkinson, R., and G. Thomas, "Common 4237 Architecture Label IPv6 Security Option (CALIPSO)", 4238 RFC 5570, DOI 10.17487/RFC5570, July 2009, 4239 . 4241 [24] Allman, M., Paxson, V., and E. Blanton, "TCP Congestion 4242 Control", RFC 5681, DOI 10.17487/RFC5681, September 2009, 4243 . 4245 [25] Sandlund, K., Pelletier, G., and L-E. Jonsson, "The RObust 4246 Header Compression (ROHC) Framework", RFC 5795, 4247 DOI 10.17487/RFC5795, March 2010, 4248 . 4250 [26] Touch, J., Mankin, A., and R. Bonica, "The TCP 4251 Authentication Option", RFC 5925, DOI 10.17487/RFC5925, 4252 June 2010, . 4254 [27] Ramaiah, A., Stewart, R., and M. Dalal, "Improving TCP's 4255 Robustness to Blind In-Window Attacks", RFC 5961, 4256 DOI 10.17487/RFC5961, August 2010, 4257 . 4259 [28] Gont, F. and A. Yourtchenko, "On the Implementation of the 4260 TCP Urgent Mechanism", RFC 6093, DOI 10.17487/RFC6093, 4261 January 2011, . 4263 [29] Gont, F., "Reducing the TIME-WAIT State Using TCP 4264 Timestamps", BCP 159, RFC 6191, DOI 10.17487/RFC6191, 4265 April 2011, . 4267 [30] Bashyam, M., Jethanandani, M., and A. Ramaiah, "TCP Sender 4268 Clarification for Persist Condition", RFC 6429, 4269 DOI 10.17487/RFC6429, December 2011, 4270 . 4272 [31] Gont, F. and S. Bellovin, "Defending against Sequence 4273 Number Attacks", RFC 6528, DOI 10.17487/RFC6528, February 4274 2012, . 4276 [32] Borman, D., "TCP Options and Maximum Segment Size (MSS)", 4277 RFC 6691, DOI 10.17487/RFC6691, July 2012, 4278 . 4280 [33] Touch, J., "Shared Use of Experimental TCP Options", 4281 RFC 6994, DOI 10.17487/RFC6994, August 2013, 4282 . 4284 [34] Borman, D., Braden, B., Jacobson, V., and R. 4285 Scheffenegger, Ed., "TCP Extensions for High Performance", 4286 RFC 7323, DOI 10.17487/RFC7323, September 2014, 4287 . 4289 [35] Cheng, Y., Chu, J., Radhakrishnan, S., and A. Jain, "TCP 4290 Fast Open", RFC 7413, DOI 10.17487/RFC7413, December 2014, 4291 . 4293 [36] Duke, M., Braden, R., Eddy, W., Blanton, E., and A. 4294 Zimmermann, "A Roadmap for Transmission Control Protocol 4295 (TCP) Specification Documents", RFC 7414, 4296 DOI 10.17487/RFC7414, February 2015, 4297 . 4299 [37] Black, D., Ed. and P. Jones, "Differentiated Services 4300 (Diffserv) and Real-Time Communication", RFC 7657, 4301 DOI 10.17487/RFC7657, November 2015, 4302 . 4304 [38] Fairhurst, G. and M. Welzl, "The Benefits of Using 4305 Explicit Congestion Notification (ECN)", RFC 8087, 4306 DOI 10.17487/RFC8087, March 2017, 4307 . 4309 [39] Fairhurst, G., Ed., Trammell, B., Ed., and M. Kuehlewind, 4310 Ed., "Services Provided by IETF Transport Protocols and 4311 Congestion Control Mechanisms", RFC 8095, 4312 DOI 10.17487/RFC8095, March 2017, 4313 . 4315 [40] IANA, "Transmission Control Protocol (TCP) Parameters, 4316 https://www.iana.org/assignments/tcp-parameters/ 4317 tcp-parameters.xhtml", 2017. 4319 [41] Gont, F., "Processing of IP Security/Compartment and 4320 Precedence Information by TCP", draft-gont-tcpm-tcp- 4321 seccomp-prec-00 (work in progress), March 2012. 4323 [42] Gont, F. and D. Borman, "On the Validation of TCP Sequence 4324 Numbers", draft-gont-tcpm-tcp-seq-validation-02 (work in 4325 progress), March 2015. 4327 [43] Bittau, A., Giffin, D., Handley, M., Mazieres, D., Slack, 4328 Q., and E. Smith, "Cryptographic protection of TCP Streams 4329 (tcpcrypt)", draft-ietf-tcpinc-tcpcrypt-09 (work in 4330 progress), November 2017. 4332 [44] Minshall, G., "A Proposed Modification to Nagle's 4333 Algorithm", draft-minshall-nagle-01 (work in progress), 4334 June 1999. 4336 Appendix A. Other Implementation Notes 4338 This section includes additional notes and references on TCP 4339 implementation decisions that are currently not a part of the RFC 4340 series or included within the TCP standard. These items can be 4341 considered by implementers, but there was not yet a consensus to 4342 include them in the standard. 4344 A.1. IP Security Compartment and Precedence 4346 RFC 793 requires checking the IP security compartment and precedence 4347 on incoming TCP segments for consistency within a connection, and 4348 with application requests. Each of these aspects of IP have become 4349 outdated, without specific updates to RFC 793. The issues with 4350 precedence were fixed by [17] which is Standards Track, and so this 4351 present TCP specification includes those changes. However, the state 4352 of IP security options that may be used by MLS systems is not as 4353 clean. 4355 Implementers of MLS systems that use IP security options (e.g. IPSO, 4356 CIPSO, or CALIPSO) should implement any additional logic appropriate 4357 for their requirements. 4359 Reseting connections when incoming packets do not meet expected 4360 security compartment or precedence expectations has been recognized 4361 as a possible attack vector [41], and there has been discussion about 4362 ammending the TCP specification to prevent connections from being 4363 aborted due to non-matching IP security compartment and DiffServ 4364 codepoint values. 4366 A.2. Sequence Number Validation 4368 There are cases where the TCP sequence number validation rules can 4369 prevent ACK fields from being processed. This can result in 4370 connection issues, as described in [42], which includes descriptions 4371 of potential problems in conditions of simultaneous open, self- 4372 connects, simultaneous close, and simultaneous window probes. The 4373 document also describes potential changes to the TCP specification to 4374 mitigate the issue by expanding the acceptable sequence numbers. 4376 In Internet usage of TCP, these conditions are rarely occuring. 4377 Common operating systems include different alternative mitigations, 4378 and the standard has not been updated yet to codify one of them, but 4379 implementers should consider the problems described in [42]. 4381 A.3. Nagle Modification 4383 In common operating systems, both the Nagle algorithm and delayed 4384 acknowledgements are implemented and enabled by default. TCP is used 4385 by many applications that have a request-response style of 4386 communication, where the combination of the Nagle algorithm and 4387 delayed acknowledgements can result in poor application performance. 4388 A modification to the Nagle algorithm is described in [44] that 4389 improves the situation for these applications. 4391 This modification is implemented in some common operating systems, 4392 and does not impact TCP interoperability. Additionally, many 4393 applications simply disable Nagle, since this is generally supported 4394 by a socket option. The TCP standard has not been updated to include 4395 this Nagle modification, but implementers may find it beneficial to 4396 consider. 4398 A.4. Low Water Mark 4400 TODO - mention the low watermark function that is in Linux - 4401 suggested by Michael Welzl 4403 SO_SNDLOWAT and SO_RCVLOWAT would be potential enhancements to the 4404 abstract TCP API 4406 TCP_NOTSENT_LOWAT is what Michael is talking about, that helps a 4407 sending TCP application to help avoid creating large amounts of 4408 buffered data (and corresponding latency). This is useful for 4409 applications that are multiplexing data from multiple upper level 4410 streams onto a connection, especially when streams may be a mix of 4411 interactive/realtime and bulk data transfer. 4413 Appendix B. TCP Requirement Summary 4415 This section is adapted from RFC 1122. 4417 TODO: this needs to be seriously redone, to use 793bis section 4418 numbers instead of 1122 ones, the RFC1122 heading should be removed, 4419 and all 1122 requirements need to be reflected in 793bis text. 4421 TODO: NOTE that PMTUD+PLPMTUD is not included in this table of 4422 recommendations. 4424 | | | | |S| | 4425 | | | | |H| |F 4426 | | | | |O|M|o 4427 | | |S| |U|U|o 4428 | | |H| |L|S|t 4429 | |M|O| |D|T|n 4430 | |U|U|M| | |o 4431 | |S|L|A|N|N|t 4432 |RFC1122 |T|D|Y|O|O|t 4433 FEATURE |SECTION | | | |T|T|e 4434 -------------------------------------------------|--------|-|-|-|-|-|-- 4435 | | | | | | | 4436 Push flag | | | | | | | 4437 Aggregate or queue un-pushed data |4.2.2.2 | | |x| | | 4438 Sender collapse successive PSH flags |4.2.2.2 | |x| | | | 4439 SEND call can specify PUSH |4.2.2.2 | | |x| | | 4440 If cannot: sender buffer indefinitely |4.2.2.2 | | | | |x| 4441 If cannot: PSH last segment |4.2.2.2 |x| | | | | 4442 Notify receiving ALP of PSH |4.2.2.2 | | |x| | |1 4443 Send max size segment when possible |4.2.2.2 | |x| | | | 4444 | | | | | | | 4445 Window | | | | | | | 4446 Treat as unsigned number |4.2.2.3 |x| | | | | 4447 Handle as 32-bit number |4.2.2.3 | |x| | | | 4448 Shrink window from right |4.2.2.16| | | |x| | 4449 Robust against shrinking window |4.2.2.16|x| | | | | 4450 Receiver's window closed indefinitely |4.2.2.17| | |x| | | 4451 Sender probe zero window |4.2.2.17|x| | | | | 4452 First probe after RTO |4.2.2.17| |x| | | | 4453 Exponential backoff |4.2.2.17| |x| | | | 4454 Allow window stay zero indefinitely |4.2.2.17|x| | | | | 4455 Sender timeout OK conn with zero wind |4.2.2.17| | | | |x| 4456 | | | | | | | 4457 Urgent Data | | | | | | | 4458 Pointer indicates first non-urgent octet |4.2.2.4 |x| | | | | 4459 Arbitrary length urgent data sequence |4.2.2.4 |x| | | | | 4460 Inform ALP asynchronously of urgent data |4.2.2.4 |x| | | | |1 4461 ALP can learn if/how much urgent data Q'd |4.2.2.4 |x| | | | |1 4462 | | | | | | | 4463 TCP Options | | | | | | | 4464 Receive TCP option in any segment |4.2.2.5 |x| | | | | 4465 Ignore unsupported options |4.2.2.5 |x| | | | | 4466 Cope with illegal option length |4.2.2.5 |x| | | | | 4467 Implement sending & receiving MSS option |4.2.2.6 |x| | | | | 4468 IPv4 Send MSS option unless 536 |4.2.2.6 | |x| | | | 4469 IPv6 Send MSS option unless 1220 | N/A | |x| | | | 4470 Send MSS option always |4.2.2.6 | | |x| | | 4471 IPv4 Send-MSS default is 536 |4.2.2.6 |x| | | | | 4472 IPv6 Send-MSS default is 1220 | N/A |x| | | | | 4473 Calculate effective send seg size |4.2.2.6 |x| | | | | 4474 MSS accounts for varying MTU | N/A | |x| | | | 4475 | | | | | | | 4477 TCP Checksums | | | | | | | 4478 Sender compute checksum |4.2.2.7 |x| | | | | 4479 Receiver check checksum |4.2.2.7 |x| | | | | 4480 | | | | | | | 4481 ISN Selection | | | | | | | 4482 Include a clock-driven ISN generator component |4.2.2.9 |x| | | | | 4483 Secure ISN generator with a PRF component | N/A | |x| | | | 4484 | | | | | | | 4485 Opening Connections | | | | | | | 4486 Support simultaneous open attempts |4.2.2.10|x| | | | | 4487 SYN-RECEIVED remembers last state |4.2.2.11|x| | | | | 4488 Passive Open call interfere with others |4.2.2.18| | | | |x| 4489 Function: simultan. LISTENs for same port |4.2.2.18|x| | | | | 4490 Ask IP for src address for SYN if necc. |4.2.3.7 |x| | | | | 4491 Otherwise, use local addr of conn. |4.2.3.7 |x| | | | | 4492 OPEN to broadcast/multicast IP Address |4.2.3.14| | | | |x| 4493 Silently discard seg to bcast/mcast addr |4.2.3.14|x| | | | | 4494 | | | | | | | 4495 Closing Connections | | | | | | | 4496 RST can contain data |4.2.2.12| |x| | | | 4497 Inform application of aborted conn |4.2.2.13|x| | | | | 4498 Half-duplex close connections |4.2.2.13| | |x| | | 4499 Send RST to indicate data lost |4.2.2.13| |x| | | | 4500 In TIME-WAIT state for 2MSL seconds |4.2.2.13|x| | | | | 4501 Accept SYN from TIME-WAIT state |4.2.2.13| | |x| | | 4502 Use Timestamps to reduce TIME-WAIT | TODO | | | | | | 4503 | | | | | | | 4504 Retransmissions | | | | | | | 4505 Jacobson Slow Start algorithm |4.2.2.15|x| | | | | 4506 Jacobson Congestion-Avoidance algorithm |4.2.2.15|x| | | | | 4507 Retransmit with same IP ident |4.2.2.15| | |x| | | 4508 Karn's algorithm |4.2.3.1 |x| | | | | 4509 Jacobson's RTO estimation alg. |4.2.3.1 |x| | | | | 4510 Exponential backoff |4.2.3.1 |x| | | | | 4511 SYN RTO calc same as data |4.2.3.1 | |x| | | | 4512 Recommended initial values and bounds |4.2.3.1 | |x| | | | 4513 | | | | | | | 4514 Generating ACK's: | | | | | | | 4515 Queue out-of-order segments |4.2.2.20| |x| | | | 4516 Process all Q'd before send ACK |4.2.2.20|x| | | | | 4517 Send ACK for out-of-order segment |4.2.2.21| | |x| | | 4518 Delayed ACK's |4.2.3.2 | |x| | | | 4519 Delay < 0.5 seconds |4.2.3.2 |x| | | | | 4520 Every 2nd full-sized segment ACK'd |4.2.3.2 |x| | | | | 4521 Receiver SWS-Avoidance Algorithm |4.2.3.3 |x| | | | | 4522 | | | | | | | 4523 Sending data | | | | | | | 4524 Configurable TTL |4.2.2.19|x| | | | | 4525 Sender SWS-Avoidance Algorithm |4.2.3.4 |x| | | | | 4526 Nagle algorithm |4.2.3.4 | |x| | | | 4527 Application can disable Nagle algorithm |4.2.3.4 |x| | | | | 4528 | | | | | | | 4529 Connection Failures: | | | | | | | 4530 Negative advice to IP on R1 retxs |4.2.3.5 |x| | | | | 4531 Close connection on R2 retxs |4.2.3.5 |x| | | | | 4532 ALP can set R2 |4.2.3.5 |x| | | | |1 4533 Inform ALP of R1<=retxs inform ALP |4.2.3.9 | |x| | | | 4558 Dest. Unreach (0,1,5) => abort conn |4.2.3.9 | | | | |x| 4559 Dest. Unreach (2-4) => abort conn |4.2.3.9 | |x| | | | 4560 Source Quench => silent discard |4.2.3.9 | |x| | | | 4561 Time Exceeded => tell ALP, don't abort |4.2.3.9 | |x| | | | 4562 Param Problem => tell ALP, don't abort |4.2.3.9 | |x| | | | 4563 | | | | | | | 4564 Address Validation | | | | | | | 4565 Reject OPEN call to invalid IP address |4.2.3.10|x| | | | | 4566 Reject SYN from invalid IP address |4.2.3.10|x| | | | | 4567 Silently discard SYN to bcast/mcast addr |4.2.3.10|x| | | | | 4568 | | | | | | | 4569 TCP/ALP Interface Services | | | | | | | 4570 Error Report mechanism |4.2.4.1 |x| | | | | 4571 ALP can disable Error Report Routine |4.2.4.1 | |x| | | | 4572 ALP can specify DiffServ field for sending |4.2.4.2 |x| | | | | 4573 Passed unchanged to IP |4.2.4.2 | |x| | | | 4574 ALP can change DiffServ field during connection|4.2.4.2 | |x| | | | 4575 Pass received DiffServ field up to ALP |4.2.4.2 | | |x| | | 4576 FLUSH call |4.2.4.3 | | |x| | | 4577 Optional local IP addr parm. in OPEN |4.2.4.4 |x| | | | | 4578 -------------------------------------------------|--------|-|-|-|-|-|-- 4580 FOOTNOTES: (1) "ALP" means Application-Layer program. 4582 Author's Address 4584 Wesley M. Eddy (editor) 4585 MTI Systems 4586 US 4588 Email: wes@mti-systems.com