idnits 2.17.1 draft-ietf-tcpm-rfc793bis-13.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 (June 3, 2019) is 1789 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: '44' is defined on line 4411, 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. '18') (Obsoleted by RFC 9293) -- Obsolete informational reference (is this intentional?): RFC 6093 (ref. '29') (Obsoleted by RFC 9293) -- Obsolete informational reference (is this intentional?): RFC 6429 (ref. '31') (Obsoleted by RFC 9293) -- Obsolete informational reference (is this intentional?): RFC 6528 (ref. '32') (Obsoleted by RFC 9293) -- Obsolete informational reference (is this intentional?): RFC 6691 (ref. '33') (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, June 3, 2019 5 6528, 6691 (if approved) 6 Updates: 5961, 1122 (if approved) 7 Intended status: Standards Track 8 Expires: December 5, 2019 10 Transmission Control Protocol Specification 11 draft-ietf-tcpm-rfc793bis-13 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 December 5, 2019. 55 Copyright Notice 57 Copyright (c) 2019 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 . . . . . . . . . . . . . . . . . . 5 88 3.1. Header Format . . . . . . . . . . . . . . . . . . . . . . 6 89 3.2. Terminology . . . . . . . . . . . . . . . . . . . . . . . 11 90 3.3. Sequence Numbers . . . . . . . . . . . . . . . . . . . . 15 91 3.4. Establishing a connection . . . . . . . . . . . . . . . . 22 92 3.5. Closing a Connection . . . . . . . . . . . . . . . . . . 29 93 3.5.1. Half-Closed Connections . . . . . . . . . . . . . . . 31 94 3.6. Precedence and Security . . . . . . . . . . . . . . . . . 32 95 3.7. Segmentation . . . . . . . . . . . . . . . . . . . . . . 33 96 3.7.1. Maximum Segment Size Option . . . . . . . . . . . . . 34 97 3.7.2. Path MTU Discovery . . . . . . . . . . . . . . . . . 36 98 3.7.3. Interfaces with Variable MTU Values . . . . . . . . . 36 99 3.7.4. Nagle Algorithm . . . . . . . . . . . . . . . . . . . 37 100 3.7.5. IPv6 Jumbograms . . . . . . . . . . . . . . . . . . . 37 101 3.8. Data Communication . . . . . . . . . . . . . . . . . . . 37 102 3.8.1. Retransmission Timeout . . . . . . . . . . . . . . . 38 103 3.8.2. TCP Congestion Control . . . . . . . . . . . . . . . 38 104 3.8.3. TCP Connection Failures . . . . . . . . . . . . . . . 39 105 3.8.4. TCP Keep-Alives . . . . . . . . . . . . . . . . . . . 40 106 3.8.5. The Communication of Urgent Information . . . . . . . 40 107 3.8.6. Managing the Window . . . . . . . . . . . . . . . . . 41 108 3.9. Interfaces . . . . . . . . . . . . . . . . . . . . . . . 46 109 3.9.1. User/TCP Interface . . . . . . . . . . . . . . . . . 46 110 3.9.2. TCP/Lower-Level Interface . . . . . . . . . . . . . . 55 111 3.10. Event Processing . . . . . . . . . . . . . . . . . . . . 57 112 3.11. Glossary . . . . . . . . . . . . . . . . . . . . . . . . 82 113 4. Changes from RFC 793 . . . . . . . . . . . . . . . . . . . . 87 114 5. IANA Considerations . . . . . . . . . . . . . . . . . . . . . 92 115 6. Security and Privacy Considerations . . . . . . . . . . . . . 92 116 7. Acknowledgements . . . . . . . . . . . . . . . . . . . . . . 93 117 8. References . . . . . . . . . . . . . . . . . . . . . . . . . 94 118 8.1. Normative References . . . . . . . . . . . . . . . . . . 94 119 8.2. Informative References . . . . . . . . . . . . . . . . . 95 120 Appendix A. Other Implementation Notes . . . . . . . . . . . . . 98 121 A.1. IP Security Compartment and Precedence . . . . . . . . . 99 122 A.2. Sequence Number Validation . . . . . . . . . . . . . . . 99 123 A.3. Nagle Modification . . . . . . . . . . . . . . . . . . . 99 124 A.4. Low Water Mark . . . . . . . . . . . . . . . . . . . . . 100 125 Appendix B. TCP Requirement Summary . . . . . . . . . . . . . . 100 126 Author's Address . . . . . . . . . . . . . . . . . . . . . . . . 104 128 1. Purpose and Scope 130 In 1981, RFC 793 [12] was released, documenting the Transmission 131 Control Protocol (TCP), and replacing earlier specifications for TCP 132 that had been published in the past. 134 Since then, TCP has been implemented many times, and has been used as 135 a transport protocol for numerous applications on the Internet. 137 For several decades, RFC 793 plus a number of other documents have 138 combined to serve as the specification for TCP [37]. Over time, a 139 number of errata have been identified on RFC 793, as well as 140 deficiencies in security, performance, and other aspects. A number 141 of enhancements has grown and been documented separately. These were 142 never accumulated together into an update to the base specification. 144 The purpose of this document is to bring together all of the IETF 145 Standards Track changes that have been made to the basic TCP 146 functional specification and unify them into an update of the RFC 793 147 protocol specification. Some companion documents are referenced for 148 important algorithms that TCP uses (e.g. for congestion control), but 149 have not been attempted to include in this document. This is a 150 conscious choice, as this base specification can be used with 151 multiple additional algorithms that are developed and incorporated 152 separately, but all TCP implementations need to implement this 153 specification as a common basis in order to interoperate. As some 154 additional TCP features have become quite complicated themselves 155 (e.g. advanced loss recovery and congestion control), future 156 companion documents may attempt to similarly bring these together. 158 In addition to the protocol specification that descibes the TCP 159 segment format, generation, and processing rules that are to be 160 implemented in code, RFC 793 and other updates also contain 161 informative and descriptive text for human readers to understand 162 aspects of the protocol design and operation. This document does not 163 attempt to alter or update this informative text, and is focused only 164 on updating the normative protocol specification. We preserve 165 references to the documentation containing the important explanations 166 and rationale, where appropriate. 168 This document is intended to be useful both in checking existing TCP 169 implementations for conformance, as well as in writing new 170 implementations. 172 2. Introduction 174 RFC 793 contains a discussion of the TCP design goals and provides 175 examples of its operation, including examples of connection 176 establishment, closing connections, and retransmitting packets to 177 repair losses. 179 This document describes the basic functionality expected in modern 180 implementations of TCP, and replaces the protocol specification in 181 RFC 793. It does not replicate or attempt to update the introduction 182 and philosophy content in RFC 793 (sections 1 and 2 of that 183 document). Other documents are referenced to provide explanation of 184 the theory of operation, rationale, and detailed discussion of design 185 decisions. This document only focuses on the normative behavior of 186 the protocol. 188 The "TCP Roadmap" [37] provides a more extensive guide to the RFCs 189 that define TCP and describe various important algorithms. The TCP 190 Roadmap contains sections on strongly encouraged enhancements that 191 improve performance and other aspects of TCP beyond the basic 192 operation specified in this document. As one example, implementing 193 congestion control (e.g. [25]) is a TCP requirement, but is a complex 194 topic on its own, and not described in detail in this document, as 195 there are many options and possibilities that do not impact basic 196 interoperability. Similarly, most common TCP implementations today 197 include the high-performance extensions in [35], but these are not 198 strictly required or discussed in this document. 200 A list of changes from RFC 793 is contained in Section 4. 202 2.1. Key TCP Concepts 204 TCP provides a reliable, in-order, byte-stream service to 205 applications. 207 The application byte-stream is conveyed over the network via TCP 208 segments, with each TCP segment sent as an Internet Protocol (IP) 209 datagram. 211 TCP reliability consists of detecting packet losses (via sequence 212 numbers) and errors (via per-segment checksums), as well as 213 correction of losses and errors via retransmission. 215 TCP supports unicast delivery of data. Anycast applications exist 216 that successfully use TCP without modifications, though there is some 217 risk of instability due to rerouting. 219 TCP is connection-oriented, though does not inherently include a 220 liveness detection capability. 222 Data flow is supported bidirectionally over TCP connections, though 223 applications are free to flow data only unidirectionally, if they so 224 choose. 226 TCP uses port numbers to identify application services and to 227 multiplex multiple flows between hosts. 229 A more detailed description of TCP's features compared to other 230 transport protocols can be found in Section 3.1 of [40]. Further 231 description of the motivations for developing TCP and its role in the 232 Internet stack can be found in Section 2 of [12] and earlier versions 233 of the TCP specification. 235 3. Functional Specification 236 3.1. Header Format 238 TCP segments are sent as internet datagrams. The Internet Protocol 239 (IP) header carries several information fields, including the source 240 and destination host addresses [1] [5]. A TCP header follows the 241 Internet header, supplying information specific to the TCP protocol. 242 This division allows for the existence of host level protocols other 243 than TCP. In early development of the Internet suite of protocols, 244 the IP header fields had been a part of TCP. 246 TCP Header Format 248 0 1 2 3 249 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 250 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 251 | Source Port | Destination Port | 252 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 253 | Sequence Number | 254 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 255 | Acknowledgment Number | 256 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 257 | Data | |C|E|U|A|P|R|S|F| | 258 | Offset| Rsrvd |W|C|R|C|S|S|Y|I| Window | 259 | | |R|E|G|K|H|T|N|N| | 260 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 261 | Checksum | Urgent Pointer | 262 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 263 | Options | Padding | 264 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 265 | data | 266 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 268 TCP Header Format 270 Note that one tick mark represents one bit position. 272 Figure 1 274 Source Port: 16 bits 276 The source port number. 278 Destination Port: 16 bits 280 The destination port number. 282 Sequence Number: 32 bits 283 The sequence number of the first data octet in this segment (except 284 when SYN is present). If SYN is present the sequence number is the 285 initial sequence number (ISN) and the first data octet is ISN+1. 287 Acknowledgment Number: 32 bits 289 If the ACK control bit is set this field contains the value of the 290 next sequence number the sender of the segment is expecting to 291 receive. Once a connection is established this is always sent. 293 Data Offset: 4 bits 295 The number of 32 bit words in the TCP Header. This indicates where 296 the data begins. The TCP header (even one including options) is an 297 integral number of 32 bits long. 299 Rsrvd - Reserved: 4 bits 301 Reserved for future use. Must be zero in generated segments and 302 must be ignored in received segments, if corresponding future 303 features are unimplemented by the sending or receiving host. 305 Control Bits: 8 bits (from left to right): 307 CWR: Congestion Window Reduced (see [9]) 308 ECE: ECN-Echo (see [9]) 309 URG: Urgent Pointer field significant 310 ACK: Acknowledgment field significant 311 PSH: Push Function (see Paragraph 5) 312 RST: Reset the connection 313 SYN: Synchronize sequence numbers 314 FIN: No more data from sender 316 Window: 16 bits 318 The number of data octets beginning with the one indicated in the 319 acknowledgment field which the sender of this segment is willing to 320 accept. 322 The window size MUST be treated as an unsigned number, or else 323 large window sizes will appear like negative windows and TCP will 324 now work (MUST-1). It is RECOMMENDED that implementations will 325 reserve 32-bit fields for the send and receive window sizes in the 326 connection record and do all window computations with 32 bits (REC- 327 1). 329 Checksum: 16 bits 330 The checksum field is the 16 bit one's complement of the one's 331 complement sum of all 16 bit words in the header and text. If a 332 segment contains an odd number of header and text octets to be 333 checksummed, the last octet is padded on the right with zeros to 334 form a 16 bit word for checksum purposes. The pad is not 335 transmitted as part of the segment. While computing the checksum, 336 the checksum field itself is replaced with zeros. 338 The checksum also covers a pseudo header conceptually prefixed to 339 the TCP header. The pseudo header is 96 bits for IPv4 and 320 bits 340 for IPv6. For IPv4, this pseudo header contains the Source 341 Address, the Destination Address, the Protocol, and TCP length. 342 This gives the TCP protection against misrouted segments. This 343 information is carried in IPv4 and is transferred across the TCP/ 344 Network interface in the arguments or results of calls by the TCP 345 on the IP. 347 +--------+--------+--------+--------+ 348 | Source Address | 349 +--------+--------+--------+--------+ 350 | Destination Address | 351 +--------+--------+--------+--------+ 352 | zero | PTCL | TCP Length | 353 +--------+--------+--------+--------+ 355 The TCP Length is the TCP header length plus the data length in 356 octets (this is not an explicitly transmitted quantity, but is 357 computed), and it does not count the 12 octets of the pseudo 358 header. 360 For IPv6, the pseudo header is contained in section 8.1 of RFC 2460 361 [5], and contains the IPv6 Source Address and Destination Address, 362 an Upper Layer Packet Length (a 32-bit value otherwise equivalent 363 to TCP Length in the IPv4 pseudo header), three bytes of zero- 364 padding, and a Next Header value (differing from the IPv6 header 365 value in the case of extension headers present in between IPv6 and 366 TCP). 368 The TCP checksum is never optional. The sender MUST generate it 369 (MUST-2) and the receiver MUST check it (MUST-3). 371 Urgent Pointer: 16 bits 373 This field communicates the current value of the urgent pointer as 374 a positive offset from the sequence number in this segment. The 375 urgent pointer points to the sequence number of the octet following 376 the urgent data. This field is only be interpreted in segments 377 with the URG control bit set. 379 Options: variable 381 Options may occupy space at the end of the TCP header and are a 382 multiple of 8 bits in length. All options are included in the 383 checksum. An option may begin on any octet boundary. There are 384 two cases for the format of an option: 386 Case 1: A single octet of option-kind. 388 Case 2: An octet of option-kind, an octet of option-length, and 389 the actual option-data octets. 391 The option-length counts the two octets of option-kind and option- 392 length as well as the option-data octets. 394 Note that the list of options may be shorter than the data offset 395 field might imply. The content of the header beyond the End-of- 396 Option option must be header padding (i.e., zero). 398 The list of all currently defined options is managed by IANA [41], 399 and each option is defined in other RFCs, as indicated there. That 400 set includes experimental options that can be extended to support 401 multiple concurrent uses [34]. 403 A given TCP implementation can support any currently defined 404 options, but the following options MUST be supported (MUST-4) (kind 405 indicated in octal): 407 Kind Length Meaning 408 ---- ------ ------- 409 0 - End of option list. 410 1 - No-Operation. 411 2 4 Maximum Segment Size. 413 A TCP MUST be able to receive a TCP option in any segment (MUST-5). 414 A TCP MUST (MUST-6) ignore without error any TCP option it does not 415 implement, assuming that the option has a length field (all TCP 416 options except End of option list and No-Operation have length 417 fields). TCP MUST be prepared to handle an illegal option length 418 (e.g., zero) without crashing; a suggested procedure is to reset 419 the connection and log the reason (MUST-7). 421 Specific Option Definitions 422 End of Option List 424 +--------+ 425 |00000000| 426 +--------+ 427 Kind=0 429 This option code indicates the end of the option list. This 430 might not coincide with the end of the TCP header according to 431 the Data Offset field. This is used at the end of all options, 432 not the end of each option, and need only be used if the end of 433 the options would not otherwise coincide with the end of the TCP 434 header. 436 No-Operation 438 +--------+ 439 |00000001| 440 +--------+ 441 Kind=1 443 This option code may be used between options, for example, to 444 align the beginning of a subsequent option on a word boundary. 445 There is no guarantee that senders will use this option, so 446 receivers must be prepared to process options even if they do 447 not begin on a word boundary. 449 Maximum Segment Size (MSS) 451 +--------+--------+---------+--------+ 452 |00000010|00000100| max seg size | 453 +--------+--------+---------+--------+ 454 Kind=2 Length=4 456 Maximum Segment Size Option Data: 16 bits 458 If this option is present, then it communicates the maximum 459 receive segment size at the TCP which sends this segment. This 460 value is limited by the IP reassembly limit. This field may be 461 sent in the initial connection request (i.e., in segments with 462 the SYN control bit set) and must not be sent in other segments. 463 If this option is not used, any segment size is allowed. A more 464 complete description of this option is in Section 3.7.1. 466 Padding: variable 467 The TCP header padding is used to ensure that the TCP header ends 468 and data begins on a 32 bit boundary. The padding is composed of 469 zeros. 471 3.2. Terminology 473 Before we can discuss very much about the operation of the TCP we 474 need to introduce some detailed terminology. The maintenance of a 475 TCP connection requires the remembering of several variables. We 476 conceive of these variables being stored in a connection record 477 called a Transmission Control Block or TCB. Among the variables 478 stored in the TCB are the local and remote socket numbers, the IP 479 security level and compartment of the connection, pointers to the 480 user's send and receive buffers, pointers to the retransmit queue and 481 to the current segment. In addition several variables relating to 482 the send and receive sequence numbers are stored in the TCB. 484 Send Sequence Variables 486 SND.UNA - send unacknowledged 487 SND.NXT - send next 488 SND.WND - send window 489 SND.UP - send urgent pointer 490 SND.WL1 - segment sequence number used for last window update 491 SND.WL2 - segment acknowledgment number used for last window 492 update 493 ISS - initial send sequence number 495 Receive Sequence Variables 497 RCV.NXT - receive next 498 RCV.WND - receive window 499 RCV.UP - receive urgent pointer 500 IRS - initial receive sequence number 502 The following diagrams may help to relate some of these variables to 503 the sequence space. 505 Send Sequence Space 507 1 2 3 4 508 ----------|----------|----------|---------- 509 SND.UNA SND.NXT SND.UNA 510 +SND.WND 512 1 - old sequence numbers which have been acknowledged 513 2 - sequence numbers of unacknowledged data 514 3 - sequence numbers allowed for new data transmission 515 4 - future sequence numbers which are not yet allowed 517 Send Sequence Space 519 Figure 2 521 The send window is the portion of the sequence space labeled 3 in 522 Figure 2. 524 Receive Sequence Space 526 1 2 3 527 ----------|----------|---------- 528 RCV.NXT RCV.NXT 529 +RCV.WND 531 1 - old sequence numbers which have been acknowledged 532 2 - sequence numbers allowed for new reception 533 3 - future sequence numbers which are not yet allowed 535 Receive Sequence Space 537 Figure 3 539 The receive window is the portion of the sequence space labeled 2 in 540 Figure 3. 542 There are also some variables used frequently in the discussion that 543 take their values from the fields of the current segment. 545 Current Segment Variables 547 SEG.SEQ - segment sequence number 548 SEG.ACK - segment acknowledgment number 549 SEG.LEN - segment length 550 SEG.WND - segment window 551 SEG.UP - segment urgent pointer 553 A connection progresses through a series of states during its 554 lifetime. The states are: LISTEN, SYN-SENT, SYN-RECEIVED, 555 ESTABLISHED, FIN-WAIT-1, FIN-WAIT-2, CLOSE-WAIT, CLOSING, LAST-ACK, 556 TIME-WAIT, and the fictional state CLOSED. CLOSED is fictional 557 because it represents the state when there is no TCB, and therefore, 558 no connection. Briefly the meanings of the states are: 560 LISTEN - represents waiting for a connection request from any 561 remote TCP and port. 563 SYN-SENT - represents waiting for a matching connection request 564 after having sent a connection request. 566 SYN-RECEIVED - represents waiting for a confirming connection 567 request acknowledgment after having both received and sent a 568 connection request. 570 ESTABLISHED - represents an open connection, data received can be 571 delivered to the user. The normal state for the data transfer 572 phase of the connection. 574 FIN-WAIT-1 - represents waiting for a connection termination 575 request from the remote TCP, or an acknowledgment of the 576 connection termination request previously sent. 578 FIN-WAIT-2 - represents waiting for a connection termination 579 request from the remote TCP. 581 CLOSE-WAIT - represents waiting for a connection termination 582 request from the local user. 584 CLOSING - represents waiting for a connection termination request 585 acknowledgment from the remote TCP. 587 LAST-ACK - represents waiting for an acknowledgment of the 588 connection termination request previously sent to the remote TCP 589 (this termination request sent to the remote TCP already included 590 an acknowledgment of the termination request sent from the remote 591 TCP). 593 TIME-WAIT - represents waiting for enough time to pass to be sure 594 the remote TCP received the acknowledgment of its connection 595 termination request. 597 CLOSED - represents no connection state at all. 599 A TCP connection progresses from one state to another in response to 600 events. The events are the user calls, OPEN, SEND, RECEIVE, CLOSE, 601 ABORT, and STATUS; the incoming segments, particularly those 602 containing the SYN, ACK, RST and FIN flags; and timeouts. 604 The state diagram in Figure 4 illustrates only state changes, 605 together with the causing events and resulting actions, but addresses 606 neither error conditions nor actions which are not connected with 607 state changes. In a later section, more detail is offered with 608 respect to the reaction of the TCP to events. Some state names are 609 abbreviated or hyphenated differently in the diagram from how they 610 appear elsewhere in the document. 612 NOTA BENE: This diagram is only a summary and must not be taken as 613 the total specification. Many details are not included. 615 +---------+ ---------\ active OPEN 616 | CLOSED | \ ----------- 617 +---------+<---------\ \ create TCB 618 | ^ \ \ snd SYN 619 passive OPEN | | CLOSE \ \ 620 ------------ | | ---------- \ \ 621 create TCB | | delete TCB \ \ 622 V | \ \ 623 rcv RST (note 1) +---------+ CLOSE | \ 624 -------------------->| LISTEN | ---------- | | 625 / +---------+ delete TCB | | 626 / rcv SYN | | SEND | | 627 / ----------- | | ------- | V 628 +--------+ snd SYN,ACK / \ snd SYN +--------+ 629 | |<----------------- ------------------>| | 630 | SYN | rcv SYN | SYN | 631 | RCVD |<-----------------------------------------------| SENT | 632 | | snd SYN,ACK | | 633 | |------------------ -------------------| | 634 +--------+ rcv ACK of SYN \ / rcv SYN,ACK +--------+ 635 | -------------- | | ----------- 636 | x | | snd ACK 637 | V V 638 | CLOSE +---------+ 639 | ------- | ESTAB | 640 | snd FIN +---------+ 641 | CLOSE | | rcv FIN 642 V ------- | | ------- 643 +---------+ snd FIN / \ snd ACK +---------+ 644 | FIN |<----------------- ------------------>| CLOSE | 645 | WAIT-1 |------------------ | WAIT | 646 +---------+ rcv FIN \ +---------+ 647 | rcv ACK of FIN ------- | CLOSE | 648 | -------------- snd ACK | ------- | 649 V x V snd FIN V 650 +---------+ +---------+ +---------+ 651 |FINWAIT-2| | CLOSING | | LAST-ACK| 652 +---------+ +---------+ +---------+ 653 | rcv ACK of FIN | rcv ACK of FIN | 654 | rcv FIN -------------- | Timeout=2MSL -------------- | 655 | ------- x V ------------ x V 656 \ snd ACK +---------+delete TCB +---------+ 657 ------------------------>|TIME WAIT|------------------>| CLOSED | 658 +---------+ +---------+ 660 note 1: The transition from SYN-RECEIVED to LISTEN on receiving a RST is 661 conditional on having reached SYN-RECEIVED after a passive open. 663 note 2: An unshown transition exists from FIN-WAIT-1 to TIME-WAIT if 664 a FIN is received and the local FIN is also acknowledged. 666 TCP Connection State Diagram 668 Figure 4 670 3.3. Sequence Numbers 672 A fundamental notion in the design is that every octet of data sent 673 over a TCP connection has a sequence number. Since every octet is 674 sequenced, each of them can be acknowledged. The acknowledgment 675 mechanism employed is cumulative so that an acknowledgment of 676 sequence number X indicates that all octets up to but not including X 677 have been received. This mechanism allows for straight-forward 678 duplicate detection in the presence of retransmission. Numbering of 679 octets within a segment is that the first data octet immediately 680 following the header is the lowest numbered, and the following octets 681 are numbered consecutively. 683 It is essential to remember that the actual sequence number space is 684 finite, though very large. This space ranges from 0 to 2**32 - 1. 685 Since the space is finite, all arithmetic dealing with sequence 686 numbers must be performed modulo 2**32. This unsigned arithmetic 687 preserves the relationship of sequence numbers as they cycle from 688 2**32 - 1 to 0 again. There are some subtleties to computer modulo 689 arithmetic, so great care should be taken in programming the 690 comparison of such values. The symbol "=<" means "less than or 691 equal" (modulo 2**32). 693 The typical kinds of sequence number comparisons which the TCP must 694 perform include: 696 (a) Determining that an acknowledgment refers to some sequence 697 number sent but not yet acknowledged. 699 (b) Determining that all sequence numbers occupied by a segment 700 have been acknowledged (e.g., to remove the segment from a 701 retransmission queue). 703 (c) Determining that an incoming segment contains sequence numbers 704 which are expected (i.e., that the segment "overlaps" the receive 705 window). 707 In response to sending data the TCP will receive acknowledgments. 708 The following comparisons are needed to process the acknowledgments. 710 SND.UNA = oldest unacknowledged sequence number 712 SND.NXT = next sequence number to be sent 714 SEG.ACK = acknowledgment from the receiving TCP (next sequence 715 number expected by the receiving TCP) 717 SEG.SEQ = first sequence number of a segment 719 SEG.LEN = the number of octets occupied by the data in the segment 720 (counting SYN and FIN) 722 SEG.SEQ+SEG.LEN-1 = last sequence number of a segment 724 A new acknowledgment (called an "acceptable ack"), is one for which 725 the inequality below holds: 727 SND.UNA < SEG.ACK =< SND.NXT 729 A segment on the retransmission queue is fully acknowledged if the 730 sum of its sequence number and length is less or equal than the 731 acknowledgment value in the incoming segment. 733 When data is received the following comparisons are needed: 735 RCV.NXT = next sequence number expected on an incoming segments, 736 and is the left or lower edge of the receive window 738 RCV.NXT+RCV.WND-1 = last sequence number expected on an incoming 739 segment, and is the right or upper edge of the receive window 741 SEG.SEQ = first sequence number occupied by the incoming segment 742 SEG.SEQ+SEG.LEN-1 = last sequence number occupied by the incoming 743 segment 745 A segment is judged to occupy a portion of valid receive sequence 746 space if 748 RCV.NXT =< SEG.SEQ < RCV.NXT+RCV.WND 750 or 752 RCV.NXT =< SEG.SEQ+SEG.LEN-1 < RCV.NXT+RCV.WND 754 The first part of this test checks to see if the beginning of the 755 segment falls in the window, the second part of the test checks to 756 see if the end of the segment falls in the window; if the segment 757 passes either part of the test it contains data in the window. 759 Actually, it is a little more complicated than this. Due to zero 760 windows and zero length segments, we have four cases for the 761 acceptability of an incoming segment: 763 Segment Receive Test 764 Length Window 765 ------- ------- ------------------------------------------- 767 0 0 SEG.SEQ = RCV.NXT 769 0 >0 RCV.NXT =< SEG.SEQ < RCV.NXT+RCV.WND 771 >0 0 not acceptable 773 >0 >0 RCV.NXT =< SEG.SEQ < RCV.NXT+RCV.WND 774 or RCV.NXT =< SEG.SEQ+SEG.LEN-1 < RCV.NXT+RCV.WND 776 Note that when the receive window is zero no segments should be 777 acceptable except ACK segments. Thus, it is be possible for a TCP to 778 maintain a zero receive window while transmitting data and receiving 779 ACKs. However, even when the receive window is zero, a TCP must 780 process the RST and URG fields of all incoming segments. 782 We have taken advantage of the numbering scheme to protect certain 783 control information as well. This is achieved by implicitly 784 including some control flags in the sequence space so they can be 785 retransmitted and acknowledged without confusion (i.e., one and only 786 one copy of the control will be acted upon). Control information is 787 not physically carried in the segment data space. Consequently, we 788 must adopt rules for implicitly assigning sequence numbers to 789 control. The SYN and FIN are the only controls requiring this 790 protection, and these controls are used only at connection opening 791 and closing. For sequence number purposes, the SYN is considered to 792 occur before the first actual data octet of the segment in which it 793 occurs, while the FIN is considered to occur after the last actual 794 data octet in a segment in which it occurs. The segment length 795 (SEG.LEN) includes both data and sequence space occupying controls. 796 When a SYN is present then SEG.SEQ is the sequence number of the SYN. 798 Initial Sequence Number Selection 800 The protocol places no restriction on a particular connection being 801 used over and over again. A connection is defined by a pair of 802 sockets. New instances of a connection will be referred to as 803 incarnations of the connection. The problem that arises from this is 804 -- "how does the TCP identify duplicate segments from previous 805 incarnations of the connection?" This problem becomes apparent if 806 the connection is being opened and closed in quick succession, or if 807 the connection breaks with loss of memory and is then reestablished. 809 To avoid confusion we must prevent segments from one incarnation of a 810 connection from being used while the same sequence numbers may still 811 be present in the network from an earlier incarnation. We want to 812 assure this, even if a TCP crashes and loses all knowledge of the 813 sequence numbers it has been using. When new connections are 814 created, an initial sequence number (ISN) generator is employed which 815 selects a new 32 bit ISN. There are security issues that result if 816 an off-path attacker is able to predict or guess ISN values. 818 The recommended ISN generator is based on the combination of a 819 (possibly fictitious) 32 bit clock whose low order bit is incremented 820 roughly every 4 microseconds, and a pseudorandom hash function (PRF). 821 The clock component is intended to insure that with a Maximum Segment 822 Lifetime (MSL), generated ISNs will be unique, since it cycles 823 approximately every 4.55 hours, which is much longer than the MSL. 824 This recommended algorithm is further described in RFC 1948 and 825 builds on the basic clock-driven algorithm from RFC 793. 827 A TCP MUST use a clock-driven selection of initial sequence numbers 828 (MUST-8), and SHOULD generate its Initial Sequence Numbers with the 829 expression: 831 ISN = M + F(localip, localport, remoteip, remoteport, secretkey) 833 where M is the 4 microsecond timer, and F() is a pseudorandom 834 function (PRF) of the connection's identifying parameters ("localip, 835 localport, remoteip, remoteport") and a secret key ("secretkey") 836 (SHLD-1). F() MUST NOT be computable from the outside (MUST-9), or 837 an attacker could still guess at sequence numbers from the ISN used 838 for some other connection. The PRF could be implemented as a 839 cryptographic has of the concatenation of the TCP connection 840 parameters and some secret data. For discussion of the selection of 841 a specific hash algorithm and management of the secret key data, 842 please see Section 3 of [32]. 844 For each connection there is a send sequence number and a receive 845 sequence number. The initial send sequence number (ISS) is chosen by 846 the data sending TCP, and the initial receive sequence number (IRS) 847 is learned during the connection establishing procedure. 849 For a connection to be established or initialized, the two TCPs must 850 synchronize on each other's initial sequence numbers. This is done 851 in an exchange of connection establishing segments carrying a control 852 bit called "SYN" (for synchronize) and the initial sequence numbers. 853 As a shorthand, segments carrying the SYN bit are also called "SYNs". 854 Hence, the solution requires a suitable mechanism for picking an 855 initial sequence number and a slightly involved handshake to exchange 856 the ISN's. 858 The synchronization requires each side to send it's own initial 859 sequence number and to receive a confirmation of it in acknowledgment 860 from the other side. Each side must also receive the other side's 861 initial sequence number and send a confirming acknowledgment. 863 1) A --> B SYN my sequence number is X 864 2) A <-- B ACK your sequence number is X 865 3) A <-- B SYN my sequence number is Y 866 4) A --> B ACK your sequence number is Y 868 Because steps 2 and 3 can be combined in a single message this is 869 called the three way (or three message) handshake. 871 A three way handshake is necessary because sequence numbers are not 872 tied to a global clock in the network, and TCPs may have different 873 mechanisms for picking the ISN's. The receiver of the first SYN has 874 no way of knowing whether the segment was an old delayed one or not, 875 unless it remembers the last sequence number used on the connection 876 (which is not always possible), and so it must ask the sender to 877 verify this SYN. The three way handshake and the advantages of a 878 clock-driven scheme are discussed in [46]. 880 Knowing When to Keep Quiet 882 To be sure that a TCP does not create a segment that carries a 883 sequence number which may be duplicated by an old segment remaining 884 in the network, the TCP must keep quiet for an MSL before assigning 885 any sequence numbers upon starting up or recovering from a crash in 886 which memory of sequence numbers in use was lost. For this 887 specification the MSL is taken to be 2 minutes. This is an 888 engineering choice, and may be changed if experience indicates it is 889 desirable to do so. Note that if a TCP is reinitialized in some 890 sense, yet retains its memory of sequence numbers in use, then it 891 need not wait at all; it must only be sure to use sequence numbers 892 larger than those recently used. 894 The TCP Quiet Time Concept 896 This specification provides that hosts which "crash" without 897 retaining any knowledge of the last sequence numbers transmitted on 898 each active (i.e., not closed) connection shall delay emitting any 899 TCP segments for at least the agreed MSL in the internet system of 900 which the host is a part. In the paragraphs below, an explanation 901 for this specification is given. TCP implementors may violate the 902 "quiet time" restriction, but only at the risk of causing some old 903 data to be accepted as new or new data rejected as old duplicated by 904 some receivers in the internet system. 906 TCPs consume sequence number space each time a segment is formed and 907 entered into the network output queue at a source host. The 908 duplicate detection and sequencing algorithm in the TCP protocol 909 relies on the unique binding of segment data to sequence space to the 910 extent that sequence numbers will not cycle through all 2**32 values 911 before the segment data bound to those sequence numbers has been 912 delivered and acknowledged by the receiver and all duplicate copies 913 of the segments have "drained" from the internet. Without such an 914 assumption, two distinct TCP segments could conceivably be assigned 915 the same or overlapping sequence numbers, causing confusion at the 916 receiver as to which data is new and which is old. Remember that 917 each segment is bound to as many consecutive sequence numbers as 918 there are octets of data and SYN or FIN flags in the segment. 920 Under normal conditions, TCPs keep track of the next sequence number 921 to emit and the oldest awaiting acknowledgment so as to avoid 922 mistakenly using a sequence number over before its first use has been 923 acknowledged. This alone does not guarantee that old duplicate data 924 is drained from the net, so the sequence space has been made very 925 large to reduce the probability that a wandering duplicate will cause 926 trouble upon arrival. At 2 megabits/sec. it takes 4.5 hours to use 927 up 2**32 octets of sequence space. Since the maximum segment 928 lifetime in the net is not likely to exceed a few tens of seconds, 929 this is deemed ample protection for foreseeable nets, even if data 930 rates escalate to l0's of megabits/sec. At 100 megabits/sec, the 931 cycle time is 5.4 minutes which may be a little short, but still 932 within reason. 934 The basic duplicate detection and sequencing algorithm in TCP can be 935 defeated, however, if a source TCP does not have any memory of the 936 sequence numbers it last used on a given connection. For example, if 937 the TCP were to start all connections with sequence number 0, then 938 upon crashing and restarting, a TCP might re-form an earlier 939 connection (possibly after half-open connection resolution) and emit 940 packets with sequence numbers identical to or overlapping with 941 packets still in the network which were emitted on an earlier 942 incarnation of the same connection. In the absence of knowledge 943 about the sequence numbers used on a particular connection, the TCP 944 specification recommends that the source delay for MSL seconds before 945 emitting segments on the connection, to allow time for segments from 946 the earlier connection incarnation to drain from the system. 948 Even hosts which can remember the time of day and used it to select 949 initial sequence number values are not immune from this problem 950 (i.e., even if time of day is used to select an initial sequence 951 number for each new connection incarnation). 953 Suppose, for example, that a connection is opened starting with 954 sequence number S. Suppose that this connection is not used much and 955 that eventually the initial sequence number function (ISN(t)) takes 956 on a value equal to the sequence number, say S1, of the last segment 957 sent by this TCP on a particular connection. Now suppose, at this 958 instant, the host crashes, recovers, and establishes a new 959 incarnation of the connection. The initial sequence number chosen is 960 S1 = ISN(t) -- last used sequence number on old incarnation of 961 connection! If the recovery occurs quickly enough, any old 962 duplicates in the net bearing sequence numbers in the neighborhood of 963 S1 may arrive and be treated as new packets by the receiver of the 964 new incarnation of the connection. 966 The problem is that the recovering host may not know for how long it 967 crashed nor does it know whether there are still old duplicates in 968 the system from earlier connection incarnations. 970 One way to deal with this problem is to deliberately delay emitting 971 segments for one MSL after recovery from a crash- this is the "quiet 972 time" specification. Hosts which prefer to avoid waiting are willing 973 to risk possible confusion of old and new packets at a given 974 destination may choose not to wait for the "quite time". 975 Implementors may provide TCP users with the ability to select on a 976 connection by connection basis whether to wait after a crash, or may 977 informally implement the "quite time" for all connections. 978 Obviously, even where a user selects to "wait," this is not necessary 979 after the host has been "up" for at least MSL seconds. 981 To summarize: every segment emitted occupies one or more sequence 982 numbers in the sequence space, the numbers occupied by a segment are 983 "busy" or "in use" until MSL seconds have passed, upon crashing a 984 block of space-time is occupied by the octets and SYN or FIN flags of 985 the last emitted segment, if a new connection is started too soon and 986 uses any of the sequence numbers in the space-time footprint of the 987 last segment of the previous connection incarnation, there is a 988 potential sequence number overlap area which could cause confusion at 989 the receiver. 991 3.4. Establishing a connection 993 The "three-way handshake" is the procedure used to establish a 994 connection. This procedure normally is initiated by one TCP and 995 responded to by another TCP. The procedure also works if two TCP 996 simultaneously initiate the procedure. When simultaneous attempt 997 occurs, each TCP receives a "SYN" segment which carries no 998 acknowledgment after it has sent a "SYN". Of course, the arrival of 999 an old duplicate "SYN" segment can potentially make it appear, to the 1000 recipient, that a simultaneous connection initiation is in progress. 1001 Proper use of "reset" segments can disambiguate these cases. 1003 Several examples of connection initiation follow. Although these 1004 examples do not show connection synchronization using data-carrying 1005 segments, this is perfectly legitimate, so long as the receiving TCP 1006 doesn't deliver the data to the user until it is clear the data is 1007 valid (i.e., the data must be buffered at the receiver until the 1008 connection reaches the ESTABLISHED state). The three-way handshake 1009 reduces the possibility of false connections. It is the 1010 implementation of a trade-off between memory and messages to provide 1011 information for this checking. 1013 The simplest three-way handshake is shown in Figure 5 below. The 1014 figures should be interpreted in the following way. Each line is 1015 numbered for reference purposes. Right arrows (-->) indicate 1016 departure of a TCP segment from TCP A to TCP B, or arrival of a 1017 segment at B from A. Left arrows (<--), indicate the reverse. 1018 Ellipsis (...) indicates a segment which is still in the network 1019 (delayed). An "XXX" indicates a segment which is lost or rejected. 1020 Comments appear in parentheses. TCP states represent the state AFTER 1021 the departure or arrival of the segment (whose contents are shown in 1022 the center of each line). Segment contents are shown in abbreviated 1023 form, with sequence number, control flags, and ACK field. Other 1024 fields such as window, addresses, lengths, and text have been left 1025 out in the interest of clarity. 1027 TCP A TCP B 1029 1. CLOSED LISTEN 1031 2. SYN-SENT --> --> SYN-RECEIVED 1033 3. ESTABLISHED <-- <-- SYN-RECEIVED 1035 4. ESTABLISHED --> --> ESTABLISHED 1037 5. ESTABLISHED --> --> ESTABLISHED 1039 Basic 3-Way Handshake for Connection Synchronization 1041 Figure 5 1043 In line 2 of Figure 5, TCP A begins by sending a SYN segment 1044 indicating that it will use sequence numbers starting with sequence 1045 number 100. In line 3, TCP B sends a SYN and acknowledges the SYN it 1046 received from TCP A. Note that the acknowledgment field indicates 1047 TCP B is now expecting to hear sequence 101, acknowledging the SYN 1048 which occupied sequence 100. 1050 At line 4, TCP A responds with an empty segment containing an ACK for 1051 TCP B's SYN; and in line 5, TCP A sends some data. Note that the 1052 sequence number of the segment in line 5 is the same as in line 4 1053 because the ACK does not occupy sequence number space (if it did, we 1054 would wind up ACKing ACK's!). 1056 Simultaneous initiation is only slightly more complex, as is shown in 1057 Figure 6. Each TCP cycles from CLOSED to SYN-SENT to SYN-RECEIVED to 1058 ESTABLISHED. 1060 TCP A TCP B 1062 1. CLOSED CLOSED 1064 2. SYN-SENT --> ... 1066 3. SYN-RECEIVED <-- <-- SYN-SENT 1068 4. ... --> SYN-RECEIVED 1070 5. SYN-RECEIVED --> ... 1072 6. ESTABLISHED <-- <-- SYN-RECEIVED 1074 7. ... --> ESTABLISHED 1076 Simultaneous Connection Synchronization 1078 Figure 6 1080 A TCP MUST support simultaneous open attempts (MUST-10). 1082 Note that a TCP implementation MUST keep track of whether a 1083 connection has reached SYN-RECEIVED state as the result of a passive 1084 OPEN or an active OPEN (MUST-11). 1086 The principle reason for the three-way handshake is to prevent old 1087 duplicate connection initiations from causing confusion. To deal 1088 with this, a special control message, reset, has been devised. If 1089 the receiving TCP is in a non-synchronized state (i.e., SYN-SENT, 1090 SYN-RECEIVED), it returns to LISTEN on receiving an acceptable reset. 1091 If the TCP is in one of the synchronized states (ESTABLISHED, FIN- 1092 WAIT-1, FIN-WAIT-2, CLOSE-WAIT, CLOSING, LAST-ACK, TIME-WAIT), it 1093 aborts the connection and informs its user. We discuss this latter 1094 case under "half-open" connections below. 1096 TCP A TCP B 1098 1. CLOSED LISTEN 1100 2. SYN-SENT --> ... 1102 3. (duplicate) ... --> SYN-RECEIVED 1104 4. SYN-SENT <-- <-- SYN-RECEIVED 1106 5. SYN-SENT --> --> LISTEN 1108 6. ... --> SYN-RECEIVED 1110 7. SYN-SENT <-- <-- SYN-RECEIVED 1112 8. ESTABLISHED --> --> ESTABLISHED 1114 Recovery from Old Duplicate SYN 1116 Figure 7 1118 As a simple example of recovery from old duplicates, consider 1119 Figure 7. At line 3, an old duplicate SYN arrives at TCP B. TCP B 1120 cannot tell that this is an old duplicate, so it responds normally 1121 (line 4). TCP A detects that the ACK field is incorrect and returns 1122 a RST (reset) with its SEQ field selected to make the segment 1123 believable. TCP B, on receiving the RST, returns to the LISTEN 1124 state. When the original SYN (pun intended) finally arrives at line 1125 6, the synchronization proceeds normally. If the SYN at line 6 had 1126 arrived before the RST, a more complex exchange might have occurred 1127 with RST's sent in both directions. 1129 Half-Open Connections and Other Anomalies 1131 An established connection is said to be "half-open" if one of the 1132 TCPs has closed or aborted the connection at its end without the 1133 knowledge of the other, or if the two ends of the connection have 1134 become desynchronized owing to a crash that resulted in loss of 1135 memory. Such connections will automatically become reset if an 1136 attempt is made to send data in either direction. However, half-open 1137 connections are expected to be unusual, and the recovery procedure is 1138 mildly involved. 1140 If at site A the connection no longer exists, then an attempt by the 1141 user at site B to send any data on it will result in the site B TCP 1142 receiving a reset control message. Such a message indicates to the 1143 site B TCP that something is wrong, and it is expected to abort the 1144 connection. 1146 Assume that two user processes A and B are communicating with one 1147 another when a crash occurs causing loss of memory to A's TCP. 1148 Depending on the operating system supporting A's TCP, it is likely 1149 that some error recovery mechanism exists. When the TCP is up again, 1150 A is likely to start again from the beginning or from a recovery 1151 point. As a result, A will probably try to OPEN the connection again 1152 or try to SEND on the connection it believes open. In the latter 1153 case, it receives the error message "connection not open" from the 1154 local (A's) TCP. In an attempt to establish the connection, A's TCP 1155 will send a segment containing SYN. This scenario leads to the 1156 example shown in Figure 8. After TCP A crashes, the user attempts to 1157 re-open the connection. TCP B, in the meantime, thinks the 1158 connection is open. 1160 TCP A TCP B 1162 1. (CRASH) (send 300,receive 100) 1164 2. CLOSED ESTABLISHED 1166 3. SYN-SENT --> --> (??) 1168 4. (!!) <-- <-- ESTABLISHED 1170 5. SYN-SENT --> --> (Abort!!) 1172 6. SYN-SENT CLOSED 1174 7. SYN-SENT --> --> 1176 Half-Open Connection Discovery 1178 Figure 8 1180 When the SYN arrives at line 3, TCP B, being in a synchronized state, 1181 and the incoming segment outside the window, responds with an 1182 acknowledgment indicating what sequence it next expects to hear (ACK 1183 100). TCP A sees that this segment does not acknowledge anything it 1184 sent and, being unsynchronized, sends a reset (RST) because it has 1185 detected a half-open connection. TCP B aborts at line 5. TCP A will 1186 continue to try to establish the connection; the problem is now 1187 reduced to the basic 3-way handshake of Figure 5. 1189 An interesting alternative case occurs when TCP A crashes and TCP B 1190 tries to send data on what it thinks is a synchronized connection. 1192 This is illustrated in Figure 9. In this case, the data arriving at 1193 TCP A from TCP B (line 2) is unacceptable because no such connection 1194 exists, so TCP A sends a RST. The RST is acceptable so TCP B 1195 processes it and aborts the connection. 1197 TCP A TCP B 1199 1. (CRASH) (send 300,receive 100) 1201 2. (??) <-- <-- ESTABLISHED 1203 3. --> --> (ABORT!!) 1205 Active Side Causes Half-Open Connection Discovery 1207 Figure 9 1209 In Figure 10, we find the two TCPs A and B with passive connections 1210 waiting for SYN. An old duplicate arriving at TCP B (line 2) stirs B 1211 into action. A SYN-ACK is returned (line 3) and causes TCP A to 1212 generate a RST (the ACK in line 3 is not acceptable). TCP B accepts 1213 the reset and returns to its passive LISTEN state. 1215 TCP A TCP B 1217 1. LISTEN LISTEN 1219 2. ... --> SYN-RECEIVED 1221 3. (??) <-- <-- SYN-RECEIVED 1223 4. --> --> (return to LISTEN!) 1225 5. LISTEN LISTEN 1227 Old Duplicate SYN Initiates a Reset on two Passive Sockets 1229 Figure 10 1231 A variety of other cases are possible, all of which are accounted for 1232 by the following rules for RST generation and processing. 1234 Reset Generation 1235 As a general rule, reset (RST) must be sent whenever a segment 1236 arrives which apparently is not intended for the current connection. 1237 A reset must not be sent if it is not clear that this is the case. 1239 There are three groups of states: 1241 1. If the connection does not exist (CLOSED) then a reset is sent 1242 in response to any incoming segment except another reset. In 1243 particular, SYNs addressed to a non-existent connection are 1244 rejected by this means. 1246 If the incoming segment has the ACK bit set, the reset takes its 1247 sequence number from the ACK field of the segment, otherwise the 1248 reset has sequence number zero and the ACK field is set to the sum 1249 of the sequence number and segment length of the incoming segment. 1250 The connection remains in the CLOSED state. 1252 2. If the connection is in any non-synchronized state (LISTEN, 1253 SYN-SENT, SYN-RECEIVED), and the incoming segment acknowledges 1254 something not yet sent (the segment carries an unacceptable ACK), 1255 or if an incoming segment has a security level or compartment 1256 which does not exactly match the level and compartment requested 1257 for the connection, a reset is sent. 1259 If the incoming segment has an ACK field, the reset takes its 1260 sequence number from the ACK field of the segment, otherwise the 1261 reset has sequence number zero and the ACK field is set to the sum 1262 of the sequence number and segment length of the incoming segment. 1263 The connection remains in the same state. 1265 3. If the connection is in a synchronized state (ESTABLISHED, 1266 FIN-WAIT-1, FIN-WAIT-2, CLOSE-WAIT, CLOSING, LAST-ACK, TIME-WAIT), 1267 any unacceptable segment (out of window sequence number or 1268 unacceptable acknowledgment number) must elicit only an empty 1269 acknowledgment segment containing the current send-sequence number 1270 and an acknowledgment indicating the next sequence number expected 1271 to be received, and the connection remains in the same state. 1273 If an incoming segment has a security level, or compartment which 1274 does not exactly match the level and compartment requested for the 1275 connection, a reset is sent and the connection goes to the CLOSED 1276 state. The reset takes its sequence number from the ACK field of 1277 the incoming segment. 1279 Reset Processing 1281 In all states except SYN-SENT, all reset (RST) segments are validated 1282 by checking their SEQ-fields. A reset is valid if its sequence 1283 number is in the window. In the SYN-SENT state (a RST received in 1284 response to an initial SYN), the RST is acceptable if the ACK field 1285 acknowledges the SYN. 1287 The receiver of a RST first validates it, then changes state. If the 1288 receiver was in the LISTEN state, it ignores it. If the receiver was 1289 in SYN-RECEIVED state and had previously been in the LISTEN state, 1290 then the receiver returns to the LISTEN state, otherwise the receiver 1291 aborts the connection and goes to the CLOSED state. If the receiver 1292 was in any other state, it aborts the connection and advises the user 1293 and goes to the CLOSED state. 1295 TCP SHOULD allow a received RST segment to include data (SHLD-2). 1297 3.5. Closing a Connection 1299 CLOSE is an operation meaning "I have no more data to send." The 1300 notion of closing a full-duplex connection is subject to ambiguous 1301 interpretation, of course, since it may not be obvious how to treat 1302 the receiving side of the connection. We have chosen to treat CLOSE 1303 in a simplex fashion. The user who CLOSEs may continue to RECEIVE 1304 until he is told that the other side has CLOSED also. Thus, a 1305 program could initiate several SENDs followed by a CLOSE, and then 1306 continue to RECEIVE until signaled that a RECEIVE failed because the 1307 other side has CLOSED. We assume that the TCP will signal a user, 1308 even if no RECEIVEs are outstanding, that the other side has closed, 1309 so the user can terminate his side gracefully. A TCP will reliably 1310 deliver all buffers SENT before the connection was CLOSED so a user 1311 who expects no data in return need only wait to hear the connection 1312 was CLOSED successfully to know that all his data was received at the 1313 destination TCP. Users must keep reading connections they close for 1314 sending until the TCP says no more data. 1316 There are essentially three cases: 1318 1) The user initiates by telling the TCP to CLOSE the connection 1320 2) The remote TCP initiates by sending a FIN control signal 1322 3) Both users CLOSE simultaneously 1324 Case 1: Local user initiates the close 1326 In this case, a FIN segment can be constructed and placed on the 1327 outgoing segment queue. No further SENDs from the user will be 1328 accepted by the TCP, and it enters the FIN-WAIT-1 state. RECEIVEs 1329 are allowed in this state. All segments preceding and including 1330 FIN will be retransmitted until acknowledged. When the other TCP 1331 has both acknowledged the FIN and sent a FIN of its own, the first 1332 TCP can ACK this FIN. Note that a TCP receiving a FIN will ACK 1333 but not send its own FIN until its user has CLOSED the connection 1334 also. 1336 Case 2: TCP receives a FIN from the network 1338 If an unsolicited FIN arrives from the network, the receiving TCP 1339 can ACK it and tell the user that the connection is closing. The 1340 user will respond with a CLOSE, upon which the TCP can send a FIN 1341 to the other TCP after sending any remaining data. The TCP then 1342 waits until its own FIN is acknowledged whereupon it deletes the 1343 connection. If an ACK is not forthcoming, after the user timeout 1344 the connection is aborted and the user is told. 1346 Case 3: both users close simultaneously 1348 A simultaneous CLOSE by users at both ends of a connection causes 1349 FIN segments to be exchanged. When all segments preceding the 1350 FINs have been processed and acknowledged, each TCP can ACK the 1351 FIN it has received. Both will, upon receiving these ACKs, delete 1352 the connection. 1354 TCP A TCP B 1356 1. ESTABLISHED ESTABLISHED 1358 2. (Close) 1359 FIN-WAIT-1 --> --> CLOSE-WAIT 1361 3. FIN-WAIT-2 <-- <-- CLOSE-WAIT 1363 4. (Close) 1364 TIME-WAIT <-- <-- LAST-ACK 1366 5. TIME-WAIT --> --> CLOSED 1368 6. (2 MSL) 1369 CLOSED 1371 Normal Close Sequence 1373 Figure 11 1375 TCP A TCP B 1377 1. ESTABLISHED ESTABLISHED 1379 2. (Close) (Close) 1380 FIN-WAIT-1 --> ... FIN-WAIT-1 1381 <-- <-- 1382 ... --> 1384 3. CLOSING --> ... CLOSING 1385 <-- <-- 1386 ... --> 1388 4. TIME-WAIT TIME-WAIT 1389 (2 MSL) (2 MSL) 1390 CLOSED CLOSED 1392 Simultaneous Close Sequence 1394 Figure 12 1396 A TCP connection may terminate in two ways: (1) the normal TCP close 1397 sequence using a FIN handshake, and (2) an "abort" in which one or 1398 more RST segments are sent and the connection state is immediately 1399 discarded. If the local TCP connection is closed by the remote side 1400 due to a FIN or RST received from the remote side, then the local 1401 application MUST be informed whether it closed normally or was 1402 aborted (MUST-12). 1404 3.5.1. Half-Closed Connections 1406 The normal TCP close sequence delivers buffered data reliably in both 1407 directions. Since the two directions of a TCP connection are closed 1408 independently, it is possible for a connection to be "half closed," 1409 i.e., closed in only one direction, and a host is permitted to 1410 continue sending data in the open direction on a half-closed 1411 connection. 1413 A host MAY implement a "half-duplex" TCP close sequence, so that an 1414 application that has called CLOSE cannot continue to read data from 1415 the connection (MAY-1). If such a host issues a CLOSE call while 1416 received data is still pending in TCP, or if new data is received 1417 after CLOSE is called, its TCP SHOULD send a RST to show that data 1418 was lost (SHLD-3). See [17] section 2.17 for discussion. 1420 When a connection is closed actively, it MUST linger in TIME-WAIT 1421 state for a time 2xMSL (Maximum Segment Lifetime) (MUST-13). 1423 However, it MAY accept a new SYN from the remote TCP to reopen the 1424 connection directly from TIME-WAIT state (MAY-2), if it: 1426 (1) assigns its initial sequence number for the new connection to 1427 be larger than the largest sequence number it used on the previous 1428 connection incarnation, and 1430 (2) returns to TIME-WAIT state if the SYN turns out to be an old 1431 duplicate. 1433 When the TCP Timestamp options are available, an improved algorithm 1434 is described in [30] in order to support higher connection 1435 establishment rates. This algorithm for reducing TIME-WAIT is a Best 1436 Current Practice that SHOULD be implemented, since timestamp options 1437 are commonly used, and using them to reduce TIME-WAIT provides 1438 benefits for busy Internet servers (SHLD-4). 1440 3.6. Precedence and Security 1442 The IPv4 specification [1] includes a precedence value in the (now 1443 obsoleted) Type of Service field (TOS) field. It was modified in 1444 [15], and then obsoleted by the definition of Differentiated Services 1445 (DiffServ) [6]. Setting and conveying TOS between the network layer, 1446 TCP, and applications is obsolete, and replaced by DiffServ in the 1447 current TCP specification. 1449 In DiffServ the former precedence values are treated as Class 1450 Selector codepoints, and methods for compatible treatment are 1451 described in the DiffServ architecture. The RFC 793/1122 TCP 1452 specification includes logic intending to have connections use the 1453 highest precedence requested by either endpoint application, and to 1454 keep the precedence consistent throughout a connection. This logic 1455 from the obsolete TOS is not applicable for DiffServ, and should not 1456 be included in TCP implementations, though changes to DiffServ values 1457 within a connection are discouraged. For discussion of this, see RFC 1458 7657 (sec 5.1, 5.3, and 6) [38]. 1460 The obsoleted TOS processing rules in TCP assumed bidirectional (or 1461 symmetric) precedence values used on a connection, but the DiffServ 1462 architecture is asymmetric. Problems with the old TCP logic in this 1463 regard were described in [18] and the solution described is to ignore 1464 IP precedence in TCP. Since RFC 2873 is a Standards Track document 1465 (although not marked as updating RFC 793), current implementations 1466 are expected to be robust to these conditions. Note that the 1467 DiffServ field value used in each direction is a part of the 1468 interface between TCP and the network layer, and values in use can be 1469 indicated both ways between TCP and the application. 1471 The IP security option (IPSO) and compartment defined in [1] was 1472 refined in RFC 1038 that was later obsoleted by RFC 1108. The 1473 Commercial IP Security Option (CIPSO) is defined in FIPS-188, and is 1474 supported by some vendors and operating systems. RFC 1108 is now 1475 Historic, though RFC 791 itself has not been updated to remove the IP 1476 security option. For IPv6, a similar option (CALIPSO) has been 1477 defined [24]. RFC 793 includes logic that includes the IP security/ 1478 compartment information in treatment of TCP segments. References to 1479 the IP "security/compartment" in this document may be relevant for 1480 Multi-Level Secure (MLS) system implementers, but can be ignored for 1481 non-MLS implementations, consistent with running code on the 1482 Internet. See Appendix A.1 for further discussion. Note that RFC 1483 5570 describes some MLS networking scenarios where IPSO, CIPSO, or 1484 CALIPSO may be used. In these special cases, TCP implementers should 1485 see section 7.3.1 of RFC 5570, and follow the guidance in that 1486 document on the relation between IP security. 1488 3.7. Segmentation 1490 The term "segmentation" refers to the activity TCP performs when 1491 ingesting a stream of bytes from a sending application and 1492 packetizing that stream of bytes into TCP segments. Individual TCP 1493 segments often do not correspond one-for-one to individual send (or 1494 socket write) calls from the application. Applications may perform 1495 writes at the granularity of messages in the upper layer protocol, 1496 but TCP guarantees no boundary coherence between the TCP segments 1497 sent and received versus user application data read or write buffer 1498 boundaries. In some specific protocols, such as RDMA using DDP and 1499 MPA [22], there are performance optimizations possible when the 1500 relation between TCP segments and application data units can be 1501 controlled, and MPA includes a specific mechanism for detecting and 1502 verifying this relationship between TCP segments and application 1503 message data strcutures, but this is specific to applications like 1504 RDMA. In general, multiple goals influence the sizing of TCP 1505 segments created by a TCP implementation. 1507 Goals driving the sending of larger segments include: 1509 o Reducing the number of packets in flight within the network. 1511 o Increasing processing efficiency and potential performance by 1512 enabling a smaller number of interrupts and inter-layer 1513 interactions. 1515 o Limiting the overhead of TCP headers. 1517 Note that the performance benefits of sending larger segments may 1518 decrease as the size increases, and there may be boundaries where 1519 advantages are reversed. For instance, on some machines 1025 bytes 1520 within a segment could lead to worse performance than 1024 bytes, due 1521 purely to data alignment on copy operations. 1523 Goals driving the sending of smaller segments include: 1525 o Avoiding sending segments larger than the smallest MTU within an 1526 IP network path, because this results in either packet loss or 1527 fragmentation. Making matters worse, some firewalls or 1528 middleboxes may drop fragmented packets or ICMP messages related 1529 related to fragmentation. 1531 o Preventing delays to the application data stream, especially when 1532 TCP is waiting on the application to generate more data, or when 1533 the application is waiting on an event or input from its peer in 1534 order to generate more data. 1536 o Enabling "fate sharing" between TCP segments and lower-layer data 1537 units (e.g. below IP, for links with cell or frame sizes smaller 1538 than the IP MTU). 1540 Towards meeting these competing sets of goals, TCP includes several 1541 mechanisms, including the Maximum Segment Size option, Path MTU 1542 Discovery, the Nagle algorithm, and support for IPv6 Jumbograms, as 1543 discussed in the following subsections. 1545 3.7.1. Maximum Segment Size Option 1547 TCP MUST implement both sending and receiving the MSS option (MUST- 1548 14). 1550 TCP SHOULD send an MSS option in every SYN segment when its receive 1551 MSS differs from the default 536 for IPv4 or 1220 for IPv6 (SHLD-5), 1552 and MAY send it always (MAY-3). 1554 If an MSS option is not received at connection setup, TCP MUST assume 1555 a default send MSS of 536 (576-40) for IPv4 or 1220 (1280 - 60) for 1556 IPv6 (MUST-15). 1558 The maximum size of a segment that TCP really sends, the "effective 1559 send MSS," MUST be the smaller (MUST-16) of the send MSS (which 1560 reflects the available reassembly buffer size at the remote host, the 1561 EMTU_R [14]) and the largest transmission size permitted by the IP 1562 layer (EMTU_S [14]): 1564 Eff.snd.MSS = 1566 min(SendMSS+20, MMS_S) - TCPhdrsize - IPoptionsize 1568 where: 1570 o SendMSS is the MSS value received from the remote host, or the 1571 default 536 for IPv4 or 1220 for IPv6, if no MSS option is 1572 received. 1574 o MMS_S is the maximum size for a transport-layer message that TCP 1575 may send. 1577 o TCPhdrsize is the size of the fixed TCP header and any options. 1578 This is 20 in the (rare) case that no options are present, but may 1579 be larger if TCP options are to be sent. Note that some options 1580 may not be included on all segments, but that for each segment 1581 sent, the sender should adjust the data length accordingly, within 1582 the Eff.snd.MSS. 1584 o IPoptionsize is the size of any IP options associated with a TCP 1585 connection. Note that some options may not be included on all 1586 packets, but that for each segment sent, the sender should adjust 1587 the data length accordingly, within the Eff.snd.MSS. 1589 The MSS value to be sent in an MSS option should be equal to the 1590 effective MTU minus the fixed IP and TCP headers. By ignoring both 1591 IP and TCP options when calculating the value for the MSS option, if 1592 there are any IP or TCP options to be sent in a packet, then the 1593 sender must decrease the size of the TCP data accordingly. RFC 6691 1594 [33] discusses this in greater detail. 1596 The MSS value to be sent in an MSS option must be less than or equal 1597 to: 1599 MMS_R - 20 1601 where MMS_R is the maximum size for a transport-layer message that 1602 can be received (and reassembled at the IP layer). TCP obtains MMS_R 1603 and MMS_S from the IP layer; see the generic call GET_MAXSIZES in 1604 Section 3.4 of RFC 1122. These are defined in terms of their IP MTU 1605 equivalents, EMTU_R and EMTU_S [14]. 1607 When TCP is used in a situation where either the IP or TCP headers 1608 are not fixed, the sender must reduce the amount of TCP data in any 1609 given packet by the number of octets used by the IP and TCP options. 1610 This has been a point of confusion historically, as explained in RFC 1611 6691, Section 3.1. 1613 3.7.2. Path MTU Discovery 1615 A TCP implementation may be aware of the MTU on directly connected 1616 links, but will rarely have insight about MTUs across an entire 1617 network path. For IPv4, RFC 1122 provides an IP-layer recommendation 1618 on the default effective MTU for sending to be less than or equal to 1619 576 for destinations not directly connected. For IPv6, this would be 1620 1280. In all cases, however, implementation of Path MTU Discovery 1621 (PMTUD) and Packetization Layer Path MTU Discovery (PLPMTUD) is 1622 strongly recommended in order for TCP to improve segmentation 1623 decisions. Both PMTUD and PLPMTUD help TCP choose segment sizes that 1624 avoid both on-path (for IPv4) and source fragmentation (IPv4 and 1625 IPv6). 1627 PMTUD for IPv4 [2] or IPv6 [3] is implemented in conjunction between 1628 TCP, IP, and ICMP protocols. It relies both on avoiding source 1629 fragmentation and setting the IPv4 DF (don't fragment) flag, the 1630 latter to inhibit on-path fragmentation. It relies on ICMP errors 1631 from routers along the path, whenever a segment is too large to 1632 traverse a link. Several adjustments to a TCP implementation with 1633 PMTUD are described in RFC 2923 in order to deal with problems 1634 experienced in practice [8]. PLPMTUD [19] is a Standards Track 1635 improvement to PMTUD that relaxes the requirement for ICMP support 1636 across a path, and improves performance in cases where ICMP is not 1637 consistently conveyed, but still tries to avoid source fragmentation. 1638 The mechanisms in all four of these RFCs are recommended to be 1639 included in TCP implementations. 1641 The TCP MSS option specifies an upper bound for the size of packets 1642 that can be received. Hence, setting the value in the MSS option too 1643 small can impact the ability for PMTUD or PLPMTUD to find a larger 1644 path MTU. RFC 1191 discusses this implication of many older TCP 1645 implementations setting MSS to 536 for non-local destinations, rather 1646 than deriving it from the MTUs of connected interfaces as 1647 recommended. 1649 3.7.3. Interfaces with Variable MTU Values 1651 The effective MTU can sometimes vary, as when used with variable 1652 compression, e.g., RObust Header Compression (ROHC) [26]. It is 1653 tempting for TCP to want to advertise the largest possible MSS, to 1654 support the most efficient use of compressed payloads. 1655 Unfortunately, some compression schemes occasionally need to transmit 1656 full headers (and thus smaller payloads) to resynchronize state at 1657 their endpoint compressors/decompressors. If the largest MTU is used 1658 to calculate the value to advertise in the MSS option, TCP 1659 retransmission may interfere with compressor resynchronization. 1661 As a result, when the effective MTU of an interface varies, TCP 1662 SHOULD use the smallest effective MTU of the interface to calculate 1663 the value to advertise in the MSS option (SHLD-6). 1665 3.7.4. Nagle Algorithm 1667 The "Nagle algorithm" was described in RFC 896 [13] and was 1668 recommended in RFC 1122 [14] for mitigation of an early problem of 1669 too many small packets being generated. It has been implemented in 1670 most current TCP code bases, sometimes with minor variations (see 1671 Appendix A.3). 1673 If there is unacknowledged data (i.e., SND.NXT > SND.UNA), then the 1674 sending TCP buffers all user data (regardless of the PSH bit), until 1675 the outstanding data has been acknowledged or until the TCP can send 1676 a full-sized segment (Eff.snd.MSS bytes). 1678 A TCP SHOULD implement the Nagle Algorithm to coalesce short segments 1679 (SHLD-7). However, there MUST be a way for an application to disable 1680 the Nagle algorithm on an individual connection (MUST-17). In all 1681 cases, sending data is also subject to the limitation imposed by the 1682 Slow Start algorithm [25]. 1684 3.7.5. IPv6 Jumbograms 1686 In order to support TCP over IPv6 jumbograms, implementations need to 1687 be able to send TCP segments larger than the 64KB limit that the MSS 1688 option can convey. RFC 2675 [7] defines that an MSS value of 65,535 1689 bytes is to be treated as infinity, and Path MTU Discovery [3] is 1690 used to determine the actual MSS. 1692 3.8. Data Communication 1694 Once the connection is established data is communicated by the 1695 exchange of segments. Because segments may be lost due to errors 1696 (checksum test failure), or network congestion, TCP uses 1697 retransmission (after a timeout) to ensure delivery of every segment. 1698 Duplicate segments may arrive due to network or TCP retransmission. 1699 As discussed in the section on sequence numbers the TCP performs 1700 certain tests on the sequence and acknowledgment numbers in the 1701 segments to verify their acceptability. 1703 The sender of data keeps track of the next sequence number to use in 1704 the variable SND.NXT. The receiver of data keeps track of the next 1705 sequence number to expect in the variable RCV.NXT. The sender of 1706 data keeps track of the oldest unacknowledged sequence number in the 1707 variable SND.UNA. If the data flow is momentarily idle and all data 1708 sent has been acknowledged then the three variables will be equal. 1710 When the sender creates a segment and transmits it the sender 1711 advances SND.NXT. When the receiver accepts a segment it advances 1712 RCV.NXT and sends an acknowledgment. When the data sender receives 1713 an acknowledgment it advances SND.UNA. The extent to which the 1714 values of these variables differ is a measure of the delay in the 1715 communication. The amount by which the variables are advanced is the 1716 length of the data and SYN or FIN flags in the segment. Note that 1717 once in the ESTABLISHED state all segments must carry current 1718 acknowledgment information. 1720 The CLOSE user call implies a push function, as does the FIN control 1721 flag in an incoming segment. 1723 3.8.1. Retransmission Timeout 1725 Because of the variability of the networks that compose an 1726 internetwork system and the wide range of uses of TCP connections the 1727 retransmission timeout (RTO) must be dynamically determined. 1729 The RTO MUST be computed according to the algorithm in [10], 1730 including Karn's algorithm for taking RTT samples (MUST-18). 1732 RFC 793 contains an early example procedure for computing the RTO. 1733 This was then replaced by the algorithm described in RFC 1122, and 1734 subsequently updated in RFC 2988, and then again in RFC 6298. 1736 If a retransmitted packet is identical to the original packet (which 1737 implies not only that the data boundaries have not changed, but also 1738 that the window and acknowledgment fields of the header have not 1739 changed), then the same IP Identification field MAY be used (see 1740 Section 3.2.1.5 of RFC 1122) (MAY-4). 1742 3.8.2. TCP Congestion Control 1744 RFC 1122 required implementation of Van Jacobson's congestion control 1745 algorithm combining slow start with congestion avoidance. RFC 2581 1746 provided IETF Standards Track description of this, along with fast 1747 retransmit and fast recovery. RFC 5681 is the current description of 1748 these algorithms and is the current standard for TCP congestion 1749 control. 1751 A TCP MUST implement RFC 5681 (MUST-19). 1753 Explicit Congestion Notification (ECN) was defined in RFC 3168 and is 1754 an IETF Standards Track enhancement that has many benefits [39]. 1756 A TCP SHOULD implement ECN as described in RFC 3168 (SHLD-8). 1758 3.8.3. TCP Connection Failures 1760 Excessive retransmission of the same segment by TCP indicates some 1761 failure of the remote host or the Internet path. This failure may be 1762 of short or long duration. The following procedure MUST be used to 1763 handle excessive retransmissions of data segments (MUST-20): 1765 (a) There are two thresholds R1 and R2 measuring the amount of 1766 retransmission that has occurred for the same segment. R1 and R2 1767 might be measured in time units or as a count of retransmissions. 1769 (b) When the number of transmissions of the same segment reaches 1770 or exceeds threshold R1, pass negative advice (see [14] 1771 Section 3.3.1.4) to the IP layer, to trigger dead-gateway 1772 diagnosis. 1774 (c) When the number of transmissions of the same segment reaches a 1775 threshold R2 greater than R1, close the connection. 1777 (d) An application MUST (MUST-21) be able to set the value for R2 1778 for a particular connection. For example, an interactive 1779 application might set R2 to "infinity," giving the user control 1780 over when to disconnect. 1782 (d) TCP SHOULD inform the application of the delivery problem 1783 (unless such information has been disabled by the application; see 1784 Asynchronous Reports section), when R1 is reached and before R2 1785 (SHLD-9). This will allow a remote login (User Telnet) 1786 application program to inform the user, for example. 1788 The value of R1 SHOULD correspond to at least 3 retransmissions, at 1789 the current RTO (SHLD-10). The value of R2 SHOULD correspond to at 1790 least 100 seconds (SHLD-11). 1792 An attempt to open a TCP connection could fail with excessive 1793 retransmissions of the SYN segment or by receipt of a RST segment or 1794 an ICMP Port Unreachable. SYN retransmissions MUST be handled in the 1795 general way just described for data retransmissions, including 1796 notification of the application layer. 1798 However, the values of R1 and R2 may be different for SYN and data 1799 segments. In particular, R2 for a SYN segment MUST be set large 1800 enough to provide retransmission of the segment for at least 3 1801 minutes. The application can close the connection (i.e., give up on 1802 the open attempt) sooner, of course. 1804 3.8.4. TCP Keep-Alives 1806 Implementors MAY include "keep-alives" in their TCP implementations 1807 (MAY-5), although this practice is not universally accepted. If 1808 keep-alives are included, the application MUST be able to turn them 1809 on or off for each TCP connection (MUST-24), and they MUST default to 1810 off (MUST-25). 1812 Keep-alive packets MUST only be sent when no data or acknowledgement 1813 packets have been received for the connection within an interval 1814 (MUST-26). This interval MUST be configurable (MUST-27) and MUST 1815 default to no less than two hours (MUST-28). 1817 It is extremely important to remember that ACK segments that contain 1818 no data are not reliably transmitted by TCP. Consequently, if a 1819 keep-alive mechanism is implemented it MUST NOT interpret failure to 1820 respond to any specific probe as a dead connection (MUST-29). 1822 An implementation SHOULD send a keep-alive segment with no data 1823 (SHLD-12); however, it MAY be configurable to send a keep-alive 1824 segment containing one garbage octet (MAY-6), for compatibility with 1825 erroneous TCP implementations. 1827 3.8.5. The Communication of Urgent Information 1829 As a result of implementation differences and middlebox interactions, 1830 new applications SHOULD NOT employ the TCP urgent mechanism (SHLD- 1831 13). However, TCP implementations MUST still include support for the 1832 urgent mechanism (MUST-30). Details can be found in RFC 6093 [29]. 1834 The objective of the TCP urgent mechanism is to allow the sending 1835 user to stimulate the receiving user to accept some urgent data and 1836 to permit the receiving TCP to indicate to the receiving user when 1837 all the currently known urgent data has been received by the user. 1839 This mechanism permits a point in the data stream to be designated as 1840 the end of urgent information. Whenever this point is in advance of 1841 the receive sequence number (RCV.NXT) at the receiving TCP, that TCP 1842 must tell the user to go into "urgent mode"; when the receive 1843 sequence number catches up to the urgent pointer, the TCP must tell 1844 user to go into "normal mode". If the urgent pointer is updated 1845 while the user is in "urgent mode", the update will be invisible to 1846 the user. 1848 The method employs a urgent field which is carried in all segments 1849 transmitted. The URG control flag indicates that the urgent field is 1850 meaningful and must be added to the segment sequence number to yield 1851 the urgent pointer. The absence of this flag indicates that there is 1852 no urgent data outstanding. 1854 To send an urgent indication the user must also send at least one 1855 data octet. If the sending user also indicates a push, timely 1856 delivery of the urgent information to the destination process is 1857 enhanced. 1859 A TCP MUST support a sequence of urgent data of any length (MUST-31). 1860 [14] 1862 The urgent pointer MUST point to the sequence number of the octet 1863 following the urgent data (MUST-62). 1865 A TCP MUST (MUST-32) inform the application layer asynchronously 1866 whenever it receives an Urgent pointer and there was previously no 1867 pending urgent data, or whenvever the Urgent pointer advances in the 1868 data stream. There MUST (MUST-33) be a way for the application to 1869 learn how much urgent data remains to be read from the connection, or 1870 at least to determine whether or not more urgent data remains to be 1871 read. [14] 1873 3.8.6. Managing the Window 1875 The window sent in each segment indicates the range of sequence 1876 numbers the sender of the window (the data receiver) is currently 1877 prepared to accept. There is an assumption that this is related to 1878 the currently available data buffer space available for this 1879 connection. 1881 The sending TCP packages the data to be transmitted into segments 1882 which fit the current window, and may repackage segments on the 1883 retransmission queue. Such repackaging is not required, but may be 1884 helpful. 1886 In a connection with a one-way data flow, the window information will 1887 be carried in acknowledgment segments that all have the same sequence 1888 number so there will be no way to reorder them if they arrive out of 1889 order. This is not a serious problem, but it will allow the window 1890 information to be on occasion temporarily based on old reports from 1891 the data receiver. A refinement to avoid this problem is to act on 1892 the window information from segments that carry the highest 1893 acknowledgment number (that is segments with acknowledgment number 1894 equal or greater than the highest previously received). 1896 Indicating a large window encourages transmissions. If more data 1897 arrives than can be accepted, it will be discarded. This will result 1898 in excessive retransmissions, adding unnecessarily to the load on the 1899 network and the TCPs. Indicating a small window may restrict the 1900 transmission of data to the point of introducing a round trip delay 1901 between each new segment transmitted. 1903 The mechanisms provided allow a TCP to advertise a large window and 1904 to subsequently advertise a much smaller window without having 1905 accepted that much data. This, so called "shrinking the window," is 1906 strongly discouraged. The robustness principle dictates that TCPs 1907 will not shrink the window themselves, but will be prepared for such 1908 behavior on the part of other TCPs. 1910 A TCP receiver SHOULD NOT shrink the window, i.e., move the right 1911 window edge to the left (SHLD-14). However, a sending TCP MUST be 1912 robust against window shrinking, which may cause the "useable window" 1913 (see Section 3.8.6.2.1) to become negative (MUST-34). 1915 If this happens, the sender SHOULD NOT send new data (SHLD-15), but 1916 SHOULD retransmit normally the old unacknowledged data between 1917 SND.UNA and SND.UNA+SND.WND (SHLD-16). The sender MAY also 1918 retransmit old data beyond SND.UNA+SND.WND (MAY-7), but SHOULD NOT 1919 time out the connection if data beyond the right window edge is not 1920 acknowledged (SHLD-17). If the window shrinks to zero, the TCP MUST 1921 probe it in the standard way (described below) (MUST-35). 1923 3.8.6.1. Zero Window Probing 1925 The sending TCP must be prepared to accept from the user and send at 1926 least one octet of new data even if the send window is zero. The 1927 sending TCP must regularly retransmit to the receiving TCP even when 1928 the window is zero, in order to "probe" the window. Two minutes is 1929 recommended for the retransmission interval when the window is zero. 1930 This retransmission is essential to guarantee that when either TCP 1931 has a zero window the re-opening of the window will be reliably 1932 reported to the other. This is referred to as Zero-Window Probing 1933 (ZWP) in other documents. 1935 Probing of zero (offered) windows MUST be supported (MUST-36). 1937 A TCP MAY keep its offered receive window closed indefinitely (MAY- 1938 8). As long as the receiving TCP continues to send acknowledgments 1939 in response to the probe segments, the sending TCP MUST allow the 1940 connection to stay open (MUST-37). This enables TCP to function in 1941 scenarios such as the "printer ran out of paper" situation described 1942 in Section 4.2.2.17 of RFC1122. The behavior is subject to the 1943 implementation's resource management concerns, as noted in [31]. 1945 When the receiving TCP has a zero window and a segment arrives it 1946 must still send an acknowledgment showing its next expected sequence 1947 number and current window (zero). 1949 The transmitting host SHOULD send the first zero-window probe when a 1950 zero window has existed for the retransmission timeout period (SHLD- 1951 29) (see Section 3.8.1), and SHOULD increase exponentially the 1952 interval between successive probes (SHLD-30). 1954 3.8.6.2. Silly Window Syndrome Avoidance 1956 The "Silly Window Syndrome" (SWS) is a stable pattern of small 1957 incremental window movements resulting in extremely poor TCP 1958 performance. Algorithms to avoid SWS are described below for both 1959 the sending side and the receiving side. RFC 1122 contains more 1960 detailed discussion of the SWS problem. Note that the Nagle 1961 algorithm and the sender SWS avoidance algorithm play complementary 1962 roles in improving performance. The Nagle algorithm discourages 1963 sending tiny segments when the data to be sent increases in small 1964 increments, while the SWS avoidance algorithm discourages small 1965 segments resulting from the right window edge advancing in small 1966 increments. 1968 3.8.6.2.1. Sender's Algorithm - When to Send Data 1970 A TCP MUST include a SWS avoidance algorithm in the sender (MUST-38). 1972 A TCP SHOULD implement the Nagle Algorithm to coalesce short segments 1973 (SHLD-7). However, there MUST be a way for an application to disable 1974 the Nagle algorithm on an individual connection (MUST-17). In all 1975 cases, sending data is also subject to the limitation imposed by the 1976 Slow Start algorithm. 1978 The sender's SWS avoidance algorithm is more difficult than the 1979 receivers's, because the sender does not know (directly) the 1980 receiver's total buffer space RCV.BUFF. An approach which has been 1981 found to work well is for the sender to calculate Max(SND.WND), the 1982 maximum send window it has seen so far on the connection, and to use 1983 this value as an estimate of RCV.BUFF. Unfortunately, this can only 1984 be an estimate; the receiver may at any time reduce the size of 1985 RCV.BUFF. To avoid a resulting deadlock, it is necessary to have a 1986 timeout to force transmission of data, overriding the SWS avoidance 1987 algorithm. In practice, this timeout should seldom occur. 1989 The "useable window" is: 1991 U = SND.UNA + SND.WND - SND.NXT 1993 i.e., the offered window less the amount of data sent but not 1994 acknowledged. If D is the amount of data queued in the sending TCP 1995 but not yet sent, then the following set of rules is recommended. 1997 Send data: 1999 (1) if a maximum-sized segment can be sent, i.e, if: 2001 min(D,U) >= Eff.snd.MSS; 2003 (2) or if the data is pushed and all queued data can be sent now, 2004 i.e., if: 2006 [SND.NXT = SND.UNA and] PUSHED and D <= U 2008 (the bracketed condition is imposed by the Nagle algorithm); 2010 (3) or if at least a fraction Fs of the maximum window can be sent, 2011 i.e., if: 2013 [SND.NXT = SND.UNA and] 2015 min(D.U) >= Fs * Max(SND.WND); 2017 (4) or if data is PUSHed and the override timeout occurs. 2019 Here Fs is a fraction whose recommended value is 1/2. The override 2020 timeout should be in the range 0.1 - 1.0 seconds. It may be 2021 convenient to combine this timer with the timer used to probe zero 2022 windows (Section Section 3.8.6.1). 2024 3.8.6.2.2. Receiver's Algorithm - When to Send a Window Update 2026 A TCP MUST include a SWS avoidance algorithm in the receiver (MUST- 2027 39). 2029 The receiver's SWS avoidance algorithm determines when the right 2030 window edge may be advanced; this is customarily known as "updating 2031 the window". This algorithm combines with the delayed ACK algorithm 2032 (see Section 3.8.6.3) to determine when an ACK segment containing the 2033 current window will really be sent to the receiver. 2035 The solution to receiver SWS is to avoid advancing the right window 2036 edge RCV.NXT+RCV.WND in small increments, even if data is received 2037 from the network in small segments. 2039 Suppose the total receive buffer space is RCV.BUFF. At any given 2040 moment, RCV.USER octets of this total may be tied up with data that 2041 has been received and acknowledged but which the user process has not 2042 yet consumed. When the connection is quiescent, RCV.WND = RCV.BUFF 2043 and RCV.USER = 0. 2045 Keeping the right window edge fixed as data arrives and is 2046 acknowledged requires that the receiver offer less than its full 2047 buffer space, i.e., the receiver must specify a RCV.WND that keeps 2048 RCV.NXT+RCV.WND constant as RCV.NXT increases. Thus, the total 2049 buffer space RCV.BUFF is generally divided into three parts: 2051 |<------- RCV.BUFF ---------------->| 2052 1 2 3 2053 ----|---------|------------------|------|---- 2054 RCV.NXT ^ 2055 (Fixed) 2057 1 - RCV.USER = data received but not yet consumed; 2058 2 - RCV.WND = space advertised to sender; 2059 3 - Reduction = space available but not yet 2060 advertised. 2062 The suggested SWS avoidance algorithm for the receiver is to keep 2063 RCV.NXT+RCV.WND fixed until the reduction satisfies: 2065 RCV.BUFF - RCV.USER - RCV.WND >= 2067 min( Fr * RCV.BUFF, Eff.snd.MSS ) 2069 where Fr is a fraction whose recommended value is 1/2, and 2070 Eff.snd.MSS is the effective send MSS for the connection (see 2071 Section 3.7.1). When the inequality is satisfied, RCV.WND is set to 2072 RCV.BUFF-RCV.USER. 2074 Note that the general effect of this algorithm is to advance RCV.WND 2075 in increments of Eff.snd.MSS (for realistic receive buffers: 2076 Eff.snd.MSS < RCV.BUFF/2). Note also that the receiver must use its 2077 own Eff.snd.MSS, assuming it is the same as the sender's. 2079 3.8.6.3. Delayed Acknowledgements - When to Send an ACK Segment 2081 A host that is receiving a stream of TCP data segments can increase 2082 efficiency in both the Internet and the hosts by sending fewer than 2083 one ACK (acknowledgment) segment per data segment received; this is 2084 known as a "delayed ACK". 2086 A TCP SHOULD implement a delayed ACK (SHLD-18), but an ACK should not 2087 be excessively delayed; in particular, the delay MUST be less than 2088 0.5 seconds (MUST-40), and in a stream of full-sized segments there 2089 SHOULD be an ACK for at least every second segment (SHLD-19). 2090 Excessive delays on ACK's can disturb the round-trip timing and 2091 packet "clocking" algorithms. 2093 3.9. Interfaces 2095 There are of course two interfaces of concern: the user/TCP interface 2096 and the TCP/lower-level interface. We have a fairly elaborate model 2097 of the user/TCP interface, but the interface to the lower level 2098 protocol module is left unspecified here, since it will be specified 2099 in detail by the specification of the lower level protocol. For the 2100 case that the lower level is IP we note some of the parameter values 2101 that TCPs might use. 2103 3.9.1. User/TCP Interface 2105 The following functional description of user commands to the TCP is, 2106 at best, fictional, since every operating system will have different 2107 facilities. Consequently, we must warn readers that different TCP 2108 implementations may have different user interfaces. However, all 2109 TCPs must provide a certain minimum set of services to guarantee that 2110 all TCP implementations can support the same protocol hierarchy. 2111 This section specifies the functional interfaces required of all TCP 2112 implementations. 2114 TCP User Commands 2116 The following sections functionally characterize a USER/TCP 2117 interface. The notation used is similar to most procedure or 2118 function calls in high level languages, but this usage is not 2119 meant to rule out trap type service calls (e.g., SVCs, UUOs, 2120 EMTs). 2122 The user commands described below specify the basic functions the 2123 TCP must perform to support interprocess communication. 2124 Individual implementations must define their own exact format, and 2125 may provide combinations or subsets of the basic functions in 2126 single calls. In particular, some implementations may wish to 2127 automatically OPEN a connection on the first SEND or RECEIVE 2128 issued by the user for a given connection. 2130 In providing interprocess communication facilities, the TCP must 2131 not only accept commands, but must also return information to the 2132 processes it serves. The latter consists of: 2134 (a) general information about a connection (e.g., interrupts, 2135 remote close, binding of unspecified foreign socket). 2137 (b) replies to specific user commands indicating success or 2138 various types of failure. 2140 Open 2142 Format: OPEN (local port, foreign socket, active/passive [, 2143 timeout] [, DiffServ field] [, security/compartment] [local IP 2144 address,] [, options]) -> local connection name 2146 We assume that the local TCP is aware of the identity of the 2147 processes it serves and will check the authority of the process 2148 to use the connection specified. Depending upon the 2149 implementation of the TCP, the local network and TCP 2150 identifiers for the source address will either be supplied by 2151 the TCP or the lower level protocol (e.g., IP). These 2152 considerations are the result of concern about security, to the 2153 extent that no TCP be able to masquerade as another one, and so 2154 on. Similarly, no process can masquerade as another without 2155 the collusion of the TCP. 2157 If the active/passive flag is set to passive, then this is a 2158 call to LISTEN for an incoming connection. A passive open may 2159 have either a fully specified foreign socket to wait for a 2160 particular connection or an unspecified foreign socket to wait 2161 for any call. A fully specified passive call can be made 2162 active by the subsequent execution of a SEND. 2164 A transmission control block (TCB) is created and partially 2165 filled in with data from the OPEN command parameters. 2167 Every passive OPEN call either creates a new connection record 2168 in LISTEN state, or it returns an error; it MUST NOT affect any 2169 previously created connection record (MUST-41). 2171 A TCP that supports multiple concurrent users MUST provide an 2172 OPEN call that will functionally allow an application to LISTEN 2173 on a port while a connection block with the same local port is 2174 in SYN-SENT or SYN-RECEIVED state (MUST-42). 2176 On an active OPEN command, the TCP will begin the procedure to 2177 synchronize (i.e., establish) the connection at once. 2179 The timeout, if present, permits the caller to set up a timeout 2180 for all data submitted to TCP. If data is not successfully 2181 delivered to the destination within the timeout period, the TCP 2182 will abort the connection. The present global default is five 2183 minutes. 2185 The TCP or some component of the operating system will verify 2186 the users authority to open a connection with the specified 2187 DiffServ field value or security/compartment. The absence of a 2188 DiffServ field value or security/compartment specification in 2189 the OPEN call indicates the default values must be used. 2191 TCP will accept incoming requests as matching only if the 2192 security/compartment information is exactly the same as that 2193 requested in the OPEN call. 2195 The DiffServ field value indicated by the user only impacts 2196 outgoing packets, may be altered en route through the network, 2197 and has no direct bearing or relation to received packets. 2199 A local connection name will be returned to the user by the 2200 TCP. The local connection name can then be used as a short 2201 hand term for the connection defined by the pair. 2204 The optional "local IP address" parameter MUST be supported to 2205 allow the specification of the local IP address (MUST-43). 2206 This enables applications that need to select the local IP 2207 address used when multihoming is present. 2209 A passive OPEN call with a specified "local IP address" 2210 parameter will await an incoming connection request to that 2211 address. If the parameter is unspecified, a passive OPEN will 2212 await an incoming connection request to any local IP address, 2213 and then bind the local IP address of the connection to the 2214 particular address that is used. 2216 For an active OPEN call, a specified "local IP address" 2217 parameter will be used for opening the connection. If the 2218 parameter is unspecified, the host will choose an appropriate 2219 local IP address (see RFC 1122 section 3.3.4.2). 2221 If an application on a multihomed host does not specify the 2222 local IP address when actively opening a TCP connection, then 2223 the TCP MUST ask the IP layer to select a local IP address 2224 before sending the (first) SYN (MUST-44). See the function 2225 GET_SRCADDR() in Section 3.4 of RFC 1122. 2227 At all other times, a previous segment has either been sent or 2228 received on this connection, and TCP MUST use the same local 2229 address is used that was used in those previous segments (MUST- 2230 45). 2232 A TCP implementation MUST reject as an error a local OPEN call 2233 for an invalid remote IP address (e.g., a broadcast or 2234 multicast address) (MUST-46). 2236 Send 2238 Format: SEND (local connection name, buffer address, byte 2239 count, PUSH flag (optional), URGENT flag [,timeout]) 2241 This call causes the data contained in the indicated user 2242 buffer to be sent on the indicated connection. If the 2243 connection has not been opened, the SEND is considered an 2244 error. Some implementations may allow users to SEND first; in 2245 which case, an automatic OPEN would be done. For example, this 2246 might be one way for application data to be included in SYN 2247 segments. If the calling process is not authorized to use this 2248 connection, an error is returned. 2250 A TCP MAY implement PUSH flags on SEND calls (MAY-15). If PUSH 2251 flags are not implemented, then the sending TCP: (1) MUST NOT 2252 buffer data indefinitely (MUST-60), and (2) MUST set the PSH 2253 bit in the last buffered segment (i.e., when there is no more 2254 queued data to be sent) (MUST-61). The remaining description 2255 below assumes the PUSH flag is supported on SEND calls. 2257 If the PUSH flag is set, the application intends the data to be 2258 transmitted promptly to the receiver, and the PUSH bit will be 2259 set in the last TCP segment created from the buffer. When an 2260 application issues a series of SEND calls without setting the 2261 PUSH flag, the TCP MAY aggregate the data internally without 2262 sending it (MAY-16). 2264 The PSH bit is not a record marker and is independent of 2265 segment boundaries. The transmitter SHOULD collapse successive 2266 bits when it packetizes data, to send the largest possible 2267 segment (SHLD-27). 2269 If the PUSH flag is not set, the data may be combined with data 2270 from subsequent SENDs for transmission efficiency. Note that 2271 when the Nagle algorithm is in use, TCP may buffer the data 2272 before sending, without regard to the PUSH flag (see 2273 Section 3.7.4). 2275 An application program is logically required to set the PUSH 2276 flag in a SEND call whenever it needs to force delivery of the 2277 data to avoid a communication deadlock. However, a TCP SHOULD 2278 send a maximum-sized segment whenever possible (SHLD-28), to 2279 improve performance (see Section 3.8.6.2.1). 2281 New applications SHOULD NOT set the URGENT flag [29] due to 2282 implementation differences and middlebox issues (SHLD-13). 2284 If the URGENT flag is set, segments sent to the destination TCP 2285 will have the urgent pointer set. The receiving TCP will 2286 signal the urgent condition to the receiving process if the 2287 urgent pointer indicates that data preceding the urgent pointer 2288 has not been consumed by the receiving process. The purpose of 2289 urgent is to stimulate the receiver to process the urgent data 2290 and to indicate to the receiver when all the currently known 2291 urgent data has been received. The number of times the sending 2292 user's TCP signals urgent will not necessarily be equal to the 2293 number of times the receiving user will be notified of the 2294 presence of urgent data. 2296 If no foreign socket was specified in the OPEN, but the 2297 connection is established (e.g., because a LISTENing connection 2298 has become specific due to a foreign segment arriving for the 2299 local socket), then the designated buffer is sent to the 2300 implied foreign socket. Users who make use of OPEN with an 2301 unspecified foreign socket can make use of SEND without ever 2302 explicitly knowing the foreign socket address. 2304 However, if a SEND is attempted before the foreign socket 2305 becomes specified, an error will be returned. Users can use 2306 the STATUS call to determine the status of the connection. In 2307 some implementations the TCP may notify the user when an 2308 unspecified socket is bound. 2310 If a timeout is specified, the current user timeout for this 2311 connection is changed to the new one. 2313 In the simplest implementation, SEND would not return control 2314 to the sending process until either the transmission was 2315 complete or the timeout had been exceeded. However, this 2316 simple method is both subject to deadlocks (for example, both 2317 sides of the connection might try to do SENDs before doing any 2318 RECEIVEs) and offers poor performance, so it is not 2319 recommended. A more sophisticated implementation would return 2320 immediately to allow the process to run concurrently with 2321 network I/O, and, furthermore, to allow multiple SENDs to be in 2322 progress. Multiple SENDs are served in first come, first 2323 served order, so the TCP will queue those it cannot service 2324 immediately. 2326 We have implicitly assumed an asynchronous user interface in 2327 which a SEND later elicits some kind of SIGNAL or pseudo- 2328 interrupt from the serving TCP. An alternative is to return a 2329 response immediately. For instance, SENDs might return 2330 immediate local acknowledgment, even if the segment sent had 2331 not been acknowledged by the distant TCP. We could 2332 optimistically assume eventual success. If we are wrong, the 2333 connection will close anyway due to the timeout. In 2334 implementations of this kind (synchronous), there will still be 2335 some asynchronous signals, but these will deal with the 2336 connection itself, and not with specific segments or buffers. 2338 In order for the process to distinguish among error or success 2339 indications for different SENDs, it might be appropriate for 2340 the buffer address to be returned along with the coded response 2341 to the SEND request. TCP-to-user signals are discussed below, 2342 indicating the information which should be returned to the 2343 calling process. 2345 Receive 2347 Format: RECEIVE (local connection name, buffer address, byte 2348 count) -> byte count, urgent flag, push flag (optional) 2350 This command allocates a receiving buffer associated with the 2351 specified connection. If no OPEN precedes this command or the 2352 calling process is not authorized to use this connection, an 2353 error is returned. 2355 In the simplest implementation, control would not return to the 2356 calling program until either the buffer was filled, or some 2357 error occurred, but this scheme is highly subject to deadlocks. 2358 A more sophisticated implementation would permit several 2359 RECEIVEs to be outstanding at once. These would be filled as 2360 segments arrive. This strategy permits increased throughput at 2361 the cost of a more elaborate scheme (possibly asynchronous) to 2362 notify the calling program that a PUSH has been seen or a 2363 buffer filled. 2365 A TCP receiver MAY pass a received PSH flag to the application 2366 layer via the PUSH flag in the interface (MAY-17), but it is 2367 not required (this was clarified in RFC 1122 section 4.2.2.2). 2368 The remainder of text describing the RECEIVE call below assumes 2369 that passing the PUSH indication is supported. 2371 If enough data arrive to fill the buffer before a PUSH is seen, 2372 the PUSH flag will not be set in the response to the RECEIVE. 2373 The buffer will be filled with as much data as it can hold. If 2374 a PUSH is seen before the buffer is filled the buffer will be 2375 returned partially filled and PUSH indicated. 2377 If there is urgent data the user will have been informed as 2378 soon as it arrived via a TCP-to-user signal. The receiving 2379 user should thus be in "urgent mode". If the URGENT flag is 2380 on, additional urgent data remains. If the URGENT flag is off, 2381 this call to RECEIVE has returned all the urgent data, and the 2382 user may now leave "urgent mode". Note that data following the 2383 urgent pointer (non-urgent data) cannot be delivered to the 2384 user in the same buffer with preceding urgent data unless the 2385 boundary is clearly marked for the user. 2387 To distinguish among several outstanding RECEIVEs and to take 2388 care of the case that a buffer is not completely filled, the 2389 return code is accompanied by both a buffer pointer and a byte 2390 count indicating the actual length of the data received. 2392 Alternative implementations of RECEIVE might have the TCP 2393 allocate buffer storage, or the TCP might share a ring buffer 2394 with the user. 2396 Close 2398 Format: CLOSE (local connection name) 2400 This command causes the connection specified to be closed. If 2401 the connection is not open or the calling process is not 2402 authorized to use this connection, an error is returned. 2403 Closing connections is intended to be a graceful operation in 2404 the sense that outstanding SENDs will be transmitted (and 2405 retransmitted), as flow control permits, until all have been 2406 serviced. Thus, it should be acceptable to make several SEND 2407 calls, followed by a CLOSE, and expect all the data to be sent 2408 to the destination. It should also be clear that users should 2409 continue to RECEIVE on CLOSING connections, since the other 2410 side may be trying to transmit the last of its data. Thus, 2411 CLOSE means "I have no more to send" but does not mean "I will 2412 not receive any more." It may happen (if the user level 2413 protocol is not well thought out) that the closing side is 2414 unable to get rid of all its data before timing out. In this 2415 event, CLOSE turns into ABORT, and the closing TCP gives up. 2417 The user may CLOSE the connection at any time on his own 2418 initiative, or in response to various prompts from the TCP 2419 (e.g., remote close executed, transmission timeout exceeded, 2420 destination inaccessible). 2422 Because closing a connection requires communication with the 2423 foreign TCP, connections may remain in the closing state for a 2424 short time. Attempts to reopen the connection before the TCP 2425 replies to the CLOSE command will result in error responses. 2427 Close also implies push function. 2429 Status 2431 Format: STATUS (local connection name) -> status data 2433 This is an implementation dependent user command and could be 2434 excluded without adverse effect. Information returned would 2435 typically come from the TCB associated with the connection. 2437 This command returns a data block containing the following 2438 information: 2440 local socket, 2441 foreign socket, 2442 local connection name, 2443 receive window, 2444 send window, 2445 connection state, 2446 number of buffers awaiting acknowledgment, 2447 number of buffers pending receipt, 2448 urgent state, 2449 DiffServ field value, 2450 security/compartment, 2451 and transmission timeout. 2453 Depending on the state of the connection, or on the 2454 implementation itself, some of this information may not be 2455 available or meaningful. If the calling process is not 2456 authorized to use this connection, an error is returned. This 2457 prevents unauthorized processes from gaining information about 2458 a connection. 2460 Abort 2462 Format: ABORT (local connection name) 2464 This command causes all pending SENDs and RECEIVES to be 2465 aborted, the TCB to be removed, and a special RESET message to 2466 be sent to the TCP on the other side of the connection. 2467 Depending on the implementation, users may receive abort 2468 indications for each outstanding SEND or RECEIVE, or may simply 2469 receive an ABORT-acknowledgment. 2471 Flush 2473 Some TCP implementations have included a FLUSH call, which will 2474 empty the TCP send queue of any data for which the user has 2475 issued SEND calls but which is still to the right of the 2476 current send window. That is, it flushes as much queued send 2477 data as possible without losing sequence number 2478 synchronization. The FLUSH call MAY be implemented (MAY-14). 2480 Asynchronous Reports 2482 There MUST be a mechanism for reporting soft TCP error 2483 conditions to the application (MUST-47). Generically, we 2484 assume this takes the form of an application-supplied 2485 ERROR_REPORT routine that may be upcalled asynchronously from 2486 the transport layer: 2488 ERROR_REPORT(local connection name, reason, subreason) 2490 The precise encoding of the reason and subreason parameters is 2491 not specified here. However, the conditions that are reported 2492 asynchronously to the application MUST include: 2494 * ICMP error message arrived (see Section 3.9.2.2 for 2495 description of handling each ICMP message type, since some 2496 message types need to be suppressed from generating reports 2497 to the application) 2499 * Excessive retransmissions (see Section 3.8.3) (TODO - the 2500 MUST here is inconsistent with SHOULD in the section 2501 describing excessive retransmissions. Both conflicting bits 2502 of text are direct from 1122) 2504 * Urgent pointer advance (see Section 3.8.5) (MUST-32). 2506 However, an application program that does not want to receive 2507 such ERROR_REPORT calls SHOULD be able to effectively disable 2508 these calls (SHLD-20). 2510 Set Differentiated Services Field (IPv4 TOS or IPv6 Traffic Class) 2512 The application layer MUST be able to specify the 2513 Differentiated Services field for segments that are sent on a 2514 connection (MUST-48). The Differentiated Services field 2515 includes the 6-bit Differentiated Services Code Point (DSCP) 2516 value. It is not required, but the application SHOULD be able 2517 to change the Differentiated Services field during the 2518 connection lifetime (SHLD-21). TCP SHOULD pass the current 2519 Differentiated Services field value without change to the IP 2520 layer, when it sends segments on the connection (SHLD-22). 2522 The Differentiated Services field will be specified 2523 independently in each direction on the connection, so that the 2524 receiver application will specify the Differentiated Services 2525 field used for ACK segments. 2527 TCP MAY pass the most recently received Differentiated Services 2528 field up to the application (MAY-9). 2530 3.9.2. TCP/Lower-Level Interface 2532 The TCP calls on a lower level protocol module to actually send and 2533 receive information over a network. The two current standard 2534 Internet Protocol (IP) versions layered below TCP are IPv4 [1] and 2535 IPv6 [5]. 2537 If the lower level protocol is IPv4 it provides arguments for a type 2538 of service (used within the Differentiated Services field) and for a 2539 time to live. TCP uses the following settings for these parameters: 2541 DiffServ field: The IP header value for the DiffServ field is 2542 given by the user. This includes the bits of the DiffServ Code 2543 Point (DSCP). 2545 Time to Live (TTL): The TTL value used to send TCP segments MUST 2546 be configurable (MUST-49). 2548 Note that RFC 793 specified one minute (60 seconds) as a 2549 constant for the TTL, because the assumed maximum segment 2550 lifetime was two minutes. This was intended to explicitly ask 2551 that a segment be destroyed if it cannot be delivered by the 2552 internet system within one minute. RFC 1122 changed this 2553 specification to require that the TTL be configurable. 2555 Note that the DiffServ field is permitted to change during a 2556 connection (section 4.2.4.2 of RFC 1122). However, the 2557 application interface might not support this ability, and the 2558 application does not have knowledge about individual TCP 2559 segments, so this can only be done on a coarse granularity, at 2560 best. This limitation is further discussed in RFC 7657 (sec 2561 5.1, 5.3, and 6) [38]. Generally, an application SHOULD NOT 2562 change the DiffServ field value during the course of a 2563 connection (SHLD-23). 2565 Any lower level protocol will have to provide the source address, 2566 destination address, and protocol fields, and some way to determine 2567 the "TCP length", both to provide the functional equivalent service 2568 of IP and to be used in the TCP checksum. 2570 When received options are passed up to TCP from the IP layer, TCP 2571 MUST ignore options that it does not understand (MUST-50). 2573 A TCP MAY support the Time Stamp (MAY-10) and Record Route (MAY-11) 2574 options. 2576 3.9.2.1. Source Routing 2578 If the lower level is IP (or other protocol that provides this 2579 feature) and source routing is used, the interface must allow the 2580 route information to be communicated. This is especially important 2581 so that the source and destination addresses used in the TCP checksum 2582 be the originating source and ultimate destination. It is also 2583 important to preserve the return route to answer connection requests. 2585 An application MUST be able to specify a source route when it 2586 actively opens a TCP connection (MUST-51), and this MUST take 2587 precedence over a source route received in a datagram (MUST-52). 2589 When a TCP connection is OPENed passively and a packet arrives with a 2590 completed IP Source Route option (containing a return route), TCP 2591 MUST save the return route and use it for all segments sent on this 2592 connection (MUST-53). If a different source route arrives in a later 2593 segment, the later definition SHOULD override the earlier one (SHLD- 2594 24). 2596 3.9.2.2. ICMP Messages 2598 TCP MUST act on an ICMP error message passed up from the IP layer, 2599 directing it to the connection that created the error (MUST-54). The 2600 necessary demultiplexing information can be found in the IP header 2601 contained within the ICMP message. 2603 This applies to ICMPv6 in addition to IPv4 ICMP. 2605 [23] contains discussion of specific ICMP and ICMPv6 messages 2606 classified as either "soft" or "hard" errors that may bear different 2607 responses. Treatment for classes of ICMP messages is described 2608 below: 2610 Source Quench 2611 TCP MUST silently discard any received ICMP Source Quench messages 2612 (MUST-55). See [11] for discussion. 2614 Soft Errors 2615 For ICMP these include: Destination Unreachable -- codes 0, 1, 5, 2616 Time Exceeded -- codes 0, 1, and Parameter Problem. 2617 For ICMPv6 these include: Destination Unreachable -- codes 0 and 3, 2618 Time Exceeded -- codes 0, 1, and Parameter Problem -- codes 0, 1, 2 2619 Since these Unreachable messages indicate soft error conditions, 2620 TCP MUST NOT abort the connection (MUST-56), and it SHOULD make the 2621 information available to the application (SHLD-25). 2623 Hard Errors 2624 For ICMP these include Destination Unreachable -- codes 2-4"> 2625 These are hard error conditions, so TCP SHOULD abort the connection 2626 (SHLD-26). [23] notes that some implementations do not abort 2627 connections when an ICMP hard error is received for a connection 2628 that is in any of the synchronized states. 2630 Note that [23] section 4 describes widespread implementation behavior 2631 that treats soft errors as hard errors during connection 2632 establishment. 2634 3.9.2.3. Remote Address Validation 2636 RFC 1122 requires addresses to be validated in incoming SYN packets: 2638 An incoming SYN with an invalid source address MUST be ignored 2639 either by TCP or by the IP layer (MUST-63) (see Section 3.2.1.3 of 2640 [14]). 2642 A TCP implementation MUST silently discard an incoming SYN segment 2643 that is addressed to a broadcast or multicast address (MUST-57). 2645 This prevents connection state and replies from being erroneously 2646 generated, and implementers should note that this guidance is 2647 applicable to all incoming segments, not just SYNs, as specifically 2648 indicated in RFC 1122. 2650 3.10. Event Processing 2652 The processing depicted in this section is an example of one possible 2653 implementation. Other implementations may have slightly different 2654 processing sequences, but they should differ from those in this 2655 section only in detail, not in substance. 2657 The activity of the TCP can be characterized as responding to events. 2658 The events that occur can be cast into three categories: user calls, 2659 arriving segments, and timeouts. This section describes the 2660 processing the TCP does in response to each of the events. In many 2661 cases the processing required depends on the state of the connection. 2663 Events that occur: 2665 User Calls 2667 OPEN 2668 SEND 2669 RECEIVE 2670 CLOSE 2671 ABORT 2672 STATUS 2674 Arriving Segments 2676 SEGMENT ARRIVES 2678 Timeouts 2680 USER TIMEOUT 2681 RETRANSMISSION TIMEOUT 2682 TIME-WAIT TIMEOUT 2684 The model of the TCP/user interface is that user commands receive an 2685 immediate return and possibly a delayed response via an event or 2686 pseudo interrupt. In the following descriptions, the term "signal" 2687 means cause a delayed response. 2689 Error responses are given as character strings. For example, user 2690 commands referencing connections that do not exist receive "error: 2691 connection not open". 2693 Please note in the following that all arithmetic on sequence numbers, 2694 acknowledgment numbers, windows, et cetera, is modulo 2**32 the size 2695 of the sequence number space. Also note that "=<" means less than or 2696 equal to (modulo 2**32). 2698 A natural way to think about processing incoming segments is to 2699 imagine that they are first tested for proper sequence number (i.e., 2700 that their contents lie in the range of the expected "receive window" 2701 in the sequence number space) and then that they are generally queued 2702 and processed in sequence number order. 2704 When a segment overlaps other already received segments we 2705 reconstruct the segment to contain just the new data, and adjust the 2706 header fields to be consistent. 2708 Note that if no state change is mentioned the TCP stays in the same 2709 state. 2711 OPEN Call 2713 CLOSED STATE (i.e., TCB does not exist) 2715 Create a new transmission control block (TCB) to hold 2716 connection state information. Fill in local socket identifier, 2717 foreign socket, DiffServ field, security/compartment, and user 2718 timeout information. Note that some parts of the foreign 2719 socket may be unspecified in a passive OPEN and are to be 2720 filled in by the parameters of the incoming SYN segment. 2721 Verify the security and DiffServ value requested are allowed 2722 for this user, if not return "error: precedence not allowed" or 2723 "error: security/compartment not allowed." If passive enter 2724 the LISTEN state and return. If active and the foreign socket 2725 is unspecified, return "error: foreign socket unspecified"; if 2726 active and the foreign socket is specified, issue a SYN 2727 segment. An initial send sequence number (ISS) is selected. A 2728 SYN segment of the form is sent. Set 2729 SND.UNA to ISS, SND.NXT to ISS+1, enter SYN-SENT state, and 2730 return. 2732 If the caller does not have access to the local socket 2733 specified, return "error: connection illegal for this process". 2734 If there is no room to create a new connection, return "error: 2735 insufficient resources". 2737 LISTEN STATE 2739 If active and the foreign socket is specified, then change the 2740 connection from passive to active, select an ISS. Send a SYN 2741 segment, set SND.UNA to ISS, SND.NXT to ISS+1. Enter SYN-SENT 2742 state. Data associated with SEND may be sent with SYN segment 2743 or queued for transmission after entering ESTABLISHED state. 2744 The urgent bit if requested in the command must be sent with 2745 the data segments sent as a result of this command. If there 2746 is no room to queue the request, respond with "error: 2747 insufficient resources". If Foreign socket was not specified, 2748 then return "error: foreign socket unspecified". 2750 SYN-SENT STATE 2751 SYN-RECEIVED STATE 2752 ESTABLISHED STATE 2753 FIN-WAIT-1 STATE 2754 FIN-WAIT-2 STATE 2755 CLOSE-WAIT STATE 2756 CLOSING STATE 2757 LAST-ACK STATE 2758 TIME-WAIT STATE 2760 Return "error: connection already exists". 2762 SEND Call 2764 CLOSED STATE (i.e., TCB does not exist) 2766 If the user does not have access to such a connection, then 2767 return "error: connection illegal for this process". 2769 Otherwise, return "error: connection does not exist". 2771 LISTEN STATE 2773 If the foreign socket is specified, then change the connection 2774 from passive to active, select an ISS. Send a SYN segment, set 2775 SND.UNA to ISS, SND.NXT to ISS+1. Enter SYN-SENT state. Data 2776 associated with SEND may be sent with SYN segment or queued for 2777 transmission after entering ESTABLISHED state. The urgent bit 2778 if requested in the command must be sent with the data segments 2779 sent as a result of this command. If there is no room to queue 2780 the request, respond with "error: insufficient resources". If 2781 Foreign socket was not specified, then return "error: foreign 2782 socket unspecified". 2784 SYN-SENT STATE 2785 SYN-RECEIVED STATE 2787 Queue the data for transmission after entering ESTABLISHED 2788 state. If no space to queue, respond with "error: insufficient 2789 resources". 2791 ESTABLISHED STATE 2792 CLOSE-WAIT STATE 2794 Segmentize the buffer and send it with a piggybacked 2795 acknowledgment (acknowledgment value = RCV.NXT). If there is 2796 insufficient space to remember this buffer, simply return 2797 "error: insufficient resources". 2799 If the urgent flag is set, then SND.UP <- SND.NXT and set the 2800 urgent pointer in the outgoing segments. 2802 FIN-WAIT-1 STATE 2803 FIN-WAIT-2 STATE 2804 CLOSING STATE 2805 LAST-ACK STATE 2806 TIME-WAIT STATE 2808 Return "error: connection closing" and do not service request. 2810 RECEIVE Call 2812 CLOSED STATE (i.e., TCB does not exist) 2814 If the user does not have access to such a connection, return 2815 "error: connection illegal for this process". 2817 Otherwise return "error: connection does not exist". 2819 LISTEN STATE 2820 SYN-SENT STATE 2821 SYN-RECEIVED STATE 2823 Queue for processing after entering ESTABLISHED state. If 2824 there is no room to queue this request, respond with "error: 2825 insufficient resources". 2827 ESTABLISHED STATE 2828 FIN-WAIT-1 STATE 2829 FIN-WAIT-2 STATE 2831 If insufficient incoming segments are queued to satisfy the 2832 request, queue the request. If there is no queue space to 2833 remember the RECEIVE, respond with "error: insufficient 2834 resources". 2836 Reassemble queued incoming segments into receive buffer and 2837 return to user. Mark "push seen" (PUSH) if this is the case. 2839 If RCV.UP is in advance of the data currently being passed to 2840 the user notify the user of the presence of urgent data. 2842 When the TCP takes responsibility for delivering data to the 2843 user that fact must be communicated to the sender via an 2844 acknowledgment. The formation of such an acknowledgment is 2845 described below in the discussion of processing an incoming 2846 segment. 2848 CLOSE-WAIT STATE 2850 Since the remote side has already sent FIN, RECEIVEs must be 2851 satisfied by text already on hand, but not yet delivered to the 2852 user. If no text is awaiting delivery, the RECEIVE will get a 2853 "error: connection closing" response. Otherwise, any remaining 2854 text can be used to satisfy the RECEIVE. 2856 CLOSING STATE 2857 LAST-ACK STATE 2858 TIME-WAIT STATE 2860 Return "error: connection closing". 2862 CLOSE Call 2864 CLOSED STATE (i.e., TCB does not exist) 2866 If the user does not have access to such a connection, return 2867 "error: connection illegal for this process". 2869 Otherwise, return "error: connection does not exist". 2871 LISTEN STATE 2873 Any outstanding RECEIVEs are returned with "error: closing" 2874 responses. Delete TCB, enter CLOSED state, and return. 2876 SYN-SENT STATE 2878 Delete the TCB and return "error: closing" responses to any 2879 queued SENDs, or RECEIVEs. 2881 SYN-RECEIVED STATE 2883 If no SENDs have been issued and there is no pending data to 2884 send, then form a FIN segment and send it, and enter FIN-WAIT-1 2885 state; otherwise queue for processing after entering 2886 ESTABLISHED state. 2888 ESTABLISHED STATE 2890 Queue this until all preceding SENDs have been segmentized, 2891 then form a FIN segment and send it. In any case, enter FIN- 2892 WAIT-1 state. 2894 FIN-WAIT-1 STATE 2895 FIN-WAIT-2 STATE 2897 Strictly speaking, this is an error and should receive a 2898 "error: connection closing" response. An "ok" response would 2899 be acceptable, too, as long as a second FIN is not emitted (the 2900 first FIN may be retransmitted though). 2902 CLOSE-WAIT STATE 2904 Queue this request until all preceding SENDs have been 2905 segmentized; then send a FIN segment, enter LAST-ACK state. 2907 CLOSING STATE 2908 LAST-ACK STATE 2909 TIME-WAIT STATE 2910 Respond with "error: connection closing". 2912 ABORT Call 2914 CLOSED STATE (i.e., TCB does not exist) 2916 If the user should not have access to such a connection, return 2917 "error: connection illegal for this process". 2919 Otherwise return "error: connection does not exist". 2921 LISTEN STATE 2923 Any outstanding RECEIVEs should be returned with "error: 2924 connection reset" responses. Delete TCB, enter CLOSED state, 2925 and return. 2927 SYN-SENT STATE 2929 All queued SENDs and RECEIVEs should be given "connection 2930 reset" notification, delete the TCB, enter CLOSED state, and 2931 return. 2933 SYN-RECEIVED STATE 2934 ESTABLISHED STATE 2935 FIN-WAIT-1 STATE 2936 FIN-WAIT-2 STATE 2937 CLOSE-WAIT STATE 2939 Send a reset segment: 2941 2943 All queued SENDs and RECEIVEs should be given "connection 2944 reset" notification; all segments queued for transmission 2945 (except for the RST formed above) or retransmission should be 2946 flushed, delete the TCB, enter CLOSED state, and return. 2948 CLOSING STATE LAST-ACK STATE TIME-WAIT STATE 2950 Respond with "ok" and delete the TCB, enter CLOSED state, and 2951 return. 2953 STATUS Call 2955 CLOSED STATE (i.e., TCB does not exist) 2957 If the user should not have access to such a connection, return 2958 "error: connection illegal for this process". 2960 Otherwise return "error: connection does not exist". 2962 LISTEN STATE 2964 Return "state = LISTEN", and the TCB pointer. 2966 SYN-SENT STATE 2968 Return "state = SYN-SENT", and the TCB pointer. 2970 SYN-RECEIVED STATE 2972 Return "state = SYN-RECEIVED", and the TCB pointer. 2974 ESTABLISHED STATE 2976 Return "state = ESTABLISHED", and the TCB pointer. 2978 FIN-WAIT-1 STATE 2980 Return "state = FIN-WAIT-1", and the TCB pointer. 2982 FIN-WAIT-2 STATE 2984 Return "state = FIN-WAIT-2", and the TCB pointer. 2986 CLOSE-WAIT STATE 2988 Return "state = CLOSE-WAIT", and the TCB pointer. 2990 CLOSING STATE 2992 Return "state = CLOSING", and the TCB pointer. 2994 LAST-ACK STATE 2996 Return "state = LAST-ACK", and the TCB pointer. 2998 TIME-WAIT STATE 3000 Return "state = TIME-WAIT", and the TCB pointer. 3002 SEGMENT ARRIVES 3004 If the state is CLOSED (i.e., TCB does not exist) then 3006 all data in the incoming segment is discarded. An incoming 3007 segment containing a RST is discarded. An incoming segment not 3008 containing a RST causes a RST to be sent in response. The 3009 acknowledgment and sequence field values are selected to make 3010 the reset sequence acceptable to the TCP that sent the 3011 offending segment. 3013 If the ACK bit is off, sequence number zero is used, 3015 3017 If the ACK bit is on, 3019 3021 Return. 3023 If the state is LISTEN then 3025 first check for an RST 3027 An incoming RST should be ignored. Return. 3029 second check for an ACK 3031 Any acknowledgment is bad if it arrives on a connection 3032 still in the LISTEN state. An acceptable reset segment 3033 should be formed for any arriving ACK-bearing segment. The 3034 RST should be formatted as follows: 3036 3038 Return. 3040 third check for a SYN 3042 If the SYN bit is set, check the security. If the security/ 3043 compartment on the incoming segment does not exactly match 3044 the security/compartment in the TCB then send a reset and 3045 return. 3047 3049 Set RCV.NXT to SEG.SEQ+1, IRS is set to SEG.SEQ and any 3050 other control or text should be queued for processing later. 3051 ISS should be selected and a SYN segment sent of the form: 3053 3055 SND.NXT is set to ISS+1 and SND.UNA to ISS. The connection 3056 state should be changed to SYN-RECEIVED. Note that any 3057 other incoming control or data (combined with SYN) will be 3058 processed in the SYN-RECEIVED state, but processing of SYN 3059 and ACK should not be repeated. If the listen was not fully 3060 specified (i.e., the foreign socket was not fully 3061 specified), then the unspecified fields should be filled in 3062 now. 3064 fourth other text or control 3066 Any other control or text-bearing segment (not containing 3067 SYN) must have an ACK and thus would be discarded by the ACK 3068 processing. An incoming RST segment could not be valid, 3069 since it could not have been sent in response to anything 3070 sent by this incarnation of the connection. So you are 3071 unlikely to get here, but if you do, drop the segment, and 3072 return. 3074 If the state is SYN-SENT then 3076 first check the ACK bit 3078 If the ACK bit is set 3080 If SEG.ACK =< ISS, or SEG.ACK > SND.NXT, send a reset 3081 (unless the RST bit is set, if so drop the segment and 3082 return) 3084 3086 and discard the segment. Return. 3088 If SND.UNA < SEG.ACK =< SND.NXT then the ACK is 3089 acceptable. Some deployed TCP code has used the check 3090 SEG.ACK == SND.NXT (using "==" rather than "=<", but this 3091 is not appropriate when the stack is capable of sending 3092 data on the SYN, because the peer TCP may not accept and 3093 acknowledge all of the data on the SYN. 3095 second check the RST bit 3096 If the RST bit is set 3098 A potential blind reset attack is described in RFC 5961 3099 [28], with the mitigation that a TCP implementation 3100 SHOULD first check that the sequence number exactly 3101 matches RCV.NXT prior to executing the action in the next 3102 paragraph. 3104 If the ACK was acceptable then signal the user "error: 3105 connection reset", drop the segment, enter CLOSED state, 3106 delete TCB, and return. Otherwise (no ACK) drop the 3107 segment and return. 3109 third check the security 3111 If the security/compartment in the segment does not exactly 3112 match the security/compartment in the TCB, send a reset 3114 If there is an ACK 3116 3118 Otherwise 3120 3122 If a reset was sent, discard the segment and return. 3124 fourth check the SYN bit 3126 This step should be reached only if the ACK is ok, or there 3127 is no ACK, and it the segment did not contain a RST. 3129 If the SYN bit is on and the security/compartment is 3130 acceptable then, RCV.NXT is set to SEG.SEQ+1, IRS is set to 3131 SEG.SEQ. SND.UNA should be advanced to equal SEG.ACK (if 3132 there is an ACK), and any segments on the retransmission 3133 queue which are thereby acknowledged should be removed. 3135 If SND.UNA > ISS (our SYN has been ACKed), change the 3136 connection state to ESTABLISHED, form an ACK segment 3138 3140 and send it. Data or controls which were queued for 3141 transmission may be included. If there are other controls 3142 or text in the segment then continue processing at the sixth 3143 step below where the URG bit is checked, otherwise return. 3145 Otherwise enter SYN-RECEIVED, form a SYN,ACK segment 3147 3149 and send it. Set the variables: 3151 SND.WND <- SEG.WND 3152 SND.WL1 <- SEG.SEQ 3153 SND.WL2 <- SEG.ACK 3155 If there are other controls or text in the segment, queue 3156 them for processing after the ESTABLISHED state has been 3157 reached, return. 3159 Note that it is legal to send and receive application data 3160 on SYN segments (this is the "text in the segment" mentioned 3161 above. There has been significant misinformation and 3162 misunderstanding of this topic historically. Some firewalls 3163 and security devices consider this suspicious. However, the 3164 capability was used in T/TCP [16] and is used in TCP Fast 3165 Open (TFO) [36], so is important for implementations and 3166 network devices to permit. 3168 fifth, if neither of the SYN or RST bits is set then drop the 3169 segment and return. 3171 Otherwise, 3173 first check sequence number 3175 SYN-RECEIVED STATE 3176 ESTABLISHED STATE 3177 FIN-WAIT-1 STATE 3178 FIN-WAIT-2 STATE 3179 CLOSE-WAIT STATE 3180 CLOSING STATE 3181 LAST-ACK STATE 3182 TIME-WAIT STATE 3184 Segments are processed in sequence. Initial tests on 3185 arrival are used to discard old duplicates, but further 3186 processing is done in SEG.SEQ order. If a segment's 3187 contents straddle the boundary between old and new, only the 3188 new parts should be processed. 3190 In general, the processing of received segments MUST be 3191 implemented to aggregate ACK segments whenever possible 3192 (MUST-58). For example, if the TCP is processing a series 3193 of queued segments, it MUST process them all before sending 3194 any ACK segments (MUST-59). 3196 There are four cases for the acceptability test for an 3197 incoming segment: 3199 Segment Receive Test 3200 Length Window 3201 ------- ------- ------------------------------------------- 3203 0 0 SEG.SEQ = RCV.NXT 3205 0 >0 RCV.NXT =< SEG.SEQ < RCV.NXT+RCV.WND 3207 >0 0 not acceptable 3209 >0 >0 RCV.NXT =< SEG.SEQ < RCV.NXT+RCV.WND 3210 or RCV.NXT =< SEG.SEQ+SEG.LEN-1 < RCV.NXT+RCV.WND 3212 In implementing sequence number validation as described 3213 here, please note Appendix A.2. 3215 If the RCV.WND is zero, no segments will be acceptable, but 3216 special allowance should be made to accept valid ACKs, URGs 3217 and RSTs. 3219 If an incoming segment is not acceptable, an acknowledgment 3220 should be sent in reply (unless the RST bit is set, if so 3221 drop the segment and return): 3223 3225 After sending the acknowledgment, drop the unacceptable 3226 segment and return. 3228 Note that for the TIME-WAIT state, there is an improved 3229 algorithm described in [30] for handling incoming SYN 3230 segments, that utilizes timestamps rather than relying on 3231 the sequence number check described here. When the improved 3232 algorithm is implemented, the logic above is not applicable 3233 for incoming SYN segments with timestamp options, received 3234 on a connection in the TIME-WAIT state. 3236 In the following it is assumed that the segment is the 3237 idealized segment that begins at RCV.NXT and does not exceed 3238 the window. One could tailor actual segments to fit this 3239 assumption by trimming off any portions that lie outside the 3240 window (including SYN and FIN), and only processing further 3241 if the segment then begins at RCV.NXT. Segments with higher 3242 beginning sequence numbers SHOULD be held for later 3243 processing (SHLD-31). 3245 second check the RST bit, 3247 RFC 5961 section 3 describes a potential blind reset attack 3248 and optional mitigation approach that SHOULD be implemented. 3249 For stacks implementing RFC 5961, the three checks below 3250 apply, otherwise processesing for these states is indicated 3251 further below. 3253 1) If the RST bit is set and the sequence number is 3254 outside the current receive window, silently drop the 3255 segment. 3257 2) If the RST bit is set and the sequence number exactly 3258 matches the next expected sequence number (RCV.NXT), then 3259 TCP MUST reset the connection in the manner prescribed 3260 below according to the connection state. 3262 3) If the RST bit is set and the sequence number does not 3263 exactly match the next expected sequence value, yet is 3264 within the current receive window, TCP MUST send an 3265 acknowledgement (challenge ACK): 3267 3269 After sending the challenge ACK, TCP MUST drop the 3270 unacceptable segment and stop processing the incoming 3271 packet further. Note that RFC 5961 and Errata ID 4772 3272 contain additional considerations for ACK throttling in 3273 an implementation. 3275 SYN-RECEIVED STATE 3277 If the RST bit is set 3279 If this connection was initiated with a passive OPEN 3280 (i.e., came from the LISTEN state), then return this 3281 connection to LISTEN state and return. The user need 3282 not be informed. If this connection was initiated 3283 with an active OPEN (i.e., came from SYN-SENT state) 3284 then the connection was refused, signal the user 3285 "connection refused". In either case, all segments on 3286 the retransmission queue should be removed. And in 3287 the active OPEN case, enter the CLOSED state and 3288 delete the TCB, and return. 3290 ESTABLISHED 3291 FIN-WAIT-1 3292 FIN-WAIT-2 3293 CLOSE-WAIT 3295 If the RST bit is set then, any outstanding RECEIVEs and 3296 SEND should receive "reset" responses. All segment 3297 queues should be flushed. Users should also receive an 3298 unsolicited general "connection reset" signal. Enter the 3299 CLOSED state, delete the TCB, and return. 3301 CLOSING STATE 3302 LAST-ACK STATE 3303 TIME-WAIT 3305 If the RST bit is set then, enter the CLOSED state, 3306 delete the TCB, and return. 3308 third check security 3310 SYN-RECEIVED 3312 If the security/compartment in the segment does not 3313 exactly match the security/compartment in the TCB then 3314 send a reset, and return. 3316 ESTABLISHED 3317 FIN-WAIT-1 3318 FIN-WAIT-2 3319 CLOSE-WAIT 3320 CLOSING 3321 LAST-ACK 3322 TIME-WAIT 3324 If the security/compartment in the segment does not 3325 exactly match the security/compartment in the TCB then 3326 send a reset, any outstanding RECEIVEs and SEND should 3327 receive "reset" responses. All segment queues should be 3328 flushed. Users should also receive an unsolicited 3329 general "connection reset" signal. Enter the CLOSED 3330 state, delete the TCB, and return. 3332 Note this check is placed following the sequence check to 3333 prevent a segment from an old connection between these ports 3334 with a different security from causing an abort of the 3335 current connection. 3337 fourth, check the SYN bit, 3339 SYN-RECEIVED 3341 If the connection was initiated with a passive OPEN, then 3342 return this connection to the LISTEN state and return. 3343 Otherwise, handle per the directions for synchronized 3344 states below. 3346 ESTABLISHED STATE 3347 FIN-WAIT STATE-1 3348 FIN-WAIT STATE-2 3349 CLOSE-WAIT STATE 3350 CLOSING STATE 3351 LAST-ACK STATE 3352 TIME-WAIT STATE 3354 If the SYN bit is set in these synchronized states, it 3355 may be either a legitimate new connection attempt (e.g. 3356 in the case of TIME-WAIT), an error where the connection 3357 should be reset, or the result of an attack attempt, as 3358 described in RFC 5961 [28]. For the TIME-WAIT state, new 3359 connections can be accepted if the timestamp option is 3360 used and meets expectations (per [30]). For all other 3361 caess, RFC 5961 provides a mitigation that SHOULD be 3362 implemented, though there are alternatives (see 3363 Section 6). RFC 5961 recommends that in these 3364 synchronized states, if the SYN bit is set, irrespective 3365 of the sequence number, TCP MUST send a "challenge ACK" 3366 to the remote peer: 3368 3370 After sending the acknowledgement, TCP MUST drop the 3371 unacceptable segment and stop processing further. Note 3372 that RFC 5961 and Errata ID 4772 contain additional ACK 3373 throttling notes for an implementation. 3375 For implementations that do not follow RFC 5961, the 3376 original RFC 793 behavior follows in this paragraph. If 3377 the SYN is in the window it is an error, send a reset, 3378 any outstanding RECEIVEs and SEND should receive "reset" 3379 responses, all segment queues should be flushed, the user 3380 should also receive an unsolicited general "connection 3381 reset" signal, enter the CLOSED state, delete the TCB, 3382 and return. 3384 If the SYN is not in the window this step would not be 3385 reached and an ack would have been sent in the first step 3386 (sequence number check). 3388 fifth check the ACK field, 3390 if the ACK bit is off drop the segment and return 3392 if the ACK bit is on 3394 RFC 5961 section 5 describes a potential blind data 3395 injection attack, and mitigation that implementations MAY 3396 choose to include (MAY-12). TCP stacks that implement 3397 RFC 5961 MUST add an input check that the ACK value is 3398 acceptable only if it is in the range of ((SND.UNA - 3399 MAX.SND.WND) =< SEG.ACK =< SND.NXT). All incoming 3400 segments whose ACK value doesn't satisfy the above 3401 condition MUST be discarded and an ACK sent back. The 3402 new state variable MAX.SND.WND is defined as the largest 3403 window that the local sender has ever received from its 3404 peer (subject to window scaling) or may be hard-coded to 3405 a maximum permissible window value. When the ACK value 3406 is acceptable, the processing per-state below applies: 3408 SYN-RECEIVED STATE 3410 If SND.UNA < SEG.ACK =< SND.NXT then enter ESTABLISHED 3411 state and continue processing with variables below set 3412 to: 3414 SND.WND <- SEG.WND 3415 SND.WL1 <- SEG.SEQ 3416 SND.WL2 <- SEG.ACK 3418 If the segment acknowledgment is not acceptable, 3419 form a reset segment, 3421 3423 and send it. 3425 ESTABLISHED STATE 3427 If SND.UNA < SEG.ACK =< SND.NXT then, set SND.UNA <- 3428 SEG.ACK. Any segments on the retransmission queue 3429 which are thereby entirely acknowledged are removed. 3430 Users should receive positive acknowledgments for 3431 buffers which have been SENT and fully acknowledged 3432 (i.e., SEND buffer should be returned with "ok" 3433 response). If the ACK is a duplicate (SEG.ACK =< 3434 SND.UNA), it can be ignored. If the ACK acks 3435 something not yet sent (SEG.ACK > SND.NXT) then send 3436 an ACK, drop the segment, and return. 3438 If SND.UNA =< SEG.ACK =< SND.NXT, the send window 3439 should be updated. If (SND.WL1 < SEG.SEQ or (SND.WL1 3440 = SEG.SEQ and SND.WL2 =< SEG.ACK)), set SND.WND <- 3441 SEG.WND, set SND.WL1 <- SEG.SEQ, and set SND.WL2 <- 3442 SEG.ACK. 3444 Note that SND.WND is an offset from SND.UNA, that 3445 SND.WL1 records the sequence number of the last 3446 segment used to update SND.WND, and that SND.WL2 3447 records the acknowledgment number of the last segment 3448 used to update SND.WND. The check here prevents using 3449 old segments to update the window. 3451 FIN-WAIT-1 STATE 3453 In addition to the processing for the ESTABLISHED 3454 state, if our FIN is now acknowledged then enter FIN- 3455 WAIT-2 and continue processing in that state. 3457 FIN-WAIT-2 STATE 3459 In addition to the processing for the ESTABLISHED 3460 state, if the retransmission queue is empty, the 3461 user's CLOSE can be acknowledged ("ok") but do not 3462 delete the TCB. 3464 CLOSE-WAIT STATE 3466 Do the same processing as for the ESTABLISHED state. 3468 CLOSING STATE 3470 In addition to the processing for the ESTABLISHED 3471 state, if the ACK acknowledges our FIN then enter the 3472 TIME-WAIT state, otherwise ignore the segment. 3474 LAST-ACK STATE 3475 The only thing that can arrive in this state is an 3476 acknowledgment of our FIN. If our FIN is now 3477 acknowledged, delete the TCB, enter the CLOSED state, 3478 and return. 3480 TIME-WAIT STATE 3482 The only thing that can arrive in this state is a 3483 retransmission of the remote FIN. Acknowledge it, and 3484 restart the 2 MSL timeout. 3486 sixth, check the URG bit, 3488 ESTABLISHED STATE 3489 FIN-WAIT-1 STATE 3490 FIN-WAIT-2 STATE 3492 If the URG bit is set, RCV.UP <- max(RCV.UP,SEG.UP), and 3493 signal the user that the remote side has urgent data if 3494 the urgent pointer (RCV.UP) is in advance of the data 3495 consumed. If the user has already been signaled (or is 3496 still in the "urgent mode") for this continuous sequence 3497 of urgent data, do not signal the user again. 3499 CLOSE-WAIT STATE 3500 CLOSING STATE 3501 LAST-ACK STATE 3502 TIME-WAIT 3504 This should not occur, since a FIN has been received from 3505 the remote side. Ignore the URG. 3507 seventh, process the segment text, 3509 ESTABLISHED STATE 3510 FIN-WAIT-1 STATE 3511 FIN-WAIT-2 STATE 3513 Once in the ESTABLISHED state, it is possible to deliver 3514 segment text to user RECEIVE buffers. Text from segments 3515 can be moved into buffers until either the buffer is full 3516 or the segment is empty. If the segment empties and 3517 carries an PUSH flag, then the user is informed, when the 3518 buffer is returned, that a PUSH has been received. 3520 When the TCP takes responsibility for delivering the data 3521 to the user it must also acknowledge the receipt of the 3522 data. 3524 Once the TCP takes responsibility for the data it 3525 advances RCV.NXT over the data accepted, and adjusts 3526 RCV.WND as appropriate to the current buffer 3527 availability. The total of RCV.NXT and RCV.WND should 3528 not be reduced. 3530 A TCP MAY send an ACK segment acknowledging RCV.NXT when 3531 a valid segment arrives that is in the window but not at 3532 the left window edge (MAY-13). 3534 Please note the window management suggestions in 3535 Section 3.8. 3537 Send an acknowledgment of the form: 3539 3541 This acknowledgment should be piggybacked on a segment 3542 being transmitted if possible without incurring undue 3543 delay. 3545 CLOSE-WAIT STATE 3546 CLOSING STATE 3547 LAST-ACK STATE 3548 TIME-WAIT STATE 3550 This should not occur, since a FIN has been received from 3551 the remote side. Ignore the segment text. 3553 eighth, check the FIN bit, 3555 Do not process the FIN if the state is CLOSED, LISTEN or 3556 SYN-SENT since the SEG.SEQ cannot be validated; drop the 3557 segment and return. 3559 If the FIN bit is set, signal the user "connection closing" 3560 and return any pending RECEIVEs with same message, advance 3561 RCV.NXT over the FIN, and send an acknowledgment for the 3562 FIN. Note that FIN implies PUSH for any segment text not 3563 yet delivered to the user. 3565 SYN-RECEIVED STATE 3566 ESTABLISHED STATE 3568 Enter the CLOSE-WAIT state. 3570 FIN-WAIT-1 STATE 3571 If our FIN has been ACKed (perhaps in this segment), 3572 then enter TIME-WAIT, start the time-wait timer, turn 3573 off the other timers; otherwise enter the CLOSING 3574 state. 3576 FIN-WAIT-2 STATE 3578 Enter the TIME-WAIT state. Start the time-wait timer, 3579 turn off the other timers. 3581 CLOSE-WAIT STATE 3583 Remain in the CLOSE-WAIT state. 3585 CLOSING STATE 3587 Remain in the CLOSING state. 3589 LAST-ACK STATE 3591 Remain in the LAST-ACK state. 3593 TIME-WAIT STATE 3595 Remain in the TIME-WAIT state. Restart the 2 MSL 3596 time-wait timeout. 3598 and return. 3600 USER TIMEOUT 3602 USER TIMEOUT 3604 For any state if the user timeout expires, flush all queues, 3605 signal the user "error: connection aborted due to user timeout" 3606 in general and for any outstanding calls, delete the TCB, enter 3607 the CLOSED state and return. 3609 RETRANSMISSION TIMEOUT 3611 For any state if the retransmission timeout expires on a 3612 segment in the retransmission queue, send the segment at the 3613 front of the retransmission queue again, reinitialize the 3614 retransmission timer, and return. 3616 TIME-WAIT TIMEOUT 3618 If the time-wait timeout expires on a connection delete the 3619 TCB, enter the CLOSED state and return. 3621 3.11. Glossary 3623 1822 BBN Report 1822, "The Specification of the Interconnection of 3624 a Host and an IMP". The specification of interface between a 3625 host and the ARPANET. 3627 ACK 3628 A control bit (acknowledge) occupying no sequence space, 3629 which indicates that the acknowledgment field of this segment 3630 specifies the next sequence number the sender of this segment 3631 is expecting to receive, hence acknowledging receipt of all 3632 previous sequence numbers. 3634 ARPANET message 3635 The unit of transmission between a host and an IMP in the 3636 ARPANET. The maximum size is about 1012 octets (8096 bits). 3638 ARPANET packet 3639 A unit of transmission used internally in the ARPANET between 3640 IMPs. The maximum size is about 126 octets (1008 bits). 3642 connection 3643 A logical communication path identified by a pair of sockets. 3645 datagram 3646 A message sent in a packet switched computer communications 3647 network. 3649 Destination Address 3650 The destination address, usually the network and host 3651 identifiers. 3653 FIN 3654 A control bit (finis) occupying one sequence number, which 3655 indicates that the sender will send no more data or control 3656 occupying sequence space. 3658 fragment 3659 A portion of a logical unit of data, in particular an 3660 internet fragment is a portion of an internet datagram. 3662 FTP 3663 A file transfer protocol. 3665 header 3666 Control information at the beginning of a message, segment, 3667 fragment, packet or block of data. 3669 host 3670 A computer. In particular a source or destination of 3671 messages from the point of view of the communication network. 3673 Identification 3674 An Internet Protocol field. This identifying value assigned 3675 by the sender aids in assembling the fragments of a datagram. 3677 IMP 3678 The Interface Message Processor, the packet switch of the 3679 ARPANET. 3681 internet address 3682 A source or destination address specific to the host level. 3684 internet datagram 3685 The unit of data exchanged between an internet module and the 3686 higher level protocol together with the internet header. 3688 internet fragment 3689 A portion of the data of an internet datagram with an 3690 internet header. 3692 IP 3693 Internet Protocol. 3695 IRS 3696 The Initial Receive Sequence number. The first sequence 3697 number used by the sender on a connection. 3699 ISN 3700 The Initial Sequence Number. The first sequence number used 3701 on a connection, (either ISS or IRS). Selected in a way that 3702 is unique within a given period of time and is unpredictable 3703 to attackers. 3705 ISS 3706 The Initial Send Sequence number. The first sequence number 3707 used by the sender on a connection. 3709 leader 3710 Control information at the beginning of a message or block of 3711 data. In particular, in the ARPANET, the control information 3712 on an ARPANET message at the host-IMP interface. 3714 left sequence 3715 This is the next sequence number to be acknowledged by the 3716 data receiving TCP (or the lowest currently unacknowledged 3717 sequence number) and is sometimes referred to as the left 3718 edge of the send window. 3720 local packet 3721 The unit of transmission within a local network. 3723 module 3724 An implementation, usually in software, of a protocol or 3725 other procedure. 3727 MSL 3728 Maximum Segment Lifetime, the time a TCP segment can exist in 3729 the internetwork system. Arbitrarily defined to be 2 3730 minutes. 3732 octet 3733 An eight bit byte. 3735 Options 3736 An Option field may contain several options, and each option 3737 may be several octets in length. 3739 packet 3740 A package of data with a header which may or may not be 3741 logically complete. More often a physical packaging than a 3742 logical packaging of data. 3744 port 3745 The portion of a socket that specifies which logical input or 3746 output channel of a process is associated with the data. 3748 process 3749 A program in execution. A source or destination of data from 3750 the point of view of the TCP or other host-to-host protocol. 3752 PUSH 3753 A control bit occupying no sequence space, indicating that 3754 this segment contains data that must be pushed through to the 3755 receiving user. 3757 RCV.NXT 3758 receive next sequence number 3760 RCV.UP 3761 receive urgent pointer 3763 RCV.WND 3764 receive window 3766 receive next sequence number 3767 This is the next sequence number the local TCP is expecting 3768 to receive. 3770 receive window 3771 This represents the sequence numbers the local (receiving) 3772 TCP is willing to receive. Thus, the local TCP considers 3773 that segments overlapping the range RCV.NXT to RCV.NXT + 3774 RCV.WND - 1 carry acceptable data or control. Segments 3775 containing sequence numbers entirely outside of this range 3776 are considered duplicates and discarded. 3778 RST 3779 A control bit (reset), occupying no sequence space, 3780 indicating that the receiver should delete the connection 3781 without further interaction. The receiver can determine, 3782 based on the sequence number and acknowledgment fields of the 3783 incoming segment, whether it should honor the reset command 3784 or ignore it. In no case does receipt of a segment 3785 containing RST give rise to a RST in response. 3787 RTP 3788 Real Time Protocol: A host-to-host protocol for communication 3789 of time critical information. 3791 SEG.ACK 3792 segment acknowledgment 3794 SEG.LEN 3795 segment length 3797 SEG.SEQ 3798 segment sequence 3800 SEG.UP 3801 segment urgent pointer field 3803 SEG.WND 3804 segment window field 3806 segment 3807 A logical unit of data, in particular a TCP segment is the 3808 unit of data transfered between a pair of TCP modules. 3810 segment acknowledgment 3811 The sequence number in the acknowledgment field of the 3812 arriving segment. 3814 segment length 3815 The amount of sequence number space occupied by a segment, 3816 including any controls which occupy sequence space. 3818 segment sequence 3819 The number in the sequence field of the arriving segment. 3821 send sequence 3822 This is the next sequence number the local (sending) TCP will 3823 use on the connection. It is initially selected from an 3824 initial sequence number curve (ISN) and is incremented for 3825 each octet of data or sequenced control transmitted. 3827 send window 3828 This represents the sequence numbers which the remote 3829 (receiving) TCP is willing to receive. It is the value of 3830 the window field specified in segments from the remote (data 3831 receiving) TCP. The range of new sequence numbers which may 3832 be emitted by a TCP lies between SND.NXT and SND.UNA + 3833 SND.WND - 1. (Retransmissions of sequence numbers between 3834 SND.UNA and SND.NXT are expected, of course.) 3836 SND.NXT 3837 send sequence 3839 SND.UNA 3840 left sequence 3842 SND.UP 3843 send urgent pointer 3845 SND.WL1 3846 segment sequence number at last window update 3848 SND.WL2 3849 segment acknowledgment number at last window update 3851 SND.WND 3852 send window 3854 socket 3855 An address which specifically includes a port identifier, 3856 that is, the concatenation of an Internet Address with a TCP 3857 port. 3859 Source Address 3860 The source address, usually the network and host identifiers. 3862 SYN 3863 A control bit in the incoming segment, occupying one sequence 3864 number, used at the initiation of a connection, to indicate 3865 where the sequence numbering will start. 3867 TCB 3868 Transmission control block, the data structure that records 3869 the state of a connection. 3871 TCP 3872 Transmission Control Protocol: A host-to-host protocol for 3873 reliable communication in internetwork environments. 3875 TOS 3876 Type of Service, an obsoleted IPv4 field. The same header 3877 bits currently are used for the Differentiated Services field 3878 [6] containing the Differentiated Services Code Point (DSCP) 3879 value and two unused bits. 3881 Type of Service 3882 An Internet Protocol field which indicates the type of 3883 service for this internet fragment. 3885 URG 3886 A control bit (urgent), occupying no sequence space, used to 3887 indicate that the receiving user should be notified to do 3888 urgent processing as long as there is data to be consumed 3889 with sequence numbers less than the value indicated in the 3890 urgent pointer. 3892 urgent pointer 3893 A control field meaningful only when the URG bit is on. This 3894 field communicates the value of the urgent pointer which 3895 indicates the data octet associated with the sending user's 3896 urgent call. 3898 4. Changes from RFC 793 3900 This document obsoletes RFC 793 as well as RFC 6093 and 6528, which 3901 updated 793. In all cases, only the normative protocol specification 3902 and requirements have been incorporated into this document, and the 3903 informational text with background and rationale has not been carried 3904 in. The informational content of those documents is still valuable 3905 in learning about and understanding TCP, and they are valid 3906 Informational references, even though their normative content has 3907 been incorporated into this document. 3909 The main body of this document was adapted from RFC 793's Section 3, 3910 titled "FUNCTIONAL SPECIFICATION", with an attempt to keep formatting 3911 and layout as close as possible. 3913 The collection of applicable RFC Errata that have been reported and 3914 either accepted or held for an update to RFC 793 were incorporated 3915 (Errata IDs: 573, 574, 700, 701, 1283, 1561, 1562, 1564, 1565, 1571, 3916 1572, 2296, 2297, 2298, 2748, 2749, 2934, 3213, 3300, 3301). Some 3917 errata were not applicable due to other changes (Errata IDs: 572, 3918 575, 1569, 3305, 3602). 3920 Changes to the specification of the Urgent Pointer described in RFC 3921 1122 and 6093 were incorporated. See RFC 6093 for detailed 3922 discussion of why these changes were necessary. 3924 The discussion of the RTO from RFC 793 was updated to refer to RFC 3925 6298. The RFC 1122 text on the RTO originally replaced the 793 text, 3926 however, RFC 2988 should have updated 1122, and has subsequently been 3927 obsoleted by 6298. 3929 RFC 1122 contains a collection of other changes and clarifications to 3930 RFC 793. The normative items impacting the protocol have been 3931 incorporated here, though some historically useful implementation 3932 advice and informative discussion from RFC 1122 is not included here. 3934 RFC 1122 contains more than just TCP requirements, so this document 3935 can't obsolete RFC 1122 entirely. It is only marked as "updating" 3936 1122, however, it should be understood to effectively obsolete all of 3937 the RFC 1122 material on TCP. 3939 The more secure Initial Sequence Number generation algorithm from RFC 3940 6528 was incorporated. See RFC 6528 for discussion of the attacks 3941 that this mitigates, as well as advice on selecting PRF algorithms 3942 and managing secret key data. 3944 A note based on RFC 6429 was added to explicitly clarify that system 3945 resource mangement concerns allow connection resources to be 3946 reclaimed. RFC 6429 is obsoleted in the sense that this 3947 clarification has been reflected in this update to the base TCP 3948 specification now. 3950 RFC EDITOR'S NOTE: the content below is for detailed change tracking 3951 and planning, and not to be included with the final revision of the 3952 document. 3954 This document started as draft-eddy-rfc793bis-00, that was merely a 3955 proposal and rough plan for updating RFC 793. 3957 The -01 revision of this draft-eddy-rfc793bis incorporates the 3958 content of RFC 793 Section 3 titled "FUNCTIONAL SPECIFICATION". 3959 Other content from RFC 793 has not been incorporated. The -01 3960 revision of this document makes some minor formatting changes to the 3961 RFC 793 content in order to convert the content into XML2RFC format 3962 and account for left-out parts of RFC 793. For instance, figure 3963 numbering differs and some indentation is not exactly the same. 3965 The -02 revision of draft-eddy-rfc793bis incorporates errata that 3966 have been verified: 3968 Errata ID 573: Reported by Bob Braden (note: This errata basically 3969 is just a reminder that RFC 1122 updates 793. Some of the 3970 associated changes are left pending to a separate revision that 3971 incorporates 1122. Bob's mention of PUSH in 793 section 2.8 was 3972 not applicable here because that section was not part of the 3973 "functional specification". Also the 1122 text on the 3974 retransmission timeout also has been updated by subsequent RFCs, 3975 so the change here deviates from Bob's suggestion to apply the 3976 1122 text.) 3977 Errata ID 574: Reported by Yin Shuming 3978 Errata ID 700: Reported by Yin Shuming 3979 Errata ID 701: Reported by Yin Shuming 3980 Errata ID 1283: Reported by Pei-chun Cheng 3981 Errata ID 1561: Reported by Constantin Hagemeier 3982 Errata ID 1562: Reported by Constantin Hagemeier 3983 Errata ID 1564: Reported by Constantin Hagemeier 3984 Errata ID 1565: Reported by Constantin Hagemeier 3985 Errata ID 1571: Reported by Constantin Hagemeier 3986 Errata ID 1572: Reported by Constantin Hagemeier 3987 Errata ID 2296: Reported by Vishwas Manral 3988 Errata ID 2297: Reported by Vishwas Manral 3989 Errata ID 2298: Reported by Vishwas Manral 3990 Errata ID 2748: Reported by Mykyta Yevstifeyev 3991 Errata ID 2749: Reported by Mykyta Yevstifeyev 3992 Errata ID 2934: Reported by Constantin Hagemeier 3993 Errata ID 3213: Reported by EugnJun Yi 3994 Errata ID 3300: Reported by Botong Huang 3995 Errata ID 3301: Reported by Botong Huang 3996 Errata ID 3305: Reported by Botong Huang 3997 Note: Some verified errata were not used in this update, as they 3998 relate to sections of RFC 793 elided from this document. These 3999 include Errata ID 572, 575, and 1569. 4000 Note: Errata ID 3602 was not applied in this revision as it is 4001 duplicative of the 1122 corrections. 4003 Not related to RFC 793 content, this revision also makes small tweaks 4004 to the introductory text, fixes indentation of the pseudoheader 4005 diagram, and notes that the Security Considerations should also 4006 include privacy, when this section is written. 4008 The -03 revision of draft-eddy-rfc793bis revises all discussion of 4009 the urgent pointer in order to comply with RFC 6093, 1122, and 1011. 4010 Since 1122 held requirements on the urgent pointer, the full list of 4011 requirements was brought into an appendix of this document, so that 4012 it can be updated as-needed. 4014 The -04 revision of draft-eddy-rfc793bis includes the ISN generation 4015 changes from RFC 6528. 4017 The -05 revision of draft-eddy-rfc793bis incorporates MSS 4018 requirements and definitions from RFC 879, 1122, and 6691, as well as 4019 option-handling requirements from RFC 1122. 4021 The -00 revision of draft-ietf-tcpm-rfc793bis incorporates several 4022 additional clarifications and updates to the section on segmentation, 4023 many of which are based on feedback from Joe Touch improving from the 4024 initial text on this in the previous revision. 4026 The -01 revision incorporates the change to Reserved bits due to ECN, 4027 as well as many other changes that come from RFC 1122. 4029 The -02 revision has small formating modifications in order to 4030 address xml2rfc warnings about long lines. It was a quick update to 4031 avoid document expiration. TCPM working group discussion in 2015 4032 also indicated that that we should not try to add sections on 4033 implementation advice or similar non-normative information. 4035 The -03 revision incorporates more content from RFC 1122: Passive 4036 OPEN Calls, Time-To-Live, Multihoming, IP Options, ICMP messages, 4037 Data Communications, When to Send Data, When to Send a Window Update, 4038 Managing the Window, Probing Zero Windows, When to Send an ACK 4039 Segment. The section on data communications was re-organized into 4040 clearer subsections (previously headings were embedded in the 793 4041 text), and windows management advice from 793 was removed (as 4042 reviewed by TCPM working group) in favor of the 1122 additions on 4043 SWS, ZWP, and related topics. 4045 The -04 revision includes reference to RFC 6429 on the ZWP condition, 4046 RFC1122 material on TCP Connection Failures, TCP Keep-Alives, 4047 Acknowledging Queued Segments, and Remote Address Validation. RTO 4048 computation is referenced from RFC 6298 rather than RFC 1122. 4050 The -05 revision includes the requirement to implement TCP congestion 4051 control with recommendation to implemente ECN, the RFC 6633 update to 4052 1122, which changed the requirement on responding to source quench 4053 ICMP messages, and discussion of ICMP (and ICMPv6) soft and hard 4054 errors per RFC 5461 (ICMPv6 handling for TCP doesn't seem to be 4055 mentioned elsewhere in standards track). 4057 The -06 revision includes an appendix on "Other Implementation Notes" 4058 to capture widely-deployed fundamental features that are not 4059 contained in the RFC series yet. It also added mention of RFC 6994 4060 and the IANA TCP parameters registry as a reference. It includes 4061 references to RFC 5961 in appropriate places. The references to TOS 4062 were changed to DiffServ field, based on reflecting RFC 2474 as well 4063 as the IPv6 presence of traffic class (carrying DiffServ field) 4064 rather than TOS. 4066 The -07 revision includes reference to RFC 6191, updated security 4067 considerations, discussion of additional implementation 4068 considerations, and clarification of data on the SYN. 4070 The -08 revision includes changes based on: 4072 describing treatment of reserved bits (following TCPM mailing list 4073 thread from July 2014 on "793bis item - reserved bit behavior" 4074 addition a brief TCP key concepts section to make up for not 4075 including the outdated section 2 of RFC 793 4076 changed "TCP" to "host" to resolve conflict between 1122 wording 4077 on whether TCP or the network layer chooses an address when 4078 multihomed 4079 fixed/updated definition of options in glossary 4080 moved note on aggregating ACKs from 1122 to a more appropriate 4081 location 4082 resolved notes on IP precedence and security/compartment 4083 added implementation note on sequence number validation 4084 added note that PUSH does not apply when Nagle is active 4085 added 1122 content on asynchronous reports to replace 793 section 4086 on TCP to user messages 4088 The -09 revision fixes section numbering problems. 4090 The -10 revision includes additions to the security considerations 4091 based on comments from Joe Touch, and suggested edits on RST/FIN 4092 notification, RFC 2525 reference, and other edits suggested by 4093 Yuchung Cheng, as well as modifications to DiffServ text from Yuchung 4094 Cheng and Gorry Fairhurst. 4096 The -11 revision includes a start at identifying all of the 4097 requirements text and referencing each instance in the common table 4098 at the end of the document. 4100 The -12 revision completes the requirement language indexing started 4101 in -11 and adds necessary description of the PUSH functionality that 4102 was missing. 4104 Some other suggested changes that will not be incorporated in this 4105 793 update unless TCPM consensus changes with regard to scope are: 4107 1. look at Tony Sabatini suggestion for describing DO field 4108 2. per discussion with Joe Touch (TAPS list, 6/20/2015), the 4109 description of the API could be revisited 4111 Early in the process of updating RFC 793, Scott Brim mentioned that 4112 this should include a PERPASS/privacy review. This may be something 4113 for the chairs or AD to request during WGLC or IETF LC. 4115 5. IANA Considerations 4117 This memo includes no request to IANA. Existing IANA registries for 4118 TCP parameters are sufficient. 4120 6. Security and Privacy Considerations 4122 The TCP design includes only rudimentary security features that 4123 improve the robustness and reliability of connections and application 4124 data transfer, but there are no built-in cryptographic capabilities 4125 to support any form of privacy, authentication, or other typical 4126 security functions. Non-cryptographic enhancements (e.g. [28]) have 4127 been developed to improve robustness of TCP connections to particular 4128 types of attacks, but the applicability and protections of non- 4129 cryptographic enhancements are limited (e.g. see section 1.1 of 4130 [28]). Applications typically utilize lower-layer (e.g. IPsec) and 4131 upper-layer (e.g. TLS) protocols to provide security and privacy for 4132 TCP connections and application data carried in TCP. Methods based 4133 on TCP options have been developed as well, to support some security 4134 capabilities. 4136 In order to fully protect TCP connections (including their control 4137 flags) IPsec or the TCP Authentication Option (TCP-AO) [27] are the 4138 only current effective methods. Other methods discussed in this 4139 section may protect the payload, but either only a subset of the 4140 fields (e.g. tcpcrypt) or none at all (e.g. TLS). Other security 4141 features that have been added to TCP (e.g. ISN generation, sequence 4142 number checks, etc.) are only capable of partially hindering attacks. 4144 Applications using long-lived TCP flows have been vulnerable to 4145 attacks that exploit the processing of control flags described in 4146 earlier TCP specifications [21]. TCP-MD5 was a commonly implemented 4147 TCP option to support authentication for some of these connections, 4148 but had flaws and is now deprecated. TCP-AO provides a capability to 4149 protect long-lived TCP connections from attacks, and has superior 4150 properties to TCP-MD5. It does not provide any privacy for 4151 application data, nor for the TCP headers. 4153 The "tcpcrypt" [44]Experimental extension to TCP provides the ability 4154 to cryptographically protect connection data. Metadata aspects of 4155 the TCP flow are still visible, but the application stream is well- 4156 protected. Within the TCP header, only the urgent pointer and FIN 4157 flag are protected through tcpcrypt. 4159 The TCP Roadmap [37] includes notes about several RFCs related to TCP 4160 security. Many of the enhancements provided by these RFCs have been 4161 integrated into the present document, including ISN generation, 4162 mitigating blind in-window attacks, and improving handling of soft 4163 errors and ICMP packets. These are all discussed in greater detail 4164 in the referenced RFCs that originally described the changes needed 4165 to earlier TCP specifications. Additionally, see RFC 6093 [29] for 4166 discussion of security considerations related to the urgent pointer 4167 field, that has been deprecated. 4169 Since TCP is often used for bulk transfer flows, some attacks are 4170 possible that abuse the TCP congestion control logic. An example is 4171 "ACK-division" attacks. Updates that have been made to the TCP 4172 congestion control specifications include mechanisms like Appropriate 4173 Byte Counting (ABC) that act as mitigations to these attacks. 4175 Other attacks are focused on exhausting the resources of a TCP 4176 server. Examples include SYN flooding [20] or wasting resources on 4177 non-progressing connections [31]. Operating systems commonly 4178 implement mitigations for these attacks. Some common defenses also 4179 utilize proxies, stateful firewalls, and other technologies outside 4180 of the end-host TCP implementation. 4182 7. Acknowledgements 4184 This document is largely a revision of RFC 793, which Jon Postel was 4185 the editor of. Due to his excellent work, it was able to last for 4186 three decades before we felt the need to revise it. 4188 Andre Oppermann was a contributor and helped to edit the first 4189 revision of this document. 4191 We are thankful for the assistance of the IETF TCPM working group 4192 chairs: 4194 Michael Scharf 4195 Yoshifumi Nishida 4196 Pasi Sarolahti 4198 During early discussion of this work on the TCPM mailing list, and at 4199 the IETF 88 meeting in Vancouver, helpful comments, critiques, and 4200 reviews were received from (listed alphebetically): David Borman, 4201 Yuchung Cheng, Martin Duke, Kevin Lahey, Kevin Mason, Matt Mathis, 4202 Hagen Paul Pfeifer, Anthony Sabatini, Joe Touch, Reji Varghese, Lloyd 4203 Wood, and Alex Zimmermann. Joe Touch provided help in clarifying the 4204 description of segment size parameters and PMTUD/PLPMTUD 4205 recommendations. 4207 This document includes content from errata that were reported by 4208 (listed chronologically): Yin Shuming, Bob Braden, Morris M. Keesan, 4209 Pei-chun Cheng, Constantin Hagemeier, Vishwas Manral, Mykyta 4210 Yevstifeyev, EungJun Yi, Botong Huang. 4212 8. References 4214 8.1. Normative References 4216 [1] Postel, J., "Internet Protocol", STD 5, RFC 791, 4217 DOI 10.17487/RFC0791, September 1981, 4218 . 4220 [2] Mogul, J. and S. Deering, "Path MTU discovery", RFC 1191, 4221 DOI 10.17487/RFC1191, November 1990, 4222 . 4224 [3] McCann, J., Deering, S., and J. Mogul, "Path MTU Discovery 4225 for IP version 6", RFC 1981, DOI 10.17487/RFC1981, August 4226 1996, . 4228 [4] Bradner, S., "Key words for use in RFCs to Indicate 4229 Requirement Levels", BCP 14, RFC 2119, 4230 DOI 10.17487/RFC2119, March 1997, 4231 . 4233 [5] Deering, S. and R. Hinden, "Internet Protocol, Version 6 4234 (IPv6) Specification", RFC 2460, DOI 10.17487/RFC2460, 4235 December 1998, . 4237 [6] Nichols, K., Blake, S., Baker, F., and D. Black, 4238 "Definition of the Differentiated Services Field (DS 4239 Field) in the IPv4 and IPv6 Headers", RFC 2474, 4240 DOI 10.17487/RFC2474, December 1998, 4241 . 4243 [7] Borman, D., Deering, S., and R. Hinden, "IPv6 Jumbograms", 4244 RFC 2675, DOI 10.17487/RFC2675, August 1999, 4245 . 4247 [8] Lahey, K., "TCP Problems with Path MTU Discovery", 4248 RFC 2923, DOI 10.17487/RFC2923, September 2000, 4249 . 4251 [9] Ramakrishnan, K., Floyd, S., and D. Black, "The Addition 4252 of Explicit Congestion Notification (ECN) to IP", 4253 RFC 3168, DOI 10.17487/RFC3168, September 2001, 4254 . 4256 [10] Paxson, V., Allman, M., Chu, J., and M. Sargent, 4257 "Computing TCP's Retransmission Timer", RFC 6298, 4258 DOI 10.17487/RFC6298, June 2011, 4259 . 4261 [11] Gont, F., "Deprecation of ICMP Source Quench Messages", 4262 RFC 6633, DOI 10.17487/RFC6633, May 2012, 4263 . 4265 8.2. Informative References 4267 [12] Postel, J., "Transmission Control Protocol", STD 7, 4268 RFC 793, DOI 10.17487/RFC0793, September 1981, 4269 . 4271 [13] Nagle, J., "Congestion Control in IP/TCP Internetworks", 4272 RFC 896, DOI 10.17487/RFC0896, January 1984, 4273 . 4275 [14] Braden, R., Ed., "Requirements for Internet Hosts - 4276 Communication Layers", STD 3, RFC 1122, 4277 DOI 10.17487/RFC1122, October 1989, 4278 . 4280 [15] Almquist, P., "Type of Service in the Internet Protocol 4281 Suite", RFC 1349, DOI 10.17487/RFC1349, July 1992, 4282 . 4284 [16] Braden, R., "T/TCP -- TCP Extensions for Transactions 4285 Functional Specification", RFC 1644, DOI 10.17487/RFC1644, 4286 July 1994, . 4288 [17] Paxson, V., Allman, M., Dawson, S., Fenner, W., Griner, 4289 J., Heavens, I., Lahey, K., Semke, J., and B. Volz, "Known 4290 TCP Implementation Problems", RFC 2525, 4291 DOI 10.17487/RFC2525, March 1999, 4292 . 4294 [18] Xiao, X., Hannan, A., Paxson, V., and E. Crabbe, "TCP 4295 Processing of the IPv4 Precedence Field", RFC 2873, 4296 DOI 10.17487/RFC2873, June 2000, 4297 . 4299 [19] Mathis, M. and J. Heffner, "Packetization Layer Path MTU 4300 Discovery", RFC 4821, DOI 10.17487/RFC4821, March 2007, 4301 . 4303 [20] Eddy, W., "TCP SYN Flooding Attacks and Common 4304 Mitigations", RFC 4987, DOI 10.17487/RFC4987, August 2007, 4305 . 4307 [21] Touch, J., "Defending TCP Against Spoofing Attacks", 4308 RFC 4953, DOI 10.17487/RFC4953, July 2007, 4309 . 4311 [22] Culley, P., Elzur, U., Recio, R., Bailey, S., and J. 4312 Carrier, "Marker PDU Aligned Framing for TCP 4313 Specification", RFC 5044, DOI 10.17487/RFC5044, October 4314 2007, . 4316 [23] Gont, F., "TCP's Reaction to Soft Errors", RFC 5461, 4317 DOI 10.17487/RFC5461, February 2009, 4318 . 4320 [24] StJohns, M., Atkinson, R., and G. Thomas, "Common 4321 Architecture Label IPv6 Security Option (CALIPSO)", 4322 RFC 5570, DOI 10.17487/RFC5570, July 2009, 4323 . 4325 [25] Allman, M., Paxson, V., and E. Blanton, "TCP Congestion 4326 Control", RFC 5681, DOI 10.17487/RFC5681, September 2009, 4327 . 4329 [26] Sandlund, K., Pelletier, G., and L-E. Jonsson, "The RObust 4330 Header Compression (ROHC) Framework", RFC 5795, 4331 DOI 10.17487/RFC5795, March 2010, 4332 . 4334 [27] Touch, J., Mankin, A., and R. Bonica, "The TCP 4335 Authentication Option", RFC 5925, DOI 10.17487/RFC5925, 4336 June 2010, . 4338 [28] Ramaiah, A., Stewart, R., and M. Dalal, "Improving TCP's 4339 Robustness to Blind In-Window Attacks", RFC 5961, 4340 DOI 10.17487/RFC5961, August 2010, 4341 . 4343 [29] Gont, F. and A. Yourtchenko, "On the Implementation of the 4344 TCP Urgent Mechanism", RFC 6093, DOI 10.17487/RFC6093, 4345 January 2011, . 4347 [30] Gont, F., "Reducing the TIME-WAIT State Using TCP 4348 Timestamps", BCP 159, RFC 6191, DOI 10.17487/RFC6191, 4349 April 2011, . 4351 [31] Bashyam, M., Jethanandani, M., and A. Ramaiah, "TCP Sender 4352 Clarification for Persist Condition", RFC 6429, 4353 DOI 10.17487/RFC6429, December 2011, 4354 . 4356 [32] Gont, F. and S. Bellovin, "Defending against Sequence 4357 Number Attacks", RFC 6528, DOI 10.17487/RFC6528, February 4358 2012, . 4360 [33] Borman, D., "TCP Options and Maximum Segment Size (MSS)", 4361 RFC 6691, DOI 10.17487/RFC6691, July 2012, 4362 . 4364 [34] Touch, J., "Shared Use of Experimental TCP Options", 4365 RFC 6994, DOI 10.17487/RFC6994, August 2013, 4366 . 4368 [35] Borman, D., Braden, B., Jacobson, V., and R. 4369 Scheffenegger, Ed., "TCP Extensions for High Performance", 4370 RFC 7323, DOI 10.17487/RFC7323, September 2014, 4371 . 4373 [36] Cheng, Y., Chu, J., Radhakrishnan, S., and A. Jain, "TCP 4374 Fast Open", RFC 7413, DOI 10.17487/RFC7413, December 2014, 4375 . 4377 [37] Duke, M., Braden, R., Eddy, W., Blanton, E., and A. 4378 Zimmermann, "A Roadmap for Transmission Control Protocol 4379 (TCP) Specification Documents", RFC 7414, 4380 DOI 10.17487/RFC7414, February 2015, 4381 . 4383 [38] Black, D., Ed. and P. Jones, "Differentiated Services 4384 (Diffserv) and Real-Time Communication", RFC 7657, 4385 DOI 10.17487/RFC7657, November 2015, 4386 . 4388 [39] Fairhurst, G. and M. Welzl, "The Benefits of Using 4389 Explicit Congestion Notification (ECN)", RFC 8087, 4390 DOI 10.17487/RFC8087, March 2017, 4391 . 4393 [40] Fairhurst, G., Ed., Trammell, B., Ed., and M. Kuehlewind, 4394 Ed., "Services Provided by IETF Transport Protocols and 4395 Congestion Control Mechanisms", RFC 8095, 4396 DOI 10.17487/RFC8095, March 2017, 4397 . 4399 [41] IANA, "Transmission Control Protocol (TCP) Parameters, 4400 https://www.iana.org/assignments/tcp-parameters/ 4401 tcp-parameters.xhtml", 2017. 4403 [42] Gont, F., "Processing of IP Security/Compartment and 4404 Precedence Information by TCP", draft-gont-tcpm-tcp- 4405 seccomp-prec-00 (work in progress), March 2012. 4407 [43] Gont, F. and D. Borman, "On the Validation of TCP Sequence 4408 Numbers", draft-gont-tcpm-tcp-seq-validation-02 (work in 4409 progress), March 2015. 4411 [44] Bittau, A., Giffin, D., Handley, M., Mazieres, D., Slack, 4412 Q., and E. Smith, "Cryptographic protection of TCP Streams 4413 (tcpcrypt)", draft-ietf-tcpinc-tcpcrypt-09 (work in 4414 progress), November 2017. 4416 [45] Minshall, G., "A Proposed Modification to Nagle's 4417 Algorithm", draft-minshall-nagle-01 (work in progress), 4418 June 1999. 4420 [46] Dalal, Y. and C. Sunshine, "Connection Management in 4421 Transport Protocols", Computer Networks Vol. 2, No. 6, pp. 4422 454-473, December 1978. 4424 Appendix A. Other Implementation Notes 4426 This section includes additional notes and references on TCP 4427 implementation decisions that are currently not a part of the RFC 4428 series or included within the TCP standard. These items can be 4429 considered by implementers, but there was not yet a consensus to 4430 include them in the standard. 4432 A.1. IP Security Compartment and Precedence 4434 RFC 793 requires checking the IP security compartment and precedence 4435 on incoming TCP segments for consistency within a connection, and 4436 with application requests. Each of these aspects of IP have become 4437 outdated, without specific updates to RFC 793. The issues with 4438 precedence were fixed by [18] which is Standards Track, and so this 4439 present TCP specification includes those changes. However, the state 4440 of IP security options that may be used by MLS systems is not as 4441 clean. 4443 Implementers of MLS systems that use IP security options (e.g. IPSO, 4444 CIPSO, or CALIPSO) should implement any additional logic appropriate 4445 for their requirements. 4447 Reseting connections when incoming packets do not meet expected 4448 security compartment or precedence expectations has been recognized 4449 as a possible attack vector [42], and there has been discussion about 4450 ammending the TCP specification to prevent connections from being 4451 aborted due to non-matching IP security compartment and DiffServ 4452 codepoint values. 4454 A.2. Sequence Number Validation 4456 There are cases where the TCP sequence number validation rules can 4457 prevent ACK fields from being processed. This can result in 4458 connection issues, as described in [43], which includes descriptions 4459 of potential problems in conditions of simultaneous open, self- 4460 connects, simultaneous close, and simultaneous window probes. The 4461 document also describes potential changes to the TCP specification to 4462 mitigate the issue by expanding the acceptable sequence numbers. 4464 In Internet usage of TCP, these conditions are rarely occuring. 4465 Common operating systems include different alternative mitigations, 4466 and the standard has not been updated yet to codify one of them, but 4467 implementers should consider the problems described in [43]. 4469 A.3. Nagle Modification 4471 In common operating systems, both the Nagle algorithm and delayed 4472 acknowledgements are implemented and enabled by default. TCP is used 4473 by many applications that have a request-response style of 4474 communication, where the combination of the Nagle algorithm and 4475 delayed acknowledgements can result in poor application performance. 4476 A modification to the Nagle algorithm is described in [45] that 4477 improves the situation for these applications. 4479 This modification is implemented in some common operating systems, 4480 and does not impact TCP interoperability. Additionally, many 4481 applications simply disable Nagle, since this is generally supported 4482 by a socket option. The TCP standard has not been updated to include 4483 this Nagle modification, but implementers may find it beneficial to 4484 consider. 4486 A.4. Low Water Mark 4488 TODO - mention the low watermark function that is in Linux - 4489 suggested by Michael Welzl 4491 SO_SNDLOWAT and SO_RCVLOWAT would be potential enhancements to the 4492 abstract TCP API 4494 TCP_NOTSENT_LOWAT is what Michael is talking about, that helps a 4495 sending TCP application to help avoid creating large amounts of 4496 buffered data (and corresponding latency). This is useful for 4497 applications that are multiplexing data from multiple upper level 4498 streams onto a connection, especially when streams may be a mix of 4499 interactive/realtime and bulk data transfer. 4501 Appendix B. TCP Requirement Summary 4503 This section is adapted from RFC 1122. 4505 Note that there is no requirement related to PLPMTUD in this list, 4506 but that PLPMTUD is recommended. 4508 | | | | |S| | 4509 | | | | |H| |F 4510 | | | | |O|M|o 4511 | | |S| |U|U|o 4512 | | |H| |L|S|t 4513 | |M|O| |D|T|n 4514 | |U|U|M| | |o 4515 | |S|L|A|N|N|t 4516 | |T|D|Y|O|O|t 4517 FEATURE | ReqID | | | |T|T|e 4518 -------------------------------------------------|--------|-|-|-|-|-|-- 4519 | | | | | | | 4520 Push flag | | | | | | | 4521 Aggregate or queue un-pushed data | MAY-16 | | |x| | | 4522 Sender collapse successive PSH flags | SHLD-27| |x| | | | 4523 SEND call can specify PUSH | MAY-15 | | |x| | | 4524 If cannot: sender buffer indefinitely | MUST-60| | | | |x| 4525 If cannot: PSH last segment | MUST-61|x| | | | | 4527 Notify receiving ALP of PSH | MAY-17 | | |x| | |1 4528 Send max size segment when possible | SHLD-28| |x| | | | 4529 | | | | | | | 4530 Window | | | | | | | 4531 Treat as unsigned number | MUST-1 |x| | | | | 4532 Handle as 32-bit number | REC-1 | |x| | | | 4533 Shrink window from right | SHLD-14| | | |x| | 4534 - Send new data when window shrinks | SHLD-15| | | |x| | 4535 - Retransmit old unacked data within window | SHLD-16| |x| | | | 4536 - Time out conn for data past right edge | SHLD-17| | | |x| | 4537 Robust against shrinking window | MUST-34|x| | | | | 4538 Receiver's window closed indefinitely | MAY-8 | | |x| | | 4539 Use standard probing logic | MUST-35|x| | | | | 4540 Sender probe zero window | MUST-36|x| | | | | 4541 First probe after RTO | SHLD-29| |x| | | | 4542 Exponential backoff | SHLD-30| |x| | | | 4543 Allow window stay zero indefinitely | MUST-37|x| | | | | 4544 Retransmit old data beyond SND.UNA+SND.WND | MAY-7 | | |x| | | 4545 | | | | | | | 4546 Urgent Data | | | | | | | 4547 Include support for urgent pointer | MUST-30|x| | | | | 4548 Pointer indicates first non-urgent octet | MUST-62|x| | | | | 4549 Arbitrary length urgent data sequence | MUST-31|x| | | | | 4550 Inform ALP asynchronously of urgent data | MUST-32|x| | | | |1 4551 ALP can learn if/how much urgent data Q'd | MUST-33|x| | | | |1 4552 ALP employ the urgent mechanism | SHLD-13| | | |x| | 4553 | | | | | | | 4554 TCP Options | | | | | | | 4555 Support the mandatory option set | MUST-4 |x| | | | | 4556 Receive TCP option in any segment | MUST-5 |x| | | | | 4557 Ignore unsupported options | MUST-6 |x| | | | | 4558 Cope with illegal option length | MUST-7 |x| | | | | 4559 Implement sending & receiving MSS option | MUST-14|x| | | | | 4560 IPv4 Send MSS option unless 536 | SHLD-5 | |x| | | | 4561 IPv6 Send MSS option unless 1220 | SHLD-5 | |x| | | | 4562 Send MSS option always | MAY-3 | | |x| | | 4563 IPv4 Send-MSS default is 536 | MUST-15|x| | | | | 4564 IPv6 Send-MSS default is 1220 | MUST-15|x| | | | | 4565 Calculate effective send seg size | MUST-16|x| | | | | 4566 MSS accounts for varying MTU | SHLD-6 | |x| | | | 4567 | | | | | | | 4568 TCP Checksums | | | | | | | 4569 Sender compute checksum | MUST-2 |x| | | | | 4570 Receiver check checksum | MUST-3 |x| | | | | 4571 | | | | | | | 4572 ISN Selection | | | | | | | 4573 Include a clock-driven ISN generator component | MUST-8 |x| | | | | 4574 Secure ISN generator with a PRF component | SHLD-1 | |x| | | | 4575 PRF computable from outside the host | MUST-9 | | | | |x| 4576 | | | | | | | 4577 Opening Connections | | | | | | | 4578 Support simultaneous open attempts | MUST-10|x| | | | | 4579 SYN-RECEIVED remembers last state | MUST-11|x| | | | | 4580 Passive Open call interfere with others | MUST-41| | | | |x| 4581 Function: simultan. LISTENs for same port | MUST-42|x| | | | | 4582 Ask IP for src address for SYN if necc. | MUST-44|x| | | | | 4583 Otherwise, use local addr of conn. | MUST-45|x| | | | | 4584 OPEN to broadcast/multicast IP Address | MUST-46| | | | |x| 4585 Silently discard seg to bcast/mcast addr | MUST-57|x| | | | | 4586 | | | | | | | 4587 Closing Connections | | | | | | | 4588 RST can contain data | SHLD-2 | |x| | | | 4589 Inform application of aborted conn | MUST-12|x| | | | | 4590 Half-duplex close connections | MAY-1 | | |x| | | 4591 Send RST to indicate data lost | SHLD-3 | |x| | | | 4592 In TIME-WAIT state for 2MSL seconds | MUST-13|x| | | | | 4593 Accept SYN from TIME-WAIT state | MAY-2 | | |x| | | 4594 Use Timestamps to reduce TIME-WAIT | SHLD-4 | |x| | | | 4595 | | | | | | | 4596 Retransmissions | | | | | | | 4597 Implement RFC 5681 | MUST-19|x| | | | | 4598 Retransmit with same IP ident | MAY-4 | | |x| | | 4599 Karn's algorithm | MUST-18|x| | | | | 4600 | | | | | | | 4601 Generating ACK's: | | | | | | | 4602 Aggregate whenever possible | MUST-58|x| | | | | 4603 Queue out-of-order segments | SHLD-31| |x| | | | 4604 Process all Q'd before send ACK | MUST-59|x| | | | | 4605 Send ACK for out-of-order segment | MAY-13 | | |x| | | 4606 Delayed ACK's | SHLD-18| |x| | | | 4607 Delay < 0.5 seconds | MUST-40|x| | | | | 4608 Every 2nd full-sized segment ACK'd | SHLD-19|x| | | | | 4609 Receiver SWS-Avoidance Algorithm | MUST-39|x| | | | | 4610 | | | | | | | 4611 Sending data | | | | | | | 4612 Configurable TTL | MUST-49|x| | | | | 4613 Sender SWS-Avoidance Algorithm | MUST-38|x| | | | | 4614 Nagle algorithm | SHLD-7 | |x| | | | 4615 Application can disable Nagle algorithm | MUST-17|x| | | | | 4616 | | | | | | | 4617 Connection Failures: | | | | | | | 4618 Negative advice to IP on R1 retxs | MUST-20|x| | | | | 4619 Close connection on R2 retxs | MUST-20|x| | | | | 4620 ALP can set R2 | MUST-21|x| | | | |1 4621 Inform ALP of R1<=retxs inform ALP | SHLD-25| |x| | | | 4649 Dest. Unreach (0,1,5) => abort conn | MUST-56| | | | |x| 4650 Dest. Unreach (2-4) => abort conn | SHLD-26| |x| | | | 4651 Source Quench => silent discard | MUST-55|x| | | | | 4652 Time Exceeded => tell ALP, don't abort | MUST-56| | | | |x| 4653 Param Problem => tell ALP, don't abort | MUST-56| | | | |x| 4654 | | | | | | | 4655 Address Validation | | | | | | | 4656 Reject OPEN call to invalid IP address | MUST-46|x| | | | | 4657 Reject SYN from invalid IP address | MUST-63|x| | | | | 4658 Silently discard SYN to bcast/mcast addr | MUST-57|x| | | | | 4659 | | | | | | | 4660 TCP/ALP Interface Services | | | | | | | 4661 Error Report mechanism | MUST-47|x| | | | | 4662 ALP can disable Error Report Routine | SHLD-20| |x| | | | 4663 ALP can specify DiffServ field for sending | MUST-48|x| | | | | 4664 Passed unchanged to IP | SHLD-22| |x| | | | 4665 ALP can change DiffServ field during connection| SHLD-21| |x| | | | 4666 ALP generally changing DiffServ during conn. | SHLD-23| | | |x| | 4667 Pass received DiffServ field up to ALP | MAY-9 | | |x| | | 4668 FLUSH call | MAY-14 | | |x| | | 4669 Optional local IP addr parm. in OPEN | MUST-43|x| | | | | 4670 | | | | | | | 4672 RFC 5961 Support: | | | | | | | 4673 Implement data injection protection | MAY-12 | | |x| | | 4674 | | | | | | | 4675 Explicit Congestion Notification: | | | | | | | 4676 Support ECN | SHLD-8 | |x| | | | 4677 -------------------------------------------------|--------|-|-|-|-|-|-- 4679 FOOTNOTES: (1) "ALP" means Application-Layer program. 4681 Author's Address 4683 Wesley M. Eddy (editor) 4684 MTI Systems 4685 US 4687 Email: wes@mti-systems.com