idnits 2.17.1 draft-ietf-tcpm-rfc793bis-12.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 (December 5, 2018) is 1967 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 4413, 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, December 5, 2018 5 6528, 6691 (if approved) 6 Updates: 5961, 1122 (if approved) 7 Intended status: Standards Track 8 Expires: June 8, 2019 10 Transmission Control Protocol Specification 11 draft-ietf-tcpm-rfc793bis-12 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 June 8, 2019. 55 Copyright Notice 57 Copyright (c) 2018 IETF Trust and the persons identified as the 58 document authors. All rights reserved. 60 This document is subject to BCP 78 and the IETF Trust's Legal 61 Provisions Relating to IETF Documents 62 (https://trustee.ietf.org/license-info) in effect on the date of 63 publication of this document. Please review these documents 64 carefully, as they describe your rights and restrictions with respect 65 to this document. Code Components extracted from this document must 66 include Simplified BSD License text as described in Section 4.e of 67 the Trust Legal Provisions and are provided without warranty as 68 described in the Simplified BSD License. 70 This document may contain material from IETF Documents or IETF 71 Contributions published or made publicly available before November 72 10, 2008. The person(s) controlling the copyright in some of this 73 material may not have granted the IETF Trust the right to allow 74 modifications of such material outside the IETF Standards Process. 75 Without obtaining an adequate license from the person(s) controlling 76 the copyright in such materials, this document may not be modified 77 outside the IETF Standards Process, and derivative works of it may 78 not be created outside the IETF Standards Process, except to format 79 it for publication as an RFC or to translate it into languages other 80 than English. 82 Table of Contents 84 1. Purpose and Scope . . . . . . . . . . . . . . . . . . . . . . 3 85 2. Introduction . . . . . . . . . . . . . . . . . . . . . . . . 4 86 2.1. Key TCP Concepts . . . . . . . . . . . . . . . . . . . . 5 87 3. Functional Specification . . . . . . . . . . . . . . . . . . 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 . . . . . . . . . . . . . 99 121 A.1. IP Security Compartment and Precedence . . . . . . . . . 99 122 A.2. Sequence Number Validation . . . . . . . . . . . . . . . 99 123 A.3. Nagle Modification . . . . . . . . . . . . . . . . . . . 100 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) (TODO - 2495 MUST here is inconsistent with SHOULDs in the section 2496 describing ICMP processing) 2498 * Excessive retransmissions (see Section 3.8.3) (TODO - MUST 2499 here is inconsistent with SHOULD in the section describing 2500 excessive retransmissions) 2502 * Urgent pointer advance (see Section 3.8.5) (MUST-32). 2504 However, an application program that does not want to receive 2505 such ERROR_REPORT calls SHOULD be able to effectively disable 2506 these calls (SHLD-20). 2508 Set Differentiated Services Field (IPv4 TOS or IPv6 Traffic Class) 2510 The application layer MUST be able to specify the 2511 Differentiated Services field for segments that are sent on a 2512 connection (MUST-48). The Differentiated Services field 2513 includes the 6-bit Differentiated Services Code Point (DSCP) 2514 value. It is not required, but the application SHOULD be able 2515 to change the Differentiated Services field during the 2516 connection lifetime (SHLD-21). TCP SHOULD pass the current 2517 Differentiated Services field value without change to the IP 2518 layer, when it sends segments on the connection (SHLD-22). 2520 The Differentiated Services field will be specified 2521 independently in each direction on the connection, so that the 2522 receiver application will specify the Differentiated Services 2523 field used for ACK segments. 2525 TCP MAY pass the most recently received Differentiated Services 2526 field up to the application (MAY-9). 2528 3.9.2. TCP/Lower-Level Interface 2530 The TCP calls on a lower level protocol module to actually send and 2531 receive information over a network. The two current standard 2532 Internet Protocol (IP) versions layered below TCP are IPv4 [1] and 2533 IPv6 [5]. 2535 If the lower level protocol is IPv4 it provides arguments for a type 2536 of service (used within the Differentiated Services field) and for a 2537 time to live. TCP uses the following settings for these parameters: 2539 DiffServ field: The IP header value for the DiffServ field is 2540 given by the user. This includes the bits of the DiffServ Code 2541 Point (DSCP). 2543 Time to Live (TTL): The TTL value used to send TCP segments MUST 2544 be configurable (MUST-49). 2546 Note that RFC 793 specified one minute (60 seconds) as a 2547 constant for the TTL, because the assumed maximum segment 2548 lifetime was two minutes. This was intended to explicitly ask 2549 that a segment be destroyed if it cannot be delivered by the 2550 internet system within one minute. RFC 1122 changed this 2551 specification to require that the TTL be configurable. 2553 Note that the DiffServ field is permitted to change during a 2554 connection (section 4.2.4.2 of RFC 1122). However, the 2555 application interface might not support this ability, and the 2556 application does not have knowledge about individual TCP 2557 segments, so this can only be done on a coarse granularity, at 2558 best. This limitation is further discussed in RFC 7657 (sec 2559 5.1, 5.3, and 6) [38]. Generally, an application SHOULD NOT 2560 change the DiffServ field value during the course of a 2561 connection (SHLD-23). 2563 Any lower level protocol will have to provide the source address, 2564 destination address, and protocol fields, and some way to determine 2565 the "TCP length", both to provide the functional equivalent service 2566 of IP and to be used in the TCP checksum. 2568 When received options are passed up to TCP from the IP layer, TCP 2569 MUST ignore options that it does not understand (MUST-50). 2571 A TCP MAY support the Time Stamp (MAY-10) and Record Route (MAY-11) 2572 options. 2574 3.9.2.1. Source Routing 2576 If the lower level is IP (or other protocol that provides this 2577 feature) and source routing is used, the interface must allow the 2578 route information to be communicated. This is especially important 2579 so that the source and destination addresses used in the TCP checksum 2580 be the originating source and ultimate destination. It is also 2581 important to preserve the return route to answer connection requests. 2583 An application MUST be able to specify a source route when it 2584 actively opens a TCP connection (MUST-51), and this MUST take 2585 precedence over a source route received in a datagram (MUST-52). 2587 When a TCP connection is OPENed passively and a packet arrives with a 2588 completed IP Source Route option (containing a return route), TCP 2589 MUST save the return route and use it for all segments sent on this 2590 connection (MUST-53). If a different source route arrives in a later 2591 segment, the later definition SHOULD override the earlier one (SHLD- 2592 24). 2594 3.9.2.2. ICMP Messages 2596 TCP MUST act on an ICMP error message passed up from the IP layer, 2597 directing it to the connection that created the error (MUST-54). The 2598 necessary demultiplexing information can be found in the IP header 2599 contained within the ICMP message. 2601 This applies to ICMPv6 in addition to IPv4 ICMP. 2603 [23] contains discussion of specific ICMP and ICMPv6 messages 2604 classified as either "soft" or "hard" errors that may bear different 2605 responses. Treatment for classes of ICMP messages is described 2606 below: 2608 Source Quench 2609 TCP MUST silently discard any received ICMP Source Quench messages 2610 (MUST-55). See [11] for discussion. 2612 Soft Errors 2613 For ICMP these include: Destination Unreachable -- codes 0, 1, 5, 2614 Time Exceeded -- codes 0, 1, and Parameter Problem. 2616 For ICMPv6 these include: Destination Unreachable -- codes 0 and 3, 2617 Time Exceeded -- codes 0, 1, and Parameter Problem -- codes 0, 1, 2 2618 Since these Unreachable messages indicate soft error conditions, 2619 TCP MUST NOT abort the connection (MUST-56), and it SHOULD make the 2620 information available to the application (SHLD-25). 2622 Hard Errors 2623 For ICMP these include Destination Unreachable -- codes 2-4"> 2624 These are hard error conditions, so TCP SHOULD abort the connection 2625 (SHLD-26). [23] notes that some implementations do not abort 2626 connections when an ICMP hard error is received for a connection 2627 that is in any of the synchronized states. 2629 Note that [23] section 4 describes widespread implementation behavior 2630 that treats soft errors as hard errors during connection 2631 establishment. 2633 3.9.2.3. Remote Address Validation 2635 RFC 1122 requires addresses to be validated in incoming SYN packets: 2637 An incoming SYN with an invalid source address MUST be ignored 2638 either by TCP or by the IP layer (MUST-63) (see Section 3.2.1.3 of 2639 [14]). 2641 A TCP implementation MUST silently discard an incoming SYN segment 2642 that is addressed to a broadcast or multicast address (MUST-57). 2644 This prevents connection state and replies from being erroneously 2645 generated, and implementers should note that this guidance is 2646 applicable to all incoming segments, not just SYNs, as specifically 2647 indicated in RFC 1122. 2649 3.10. Event Processing 2651 The processing depicted in this section is an example of one possible 2652 implementation. Other implementations may have slightly different 2653 processing sequences, but they should differ from those in this 2654 section only in detail, not in substance. 2656 The activity of the TCP can be characterized as responding to events. 2657 The events that occur can be cast into three categories: user calls, 2658 arriving segments, and timeouts. This section describes the 2659 processing the TCP does in response to each of the events. In many 2660 cases the processing required depends on the state of the connection. 2662 Events that occur: 2664 User Calls 2666 OPEN 2667 SEND 2668 RECEIVE 2669 CLOSE 2670 ABORT 2671 STATUS 2673 Arriving Segments 2675 SEGMENT ARRIVES 2677 Timeouts 2679 USER TIMEOUT 2680 RETRANSMISSION TIMEOUT 2681 TIME-WAIT TIMEOUT 2683 The model of the TCP/user interface is that user commands receive an 2684 immediate return and possibly a delayed response via an event or 2685 pseudo interrupt. In the following descriptions, the term "signal" 2686 means cause a delayed response. 2688 Error responses are given as character strings. For example, user 2689 commands referencing connections that do not exist receive "error: 2690 connection not open". 2692 Please note in the following that all arithmetic on sequence numbers, 2693 acknowledgment numbers, windows, et cetera, is modulo 2**32 the size 2694 of the sequence number space. Also note that "=<" means less than or 2695 equal to (modulo 2**32). 2697 A natural way to think about processing incoming segments is to 2698 imagine that they are first tested for proper sequence number (i.e., 2699 that their contents lie in the range of the expected "receive window" 2700 in the sequence number space) and then that they are generally queued 2701 and processed in sequence number order. 2703 When a segment overlaps other already received segments we 2704 reconstruct the segment to contain just the new data, and adjust the 2705 header fields to be consistent. 2707 Note that if no state change is mentioned the TCP stays in the same 2708 state. 2710 OPEN Call 2712 CLOSED STATE (i.e., TCB does not exist) 2714 Create a new transmission control block (TCB) to hold 2715 connection state information. Fill in local socket identifier, 2716 foreign socket, DiffServ field, security/compartment, and user 2717 timeout information. Note that some parts of the foreign 2718 socket may be unspecified in a passive OPEN and are to be 2719 filled in by the parameters of the incoming SYN segment. 2720 Verify the security and DiffServ value requested are allowed 2721 for this user, if not return "error: precedence not allowed" or 2722 "error: security/compartment not allowed." If passive enter 2723 the LISTEN state and return. If active and the foreign socket 2724 is unspecified, return "error: foreign socket unspecified"; if 2725 active and the foreign socket is specified, issue a SYN 2726 segment. An initial send sequence number (ISS) is selected. A 2727 SYN segment of the form is sent. Set 2728 SND.UNA to ISS, SND.NXT to ISS+1, enter SYN-SENT state, and 2729 return. 2731 If the caller does not have access to the local socket 2732 specified, return "error: connection illegal for this process". 2733 If there is no room to create a new connection, return "error: 2734 insufficient resources". 2736 LISTEN STATE 2738 If active and the foreign socket is specified, then change the 2739 connection from passive to active, select an ISS. Send a SYN 2740 segment, set SND.UNA to ISS, SND.NXT to ISS+1. Enter SYN-SENT 2741 state. Data associated with SEND may be sent with SYN segment 2742 or queued for transmission after entering ESTABLISHED state. 2743 The urgent bit if requested in the command must be sent with 2744 the data segments sent as a result of this command. If there 2745 is no room to queue the request, respond with "error: 2746 insufficient resources". If Foreign socket was not specified, 2747 then return "error: foreign socket unspecified". 2749 SYN-SENT STATE 2750 SYN-RECEIVED STATE 2751 ESTABLISHED STATE 2752 FIN-WAIT-1 STATE 2753 FIN-WAIT-2 STATE 2754 CLOSE-WAIT STATE 2755 CLOSING STATE 2756 LAST-ACK STATE 2757 TIME-WAIT STATE 2759 Return "error: connection already exists". 2761 SEND Call 2763 CLOSED STATE (i.e., TCB does not exist) 2765 If the user does not have access to such a connection, then 2766 return "error: connection illegal for this process". 2768 Otherwise, return "error: connection does not exist". 2770 LISTEN STATE 2772 If the foreign socket is specified, then change the connection 2773 from passive to active, select an ISS. Send a SYN segment, set 2774 SND.UNA to ISS, SND.NXT to ISS+1. Enter SYN-SENT state. Data 2775 associated with SEND may be sent with SYN segment or queued for 2776 transmission after entering ESTABLISHED state. The urgent bit 2777 if requested in the command must be sent with the data segments 2778 sent as a result of this command. If there is no room to queue 2779 the request, respond with "error: insufficient resources". If 2780 Foreign socket was not specified, then return "error: foreign 2781 socket unspecified". 2783 SYN-SENT STATE 2784 SYN-RECEIVED STATE 2786 Queue the data for transmission after entering ESTABLISHED 2787 state. If no space to queue, respond with "error: insufficient 2788 resources". 2790 ESTABLISHED STATE 2791 CLOSE-WAIT STATE 2793 Segmentize the buffer and send it with a piggybacked 2794 acknowledgment (acknowledgment value = RCV.NXT). If there is 2795 insufficient space to remember this buffer, simply return 2796 "error: insufficient resources". 2798 If the urgent flag is set, then SND.UP <- SND.NXT and set the 2799 urgent pointer in the outgoing segments. 2801 FIN-WAIT-1 STATE 2802 FIN-WAIT-2 STATE 2803 CLOSING STATE 2804 LAST-ACK STATE 2805 TIME-WAIT STATE 2807 Return "error: connection closing" and do not service request. 2809 RECEIVE Call 2811 CLOSED STATE (i.e., TCB does not exist) 2813 If the user does not have access to such a connection, return 2814 "error: connection illegal for this process". 2816 Otherwise return "error: connection does not exist". 2818 LISTEN STATE 2819 SYN-SENT STATE 2820 SYN-RECEIVED STATE 2822 Queue for processing after entering ESTABLISHED state. If 2823 there is no room to queue this request, respond with "error: 2824 insufficient resources". 2826 ESTABLISHED STATE 2827 FIN-WAIT-1 STATE 2828 FIN-WAIT-2 STATE 2830 If insufficient incoming segments are queued to satisfy the 2831 request, queue the request. If there is no queue space to 2832 remember the RECEIVE, respond with "error: insufficient 2833 resources". 2835 Reassemble queued incoming segments into receive buffer and 2836 return to user. Mark "push seen" (PUSH) if this is the case. 2838 If RCV.UP is in advance of the data currently being passed to 2839 the user notify the user of the presence of urgent data. 2841 When the TCP takes responsibility for delivering data to the 2842 user that fact must be communicated to the sender via an 2843 acknowledgment. The formation of such an acknowledgment is 2844 described below in the discussion of processing an incoming 2845 segment. 2847 CLOSE-WAIT STATE 2849 Since the remote side has already sent FIN, RECEIVEs must be 2850 satisfied by text already on hand, but not yet delivered to the 2851 user. If no text is awaiting delivery, the RECEIVE will get a 2852 "error: connection closing" response. Otherwise, any remaining 2853 text can be used to satisfy the RECEIVE. 2855 CLOSING STATE 2856 LAST-ACK STATE 2857 TIME-WAIT STATE 2859 Return "error: connection closing". 2861 CLOSE Call 2863 CLOSED STATE (i.e., TCB does not exist) 2865 If the user does not have access to such a connection, return 2866 "error: connection illegal for this process". 2868 Otherwise, return "error: connection does not exist". 2870 LISTEN STATE 2872 Any outstanding RECEIVEs are returned with "error: closing" 2873 responses. Delete TCB, enter CLOSED state, and return. 2875 SYN-SENT STATE 2877 Delete the TCB and return "error: closing" responses to any 2878 queued SENDs, or RECEIVEs. 2880 SYN-RECEIVED STATE 2882 If no SENDs have been issued and there is no pending data to 2883 send, then form a FIN segment and send it, and enter FIN-WAIT-1 2884 state; otherwise queue for processing after entering 2885 ESTABLISHED state. 2887 ESTABLISHED STATE 2889 Queue this until all preceding SENDs have been segmentized, 2890 then form a FIN segment and send it. In any case, enter FIN- 2891 WAIT-1 state. 2893 FIN-WAIT-1 STATE 2894 FIN-WAIT-2 STATE 2896 Strictly speaking, this is an error and should receive a 2897 "error: connection closing" response. An "ok" response would 2898 be acceptable, too, as long as a second FIN is not emitted (the 2899 first FIN may be retransmitted though). 2901 CLOSE-WAIT STATE 2903 Queue this request until all preceding SENDs have been 2904 segmentized; then send a FIN segment, enter LAST-ACK state. 2906 CLOSING STATE 2907 LAST-ACK STATE 2908 TIME-WAIT STATE 2909 Respond with "error: connection closing". 2911 ABORT Call 2913 CLOSED STATE (i.e., TCB does not exist) 2915 If the user should not have access to such a connection, return 2916 "error: connection illegal for this process". 2918 Otherwise return "error: connection does not exist". 2920 LISTEN STATE 2922 Any outstanding RECEIVEs should be returned with "error: 2923 connection reset" responses. Delete TCB, enter CLOSED state, 2924 and return. 2926 SYN-SENT STATE 2928 All queued SENDs and RECEIVEs should be given "connection 2929 reset" notification, delete the TCB, enter CLOSED state, and 2930 return. 2932 SYN-RECEIVED STATE 2933 ESTABLISHED STATE 2934 FIN-WAIT-1 STATE 2935 FIN-WAIT-2 STATE 2936 CLOSE-WAIT STATE 2938 Send a reset segment: 2940 2942 All queued SENDs and RECEIVEs should be given "connection 2943 reset" notification; all segments queued for transmission 2944 (except for the RST formed above) or retransmission should be 2945 flushed, delete the TCB, enter CLOSED state, and return. 2947 CLOSING STATE LAST-ACK STATE TIME-WAIT STATE 2949 Respond with "ok" and delete the TCB, enter CLOSED state, and 2950 return. 2952 STATUS Call 2954 CLOSED STATE (i.e., TCB does not exist) 2956 If the user should not have access to such a connection, return 2957 "error: connection illegal for this process". 2959 Otherwise return "error: connection does not exist". 2961 LISTEN STATE 2963 Return "state = LISTEN", and the TCB pointer. 2965 SYN-SENT STATE 2967 Return "state = SYN-SENT", and the TCB pointer. 2969 SYN-RECEIVED STATE 2971 Return "state = SYN-RECEIVED", and the TCB pointer. 2973 ESTABLISHED STATE 2975 Return "state = ESTABLISHED", and the TCB pointer. 2977 FIN-WAIT-1 STATE 2979 Return "state = FIN-WAIT-1", and the TCB pointer. 2981 FIN-WAIT-2 STATE 2983 Return "state = FIN-WAIT-2", and the TCB pointer. 2985 CLOSE-WAIT STATE 2987 Return "state = CLOSE-WAIT", and the TCB pointer. 2989 CLOSING STATE 2991 Return "state = CLOSING", and the TCB pointer. 2993 LAST-ACK STATE 2995 Return "state = LAST-ACK", and the TCB pointer. 2997 TIME-WAIT STATE 2999 Return "state = TIME-WAIT", and the TCB pointer. 3001 SEGMENT ARRIVES 3003 If the state is CLOSED (i.e., TCB does not exist) then 3005 all data in the incoming segment is discarded. An incoming 3006 segment containing a RST is discarded. An incoming segment not 3007 containing a RST causes a RST to be sent in response. The 3008 acknowledgment and sequence field values are selected to make 3009 the reset sequence acceptable to the TCP that sent the 3010 offending segment. 3012 If the ACK bit is off, sequence number zero is used, 3014 3016 If the ACK bit is on, 3018 3020 Return. 3022 If the state is LISTEN then 3024 first check for an RST 3026 An incoming RST should be ignored. Return. 3028 second check for an ACK 3030 Any acknowledgment is bad if it arrives on a connection 3031 still in the LISTEN state. An acceptable reset segment 3032 should be formed for any arriving ACK-bearing segment. The 3033 RST should be formatted as follows: 3035 3037 Return. 3039 third check for a SYN 3041 If the SYN bit is set, check the security. If the security/ 3042 compartment on the incoming segment does not exactly match 3043 the security/compartment in the TCB then send a reset and 3044 return. 3046 3048 Set RCV.NXT to SEG.SEQ+1, IRS is set to SEG.SEQ and any 3049 other control or text should be queued for processing later. 3050 ISS should be selected and a SYN segment sent of the form: 3052 3054 SND.NXT is set to ISS+1 and SND.UNA to ISS. The connection 3055 state should be changed to SYN-RECEIVED. Note that any 3056 other incoming control or data (combined with SYN) will be 3057 processed in the SYN-RECEIVED state, but processing of SYN 3058 and ACK should not be repeated. If the listen was not fully 3059 specified (i.e., the foreign socket was not fully 3060 specified), then the unspecified fields should be filled in 3061 now. 3063 fourth other text or control 3065 Any other control or text-bearing segment (not containing 3066 SYN) must have an ACK and thus would be discarded by the ACK 3067 processing. An incoming RST segment could not be valid, 3068 since it could not have been sent in response to anything 3069 sent by this incarnation of the connection. So you are 3070 unlikely to get here, but if you do, drop the segment, and 3071 return. 3073 If the state is SYN-SENT then 3075 first check the ACK bit 3077 If the ACK bit is set 3079 If SEG.ACK =< ISS, or SEG.ACK > SND.NXT, send a reset 3080 (unless the RST bit is set, if so drop the segment and 3081 return) 3083 3085 and discard the segment. Return. 3087 If SND.UNA < SEG.ACK =< SND.NXT then the ACK is 3088 acceptable. Some deployed TCP code has used the check 3089 SEG.ACK == SND.NXT (using "==" rather than "=<", but this 3090 is not appropriate when the stack is capable of sending 3091 data on the SYN, because the peer TCP may not accept and 3092 acknowledge all of the data on the SYN. 3094 second check the RST bit 3095 If the RST bit is set 3097 A potential blind reset attack is described in RFC 5961 3098 [28], with the mitigation that a TCP implementation 3099 SHOULD first check that the sequence number exactly 3100 matches RCV.NXT prior to executing the action in the next 3101 paragraph. 3103 If the ACK was acceptable then signal the user "error: 3104 connection reset", drop the segment, enter CLOSED state, 3105 delete TCB, and return. Otherwise (no ACK) drop the 3106 segment and return. 3108 third check the security 3110 If the security/compartment in the segment does not exactly 3111 match the security/compartment in the TCB, send a reset 3113 If there is an ACK 3115 3117 Otherwise 3119 3121 If a reset was sent, discard the segment and return. 3123 fourth check the SYN bit 3125 This step should be reached only if the ACK is ok, or there 3126 is no ACK, and it the segment did not contain a RST. 3128 If the SYN bit is on and the security/compartment is 3129 acceptable then, RCV.NXT is set to SEG.SEQ+1, IRS is set to 3130 SEG.SEQ. SND.UNA should be advanced to equal SEG.ACK (if 3131 there is an ACK), and any segments on the retransmission 3132 queue which are thereby acknowledged should be removed. 3134 If SND.UNA > ISS (our SYN has been ACKed), change the 3135 connection state to ESTABLISHED, form an ACK segment 3137 3139 and send it. Data or controls which were queued for 3140 transmission may be included. If there are other controls 3141 or text in the segment then continue processing at the sixth 3142 step below where the URG bit is checked, otherwise return. 3144 Otherwise enter SYN-RECEIVED, form a SYN,ACK segment 3146 3148 and send it. Set the variables: 3150 SND.WND <- SEG.WND 3151 SND.WL1 <- SEG.SEQ 3152 SND.WL2 <- SEG.ACK 3154 If there are other controls or text in the segment, queue 3155 them for processing after the ESTABLISHED state has been 3156 reached, return. 3158 Note that it is legal to send and receive application data 3159 on SYN segments (this is the "text in the segment" mentioned 3160 above. There has been significant misinformation and 3161 misunderstanding of this topic historically. Some firewalls 3162 and security devices consider this suspicious. However, the 3163 capability was used in T/TCP [16] and is used in TCP Fast 3164 Open (TFO) [36], so is important for implementations and 3165 network devices to permit. 3167 fifth, if neither of the SYN or RST bits is set then drop the 3168 segment and return. 3170 Otherwise, 3172 first check sequence number 3174 SYN-RECEIVED STATE 3175 ESTABLISHED STATE 3176 FIN-WAIT-1 STATE 3177 FIN-WAIT-2 STATE 3178 CLOSE-WAIT STATE 3179 CLOSING STATE 3180 LAST-ACK STATE 3181 TIME-WAIT STATE 3183 Segments are processed in sequence. Initial tests on 3184 arrival are used to discard old duplicates, but further 3185 processing is done in SEG.SEQ order. If a segment's 3186 contents straddle the boundary between old and new, only the 3187 new parts should be processed. 3189 In general, the processing of received segments MUST be 3190 implemented to aggregate ACK segments whenever possible 3191 (MUST-58). For example, if the TCP is processing a series 3192 of queued segments, it MUST process them all before sending 3193 any ACK segments (MUST-59). 3195 There are four cases for the acceptability test for an 3196 incoming segment: 3198 Segment Receive Test 3199 Length Window 3200 ------- ------- ------------------------------------------- 3202 0 0 SEG.SEQ = RCV.NXT 3204 0 >0 RCV.NXT =< SEG.SEQ < RCV.NXT+RCV.WND 3206 >0 0 not acceptable 3208 >0 >0 RCV.NXT =< SEG.SEQ < RCV.NXT+RCV.WND 3209 or RCV.NXT =< SEG.SEQ+SEG.LEN-1 < RCV.NXT+RCV.WND 3211 In implementing sequence number validation as described 3212 here, please note Appendix A.2. 3214 If the RCV.WND is zero, no segments will be acceptable, but 3215 special allowance should be made to accept valid ACKs, URGs 3216 and RSTs. 3218 If an incoming segment is not acceptable, an acknowledgment 3219 should be sent in reply (unless the RST bit is set, if so 3220 drop the segment and return): 3222 3224 After sending the acknowledgment, drop the unacceptable 3225 segment and return. 3227 Note that for the TIME-WAIT state, there is an improved 3228 algorithm described in [30] for handling incoming SYN 3229 segments, that utilizes timestamps rather than relying on 3230 the sequence number check described here. When the improved 3231 algorithm is implemented, the logic above is not applicable 3232 for incoming SYN segments with timestamp options, received 3233 on a connection in the TIME-WAIT state. 3235 In the following it is assumed that the segment is the 3236 idealized segment that begins at RCV.NXT and does not exceed 3237 the window. One could tailor actual segments to fit this 3238 assumption by trimming off any portions that lie outside the 3239 window (including SYN and FIN), and only processing further 3240 if the segment then begins at RCV.NXT. Segments with higher 3241 beginning sequence numbers SHOULD be held for later 3242 processing (SHLD-31). 3244 second check the RST bit, 3246 RFC 5961 section 3 describes a potential blind reset attack 3247 and optional mitigation approach that SHOULD be implemented. 3248 For stacks implementing RFC 5961, the three checks below 3249 apply, otherwise processesing for these states is indicated 3250 further below. 3252 1) If the RST bit is set and the sequence number is 3253 outside the current receive window, silently drop the 3254 segment. 3256 2) If the RST bit is set and the sequence number exactly 3257 matches the next expected sequence number (RCV.NXT), then 3258 TCP MUST reset the connection in the manner prescribed 3259 below according to the connection state. 3261 3) If the RST bit is set and the sequence number does not 3262 exactly match the next expected sequence value, yet is 3263 within the current receive window, TCP MUST send an 3264 acknowledgement (challenge ACK): 3266 3268 After sending the challenge ACK, TCP MUST drop the 3269 unacceptable segment and stop processing the incoming 3270 packet further. Note that RFC 5961 and Errata ID 4772 3271 contain additional considerations for ACK throttling in 3272 an implementation. 3274 SYN-RECEIVED STATE 3276 If the RST bit is set 3278 If this connection was initiated with a passive OPEN 3279 (i.e., came from the LISTEN state), then return this 3280 connection to LISTEN state and return. The user need 3281 not be informed. If this connection was initiated 3282 with an active OPEN (i.e., came from SYN-SENT state) 3283 then the connection was refused, signal the user 3284 "connection refused". In either case, all segments on 3285 the retransmission queue should be removed. And in 3286 the active OPEN case, enter the CLOSED state and 3287 delete the TCB, and return. 3289 ESTABLISHED 3290 FIN-WAIT-1 3291 FIN-WAIT-2 3292 CLOSE-WAIT 3294 If the RST bit is set then, any outstanding RECEIVEs and 3295 SEND should receive "reset" responses. All segment 3296 queues should be flushed. Users should also receive an 3297 unsolicited general "connection reset" signal. Enter the 3298 CLOSED state, delete the TCB, and return. 3300 CLOSING STATE 3301 LAST-ACK STATE 3302 TIME-WAIT 3304 If the RST bit is set then, enter the CLOSED state, 3305 delete the TCB, and return. 3307 third check security 3309 SYN-RECEIVED 3311 If the security/compartment in the segment does not 3312 exactly match the security/compartment in the TCB then 3313 send a reset, and return. 3315 ESTABLISHED 3316 FIN-WAIT-1 3317 FIN-WAIT-2 3318 CLOSE-WAIT 3319 CLOSING 3320 LAST-ACK 3321 TIME-WAIT 3323 If the security/compartment in the segment does not 3324 exactly match the security/compartment in the TCB then 3325 send a reset, any outstanding RECEIVEs and SEND should 3326 receive "reset" responses. All segment queues should be 3327 flushed. Users should also receive an unsolicited 3328 general "connection reset" signal. Enter the CLOSED 3329 state, delete the TCB, and return. 3331 Note this check is placed following the sequence check to 3332 prevent a segment from an old connection between these ports 3333 with a different security from causing an abort of the 3334 current connection. 3336 fourth, check the SYN bit, 3338 SYN-RECEIVED 3340 If the connection was initiated with a passive OPEN, then 3341 return this connection to the LISTEN state and return. 3342 Otherwise, handle per the directions for synchronized 3343 states below. 3345 ESTABLISHED STATE 3346 FIN-WAIT STATE-1 3347 FIN-WAIT STATE-2 3348 CLOSE-WAIT STATE 3349 CLOSING STATE 3350 LAST-ACK STATE 3351 TIME-WAIT STATE 3353 If the SYN bit is set in these synchronized states, it 3354 may be either a legitimate new connection attempt (e.g. 3355 in the case of TIME-WAIT), an error where the connection 3356 should be reset, or the result of an attack attempt, as 3357 described in RFC 5961 [28]. For the TIME-WAIT state, new 3358 connections can be accepted if the timestamp option is 3359 used and meets expectations (per [30]). For all other 3360 caess, RFC 5961 provides a mitigation that SHOULD be 3361 implemented, though there are alternatives (see 3362 Section 6). RFC 5961 recommends that in these 3363 synchronized states, if the SYN bit is set, irrespective 3364 of the sequence number, TCP MUST send a "challenge ACK" 3365 to the remote peer: 3367 3369 After sending the acknowledgement, TCP MUST drop the 3370 unacceptable segment and stop processing further. Note 3371 that RFC 5961 and Errata ID 4772 contain additional ACK 3372 throttling notes for an implementation. 3374 For implementations that do not follow RFC 5961, the 3375 original RFC 793 behavior follows in this paragraph. If 3376 the SYN is in the window it is an error, send a reset, 3377 any outstanding RECEIVEs and SEND should receive "reset" 3378 responses, all segment queues should be flushed, the user 3379 should also receive an unsolicited general "connection 3380 reset" signal, enter the CLOSED state, delete the TCB, 3381 and return. 3383 If the SYN is not in the window this step would not be 3384 reached and an ack would have been sent in the first step 3385 (sequence number check). 3387 fifth check the ACK field, 3389 if the ACK bit is off drop the segment and return 3391 if the ACK bit is on 3393 RFC 5961 section 5 describes a potential blind data 3394 injection attack, and mitigation that implementations MAY 3395 choose to include (MAY-12). TCP stacks that implement 3396 RFC 5961 MUST add an input check that the ACK value is 3397 acceptable only if it is in the range of ((SND.UNA - 3398 MAX.SND.WND) =< SEG.ACK =< SND.NXT). All incoming 3399 segments whose ACK value doesn't satisfy the above 3400 condition MUST be discarded and an ACK sent back. The 3401 new state variable MAX.SND.WND is defined as the largest 3402 window that the local sender has ever received from its 3403 peer (subject to window scaling) or may be hard-coded to 3404 a maximum permissible window value. When the ACK value 3405 is acceptable, the processing per-state below applies: 3407 SYN-RECEIVED STATE 3409 If SND.UNA < SEG.ACK =< SND.NXT then enter ESTABLISHED 3410 state and continue processing with variables below set 3411 to: 3413 SND.WND <- SEG.WND 3414 SND.WL1 <- SEG.SEQ 3415 SND.WL2 <- SEG.ACK 3417 If the segment acknowledgment is not acceptable, 3418 form a reset segment, 3420 3422 and send it. 3424 ESTABLISHED STATE 3426 If SND.UNA < SEG.ACK =< SND.NXT then, set SND.UNA <- 3427 SEG.ACK. Any segments on the retransmission queue 3428 which are thereby entirely acknowledged are removed. 3429 Users should receive positive acknowledgments for 3430 buffers which have been SENT and fully acknowledged 3431 (i.e., SEND buffer should be returned with "ok" 3432 response). If the ACK is a duplicate (SEG.ACK =< 3433 SND.UNA), it can be ignored. If the ACK acks 3434 something not yet sent (SEG.ACK > SND.NXT) then send 3435 an ACK, drop the segment, and return. 3437 If SND.UNA =< SEG.ACK =< SND.NXT, the send window 3438 should be updated. If (SND.WL1 < SEG.SEQ or (SND.WL1 3439 = SEG.SEQ and SND.WL2 =< SEG.ACK)), set SND.WND <- 3440 SEG.WND, set SND.WL1 <- SEG.SEQ, and set SND.WL2 <- 3441 SEG.ACK. 3443 Note that SND.WND is an offset from SND.UNA, that 3444 SND.WL1 records the sequence number of the last 3445 segment used to update SND.WND, and that SND.WL2 3446 records the acknowledgment number of the last segment 3447 used to update SND.WND. The check here prevents using 3448 old segments to update the window. 3450 FIN-WAIT-1 STATE 3452 In addition to the processing for the ESTABLISHED 3453 state, if our FIN is now acknowledged then enter FIN- 3454 WAIT-2 and continue processing in that state. 3456 FIN-WAIT-2 STATE 3458 In addition to the processing for the ESTABLISHED 3459 state, if the retransmission queue is empty, the 3460 user's CLOSE can be acknowledged ("ok") but do not 3461 delete the TCB. 3463 CLOSE-WAIT STATE 3465 Do the same processing as for the ESTABLISHED state. 3467 CLOSING STATE 3469 In addition to the processing for the ESTABLISHED 3470 state, if the ACK acknowledges our FIN then enter the 3471 TIME-WAIT state, otherwise ignore the segment. 3473 LAST-ACK STATE 3474 The only thing that can arrive in this state is an 3475 acknowledgment of our FIN. If our FIN is now 3476 acknowledged, delete the TCB, enter the CLOSED state, 3477 and return. 3479 TIME-WAIT STATE 3481 The only thing that can arrive in this state is a 3482 retransmission of the remote FIN. Acknowledge it, and 3483 restart the 2 MSL timeout. 3485 sixth, check the URG bit, 3487 ESTABLISHED STATE 3488 FIN-WAIT-1 STATE 3489 FIN-WAIT-2 STATE 3491 If the URG bit is set, RCV.UP <- max(RCV.UP,SEG.UP), and 3492 signal the user that the remote side has urgent data if 3493 the urgent pointer (RCV.UP) is in advance of the data 3494 consumed. If the user has already been signaled (or is 3495 still in the "urgent mode") for this continuous sequence 3496 of urgent data, do not signal the user again. 3498 CLOSE-WAIT STATE 3499 CLOSING STATE 3500 LAST-ACK STATE 3501 TIME-WAIT 3503 This should not occur, since a FIN has been received from 3504 the remote side. Ignore the URG. 3506 seventh, process the segment text, 3508 ESTABLISHED STATE 3509 FIN-WAIT-1 STATE 3510 FIN-WAIT-2 STATE 3512 Once in the ESTABLISHED state, it is possible to deliver 3513 segment text to user RECEIVE buffers. Text from segments 3514 can be moved into buffers until either the buffer is full 3515 or the segment is empty. If the segment empties and 3516 carries an PUSH flag, then the user is informed, when the 3517 buffer is returned, that a PUSH has been received. 3519 When the TCP takes responsibility for delivering the data 3520 to the user it must also acknowledge the receipt of the 3521 data. 3523 Once the TCP takes responsibility for the data it 3524 advances RCV.NXT over the data accepted, and adjusts 3525 RCV.WND as appropriate to the current buffer 3526 availability. The total of RCV.NXT and RCV.WND should 3527 not be reduced. 3529 A TCP MAY send an ACK segment acknowledging RCV.NXT when 3530 a valid segment arrives that is in the window but not at 3531 the left window edge (MAY-13). 3533 Please note the window management suggestions in 3534 Section 3.8. 3536 Send an acknowledgment of the form: 3538 3540 This acknowledgment should be piggybacked on a segment 3541 being transmitted if possible without incurring undue 3542 delay. 3544 CLOSE-WAIT STATE 3545 CLOSING STATE 3546 LAST-ACK STATE 3547 TIME-WAIT STATE 3549 This should not occur, since a FIN has been received from 3550 the remote side. Ignore the segment text. 3552 eighth, check the FIN bit, 3554 Do not process the FIN if the state is CLOSED, LISTEN or 3555 SYN-SENT since the SEG.SEQ cannot be validated; drop the 3556 segment and return. 3558 If the FIN bit is set, signal the user "connection closing" 3559 and return any pending RECEIVEs with same message, advance 3560 RCV.NXT over the FIN, and send an acknowledgment for the 3561 FIN. Note that FIN implies PUSH for any segment text not 3562 yet delivered to the user. 3564 SYN-RECEIVED STATE 3565 ESTABLISHED STATE 3567 Enter the CLOSE-WAIT state. 3569 FIN-WAIT-1 STATE 3570 If our FIN has been ACKed (perhaps in this segment), 3571 then enter TIME-WAIT, start the time-wait timer, turn 3572 off the other timers; otherwise enter the CLOSING 3573 state. 3575 FIN-WAIT-2 STATE 3577 Enter the TIME-WAIT state. Start the time-wait timer, 3578 turn off the other timers. 3580 CLOSE-WAIT STATE 3582 Remain in the CLOSE-WAIT state. 3584 CLOSING STATE 3586 Remain in the CLOSING state. 3588 LAST-ACK STATE 3590 Remain in the LAST-ACK state. 3592 TIME-WAIT STATE 3594 Remain in the TIME-WAIT state. Restart the 2 MSL 3595 time-wait timeout. 3597 and return. 3599 USER TIMEOUT 3601 USER TIMEOUT 3603 For any state if the user timeout expires, flush all queues, 3604 signal the user "error: connection aborted due to user timeout" 3605 in general and for any outstanding calls, delete the TCB, enter 3606 the CLOSED state and return. 3608 RETRANSMISSION TIMEOUT 3610 For any state if the retransmission timeout expires on a 3611 segment in the retransmission queue, send the segment at the 3612 front of the retransmission queue again, reinitialize the 3613 retransmission timer, and return. 3615 TIME-WAIT TIMEOUT 3617 If the time-wait timeout expires on a connection delete the 3618 TCB, enter the CLOSED state and return. 3620 3.11. Glossary 3622 1822 BBN Report 1822, "The Specification of the Interconnection of 3623 a Host and an IMP". The specification of interface between a 3624 host and the ARPANET. 3626 ACK 3627 A control bit (acknowledge) occupying no sequence space, 3628 which indicates that the acknowledgment field of this segment 3629 specifies the next sequence number the sender of this segment 3630 is expecting to receive, hence acknowledging receipt of all 3631 previous sequence numbers. 3633 ARPANET message 3634 The unit of transmission between a host and an IMP in the 3635 ARPANET. The maximum size is about 1012 octets (8096 bits). 3637 ARPANET packet 3638 A unit of transmission used internally in the ARPANET between 3639 IMPs. The maximum size is about 126 octets (1008 bits). 3641 connection 3642 A logical communication path identified by a pair of sockets. 3644 datagram 3645 A message sent in a packet switched computer communications 3646 network. 3648 Destination Address 3649 The destination address, usually the network and host 3650 identifiers. 3652 FIN 3653 A control bit (finis) occupying one sequence number, which 3654 indicates that the sender will send no more data or control 3655 occupying sequence space. 3657 fragment 3658 A portion of a logical unit of data, in particular an 3659 internet fragment is a portion of an internet datagram. 3661 FTP 3662 A file transfer protocol. 3664 header 3665 Control information at the beginning of a message, segment, 3666 fragment, packet or block of data. 3668 host 3669 A computer. In particular a source or destination of 3670 messages from the point of view of the communication network. 3672 Identification 3673 An Internet Protocol field. This identifying value assigned 3674 by the sender aids in assembling the fragments of a datagram. 3676 IMP 3677 The Interface Message Processor, the packet switch of the 3678 ARPANET. 3680 internet address 3681 A source or destination address specific to the host level. 3683 internet datagram 3684 The unit of data exchanged between an internet module and the 3685 higher level protocol together with the internet header. 3687 internet fragment 3688 A portion of the data of an internet datagram with an 3689 internet header. 3691 IP 3692 Internet Protocol. 3694 IRS 3695 The Initial Receive Sequence number. The first sequence 3696 number used by the sender on a connection. 3698 ISN 3699 The Initial Sequence Number. The first sequence number used 3700 on a connection, (either ISS or IRS). Selected in a way that 3701 is unique within a given period of time and is unpredictable 3702 to attackers. 3704 ISS 3705 The Initial Send Sequence number. The first sequence number 3706 used by the sender on a connection. 3708 leader 3709 Control information at the beginning of a message or block of 3710 data. In particular, in the ARPANET, the control information 3711 on an ARPANET message at the host-IMP interface. 3713 left sequence 3714 This is the next sequence number to be acknowledged by the 3715 data receiving TCP (or the lowest currently unacknowledged 3716 sequence number) and is sometimes referred to as the left 3717 edge of the send window. 3719 local packet 3720 The unit of transmission within a local network. 3722 module 3723 An implementation, usually in software, of a protocol or 3724 other procedure. 3726 MSL 3727 Maximum Segment Lifetime, the time a TCP segment can exist in 3728 the internetwork system. Arbitrarily defined to be 2 3729 minutes. 3731 octet 3732 An eight bit byte. 3734 Options 3735 An Option field may contain several options, and each option 3736 may be several octets in length. 3738 packet 3739 A package of data with a header which may or may not be 3740 logically complete. More often a physical packaging than a 3741 logical packaging of data. 3743 port 3744 The portion of a socket that specifies which logical input or 3745 output channel of a process is associated with the data. 3747 process 3748 A program in execution. A source or destination of data from 3749 the point of view of the TCP or other host-to-host protocol. 3751 PUSH 3752 A control bit occupying no sequence space, indicating that 3753 this segment contains data that must be pushed through to the 3754 receiving user. 3756 RCV.NXT 3757 receive next sequence number 3759 RCV.UP 3760 receive urgent pointer 3762 RCV.WND 3763 receive window 3765 receive next sequence number 3766 This is the next sequence number the local TCP is expecting 3767 to receive. 3769 receive window 3770 This represents the sequence numbers the local (receiving) 3771 TCP is willing to receive. Thus, the local TCP considers 3772 that segments overlapping the range RCV.NXT to RCV.NXT + 3773 RCV.WND - 1 carry acceptable data or control. Segments 3774 containing sequence numbers entirely outside of this range 3775 are considered duplicates and discarded. 3777 RST 3778 A control bit (reset), occupying no sequence space, 3779 indicating that the receiver should delete the connection 3780 without further interaction. The receiver can determine, 3781 based on the sequence number and acknowledgment fields of the 3782 incoming segment, whether it should honor the reset command 3783 or ignore it. In no case does receipt of a segment 3784 containing RST give rise to a RST in response. 3786 RTP 3787 Real Time Protocol: A host-to-host protocol for communication 3788 of time critical information. 3790 SEG.ACK 3791 segment acknowledgment 3793 SEG.LEN 3794 segment length 3796 SEG.SEQ 3797 segment sequence 3799 SEG.UP 3800 segment urgent pointer field 3802 SEG.WND 3803 segment window field 3805 segment 3806 A logical unit of data, in particular a TCP segment is the 3807 unit of data transfered between a pair of TCP modules. 3809 segment acknowledgment 3810 The sequence number in the acknowledgment field of the 3811 arriving segment. 3813 segment length 3814 The amount of sequence number space occupied by a segment, 3815 including any controls which occupy sequence space. 3817 segment sequence 3818 The number in the sequence field of the arriving segment. 3820 send sequence 3821 This is the next sequence number the local (sending) TCP will 3822 use on the connection. It is initially selected from an 3823 initial sequence number curve (ISN) and is incremented for 3824 each octet of data or sequenced control transmitted. 3826 send window 3827 This represents the sequence numbers which the remote 3828 (receiving) TCP is willing to receive. It is the value of 3829 the window field specified in segments from the remote (data 3830 receiving) TCP. The range of new sequence numbers which may 3831 be emitted by a TCP lies between SND.NXT and SND.UNA + 3832 SND.WND - 1. (Retransmissions of sequence numbers between 3833 SND.UNA and SND.NXT are expected, of course.) 3835 SND.NXT 3836 send sequence 3838 SND.UNA 3839 left sequence 3841 SND.UP 3842 send urgent pointer 3844 SND.WL1 3845 segment sequence number at last window update 3847 SND.WL2 3848 segment acknowledgment number at last window update 3850 SND.WND 3851 send window 3853 socket 3854 An address which specifically includes a port identifier, 3855 that is, the concatenation of an Internet Address with a TCP 3856 port. 3858 Source Address 3859 The source address, usually the network and host identifiers. 3861 SYN 3862 A control bit in the incoming segment, occupying one sequence 3863 number, used at the initiation of a connection, to indicate 3864 where the sequence numbering will start. 3866 TCB 3867 Transmission control block, the data structure that records 3868 the state of a connection. 3870 TCP 3871 Transmission Control Protocol: A host-to-host protocol for 3872 reliable communication in internetwork environments. 3874 TOS 3875 Type of Service, an obsoleted IPv4 field. The same header 3876 bits currently are used for the Differentiated Services field 3877 [6] containing the Differentiated Services Code Point (DSCP) 3878 value and two unused bits. 3880 Type of Service 3881 An Internet Protocol field which indicates the type of 3882 service for this internet fragment. 3884 URG 3885 A control bit (urgent), occupying no sequence space, used to 3886 indicate that the receiving user should be notified to do 3887 urgent processing as long as there is data to be consumed 3888 with sequence numbers less than the value indicated in the 3889 urgent pointer. 3891 urgent pointer 3892 A control field meaningful only when the URG bit is on. This 3893 field communicates the value of the urgent pointer which 3894 indicates the data octet associated with the sending user's 3895 urgent call. 3897 4. Changes from RFC 793 3899 This document obsoletes RFC 793 as well as RFC 6093 and 6528, which 3900 updated 793. In all cases, only the normative protocol specification 3901 and requirements have been incorporated into this document, and the 3902 informational text with background and rationale has not been carried 3903 in. The informational content of those documents is still valuable 3904 in learning about and understanding TCP, and they are valid 3905 Informational references, even though their normative content has 3906 been incorporated into this document. 3908 The main body of this document was adapted from RFC 793's Section 3, 3909 titled "FUNCTIONAL SPECIFICATION", with an attempt to keep formatting 3910 and layout as close as possible. 3912 The collection of applicable RFC Errata that have been reported and 3913 either accepted or held for an update to RFC 793 were incorporated 3914 (Errata IDs: 573, 574, 700, 701, 1283, 1561, 1562, 1564, 1565, 1571, 3915 1572, 2296, 2297, 2298, 2748, 2749, 2934, 3213, 3300, 3301). Some 3916 errata were not applicable due to other changes (Errata IDs: 572, 3917 575, 1569, 3305, 3602). 3919 Changes to the specification of the Urgent Pointer described in RFC 3920 1122 and 6093 were incorporated. See RFC 6093 for detailed 3921 discussion of why these changes were necessary. 3923 The discussion of the RTO from RFC 793 was updated to refer to RFC 3924 6298. The RFC 1122 text on the RTO originally replaced the 793 text, 3925 however, RFC 2988 should have updated 1122, and has subsequently been 3926 obsoleted by 6298. 3928 RFC 1122 contains a collection of other changes and clarifications to 3929 RFC 793. The normative items impacting the protocol have been 3930 incorporated here, though some historically useful implementation 3931 advice and informative discussion from RFC 1122 is not included here. 3933 RFC 1122 contains more than just TCP requirements, so this document 3934 can't obsolete RFC 1122 entirely. It is only marked as "updating" 3935 1122, however, it should be understood to effectively obsolete all of 3936 the RFC 1122 material on TCP. 3938 The more secure Initial Sequence Number generation algorithm from RFC 3939 6528 was incorporated. See RFC 6528 for discussion of the attacks 3940 that this mitigates, as well as advice on selecting PRF algorithms 3941 and managing secret key data. 3943 A note based on RFC 6429 was added to explicitly clarify that system 3944 resource mangement concerns allow connection resources to be 3945 reclaimed. RFC 6429 is obsoleted in the sense that this 3946 clarification has been reflected in this update to the base TCP 3947 specification now. 3949 RFC EDITOR'S NOTE: the content below is for detailed change tracking 3950 and planning, and not to be included with the final revision of the 3951 document. 3953 This document started as draft-eddy-rfc793bis-00, that was merely a 3954 proposal and rough plan for updating RFC 793. 3956 The -01 revision of this draft-eddy-rfc793bis incorporates the 3957 content of RFC 793 Section 3 titled "FUNCTIONAL SPECIFICATION". 3958 Other content from RFC 793 has not been incorporated. The -01 3959 revision of this document makes some minor formatting changes to the 3960 RFC 793 content in order to convert the content into XML2RFC format 3961 and account for left-out parts of RFC 793. For instance, figure 3962 numbering differs and some indentation is not exactly the same. 3964 The -02 revision of draft-eddy-rfc793bis incorporates errata that 3965 have been verified: 3967 Errata ID 573: Reported by Bob Braden (note: This errata basically 3968 is just a reminder that RFC 1122 updates 793. Some of the 3969 associated changes are left pending to a separate revision that 3970 incorporates 1122. Bob's mention of PUSH in 793 section 2.8 was 3971 not applicable here because that section was not part of the 3972 "functional specification". Also the 1122 text on the 3973 retransmission timeout also has been updated by subsequent RFCs, 3974 so the change here deviates from Bob's suggestion to apply the 3975 1122 text.) 3976 Errata ID 574: Reported by Yin Shuming 3977 Errata ID 700: Reported by Yin Shuming 3978 Errata ID 701: Reported by Yin Shuming 3979 Errata ID 1283: Reported by Pei-chun Cheng 3980 Errata ID 1561: Reported by Constantin Hagemeier 3981 Errata ID 1562: Reported by Constantin Hagemeier 3982 Errata ID 1564: Reported by Constantin Hagemeier 3983 Errata ID 1565: Reported by Constantin Hagemeier 3984 Errata ID 1571: Reported by Constantin Hagemeier 3985 Errata ID 1572: Reported by Constantin Hagemeier 3986 Errata ID 2296: Reported by Vishwas Manral 3987 Errata ID 2297: Reported by Vishwas Manral 3988 Errata ID 2298: Reported by Vishwas Manral 3989 Errata ID 2748: Reported by Mykyta Yevstifeyev 3990 Errata ID 2749: Reported by Mykyta Yevstifeyev 3991 Errata ID 2934: Reported by Constantin Hagemeier 3992 Errata ID 3213: Reported by EugnJun Yi 3993 Errata ID 3300: Reported by Botong Huang 3994 Errata ID 3301: Reported by Botong Huang 3995 Errata ID 3305: Reported by Botong Huang 3996 Note: Some verified errata were not used in this update, as they 3997 relate to sections of RFC 793 elided from this document. These 3998 include Errata ID 572, 575, and 1569. 3999 Note: Errata ID 3602 was not applied in this revision as it is 4000 duplicative of the 1122 corrections. 4002 Not related to RFC 793 content, this revision also makes small tweaks 4003 to the introductory text, fixes indentation of the pseudoheader 4004 diagram, and notes that the Security Considerations should also 4005 include privacy, when this section is written. 4007 The -03 revision of draft-eddy-rfc793bis revises all discussion of 4008 the urgent pointer in order to comply with RFC 6093, 1122, and 1011. 4009 Since 1122 held requirements on the urgent pointer, the full list of 4010 requirements was brought into an appendix of this document, so that 4011 it can be updated as-needed. 4013 The -04 revision of draft-eddy-rfc793bis includes the ISN generation 4014 changes from RFC 6528. 4016 The -05 revision of draft-eddy-rfc793bis incorporates MSS 4017 requirements and definitions from RFC 879, 1122, and 6691, as well as 4018 option-handling requirements from RFC 1122. 4020 The -00 revision of draft-ietf-tcpm-rfc793bis incorporates several 4021 additional clarifications and updates to the section on segmentation, 4022 many of which are based on feedback from Joe Touch improving from the 4023 initial text on this in the previous revision. 4025 The -01 revision incorporates the change to Reserved bits due to ECN, 4026 as well as many other changes that come from RFC 1122. 4028 The -02 revision has small formating modifications in order to 4029 address xml2rfc warnings about long lines. It was a quick update to 4030 avoid document expiration. TCPM working group discussion in 2015 4031 also indicated that that we should not try to add sections on 4032 implementation advice or similar non-normative information. 4034 The -03 revision incorporates more content from RFC 1122: Passive 4035 OPEN Calls, Time-To-Live, Multihoming, IP Options, ICMP messages, 4036 Data Communications, When to Send Data, When to Send a Window Update, 4037 Managing the Window, Probing Zero Windows, When to Send an ACK 4038 Segment. The section on data communications was re-organized into 4039 clearer subsections (previously headings were embedded in the 793 4040 text), and windows management advice from 793 was removed (as 4041 reviewed by TCPM working group) in favor of the 1122 additions on 4042 SWS, ZWP, and related topics. 4044 The -04 revision includes reference to RFC 6429 on the ZWP condition, 4045 RFC1122 material on TCP Connection Failures, TCP Keep-Alives, 4046 Acknowledging Queued Segments, and Remote Address Validation. RTO 4047 computation is referenced from RFC 6298 rather than RFC 1122. 4049 The -05 revision includes the requirement to implement TCP congestion 4050 control with recommendation to implemente ECN, the RFC 6633 update to 4051 1122, which changed the requirement on responding to source quench 4052 ICMP messages, and discussion of ICMP (and ICMPv6) soft and hard 4053 errors per RFC 5461 (ICMPv6 handling for TCP doesn't seem to be 4054 mentioned elsewhere in standards track). 4056 The -06 revision includes an appendix on "Other Implementation Notes" 4057 to capture widely-deployed fundamental features that are not 4058 contained in the RFC series yet. It also added mention of RFC 6994 4059 and the IANA TCP parameters registry as a reference. It includes 4060 references to RFC 5961 in appropriate places. The references to TOS 4061 were changed to DiffServ field, based on reflecting RFC 2474 as well 4062 as the IPv6 presence of traffic class (carrying DiffServ field) 4063 rather than TOS. 4065 The -07 revision includes reference to RFC 6191, updated security 4066 considerations, discussion of additional implementation 4067 considerations, and clarification of data on the SYN. 4069 The -08 revision includes changes based on: 4071 describing treatment of reserved bits (following TCPM mailing list 4072 thread from July 2014 on "793bis item - reserved bit behavior" 4073 addition a brief TCP key concepts section to make up for not 4074 including the outdated section 2 of RFC 793 4075 changed "TCP" to "host" to resolve conflict between 1122 wording 4076 on whether TCP or the network layer chooses an address when 4077 multihomed 4078 fixed/updated definition of options in glossary 4079 moved note on aggregating ACKs from 1122 to a more appropriate 4080 location 4081 resolved notes on IP precedence and security/compartment 4082 added implementation note on sequence number validation 4083 added note that PUSH does not apply when Nagle is active 4084 added 1122 content on asynchronous reports to replace 793 section 4085 on TCP to user messages 4087 The -09 revision fixes section numbering problems. 4089 The -10 revision includes additions to the security considerations 4090 based on comments from Joe Touch, and suggested edits on RST/FIN 4091 notification, RFC 2525 reference, and other edits suggested by 4092 Yuchung Cheng, as well as modifications to DiffServ text from Yuchung 4093 Cheng and Gorry Fairhurst. 4095 The -11 revision includes a start at identifying all of the 4096 requirements text and referencing each instance in the common table 4097 at the end of the document. 4099 The -12 revision completes the requirement language indexing started 4100 in -11 and adds necessary description of the PUSH functionality that 4101 was missing. 4103 Some other suggested changes that will not be incorporated in this 4104 793 update unless TCPM consensus changes with regard to scope are: 4106 1. look at Tony Sabatini suggestion for describing DO field 4107 2. per discussion with Joe Touch (TAPS list, 6/20/2015), the 4108 description of the API could be revisited 4110 Early in the process of updating RFC 793, Scott Brim mentioned that 4111 this should include a PERPASS/privacy review. This may be something 4112 for the chairs or AD to request during WGLC or IETF LC. 4114 5. IANA Considerations 4116 This memo includes no request to IANA. Existing IANA registries for 4117 TCP parameters are sufficient. 4119 TODO: check whether entries pointing to 793 and other documents 4120 obsoleted by this one should be updated to point to this one instead. 4122 6. Security and Privacy Considerations 4124 The TCP design includes only rudimentary security features that 4125 improve the robustness and reliability of connections and application 4126 data transfer, but there are no built-in cryptographic capabilities 4127 to support any form of privacy, authentication, or other typical 4128 security functions. Non-cryptographic enhancements (e.g. [28]) have 4129 been developed to improve robustness of TCP connections to particular 4130 types of attacks, but the applicability and protections of non- 4131 cryptographic enhancements are limited (e.g. see section 1.1 of 4132 [28]). Applications typically utilize lower-layer (e.g. IPsec) and 4133 upper-layer (e.g. TLS) protocols to provide security and privacy for 4134 TCP connections and application data carried in TCP. Methods based 4135 on TCP options have been developed as well, to support some security 4136 capabilities. 4138 In order to fully protect TCP connections (including their control 4139 flags) IPsec or the TCP Authentication Option (TCP-AO) [27] are the 4140 only current effective methods. Other methods discussed in this 4141 section may protect the payload, but either only a subset of the 4142 fields (e.g. tcpcrypt) or none at all (e.g. TLS). Other security 4143 features that have been added to TCP (e.g. ISN generation, sequence 4144 number checks, etc.) are only capable of partially hindering attacks. 4146 Applications using long-lived TCP flows have been vulnerable to 4147 attacks that exploit the processing of control flags described in 4148 earlier TCP specifications [21]. TCP-MD5 was a commonly implemented 4149 TCP option to support authentication for some of these connections, 4150 but had flaws and is now deprecated. TCP-AO provides a capability to 4151 protect long-lived TCP connections from attacks, and has superior 4152 properties to TCP-MD5. It does not provide any privacy for 4153 application data, nor for the TCP headers. 4155 The "tcpcrypt" [44]Experimental extension to TCP provides the ability 4156 to cryptographically protect connection data. Metadata aspects of 4157 the TCP flow are still visible, but the application stream is well- 4158 protected. Within the TCP header, only the urgent pointer and FIN 4159 flag are protected through tcpcrypt. 4161 The TCP Roadmap [37] includes notes about several RFCs related to TCP 4162 security. Many of the enhancements provided by these RFCs have been 4163 integrated into the present document, including ISN generation, 4164 mitigating blind in-window attacks, and improving handling of soft 4165 errors and ICMP packets. These are all discussed in greater detail 4166 in the referenced RFCs that originally described the changes needed 4167 to earlier TCP specifications. Additionally, see RFC 6093 [29] for 4168 discussion of security considerations related to the urgent pointer 4169 field, that has been deprecated. 4171 Since TCP is often used for bulk transfer flows, some attacks are 4172 possible that abuse the TCP congestion control logic. An example is 4173 "ACK-division" attacks. Updates that have been made to the TCP 4174 congestion control specifications include mechanisms like Appropriate 4175 Byte Counting (ABC) that act as mitigations to these attacks. 4177 Other attacks are focused on exhausting the resources of a TCP 4178 server. Examples include SYN flooding [20] or wasting resources on 4179 non-progressing connections [31]. Operating systems commonly 4180 implement mitigations for these attacks. Some common defenses also 4181 utilize proxies, stateful firewalls, and other technologies outside 4182 of the end-host TCP implementation. 4184 7. Acknowledgements 4186 This document is largely a revision of RFC 793, which Jon Postel was 4187 the editor of. Due to his excellent work, it was able to last for 4188 three decades before we felt the need to revise it. 4190 Andre Oppermann was a contributor and helped to edit the first 4191 revision of this document. 4193 We are thankful for the assistance of the IETF TCPM working group 4194 chairs: 4196 Michael Scharf 4197 Yoshifumi Nishida 4198 Pasi Sarolahti 4200 During early discussion of this work on the TCPM mailing list, and at 4201 the IETF 88 meeting in Vancouver, helpful comments, critiques, and 4202 reviews were received from (listed alphebetically): David Borman, 4203 Yuchung Cheng, Martin Duke, Kevin Lahey, Kevin Mason, Matt Mathis, 4204 Hagen Paul Pfeifer, Anthony Sabatini, Joe Touch, Reji Varghese, Lloyd 4205 Wood, and Alex Zimmermann. Joe Touch provided help in clarifying the 4206 description of segment size parameters and PMTUD/PLPMTUD 4207 recommendations. 4209 This document includes content from errata that were reported by 4210 (listed chronologically): Yin Shuming, Bob Braden, Morris M. Keesan, 4211 Pei-chun Cheng, Constantin Hagemeier, Vishwas Manral, Mykyta 4212 Yevstifeyev, EungJun Yi, Botong Huang. 4214 8. References 4216 8.1. Normative References 4218 [1] Postel, J., "Internet Protocol", STD 5, RFC 791, 4219 DOI 10.17487/RFC0791, September 1981, 4220 . 4222 [2] Mogul, J. and S. Deering, "Path MTU discovery", RFC 1191, 4223 DOI 10.17487/RFC1191, November 1990, 4224 . 4226 [3] McCann, J., Deering, S., and J. Mogul, "Path MTU Discovery 4227 for IP version 6", RFC 1981, DOI 10.17487/RFC1981, August 4228 1996, . 4230 [4] Bradner, S., "Key words for use in RFCs to Indicate 4231 Requirement Levels", BCP 14, RFC 2119, 4232 DOI 10.17487/RFC2119, March 1997, 4233 . 4235 [5] Deering, S. and R. Hinden, "Internet Protocol, Version 6 4236 (IPv6) Specification", RFC 2460, DOI 10.17487/RFC2460, 4237 December 1998, . 4239 [6] Nichols, K., Blake, S., Baker, F., and D. Black, 4240 "Definition of the Differentiated Services Field (DS 4241 Field) in the IPv4 and IPv6 Headers", RFC 2474, 4242 DOI 10.17487/RFC2474, December 1998, 4243 . 4245 [7] Borman, D., Deering, S., and R. Hinden, "IPv6 Jumbograms", 4246 RFC 2675, DOI 10.17487/RFC2675, August 1999, 4247 . 4249 [8] Lahey, K., "TCP Problems with Path MTU Discovery", 4250 RFC 2923, DOI 10.17487/RFC2923, September 2000, 4251 . 4253 [9] Ramakrishnan, K., Floyd, S., and D. Black, "The Addition 4254 of Explicit Congestion Notification (ECN) to IP", 4255 RFC 3168, DOI 10.17487/RFC3168, September 2001, 4256 . 4258 [10] Paxson, V., Allman, M., Chu, J., and M. Sargent, 4259 "Computing TCP's Retransmission Timer", RFC 6298, 4260 DOI 10.17487/RFC6298, June 2011, 4261 . 4263 [11] Gont, F., "Deprecation of ICMP Source Quench Messages", 4264 RFC 6633, DOI 10.17487/RFC6633, May 2012, 4265 . 4267 8.2. Informative References 4269 [12] Postel, J., "Transmission Control Protocol", STD 7, 4270 RFC 793, DOI 10.17487/RFC0793, September 1981, 4271 . 4273 [13] Nagle, J., "Congestion Control in IP/TCP Internetworks", 4274 RFC 896, DOI 10.17487/RFC0896, January 1984, 4275 . 4277 [14] Braden, R., Ed., "Requirements for Internet Hosts - 4278 Communication Layers", STD 3, RFC 1122, 4279 DOI 10.17487/RFC1122, October 1989, 4280 . 4282 [15] Almquist, P., "Type of Service in the Internet Protocol 4283 Suite", RFC 1349, DOI 10.17487/RFC1349, July 1992, 4284 . 4286 [16] Braden, R., "T/TCP -- TCP Extensions for Transactions 4287 Functional Specification", RFC 1644, DOI 10.17487/RFC1644, 4288 July 1994, . 4290 [17] Paxson, V., Allman, M., Dawson, S., Fenner, W., Griner, 4291 J., Heavens, I., Lahey, K., Semke, J., and B. Volz, "Known 4292 TCP Implementation Problems", RFC 2525, 4293 DOI 10.17487/RFC2525, March 1999, 4294 . 4296 [18] Xiao, X., Hannan, A., Paxson, V., and E. Crabbe, "TCP 4297 Processing of the IPv4 Precedence Field", RFC 2873, 4298 DOI 10.17487/RFC2873, June 2000, 4299 . 4301 [19] Mathis, M. and J. Heffner, "Packetization Layer Path MTU 4302 Discovery", RFC 4821, DOI 10.17487/RFC4821, March 2007, 4303 . 4305 [20] Eddy, W., "TCP SYN Flooding Attacks and Common 4306 Mitigations", RFC 4987, DOI 10.17487/RFC4987, August 2007, 4307 . 4309 [21] Touch, J., "Defending TCP Against Spoofing Attacks", 4310 RFC 4953, DOI 10.17487/RFC4953, July 2007, 4311 . 4313 [22] Culley, P., Elzur, U., Recio, R., Bailey, S., and J. 4314 Carrier, "Marker PDU Aligned Framing for TCP 4315 Specification", RFC 5044, DOI 10.17487/RFC5044, October 4316 2007, . 4318 [23] Gont, F., "TCP's Reaction to Soft Errors", RFC 5461, 4319 DOI 10.17487/RFC5461, February 2009, 4320 . 4322 [24] StJohns, M., Atkinson, R., and G. Thomas, "Common 4323 Architecture Label IPv6 Security Option (CALIPSO)", 4324 RFC 5570, DOI 10.17487/RFC5570, July 2009, 4325 . 4327 [25] Allman, M., Paxson, V., and E. Blanton, "TCP Congestion 4328 Control", RFC 5681, DOI 10.17487/RFC5681, September 2009, 4329 . 4331 [26] Sandlund, K., Pelletier, G., and L-E. Jonsson, "The RObust 4332 Header Compression (ROHC) Framework", RFC 5795, 4333 DOI 10.17487/RFC5795, March 2010, 4334 . 4336 [27] Touch, J., Mankin, A., and R. Bonica, "The TCP 4337 Authentication Option", RFC 5925, DOI 10.17487/RFC5925, 4338 June 2010, . 4340 [28] Ramaiah, A., Stewart, R., and M. Dalal, "Improving TCP's 4341 Robustness to Blind In-Window Attacks", RFC 5961, 4342 DOI 10.17487/RFC5961, August 2010, 4343 . 4345 [29] Gont, F. and A. Yourtchenko, "On the Implementation of the 4346 TCP Urgent Mechanism", RFC 6093, DOI 10.17487/RFC6093, 4347 January 2011, . 4349 [30] Gont, F., "Reducing the TIME-WAIT State Using TCP 4350 Timestamps", BCP 159, RFC 6191, DOI 10.17487/RFC6191, 4351 April 2011, . 4353 [31] Bashyam, M., Jethanandani, M., and A. Ramaiah, "TCP Sender 4354 Clarification for Persist Condition", RFC 6429, 4355 DOI 10.17487/RFC6429, December 2011, 4356 . 4358 [32] Gont, F. and S. Bellovin, "Defending against Sequence 4359 Number Attacks", RFC 6528, DOI 10.17487/RFC6528, February 4360 2012, . 4362 [33] Borman, D., "TCP Options and Maximum Segment Size (MSS)", 4363 RFC 6691, DOI 10.17487/RFC6691, July 2012, 4364 . 4366 [34] Touch, J., "Shared Use of Experimental TCP Options", 4367 RFC 6994, DOI 10.17487/RFC6994, August 2013, 4368 . 4370 [35] Borman, D., Braden, B., Jacobson, V., and R. 4371 Scheffenegger, Ed., "TCP Extensions for High Performance", 4372 RFC 7323, DOI 10.17487/RFC7323, September 2014, 4373 . 4375 [36] Cheng, Y., Chu, J., Radhakrishnan, S., and A. Jain, "TCP 4376 Fast Open", RFC 7413, DOI 10.17487/RFC7413, December 2014, 4377 . 4379 [37] Duke, M., Braden, R., Eddy, W., Blanton, E., and A. 4380 Zimmermann, "A Roadmap for Transmission Control Protocol 4381 (TCP) Specification Documents", RFC 7414, 4382 DOI 10.17487/RFC7414, February 2015, 4383 . 4385 [38] Black, D., Ed. and P. Jones, "Differentiated Services 4386 (Diffserv) and Real-Time Communication", RFC 7657, 4387 DOI 10.17487/RFC7657, November 2015, 4388 . 4390 [39] Fairhurst, G. and M. Welzl, "The Benefits of Using 4391 Explicit Congestion Notification (ECN)", RFC 8087, 4392 DOI 10.17487/RFC8087, March 2017, 4393 . 4395 [40] Fairhurst, G., Ed., Trammell, B., Ed., and M. Kuehlewind, 4396 Ed., "Services Provided by IETF Transport Protocols and 4397 Congestion Control Mechanisms", RFC 8095, 4398 DOI 10.17487/RFC8095, March 2017, 4399 . 4401 [41] IANA, "Transmission Control Protocol (TCP) Parameters, 4402 https://www.iana.org/assignments/tcp-parameters/ 4403 tcp-parameters.xhtml", 2017. 4405 [42] Gont, F., "Processing of IP Security/Compartment and 4406 Precedence Information by TCP", draft-gont-tcpm-tcp- 4407 seccomp-prec-00 (work in progress), March 2012. 4409 [43] Gont, F. and D. Borman, "On the Validation of TCP Sequence 4410 Numbers", draft-gont-tcpm-tcp-seq-validation-02 (work in 4411 progress), March 2015. 4413 [44] Bittau, A., Giffin, D., Handley, M., Mazieres, D., Slack, 4414 Q., and E. Smith, "Cryptographic protection of TCP Streams 4415 (tcpcrypt)", draft-ietf-tcpinc-tcpcrypt-09 (work in 4416 progress), November 2017. 4418 [45] Minshall, G., "A Proposed Modification to Nagle's 4419 Algorithm", draft-minshall-nagle-01 (work in progress), 4420 June 1999. 4422 [46] Dalal, Y. and C. Sunshine, "Connection Management in 4423 Transport Protocols", Computer Networks Vol. 2, No. 6, pp. 4424 454-473, December 1978. 4426 Appendix A. Other Implementation Notes 4428 This section includes additional notes and references on TCP 4429 implementation decisions that are currently not a part of the RFC 4430 series or included within the TCP standard. These items can be 4431 considered by implementers, but there was not yet a consensus to 4432 include them in the standard. 4434 A.1. IP Security Compartment and Precedence 4436 RFC 793 requires checking the IP security compartment and precedence 4437 on incoming TCP segments for consistency within a connection, and 4438 with application requests. Each of these aspects of IP have become 4439 outdated, without specific updates to RFC 793. The issues with 4440 precedence were fixed by [18] which is Standards Track, and so this 4441 present TCP specification includes those changes. However, the state 4442 of IP security options that may be used by MLS systems is not as 4443 clean. 4445 Implementers of MLS systems that use IP security options (e.g. IPSO, 4446 CIPSO, or CALIPSO) should implement any additional logic appropriate 4447 for their requirements. 4449 Reseting connections when incoming packets do not meet expected 4450 security compartment or precedence expectations has been recognized 4451 as a possible attack vector [42], and there has been discussion about 4452 ammending the TCP specification to prevent connections from being 4453 aborted due to non-matching IP security compartment and DiffServ 4454 codepoint values. 4456 A.2. Sequence Number Validation 4458 There are cases where the TCP sequence number validation rules can 4459 prevent ACK fields from being processed. This can result in 4460 connection issues, as described in [43], which includes descriptions 4461 of potential problems in conditions of simultaneous open, self- 4462 connects, simultaneous close, and simultaneous window probes. The 4463 document also describes potential changes to the TCP specification to 4464 mitigate the issue by expanding the acceptable sequence numbers. 4466 In Internet usage of TCP, these conditions are rarely occuring. 4467 Common operating systems include different alternative mitigations, 4468 and the standard has not been updated yet to codify one of them, but 4469 implementers should consider the problems described in [43]. 4471 A.3. Nagle Modification 4473 In common operating systems, both the Nagle algorithm and delayed 4474 acknowledgements are implemented and enabled by default. TCP is used 4475 by many applications that have a request-response style of 4476 communication, where the combination of the Nagle algorithm and 4477 delayed acknowledgements can result in poor application performance. 4478 A modification to the Nagle algorithm is described in [45] that 4479 improves the situation for these applications. 4481 This modification is implemented in some common operating systems, 4482 and does not impact TCP interoperability. Additionally, many 4483 applications simply disable Nagle, since this is generally supported 4484 by a socket option. The TCP standard has not been updated to include 4485 this Nagle modification, but implementers may find it beneficial to 4486 consider. 4488 A.4. Low Water Mark 4490 TODO - mention the low watermark function that is in Linux - 4491 suggested by Michael Welzl 4493 SO_SNDLOWAT and SO_RCVLOWAT would be potential enhancements to the 4494 abstract TCP API 4496 TCP_NOTSENT_LOWAT is what Michael is talking about, that helps a 4497 sending TCP application to help avoid creating large amounts of 4498 buffered data (and corresponding latency). This is useful for 4499 applications that are multiplexing data from multiple upper level 4500 streams onto a connection, especially when streams may be a mix of 4501 interactive/realtime and bulk data transfer. 4503 Appendix B. TCP Requirement Summary 4505 This section is adapted from RFC 1122. 4507 Note that there is no requirement related to PLPMTUD in this list, 4508 but that PLPMTUD is recommended. 4510 | | | | |S| | 4511 | | | | |H| |F 4512 | | | | |O|M|o 4513 | | |S| |U|U|o 4514 | | |H| |L|S|t 4515 | |M|O| |D|T|n 4516 | |U|U|M| | |o 4517 | |S|L|A|N|N|t 4518 | |T|D|Y|O|O|t 4519 FEATURE | ReqID | | | |T|T|e 4520 -------------------------------------------------|--------|-|-|-|-|-|-- 4521 | | | | | | | 4522 Push flag | | | | | | | 4523 Aggregate or queue un-pushed data | MAY-16 | | |x| | | 4524 Sender collapse successive PSH flags | SHLD-27| |x| | | | 4525 SEND call can specify PUSH | MAY-15 | | |x| | | 4526 If cannot: sender buffer indefinitely | MUST-60| | | | |x| 4527 If cannot: PSH last segment | MUST-61|x| | | | | 4528 Notify receiving ALP of PSH | MAY-17 | | |x| | |1 4529 Send max size segment when possible | SHLD-28| |x| | | | 4530 | | | | | | | 4531 Window | | | | | | | 4532 Treat as unsigned number | MUST-1 |x| | | | | 4533 Handle as 32-bit number | REC-1 | |x| | | | 4534 Shrink window from right | SHLD-14| | | |x| | 4535 - Send new data when window shrinks | SHLD-15| | | |x| | 4536 - Retransmit old unacked data within window | SHLD-16| |x| | | | 4537 - Time out conn for data past right edge | SHLD-17| | | |x| | 4538 Robust against shrinking window | MUST-34|x| | | | | 4539 Receiver's window closed indefinitely | MAY-8 | | |x| | | 4540 Use standard probing logic | MUST-35|x| | | | | 4541 Sender probe zero window | MUST-36|x| | | | | 4542 First probe after RTO | SHLD-29| |x| | | | 4543 Exponential backoff | SHLD-30| |x| | | | 4544 Allow window stay zero indefinitely | MUST-37|x| | | | | 4545 Retransmit old data beyond SND.UNA+SND.WND | MAY-7 | | |x| | | 4546 | | | | | | | 4547 Urgent Data | | | | | | | 4548 Include support for urgent pointer | MUST-30|x| | | | | 4549 Pointer indicates first non-urgent octet | MUST-62|x| | | | | 4550 Arbitrary length urgent data sequence | MUST-31|x| | | | | 4551 Inform ALP asynchronously of urgent data | MUST-32|x| | | | |1 4552 ALP can learn if/how much urgent data Q'd | MUST-33|x| | | | |1 4553 ALP employ the urgent mechanism | SHLD-13| | | |x| | 4554 | | | | | | | 4555 TCP Options | | | | | | | 4556 Support the mandatory option set | MUST-4 |x| | | | | 4557 Receive TCP option in any segment | MUST-5 |x| | | | | 4558 Ignore unsupported options | MUST-6 |x| | | | | 4559 Cope with illegal option length | MUST-7 |x| | | | | 4560 Implement sending & receiving MSS option | MUST-14|x| | | | | 4561 IPv4 Send MSS option unless 536 | SHLD-5 | |x| | | | 4562 IPv6 Send MSS option unless 1220 | SHLD-5 | |x| | | | 4563 Send MSS option always | MAY-3 | | |x| | | 4564 IPv4 Send-MSS default is 536 | MUST-15|x| | | | | 4565 IPv6 Send-MSS default is 1220 | MUST-15|x| | | | | 4566 Calculate effective send seg size | MUST-16|x| | | | | 4567 MSS accounts for varying MTU | SHLD-6 | |x| | | | 4568 | | | | | | | 4569 TCP Checksums | | | | | | | 4570 Sender compute checksum | MUST-2 |x| | | | | 4571 Receiver check checksum | MUST-3 |x| | | | | 4572 | | | | | | | 4573 ISN Selection | | | | | | | 4574 Include a clock-driven ISN generator component | MUST-8 |x| | | | | 4575 Secure ISN generator with a PRF component | SHLD-1 | |x| | | | 4576 PRF computable from outside the host | MUST-9 | | | | |x| 4577 | | | | | | | 4578 Opening Connections | | | | | | | 4579 Support simultaneous open attempts | MUST-10|x| | | | | 4580 SYN-RECEIVED remembers last state | MUST-11|x| | | | | 4581 Passive Open call interfere with others | MUST-41| | | | |x| 4582 Function: simultan. LISTENs for same port | MUST-42|x| | | | | 4583 Ask IP for src address for SYN if necc. | MUST-44|x| | | | | 4584 Otherwise, use local addr of conn. | MUST-45|x| | | | | 4585 OPEN to broadcast/multicast IP Address | MUST-46| | | | |x| 4586 Silently discard seg to bcast/mcast addr | MUST-57|x| | | | | 4587 | | | | | | | 4588 Closing Connections | | | | | | | 4589 RST can contain data | SHLD-2 | |x| | | | 4590 Inform application of aborted conn | MUST-12|x| | | | | 4591 Half-duplex close connections | MAY-1 | | |x| | | 4592 Send RST to indicate data lost | SHLD-3 | |x| | | | 4593 In TIME-WAIT state for 2MSL seconds | MUST-13|x| | | | | 4594 Accept SYN from TIME-WAIT state | MAY-2 | | |x| | | 4595 Use Timestamps to reduce TIME-WAIT | SHLD-4 | |x| | | | 4596 | | | | | | | 4597 Retransmissions | | | | | | | 4598 Implement RFC 5681 | MUST-19|x| | | | | 4599 Retransmit with same IP ident | MAY-4 | | |x| | | 4600 Karn's algorithm | MUST-18|x| | | | | 4601 | | | | | | | 4602 Generating ACK's: | | | | | | | 4603 Aggregate whenever possible | MUST-58|x| | | | | 4604 Queue out-of-order segments | SHLD-31| |x| | | | 4605 Process all Q'd before send ACK | MUST-59|x| | | | | 4606 Send ACK for out-of-order segment | MAY-13 | | |x| | | 4607 Delayed ACK's | SHLD-18| |x| | | | 4608 Delay < 0.5 seconds | MUST-40|x| | | | | 4609 Every 2nd full-sized segment ACK'd | SHLD-19|x| | | | | 4610 Receiver SWS-Avoidance Algorithm | MUST-39|x| | | | | 4611 | | | | | | | 4612 Sending data | | | | | | | 4613 Configurable TTL | MUST-49|x| | | | | 4614 Sender SWS-Avoidance Algorithm | MUST-38|x| | | | | 4615 Nagle algorithm | SHLD-7 | |x| | | | 4616 Application can disable Nagle algorithm | MUST-17|x| | | | | 4617 | | | | | | | 4618 Connection Failures: | | | | | | | 4619 Negative advice to IP on R1 retxs | MUST-20|x| | | | | 4620 Close connection on R2 retxs | MUST-20|x| | | | | 4621 ALP can set R2 | MUST-21|x| | | | |1 4622 Inform ALP of R1<=retxs inform ALP | SHLD-25| |x| | | | 4650 Dest. Unreach (0,1,5) => abort conn | MUST-56| | | | |x| 4651 Dest. Unreach (2-4) => abort conn | SHLD-26| |x| | | | 4652 Source Quench => silent discard | MUST-55|x| | | | | 4653 Time Exceeded => tell ALP, don't abort | MUST-56| | | | |x| 4654 Param Problem => tell ALP, don't abort | MUST-56| | | | |x| 4655 | | | | | | | 4656 Address Validation | | | | | | | 4657 Reject OPEN call to invalid IP address | MUST-46|x| | | | | 4658 Reject SYN from invalid IP address | MUST-63|x| | | | | 4659 Silently discard SYN to bcast/mcast addr | MUST-57|x| | | | | 4660 | | | | | | | 4661 TCP/ALP Interface Services | | | | | | | 4662 Error Report mechanism | MUST-47|x| | | | | 4663 ALP can disable Error Report Routine | SHLD-20| |x| | | | 4664 ALP can specify DiffServ field for sending | MUST-48|x| | | | | 4665 Passed unchanged to IP | SHLD-22| |x| | | | 4666 ALP can change DiffServ field during connection| SHLD-21| |x| | | | 4667 ALP generally changing DiffServ during conn. | SHLD-23| | | |x| | 4668 Pass received DiffServ field up to ALP | MAY-9 | | |x| | | 4669 FLUSH call | MAY-14 | | |x| | | 4670 Optional local IP addr parm. in OPEN | MUST-43|x| | | | | 4671 | | | | | | | 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