idnits 2.17.1 draft-ietf-tcpm-rfc793bis-11.txt: Checking boilerplate required by RFC 5378 and the IETF Trust (see https://trustee.ietf.org/license-info): ---------------------------------------------------------------------------- No issues found here. Checking nits according to https://www.ietf.org/id-info/1id-guidelines.txt: ---------------------------------------------------------------------------- No issues found here. Checking nits according to https://www.ietf.org/id-info/checklist : ---------------------------------------------------------------------------- ** The document seems to lack a Security Considerations section. == There are 3 instances of lines with non-RFC2606-compliant FQDNs in the document. == There are 1 instance of lines with non-RFC6890-compliant IPv4 addresses in the document. If these are example addresses, they should be changed. -- The draft header indicates that this document obsoletes RFC6093, but the abstract doesn't seem to mention this, which it should. -- The draft header indicates that this document obsoletes RFC2873, but the abstract doesn't seem to mention this, which it should. -- The draft header indicates that this document obsoletes RFC6429, but the abstract doesn't seem to mention this, which it should. -- The draft header indicates that this document obsoletes RFC879, but the abstract doesn't seem to mention this, which it should. Miscellaneous warnings: ---------------------------------------------------------------------------- == The copyright year in the IETF Trust and authors Copyright Line does not match the current year (Using the creation date from RFC1122, updated by this document, for RFC5378 checks: 1989-10-01) -- The document seems to contain a disclaimer for pre-RFC5378 work, and may have content which was first submitted before 10 November 2008. The disclaimer is necessary when there are original authors that you have been unable to contact, or if some do not wish to grant the BCP78 rights to the IETF Trust. If you are able to get all authors (current and original) to grant those rights, you can and should remove the disclaimer; otherwise, the disclaimer is needed and you can ignore this comment. (See the Legal Provisions document at https://trustee.ietf.org/license-info for more information.) -- The document date (October 22, 2018) is 2012 days in the past. Is this intentional? Checking references for intended status: Proposed Standard ---------------------------------------------------------------------------- (See RFCs 3967 and 4897 for information about using normative references to lower-maturity documents in RFCs) == Unused Reference: '44' is defined on line 4378, but no explicit reference was found in the text ** Obsolete normative reference: RFC 1981 (ref. '3') (Obsoleted by RFC 8201) ** Obsolete normative reference: RFC 2460 (ref. '5') (Obsoleted by RFC 8200) ** Downref: Normative reference to an Informational RFC: RFC 2923 (ref. '8') -- Obsolete informational reference (is this intentional?): RFC 793 (ref. '12') (Obsoleted by RFC 9293) -- Obsolete informational reference (is this intentional?): RFC 896 (ref. '13') (Obsoleted by RFC 7805) -- Obsolete informational reference (is this intentional?): RFC 1349 (ref. '15') (Obsoleted by RFC 2474) -- Obsolete informational reference (is this intentional?): RFC 1644 (ref. '16') (Obsoleted by RFC 6247) -- Obsolete informational reference (is this intentional?): RFC 2873 (ref. '18') (Obsoleted by RFC 9293) -- Obsolete informational reference (is this intentional?): RFC 6093 (ref. '29') (Obsoleted by RFC 9293) -- Obsolete informational reference (is this intentional?): RFC 6429 (ref. '31') (Obsoleted by RFC 9293) -- Obsolete informational reference (is this intentional?): RFC 6528 (ref. '32') (Obsoleted by RFC 9293) -- Obsolete informational reference (is this intentional?): RFC 6691 (ref. '33') (Obsoleted by RFC 9293) == Outdated reference: A later version (-04) exists of draft-gont-tcpm-tcp-seq-validation-02 == Outdated reference: A later version (-15) exists of draft-ietf-tcpinc-tcpcrypt-09 Summary: 4 errors (**), 0 flaws (~~), 6 warnings (==), 15 comments (--). Run idnits with the --verbose option for more detailed information about the items above. -------------------------------------------------------------------------------- 2 Internet Engineering Task Force W. Eddy, Ed. 3 Internet-Draft MTI Systems 4 Obsoletes: 793, 879, 2873, 6093, 6429, October 22, 2018 5 6528, 6691 (if approved) 6 Updates: 5961, 1122 (if approved) 7 Intended status: Standards Track 8 Expires: April 25, 2019 10 Transmission Control Protocol Specification 11 draft-ietf-tcpm-rfc793bis-11 13 Abstract 15 This document specifies the Internet's Transmission Control Protocol 16 (TCP). TCP is an important transport layer protocol in the Internet 17 stack, and has continuously evolved over decades of use and growth of 18 the Internet. Over this time, a number of changes have been made to 19 TCP as it was specified in RFC 793, though these have only been 20 documented in a piecemeal fashion. This document collects and brings 21 those changes together with the protocol specification from RFC 793. 22 This document obsoletes RFC 793, as well as 879, 2873, 6093, 6429, 23 6528, and 6691 that updated parts of RFC 793. It updates RFC 1122, 24 and should be considered as a replacement for the portions of that 25 document dealing with TCP requirements. It updates RFC 5961 due to a 26 small clarification in reset handling while in the SYN-RECEIVED 27 state. 29 RFC EDITOR NOTE: If approved for publication as an RFC, this should 30 be marked additionally as "STD: 7" and replace RFC 793 in that role. 32 Requirements Language 34 The key words "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT", 35 "SHOULD", "SHOULD NOT", "RECOMMENDED", "MAY", and "OPTIONAL" in this 36 document are to be interpreted as described in RFC 2119 [4]. 38 Status of This Memo 40 This Internet-Draft is submitted in full conformance with the 41 provisions of BCP 78 and BCP 79. 43 Internet-Drafts are working documents of the Internet Engineering 44 Task Force (IETF). Note that other groups may also distribute 45 working documents as Internet-Drafts. The list of current Internet- 46 Drafts is at https://datatracker.ietf.org/drafts/current/. 48 Internet-Drafts are draft documents valid for a maximum of six months 49 and may be updated, replaced, or obsoleted by other documents at any 50 time. It is inappropriate to use Internet-Drafts as reference 51 material or to cite them other than as "work in progress." 53 This Internet-Draft will expire on April 25, 2019. 55 Copyright Notice 57 Copyright (c) 2018 IETF Trust and the persons identified as the 58 document authors. All rights reserved. 60 This document is subject to BCP 78 and the IETF Trust's Legal 61 Provisions Relating to IETF Documents 62 (https://trustee.ietf.org/license-info) in effect on the date of 63 publication of this document. Please review these documents 64 carefully, as they describe your rights and restrictions with respect 65 to this document. Code Components extracted from this document must 66 include Simplified BSD License text as described in Section 4.e of 67 the Trust Legal Provisions and are provided without warranty as 68 described in the Simplified BSD License. 70 This document may contain material from IETF Documents or IETF 71 Contributions published or made publicly available before November 72 10, 2008. The person(s) controlling the copyright in some of this 73 material may not have granted the IETF Trust the right to allow 74 modifications of such material outside the IETF Standards Process. 75 Without obtaining an adequate license from the person(s) controlling 76 the copyright in such materials, this document may not be modified 77 outside the IETF Standards Process, and derivative works of it may 78 not be created outside the IETF Standards Process, except to format 79 it for publication as an RFC or to translate it into languages other 80 than English. 82 Table of Contents 84 1. Purpose and Scope . . . . . . . . . . . . . . . . . . . . . . 3 85 2. Introduction . . . . . . . . . . . . . . . . . . . . . . . . 4 86 2.1. Key TCP Concepts . . . . . . . . . . . . . . . . . . . . 5 87 3. Functional Specification . . . . . . . . . . . . . . . . . . 6 88 3.1. Header Format . . . . . . . . . . . . . . . . . . . . . . 6 89 3.2. Terminology . . . . . . . . . . . . . . . . . . . . . . . 11 90 3.3. Sequence Numbers . . . . . . . . . . . . . . . . . . . . 15 91 3.4. Establishing a connection . . . . . . . . . . . . . . . . 22 92 3.5. Closing a Connection . . . . . . . . . . . . . . . . . . 29 93 3.5.1. Half-Closed Connections . . . . . . . . . . . . . . . 31 94 3.6. Precedence and Security . . . . . . . . . . . . . . . . . 32 95 3.7. Segmentation . . . . . . . . . . . . . . . . . . . . . . 33 96 3.7.1. Maximum Segment Size Option . . . . . . . . . . . . . 34 97 3.7.2. Path MTU Discovery . . . . . . . . . . . . . . . . . 36 98 3.7.3. Interfaces with Variable MTU Values . . . . . . . . . 36 99 3.7.4. Nagle Algorithm . . . . . . . . . . . . . . . . . . . 37 100 3.7.5. IPv6 Jumbograms . . . . . . . . . . . . . . . . . . . 37 101 3.8. Data Communication . . . . . . . . . . . . . . . . . . . 37 102 3.8.1. Retransmission Timeout . . . . . . . . . . . . . . . 38 103 3.8.2. TCP Congestion Control . . . . . . . . . . . . . . . 38 104 3.8.3. TCP Connection Failures . . . . . . . . . . . . . . . 39 105 3.8.4. TCP Keep-Alives . . . . . . . . . . . . . . . . . . . 40 106 3.8.5. The Communication of Urgent Information . . . . . . . 40 107 3.8.6. Managing the Window . . . . . . . . . . . . . . . . . 41 108 3.9. Interfaces . . . . . . . . . . . . . . . . . . . . . . . 45 109 3.9.1. User/TCP Interface . . . . . . . . . . . . . . . . . 46 110 3.9.2. TCP/Lower-Level Interface . . . . . . . . . . . . . . 54 111 3.10. Event Processing . . . . . . . . . . . . . . . . . . . . 56 112 3.11. Glossary . . . . . . . . . . . . . . . . . . . . . . . . 82 113 4. Changes from RFC 793 . . . . . . . . . . . . . . . . . . . . 87 114 5. IANA Considerations . . . . . . . . . . . . . . . . . . . . . 92 115 6. Security and Privacy Considerations . . . . . . . . . . . . . 92 116 7. Acknowledgements . . . . . . . . . . . . . . . . . . . . . . 93 117 8. References . . . . . . . . . . . . . . . . . . . . . . . . . 94 118 8.1. Normative References . . . . . . . . . . . . . . . . . . 94 119 8.2. Informative References . . . . . . . . . . . . . . . . . 95 120 Appendix A. Other Implementation Notes . . . . . . . . . . . . . 98 121 A.1. IP Security Compartment and Precedence . . . . . . . . . 99 122 A.2. Sequence Number Validation . . . . . . . . . . . . . . . 99 123 A.3. Nagle Modification . . . . . . . . . . . . . . . . . . . 99 124 A.4. Low Water Mark . . . . . . . . . . . . . . . . . . . . . 100 125 Appendix B. TCP Requirement Summary . . . . . . . . . . . . . . 100 126 Author's Address . . . . . . . . . . . . . . . . . . . . . . . . 104 128 1. Purpose and Scope 130 In 1981, RFC 793 [12] was released, documenting the Transmission 131 Control Protocol (TCP), and replacing earlier specifications for TCP 132 that had been published in the past. 134 Since then, TCP has been implemented many times, and has been used as 135 a transport protocol for numerous applications on the Internet. 137 For several decades, RFC 793 plus a number of other documents have 138 combined to serve as the specification for TCP [37]. Over time, a 139 number of errata have been identified on RFC 793, as well as 140 deficiencies in security, performance, and other aspects. A number 141 of enhancements has grown and been documented separately. These were 142 never accumulated together into an update to the base specification. 144 The purpose of this document is to bring together all of the IETF 145 Standards Track changes that have been made to the basic TCP 146 functional specification and unify them into an update of the RFC 793 147 protocol specification. Some companion documents are referenced for 148 important algorithms that TCP uses (e.g. for congestion control), but 149 have not been attempted to include in this document. This is a 150 conscious choice, as this base specification can be used with 151 multiple additional algorithms that are developed and incorporated 152 separately, but all TCP implementations need to implement this 153 specification as a common basis in order to interoperate. As some 154 additional TCP features have become quite complicated themselves 155 (e.g. advanced loss recovery and congestion control), future 156 companion documents may attempt to similarly bring these together. 158 In addition to the protocol specification that descibes the TCP 159 segment format, generation, and processing rules that are to be 160 implemented in code, RFC 793 and other updates also contain 161 informative and descriptive text for human readers to understand 162 aspects of the protocol design and operation. This document does not 163 attempt to alter or update this informative text, and is focused only 164 on updating the normative protocol specification. We preserve 165 references to the documentation containing the important explanations 166 and rationale, where appropriate. 168 This document is intended to be useful both in checking existing TCP 169 implementations for conformance, as well as in writing new 170 implementations. 172 2. Introduction 174 RFC 793 contains a discussion of the TCP design goals and provides 175 examples of its operation, including examples of connection 176 establishment, closing connections, and retransmitting packets to 177 repair losses. 179 This document describes the basic functionality expected in modern 180 implementations of TCP, and replaces the protocol specification in 181 RFC 793. It does not replicate or attempt to update the examples and 182 other discussion in RFC 793. Other documents are referenced to 183 provide explanation of the theory of operation, rationale, and 184 detailed discussion of design decisions. This document only focuses 185 on the normative behavior of the protocol. 187 The "TCP Roadmap" [37] provides a more extensive guide to the RFCs 188 that define TCP and describe various important algorithms. The TCP 189 Roadmap contains sections on strongly encouraged enhancements that 190 improve performance and other aspects of TCP beyond the basic 191 operation specified in this document. As one example, implementing 192 congestion control (e.g. [25]) is a TCP requirement, but is a complex 193 topic on its own, and not described in detail in this document, as 194 there are many options and possibilities that do not impact basic 195 interoperability. Similarly, most common TCP implementations today 196 include the high-performance extensions in [35], but these are not 197 strictly required or discussed in this document. 199 TEMPORARY EDITOR'S NOTE: This is an early revision in the process of 200 updating RFC 793. Many planned changes are not yet incorporated. 202 ***Please do not use this revision as a basis for any work or 203 reference.*** 205 A list of changes from RFC 793 is contained in Section 4. 207 TEMPORARY EDITOR'S NOTE: the current revision of this document does 208 not yet collect all of the changes that will be in the final version. 209 The set of content changes planned for future revisions is kept in 210 Section 4. 212 2.1. Key TCP Concepts 214 TCP provides a reliable, in-order, byte-stream service to 215 applications. 217 The application byte-stream is conveyed over the network via TCP 218 segments, with each TCP segment sent as an Internet Protocol (IP) 219 datagram. 221 TCP reliability consists of detecting packet losses (via sequence 222 numbers) and errors (via per-segment checksums), as well as 223 correction of losses and errors via retransmission. 225 TCP supports unicast delivery of data. Anycast applications exist 226 that successfully use TCP without modifications, though there is some 227 risk of instability due to rerouting. 229 TCP is connection-oriented, though does not inherently include a 230 liveness detection capability. 232 Data flow is supported bidirectionally over TCP connections, though 233 applications are free to flow data only unidirectionally, if they so 234 choose. 236 TCP uses port numbers to identify application services and to 237 multiplex multiple flows between hosts. 239 A more detailed description of TCP's features compared to other 240 transport protocols can be found in Section 3.1 of [40]. Further 241 description of the motivations for developing TCP and its role in the 242 Internet stack can be found in Section 2 of [12] and earlier versions 243 of the TCP specification. 245 3. Functional Specification 247 3.1. Header Format 249 TCP segments are sent as internet datagrams. The Internet Protocol 250 (IP) header carries several information fields, including the source 251 and destination host addresses [1] [5]. A TCP header follows the 252 Internet header, supplying information specific to the TCP protocol. 253 This division allows for the existence of host level protocols other 254 than TCP. In early development of the Internet suite of protocols, 255 the IP header fields had been a part of TCP. 257 TCP Header Format 259 0 1 2 3 260 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 261 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 262 | Source Port | Destination Port | 263 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 264 | Sequence Number | 265 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 266 | Acknowledgment Number | 267 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 268 | Data | |C|E|U|A|P|R|S|F| | 269 | Offset| Rsrvd |W|C|R|C|S|S|Y|I| Window | 270 | | |R|E|G|K|H|T|N|N| | 271 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 272 | Checksum | Urgent Pointer | 273 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 274 | Options | Padding | 275 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 276 | data | 277 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 279 TCP Header Format 281 Note that one tick mark represents one bit position. 283 Figure 1 285 Source Port: 16 bits 286 The source port number. 288 Destination Port: 16 bits 290 The destination port number. 292 Sequence Number: 32 bits 294 The sequence number of the first data octet in this segment (except 295 when SYN is present). If SYN is present the sequence number is the 296 initial sequence number (ISN) and the first data octet is ISN+1. 298 Acknowledgment Number: 32 bits 300 If the ACK control bit is set this field contains the value of the 301 next sequence number the sender of the segment is expecting to 302 receive. Once a connection is established this is always sent. 304 Data Offset: 4 bits 306 The number of 32 bit words in the TCP Header. This indicates where 307 the data begins. The TCP header (even one including options) is an 308 integral number of 32 bits long. 310 Rsrvd - Reserved: 4 bits 312 Reserved for future use. Must be zero in generated segments and 313 must be ignored in received segments, if corresponding future 314 features are unimplemented by the sending or receiving host. 316 Control Bits: 8 bits (from left to right): 318 CWR: Congestion Window Reduced (see [9]) 319 ECE: ECN-Echo (see [9]) 320 URG: Urgent Pointer field significant 321 ACK: Acknowledgment field significant 322 PSH: Push Function 323 RST: Reset the connection 324 SYN: Synchronize sequence numbers 325 FIN: No more data from sender 327 Window: 16 bits 329 The number of data octets beginning with the one indicated in the 330 acknowledgment field which the sender of this segment is willing to 331 accept. 333 The window size MUST be treated as an unsigned number, or else 334 large window sizes will appear like negative windows and TCP will 335 now work (MUST-1). It is RECOMMENDED that implementations will 336 reserve 32-bit fields for the send and receive window sizes in the 337 connection record and do all window computations with 32 bits (REC- 338 1). 340 Checksum: 16 bits 342 The checksum field is the 16 bit one's complement of the one's 343 complement sum of all 16 bit words in the header and text. If a 344 segment contains an odd number of header and text octets to be 345 checksummed, the last octet is padded on the right with zeros to 346 form a 16 bit word for checksum purposes. The pad is not 347 transmitted as part of the segment. While computing the checksum, 348 the checksum field itself is replaced with zeros. 350 The checksum also covers a pseudo header conceptually prefixed to 351 the TCP header. The pseudo header is 96 bits for IPv4 and 320 bits 352 for IPv6. For IPv4, this pseudo header contains the Source 353 Address, the Destination Address, the Protocol, and TCP length. 354 This gives the TCP protection against misrouted segments. This 355 information is carried in IPv4 and is transferred across the TCP/ 356 Network interface in the arguments or results of calls by the TCP 357 on the IP. 359 +--------+--------+--------+--------+ 360 | Source Address | 361 +--------+--------+--------+--------+ 362 | Destination Address | 363 +--------+--------+--------+--------+ 364 | zero | PTCL | TCP Length | 365 +--------+--------+--------+--------+ 367 The TCP Length is the TCP header length plus the data length in 368 octets (this is not an explicitly transmitted quantity, but is 369 computed), and it does not count the 12 octets of the pseudo 370 header. 372 For IPv6, the pseudo header is contained in section 8.1 of RFC 2460 373 [5], and contains the IPv6 Source Address and Destination Address, 374 an Upper Layer Packet Length (a 32-bit value otherwise equivalent 375 to TCP Length in the IPv4 pseudo header), three bytes of zero- 376 padding, and a Next Header value (differing from the IPv6 header 377 value in the case of extension headers present in between IPv6 and 378 TCP). 380 The TCP checksum is never optional. The sender MUST generate it 381 (MUST-2) and the receiver MUST check it (MUST-3). 383 Urgent Pointer: 16 bits 385 This field communicates the current value of the urgent pointer as 386 a positive offset from the sequence number in this segment. The 387 urgent pointer points to the sequence number of the octet following 388 the urgent data. This field is only be interpreted in segments 389 with the URG control bit set. 391 Options: variable 393 Options may occupy space at the end of the TCP header and are a 394 multiple of 8 bits in length. All options are included in the 395 checksum. An option may begin on any octet boundary. There are 396 two cases for the format of an option: 398 Case 1: A single octet of option-kind. 400 Case 2: An octet of option-kind, an octet of option-length, and 401 the actual option-data octets. 403 The option-length counts the two octets of option-kind and option- 404 length as well as the option-data octets. 406 Note that the list of options may be shorter than the data offset 407 field might imply. The content of the header beyond the End-of- 408 Option option must be header padding (i.e., zero). 410 The list of all currently defined options is managed by IANA [41], 411 and each option is defined in other RFCs, as indicated there. That 412 set includes experimental options that can be extended to support 413 multiple concurrent uses [34]. 415 A given TCP implementation can support any currently defined 416 options, but the following options MUST be supported (MUST-4) (kind 417 indicated in octal): 419 Kind Length Meaning 420 ---- ------ ------- 421 0 - End of option list. 422 1 - No-Operation. 423 2 4 Maximum Segment Size. 425 A TCP MUST be able to receive a TCP option in any segment (MUST-5). 427 A TCP MUST (MUST-6) ignore without error any TCP option it does not 428 implement, assuming that the option has a length field (all TCP 429 options except End of option list and No-Operation have length 430 fields). TCP MUST be prepared to handle an illegal option length 431 (e.g., zero) without crashing; a suggested procedure is to reset 432 the connection and log the reason (MUST-7). 434 Specific Option Definitions 436 End of Option List 438 +--------+ 439 |00000000| 440 +--------+ 441 Kind=0 443 This option code indicates the end of the option list. This 444 might not coincide with the end of the TCP header according to 445 the Data Offset field. This is used at the end of all options, 446 not the end of each option, and need only be used if the end of 447 the options would not otherwise coincide with the end of the TCP 448 header. 450 No-Operation 452 +--------+ 453 |00000001| 454 +--------+ 455 Kind=1 457 This option code may be used between options, for example, to 458 align the beginning of a subsequent option on a word boundary. 459 There is no guarantee that senders will use this option, so 460 receivers must be prepared to process options even if they do 461 not begin on a word boundary. 463 Maximum Segment Size (MSS) 465 +--------+--------+---------+--------+ 466 |00000010|00000100| max seg size | 467 +--------+--------+---------+--------+ 468 Kind=2 Length=4 470 Maximum Segment Size Option Data: 16 bits 472 If this option is present, then it communicates the maximum 473 receive segment size at the TCP which sends this segment. This 474 value is limited by the IP reassembly limit. This field may be 475 sent in the initial connection request (i.e., in segments with 476 the SYN control bit set) and must not be sent in other segments. 477 If this option is not used, any segment size is allowed. A more 478 complete description of this option is in Section 3.7.1. 480 Padding: variable 482 The TCP header padding is used to ensure that the TCP header ends 483 and data begins on a 32 bit boundary. The padding is composed of 484 zeros. 486 3.2. Terminology 488 Before we can discuss very much about the operation of the TCP we 489 need to introduce some detailed terminology. The maintenance of a 490 TCP connection requires the remembering of several variables. We 491 conceive of these variables being stored in a connection record 492 called a Transmission Control Block or TCB. Among the variables 493 stored in the TCB are the local and remote socket numbers, the IP 494 security level and compartment of the connection, pointers to the 495 user's send and receive buffers, pointers to the retransmit queue and 496 to the current segment. In addition several variables relating to 497 the send and receive sequence numbers are stored in the TCB. 499 Send Sequence Variables 501 SND.UNA - send unacknowledged 502 SND.NXT - send next 503 SND.WND - send window 504 SND.UP - send urgent pointer 505 SND.WL1 - segment sequence number used for last window update 506 SND.WL2 - segment acknowledgment number used for last window 507 update 508 ISS - initial send sequence number 510 Receive Sequence Variables 512 RCV.NXT - receive next 513 RCV.WND - receive window 514 RCV.UP - receive urgent pointer 515 IRS - initial receive sequence number 517 The following diagrams may help to relate some of these variables to 518 the sequence space. 520 Send Sequence Space 522 1 2 3 4 523 ----------|----------|----------|---------- 524 SND.UNA SND.NXT SND.UNA 525 +SND.WND 527 1 - old sequence numbers which have been acknowledged 528 2 - sequence numbers of unacknowledged data 529 3 - sequence numbers allowed for new data transmission 530 4 - future sequence numbers which are not yet allowed 532 Send Sequence Space 534 Figure 2 536 The send window is the portion of the sequence space labeled 3 in 537 Figure 2. 539 Receive Sequence Space 541 1 2 3 542 ----------|----------|---------- 543 RCV.NXT RCV.NXT 544 +RCV.WND 546 1 - old sequence numbers which have been acknowledged 547 2 - sequence numbers allowed for new reception 548 3 - future sequence numbers which are not yet allowed 550 Receive Sequence Space 552 Figure 3 554 The receive window is the portion of the sequence space labeled 2 in 555 Figure 3. 557 There are also some variables used frequently in the discussion that 558 take their values from the fields of the current segment. 560 Current Segment Variables 562 SEG.SEQ - segment sequence number 563 SEG.ACK - segment acknowledgment number 564 SEG.LEN - segment length 565 SEG.WND - segment window 566 SEG.UP - segment urgent pointer 568 A connection progresses through a series of states during its 569 lifetime. The states are: LISTEN, SYN-SENT, SYN-RECEIVED, 570 ESTABLISHED, FIN-WAIT-1, FIN-WAIT-2, CLOSE-WAIT, CLOSING, LAST-ACK, 571 TIME-WAIT, and the fictional state CLOSED. CLOSED is fictional 572 because it represents the state when there is no TCB, and therefore, 573 no connection. Briefly the meanings of the states are: 575 LISTEN - represents waiting for a connection request from any 576 remote TCP and port. 578 SYN-SENT - represents waiting for a matching connection request 579 after having sent a connection request. 581 SYN-RECEIVED - represents waiting for a confirming connection 582 request acknowledgment after having both received and sent a 583 connection request. 585 ESTABLISHED - represents an open connection, data received can be 586 delivered to the user. The normal state for the data transfer 587 phase of the connection. 589 FIN-WAIT-1 - represents waiting for a connection termination 590 request from the remote TCP, or an acknowledgment of the 591 connection termination request previously sent. 593 FIN-WAIT-2 - represents waiting for a connection termination 594 request from the remote TCP. 596 CLOSE-WAIT - represents waiting for a connection termination 597 request from the local user. 599 CLOSING - represents waiting for a connection termination request 600 acknowledgment from the remote TCP. 602 LAST-ACK - represents waiting for an acknowledgment of the 603 connection termination request previously sent to the remote TCP 604 (this termination request sent to the remote TCP already included 605 an acknowledgment of the termination request sent from the remote 606 TCP). 608 TIME-WAIT - represents waiting for enough time to pass to be sure 609 the remote TCP received the acknowledgment of its connection 610 termination request. 612 CLOSED - represents no connection state at all. 614 A TCP connection progresses from one state to another in response to 615 events. The events are the user calls, OPEN, SEND, RECEIVE, CLOSE, 616 ABORT, and STATUS; the incoming segments, particularly those 617 containing the SYN, ACK, RST and FIN flags; and timeouts. 619 The state diagram in Figure 4 illustrates only state changes, 620 together with the causing events and resulting actions, but addresses 621 neither error conditions nor actions which are not connected with 622 state changes. In a later section, more detail is offered with 623 respect to the reaction of the TCP to events. Some state names are 624 abbreviated or hyphenated differently in the diagram from how they 625 appear elsewhere in the document. 627 NOTA BENE: This diagram is only a summary and must not be taken as 628 the total specification. Many details are not included. 630 +---------+ ---------\ active OPEN 631 | CLOSED | \ ----------- 632 +---------+<---------\ \ create TCB 633 | ^ \ \ snd SYN 634 passive OPEN | | CLOSE \ \ 635 ------------ | | ---------- \ \ 636 create TCB | | delete TCB \ \ 637 V | \ \ 638 rcv RST (note 1) +---------+ CLOSE | \ 639 -------------------->| LISTEN | ---------- | | 640 / +---------+ delete TCB | | 641 / rcv SYN | | SEND | | 642 / ----------- | | ------- | V 643 +--------+ snd SYN,ACK / \ snd SYN +--------+ 644 | |<----------------- ------------------>| | 645 | SYN | rcv SYN | SYN | 646 | RCVD |<-----------------------------------------------| SENT | 647 | | snd SYN,ACK | | 648 | |------------------ -------------------| | 649 +--------+ rcv ACK of SYN \ / rcv SYN,ACK +--------+ 650 | -------------- | | ----------- 651 | x | | snd ACK 652 | V V 653 | CLOSE +---------+ 654 | ------- | ESTAB | 655 | snd FIN +---------+ 656 | CLOSE | | rcv FIN 657 V ------- | | ------- 658 +---------+ snd FIN / \ snd ACK +---------+ 659 | FIN |<----------------- ------------------>| CLOSE | 660 | WAIT-1 |------------------ | WAIT | 661 +---------+ rcv FIN \ +---------+ 662 | rcv ACK of FIN ------- | CLOSE | 663 | -------------- snd ACK | ------- | 664 V x V snd FIN V 665 +---------+ +---------+ +---------+ 666 |FINWAIT-2| | CLOSING | | LAST-ACK| 667 +---------+ +---------+ +---------+ 668 | rcv ACK of FIN | rcv ACK of FIN | 669 | rcv FIN -------------- | Timeout=2MSL -------------- | 670 | ------- x V ------------ x V 671 \ snd ACK +---------+delete TCB +---------+ 672 ------------------------>|TIME WAIT|------------------>| CLOSED | 673 +---------+ +---------+ 675 note 1: The transition from SYN-RECEIVED to LISTEN on receiving a RST is 676 conditional on having reached SYN-RECEIVED after a passive open. 678 note 2: An unshown transition exists from FIN-WAIT-1 to TIME-WAIT if 679 a FIN is received and the local FIN is also acknowledged. 681 TCP Connection State Diagram 683 Figure 4 685 3.3. Sequence Numbers 687 A fundamental notion in the design is that every octet of data sent 688 over a TCP connection has a sequence number. Since every octet is 689 sequenced, each of them can be acknowledged. The acknowledgment 690 mechanism employed is cumulative so that an acknowledgment of 691 sequence number X indicates that all octets up to but not including X 692 have been received. This mechanism allows for straight-forward 693 duplicate detection in the presence of retransmission. Numbering of 694 octets within a segment is that the first data octet immediately 695 following the header is the lowest numbered, and the following octets 696 are numbered consecutively. 698 It is essential to remember that the actual sequence number space is 699 finite, though very large. This space ranges from 0 to 2**32 - 1. 700 Since the space is finite, all arithmetic dealing with sequence 701 numbers must be performed modulo 2**32. This unsigned arithmetic 702 preserves the relationship of sequence numbers as they cycle from 703 2**32 - 1 to 0 again. There are some subtleties to computer modulo 704 arithmetic, so great care should be taken in programming the 705 comparison of such values. The symbol "=<" means "less than or 706 equal" (modulo 2**32). 708 The typical kinds of sequence number comparisons which the TCP must 709 perform include: 711 (a) Determining that an acknowledgment refers to some sequence 712 number sent but not yet acknowledged. 714 (b) Determining that all sequence numbers occupied by a segment 715 have been acknowledged (e.g., to remove the segment from a 716 retransmission queue). 718 (c) Determining that an incoming segment contains sequence numbers 719 which are expected (i.e., that the segment "overlaps" the receive 720 window). 722 In response to sending data the TCP will receive acknowledgments. 723 The following comparisons are needed to process the acknowledgments. 725 SND.UNA = oldest unacknowledged sequence number 727 SND.NXT = next sequence number to be sent 729 SEG.ACK = acknowledgment from the receiving TCP (next sequence 730 number expected by the receiving TCP) 732 SEG.SEQ = first sequence number of a segment 734 SEG.LEN = the number of octets occupied by the data in the segment 735 (counting SYN and FIN) 737 SEG.SEQ+SEG.LEN-1 = last sequence number of a segment 739 A new acknowledgment (called an "acceptable ack"), is one for which 740 the inequality below holds: 742 SND.UNA < SEG.ACK =< SND.NXT 744 A segment on the retransmission queue is fully acknowledged if the 745 sum of its sequence number and length is less or equal than the 746 acknowledgment value in the incoming segment. 748 When data is received the following comparisons are needed: 750 RCV.NXT = next sequence number expected on an incoming segments, 751 and is the left or lower edge of the receive window 753 RCV.NXT+RCV.WND-1 = last sequence number expected on an incoming 754 segment, and is the right or upper edge of the receive window 756 SEG.SEQ = first sequence number occupied by the incoming segment 757 SEG.SEQ+SEG.LEN-1 = last sequence number occupied by the incoming 758 segment 760 A segment is judged to occupy a portion of valid receive sequence 761 space if 763 RCV.NXT =< SEG.SEQ < RCV.NXT+RCV.WND 765 or 767 RCV.NXT =< SEG.SEQ+SEG.LEN-1 < RCV.NXT+RCV.WND 769 The first part of this test checks to see if the beginning of the 770 segment falls in the window, the second part of the test checks to 771 see if the end of the segment falls in the window; if the segment 772 passes either part of the test it contains data in the window. 774 Actually, it is a little more complicated than this. Due to zero 775 windows and zero length segments, we have four cases for the 776 acceptability of an incoming segment: 778 Segment Receive Test 779 Length Window 780 ------- ------- ------------------------------------------- 782 0 0 SEG.SEQ = RCV.NXT 784 0 >0 RCV.NXT =< SEG.SEQ < RCV.NXT+RCV.WND 786 >0 0 not acceptable 788 >0 >0 RCV.NXT =< SEG.SEQ < RCV.NXT+RCV.WND 789 or RCV.NXT =< SEG.SEQ+SEG.LEN-1 < RCV.NXT+RCV.WND 791 Note that when the receive window is zero no segments should be 792 acceptable except ACK segments. Thus, it is be possible for a TCP to 793 maintain a zero receive window while transmitting data and receiving 794 ACKs. However, even when the receive window is zero, a TCP must 795 process the RST and URG fields of all incoming segments. 797 We have taken advantage of the numbering scheme to protect certain 798 control information as well. This is achieved by implicitly 799 including some control flags in the sequence space so they can be 800 retransmitted and acknowledged without confusion (i.e., one and only 801 one copy of the control will be acted upon). Control information is 802 not physically carried in the segment data space. Consequently, we 803 must adopt rules for implicitly assigning sequence numbers to 804 control. The SYN and FIN are the only controls requiring this 805 protection, and these controls are used only at connection opening 806 and closing. For sequence number purposes, the SYN is considered to 807 occur before the first actual data octet of the segment in which it 808 occurs, while the FIN is considered to occur after the last actual 809 data octet in a segment in which it occurs. The segment length 810 (SEG.LEN) includes both data and sequence space occupying controls. 811 When a SYN is present then SEG.SEQ is the sequence number of the SYN. 813 Initial Sequence Number Selection 815 The protocol places no restriction on a particular connection being 816 used over and over again. A connection is defined by a pair of 817 sockets. New instances of a connection will be referred to as 818 incarnations of the connection. The problem that arises from this is 819 -- "how does the TCP identify duplicate segments from previous 820 incarnations of the connection?" This problem becomes apparent if 821 the connection is being opened and closed in quick succession, or if 822 the connection breaks with loss of memory and is then reestablished. 824 To avoid confusion we must prevent segments from one incarnation of a 825 connection from being used while the same sequence numbers may still 826 be present in the network from an earlier incarnation. We want to 827 assure this, even if a TCP crashes and loses all knowledge of the 828 sequence numbers it has been using. When new connections are 829 created, an initial sequence number (ISN) generator is employed which 830 selects a new 32 bit ISN. There are security issues that result if 831 an off-path attacker is able to predict or guess ISN values. 833 The recommended ISN generator is based on the combination of a 834 (possibly fictitious) 32 bit clock whose low order bit is incremented 835 roughly every 4 microseconds, and a pseudorandom hash function (PRF). 836 The clock component is intended to insure that with a Maximum Segment 837 Lifetime (MSL), generated ISNs will be unique, since it cycles 838 approximately every 4.55 hours, which is much longer than the MSL. 839 This recommended algorithm is further described in RFC 1948 and 840 builds on the basic clock-driven algorithm from RFC 793. 842 A TCP MUST use a clock-driven selection of initial sequence numbers 843 (MUST-8), and SHOULD generate its Initial Sequence Numbers with the 844 expression: 846 ISN = M + F(localip, localport, remoteip, remoteport, secretkey) 848 where M is the 4 microsecond timer, and F() is a pseudorandom 849 function (PRF) of the connection's identifying parameters ("localip, 850 localport, remoteip, remoteport") and a secret key ("secretkey") 851 (SHLD-1). F() MUST NOT be computable from the outside (MUST-9), or 852 an attacker could still guess at sequence numbers from the ISN used 853 for some other connection. The PRF could be implemented as a 854 cryptographic has of the concatenation of the TCP connection 855 parameters and some secret data. For discussion of the selection of 856 a specific hash algorithm and management of the secret key data, 857 please see Section 3 of [32]. 859 For each connection there is a send sequence number and a receive 860 sequence number. The initial send sequence number (ISS) is chosen by 861 the data sending TCP, and the initial receive sequence number (IRS) 862 is learned during the connection establishing procedure. 864 For a connection to be established or initialized, the two TCPs must 865 synchronize on each other's initial sequence numbers. This is done 866 in an exchange of connection establishing segments carrying a control 867 bit called "SYN" (for synchronize) and the initial sequence numbers. 868 As a shorthand, segments carrying the SYN bit are also called "SYNs". 869 Hence, the solution requires a suitable mechanism for picking an 870 initial sequence number and a slightly involved handshake to exchange 871 the ISN's. 873 The synchronization requires each side to send it's own initial 874 sequence number and to receive a confirmation of it in acknowledgment 875 from the other side. Each side must also receive the other side's 876 initial sequence number and send a confirming acknowledgment. 878 1) A --> B SYN my sequence number is X 879 2) A <-- B ACK your sequence number is X 880 3) A <-- B SYN my sequence number is Y 881 4) A --> B ACK your sequence number is Y 883 Because steps 2 and 3 can be combined in a single message this is 884 called the three way (or three message) handshake. 886 A three way handshake is necessary because sequence numbers are not 887 tied to a global clock in the network, and TCPs may have different 888 mechanisms for picking the ISN's. The receiver of the first SYN has 889 no way of knowing whether the segment was an old delayed one or not, 890 unless it remembers the last sequence number used on the connection 891 (which is not always possible), and so it must ask the sender to 892 verify this SYN. The three way handshake and the advantages of a 893 clock-driven scheme are discussed in [46]. 895 Knowing When to Keep Quiet 897 To be sure that a TCP does not create a segment that carries a 898 sequence number which may be duplicated by an old segment remaining 899 in the network, the TCP must keep quiet for an MSL before assigning 900 any sequence numbers upon starting up or recovering from a crash in 901 which memory of sequence numbers in use was lost. For this 902 specification the MSL is taken to be 2 minutes. This is an 903 engineering choice, and may be changed if experience indicates it is 904 desirable to do so. Note that if a TCP is reinitialized in some 905 sense, yet retains its memory of sequence numbers in use, then it 906 need not wait at all; it must only be sure to use sequence numbers 907 larger than those recently used. 909 The TCP Quiet Time Concept 911 This specification provides that hosts which "crash" without 912 retaining any knowledge of the last sequence numbers transmitted on 913 each active (i.e., not closed) connection shall delay emitting any 914 TCP segments for at least the agreed MSL in the internet system of 915 which the host is a part. In the paragraphs below, an explanation 916 for this specification is given. TCP implementors may violate the 917 "quiet time" restriction, but only at the risk of causing some old 918 data to be accepted as new or new data rejected as old duplicated by 919 some receivers in the internet system. 921 TCPs consume sequence number space each time a segment is formed and 922 entered into the network output queue at a source host. The 923 duplicate detection and sequencing algorithm in the TCP protocol 924 relies on the unique binding of segment data to sequence space to the 925 extent that sequence numbers will not cycle through all 2**32 values 926 before the segment data bound to those sequence numbers has been 927 delivered and acknowledged by the receiver and all duplicate copies 928 of the segments have "drained" from the internet. Without such an 929 assumption, two distinct TCP segments could conceivably be assigned 930 the same or overlapping sequence numbers, causing confusion at the 931 receiver as to which data is new and which is old. Remember that 932 each segment is bound to as many consecutive sequence numbers as 933 there are octets of data and SYN or FIN flags in the segment. 935 Under normal conditions, TCPs keep track of the next sequence number 936 to emit and the oldest awaiting acknowledgment so as to avoid 937 mistakenly using a sequence number over before its first use has been 938 acknowledged. This alone does not guarantee that old duplicate data 939 is drained from the net, so the sequence space has been made very 940 large to reduce the probability that a wandering duplicate will cause 941 trouble upon arrival. At 2 megabits/sec. it takes 4.5 hours to use 942 up 2**32 octets of sequence space. Since the maximum segment 943 lifetime in the net is not likely to exceed a few tens of seconds, 944 this is deemed ample protection for foreseeable nets, even if data 945 rates escalate to l0's of megabits/sec. At 100 megabits/sec, the 946 cycle time is 5.4 minutes which may be a little short, but still 947 within reason. 949 The basic duplicate detection and sequencing algorithm in TCP can be 950 defeated, however, if a source TCP does not have any memory of the 951 sequence numbers it last used on a given connection. For example, if 952 the TCP were to start all connections with sequence number 0, then 953 upon crashing and restarting, a TCP might re-form an earlier 954 connection (possibly after half-open connection resolution) and emit 955 packets with sequence numbers identical to or overlapping with 956 packets still in the network which were emitted on an earlier 957 incarnation of the same connection. In the absence of knowledge 958 about the sequence numbers used on a particular connection, the TCP 959 specification recommends that the source delay for MSL seconds before 960 emitting segments on the connection, to allow time for segments from 961 the earlier connection incarnation to drain from the system. 963 Even hosts which can remember the time of day and used it to select 964 initial sequence number values are not immune from this problem 965 (i.e., even if time of day is used to select an initial sequence 966 number for each new connection incarnation). 968 Suppose, for example, that a connection is opened starting with 969 sequence number S. Suppose that this connection is not used much and 970 that eventually the initial sequence number function (ISN(t)) takes 971 on a value equal to the sequence number, say S1, of the last segment 972 sent by this TCP on a particular connection. Now suppose, at this 973 instant, the host crashes, recovers, and establishes a new 974 incarnation of the connection. The initial sequence number chosen is 975 S1 = ISN(t) -- last used sequence number on old incarnation of 976 connection! If the recovery occurs quickly enough, any old 977 duplicates in the net bearing sequence numbers in the neighborhood of 978 S1 may arrive and be treated as new packets by the receiver of the 979 new incarnation of the connection. 981 The problem is that the recovering host may not know for how long it 982 crashed nor does it know whether there are still old duplicates in 983 the system from earlier connection incarnations. 985 One way to deal with this problem is to deliberately delay emitting 986 segments for one MSL after recovery from a crash- this is the "quiet 987 time" specification. Hosts which prefer to avoid waiting are willing 988 to risk possible confusion of old and new packets at a given 989 destination may choose not to wait for the "quite time". 990 Implementors may provide TCP users with the ability to select on a 991 connection by connection basis whether to wait after a crash, or may 992 informally implement the "quite time" for all connections. 993 Obviously, even where a user selects to "wait," this is not necessary 994 after the host has been "up" for at least MSL seconds. 996 To summarize: every segment emitted occupies one or more sequence 997 numbers in the sequence space, the numbers occupied by a segment are 998 "busy" or "in use" until MSL seconds have passed, upon crashing a 999 block of space-time is occupied by the octets and SYN or FIN flags of 1000 the last emitted segment, if a new connection is started too soon and 1001 uses any of the sequence numbers in the space-time footprint of the 1002 last segment of the previous connection incarnation, there is a 1003 potential sequence number overlap area which could cause confusion at 1004 the receiver. 1006 3.4. Establishing a connection 1008 The "three-way handshake" is the procedure used to establish a 1009 connection. This procedure normally is initiated by one TCP and 1010 responded to by another TCP. The procedure also works if two TCP 1011 simultaneously initiate the procedure. When simultaneous attempt 1012 occurs, each TCP receives a "SYN" segment which carries no 1013 acknowledgment after it has sent a "SYN". Of course, the arrival of 1014 an old duplicate "SYN" segment can potentially make it appear, to the 1015 recipient, that a simultaneous connection initiation is in progress. 1016 Proper use of "reset" segments can disambiguate these cases. 1018 Several examples of connection initiation follow. Although these 1019 examples do not show connection synchronization using data-carrying 1020 segments, this is perfectly legitimate, so long as the receiving TCP 1021 doesn't deliver the data to the user until it is clear the data is 1022 valid (i.e., the data must be buffered at the receiver until the 1023 connection reaches the ESTABLISHED state). The three-way handshake 1024 reduces the possibility of false connections. It is the 1025 implementation of a trade-off between memory and messages to provide 1026 information for this checking. 1028 The simplest three-way handshake is shown in Figure 5 below. The 1029 figures should be interpreted in the following way. Each line is 1030 numbered for reference purposes. Right arrows (-->) indicate 1031 departure of a TCP segment from TCP A to TCP B, or arrival of a 1032 segment at B from A. Left arrows (<--), indicate the reverse. 1033 Ellipsis (...) indicates a segment which is still in the network 1034 (delayed). An "XXX" indicates a segment which is lost or rejected. 1035 Comments appear in parentheses. TCP states represent the state AFTER 1036 the departure or arrival of the segment (whose contents are shown in 1037 the center of each line). Segment contents are shown in abbreviated 1038 form, with sequence number, control flags, and ACK field. Other 1039 fields such as window, addresses, lengths, and text have been left 1040 out in the interest of clarity. 1042 TCP A TCP B 1044 1. CLOSED LISTEN 1046 2. SYN-SENT --> --> SYN-RECEIVED 1048 3. ESTABLISHED <-- <-- SYN-RECEIVED 1050 4. ESTABLISHED --> --> ESTABLISHED 1052 5. ESTABLISHED --> --> ESTABLISHED 1054 Basic 3-Way Handshake for Connection Synchronization 1056 Figure 5 1058 In line 2 of Figure 5, TCP A begins by sending a SYN segment 1059 indicating that it will use sequence numbers starting with sequence 1060 number 100. In line 3, TCP B sends a SYN and acknowledges the SYN it 1061 received from TCP A. Note that the acknowledgment field indicates 1062 TCP B is now expecting to hear sequence 101, acknowledging the SYN 1063 which occupied sequence 100. 1065 At line 4, TCP A responds with an empty segment containing an ACK for 1066 TCP B's SYN; and in line 5, TCP A sends some data. Note that the 1067 sequence number of the segment in line 5 is the same as in line 4 1068 because the ACK does not occupy sequence number space (if it did, we 1069 would wind up ACKing ACK's!). 1071 Simultaneous initiation is only slightly more complex, as is shown in 1072 Figure 6. Each TCP cycles from CLOSED to SYN-SENT to SYN-RECEIVED to 1073 ESTABLISHED. 1075 TCP A TCP B 1077 1. CLOSED CLOSED 1079 2. SYN-SENT --> ... 1081 3. SYN-RECEIVED <-- <-- SYN-SENT 1083 4. ... --> SYN-RECEIVED 1085 5. SYN-RECEIVED --> ... 1087 6. ESTABLISHED <-- <-- SYN-RECEIVED 1089 7. ... --> ESTABLISHED 1091 Simultaneous Connection Synchronization 1093 Figure 6 1095 A TCP MUST support simultaneous open attempts (MUST-10). 1097 Note that a TCP implementation MUST keep track of whether a 1098 connection has reached SYN-RECEIVED state as the result of a passive 1099 OPEN or an active OPEN (MUST-11). 1101 The principle reason for the three-way handshake is to prevent old 1102 duplicate connection initiations from causing confusion. To deal 1103 with this, a special control message, reset, has been devised. If 1104 the receiving TCP is in a non-synchronized state (i.e., SYN-SENT, 1105 SYN-RECEIVED), it returns to LISTEN on receiving an acceptable reset. 1106 If the TCP is in one of the synchronized states (ESTABLISHED, FIN- 1107 WAIT-1, FIN-WAIT-2, CLOSE-WAIT, CLOSING, LAST-ACK, TIME-WAIT), it 1108 aborts the connection and informs its user. We discuss this latter 1109 case under "half-open" connections below. 1111 TCP A TCP B 1113 1. CLOSED LISTEN 1115 2. SYN-SENT --> ... 1117 3. (duplicate) ... --> SYN-RECEIVED 1119 4. SYN-SENT <-- <-- SYN-RECEIVED 1121 5. SYN-SENT --> --> LISTEN 1123 6. ... --> SYN-RECEIVED 1125 7. SYN-SENT <-- <-- SYN-RECEIVED 1127 8. ESTABLISHED --> --> ESTABLISHED 1129 Recovery from Old Duplicate SYN 1131 Figure 7 1133 As a simple example of recovery from old duplicates, consider 1134 Figure 7. At line 3, an old duplicate SYN arrives at TCP B. TCP B 1135 cannot tell that this is an old duplicate, so it responds normally 1136 (line 4). TCP A detects that the ACK field is incorrect and returns 1137 a RST (reset) with its SEQ field selected to make the segment 1138 believable. TCP B, on receiving the RST, returns to the LISTEN 1139 state. When the original SYN (pun intended) finally arrives at line 1140 6, the synchronization proceeds normally. If the SYN at line 6 had 1141 arrived before the RST, a more complex exchange might have occurred 1142 with RST's sent in both directions. 1144 Half-Open Connections and Other Anomalies 1146 An established connection is said to be "half-open" if one of the 1147 TCPs has closed or aborted the connection at its end without the 1148 knowledge of the other, or if the two ends of the connection have 1149 become desynchronized owing to a crash that resulted in loss of 1150 memory. Such connections will automatically become reset if an 1151 attempt is made to send data in either direction. However, half-open 1152 connections are expected to be unusual, and the recovery procedure is 1153 mildly involved. 1155 If at site A the connection no longer exists, then an attempt by the 1156 user at site B to send any data on it will result in the site B TCP 1157 receiving a reset control message. Such a message indicates to the 1158 site B TCP that something is wrong, and it is expected to abort the 1159 connection. 1161 Assume that two user processes A and B are communicating with one 1162 another when a crash occurs causing loss of memory to A's TCP. 1163 Depending on the operating system supporting A's TCP, it is likely 1164 that some error recovery mechanism exists. When the TCP is up again, 1165 A is likely to start again from the beginning or from a recovery 1166 point. As a result, A will probably try to OPEN the connection again 1167 or try to SEND on the connection it believes open. In the latter 1168 case, it receives the error message "connection not open" from the 1169 local (A's) TCP. In an attempt to establish the connection, A's TCP 1170 will send a segment containing SYN. This scenario leads to the 1171 example shown in Figure 8. After TCP A crashes, the user attempts to 1172 re-open the connection. TCP B, in the meantime, thinks the 1173 connection is open. 1175 TCP A TCP B 1177 1. (CRASH) (send 300,receive 100) 1179 2. CLOSED ESTABLISHED 1181 3. SYN-SENT --> --> (??) 1183 4. (!!) <-- <-- ESTABLISHED 1185 5. SYN-SENT --> --> (Abort!!) 1187 6. SYN-SENT CLOSED 1189 7. SYN-SENT --> --> 1191 Half-Open Connection Discovery 1193 Figure 8 1195 When the SYN arrives at line 3, TCP B, being in a synchronized state, 1196 and the incoming segment outside the window, responds with an 1197 acknowledgment indicating what sequence it next expects to hear (ACK 1198 100). TCP A sees that this segment does not acknowledge anything it 1199 sent and, being unsynchronized, sends a reset (RST) because it has 1200 detected a half-open connection. TCP B aborts at line 5. TCP A will 1201 continue to try to establish the connection; the problem is now 1202 reduced to the basic 3-way handshake of Figure 5. 1204 An interesting alternative case occurs when TCP A crashes and TCP B 1205 tries to send data on what it thinks is a synchronized connection. 1207 This is illustrated in Figure 9. In this case, the data arriving at 1208 TCP A from TCP B (line 2) is unacceptable because no such connection 1209 exists, so TCP A sends a RST. The RST is acceptable so TCP B 1210 processes it and aborts the connection. 1212 TCP A TCP B 1214 1. (CRASH) (send 300,receive 100) 1216 2. (??) <-- <-- ESTABLISHED 1218 3. --> --> (ABORT!!) 1220 Active Side Causes Half-Open Connection Discovery 1222 Figure 9 1224 In Figure 10, we find the two TCPs A and B with passive connections 1225 waiting for SYN. An old duplicate arriving at TCP B (line 2) stirs B 1226 into action. A SYN-ACK is returned (line 3) and causes TCP A to 1227 generate a RST (the ACK in line 3 is not acceptable). TCP B accepts 1228 the reset and returns to its passive LISTEN state. 1230 TCP A TCP B 1232 1. LISTEN LISTEN 1234 2. ... --> SYN-RECEIVED 1236 3. (??) <-- <-- SYN-RECEIVED 1238 4. --> --> (return to LISTEN!) 1240 5. LISTEN LISTEN 1242 Old Duplicate SYN Initiates a Reset on two Passive Sockets 1244 Figure 10 1246 A variety of other cases are possible, all of which are accounted for 1247 by the following rules for RST generation and processing. 1249 Reset Generation 1250 As a general rule, reset (RST) must be sent whenever a segment 1251 arrives which apparently is not intended for the current connection. 1252 A reset must not be sent if it is not clear that this is the case. 1254 There are three groups of states: 1256 1. If the connection does not exist (CLOSED) then a reset is sent 1257 in response to any incoming segment except another reset. In 1258 particular, SYNs addressed to a non-existent connection are 1259 rejected by this means. 1261 If the incoming segment has the ACK bit set, the reset takes its 1262 sequence number from the ACK field of the segment, otherwise the 1263 reset has sequence number zero and the ACK field is set to the sum 1264 of the sequence number and segment length of the incoming segment. 1265 The connection remains in the CLOSED state. 1267 2. If the connection is in any non-synchronized state (LISTEN, 1268 SYN-SENT, SYN-RECEIVED), and the incoming segment acknowledges 1269 something not yet sent (the segment carries an unacceptable ACK), 1270 or if an incoming segment has a security level or compartment 1271 which does not exactly match the level and compartment requested 1272 for the connection, a reset is sent. 1274 If the incoming segment has an ACK field, the reset takes its 1275 sequence number from the ACK field of the segment, otherwise the 1276 reset has sequence number zero and the ACK field is set to the sum 1277 of the sequence number and segment length of the incoming segment. 1278 The connection remains in the same state. 1280 3. If the connection is in a synchronized state (ESTABLISHED, 1281 FIN-WAIT-1, FIN-WAIT-2, CLOSE-WAIT, CLOSING, LAST-ACK, TIME-WAIT), 1282 any unacceptable segment (out of window sequence number or 1283 unacceptable acknowledgment number) must elicit only an empty 1284 acknowledgment segment containing the current send-sequence number 1285 and an acknowledgment indicating the next sequence number expected 1286 to be received, and the connection remains in the same state. 1288 If an incoming segment has a security level, or compartment which 1289 does not exactly match the level and compartment requested for the 1290 connection, a reset is sent and the connection goes to the CLOSED 1291 state. The reset takes its sequence number from the ACK field of 1292 the incoming segment. 1294 Reset Processing 1296 In all states except SYN-SENT, all reset (RST) segments are validated 1297 by checking their SEQ-fields. A reset is valid if its sequence 1298 number is in the window. In the SYN-SENT state (a RST received in 1299 response to an initial SYN), the RST is acceptable if the ACK field 1300 acknowledges the SYN. 1302 The receiver of a RST first validates it, then changes state. If the 1303 receiver was in the LISTEN state, it ignores it. If the receiver was 1304 in SYN-RECEIVED state and had previously been in the LISTEN state, 1305 then the receiver returns to the LISTEN state, otherwise the receiver 1306 aborts the connection and goes to the CLOSED state. If the receiver 1307 was in any other state, it aborts the connection and advises the user 1308 and goes to the CLOSED state. 1310 TCP SHOULD allow a received RST segment to include data (SHLD-2). 1312 3.5. Closing a Connection 1314 CLOSE is an operation meaning "I have no more data to send." The 1315 notion of closing a full-duplex connection is subject to ambiguous 1316 interpretation, of course, since it may not be obvious how to treat 1317 the receiving side of the connection. We have chosen to treat CLOSE 1318 in a simplex fashion. The user who CLOSEs may continue to RECEIVE 1319 until he is told that the other side has CLOSED also. Thus, a 1320 program could initiate several SENDs followed by a CLOSE, and then 1321 continue to RECEIVE until signaled that a RECEIVE failed because the 1322 other side has CLOSED. We assume that the TCP will signal a user, 1323 even if no RECEIVEs are outstanding, that the other side has closed, 1324 so the user can terminate his side gracefully. A TCP will reliably 1325 deliver all buffers SENT before the connection was CLOSED so a user 1326 who expects no data in return need only wait to hear the connection 1327 was CLOSED successfully to know that all his data was received at the 1328 destination TCP. Users must keep reading connections they close for 1329 sending until the TCP says no more data. 1331 There are essentially three cases: 1333 1) The user initiates by telling the TCP to CLOSE the connection 1335 2) The remote TCP initiates by sending a FIN control signal 1337 3) Both users CLOSE simultaneously 1339 Case 1: Local user initiates the close 1341 In this case, a FIN segment can be constructed and placed on the 1342 outgoing segment queue. No further SENDs from the user will be 1343 accepted by the TCP, and it enters the FIN-WAIT-1 state. RECEIVEs 1344 are allowed in this state. All segments preceding and including 1345 FIN will be retransmitted until acknowledged. When the other TCP 1346 has both acknowledged the FIN and sent a FIN of its own, the first 1347 TCP can ACK this FIN. Note that a TCP receiving a FIN will ACK 1348 but not send its own FIN until its user has CLOSED the connection 1349 also. 1351 Case 2: TCP receives a FIN from the network 1353 If an unsolicited FIN arrives from the network, the receiving TCP 1354 can ACK it and tell the user that the connection is closing. The 1355 user will respond with a CLOSE, upon which the TCP can send a FIN 1356 to the other TCP after sending any remaining data. The TCP then 1357 waits until its own FIN is acknowledged whereupon it deletes the 1358 connection. If an ACK is not forthcoming, after the user timeout 1359 the connection is aborted and the user is told. 1361 Case 3: both users close simultaneously 1363 A simultaneous CLOSE by users at both ends of a connection causes 1364 FIN segments to be exchanged. When all segments preceding the 1365 FINs have been processed and acknowledged, each TCP can ACK the 1366 FIN it has received. Both will, upon receiving these ACKs, delete 1367 the connection. 1369 TCP A TCP B 1371 1. ESTABLISHED ESTABLISHED 1373 2. (Close) 1374 FIN-WAIT-1 --> --> CLOSE-WAIT 1376 3. FIN-WAIT-2 <-- <-- CLOSE-WAIT 1378 4. (Close) 1379 TIME-WAIT <-- <-- LAST-ACK 1381 5. TIME-WAIT --> --> CLOSED 1383 6. (2 MSL) 1384 CLOSED 1386 Normal Close Sequence 1388 Figure 11 1390 TCP A TCP B 1392 1. ESTABLISHED ESTABLISHED 1394 2. (Close) (Close) 1395 FIN-WAIT-1 --> ... FIN-WAIT-1 1396 <-- <-- 1397 ... --> 1399 3. CLOSING --> ... CLOSING 1400 <-- <-- 1401 ... --> 1403 4. TIME-WAIT TIME-WAIT 1404 (2 MSL) (2 MSL) 1405 CLOSED CLOSED 1407 Simultaneous Close Sequence 1409 Figure 12 1411 A TCP connection may terminate in two ways: (1) the normal TCP close 1412 sequence using a FIN handshake, and (2) an "abort" in which one or 1413 more RST segments are sent and the connection state is immediately 1414 discarded. If the local TCP connection is closed by the remote side 1415 due to a FIN or RST received from the remote side, then the local 1416 application MUST be informed whether it closed normally or was 1417 aborted (MUST-12). 1419 3.5.1. Half-Closed Connections 1421 The normal TCP close sequence delivers buffered data reliably in both 1422 directions. Since the two directions of a TCP connection are closed 1423 independently, it is possible for a connection to be "half closed," 1424 i.e., closed in only one direction, and a host is permitted to 1425 continue sending data in the open direction on a half-closed 1426 connection. 1428 A host MAY implement a "half-duplex" TCP close sequence, so that an 1429 application that has called CLOSE cannot continue to read data from 1430 the connection (MAY-1). If such a host issues a CLOSE call while 1431 received data is still pending in TCP, or if new data is received 1432 after CLOSE is called, its TCP SHOULD send a RST to show that data 1433 was lost (SHLD-3). See [17] section 2.17 for discussion. 1435 When a connection is closed actively, it MUST linger in TIME-WAIT 1436 state for a time 2xMSL (Maximum Segment Lifetime) (MUST-13). 1438 However, it MAY accept a new SYN from the remote TCP to reopen the 1439 connection directly from TIME-WAIT state (MAY-2), if it: 1441 (1) assigns its initial sequence number for the new connection to 1442 be larger than the largest sequence number it used on the previous 1443 connection incarnation, and 1445 (2) returns to TIME-WAIT state if the SYN turns out to be an old 1446 duplicate. 1448 When the TCP Timestamp options are available, an improved algorithm 1449 is described in [30] in order to support higher connection 1450 establishment rates. This algorithm for reducing TIME-WAIT is a Best 1451 Current Practice that SHOULD be implemented, since timestamp options 1452 are commonly used, and using them to reduce TIME-WAIT provides 1453 benefits for busy Internet servers (SHLD-4). 1455 3.6. Precedence and Security 1457 The IPv4 specification [1] includes a precedence value in the (now 1458 obsoleted) Type of Service field (TOS) field. It was modified in 1459 [15], and then obsoleted by the definition of Differentiated Services 1460 (DiffServ) [6]. Setting and conveying TOS between the network layer, 1461 TCP, and applications is obsolete, and replaced by DiffServ in the 1462 current TCP specification. 1464 In DiffServ the former precedence values are treated as Class 1465 Selector codepoints, and methods for compatible treatment are 1466 described in the DiffServ architecture. The RFC 793/1122 TCP 1467 specification includes logic intending to have connections use the 1468 highest precedence requested by either endpoint application, and to 1469 keep the precedence consistent throughout a connection. This logic 1470 from the obsolete TOS is not applicable for DiffServ, and should not 1471 be included in TCP implementations, though changes to DiffServ values 1472 within a connection are discouraged. For discussion of this, see RFC 1473 7657 (sec 5.1, 5.3, and 6) [38]. 1475 The obsoleted TOS processing rules in TCP assumed bidirectional (or 1476 symmetric) precedence values used on a connection, but the DiffServ 1477 architecture is asymmetric. Problems with the old TCP logic in this 1478 regard were described in [18] and the solution described is to ignore 1479 IP precedence in TCP. Since RFC 2873 is a Standards Track document 1480 (although not marked as updating RFC 793), current implementations 1481 are expected to be robust to these conditions. Note that the 1482 DiffServ field value used in each direction is a part of the 1483 interface between TCP and the network layer, and values in use can be 1484 indicated both ways between TCP and the application. 1486 The IP security option (IPSO) and compartment defined in [1] was 1487 refined in RFC 1038 that was later obsoleted by RFC 1108. The 1488 Commercial IP Security Option (CIPSO) is defined in FIPS-188, and is 1489 supported by some vendors and operating systems. RFC 1108 is now 1490 Historic, though RFC 791 itself has not been updated to remove the IP 1491 security option. For IPv6, a similar option (CALIPSO) has been 1492 defined [24]. RFC 793 includes logic that includes the IP security/ 1493 compartment information in treatment of TCP segments. References to 1494 the IP "security/compartment" in this document may be relevant for 1495 Multi-Level Secure (MLS) system implementers, but can be ignored for 1496 non-MLS implementations, consistent with running code on the 1497 Internet. See Appendix A.1 for further discussion. Note that RFC 1498 5570 describes some MLS networking scenarios where IPSO, CIPSO, or 1499 CALIPSO may be used. In these special cases, TCP implementers should 1500 see section 7.3.1 of RFC 5570, and follow the guidance in that 1501 document on the relation between IP security. 1503 3.7. Segmentation 1505 The term "segmentation" refers to the activity TCP performs when 1506 ingesting a stream of bytes from a sending application and 1507 packetizing that stream of bytes into TCP segments. Individual TCP 1508 segments often do not correspond one-for-one to individual send (or 1509 socket write) calls from the application. Applications may perform 1510 writes at the granularity of messages in the upper layer protocol, 1511 but TCP guarantees no boundary coherence between the TCP segments 1512 sent and received versus user application data read or write buffer 1513 boundaries. In some specific protocols, such as RDMA using DDP and 1514 MPA [22], there are performance optimizations possible when the 1515 relation between TCP segments and application data units can be 1516 controlled, and MPA includes a specific mechanism for detecting and 1517 verifying this relationship between TCP segments and application 1518 message data strcutures, but this is specific to applications like 1519 RDMA. In general, multiple goals influence the sizing of TCP 1520 segments created by a TCP implementation. 1522 Goals driving the sending of larger segments include: 1524 o Reducing the number of packets in flight within the network. 1526 o Increasing processing efficiency and potential performance by 1527 enabling a smaller number of interrupts and inter-layer 1528 interactions. 1530 o Limiting the overhead of TCP headers. 1532 Note that the performance benefits of sending larger segments may 1533 decrease as the size increases, and there may be boundaries where 1534 advantages are reversed. For instance, on some machines 1025 bytes 1535 within a segment could lead to worse performance than 1024 bytes, due 1536 purely to data alignment on copy operations. 1538 Goals driving the sending of smaller segments include: 1540 o Avoiding sending segments larger than the smallest MTU within an 1541 IP network path, because this results in either packet loss or 1542 fragmentation. Making matters worse, some firewalls or 1543 middleboxes may drop fragmented packets or ICMP messages related 1544 related to fragmentation. 1546 o Preventing delays to the application data stream, especially when 1547 TCP is waiting on the application to generate more data, or when 1548 the application is waiting on an event or input from its peer in 1549 order to generate more data. 1551 o Enabling "fate sharing" between TCP segments and lower-layer data 1552 units (e.g. below IP, for links with cell or frame sizes smaller 1553 than the IP MTU). 1555 Towards meeting these competing sets of goals, TCP includes several 1556 mechanisms, including the Maximum Segment Size option, Path MTU 1557 Discovery, the Nagle algorithm, and support for IPv6 Jumbograms, as 1558 discussed in the following subsections. 1560 3.7.1. Maximum Segment Size Option 1562 TCP MUST implement both sending and receiving the MSS option (MUST- 1563 14). 1565 TCP SHOULD send an MSS option in every SYN segment when its receive 1566 MSS differs from the default 536 for IPv4 or 1220 for IPv6 (SHLD-5), 1567 and MAY send it always (MAY-3). 1569 If an MSS option is not received at connection setup, TCP MUST assume 1570 a default send MSS of 536 (576-40) for IPv4 or 1220 (1280 - 60) for 1571 IPv6 (MUST-15). 1573 The maximum size of a segment that TCP really sends, the "effective 1574 send MSS," MUST be the smaller (MUST-16) of the send MSS (which 1575 reflects the available reassembly buffer size at the remote host, the 1576 EMTU_R [14]) and the largest transmission size permitted by the IP 1577 layer (EMTU_S [14]): 1579 Eff.snd.MSS = 1581 min(SendMSS+20, MMS_S) - TCPhdrsize - IPoptionsize 1583 where: 1585 o SendMSS is the MSS value received from the remote host, or the 1586 default 536 for IPv4 or 1220 for IPv6, if no MSS option is 1587 received. 1589 o MMS_S is the maximum size for a transport-layer message that TCP 1590 may send. 1592 o TCPhdrsize is the size of the fixed TCP header and any options. 1593 This is 20 in the (rare) case that no options are present, but may 1594 be larger if TCP options are to be sent. Note that some options 1595 may not be included on all segments, but that for each segment 1596 sent, the sender should adjust the data length accordingly, within 1597 the Eff.snd.MSS. 1599 o IPoptionsize is the size of any IP options associated with a TCP 1600 connection. Note that some options may not be included on all 1601 packets, but that for each segment sent, the sender should adjust 1602 the data length accordingly, within the Eff.snd.MSS. 1604 The MSS value to be sent in an MSS option should be equal to the 1605 effective MTU minus the fixed IP and TCP headers. By ignoring both 1606 IP and TCP options when calculating the value for the MSS option, if 1607 there are any IP or TCP options to be sent in a packet, then the 1608 sender must decrease the size of the TCP data accordingly. RFC 6691 1609 [33] discusses this in greater detail. 1611 The MSS value to be sent in an MSS option must be less than or equal 1612 to: 1614 MMS_R - 20 1616 where MMS_R is the maximum size for a transport-layer message that 1617 can be received (and reassembled at the IP layer). TCP obtains MMS_R 1618 and MMS_S from the IP layer; see the generic call GET_MAXSIZES in 1619 Section 3.4 of RFC 1122. These are defined in terms of their IP MTU 1620 equivalents, EMTU_R and EMTU_S [14]. 1622 When TCP is used in a situation where either the IP or TCP headers 1623 are not fixed, the sender must reduce the amount of TCP data in any 1624 given packet by the number of octets used by the IP and TCP options. 1625 This has been a point of confusion historically, as explained in RFC 1626 6691, Section 3.1. 1628 3.7.2. Path MTU Discovery 1630 A TCP implementation may be aware of the MTU on directly connected 1631 links, but will rarely have insight about MTUs across an entire 1632 network path. For IPv4, RFC 1122 provides an IP-layer recommendation 1633 on the default effective MTU for sending to be less than or equal to 1634 576 for destinations not directly connected. For IPv6, this would be 1635 1280. In all cases, however, implementation of Path MTU Discovery 1636 (PMTUD) and Packetization Layer Path MTU Discovery (PLPMTUD) is 1637 strongly recommended in order for TCP to improve segmentation 1638 decisions. Both PMTUD and PLPMTUD help TCP choose segment sizes that 1639 avoid both on-path (for IPv4) and source fragmentation (IPv4 and 1640 IPv6). 1642 PMTUD for IPv4 [2] or IPv6 [3] is implemented in conjunction between 1643 TCP, IP, and ICMP protocols. It relies both on avoiding source 1644 fragmentation and setting the IPv4 DF (don't fragment) flag, the 1645 latter to inhibit on-path fragmentation. It relies on ICMP errors 1646 from routers along the path, whenever a segment is too large to 1647 traverse a link. Several adjustments to a TCP implementation with 1648 PMTUD are described in RFC 2923 in order to deal with problems 1649 experienced in practice [8]. PLPMTUD [19] is a Standards Track 1650 improvement to PMTUD that relaxes the requirement for ICMP support 1651 across a path, and improves performance in cases where ICMP is not 1652 consistently conveyed, but still tries to avoid source fragmentation. 1653 The mechanisms in all four of these RFCs are recommended to be 1654 included in TCP implementations. 1656 The TCP MSS option specifies an upper bound for the size of packets 1657 that can be received. Hence, setting the value in the MSS option too 1658 small can impact the ability for PMTUD or PLPMTUD to find a larger 1659 path MTU. RFC 1191 discusses this implication of many older TCP 1660 implementations setting MSS to 536 for non-local destinations, rather 1661 than deriving it from the MTUs of connected interfaces as 1662 recommended. 1664 3.7.3. Interfaces with Variable MTU Values 1666 The effective MTU can sometimes vary, as when used with variable 1667 compression, e.g., RObust Header Compression (ROHC) [26]. It is 1668 tempting for TCP to want to advertise the largest possible MSS, to 1669 support the most efficient use of compressed payloads. 1670 Unfortunately, some compression schemes occasionally need to transmit 1671 full headers (and thus smaller payloads) to resynchronize state at 1672 their endpoint compressors/decompressors. If the largest MTU is used 1673 to calculate the value to advertise in the MSS option, TCP 1674 retransmission may interfere with compressor resynchronization. 1676 As a result, when the effective MTU of an interface varies, TCP 1677 SHOULD use the smallest effective MTU of the interface to calculate 1678 the value to advertise in the MSS option (SHLD-6). 1680 3.7.4. Nagle Algorithm 1682 The "Nagle algorithm" was described in RFC 896 [13] and was 1683 recommended in RFC 1122 [14] for mitigation of an early problem of 1684 too many small packets being generated. It has been implemented in 1685 most current TCP code bases, sometimes with minor variations (see 1686 Appendix A.3). 1688 If there is unacknowledged data (i.e., SND.NXT > SND.UNA), then the 1689 sending TCP buffers all user data (regardless of the PSH bit), until 1690 the outstanding data has been acknowledged or until the TCP can send 1691 a full-sized segment (Eff.snd.MSS bytes). 1693 A TCP SHOULD implement the Nagle Algorithm to coalesce short segments 1694 (SHLD-7). However, there MUST be a way for an application to disable 1695 the Nagle algorithm on an individual connection (MUST-17). In all 1696 cases, sending data is also subject to the limitation imposed by the 1697 Slow Start algorithm [25]. 1699 3.7.5. IPv6 Jumbograms 1701 In order to support TCP over IPv6 jumbograms, implementations need to 1702 be able to send TCP segments larger than the 64KB limit that the MSS 1703 option can convey. RFC 2675 [7] defines that an MSS value of 65,535 1704 bytes is to be treated as infinity, and Path MTU Discovery [3] is 1705 used to determine the actual MSS. 1707 3.8. Data Communication 1709 Once the connection is established data is communicated by the 1710 exchange of segments. Because segments may be lost due to errors 1711 (checksum test failure), or network congestion, TCP uses 1712 retransmission (after a timeout) to ensure delivery of every segment. 1713 Duplicate segments may arrive due to network or TCP retransmission. 1714 As discussed in the section on sequence numbers the TCP performs 1715 certain tests on the sequence and acknowledgment numbers in the 1716 segments to verify their acceptability. 1718 The sender of data keeps track of the next sequence number to use in 1719 the variable SND.NXT. The receiver of data keeps track of the next 1720 sequence number to expect in the variable RCV.NXT. The sender of 1721 data keeps track of the oldest unacknowledged sequence number in the 1722 variable SND.UNA. If the data flow is momentarily idle and all data 1723 sent has been acknowledged then the three variables will be equal. 1725 When the sender creates a segment and transmits it the sender 1726 advances SND.NXT. When the receiver accepts a segment it advances 1727 RCV.NXT and sends an acknowledgment. When the data sender receives 1728 an acknowledgment it advances SND.UNA. The extent to which the 1729 values of these variables differ is a measure of the delay in the 1730 communication. The amount by which the variables are advanced is the 1731 length of the data and SYN or FIN flags in the segment. Note that 1732 once in the ESTABLISHED state all segments must carry current 1733 acknowledgment information. 1735 The CLOSE user call implies a push function, as does the FIN control 1736 flag in an incoming segment. 1738 3.8.1. Retransmission Timeout 1740 Because of the variability of the networks that compose an 1741 internetwork system and the wide range of uses of TCP connections the 1742 retransmission timeout (RTO) must be dynamically determined. 1744 The RTO MUST be computed according to the algorithm in [10], 1745 including Karn's algorithm for taking RTT samples (MUST-18). 1747 RFC 793 contains an early example procedure for computing the RTO. 1748 This was then replaced by the algorithm described in RFC 1122, and 1749 subsequently updated in RFC 2988, and then again in RFC 6298. 1751 If a retransmitted packet is identical to the original packet (which 1752 implies not only that the data boundaries have not changed, but also 1753 that the window and acknowledgment fields of the header have not 1754 changed), then the same IP Identification field MAY be used (see 1755 Section 3.2.1.5 of RFC 1122) (MAY-4). 1757 3.8.2. TCP Congestion Control 1759 RFC 1122 required implementation of Van Jacobson's congestion control 1760 algorithm combining slow start with congestion avoidance. RFC 2581 1761 provided IETF Standards Track description of this, along with fast 1762 retransmit and fast recovery. RFC 5681 is the current description of 1763 these algorithms and is the current standard for TCP congestion 1764 control. 1766 A TCP MUST implement RFC 5681 (MUST-19). 1768 Explicit Congestion Notification (ECN) was defined in RFC 3168 and is 1769 an IETF Standards Track enhancement that has many benefits [39]. 1771 A TCP SHOULD implement ECN as described in RFC 3168 (SHLD-8). 1773 3.8.3. TCP Connection Failures 1775 Excessive retransmission of the same segment by TCP indicates some 1776 failure of the remote host or the Internet path. This failure may be 1777 of short or long duration. The following procedure MUST be used to 1778 handle excessive retransmissions of data segments (MUST-20): 1780 (a) There are two thresholds R1 and R2 measuring the amount of 1781 retransmission that has occurred for the same segment. R1 and R2 1782 might be measured in time units or as a count of retransmissions. 1784 (b) When the number of transmissions of the same segment reaches 1785 or exceeds threshold R1, pass negative advice (see [14] 1786 Section 3.3.1.4) to the IP layer, to trigger dead-gateway 1787 diagnosis. 1789 (c) When the number of transmissions of the same segment reaches a 1790 threshold R2 greater than R1, close the connection. 1792 (d) An application MUST (MUST-21) be able to set the value for R2 1793 for a particular connection. For example, an interactive 1794 application might set R2 to "infinity," giving the user control 1795 over when to disconnect. 1797 (d) TCP SHOULD inform the application of the delivery problem 1798 (unless such information has been disabled by the application; see 1799 Asynchronous Reports section), when R1 is reached and before R2 1800 (SHLD-9). This will allow a remote login (User Telnet) 1801 application program to inform the user, for example. 1803 The value of R1 SHOULD correspond to at least 3 retransmissions, at 1804 the current RTO (SHLD-10). The value of R2 SHOULD correspond to at 1805 least 100 seconds (SHLD-11). 1807 An attempt to open a TCP connection could fail with excessive 1808 retransmissions of the SYN segment or by receipt of a RST segment or 1809 an ICMP Port Unreachable. SYN retransmissions MUST be handled in the 1810 general way just described for data retransmissions, including 1811 notification of the application layer. 1813 However, the values of R1 and R2 may be different for SYN and data 1814 segments. In particular, R2 for a SYN segment MUST be set large 1815 enough to provide retransmission of the segment for at least 3 1816 minutes. The application can close the connection (i.e., give up on 1817 the open attempt) sooner, of course. 1819 3.8.4. TCP Keep-Alives 1821 Implementors MAY include "keep-alives" in their TCP implementations 1822 (MAY-5), although this practice is not universally accepted. If 1823 keep-alives are included, the application MUST be able to turn them 1824 on or off for each TCP connection (MUST-24), and they MUST default to 1825 off (MUST-25). 1827 Keep-alive packets MUST only be sent when no data or acknowledgement 1828 packets have been received for the connection within an interval 1829 (MUST-26). This interval MUST be configurable (MUST-27) and MUST 1830 default to no less than two hours (MUST-28). 1832 It is extremely important to remember that ACK segments that contain 1833 no data are not reliably transmitted by TCP. Consequently, if a 1834 keep-alive mechanism is implemented it MUST NOT interpret failure to 1835 respond to any specific probe as a dead connection (MUST-29). 1837 An implementation SHOULD send a keep-alive segment with no data 1838 (SHLD-12); however, it MAY be configurable to send a keep-alive 1839 segment containing one garbage octet (MAY-6), for compatibility with 1840 erroneous TCP implementations. 1842 3.8.5. The Communication of Urgent Information 1844 As a result of implementation differences and middlebox interactions, 1845 new applications SHOULD NOT employ the TCP urgent mechanism (SHLD- 1846 13). However, TCP implementations MUST still include support for the 1847 urgent mechanism (MUST-30). Details can be found in RFC 6093 [29]. 1849 The objective of the TCP urgent mechanism is to allow the sending 1850 user to stimulate the receiving user to accept some urgent data and 1851 to permit the receiving TCP to indicate to the receiving user when 1852 all the currently known urgent data has been received by the user. 1854 This mechanism permits a point in the data stream to be designated as 1855 the end of urgent information. Whenever this point is in advance of 1856 the receive sequence number (RCV.NXT) at the receiving TCP, that TCP 1857 must tell the user to go into "urgent mode"; when the receive 1858 sequence number catches up to the urgent pointer, the TCP must tell 1859 user to go into "normal mode". If the urgent pointer is updated 1860 while the user is in "urgent mode", the update will be invisible to 1861 the user. 1863 The method employs a urgent field which is carried in all segments 1864 transmitted. The URG control flag indicates that the urgent field is 1865 meaningful and must be added to the segment sequence number to yield 1866 the urgent pointer. The absence of this flag indicates that there is 1867 no urgent data outstanding. 1869 To send an urgent indication the user must also send at least one 1870 data octet. If the sending user also indicates a push, timely 1871 delivery of the urgent information to the destination process is 1872 enhanced. 1874 A TCP MUST support a sequence of urgent data of any length (MUST-31). 1875 [14] 1877 A TCP MUST (MUST-32) inform the application layer asynchronously 1878 whenever it receives an Urgent pointer and there was previously no 1879 pending urgent data, or whenvever the Urgent pointer advances in the 1880 data stream. There MUST (MUST-33) be a way for the application to 1881 learn how much urgent data remains to be read from the connection, or 1882 at least to determine whether or not more urgent data remains to be 1883 read. [14] 1885 3.8.6. Managing the Window 1887 The window sent in each segment indicates the range of sequence 1888 numbers the sender of the window (the data receiver) is currently 1889 prepared to accept. There is an assumption that this is related to 1890 the currently available data buffer space available for this 1891 connection. 1893 The sending TCP packages the data to be transmitted into segments 1894 which fit the current window, and may repackage segments on the 1895 retransmission queue. Such repackaging is not required, but may be 1896 helpful. 1898 In a connection with a one-way data flow, the window information will 1899 be carried in acknowledgment segments that all have the same sequence 1900 number so there will be no way to reorder them if they arrive out of 1901 order. This is not a serious problem, but it will allow the window 1902 information to be on occasion temporarily based on old reports from 1903 the data receiver. A refinement to avoid this problem is to act on 1904 the window information from segments that carry the highest 1905 acknowledgment number (that is segments with acknowledgment number 1906 equal or greater than the highest previously received). 1908 Indicating a large window encourages transmissions. If more data 1909 arrives than can be accepted, it will be discarded. This will result 1910 in excessive retransmissions, adding unnecessarily to the load on the 1911 network and the TCPs. Indicating a small window may restrict the 1912 transmission of data to the point of introducing a round trip delay 1913 between each new segment transmitted. 1915 The mechanisms provided allow a TCP to advertise a large window and 1916 to subsequently advertise a much smaller window without having 1917 accepted that much data. This, so called "shrinking the window," is 1918 strongly discouraged. The robustness principle dictates that TCPs 1919 will not shrink the window themselves, but will be prepared for such 1920 behavior on the part of other TCPs. 1922 A TCP receiver SHOULD NOT shrink the window, i.e., move the right 1923 window edge to the left (SHLD-14). However, a sending TCP MUST be 1924 robust against window shrinking, which may cause the "useable window" 1925 (see Section 3.8.6.2.1) to become negative (MUST-34). 1927 If this happens, the sender SHOULD NOT send new data (SHLD-15), but 1928 SHOULD retransmit normally the old unacknowledged data between 1929 SND.UNA and SND.UNA+SND.WND (SHLD-16). The sender MAY also 1930 retransmit old data beyond SND.UNA+SND.WND (MAY-7), but SHOULD NOT 1931 time out the connection if data beyond the right window edge is not 1932 acknowledged (SHLD-17). If the window shrinks to zero, the TCP MUST 1933 probe it in the standard way (described below) (MUST-35). 1935 3.8.6.1. Zero Window Probing 1937 The sending TCP must be prepared to accept from the user and send at 1938 least one octet of new data even if the send window is zero. The 1939 sending TCP must regularly retransmit to the receiving TCP even when 1940 the window is zero, in order to "probe" the window. Two minutes is 1941 recommended for the retransmission interval when the window is zero. 1942 This retransmission is essential to guarantee that when either TCP 1943 has a zero window the re-opening of the window will be reliably 1944 reported to the other. This is referred to as Zero-Window Probing 1945 (ZWP) in other documents. 1947 Probing of zero (offered) windows MUST be supported (MUST-36). 1949 A TCP MAY keep its offered receive window closed indefinitely (MAY- 1950 8). As long as the receiving TCP continues to send acknowledgments 1951 in response to the probe segments, the sending TCP MUST allow the 1952 connection to stay open (MUST-37). This enables TCP to function in 1953 scenarios such as the "printer ran out of paper" situation described 1954 in Section 4.2.2.17 of RFC1122. The behavior is subject to the 1955 implementation's resource management concerns, as noted in [31]. 1957 When the receiving TCP has a zero window and a segment arrives it 1958 must still send an acknowledgment showing its next expected sequence 1959 number and current window (zero). 1961 3.8.6.2. Silly Window Syndrome Avoidance 1963 The "Silly Window Syndrome" (SWS) is a stable pattern of small 1964 incremental window movements resulting in extremely poor TCP 1965 performance. Algorithms to avoid SWS are described below for both 1966 the sending side and the receiving side. RFC 1122 contains more 1967 detailed discussion of the SWS problem. Note that the Nagle 1968 algorithm and the sender SWS avoidance algorithm play complementary 1969 roles in improving performance. The Nagle algorithm discourages 1970 sending tiny segments when the data to be sent increases in small 1971 increments, while the SWS avoidance algorithm discourages small 1972 segments resulting from the right window edge advancing in small 1973 increments. 1975 3.8.6.2.1. Sender's Algorithm - When to Send Data 1977 A TCP MUST include a SWS avoidance algorithm in the sender (MUST-38). 1979 A TCP SHOULD implement the Nagle Algorithm to coalesce short segments 1980 (SHLD-7). However, there MUST be a way for an application to disable 1981 the Nagle algorithm on an individual connection (MUST-17). In all 1982 cases, sending data is also subject to the limitation imposed by the 1983 Slow Start algorithm. 1985 The sender's SWS avoidance algorithm is more difficult than the 1986 receivers's, because the sender does not know (directly) the 1987 receiver's total buffer space RCV.BUFF. An approach which has been 1988 found to work well is for the sender to calculate Max(SND.WND), the 1989 maximum send window it has seen so far on the connection, and to use 1990 this value as an estimate of RCV.BUFF. Unfortunately, this can only 1991 be an estimate; the receiver may at any time reduce the size of 1992 RCV.BUFF. To avoid a resulting deadlock, it is necessary to have a 1993 timeout to force transmission of data, overriding the SWS avoidance 1994 algorithm. In practice, this timeout should seldom occur. 1996 The "useable window" is: 1998 U = SND.UNA + SND.WND - SND.NXT 2000 i.e., the offered window less the amount of data sent but not 2001 acknowledged. If D is the amount of data queued in the sending TCP 2002 but not yet sent, then the following set of rules is recommended. 2004 Send data: 2006 (1) if a maximum-sized segment can be sent, i.e, if: 2008 min(D,U) >= Eff.snd.MSS; 2010 (2) or if the data is pushed and all queued data can be sent now, 2011 i.e., if: 2013 [SND.NXT = SND.UNA and] PUSHED and D <= U 2015 (the bracketed condition is imposed by the Nagle algorithm); 2017 (3) or if at least a fraction Fs of the maximum window can be sent, 2018 i.e., if: 2020 [SND.NXT = SND.UNA and] 2022 min(D.U) >= Fs * Max(SND.WND); 2024 (4) or if data is PUSHed and the override timeout occurs. 2026 Here Fs is a fraction whose recommended value is 1/2. The override 2027 timeout should be in the range 0.1 - 1.0 seconds. It may be 2028 convenient to combine this timer with the timer used to probe zero 2029 windows (Section Section 3.8.6.1). 2031 3.8.6.2.2. Receiver's Algorithm - When to Send a Window Update 2033 A TCP MUST include a SWS avoidance algorithm in the receiver (MUST- 2034 39). 2036 The receiver's SWS avoidance algorithm determines when the right 2037 window edge may be advanced; this is customarily known as "updating 2038 the window". This algorithm combines with the delayed ACK algorithm 2039 (see Section 3.8.6.3) to determine when an ACK segment containing the 2040 current window will really be sent to the receiver. 2042 The solution to receiver SWS is to avoid advancing the right window 2043 edge RCV.NXT+RCV.WND in small increments, even if data is received 2044 from the network in small segments. 2046 Suppose the total receive buffer space is RCV.BUFF. At any given 2047 moment, RCV.USER octets of this total may be tied up with data that 2048 has been received and acknowledged but which the user process has not 2049 yet consumed. When the connection is quiescent, RCV.WND = RCV.BUFF 2050 and RCV.USER = 0. 2052 Keeping the right window edge fixed as data arrives and is 2053 acknowledged requires that the receiver offer less than its full 2054 buffer space, i.e., the receiver must specify a RCV.WND that keeps 2055 RCV.NXT+RCV.WND constant as RCV.NXT increases. Thus, the total 2056 buffer space RCV.BUFF is generally divided into three parts: 2058 |<------- RCV.BUFF ---------------->| 2059 1 2 3 2060 ----|---------|------------------|------|---- 2061 RCV.NXT ^ 2062 (Fixed) 2064 1 - RCV.USER = data received but not yet consumed; 2065 2 - RCV.WND = space advertised to sender; 2066 3 - Reduction = space available but not yet 2067 advertised. 2069 The suggested SWS avoidance algorithm for the receiver is to keep 2070 RCV.NXT+RCV.WND fixed until the reduction satisfies: 2072 RCV.BUFF - RCV.USER - RCV.WND >= 2074 min( Fr * RCV.BUFF, Eff.snd.MSS ) 2076 where Fr is a fraction whose recommended value is 1/2, and 2077 Eff.snd.MSS is the effective send MSS for the connection (see 2078 Section 3.7.1). When the inequality is satisfied, RCV.WND is set to 2079 RCV.BUFF-RCV.USER. 2081 Note that the general effect of this algorithm is to advance RCV.WND 2082 in increments of Eff.snd.MSS (for realistic receive buffers: 2083 Eff.snd.MSS < RCV.BUFF/2). Note also that the receiver must use its 2084 own Eff.snd.MSS, assuming it is the same as the sender's. 2086 3.8.6.3. Delayed Acknowledgements - When to Send an ACK Segment 2088 A host that is receiving a stream of TCP data segments can increase 2089 efficiency in both the Internet and the hosts by sending fewer than 2090 one ACK (acknowledgment) segment per data segment received; this is 2091 known as a "delayed ACK". 2093 A TCP SHOULD implement a delayed ACK (SHLD-18), but an ACK should not 2094 be excessively delayed; in particular, the delay MUST be less than 2095 0.5 seconds (MUST-40), and in a stream of full-sized segments there 2096 SHOULD be an ACK for at least every second segment (SHLD-19). 2097 Excessive delays on ACK's can disturb the round-trip timing and 2098 packet "clocking" algorithms. 2100 3.9. Interfaces 2102 There are of course two interfaces of concern: the user/TCP interface 2103 and the TCP/lower-level interface. We have a fairly elaborate model 2104 of the user/TCP interface, but the interface to the lower level 2105 protocol module is left unspecified here, since it will be specified 2106 in detail by the specification of the lower level protocol. For the 2107 case that the lower level is IP we note some of the parameter values 2108 that TCPs might use. 2110 3.9.1. User/TCP Interface 2112 The following functional description of user commands to the TCP is, 2113 at best, fictional, since every operating system will have different 2114 facilities. Consequently, we must warn readers that different TCP 2115 implementations may have different user interfaces. However, all 2116 TCPs must provide a certain minimum set of services to guarantee that 2117 all TCP implementations can support the same protocol hierarchy. 2118 This section specifies the functional interfaces required of all TCP 2119 implementations. 2121 TCP User Commands 2123 The following sections functionally characterize a USER/TCP 2124 interface. The notation used is similar to most procedure or 2125 function calls in high level languages, but this usage is not 2126 meant to rule out trap type service calls (e.g., SVCs, UUOs, 2127 EMTs). 2129 The user commands described below specify the basic functions the 2130 TCP must perform to support interprocess communication. 2131 Individual implementations must define their own exact format, and 2132 may provide combinations or subsets of the basic functions in 2133 single calls. In particular, some implementations may wish to 2134 automatically OPEN a connection on the first SEND or RECEIVE 2135 issued by the user for a given connection. 2137 In providing interprocess communication facilities, the TCP must 2138 not only accept commands, but must also return information to the 2139 processes it serves. The latter consists of: 2141 (a) general information about a connection (e.g., interrupts, 2142 remote close, binding of unspecified foreign socket). 2144 (b) replies to specific user commands indicating success or 2145 various types of failure. 2147 Open 2149 Format: OPEN (local port, foreign socket, active/passive [, 2150 timeout] [, DiffServ field] [, security/compartment] [local IP 2151 address,] [, options]) -> local connection name 2152 We assume that the local TCP is aware of the identity of the 2153 processes it serves and will check the authority of the process 2154 to use the connection specified. Depending upon the 2155 implementation of the TCP, the local network and TCP 2156 identifiers for the source address will either be supplied by 2157 the TCP or the lower level protocol (e.g., IP). These 2158 considerations are the result of concern about security, to the 2159 extent that no TCP be able to masquerade as another one, and so 2160 on. Similarly, no process can masquerade as another without 2161 the collusion of the TCP. 2163 If the active/passive flag is set to passive, then this is a 2164 call to LISTEN for an incoming connection. A passive open may 2165 have either a fully specified foreign socket to wait for a 2166 particular connection or an unspecified foreign socket to wait 2167 for any call. A fully specified passive call can be made 2168 active by the subsequent execution of a SEND. 2170 A transmission control block (TCB) is created and partially 2171 filled in with data from the OPEN command parameters. 2173 Every passive OPEN call either creates a new connection record 2174 in LISTEN state, or it returns an error; it MUST NOT affect any 2175 previously created connection record (MUST-41). 2177 A TCP that supports multiple concurrent users MUST provide an 2178 OPEN call that will functionally allow an application to LISTEN 2179 on a port while a connection block with the same local port is 2180 in SYN-SENT or SYN-RECEIVED state (MUST-42). 2182 On an active OPEN command, the TCP will begin the procedure to 2183 synchronize (i.e., establish) the connection at once. 2185 The timeout, if present, permits the caller to set up a timeout 2186 for all data submitted to TCP. If data is not successfully 2187 delivered to the destination within the timeout period, the TCP 2188 will abort the connection. The present global default is five 2189 minutes. 2191 The TCP or some component of the operating system will verify 2192 the users authority to open a connection with the specified 2193 DiffServ field value or security/compartment. The absence of a 2194 DiffServ field value or security/compartment specification in 2195 the OPEN call indicates the default values must be used. 2197 TCP will accept incoming requests as matching only if the 2198 security/compartment information is exactly the same as that 2199 requested in the OPEN call. 2201 The DiffServ field value indicated by the user only impacts 2202 outgoing packets, may be altered en route through the network, 2203 and has no direct bearing or relation to received packets. 2205 A local connection name will be returned to the user by the 2206 TCP. The local connection name can then be used as a short 2207 hand term for the connection defined by the pair. 2210 The optional "local IP address" parameter MUST be supported to 2211 allow the specification of the local IP address. This enables 2212 applications that need to select the local IP address used when 2213 multihoming is present (MUST-43). 2215 A passive OPEN call with a specified "local IP address" 2216 parameter will await an incoming connection request to that 2217 address. If the parameter is unspecified, a passive OPEN will 2218 await an incoming connection request to any local IP address, 2219 and then bind the local IP address of the connection to the 2220 particular address that is used. 2222 For an active OPEN call, a specified "local IP address" 2223 parameter MUST be used for opening the connection (MUST-43). 2224 If the parameter is unspecified, the host will choose an 2225 appropriate local IP address (see RFC 1122 section 2226 3.3.4.2).Editor's note: should this replace the paragraph with 2227 MUST-43 two paragraphs above? These seem to be duplicative of 2228 one another (first from 793, then from 1122)? TBD 2230 If an application on a multihomed host does not specify the 2231 local IP address when actively opening a TCP connection, then 2232 the TCP MUST ask the IP layer to select a local IP address 2233 before sending the (first) SYN (MUST-44). See the function 2234 GET_SRCADDR() in Section 3.4 of RFC 1122. 2236 At all other times, a previous segment has either been sent or 2237 received on this connection, and TCP MUST use the same local 2238 address is used that was used in those previous segments (MUST- 2239 45). 2241 A TCP implementation MUST reject as an error a local OPEN call 2242 for an invalid remote IP address (e.g., a broadcast or 2243 multicast address) (MUST-46). 2245 Send 2247 Format: SEND (local connection name, buffer address, byte 2248 count, PUSH flag, URGENT flag [,timeout]) 2249 This call causes the data contained in the indicated user 2250 buffer to be sent on the indicated connection. If the 2251 connection has not been opened, the SEND is considered an 2252 error. Some implementations may allow users to SEND first; in 2253 which case, an automatic OPEN would be done. For example, this 2254 might be one way for application data to be included in SYN 2255 segments. If the calling process is not authorized to use this 2256 connection, an error is returned. 2258 If the PUSH flag is set, the data must be transmitted promptly 2259 to the receiver, and the PUSH bit will be set in the last TCP 2260 segment created from the buffer. If the PUSH flag is not set, 2261 the data may be combined with data from subsequent SENDs for 2262 transmission efficiency. Note that when the Nagle algorithm is 2263 in use, TCP may buffer the data before sending, without regard 2264 to the PUSH flag (see Section 3.7.4). 2266 New applications SHOULD NOT set the URGENT flag [29] due to 2267 implementation differences and middlebox issues (SHLD-13). 2269 If the URGENT flag is set, segments sent to the destination TCP 2270 will have the urgent pointer set. The receiving TCP will 2271 signal the urgent condition to the receiving process if the 2272 urgent pointer indicates that data preceding the urgent pointer 2273 has not been consumed by the receiving process. The purpose of 2274 urgent is to stimulate the receiver to process the urgent data 2275 and to indicate to the receiver when all the currently known 2276 urgent data has been received. The number of times the sending 2277 user's TCP signals urgent will not necessarily be equal to the 2278 number of times the receiving user will be notified of the 2279 presence of urgent data. 2281 If no foreign socket was specified in the OPEN, but the 2282 connection is established (e.g., because a LISTENing connection 2283 has become specific due to a foreign segment arriving for the 2284 local socket), then the designated buffer is sent to the 2285 implied foreign socket. Users who make use of OPEN with an 2286 unspecified foreign socket can make use of SEND without ever 2287 explicitly knowing the foreign socket address. 2289 However, if a SEND is attempted before the foreign socket 2290 becomes specified, an error will be returned. Users can use 2291 the STATUS call to determine the status of the connection. In 2292 some implementations the TCP may notify the user when an 2293 unspecified socket is bound. 2295 If a timeout is specified, the current user timeout for this 2296 connection is changed to the new one. 2298 In the simplest implementation, SEND would not return control 2299 to the sending process until either the transmission was 2300 complete or the timeout had been exceeded. However, this 2301 simple method is both subject to deadlocks (for example, both 2302 sides of the connection might try to do SENDs before doing any 2303 RECEIVEs) and offers poor performance, so it is not 2304 recommended. A more sophisticated implementation would return 2305 immediately to allow the process to run concurrently with 2306 network I/O, and, furthermore, to allow multiple SENDs to be in 2307 progress. Multiple SENDs are served in first come, first 2308 served order, so the TCP will queue those it cannot service 2309 immediately. 2311 We have implicitly assumed an asynchronous user interface in 2312 which a SEND later elicits some kind of SIGNAL or pseudo- 2313 interrupt from the serving TCP. An alternative is to return a 2314 response immediately. For instance, SENDs might return 2315 immediate local acknowledgment, even if the segment sent had 2316 not been acknowledged by the distant TCP. We could 2317 optimistically assume eventual success. If we are wrong, the 2318 connection will close anyway due to the timeout. In 2319 implementations of this kind (synchronous), there will still be 2320 some asynchronous signals, but these will deal with the 2321 connection itself, and not with specific segments or buffers. 2323 In order for the process to distinguish among error or success 2324 indications for different SENDs, it might be appropriate for 2325 the buffer address to be returned along with the coded response 2326 to the SEND request. TCP-to-user signals are discussed below, 2327 indicating the information which should be returned to the 2328 calling process. 2330 Receive 2332 Format: RECEIVE (local connection name, buffer address, byte 2333 count) -> byte count, urgent flag, push flag 2335 This command allocates a receiving buffer associated with the 2336 specified connection. If no OPEN precedes this command or the 2337 calling process is not authorized to use this connection, an 2338 error is returned. 2340 In the simplest implementation, control would not return to the 2341 calling program until either the buffer was filled, or some 2342 error occurred, but this scheme is highly subject to deadlocks. 2343 A more sophisticated implementation would permit several 2344 RECEIVEs to be outstanding at once. These would be filled as 2345 segments arrive. This strategy permits increased throughput at 2346 the cost of a more elaborate scheme (possibly asynchronous) to 2347 notify the calling program that a PUSH has been seen or a 2348 buffer filled. 2350 If enough data arrive to fill the buffer before a PUSH is seen, 2351 the PUSH flag will not be set in the response to the RECEIVE. 2352 The buffer will be filled with as much data as it can hold. If 2353 a PUSH is seen before the buffer is filled the buffer will be 2354 returned partially filled and PUSH indicated. 2356 If there is urgent data the user will have been informed as 2357 soon as it arrived via a TCP-to-user signal. The receiving 2358 user should thus be in "urgent mode". If the URGENT flag is 2359 on, additional urgent data remains. If the URGENT flag is off, 2360 this call to RECEIVE has returned all the urgent data, and the 2361 user may now leave "urgent mode". Note that data following the 2362 urgent pointer (non-urgent data) cannot be delivered to the 2363 user in the same buffer with preceding urgent data unless the 2364 boundary is clearly marked for the user. 2366 To distinguish among several outstanding RECEIVEs and to take 2367 care of the case that a buffer is not completely filled, the 2368 return code is accompanied by both a buffer pointer and a byte 2369 count indicating the actual length of the data received. 2371 Alternative implementations of RECEIVE might have the TCP 2372 allocate buffer storage, or the TCP might share a ring buffer 2373 with the user. 2375 Close 2377 Format: CLOSE (local connection name) 2379 This command causes the connection specified to be closed. If 2380 the connection is not open or the calling process is not 2381 authorized to use this connection, an error is returned. 2382 Closing connections is intended to be a graceful operation in 2383 the sense that outstanding SENDs will be transmitted (and 2384 retransmitted), as flow control permits, until all have been 2385 serviced. Thus, it should be acceptable to make several SEND 2386 calls, followed by a CLOSE, and expect all the data to be sent 2387 to the destination. It should also be clear that users should 2388 continue to RECEIVE on CLOSING connections, since the other 2389 side may be trying to transmit the last of its data. Thus, 2390 CLOSE means "I have no more to send" but does not mean "I will 2391 not receive any more." It may happen (if the user level 2392 protocol is not well thought out) that the closing side is 2393 unable to get rid of all its data before timing out. In this 2394 event, CLOSE turns into ABORT, and the closing TCP gives up. 2396 The user may CLOSE the connection at any time on his own 2397 initiative, or in response to various prompts from the TCP 2398 (e.g., remote close executed, transmission timeout exceeded, 2399 destination inaccessible). 2401 Because closing a connection requires communication with the 2402 foreign TCP, connections may remain in the closing state for a 2403 short time. Attempts to reopen the connection before the TCP 2404 replies to the CLOSE command will result in error responses. 2406 Close also implies push function. 2408 Status 2410 Format: STATUS (local connection name) -> status data 2412 This is an implementation dependent user command and could be 2413 excluded without adverse effect. Information returned would 2414 typically come from the TCB associated with the connection. 2416 This command returns a data block containing the following 2417 information: 2419 local socket, 2420 foreign socket, 2421 local connection name, 2422 receive window, 2423 send window, 2424 connection state, 2425 number of buffers awaiting acknowledgment, 2426 number of buffers pending receipt, 2427 urgent state, 2428 DiffServ field value, 2429 security/compartment, 2430 and transmission timeout. 2432 Depending on the state of the connection, or on the 2433 implementation itself, some of this information may not be 2434 available or meaningful. If the calling process is not 2435 authorized to use this connection, an error is returned. This 2436 prevents unauthorized processes from gaining information about 2437 a connection. 2439 Abort 2440 Format: ABORT (local connection name) 2442 This command causes all pending SENDs and RECEIVES to be 2443 aborted, the TCB to be removed, and a special RESET message to 2444 be sent to the TCP on the other side of the connection. 2445 Depending on the implementation, users may receive abort 2446 indications for each outstanding SEND or RECEIVE, or may simply 2447 receive an ABORT-acknowledgment. 2449 Flush 2451 Some TCP implementations have included a FLUSH call, which will 2452 empty the TCP send queue of any data for which the user has 2453 issued SEND calls but which is still to the right of the 2454 current send window. That is, it flushes as much queued send 2455 data as possible without losing sequence number 2456 synchronization. The FLUSH call MAY be implemented (MAY-14). 2458 Asynchronous Reports 2460 There MUST be a mechanism for reporting soft TCP error 2461 conditions to the application (MUST-47). Generically, we 2462 assume this takes the form of an application-supplied 2463 ERROR_REPORT routine that may be upcalled asynchronously from 2464 the transport layer: 2466 ERROR_REPORT(local connection name, reason, subreason) 2468 The precise encoding of the reason and subreason parameters is 2469 not specified here. However, the conditions that are reported 2470 asynchronously to the application MUST include: 2472 * ICMP error message arrived (see Section 3.9.2.2) (MUST- 2473 TBD) 2475 * Excessive retransmissions (see Section 3.8.3) (MUST-TBD) 2477 * Urgent pointer advance (see Section 3.8.5) (MUST-32). 2479 However, an application program that does not want to receive 2480 such ERROR_REPORT calls SHOULD be able to effectively disable 2481 these calls (SHLD-20). 2483 Set Differentiated Services Field (IPv4 TOS or IPv6 Traffic Class) 2485 The application layer MUST be able to specify the 2486 Differentiated Services field for segments that are sent on a 2487 connection (MUST-48). The Differentiated Services field 2488 includes the 6-bit Differentiated Services Code Point (DSCP) 2489 value. It is not required, but the application SHOULD be able 2490 to change the Differentiated Services field during the 2491 connection lifetime (SHLD-21). TCP SHOULD pass the current 2492 Differentiated Services field value without change to the IP 2493 layer, when it sends segments on the connection (SHLD-22). 2495 The Differentiated Services field will be specified 2496 independently in each direction on the connection, so that the 2497 receiver application will specify the Differentiated Services 2498 field used for ACK segments. 2500 TCP MAY pass the most recently received Differentiated Services 2501 field up to the application (MAY-9). 2503 3.9.2. TCP/Lower-Level Interface 2505 The TCP calls on a lower level protocol module to actually send and 2506 receive information over a network. The two current standard 2507 Internet Protocol (IP) versions layered below TCP are IPv4 [1] and 2508 IPv6 [5]. 2510 If the lower level protocol is IPv4 it provides arguments for a type 2511 of service (used within the Differentiated Services field) and for a 2512 time to live. TCP uses the following settings for these parameters: 2514 DiffServ field: The IP header value for the DiffServ field is 2515 given by the user. This includes the bits of the DiffServ Code 2516 Point (DSCP). 2518 Time to Live (TTL): The TTL value used to send TCP segments MUST 2519 be configurable (MUST-49). 2521 Note that RFC 793 specified one minute (60 seconds) as a 2522 constant for the TTL, because the assumed maximum segment 2523 lifetime was two minutes. This was intended to explicitly ask 2524 that a segment be destroyed if it cannot be delivered by the 2525 internet system within one minute. RFC 1122 changed this 2526 specification to require that the TTL be configurable. 2528 Note that the DiffServ field is permitted to change during a 2529 connection (section 4.2.4.2 of RFC 1122). However, the 2530 application interface might not support this ability, and the 2531 application does not have knowledge about individual TCP 2532 segments, so this can only be done on a coarse granularity, at 2533 best. This limitation is further discussed in RFC 7657 (sec 2534 5.1, 5.3, and 6) [38]. Generally, an application SHOULD NOT 2535 change the DiffServ field value during the course of a 2536 connection (SHLD-23). 2538 Any lower level protocol will have to provide the source address, 2539 destination address, and protocol fields, and some way to determine 2540 the "TCP length", both to provide the functional equivalent service 2541 of IP and to be used in the TCP checksum. 2543 When received options are passed up to TCP from the IP layer, TCP 2544 MUST ignore options that it does not understand (MUST-50). 2546 A TCP MAY support the Time Stamp (MAY-10) and Record Route (MAY-11) 2547 options. 2549 3.9.2.1. Source Routing 2551 If the lower level is IP (or other protocol that provides this 2552 feature) and source routing is used, the interface must allow the 2553 route information to be communicated. This is especially important 2554 so that the source and destination addresses used in the TCP checksum 2555 be the originating source and ultimate destination. It is also 2556 important to preserve the return route to answer connection requests. 2558 An application MUST be able to specify a source route when it 2559 actively opens a TCP connection (MUST-51), and this MUST take 2560 precedence over a source route received in a datagram (MUST-52). 2562 When a TCP connection is OPENed passively and a packet arrives with a 2563 completed IP Source Route option (containing a return route), TCP 2564 MUST save the return route and use it for all segments sent on this 2565 connection (MUST-53). If a different source route arrives in a later 2566 segment, the later definition SHOULD override the earlier one (SHLD- 2567 24). 2569 3.9.2.2. ICMP Messages 2571 TCP MUST act on an ICMP error message passed up from the IP layer, 2572 directing it to the connection that created the error (MUST-54). The 2573 necessary demultiplexing information can be found in the IP header 2574 contained within the ICMP message. 2576 This applies to ICMPv6 in addition to IPv4 ICMP. 2578 [23] contains discussion of specific ICMP and ICMPv6 messages 2579 classified as either "soft" or "hard" errors that may bear different 2580 responses. Treatment for classes of ICMP messages is described 2581 below: 2583 Source Quench 2584 TCP MUST silently discard any received ICMP Source Quench messages 2585 (MUST-55). See [11] for discussion. 2587 Soft Errors 2588 For ICMP these include: Destination Unreachable -- codes 0, 1, 5, 2589 Time Exceeded -- codes 0, 1, and Parameter Problem. 2590 For ICMPv6 these include: Destination Unreachable -- codes 0 and 3, 2591 Time Exceeded -- codes 0, 1, and Parameter Problem -- codes 0, 1, 2 2592 Since these Unreachable messages indicate soft error conditions, 2593 TCP MUST NOT abort the connection (MUST-56), and it SHOULD make the 2594 information available to the application (SHLD-25). 2596 Hard Errors 2597 For ICMP these include Destination Unreachable -- codes 2-4"> 2598 These are hard error conditions, so TCP SHOULD abort the connection 2599 (SHLD-26). [23] notes that some implementations do not abort 2600 connections when an ICMP hard error is received for a connection 2601 that is in any of the synchronized states. 2603 Note that [23] section 4 describes widespread implementation behavior 2604 that treats soft errors as hard errors during connection 2605 establishment. 2607 3.9.2.3. Remote Address Validation 2609 RFC 1122 requires addresses to be validated in incoming SYN packets: 2611 An incoming SYN with an invalid source address must be ignored 2612 either by TCP or by the IP layer (see Section 3.2.1.3 of [14]). 2614 A TCP implementation MUST silently discard an incoming SYN segment 2615 that is addressed to a broadcast or multicast address (MUST-57). 2617 This prevents connection state and replies from being erroneously 2618 generated, and implementers should note that this guidance is 2619 applicable to all incoming segments, not just SYNs, as specifically 2620 indicated in RFC 1122. 2622 3.10. Event Processing 2624 The processing depicted in this section is an example of one possible 2625 implementation. Other implementations may have slightly different 2626 processing sequences, but they should differ from those in this 2627 section only in detail, not in substance. 2629 The activity of the TCP can be characterized as responding to events. 2630 The events that occur can be cast into three categories: user calls, 2631 arriving segments, and timeouts. This section describes the 2632 processing the TCP does in response to each of the events. In many 2633 cases the processing required depends on the state of the connection. 2635 Events that occur: 2637 User Calls 2639 OPEN 2640 SEND 2641 RECEIVE 2642 CLOSE 2643 ABORT 2644 STATUS 2646 Arriving Segments 2648 SEGMENT ARRIVES 2650 Timeouts 2652 USER TIMEOUT 2653 RETRANSMISSION TIMEOUT 2654 TIME-WAIT TIMEOUT 2656 The model of the TCP/user interface is that user commands receive an 2657 immediate return and possibly a delayed response via an event or 2658 pseudo interrupt. In the following descriptions, the term "signal" 2659 means cause a delayed response. 2661 Error responses are given as character strings. For example, user 2662 commands referencing connections that do not exist receive "error: 2663 connection not open". 2665 Please note in the following that all arithmetic on sequence numbers, 2666 acknowledgment numbers, windows, et cetera, is modulo 2**32 the size 2667 of the sequence number space. Also note that "=<" means less than or 2668 equal to (modulo 2**32). 2670 A natural way to think about processing incoming segments is to 2671 imagine that they are first tested for proper sequence number (i.e., 2672 that their contents lie in the range of the expected "receive window" 2673 in the sequence number space) and then that they are generally queued 2674 and processed in sequence number order. 2676 When a segment overlaps other already received segments we 2677 reconstruct the segment to contain just the new data, and adjust the 2678 header fields to be consistent. 2680 Note that if no state change is mentioned the TCP stays in the same 2681 state. 2683 OPEN Call 2685 CLOSED STATE (i.e., TCB does not exist) 2687 Create a new transmission control block (TCB) to hold 2688 connection state information. Fill in local socket identifier, 2689 foreign socket, DiffServ field, security/compartment, and user 2690 timeout information. Note that some parts of the foreign 2691 socket may be unspecified in a passive OPEN and are to be 2692 filled in by the parameters of the incoming SYN segment. 2693 Verify the security and DiffServ value requested are allowed 2694 for this user, if not return "error: precedence not allowed" or 2695 "error: security/compartment not allowed." If passive enter 2696 the LISTEN state and return. If active and the foreign socket 2697 is unspecified, return "error: foreign socket unspecified"; if 2698 active and the foreign socket is specified, issue a SYN 2699 segment. An initial send sequence number (ISS) is selected. A 2700 SYN segment of the form is sent. Set 2701 SND.UNA to ISS, SND.NXT to ISS+1, enter SYN-SENT state, and 2702 return. 2704 If the caller does not have access to the local socket 2705 specified, return "error: connection illegal for this process". 2706 If there is no room to create a new connection, return "error: 2707 insufficient resources". 2709 LISTEN STATE 2711 If active and the foreign socket is specified, then change the 2712 connection from passive to active, select an ISS. Send a SYN 2713 segment, set SND.UNA to ISS, SND.NXT to ISS+1. Enter SYN-SENT 2714 state. Data associated with SEND may be sent with SYN segment 2715 or queued for transmission after entering ESTABLISHED state. 2716 The urgent bit if requested in the command must be sent with 2717 the data segments sent as a result of this command. If there 2718 is no room to queue the request, respond with "error: 2719 insufficient resources". If Foreign socket was not specified, 2720 then return "error: foreign socket unspecified". 2722 SYN-SENT STATE 2723 SYN-RECEIVED STATE 2724 ESTABLISHED STATE 2725 FIN-WAIT-1 STATE 2726 FIN-WAIT-2 STATE 2727 CLOSE-WAIT STATE 2728 CLOSING STATE 2729 LAST-ACK STATE 2730 TIME-WAIT STATE 2732 Return "error: connection already exists". 2734 SEND Call 2736 CLOSED STATE (i.e., TCB does not exist) 2738 If the user does not have access to such a connection, then 2739 return "error: connection illegal for this process". 2741 Otherwise, return "error: connection does not exist". 2743 LISTEN STATE 2745 If the foreign socket is specified, then change the connection 2746 from passive to active, select an ISS. Send a SYN segment, set 2747 SND.UNA to ISS, SND.NXT to ISS+1. Enter SYN-SENT state. Data 2748 associated with SEND may be sent with SYN segment or queued for 2749 transmission after entering ESTABLISHED state. The urgent bit 2750 if requested in the command must be sent with the data segments 2751 sent as a result of this command. If there is no room to queue 2752 the request, respond with "error: insufficient resources". If 2753 Foreign socket was not specified, then return "error: foreign 2754 socket unspecified". 2756 SYN-SENT STATE 2757 SYN-RECEIVED STATE 2759 Queue the data for transmission after entering ESTABLISHED 2760 state. If no space to queue, respond with "error: insufficient 2761 resources". 2763 ESTABLISHED STATE 2764 CLOSE-WAIT STATE 2766 Segmentize the buffer and send it with a piggybacked 2767 acknowledgment (acknowledgment value = RCV.NXT). If there is 2768 insufficient space to remember this buffer, simply return 2769 "error: insufficient resources". 2771 If the urgent flag is set, then SND.UP <- SND.NXT and set the 2772 urgent pointer in the outgoing segments. 2774 FIN-WAIT-1 STATE 2775 FIN-WAIT-2 STATE 2776 CLOSING STATE 2777 LAST-ACK STATE 2778 TIME-WAIT STATE 2780 Return "error: connection closing" and do not service request. 2782 RECEIVE Call 2784 CLOSED STATE (i.e., TCB does not exist) 2786 If the user does not have access to such a connection, return 2787 "error: connection illegal for this process". 2789 Otherwise return "error: connection does not exist". 2791 LISTEN STATE 2792 SYN-SENT STATE 2793 SYN-RECEIVED STATE 2795 Queue for processing after entering ESTABLISHED state. If 2796 there is no room to queue this request, respond with "error: 2797 insufficient resources". 2799 ESTABLISHED STATE 2800 FIN-WAIT-1 STATE 2801 FIN-WAIT-2 STATE 2803 If insufficient incoming segments are queued to satisfy the 2804 request, queue the request. If there is no queue space to 2805 remember the RECEIVE, respond with "error: insufficient 2806 resources". 2808 Reassemble queued incoming segments into receive buffer and 2809 return to user. Mark "push seen" (PUSH) if this is the case. 2811 If RCV.UP is in advance of the data currently being passed to 2812 the user notify the user of the presence of urgent data. 2814 When the TCP takes responsibility for delivering data to the 2815 user that fact must be communicated to the sender via an 2816 acknowledgment. The formation of such an acknowledgment is 2817 described below in the discussion of processing an incoming 2818 segment. 2820 CLOSE-WAIT STATE 2822 Since the remote side has already sent FIN, RECEIVEs must be 2823 satisfied by text already on hand, but not yet delivered to the 2824 user. If no text is awaiting delivery, the RECEIVE will get a 2825 "error: connection closing" response. Otherwise, any remaining 2826 text can be used to satisfy the RECEIVE. 2828 CLOSING STATE 2829 LAST-ACK STATE 2830 TIME-WAIT STATE 2832 Return "error: connection closing". 2834 CLOSE Call 2836 CLOSED STATE (i.e., TCB does not exist) 2838 If the user does not have access to such a connection, return 2839 "error: connection illegal for this process". 2841 Otherwise, return "error: connection does not exist". 2843 LISTEN STATE 2845 Any outstanding RECEIVEs are returned with "error: closing" 2846 responses. Delete TCB, enter CLOSED state, and return. 2848 SYN-SENT STATE 2850 Delete the TCB and return "error: closing" responses to any 2851 queued SENDs, or RECEIVEs. 2853 SYN-RECEIVED STATE 2855 If no SENDs have been issued and there is no pending data to 2856 send, then form a FIN segment and send it, and enter FIN-WAIT-1 2857 state; otherwise queue for processing after entering 2858 ESTABLISHED state. 2860 ESTABLISHED STATE 2862 Queue this until all preceding SENDs have been segmentized, 2863 then form a FIN segment and send it. In any case, enter FIN- 2864 WAIT-1 state. 2866 FIN-WAIT-1 STATE 2867 FIN-WAIT-2 STATE 2869 Strictly speaking, this is an error and should receive a 2870 "error: connection closing" response. An "ok" response would 2871 be acceptable, too, as long as a second FIN is not emitted (the 2872 first FIN may be retransmitted though). 2874 CLOSE-WAIT STATE 2876 Queue this request until all preceding SENDs have been 2877 segmentized; then send a FIN segment, enter LAST-ACK state. 2879 CLOSING STATE 2880 LAST-ACK STATE 2881 TIME-WAIT STATE 2882 Respond with "error: connection closing". 2884 ABORT Call 2886 CLOSED STATE (i.e., TCB does not exist) 2888 If the user should not have access to such a connection, return 2889 "error: connection illegal for this process". 2891 Otherwise return "error: connection does not exist". 2893 LISTEN STATE 2895 Any outstanding RECEIVEs should be returned with "error: 2896 connection reset" responses. Delete TCB, enter CLOSED state, 2897 and return. 2899 SYN-SENT STATE 2901 All queued SENDs and RECEIVEs should be given "connection 2902 reset" notification, delete the TCB, enter CLOSED state, and 2903 return. 2905 SYN-RECEIVED STATE 2906 ESTABLISHED STATE 2907 FIN-WAIT-1 STATE 2908 FIN-WAIT-2 STATE 2909 CLOSE-WAIT STATE 2911 Send a reset segment: 2913 2915 All queued SENDs and RECEIVEs should be given "connection 2916 reset" notification; all segments queued for transmission 2917 (except for the RST formed above) or retransmission should be 2918 flushed, delete the TCB, enter CLOSED state, and return. 2920 CLOSING STATE LAST-ACK STATE TIME-WAIT STATE 2922 Respond with "ok" and delete the TCB, enter CLOSED state, and 2923 return. 2925 STATUS Call 2927 CLOSED STATE (i.e., TCB does not exist) 2929 If the user should not have access to such a connection, return 2930 "error: connection illegal for this process". 2932 Otherwise return "error: connection does not exist". 2934 LISTEN STATE 2936 Return "state = LISTEN", and the TCB pointer. 2938 SYN-SENT STATE 2940 Return "state = SYN-SENT", and the TCB pointer. 2942 SYN-RECEIVED STATE 2944 Return "state = SYN-RECEIVED", and the TCB pointer. 2946 ESTABLISHED STATE 2948 Return "state = ESTABLISHED", and the TCB pointer. 2950 FIN-WAIT-1 STATE 2952 Return "state = FIN-WAIT-1", and the TCB pointer. 2954 FIN-WAIT-2 STATE 2956 Return "state = FIN-WAIT-2", and the TCB pointer. 2958 CLOSE-WAIT STATE 2960 Return "state = CLOSE-WAIT", and the TCB pointer. 2962 CLOSING STATE 2964 Return "state = CLOSING", and the TCB pointer. 2966 LAST-ACK STATE 2968 Return "state = LAST-ACK", and the TCB pointer. 2970 TIME-WAIT STATE 2972 Return "state = TIME-WAIT", and the TCB pointer. 2974 SEGMENT ARRIVES 2976 If the state is CLOSED (i.e., TCB does not exist) then 2978 all data in the incoming segment is discarded. An incoming 2979 segment containing a RST is discarded. An incoming segment not 2980 containing a RST causes a RST to be sent in response. The 2981 acknowledgment and sequence field values are selected to make 2982 the reset sequence acceptable to the TCP that sent the 2983 offending segment. 2985 If the ACK bit is off, sequence number zero is used, 2987 2989 If the ACK bit is on, 2991 2993 Return. 2995 If the state is LISTEN then 2997 first check for an RST 2999 An incoming RST should be ignored. Return. 3001 second check for an ACK 3003 Any acknowledgment is bad if it arrives on a connection 3004 still in the LISTEN state. An acceptable reset segment 3005 should be formed for any arriving ACK-bearing segment. The 3006 RST should be formatted as follows: 3008 3010 Return. 3012 third check for a SYN 3014 If the SYN bit is set, check the security. If the security/ 3015 compartment on the incoming segment does not exactly match 3016 the security/compartment in the TCB then send a reset and 3017 return. 3019 3021 Set RCV.NXT to SEG.SEQ+1, IRS is set to SEG.SEQ and any 3022 other control or text should be queued for processing later. 3023 ISS should be selected and a SYN segment sent of the form: 3025 3027 SND.NXT is set to ISS+1 and SND.UNA to ISS. The connection 3028 state should be changed to SYN-RECEIVED. Note that any 3029 other incoming control or data (combined with SYN) will be 3030 processed in the SYN-RECEIVED state, but processing of SYN 3031 and ACK should not be repeated. If the listen was not fully 3032 specified (i.e., the foreign socket was not fully 3033 specified), then the unspecified fields should be filled in 3034 now. 3036 fourth other text or control 3038 Any other control or text-bearing segment (not containing 3039 SYN) must have an ACK and thus would be discarded by the ACK 3040 processing. An incoming RST segment could not be valid, 3041 since it could not have been sent in response to anything 3042 sent by this incarnation of the connection. So you are 3043 unlikely to get here, but if you do, drop the segment, and 3044 return. 3046 If the state is SYN-SENT then 3048 first check the ACK bit 3050 If the ACK bit is set 3052 If SEG.ACK =< ISS, or SEG.ACK > SND.NXT, send a reset 3053 (unless the RST bit is set, if so drop the segment and 3054 return) 3056 3058 and discard the segment. Return. 3060 If SND.UNA < SEG.ACK =< SND.NXT then the ACK is 3061 acceptable. Some deployed TCP code has used the check 3062 SEG.ACK == SND.NXT (using "==" rather than "=<", but this 3063 is not appropriate when the stack is capable of sending 3064 data on the SYN, because the peer TCP may not accept and 3065 acknowledge all of the data on the SYN. 3067 second check the RST bit 3068 If the RST bit is set 3070 A potential blind reset attack is described in RFC 5961 3071 [28], with the mitigation that a TCP implementation 3072 SHOULD first check that the sequence number exactly 3073 matches RCV.NXT prior to executing the action in the next 3074 paragraph. 3076 If the ACK was acceptable then signal the user "error: 3077 connection reset", drop the segment, enter CLOSED state, 3078 delete TCB, and return. Otherwise (no ACK) drop the 3079 segment and return. 3081 third check the security 3083 If the security/compartment in the segment does not exactly 3084 match the security/compartment in the TCB, send a reset 3086 If there is an ACK 3088 3090 Otherwise 3092 3094 If a reset was sent, discard the segment and return. 3096 fourth check the SYN bit 3098 This step should be reached only if the ACK is ok, or there 3099 is no ACK, and it the segment did not contain a RST. 3101 If the SYN bit is on and the security/compartment is 3102 acceptable then, RCV.NXT is set to SEG.SEQ+1, IRS is set to 3103 SEG.SEQ. SND.UNA should be advanced to equal SEG.ACK (if 3104 there is an ACK), and any segments on the retransmission 3105 queue which are thereby acknowledged should be removed. 3107 If SND.UNA > ISS (our SYN has been ACKed), change the 3108 connection state to ESTABLISHED, form an ACK segment 3110 3112 and send it. Data or controls which were queued for 3113 transmission may be included. If there are other controls 3114 or text in the segment then continue processing at the sixth 3115 step below where the URG bit is checked, otherwise return. 3117 Otherwise enter SYN-RECEIVED, form a SYN,ACK segment 3119 3121 and send it. Set the variables: 3123 SND.WND <- SEG.WND 3124 SND.WL1 <- SEG.SEQ 3125 SND.WL2 <- SEG.ACK 3127 If there are other controls or text in the segment, queue 3128 them for processing after the ESTABLISHED state has been 3129 reached, return. 3131 Note that it is legal to send and receive application data 3132 on SYN segments (this is the "text in the segment" mentioned 3133 above. There has been significant misinformation and 3134 misunderstanding of this topic historically. Some firewalls 3135 and security devices consider this suspicious. However, the 3136 capability was used in T/TCP [16] and is used in TCP Fast 3137 Open (TFO) [36], so is important for implementations and 3138 network devices to permit. 3140 fifth, if neither of the SYN or RST bits is set then drop the 3141 segment and return. 3143 Otherwise, 3145 first check sequence number 3147 SYN-RECEIVED STATE 3148 ESTABLISHED STATE 3149 FIN-WAIT-1 STATE 3150 FIN-WAIT-2 STATE 3151 CLOSE-WAIT STATE 3152 CLOSING STATE 3153 LAST-ACK STATE 3154 TIME-WAIT STATE 3156 Segments are processed in sequence. Initial tests on 3157 arrival are used to discard old duplicates, but further 3158 processing is done in SEG.SEQ order. If a segment's 3159 contents straddle the boundary between old and new, only the 3160 new parts should be processed. 3162 In general, the processing of received segments MUST be 3163 implemented to aggregate ACK segments whenever possible 3164 (MUST-58). For example, if the TCP is processing a series 3165 of queued segments, it MUST process them all before sending 3166 any ACK segments (MUST-59). 3168 There are four cases for the acceptability test for an 3169 incoming segment: 3171 Segment Receive Test 3172 Length Window 3173 ------- ------- ------------------------------------------- 3175 0 0 SEG.SEQ = RCV.NXT 3177 0 >0 RCV.NXT =< SEG.SEQ < RCV.NXT+RCV.WND 3179 >0 0 not acceptable 3181 >0 >0 RCV.NXT =< SEG.SEQ < RCV.NXT+RCV.WND 3182 or RCV.NXT =< SEG.SEQ+SEG.LEN-1 < RCV.NXT+RCV.WND 3184 In implementing sequence number validation as described 3185 here, please note Appendix A.2. 3187 If the RCV.WND is zero, no segments will be acceptable, but 3188 special allowance should be made to accept valid ACKs, URGs 3189 and RSTs. 3191 If an incoming segment is not acceptable, an acknowledgment 3192 should be sent in reply (unless the RST bit is set, if so 3193 drop the segment and return): 3195 3197 After sending the acknowledgment, drop the unacceptable 3198 segment and return. 3200 Note that for the TIME-WAIT state, there is an improved 3201 algorithm described in [30] for handling incoming SYN 3202 segments, that utilizes timestamps rather than relying on 3203 the sequence number check described here. When the improved 3204 algorithm is implemented, the logic above is not applicable 3205 for incoming SYN segments with timestamp options, received 3206 on a connection in the TIME-WAIT state. 3208 In the following it is assumed that the segment is the 3209 idealized segment that begins at RCV.NXT and does not exceed 3210 the window. One could tailor actual segments to fit this 3211 assumption by trimming off any portions that lie outside the 3212 window (including SYN and FIN), and only processing further 3213 if the segment then begins at RCV.NXT. Segments with higher 3214 beginning sequence numbers should be held for later 3215 processing. 3217 second check the RST bit, 3219 RFC 5961 section 3 describes a potential blind reset attack 3220 and optional mitigation approach that SHOULD be implemented. 3221 For stacks implementing RFC 5961, the three checks below 3222 apply, otherwise processesing for these states is indicated 3223 further below. 3225 1) If the RST bit is set and the sequence number is 3226 outside the current receive window, silently drop the 3227 segment. 3229 2) If the RST bit is set and the sequence number exactly 3230 matches the next expected sequence number (RCV.NXT), then 3231 TCP MUST reset the connection in the manner prescribed 3232 below according to the connection state. 3234 3) If the RST bit is set and the sequence number does not 3235 exactly match the next expected sequence value, yet is 3236 within the current receive window, TCP MUST send an 3237 acknowledgement (challenge ACK): 3239 3241 After sending the challenge ACK, TCP MUST drop the 3242 unacceptable segment and stop processing the incoming 3243 packet further. Note that RFC 5961 and Errata ID 4772 3244 contain additional considerations for ACK throttling in 3245 an implementation. 3247 SYN-RECEIVED STATE 3249 If the RST bit is set 3251 If this connection was initiated with a passive OPEN 3252 (i.e., came from the LISTEN state), then return this 3253 connection to LISTEN state and return. The user need 3254 not be informed. If this connection was initiated 3255 with an active OPEN (i.e., came from SYN-SENT state) 3256 then the connection was refused, signal the user 3257 "connection refused". In either case, all segments on 3258 the retransmission queue should be removed. And in 3259 the active OPEN case, enter the CLOSED state and 3260 delete the TCB, and return. 3262 ESTABLISHED 3263 FIN-WAIT-1 3264 FIN-WAIT-2 3265 CLOSE-WAIT 3267 If the RST bit is set then, any outstanding RECEIVEs and 3268 SEND should receive "reset" responses. All segment 3269 queues should be flushed. Users should also receive an 3270 unsolicited general "connection reset" signal. Enter the 3271 CLOSED state, delete the TCB, and return. 3273 CLOSING STATE 3274 LAST-ACK STATE 3275 TIME-WAIT 3277 If the RST bit is set then, enter the CLOSED state, 3278 delete the TCB, and return. 3280 third check security 3282 SYN-RECEIVED 3284 If the security/compartment in the segment does not 3285 exactly match the security/compartment in the TCB then 3286 send a reset, and return. 3288 ESTABLISHED 3289 FIN-WAIT-1 3290 FIN-WAIT-2 3291 CLOSE-WAIT 3292 CLOSING 3293 LAST-ACK 3294 TIME-WAIT 3296 If the security/compartment in the segment does not 3297 exactly match the security/compartment in the TCB then 3298 send a reset, any outstanding RECEIVEs and SEND should 3299 receive "reset" responses. All segment queues should be 3300 flushed. Users should also receive an unsolicited 3301 general "connection reset" signal. Enter the CLOSED 3302 state, delete the TCB, and return. 3304 Note this check is placed following the sequence check to 3305 prevent a segment from an old connection between these ports 3306 with a different security from causing an abort of the 3307 current connection. 3309 fourth, check the SYN bit, 3311 SYN-RECEIVED 3313 If the connection was initiated with a passive OPEN, then 3314 return this connection to the LISTEN state and return. 3315 Otherwise, handle per the directions for synchronized 3316 states below. 3318 ESTABLISHED STATE 3319 FIN-WAIT STATE-1 3320 FIN-WAIT STATE-2 3321 CLOSE-WAIT STATE 3322 CLOSING STATE 3323 LAST-ACK STATE 3324 TIME-WAIT STATE 3326 If the SYN bit is set in these synchronized states, it 3327 may be either a legitimate new connection attempt (e.g. 3328 in the case of TIME-WAIT), an error where the connection 3329 should be reset, or the result of an attack attempt, as 3330 described in RFC 5961 [28]. For the TIME-WAIT state, new 3331 connections can be accepted if the timestamp option is 3332 used and meets expectations (per [30]). For all other 3333 caess, RFC 5961 provides a mitigation that SHOULD be 3334 implemented, though there are alternatives (see 3335 Section 6). RFC 5961 recommends that in these 3336 synchronized states, if the SYN bit is set, irrespective 3337 of the sequence number, TCP MUST send a "challenge ACK" 3338 to the remote peer: 3340 3342 After sending the acknowledgement, TCP MUST drop the 3343 unacceptable segment and stop processing further. Note 3344 that RFC 5961 and Errata ID 4772 contain additional ACK 3345 throttling notes for an implementation. 3347 For implementations that do not follow RFC 5961, the 3348 original RFC 793 behavior follows in this paragraph. If 3349 the SYN is in the window it is an error, send a reset, 3350 any outstanding RECEIVEs and SEND should receive "reset" 3351 responses, all segment queues should be flushed, the user 3352 should also receive an unsolicited general "connection 3353 reset" signal, enter the CLOSED state, delete the TCB, 3354 and return. 3356 If the SYN is not in the window this step would not be 3357 reached and an ack would have been sent in the first step 3358 (sequence number check). 3360 fifth check the ACK field, 3362 if the ACK bit is off drop the segment and return 3364 if the ACK bit is on 3366 RFC 5961 section 5 describes a potential blind data 3367 injection attack, and mitigation that implementations MAY 3368 choose to include (MAY-12). TCP stacks that implement 3369 RFC 5961 MUST add an input check that the ACK value is 3370 acceptable only if it is in the range of ((SND.UNA - 3371 MAX.SND.WND) =< SEG.ACK =< SND.NXT). All incoming 3372 segments whose ACK value doesn't satisfy the above 3373 condition MUST be discarded and an ACK sent back. The 3374 new state variable MAX.SND.WND is defined as the largest 3375 window that the local sender has ever received from its 3376 peer (subject to window scaling) or may be hard-coded to 3377 a maximum permissible window value. When the ACK value 3378 is acceptable, the processing per-state below applies: 3380 SYN-RECEIVED STATE 3382 If SND.UNA < SEG.ACK =< SND.NXT then enter ESTABLISHED 3383 state and continue processing with variables below set 3384 to: 3386 SND.WND <- SEG.WND 3387 SND.WL1 <- SEG.SEQ 3388 SND.WL2 <- SEG.ACK 3390 If the segment acknowledgment is not acceptable, 3391 form a reset segment, 3393 3395 and send it. 3397 ESTABLISHED STATE 3399 If SND.UNA < SEG.ACK =< SND.NXT then, set SND.UNA <- 3400 SEG.ACK. Any segments on the retransmission queue 3401 which are thereby entirely acknowledged are removed. 3402 Users should receive positive acknowledgments for 3403 buffers which have been SENT and fully acknowledged 3404 (i.e., SEND buffer should be returned with "ok" 3405 response). If the ACK is a duplicate (SEG.ACK =< 3406 SND.UNA), it can be ignored. If the ACK acks 3407 something not yet sent (SEG.ACK > SND.NXT) then send 3408 an ACK, drop the segment, and return. 3410 If SND.UNA =< SEG.ACK =< SND.NXT, the send window 3411 should be updated. If (SND.WL1 < SEG.SEQ or (SND.WL1 3412 = SEG.SEQ and SND.WL2 =< SEG.ACK)), set SND.WND <- 3413 SEG.WND, set SND.WL1 <- SEG.SEQ, and set SND.WL2 <- 3414 SEG.ACK. 3416 Note that SND.WND is an offset from SND.UNA, that 3417 SND.WL1 records the sequence number of the last 3418 segment used to update SND.WND, and that SND.WL2 3419 records the acknowledgment number of the last segment 3420 used to update SND.WND. The check here prevents using 3421 old segments to update the window. 3423 FIN-WAIT-1 STATE 3425 In addition to the processing for the ESTABLISHED 3426 state, if our FIN is now acknowledged then enter FIN- 3427 WAIT-2 and continue processing in that state. 3429 FIN-WAIT-2 STATE 3431 In addition to the processing for the ESTABLISHED 3432 state, if the retransmission queue is empty, the 3433 user's CLOSE can be acknowledged ("ok") but do not 3434 delete the TCB. 3436 CLOSE-WAIT STATE 3438 Do the same processing as for the ESTABLISHED state. 3440 CLOSING STATE 3442 In addition to the processing for the ESTABLISHED 3443 state, if the ACK acknowledges our FIN then enter the 3444 TIME-WAIT state, otherwise ignore the segment. 3446 LAST-ACK STATE 3447 The only thing that can arrive in this state is an 3448 acknowledgment of our FIN. If our FIN is now 3449 acknowledged, delete the TCB, enter the CLOSED state, 3450 and return. 3452 TIME-WAIT STATE 3454 The only thing that can arrive in this state is a 3455 retransmission of the remote FIN. Acknowledge it, and 3456 restart the 2 MSL timeout. 3458 sixth, check the URG bit, 3460 ESTABLISHED STATE 3461 FIN-WAIT-1 STATE 3462 FIN-WAIT-2 STATE 3464 If the URG bit is set, RCV.UP <- max(RCV.UP,SEG.UP), and 3465 signal the user that the remote side has urgent data if 3466 the urgent pointer (RCV.UP) is in advance of the data 3467 consumed. If the user has already been signaled (or is 3468 still in the "urgent mode") for this continuous sequence 3469 of urgent data, do not signal the user again. 3471 CLOSE-WAIT STATE 3472 CLOSING STATE 3473 LAST-ACK STATE 3474 TIME-WAIT 3476 This should not occur, since a FIN has been received from 3477 the remote side. Ignore the URG. 3479 seventh, process the segment text, 3481 ESTABLISHED STATE 3482 FIN-WAIT-1 STATE 3483 FIN-WAIT-2 STATE 3485 Once in the ESTABLISHED state, it is possible to deliver 3486 segment text to user RECEIVE buffers. Text from segments 3487 can be moved into buffers until either the buffer is full 3488 or the segment is empty. If the segment empties and 3489 carries an PUSH flag, then the user is informed, when the 3490 buffer is returned, that a PUSH has been received. 3492 When the TCP takes responsibility for delivering the data 3493 to the user it must also acknowledge the receipt of the 3494 data. 3496 Once the TCP takes responsibility for the data it 3497 advances RCV.NXT over the data accepted, and adjusts 3498 RCV.WND as appropriate to the current buffer 3499 availability. The total of RCV.NXT and RCV.WND should 3500 not be reduced. 3502 A TCP MAY send an ACK segment acknowledging RCV.NXT when 3503 a valid segment arrives that is in the window but not at 3504 the left window edge (MAY-13). 3506 Please note the window management suggestions in 3507 Section 3.8. 3509 Send an acknowledgment of the form: 3511 3513 This acknowledgment should be piggybacked on a segment 3514 being transmitted if possible without incurring undue 3515 delay. 3517 CLOSE-WAIT STATE 3518 CLOSING STATE 3519 LAST-ACK STATE 3520 TIME-WAIT STATE 3522 This should not occur, since a FIN has been received from 3523 the remote side. Ignore the segment text. 3525 eighth, check the FIN bit, 3527 Do not process the FIN if the state is CLOSED, LISTEN or 3528 SYN-SENT since the SEG.SEQ cannot be validated; drop the 3529 segment and return. 3531 If the FIN bit is set, signal the user "connection closing" 3532 and return any pending RECEIVEs with same message, advance 3533 RCV.NXT over the FIN, and send an acknowledgment for the 3534 FIN. Note that FIN implies PUSH for any segment text not 3535 yet delivered to the user. 3537 SYN-RECEIVED STATE 3538 ESTABLISHED STATE 3540 Enter the CLOSE-WAIT state. 3542 FIN-WAIT-1 STATE 3543 If our FIN has been ACKed (perhaps in this segment), 3544 then enter TIME-WAIT, start the time-wait timer, turn 3545 off the other timers; otherwise enter the CLOSING 3546 state. 3548 FIN-WAIT-2 STATE 3550 Enter the TIME-WAIT state. Start the time-wait timer, 3551 turn off the other timers. 3553 CLOSE-WAIT STATE 3555 Remain in the CLOSE-WAIT state. 3557 CLOSING STATE 3559 Remain in the CLOSING state. 3561 LAST-ACK STATE 3563 Remain in the LAST-ACK state. 3565 TIME-WAIT STATE 3567 Remain in the TIME-WAIT state. Restart the 2 MSL 3568 time-wait timeout. 3570 and return. 3572 USER TIMEOUT 3574 USER TIMEOUT 3576 For any state if the user timeout expires, flush all queues, 3577 signal the user "error: connection aborted due to user timeout" 3578 in general and for any outstanding calls, delete the TCB, enter 3579 the CLOSED state and return. 3581 RETRANSMISSION TIMEOUT 3583 For any state if the retransmission timeout expires on a 3584 segment in the retransmission queue, send the segment at the 3585 front of the retransmission queue again, reinitialize the 3586 retransmission timer, and return. 3588 TIME-WAIT TIMEOUT 3590 If the time-wait timeout expires on a connection delete the 3591 TCB, enter the CLOSED state and return. 3593 3.11. Glossary 3595 1822 BBN Report 1822, "The Specification of the Interconnection of 3596 a Host and an IMP". The specification of interface between a 3597 host and the ARPANET. 3599 ACK 3600 A control bit (acknowledge) occupying no sequence space, 3601 which indicates that the acknowledgment field of this segment 3602 specifies the next sequence number the sender of this segment 3603 is expecting to receive, hence acknowledging receipt of all 3604 previous sequence numbers. 3606 ARPANET message 3607 The unit of transmission between a host and an IMP in the 3608 ARPANET. The maximum size is about 1012 octets (8096 bits). 3610 ARPANET packet 3611 A unit of transmission used internally in the ARPANET between 3612 IMPs. The maximum size is about 126 octets (1008 bits). 3614 connection 3615 A logical communication path identified by a pair of sockets. 3617 datagram 3618 A message sent in a packet switched computer communications 3619 network. 3621 Destination Address 3622 The destination address, usually the network and host 3623 identifiers. 3625 FIN 3626 A control bit (finis) occupying one sequence number, which 3627 indicates that the sender will send no more data or control 3628 occupying sequence space. 3630 fragment 3631 A portion of a logical unit of data, in particular an 3632 internet fragment is a portion of an internet datagram. 3634 FTP 3635 A file transfer protocol. 3637 header 3638 Control information at the beginning of a message, segment, 3639 fragment, packet or block of data. 3641 host 3642 A computer. In particular a source or destination of 3643 messages from the point of view of the communication network. 3645 Identification 3646 An Internet Protocol field. This identifying value assigned 3647 by the sender aids in assembling the fragments of a datagram. 3649 IMP 3650 The Interface Message Processor, the packet switch of the 3651 ARPANET. 3653 internet address 3654 A source or destination address specific to the host level. 3656 internet datagram 3657 The unit of data exchanged between an internet module and the 3658 higher level protocol together with the internet header. 3660 internet fragment 3661 A portion of the data of an internet datagram with an 3662 internet header. 3664 IP 3665 Internet Protocol. 3667 IRS 3668 The Initial Receive Sequence number. The first sequence 3669 number used by the sender on a connection. 3671 ISN 3672 The Initial Sequence Number. The first sequence number used 3673 on a connection, (either ISS or IRS). Selected in a way that 3674 is unique within a given period of time and is unpredictable 3675 to attackers. 3677 ISS 3678 The Initial Send Sequence number. The first sequence number 3679 used by the sender on a connection. 3681 leader 3682 Control information at the beginning of a message or block of 3683 data. In particular, in the ARPANET, the control information 3684 on an ARPANET message at the host-IMP interface. 3686 left sequence 3687 This is the next sequence number to be acknowledged by the 3688 data receiving TCP (or the lowest currently unacknowledged 3689 sequence number) and is sometimes referred to as the left 3690 edge of the send window. 3692 local packet 3693 The unit of transmission within a local network. 3695 module 3696 An implementation, usually in software, of a protocol or 3697 other procedure. 3699 MSL 3700 Maximum Segment Lifetime, the time a TCP segment can exist in 3701 the internetwork system. Arbitrarily defined to be 2 3702 minutes. 3704 octet 3705 An eight bit byte. 3707 Options 3708 An Option field may contain several options, and each option 3709 may be several octets in length. 3711 packet 3712 A package of data with a header which may or may not be 3713 logically complete. More often a physical packaging than a 3714 logical packaging of data. 3716 port 3717 The portion of a socket that specifies which logical input or 3718 output channel of a process is associated with the data. 3720 process 3721 A program in execution. A source or destination of data from 3722 the point of view of the TCP or other host-to-host protocol. 3724 PUSH 3725 A control bit occupying no sequence space, indicating that 3726 this segment contains data that must be pushed through to the 3727 receiving user. 3729 RCV.NXT 3730 receive next sequence number 3732 RCV.UP 3733 receive urgent pointer 3735 RCV.WND 3736 receive window 3738 receive next sequence number 3739 This is the next sequence number the local TCP is expecting 3740 to receive. 3742 receive window 3743 This represents the sequence numbers the local (receiving) 3744 TCP is willing to receive. Thus, the local TCP considers 3745 that segments overlapping the range RCV.NXT to RCV.NXT + 3746 RCV.WND - 1 carry acceptable data or control. Segments 3747 containing sequence numbers entirely outside of this range 3748 are considered duplicates and discarded. 3750 RST 3751 A control bit (reset), occupying no sequence space, 3752 indicating that the receiver should delete the connection 3753 without further interaction. The receiver can determine, 3754 based on the sequence number and acknowledgment fields of the 3755 incoming segment, whether it should honor the reset command 3756 or ignore it. In no case does receipt of a segment 3757 containing RST give rise to a RST in response. 3759 RTP 3760 Real Time Protocol: A host-to-host protocol for communication 3761 of time critical information. 3763 SEG.ACK 3764 segment acknowledgment 3766 SEG.LEN 3767 segment length 3769 SEG.SEQ 3770 segment sequence 3772 SEG.UP 3773 segment urgent pointer field 3775 SEG.WND 3776 segment window field 3778 segment 3779 A logical unit of data, in particular a TCP segment is the 3780 unit of data transfered between a pair of TCP modules. 3782 segment acknowledgment 3783 The sequence number in the acknowledgment field of the 3784 arriving segment. 3786 segment length 3787 The amount of sequence number space occupied by a segment, 3788 including any controls which occupy sequence space. 3790 segment sequence 3791 The number in the sequence field of the arriving segment. 3793 send sequence 3794 This is the next sequence number the local (sending) TCP will 3795 use on the connection. It is initially selected from an 3796 initial sequence number curve (ISN) and is incremented for 3797 each octet of data or sequenced control transmitted. 3799 send window 3800 This represents the sequence numbers which the remote 3801 (receiving) TCP is willing to receive. It is the value of 3802 the window field specified in segments from the remote (data 3803 receiving) TCP. The range of new sequence numbers which may 3804 be emitted by a TCP lies between SND.NXT and SND.UNA + 3805 SND.WND - 1. (Retransmissions of sequence numbers between 3806 SND.UNA and SND.NXT are expected, of course.) 3808 SND.NXT 3809 send sequence 3811 SND.UNA 3812 left sequence 3814 SND.UP 3815 send urgent pointer 3817 SND.WL1 3818 segment sequence number at last window update 3820 SND.WL2 3821 segment acknowledgment number at last window update 3823 SND.WND 3824 send window 3826 socket 3827 An address which specifically includes a port identifier, 3828 that is, the concatenation of an Internet Address with a TCP 3829 port. 3831 Source Address 3832 The source address, usually the network and host identifiers. 3834 SYN 3835 A control bit in the incoming segment, occupying one sequence 3836 number, used at the initiation of a connection, to indicate 3837 where the sequence numbering will start. 3839 TCB 3840 Transmission control block, the data structure that records 3841 the state of a connection. 3843 TCP 3844 Transmission Control Protocol: A host-to-host protocol for 3845 reliable communication in internetwork environments. 3847 TOS 3848 Type of Service, an obsoleted IPv4 field. The same header 3849 bits currently are used for the Differentiated Services field 3850 [6] containing the Differentiated Services Code Point (DSCP) 3851 value and two unused bits. 3853 Type of Service 3854 An Internet Protocol field which indicates the type of 3855 service for this internet fragment. 3857 URG 3858 A control bit (urgent), occupying no sequence space, used to 3859 indicate that the receiving user should be notified to do 3860 urgent processing as long as there is data to be consumed 3861 with sequence numbers less than the value indicated in the 3862 urgent pointer. 3864 urgent pointer 3865 A control field meaningful only when the URG bit is on. This 3866 field communicates the value of the urgent pointer which 3867 indicates the data octet associated with the sending user's 3868 urgent call. 3870 4. Changes from RFC 793 3872 This document obsoletes RFC 793 as well as RFC 6093 and 6528, which 3873 updated 793. In all cases, only the normative protocol specification 3874 and requirements have been incorporated into this document, and the 3875 informational text with background and rationale has not been carried 3876 in. The informational content of those documents is still valuable 3877 in learning about and understanding TCP, and they are valid 3878 Informational references, even though their normative content has 3879 been incorporated into this document. 3881 The main body of this document was adapted from RFC 793's Section 3, 3882 titled "FUNCTIONAL SPECIFICATION", with an attempt to keep formatting 3883 and layout as close as possible. 3885 The collection of applicable RFC Errata that have been reported and 3886 either accepted or held for an update to RFC 793 were incorporated 3887 (Errata IDs: 573, 574, 700, 701, 1283, 1561, 1562, 1564, 1565, 1571, 3888 1572, 2296, 2297, 2298, 2748, 2749, 2934, 3213, 3300, 3301). Some 3889 errata were not applicable due to other changes (Errata IDs: 572, 3890 575, 1569, 3305, 3602). 3892 Changes to the specification of the Urgent Pointer described in RFC 3893 1122 and 6093 were incorporated. See RFC 6093 for detailed 3894 discussion of why these changes were necessary. 3896 The discussion of the RTO from RFC 793 was updated to refer to RFC 3897 6298. The RFC 1122 text on the RTO originally replaced the 793 text, 3898 however, RFC 2988 should have updated 1122, and has subsequently been 3899 obsoleted by 6298. 3901 RFC 1122 contains a collection of other changes and clarifications to 3902 RFC 793. The normative items impacting the protocol have been 3903 incorporated here, though some historically useful implementation 3904 advice and informative discussion from RFC 1122 is not included here. 3906 RFC 1122 contains more than just TCP requirements, so this document 3907 can't obsolete RFC 1122 entirely. It is only marked as "updating" 3908 1122, however, it should be understood to effectively obsolete all of 3909 the RFC 1122 material on TCP. 3911 The more secure Initial Sequence Number generation algorithm from RFC 3912 6528 was incorporated. See RFC 6528 for discussion of the attacks 3913 that this mitigates, as well as advice on selecting PRF algorithms 3914 and managing secret key data. 3916 A note based on RFC 6429 was added to explicitly clarify that system 3917 resource mangement concerns allow connection resources to be 3918 reclaimed. RFC 6429 is obsoleted in the sense that this 3919 clarification has been reflected in this update to the base TCP 3920 specification now. 3922 RFC EDITOR'S NOTE: the content below is for detailed change tracking 3923 and planning, and not to be included with the final revision of the 3924 document. 3926 This document started as draft-eddy-rfc793bis-00, that was merely a 3927 proposal and rough plan for updating RFC 793. 3929 The -01 revision of this draft-eddy-rfc793bis incorporates the 3930 content of RFC 793 Section 3 titled "FUNCTIONAL SPECIFICATION". 3931 Other content from RFC 793 has not been incorporated. The -01 3932 revision of this document makes some minor formatting changes to the 3933 RFC 793 content in order to convert the content into XML2RFC format 3934 and account for left-out parts of RFC 793. For instance, figure 3935 numbering differs and some indentation is not exactly the same. 3937 The -02 revision of draft-eddy-rfc793bis incorporates errata that 3938 have been verified: 3940 Errata ID 573: Reported by Bob Braden (note: This errata basically 3941 is just a reminder that RFC 1122 updates 793. Some of the 3942 associated changes are left pending to a separate revision that 3943 incorporates 1122. Bob's mention of PUSH in 793 section 2.8 was 3944 not applicable here because that section was not part of the 3945 "functional specification". Also the 1122 text on the 3946 retransmission timeout also has been updated by subsequent RFCs, 3947 so the change here deviates from Bob's suggestion to apply the 3948 1122 text.) 3949 Errata ID 574: Reported by Yin Shuming 3950 Errata ID 700: Reported by Yin Shuming 3951 Errata ID 701: Reported by Yin Shuming 3952 Errata ID 1283: Reported by Pei-chun Cheng 3953 Errata ID 1561: Reported by Constantin Hagemeier 3954 Errata ID 1562: Reported by Constantin Hagemeier 3955 Errata ID 1564: Reported by Constantin Hagemeier 3956 Errata ID 1565: Reported by Constantin Hagemeier 3957 Errata ID 1571: Reported by Constantin Hagemeier 3958 Errata ID 1572: Reported by Constantin Hagemeier 3959 Errata ID 2296: Reported by Vishwas Manral 3960 Errata ID 2297: Reported by Vishwas Manral 3961 Errata ID 2298: Reported by Vishwas Manral 3962 Errata ID 2748: Reported by Mykyta Yevstifeyev 3963 Errata ID 2749: Reported by Mykyta Yevstifeyev 3964 Errata ID 2934: Reported by Constantin Hagemeier 3965 Errata ID 3213: Reported by EugnJun Yi 3966 Errata ID 3300: Reported by Botong Huang 3967 Errata ID 3301: Reported by Botong Huang 3968 Errata ID 3305: Reported by Botong Huang 3969 Note: Some verified errata were not used in this update, as they 3970 relate to sections of RFC 793 elided from this document. These 3971 include Errata ID 572, 575, and 1569. 3972 Note: Errata ID 3602 was not applied in this revision as it is 3973 duplicative of the 1122 corrections. 3975 Not related to RFC 793 content, this revision also makes small tweaks 3976 to the introductory text, fixes indentation of the pseudoheader 3977 diagram, and notes that the Security Considerations should also 3978 include privacy, when this section is written. 3980 The -03 revision of draft-eddy-rfc793bis revises all discussion of 3981 the urgent pointer in order to comply with RFC 6093, 1122, and 1011. 3982 Since 1122 held requirements on the urgent pointer, the full list of 3983 requirements was brought into an appendix of this document, so that 3984 it can be updated as-needed. 3986 The -04 revision of draft-eddy-rfc793bis includes the ISN generation 3987 changes from RFC 6528. 3989 The -05 revision of draft-eddy-rfc793bis incorporates MSS 3990 requirements and definitions from RFC 879, 1122, and 6691, as well as 3991 option-handling requirements from RFC 1122. 3993 The -00 revision of draft-ietf-tcpm-rfc793bis incorporates several 3994 additional clarifications and updates to the section on segmentation, 3995 many of which are based on feedback from Joe Touch improving from the 3996 initial text on this in the previous revision. 3998 The -01 revision incorporates the change to Reserved bits due to ECN, 3999 as well as many other changes that come from RFC 1122. 4001 The -02 revision has small formating modifications in order to 4002 address xml2rfc warnings about long lines. It was a quick update to 4003 avoid document expiration. TCPM working group discussion in 2015 4004 also indicated that that we should not try to add sections on 4005 implementation advice or similar non-normative information. 4007 The -03 revision incorporates more content from RFC 1122: Passive 4008 OPEN Calls, Time-To-Live, Multihoming, IP Options, ICMP messages, 4009 Data Communications, When to Send Data, When to Send a Window Update, 4010 Managing the Window, Probing Zero Windows, When to Send an ACK 4011 Segment. The section on data communications was re-organized into 4012 clearer subsections (previously headings were embedded in the 793 4013 text), and windows management advice from 793 was removed (as 4014 reviewed by TCPM working group) in favor of the 1122 additions on 4015 SWS, ZWP, and related topics. 4017 The -04 revision includes reference to RFC 6429 on the ZWP condition, 4018 RFC1122 material on TCP Connection Failures, TCP Keep-Alives, 4019 Acknowledging Queued Segments, and Remote Address Validation. RTO 4020 computation is referenced from RFC 6298 rather than RFC 1122. 4022 The -05 revision includes the requirement to implement TCP congestion 4023 control with recommendation to implemente ECN, the RFC 6633 update to 4024 1122, which changed the requirement on responding to source quench 4025 ICMP messages, and discussion of ICMP (and ICMPv6) soft and hard 4026 errors per RFC 5461 (ICMPv6 handling for TCP doesn't seem to be 4027 mentioned elsewhere in standards track). 4029 The -06 revision includes an appendix on "Other Implementation Notes" 4030 to capture widely-deployed fundamental features that are not 4031 contained in the RFC series yet. It also added mention of RFC 6994 4032 and the IANA TCP parameters registry as a reference. It includes 4033 references to RFC 5961 in appropriate places. The references to TOS 4034 were changed to DiffServ field, based on reflecting RFC 2474 as well 4035 as the IPv6 presence of traffic class (carrying DiffServ field) 4036 rather than TOS. 4038 The -07 revision includes reference to RFC 6191, updated security 4039 considerations, discussion of additional implementation 4040 considerations, and clarification of data on the SYN. 4042 The -08 revision includes changes based on: 4044 describing treatment of reserved bits (following TCPM mailing list 4045 thread from July 2014 on "793bis item - reserved bit behavior" 4046 addition a brief TCP key concepts section to make up for not 4047 including the outdated section 2 of RFC 793 4048 changed "TCP" to "host" to resolve conflict between 1122 wording 4049 on whether TCP or the network layer chooses an address when 4050 multihomed 4051 fixed/updated definition of options in glossary 4052 moved note on aggregating ACKs from 1122 to a more appropriate 4053 location 4054 resolved notes on IP precedence and security/compartment 4055 added implementation note on sequence number validation 4056 added note that PUSH does not apply when Nagle is active 4057 added 1122 content on asynchronous reports to replace 793 section 4058 on TCP to user messages 4060 The -09 revision fixes section numbering problems. 4062 The -10 revision includes additions to the security considerations 4063 based on comments from Joe Touch, and suggested edits on RST/FIN 4064 notification, RFC 2525 reference, and other edits suggested by 4065 Yuchung Cheng, as well as modifications to DiffServ text from Yuchung 4066 Cheng and Gorry Fairhurst. 4068 Some other suggested changes that will not be incorporated in this 4069 793 update unless TCPM consensus changes with regard to scope are: 4071 1. look at Tony Sabatini suggestion for describing DO field 4072 2. per discussion with Joe Touch (TAPS list, 6/20/2015), the 4073 description of the API could be revisited 4075 Early in the process of updating RFC 793, Scott Brim mentioned that 4076 this should include a PERPASS/privacy review. This may be something 4077 for the chairs or AD to request during WGLC or IETF LC. 4079 5. IANA Considerations 4081 This memo includes no request to IANA. Existing IANA registries for 4082 TCP parameters are sufficient. 4084 TODO: check whether entries pointing to 793 and other documents 4085 obsoleted by this one should be updated to point to this one instead. 4087 6. Security and Privacy Considerations 4089 The TCP design includes only rudimentary security features that 4090 improve the robustness and reliability of connections and application 4091 data transfer, but there are no built-in cryptographic capabilities 4092 to support any form of privacy, authentication, or other typical 4093 security functions. Non-cryptographic enhancements (e.g. [28]) have 4094 been developed to improve robustness of TCP connections to particular 4095 types of attacks, but the applicability and protections of non- 4096 cryptographic enhancements are limited (e.g. see section 1.1 of 4097 [28]). Applications typically utilize lower-layer (e.g. IPsec) and 4098 upper-layer (e.g. TLS) protocols to provide security and privacy for 4099 TCP connections and application data carried in TCP. Methods based 4100 on TCP options have been developed as well, to support some security 4101 capabilities. 4103 In order to fully protect TCP connections (including their control 4104 flags) IPsec or the TCP Authentication Option (TCP-AO) [27] are the 4105 only current effective methods. Other methods discussed in this 4106 section may protect the payload, but either only a subset of the 4107 fields (e.g. tcpcrypt) or none at all (e.g. TLS). Other security 4108 features that have been added to TCP (e.g. ISN generation, sequence 4109 number checks, etc.) are only capable of partially hindering attacks. 4111 Applications using long-lived TCP flows have been vulnerable to 4112 attacks that exploit the processing of control flags described in 4113 earlier TCP specifications [21]. TCP-MD5 was a commonly implemented 4114 TCP option to support authentication for some of these connections, 4115 but had flaws and is now deprecated. TCP-AO provides a capability to 4116 protect long-lived TCP connections from attacks, and has superior 4117 properties to TCP-MD5. It does not provide any privacy for 4118 application data, nor for the TCP headers. 4120 The "tcpcrypt" [44]Experimental extension to TCP provides the ability 4121 to cryptographically protect connection data. Metadata aspects of 4122 the TCP flow are still visible, but the application stream is well- 4123 protected. Within the TCP header, only the urgent pointer and FIN 4124 flag are protected through tcpcrypt. 4126 The TCP Roadmap [37] includes notes about several RFCs related to TCP 4127 security. Many of the enhancements provided by these RFCs have been 4128 integrated into the present document, including ISN generation, 4129 mitigating blind in-window attacks, and improving handling of soft 4130 errors and ICMP packets. These are all discussed in greater detail 4131 in the referenced RFCs that originally described the changes needed 4132 to earlier TCP specifications. Additionally, see RFC 6093 [29] for 4133 discussion of security considerations related to the urgent pointer 4134 field, that has been deprecated. 4136 Since TCP is often used for bulk transfer flows, some attacks are 4137 possible that abuse the TCP congestion control logic. An example is 4138 "ACK-division" attacks. Updates that have been made to the TCP 4139 congestion control specifications include mechanisms like Appropriate 4140 Byte Counting (ABC) that act as mitigations to these attacks. 4142 Other attacks are focused on exhausting the resources of a TCP 4143 server. Examples include SYN flooding [20] or wasting resources on 4144 non-progressing connections [31]. Operating systems commonly 4145 implement mitigations for these attacks. Some common defenses also 4146 utilize proxies, stateful firewalls, and other technologies outside 4147 of the end-host TCP implementation. 4149 7. Acknowledgements 4151 This document is largely a revision of RFC 793, which Jon Postel was 4152 the editor of. Due to his excellent work, it was able to last for 4153 three decades before we felt the need to revise it. 4155 Andre Oppermann was a contributor and helped to edit the first 4156 revision of this document. 4158 We are thankful for the assistance of the IETF TCPM working group 4159 chairs: 4161 Michael Scharf 4162 Yoshifumi Nishida 4163 Pasi Sarolahti 4165 During early discussion of this work on the TCPM mailing list, and at 4166 the IETF 88 meeting in Vancouver, helpful comments, critiques, and 4167 reviews were received from (listed alphebetically): David Borman, 4168 Yuchung Cheng, Martin Duke, Kevin Lahey, Kevin Mason, Matt Mathis, 4169 Hagen Paul Pfeifer, Anthony Sabatini, Joe Touch, Reji Varghese, Lloyd 4170 Wood, and Alex Zimmermann. Joe Touch provided help in clarifying the 4171 description of segment size parameters and PMTUD/PLPMTUD 4172 recommendations. 4174 This document includes content from errata that were reported by 4175 (listed chronologically): Yin Shuming, Bob Braden, Morris M. Keesan, 4176 Pei-chun Cheng, Constantin Hagemeier, Vishwas Manral, Mykyta 4177 Yevstifeyev, EungJun Yi, Botong Huang. 4179 8. References 4181 8.1. Normative References 4183 [1] Postel, J., "Internet Protocol", STD 5, RFC 791, 4184 DOI 10.17487/RFC0791, September 1981, 4185 . 4187 [2] Mogul, J. and S. Deering, "Path MTU discovery", RFC 1191, 4188 DOI 10.17487/RFC1191, November 1990, 4189 . 4191 [3] McCann, J., Deering, S., and J. Mogul, "Path MTU Discovery 4192 for IP version 6", RFC 1981, DOI 10.17487/RFC1981, August 4193 1996, . 4195 [4] Bradner, S., "Key words for use in RFCs to Indicate 4196 Requirement Levels", BCP 14, RFC 2119, 4197 DOI 10.17487/RFC2119, March 1997, 4198 . 4200 [5] Deering, S. and R. Hinden, "Internet Protocol, Version 6 4201 (IPv6) Specification", RFC 2460, DOI 10.17487/RFC2460, 4202 December 1998, . 4204 [6] Nichols, K., Blake, S., Baker, F., and D. Black, 4205 "Definition of the Differentiated Services Field (DS 4206 Field) in the IPv4 and IPv6 Headers", RFC 2474, 4207 DOI 10.17487/RFC2474, December 1998, 4208 . 4210 [7] Borman, D., Deering, S., and R. Hinden, "IPv6 Jumbograms", 4211 RFC 2675, DOI 10.17487/RFC2675, August 1999, 4212 . 4214 [8] Lahey, K., "TCP Problems with Path MTU Discovery", 4215 RFC 2923, DOI 10.17487/RFC2923, September 2000, 4216 . 4218 [9] Ramakrishnan, K., Floyd, S., and D. Black, "The Addition 4219 of Explicit Congestion Notification (ECN) to IP", 4220 RFC 3168, DOI 10.17487/RFC3168, September 2001, 4221 . 4223 [10] Paxson, V., Allman, M., Chu, J., and M. Sargent, 4224 "Computing TCP's Retransmission Timer", RFC 6298, 4225 DOI 10.17487/RFC6298, June 2011, 4226 . 4228 [11] Gont, F., "Deprecation of ICMP Source Quench Messages", 4229 RFC 6633, DOI 10.17487/RFC6633, May 2012, 4230 . 4232 8.2. Informative References 4234 [12] Postel, J., "Transmission Control Protocol", STD 7, 4235 RFC 793, DOI 10.17487/RFC0793, September 1981, 4236 . 4238 [13] Nagle, J., "Congestion Control in IP/TCP Internetworks", 4239 RFC 896, DOI 10.17487/RFC0896, January 1984, 4240 . 4242 [14] Braden, R., Ed., "Requirements for Internet Hosts - 4243 Communication Layers", STD 3, RFC 1122, 4244 DOI 10.17487/RFC1122, October 1989, 4245 . 4247 [15] Almquist, P., "Type of Service in the Internet Protocol 4248 Suite", RFC 1349, DOI 10.17487/RFC1349, July 1992, 4249 . 4251 [16] Braden, R., "T/TCP -- TCP Extensions for Transactions 4252 Functional Specification", RFC 1644, DOI 10.17487/RFC1644, 4253 July 1994, . 4255 [17] Paxson, V., Allman, M., Dawson, S., Fenner, W., Griner, 4256 J., Heavens, I., Lahey, K., Semke, J., and B. Volz, "Known 4257 TCP Implementation Problems", RFC 2525, 4258 DOI 10.17487/RFC2525, March 1999, 4259 . 4261 [18] Xiao, X., Hannan, A., Paxson, V., and E. Crabbe, "TCP 4262 Processing of the IPv4 Precedence Field", RFC 2873, 4263 DOI 10.17487/RFC2873, June 2000, 4264 . 4266 [19] Mathis, M. and J. Heffner, "Packetization Layer Path MTU 4267 Discovery", RFC 4821, DOI 10.17487/RFC4821, March 2007, 4268 . 4270 [20] Eddy, W., "TCP SYN Flooding Attacks and Common 4271 Mitigations", RFC 4987, DOI 10.17487/RFC4987, August 2007, 4272 . 4274 [21] Touch, J., "Defending TCP Against Spoofing Attacks", 4275 RFC 4953, DOI 10.17487/RFC4953, July 2007, 4276 . 4278 [22] Culley, P., Elzur, U., Recio, R., Bailey, S., and J. 4279 Carrier, "Marker PDU Aligned Framing for TCP 4280 Specification", RFC 5044, DOI 10.17487/RFC5044, October 4281 2007, . 4283 [23] Gont, F., "TCP's Reaction to Soft Errors", RFC 5461, 4284 DOI 10.17487/RFC5461, February 2009, 4285 . 4287 [24] StJohns, M., Atkinson, R., and G. Thomas, "Common 4288 Architecture Label IPv6 Security Option (CALIPSO)", 4289 RFC 5570, DOI 10.17487/RFC5570, July 2009, 4290 . 4292 [25] Allman, M., Paxson, V., and E. Blanton, "TCP Congestion 4293 Control", RFC 5681, DOI 10.17487/RFC5681, September 2009, 4294 . 4296 [26] Sandlund, K., Pelletier, G., and L-E. Jonsson, "The RObust 4297 Header Compression (ROHC) Framework", RFC 5795, 4298 DOI 10.17487/RFC5795, March 2010, 4299 . 4301 [27] Touch, J., Mankin, A., and R. Bonica, "The TCP 4302 Authentication Option", RFC 5925, DOI 10.17487/RFC5925, 4303 June 2010, . 4305 [28] Ramaiah, A., Stewart, R., and M. Dalal, "Improving TCP's 4306 Robustness to Blind In-Window Attacks", RFC 5961, 4307 DOI 10.17487/RFC5961, August 2010, 4308 . 4310 [29] Gont, F. and A. Yourtchenko, "On the Implementation of the 4311 TCP Urgent Mechanism", RFC 6093, DOI 10.17487/RFC6093, 4312 January 2011, . 4314 [30] Gont, F., "Reducing the TIME-WAIT State Using TCP 4315 Timestamps", BCP 159, RFC 6191, DOI 10.17487/RFC6191, 4316 April 2011, . 4318 [31] Bashyam, M., Jethanandani, M., and A. Ramaiah, "TCP Sender 4319 Clarification for Persist Condition", RFC 6429, 4320 DOI 10.17487/RFC6429, December 2011, 4321 . 4323 [32] Gont, F. and S. Bellovin, "Defending against Sequence 4324 Number Attacks", RFC 6528, DOI 10.17487/RFC6528, February 4325 2012, . 4327 [33] Borman, D., "TCP Options and Maximum Segment Size (MSS)", 4328 RFC 6691, DOI 10.17487/RFC6691, July 2012, 4329 . 4331 [34] Touch, J., "Shared Use of Experimental TCP Options", 4332 RFC 6994, DOI 10.17487/RFC6994, August 2013, 4333 . 4335 [35] Borman, D., Braden, B., Jacobson, V., and R. 4336 Scheffenegger, Ed., "TCP Extensions for High Performance", 4337 RFC 7323, DOI 10.17487/RFC7323, September 2014, 4338 . 4340 [36] Cheng, Y., Chu, J., Radhakrishnan, S., and A. Jain, "TCP 4341 Fast Open", RFC 7413, DOI 10.17487/RFC7413, December 2014, 4342 . 4344 [37] Duke, M., Braden, R., Eddy, W., Blanton, E., and A. 4345 Zimmermann, "A Roadmap for Transmission Control Protocol 4346 (TCP) Specification Documents", RFC 7414, 4347 DOI 10.17487/RFC7414, February 2015, 4348 . 4350 [38] Black, D., Ed. and P. Jones, "Differentiated Services 4351 (Diffserv) and Real-Time Communication", RFC 7657, 4352 DOI 10.17487/RFC7657, November 2015, 4353 . 4355 [39] Fairhurst, G. and M. Welzl, "The Benefits of Using 4356 Explicit Congestion Notification (ECN)", RFC 8087, 4357 DOI 10.17487/RFC8087, March 2017, 4358 . 4360 [40] Fairhurst, G., Ed., Trammell, B., Ed., and M. Kuehlewind, 4361 Ed., "Services Provided by IETF Transport Protocols and 4362 Congestion Control Mechanisms", RFC 8095, 4363 DOI 10.17487/RFC8095, March 2017, 4364 . 4366 [41] IANA, "Transmission Control Protocol (TCP) Parameters, 4367 https://www.iana.org/assignments/tcp-parameters/ 4368 tcp-parameters.xhtml", 2017. 4370 [42] Gont, F., "Processing of IP Security/Compartment and 4371 Precedence Information by TCP", draft-gont-tcpm-tcp- 4372 seccomp-prec-00 (work in progress), March 2012. 4374 [43] Gont, F. and D. Borman, "On the Validation of TCP Sequence 4375 Numbers", draft-gont-tcpm-tcp-seq-validation-02 (work in 4376 progress), March 2015. 4378 [44] Bittau, A., Giffin, D., Handley, M., Mazieres, D., Slack, 4379 Q., and E. Smith, "Cryptographic protection of TCP Streams 4380 (tcpcrypt)", draft-ietf-tcpinc-tcpcrypt-09 (work in 4381 progress), November 2017. 4383 [45] Minshall, G., "A Proposed Modification to Nagle's 4384 Algorithm", draft-minshall-nagle-01 (work in progress), 4385 June 1999. 4387 [46] Dalal, Y. and C. Sunshine, "Connection Management in 4388 Transport Protocols", Computer Networks Vol. 2, No. 6, pp. 4389 454-473, December 1978. 4391 Appendix A. Other Implementation Notes 4393 This section includes additional notes and references on TCP 4394 implementation decisions that are currently not a part of the RFC 4395 series or included within the TCP standard. These items can be 4396 considered by implementers, but there was not yet a consensus to 4397 include them in the standard. 4399 A.1. IP Security Compartment and Precedence 4401 RFC 793 requires checking the IP security compartment and precedence 4402 on incoming TCP segments for consistency within a connection, and 4403 with application requests. Each of these aspects of IP have become 4404 outdated, without specific updates to RFC 793. The issues with 4405 precedence were fixed by [18] which is Standards Track, and so this 4406 present TCP specification includes those changes. However, the state 4407 of IP security options that may be used by MLS systems is not as 4408 clean. 4410 Implementers of MLS systems that use IP security options (e.g. IPSO, 4411 CIPSO, or CALIPSO) should implement any additional logic appropriate 4412 for their requirements. 4414 Reseting connections when incoming packets do not meet expected 4415 security compartment or precedence expectations has been recognized 4416 as a possible attack vector [42], and there has been discussion about 4417 ammending the TCP specification to prevent connections from being 4418 aborted due to non-matching IP security compartment and DiffServ 4419 codepoint values. 4421 A.2. Sequence Number Validation 4423 There are cases where the TCP sequence number validation rules can 4424 prevent ACK fields from being processed. This can result in 4425 connection issues, as described in [43], which includes descriptions 4426 of potential problems in conditions of simultaneous open, self- 4427 connects, simultaneous close, and simultaneous window probes. The 4428 document also describes potential changes to the TCP specification to 4429 mitigate the issue by expanding the acceptable sequence numbers. 4431 In Internet usage of TCP, these conditions are rarely occuring. 4432 Common operating systems include different alternative mitigations, 4433 and the standard has not been updated yet to codify one of them, but 4434 implementers should consider the problems described in [43]. 4436 A.3. Nagle Modification 4438 In common operating systems, both the Nagle algorithm and delayed 4439 acknowledgements are implemented and enabled by default. TCP is used 4440 by many applications that have a request-response style of 4441 communication, where the combination of the Nagle algorithm and 4442 delayed acknowledgements can result in poor application performance. 4443 A modification to the Nagle algorithm is described in [45] that 4444 improves the situation for these applications. 4446 This modification is implemented in some common operating systems, 4447 and does not impact TCP interoperability. Additionally, many 4448 applications simply disable Nagle, since this is generally supported 4449 by a socket option. The TCP standard has not been updated to include 4450 this Nagle modification, but implementers may find it beneficial to 4451 consider. 4453 A.4. Low Water Mark 4455 TODO - mention the low watermark function that is in Linux - 4456 suggested by Michael Welzl 4458 SO_SNDLOWAT and SO_RCVLOWAT would be potential enhancements to the 4459 abstract TCP API 4461 TCP_NOTSENT_LOWAT is what Michael is talking about, that helps a 4462 sending TCP application to help avoid creating large amounts of 4463 buffered data (and corresponding latency). This is useful for 4464 applications that are multiplexing data from multiple upper level 4465 streams onto a connection, especially when streams may be a mix of 4466 interactive/realtime and bulk data transfer. 4468 Appendix B. TCP Requirement Summary 4470 This section is adapted from RFC 1122. 4472 TODO: This needs to be worked on a little bit still, to fix the 4473 remaining TBDs. Through this, it became clear that content on PUSH 4474 needs to be included from 793/1122 still. 4476 TODO: NOTE that PMTUD+PLPMTUD is not included in this table of 4477 recommendations. 4479 | | | | |S| | 4480 | | | | |H| |F 4481 | | | | |O|M|o 4482 | | |S| |U|U|o 4483 | | |H| |L|S|t 4484 | |M|O| |D|T|n 4485 | |U|U|M| | |o 4486 | |S|L|A|N|N|t 4487 | |T|D|Y|O|O|t 4488 FEATURE | ReqID | | | |T|T|e 4489 -------------------------------------------------|--------|-|-|-|-|-|-- 4490 | | | | | | | 4491 Push flag | | | | | | | 4492 Aggregate or queue un-pushed data | TBD | | |x| | | 4493 Sender collapse successive PSH flags | TBD | |x| | | | 4494 SEND call can specify PUSH | TBD | | |x| | | 4495 If cannot: sender buffer indefinitely | TBD | | | | |x| 4496 If cannot: PSH last segment | TBD |x| | | | | 4497 Notify receiving ALP of PSH | TBD | | |x| | |1 4498 Send max size segment when possible | TBD | |x| | | | 4499 | | | | | | | 4500 Window | | | | | | | 4501 Treat as unsigned number | MUST-1 |x| | | | | 4502 Handle as 32-bit number | REC-1 | |x| | | | 4503 Shrink window from right | SHLD-14| | | |x| | 4504 - Send new data when window shrinks | SHLD-15| | | |x| | 4505 - Retransmit old unacked data within window | SHLD-16| |x| | | | 4506 - Time out conn for data past right edge | SHLD-17| | | |x| | 4507 Robust against shrinking window | MUST-34|x| | | | | 4508 Receiver's window closed indefinitely | MAY-8 | | |x| | | 4509 Use standard probing logic | MUST-35|x| | | | | 4510 Sender probe zero window | MUST-36|x| | | | | 4511 First probe after RTO | TBD | |x| | | | 4512 Exponential backoff | TBD | |x| | | | 4513 Allow window stay zero indefinitely | MUST-37|x| | | | | 4514 Sender timeout OK conn with zero wind | TBD | | | | |x| 4515 Retransmit old data beyond SND.UNA+SND.WND | MAY-7 | | |x| | | 4516 | | | | | | | 4517 Urgent Data | | | | | | | 4518 Include support for urgent pointer | MUST-30|x| | | | | 4519 Pointer indicates first non-urgent octet | TBD |x| | | | | 4520 Arbitrary length urgent data sequence | MUST-31|x| | | | | 4521 Inform ALP asynchronously of urgent data | MUST-32|x| | | | |1 4522 ALP can learn if/how much urgent data Q'd | MUST-33|x| | | | |1 4523 ALP employ the urgent mechanism | SHLD-13| | | |x| | 4524 | | | | | | | 4525 TCP Options | | | | | | | 4526 Support the mandatory option set | MUST-4 |x| | | | | 4527 Receive TCP option in any segment | MUST-5 |x| | | | | 4528 Ignore unsupported options | MUST-6 |x| | | | | 4529 Cope with illegal option length | MUST-7 |x| | | | | 4530 Implement sending & receiving MSS option | MUST-14|x| | | | | 4531 IPv4 Send MSS option unless 536 | SHLD-5 | |x| | | | 4532 IPv6 Send MSS option unless 1220 | SHLD-5 | |x| | | | 4533 Send MSS option always | MAY-3 | | |x| | | 4534 IPv4 Send-MSS default is 536 | MUST-15|x| | | | | 4535 IPv6 Send-MSS default is 1220 | MUST-15|x| | | | | 4536 Calculate effective send seg size | MUST-16|x| | | | | 4537 MSS accounts for varying MTU | SHLD-6 | |x| | | | 4538 | | | | | | | 4539 TCP Checksums | | | | | | | 4540 Sender compute checksum | MUST-2 |x| | | | | 4541 Receiver check checksum | MUST-3 |x| | | | | 4542 | | | | | | | 4543 ISN Selection | | | | | | | 4544 Include a clock-driven ISN generator component | MUST-8 |x| | | | | 4545 Secure ISN generator with a PRF component | SHLD-1 | |x| | | | 4546 PRF computable from outside the host | MUST-9 | | | | |x| 4547 | | | | | | | 4548 Opening Connections | | | | | | | 4549 Support simultaneous open attempts | MUST-10|x| | | | | 4550 SYN-RECEIVED remembers last state | MUST-11|x| | | | | 4551 Passive Open call interfere with others | MUST-41| | | | |x| 4552 Function: simultan. LISTENs for same port | MUST-42|x| | | | | 4553 Ask IP for src address for SYN if necc. | MUST-44|x| | | | | 4554 Otherwise, use local addr of conn. | MUST-45|x| | | | | 4555 OPEN to broadcast/multicast IP Address | MUST-46| | | | |x| 4556 Silently discard seg to bcast/mcast addr | TBD |x| | | | | 4557 | | | | | | | 4558 Closing Connections | | | | | | | 4559 RST can contain data | SHLD-2 | |x| | | | 4560 Inform application of aborted conn | MUST-12|x| | | | | 4561 Half-duplex close connections | MAY-1 | | |x| | | 4562 Send RST to indicate data lost | SHLD-3 | |x| | | | 4563 In TIME-WAIT state for 2MSL seconds | MUST-13|x| | | | | 4564 Accept SYN from TIME-WAIT state | MAY-2 | | |x| | | 4565 Use Timestamps to reduce TIME-WAIT | SHLD-4 | |x| | | | 4566 | | | | | | | 4567 Retransmissions | | | | | | | 4568 Implement RFC 5681 | MUST-19|x| | | | | 4569 Retransmit with same IP ident | MAY-4 | | |x| | | 4570 Karn's algorithm | MUST-18|x| | | | | 4571 | | | | | | | 4572 Generating ACK's: | | | | | | | 4573 Aggregate whenever possible | MUST-58|x| | | | | 4574 Queue out-of-order segments | TBD | |x| | | | 4575 Process all Q'd before send ACK | MUST-59|x| | | | | 4576 Send ACK for out-of-order segment | MAY-13 | | |x| | | 4577 Delayed ACK's | SHLD-18| |x| | | | 4578 Delay < 0.5 seconds | MUST-40|x| | | | | 4579 Every 2nd full-sized segment ACK'd | SHLD-19|x| | | | | 4580 Receiver SWS-Avoidance Algorithm | MUST-39|x| | | | | 4581 | | | | | | | 4582 Sending data | | | | | | | 4583 Configurable TTL | MUST-49|x| | | | | 4584 Sender SWS-Avoidance Algorithm | MUST-38|x| | | | | 4585 Nagle algorithm | SHLD-7 | |x| | | | 4586 Application can disable Nagle algorithm | MUST-17|x| | | | | 4587 | | | | | | | 4588 Connection Failures: | | | | | | | 4589 Negative advice to IP on R1 retxs | MUST-20|x| | | | | 4590 Close connection on R2 retxs | MUST-20|x| | | | | 4591 ALP can set R2 | MUST-21|x| | | | |1 4592 Inform ALP of R1<=retxs inform ALP | SHLD-25| |x| | | | 4620 Dest. Unreach (0,1,5) => abort conn | MUST-56| | | | |x| 4621 Dest. Unreach (2-4) => abort conn | SHLD-26| |x| | | | 4622 Source Quench => silent discard | MUST-55|x| | | | | 4623 Time Exceeded => tell ALP, don't abort | MUST-56| | | | |x| 4624 Param Problem => tell ALP, don't abort | MUST-56| | | | |x| 4625 | | | | | | | 4626 Address Validation | | | | | | | 4627 Reject OPEN call to invalid IP address | MUST-46|x| | | | | 4628 Reject SYN from invalid IP address | TBD |x| | | | | 4629 Silently discard SYN to bcast/mcast addr | MUST-57|x| | | | | 4630 | | | | | | | 4631 TCP/ALP Interface Services | | | | | | | 4632 Error Report mechanism | MUST-47|x| | | | | 4633 ALP can disable Error Report Routine | SHLD-20| |x| | | | 4634 ALP can specify DiffServ field for sending | MUST-48|x| | | | | 4635 Passed unchanged to IP | SHLD-22| |x| | | | 4636 ALP can change DiffServ field during connection| SHLD-21| |x| | | | 4637 ALP generally changing DiffServ during conn. | SHLD-23| | | |x| | 4638 Pass received DiffServ field up to ALP | MAY-9 | | |x| | | 4639 FLUSH call | MAY-14 | | |x| | | 4640 Optional local IP addr parm. in OPEN | TBD |x| | | | | 4641 | | | | | | | 4642 RFC 5961 Support: | | | | | | | 4643 Implement data injection protection | MAY-12 | | |x| | | 4644 | | | | | | | 4645 Explicit Congestion Notification: | | | | | | | 4646 Support ECN | SHLD-8 | |x| | | | 4647 -------------------------------------------------|--------|-|-|-|-|-|-- 4649 FOOTNOTES: (1) "ALP" means Application-Layer program. 4651 Author's Address 4653 Wesley M. Eddy (editor) 4654 MTI Systems 4655 US 4657 Email: wes@mti-systems.com