idnits 2.17.1 draft-ietf-tcpm-rfc793bis-24.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 too long lines in the document, the longest one being 54 characters in excess of 72. == 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 == The document seems to lack the recommended RFC 2119 boilerplate, even if it appears to use RFC 2119 keywords -- however, there's a paragraph with a matching beginning. Boilerplate error? (The document does seem to have the reference to RFC 2119 which the ID-Checklist requires). (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 (July 12, 2021) is 1012 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) -- Looks like a reference, but probably isn't: 'Options' on line 302 -- Looks like a reference, but probably isn't: 'RFC8311' on line 4373 -- Looks like a reference, but probably isn't: 'RFC3540' on line 4373 -- Looks like a reference, but probably isn't: 'RFC3168' on line 4375 -- Obsolete informational reference (is this intentional?): RFC 793 (ref. '16') (Obsoleted by RFC 9293) -- Obsolete informational reference (is this intentional?): RFC 896 (ref. '17') (Obsoleted by RFC 7805) -- Obsolete informational reference (is this intentional?): RFC 1349 (ref. '19') (Obsoleted by RFC 2474) -- Obsolete informational reference (is this intentional?): RFC 1644 (ref. '20') (Obsoleted by RFC 6247) -- Obsolete informational reference (is this intentional?): RFC 2873 (ref. '23') (Obsoleted by RFC 9293) -- Obsolete informational reference (is this intentional?): RFC 6093 (ref. '38') (Obsoleted by RFC 9293) -- Obsolete informational reference (is this intentional?): RFC 6429 (ref. '40') (Obsoleted by RFC 9293) -- Obsolete informational reference (is this intentional?): RFC 6528 (ref. '41') (Obsoleted by RFC 9293) -- Obsolete informational reference (is this intentional?): RFC 6691 (ref. '42') (Obsoleted by RFC 9293) == Outdated reference: A later version (-13) exists of draft-ietf-tcpm-tcp-edo-10 == Outdated reference: A later version (-13) exists of draft-mcquistin-augmented-ascii-diagrams-08 Summary: 2 errors (**), 0 flaws (~~), 5 warnings (==), 19 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, July 12, 2021 5 6528, 6691 (if approved) 6 Updates: 5961, 1122 (if approved) 7 Intended status: Standards Track 8 Expires: January 13, 2022 10 Transmission Control Protocol (TCP) Specification 11 draft-ietf-tcpm-rfc793bis-24 13 Abstract 15 This document specifies the Transmission Control Protocol (TCP). TCP 16 is an important transport layer protocol in the Internet protocol 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 RFCs 879, 2873, 6093, 23 6429, 6528, and 6691 that updated parts of RFC 793. It updates RFC 24 1122, and should be considered as a replacement for the portions of 25 that document dealing with TCP requirements. It also updates RFC 26 5961 by adding a small clarification in reset handling while in the 27 SYN-RECEIVED state. The TCP header control bits from RFC 793 have 28 also been updated based on RFC 3168. 30 RFC EDITOR NOTE: If approved for publication as an RFC, this should 31 be marked additionally as "STD: 7" and replace RFC 793 in that role. 33 Status of This Memo 35 This Internet-Draft is submitted in full conformance with the 36 provisions of BCP 78 and BCP 79. 38 Internet-Drafts are working documents of the Internet Engineering 39 Task Force (IETF). Note that other groups may also distribute 40 working documents as Internet-Drafts. The list of current Internet- 41 Drafts is at https://datatracker.ietf.org/drafts/current/. 43 Internet-Drafts are draft documents valid for a maximum of six months 44 and may be updated, replaced, or obsoleted by other documents at any 45 time. It is inappropriate to use Internet-Drafts as reference 46 material or to cite them other than as "work in progress." 48 This Internet-Draft will expire on January 13, 2022. 50 Copyright Notice 52 Copyright (c) 2021 IETF Trust and the persons identified as the 53 document authors. All rights reserved. 55 This document is subject to BCP 78 and the IETF Trust's Legal 56 Provisions Relating to IETF Documents 57 (https://trustee.ietf.org/license-info) in effect on the date of 58 publication of this document. Please review these documents 59 carefully, as they describe your rights and restrictions with respect 60 to this document. Code Components extracted from this document must 61 include Simplified BSD License text as described in Section 4.e of 62 the Trust Legal Provisions and are provided without warranty as 63 described in the Simplified BSD License. 65 This document may contain material from IETF Documents or IETF 66 Contributions published or made publicly available before November 67 10, 2008. The person(s) controlling the copyright in some of this 68 material may not have granted the IETF Trust the right to allow 69 modifications of such material outside the IETF Standards Process. 70 Without obtaining an adequate license from the person(s) controlling 71 the copyright in such materials, this document may not be modified 72 outside the IETF Standards Process, and derivative works of it may 73 not be created outside the IETF Standards Process, except to format 74 it for publication as an RFC or to translate it into languages other 75 than English. 77 Table of Contents 79 1. Purpose and Scope . . . . . . . . . . . . . . . . . . . . . . 3 80 2. Introduction . . . . . . . . . . . . . . . . . . . . . . . . 4 81 2.1. Requirements Language . . . . . . . . . . . . . . . . . . 5 82 2.2. Key TCP Concepts . . . . . . . . . . . . . . . . . . . . 5 83 3. Functional Specification . . . . . . . . . . . . . . . . . . 6 84 3.1. Header Format . . . . . . . . . . . . . . . . . . . . . . 6 85 3.2. Specific Option Definitions . . . . . . . . . . . . . . . 11 86 3.2.1. Other Common Options . . . . . . . . . . . . . . . . 13 87 3.2.2. Experimental TCP Options . . . . . . . . . . . . . . 13 88 3.3. TCP Terminology Overview . . . . . . . . . . . . . . . . 13 89 3.3.1. Key Connection State Variables . . . . . . . . . . . 13 90 3.3.2. State Machine Overview . . . . . . . . . . . . . . . 15 91 3.4. Sequence Numbers . . . . . . . . . . . . . . . . . . . . 18 92 3.5. Establishing a connection . . . . . . . . . . . . . . . . 25 93 3.6. Closing a Connection . . . . . . . . . . . . . . . . . . 32 94 3.6.1. Half-Closed Connections . . . . . . . . . . . . . . . 34 95 3.7. Segmentation . . . . . . . . . . . . . . . . . . . . . . 35 96 3.7.1. Maximum Segment Size Option . . . . . . . . . . . . . 36 97 3.7.2. Path MTU Discovery . . . . . . . . . . . . . . . . . 38 98 3.7.3. Interfaces with Variable MTU Values . . . . . . . . . 38 99 3.7.4. Nagle Algorithm . . . . . . . . . . . . . . . . . . . 39 100 3.7.5. IPv6 Jumbograms . . . . . . . . . . . . . . . . . . . 39 101 3.8. Data Communication . . . . . . . . . . . . . . . . . . . 39 102 3.8.1. Retransmission Timeout . . . . . . . . . . . . . . . 40 103 3.8.2. TCP Congestion Control . . . . . . . . . . . . . . . 41 104 3.8.3. TCP Connection Failures . . . . . . . . . . . . . . . 41 105 3.8.4. TCP Keep-Alives . . . . . . . . . . . . . . . . . . . 42 106 3.8.5. The Communication of Urgent Information . . . . . . . 43 107 3.8.6. Managing the Window . . . . . . . . . . . . . . . . . 44 108 3.9. Interfaces . . . . . . . . . . . . . . . . . . . . . . . 49 109 3.9.1. User/TCP Interface . . . . . . . . . . . . . . . . . 49 110 3.9.2. TCP/Lower-Level Interface . . . . . . . . . . . . . . 58 111 3.10. Event Processing . . . . . . . . . . . . . . . . . . . . 60 112 3.10.1. OPEN Call . . . . . . . . . . . . . . . . . . . . . 62 113 3.10.2. SEND Call . . . . . . . . . . . . . . . . . . . . . 63 114 3.10.3. RECEIVE Call . . . . . . . . . . . . . . . . . . . . 64 115 3.10.4. CLOSE Call . . . . . . . . . . . . . . . . . . . . . 65 116 3.10.5. ABORT Call . . . . . . . . . . . . . . . . . . . . . 66 117 3.10.6. STATUS Call . . . . . . . . . . . . . . . . . . . . 67 118 3.10.7. SEGMENT ARRIVES . . . . . . . . . . . . . . . . . . 68 119 3.10.8. Timeouts . . . . . . . . . . . . . . . . . . . . . . 81 120 4. Glossary . . . . . . . . . . . . . . . . . . . . . . . . . . 81 121 5. Changes from RFC 793 . . . . . . . . . . . . . . . . . . . . 86 122 6. IANA Considerations . . . . . . . . . . . . . . . . . . . . . 92 123 7. Security and Privacy Considerations . . . . . . . . . . . . . 93 124 8. Acknowledgements . . . . . . . . . . . . . . . . . . . . . . 95 125 9. References . . . . . . . . . . . . . . . . . . . . . . . . . 95 126 9.1. Normative References . . . . . . . . . . . . . . . . . . 96 127 9.2. Informative References . . . . . . . . . . . . . . . . . 97 128 Appendix A. Other Implementation Notes . . . . . . . . . . . . . 102 129 A.1. IP Security Compartment and Precedence . . . . . . . . . 102 130 A.1.1. Precedence . . . . . . . . . . . . . . . . . . . . . 102 131 A.1.2. MLS Systems . . . . . . . . . . . . . . . . . . . . . 103 132 A.2. Sequence Number Validation . . . . . . . . . . . . . . . 103 133 A.3. Nagle Modification . . . . . . . . . . . . . . . . . . . 104 134 A.4. Low Water Mark Settings . . . . . . . . . . . . . . . . . 104 135 Appendix B. TCP Requirement Summary . . . . . . . . . . . . . . 104 136 Author's Address . . . . . . . . . . . . . . . . . . . . . . . . 108 138 1. Purpose and Scope 140 In 1981, RFC 793 [16] was released, documenting the Transmission 141 Control Protocol (TCP), and replacing earlier specifications for TCP 142 that had been published in the past. 144 Since then, TCP has been widely implemented, and has been used as a 145 transport protocol for numerous applications on the Internet. 147 For several decades, RFC 793 plus a number of other documents have 148 combined to serve as the core specification for TCP [48]. Over time, 149 a number of errata have been filed against RFC 793, as well as 150 deficiencies in security, performance, and many other aspects. The 151 number of enhancements has grown over time across many separate 152 documents. These were never accumulated together into a 153 comprehensive update to the base specification. 155 The purpose of this document is to bring together all of the IETF 156 Standards Track changes that have been made to the base TCP 157 functional specification and unify them into an update of RFC 793. 159 Some companion documents are referenced for important algorithms that 160 are used by TCP (e.g. for congestion control), but have not been 161 completely included in this document. This is a conscious choice, as 162 this base specification can be used with multiple additional 163 algorithms that are developed and incorporated separately. This 164 document focuses on the common basis all TCP implementations must 165 support in order to interoperate. Since some additional TCP features 166 have become quite complicated themselves (e.g. advanced loss recovery 167 and congestion control), future companion documents may attempt to 168 similarly bring these together. 170 In addition to the protocol specification that describes the TCP 171 segment format, generation, and processing rules that are to be 172 implemented in code, RFC 793 and other updates also contain 173 informative and descriptive text for readers to understand aspects of 174 the protocol design and operation. This document does not attempt to 175 alter or update this informative text, and is focused only on 176 updating the normative protocol specification. This document 177 preserves references to the documentation containing the important 178 explanations and rationale, where appropriate. 180 This document is intended to be useful both in checking existing TCP 181 implementations for conformance purposes, as well as in writing new 182 implementations. 184 2. Introduction 186 RFC 793 contains a discussion of the TCP design goals and provides 187 examples of its operation, including examples of connection 188 establishment, connection termination, packet retransmission to 189 repair losses. 191 This document describes the basic functionality expected in modern 192 TCP implementations, and replaces the protocol specification in RFC 193 793. It does not replicate or attempt to update the introduction and 194 philosophy content in Sections 1 and 2 of RFC 793. Other documents 195 are referenced to provide explanation of the theory of operation, 196 rationale, and detailed discussion of design decisions. This 197 document only focuses on the normative behavior of the protocol. 199 The "TCP Roadmap" [48] provides a more extensive guide to the RFCs 200 that define TCP and describe various important algorithms. The TCP 201 Roadmap contains sections on strongly encouraged enhancements that 202 improve performance and other aspects of TCP beyond the basic 203 operation specified in this document. As one example, implementing 204 congestion control (e.g. [9]) is a TCP requirement, but is a complex 205 topic on its own, and not described in detail in this document, as 206 there are many options and possibilities that do not impact basic 207 interoperability. Similarly, most TCP implementations today include 208 the high-performance extensions in [46], but these are not strictly 209 required or discussed in this document. Multipath considerations for 210 TCP are also specified separately in [55]. 212 A list of changes from RFC 793 is contained in Section 5. 214 2.1. Requirements Language 216 The key words "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT", 217 "SHOULD", "SHOULD NOT", "RECOMMENDED", "NOT RECOMMENDED", "MAY", and 218 "OPTIONAL" in this document are to be interpreted as described in BCP 219 14 [3][12] when, and only when, they appear in all capitals, as shown 220 here. 222 Each use of RFC 2119 keywords in the document is individually labeled 223 and referenced in Appendix B that summarizes implementation 224 requirements. 226 Sentences using "MUST" are labeled as "MUST-X" with X being a numeric 227 identifier enabling the requirement to be located easily when 228 referenced from Appendix B. 230 Similarly, sentences using "SHOULD" are labeled with "SHLD-X", "MAY" 231 with "MAY-X", and "RECOMMENDED" with "REC-X". 233 For the purposes of this labeling, "SHOULD NOT" and "MUST NOT" are 234 labeled the same as "SHOULD" and "MUST" instances. 236 2.2. Key TCP Concepts 238 TCP provides a reliable, in-order, byte-stream service to 239 applications. 241 The application byte-stream is conveyed over the network via TCP 242 segments, with each TCP segment sent as an Internet Protocol (IP) 243 datagram. 245 TCP reliability consists of detecting packet losses (via sequence 246 numbers) and errors (via per-segment checksums), as well as 247 correction via retransmission. 249 TCP supports unicast delivery of data. Anycast applications exist 250 that successfully use TCP without modifications, though there is some 251 risk of instability due to changes of lower-layer forwarding behavior 252 [45]. 254 TCP is connection-oriented, though does not inherently include a 255 liveness detection capability. 257 Data flow is supported bidirectionally over TCP connections, though 258 applications are free to send data only unidirectionally, if they so 259 choose. 261 TCP uses port numbers to identify application services and to 262 multiplex distinct flows between hosts. 264 A more detailed description of TCP features compared to other 265 transport protocols can be found in Section 3.1 of [51]. Further 266 description of the motivations for developing TCP and its role in the 267 Internet protocol stack can be found in Section 2 of [16] and earlier 268 versions of the TCP specification. 270 3. Functional Specification 272 3.1. Header Format 274 TCP segments are sent as internet datagrams. The Internet Protocol 275 (IP) header carries several information fields, including the source 276 and destination host addresses [1] [13]. A TCP header follows the IP 277 headers, supplying information specific to the TCP protocol. This 278 division allows for the existence of host level protocols other than 279 TCP. In early development of the Internet suite of protocols, the IP 280 header fields had been a part of TCP. 282 This document describes the TCP protocol. The TCP protocol uses TCP 283 Headers. 285 A TCP Header is formatted as follows, using the style from [61]: 287 0 1 2 3 288 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 289 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 290 | Source Port | Destination Port | 291 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 292 | Sequence Number | 293 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 294 | Acknowledgment Number | 295 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 296 | Data | |C|E|U|A|P|R|S|F| | 297 | Offset| Rsrvd |W|C|R|C|S|S|Y|I| Window | 298 | | |R|E|G|K|H|T|N|N| | 299 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 300 | Checksum | Urgent Pointer | 301 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 302 | [Options] | 303 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 304 | : 305 : Data : 306 : | 307 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 309 Note that one tick mark represents one bit position. 311 Figure 1: TCP Header Format 313 where: 315 Source Port: 16 bits. 317 The source port number. 319 Destination Port: 16 bits. 321 The destination port number. 323 Sequence Number: 32 bits. 325 The sequence number of the first data octet in this segment (except 326 when the SYN flag is set). If SYN is set the sequence number is 327 the initial sequence number (ISN) and the first data octet is 328 ISN+1. 330 Acknowledgment Number: 32 bits. 332 If the ACK control bit is set, this field contains the value of the 333 next sequence number the sender of the segment is expecting to 334 receive. Once a connection is established, this is always sent. 336 Data Offset (DOffset): 4 bits. 338 The number of 32 bit words in the TCP Header. This indicates where 339 the data begins. The TCP header (even one including options) is an 340 integer multiple of 32 bits long. 342 Reserved (Rsrvd): 4 bits. 344 A set of control bits reserved for future use. Must be zero in 345 generated segments and must be ignored in received segments, if 346 corresponding future features are unimplemented by the sending or 347 receiving host. 349 The control bits are also know as "flags". Assignment is managed 350 by IANA from the "TCP Header Flags" registry [57]. The currently 351 assigned control bits are CWR, ECE, URG, ACK, PSH, RST, SYN, and 352 FIN. 354 CWR: 1 bit. 356 Congestion Window Reduced (see [7]). 358 ECE: 1 bit. 360 ECN-Echo (see [7]). 362 URG: 1 bit. 364 Urgent Pointer field is significant. 366 ACK: 1 bit. 368 Acknowledgment field is significant. 370 PSH: 1 bit. 372 Push Function (see the Send Call description in Section 3.9.1). 374 RST: 1 bit. 376 Reset the connection. 378 SYN: 1 bit. 380 Synchronize sequence numbers. 382 FIN: 1 bit. 384 No more data from sender. 386 Window: 16 bits. 388 The number of data octets beginning with the one indicated in the 389 acknowledgment field that the sender of this segment is willing to 390 accept. The value is shifted when the Window Scaling extension is 391 used [46]. 393 The window size MUST be treated as an unsigned number, or else 394 large window sizes will appear like negative windows and TCP will 395 not work (MUST-1). It is RECOMMENDED that implementations will 396 reserve 32-bit fields for the send and receive window sizes in the 397 connection record and do all window computations with 32 bits (REC- 398 1). 400 Checksum: 16 bits. 402 The checksum field is the 16 bit one's complement of the one's 403 complement sum of all 16 bit words in the header and text. The 404 checksum computation needs to ensure the 16-bit alignment of the 405 data being summed. If a segment contains an odd number of header 406 and text octets, alignment can be achieved by padding the last 407 octet with zeros on its right to form a 16 bit word for checksum 408 purposes. The pad is not transmitted as part of the segment. 409 While computing the checksum, the checksum field itself is replaced 410 with zeros. 412 The checksum also covers a pseudo header (Figure 2) conceptually 413 prefixed to the TCP header. The pseudo header is 96 bits for IPv4 414 and 320 bits for IPv6. Including the pseudo header in the checksum 415 gives the TCP connection protection against misrouted segments. 416 This information is carried in IP headers and is transferred across 417 the TCP/Network interface in the arguments or results of calls by 418 the TCP implementation on the IP layer. 420 +--------+--------+--------+--------+ 421 | Source Address | 422 +--------+--------+--------+--------+ 423 | Destination Address | 424 +--------+--------+--------+--------+ 425 | zero | PTCL | TCP Length | 426 +--------+--------+--------+--------+ 428 Figure 2: IPv4 Pseudo Header 430 Pseudo header components for IPv4: 432 Source Address: the IPv4 source address in network byte order 434 Destination Address: the IPv4 destination address in network 435 byte order 437 zero: bits set to zero 439 PTCL: the protocol number from the IP header 441 TCP Length: the TCP header length plus the data length in 442 octets (this is not an explicitly transmitted quantity, but is 443 computed), and it does not count the 12 octets of the pseudo 444 header. 446 For IPv6, the pseudo header is defined in Section 8.1 of RFC 8200 447 [13], and contains the IPv6 Source Address and Destination 448 Address, an Upper Layer Packet Length (a 32-bit value otherwise 449 equivalent to TCP Length in the IPv4 pseudo header), three bytes 450 of zero-padding, and a Next Header value (differing from the IPv6 451 header value in the case of extension headers present in between 452 IPv6 and TCP). 454 The TCP checksum is never optional. The sender MUST generate it 455 (MUST-2) and the receiver MUST check it (MUST-3). 457 Urgent Pointer: 16 bits. 459 This field communicates the current value of the urgent pointer as 460 a positive offset from the sequence number in this segment. The 461 urgent pointer points to the sequence number of the octet following 462 the urgent data. This field is only be interpreted in segments 463 with the URG control bit set. 465 Options: [TCP Option]; Options#Size == (DOffset-5)*32; present only 466 when DOffset > 5. 468 Options may occupy space at the end of the TCP header and are a 469 multiple of 8 bits in length. All options are included in the 470 checksum. An option may begin on any octet boundary. There are two 471 cases for the format of an option: 473 Case 1: A single octet of option-kind. 475 Case 2: An octet of option-kind (Kind), an octet of option- 476 length, and the actual option-data octets. 478 The option-length counts the two octets of option-kind and option- 479 length as well as the option-data octets. 481 Note that the list of options may be shorter than the data offset 482 field might imply. The content of the header beyond the End-of- 483 Option option must be header padding (i.e., zero). 485 The list of all currently defined options is managed by IANA [56], 486 and each option is defined in other RFCs, as indicated there. That 487 set includes experimental options that can be extended to support 488 multiple concurrent usages [44]. 490 A given TCP implementation can support any currently defined 491 options, but the following options MUST be supported (MUST-4 - note 492 Maximum Segment Size option support is also part of MUST-19 in 493 Section 3.7.2): 495 Kind Length Meaning 496 ---- ------ ------- 497 0 - End of option list. 498 1 - No-Operation. 499 2 4 Maximum Segment Size. 501 These options are specified in detail in Section 3.2. 503 A TCP implementation MUST be able to receive a TCP option in any 504 segment (MUST-5). 506 A TCP implementation MUST (MUST-6) ignore without error any TCP 507 option it does not implement, assuming that the option has a length 508 field. All TCP options except End of option list and No-Operation 509 MUST have length fields, including all future options (MUST-68). 510 TCP implementations MUST be prepared to handle an illegal option 511 length (e.g., zero); a suggested procedure is to reset the 512 connection and log the error cause (MUST-7). 514 Note: There is ongoing work to extend the space available for TCP 515 options, such as [60]. 517 Data: variable length. 519 User data carried by the TCP segment. 521 3.2. Specific Option Definitions 523 A TCP Option is one of: an End of Option List Option, a No-Operation 524 Option, or a Maximum Segment Size Option. 526 An End of Option List Option is formatted as follows: 528 0 529 0 1 2 3 4 5 6 7 530 +-+-+-+-+-+-+-+-+ 531 | 0 | 532 +-+-+-+-+-+-+-+-+ 534 where: 536 Kind: 1 byte; Kind == 0. 538 This option code indicates the end of the option list. This might 539 not coincide with the end of the TCP header according to the Data 540 Offset field. This is used at the end of all options, not the end 541 of each option, and need only be used if the end of the options 542 would not otherwise coincide with the end of the TCP header. 544 A No-Operation Option is formatted as follows: 546 0 547 0 1 2 3 4 5 6 7 548 +-+-+-+-+-+-+-+-+ 549 | 1 | 550 +-+-+-+-+-+-+-+-+ 552 where: 554 Kind: 1 byte; Kind == 1. 556 This option code can be used between options, for example, to align 557 the beginning of a subsequent option on a word boundary. There is 558 no guarantee that senders will use this option, so receivers MUST 559 be prepared to process options even if they do not begin on a word 560 boundary (MUST-64). 562 A Maximum Segment Size Option is formatted as follows: 564 0 1 2 3 565 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 566 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 567 | 2 | Length | Maximum Segment Size (MSS) | 568 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 570 where: 572 Kind: 1 byte; Kind == 2. 574 If this option is present, then it communicates the maximum receive 575 segment size at the TCP endpoint that sends this segment. This 576 value is limited by the IP reassembly limit. This field may be 577 sent in the initial connection request (i.e., in segments with the 578 SYN control bit set) and MUST NOT be sent in other segments (MUST- 579 65). If this option is not used, any segment size is allowed. A 580 more complete description of this option is provided in 581 Section 3.7.1. 583 Length: 1 byte; Length == 4. 585 Length of the option in bytes. 587 Maximum Segment Size (MSS): 2 bytes. 589 The maximum receive segment size at the TCP endpoint that sends 590 this segment. 592 3.2.1. Other Common Options 594 Additional RFCs define some other commonly used options that are 595 recommended to implement for high performance, but not necessary for 596 basic TCP interoperability. These are the TCP Selective 597 Acknowledgement (SACK) option [21][24], TCP Timestamp (TS) option 598 [46], and TCP Window Scaling (WS) option [46]. 600 3.2.2. Experimental TCP Options 602 Experimental TCP option values are defined in [28], and [44] 603 describes the current recommended usage for these experimental 604 values. 606 3.3. TCP Terminology Overview 608 This section includes an overview of key terms needed to understand 609 the detailed protocol operation in the rest of the document. There 610 is a traditional glossary of terms in Section 4. 612 3.3.1. Key Connection State Variables 614 Before we can discuss very much about the operation of the TCP 615 implementation we need to introduce some detailed terminology. The 616 maintenance of a TCP connection requires the remembering of several 617 variables. We conceive of these variables being stored in a 618 connection record called a Transmission Control Block or TCB. Among 619 the variables stored in the TCB are the local and remote IP addresses 620 and port numbers, the IP security level and compartment of the 621 connection (see Appendix A.1), pointers to the user's send and 622 receive buffers, pointers to the retransmit queue and to the current 623 segment. In addition several variables relating to the send and 624 receive sequence numbers are stored in the TCB. 626 Send Sequence Variables: 628 SND.UNA - send unacknowledged 629 SND.NXT - send next 630 SND.WND - send window 631 SND.UP - send urgent pointer 632 SND.WL1 - segment sequence number used for last window update 633 SND.WL2 - segment acknowledgment number used for last window 634 update 635 ISS - initial send sequence number 637 Receive Sequence Variables: 639 RCV.NXT - receive next 640 RCV.WND - receive window 641 RCV.UP - receive urgent pointer 642 IRS - initial receive sequence number 644 The following diagrams may help to relate some of these variables to 645 the sequence space. 647 1 2 3 4 648 ----------|----------|----------|---------- 649 SND.UNA SND.NXT SND.UNA 650 +SND.WND 652 1 - old sequence numbers that have been acknowledged 653 2 - sequence numbers of unacknowledged data 654 3 - sequence numbers allowed for new data transmission 655 4 - future sequence numbers that are not yet allowed 657 Figure 3: Send Sequence Space 659 The send window is the portion of the sequence space labeled 3 in 660 Figure 3. 662 1 2 3 663 ----------|----------|---------- 664 RCV.NXT RCV.NXT 665 +RCV.WND 667 1 - old sequence numbers that have been acknowledged 668 2 - sequence numbers allowed for new reception 669 3 - future sequence numbers that are not yet allowed 671 Figure 4: Receive Sequence Space 673 The receive window is the portion of the sequence space labeled 2 in 674 Figure 4. 676 There are also some variables used frequently in the discussion that 677 take their values from the fields of the current segment. 679 Current Segment Variables: 681 SEG.SEQ - segment sequence number 682 SEG.ACK - segment acknowledgment number 683 SEG.LEN - segment length 684 SEG.WND - segment window 685 SEG.UP - segment urgent pointer 687 3.3.2. State Machine Overview 689 A connection progresses through a series of states during its 690 lifetime. The states are: LISTEN, SYN-SENT, SYN-RECEIVED, 691 ESTABLISHED, FIN-WAIT-1, FIN-WAIT-2, CLOSE-WAIT, CLOSING, LAST-ACK, 692 TIME-WAIT, and the fictional state CLOSED. CLOSED is fictional 693 because it represents the state when there is no TCB, and therefore, 694 no connection. Briefly the meanings of the states are: 696 LISTEN - represents waiting for a connection request from any 697 remote TCP peer and port. 699 SYN-SENT - represents waiting for a matching connection request 700 after having sent a connection request. 702 SYN-RECEIVED - represents waiting for a confirming connection 703 request acknowledgment after having both received and sent a 704 connection request. 706 ESTABLISHED - represents an open connection, data received can be 707 delivered to the user. The normal state for the data transfer 708 phase of the connection. 710 FIN-WAIT-1 - represents waiting for a connection termination 711 request from the remote TCP peer, or an acknowledgment of the 712 connection termination request previously sent. 714 FIN-WAIT-2 - represents waiting for a connection termination 715 request from the remote TCP peer. 717 CLOSE-WAIT - represents waiting for a connection termination 718 request from the local user. 720 CLOSING - represents waiting for a connection termination request 721 acknowledgment from the remote TCP peer. 723 LAST-ACK - represents waiting for an acknowledgment of the 724 connection termination request previously sent to the remote TCP 725 peer (this termination request sent to the remote TCP peer already 726 included an acknowledgment of the termination request sent from 727 the remote TCP peer). 729 TIME-WAIT - represents waiting for enough time to pass to be sure 730 the remote TCP peer received the acknowledgment of its connection 731 termination request, and to avoid new connections being impacted 732 by delayed segments from previous connections. 734 CLOSED - represents no connection state at all. 736 A TCP connection progresses from one state to another in response to 737 events. The events are the user calls, OPEN, SEND, RECEIVE, CLOSE, 738 ABORT, and STATUS; the incoming segments, particularly those 739 containing the SYN, ACK, RST and FIN flags; and timeouts. 741 The state diagram in Figure 5 illustrates only state changes, 742 together with the causing events and resulting actions, but addresses 743 neither error conditions nor actions that are not connected with 744 state changes. In a later section, more detail is offered with 745 respect to the reaction of the TCP implementation to events. Some 746 state names are abbreviated or hyphenated differently in the diagram 747 from how they appear elsewhere in the document. 749 NOTA BENE: This diagram is only a summary and must not be taken as 750 the total specification. Many details are not included. 752 +---------+ ---------\ active OPEN 753 | CLOSED | \ ----------- 754 +---------+<---------\ \ create TCB 755 | ^ \ \ snd SYN 756 passive OPEN | | CLOSE \ \ 757 ------------ | | ---------- \ \ 758 create TCB | | delete TCB \ \ 759 V | \ \ 760 rcv RST (note 1) +---------+ CLOSE | \ 761 -------------------->| LISTEN | ---------- | | 762 / +---------+ delete TCB | | 763 / rcv SYN | | SEND | | 764 / ----------- | | ------- | V 765 +--------+ snd SYN,ACK / \ snd SYN +--------+ 766 | |<----------------- ------------------>| | 767 | SYN | rcv SYN | SYN | 768 | RCVD |<-----------------------------------------------| SENT | 769 | | snd SYN,ACK | | 770 | |------------------ -------------------| | 771 +--------+ rcv ACK of SYN \ / rcv SYN,ACK +--------+ 772 | -------------- | | ----------- 773 | x | | snd ACK 774 | V V 775 | CLOSE +---------+ 776 | ------- | ESTAB | 777 | snd FIN +---------+ 778 | CLOSE | | rcv FIN 779 V ------- | | ------- 780 +---------+ snd FIN / \ snd ACK +---------+ 781 | FIN |<---------------- ------------------>| CLOSE | 782 | WAIT-1 |------------------ | WAIT | 783 +---------+ rcv FIN \ +---------+ 784 | rcv ACK of FIN ------- | CLOSE | 785 | -------------- snd ACK | ------- | 786 V x V snd FIN V 787 +---------+ +---------+ +---------+ 788 |FINWAIT-2| | CLOSING | | LAST-ACK| 789 +---------+ +---------+ +---------+ 790 | rcv ACK of FIN | rcv ACK of FIN | 791 | rcv FIN -------------- | Timeout=2MSL -------------- | 792 | ------- x V ------------ x V 793 \ snd ACK +---------+delete TCB +---------+ 794 -------------------->|TIME-WAIT|------------------->| CLOSED | 795 +---------+ +---------+ 797 Figure 5: TCP Connection State Diagram 799 The following notes apply to Figure 5: 801 Note 1: The transition from SYN-RECEIVED to LISTEN on receiving a 802 RST is conditional on having reached SYN-RECEIVED after a passive 803 open. 805 Note 2: An unshown transition exists from FIN-WAIT-1 to TIME-WAIT 806 if a FIN is received and the local FIN is also acknowledged. 808 Note 3: A RST can be sent from any state with a corresponding 809 transition to TIME-WAIT (see [64] for rationale). These 810 transitions are not not explicitly shown, otherwise the diagram 811 would become very difficult to read. Similarly, receipt of a RST 812 from any state results in a transition to LISTEN or CLOSED, though 813 this is also omitted from the diagram for legibility. 815 3.4. Sequence Numbers 817 A fundamental notion in the design is that every octet of data sent 818 over a TCP connection has a sequence number. Since every octet is 819 sequenced, each of them can be acknowledged. The acknowledgment 820 mechanism employed is cumulative so that an acknowledgment of 821 sequence number X indicates that all octets up to but not including X 822 have been received. This mechanism allows for straight-forward 823 duplicate detection in the presence of retransmission. Numbering of 824 octets within a segment is that the first data octet immediately 825 following the header is the lowest numbered, and the following octets 826 are numbered consecutively. 828 It is essential to remember that the actual sequence number space is 829 finite, though very large. This space ranges from 0 to 2**32 - 1. 830 Since the space is finite, all arithmetic dealing with sequence 831 numbers must be performed modulo 2**32. This unsigned arithmetic 832 preserves the relationship of sequence numbers as they cycle from 833 2**32 - 1 to 0 again. There are some subtleties to computer modulo 834 arithmetic, so great care should be taken in programming the 835 comparison of such values. The symbol "=<" means "less than or 836 equal" (modulo 2**32). 838 The typical kinds of sequence number comparisons that the TCP 839 implementation must perform include: 841 (a) Determining that an acknowledgment refers to some sequence 842 number sent but not yet acknowledged. 844 (b) Determining that all sequence numbers occupied by a segment 845 have been acknowledged (e.g., to remove the segment from a 846 retransmission queue). 848 (c) Determining that an incoming segment contains sequence numbers 849 that are expected (i.e., that the segment "overlaps" the receive 850 window). 852 In response to sending data the TCP endpoint will receive 853 acknowledgments. The following comparisons are needed to process the 854 acknowledgments. 856 SND.UNA = oldest unacknowledged sequence number 858 SND.NXT = next sequence number to be sent 860 SEG.ACK = acknowledgment from the receiving TCP peer (next 861 sequence number expected by the receiving TCP peer) 863 SEG.SEQ = first sequence number of a segment 865 SEG.LEN = the number of octets occupied by the data in the segment 866 (counting SYN and FIN) 868 SEG.SEQ+SEG.LEN-1 = last sequence number of a segment 870 A new acknowledgment (called an "acceptable ack"), is one for which 871 the inequality below holds: 873 SND.UNA < SEG.ACK =< SND.NXT 875 A segment on the retransmission queue is fully acknowledged if the 876 sum of its sequence number and length is less or equal than the 877 acknowledgment value in the incoming segment. 879 When data is received the following comparisons are needed: 881 RCV.NXT = next sequence number expected on an incoming segments, 882 and is the left or lower edge of the receive window 884 RCV.NXT+RCV.WND-1 = last sequence number expected on an incoming 885 segment, and is the right or upper edge of the receive window 887 SEG.SEQ = first sequence number occupied by the incoming segment 889 SEG.SEQ+SEG.LEN-1 = last sequence number occupied by the incoming 890 segment 892 A segment is judged to occupy a portion of valid receive sequence 893 space if 895 RCV.NXT =< SEG.SEQ < RCV.NXT+RCV.WND 897 or 899 RCV.NXT =< SEG.SEQ+SEG.LEN-1 < RCV.NXT+RCV.WND 901 The first part of this test checks to see if the beginning of the 902 segment falls in the window, the second part of the test checks to 903 see if the end of the segment falls in the window; if the segment 904 passes either part of the test it contains data in the window. 906 Actually, it is a little more complicated than this. Due to zero 907 windows and zero length segments, we have four cases for the 908 acceptability of an incoming segment: 910 Segment Receive Test 911 Length Window 912 ------- ------- ------------------------------------------- 914 0 0 SEG.SEQ = RCV.NXT 916 0 >0 RCV.NXT =< SEG.SEQ < RCV.NXT+RCV.WND 918 >0 0 not acceptable 920 >0 >0 RCV.NXT =< SEG.SEQ < RCV.NXT+RCV.WND 921 or RCV.NXT =< SEG.SEQ+SEG.LEN-1 < RCV.NXT+RCV.WND 923 Note that when the receive window is zero no segments should be 924 acceptable except ACK segments. Thus, it is possible for a TCP 925 implementation to maintain a zero receive window while transmitting 926 data and receiving ACKs. A TCP receiver MUST process the RST and URG 927 fields of all incoming segments, even when the receive window is zero 928 (MUST-66). 930 We have taken advantage of the numbering scheme to protect certain 931 control information as well. This is achieved by implicitly 932 including some control flags in the sequence space so they can be 933 retransmitted and acknowledged without confusion (i.e., one and only 934 one copy of the control will be acted upon). Control information is 935 not physically carried in the segment data space. Consequently, we 936 must adopt rules for implicitly assigning sequence numbers to 937 control. The SYN and FIN are the only controls requiring this 938 protection, and these controls are used only at connection opening 939 and closing. For sequence number purposes, the SYN is considered to 940 occur before the first actual data octet of the segment in which it 941 occurs, while the FIN is considered to occur after the last actual 942 data octet in a segment in which it occurs. The segment length 943 (SEG.LEN) includes both data and sequence space occupying controls. 944 When a SYN is present then SEG.SEQ is the sequence number of the SYN. 946 Initial Sequence Number Selection 948 A connection is defined by a pair of sockets. Connections can be 949 reused. New instances of a connection will be referred to as 950 incarnations of the connection. The problem that arises from this is 951 -- "how does the TCP implementation identify duplicate segments from 952 previous incarnations of the connection?" This problem becomes 953 apparent if the connection is being opened and closed in quick 954 succession, or if the connection breaks with loss of memory and is 955 then reestablished. To support this, the TIME-WAIT state limits the 956 rate of connection reuse, while the initial sequence number selection 957 described below further protects against ambiguity about what 958 incarnation of a connection an incoming packet corresponds to. 960 To avoid confusion we must prevent segments from one incarnation of a 961 connection from being used while the same sequence numbers may still 962 be present in the network from an earlier incarnation. We want to 963 assure this, even if a TCP endpoint loses all knowledge of the 964 sequence numbers it has been using. When new connections are 965 created, an initial sequence number (ISN) generator is employed that 966 selects a new 32 bit ISN. There are security issues that result if 967 an off-path attacker is able to predict or guess ISN values. 969 TCP Initial Sequence Numbers are generated from a number sequence 970 that monotonically increases until it wraps, known loosely as a 971 "clock". This clock is a 32-bit counter that typically increments at 972 least once every roughly 4 microseconds, although it is neither 973 assumed to be realtime nor precise, and need not persist across 974 reboots. The clock component is intended to insure that with a 975 Maximum Segment Lifetime (MSL), generated ISNs will be unique, since 976 it cycles approximately every 4.55 hours, which is much longer than 977 the MSL. 979 A TCP implementation MUST use the above type of "clock" for clock- 980 driven selection of initial sequence numbers (MUST-8), and SHOULD 981 generate its Initial Sequence Numbers with the expression: 983 ISN = M + F(localip, localport, remoteip, remoteport, secretkey) 985 where M is the 4 microsecond timer, and F() is a pseudorandom 986 function (PRF) of the connection's identifying parameters ("localip, 987 localport, remoteip, remoteport") and a secret key ("secretkey") 988 (SHLD-1). F() MUST NOT be computable from the outside (MUST-9), or 989 an attacker could still guess at sequence numbers from the ISN used 990 for some other connection. The PRF could be implemented as a 991 cryptographic hash of the concatenation of the TCP connection 992 parameters and some secret data. For discussion of the selection of 993 a specific hash algorithm and management of the secret key data, 994 please see Section 3 of [41]. 996 For each connection there is a send sequence number and a receive 997 sequence number. The initial send sequence number (ISS) is chosen by 998 the data sending TCP peer, and the initial receive sequence number 999 (IRS) is learned during the connection establishing procedure. 1001 For a connection to be established or initialized, the two TCP peers 1002 must synchronize on each other's initial sequence numbers. This is 1003 done in an exchange of connection establishing segments carrying a 1004 control bit called "SYN" (for synchronize) and the initial sequence 1005 numbers. As a shorthand, segments carrying the SYN bit are also 1006 called "SYNs". Hence, the solution requires a suitable mechanism for 1007 picking an initial sequence number and a slightly involved handshake 1008 to exchange the ISNs. 1010 The synchronization requires each side to send its own initial 1011 sequence number and to receive a confirmation of it in acknowledgment 1012 from the remote TCP peer. Each side must also receive the remote 1013 peer's initial sequence number and send a confirming acknowledgment. 1015 1) A --> B SYN my sequence number is X 1016 2) A <-- B ACK your sequence number is X 1017 3) A <-- B SYN my sequence number is Y 1018 4) A --> B ACK your sequence number is Y 1020 Because steps 2 and 3 can be combined in a single message this is 1021 called the three-way (or three message) handshake (3WHS). 1023 A 3WHS is necessary because sequence numbers are not tied to a global 1024 clock in the network, and TCP implementations may have different 1025 mechanisms for picking the ISNs. The receiver of the first SYN has 1026 no way of knowing whether the segment was an old delayed one or not, 1027 unless it remembers the last sequence number used on the connection 1028 (which is not always possible), and so it must ask the sender to 1029 verify this SYN. The three way handshake and the advantages of a 1030 clock-driven scheme are discussed in [63]. 1032 Knowing When to Keep Quiet 1034 A theoretical problem exists where data could be corrupted due to 1035 confusion between old segments in the network and new ones after a 1036 host reboots, if the same port numbers and sequence space are reused. 1037 The "Quiet Time" concept discussed below addresses this and the 1038 discussion of it is included for situations where it might be 1039 relevant, although it is not felt to be necessary in most current 1040 implementations. The problem was more relevant earlier in the 1041 history of TCP. In practical use on the Internet today, the error- 1042 prone conditions are sufficiently unlikely that it is felt safe to 1043 ignore. Reasons why it is now negligible include: (a) ISS and 1044 ephemeral port randomization have reduced likelihood of reuse of port 1045 numbers and sequence numbers after reboots, (b) the effective MSL of 1046 the Internet has declined as links have become faster, and (c) 1047 reboots often taking longer than an MSL anyways. 1049 To be sure that a TCP implementation does not create a segment 1050 carrying a sequence number that may be duplicated by an old segment 1051 remaining in the network, the TCP endpoint must keep quiet for an MSL 1052 before assigning any sequence numbers upon starting up or recovering 1053 from a situation where memory of sequence numbers in use was lost. 1054 For this specification the MSL is taken to be 2 minutes. This is an 1055 engineering choice, and may be changed if experience indicates it is 1056 desirable to do so. Note that if a TCP endpoint is reinitialized in 1057 some sense, yet retains its memory of sequence numbers in use, then 1058 it need not wait at all; it must only be sure to use sequence numbers 1059 larger than those recently used. 1061 The TCP Quiet Time Concept 1063 Hosts that for any reason lose knowledge of the last sequence numbers 1064 transmitted on each active (i.e., not closed) connection shall delay 1065 emitting any TCP segments for at least the agreed MSL in the internet 1066 system that the host is a part of. In the paragraphs below, an 1067 explanation for this specification is given. TCP implementors may 1068 violate the "quiet time" restriction, but only at the risk of causing 1069 some old data to be accepted as new or new data rejected as old 1070 duplicated by some receivers in the internet system. 1072 TCP endpoints consume sequence number space each time a segment is 1073 formed and entered into the network output queue at a source host. 1074 The duplicate detection and sequencing algorithm in the TCP protocol 1075 relies on the unique binding of segment data to sequence space to the 1076 extent that sequence numbers will not cycle through all 2**32 values 1077 before the segment data bound to those sequence numbers has been 1078 delivered and acknowledged by the receiver and all duplicate copies 1079 of the segments have "drained" from the internet. Without such an 1080 assumption, two distinct TCP segments could conceivably be assigned 1081 the same or overlapping sequence numbers, causing confusion at the 1082 receiver as to which data is new and which is old. Remember that 1083 each segment is bound to as many consecutive sequence numbers as 1084 there are octets of data and SYN or FIN flags in the segment. 1086 Under normal conditions, TCP implementations keep track of the next 1087 sequence number to emit and the oldest awaiting acknowledgment so as 1088 to avoid mistakenly using a sequence number over before its first use 1089 has been acknowledged. This alone does not guarantee that old 1090 duplicate data is drained from the net, so the sequence space has 1091 been made very large to reduce the probability that a wandering 1092 duplicate will cause trouble upon arrival. At 2 megabits/sec. it 1093 takes 4.5 hours to use up 2**32 octets of sequence space. Since the 1094 maximum segment lifetime in the net is not likely to exceed a few 1095 tens of seconds, this is deemed ample protection for foreseeable 1096 nets, even if data rates escalate to 10's of megabits/sec. At 100 1097 megabits/sec, the cycle time is 5.4 minutes, which may be a little 1098 short, but still within reason. 1100 The basic duplicate detection and sequencing algorithm in TCP can be 1101 defeated, however, if a source TCP endpoint does not have any memory 1102 of the sequence numbers it last used on a given connection. For 1103 example, if the TCP implementation were to start all connections with 1104 sequence number 0, then upon the host rebooting, a TCP peer might re- 1105 form an earlier connection (possibly after half-open connection 1106 resolution) and emit packets with sequence numbers identical to or 1107 overlapping with packets still in the network, which were emitted on 1108 an earlier incarnation of the same connection. In the absence of 1109 knowledge about the sequence numbers used on a particular connection, 1110 the TCP specification recommends that the source delay for MSL 1111 seconds before emitting segments on the connection, to allow time for 1112 segments from the earlier connection incarnation to drain from the 1113 system. 1115 Even hosts that can remember the time of day and used it to select 1116 initial sequence number values are not immune from this problem 1117 (i.e., even if time of day is used to select an initial sequence 1118 number for each new connection incarnation). 1120 Suppose, for example, that a connection is opened starting with 1121 sequence number S. Suppose that this connection is not used much and 1122 that eventually the initial sequence number function (ISN(t)) takes 1123 on a value equal to the sequence number, say S1, of the last segment 1124 sent by this TCP endpoint on a particular connection. Now suppose, 1125 at this instant, the host reboots and establishes a new incarnation 1126 of the connection. The initial sequence number chosen is S1 = ISN(t) 1127 -- last used sequence number on old incarnation of connection! If 1128 the recovery occurs quickly enough, any old duplicates in the net 1129 bearing sequence numbers in the neighborhood of S1 may arrive and be 1130 treated as new packets by the receiver of the new incarnation of the 1131 connection. 1133 The problem is that the recovering host may not know for how long it 1134 was down between rebooting nor does it know whether there are still 1135 old duplicates in the system from earlier connection incarnations. 1137 One way to deal with this problem is to deliberately delay emitting 1138 segments for one MSL after recovery from a reboot - this is the 1139 "quiet time" specification. Hosts that prefer to avoid waiting are 1140 willing to risk possible confusion of old and new packets at a given 1141 destination may choose not to wait for the "quiet time". 1142 Implementors may provide TCP users with the ability to select on a 1143 connection by connection basis whether to wait after a reboot, or may 1144 informally implement the "quiet time" for all connections. 1145 Obviously, even where a user selects to "wait," this is not necessary 1146 after the host has been "up" for at least MSL seconds. 1148 To summarize: every segment emitted occupies one or more sequence 1149 numbers in the sequence space, the numbers occupied by a segment are 1150 "busy" or "in use" until MSL seconds have passed, upon rebooting a 1151 block of space-time is occupied by the octets and SYN or FIN flags of 1152 the last emitted segment, if a new connection is started too soon and 1153 uses any of the sequence numbers in the space-time footprint of the 1154 last segment of the previous connection incarnation, there is a 1155 potential sequence number overlap area that could cause confusion at 1156 the receiver. 1158 3.5. Establishing a connection 1160 The "three-way handshake" is the procedure used to establish a 1161 connection. This procedure normally is initiated by one TCP peer and 1162 responded to by another TCP peer. The procedure also works if two 1163 TCP peers simultaneously initiate the procedure. When simultaneous 1164 open occurs, each TCP peer receives a "SYN" segment that carries no 1165 acknowledgment after it has sent a "SYN". Of course, the arrival of 1166 an old duplicate "SYN" segment can potentially make it appear, to the 1167 recipient, that a simultaneous connection initiation is in progress. 1168 Proper use of "reset" segments can disambiguate these cases. 1170 Several examples of connection initiation follow. Although these 1171 examples do not show connection synchronization using data-carrying 1172 segments, this is perfectly legitimate, so long as the receiving TCP 1173 endpoint doesn't deliver the data to the user until it is clear the 1174 data is valid (e.g., the data is buffered at the receiver until the 1175 connection reaches the ESTABLISHED state, given that the three-way 1176 handshake reduces the possibility of false connections). It is the 1177 implementation of a trade-off between memory and messages to provide 1178 information for this checking. 1180 The simplest 3WHS is shown in Figure 6. The figures should be 1181 interpreted in the following way. Each line is numbered for 1182 reference purposes. Right arrows (-->) indicate departure of a TCP 1183 segment from TCP peer A to TCP peer B, or arrival of a segment at B 1184 from A. Left arrows (<--), indicate the reverse. Ellipsis (...) 1185 indicates a segment that is still in the network (delayed). Comments 1186 appear in parentheses. TCP connection states represent the state 1187 AFTER the departure or arrival of the segment (whose contents are 1188 shown in the center of each line). Segment contents are shown in 1189 abbreviated form, with sequence number, control flags, and ACK field. 1190 Other fields such as window, addresses, lengths, and text have been 1191 left out in the interest of clarity. 1193 TCP Peer A TCP Peer B 1195 1. CLOSED LISTEN 1197 2. SYN-SENT --> --> SYN-RECEIVED 1199 3. ESTABLISHED <-- <-- SYN-RECEIVED 1201 4. ESTABLISHED --> --> ESTABLISHED 1203 5. ESTABLISHED --> --> ESTABLISHED 1205 Figure 6: Basic 3-Way Handshake for Connection Synchronization 1207 In line 2 of Figure 6, TCP Peer A begins by sending a SYN segment 1208 indicating that it will use sequence numbers starting with sequence 1209 number 100. In line 3, TCP Peer B sends a SYN and acknowledges the 1210 SYN it received from TCP Peer A. Note that the acknowledgment field 1211 indicates TCP Peer B is now expecting to hear sequence 101, 1212 acknowledging the SYN that occupied sequence 100. 1214 At line 4, TCP Peer A responds with an empty segment containing an 1215 ACK for TCP Peer B's SYN; and in line 5, TCP Peer A sends some data. 1216 Note that the sequence number of the segment in line 5 is the same as 1217 in line 4 because the ACK does not occupy sequence number space (if 1218 it did, we would wind up ACKing ACKs!). 1220 Simultaneous initiation is only slightly more complex, as is shown in 1221 Figure 7. Each TCP peer's connection state cycles from CLOSED to 1222 SYN-SENT to SYN-RECEIVED to ESTABLISHED. 1224 TCP Peer A TCP Peer B 1226 1. CLOSED CLOSED 1228 2. SYN-SENT --> ... 1230 3. SYN-RECEIVED <-- <-- SYN-SENT 1232 4. ... --> SYN-RECEIVED 1234 5. SYN-RECEIVED --> ... 1236 6. ESTABLISHED <-- <-- SYN-RECEIVED 1238 7. ... --> ESTABLISHED 1240 Figure 7: Simultaneous Connection Synchronization 1242 A TCP implementation MUST support simultaneous open attempts (MUST- 1243 10). 1245 Note that a TCP implementation MUST keep track of whether a 1246 connection has reached SYN-RECEIVED state as the result of a passive 1247 OPEN or an active OPEN (MUST-11). 1249 The principal reason for the three-way handshake is to prevent old 1250 duplicate connection initiations from causing confusion. To deal 1251 with this, a special control message, reset, is specified. If the 1252 receiving TCP peer is in a non-synchronized state (i.e., SYN-SENT, 1253 SYN-RECEIVED), it returns to LISTEN on receiving an acceptable reset. 1254 If the TCP peer is in one of the synchronized states (ESTABLISHED, 1255 FIN-WAIT-1, FIN-WAIT-2, CLOSE-WAIT, CLOSING, LAST-ACK, TIME-WAIT), it 1256 aborts the connection and informs its user. We discuss this latter 1257 case under "half-open" connections below. 1259 TCP Peer A TCP Peer B 1261 1. CLOSED LISTEN 1263 2. SYN-SENT --> ... 1265 3. (duplicate) ... --> SYN-RECEIVED 1267 4. SYN-SENT <-- <-- SYN-RECEIVED 1269 5. SYN-SENT --> --> LISTEN 1271 6. ... --> SYN-RECEIVED 1273 7. ESTABLISHED <-- <-- SYN-RECEIVED 1275 8. ESTABLISHED --> --> ESTABLISHED 1277 Figure 8: Recovery from Old Duplicate SYN 1279 As a simple example of recovery from old duplicates, consider 1280 Figure 8. At line 3, an old duplicate SYN arrives at TCP Peer B. 1281 TCP Peer B cannot tell that this is an old duplicate, so it responds 1282 normally (line 4). TCP Peer A detects that the ACK field is 1283 incorrect and returns a RST (reset) with its SEQ field selected to 1284 make the segment believable. TCP Peer B, on receiving the RST, 1285 returns to the LISTEN state. When the original SYN finally arrives 1286 at line 6, the synchronization proceeds normally. If the SYN at line 1287 6 had arrived before the RST, a more complex exchange might have 1288 occurred with RST's sent in both directions. 1290 Half-Open Connections and Other Anomalies 1292 An established connection is said to be "half-open" if one of the TCP 1293 peers has closed or aborted the connection at its end without the 1294 knowledge of the other, or if the two ends of the connection have 1295 become desynchronized owing to a failure or reboot that resulted in 1296 loss of memory. Such connections will automatically become reset if 1297 an attempt is made to send data in either direction. However, half- 1298 open connections are expected to be unusual. 1300 If at site A the connection no longer exists, then an attempt by the 1301 user at site B to send any data on it will result in the site B TCP 1302 endpoint receiving a reset control message. Such a message indicates 1303 to the site B TCP endpoint that something is wrong, and it is 1304 expected to abort the connection. 1306 Assume that two user processes A and B are communicating with one 1307 another when a failure or reboot occurs causing loss of memory to A's 1308 TCP implementation. Depending on the operating system supporting A's 1309 TCP implementation, it is likely that some error recovery mechanism 1310 exists. When the TCP endpoint is up again, A is likely to start 1311 again from the beginning or from a recovery point. As a result, A 1312 will probably try to OPEN the connection again or try to SEND on the 1313 connection it believes open. In the latter case, it receives the 1314 error message "connection not open" from the local (A's) TCP 1315 implementation. In an attempt to establish the connection, A's TCP 1316 implementation will send a segment containing SYN. This scenario 1317 leads to the example shown in Figure 9. After TCP Peer A reboots, 1318 the user attempts to re-open the connection. TCP Peer B, in the 1319 meantime, thinks the connection is open. 1321 TCP Peer A TCP Peer B 1323 1. (REBOOT) (send 300,receive 100) 1325 2. CLOSED ESTABLISHED 1327 3. SYN-SENT --> --> (??) 1329 4. (!!) <-- <-- ESTABLISHED 1331 5. SYN-SENT --> --> (Abort!!) 1333 6. SYN-SENT CLOSED 1335 7. SYN-SENT --> --> 1337 Figure 9: Half-Open Connection Discovery 1339 When the SYN arrives at line 3, TCP Peer B, being in a synchronized 1340 state, and the incoming segment outside the window, responds with an 1341 acknowledgment indicating what sequence it next expects to hear (ACK 1342 100). TCP Peer A sees that this segment does not acknowledge 1343 anything it sent and, being unsynchronized, sends a reset (RST) 1344 because it has detected a half-open connection. TCP Peer B aborts at 1345 line 5. TCP Peer A will continue to try to establish the connection; 1346 the problem is now reduced to the basic 3-way handshake of Figure 6. 1348 An interesting alternative case occurs when TCP Peer A reboots and 1349 TCP Peer B tries to send data on what it thinks is a synchronized 1350 connection. This is illustrated in Figure 10. In this case, the 1351 data arriving at TCP Peer A from TCP Peer B (line 2) is unacceptable 1352 because no such connection exists, so TCP Peer A sends a RST. The 1353 RST is acceptable so TCP Peer B processes it and aborts the 1354 connection. 1356 TCP Peer A TCP Peer B 1358 1. (REBOOT) (send 300,receive 100) 1360 2. (??) <-- <-- ESTABLISHED 1362 3. --> --> (ABORT!!) 1364 Figure 10: Active Side Causes Half-Open Connection Discovery 1366 In Figure 11, two TCP Peers A and B with passive connections waiting 1367 for SYN are depicted. An old duplicate arriving at TCP Peer B (line 1368 2) stirs B into action. A SYN-ACK is returned (line 3) and causes 1369 TCP A to generate a RST (the ACK in line 3 is not acceptable). TCP 1370 Peer B accepts the reset and returns to its passive LISTEN state. 1372 TCP Peer A TCP Peer B 1374 1. LISTEN LISTEN 1376 2. ... --> SYN-RECEIVED 1378 3. (??) <-- <-- SYN-RECEIVED 1380 4. --> --> (return to LISTEN!) 1382 5. LISTEN LISTEN 1384 Figure 11: Old Duplicate SYN Initiates a Reset on two Passive Sockets 1386 A variety of other cases are possible, all of which are accounted for 1387 by the following rules for RST generation and processing. 1389 Reset Generation 1391 A TCP user or application can issue a reset on a connection at any 1392 time, though reset events are also generated by the protocol itself 1393 when various error conditions occur, as described below. The side of 1394 a connection issuing a reset should enter the TIME-WAIT state, as 1395 this generally helps to reduce the load on busy servers for reasons 1396 described in [64]. 1398 As a general rule, reset (RST) is sent whenever a segment arrives 1399 that apparently is not intended for the current connection. A reset 1400 must not be sent if it is not clear that this is the case. 1402 There are three groups of states: 1404 1. If the connection does not exist (CLOSED) then a reset is sent 1405 in response to any incoming segment except another reset. A SYN 1406 segment that does not match an existing connection is rejected by 1407 this means. 1409 If the incoming segment has the ACK bit set, the reset takes its 1410 sequence number from the ACK field of the segment, otherwise the 1411 reset has sequence number zero and the ACK field is set to the sum 1412 of the sequence number and segment length of the incoming segment. 1413 The connection remains in the CLOSED state. 1415 2. If the connection is in any non-synchronized state (LISTEN, 1416 SYN-SENT, SYN-RECEIVED), and the incoming segment acknowledges 1417 something not yet sent (the segment carries an unacceptable ACK), 1418 or if an incoming segment has a security level or compartment that 1419 does not exactly match the level and compartment requested for the 1420 connection, a reset is sent. 1422 If the incoming segment has an ACK field, the reset takes its 1423 sequence number from the ACK field of the segment, otherwise the 1424 reset has sequence number zero and the ACK field is set to the sum 1425 of the sequence number and segment length of the incoming segment. 1426 The connection remains in the same state. 1428 3. If the connection is in a synchronized state (ESTABLISHED, 1429 FIN-WAIT-1, FIN-WAIT-2, CLOSE-WAIT, CLOSING, LAST-ACK, TIME-WAIT), 1430 any unacceptable segment (out of window sequence number or 1431 unacceptable acknowledgment number) must be responded to with an 1432 empty acknowledgment segment (without any user data) containing 1433 the current send-sequence number and an acknowledgment indicating 1434 the next sequence number expected to be received, and the 1435 connection remains in the same state. 1437 If an incoming segment has a security level, or compartment that 1438 does not exactly match the level and compartment requested for the 1439 connection, a reset is sent and the connection goes to the CLOSED 1440 state. The reset takes its sequence number from the ACK field of 1441 the incoming segment. 1443 Reset Processing 1444 In all states except SYN-SENT, all reset (RST) segments are validated 1445 by checking their SEQ-fields. A reset is valid if its sequence 1446 number is in the window. In the SYN-SENT state (a RST received in 1447 response to an initial SYN), the RST is acceptable if the ACK field 1448 acknowledges the SYN. 1450 The receiver of a RST first validates it, then changes state. If the 1451 receiver was in the LISTEN state, it ignores it. If the receiver was 1452 in SYN-RECEIVED state and had previously been in the LISTEN state, 1453 then the receiver returns to the LISTEN state, otherwise the receiver 1454 aborts the connection and goes to the CLOSED state. If the receiver 1455 was in any other state, it aborts the connection and advises the user 1456 and goes to the CLOSED state. 1458 TCP implementations SHOULD allow a received RST segment to include 1459 data (SHLD-2). 1461 3.6. Closing a Connection 1463 CLOSE is an operation meaning "I have no more data to send." The 1464 notion of closing a full-duplex connection is subject to ambiguous 1465 interpretation, of course, since it may not be obvious how to treat 1466 the receiving side of the connection. We have chosen to treat CLOSE 1467 in a simplex fashion. The user who CLOSEs may continue to RECEIVE 1468 until the TCP receiver is told that the remote peer has CLOSED also. 1469 Thus, a program could initiate several SENDs followed by a CLOSE, and 1470 then continue to RECEIVE until signaled that a RECEIVE failed because 1471 the remote peer has CLOSED. The TCP implementation will signal a 1472 user, even if no RECEIVEs are outstanding, that the remote peer has 1473 closed, so the user can terminate his side gracefully. A TCP 1474 implementation will reliably deliver all buffers SENT before the 1475 connection was CLOSED so a user who expects no data in return need 1476 only wait to hear the connection was CLOSED successfully to know that 1477 all their data was received at the destination TCP endpoint. Users 1478 must keep reading connections they close for sending until the TCP 1479 implementation indicates there is no more data. 1481 There are essentially three cases: 1483 1) The user initiates by telling the TCP implementation to CLOSE 1484 the connection (TCP Peer A in Figure 12). 1486 2) The remote TCP endpoint initiates by sending a FIN control 1487 signal (TCP Peer B in Figure 12). 1489 3) Both users CLOSE simultaneously (Figure 13). 1491 Case 1: Local user initiates the close 1492 In this case, a FIN segment can be constructed and placed on the 1493 outgoing segment queue. No further SENDs from the user will be 1494 accepted by the TCP implementation, and it enters the FIN-WAIT-1 1495 state. RECEIVEs are allowed in this state. All segments 1496 preceding and including FIN will be retransmitted until 1497 acknowledged. When the other TCP peer has both acknowledged the 1498 FIN and sent a FIN of its own, the first TCP peer can ACK this 1499 FIN. Note that a TCP endpoint receiving a FIN will ACK but not 1500 send its own FIN until its user has CLOSED the connection also. 1502 Case 2: TCP endpoint receives a FIN from the network 1504 If an unsolicited FIN arrives from the network, the receiving TCP 1505 endpoint can ACK it and tell the user that the connection is 1506 closing. The user will respond with a CLOSE, upon which the TCP 1507 endpoint can send a FIN to the other TCP peer after sending any 1508 remaining data. The TCP endpoint then waits until its own FIN is 1509 acknowledged whereupon it deletes the connection. If an ACK is 1510 not forthcoming, after the user timeout the connection is aborted 1511 and the user is told. 1513 Case 3: Both users close simultaneously 1515 A simultaneous CLOSE by users at both ends of a connection causes 1516 FIN segments to be exchanged (Figure 13). When all segments 1517 preceding the FINs have been processed and acknowledged, each TCP 1518 peer can ACK the FIN it has received. Both will, upon receiving 1519 these ACKs, delete the connection. 1521 TCP Peer A TCP Peer B 1523 1. ESTABLISHED ESTABLISHED 1525 2. (Close) 1526 FIN-WAIT-1 --> --> CLOSE-WAIT 1528 3. FIN-WAIT-2 <-- <-- CLOSE-WAIT 1530 4. (Close) 1531 TIME-WAIT <-- <-- LAST-ACK 1533 5. TIME-WAIT --> --> CLOSED 1535 6. (2 MSL) 1536 CLOSED 1538 Figure 12: Normal Close Sequence 1540 TCP Peer A TCP Peer B 1542 1. ESTABLISHED ESTABLISHED 1544 2. (Close) (Close) 1545 FIN-WAIT-1 --> ... FIN-WAIT-1 1546 <-- <-- 1547 ... --> 1549 3. CLOSING --> ... CLOSING 1550 <-- <-- 1551 ... --> 1553 4. TIME-WAIT TIME-WAIT 1554 (2 MSL) (2 MSL) 1555 CLOSED CLOSED 1557 Figure 13: Simultaneous Close Sequence 1559 A TCP connection may terminate in two ways: (1) the normal TCP close 1560 sequence using a FIN handshake (Figure 12), and (2) an "abort" in 1561 which one or more RST segments are sent and the connection state is 1562 immediately discarded. If the local TCP connection is closed by the 1563 remote side due to a FIN or RST received from the remote side, then 1564 the local application MUST be informed whether it closed normally or 1565 was aborted (MUST-12). 1567 3.6.1. Half-Closed Connections 1569 The normal TCP close sequence delivers buffered data reliably in both 1570 directions. Since the two directions of a TCP connection are closed 1571 independently, it is possible for a connection to be "half closed," 1572 i.e., closed in only one direction, and a host is permitted to 1573 continue sending data in the open direction on a half-closed 1574 connection. 1576 A host MAY implement a "half-duplex" TCP close sequence, so that an 1577 application that has called CLOSE cannot continue to read data from 1578 the connection (MAY-1). If such a host issues a CLOSE call while 1579 received data is still pending in the TCP connection, or if new data 1580 is received after CLOSE is called, its TCP implementation SHOULD send 1581 a RST to show that data was lost (SHLD-3). See [22] section 2.17 for 1582 discussion. 1584 When a connection is closed actively, it MUST linger in the TIME-WAIT 1585 state for a time 2xMSL (Maximum Segment Lifetime) (MUST-13). 1586 However, it MAY accept a new SYN from the remote TCP endpoint to 1587 reopen the connection directly from TIME-WAIT state (MAY-2), if it: 1589 (1) assigns its initial sequence number for the new connection to 1590 be larger than the largest sequence number it used on the previous 1591 connection incarnation, and 1593 (2) returns to TIME-WAIT state if the SYN turns out to be an old 1594 duplicate. 1596 When the TCP Timestamp options are available, an improved algorithm 1597 is described in [39] in order to support higher connection 1598 establishment rates. This algorithm for reducing TIME-WAIT is a Best 1599 Current Practice that SHOULD be implemented, since timestamp options 1600 are commonly used, and using them to reduce TIME-WAIT provides 1601 benefits for busy Internet servers (SHLD-4). 1603 3.7. Segmentation 1605 The term "segmentation" refers to the activity TCP performs when 1606 ingesting a stream of bytes from a sending application and 1607 packetizing that stream of bytes into TCP segments. Individual TCP 1608 segments often do not correspond one-for-one to individual send (or 1609 socket write) calls from the application. Applications may perform 1610 writes at the granularity of messages in the upper layer protocol, 1611 but TCP guarantees no boundary coherence between the TCP segments 1612 sent and received versus user application data read or write buffer 1613 boundaries. In some specific protocols, such as Remote Direct Memory 1614 Access (RDMA) using Direct Data Placement (DDP) and Marker PDU 1615 Aligned Framing (MPA) [32], there are performance optimizations 1616 possible when the relation between TCP segments and application data 1617 units can be controlled, and MPA includes a specific mechanism for 1618 detecting and verifying this relationship between TCP segments and 1619 application message data structures, but this is specific to 1620 applications like RDMA. In general, multiple goals influence the 1621 sizing of TCP segments created by a TCP implementation. 1623 Goals driving the sending of larger segments include: 1625 o Reducing the number of packets in flight within the network. 1627 o Increasing processing efficiency and potential performance by 1628 enabling a smaller number of interrupts and inter-layer 1629 interactions. 1631 o Limiting the overhead of TCP headers. 1633 Note that the performance benefits of sending larger segments may 1634 decrease as the size increases, and there may be boundaries where 1635 advantages are reversed. For instance, on some implementation 1636 architectures, 1025 bytes within a segment could lead to worse 1637 performance than 1024 bytes, due purely to data alignment on copy 1638 operations. 1640 Goals driving the sending of smaller segments include: 1642 o Avoiding sending a TCP segment that would result in an IP datagram 1643 larger than the smallest MTU along an IP network path, because 1644 this results in either packet loss or packet fragmentation. 1645 Making matters worse, some firewalls or middleboxes may drop 1646 fragmented packets or ICMP messages related to fragmentation. 1648 o Preventing delays to the application data stream, especially when 1649 TCP is waiting on the application to generate more data, or when 1650 the application is waiting on an event or input from its peer in 1651 order to generate more data. 1653 o Enabling "fate sharing" between TCP segments and lower-layer data 1654 units (e.g. below IP, for links with cell or frame sizes smaller 1655 than the IP MTU). 1657 Towards meeting these competing sets of goals, TCP includes several 1658 mechanisms, including the Maximum Segment Size option, Path MTU 1659 Discovery, the Nagle algorithm, and support for IPv6 Jumbograms, as 1660 discussed in the following subsections. 1662 3.7.1. Maximum Segment Size Option 1664 TCP endpoints MUST implement both sending and receiving the MSS 1665 option (MUST-14). 1667 TCP implementations SHOULD send an MSS option in every SYN segment 1668 when its receive MSS differs from the default 536 for IPv4 or 1220 1669 for IPv6 (SHLD-5), and MAY send it always (MAY-3). 1671 If an MSS option is not received at connection setup, TCP 1672 implementations MUST assume a default send MSS of 536 (576-40) for 1673 IPv4 or 1220 (1280 - 60) for IPv6 (MUST-15). 1675 The maximum size of a segment that TCP endpoint really sends, the 1676 "effective send MSS," MUST be the smaller (MUST-16) of the send MSS 1677 (that reflects the available reassembly buffer size at the remote 1678 host, the EMTU_R [18]) and the largest transmission size permitted by 1679 the IP layer (EMTU_S [18]): 1681 Eff.snd.MSS = 1683 min(SendMSS+20, MMS_S) - TCPhdrsize - IPoptionsize 1685 where: 1687 o SendMSS is the MSS value received from the remote host, or the 1688 default 536 for IPv4 or 1220 for IPv6, if no MSS option is 1689 received. 1691 o MMS_S is the maximum size for a transport-layer message that TCP 1692 may send. 1694 o TCPhdrsize is the size of the fixed TCP header and any options. 1695 This is 20 in the (rare) case that no options are present, but may 1696 be larger if TCP options are to be sent. Note that some options 1697 might not be included on all segments, but that for each segment 1698 sent, the sender should adjust the data length accordingly, within 1699 the Eff.snd.MSS. 1701 o IPoptionsize is the size of any IPv4 options or IPv6 extension 1702 headers associated with a TCP connection. Note that some options 1703 or extension headers might not be included on all packets, but 1704 that for each segment sent, the sender should adjust the data 1705 length accordingly, within the Eff.snd.MSS. 1707 The MSS value to be sent in an MSS option should be equal to the 1708 effective MTU minus the fixed IP and TCP headers. By ignoring both 1709 IP and TCP options when calculating the value for the MSS option, if 1710 there are any IP or TCP options to be sent in a packet, then the 1711 sender must decrease the size of the TCP data accordingly. RFC 6691 1712 [42] discusses this in greater detail. 1714 The MSS value to be sent in an MSS option must be less than or equal 1715 to: 1717 MMS_R - 20 1719 where MMS_R is the maximum size for a transport-layer message that 1720 can be received (and reassembled at the IP layer) (MUST-67). TCP 1721 obtains MMS_R and MMS_S from the IP layer; see the generic call 1722 GET_MAXSIZES in Section 3.4 of RFC 1122. These are defined in terms 1723 of their IP MTU equivalents, EMTU_R and EMTU_S [18]. 1725 When TCP is used in a situation where either the IP or TCP headers 1726 are not fixed, the sender must reduce the amount of TCP data in any 1727 given packet by the number of octets used by the IP and TCP options. 1728 This has been a point of confusion historically, as explained in RFC 1729 6691, Section 3.1. 1731 3.7.2. Path MTU Discovery 1733 A TCP implementation may be aware of the MTU on directly connected 1734 links, but will rarely have insight about MTUs across an entire 1735 network path. For IPv4, RFC 1122 recommends an IP-layer default 1736 effective MTU of less than or equal to 576 for destinations not 1737 directly connected, and for IPv6 this would be 1280. Using these 1738 fixed values limits TCP connection performance and efficiency. 1739 Instead, implementation of Path MTU Discovery (PMTUD) and 1740 Packetization Layer Path MTU Discovery (PLPMTUD) is strongly 1741 recommended in order for TCP to improve segmentation decisions. Both 1742 PMTUD and PLPMTUD help TCP choose segment sizes that avoid both on- 1743 path (for IPv4) and source fragmentation (IPv4 and IPv6). 1745 PMTUD for IPv4 [2] or IPv6 [14] is implemented in conjunction between 1746 TCP, IP, and ICMP protocols. It relies both on avoiding source 1747 fragmentation and setting the IPv4 DF (don't fragment) flag, the 1748 latter to inhibit on-path fragmentation. It relies on ICMP errors 1749 from routers along the path, whenever a segment is too large to 1750 traverse a link. Several adjustments to a TCP implementation with 1751 PMTUD are described in RFC 2923 in order to deal with problems 1752 experienced in practice [25]. PLPMTUD [29] is a Standards Track 1753 improvement to PMTUD that relaxes the requirement for ICMP support 1754 across a path, and improves performance in cases where ICMP is not 1755 consistently conveyed, but still tries to avoid source fragmentation. 1756 The mechanisms in all four of these RFCs are recommended to be 1757 included in TCP implementations. 1759 The TCP MSS option specifies an upper bound for the size of packets 1760 that can be received (see [42]). Hence, setting the value in the MSS 1761 option too small can impact the ability for PMTUD or PLPMTUD to find 1762 a larger path MTU. RFC 1191 discusses this implication of many older 1763 TCP implementations setting the TCP MSS to 536 (corresponding to the 1764 IPv4 576 byte default MTU) for non-local destinations, rather than 1765 deriving it from the MTUs of connected interfaces as recommended. 1767 3.7.3. Interfaces with Variable MTU Values 1769 The effective MTU can sometimes vary, as when used with variable 1770 compression, e.g., RObust Header Compression (ROHC) [35]. It is 1771 tempting for a TCP implementation to advertise the largest possible 1772 MSS, to support the most efficient use of compressed payloads. 1773 Unfortunately, some compression schemes occasionally need to transmit 1774 full headers (and thus smaller payloads) to resynchronize state at 1775 their endpoint compressors/decompressors. If the largest MTU is used 1776 to calculate the value to advertise in the MSS option, TCP 1777 retransmission may interfere with compressor resynchronization. 1779 As a result, when the effective MTU of an interface varies packet-to- 1780 packet, TCP implementations SHOULD use the smallest effective MTU of 1781 the interface to calculate the value to advertise in the MSS option 1782 (SHLD-6). 1784 3.7.4. Nagle Algorithm 1786 The "Nagle algorithm" was described in RFC 896 [17] and was 1787 recommended in RFC 1122 [18] for mitigation of an early problem of 1788 too many small packets being generated. It has been implemented in 1789 most current TCP code bases, sometimes with minor variations (see 1790 Appendix A.3). 1792 If there is unacknowledged data (i.e., SND.NXT > SND.UNA), then the 1793 sending TCP endpoint buffers all user data (regardless of the PSH 1794 bit), until the outstanding data has been acknowledged or until the 1795 TCP endpoint can send a full-sized segment (Eff.snd.MSS bytes). 1797 A TCP implementation SHOULD implement the Nagle Algorithm to coalesce 1798 short segments (SHLD-7). However, there MUST be a way for an 1799 application to disable the Nagle algorithm on an individual 1800 connection (MUST-17). In all cases, sending data is also subject to 1801 the limitation imposed by the Slow Start algorithm [9]. 1803 Since there can be problematic interactions between the Nagle 1804 Algorithm and delayed acknowledgements, some implementations use 1805 minor variations of the Nagle algorithm, such as the one described in 1806 Appendix A.3. 1808 3.7.5. IPv6 Jumbograms 1810 In order to support TCP over IPv6 Jumbograms, implementations need to 1811 be able to send TCP segments larger than the 64KB limit that the MSS 1812 option can convey. RFC 2675 [5] defines that an MSS value of 65,535 1813 bytes is to be treated as infinity, and Path MTU Discovery [14] is 1814 used to determine the actual MSS. 1816 The Jumbo Payload option need not be implemented or understood by 1817 IPv6 nodes that do not support attachment to links with a MTU greater 1818 than 65,575 [5], and the present IPv6 Node Requirements does not 1819 include support for Jumbograms [53]. 1821 3.8. Data Communication 1823 Once the connection is established data is communicated by the 1824 exchange of segments. Because segments may be lost due to errors 1825 (checksum test failure), or network congestion, TCP uses 1826 retransmission to ensure delivery of every segment. Duplicate 1827 segments may arrive due to network or TCP retransmission. As 1828 discussed in the section on sequence numbers the TCP implementation 1829 performs certain tests on the sequence and acknowledgment numbers in 1830 the segments to verify their acceptability. 1832 The sender of data keeps track of the next sequence number to use in 1833 the variable SND.NXT. The receiver of data keeps track of the next 1834 sequence number to expect in the variable RCV.NXT. The sender of 1835 data keeps track of the oldest unacknowledged sequence number in the 1836 variable SND.UNA. If the data flow is momentarily idle and all data 1837 sent has been acknowledged then the three variables will be equal. 1839 When the sender creates a segment and transmits it the sender 1840 advances SND.NXT. When the receiver accepts a segment it advances 1841 RCV.NXT and sends an acknowledgment. When the data sender receives 1842 an acknowledgment it advances SND.UNA. The extent to which the 1843 values of these variables differ is a measure of the delay in the 1844 communication. The amount by which the variables are advanced is the 1845 length of the data and SYN or FIN flags in the segment. Note that 1846 once in the ESTABLISHED state all segments must carry current 1847 acknowledgment information. 1849 The CLOSE user call implies a push function (see Section 3.9.1), as 1850 does the FIN control flag in an incoming segment. 1852 3.8.1. Retransmission Timeout 1854 Because of the variability of the networks that compose an 1855 internetwork system and the wide range of uses of TCP connections the 1856 retransmission timeout (RTO) must be dynamically determined. 1858 The RTO MUST be computed according to the algorithm in [10], 1859 including Karn's algorithm for taking RTT samples (MUST-18). 1861 RFC 793 contains an early example procedure for computing the RTO. 1862 This was then replaced by the algorithm described in RFC 1122, and 1863 subsequently updated in RFC 2988, and then again in RFC 6298. 1865 RFC 1122 allows that if a retransmitted packet is identical to the 1866 original packet (which implies not only that the data boundaries have 1867 not changed, but also that none of the headers have changed), then 1868 the same IPv4 Identification field MAY be used (see Section 3.2.1.5 1869 of RFC 1122) (MAY-4). The same IP identification field may be reused 1870 anyways, since it is only meaningful when a datagram is fragmented 1871 [43]. TCP implementations should not rely on or typically interact 1872 with this IPv4 header field in any way. It is not a reasonable way 1873 to either indicate duplicate sent segments, nor to identify duplicate 1874 received segments. 1876 3.8.2. TCP Congestion Control 1878 RFC 2914 [6] explains the importance of congestion control for the 1879 Internet. 1881 RFC 1122 required implementation of Van Jacobson's congestion control 1882 algorithms slow start and congestion avoidance together with 1883 exponential back-off for successive RTO values for the same segment. 1884 RFC 2581 provided IETF Standards Track description of slow start and 1885 congestion avoidance, along with fast retransmit and fast recovery. 1886 RFC 5681 is the current description of these algorithms and is the 1887 current Standards Track specification providing guidelines for TCP 1888 congestion control. RFC 6298 describes exponential back-off of RTO 1889 values, including keeping the backed-off value until a subsequent 1890 segment with new data has been sent and acknowledged without 1891 retransmission. 1893 A TCP endpoint MUST implement the basic congestion control algorithms 1894 slow start, congestion avoidance, and exponential back-off of RTO to 1895 avoid creating congestion collapse conditions (MUST-19). RFC 5681 1896 and RFC 6298 describe the basic algorithms on the IETF Standards 1897 Track that are broadly applicable. Multiple other suitable 1898 algorithms exist and have been widely used. Many TCP implementations 1899 support a set of alternative algorithms that can be configured for 1900 use on the endpoint. An endpoint MAY implement such alternative 1901 algorithms provided that the algorithms are conformant with the TCP 1902 specifications from the IETF Standards Track as described in RFC 1903 2914, RFC 5033 [8], and RFC 8961 [15] (MAY-18). 1905 Explicit Congestion Notification (ECN) was defined in RFC 3168 and is 1906 an IETF Standards Track enhancement that has many benefits [50]. 1908 A TCP endpoint SHOULD implement ECN as described in RFC 3168 (SHLD- 1909 8). 1911 3.8.3. TCP Connection Failures 1913 Excessive retransmission of the same segment by a TCP endpoint 1914 indicates some failure of the remote host or the Internet path. This 1915 failure may be of short or long duration. The following procedure 1916 MUST be used to handle excessive retransmissions of data segments 1917 (MUST-20): 1919 (a) There are two thresholds R1 and R2 measuring the amount of 1920 retransmission that has occurred for the same segment. R1 and R2 1921 might be measured in time units or as a count of retransmissions 1922 (with the current RTO and corresponding backoffs as a conversion 1923 factor, if needed). 1925 (b) When the number of transmissions of the same segment reaches 1926 or exceeds threshold R1, pass negative advice (see Section 3.3.1.4 1927 of [18]) to the IP layer, to trigger dead-gateway diagnosis. 1929 (c) When the number of transmissions of the same segment reaches a 1930 threshold R2 greater than R1, close the connection. 1932 (d) An application MUST (MUST-21) be able to set the value for R2 1933 for a particular connection. For example, an interactive 1934 application might set R2 to "infinity," giving the user control 1935 over when to disconnect. 1937 (e) TCP implementations SHOULD inform the application of the 1938 delivery problem (unless such information has been disabled by the 1939 application; see Asynchronous Reports section), when R1 is reached 1940 and before R2 (SHLD-9). This will allow a remote login (User 1941 Telnet) application program to inform the user, for example. 1943 The value of R1 SHOULD correspond to at least 3 retransmissions, at 1944 the current RTO (SHLD-10). The value of R2 SHOULD correspond to at 1945 least 100 seconds (SHLD-11). 1947 An attempt to open a TCP connection could fail with excessive 1948 retransmissions of the SYN segment or by receipt of a RST segment or 1949 an ICMP Port Unreachable. SYN retransmissions MUST be handled in the 1950 general way just described for data retransmissions, including 1951 notification of the application layer. 1953 However, the values of R1 and R2 may be different for SYN and data 1954 segments. In particular, R2 for a SYN segment MUST be set large 1955 enough to provide retransmission of the segment for at least 3 1956 minutes (MUST-23). The application can close the connection (i.e., 1957 give up on the open attempt) sooner, of course. 1959 3.8.4. TCP Keep-Alives 1961 A TCP connection is said to be "idle" if for some long amount of time 1962 there have been no incoming segments received and there is no new or 1963 unacknowledged data to be sent. 1965 Implementors MAY include "keep-alives" in their TCP implementations 1966 (MAY-5), although this practice is not universally accepted. Some 1967 TCP implementations, however, have included a keep-alive mechanism. 1968 To confirm that an idle connection is still active, these 1969 implementations send a probe segment designed to elicit a response 1970 from the TCP peer. Such a segment generally contains SEG.SEQ = 1971 SND.NXT-1 and may or may not contain one garbage octet of data. If 1972 keep-alives are included, the application MUST be able to turn them 1973 on or off for each TCP connection (MUST-24), and they MUST default to 1974 off (MUST-25). 1976 Keep-alive packets MUST only be sent when no sent data is 1977 outstanding, and no data or acknowledgement packets have been 1978 received for the connection within an interval (MUST-26). This 1979 interval MUST be configurable (MUST-27) and MUST default to no less 1980 than two hours (MUST-28). 1982 It is extremely important to remember that ACK segments that contain 1983 no data are not reliably transmitted by TCP. Consequently, if a 1984 keep-alive mechanism is implemented it MUST NOT interpret failure to 1985 respond to any specific probe as a dead connection (MUST-29). 1987 An implementation SHOULD send a keep-alive segment with no data 1988 (SHLD-12); however, it MAY be configurable to send a keep-alive 1989 segment containing one garbage octet (MAY-6), for compatibility with 1990 erroneous TCP implementations. 1992 3.8.5. The Communication of Urgent Information 1994 As a result of implementation differences and middlebox interactions, 1995 new applications SHOULD NOT employ the TCP urgent mechanism (SHLD- 1996 13). However, TCP implementations MUST still include support for the 1997 urgent mechanism (MUST-30). Details can be found in RFC 6093 [38]. 1999 The objective of the TCP urgent mechanism is to allow the sending 2000 user to stimulate the receiving user to accept some urgent data and 2001 to permit the receiving TCP endpoint to indicate to the receiving 2002 user when all the currently known urgent data has been received by 2003 the user. 2005 This mechanism permits a point in the data stream to be designated as 2006 the end of urgent information. Whenever this point is in advance of 2007 the receive sequence number (RCV.NXT) at the receiving TCP endpoint, 2008 that TCP must tell the user to go into "urgent mode"; when the 2009 receive sequence number catches up to the urgent pointer, the TCP 2010 implementation must tell user to go into "normal mode". If the 2011 urgent pointer is updated while the user is in "urgent mode", the 2012 update will be invisible to the user. 2014 The method employs an urgent field that is carried in all segments 2015 transmitted. The URG control flag indicates that the urgent field is 2016 meaningful and must be added to the segment sequence number to yield 2017 the urgent pointer. The absence of this flag indicates that there is 2018 no urgent data outstanding. 2020 To send an urgent indication the user must also send at least one 2021 data octet. If the sending user also indicates a push, timely 2022 delivery of the urgent information to the destination process is 2023 enhanced. Note that because changes in the urgent pointer correspond 2024 to data being written by a sending application, the urgent pointer 2025 can not "recede" in the sequence space, but a TCP receiver should be 2026 robust to invalid urgent pointer values. 2028 A TCP implementation MUST support a sequence of urgent data of any 2029 length (MUST-31). [18] 2031 The urgent pointer MUST point to the sequence number of the octet 2032 following the urgent data (MUST-62). 2034 A TCP implementation MUST (MUST-32) inform the application layer 2035 asynchronously whenever it receives an Urgent pointer and there was 2036 previously no pending urgent data, or whenever the Urgent pointer 2037 advances in the data stream. The TCP implementation MUST (MUST-33) 2038 provide a way for the application to learn how much urgent data 2039 remains to be read from the connection, or at least to determine 2040 whether or not more urgent data remains to be read [18]. 2042 3.8.6. Managing the Window 2044 The window sent in each segment indicates the range of sequence 2045 numbers the sender of the window (the data receiver) is currently 2046 prepared to accept. There is an assumption that this is related to 2047 the currently available data buffer space available for this 2048 connection. 2050 The sending TCP endpoint packages the data to be transmitted into 2051 segments that fit the current window, and may repackage segments on 2052 the retransmission queue. Such repackaging is not required, but may 2053 be helpful. 2055 In a connection with a one-way data flow, the window information will 2056 be carried in acknowledgment segments that all have the same sequence 2057 number so there will be no way to reorder them if they arrive out of 2058 order. This is not a serious problem, but it will allow the window 2059 information to be on occasion temporarily based on old reports from 2060 the data receiver. A refinement to avoid this problem is to act on 2061 the window information from segments that carry the highest 2062 acknowledgment number (that is segments with acknowledgment number 2063 equal or greater than the highest previously received). 2065 Indicating a large window encourages transmissions. If more data 2066 arrives than can be accepted, it will be discarded. This will result 2067 in excessive retransmissions, adding unnecessarily to the load on the 2068 network and the TCP endpoints. Indicating a small window may 2069 restrict the transmission of data to the point of introducing a round 2070 trip delay between each new segment transmitted. 2072 The mechanisms provided allow a TCP endpoint to advertise a large 2073 window and to subsequently advertise a much smaller window without 2074 having accepted that much data. This, so called "shrinking the 2075 window," is strongly discouraged. The robustness principle [18] 2076 dictates that TCP peers will not shrink the window themselves, but 2077 will be prepared for such behavior on the part of other TCP peers. 2079 A TCP receiver SHOULD NOT shrink the window, i.e., move the right 2080 window edge to the left (SHLD-14). However, a sending TCP peer MUST 2081 be robust against window shrinking, which may cause the "usable 2082 window" (see Section 3.8.6.2.1) to become negative (MUST-34). 2084 If this happens, the sender SHOULD NOT send new data (SHLD-15), but 2085 SHOULD retransmit normally the old unacknowledged data between 2086 SND.UNA and SND.UNA+SND.WND (SHLD-16). The sender MAY also 2087 retransmit old data beyond SND.UNA+SND.WND (MAY-7), but SHOULD NOT 2088 time out the connection if data beyond the right window edge is not 2089 acknowledged (SHLD-17). If the window shrinks to zero, the TCP 2090 implementation MUST probe it in the standard way (described below) 2091 (MUST-35). 2093 3.8.6.1. Zero Window Probing 2095 The sending TCP peer must regularly transmit at least one octet of 2096 new data (if available) or retransmit to the receiving TCP peer even 2097 if the send window is zero, in order to "probe" the window. This 2098 retransmission is essential to guarantee that when either TCP peer 2099 has a zero window the re-opening of the window will be reliably 2100 reported to the other. This is referred to as Zero-Window Probing 2101 (ZWP) in other documents. 2103 Probing of zero (offered) windows MUST be supported (MUST-36). 2105 A TCP implementation MAY keep its offered receive window closed 2106 indefinitely (MAY-8). As long as the receiving TCP peer continues to 2107 send acknowledgments in response to the probe segments, the sending 2108 TCP peer MUST allow the connection to stay open (MUST-37). This 2109 enables TCP to function in scenarios such as the "printer ran out of 2110 paper" situation described in Section 4.2.2.17 of RFC1122. The 2111 behavior is subject to the implementation's resource management 2112 concerns, as noted in [40]. 2114 When the receiving TCP peer has a zero window and a segment arrives 2115 it must still send an acknowledgment showing its next expected 2116 sequence number and current window (zero). 2118 The transmitting host SHOULD send the first zero-window probe when a 2119 zero window has existed for the retransmission timeout period (SHLD- 2120 29) (Section 3.8.1), and SHOULD increase exponentially the interval 2121 between successive probes (SHLD-30). 2123 3.8.6.2. Silly Window Syndrome Avoidance 2125 The "Silly Window Syndrome" (SWS) is a stable pattern of small 2126 incremental window movements resulting in extremely poor TCP 2127 performance. Algorithms to avoid SWS are described below for both 2128 the sending side and the receiving side. RFC 1122 contains more 2129 detailed discussion of the SWS problem. Note that the Nagle 2130 algorithm and the sender SWS avoidance algorithm play complementary 2131 roles in improving performance. The Nagle algorithm discourages 2132 sending tiny segments when the data to be sent increases in small 2133 increments, while the SWS avoidance algorithm discourages small 2134 segments resulting from the right window edge advancing in small 2135 increments. 2137 3.8.6.2.1. Sender's Algorithm - When to Send Data 2139 A TCP implementation MUST include a SWS avoidance algorithm in the 2140 sender (MUST-38). 2142 The Nagle algorithm from Section 3.7.4 additionally describes how to 2143 coalesce short segments. 2145 The sender's SWS avoidance algorithm is more difficult than the 2146 receivers's, because the sender does not know (directly) the 2147 receiver's total buffer space RCV.BUFF. An approach that has been 2148 found to work well is for the sender to calculate Max(SND.WND), the 2149 maximum send window it has seen so far on the connection, and to use 2150 this value as an estimate of RCV.BUFF. Unfortunately, this can only 2151 be an estimate; the receiver may at any time reduce the size of 2152 RCV.BUFF. To avoid a resulting deadlock, it is necessary to have a 2153 timeout to force transmission of data, overriding the SWS avoidance 2154 algorithm. In practice, this timeout should seldom occur. 2156 The "usable window" is: 2158 U = SND.UNA + SND.WND - SND.NXT 2160 i.e., the offered window less the amount of data sent but not 2161 acknowledged. If D is the amount of data queued in the sending TCP 2162 endpoint but not yet sent, then the following set of rules is 2163 recommended. 2165 Send data: 2167 (1) if a maximum-sized segment can be sent, i.e, if: 2169 min(D,U) >= Eff.snd.MSS; 2171 (2) or if the data is pushed and all queued data can be sent now, 2172 i.e., if: 2174 [SND.NXT = SND.UNA and] PUSHED and D <= U 2176 (the bracketed condition is imposed by the Nagle algorithm); 2178 (3) or if at least a fraction Fs of the maximum window can be sent, 2179 i.e., if: 2181 [SND.NXT = SND.UNA and] 2183 min(D,U) >= Fs * Max(SND.WND); 2185 (4) or if the override timeout occurs. 2187 Here Fs is a fraction whose recommended value is 1/2. The override 2188 timeout should be in the range 0.1 - 1.0 seconds. It may be 2189 convenient to combine this timer with the timer used to probe zero 2190 windows (Section 3.8.6.1). 2192 3.8.6.2.2. Receiver's Algorithm - When to Send a Window Update 2194 A TCP implementation MUST include a SWS avoidance algorithm in the 2195 receiver (MUST-39). 2197 The receiver's SWS avoidance algorithm determines when the right 2198 window edge may be advanced; this is customarily known as "updating 2199 the window". This algorithm combines with the delayed ACK algorithm 2200 (Section 3.8.6.3) to determine when an ACK segment containing the 2201 current window will really be sent to the receiver. 2203 The solution to receiver SWS is to avoid advancing the right window 2204 edge RCV.NXT+RCV.WND in small increments, even if data is received 2205 from the network in small segments. 2207 Suppose the total receive buffer space is RCV.BUFF. At any given 2208 moment, RCV.USER octets of this total may be tied up with data that 2209 has been received and acknowledged but that the user process has not 2210 yet consumed. When the connection is quiescent, RCV.WND = RCV.BUFF 2211 and RCV.USER = 0. 2213 Keeping the right window edge fixed as data arrives and is 2214 acknowledged requires that the receiver offer less than its full 2215 buffer space, i.e., the receiver must specify a RCV.WND that keeps 2216 RCV.NXT+RCV.WND constant as RCV.NXT increases. Thus, the total 2217 buffer space RCV.BUFF is generally divided into three parts: 2219 |<------- RCV.BUFF ---------------->| 2220 1 2 3 2221 ----|---------|------------------|------|---- 2222 RCV.NXT ^ 2223 (Fixed) 2225 1 - RCV.USER = data received but not yet consumed; 2226 2 - RCV.WND = space advertised to sender; 2227 3 - Reduction = space available but not yet 2228 advertised. 2230 The suggested SWS avoidance algorithm for the receiver is to keep 2231 RCV.NXT+RCV.WND fixed until the reduction satisfies: 2233 RCV.BUFF - RCV.USER - RCV.WND >= 2235 min( Fr * RCV.BUFF, Eff.snd.MSS ) 2237 where Fr is a fraction whose recommended value is 1/2, and 2238 Eff.snd.MSS is the effective send MSS for the connection (see 2239 Section 3.7.1). When the inequality is satisfied, RCV.WND is set to 2240 RCV.BUFF-RCV.USER. 2242 Note that the general effect of this algorithm is to advance RCV.WND 2243 in increments of Eff.snd.MSS (for realistic receive buffers: 2244 Eff.snd.MSS < RCV.BUFF/2). Note also that the receiver must use its 2245 own Eff.snd.MSS, assuming it is the same as the sender's. 2247 3.8.6.3. Delayed Acknowledgements - When to Send an ACK Segment 2249 A host that is receiving a stream of TCP data segments can increase 2250 efficiency in both the Internet and the hosts by sending fewer than 2251 one ACK (acknowledgment) segment per data segment received; this is 2252 known as a "delayed ACK". 2254 A TCP endpoint SHOULD implement a delayed ACK (SHLD-18), but an ACK 2255 should not be excessively delayed; in particular, the delay MUST be 2256 less than 0.5 seconds (MUST-40). An ACK SHOULD be generated for at 2257 least every second full-sized segment or 2*RMSS bytes of new data 2258 (where RMSS is the MSS specified by the TCP endpoint receiving the 2259 segments to be acknowledged, or the default value if not specified) 2260 (SHLD-19). Excessive delays on ACKs can disturb the round-trip 2261 timing and packet "clocking" algorithms. More complete discussion of 2262 delayed ACK behavior is in Section 4.2 of RFC 5681 [9], including 2263 recomendations to immediately acknowledge out-of-order segments, 2264 segments above a gap in sequence space, or segments that fill all or 2265 part of a gap, in order to accelerate loss recovery. 2267 Note that there are several current practices that further lead to a 2268 reduced number of ACKs, including generic receive offload (GRO), ACK 2269 compression, and ACK decimation [26]. 2271 3.9. Interfaces 2273 There are of course two interfaces of concern: the user/TCP interface 2274 and the TCP/lower-level interface. We have a fairly elaborate model 2275 of the user/TCP interface, but the interface to the lower level 2276 protocol module is left unspecified here, since it will be specified 2277 in detail by the specification of the lower level protocol. For the 2278 case that the lower level is IP we note some of the parameter values 2279 that TCP implementations might use. 2281 3.9.1. User/TCP Interface 2283 The following functional description of user commands to the TCP 2284 implementation is, at best, fictional, since every operating system 2285 will have different facilities. Consequently, we must warn readers 2286 that different TCP implementations may have different user 2287 interfaces. However, all TCP implementations must provide a certain 2288 minimum set of services to guarantee that all TCP implementations can 2289 support the same protocol hierarchy. This section specifies the 2290 functional interfaces required of all TCP implementations. 2292 Section 3.1 of [52] also identifies primitives provided by TCP, and 2293 could be used as an additional reference for implementers. 2295 TCP User Commands 2297 The following sections functionally characterize a USER/TCP 2298 interface. The notation used is similar to most procedure or 2299 function calls in high level languages, but this usage is not 2300 meant to rule out trap type service calls. 2302 The user commands described below specify the basic functions the 2303 TCP implementation must perform to support interprocess 2304 communication. Individual implementations must define their own 2305 exact format, and may provide combinations or subsets of the basic 2306 functions in single calls. In particular, some implementations 2307 may wish to automatically OPEN a connection on the first SEND or 2308 RECEIVE issued by the user for a given connection. 2310 In providing interprocess communication facilities, the TCP 2311 implementation must not only accept commands, but must also return 2312 information to the processes it serves. The latter consists of: 2314 (a) general information about a connection (e.g., interrupts, 2315 remote close, binding of unspecified remote socket). 2317 (b) replies to specific user commands indicating success or 2318 various types of failure. 2320 Open 2322 Format: OPEN (local port, remote socket, active/passive [, 2323 timeout] [, DiffServ field] [, security/compartment] [local IP 2324 address,] [, options]) -> local connection name 2326 If the active/passive flag is set to passive, then this is a 2327 call to LISTEN for an incoming connection. A passive open may 2328 have either a fully specified remote socket to wait for a 2329 particular connection or an unspecified remote socket to wait 2330 for any call. A fully specified passive call can be made 2331 active by the subsequent execution of a SEND. 2333 A transmission control block (TCB) is created and partially 2334 filled in with data from the OPEN command parameters. 2336 Every passive OPEN call either creates a new connection record 2337 in LISTEN state, or it returns an error; it MUST NOT affect any 2338 previously created connection record (MUST-41). 2340 A TCP implementation that supports multiple concurrent 2341 connections MUST provide an OPEN call that will functionally 2342 allow an application to LISTEN on a port while a connection 2343 block with the same local port is in SYN-SENT or SYN-RECEIVED 2344 state (MUST-42). 2346 On an active OPEN command, the TCP endpoint will begin the 2347 procedure to synchronize (i.e., establish) the connection at 2348 once. 2350 The timeout, if present, permits the caller to set up a timeout 2351 for all data submitted to TCP. If data is not successfully 2352 delivered to the destination within the timeout period, the TCP 2353 endpoint will abort the connection. The present global default 2354 is five minutes. 2356 The TCP implementation or some component of the operating 2357 system will verify the users authority to open a connection 2358 with the specified DiffServ field value or security/ 2359 compartment. The absence of a DiffServ field value or 2360 security/compartment specification in the OPEN call indicates 2361 the default values must be used. 2363 TCP will accept incoming requests as matching only if the 2364 security/compartment information is exactly the same as that 2365 requested in the OPEN call. 2367 The DiffServ field value indicated by the user only impacts 2368 outgoing packets, may be altered en route through the network, 2369 and has no direct bearing or relation to received packets. 2371 A local connection name will be returned to the user by the TCP 2372 implementation. The local connection name can then be used as 2373 a short hand term for the connection defined by the pair. 2376 The optional "local IP address" parameter MUST be supported to 2377 allow the specification of the local IP address (MUST-43). 2378 This enables applications that need to select the local IP 2379 address used when multihoming is present. 2381 A passive OPEN call with a specified "local IP address" 2382 parameter will await an incoming connection request to that 2383 address. If the parameter is unspecified, a passive OPEN will 2384 await an incoming connection request to any local IP address, 2385 and then bind the local IP address of the connection to the 2386 particular address that is used. 2388 For an active OPEN call, a specified "local IP address" 2389 parameter will be used for opening the connection. If the 2390 parameter is unspecified, the host will choose an appropriate 2391 local IP address (see RFC 1122 section 3.3.4.2). 2393 If an application on a multihomed host does not specify the 2394 local IP address when actively opening a TCP connection, then 2395 the TCP implementation MUST ask the IP layer to select a local 2396 IP address before sending the (first) SYN (MUST-44). See the 2397 function GET_SRCADDR() in Section 3.4 of RFC 1122. 2399 At all other times, a previous segment has either been sent or 2400 received on this connection, and TCP implementations MUST use 2401 the same local address is used that was used in those previous 2402 segments (MUST-45). 2404 A TCP implementation MUST reject as an error a local OPEN call 2405 for an invalid remote IP address (e.g., a broadcast or 2406 multicast address) (MUST-46). 2408 Send 2410 Format: SEND (local connection name, buffer address, byte 2411 count, PUSH flag (optional), URGENT flag [,timeout]) 2413 This call causes the data contained in the indicated user 2414 buffer to be sent on the indicated connection. If the 2415 connection has not been opened, the SEND is considered an 2416 error. Some implementations may allow users to SEND first; in 2417 which case, an automatic OPEN would be done. For example, this 2418 might be one way for application data to be included in SYN 2419 segments. If the calling process is not authorized to use this 2420 connection, an error is returned. 2422 A TCP endpoint MAY implement PUSH flags on SEND calls (MAY-15). 2423 If PUSH flags are not implemented, then the sending TCP peer: 2424 (1) MUST NOT buffer data indefinitely (MUST-60), and (2) MUST 2425 set the PSH bit in the last buffered segment (i.e., when there 2426 is no more queued data to be sent) (MUST-61). The remaining 2427 description below assumes the PUSH flag is supported on SEND 2428 calls. 2430 If the PUSH flag is set, the application intends the data to be 2431 transmitted promptly to the receiver, and the PUSH bit will be 2432 set in the last TCP segment created from the buffer. When an 2433 application issues a series of SEND calls without setting the 2434 PUSH flag, the TCP implementation MAY aggregate the data 2435 internally without sending it (MAY-16). 2437 The PSH bit is not a record marker and is independent of 2438 segment boundaries. The transmitter SHOULD collapse successive 2439 bits when it packetizes data, to send the largest possible 2440 segment (SHLD-27). 2442 If the PUSH flag is not set, the data may be combined with data 2443 from subsequent SENDs for transmission efficiency. Note that 2444 when the Nagle algorithm is in use, TCP implementations may 2445 buffer the data before sending, without regard to the PUSH flag 2446 (see Section 3.7.4). 2448 An application program is logically required to set the PUSH 2449 flag in a SEND call whenever it needs to force delivery of the 2450 data to avoid a communication deadlock. However, a TCP 2451 implementation SHOULD send a maximum-sized segment whenever 2452 possible (SHLD-28), to improve performance (see 2453 Section 3.8.6.2.1). 2455 New applications SHOULD NOT set the URGENT flag [38] due to 2456 implementation differences and middlebox issues (SHLD-13). 2458 If the URGENT flag is set, segments sent to the destination TCP 2459 peer will have the urgent pointer set. The receiving TCP peer 2460 will signal the urgent condition to the receiving process if 2461 the urgent pointer indicates that data preceding the urgent 2462 pointer has not been consumed by the receiving process. The 2463 purpose of urgent is to stimulate the receiver to process the 2464 urgent data and to indicate to the receiver when all the 2465 currently known urgent data has been received. The number of 2466 times the sending user's TCP implementation signals urgent will 2467 not necessarily be equal to the number of times the receiving 2468 user will be notified of the presence of urgent data. 2470 If no remote socket was specified in the OPEN, but the 2471 connection is established (e.g., because a LISTENing connection 2472 has become specific due to a remote segment arriving for the 2473 local socket), then the designated buffer is sent to the 2474 implied remote socket. Users who make use of OPEN with an 2475 unspecified remote socket can make use of SEND without ever 2476 explicitly knowing the remote socket address. 2478 However, if a SEND is attempted before the remote socket 2479 becomes specified, an error will be returned. Users can use 2480 the STATUS call to determine the status of the connection. 2481 Some TCP implementations may notify the user when an 2482 unspecified socket is bound. 2484 If a timeout is specified, the current user timeout for this 2485 connection is changed to the new one. 2487 In the simplest implementation, SEND would not return control 2488 to the sending process until either the transmission was 2489 complete or the timeout had been exceeded. However, this 2490 simple method is both subject to deadlocks (for example, both 2491 sides of the connection might try to do SENDs before doing any 2492 RECEIVEs) and offers poor performance, so it is not 2493 recommended. A more sophisticated implementation would return 2494 immediately to allow the process to run concurrently with 2495 network I/O, and, furthermore, to allow multiple SENDs to be in 2496 progress. Multiple SENDs are served in first come, first 2497 served order, so the TCP endpoint will queue those it cannot 2498 service immediately. 2500 We have implicitly assumed an asynchronous user interface in 2501 which a SEND later elicits some kind of SIGNAL or pseudo- 2502 interrupt from the serving TCP endpoint. An alternative is to 2503 return a response immediately. For instance, SENDs might 2504 return immediate local acknowledgment, even if the segment sent 2505 had not been acknowledged by the distant TCP endpoint. We 2506 could optimistically assume eventual success. If we are wrong, 2507 the connection will close anyway due to the timeout. In 2508 implementations of this kind (synchronous), there will still be 2509 some asynchronous signals, but these will deal with the 2510 connection itself, and not with specific segments or buffers. 2512 In order for the process to distinguish among error or success 2513 indications for different SENDs, it might be appropriate for 2514 the buffer address to be returned along with the coded response 2515 to the SEND request. TCP-to-user signals are discussed below, 2516 indicating the information that should be returned to the 2517 calling process. 2519 Receive 2521 Format: RECEIVE (local connection name, buffer address, byte 2522 count) -> byte count, urgent flag, push flag (optional) 2524 This command allocates a receiving buffer associated with the 2525 specified connection. If no OPEN precedes this command or the 2526 calling process is not authorized to use this connection, an 2527 error is returned. 2529 In the simplest implementation, control would not return to the 2530 calling program until either the buffer was filled, or some 2531 error occurred, but this scheme is highly subject to deadlocks. 2532 A more sophisticated implementation would permit several 2533 RECEIVEs to be outstanding at once. These would be filled as 2534 segments arrive. This strategy permits increased throughput at 2535 the cost of a more elaborate scheme (possibly asynchronous) to 2536 notify the calling program that a PUSH has been seen or a 2537 buffer filled. 2539 A TCP receiver MAY pass a received PSH flag to the application 2540 layer via the PUSH flag in the interface (MAY-17), but it is 2541 not required (this was clarified in RFC 1122 section 4.2.2.2). 2542 The remainder of text describing the RECEIVE call below assumes 2543 that passing the PUSH indication is supported. 2545 If enough data arrive to fill the buffer before a PUSH is seen, 2546 the PUSH flag will not be set in the response to the RECEIVE. 2547 The buffer will be filled with as much data as it can hold. If 2548 a PUSH is seen before the buffer is filled the buffer will be 2549 returned partially filled and PUSH indicated. 2551 If there is urgent data the user will have been informed as 2552 soon as it arrived via a TCP-to-user signal. The receiving 2553 user should thus be in "urgent mode". If the URGENT flag is 2554 on, additional urgent data remains. If the URGENT flag is off, 2555 this call to RECEIVE has returned all the urgent data, and the 2556 user may now leave "urgent mode". Note that data following the 2557 urgent pointer (non-urgent data) cannot be delivered to the 2558 user in the same buffer with preceding urgent data unless the 2559 boundary is clearly marked for the user. 2561 To distinguish among several outstanding RECEIVEs and to take 2562 care of the case that a buffer is not completely filled, the 2563 return code is accompanied by both a buffer pointer and a byte 2564 count indicating the actual length of the data received. 2566 Alternative implementations of RECEIVE might have the TCP 2567 endpoint allocate buffer storage, or the TCP endpoint might 2568 share a ring buffer with the user. 2570 Close 2572 Format: CLOSE (local connection name) 2574 This command causes the connection specified to be closed. If 2575 the connection is not open or the calling process is not 2576 authorized to use this connection, an error is returned. 2577 Closing connections is intended to be a graceful operation in 2578 the sense that outstanding SENDs will be transmitted (and 2579 retransmitted), as flow control permits, until all have been 2580 serviced. Thus, it should be acceptable to make several SEND 2581 calls, followed by a CLOSE, and expect all the data to be sent 2582 to the destination. It should also be clear that users should 2583 continue to RECEIVE on CLOSING connections, since the remote 2584 peer may be trying to transmit the last of its data. Thus, 2585 CLOSE means "I have no more to send" but does not mean "I will 2586 not receive any more." It may happen (if the user level 2587 protocol is not well thought out) that the closing side is 2588 unable to get rid of all its data before timing out. In this 2589 event, CLOSE turns into ABORT, and the closing TCP peer gives 2590 up. 2592 The user may CLOSE the connection at any time on their own 2593 initiative, or in response to various prompts from the TCP 2594 implementation (e.g., remote close executed, transmission 2595 timeout exceeded, destination inaccessible). 2597 Because closing a connection requires communication with the 2598 remote TCP peer, connections may remain in the closing state 2599 for a short time. Attempts to reopen the connection before the 2600 TCP peer replies to the CLOSE command will result in error 2601 responses. 2603 Close also implies push function. 2605 Status 2607 Format: STATUS (local connection name) -> status data 2609 This is an implementation dependent user command and could be 2610 excluded without adverse effect. Information returned would 2611 typically come from the TCB associated with the connection. 2613 This command returns a data block containing the following 2614 information: 2616 local socket, 2617 remote socket, 2618 local connection name, 2619 receive window, 2620 send window, 2621 connection state, 2622 number of buffers awaiting acknowledgment, 2623 number of buffers pending receipt, 2624 urgent state, 2625 DiffServ field value, 2626 security/compartment, 2627 and transmission timeout. 2629 Depending on the state of the connection, or on the 2630 implementation itself, some of this information may not be 2631 available or meaningful. If the calling process is not 2632 authorized to use this connection, an error is returned. This 2633 prevents unauthorized processes from gaining information about 2634 a connection. 2636 Abort 2638 Format: ABORT (local connection name) 2639 This command causes all pending SENDs and RECEIVES to be 2640 aborted, the TCB to be removed, and a special RESET message to 2641 be sent to the remote TCP peer of the connection. Depending on 2642 the implementation, users may receive abort indications for 2643 each outstanding SEND or RECEIVE, or may simply receive an 2644 ABORT-acknowledgment. 2646 Flush 2648 Some TCP implementations have included a FLUSH call, which will 2649 empty the TCP send queue of any data that the user has issued 2650 SEND calls but is still to the right of the current send 2651 window. That is, it flushes as much queued send data as 2652 possible without losing sequence number synchronization. The 2653 FLUSH call MAY be implemented (MAY-14). 2655 Asynchronous Reports 2657 There MUST be a mechanism for reporting soft TCP error 2658 conditions to the application (MUST-47). Generically, we 2659 assume this takes the form of an application-supplied 2660 ERROR_REPORT routine that may be upcalled asynchronously from 2661 the transport layer: 2663 ERROR_REPORT(local connection name, reason, subreason) 2665 The precise encoding of the reason and subreason parameters is 2666 not specified here. However, the conditions that are reported 2667 asynchronously to the application MUST include: 2669 * ICMP error message arrived (see Section 3.9.2.2 for 2670 description of handling each ICMP message type, since some 2671 message types need to be suppressed from generating reports 2672 to the application) 2674 * Excessive retransmissions (see Section 3.8.3) 2676 * Urgent pointer advance (see Section 3.8.5) 2678 However, an application program that does not want to receive 2679 such ERROR_REPORT calls SHOULD be able to effectively disable 2680 these calls (SHLD-20). 2682 Set Differentiated Services Field (IPv4 TOS or IPv6 Traffic Class) 2684 The application layer MUST be able to specify the 2685 Differentiated Services field for segments that are sent on a 2686 connection (MUST-48). The Differentiated Services field 2687 includes the 6-bit Differentiated Services Code Point (DSCP) 2688 value. It is not required, but the application SHOULD be able 2689 to change the Differentiated Services field during the 2690 connection lifetime (SHLD-21). TCP implementations SHOULD pass 2691 the current Differentiated Services field value without change 2692 to the IP layer, when it sends segments on the connection 2693 (SHLD-22). 2695 The Differentiated Services field will be specified 2696 independently in each direction on the connection, so that the 2697 receiver application will specify the Differentiated Services 2698 field used for ACK segments. 2700 TCP implementations MAY pass the most recently received 2701 Differentiated Services field up to the application (MAY-9). 2703 3.9.2. TCP/Lower-Level Interface 2705 The TCP endpoint calls on a lower level protocol module to actually 2706 send and receive information over a network. The two current 2707 standard Internet Protocol (IP) versions layered below TCP are IPv4 2708 [1] and IPv6 [13]. 2710 If the lower level protocol is IPv4 it provides arguments for a type 2711 of service (used within the Differentiated Services field) and for a 2712 time to live. TCP uses the following settings for these parameters: 2714 DiffServ field: The IP header value for the DiffServ field is 2715 given by the user. This includes the bits of the DiffServ Code 2716 Point (DSCP). 2718 Time to Live (TTL): The TTL value used to send TCP segments MUST 2719 be configurable (MUST-49). 2721 Note that RFC 793 specified one minute (60 seconds) as a 2722 constant for the TTL, because the assumed maximum segment 2723 lifetime was two minutes. This was intended to explicitly ask 2724 that a segment be destroyed if it cannot be delivered by the 2725 internet system within one minute. RFC 1122 changed this 2726 specification to require that the TTL be configurable. 2728 Note that the DiffServ field is permitted to change during a 2729 connection (Section 4.2.4.2 of RFC 1122). However, the 2730 application interface might not support this ability, and the 2731 application does not have knowledge about individual TCP 2732 segments, so this can only be done on a coarse granularity, at 2733 best. This limitation is further discussed in RFC 7657 (sec 2734 5.1, 5.3, and 6) [49]. Generally, an application SHOULD NOT 2735 change the DiffServ field value during the course of a 2736 connection (SHLD-23). 2738 Any lower level protocol will have to provide the source address, 2739 destination address, and protocol fields, and some way to determine 2740 the "TCP length", both to provide the functional equivalent service 2741 of IP and to be used in the TCP checksum. 2743 When received options are passed up to TCP from the IP layer, TCP 2744 implementations MUST ignore options that it does not understand 2745 (MUST-50). 2747 A TCP implementation MAY support the Time Stamp (MAY-10) and Record 2748 Route (MAY-11) options. 2750 3.9.2.1. Source Routing 2752 If the lower level is IP (or other protocol that provides this 2753 feature) and source routing is used, the interface must allow the 2754 route information to be communicated. This is especially important 2755 so that the source and destination addresses used in the TCP checksum 2756 be the originating source and ultimate destination. It is also 2757 important to preserve the return route to answer connection requests. 2759 An application MUST be able to specify a source route when it 2760 actively opens a TCP connection (MUST-51), and this MUST take 2761 precedence over a source route received in a datagram (MUST-52). 2763 When a TCP connection is OPENed passively and a packet arrives with a 2764 completed IP Source Route option (containing a return route), TCP 2765 implementations MUST save the return route and use it for all 2766 segments sent on this connection (MUST-53). If a different source 2767 route arrives in a later segment, the later definition SHOULD 2768 override the earlier one (SHLD-24). 2770 3.9.2.2. ICMP Messages 2772 TCP implementations MUST act on an ICMP error message passed up from 2773 the IP layer, directing it to the connection that created the error 2774 (MUST-54). The necessary demultiplexing information can be found in 2775 the IP header contained within the ICMP message. 2777 This applies to ICMPv6 in addition to IPv4 ICMP. 2779 [33] contains discussion of specific ICMP and ICMPv6 messages 2780 classified as either "soft" or "hard" errors that may bear different 2781 responses. Treatment for classes of ICMP messages is described 2782 below: 2784 Source Quench 2785 TCP implementations MUST silently discard any received ICMP Source 2786 Quench messages (MUST-55). See [11] for discussion. 2788 Soft Errors 2789 For ICMP these include: Destination Unreachable -- codes 0, 1, 5, 2790 Time Exceeded -- codes 0, 1, and Parameter Problem. 2791 For ICMPv6 these include: Destination Unreachable -- codes 0 and 3, 2792 Time Exceeded -- codes 0, 1, and Parameter Problem -- codes 0, 1, 2793 2. 2794 Since these Unreachable messages indicate soft error conditions, 2795 TCP implementations MUST NOT abort the connection (MUST-56), and it 2796 SHOULD make the information available to the application (SHLD-25). 2798 Hard Errors 2799 For ICMP these include Destination Unreachable -- codes 2-4. 2800 These are hard error conditions, so TCP implementations SHOULD 2801 abort the connection (SHLD-26). [33] notes that some 2802 implementations do not abort connections when an ICMP hard error is 2803 received for a connection that is in any of the synchronized 2804 states. 2806 Note that [33] section 4 describes widespread implementation behavior 2807 that treats soft errors as hard errors during connection 2808 establishment. 2810 3.9.2.3. Source Address Validation 2812 RFC 1122 requires addresses to be validated in incoming SYN packets: 2814 An incoming SYN with an invalid source address MUST be ignored 2815 either by TCP or by the IP layer (MUST-63) (Section 3.2.1.3 of 2816 [18]). 2818 A TCP implementation MUST silently discard an incoming SYN segment 2819 that is addressed to a broadcast or multicast address (MUST-57). 2821 This prevents connection state and replies from being erroneously 2822 generated, and implementers should note that this guidance is 2823 applicable to all incoming segments, not just SYNs, as specifically 2824 indicated in RFC 1122. 2826 3.10. Event Processing 2828 The processing depicted in this section is an example of one possible 2829 implementation. Other implementations may have slightly different 2830 processing sequences, but they should differ from those in this 2831 section only in detail, not in substance. 2833 The activity of the TCP endpoint can be characterized as responding 2834 to events. The events that occur can be cast into three categories: 2835 user calls, arriving segments, and timeouts. This section describes 2836 the processing the TCP endpoint does in response to each of the 2837 events. In many cases the processing required depends on the state 2838 of the connection. 2840 Events that occur: 2842 User Calls 2844 OPEN 2845 SEND 2846 RECEIVE 2847 CLOSE 2848 ABORT 2849 STATUS 2851 Arriving Segments 2853 SEGMENT ARRIVES 2855 Timeouts 2857 USER TIMEOUT 2858 RETRANSMISSION TIMEOUT 2859 TIME-WAIT TIMEOUT 2861 The model of the TCP/user interface is that user commands receive an 2862 immediate return and possibly a delayed response via an event or 2863 pseudo interrupt. In the following descriptions, the term "signal" 2864 means cause a delayed response. 2866 Error responses in this document are identified by character strings. 2867 For example, user commands referencing connections that do not exist 2868 receive "error: connection not open". 2870 Please note in the following that all arithmetic on sequence numbers, 2871 acknowledgment numbers, windows, et cetera, is modulo 2**32 the size 2872 of the sequence number space. Also note that "=<" means less than or 2873 equal to (modulo 2**32). 2875 A natural way to think about processing incoming segments is to 2876 imagine that they are first tested for proper sequence number (i.e., 2877 that their contents lie in the range of the expected "receive window" 2878 in the sequence number space) and then that they are generally queued 2879 and processed in sequence number order. 2881 When a segment overlaps other already received segments we 2882 reconstruct the segment to contain just the new data, and adjust the 2883 header fields to be consistent. 2885 Note that if no state change is mentioned the TCP connection stays in 2886 the same state. 2888 3.10.1. OPEN Call 2890 CLOSED STATE (i.e., TCB does not exist) 2892 Create a new transmission control block (TCB) to hold 2893 connection state information. Fill in local socket identifier, 2894 remote socket, DiffServ field, security/compartment, and user 2895 timeout information. Note that some parts of the remote socket 2896 may be unspecified in a passive OPEN and are to be filled in by 2897 the parameters of the incoming SYN segment. Verify the 2898 security and DiffServ value requested are allowed for this 2899 user, if not return "error: precedence not allowed" or "error: 2900 security/compartment not allowed." If passive enter the LISTEN 2901 state and return. If active and the remote socket is 2902 unspecified, return "error: remote socket unspecified"; if 2903 active and the remote socket is specified, issue a SYN segment. 2904 An initial send sequence number (ISS) is selected. A SYN 2905 segment of the form is sent. Set SND.UNA to 2906 ISS, SND.NXT to ISS+1, enter SYN-SENT state, and return. 2908 If the caller does not have access to the local socket 2909 specified, return "error: connection illegal for this process". 2910 If there is no room to create a new connection, return "error: 2911 insufficient resources". 2913 LISTEN STATE 2915 If the OPEN call is active and the remote socket is specified, 2916 then change the connection from passive to active, select an 2917 ISS. Send a SYN segment, set SND.UNA to ISS, SND.NXT to ISS+1. 2918 Enter SYN-SENT state. Data associated with SEND may be sent 2919 with SYN segment or queued for transmission after entering 2920 ESTABLISHED state. The urgent bit if requested in the command 2921 must be sent with the data segments sent as a result of this 2922 command. If there is no room to queue the request, respond 2923 with "error: insufficient resources". If Foreign socket was 2924 not specified, then return "error: remote socket unspecified". 2926 SYN-SENT STATE 2927 SYN-RECEIVED STATE 2928 ESTABLISHED STATE 2929 FIN-WAIT-1 STATE 2930 FIN-WAIT-2 STATE 2931 CLOSE-WAIT STATE 2932 CLOSING STATE 2933 LAST-ACK STATE 2934 TIME-WAIT STATE 2936 Return "error: connection already exists". 2938 3.10.2. SEND Call 2940 CLOSED STATE (i.e., TCB does not exist) 2942 If the user does not have access to such a connection, then 2943 return "error: connection illegal for this process". 2945 Otherwise, return "error: connection does not exist". 2947 LISTEN STATE 2949 If the remote socket is specified, then change the connection 2950 from passive to active, select an ISS. Send a SYN segment, set 2951 SND.UNA to ISS, SND.NXT to ISS+1. Enter SYN-SENT state. Data 2952 associated with SEND may be sent with SYN segment or queued for 2953 transmission after entering ESTABLISHED state. The urgent bit 2954 if requested in the command must be sent with the data segments 2955 sent as a result of this command. If there is no room to queue 2956 the request, respond with "error: insufficient resources". If 2957 Foreign socket was not specified, then return "error: remote 2958 socket unspecified". 2960 SYN-SENT STATE 2961 SYN-RECEIVED STATE 2963 Queue the data for transmission after entering ESTABLISHED 2964 state. If no space to queue, respond with "error: insufficient 2965 resources". 2967 ESTABLISHED STATE 2968 CLOSE-WAIT STATE 2970 Segmentize the buffer and send it with a piggybacked 2971 acknowledgment (acknowledgment value = RCV.NXT). If there is 2972 insufficient space to remember this buffer, simply return 2973 "error: insufficient resources". 2975 If the urgent flag is set, then SND.UP <- SND.NXT and set the 2976 urgent pointer in the outgoing segments. 2978 FIN-WAIT-1 STATE 2979 FIN-WAIT-2 STATE 2980 CLOSING STATE 2981 LAST-ACK STATE 2982 TIME-WAIT STATE 2984 Return "error: connection closing" and do not service request. 2986 3.10.3. RECEIVE Call 2988 CLOSED STATE (i.e., TCB does not exist) 2990 If the user does not have access to such a connection, return 2991 "error: connection illegal for this process". 2993 Otherwise return "error: connection does not exist". 2995 LISTEN STATE 2996 SYN-SENT STATE 2997 SYN-RECEIVED STATE 2999 Queue for processing after entering ESTABLISHED state. If 3000 there is no room to queue this request, respond with "error: 3001 insufficient resources". 3003 ESTABLISHED STATE 3004 FIN-WAIT-1 STATE 3005 FIN-WAIT-2 STATE 3007 If insufficient incoming segments are queued to satisfy the 3008 request, queue the request. If there is no queue space to 3009 remember the RECEIVE, respond with "error: insufficient 3010 resources". 3012 Reassemble queued incoming segments into receive buffer and 3013 return to user. Mark "push seen" (PUSH) if this is the case. 3015 If RCV.UP is in advance of the data currently being passed to 3016 the user notify the user of the presence of urgent data. 3018 When the TCP endpoint takes responsibility for delivering data 3019 to the user that fact must be communicated to the sender via an 3020 acknowledgment. The formation of such an acknowledgment is 3021 described below in the discussion of processing an incoming 3022 segment. 3024 CLOSE-WAIT STATE 3026 Since the remote side has already sent FIN, RECEIVEs must be 3027 satisfied by data already on hand, but not yet delivered to the 3028 user. If no text is awaiting delivery, the RECEIVE will get a 3029 "error: connection closing" response. Otherwise, any remaining 3030 text can be used to satisfy the RECEIVE. 3032 CLOSING STATE 3033 LAST-ACK STATE 3034 TIME-WAIT STATE 3036 Return "error: connection closing". 3038 3.10.4. CLOSE Call 3040 CLOSED STATE (i.e., TCB does not exist) 3042 If the user does not have access to such a connection, return 3043 "error: connection illegal for this process". 3045 Otherwise, return "error: connection does not exist". 3047 LISTEN STATE 3049 Any outstanding RECEIVEs are returned with "error: closing" 3050 responses. Delete TCB, enter CLOSED state, and return. 3052 SYN-SENT STATE 3054 Delete the TCB and return "error: closing" responses to any 3055 queued SENDs, or RECEIVEs. 3057 SYN-RECEIVED STATE 3059 If no SENDs have been issued and there is no pending data to 3060 send, then form a FIN segment and send it, and enter FIN-WAIT-1 3061 state; otherwise queue for processing after entering 3062 ESTABLISHED state. 3064 ESTABLISHED STATE 3066 Queue this until all preceding SENDs have been segmentized, 3067 then form a FIN segment and send it. In any case, enter FIN- 3068 WAIT-1 state. 3070 FIN-WAIT-1 STATE 3071 FIN-WAIT-2 STATE 3072 Strictly speaking, this is an error and should receive a 3073 "error: connection closing" response. An "ok" response would 3074 be acceptable, too, as long as a second FIN is not emitted (the 3075 first FIN may be retransmitted though). 3077 CLOSE-WAIT STATE 3079 Queue this request until all preceding SENDs have been 3080 segmentized; then send a FIN segment, enter LAST-ACK state. 3082 CLOSING STATE 3083 LAST-ACK STATE 3084 TIME-WAIT STATE 3086 Respond with "error: connection closing". 3088 3.10.5. ABORT Call 3090 CLOSED STATE (i.e., TCB does not exist) 3092 If the user should not have access to such a connection, return 3093 "error: connection illegal for this process". 3095 Otherwise return "error: connection does not exist". 3097 LISTEN STATE 3099 Any outstanding RECEIVEs should be returned with "error: 3100 connection reset" responses. Delete TCB, enter CLOSED state, 3101 and return. 3103 SYN-SENT STATE 3105 All queued SENDs and RECEIVEs should be given "connection 3106 reset" notification, delete the TCB, enter CLOSED state, and 3107 return. 3109 SYN-RECEIVED STATE 3110 ESTABLISHED STATE 3111 FIN-WAIT-1 STATE 3112 FIN-WAIT-2 STATE 3113 CLOSE-WAIT STATE 3115 Send a reset segment: 3117 3119 All queued SENDs and RECEIVEs should be given "connection 3120 reset" notification; all segments queued for transmission 3121 (except for the RST formed above) or retransmission should be 3122 flushed, delete the TCB, enter CLOSED state, and return. 3124 CLOSING STATE LAST-ACK STATE TIME-WAIT STATE 3126 Respond with "ok" and delete the TCB, enter CLOSED state, and 3127 return. 3129 3.10.6. STATUS Call 3131 CLOSED STATE (i.e., TCB does not exist) 3133 If the user should not have access to such a connection, return 3134 "error: connection illegal for this process". 3136 Otherwise return "error: connection does not exist". 3138 LISTEN STATE 3140 Return "state = LISTEN", and the TCB pointer. 3142 SYN-SENT STATE 3144 Return "state = SYN-SENT", and the TCB pointer. 3146 SYN-RECEIVED STATE 3148 Return "state = SYN-RECEIVED", and the TCB pointer. 3150 ESTABLISHED STATE 3152 Return "state = ESTABLISHED", and the TCB pointer. 3154 FIN-WAIT-1 STATE 3156 Return "state = FIN-WAIT-1", and the TCB pointer. 3158 FIN-WAIT-2 STATE 3160 Return "state = FIN-WAIT-2", and the TCB pointer. 3162 CLOSE-WAIT STATE 3164 Return "state = CLOSE-WAIT", and the TCB pointer. 3166 CLOSING STATE 3167 Return "state = CLOSING", and the TCB pointer. 3169 LAST-ACK STATE 3171 Return "state = LAST-ACK", and the TCB pointer. 3173 TIME-WAIT STATE 3175 Return "state = TIME-WAIT", and the TCB pointer. 3177 3.10.7. SEGMENT ARRIVES 3179 3.10.7.1. CLOSED State 3181 If the state is CLOSED (i.e., TCB does not exist) then 3183 all data in the incoming segment is discarded. An incoming 3184 segment containing a RST is discarded. An incoming segment not 3185 containing a RST causes a RST to be sent in response. The 3186 acknowledgment and sequence field values are selected to make the 3187 reset sequence acceptable to the TCP endpoint that sent the 3188 offending segment. 3190 If the ACK bit is off, sequence number zero is used, 3192 3194 If the ACK bit is on, 3196 3198 Return. 3200 3.10.7.2. LISTEN State 3202 If the state is LISTEN then 3204 first check for an RST 3206 An incoming RST segment could not be valid, since it could not 3207 have been sent in response to anything sent by this incarnation 3208 of the connection. An incoming RST should be ignored. Return. 3210 second check for an ACK 3212 Any acknowledgment is bad if it arrives on a connection still 3213 in the LISTEN state. An acceptable reset segment should be 3214 formed for any arriving ACK-bearing segment. The RST should be 3215 formatted as follows: 3217 3219 Return. 3221 third check for a SYN 3223 If the SYN bit is set, check the security. If the security/ 3224 compartment on the incoming segment does not exactly match the 3225 security/compartment in the TCB then send a reset and return. 3227 3229 Set RCV.NXT to SEG.SEQ+1, IRS is set to SEG.SEQ and any other 3230 control or text should be queued for processing later. ISS 3231 should be selected and a SYN segment sent of the form: 3233 3235 SND.NXT is set to ISS+1 and SND.UNA to ISS. The connection 3236 state should be changed to SYN-RECEIVED. Note that any other 3237 incoming control or data (combined with SYN) will be processed 3238 in the SYN-RECEIVED state, but processing of SYN and ACK should 3239 not be repeated. If the listen was not fully specified (i.e., 3240 the remote socket was not fully specified), then the 3241 unspecified fields should be filled in now. 3243 fourth other data or control 3245 This should not be reached. Drop the segment and return. Any 3246 other control or data-bearing segment (not containing SYN) must 3247 have an ACK and thus would have been discarded by the ACK 3248 processing in the second step, unless it was first discarded by 3249 RST checking in the first step. 3251 3.10.7.3. SYN-SENT State 3253 If the state is SYN-SENT then 3255 first check the ACK bit 3257 If the ACK bit is set 3259 If SEG.ACK =< ISS, or SEG.ACK > SND.NXT, send a reset 3260 (unless the RST bit is set, if so drop the segment and 3261 return) 3262 3264 and discard the segment. Return. 3266 If SND.UNA < SEG.ACK =< SND.NXT then the ACK is acceptable. 3267 Some deployed TCP code has used the check SEG.ACK == SND.NXT 3268 (using "==" rather than "=<", but this is not appropriate 3269 when the stack is capable of sending data on the SYN, 3270 because the TCP peer may not accept and acknowledge all of 3271 the data on the SYN. 3273 second check the RST bit 3275 If the RST bit is set 3277 A potential blind reset attack is described in RFC 5961 3278 [37]. The mitigation described in that document has 3279 specific applicability explained therein, and is not a 3280 substitute for cryptographic protection (e.g. IPsec or TCP- 3281 AO). A TCP implementation that supports the RFC 5961 3282 mitigation SHOULD first check that the sequence number 3283 exactly matches RCV.NXT prior to executing the action in the 3284 next paragraph. 3286 If the ACK was acceptable then signal the user "error: 3287 connection reset", drop the segment, enter CLOSED state, 3288 delete TCB, and return. Otherwise (no ACK) drop the segment 3289 and return. 3291 third check the security 3293 If the security/compartment in the segment does not exactly 3294 match the security/compartment in the TCB, send a reset 3296 If there is an ACK 3298 3300 Otherwise 3302 3304 If a reset was sent, discard the segment and return. 3306 fourth check the SYN bit 3308 This step should be reached only if the ACK is ok, or there is 3309 no ACK, and the segment did not contain a RST. 3311 If the SYN bit is on and the security/compartment is acceptable 3312 then, RCV.NXT is set to SEG.SEQ+1, IRS is set to SEG.SEQ. 3313 SND.UNA should be advanced to equal SEG.ACK (if there is an 3314 ACK), and any segments on the retransmission queue that are 3315 thereby acknowledged should be removed. 3317 If SND.UNA > ISS (our SYN has been ACKed), change the 3318 connection state to ESTABLISHED, form an ACK segment 3320 3322 and send it. Data or controls that were queued for 3323 transmission MAY be included. Some TCP implementations 3324 suppress sending this segment when the received segment 3325 contains data that will anyways generate an acknowledgement in 3326 the later processing steps, saving this extra acknowledgement 3327 of the SYN from being sent. If there are other controls or 3328 text in the segment then continue processing at the sixth step 3329 under Section 3.10.7.4 where the URG bit is checked, otherwise 3330 return. 3332 Otherwise enter SYN-RECEIVED, form a SYN,ACK segment 3334 3336 and send it. Set the variables: 3338 SND.WND <- SEG.WND 3339 SND.WL1 <- SEG.SEQ 3340 SND.WL2 <- SEG.ACK 3342 If there are other controls or text in the segment, queue them 3343 for processing after the ESTABLISHED state has been reached, 3344 return. 3346 Note that it is legal to send and receive application data on 3347 SYN segments (this is the "text in the segment" mentioned 3348 above. There has been significant misinformation and 3349 misunderstanding of this topic historically. Some firewalls 3350 and security devices consider this suspicious. However, the 3351 capability was used in T/TCP [20] and is used in TCP Fast Open 3352 (TFO) [47], so is important for implementations and network 3353 devices to permit. 3355 fifth, if neither of the SYN or RST bits is set then drop the 3356 segment and return. 3358 3.10.7.4. Other States 3360 Otherwise, 3362 first check sequence number 3364 SYN-RECEIVED STATE 3365 ESTABLISHED STATE 3366 FIN-WAIT-1 STATE 3367 FIN-WAIT-2 STATE 3368 CLOSE-WAIT STATE 3369 CLOSING STATE 3370 LAST-ACK STATE 3371 TIME-WAIT STATE 3373 Segments are processed in sequence. Initial tests on 3374 arrival are used to discard old duplicates, but further 3375 processing is done in SEG.SEQ order. If a segment's 3376 contents straddle the boundary between old and new, only the 3377 new parts should be processed. 3379 In general, the processing of received segments MUST be 3380 implemented to aggregate ACK segments whenever possible 3381 (MUST-58). For example, if the TCP endpoint is processing a 3382 series of queued segments, it MUST process them all before 3383 sending any ACK segments (MUST-59). 3385 There are four cases for the acceptability test for an 3386 incoming segment: 3388 Segment Receive Test 3389 Length Window 3390 ------- ------- ------------------------------------------- 3392 0 0 SEG.SEQ = RCV.NXT 3394 0 >0 RCV.NXT =< SEG.SEQ < RCV.NXT+RCV.WND 3396 >0 0 not acceptable 3398 >0 >0 RCV.NXT =< SEG.SEQ < RCV.NXT+RCV.WND 3399 or RCV.NXT =< SEG.SEQ+SEG.LEN-1 < RCV.NXT+RCV.WND 3401 In implementing sequence number validation as described 3402 here, please note Appendix A.2. 3404 If the RCV.WND is zero, no segments will be acceptable, but 3405 special allowance should be made to accept valid ACKs, URGs 3406 and RSTs. 3408 If an incoming segment is not acceptable, an acknowledgment 3409 should be sent in reply (unless the RST bit is set, if so 3410 drop the segment and return): 3412 3414 After sending the acknowledgment, drop the unacceptable 3415 segment and return. 3417 Note that for the TIME-WAIT state, there is an improved 3418 algorithm described in [39] for handling incoming SYN 3419 segments, that utilizes timestamps rather than relying on 3420 the sequence number check described here. When the improved 3421 algorithm is implemented, the logic above is not applicable 3422 for incoming SYN segments with timestamp options, received 3423 on a connection in the TIME-WAIT state. 3425 In the following it is assumed that the segment is the 3426 idealized segment that begins at RCV.NXT and does not exceed 3427 the window. One could tailor actual segments to fit this 3428 assumption by trimming off any portions that lie outside the 3429 window (including SYN and FIN), and only processing further 3430 if the segment then begins at RCV.NXT. Segments with higher 3431 beginning sequence numbers SHOULD be held for later 3432 processing (SHLD-31). 3434 second check the RST bit, 3436 RFC 5961 [37] section 3 describes a potential blind reset 3437 attack and optional mitigation approach. This does not 3438 provide a cryptographic protection (e.g. as in IPsec or TCP- 3439 AO), but can be applicable in situations described in RFC 3440 5961. For stacks implementing the RFC 5961 protection, the 3441 three checks below apply, otherwise processing for these 3442 states is indicated further below. 3444 1) If the RST bit is set and the sequence number is 3445 outside the current receive window, silently drop the 3446 segment. 3448 2) If the RST bit is set and the sequence number exactly 3449 matches the next expected sequence number (RCV.NXT), then 3450 TCP endpoints MUST reset the connection in the manner 3451 prescribed below according to the connection state. 3453 3) If the RST bit is set and the sequence number does not 3454 exactly match the next expected sequence value, yet is 3455 within the current receive window, TCP endpoints MUST 3456 send an acknowledgement (challenge ACK): 3458 3460 After sending the challenge ACK, TCP endpoints MUST drop 3461 the unacceptable segment and stop processing the incoming 3462 packet further. Note that RFC 5961 and Errata ID 4772 3463 contain additional considerations for ACK throttling in 3464 an implementation. 3466 SYN-RECEIVED STATE 3468 If the RST bit is set 3470 If this connection was initiated with a passive OPEN 3471 (i.e., came from the LISTEN state), then return this 3472 connection to LISTEN state and return. The user need 3473 not be informed. If this connection was initiated 3474 with an active OPEN (i.e., came from SYN-SENT state) 3475 then the connection was refused, signal the user 3476 "connection refused". In either case, all segments on 3477 the retransmission queue should be removed. And in 3478 the active OPEN case, enter the CLOSED state and 3479 delete the TCB, and return. 3481 ESTABLISHED 3482 FIN-WAIT-1 3483 FIN-WAIT-2 3484 CLOSE-WAIT 3486 If the RST bit is set then, any outstanding RECEIVEs and 3487 SEND should receive "reset" responses. All segment 3488 queues should be flushed. Users should also receive an 3489 unsolicited general "connection reset" signal. Enter the 3490 CLOSED state, delete the TCB, and return. 3492 CLOSING STATE 3493 LAST-ACK STATE 3494 TIME-WAIT 3496 If the RST bit is set then, enter the CLOSED state, 3497 delete the TCB, and return. 3499 third check security 3500 SYN-RECEIVED 3502 If the security/compartment in the segment does not 3503 exactly match the security/compartment in the TCB then 3504 send a reset, and return. 3506 ESTABLISHED 3507 FIN-WAIT-1 3508 FIN-WAIT-2 3509 CLOSE-WAIT 3510 CLOSING 3511 LAST-ACK 3512 TIME-WAIT 3514 If the security/compartment in the segment does not 3515 exactly match the security/compartment in the TCB then 3516 send a reset, any outstanding RECEIVEs and SEND should 3517 receive "reset" responses. All segment queues should be 3518 flushed. Users should also receive an unsolicited 3519 general "connection reset" signal. Enter the CLOSED 3520 state, delete the TCB, and return. 3522 Note this check is placed following the sequence check to 3523 prevent a segment from an old connection between these port 3524 numbers with a different security from causing an abort of 3525 the current connection. 3527 fourth, check the SYN bit, 3529 SYN-RECEIVED 3531 If the connection was initiated with a passive OPEN, then 3532 return this connection to the LISTEN state and return. 3533 Otherwise, handle per the directions for synchronized 3534 states below. 3536 ESTABLISHED STATE 3537 FIN-WAIT STATE-1 3538 FIN-WAIT STATE-2 3539 CLOSE-WAIT STATE 3540 CLOSING STATE 3541 LAST-ACK STATE 3542 TIME-WAIT STATE 3544 If the SYN bit is set in these synchronized states, it 3545 may be either a legitimate new connection attempt (e.g. 3546 in the case of TIME-WAIT), an error where the connection 3547 should be reset, or the result of an attack attempt, as 3548 described in RFC 5961 [37]. For the TIME-WAIT state, new 3549 connections can be accepted if the timestamp option is 3550 used and meets expectations (per [39]). For all other 3551 cases, RFC 5961 provides a mitigation with applicability 3552 to some situations, though there are also alternatives 3553 that offer cryptographic protection (see Section 7). RFC 3554 5961 recommends that in these synchronized states, if the 3555 SYN bit is set, irrespective of the sequence number, TCP 3556 endpoints MUST send a "challenge ACK" to the remote peer: 3558 3560 After sending the acknowledgement, TCP implementations 3561 MUST drop the unacceptable segment and stop processing 3562 further. Note that RFC 5961 and Errata ID 4772 contain 3563 additional ACK throttling notes for an implementation. 3565 For implementations that do not follow RFC 5961, the 3566 original RFC 793 behavior follows in this paragraph. If 3567 the SYN is in the window it is an error, send a reset, 3568 any outstanding RECEIVEs and SEND should receive "reset" 3569 responses, all segment queues should be flushed, the user 3570 should also receive an unsolicited general "connection 3571 reset" signal, enter the CLOSED state, delete the TCB, 3572 and return. 3574 If the SYN is not in the window this step would not be 3575 reached and an ACK would have been sent in the first step 3576 (sequence number check). 3578 fifth check the ACK field, 3580 if the ACK bit is off drop the segment and return 3582 if the ACK bit is on 3584 RFC 5961 [37] section 5 describes a potential blind data 3585 injection attack, and mitigation that implementations MAY 3586 choose to include (MAY-12). TCP stacks that implement 3587 RFC 5961 MUST add an input check that the ACK value is 3588 acceptable only if it is in the range of ((SND.UNA - 3589 MAX.SND.WND) =< SEG.ACK =< SND.NXT). All incoming 3590 segments whose ACK value doesn't satisfy the above 3591 condition MUST be discarded and an ACK sent back. The 3592 new state variable MAX.SND.WND is defined as the largest 3593 window that the local sender has ever received from its 3594 peer (subject to window scaling) or may be hard-coded to 3595 a maximum permissible window value. When the ACK value 3596 is acceptable, the processing per-state below applies: 3598 SYN-RECEIVED STATE 3600 If SND.UNA < SEG.ACK =< SND.NXT then enter ESTABLISHED 3601 state and continue processing with variables below set 3602 to: 3604 SND.WND <- SEG.WND 3605 SND.WL1 <- SEG.SEQ 3606 SND.WL2 <- SEG.ACK 3608 If the segment acknowledgment is not acceptable, form 3609 a reset segment, 3611 3613 and send it. 3615 ESTABLISHED STATE 3617 If SND.UNA < SEG.ACK =< SND.NXT then, set SND.UNA <- 3618 SEG.ACK. Any segments on the retransmission queue 3619 that are thereby entirely acknowledged are removed. 3620 Users should receive positive acknowledgments for 3621 buffers that have been SENT and fully acknowledged 3622 (i.e., SEND buffer should be returned with "ok" 3623 response). If the ACK is a duplicate (SEG.ACK =< 3624 SND.UNA), it can be ignored. If the ACK acks 3625 something not yet sent (SEG.ACK > SND.NXT) then send 3626 an ACK, drop the segment, and return. 3628 If SND.UNA =< SEG.ACK =< SND.NXT, the send window 3629 should be updated. If (SND.WL1 < SEG.SEQ or (SND.WL1 3630 = SEG.SEQ and SND.WL2 =< SEG.ACK)), set SND.WND <- 3631 SEG.WND, set SND.WL1 <- SEG.SEQ, and set SND.WL2 <- 3632 SEG.ACK. 3634 Note that SND.WND is an offset from SND.UNA, that 3635 SND.WL1 records the sequence number of the last 3636 segment used to update SND.WND, and that SND.WL2 3637 records the acknowledgment number of the last segment 3638 used to update SND.WND. The check here prevents using 3639 old segments to update the window. 3641 FIN-WAIT-1 STATE 3642 In addition to the processing for the ESTABLISHED 3643 state, if the FIN segment is now acknowledged then 3644 enter FIN-WAIT-2 and continue processing in that 3645 state. 3647 FIN-WAIT-2 STATE 3649 In addition to the processing for the ESTABLISHED 3650 state, if the retransmission queue is empty, the 3651 user's CLOSE can be acknowledged ("ok") but do not 3652 delete the TCB. 3654 CLOSE-WAIT STATE 3656 Do the same processing as for the ESTABLISHED state. 3658 CLOSING STATE 3660 In addition to the processing for the ESTABLISHED 3661 state, if the ACK acknowledges our FIN then enter the 3662 TIME-WAIT state, otherwise ignore the segment. 3664 LAST-ACK STATE 3666 The only thing that can arrive in this state is an 3667 acknowledgment of our FIN. If our FIN is now 3668 acknowledged, delete the TCB, enter the CLOSED state, 3669 and return. 3671 TIME-WAIT STATE 3673 The only thing that can arrive in this state is a 3674 retransmission of the remote FIN. Acknowledge it, and 3675 restart the 2 MSL timeout. 3677 sixth, check the URG bit, 3679 ESTABLISHED STATE 3680 FIN-WAIT-1 STATE 3681 FIN-WAIT-2 STATE 3683 If the URG bit is set, RCV.UP <- max(RCV.UP,SEG.UP), and 3684 signal the user that the remote side has urgent data if 3685 the urgent pointer (RCV.UP) is in advance of the data 3686 consumed. If the user has already been signaled (or is 3687 still in the "urgent mode") for this continuous sequence 3688 of urgent data, do not signal the user again. 3690 CLOSE-WAIT STATE 3691 CLOSING STATE 3692 LAST-ACK STATE 3693 TIME-WAIT 3695 This should not occur, since a FIN has been received from 3696 the remote side. Ignore the URG. 3698 seventh, process the segment text, 3700 ESTABLISHED STATE 3701 FIN-WAIT-1 STATE 3702 FIN-WAIT-2 STATE 3704 Once in the ESTABLISHED state, it is possible to deliver 3705 segment text to user RECEIVE buffers. Text from segments 3706 can be moved into buffers until either the buffer is full 3707 or the segment is empty. If the segment empties and 3708 carries a PUSH flag, then the user is informed, when the 3709 buffer is returned, that a PUSH has been received. 3711 When the TCP endpoint takes responsibility for delivering 3712 the data to the user it must also acknowledge the receipt 3713 of the data. 3715 Once the TCP endpoint takes responsibility for the data 3716 it advances RCV.NXT over the data accepted, and adjusts 3717 RCV.WND as appropriate to the current buffer 3718 availability. The total of RCV.NXT and RCV.WND should 3719 not be reduced. 3721 A TCP implementation MAY send an ACK segment 3722 acknowledging RCV.NXT when a valid segment arrives that 3723 is in the window but not at the left window edge (MAY- 3724 13). 3726 Please note the window management suggestions in 3727 Section 3.8. 3729 Send an acknowledgment of the form: 3731 3733 This acknowledgment should be piggybacked on a segment 3734 being transmitted if possible without incurring undue 3735 delay. 3737 CLOSE-WAIT STATE 3738 CLOSING STATE 3739 LAST-ACK STATE 3740 TIME-WAIT STATE 3742 This should not occur, since a FIN has been received from 3743 the remote side. Ignore the segment text. 3745 eighth, check the FIN bit, 3747 Do not process the FIN if the state is CLOSED, LISTEN or 3748 SYN-SENT since the SEG.SEQ cannot be validated; drop the 3749 segment and return. 3751 If the FIN bit is set, signal the user "connection closing" 3752 and return any pending RECEIVEs with same message, advance 3753 RCV.NXT over the FIN, and send an acknowledgment for the 3754 FIN. Note that FIN implies PUSH for any segment text not 3755 yet delivered to the user. 3757 SYN-RECEIVED STATE 3758 ESTABLISHED STATE 3760 Enter the CLOSE-WAIT state. 3762 FIN-WAIT-1 STATE 3764 If our FIN has been ACKed (perhaps in this segment), 3765 then enter TIME-WAIT, start the time-wait timer, turn 3766 off the other timers; otherwise enter the CLOSING 3767 state. 3769 FIN-WAIT-2 STATE 3771 Enter the TIME-WAIT state. Start the time-wait timer, 3772 turn off the other timers. 3774 CLOSE-WAIT STATE 3776 Remain in the CLOSE-WAIT state. 3778 CLOSING STATE 3780 Remain in the CLOSING state. 3782 LAST-ACK STATE 3784 Remain in the LAST-ACK state. 3786 TIME-WAIT STATE 3788 Remain in the TIME-WAIT state. Restart the 2 MSL 3789 time-wait timeout. 3791 and return. 3793 3.10.8. Timeouts 3795 USER TIMEOUT 3797 For any state if the user timeout expires, flush all queues, 3798 signal the user "error: connection aborted due to user timeout" 3799 in general and for any outstanding calls, delete the TCB, enter 3800 the CLOSED state and return. 3802 RETRANSMISSION TIMEOUT 3804 For any state if the retransmission timeout expires on a 3805 segment in the retransmission queue, send the segment at the 3806 front of the retransmission queue again, reinitialize the 3807 retransmission timer, and return. 3809 TIME-WAIT TIMEOUT 3811 If the time-wait timeout expires on a connection delete the 3812 TCB, enter the CLOSED state and return. 3814 4. Glossary 3816 ACK 3817 A control bit (acknowledge) occupying no sequence space, 3818 which indicates that the acknowledgment field of this segment 3819 specifies the next sequence number the sender of this segment 3820 is expecting to receive, hence acknowledging receipt of all 3821 previous sequence numbers. 3823 connection 3824 A logical communication path identified by a pair of sockets. 3826 datagram 3827 A message sent in a packet switched computer communications 3828 network. 3830 Destination Address 3831 The network layer address of the remote endpoint. 3833 FIN 3834 A control bit (finis) occupying one sequence number, which 3835 indicates that the sender will send no more data or control 3836 occupying sequence space. 3838 fragment 3839 A portion of a logical unit of data, in particular an 3840 internet fragment is a portion of an internet datagram. 3842 header 3843 Control information at the beginning of a message, segment, 3844 fragment, packet or block of data. 3846 host 3847 A computer. In particular a source or destination of 3848 messages from the point of view of the communication network. 3850 Identification 3851 An Internet Protocol field. This identifying value assigned 3852 by the sender aids in assembling the fragments of a datagram. 3854 internet address 3855 A network layer address. 3857 internet datagram 3858 The unit of data exchanged between an internet module and the 3859 higher level protocol together with the internet header. 3861 internet fragment 3862 A portion of the data of an internet datagram with an 3863 internet header. 3865 IP 3866 Internet Protocol. See [1] and [13]. 3868 IRS 3869 The Initial Receive Sequence number. The first sequence 3870 number used by the sender on a connection. 3872 ISN 3873 The Initial Sequence Number. The first sequence number used 3874 on a connection, (either ISS or IRS). Selected in a way that 3875 is unique within a given period of time and is unpredictable 3876 to attackers. 3878 ISS 3879 The Initial Send Sequence number. The first sequence number 3880 used by the sender on a connection. 3882 left sequence 3883 This is the next sequence number to be acknowledged by the 3884 data receiving TCP endpoint (or the lowest currently 3885 unacknowledged sequence number) and is sometimes referred to 3886 as the left edge of the send window. 3888 module 3889 An implementation, usually in software, of a protocol or 3890 other procedure. 3892 MSL 3893 Maximum Segment Lifetime, the time a TCP segment can exist in 3894 the internetwork system. Arbitrarily defined to be 2 3895 minutes. 3897 octet 3898 An eight bit byte. 3900 Options 3901 An Option field may contain several options, and each option 3902 may be several octets in length. 3904 packet 3905 A package of data with a header that may or may not be 3906 logically complete. More often a physical packaging than a 3907 logical packaging of data. 3909 port 3910 The portion of a connection identifier used for 3911 demultiplexing connections at an endpoint. 3913 process 3914 A program in execution. A source or destination of data from 3915 the point of view of the TCP endpoint or other host-to-host 3916 protocol. 3918 PUSH 3919 A control bit occupying no sequence space, indicating that 3920 this segment contains data that must be pushed through to the 3921 receiving user. 3923 RCV.NXT 3924 receive next sequence number 3926 RCV.UP 3927 receive urgent pointer 3929 RCV.WND 3930 receive window 3932 receive next sequence number 3933 This is the next sequence number the local TCP endpoint is 3934 expecting to receive. 3936 receive window 3937 This represents the sequence numbers the local (receiving) 3938 TCP endpoint is willing to receive. Thus, the local TCP 3939 endpoint considers that segments overlapping the range 3940 RCV.NXT to RCV.NXT + RCV.WND - 1 carry acceptable data or 3941 control. Segments containing sequence numbers entirely 3942 outside of this range are considered duplicates and 3943 discarded. 3945 RST 3946 A control bit (reset), occupying no sequence space, 3947 indicating that the receiver should delete the connection 3948 without further interaction. The receiver can determine, 3949 based on the sequence number and acknowledgment fields of the 3950 incoming segment, whether it should honor the reset command 3951 or ignore it. In no case does receipt of a segment 3952 containing RST give rise to a RST in response. 3954 SEG.ACK 3955 segment acknowledgment 3957 SEG.LEN 3958 segment length 3960 SEG.SEQ 3961 segment sequence 3963 SEG.UP 3964 segment urgent pointer field 3966 SEG.WND 3967 segment window field 3969 segment 3970 A logical unit of data, in particular a TCP segment is the 3971 unit of data transferred between a pair of TCP modules. 3973 segment acknowledgment 3974 The sequence number in the acknowledgment field of the 3975 arriving segment. 3977 segment length 3978 The amount of sequence number space occupied by a segment, 3979 including any controls that occupy sequence space. 3981 segment sequence 3982 The number in the sequence field of the arriving segment. 3984 send sequence 3985 This is the next sequence number the local (sending) TCP 3986 endpoint will use on the connection. It is initially 3987 selected from an initial sequence number curve (ISN) and is 3988 incremented for each octet of data or sequenced control 3989 transmitted. 3991 send window 3992 This represents the sequence numbers that the remote 3993 (receiving) TCP endpoint is willing to receive. It is the 3994 value of the window field specified in segments from the 3995 remote (data receiving) TCP endpoint. The range of new 3996 sequence numbers that may be emitted by a TCP implementation 3997 lies between SND.NXT and SND.UNA + SND.WND - 1. 3998 (Retransmissions of sequence numbers between SND.UNA and 3999 SND.NXT are expected, of course.) 4001 SND.NXT 4002 send sequence 4004 SND.UNA 4005 left sequence 4007 SND.UP 4008 send urgent pointer 4010 SND.WL1 4011 segment sequence number at last window update 4013 SND.WL2 4014 segment acknowledgment number at last window update 4016 SND.WND 4017 send window 4019 socket (or socket number, or socket address, or socket identifier) 4020 An address that specifically includes a port identifier, that 4021 is, the concatenation of an Internet Address with a TCP port. 4023 Source Address 4024 The network layer address of the sending endpoint. 4026 SYN 4027 A control bit in the incoming segment, occupying one sequence 4028 number, used at the initiation of a connection, to indicate 4029 where the sequence numbering will start. 4031 TCB 4032 Transmission control block, the data structure that records 4033 the state of a connection. 4035 TCP 4036 Transmission Control Protocol: A host-to-host protocol for 4037 reliable communication in internetwork environments. 4039 TOS 4040 Type of Service, an obsoleted IPv4 field. The same header 4041 bits currently are used for the Differentiated Services field 4042 [4] containing the Differentiated Services Code Point (DSCP) 4043 value and the 2-bit ECN codepoint [7]. 4045 Type of Service 4046 See "TOS". 4048 URG 4049 A control bit (urgent), occupying no sequence space, used to 4050 indicate that the receiving user should be notified to do 4051 urgent processing as long as there is data to be consumed 4052 with sequence numbers less than the value indicated in the 4053 urgent pointer. 4055 urgent pointer 4056 A control field meaningful only when the URG bit is on. This 4057 field communicates the value of the urgent pointer that 4058 indicates the data octet associated with the sending user's 4059 urgent call. 4061 5. Changes from RFC 793 4063 This document obsoletes RFC 793 as well as RFC 6093 and 6528, which 4064 updated 793. In all cases, only the normative protocol specification 4065 and requirements have been incorporated into this document, and some 4066 informational text with background and rationale may not have been 4067 carried in. The informational content of those documents is still 4068 valuable in learning about and understanding TCP, and they are valid 4069 Informational references, even though their normative content has 4070 been incorporated into this document. 4072 The main body of this document was adapted from RFC 793's Section 3, 4073 titled "FUNCTIONAL SPECIFICATION", with an attempt to keep formatting 4074 and layout as close as possible. 4076 The collection of applicable RFC Errata that have been reported and 4077 either accepted or held for an update to RFC 793 were incorporated 4078 (Errata IDs: 573, 574, 700, 701, 1283, 1561, 1562, 1564, 1565, 1571, 4079 1572, 2296, 2297, 2298, 2748, 2749, 2934, 3213, 3300, 3301, 6222). 4080 Some errata were not applicable due to other changes (Errata IDs: 4081 572, 575, 1569, 3305, 3602). 4083 Changes to the specification of the Urgent Pointer described in RFC 4084 1122 and 6093 were incorporated. See RFC 6093 for detailed 4085 discussion of why these changes were necessary. 4087 The discussion of the RTO from RFC 793 was updated to refer to RFC 4088 6298. The RFC 1122 text on the RTO originally replaced the 793 text, 4089 however, RFC 2988 should have updated 1122, and has subsequently been 4090 obsoleted by 6298. 4092 RFC 1122 contains a collection of other changes and clarifications to 4093 RFC 793. The normative items impacting the protocol have been 4094 incorporated here, though some historically useful implementation 4095 advice and informative discussion from RFC 1122 is not included here. 4097 RFC 1122 contains more than just TCP requirements, so this document 4098 can't obsolete RFC 1122 entirely. It is only marked as "updating" 4099 1122, however, it should be understood to effectively obsolete all of 4100 the RFC 1122 material on TCP. 4102 The more secure Initial Sequence Number generation algorithm from RFC 4103 6528 was incorporated. See RFC 6528 for discussion of the attacks 4104 that this mitigates, as well as advice on selecting PRF algorithms 4105 and managing secret key data. 4107 A note based on RFC 6429 was added to explicitly clarify that system 4108 resource management concerns allow connection resources to be 4109 reclaimed. RFC 6429 is obsoleted in the sense that this 4110 clarification has been reflected in this update to the base TCP 4111 specification now. 4113 The description of congestion control implementation was added, based 4114 on the set of documents that are IETF BCP or Standards Track on the 4115 topic, and the current state of common implementations. 4117 RFC EDITOR'S NOTE: the content below is for detailed change tracking 4118 and planning, and not to be included with the final revision of the 4119 document. 4121 This document started as draft-eddy-rfc793bis-00, that was merely a 4122 proposal and rough plan for updating RFC 793. 4124 The -01 revision of this draft-eddy-rfc793bis incorporates the 4125 content of RFC 793 Section 3 titled "FUNCTIONAL SPECIFICATION". 4126 Other content from RFC 793 has not been incorporated. The -01 4127 revision of this document makes some minor formatting changes to the 4128 RFC 793 content in order to convert the content into XML2RFC format 4129 and account for left-out parts of RFC 793. For instance, figure 4130 numbering differs and some indentation is not exactly the same. 4132 The -02 revision of draft-eddy-rfc793bis incorporates errata that 4133 have been verified: 4135 Errata ID 573: Reported by Bob Braden (note: This errata basically 4136 is just a reminder that RFC 1122 updates 793. Some of the 4137 associated changes are left pending to a separate revision that 4138 incorporates 1122. Bob's mention of PUSH in 793 section 2.8 was 4139 not applicable here because that section was not part of the 4140 "functional specification". Also the 1122 text on the 4141 retransmission timeout also has been updated by subsequent RFCs, 4142 so the change here deviates from Bob's suggestion to apply the 4143 1122 text.) 4144 Errata ID 574: Reported by Yin Shuming 4145 Errata ID 700: Reported by Yin Shuming 4146 Errata ID 701: Reported by Yin Shuming 4147 Errata ID 1283: Reported by Pei-chun Cheng 4148 Errata ID 1561: Reported by Constantin Hagemeier 4149 Errata ID 1562: Reported by Constantin Hagemeier 4150 Errata ID 1564: Reported by Constantin Hagemeier 4151 Errata ID 1565: Reported by Constantin Hagemeier 4152 Errata ID 1571: Reported by Constantin Hagemeier 4153 Errata ID 1572: Reported by Constantin Hagemeier 4154 Errata ID 2296: Reported by Vishwas Manral 4155 Errata ID 2297: Reported by Vishwas Manral 4156 Errata ID 2298: Reported by Vishwas Manral 4157 Errata ID 2748: Reported by Mykyta Yevstifeyev 4158 Errata ID 2749: Reported by Mykyta Yevstifeyev 4159 Errata ID 2934: Reported by Constantin Hagemeier 4160 Errata ID 3213: Reported by EugnJun Yi 4161 Errata ID 3300: Reported by Botong Huang 4162 Errata ID 3301: Reported by Botong Huang 4163 Errata ID 3305: Reported by Botong Huang 4164 Note: Some verified errata were not used in this update, as they 4165 relate to sections of RFC 793 elided from this document. These 4166 include Errata ID 572, 575, and 1569. 4167 Note: Errata ID 3602 was not applied in this revision as it is 4168 duplicative of the 1122 corrections. 4170 Not related to RFC 793 content, this revision also makes small tweaks 4171 to the introductory text, fixes indentation of the pseudo header 4172 diagram, and notes that the Security Considerations should also 4173 include privacy, when this section is written. 4175 The -03 revision of draft-eddy-rfc793bis revises all discussion of 4176 the urgent pointer in order to comply with RFC 6093, 1122, and 1011. 4177 Since 1122 held requirements on the urgent pointer, the full list of 4178 requirements was brought into an appendix of this document, so that 4179 it can be updated as-needed. 4181 The -04 revision of draft-eddy-rfc793bis includes the ISN generation 4182 changes from RFC 6528. 4184 The -05 revision of draft-eddy-rfc793bis incorporates MSS 4185 requirements and definitions from RFC 879, 1122, and 6691, as well as 4186 option-handling requirements from RFC 1122. 4188 The -00 revision of draft-ietf-tcpm-rfc793bis incorporates several 4189 additional clarifications and updates to the section on segmentation, 4190 many of which are based on feedback from Joe Touch improving from the 4191 initial text on this in the previous revision. 4193 The -01 revision incorporates the change to Reserved bits due to ECN, 4194 as well as many other changes that come from RFC 1122. 4196 The -02 revision has small formatting modifications in order to 4197 address xml2rfc warnings about long lines. It was a quick update to 4198 avoid document expiration. TCPM working group discussion in 2015 4199 also indicated that that we should not try to add sections on 4200 implementation advice or similar non-normative information. 4202 The -03 revision incorporates more content from RFC 1122: Passive 4203 OPEN Calls, Time-To-Live, Multihoming, IP Options, ICMP messages, 4204 Data Communications, When to Send Data, When to Send a Window Update, 4205 Managing the Window, Probing Zero Windows, When to Send an ACK 4206 Segment. The section on data communications was re-organized into 4207 clearer subsections (previously headings were embedded in the 793 4208 text), and windows management advice from 793 was removed (as 4209 reviewed by TCPM working group) in favor of the 1122 additions on 4210 SWS, ZWP, and related topics. 4212 The -04 revision includes reference to RFC 6429 on the ZWP condition, 4213 RFC1122 material on TCP Connection Failures, TCP Keep-Alives, 4214 Acknowledging Queued Segments, and Remote Address Validation. RTO 4215 computation is referenced from RFC 6298 rather than RFC 1122. 4217 The -05 revision includes the requirement to implement TCP congestion 4218 control with recommendation to implement ECN, the RFC 6633 update to 4219 1122, which changed the requirement on responding to source quench 4220 ICMP messages, and discussion of ICMP (and ICMPv6) soft and hard 4221 errors per RFC 5461 (ICMPv6 handling for TCP doesn't seem to be 4222 mentioned elsewhere in standards track). 4224 The -06 revision includes an appendix on "Other Implementation Notes" 4225 to capture widely-deployed fundamental features that are not 4226 contained in the RFC series yet. It also added mention of RFC 6994 4227 and the IANA TCP parameters registry as a reference. It includes 4228 references to RFC 5961 in appropriate places. The references to TOS 4229 were changed to DiffServ field, based on reflecting RFC 2474 as well 4230 as the IPv6 presence of traffic class (carrying DiffServ field) 4231 rather than TOS. 4233 The -07 revision includes reference to RFC 6191, updated security 4234 considerations, discussion of additional implementation 4235 considerations, and clarification of data on the SYN. 4237 The -08 revision includes changes based on: 4239 describing treatment of reserved bits (following TCPM mailing list 4240 thread from July 2014 on "793bis item - reserved bit behavior" 4241 addition a brief TCP key concepts section to make up for not 4242 including the outdated section 2 of RFC 793 4243 changed "TCP" to "host" to resolve conflict between 1122 wording 4244 on whether TCP or the network layer chooses an address when 4245 multihomed 4246 fixed/updated definition of options in glossary 4247 moved note on aggregating ACKs from 1122 to a more appropriate 4248 location 4249 resolved notes on IP precedence and security/compartment 4250 added implementation note on sequence number validation 4251 added note that PUSH does not apply when Nagle is active 4252 added 1122 content on asynchronous reports to replace 793 section 4253 on TCP to user messages 4255 The -09 revision fixes section numbering problems. 4257 The -10 revision includes additions to the security considerations 4258 based on comments from Joe Touch, and suggested edits on RST/FIN 4259 notification, RFC 2525 reference, and other edits suggested by 4260 Yuchung Cheng, as well as modifications to DiffServ text from Yuchung 4261 Cheng and Gorry Fairhurst. 4263 The -11 revision includes a start at identifying all of the 4264 requirements text and referencing each instance in the common table 4265 at the end of the document. 4267 The -12 revision completes the requirement language indexing started 4268 in -11 and adds necessary description of the PUSH functionality that 4269 was missing. 4271 The -13 revision contains only changes in the inline editor notes. 4273 The -14 revision includes updates with regard to several comments 4274 from the mailing list, including editorial fixes, adding IANA 4275 considerations for the header flags, improving figure title 4276 placement, and breaking up the "Terminology" section into more 4277 appropriately titled subsections. 4279 The -15 revision has many technical and editorial corrections from 4280 Gorry Fairhurst's review, and subsequent discussion on the TCPM list, 4281 as well as some other collected clarifications and improvements from 4282 mailing list discussion. 4284 The -16 revision addresses several discussions that rose from 4285 additional reviews and follow-up on some of Gorry Fairhurst's 4286 comments from revision 14. 4288 The -17 revision includes errata 6222 from Charles Deng, update to 4289 the key words boilerplate, updated description of the header flags 4290 registry changes, and clarification about connections rather than 4291 users in the discussion of OPEN calls. 4293 The -18 revision includes editorial changes to the IANA 4294 considerations, based on comments from Richard Scheffenegger at the 4295 IETF 108 TCPM virtual meeting. 4297 The -19 revision includes editorial changes from Errata 6281 and 6282 4298 reported by Merlin Buge. It also includes WGLC changes noted by 4299 Mohamed Boucadair, Rahul Jadhav, Praveen Balasubramanian, Matt Olson, 4300 Yi Huang, Joe Touch, and Juhamatti Kuusisaari. 4302 The -20 revision includes text on congestion control based on mailing 4303 list and meeting discussion, put together in its final form by Markku 4304 Kojo. It also clarifies that SACK, WS, and TS options are 4305 recommended for high performance, but not needed for basic 4306 interoperability. It also clarifies that the length field is 4307 required for new TCP options. 4309 The -21 revision includes slight changes to the header diagram for 4310 compatibility with tooling, from Stephen McQuistin, clarification on 4311 the meaning of idle connections from Yuchung Cheng, Neal Cardwell, 4312 Michael Scharf, and Richard Scheffenegger, editorial improvements 4313 from Markku Kojo, notes that some stacks suppress extra 4314 acknowledgments of the SYN when SYN-ACK carries data from Richard 4315 Scheffenegger, and adds MAY-18 numbering based on note from Jonathan 4316 Morton. 4318 The -22 revision includes small clarifications on terminology (might 4319 versus may) and IPv6 extension headers versus IPv4 options, based on 4320 comments from Gorry Fairhurst. 4322 The -23 revision has a fix to indentation from Michael Tuexen and 4323 idnits issues addressed from Michael Scharf. 4325 The -24 revision incorporates changes after Martin Duke's AD review, 4326 including further feedback on those comments from Yuchung Cheng and 4327 Joe Touch. Important changes for review include (1) removal of the 4328 need to check for the PUSH flag when evaluating the SWS override 4329 timer expiration, (2) clarification about receding urgent pointer, 4330 and (3) de-duplicating handling of the RST checking between step 4 4331 and step 1. 4333 Some other suggested changes that will not be incorporated in this 4334 793 update unless TCPM consensus changes with regard to scope are: 4336 1. Tony Sabatini's suggestion for describing DO field 4337 2. Per discussion with Joe Touch (TAPS list, 6/20/2015), the 4338 description of the API could be revisited 4339 3. Reducing the R2 value for SYNs has been suggested as a possible 4340 topic for future consideration. 4342 Early in the process of updating RFC 793, Scott Brim mentioned that 4343 this should include a PERPASS/privacy review. This may be something 4344 for the chairs or AD to request during WGLC or IETF LC. 4346 6. IANA Considerations 4348 In the "Transmission Control Protocol (TCP) Header Flags" registry, 4349 IANA is asked to make several changes described in this section. 4351 RFC 3168 originally created this registry, but only populated it with 4352 the new bits defined in RFC 3168, neglecting the other bits that had 4353 previously been described in RFC 793 and other documents. Bit 7 has 4354 since also been updated by RFC 8311. 4356 The "Bit" column is renamed below as the "Bit Offset" column, since 4357 it references each header flag's offset within the 16-bit aligned 4358 view of the TCP header in Figure 1. The bits in offsets 0 through 4 4359 are the TCP segment Data Offset field, and not header flags. 4361 IANA should add a column for "Assignment Notes". 4363 IANA should assign values indicated below. 4365 TCP Header Flags 4367 Bit Name Reference Assignment Notes 4368 Offset 4369 --- ---- --------- ---------------- 4370 4 Reserved for future use (this document) 4371 5 Reserved for future use (this document) 4372 6 Reserved for future use (this document) 4373 7 Reserved for future use [RFC8311] Previously used by Historic [RFC3540] as NS (Nonce Sum) 4374 8 CWR (Congestion Window Reduced) [RFC3168] 4375 9 ECE (ECN-Echo) [RFC3168] 4376 10 Urgent Pointer field is significant (URG) (this document) 4377 11 Acknowledgment field is significant (ACK) (this document) 4378 12 Push Function (PSH) (this document) 4379 13 Reset the connection (RST) (this document) 4380 14 Synchronize sequence numbers (SYN) (this document) 4381 15 No more data from sender (FIN) (this document) 4383 This TCP Header Flags registry should also be moved to a sub-registry 4384 under the global "Transmission Control Protocol (TCP) Parameters 4385 registry (https://www.iana.org/assignments/tcp-parameters/tcp- 4386 parameters.xhtml). 4388 The registry's Registration Procedure should remain Standards Action, 4389 but the Reference can be updated to this document, and the Note 4390 removed. 4392 7. Security and Privacy Considerations 4394 The TCP design includes only rudimentary security features that 4395 improve the robustness and reliability of connections and application 4396 data transfer, but there are no built-in cryptographic capabilities 4397 to support any form of privacy, authentication, or other typical 4398 security functions. Non-cryptographic enhancements (e.g. [37]) have 4399 been developed to improve robustness of TCP connections to particular 4400 types of attacks, but the applicability and protections of non- 4401 cryptographic enhancements are limited (e.g. see section 1.1 of 4402 [37]). Applications typically utilize lower-layer (e.g. IPsec) and 4403 upper-layer (e.g. TLS) protocols to provide security and privacy for 4404 TCP connections and application data carried in TCP. Methods based 4405 on TCP options have been developed as well, to support some security 4406 capabilities. 4408 In order to fully protect TCP connections (including their control 4409 flags) IPsec or the TCP Authentication Option (TCP-AO) [36] are the 4410 only current effective methods. Other methods discussed in this 4411 section may protect the payload, but either only a subset of the 4412 fields (e.g. tcpcrypt [54]) or none at all (e.g. TLS). Other 4413 security features that have been added to TCP (e.g. ISN generation, 4414 sequence number checks, and others) are only capable of partially 4415 hindering attacks. 4417 Applications using long-lived TCP flows have been vulnerable to 4418 attacks that exploit the processing of control flags described in 4419 earlier TCP specifications [31]. TCP-MD5 was a commonly implemented 4420 TCP option to support authentication for some of these connections, 4421 but had flaws and is now deprecated. TCP-AO provides a capability to 4422 protect long-lived TCP connections from attacks, and has superior 4423 properties to TCP-MD5. It does not provide any privacy for 4424 application data, nor for the TCP headers. 4426 The "tcpcrypt" [54] Experimental extension to TCP provides the 4427 ability to cryptographically protect connection data. Metadata 4428 aspects of the TCP flow are still visible, but the application stream 4429 is well-protected. Within the TCP header, only the urgent pointer 4430 and FIN flag are protected through tcpcrypt. 4432 The TCP Roadmap [48] includes notes about several RFCs related to TCP 4433 security. Many of the enhancements provided by these RFCs have been 4434 integrated into the present document, including ISN generation, 4435 mitigating blind in-window attacks, and improving handling of soft 4436 errors and ICMP packets. These are all discussed in greater detail 4437 in the referenced RFCs that originally described the changes needed 4438 to earlier TCP specifications. Additionally, see RFC 6093 [38] for 4439 discussion of security considerations related to the urgent pointer 4440 field, that has been deprecated. 4442 Since TCP is often used for bulk transfer flows, some attacks are 4443 possible that abuse the TCP congestion control logic. An example is 4444 "ACK-division" attacks. Updates that have been made to the TCP 4445 congestion control specifications include mechanisms like Appropriate 4446 Byte Counting (ABC) [27] that act as mitigations to these attacks. 4448 Other attacks are focused on exhausting the resources of a TCP 4449 server. Examples include SYN flooding [30] or wasting resources on 4450 non-progressing connections [40]. Operating systems commonly 4451 implement mitigations for these attacks. Some common defenses also 4452 utilize proxies, stateful firewalls, and other technologies outside 4453 of the end-host TCP implementation. 4455 8. Acknowledgements 4457 This document is largely a revision of RFC 793, which Jon Postel was 4458 the editor of. Due to his excellent work, it was able to last for 4459 three decades before we felt the need to revise it. 4461 Andre Oppermann was a contributor and helped to edit the first 4462 revision of this document. 4464 We are thankful for the assistance of the IETF TCPM working group 4465 chairs, over the course of work on this document: 4467 Michael Scharf 4468 Yoshifumi Nishida 4469 Pasi Sarolahti 4470 Michael Tuexen 4472 During the discussions of this work on the TCPM mailing list and in 4473 working group meetings, helpful comments, critiques, and reviews were 4474 received from (listed alphabetically by last name): Praveen 4475 Balasubramanian, David Borman, Mohamed Boucadair, Bob Briscoe, Neal 4476 Cardwell, Yuchung Cheng, Martin Duke, Ted Faber, Gorry Fairhurst, 4477 Fernando Gont, Rodney Grimes, Yi Huang, Rahul Jadhav, Markku Kojo, 4478 Mike Kosek, Juhamatti Kuusisaari, Kevin Lahey, Kevin Mason, Matt 4479 Mathis, Stephen McQuistin, Jonathan Morton, Matt Olson, Tommy Pauly, 4480 Tom Petch, Hagen Paul Pfeifer, Anthony Sabatini, Michael Scharf, Greg 4481 Skinner, Joe Touch, Michael Tuexen, Reji Varghese, Tim Wicinski, 4482 Lloyd Wood, and Alex Zimmermann. 4484 Joe Touch provided additional help in clarifying the description of 4485 segment size parameters and PMTUD/PLPMTUD recommendations. Markku 4486 Kojo helped put together the text in the section on TCP Congestion 4487 Control. 4489 This document includes content from errata that were reported by 4490 (listed chronologically): Yin Shuming, Bob Braden, Morris M. Keesan, 4491 Pei-chun Cheng, Constantin Hagemeier, Vishwas Manral, Mykyta 4492 Yevstifeyev, EungJun Yi, Botong Huang, Charles Deng, Merlin Buge. 4494 9. References 4495 9.1. Normative References 4497 [1] Postel, J., "Internet Protocol", STD 5, RFC 791, 4498 DOI 10.17487/RFC0791, September 1981, 4499 . 4501 [2] Mogul, J. and S. Deering, "Path MTU discovery", RFC 1191, 4502 DOI 10.17487/RFC1191, November 1990, 4503 . 4505 [3] Bradner, S., "Key words for use in RFCs to Indicate 4506 Requirement Levels", BCP 14, RFC 2119, 4507 DOI 10.17487/RFC2119, March 1997, 4508 . 4510 [4] Nichols, K., Blake, S., Baker, F., and D. Black, 4511 "Definition of the Differentiated Services Field (DS 4512 Field) in the IPv4 and IPv6 Headers", RFC 2474, 4513 DOI 10.17487/RFC2474, December 1998, 4514 . 4516 [5] Borman, D., Deering, S., and R. Hinden, "IPv6 Jumbograms", 4517 RFC 2675, DOI 10.17487/RFC2675, August 1999, 4518 . 4520 [6] Floyd, S., "Congestion Control Principles", BCP 41, 4521 RFC 2914, DOI 10.17487/RFC2914, September 2000, 4522 . 4524 [7] Ramakrishnan, K., Floyd, S., and D. Black, "The Addition 4525 of Explicit Congestion Notification (ECN) to IP", 4526 RFC 3168, DOI 10.17487/RFC3168, September 2001, 4527 . 4529 [8] Floyd, S. and M. Allman, "Specifying New Congestion 4530 Control Algorithms", BCP 133, RFC 5033, 4531 DOI 10.17487/RFC5033, August 2007, 4532 . 4534 [9] Allman, M., Paxson, V., and E. Blanton, "TCP Congestion 4535 Control", RFC 5681, DOI 10.17487/RFC5681, September 2009, 4536 . 4538 [10] Paxson, V., Allman, M., Chu, J., and M. Sargent, 4539 "Computing TCP's Retransmission Timer", RFC 6298, 4540 DOI 10.17487/RFC6298, June 2011, 4541 . 4543 [11] Gont, F., "Deprecation of ICMP Source Quench Messages", 4544 RFC 6633, DOI 10.17487/RFC6633, May 2012, 4545 . 4547 [12] Leiba, B., "Ambiguity of Uppercase vs Lowercase in RFC 4548 2119 Key Words", BCP 14, RFC 8174, DOI 10.17487/RFC8174, 4549 May 2017, . 4551 [13] Deering, S. and R. Hinden, "Internet Protocol, Version 6 4552 (IPv6) Specification", STD 86, RFC 8200, 4553 DOI 10.17487/RFC8200, July 2017, 4554 . 4556 [14] McCann, J., Deering, S., Mogul, J., and R. Hinden, Ed., 4557 "Path MTU Discovery for IP version 6", STD 87, RFC 8201, 4558 DOI 10.17487/RFC8201, July 2017, 4559 . 4561 [15] Allman, M., "Requirements for Time-Based Loss Detection", 4562 BCP 233, RFC 8961, DOI 10.17487/RFC8961, November 2020, 4563 . 4565 9.2. Informative References 4567 [16] Postel, J., "Transmission Control Protocol", STD 7, 4568 RFC 793, DOI 10.17487/RFC0793, September 1981, 4569 . 4571 [17] Nagle, J., "Congestion Control in IP/TCP Internetworks", 4572 RFC 896, DOI 10.17487/RFC0896, January 1984, 4573 . 4575 [18] Braden, R., Ed., "Requirements for Internet Hosts - 4576 Communication Layers", STD 3, RFC 1122, 4577 DOI 10.17487/RFC1122, October 1989, 4578 . 4580 [19] Almquist, P., "Type of Service in the Internet Protocol 4581 Suite", RFC 1349, DOI 10.17487/RFC1349, July 1992, 4582 . 4584 [20] Braden, R., "T/TCP -- TCP Extensions for Transactions 4585 Functional Specification", RFC 1644, DOI 10.17487/RFC1644, 4586 July 1994, . 4588 [21] Mathis, M., Mahdavi, J., Floyd, S., and A. Romanow, "TCP 4589 Selective Acknowledgment Options", RFC 2018, 4590 DOI 10.17487/RFC2018, October 1996, 4591 . 4593 [22] Paxson, V., Allman, M., Dawson, S., Fenner, W., Griner, 4594 J., Heavens, I., Lahey, K., Semke, J., and B. Volz, "Known 4595 TCP Implementation Problems", RFC 2525, 4596 DOI 10.17487/RFC2525, March 1999, 4597 . 4599 [23] Xiao, X., Hannan, A., Paxson, V., and E. Crabbe, "TCP 4600 Processing of the IPv4 Precedence Field", RFC 2873, 4601 DOI 10.17487/RFC2873, June 2000, 4602 . 4604 [24] Floyd, S., Mahdavi, J., Mathis, M., and M. Podolsky, "An 4605 Extension to the Selective Acknowledgement (SACK) Option 4606 for TCP", RFC 2883, DOI 10.17487/RFC2883, July 2000, 4607 . 4609 [25] Lahey, K., "TCP Problems with Path MTU Discovery", 4610 RFC 2923, DOI 10.17487/RFC2923, September 2000, 4611 . 4613 [26] Balakrishnan, H., Padmanabhan, V., Fairhurst, G., and M. 4614 Sooriyabandara, "TCP Performance Implications of Network 4615 Path Asymmetry", BCP 69, RFC 3449, DOI 10.17487/RFC3449, 4616 December 2002, . 4618 [27] Allman, M., "TCP Congestion Control with Appropriate Byte 4619 Counting (ABC)", RFC 3465, DOI 10.17487/RFC3465, February 4620 2003, . 4622 [28] Fenner, B., "Experimental Values In IPv4, IPv6, ICMPv4, 4623 ICMPv6, UDP, and TCP Headers", RFC 4727, 4624 DOI 10.17487/RFC4727, November 2006, 4625 . 4627 [29] Mathis, M. and J. Heffner, "Packetization Layer Path MTU 4628 Discovery", RFC 4821, DOI 10.17487/RFC4821, March 2007, 4629 . 4631 [30] Eddy, W., "TCP SYN Flooding Attacks and Common 4632 Mitigations", RFC 4987, DOI 10.17487/RFC4987, August 2007, 4633 . 4635 [31] Touch, J., "Defending TCP Against Spoofing Attacks", 4636 RFC 4953, DOI 10.17487/RFC4953, July 2007, 4637 . 4639 [32] Culley, P., Elzur, U., Recio, R., Bailey, S., and J. 4640 Carrier, "Marker PDU Aligned Framing for TCP 4641 Specification", RFC 5044, DOI 10.17487/RFC5044, October 4642 2007, . 4644 [33] Gont, F., "TCP's Reaction to Soft Errors", RFC 5461, 4645 DOI 10.17487/RFC5461, February 2009, 4646 . 4648 [34] StJohns, M., Atkinson, R., and G. Thomas, "Common 4649 Architecture Label IPv6 Security Option (CALIPSO)", 4650 RFC 5570, DOI 10.17487/RFC5570, July 2009, 4651 . 4653 [35] Sandlund, K., Pelletier, G., and L-E. Jonsson, "The RObust 4654 Header Compression (ROHC) Framework", RFC 5795, 4655 DOI 10.17487/RFC5795, March 2010, 4656 . 4658 [36] Touch, J., Mankin, A., and R. Bonica, "The TCP 4659 Authentication Option", RFC 5925, DOI 10.17487/RFC5925, 4660 June 2010, . 4662 [37] Ramaiah, A., Stewart, R., and M. Dalal, "Improving TCP's 4663 Robustness to Blind In-Window Attacks", RFC 5961, 4664 DOI 10.17487/RFC5961, August 2010, 4665 . 4667 [38] Gont, F. and A. Yourtchenko, "On the Implementation of the 4668 TCP Urgent Mechanism", RFC 6093, DOI 10.17487/RFC6093, 4669 January 2011, . 4671 [39] Gont, F., "Reducing the TIME-WAIT State Using TCP 4672 Timestamps", BCP 159, RFC 6191, DOI 10.17487/RFC6191, 4673 April 2011, . 4675 [40] Bashyam, M., Jethanandani, M., and A. Ramaiah, "TCP Sender 4676 Clarification for Persist Condition", RFC 6429, 4677 DOI 10.17487/RFC6429, December 2011, 4678 . 4680 [41] Gont, F. and S. Bellovin, "Defending against Sequence 4681 Number Attacks", RFC 6528, DOI 10.17487/RFC6528, February 4682 2012, . 4684 [42] Borman, D., "TCP Options and Maximum Segment Size (MSS)", 4685 RFC 6691, DOI 10.17487/RFC6691, July 2012, 4686 . 4688 [43] Touch, J., "Updated Specification of the IPv4 ID Field", 4689 RFC 6864, DOI 10.17487/RFC6864, February 2013, 4690 . 4692 [44] Touch, J., "Shared Use of Experimental TCP Options", 4693 RFC 6994, DOI 10.17487/RFC6994, August 2013, 4694 . 4696 [45] McPherson, D., Oran, D., Thaler, D., and E. Osterweil, 4697 "Architectural Considerations of IP Anycast", RFC 7094, 4698 DOI 10.17487/RFC7094, January 2014, 4699 . 4701 [46] Borman, D., Braden, B., Jacobson, V., and R. 4702 Scheffenegger, Ed., "TCP Extensions for High Performance", 4703 RFC 7323, DOI 10.17487/RFC7323, September 2014, 4704 . 4706 [47] Cheng, Y., Chu, J., Radhakrishnan, S., and A. Jain, "TCP 4707 Fast Open", RFC 7413, DOI 10.17487/RFC7413, December 2014, 4708 . 4710 [48] Duke, M., Braden, R., Eddy, W., Blanton, E., and A. 4711 Zimmermann, "A Roadmap for Transmission Control Protocol 4712 (TCP) Specification Documents", RFC 7414, 4713 DOI 10.17487/RFC7414, February 2015, 4714 . 4716 [49] Black, D., Ed. and P. Jones, "Differentiated Services 4717 (Diffserv) and Real-Time Communication", RFC 7657, 4718 DOI 10.17487/RFC7657, November 2015, 4719 . 4721 [50] Fairhurst, G. and M. Welzl, "The Benefits of Using 4722 Explicit Congestion Notification (ECN)", RFC 8087, 4723 DOI 10.17487/RFC8087, March 2017, 4724 . 4726 [51] Fairhurst, G., Ed., Trammell, B., Ed., and M. Kuehlewind, 4727 Ed., "Services Provided by IETF Transport Protocols and 4728 Congestion Control Mechanisms", RFC 8095, 4729 DOI 10.17487/RFC8095, March 2017, 4730 . 4732 [52] Welzl, M., Tuexen, M., and N. Khademi, "On the Usage of 4733 Transport Features Provided by IETF Transport Protocols", 4734 RFC 8303, DOI 10.17487/RFC8303, February 2018, 4735 . 4737 [53] Chown, T., Loughney, J., and T. Winters, "IPv6 Node 4738 Requirements", BCP 220, RFC 8504, DOI 10.17487/RFC8504, 4739 January 2019, . 4741 [54] Bittau, A., Giffin, D., Handley, M., Mazieres, D., Slack, 4742 Q., and E. Smith, "Cryptographic Protection of TCP Streams 4743 (tcpcrypt)", RFC 8548, DOI 10.17487/RFC8548, May 2019, 4744 . 4746 [55] Ford, A., Raiciu, C., Handley, M., Bonaventure, O., and C. 4747 Paasch, "TCP Extensions for Multipath Operation with 4748 Multiple Addresses", RFC 8684, DOI 10.17487/RFC8684, March 4749 2020, . 4751 [56] IANA, "Transmission Control Protocol (TCP) Parameters, 4752 https://www.iana.org/assignments/tcp-parameters/tcp- 4753 parameters.xhtml", 2019. 4755 [57] IANA, "Transmission Control Protocol (TCP) Header Flags, 4756 https://www.iana.org/assignments/tcp-header-flags/tcp- 4757 header-flags.xhtml", 2019. 4759 [58] Gont, F., "Processing of IP Security/Compartment and 4760 Precedence Information by TCP", draft-gont-tcpm-tcp- 4761 seccomp-prec-00 (work in progress), March 2012. 4763 [59] Gont, F. and D. Borman, "On the Validation of TCP Sequence 4764 Numbers", draft-gont-tcpm-tcp-seq-validation-04 (work in 4765 progress), March 2019. 4767 [60] Touch, J. and W. Eddy, "TCP Extended Data Offset Option", 4768 draft-ietf-tcpm-tcp-edo-10 (work in progress), July 2018. 4770 [61] McQuistin, S., Band, V., Jacob, D., and C. Perkins, 4771 "Describing Protocol Data Units with Augmented Packet 4772 Header Diagrams", draft-mcquistin-augmented-ascii- 4773 diagrams-08 (work in progress), May 2021. 4775 [62] Minshall, G., "A Proposed Modification to Nagle's 4776 Algorithm", draft-minshall-nagle-01 (work in progress), 4777 June 1999. 4779 [63] Dalal, Y. and C. Sunshine, "Connection Management in 4780 Transport Protocols", Computer Networks Vol. 2, No. 6, pp. 4781 454-473, December 1978. 4783 [64] Faber, T., Touch, J., and W. Yui, "The TIME-WAIT state in 4784 TCP and Its Effect on Busy Servers", Proceedings of IEEE 4785 INFOCOM pp. 1573-1583, March 1999. 4787 Appendix A. Other Implementation Notes 4789 This section includes additional notes and references on TCP 4790 implementation decisions that are currently not a part of the RFC 4791 series or included within the TCP standard. These items can be 4792 considered by implementers, but there was not yet a consensus to 4793 include them in the standard. 4795 A.1. IP Security Compartment and Precedence 4797 The IPv4 specification [1] includes a precedence value in the (now 4798 obsoleted) Type of Service field (TOS) field. It was modified in 4799 [19], and then obsoleted by the definition of Differentiated Services 4800 (DiffServ) [4]. Setting and conveying TOS between the network layer, 4801 TCP implementation, and applications is obsolete, and replaced by 4802 DiffServ in the current TCP specification. 4804 RFC 793 requires checking the IP security compartment and precedence 4805 on incoming TCP segments for consistency within a connection, and 4806 with application requests. Each of these aspects of IP have become 4807 outdated, without specific updates to RFC 793. The issues with 4808 precedence were fixed by [23], which is Standards Track, and so this 4809 present TCP specification includes those changes. However, the state 4810 of IP security options that may be used by MLS systems is not as 4811 clean. 4813 Resetting connections when incoming packets do not meet expected 4814 security compartment or precedence expectations has been recognized 4815 as a possible attack vector [58], and there has been discussion about 4816 amending the TCP specification to prevent connections from being 4817 aborted due to non-matching IP security compartment and DiffServ 4818 codepoint values. 4820 A.1.1. Precedence 4822 In DiffServ the former precedence values are treated as Class 4823 Selector codepoints, and methods for compatible treatment are 4824 described in the DiffServ architecture. The RFC 793/1122 TCP 4825 specification includes logic intending to have connections use the 4826 highest precedence requested by either endpoint application, and to 4827 keep the precedence consistent throughout a connection. This logic 4828 from the obsolete TOS is not applicable for DiffServ, and should not 4829 be included in TCP implementations, though changes to DiffServ values 4830 within a connection are discouraged. For discussion of this, see RFC 4831 7657 (sec 5.1, 5.3, and 6) [49]. 4833 The obsoleted TOS processing rules in TCP assumed bidirectional (or 4834 symmetric) precedence values used on a connection, but the DiffServ 4835 architecture is asymmetric. Problems with the old TCP logic in this 4836 regard were described in [23] and the solution described is to ignore 4837 IP precedence in TCP. Since RFC 2873 is a Standards Track document 4838 (although not marked as updating RFC 793), current implementations 4839 are expected to be robust to these conditions. Note that the 4840 DiffServ field value used in each direction is a part of the 4841 interface between TCP and the network layer, and values in use can be 4842 indicated both ways between TCP and the application. 4844 A.1.2. MLS Systems 4846 The IP security option (IPSO) and compartment defined in [1] was 4847 refined in RFC 1038 that was later obsoleted by RFC 1108. The 4848 Commercial IP Security Option (CIPSO) is defined in FIPS-188, and is 4849 supported by some vendors and operating systems. RFC 1108 is now 4850 Historic, though RFC 791 itself has not been updated to remove the IP 4851 security option. For IPv6, a similar option (CALIPSO) has been 4852 defined [34]. RFC 793 includes logic that includes the IP security/ 4853 compartment information in treatment of TCP segments. References to 4854 the IP "security/compartment" in this document may be relevant for 4855 Multi-Level Secure (MLS) system implementers, but can be ignored for 4856 non-MLS implementations, consistent with running code on the 4857 Internet. See Appendix A.1 for further discussion. Note that RFC 4858 5570 describes some MLS networking scenarios where IPSO, CIPSO, or 4859 CALIPSO may be used. In these special cases, TCP implementers should 4860 see section 7.3.1 of RFC 5570, and follow the guidance in that 4861 document. 4863 A.2. Sequence Number Validation 4865 There are cases where the TCP sequence number validation rules can 4866 prevent ACK fields from being processed. This can result in 4867 connection issues, as described in [59], which includes descriptions 4868 of potential problems in conditions of simultaneous open, self- 4869 connects, simultaneous close, and simultaneous window probes. The 4870 document also describes potential changes to the TCP specification to 4871 mitigate the issue by expanding the acceptable sequence numbers. 4873 In Internet usage of TCP, these conditions are rarely occurring. 4874 Common operating systems include different alternative mitigations, 4875 and the standard has not been updated yet to codify one of them, but 4876 implementers should consider the problems described in [59]. 4878 A.3. Nagle Modification 4880 In common operating systems, both the Nagle algorithm and delayed 4881 acknowledgements are implemented and enabled by default. TCP is used 4882 by many applications that have a request-response style of 4883 communication, where the combination of the Nagle algorithm and 4884 delayed acknowledgements can result in poor application performance. 4885 A modification to the Nagle algorithm is described in [62] that 4886 improves the situation for these applications. 4888 This modification is implemented in some common operating systems, 4889 and does not impact TCP interoperability. Additionally, many 4890 applications simply disable Nagle, since this is generally supported 4891 by a socket option. The TCP standard has not been updated to include 4892 this Nagle modification, but implementers may find it beneficial to 4893 consider. 4895 A.4. Low Water Mark Settings 4897 Some operating system kernel TCP implementations include socket 4898 options that allow specifying the number of bytes in the buffer until 4899 the socket layer will pass sent data to TCP (SO_SNDLOWAT) or to the 4900 application on receiving (SO_RCVLOWAT). 4902 In addition, another socket option (TCP_NOTSENT_LOWAT) can be used to 4903 control the amount of unsent bytes in the write queue. This can help 4904 a sending TCP application to avoid creating large amounts of buffered 4905 data (and corresponding latency). As an example, this may be useful 4906 for applications that are multiplexing data from multiple upper level 4907 streams onto a connection, especially when streams may be a mix of 4908 interactive / real-time and bulk data transfer. 4910 Appendix B. TCP Requirement Summary 4912 This section is adapted from RFC 1122. 4914 Note that there is no requirement related to PLPMTUD in this list, 4915 but that PLPMTUD is recommended. 4917 | | | | |S| | 4918 | | | | |H| |F 4919 | | | | |O|M|o 4920 | | |S| |U|U|o 4921 | | |H| |L|S|t 4922 | |M|O| |D|T|n 4923 | |U|U|M| | |o 4924 | |S|L|A|N|N|t 4925 | |T|D|Y|O|O|t 4926 FEATURE | ReqID | | | |T|T|e 4927 -------------------------------------------------|--------|-|-|-|-|-|-- 4928 | | | | | | | 4929 Push flag | | | | | | | 4930 Aggregate or queue un-pushed data | MAY-16 | | |x| | | 4931 Sender collapse successive PSH flags | SHLD-27| |x| | | | 4932 SEND call can specify PUSH | MAY-15 | | |x| | | 4933 If cannot: sender buffer indefinitely | MUST-60| | | | |x| 4934 If cannot: PSH last segment | MUST-61|x| | | | | 4935 Notify receiving ALP of PSH | MAY-17 | | |x| | |1 4936 Send max size segment when possible | SHLD-28| |x| | | | 4937 | | | | | | | 4938 Window | | | | | | | 4939 Treat as unsigned number | MUST-1 |x| | | | | 4940 Handle as 32-bit number | REC-1 | |x| | | | 4941 Shrink window from right | SHLD-14| | | |x| | 4942 - Send new data when window shrinks | SHLD-15| | | |x| | 4943 - Retransmit old unacked data within window | SHLD-16| |x| | | | 4944 - Time out conn for data past right edge | SHLD-17| | | |x| | 4945 Robust against shrinking window | MUST-34|x| | | | | 4946 Receiver's window closed indefinitely | MAY-8 | | |x| | | 4947 Use standard probing logic | MUST-35|x| | | | | 4948 Sender probe zero window | MUST-36|x| | | | | 4949 First probe after RTO | SHLD-29| |x| | | | 4950 Exponential backoff | SHLD-30| |x| | | | 4951 Allow window stay zero indefinitely | MUST-37|x| | | | | 4952 Retransmit old data beyond SND.UNA+SND.WND | MAY-7 | | |x| | | 4953 Process RST and URG even with zero window | MUST-66|x| | | | | 4954 | | | | | | | 4955 Urgent Data | | | | | | | 4956 Include support for urgent pointer | MUST-30|x| | | | | 4957 Pointer indicates first non-urgent octet | MUST-62|x| | | | | 4958 Arbitrary length urgent data sequence | MUST-31|x| | | | | 4959 Inform ALP asynchronously of urgent data | MUST-32|x| | | | |1 4960 ALP can learn if/how much urgent data Q'd | MUST-33|x| | | | |1 4961 ALP employ the urgent mechanism | SHLD-13| | | |x| | 4962 | | | | | | | 4963 TCP Options | | | | | | | 4964 Support the mandatory option set | MUST-4 |x| | | | | 4965 Receive TCP option in any segment | MUST-5 |x| | | | | 4966 Ignore unsupported options | MUST-6 |x| | | | | 4967 Include length for all options except EOL+NOP | MUST-68|x| | | | | 4968 Cope with illegal option length | MUST-7 |x| | | | | 4969 Process options regardless of word alignment | MUST-64|x| | | | | 4970 Implement sending & receiving MSS option | MUST-14|x| | | | | 4971 IPv4 Send MSS option unless 536 | SHLD-5 | |x| | | | 4972 IPv6 Send MSS option unless 1220 | SHLD-5 | |x| | | | 4973 Send MSS option always | MAY-3 | | |x| | | 4974 IPv4 Send-MSS default is 536 | MUST-15|x| | | | | 4975 IPv6 Send-MSS default is 1220 | MUST-15|x| | | | | 4976 Calculate effective send seg size | MUST-16|x| | | | | 4977 MSS accounts for varying MTU | SHLD-6 | |x| | | | 4978 MSS not sent on non-SYN segments | MUST-65| | | | |x| 4979 MSS value based on MMS_R | MUST-67|x| | | | | 4980 | | | | | | | 4981 TCP Checksums | | | | | | | 4982 Sender compute checksum | MUST-2 |x| | | | | 4983 Receiver check checksum | MUST-3 |x| | | | | 4984 | | | | | | | 4985 ISN Selection | | | | | | | 4986 Include a clock-driven ISN generator component | MUST-8 |x| | | | | 4987 Secure ISN generator with a PRF component | SHLD-1 | |x| | | | 4988 PRF computable from outside the host | MUST-9 | | | | |x| 4989 | | | | | | | 4990 Opening Connections | | | | | | | 4991 Support simultaneous open attempts | MUST-10|x| | | | | 4992 SYN-RECEIVED remembers last state | MUST-11|x| | | | | 4993 Passive Open call interfere with others | MUST-41| | | | |x| 4994 Function: simultan. LISTENs for same port | MUST-42|x| | | | | 4995 Ask IP for src address for SYN if necc. | MUST-44|x| | | | | 4996 Otherwise, use local addr of conn. | MUST-45|x| | | | | 4997 OPEN to broadcast/multicast IP Address | MUST-46| | | | |x| 4998 Silently discard seg to bcast/mcast addr | MUST-57|x| | | | | 4999 | | | | | | | 5000 Closing Connections | | | | | | | 5001 RST can contain data | SHLD-2 | |x| | | | 5002 Inform application of aborted conn | MUST-12|x| | | | | 5003 Half-duplex close connections | MAY-1 | | |x| | | 5004 Send RST to indicate data lost | SHLD-3 | |x| | | | 5005 In TIME-WAIT state for 2MSL seconds | MUST-13|x| | | | | 5006 Accept SYN from TIME-WAIT state | MAY-2 | | |x| | | 5007 Use Timestamps to reduce TIME-WAIT | SHLD-4 | |x| | | | 5008 | | | | | | | 5009 Retransmissions | | | | | | | 5010 Implement exponential backoff, slow start, and | MUST-19|x| | | | | 5011 congestion avoidance | | | | | | | 5012 Retransmit with same IP ident | MAY-4 | | |x| | | 5013 Karn's algorithm | MUST-18|x| | | | | 5014 | | | | | | | 5015 Generating ACKs: | | | | | | | 5016 Aggregate whenever possible | MUST-58|x| | | | | 5017 Queue out-of-order segments | SHLD-31| |x| | | | 5018 Process all Q'd before send ACK | MUST-59|x| | | | | 5019 Send ACK for out-of-order segment | MAY-13 | | |x| | | 5020 Delayed ACKs | SHLD-18| |x| | | | 5021 Delay < 0.5 seconds | MUST-40|x| | | | | 5022 Every 2nd full-sized segment or 2*RMSS ACK'd | SHLD-19|x| | | | | 5023 Receiver SWS-Avoidance Algorithm | MUST-39|x| | | | | 5024 | | | | | | | 5025 Sending data | | | | | | | 5026 Configurable TTL | MUST-49|x| | | | | 5027 Sender SWS-Avoidance Algorithm | MUST-38|x| | | | | 5028 Nagle algorithm | SHLD-7 | |x| | | | 5029 Application can disable Nagle algorithm | MUST-17|x| | | | | 5030 | | | | | | | 5031 Connection Failures: | | | | | | | 5032 Negative advice to IP on R1 retxs | MUST-20|x| | | | | 5033 Close connection on R2 retxs | MUST-20|x| | | | | 5034 ALP can set R2 | MUST-21|x| | | | |1 5035 Inform ALP of R1<=retxs inform ALP | SHLD-25| |x| | | | 5063 Dest. Unreach (0,1,5) => abort conn | MUST-56| | | | |x| 5064 Dest. Unreach (2-4) => abort conn | SHLD-26| |x| | | | 5065 Source Quench => silent discard | MUST-55|x| | | | | 5066 Time Exceeded => tell ALP, don't abort | MUST-56| | | | |x| 5067 Param Problem => tell ALP, don't abort | MUST-56| | | | |x| 5068 | | | | | | | 5069 Address Validation | | | | | | | 5070 Reject OPEN call to invalid IP address | MUST-46|x| | | | | 5071 Reject SYN from invalid IP address | MUST-63|x| | | | | 5072 Silently discard SYN to bcast/mcast addr | MUST-57|x| | | | | 5073 | | | | | | | 5074 TCP/ALP Interface Services | | | | | | | 5075 Error Report mechanism | MUST-47|x| | | | | 5076 ALP can disable Error Report Routine | SHLD-20| |x| | | | 5077 ALP can specify DiffServ field for sending | MUST-48|x| | | | | 5078 Passed unchanged to IP | SHLD-22| |x| | | | 5079 ALP can change DiffServ field during connection| SHLD-21| |x| | | | 5080 ALP generally changing DiffServ during conn. | SHLD-23| | | |x| | 5081 Pass received DiffServ field up to ALP | MAY-9 | | |x| | | 5082 FLUSH call | MAY-14 | | |x| | | 5083 Optional local IP addr parm. in OPEN | MUST-43|x| | | | | 5084 | | | | | | | 5085 RFC 5961 Support: | | | | | | | 5086 Implement data injection protection | MAY-12 | | |x| | | 5087 | | | | | | | 5088 Explicit Congestion Notification: | | | | | | | 5089 Support ECN | SHLD-8 | |x| | | | 5090 | | | | | | | 5091 Alternative Congestion Control: | | | | | | | 5092 Implement alternative conformant algorithm(s) | MAY-18 | | |x| | | 5093 -------------------------------------------------|--------|-|-|-|-|-|- 5095 FOOTNOTES: (1) "ALP" means Application-Layer Program. 5097 Author's Address 5099 Wesley M. Eddy (editor) 5100 MTI Systems 5101 US 5103 Email: wes@mti-systems.com