idnits 2.17.1 draft-ietf-tcpm-rfc793bis-09.txt: Checking boilerplate required by RFC 5378 and the IETF Trust (see https://trustee.ietf.org/license-info): ---------------------------------------------------------------------------- No issues found here. Checking nits according to https://www.ietf.org/id-info/1id-guidelines.txt: ---------------------------------------------------------------------------- No issues found here. Checking nits according to https://www.ietf.org/id-info/checklist : ---------------------------------------------------------------------------- ** The document seems to lack a Security Considerations section. == There are 3 instances of lines with non-RFC2606-compliant FQDNs in the document. -- The draft header indicates that this document obsoletes RFC6093, but the abstract doesn't seem to mention this, which it should. -- The draft header indicates that this document obsoletes RFC2873, but the abstract doesn't seem to mention this, which it should. -- The draft header indicates that this document obsoletes RFC6429, but the abstract doesn't seem to mention this, which it should. -- The draft header indicates that this document obsoletes RFC879, but the abstract doesn't seem to mention this, which it should. Miscellaneous warnings: ---------------------------------------------------------------------------- == The copyright year in the IETF Trust and authors Copyright Line does not match the current year (Using the creation date from RFC1122, updated by this document, for RFC5378 checks: 1989-10-01) -- The document seems to contain a disclaimer for pre-RFC5378 work, and may have content which was first submitted before 10 November 2008. The disclaimer is necessary when there are original authors that you have been unable to contact, or if some do not wish to grant the BCP78 rights to the IETF Trust. If you are able to get all authors (current and original) to grant those rights, you can and should remove the disclaimer; otherwise, the disclaimer is needed and you can ignore this comment. (See the Legal Provisions document at https://trustee.ietf.org/license-info for more information.) -- The document date (March 28, 2018) is 2220 days in the past. Is this intentional? Checking references for intended status: Proposed Standard ---------------------------------------------------------------------------- (See RFCs 3967 and 4897 for information about using normative references to lower-maturity documents in RFCs) == Unused Reference: '43' is defined on line 4323, but no explicit reference was found in the text ** Obsolete normative reference: RFC 1981 (ref. '3') (Obsoleted by RFC 8201) ** Obsolete normative reference: RFC 2460 (ref. '5') (Obsoleted by RFC 8200) ** Downref: Normative reference to an Informational RFC: RFC 2923 (ref. '8') -- Obsolete informational reference (is this intentional?): RFC 793 (ref. '12') (Obsoleted by RFC 9293) -- Obsolete informational reference (is this intentional?): RFC 896 (ref. '13') (Obsoleted by RFC 7805) -- Obsolete informational reference (is this intentional?): RFC 1349 (ref. '15') (Obsoleted by RFC 2474) -- Obsolete informational reference (is this intentional?): RFC 1644 (ref. '16') (Obsoleted by RFC 6247) -- Obsolete informational reference (is this intentional?): RFC 2873 (ref. '17') (Obsoleted by RFC 9293) -- Obsolete informational reference (is this intentional?): RFC 6093 (ref. '28') (Obsoleted by RFC 9293) -- Obsolete informational reference (is this intentional?): RFC 6429 (ref. '30') (Obsoleted by RFC 9293) -- Obsolete informational reference (is this intentional?): RFC 6528 (ref. '31') (Obsoleted by RFC 9293) -- Obsolete informational reference (is this intentional?): RFC 6691 (ref. '32') (Obsoleted by RFC 9293) == Outdated reference: A later version (-04) exists of draft-gont-tcpm-tcp-seq-validation-02 == Outdated reference: A later version (-15) exists of draft-ietf-tcpinc-tcpcrypt-09 Summary: 4 errors (**), 0 flaws (~~), 5 warnings (==), 15 comments (--). Run idnits with the --verbose option for more detailed information about the items above. -------------------------------------------------------------------------------- 2 Internet Engineering Task Force W. Eddy, Ed. 3 Internet-Draft MTI Systems 4 Obsoletes: 793, 879, 2873, 6093, 6429, March 28, 2018 5 6528, 6691 (if approved) 6 Updates: 5961, 1122 (if approved) 7 Intended status: Standards Track 8 Expires: September 29, 2018 10 Transmission Control Protocol Specification 11 draft-ietf-tcpm-rfc793bis-09 13 Abstract 15 This document specifies the Internet's Transmission Control Protocol 16 (TCP). TCP is an important transport layer protocol in the Internet 17 stack, and has continuously evolved over decades of use and growth of 18 the Internet. Over this time, a number of changes have been made to 19 TCP as it was specified in RFC 793, though these have only been 20 documented in a piecemeal fashion. This document collects and brings 21 those changes together with the protocol specification from RFC 793. 22 This document obsoletes RFC 793, as well as 879, 2873, 6093, 6429, 23 6528, and 6691 that updated parts of RFC 793. It updates RFC 1122, 24 and should be considered as a replacement for the portions of that 25 document dealing with TCP requirements. It updates RFC 5961 due to a 26 small clarification in reset handling while in the SYN-RECEIVED 27 state. 29 RFC EDITOR NOTE: If approved for publication as an RFC, this should 30 be marked additionally as "STD: 7" and replace RFC 793 in that role. 32 Requirements Language 34 The key words "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT", 35 "SHOULD", "SHOULD NOT", "RECOMMENDED", "MAY", and "OPTIONAL" in this 36 document are to be interpreted as described in RFC 2119 [4]. 38 Status of This Memo 40 This Internet-Draft is submitted in full conformance with the 41 provisions of BCP 78 and BCP 79. 43 Internet-Drafts are working documents of the Internet Engineering 44 Task Force (IETF). Note that other groups may also distribute 45 working documents as Internet-Drafts. The list of current Internet- 46 Drafts is at https://datatracker.ietf.org/drafts/current/. 48 Internet-Drafts are draft documents valid for a maximum of six months 49 and may be updated, replaced, or obsoleted by other documents at any 50 time. It is inappropriate to use Internet-Drafts as reference 51 material or to cite them other than as "work in progress." 53 This Internet-Draft will expire on September 29, 2018. 55 Copyright Notice 57 Copyright (c) 2018 IETF Trust and the persons identified as the 58 document authors. All rights reserved. 60 This document is subject to BCP 78 and the IETF Trust's Legal 61 Provisions Relating to IETF Documents 62 (https://trustee.ietf.org/license-info) in effect on the date of 63 publication of this document. Please review these documents 64 carefully, as they describe your rights and restrictions with respect 65 to this document. Code Components extracted from this document must 66 include Simplified BSD License text as described in Section 4.e of 67 the Trust Legal Provisions and are provided without warranty as 68 described in the Simplified BSD License. 70 This document may contain material from IETF Documents or IETF 71 Contributions published or made publicly available before November 72 10, 2008. The person(s) controlling the copyright in some of this 73 material may not have granted the IETF Trust the right to allow 74 modifications of such material outside the IETF Standards Process. 75 Without obtaining an adequate license from the person(s) controlling 76 the copyright in such materials, this document may not be modified 77 outside the IETF Standards Process, and derivative works of it may 78 not be created outside the IETF Standards Process, except to format 79 it for publication as an RFC or to translate it into languages other 80 than English. 82 Table of Contents 84 1. Purpose and Scope . . . . . . . . . . . . . . . . . . . . . . 3 85 2. Introduction . . . . . . . . . . . . . . . . . . . . . . . . 4 86 2.1. Key TCP Concepts . . . . . . . . . . . . . . . . . . . . 5 87 3. Functional Specification . . . . . . . . . . . . . . . . . . 6 88 3.1. Header Format . . . . . . . . . . . . . . . . . . . . . . 6 89 3.2. Terminology . . . . . . . . . . . . . . . . . . . . . . . 11 90 3.3. Sequence Numbers . . . . . . . . . . . . . . . . . . . . 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 . . . . . . . . . . . . . . . . . 35 98 3.7.3. Interfaces with Variable MTU Values . . . . . . . . . 36 99 3.7.4. Nagle Algorithm . . . . . . . . . . . . . . . . . . . 36 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 . . . . . . . . . . . . . . . 38 105 3.8.4. TCP Keep-Alives . . . . . . . . . . . . . . . . . . . 39 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 . . . . . . . . . . . . . . . . . 45 110 3.9.2. TCP/Lower-Level Interface . . . . . . . . . . . . . . 53 111 3.10. Event Processing . . . . . . . . . . . . . . . . . . . . 56 112 3.11. Glossary . . . . . . . . . . . . . . . . . . . . . . . . 81 113 4. Changes from RFC 793 . . . . . . . . . . . . . . . . . . . . 86 114 5. IANA Considerations . . . . . . . . . . . . . . . . . . . . . 91 115 6. Security and Privacy Considerations . . . . . . . . . . . . . 91 116 7. Acknowledgements . . . . . . . . . . . . . . . . . . . . . . 92 117 8. References . . . . . . . . . . . . . . . . . . . . . . . . . 92 118 8.1. Normative References . . . . . . . . . . . . . . . . . . 92 119 8.2. Informative References . . . . . . . . . . . . . . . . . 94 120 Appendix A. Other Implementation Notes . . . . . . . . . . . . . 97 121 A.1. IP Security Compartment and Precedence . . . . . . . . . 97 122 A.2. Sequence Number Validation . . . . . . . . . . . . . . . 97 123 A.3. Nagle Modification . . . . . . . . . . . . . . . . . . . 98 124 A.4. Low Water Mark . . . . . . . . . . . . . . . . . . . . . 98 125 Appendix B. TCP Requirement Summary . . . . . . . . . . . . . . 98 126 Author's Address . . . . . . . . . . . . . . . . . . . . . . . . 102 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 [36]. 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" [36] 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. [24]) 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 [34], 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 [39]. 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. It is RECOMMENDED that implementations will reserve 336 32-bit fields for the send and receive window sizes in the 337 connection record and do all window computations with 32 bits. 339 Checksum: 16 bits 341 The checksum field is the 16 bit one's complement of the one's 342 complement sum of all 16 bit words in the header and text. If a 343 segment contains an odd number of header and text octets to be 344 checksummed, the last octet is padded on the right with zeros to 345 form a 16 bit word for checksum purposes. The pad is not 346 transmitted as part of the segment. While computing the checksum, 347 the checksum field itself is replaced with zeros. 349 The checksum also covers a pseudo header conceptually prefixed to 350 the TCP header. The pseudo header is 96 bits for IPv4 and 320 bits 351 for IPv6. For IPv4, this pseudo header contains the Source 352 Address, the Destination Address, the Protocol, and TCP length. 353 This gives the TCP protection against misrouted segments. This 354 information is carried in IPv4 and is transferred across the TCP/ 355 Network interface in the arguments or results of calls by the TCP 356 on the IP. 358 +--------+--------+--------+--------+ 359 | Source Address | 360 +--------+--------+--------+--------+ 361 | Destination Address | 362 +--------+--------+--------+--------+ 363 | zero | PTCL | TCP Length | 364 +--------+--------+--------+--------+ 366 The TCP Length is the TCP header length plus the data length in 367 octets (this is not an explicitly transmitted quantity, but is 368 computed), and it does not count the 12 octets of the pseudo 369 header. 371 For IPv6, the pseudo header is contained in section 8.1 of RFC 2460 372 [5], and contains the IPv6 Source Address and Destination Address, 373 an Upper Layer Packet Length (a 32-bit value otherwise equivalent 374 to TCP Length in the IPv4 pseudo header), three bytes of zero- 375 padding, and a Next Header value (differing from the IPv6 header 376 value in the case of extension headers present in between IPv6 and 377 TCP). 379 The TCP checksum is never optional. The sender MUST generate it 380 and the receiver MUST check it. 382 Urgent Pointer: 16 bits 384 This field communicates the current value of the urgent pointer as 385 a positive offset from the sequence number in this segment. The 386 urgent pointer points to the sequence number of the octet following 387 the urgent data. This field is only be interpreted in segments 388 with the URG control bit set. 390 Options: variable 392 Options may occupy space at the end of the TCP header and are a 393 multiple of 8 bits in length. All options are included in the 394 checksum. An option may begin on any octet boundary. There are 395 two cases for the format of an option: 397 Case 1: A single octet of option-kind. 399 Case 2: An octet of option-kind, an octet of option-length, and 400 the actual option-data octets. 402 The option-length counts the two octets of option-kind and option- 403 length as well as the option-data octets. 405 Note that the list of options may be shorter than the data offset 406 field might imply. The content of the header beyond the End-of- 407 Option option must be header padding (i.e., zero). 409 The list of all currently defined options is managed by IANA [40], 410 and each option is defined in other RFCs, as indicated there. That 411 set includes experimental options that can be extended to support 412 multiple concurrent uses [33]. 414 A given TCP implementation can support any currently defined 415 options, but the following options MUST be supported (kind 416 indicated in octal): 418 Kind Length Meaning 419 ---- ------ ------- 420 0 - End of option list. 421 1 - No-Operation. 422 2 4 Maximum Segment Size. 424 A TCP MUST be able to receive a TCP option in any segment. 426 A TCP MUST ignore without error any TCP option it does not 427 implement, assuming that the option has a length field (all TCP 428 options except End of option list and No-Operation have length 429 fields). TCP MUST be prepared to handle an illegal option length 430 (e.g., zero) without crashing; a suggested procedure is to reset 431 the connection and log the reason. 433 Specific Option Definitions 435 End of Option List 437 +--------+ 438 |00000000| 439 +--------+ 440 Kind=0 442 This option code indicates the end of the option list. This 443 might not coincide with the end of the TCP header according to 444 the Data Offset field. This is used at the end of all options, 445 not the end of each option, and need only be used if the end of 446 the options would not otherwise coincide with the end of the TCP 447 header. 449 No-Operation 451 +--------+ 452 |00000001| 453 +--------+ 454 Kind=1 456 This option code may be used between options, for example, to 457 align the beginning of a subsequent option on a word boundary. 458 There is no guarantee that senders will use this option, so 459 receivers must be prepared to process options even if they do 460 not begin on a word boundary. 462 Maximum Segment Size (MSS) 464 +--------+--------+---------+--------+ 465 |00000010|00000100| max seg size | 466 +--------+--------+---------+--------+ 467 Kind=2 Length=4 469 Maximum Segment Size Option Data: 16 bits 471 If this option is present, then it communicates the maximum 472 receive segment size at the TCP which sends this segment. This 473 value is limited by the IP reassembly limit. This field may be 474 sent in the initial connection request (i.e., in segments with 475 the SYN control bit set) and must not be sent in other segments. 476 If this option is not used, any segment size is allowed. A more 477 complete description of this option is in Section 3.7.1. 479 Padding: variable 481 The TCP header padding is used to ensure that the TCP header ends 482 and data begins on a 32 bit boundary. The padding is composed of 483 zeros. 485 3.2. Terminology 487 Before we can discuss very much about the operation of the TCP we 488 need to introduce some detailed terminology. The maintenance of a 489 TCP connection requires the remembering of several variables. We 490 conceive of these variables being stored in a connection record 491 called a Transmission Control Block or TCB. Among the variables 492 stored in the TCB are the local and remote socket numbers, the IP 493 security level and compartment of the connection, pointers to the 494 user's send and receive buffers, pointers to the retransmit queue and 495 to the current segment. In addition several variables relating to 496 the send and receive sequence numbers are stored in the TCB. 498 Send Sequence Variables 500 SND.UNA - send unacknowledged 501 SND.NXT - send next 502 SND.WND - send window 503 SND.UP - send urgent pointer 504 SND.WL1 - segment sequence number used for last window update 505 SND.WL2 - segment acknowledgment number used for last window 506 update 507 ISS - initial send sequence number 509 Receive Sequence Variables 511 RCV.NXT - receive next 512 RCV.WND - receive window 513 RCV.UP - receive urgent pointer 514 IRS - initial receive sequence number 516 The following diagrams may help to relate some of these variables to 517 the sequence space. 519 Send Sequence Space 521 1 2 3 4 522 ----------|----------|----------|---------- 523 SND.UNA SND.NXT SND.UNA 524 +SND.WND 526 1 - old sequence numbers which have been acknowledged 527 2 - sequence numbers of unacknowledged data 528 3 - sequence numbers allowed for new data transmission 529 4 - future sequence numbers which are not yet allowed 531 Send Sequence Space 533 Figure 2 535 The send window is the portion of the sequence space labeled 3 in 536 Figure 2. 538 Receive Sequence Space 540 1 2 3 541 ----------|----------|---------- 542 RCV.NXT RCV.NXT 543 +RCV.WND 545 1 - old sequence numbers which have been acknowledged 546 2 - sequence numbers allowed for new reception 547 3 - future sequence numbers which are not yet allowed 549 Receive Sequence Space 551 Figure 3 553 The receive window is the portion of the sequence space labeled 2 in 554 Figure 3. 556 There are also some variables used frequently in the discussion that 557 take their values from the fields of the current segment. 559 Current Segment Variables 561 SEG.SEQ - segment sequence number 562 SEG.ACK - segment acknowledgment number 563 SEG.LEN - segment length 564 SEG.WND - segment window 565 SEG.UP - segment urgent pointer 567 A connection progresses through a series of states during its 568 lifetime. The states are: LISTEN, SYN-SENT, SYN-RECEIVED, 569 ESTABLISHED, FIN-WAIT-1, FIN-WAIT-2, CLOSE-WAIT, CLOSING, LAST-ACK, 570 TIME-WAIT, and the fictional state CLOSED. CLOSED is fictional 571 because it represents the state when there is no TCB, and therefore, 572 no connection. Briefly the meanings of the states are: 574 LISTEN - represents waiting for a connection request from any 575 remote TCP and port. 577 SYN-SENT - represents waiting for a matching connection request 578 after having sent a connection request. 580 SYN-RECEIVED - represents waiting for a confirming connection 581 request acknowledgment after having both received and sent a 582 connection request. 584 ESTABLISHED - represents an open connection, data received can be 585 delivered to the user. The normal state for the data transfer 586 phase of the connection. 588 FIN-WAIT-1 - represents waiting for a connection termination 589 request from the remote TCP, or an acknowledgment of the 590 connection termination request previously sent. 592 FIN-WAIT-2 - represents waiting for a connection termination 593 request from the remote TCP. 595 CLOSE-WAIT - represents waiting for a connection termination 596 request from the local user. 598 CLOSING - represents waiting for a connection termination request 599 acknowledgment from the remote TCP. 601 LAST-ACK - represents waiting for an acknowledgment of the 602 connection termination request previously sent to the remote TCP 603 (this termination request sent to the remote TCP already included 604 an acknowledgment of the termination request sent from the remote 605 TCP). 607 TIME-WAIT - represents waiting for enough time to pass to be sure 608 the remote TCP received the acknowledgment of its connection 609 termination request. 611 CLOSED - represents no connection state at all. 613 A TCP connection progresses from one state to another in response to 614 events. The events are the user calls, OPEN, SEND, RECEIVE, CLOSE, 615 ABORT, and STATUS; the incoming segments, particularly those 616 containing the SYN, ACK, RST and FIN flags; and timeouts. 618 The state diagram in Figure 4 illustrates only state changes, 619 together with the causing events and resulting actions, but addresses 620 neither error conditions nor actions which are not connected with 621 state changes. In a later section, more detail is offered with 622 respect to the reaction of the TCP to events. Some state names are 623 abbreviated or hyphenated differently in the diagram from how they 624 appear elsewhere in the document. 626 NOTA BENE: This diagram is only a summary and must not be taken as 627 the total specification. Many details are not included. 629 +---------+ ---------\ active OPEN 630 | CLOSED | \ ----------- 631 +---------+<---------\ \ create TCB 632 | ^ \ \ snd SYN 633 passive OPEN | | CLOSE \ \ 634 ------------ | | ---------- \ \ 635 create TCB | | delete TCB \ \ 636 V | \ \ 637 rcv RST (note 1) +---------+ CLOSE | \ 638 -------------------->| LISTEN | ---------- | | 639 / +---------+ delete TCB | | 640 / rcv SYN | | SEND | | 641 / ----------- | | ------- | V 642 +--------+ snd SYN,ACK / \ snd SYN +--------+ 643 | |<----------------- ------------------>| | 644 | SYN | rcv SYN | SYN | 645 | RCVD |<-----------------------------------------------| SENT | 646 | | snd SYN,ACK | | 647 | |------------------ -------------------| | 648 +--------+ rcv ACK of SYN \ / rcv SYN,ACK +--------+ 649 | -------------- | | ----------- 650 | x | | snd ACK 651 | V V 652 | CLOSE +---------+ 653 | ------- | ESTAB | 654 | snd FIN +---------+ 655 | CLOSE | | rcv FIN 656 V ------- | | ------- 657 +---------+ snd FIN / \ snd ACK +---------+ 658 | FIN |<----------------- ------------------>| CLOSE | 659 | WAIT-1 |------------------ | WAIT | 660 +---------+ rcv FIN \ +---------+ 661 | rcv ACK of FIN ------- | CLOSE | 662 | -------------- snd ACK | ------- | 663 V x V snd FIN V 664 +---------+ +---------+ +---------+ 665 |FINWAIT-2| | CLOSING | | LAST-ACK| 666 +---------+ +---------+ +---------+ 667 | rcv ACK of FIN | rcv ACK of FIN | 668 | rcv FIN -------------- | Timeout=2MSL -------------- | 669 | ------- x V ------------ x V 670 \ snd ACK +---------+delete TCB +---------+ 671 ------------------------>|TIME WAIT|------------------>| CLOSED | 672 +---------+ +---------+ 674 note 1: The transition from SYN-RECEIVED to LISTEN on receiving a RST is 675 conditional on having reached SYN-RECEIVED after a passive open. 677 note 2: An unshown transition exists from FIN-WAIT-1 to TIME-WAIT if 678 a FIN is received and the local FIN is also acknowledged. 680 TCP Connection State Diagram 682 Figure 4 684 3.3. Sequence Numbers 686 A fundamental notion in the design is that every octet of data sent 687 over a TCP connection has a sequence number. Since every octet is 688 sequenced, each of them can be acknowledged. The acknowledgment 689 mechanism employed is cumulative so that an acknowledgment of 690 sequence number X indicates that all octets up to but not including X 691 have been received. This mechanism allows for straight-forward 692 duplicate detection in the presence of retransmission. Numbering of 693 octets within a segment is that the first data octet immediately 694 following the header is the lowest numbered, and the following octets 695 are numbered consecutively. 697 It is essential to remember that the actual sequence number space is 698 finite, though very large. This space ranges from 0 to 2**32 - 1. 699 Since the space is finite, all arithmetic dealing with sequence 700 numbers must be performed modulo 2**32. This unsigned arithmetic 701 preserves the relationship of sequence numbers as they cycle from 702 2**32 - 1 to 0 again. There are some subtleties to computer modulo 703 arithmetic, so great care should be taken in programming the 704 comparison of such values. The symbol "=<" means "less than or 705 equal" (modulo 2**32). 707 The typical kinds of sequence number comparisons which the TCP must 708 perform include: 710 (a) Determining that an acknowledgment refers to some sequence 711 number sent but not yet acknowledged. 713 (b) Determining that all sequence numbers occupied by a segment 714 have been acknowledged (e.g., to remove the segment from a 715 retransmission queue). 717 (c) Determining that an incoming segment contains sequence numbers 718 which are expected (i.e., that the segment "overlaps" the receive 719 window). 721 In response to sending data the TCP will receive acknowledgments. 722 The following comparisons are needed to process the acknowledgments. 724 SND.UNA = oldest unacknowledged sequence number 726 SND.NXT = next sequence number to be sent 728 SEG.ACK = acknowledgment from the receiving TCP (next sequence 729 number expected by the receiving TCP) 731 SEG.SEQ = first sequence number of a segment 733 SEG.LEN = the number of octets occupied by the data in the segment 734 (counting SYN and FIN) 736 SEG.SEQ+SEG.LEN-1 = last sequence number of a segment 738 A new acknowledgment (called an "acceptable ack"), is one for which 739 the inequality below holds: 741 SND.UNA < SEG.ACK =< SND.NXT 743 A segment on the retransmission queue is fully acknowledged if the 744 sum of its sequence number and length is less or equal than the 745 acknowledgment value in the incoming segment. 747 When data is received the following comparisons are needed: 749 RCV.NXT = next sequence number expected on an incoming segments, 750 and is the left or lower edge of the receive window 752 RCV.NXT+RCV.WND-1 = last sequence number expected on an incoming 753 segment, and is the right or upper edge of the receive window 755 SEG.SEQ = first sequence number occupied by the incoming segment 756 SEG.SEQ+SEG.LEN-1 = last sequence number occupied by the incoming 757 segment 759 A segment is judged to occupy a portion of valid receive sequence 760 space if 762 RCV.NXT =< SEG.SEQ < RCV.NXT+RCV.WND 764 or 766 RCV.NXT =< SEG.SEQ+SEG.LEN-1 < RCV.NXT+RCV.WND 768 The first part of this test checks to see if the beginning of the 769 segment falls in the window, the second part of the test checks to 770 see if the end of the segment falls in the window; if the segment 771 passes either part of the test it contains data in the window. 773 Actually, it is a little more complicated than this. Due to zero 774 windows and zero length segments, we have four cases for the 775 acceptability of an incoming segment: 777 Segment Receive Test 778 Length Window 779 ------- ------- ------------------------------------------- 781 0 0 SEG.SEQ = RCV.NXT 783 0 >0 RCV.NXT =< SEG.SEQ < RCV.NXT+RCV.WND 785 >0 0 not acceptable 787 >0 >0 RCV.NXT =< SEG.SEQ < RCV.NXT+RCV.WND 788 or RCV.NXT =< SEG.SEQ+SEG.LEN-1 < RCV.NXT+RCV.WND 790 Note that when the receive window is zero no segments should be 791 acceptable except ACK segments. Thus, it is be possible for a TCP to 792 maintain a zero receive window while transmitting data and receiving 793 ACKs. However, even when the receive window is zero, a TCP must 794 process the RST and URG fields of all incoming segments. 796 We have taken advantage of the numbering scheme to protect certain 797 control information as well. This is achieved by implicitly 798 including some control flags in the sequence space so they can be 799 retransmitted and acknowledged without confusion (i.e., one and only 800 one copy of the control will be acted upon). Control information is 801 not physically carried in the segment data space. Consequently, we 802 must adopt rules for implicitly assigning sequence numbers to 803 control. The SYN and FIN are the only controls requiring this 804 protection, and these controls are used only at connection opening 805 and closing. For sequence number purposes, the SYN is considered to 806 occur before the first actual data octet of the segment in which it 807 occurs, while the FIN is considered to occur after the last actual 808 data octet in a segment in which it occurs. The segment length 809 (SEG.LEN) includes both data and sequence space occupying controls. 810 When a SYN is present then SEG.SEQ is the sequence number of the SYN. 812 Initial Sequence Number Selection 814 The protocol places no restriction on a particular connection being 815 used over and over again. A connection is defined by a pair of 816 sockets. New instances of a connection will be referred to as 817 incarnations of the connection. The problem that arises from this is 818 -- "how does the TCP identify duplicate segments from previous 819 incarnations of the connection?" This problem becomes apparent if 820 the connection is being opened and closed in quick succession, or if 821 the connection breaks with loss of memory and is then reestablished. 823 To avoid confusion we must prevent segments from one incarnation of a 824 connection from being used while the same sequence numbers may still 825 be present in the network from an earlier incarnation. We want to 826 assure this, even if a TCP crashes and loses all knowledge of the 827 sequence numbers it has been using. When new connections are 828 created, an initial sequence number (ISN) generator is employed which 829 selects a new 32 bit ISN. There are security issues that result if 830 an off-path attacker is able to predict or guess ISN values. 832 The recommended ISN generator is based on the combination of a 833 (possibly fictitious) 32 bit clock whose low order bit is incremented 834 roughly every 4 microseconds, and a pseudorandom hash function (PRF). 835 The clock component is intended to insure that with a Maximum Segment 836 Lifetime (MSL), generated ISNs will be unique, since it cycles 837 approximately every 4.55 hours, which is much longer than the MSL. 838 This recommended algorithm is further described in RFC 1948 and 839 builds on the basic clock-driven algorithm from RFC 793. 841 A TCP MUST use a clock-driven selection of initial sequence numbers, 842 and SHOULD generate its Initial Sequence Numbers with the expression: 844 ISN = M + F(localip, localport, remoteip, remoteport, secretkey) 846 where M is the 4 microsecond timer, and F() is a pseudorandom 847 function (PRF) of the connection's identifying parameters ("localip, 848 localport, remoteip, remoteport") and a secret key ("secretkey"). 849 F() MUST NOT be computable from the outside, or an attacker could 850 still guess at sequence numbers from the ISN used for some other 851 connection. The PRF could be implemented as a cryptographic has of 852 the concatenation of the TCP connection parameters and some secret 853 data. For discussion of the selection of a specific hash algorithm 854 and management of the secret key data, please see Section 3 of [31]. 856 For each connection there is a send sequence number and a receive 857 sequence number. The initial send sequence number (ISS) is chosen by 858 the data sending TCP, and the initial receive sequence number (IRS) 859 is learned during the connection establishing procedure. 861 For a connection to be established or initialized, the two TCPs must 862 synchronize on each other's initial sequence numbers. This is done 863 in an exchange of connection establishing segments carrying a control 864 bit called "SYN" (for synchronize) and the initial sequence numbers. 865 As a shorthand, segments carrying the SYN bit are also called "SYNs". 866 Hence, the solution requires a suitable mechanism for picking an 867 initial sequence number and a slightly involved handshake to exchange 868 the ISN's. 870 The synchronization requires each side to send it's own initial 871 sequence number and to receive a confirmation of it in acknowledgment 872 from the other side. Each side must also receive the other side's 873 initial sequence number and send a confirming acknowledgment. 875 1) A --> B SYN my sequence number is X 876 2) A <-- B ACK your sequence number is X 877 3) A <-- B SYN my sequence number is Y 878 4) A --> B ACK your sequence number is Y 880 Because steps 2 and 3 can be combined in a single message this is 881 called the three way (or three message) handshake. 883 A three way handshake is necessary because sequence numbers are not 884 tied to a global clock in the network, and TCPs may have different 885 mechanisms for picking the ISN's. The receiver of the first SYN has 886 no way of knowing whether the segment was an old delayed one or not, 887 unless it remembers the last sequence number used on the connection 888 (which is not always possible), and so it must ask the sender to 889 verify this SYN. The three way handshake and the advantages of a 890 clock-driven scheme are discussed in [3]. 892 Knowing When to Keep Quiet 894 To be sure that a TCP does not create a segment that carries a 895 sequence number which may be duplicated by an old segment remaining 896 in the network, the TCP must keep quiet for an MSL before assigning 897 any sequence numbers upon starting up or recovering from a crash in 898 which memory of sequence numbers in use was lost. For this 899 specification the MSL is taken to be 2 minutes. This is an 900 engineering choice, and may be changed if experience indicates it is 901 desirable to do so. Note that if a TCP is reinitialized in some 902 sense, yet retains its memory of sequence numbers in use, then it 903 need not wait at all; it must only be sure to use sequence numbers 904 larger than those recently used. 906 The TCP Quiet Time Concept 908 This specification provides that hosts which "crash" without 909 retaining any knowledge of the last sequence numbers transmitted on 910 each active (i.e., not closed) connection shall delay emitting any 911 TCP segments for at least the agreed MSL in the internet system of 912 which the host is a part. In the paragraphs below, an explanation 913 for this specification is given. TCP implementors may violate the 914 "quiet time" restriction, but only at the risk of causing some old 915 data to be accepted as new or new data rejected as old duplicated by 916 some receivers in the internet system. 918 TCPs consume sequence number space each time a segment is formed and 919 entered into the network output queue at a source host. The 920 duplicate detection and sequencing algorithm in the TCP protocol 921 relies on the unique binding of segment data to sequence space to the 922 extent that sequence numbers will not cycle through all 2**32 values 923 before the segment data bound to those sequence numbers has been 924 delivered and acknowledged by the receiver and all duplicate copies 925 of the segments have "drained" from the internet. Without such an 926 assumption, two distinct TCP segments could conceivably be assigned 927 the same or overlapping sequence numbers, causing confusion at the 928 receiver as to which data is new and which is old. Remember that 929 each segment is bound to as many consecutive sequence numbers as 930 there are octets of data and SYN or FIN flags in the segment. 932 Under normal conditions, TCPs keep track of the next sequence number 933 to emit and the oldest awaiting acknowledgment so as to avoid 934 mistakenly using a sequence number over before its first use has been 935 acknowledged. This alone does not guarantee that old duplicate data 936 is drained from the net, so the sequence space has been made very 937 large to reduce the probability that a wandering duplicate will cause 938 trouble upon arrival. At 2 megabits/sec. it takes 4.5 hours to use 939 up 2**32 octets of sequence space. Since the maximum segment 940 lifetime in the net is not likely to exceed a few tens of seconds, 941 this is deemed ample protection for foreseeable nets, even if data 942 rates escalate to l0's of megabits/sec. At 100 megabits/sec, the 943 cycle time is 5.4 minutes which may be a little short, but still 944 within reason. 946 The basic duplicate detection and sequencing algorithm in TCP can be 947 defeated, however, if a source TCP does not have any memory of the 948 sequence numbers it last used on a given connection. For example, if 949 the TCP were to start all connections with sequence number 0, then 950 upon crashing and restarting, a TCP might re-form an earlier 951 connection (possibly after half-open connection resolution) and emit 952 packets with sequence numbers identical to or overlapping with 953 packets still in the network which were emitted on an earlier 954 incarnation of the same connection. In the absence of knowledge 955 about the sequence numbers used on a particular connection, the TCP 956 specification recommends that the source delay for MSL seconds before 957 emitting segments on the connection, to allow time for segments from 958 the earlier connection incarnation to drain from the system. 960 Even hosts which can remember the time of day and used it to select 961 initial sequence number values are not immune from this problem 962 (i.e., even if time of day is used to select an initial sequence 963 number for each new connection incarnation). 965 Suppose, for example, that a connection is opened starting with 966 sequence number S. Suppose that this connection is not used much and 967 that eventually the initial sequence number function (ISN(t)) takes 968 on a value equal to the sequence number, say S1, of the last segment 969 sent by this TCP on a particular connection. Now suppose, at this 970 instant, the host crashes, recovers, and establishes a new 971 incarnation of the connection. The initial sequence number chosen is 972 S1 = ISN(t) -- last used sequence number on old incarnation of 973 connection! If the recovery occurs quickly enough, any old 974 duplicates in the net bearing sequence numbers in the neighborhood of 975 S1 may arrive and be treated as new packets by the receiver of the 976 new incarnation of the connection. 978 The problem is that the recovering host may not know for how long it 979 crashed nor does it know whether there are still old duplicates in 980 the system from earlier connection incarnations. 982 One way to deal with this problem is to deliberately delay emitting 983 segments for one MSL after recovery from a crash- this is the "quiet 984 time" specification. Hosts which prefer to avoid waiting are willing 985 to risk possible confusion of old and new packets at a given 986 destination may choose not to wait for the "quite time". 987 Implementors may provide TCP users with the ability to select on a 988 connection by connection basis whether to wait after a crash, or may 989 informally implement the "quite time" for all connections. 990 Obviously, even where a user selects to "wait," this is not necessary 991 after the host has been "up" for at least MSL seconds. 993 To summarize: every segment emitted occupies one or more sequence 994 numbers in the sequence space, the numbers occupied by a segment are 995 "busy" or "in use" until MSL seconds have passed, upon crashing a 996 block of space-time is occupied by the octets and SYN or FIN flags of 997 the last emitted segment, if a new connection is started too soon and 998 uses any of the sequence numbers in the space-time footprint of the 999 last segment of the previous connection incarnation, there is a 1000 potential sequence number overlap area which could cause confusion at 1001 the receiver. 1003 3.4. Establishing a connection 1005 The "three-way handshake" is the procedure used to establish a 1006 connection. This procedure normally is initiated by one TCP and 1007 responded to by another TCP. The procedure also works if two TCP 1008 simultaneously initiate the procedure. When simultaneous attempt 1009 occurs, each TCP receives a "SYN" segment which carries no 1010 acknowledgment after it has sent a "SYN". Of course, the arrival of 1011 an old duplicate "SYN" segment can potentially make it appear, to the 1012 recipient, that a simultaneous connection initiation is in progress. 1013 Proper use of "reset" segments can disambiguate these cases. 1015 Several examples of connection initiation follow. Although these 1016 examples do not show connection synchronization using data-carrying 1017 segments, this is perfectly legitimate, so long as the receiving TCP 1018 doesn't deliver the data to the user until it is clear the data is 1019 valid (i.e., the data must be buffered at the receiver until the 1020 connection reaches the ESTABLISHED state). The three-way handshake 1021 reduces the possibility of false connections. It is the 1022 implementation of a trade-off between memory and messages to provide 1023 information for this checking. 1025 The simplest three-way handshake is shown in Figure 5 below. The 1026 figures should be interpreted in the following way. Each line is 1027 numbered for reference purposes. Right arrows (-->) indicate 1028 departure of a TCP segment from TCP A to TCP B, or arrival of a 1029 segment at B from A. Left arrows (<--), indicate the reverse. 1030 Ellipsis (...) indicates a segment which is still in the network 1031 (delayed). An "XXX" indicates a segment which is lost or rejected. 1032 Comments appear in parentheses. TCP states represent the state AFTER 1033 the departure or arrival of the segment (whose contents are shown in 1034 the center of each line). Segment contents are shown in abbreviated 1035 form, with sequence number, control flags, and ACK field. Other 1036 fields such as window, addresses, lengths, and text have been left 1037 out in the interest of clarity. 1039 TCP A TCP B 1041 1. CLOSED LISTEN 1043 2. SYN-SENT --> --> SYN-RECEIVED 1045 3. ESTABLISHED <-- <-- SYN-RECEIVED 1047 4. ESTABLISHED --> --> ESTABLISHED 1049 5. ESTABLISHED --> --> ESTABLISHED 1051 Basic 3-Way Handshake for Connection Synchronization 1053 Figure 5 1055 In line 2 of Figure 5, TCP A begins by sending a SYN segment 1056 indicating that it will use sequence numbers starting with sequence 1057 number 100. In line 3, TCP B sends a SYN and acknowledges the SYN it 1058 received from TCP A. Note that the acknowledgment field indicates 1059 TCP B is now expecting to hear sequence 101, acknowledging the SYN 1060 which occupied sequence 100. 1062 At line 4, TCP A responds with an empty segment containing an ACK for 1063 TCP B's SYN; and in line 5, TCP A sends some data. Note that the 1064 sequence number of the segment in line 5 is the same as in line 4 1065 because the ACK does not occupy sequence number space (if it did, we 1066 would wind up ACKing ACK's!). 1068 Simultaneous initiation is only slightly more complex, as is shown in 1069 Figure 6. Each TCP cycles from CLOSED to SYN-SENT to SYN-RECEIVED to 1070 ESTABLISHED. 1072 TCP A TCP B 1074 1. CLOSED CLOSED 1076 2. SYN-SENT --> ... 1078 3. SYN-RECEIVED <-- <-- SYN-SENT 1080 4. ... --> SYN-RECEIVED 1082 5. SYN-RECEIVED --> ... 1084 6. ESTABLISHED <-- <-- SYN-RECEIVED 1086 7. ... --> ESTABLISHED 1088 Simultaneous Connection Synchronization 1090 Figure 6 1092 A TCP MUST support simultaneous open attempts. 1094 Note that a TCP implementation MUST keep track of whether a 1095 connection has reached SYN-RECEIVED state as the result of a passive 1096 OPEN or an active OPEN. 1098 The principle reason for the three-way handshake is to prevent old 1099 duplicate connection initiations from causing confusion. To deal 1100 with this, a special control message, reset, has been devised. If 1101 the receiving TCP is in a non-synchronized state (i.e., SYN-SENT, 1102 SYN-RECEIVED), it returns to LISTEN on receiving an acceptable reset. 1103 If the TCP is in one of the synchronized states (ESTABLISHED, FIN- 1104 WAIT-1, FIN-WAIT-2, CLOSE-WAIT, CLOSING, LAST-ACK, TIME-WAIT), it 1105 aborts the connection and informs its user. We discuss this latter 1106 case under "half-open" connections below. 1108 TCP A TCP B 1110 1. CLOSED LISTEN 1112 2. SYN-SENT --> ... 1114 3. (duplicate) ... --> SYN-RECEIVED 1116 4. SYN-SENT <-- <-- SYN-RECEIVED 1118 5. SYN-SENT --> --> LISTEN 1120 6. ... --> SYN-RECEIVED 1122 7. SYN-SENT <-- <-- SYN-RECEIVED 1124 8. ESTABLISHED --> --> ESTABLISHED 1126 Recovery from Old Duplicate SYN 1128 Figure 7 1130 As a simple example of recovery from old duplicates, consider 1131 Figure 7. At line 3, an old duplicate SYN arrives at TCP B. TCP B 1132 cannot tell that this is an old duplicate, so it responds normally 1133 (line 4). TCP A detects that the ACK field is incorrect and returns 1134 a RST (reset) with its SEQ field selected to make the segment 1135 believable. TCP B, on receiving the RST, returns to the LISTEN 1136 state. When the original SYN (pun intended) finally arrives at line 1137 6, the synchronization proceeds normally. If the SYN at line 6 had 1138 arrived before the RST, a more complex exchange might have occurred 1139 with RST's sent in both directions. 1141 Half-Open Connections and Other Anomalies 1143 An established connection is said to be "half-open" if one of the 1144 TCPs has closed or aborted the connection at its end without the 1145 knowledge of the other, or if the two ends of the connection have 1146 become desynchronized owing to a crash that resulted in loss of 1147 memory. Such connections will automatically become reset if an 1148 attempt is made to send data in either direction. However, half-open 1149 connections are expected to be unusual, and the recovery procedure is 1150 mildly involved. 1152 If at site A the connection no longer exists, then an attempt by the 1153 user at site B to send any data on it will result in the site B TCP 1154 receiving a reset control message. Such a message indicates to the 1155 site B TCP that something is wrong, and it is expected to abort the 1156 connection. 1158 Assume that two user processes A and B are communicating with one 1159 another when a crash occurs causing loss of memory to A's TCP. 1160 Depending on the operating system supporting A's TCP, it is likely 1161 that some error recovery mechanism exists. When the TCP is up again, 1162 A is likely to start again from the beginning or from a recovery 1163 point. As a result, A will probably try to OPEN the connection again 1164 or try to SEND on the connection it believes open. In the latter 1165 case, it receives the error message "connection not open" from the 1166 local (A's) TCP. In an attempt to establish the connection, A's TCP 1167 will send a segment containing SYN. This scenario leads to the 1168 example shown in Figure 8. After TCP A crashes, the user attempts to 1169 re-open the connection. TCP B, in the meantime, thinks the 1170 connection is open. 1172 TCP A TCP B 1174 1. (CRASH) (send 300,receive 100) 1176 2. CLOSED ESTABLISHED 1178 3. SYN-SENT --> --> (??) 1180 4. (!!) <-- <-- ESTABLISHED 1182 5. SYN-SENT --> --> (Abort!!) 1184 6. SYN-SENT CLOSED 1186 7. SYN-SENT --> --> 1188 Half-Open Connection Discovery 1190 Figure 8 1192 When the SYN arrives at line 3, TCP B, being in a synchronized state, 1193 and the incoming segment outside the window, responds with an 1194 acknowledgment indicating what sequence it next expects to hear (ACK 1195 100). TCP A sees that this segment does not acknowledge anything it 1196 sent and, being unsynchronized, sends a reset (RST) because it has 1197 detected a half-open connection. TCP B aborts at line 5. TCP A will 1198 continue to try to establish the connection; the problem is now 1199 reduced to the basic 3-way handshake of Figure 5. 1201 An interesting alternative case occurs when TCP A crashes and TCP B 1202 tries to send data on what it thinks is a synchronized connection. 1204 This is illustrated in Figure 9. In this case, the data arriving at 1205 TCP A from TCP B (line 2) is unacceptable because no such connection 1206 exists, so TCP A sends a RST. The RST is acceptable so TCP B 1207 processes it and aborts the connection. 1209 TCP A TCP B 1211 1. (CRASH) (send 300,receive 100) 1213 2. (??) <-- <-- ESTABLISHED 1215 3. --> --> (ABORT!!) 1217 Active Side Causes Half-Open Connection Discovery 1219 Figure 9 1221 In Figure 10, we find the two TCPs A and B with passive connections 1222 waiting for SYN. An old duplicate arriving at TCP B (line 2) stirs B 1223 into action. A SYN-ACK is returned (line 3) and causes TCP A to 1224 generate a RST (the ACK in line 3 is not acceptable). TCP B accepts 1225 the reset and returns to its passive LISTEN state. 1227 TCP A TCP B 1229 1. LISTEN LISTEN 1231 2. ... --> SYN-RECEIVED 1233 3. (??) <-- <-- SYN-RECEIVED 1235 4. --> --> (return to LISTEN!) 1237 5. LISTEN LISTEN 1239 Old Duplicate SYN Initiates a Reset on two Passive Sockets 1241 Figure 10 1243 A variety of other cases are possible, all of which are accounted for 1244 by the following rules for RST generation and processing. 1246 Reset Generation 1247 As a general rule, reset (RST) must be sent whenever a segment 1248 arrives which apparently is not intended for the current connection. 1249 A reset must not be sent if it is not clear that this is the case. 1251 There are three groups of states: 1253 1. If the connection does not exist (CLOSED) then a reset is sent 1254 in response to any incoming segment except another reset. In 1255 particular, SYNs addressed to a non-existent connection are 1256 rejected by this means. 1258 If the incoming segment has the ACK bit set, the reset takes its 1259 sequence number from the ACK field of the segment, otherwise the 1260 reset has sequence number zero and the ACK field is set to the sum 1261 of the sequence number and segment length of the incoming segment. 1262 The connection remains in the CLOSED state. 1264 2. If the connection is in any non-synchronized state (LISTEN, 1265 SYN-SENT, SYN-RECEIVED), and the incoming segment acknowledges 1266 something not yet sent (the segment carries an unacceptable ACK), 1267 or if an incoming segment has a security level or compartment 1268 which does not exactly match the level and compartment requested 1269 for the connection, a reset is sent. 1271 If the incoming segment has an ACK field, the reset takes its 1272 sequence number from the ACK field of the segment, otherwise the 1273 reset has sequence number zero and the ACK field is set to the sum 1274 of the sequence number and segment length of the incoming segment. 1275 The connection remains in the same state. 1277 3. If the connection is in a synchronized state (ESTABLISHED, 1278 FIN-WAIT-1, FIN-WAIT-2, CLOSE-WAIT, CLOSING, LAST-ACK, TIME-WAIT), 1279 any unacceptable segment (out of window sequence number or 1280 unacceptable acknowledgment number) must elicit only an empty 1281 acknowledgment segment containing the current send-sequence number 1282 and an acknowledgment indicating the next sequence number expected 1283 to be received, and the connection remains in the same state. 1285 If an incoming segment has a security level, or compartment which 1286 does not exactly match the level and compartment requested for the 1287 connection, a reset is sent and the connection goes to the CLOSED 1288 state. The reset takes its sequence number from the ACK field of 1289 the incoming segment. 1291 Reset Processing 1293 In all states except SYN-SENT, all reset (RST) segments are validated 1294 by checking their SEQ-fields. A reset is valid if its sequence 1295 number is in the window. In the SYN-SENT state (a RST received in 1296 response to an initial SYN), the RST is acceptable if the ACK field 1297 acknowledges the SYN. 1299 The receiver of a RST first validates it, then changes state. If the 1300 receiver was in the LISTEN state, it ignores it. If the receiver was 1301 in SYN-RECEIVED state and had previously been in the LISTEN state, 1302 then the receiver returns to the LISTEN state, otherwise the receiver 1303 aborts the connection and goes to the CLOSED state. If the receiver 1304 was in any other state, it aborts the connection and advises the user 1305 and goes to the CLOSED state. 1307 TCP SHOULD allow a received RST segment to include data. 1309 3.5. Closing a Connection 1311 CLOSE is an operation meaning "I have no more data to send." The 1312 notion of closing a full-duplex connection is subject to ambiguous 1313 interpretation, of course, since it may not be obvious how to treat 1314 the receiving side of the connection. We have chosen to treat CLOSE 1315 in a simplex fashion. The user who CLOSEs may continue to RECEIVE 1316 until he is told that the other side has CLOSED also. Thus, a 1317 program could initiate several SENDs followed by a CLOSE, and then 1318 continue to RECEIVE until signaled that a RECEIVE failed because the 1319 other side has CLOSED. We assume that the TCP will signal a user, 1320 even if no RECEIVEs are outstanding, that the other side has closed, 1321 so the user can terminate his side gracefully. A TCP will reliably 1322 deliver all buffers SENT before the connection was CLOSED so a user 1323 who expects no data in return need only wait to hear the connection 1324 was CLOSED successfully to know that all his data was received at the 1325 destination TCP. Users must keep reading connections they close for 1326 sending until the TCP says no more data. 1328 There are essentially three cases: 1330 1) The user initiates by telling the TCP to CLOSE the connection 1332 2) The remote TCP initiates by sending a FIN control signal 1334 3) Both users CLOSE simultaneously 1336 Case 1: Local user initiates the close 1338 In this case, a FIN segment can be constructed and placed on the 1339 outgoing segment queue. No further SENDs from the user will be 1340 accepted by the TCP, and it enters the FIN-WAIT-1 state. RECEIVEs 1341 are allowed in this state. All segments preceding and including 1342 FIN will be retransmitted until acknowledged. When the other TCP 1343 has both acknowledged the FIN and sent a FIN of its own, the first 1344 TCP can ACK this FIN. Note that a TCP receiving a FIN will ACK 1345 but not send its own FIN until its user has CLOSED the connection 1346 also. 1348 Case 2: TCP receives a FIN from the network 1350 If an unsolicited FIN arrives from the network, the receiving TCP 1351 can ACK it and tell the user that the connection is closing. The 1352 user will respond with a CLOSE, upon which the TCP can send a FIN 1353 to the other TCP after sending any remaining data. The TCP then 1354 waits until its own FIN is acknowledged whereupon it deletes the 1355 connection. If an ACK is not forthcoming, after the user timeout 1356 the connection is aborted and the user is told. 1358 Case 3: both users close simultaneously 1360 A simultaneous CLOSE by users at both ends of a connection causes 1361 FIN segments to be exchanged. When all segments preceding the 1362 FINs have been processed and acknowledged, each TCP can ACK the 1363 FIN it has received. Both will, upon receiving these ACKs, delete 1364 the connection. 1366 TCP A TCP B 1368 1. ESTABLISHED ESTABLISHED 1370 2. (Close) 1371 FIN-WAIT-1 --> --> CLOSE-WAIT 1373 3. FIN-WAIT-2 <-- <-- CLOSE-WAIT 1375 4. (Close) 1376 TIME-WAIT <-- <-- LAST-ACK 1378 5. TIME-WAIT --> --> CLOSED 1380 6. (2 MSL) 1381 CLOSED 1383 Normal Close Sequence 1385 Figure 11 1387 TCP A TCP B 1389 1. ESTABLISHED ESTABLISHED 1391 2. (Close) (Close) 1392 FIN-WAIT-1 --> ... FIN-WAIT-1 1393 <-- <-- 1394 ... --> 1396 3. CLOSING --> ... CLOSING 1397 <-- <-- 1398 ... --> 1400 4. TIME-WAIT TIME-WAIT 1401 (2 MSL) (2 MSL) 1402 CLOSED CLOSED 1404 Simultaneous Close Sequence 1406 Figure 12 1408 A TCP connection may terminate in two ways: (1) the normal TCP close 1409 sequence using a FIN handshake, and (2) an "abort" in which one or 1410 more RST segments are sent and the connection state is immediately 1411 discarded. If a TCP connection is closed by the remote site, the 1412 local application MUST be informed whether it closed normally or was 1413 aborted. 1415 3.5.1. Half-Closed Connections 1417 The normal TCP close sequence delivers buffered data reliably in both 1418 directions. Since the two directions of a TCP connection are closed 1419 independently, it is possible for a connection to be "half closed," 1420 i.e., closed in only one direction, and a host is permitted to 1421 continue sending data in the open direction on a half-closed 1422 connection. 1424 A host MAY implement a "half-duplex" TCP close sequence, so that an 1425 application that has called CLOSE cannot continue to read data from 1426 the connection. If such a host issues a CLOSE call while received 1427 data is still pending in TCP, or if new data is received after CLOSE 1428 is called, its TCP SHOULD send a RST to show that data was lost. 1430 When a connection is closed actively, it MUST linger in TIME-WAIT 1431 state for a time 2xMSL (Maximum Segment Lifetime). However, it MAY 1432 accept a new SYN from the remote TCP to reopen the connection 1433 directly from TIME-WAIT state, if it: 1435 (1) assigns its initial sequence number for the new connection to 1436 be larger than the largest sequence number it used on the previous 1437 connection incarnation, and 1439 (2) returns to TIME-WAIT state if the SYN turns out to be an old 1440 duplicate. 1442 When the TCP Timestamp options are available, an improved algorithm 1443 is described in [29] in order to support higher connection 1444 establishment rates. This algorithm for reducing TIME-WAIT is a Best 1445 Current Practice that SHOULD be implemented, since timestamp options 1446 are commonly used, and using them to reduce TIME-WAIT provides 1447 benefits for busy Internet servers. 1449 3.6. Precedence and Security 1451 The IPv4 specification [1] includes a precedence value in the Type of 1452 Service field (TOS), that was also modified in [15], and then 1453 obsoleted by the definition of Differentiated Services (DiffServ) 1454 [6]. In DiffServ the former precedence values are treated as Class 1455 Selector codepoints, and methods for compatible treatment are 1456 described in the DiffServ architecture. The RFC 793/1122 TCP 1457 specification includes logic intending to have connections use the 1458 highest precedence requested by either endpoint application, and to 1459 keep the precedence consistent throughout a connection. There is an 1460 assumption of bidirectional/symmetric precedence values, however, the 1461 DiffServ architecture is asymmetric. Problems were described in [17] 1462 and the solution described is to ignore IP precedence in TCP. Since 1463 RFC 2873 is a Standards Track document (although not marked as 1464 updating RFC 793), these checks are no longer a part of the TCP 1465 standard defined in this document, though the DiffServ field value is 1466 still is a part of the interface between TCP and the network layer, 1467 and values can be indicated both ways between TCP and the 1468 application. 1470 The IP security option (IPSO) and compartment defined in [1] was 1471 refined in RFC 1038 that was later obsoleted by RFC 1108. The 1472 Commercial IP Security Option (CIPSO) is defined in FIPS-188, and is 1473 supported by some vendors and operating systems. RFC 1108 is now 1474 Historic, though RFC 791 itself has not been updated to remove the IP 1475 security option. For IPv6, a similar option (CALIPSO) has been 1476 defined [23]. RFC 793 includes logic that includes the IP security/ 1477 compartment information in treatment of TCP segments. References to 1478 the IP "security/compartment" in this document may be relevant for 1479 Multi-Level Secure (MLS) system implementers, but can be ignored for 1480 non-MLS implementations, consistent with running code on the 1481 Internet. See Appendix A.1 for further discussion. Note that RFC 1482 5570 describes some MLS networking scenarios where IPSO, CIPSO, or 1483 CALIPSO may be used. In these special cases, TCP implementers should 1484 see section 7.3.1 of RFC 5570, and follow the guidance in that 1485 document on the relation between IP security. 1487 3.7. Segmentation 1489 The term "segmentation" refers to the activity TCP performs when 1490 ingesting a stream of bytes from a sending application and 1491 packetizing that stream of bytes into TCP segments. Individual TCP 1492 segments often do not correspond one-for-one to individual send (or 1493 socket write) calls from the application. Applications may perform 1494 writes at the granularity of messages in the upper layer protocol, 1495 but TCP guarantees no boundary coherence between the TCP segments 1496 sent and received versus user application data read or write buffer 1497 boundaries. In some specific protocols, such as RDMA using DDP and 1498 MPA [21], there are performance optimizations possible when the 1499 relation between TCP segments and application data units can be 1500 controlled, and MPA includes a specific mechanism for detecting and 1501 verifying this relationship between TCP segments and application 1502 message data strcutures, but this is specific to applications like 1503 RDMA. In general, multiple goals influence the sizing of TCP 1504 segments created by a TCP implementation. 1506 Goals driving the sending of larger segments include: 1508 o Reducing the number of packets in flight within the network. 1510 o Increasing processing efficiency and potential performance by 1511 enabling a smaller number of interrupts and inter-layer 1512 interactions. 1514 o Limiting the overhead of TCP headers. 1516 Note that the performance benefits of sending larger segments may 1517 decrease as the size increases, and there may be boundaries where 1518 advantages are reversed. For instance, on some machines 1025 bytes 1519 within a segment could lead to worse performance than 1024 bytes, due 1520 purely to data alignment on copy operations. 1522 Goals driving the sending of smaller segments include: 1524 o Avoiding sending segments larger than the smallest MTU within an 1525 IP network path, because this results in either packet loss or 1526 fragmentation. Making matters worse, some firewalls or 1527 middleboxes may drop fragmented packets or ICMP messages related 1528 related to fragmentation. 1530 o Preventing delays to the application data stream, especially when 1531 TCP is waiting on the application to generate more data, or when 1532 the application is waiting on an event or input from its peer in 1533 order to generate more data. 1535 o Enabling "fate sharing" between TCP segments and lower-layer data 1536 units (e.g. below IP, for links with cell or frame sizes smaller 1537 than the IP MTU). 1539 Towards meeting these competing sets of goals, TCP includes several 1540 mechanisms, including the Maximum Segment Size option, Path MTU 1541 Discovery, the Nagle algorithm, and support for IPv6 Jumbograms, as 1542 discussed in the following subsections. 1544 3.7.1. Maximum Segment Size Option 1546 TCP MUST implement both sending and receiving the MSS option. 1548 TCP SHOULD send an MSS option in every SYN segment when its receive 1549 MSS differs from the default 536 for IPv4 or 1220 for IPv6, and MAY 1550 send it always. 1552 If an MSS option is not received at connection setup, TCP MUST assume 1553 a default send MSS of 536 (576-40) for IPv4 or 1220 (1280 - 60) for 1554 IPv6. 1556 The maximum size of a segment that TCP really sends, the "effective 1557 send MSS," MUST be the smaller of the send MSS (which reflects the 1558 available reassembly buffer size at the remote host, the EMTU_R [14]) 1559 and the largest transmission size permitted by the IP layer (EMTU_S 1560 [14]): 1562 Eff.snd.MSS = 1564 min(SendMSS+20, MMS_S) - TCPhdrsize - IPoptionsize 1566 where: 1568 o SendMSS is the MSS value received from the remote host, or the 1569 default 536 for IPv4 or 1220 for IPv6, if no MSS option is 1570 received. 1572 o MMS_S is the maximum size for a transport-layer message that TCP 1573 may send. 1575 o TCPhdrsize is the size of the fixed TCP header and any options. 1576 This is 20 in the (rare) case that no options are present, but may 1577 be larger if TCP options are to be sent. Note that some options 1578 may not be included on all segments, but that for each segment 1579 sent, the sender should adjust the data length accordingly, within 1580 the Eff.snd.MSS. 1582 o IPoptionsize is the size of any IP options associated with a TCP 1583 connection. Note that some options may not be included on all 1584 packets, but that for each segment sent, the sender should adjust 1585 the data length accordingly, within the Eff.snd.MSS. 1587 The MSS value to be sent in an MSS option should be equal to the 1588 effective MTU minus the fixed IP and TCP headers. By ignoring both 1589 IP and TCP options when calculating the value for the MSS option, if 1590 there are any IP or TCP options to be sent in a packet, then the 1591 sender must decrease the size of the TCP data accordingly. RFC 6691 1592 [32] discusses this in greater detail. 1594 The MSS value to be sent in an MSS option must be less than or equal 1595 to: 1597 MMS_R - 20 1599 where MMS_R is the maximum size for a transport-layer message that 1600 can be received (and reassembled at the IP layer). TCP obtains MMS_R 1601 and MMS_S from the IP layer; see the generic call GET_MAXSIZES in 1602 Section 3.4 of RFC 1122. These are defined in terms of their IP MTU 1603 equivalents, EMTU_R and EMTU_S [14]. 1605 When TCP is used in a situation where either the IP or TCP headers 1606 are not fixed, the sender must reduce the amount of TCP data in any 1607 given packet by the number of octets used by the IP and TCP options. 1608 This has been a point of confusion historically, as explained in RFC 1609 6691, Section 3.1. 1611 3.7.2. Path MTU Discovery 1613 A TCP implementation may be aware of the MTU on directly connected 1614 links, but will rarely have insight about MTUs across an entire 1615 network path. For IPv4, RFC 1122 provides an IP-layer recommendation 1616 on the default effective MTU for sending to be less than or equal to 1617 576 for destinations not directly connected. For IPv6, this would be 1618 1280. In all cases, however, implementation of Path MTU Discovery 1619 (PMTUD) and Packetization Layer Path MTU Discovery (PLPMTUD) is 1620 strongly recommended in order for TCP to improve segmentation 1621 decisions. Both PMTUD and PLPMTUD help TCP choose segment sizes that 1622 avoid both on-path (for IPv4) and source fragmentation (IPv4 and 1623 IPv6). 1625 PMTUD for IPv4 [2] or IPv6 [3] is implemented in conjunction between 1626 TCP, IP, and ICMP protocols. It relies both on avoiding source 1627 fragmentation and setting the IPv4 DF (don't fragment) flag, the 1628 latter to inhibit on-path fragmentation. It relies on ICMP errors 1629 from routers along the path, whenever a segment is too large to 1630 traverse a link. Several adjustments to a TCP implementation with 1631 PMTUD are described in RFC 2923 in order to deal with problems 1632 experienced in practice [8]. PLPMTUD [18] is a Standards Track 1633 improvement to PMTUD that relaxes the requirement for ICMP support 1634 across a path, and improves performance in cases where ICMP is not 1635 consistently conveyed, but still tries to avoid source fragmentation. 1636 The mechanisms in all four of these RFCs are recommended to be 1637 included in TCP implementations. 1639 The TCP MSS option specifies an upper bound for the size of packets 1640 that can be received. Hence, setting the value in the MSS option too 1641 small can impact the ability for PMTUD or PLPMTUD to find a larger 1642 path MTU. RFC 1191 discusses this implication of many older TCP 1643 implementations setting MSS to 536 for non-local destinations, rather 1644 than deriving it from the MTUs of connected interfaces as 1645 recommended. 1647 3.7.3. Interfaces with Variable MTU Values 1649 The effective MTU can sometimes vary, as when used with variable 1650 compression, e.g., RObust Header Compression (ROHC) [25]. It is 1651 tempting for TCP to want to advertise the largest possible MSS, to 1652 support the most efficient use of compressed payloads. 1653 Unfortunately, some compression schemes occasionally need to transmit 1654 full headers (and thus smaller payloads) to resynchronize state at 1655 their endpoint compressors/decompressors. If the largest MTU is used 1656 to calculate the value to advertise in the MSS option, TCP 1657 retransmission may interfere with compressor resynchronization. 1659 As a result, when the effective MTU of an interface varies, TCP 1660 SHOULD use the smallest effective MTU of the interface to calculate 1661 the value to advertise in the MSS option. 1663 3.7.4. Nagle Algorithm 1665 The "Nagle algorithm" was described in RFC 896 [13] and was 1666 recommended in RFC 1122 [14] for mitigation of an early problem of 1667 too many small packets being generated. It has been implemented in 1668 most current TCP code bases, sometimes with minor variations (see 1669 Appendix A.3). 1671 If there is unacknowledged data (i.e., SND.NXT > SND.UNA), then the 1672 sending TCP buffers all user data (regardless of the PSH bit), until 1673 the outstanding data has been acknowledged or until the TCP can send 1674 a full-sized segment (Eff.snd.MSS bytes). 1676 A TCP SHOULD implement the Nagle Algorithm to coalesce short 1677 segments. However, there MUST be a way for an application to disable 1678 the Nagle algorithm on an individual connection. In all cases, 1679 sending data is also subject to the limitation imposed by the Slow 1680 Start algorithm [24]. 1682 3.7.5. IPv6 Jumbograms 1684 In order to support TCP over IPv6 jumbograms, implementations need to 1685 be able to send TCP segments larger than the 64KB limit that the MSS 1686 option can convey. RFC 2675 [7] defines that an MSS value of 65,535 1687 bytes is to be treated as infinity, and Path MTU Discovery [3] is 1688 used to determine the actual MSS. 1690 3.8. Data Communication 1692 Once the connection is established data is communicated by the 1693 exchange of segments. Because segments may be lost due to errors 1694 (checksum test failure), or network congestion, TCP uses 1695 retransmission (after a timeout) to ensure delivery of every segment. 1696 Duplicate segments may arrive due to network or TCP retransmission. 1697 As discussed in the section on sequence numbers the TCP performs 1698 certain tests on the sequence and acknowledgment numbers in the 1699 segments to verify their acceptability. 1701 The sender of data keeps track of the next sequence number to use in 1702 the variable SND.NXT. The receiver of data keeps track of the next 1703 sequence number to expect in the variable RCV.NXT. The sender of 1704 data keeps track of the oldest unacknowledged sequence number in the 1705 variable SND.UNA. If the data flow is momentarily idle and all data 1706 sent has been acknowledged then the three variables will be equal. 1708 When the sender creates a segment and transmits it the sender 1709 advances SND.NXT. When the receiver accepts a segment it advances 1710 RCV.NXT and sends an acknowledgment. When the data sender receives 1711 an acknowledgment it advances SND.UNA. The extent to which the 1712 values of these variables differ is a measure of the delay in the 1713 communication. The amount by which the variables are advanced is the 1714 length of the data and SYN or FIN flags in the segment. Note that 1715 once in the ESTABLISHED state all segments must carry current 1716 acknowledgment information. 1718 The CLOSE user call implies a push function, as does the FIN control 1719 flag in an incoming segment. 1721 3.8.1. Retransmission Timeout 1723 Because of the variability of the networks that compose an 1724 internetwork system and the wide range of uses of TCP connections the 1725 retransmission timeout (RTO) must be dynamically determined. 1727 The RTO MUST be computed according to the algorithm in [10], 1728 including Karn's algorithm for taking RTT samples. 1730 RFC 793 contains an early example procedure for computing the RTO. 1731 This was then replaced by the algorithm described in RFC 1122, and 1732 subsequently updated in RFC 2988, and then again in RFC 6298. 1734 If a retransmitted packet is identical to the original packet (which 1735 implies not only that the data boundaries have not changed, but also 1736 that the window and acknowledgment fields of the header have not 1737 changed), then the same IP Identification field MAY be used (see 1738 Section 3.2.1.5 of RFC 1122). 1740 3.8.2. TCP Congestion Control 1742 RFC 1122 required implementation of Van Jacobson's congestion control 1743 algorithm combining slow start with congestion avoidance. RFC 2581 1744 provided IETF Standards Track description of this, along with fast 1745 retransmit and fast recovery. RFC 5681 is the current description of 1746 these algorithms and is the current standard for TCP congestion 1747 control. 1749 A TCP MUST implement RFC 5681. 1751 Explicit Congestion Notification (ECN) was defined in RFC 3168 and is 1752 an IETF Standards Track enhancement that has many benefits [38]. 1754 A TCP SHOULD implement ECN as described in RFC 3168. 1756 3.8.3. TCP Connection Failures 1758 Excessive retransmission of the same segment by TCP indicates some 1759 failure of the remote host or the Internet path. This failure may be 1760 of short or long duration. The following procedure MUST be used to 1761 handle excessive retransmissions of data segments: 1763 (a) There are two thresholds R1 and R2 measuring the amount of 1764 retransmission that has occurred for the same segment. R1 and R2 1765 might be measured in time units or as a count of retransmissions. 1767 (b) When the number of transmissions of the same segment reaches 1768 or exceeds threshold R1, pass negative advice (see [14] 1769 Section 3.3.1.4) to the IP layer, to trigger dead-gateway 1770 diagnosis. 1772 (c) When the number of transmissions of the same segment reaches a 1773 threshold R2 greater than R1, close the connection. 1775 (d) An application MUST be able to set the value for R2 for a 1776 particular connection. For example, an interactive application 1777 might set R2 to "infinity," giving the user control over when to 1778 disconnect. 1780 (d) TCP SHOULD inform the application of the delivery problem 1781 (unless such information has been disabled by the application; see 1782 Asynchronous Reports section), when R1 is reached and before R2. 1783 This will allow a remote login (User Telnet) application program 1784 to inform the user, for example. 1786 The value of R1 SHOULD correspond to at least 3 retransmissions, at 1787 the current RTO. The value of R2 SHOULD correspond to at least 100 1788 seconds. 1790 An attempt to open a TCP connection could fail with excessive 1791 retransmissions of the SYN segment or by receipt of a RST segment or 1792 an ICMP Port Unreachable. SYN retransmissions MUST be handled in the 1793 general way just described for data retransmissions, including 1794 notification of the application layer. 1796 However, the values of R1 and R2 may be different for SYN and data 1797 segments. In particular, R2 for a SYN segment MUST be set large 1798 enough to provide retransmission of the segment for at least 3 1799 minutes. The application can close the connection (i.e., give up on 1800 the open attempt) sooner, of course. 1802 3.8.4. TCP Keep-Alives 1804 Implementors MAY include "keep-alives" in their TCP implementations, 1805 although this practice is not universally accepted. If keep-alives 1806 are included, the application MUST be able to turn them on or off for 1807 each TCP connection, and they MUST default to off. 1809 Keep-alive packets MUST only be sent when no data or acknowledgement 1810 packets have been received for the connection within an interval. 1811 This interval MUST be configurable and MUST default to no less than 1812 two hours. 1814 It is extremely important to remember that ACK segments that contain 1815 no data are not reliably transmitted by TCP. Consequently, if a 1816 keep-alive mechanism is implemented it MUST NOT interpret failure to 1817 respond to any specific probe as a dead connection. 1819 An implementation SHOULD send a keep-alive segment with no data; 1820 however, it MAY be configurable to send a keep-alive segment 1821 containing one garbage octet, for compatibility with erroneous TCP 1822 implementations. 1824 3.8.5. The Communication of Urgent Information 1826 As a result of implementation differences and middlebox interactions, 1827 new applications SHOULD NOT employ the TCP urgent mechanism. 1828 However, TCP implementations MUST still include support for the 1829 urgent mechanism. Details can be found in RFC 6093 [28]. 1831 The objective of the TCP urgent mechanism is to allow the sending 1832 user to stimulate the receiving user to accept some urgent data and 1833 to permit the receiving TCP to indicate to the receiving user when 1834 all the currently known urgent data has been received by the user. 1836 This mechanism permits a point in the data stream to be designated as 1837 the end of urgent information. Whenever this point is in advance of 1838 the receive sequence number (RCV.NXT) at the receiving TCP, that TCP 1839 must tell the user to go into "urgent mode"; when the receive 1840 sequence number catches up to the urgent pointer, the TCP must tell 1841 user to go into "normal mode". If the urgent pointer is updated 1842 while the user is in "urgent mode", the update will be invisible to 1843 the user. 1845 The method employs a urgent field which is carried in all segments 1846 transmitted. The URG control flag indicates that the urgent field is 1847 meaningful and must be added to the segment sequence number to yield 1848 the urgent pointer. The absence of this flag indicates that there is 1849 no urgent data outstanding. 1851 To send an urgent indication the user must also send at least one 1852 data octet. If the sending user also indicates a push, timely 1853 delivery of the urgent information to the destination process is 1854 enhanced. 1856 A TCP MUST support a sequence of urgent data of any length. [14] 1858 A TCP MUST inform the application layer asynchronously whenever it 1859 receives an Urgent pointer and there was previously no pending urgent 1860 data, or whenvever the Urgent pointer advances in the data stream. 1861 There MUST be a way for the application to learn how much urgent data 1862 remains to be read from the connection, or at least to determine 1863 whether or not more urgent data remains to be read. [14] 1865 3.8.6. Managing the Window 1867 The window sent in each segment indicates the range of sequence 1868 numbers the sender of the window (the data receiver) is currently 1869 prepared to accept. There is an assumption that this is related to 1870 the currently available data buffer space available for this 1871 connection. 1873 The sending TCP packages the data to be transmitted into segments 1874 which fit the current window, and may repackage segments on the 1875 retransmission queue. Such repackaging is not required, but may be 1876 helpful. 1878 In a connection with a one-way data flow, the window information will 1879 be carried in acknowledgment segments that all have the same sequence 1880 number so there will be no way to reorder them if they arrive out of 1881 order. This is not a serious problem, but it will allow the window 1882 information to be on occasion temporarily based on old reports from 1883 the data receiver. A refinement to avoid this problem is to act on 1884 the window information from segments that carry the highest 1885 acknowledgment number (that is segments with acknowledgment number 1886 equal or greater than the highest previously received). 1888 Indicating a large window encourages transmissions. If more data 1889 arrives than can be accepted, it will be discarded. This will result 1890 in excessive retransmissions, adding unnecessarily to the load on the 1891 network and the TCPs. Indicating a small window may restrict the 1892 transmission of data to the point of introducing a round trip delay 1893 between each new segment transmitted. 1895 The mechanisms provided allow a TCP to advertise a large window and 1896 to subsequently advertise a much smaller window without having 1897 accepted that much data. This, so called "shrinking the window," is 1898 strongly discouraged. The robustness principle dictates that TCPs 1899 will not shrink the window themselves, but will be prepared for such 1900 behavior on the part of other TCPs. 1902 A TCP receiver SHOULD NOT shrink the window, i.e., move the right 1903 window edge to the left. However, a sending TCP MUST be robust 1904 against window shrinking, which may cause the "useable window" (see 1905 Section 3.8.6.2.1) to become negative. 1907 If this happens, the sender SHOULD NOT send new data, but SHOULD 1908 retransmit normally the old unacknowledged data between SND.UNA and 1909 SND.UNA+SND.WND. The sender MAY also retransmit old data beyond 1910 SND.UNA+SND.WND, but SHOULD NOT time out the connection if data 1911 beyond the right window edge is not acknowledged. If the window 1912 shrinks to zero, the TCP MUST probe it in the standard way (described 1913 below). 1915 3.8.6.1. Zero Window Probing 1917 The sending TCP must be prepared to accept from the user and send at 1918 least one octet of new data even if the send window is zero. The 1919 sending TCP must regularly retransmit to the receiving TCP even when 1920 the window is zero, in order to "probe" the window. Two minutes is 1921 recommended for the retransmission interval when the window is zero. 1922 This retransmission is essential to guarantee that when either TCP 1923 has a zero window the re-opening of the window will be reliably 1924 reported to the other. This is referred to as Zero-Window Probing 1925 (ZWP) in other documents. 1927 Probing of zero (offered) windows MUST be supported. 1929 A TCP MAY keep its offered receive window closed indefinitely. As 1930 long as the receiving TCP continues to send acknowledgments in 1931 response to the probe segments, the sending TCP MUST allow the 1932 connection to stay open. This enables TCP to function in scenarios 1933 such as the "printer ran out of paper" situation described in 1934 Section 4.2.2.17 of RFC1122. The behavior is subject to the 1935 implementation's resource management concerns, as noted in [30]. 1937 When the receiving TCP has a zero window and a segment arrives it 1938 must still send an acknowledgment showing its next expected sequence 1939 number and current window (zero). 1941 3.8.6.2. Silly Window Syndrome Avoidance 1943 The "Silly Window Syndrome" (SWS) is a stable pattern of small 1944 incremental window movements resulting in extremely poor TCP 1945 performance. Algorithms to avoid SWS are described below for both 1946 the sending side and the receiving side. RFC 1122 contains more 1947 detailed discussion of the SWS problem. Note that the Nagle 1948 algorithm and the sender SWS avoidance algorithm play complementary 1949 roles in improving performance. The Nagle algorithm discourages 1950 sending tiny segments when the data to be sent increases in small 1951 increments, while the SWS avoidance algorithm discourages small 1952 segments resulting from the right window edge advancing in small 1953 increments. 1955 3.8.6.2.1. Sender's Algorithm - When to Send Data 1957 A TCP MUST include a SWS avoidance algorithm in the sender. 1959 A TCP SHOULD implement the Nagle Algorithm to coalesce short 1960 segments. However, there MUST be a way for an application to disable 1961 the Nagle algorithm on an individual connection. In all cases, 1962 sending data is also subject to the limitation imposed by the Slow 1963 Start algorithm. 1965 The sender's SWS avoidance algorithm is more difficult than the 1966 receivers's, because the sender does not know (directly) the 1967 receiver's total buffer space RCV.BUFF. An approach which has been 1968 found to work well is for the sender to calculate Max(SND.WND), the 1969 maximum send window it has seen so far on the connection, and to use 1970 this value as an estimate of RCV.BUFF. Unfortunately, this can only 1971 be an estimate; the receiver may at any time reduce the size of 1972 RCV.BUFF. To avoid a resulting deadlock, it is necessary to have a 1973 timeout to force transmission of data, overriding the SWS avoidance 1974 algorithm. In practice, this timeout should seldom occur. 1976 The "useable window" is: 1978 U = SND.UNA + SND.WND - SND.NXT 1980 i.e., the offered window less the amount of data sent but not 1981 acknowledged. If D is the amount of data queued in the sending TCP 1982 but not yet sent, then the following set of rules is recommended. 1984 Send data: 1986 (1) if a maximum-sized segment can be sent, i.e, if: 1988 min(D,U) >= Eff.snd.MSS; 1990 (2) or if the data is pushed and all queued data can be sent now, 1991 i.e., if: 1993 [SND.NXT = SND.UNA and] PUSHED and D <= U 1995 (the bracketed condition is imposed by the Nagle algorithm); 1997 (3) or if at least a fraction Fs of the maximum window can be sent, 1998 i.e., if: 2000 [SND.NXT = SND.UNA and] 2002 min(D.U) >= Fs * Max(SND.WND); 2004 (4) or if data is PUSHed and the override timeout occurs. 2006 Here Fs is a fraction whose recommended value is 1/2. The override 2007 timeout should be in the range 0.1 - 1.0 seconds. It may be 2008 convenient to combine this timer with the timer used to probe zero 2009 windows (Section Section 3.8.6.1). 2011 3.8.6.2.2. Receiver's Algorithm - When to Send a Window Update 2013 A TCP MUST include a SWS avoidance algorithm in the receiver. 2015 The receiver's SWS avoidance algorithm determines when the right 2016 window edge may be advanced; this is customarily known as "updating 2017 the window". This algorithm combines with the delayed ACK algorithm 2018 (see Section 3.8.6.3) to determine when an ACK segment containing the 2019 current window will really be sent to the receiver. 2021 The solution to receiver SWS is to avoid advancing the right window 2022 edge RCV.NXT+RCV.WND in small increments, even if data is received 2023 from the network in small segments. 2025 Suppose the total receive buffer space is RCV.BUFF. At any given 2026 moment, RCV.USER octets of this total may be tied up with data that 2027 has been received and acknowledged but which the user process has not 2028 yet consumed. When the connection is quiescent, RCV.WND = RCV.BUFF 2029 and RCV.USER = 0. 2031 Keeping the right window edge fixed as data arrives and is 2032 acknowledged requires that the receiver offer less than its full 2033 buffer space, i.e., the receiver must specify a RCV.WND that keeps 2034 RCV.NXT+RCV.WND constant as RCV.NXT increases. Thus, the total 2035 buffer space RCV.BUFF is generally divided into three parts: 2037 |<------- RCV.BUFF ---------------->| 2038 1 2 3 2039 ----|---------|------------------|------|---- 2040 RCV.NXT ^ 2041 (Fixed) 2043 1 - RCV.USER = data received but not yet consumed; 2044 2 - RCV.WND = space advertised to sender; 2045 3 - Reduction = space available but not yet 2046 advertised. 2048 The suggested SWS avoidance algorithm for the receiver is to keep 2049 RCV.NXT+RCV.WND fixed until the reduction satisfies: 2051 RCV.BUFF - RCV.USER - RCV.WND >= 2053 min( Fr * RCV.BUFF, Eff.snd.MSS ) 2055 where Fr is a fraction whose recommended value is 1/2, and 2056 Eff.snd.MSS is the effective send MSS for the connection (see 2057 Section 3.7.1). When the inequality is satisfied, RCV.WND is set to 2058 RCV.BUFF-RCV.USER. 2060 Note that the general effect of this algorithm is to advance RCV.WND 2061 in increments of Eff.snd.MSS (for realistic receive buffers: 2062 Eff.snd.MSS < RCV.BUFF/2). Note also that the receiver must use its 2063 own Eff.snd.MSS, assuming it is the same as the sender's. 2065 3.8.6.3. Delayed Acknowledgements - When to Send an ACK Segment 2067 A host that is receiving a stream of TCP data segments can increase 2068 efficiency in both the Internet and the hosts by sending fewer than 2069 one ACK (acknowledgment) segment per data segment received; this is 2070 known as a "delayed ACK". 2072 A TCP SHOULD implement a delayed ACK, but an ACK should not be 2073 excessively delayed; in particular, the delay MUST be less than 0.5 2074 seconds, and in a stream of full-sized segments there SHOULD be an 2075 ACK for at least every second segment. Excessive delays on ACK's can 2076 disturb the round-trip timing and packet "clocking" algorithms. 2078 3.9. Interfaces 2080 There are of course two interfaces of concern: the user/TCP interface 2081 and the TCP/lower-level interface. We have a fairly elaborate model 2082 of the user/TCP interface, but the interface to the lower level 2083 protocol module is left unspecified here, since it will be specified 2084 in detail by the specification of the lower level protocol. For the 2085 case that the lower level is IP we note some of the parameter values 2086 that TCPs might use. 2088 3.9.1. User/TCP Interface 2090 The following functional description of user commands to the TCP is, 2091 at best, fictional, since every operating system will have different 2092 facilities. Consequently, we must warn readers that different TCP 2093 implementations may have different user interfaces. However, all 2094 TCPs must provide a certain minimum set of services to guarantee that 2095 all TCP implementations can support the same protocol hierarchy. 2096 This section specifies the functional interfaces required of all TCP 2097 implementations. 2099 TCP User Commands 2101 The following sections functionally characterize a USER/TCP 2102 interface. The notation used is similar to most procedure or 2103 function calls in high level languages, but this usage is not 2104 meant to rule out trap type service calls (e.g., SVCs, UUOs, 2105 EMTs). 2107 The user commands described below specify the basic functions the 2108 TCP must perform to support interprocess communication. 2109 Individual implementations must define their own exact format, and 2110 may provide combinations or subsets of the basic functions in 2111 single calls. In particular, some implementations may wish to 2112 automatically OPEN a connection on the first SEND or RECEIVE 2113 issued by the user for a given connection. 2115 In providing interprocess communication facilities, the TCP must 2116 not only accept commands, but must also return information to the 2117 processes it serves. The latter consists of: 2119 (a) general information about a connection (e.g., interrupts, 2120 remote close, binding of unspecified foreign socket). 2122 (b) replies to specific user commands indicating success or 2123 various types of failure. 2125 Open 2127 Format: OPEN (local port, foreign socket, active/passive [, 2128 timeout] [, DiffServ field] [, security/compartment] [local IP 2129 address,] [, options]) -> local connection name 2131 We assume that the local TCP is aware of the identity of the 2132 processes it serves and will check the authority of the process 2133 to use the connection specified. Depending upon the 2134 implementation of the TCP, the local network and TCP 2135 identifiers for the source address will either be supplied by 2136 the TCP or the lower level protocol (e.g., IP). These 2137 considerations are the result of concern about security, to the 2138 extent that no TCP be able to masquerade as another one, and so 2139 on. Similarly, no process can masquerade as another without 2140 the collusion of the TCP. 2142 If the active/passive flag is set to passive, then this is a 2143 call to LISTEN for an incoming connection. A passive open may 2144 have either a fully specified foreign socket to wait for a 2145 particular connection or an unspecified foreign socket to wait 2146 for any call. A fully specified passive call can be made 2147 active by the subsequent execution of a SEND. 2149 A transmission control block (TCB) is created and partially 2150 filled in with data from the OPEN command parameters. 2152 Every passive OPEN call either creates a new connection record 2153 in LISTEN state, or it returns an error; it MUST NOT affect any 2154 previously created connection record. 2156 A TCP that supports multiple concurrent users MUST provide an 2157 OPEN call that will functionally allow an application to LISTEN 2158 on a port while a connection block with the same local port is 2159 in SYN-SENT or SYN-RECEIVED state. 2161 On an active OPEN command, the TCP will begin the procedure to 2162 synchronize (i.e., establish) the connection at once. 2164 The timeout, if present, permits the caller to set up a timeout 2165 for all data submitted to TCP. If data is not successfully 2166 delivered to the destination within the timeout period, the TCP 2167 will abort the connection. The present global default is five 2168 minutes. 2170 The TCP or some component of the operating system will verify 2171 the users authority to open a connection with the specified 2172 DiffServ field value or security/compartment. The absence of a 2173 DiffServ field value or security/compartment specification in 2174 the OPEN call indicates the default values must be used. 2176 TCP will accept incoming requests as matching only if the 2177 security/compartment information is exactly the same as that 2178 requested in the OPEN call. 2180 The DiffServ field value indicated by the user only impacts 2181 outgoing packets, may be altered en route through the network, 2182 and has no direct bearing or relation to received packets. 2184 A local connection name will be returned to the user by the 2185 TCP. The local connection name can then be used as a short 2186 hand term for the connection defined by the pair. 2189 The optional "local IP address" parameter MUST be supported to 2190 allow the specification of the local IP address. This enables 2191 applications that need to select the local IP address used when 2192 multihoming is present. 2194 A passive OPEN call with a specified "local IP address" 2195 parameter will await an incoming connection request to that 2196 address. If the parameter is unspecified, a passive OPEN will 2197 await an incoming connection request to any local IP address, 2198 and then bind the local IP address of the connection to the 2199 particular address that is used. 2201 For an active OPEN call, a specified "local IP address" 2202 parameter MUST be used for opening the connection. If the 2203 parameter is unspecified, the host will choose an appropriate 2204 local IP address (see RFC 1122 section 3.3.4.2). 2206 If an application on a multihomed host does not specify the 2207 local IP address when actively opening a TCP connection, then 2208 the TCP MUST ask the IP layer to select a local IP address 2209 before sending the (first) SYN. See the function GET_SRCADDR() 2210 in Section 3.4 of RFC 1122. 2212 At all other times, a previous segment has either been sent or 2213 received on this connection, and TCP MUST use the same local 2214 address is used that was used in those previous segments. 2216 A TCP implementation MUST reject as an error a local OPEN call 2217 for an invalid remote IP address (e.g., a broadcast or 2218 multicast address). 2220 Send 2222 Format: SEND (local connection name, buffer address, byte 2223 count, PUSH flag, URGENT flag [,timeout]) 2225 This call causes the data contained in the indicated user 2226 buffer to be sent on the indicated connection. If the 2227 connection has not been opened, the SEND is considered an 2228 error. Some implementations may allow users to SEND first; in 2229 which case, an automatic OPEN would be done. For example, this 2230 might be one way for application data to be included in SYN 2231 segments. If the calling process is not authorized to use this 2232 connection, an error is returned. 2234 If the PUSH flag is set, the data must be transmitted promptly 2235 to the receiver, and the PUSH bit will be set in the last TCP 2236 segment created from the buffer. If the PUSH flag is not set, 2237 the data may be combined with data from subsequent SENDs for 2238 transmission efficiency. Note that when the Nagle algorithm is 2239 in use, TCP may be buffer the data before sending, without 2240 regard to the PUSH flag (see Section 3.7.4). 2242 New applications SHOULD NOT set the URGENT flag [28] due to 2243 implementation differences and middlebox issues. 2245 If the URGENT flag is set, segments sent to the destination TCP 2246 will have the urgent pointer set. The receiving TCP will 2247 signal the urgent condition to the receiving process if the 2248 urgent pointer indicates that data preceding the urgent pointer 2249 has not been consumed by the receiving process. The purpose of 2250 urgent is to stimulate the receiver to process the urgent data 2251 and to indicate to the receiver when all the currently known 2252 urgent data has been received. The number of times the sending 2253 user's TCP signals urgent will not necessarily be equal to the 2254 number of times the receiving user will be notified of the 2255 presence of urgent data. 2257 If no foreign socket was specified in the OPEN, but the 2258 connection is established (e.g., because a LISTENing connection 2259 has become specific due to a foreign segment arriving for the 2260 local socket), then the designated buffer is sent to the 2261 implied foreign socket. Users who make use of OPEN with an 2262 unspecified foreign socket can make use of SEND without ever 2263 explicitly knowing the foreign socket address. 2265 However, if a SEND is attempted before the foreign socket 2266 becomes specified, an error will be returned. Users can use 2267 the STATUS call to determine the status of the connection. In 2268 some implementations the TCP may notify the user when an 2269 unspecified socket is bound. 2271 If a timeout is specified, the current user timeout for this 2272 connection is changed to the new one. 2274 In the simplest implementation, SEND would not return control 2275 to the sending process until either the transmission was 2276 complete or the timeout had been exceeded. However, this 2277 simple method is both subject to deadlocks (for example, both 2278 sides of the connection might try to do SENDs before doing any 2279 RECEIVEs) and offers poor performance, so it is not 2280 recommended. A more sophisticated implementation would return 2281 immediately to allow the process to run concurrently with 2282 network I/O, and, furthermore, to allow multiple SENDs to be in 2283 progress. Multiple SENDs are served in first come, first 2284 served order, so the TCP will queue those it cannot service 2285 immediately. 2287 We have implicitly assumed an asynchronous user interface in 2288 which a SEND later elicits some kind of SIGNAL or pseudo- 2289 interrupt from the serving TCP. An alternative is to return a 2290 response immediately. For instance, SENDs might return 2291 immediate local acknowledgment, even if the segment sent had 2292 not been acknowledged by the distant TCP. We could 2293 optimistically assume eventual success. If we are wrong, the 2294 connection will close anyway due to the timeout. In 2295 implementations of this kind (synchronous), there will still be 2296 some asynchronous signals, but these will deal with the 2297 connection itself, and not with specific segments or buffers. 2299 In order for the process to distinguish among error or success 2300 indications for different SENDs, it might be appropriate for 2301 the buffer address to be returned along with the coded response 2302 to the SEND request. TCP-to-user signals are discussed below, 2303 indicating the information which should be returned to the 2304 calling process. 2306 Receive 2308 Format: RECEIVE (local connection name, buffer address, byte 2309 count) -> byte count, urgent flag, push flag 2311 This command allocates a receiving buffer associated with the 2312 specified connection. If no OPEN precedes this command or the 2313 calling process is not authorized to use this connection, an 2314 error is returned. 2316 In the simplest implementation, control would not return to the 2317 calling program until either the buffer was filled, or some 2318 error occurred, but this scheme is highly subject to deadlocks. 2319 A more sophisticated implementation would permit several 2320 RECEIVEs to be outstanding at once. These would be filled as 2321 segments arrive. This strategy permits increased throughput at 2322 the cost of a more elaborate scheme (possibly asynchronous) to 2323 notify the calling program that a PUSH has been seen or a 2324 buffer filled. 2326 If enough data arrive to fill the buffer before a PUSH is seen, 2327 the PUSH flag will not be set in the response to the RECEIVE. 2328 The buffer will be filled with as much data as it can hold. If 2329 a PUSH is seen before the buffer is filled the buffer will be 2330 returned partially filled and PUSH indicated. 2332 If there is urgent data the user will have been informed as 2333 soon as it arrived via a TCP-to-user signal. The receiving 2334 user should thus be in "urgent mode". If the URGENT flag is 2335 on, additional urgent data remains. If the URGENT flag is off, 2336 this call to RECEIVE has returned all the urgent data, and the 2337 user may now leave "urgent mode". Note that data following the 2338 urgent pointer (non-urgent data) cannot be delivered to the 2339 user in the same buffer with preceding urgent data unless the 2340 boundary is clearly marked for the user. 2342 To distinguish among several outstanding RECEIVEs and to take 2343 care of the case that a buffer is not completely filled, the 2344 return code is accompanied by both a buffer pointer and a byte 2345 count indicating the actual length of the data received. 2347 Alternative implementations of RECEIVE might have the TCP 2348 allocate buffer storage, or the TCP might share a ring buffer 2349 with the user. 2351 Close 2353 Format: CLOSE (local connection name) 2355 This command causes the connection specified to be closed. If 2356 the connection is not open or the calling process is not 2357 authorized to use this connection, an error is returned. 2358 Closing connections is intended to be a graceful operation in 2359 the sense that outstanding SENDs will be transmitted (and 2360 retransmitted), as flow control permits, until all have been 2361 serviced. Thus, it should be acceptable to make several SEND 2362 calls, followed by a CLOSE, and expect all the data to be sent 2363 to the destination. It should also be clear that users should 2364 continue to RECEIVE on CLOSING connections, since the other 2365 side may be trying to transmit the last of its data. Thus, 2366 CLOSE means "I have no more to send" but does not mean "I will 2367 not receive any more." It may happen (if the user level 2368 protocol is not well thought out) that the closing side is 2369 unable to get rid of all its data before timing out. In this 2370 event, CLOSE turns into ABORT, and the closing TCP gives up. 2372 The user may CLOSE the connection at any time on his own 2373 initiative, or in response to various prompts from the TCP 2374 (e.g., remote close executed, transmission timeout exceeded, 2375 destination inaccessible). 2377 Because closing a connection requires communication with the 2378 foreign TCP, connections may remain in the closing state for a 2379 short time. Attempts to reopen the connection before the TCP 2380 replies to the CLOSE command will result in error responses. 2382 Close also implies push function. 2384 Status 2385 Format: STATUS (local connection name) -> status data 2387 This is an implementation dependent user command and could be 2388 excluded without adverse effect. Information returned would 2389 typically come from the TCB associated with the connection. 2391 This command returns a data block containing the following 2392 information: 2394 local socket, 2395 foreign socket, 2396 local connection name, 2397 receive window, 2398 send window, 2399 connection state, 2400 number of buffers awaiting acknowledgment, 2401 number of buffers pending receipt, 2402 urgent state, 2403 DiffServ field value, 2404 security/compartment, 2405 and transmission timeout. 2407 Depending on the state of the connection, or on the 2408 implementation itself, some of this information may not be 2409 available or meaningful. If the calling process is not 2410 authorized to use this connection, an error is returned. This 2411 prevents unauthorized processes from gaining information about 2412 a connection. 2414 Abort 2416 Format: ABORT (local connection name) 2418 This command causes all pending SENDs and RECEIVES to be 2419 aborted, the TCB to be removed, and a special RESET message to 2420 be sent to the TCP on the other side of the connection. 2421 Depending on the implementation, users may receive abort 2422 indications for each outstanding SEND or RECEIVE, or may simply 2423 receive an ABORT-acknowledgment. 2425 Flush 2427 Some TCP implementations have included a FLUSH call, which will 2428 empty the TCP send queue of any data for which the user has 2429 issued SEND calls but which is still to the right of the 2430 current send window. That is, it flushes as much queued send 2431 data as possible without losing sequence number 2432 synchronization. 2434 Asynchronous Reports 2436 There MUST be a mechanism for reporting soft TCP error 2437 conditions to the application. Generically, we assume this 2438 takes the form of an application-supplied ERROR_REPORT routine 2439 that may be upcalled asynchronously from the transport layer: 2441 ERROR_REPORT(local connection name, reason, subreason) 2443 The precise encoding of the reason and subreason parameters is 2444 not specified here. However, the conditions that are reported 2445 asynchronously to the application MUST include: 2447 * ICMP error message arrived (see Section 3.9.2.2) 2449 * Excessive retransmissions (see Section 3.8.3) 2451 * Urgent pointer advance (see Section 3.8.5). 2453 However, an application program that does not want to receive 2454 such ERROR_REPORT calls SHOULD be able to effectively disable 2455 these calls. 2457 Set Differentiated Services Field (IPv4 TOS or IPv6 Traffic Class) 2459 The application layer MUST be able to specify the 2460 Differentiated Services field for segments that are sent on a 2461 connection. The Differentiated Services field includes the 2462 6-bit Differentiated Services Code Point (DSCP) value. It is 2463 not required, but the application SHOULD be able to change the 2464 Differentiated Services field during the connection lifetime. 2465 TCP SHOULD pass the current Differentiated Services field value 2466 without change to the IP layer, when it sends segments on the 2467 connection. 2469 The Differentiated Services field will be specified 2470 independently in each direction on the connection, so that the 2471 receiver application will specify the Differentiated Services 2472 field used for ACK segments. 2474 TCP MAY pass the most recently received Differentiated Services 2475 field up to the application. 2477 3.9.2. TCP/Lower-Level Interface 2479 The TCP calls on a lower level protocol module to actually send and 2480 receive information over a network. The two current standard 2481 Internet Protocol (IP) versions layered below TCP are IPv4 [1] and 2482 IPv6 [5]. 2484 If the lower level protocol is IPv4 it provides arguments for a type 2485 of service (used within the Differentiated Services field) and for a 2486 time to live. TCP uses the following settings for these parameters: 2488 DiffServ field: The IP header value for the DiffServ field is 2489 given by the user. This includes the bits of the DiffServ Code 2490 Point (DSCP). 2492 Time to Live (TTL): The TTL value used to send TCP segments MUST 2493 be configurable. 2495 Note that RFC 793 specified one minute (60 seconds) as a 2496 constant for the TTL, because the assumed maximum segment 2497 lifetime was two minutes. This was intended to explicitly ask 2498 that a segment be destroyed if it cannot be delivered by the 2499 internet system within one minute. RFC 1122 changed this 2500 specification to require that the TTL be configurable. 2502 Note that the DiffServ field is permitted to change during a 2503 connection (section 4.2.4.2 of RFC 1122). However, the 2504 application interface might not support this ability, and the 2505 application does not have knowledge about individual TCP 2506 segments, so this can only be done on a coarse granularity, at 2507 best. This limitation is further discussed in RFC 7657 (sec 2508 5.1, 5.3, and 6) [37]. Generally, an application SHOULD NOT 2509 change the DiffServ field value during the course of a 2510 connection. 2512 Any lower level protocol will have to provide the source address, 2513 destination address, and protocol fields, and some way to determine 2514 the "TCP length", both to provide the functional equivalent service 2515 of IP and to be used in the TCP checksum. 2517 When received options are passed up to TCP from the IP layer, TCP 2518 MUST ignore options that it does not understand. 2520 A TCP MAY support the Time Stamp and Record Route options. 2522 3.9.2.1. Source Routing 2524 If the lower level is IP (or other protocol that provides this 2525 feature) and source routing is used, the interface must allow the 2526 route information to be communicated. This is especially important 2527 so that the source and destination addresses used in the TCP checksum 2528 be the originating source and ultimate destination. It is also 2529 important to preserve the return route to answer connection requests. 2531 An application MUST be able to specify a source route when it 2532 actively opens a TCP connection, and this MUST take precedence over a 2533 source route received in a datagram. 2535 When a TCP connection is OPENed passively and a packet arrives with a 2536 completed IP Source Route option (containing a return route), TCP 2537 MUST save the return route and use it for all segments sent on this 2538 connection. If a different source route arrives in a later segment, 2539 the later definition SHOULD override the earlier one. 2541 3.9.2.2. ICMP Messages 2543 TCP MUST act on an ICMP error message passed up from the IP layer, 2544 directing it to the connection that created the error. The necessary 2545 demultiplexing information can be found in the IP header contained 2546 within the ICMP message. 2548 This applies to ICMPv6 in addition to IPv4 ICMP. 2550 [22] contains discussion of specific ICMP and ICMPv6 messages 2551 classified as either "soft" or "hard" errors that may bear different 2552 responses. Treatment for classes of ICMP messages is described 2553 below: 2555 Source Quench 2556 TCP MUST silently discard any received ICMP Source Quench messages. 2557 See [11] for discussion. 2559 Soft Errors 2560 For ICMP these include: Destination Unreachable -- codes 0, 1, 5, 2561 Time Exceeded -- codes 0, 1, and Parameter Problem. 2562 For ICMPv6 these include: Destination Unreachable -- codes 0 and 3, 2563 Time Exceeded -- codes 0, 1, and Parameter Problem -- codes 0, 1, 2 2564 Since these Unreachable messages indicate soft error conditions, 2565 TCP MUST NOT abort the connection, and it SHOULD make the 2566 information available to the application. 2568 Hard Errors 2569 For ICMP these include Destination Unreachable -- codes 2-4"> 2570 These are hard error conditions, so TCP SHOULD abort the 2571 connection. [22] notes that some implementations do not abort 2572 connections when an ICMP hard error is received for a connection 2573 that is in any of the synchronized states. 2575 Note that [22] section 4 describes widespread implementation behavior 2576 that treats soft errors as hard errors during connection 2577 establishment. 2579 3.9.2.3. Remote Address Validation 2581 RFC 1122 requires addresses to be validated in incoming SYN packets: 2583 An incoming SYN with an invalid source address must be ignored 2584 either by TCP or by the IP layer (see Section 3.2.1.3 of [14]). 2586 A TCP implementation MUST silently discard an incoming SYN segment 2587 that is addressed to a broadcast or multicast address. 2589 This prevents connection state and replies from being erroneously 2590 generated, and implementers should note that this guidance is 2591 applicable to all incoming segments, not just SYNs, as specifically 2592 indicated in RFC 1122. 2594 3.10. Event Processing 2596 The processing depicted in this section is an example of one possible 2597 implementation. Other implementations may have slightly different 2598 processing sequences, but they should differ from those in this 2599 section only in detail, not in substance. 2601 The activity of the TCP can be characterized as responding to events. 2602 The events that occur can be cast into three categories: user calls, 2603 arriving segments, and timeouts. This section describes the 2604 processing the TCP does in response to each of the events. In many 2605 cases the processing required depends on the state of the connection. 2607 Events that occur: 2609 User Calls 2611 OPEN 2612 SEND 2613 RECEIVE 2614 CLOSE 2615 ABORT 2616 STATUS 2618 Arriving Segments 2620 SEGMENT ARRIVES 2622 Timeouts 2623 USER TIMEOUT 2624 RETRANSMISSION TIMEOUT 2625 TIME-WAIT TIMEOUT 2627 The model of the TCP/user interface is that user commands receive an 2628 immediate return and possibly a delayed response via an event or 2629 pseudo interrupt. In the following descriptions, the term "signal" 2630 means cause a delayed response. 2632 Error responses are given as character strings. For example, user 2633 commands referencing connections that do not exist receive "error: 2634 connection not open". 2636 Please note in the following that all arithmetic on sequence numbers, 2637 acknowledgment numbers, windows, et cetera, is modulo 2**32 the size 2638 of the sequence number space. Also note that "=<" means less than or 2639 equal to (modulo 2**32). 2641 A natural way to think about processing incoming segments is to 2642 imagine that they are first tested for proper sequence number (i.e., 2643 that their contents lie in the range of the expected "receive window" 2644 in the sequence number space) and then that they are generally queued 2645 and processed in sequence number order. 2647 When a segment overlaps other already received segments we 2648 reconstruct the segment to contain just the new data, and adjust the 2649 header fields to be consistent. 2651 Note that if no state change is mentioned the TCP stays in the same 2652 state. 2654 OPEN Call 2656 CLOSED STATE (i.e., TCB does not exist) 2658 Create a new transmission control block (TCB) to hold 2659 connection state information. Fill in local socket identifier, 2660 foreign socket, DiffServ field, security/compartment, and user 2661 timeout information. Note that some parts of the foreign 2662 socket may be unspecified in a passive OPEN and are to be 2663 filled in by the parameters of the incoming SYN segment. 2664 Verify the security and DiffServ value requested are allowed 2665 for this user, if not return "error: precedence not allowed" or 2666 "error: security/compartment not allowed." If passive enter 2667 the LISTEN state and return. If active and the foreign socket 2668 is unspecified, return "error: foreign socket unspecified"; if 2669 active and the foreign socket is specified, issue a SYN 2670 segment. An initial send sequence number (ISS) is selected. A 2671 SYN segment of the form is sent. Set 2672 SND.UNA to ISS, SND.NXT to ISS+1, enter SYN-SENT state, and 2673 return. 2675 If the caller does not have access to the local socket 2676 specified, return "error: connection illegal for this process". 2677 If there is no room to create a new connection, return "error: 2678 insufficient resources". 2680 LISTEN STATE 2682 If active and the foreign socket is specified, then change the 2683 connection from passive to active, select an ISS. Send a SYN 2684 segment, set SND.UNA to ISS, SND.NXT to ISS+1. Enter SYN-SENT 2685 state. Data associated with SEND may be sent with SYN segment 2686 or queued for transmission after entering ESTABLISHED state. 2687 The urgent bit if requested in the command must be sent with 2688 the data segments sent as a result of this command. If there 2689 is no room to queue the request, respond with "error: 2690 insufficient resources". If Foreign socket was not specified, 2691 then return "error: foreign socket unspecified". 2693 SYN-SENT STATE 2694 SYN-RECEIVED STATE 2695 ESTABLISHED STATE 2696 FIN-WAIT-1 STATE 2697 FIN-WAIT-2 STATE 2698 CLOSE-WAIT STATE 2699 CLOSING STATE 2700 LAST-ACK STATE 2701 TIME-WAIT STATE 2703 Return "error: connection already exists". 2705 SEND Call 2707 CLOSED STATE (i.e., TCB does not exist) 2709 If the user does not have access to such a connection, then 2710 return "error: connection illegal for this process". 2712 Otherwise, return "error: connection does not exist". 2714 LISTEN STATE 2716 If the foreign socket is specified, then change the connection 2717 from passive to active, select an ISS. Send a SYN segment, set 2718 SND.UNA to ISS, SND.NXT to ISS+1. Enter SYN-SENT state. Data 2719 associated with SEND may be sent with SYN segment or queued for 2720 transmission after entering ESTABLISHED state. The urgent bit 2721 if requested in the command must be sent with the data segments 2722 sent as a result of this command. If there is no room to queue 2723 the request, respond with "error: insufficient resources". If 2724 Foreign socket was not specified, then return "error: foreign 2725 socket unspecified". 2727 SYN-SENT STATE 2728 SYN-RECEIVED STATE 2730 Queue the data for transmission after entering ESTABLISHED 2731 state. If no space to queue, respond with "error: insufficient 2732 resources". 2734 ESTABLISHED STATE 2735 CLOSE-WAIT STATE 2737 Segmentize the buffer and send it with a piggybacked 2738 acknowledgment (acknowledgment value = RCV.NXT). If there is 2739 insufficient space to remember this buffer, simply return 2740 "error: insufficient resources". 2742 If the urgent flag is set, then SND.UP <- SND.NXT and set the 2743 urgent pointer in the outgoing segments. 2745 FIN-WAIT-1 STATE 2746 FIN-WAIT-2 STATE 2747 CLOSING STATE 2748 LAST-ACK STATE 2749 TIME-WAIT STATE 2751 Return "error: connection closing" and do not service request. 2753 RECEIVE Call 2755 CLOSED STATE (i.e., TCB does not exist) 2757 If the user does not have access to such a connection, return 2758 "error: connection illegal for this process". 2760 Otherwise return "error: connection does not exist". 2762 LISTEN STATE 2763 SYN-SENT STATE 2764 SYN-RECEIVED STATE 2766 Queue for processing after entering ESTABLISHED state. If 2767 there is no room to queue this request, respond with "error: 2768 insufficient resources". 2770 ESTABLISHED STATE 2771 FIN-WAIT-1 STATE 2772 FIN-WAIT-2 STATE 2774 If insufficient incoming segments are queued to satisfy the 2775 request, queue the request. If there is no queue space to 2776 remember the RECEIVE, respond with "error: insufficient 2777 resources". 2779 Reassemble queued incoming segments into receive buffer and 2780 return to user. Mark "push seen" (PUSH) if this is the case. 2782 If RCV.UP is in advance of the data currently being passed to 2783 the user notify the user of the presence of urgent data. 2785 When the TCP takes responsibility for delivering data to the 2786 user that fact must be communicated to the sender via an 2787 acknowledgment. The formation of such an acknowledgment is 2788 described below in the discussion of processing an incoming 2789 segment. 2791 CLOSE-WAIT STATE 2793 Since the remote side has already sent FIN, RECEIVEs must be 2794 satisfied by text already on hand, but not yet delivered to the 2795 user. If no text is awaiting delivery, the RECEIVE will get a 2796 "error: connection closing" response. Otherwise, any remaining 2797 text can be used to satisfy the RECEIVE. 2799 CLOSING STATE 2800 LAST-ACK STATE 2801 TIME-WAIT STATE 2803 Return "error: connection closing". 2805 CLOSE Call 2807 CLOSED STATE (i.e., TCB does not exist) 2809 If the user does not have access to such a connection, return 2810 "error: connection illegal for this process". 2812 Otherwise, return "error: connection does not exist". 2814 LISTEN STATE 2816 Any outstanding RECEIVEs are returned with "error: closing" 2817 responses. Delete TCB, enter CLOSED state, and return. 2819 SYN-SENT STATE 2821 Delete the TCB and return "error: closing" responses to any 2822 queued SENDs, or RECEIVEs. 2824 SYN-RECEIVED STATE 2826 If no SENDs have been issued and there is no pending data to 2827 send, then form a FIN segment and send it, and enter FIN-WAIT-1 2828 state; otherwise queue for processing after entering 2829 ESTABLISHED state. 2831 ESTABLISHED STATE 2833 Queue this until all preceding SENDs have been segmentized, 2834 then form a FIN segment and send it. In any case, enter FIN- 2835 WAIT-1 state. 2837 FIN-WAIT-1 STATE 2838 FIN-WAIT-2 STATE 2840 Strictly speaking, this is an error and should receive a 2841 "error: connection closing" response. An "ok" response would 2842 be acceptable, too, as long as a second FIN is not emitted (the 2843 first FIN may be retransmitted though). 2845 CLOSE-WAIT STATE 2847 Queue this request until all preceding SENDs have been 2848 segmentized; then send a FIN segment, enter LAST-ACK state. 2850 CLOSING STATE 2851 LAST-ACK STATE 2852 TIME-WAIT STATE 2853 Respond with "error: connection closing". 2855 ABORT Call 2857 CLOSED STATE (i.e., TCB does not exist) 2859 If the user should not have access to such a connection, return 2860 "error: connection illegal for this process". 2862 Otherwise return "error: connection does not exist". 2864 LISTEN STATE 2866 Any outstanding RECEIVEs should be returned with "error: 2867 connection reset" responses. Delete TCB, enter CLOSED state, 2868 and return. 2870 SYN-SENT STATE 2872 All queued SENDs and RECEIVEs should be given "connection 2873 reset" notification, delete the TCB, enter CLOSED state, and 2874 return. 2876 SYN-RECEIVED STATE 2877 ESTABLISHED STATE 2878 FIN-WAIT-1 STATE 2879 FIN-WAIT-2 STATE 2880 CLOSE-WAIT STATE 2882 Send a reset segment: 2884 2886 All queued SENDs and RECEIVEs should be given "connection 2887 reset" notification; all segments queued for transmission 2888 (except for the RST formed above) or retransmission should be 2889 flushed, delete the TCB, enter CLOSED state, and return. 2891 CLOSING STATE LAST-ACK STATE TIME-WAIT STATE 2893 Respond with "ok" and delete the TCB, enter CLOSED state, and 2894 return. 2896 STATUS Call 2898 CLOSED STATE (i.e., TCB does not exist) 2900 If the user should not have access to such a connection, return 2901 "error: connection illegal for this process". 2903 Otherwise return "error: connection does not exist". 2905 LISTEN STATE 2907 Return "state = LISTEN", and the TCB pointer. 2909 SYN-SENT STATE 2911 Return "state = SYN-SENT", and the TCB pointer. 2913 SYN-RECEIVED STATE 2915 Return "state = SYN-RECEIVED", and the TCB pointer. 2917 ESTABLISHED STATE 2919 Return "state = ESTABLISHED", and the TCB pointer. 2921 FIN-WAIT-1 STATE 2923 Return "state = FIN-WAIT-1", and the TCB pointer. 2925 FIN-WAIT-2 STATE 2927 Return "state = FIN-WAIT-2", and the TCB pointer. 2929 CLOSE-WAIT STATE 2931 Return "state = CLOSE-WAIT", and the TCB pointer. 2933 CLOSING STATE 2935 Return "state = CLOSING", and the TCB pointer. 2937 LAST-ACK STATE 2939 Return "state = LAST-ACK", and the TCB pointer. 2941 TIME-WAIT STATE 2943 Return "state = TIME-WAIT", and the TCB pointer. 2945 SEGMENT ARRIVES 2947 If the state is CLOSED (i.e., TCB does not exist) then 2949 all data in the incoming segment is discarded. An incoming 2950 segment containing a RST is discarded. An incoming segment not 2951 containing a RST causes a RST to be sent in response. The 2952 acknowledgment and sequence field values are selected to make 2953 the reset sequence acceptable to the TCP that sent the 2954 offending segment. 2956 If the ACK bit is off, sequence number zero is used, 2958 2960 If the ACK bit is on, 2962 2964 Return. 2966 If the state is LISTEN then 2968 first check for an RST 2970 An incoming RST should be ignored. Return. 2972 second check for an ACK 2974 Any acknowledgment is bad if it arrives on a connection 2975 still in the LISTEN state. An acceptable reset segment 2976 should be formed for any arriving ACK-bearing segment. The 2977 RST should be formatted as follows: 2979 2981 Return. 2983 third check for a SYN 2985 If the SYN bit is set, check the security. If the security/ 2986 compartment on the incoming segment does not exactly match 2987 the security/compartment in the TCB then send a reset and 2988 return. 2990 2992 Set RCV.NXT to SEG.SEQ+1, IRS is set to SEG.SEQ and any 2993 other control or text should be queued for processing later. 2994 ISS should be selected and a SYN segment sent of the form: 2996 2998 SND.NXT is set to ISS+1 and SND.UNA to ISS. The connection 2999 state should be changed to SYN-RECEIVED. Note that any 3000 other incoming control or data (combined with SYN) will be 3001 processed in the SYN-RECEIVED state, but processing of SYN 3002 and ACK should not be repeated. If the listen was not fully 3003 specified (i.e., the foreign socket was not fully 3004 specified), then the unspecified fields should be filled in 3005 now. 3007 fourth other text or control 3009 Any other control or text-bearing segment (not containing 3010 SYN) must have an ACK and thus would be discarded by the ACK 3011 processing. An incoming RST segment could not be valid, 3012 since it could not have been sent in response to anything 3013 sent by this incarnation of the connection. So you are 3014 unlikely to get here, but if you do, drop the segment, and 3015 return. 3017 If the state is SYN-SENT then 3019 first check the ACK bit 3021 If the ACK bit is set 3023 If SEG.ACK =< ISS, or SEG.ACK > SND.NXT, send a reset 3024 (unless the RST bit is set, if so drop the segment and 3025 return) 3027 3029 and discard the segment. Return. 3031 If SND.UNA < SEG.ACK =< SND.NXT then the ACK is 3032 acceptable. Some deployed TCP code has used the check 3033 SEG.ACK == SND.NEXT (using "==" rather than "=<", but 3034 this is not appropriate when the stack is capable of 3035 sending data on the SYN, because the peer TCP may not 3036 accept and acknowledge all of the data on the SYN. 3038 second check the RST bit 3039 If the RST bit is set 3041 A potential blind reset attack is described in RFC 5961 3042 [27], with the mitigation that a TCP implementation 3043 SHOULD first check that the sequence number exactly 3044 matches RCV.NXT prior to executing the action in the next 3045 paragraph. 3047 If the ACK was acceptable then signal the user "error: 3048 connection reset", drop the segment, enter CLOSED state, 3049 delete TCB, and return. Otherwise (no ACK) drop the 3050 segment and return. 3052 third check the security 3054 If the security/compartment in the segment does not exactly 3055 match the security/compartment in the TCB, send a reset 3057 If there is an ACK 3059 3061 Otherwise 3063 3065 If a reset was sent, discard the segment and return. 3067 fourth check the SYN bit 3069 This step should be reached only if the ACK is ok, or there 3070 is no ACK, and it the segment did not contain a RST. 3072 If the SYN bit is on and the security/compartment is 3073 acceptable then, RCV.NXT is set to SEG.SEQ+1, IRS is set to 3074 SEG.SEQ. SND.UNA should be advanced to equal SEG.ACK (if 3075 there is an ACK), and any segments on the retransmission 3076 queue which are thereby acknowledged should be removed. 3078 If SND.UNA > ISS (our SYN has been ACKed), change the 3079 connection state to ESTABLISHED, form an ACK segment 3081 3083 and send it. Data or controls which were queued for 3084 transmission may be included. If there are other controls 3085 or text in the segment then continue processing at the sixth 3086 step below where the URG bit is checked, otherwise return. 3088 Otherwise enter SYN-RECEIVED, form a SYN,ACK segment 3090 3092 and send it. Set the variables: 3094 SND.WND <- SEG.WND 3095 SND.WL1 <- SEG.SEQ 3096 SND.WL2 <- SEG.ACK 3098 If there are other controls or text in the segment, queue 3099 them for processing after the ESTABLISHED state has been 3100 reached, return. 3102 Note that it is legal to send and receive application data 3103 on SYN segments (this is the "text in the segment" mentioned 3104 above. There has been significant misinformation and 3105 misunderstanding of this topic historically. Some firewalls 3106 and security devices consider this suspicious. However, the 3107 capability was used in T/TCP [16] and is used in TCP Fast 3108 Open (TFO) [35], so is important for implementations and 3109 network devices to permit. 3111 fifth, if neither of the SYN or RST bits is set then drop the 3112 segment and return. 3114 Otherwise, 3116 first check sequence number 3118 SYN-RECEIVED STATE 3119 ESTABLISHED STATE 3120 FIN-WAIT-1 STATE 3121 FIN-WAIT-2 STATE 3122 CLOSE-WAIT STATE 3123 CLOSING STATE 3124 LAST-ACK STATE 3125 TIME-WAIT STATE 3127 Segments are processed in sequence. Initial tests on 3128 arrival are used to discard old duplicates, but further 3129 processing is done in SEG.SEQ order. If a segment's 3130 contents straddle the boundary between old and new, only the 3131 new parts should be processed. 3133 In general, the processing of received segments MUST be 3134 implemented to aggregate ACK segments whenever possible. 3135 For example, if the TCP is processing a series of queued 3136 segments, it MUST process them all before sending any ACK 3137 segments. 3139 There are four cases for the acceptability test for an 3140 incoming segment: 3142 Segment Receive Test 3143 Length Window 3144 ------- ------- ------------------------------------------- 3146 0 0 SEG.SEQ = RCV.NXT 3148 0 >0 RCV.NXT =< SEG.SEQ < RCV.NXT+RCV.WND 3150 >0 0 not acceptable 3152 >0 >0 RCV.NXT =< SEG.SEQ < RCV.NXT+RCV.WND 3153 or RCV.NXT =< SEG.SEQ+SEG.LEN-1 < RCV.NXT+RCV.WND 3155 In implementing sequence number validation as described 3156 here, please note Appendix A.2. 3158 If the RCV.WND is zero, no segments will be acceptable, but 3159 special allowance should be made to accept valid ACKs, URGs 3160 and RSTs. 3162 If an incoming segment is not acceptable, an acknowledgment 3163 should be sent in reply (unless the RST bit is set, if so 3164 drop the segment and return): 3166 3168 After sending the acknowledgment, drop the unacceptable 3169 segment and return. 3171 Note that for the TIME-WAIT state, there is an improved 3172 algorithm described in [29] for handling incoming SYN 3173 segments, that utilizes timestamps rather than relying on 3174 the sequence number check described here. When the improved 3175 algorithm is implemented, the logic above is not applicable 3176 for incoming SYN segments with timestamp options, received 3177 on a connection in the TIME-WAIT state. 3179 In the following it is assumed that the segment is the 3180 idealized segment that begins at RCV.NXT and does not exceed 3181 the window. One could tailor actual segments to fit this 3182 assumption by trimming off any portions that lie outside the 3183 window (including SYN and FIN), and only processing further 3184 if the segment then begins at RCV.NXT. Segments with higher 3185 beginning sequence numbers should be held for later 3186 processing. 3188 second check the RST bit, 3190 RFC 5961 section 3 describes a potential blind reset attack 3191 and optional mitigation approach that SHOULD be implemented. 3192 For stacks implementing RFC 5961, the three checks below 3193 apply, otherwise processesing for these states is indicated 3194 further below. 3196 1) If the RST bit is set and the sequence number is 3197 outside the current receive window, silently drop the 3198 segment. 3200 2) If the RST bit is set and the sequence number exactly 3201 matches the next expected sequence number (RCV.NXT), then 3202 TCP MUST reset the connection in the manner prescribed 3203 below according to the connection state. 3205 3) If the RST bit is set and the sequence number does not 3206 exactly match the next expected sequence value, yet is 3207 within the current receive window, TCP MUST send an 3208 acknowledgement (challenge ACK): 3210 3212 After sending the challenge ACK, TCP MUST drop the 3213 unacceptable segment and stop processing the incoming 3214 packet further. Note that RFC 5961 and Errata ID 4772 3215 contain additional considerations for ACK throttling in 3216 an implementation. 3218 SYN-RECEIVED STATE 3220 If the RST bit is set 3222 If this connection was initiated with a passive OPEN 3223 (i.e., came from the LISTEN state), then return this 3224 connection to LISTEN state and return. The user need 3225 not be informed. If this connection was initiated 3226 with an active OPEN (i.e., came from SYN-SENT state) 3227 then the connection was refused, signal the user 3228 "connection refused". In either case, all segments on 3229 the retransmission queue should be removed. And in 3230 the active OPEN case, enter the CLOSED state and 3231 delete the TCB, and return. 3233 ESTABLISHED 3234 FIN-WAIT-1 3235 FIN-WAIT-2 3236 CLOSE-WAIT 3238 If the RST bit is set then, any outstanding RECEIVEs and 3239 SEND should receive "reset" responses. All segment 3240 queues should be flushed. Users should also receive an 3241 unsolicited general "connection reset" signal. Enter the 3242 CLOSED state, delete the TCB, and return. 3244 CLOSING STATE 3245 LAST-ACK STATE 3246 TIME-WAIT 3248 If the RST bit is set then, enter the CLOSED state, 3249 delete the TCB, and return. 3251 third check security 3253 SYN-RECEIVED 3255 If the security/compartment in the segment does not 3256 exactly match the security/compartment in the TCB then 3257 send a reset, and return. 3259 ESTABLISHED 3260 FIN-WAIT-1 3261 FIN-WAIT-2 3262 CLOSE-WAIT 3263 CLOSING 3264 LAST-ACK 3265 TIME-WAIT 3267 If the security/compartment in the segment does not 3268 exactly match the security/compartment in the TCB then 3269 send a reset, any outstanding RECEIVEs and SEND should 3270 receive "reset" responses. All segment queues should be 3271 flushed. Users should also receive an unsolicited 3272 general "connection reset" signal. Enter the CLOSED 3273 state, delete the TCB, and return. 3275 Note this check is placed following the sequence check to 3276 prevent a segment from an old connection between these ports 3277 with a different security from causing an abort of the 3278 current connection. 3280 fourth, check the SYN bit, 3282 SYN-RECEIVED 3284 If the connection was initiated with a passive OPEN, then 3285 return this connection to the LISTEN state and return. 3286 Otherwise, handle per the directions for synchronized 3287 states below. 3289 ESTABLISHED STATE 3290 FIN-WAIT STATE-1 3291 FIN-WAIT STATE-2 3292 CLOSE-WAIT STATE 3293 CLOSING STATE 3294 LAST-ACK STATE 3295 TIME-WAIT STATE 3297 If the SYN bit is set in these synchronized states, it 3298 may be either a legitimate new connection attempt (e.g. 3299 in the case of TIME-WAIT), an error where the connection 3300 should be reset, or the result of an attack attempt, as 3301 described in RFC 5961 [27]. For the TIME-WAIT state, new 3302 connections can be accepted if the timestamp option is 3303 used and meets expectations (per [29]). For all other 3304 caess, RFC 5961 provides a mitigation that SHOULD be 3305 implemented, though there are alternatives (see 3306 Section 6). RFC 5961 recommends that in these 3307 synchronized states, if the SYN bit is set, irrespective 3308 of the sequence number, TCP MUST send a "challenge ACK" 3309 to the remote peer: 3311 3313 After sending the acknowledgement, TCP MUST drop the 3314 unacceptable segment and stop processing further. Note 3315 that RFC 5961 and Errata ID 4772 contain additional ACK 3316 throttling notes for an implementation. 3318 For implementations that do not follow RFC 5961, the 3319 original RFC 793 behavior follows in this paragraph. If 3320 the SYN is in the window it is an error, send a reset, 3321 any outstanding RECEIVEs and SEND should receive "reset" 3322 responses, all segment queues should be flushed, the user 3323 should also receive an unsolicited general "connection 3324 reset" signal, enter the CLOSED state, delete the TCB, 3325 and return. 3327 If the SYN is not in the window this step would not be 3328 reached and an ack would have been sent in the first step 3329 (sequence number check). 3331 fifth check the ACK field, 3333 if the ACK bit is off drop the segment and return 3335 if the ACK bit is on 3337 RFC 5961 section 5 describes a potential blind data 3338 injection attack, and mitigation that implementations MAY 3339 choose to include. TCP stacks that implement RFC 5961 3340 MUST add an input check that the ACK value is acceptable 3341 only if it is in the range of ((SND.UNA - MAX.SND.WND) =< 3342 SEG.ACK =< SND.NXT). All incoming segments whose ACK 3343 value doesn't satisfy the above condition MUST be 3344 discarded and an ACK sent back. The new state variable 3345 MAX.SND.WND is defined as the largest window that the 3346 local sender has ever received from its peer (subject to 3347 window scaling) or may be hard-coded to a maximum 3348 permissible window value. When the ACK value is 3349 acceptable, the processing per-state below applies: 3351 SYN-RECEIVED STATE 3353 If SND.UNA < SEG.ACK =< SND.NXT then enter ESTABLISHED 3354 state and continue processing with variables below set 3355 to: 3357 SND.WND <- SEG.WND 3358 SND.WL1 <- SEG.SEQ 3359 SND.WL2 <- SEG.ACK 3361 If the segment acknowledgment is not acceptable, 3362 form a reset segment, 3364 3366 and send it. 3368 ESTABLISHED STATE 3370 If SND.UNA < SEG.ACK =< SND.NXT then, set SND.UNA <- 3371 SEG.ACK. Any segments on the retransmission queue 3372 which are thereby entirely acknowledged are removed. 3373 Users should receive positive acknowledgments for 3374 buffers which have been SENT and fully acknowledged 3375 (i.e., SEND buffer should be returned with "ok" 3376 response). If the ACK is a duplicate (SEG.ACK =< 3377 SND.UNA), it can be ignored. If the ACK acks 3378 something not yet sent (SEG.ACK > SND.NXT) then send 3379 an ACK, drop the segment, and return. 3381 If SND.UNA =< SEG.ACK =< SND.NXT, the send window 3382 should be updated. If (SND.WL1 < SEG.SEQ or (SND.WL1 3383 = SEG.SEQ and SND.WL2 =< SEG.ACK)), set SND.WND <- 3384 SEG.WND, set SND.WL1 <- SEG.SEQ, and set SND.WL2 <- 3385 SEG.ACK. 3387 Note that SND.WND is an offset from SND.UNA, that 3388 SND.WL1 records the sequence number of the last 3389 segment used to update SND.WND, and that SND.WL2 3390 records the acknowledgment number of the last segment 3391 used to update SND.WND. The check here prevents using 3392 old segments to update the window. 3394 FIN-WAIT-1 STATE 3396 In addition to the processing for the ESTABLISHED 3397 state, if our FIN is now acknowledged then enter FIN- 3398 WAIT-2 and continue processing in that state. 3400 FIN-WAIT-2 STATE 3402 In addition to the processing for the ESTABLISHED 3403 state, if the retransmission queue is empty, the 3404 user's CLOSE can be acknowledged ("ok") but do not 3405 delete the TCB. 3407 CLOSE-WAIT STATE 3409 Do the same processing as for the ESTABLISHED state. 3411 CLOSING STATE 3413 In addition to the processing for the ESTABLISHED 3414 state, if the ACK acknowledges our FIN then enter the 3415 TIME-WAIT state, otherwise ignore the segment. 3417 LAST-ACK STATE 3418 The only thing that can arrive in this state is an 3419 acknowledgment of our FIN. If our FIN is now 3420 acknowledged, delete the TCB, enter the CLOSED state, 3421 and return. 3423 TIME-WAIT STATE 3425 The only thing that can arrive in this state is a 3426 retransmission of the remote FIN. Acknowledge it, and 3427 restart the 2 MSL timeout. 3429 sixth, check the URG bit, 3431 ESTABLISHED STATE 3432 FIN-WAIT-1 STATE 3433 FIN-WAIT-2 STATE 3435 If the URG bit is set, RCV.UP <- max(RCV.UP,SEG.UP), and 3436 signal the user that the remote side has urgent data if 3437 the urgent pointer (RCV.UP) is in advance of the data 3438 consumed. If the user has already been signaled (or is 3439 still in the "urgent mode") for this continuous sequence 3440 of urgent data, do not signal the user again. 3442 CLOSE-WAIT STATE 3443 CLOSING STATE 3444 LAST-ACK STATE 3445 TIME-WAIT 3447 This should not occur, since a FIN has been received from 3448 the remote side. Ignore the URG. 3450 seventh, process the segment text, 3452 ESTABLISHED STATE 3453 FIN-WAIT-1 STATE 3454 FIN-WAIT-2 STATE 3456 Once in the ESTABLISHED state, it is possible to deliver 3457 segment text to user RECEIVE buffers. Text from segments 3458 can be moved into buffers until either the buffer is full 3459 or the segment is empty. If the segment empties and 3460 carries an PUSH flag, then the user is informed, when the 3461 buffer is returned, that a PUSH has been received. 3463 When the TCP takes responsibility for delivering the data 3464 to the user it must also acknowledge the receipt of the 3465 data. 3467 Once the TCP takes responsibility for the data it 3468 advances RCV.NXT over the data accepted, and adjusts 3469 RCV.WND as appropriate to the current buffer 3470 availability. The total of RCV.NXT and RCV.WND should 3471 not be reduced. 3473 A TCP MAY send an ACK segment acknowledging RCV.NXT when 3474 a valid segment arrives that is in the window but not at 3475 the left window edge. 3477 Please note the window management suggestions in 3478 Section 3.8. 3480 Send an acknowledgment of the form: 3482 3484 This acknowledgment should be piggybacked on a segment 3485 being transmitted if possible without incurring undue 3486 delay. 3488 CLOSE-WAIT STATE 3489 CLOSING STATE 3490 LAST-ACK STATE 3491 TIME-WAIT STATE 3493 This should not occur, since a FIN has been received from 3494 the remote side. Ignore the segment text. 3496 eighth, check the FIN bit, 3498 Do not process the FIN if the state is CLOSED, LISTEN or 3499 SYN-SENT since the SEG.SEQ cannot be validated; drop the 3500 segment and return. 3502 If the FIN bit is set, signal the user "connection closing" 3503 and return any pending RECEIVEs with same message, advance 3504 RCV.NXT over the FIN, and send an acknowledgment for the 3505 FIN. Note that FIN implies PUSH for any segment text not 3506 yet delivered to the user. 3508 SYN-RECEIVED STATE 3509 ESTABLISHED STATE 3511 Enter the CLOSE-WAIT state. 3513 FIN-WAIT-1 STATE 3514 If our FIN has been ACKed (perhaps in this segment), 3515 then enter TIME-WAIT, start the time-wait timer, turn 3516 off the other timers; otherwise enter the CLOSING 3517 state. 3519 FIN-WAIT-2 STATE 3521 Enter the TIME-WAIT state. Start the time-wait timer, 3522 turn off the other timers. 3524 CLOSE-WAIT STATE 3526 Remain in the CLOSE-WAIT state. 3528 CLOSING STATE 3530 Remain in the CLOSING state. 3532 LAST-ACK STATE 3534 Remain in the LAST-ACK state. 3536 TIME-WAIT STATE 3538 Remain in the TIME-WAIT state. Restart the 2 MSL 3539 time-wait timeout. 3541 and return. 3543 USER TIMEOUT 3545 USER TIMEOUT 3547 For any state if the user timeout expires, flush all queues, 3548 signal the user "error: connection aborted due to user timeout" 3549 in general and for any outstanding calls, delete the TCB, enter 3550 the CLOSED state and return. 3552 RETRANSMISSION TIMEOUT 3554 For any state if the retransmission timeout expires on a 3555 segment in the retransmission queue, send the segment at the 3556 front of the retransmission queue again, reinitialize the 3557 retransmission timer, and return. 3559 TIME-WAIT TIMEOUT 3561 If the time-wait timeout expires on a connection delete the 3562 TCB, enter the CLOSED state and return. 3564 3.11. Glossary 3566 1822 BBN Report 1822, "The Specification of the Interconnection of 3567 a Host and an IMP". The specification of interface between a 3568 host and the ARPANET. 3570 ACK 3571 A control bit (acknowledge) occupying no sequence space, 3572 which indicates that the acknowledgment field of this segment 3573 specifies the next sequence number the sender of this segment 3574 is expecting to receive, hence acknowledging receipt of all 3575 previous sequence numbers. 3577 ARPANET message 3578 The unit of transmission between a host and an IMP in the 3579 ARPANET. The maximum size is about 1012 octets (8096 bits). 3581 ARPANET packet 3582 A unit of transmission used internally in the ARPANET between 3583 IMPs. The maximum size is about 126 octets (1008 bits). 3585 connection 3586 A logical communication path identified by a pair of sockets. 3588 datagram 3589 A message sent in a packet switched computer communications 3590 network. 3592 Destination Address 3593 The destination address, usually the network and host 3594 identifiers. 3596 FIN 3597 A control bit (finis) occupying one sequence number, which 3598 indicates that the sender will send no more data or control 3599 occupying sequence space. 3601 fragment 3602 A portion of a logical unit of data, in particular an 3603 internet fragment is a portion of an internet datagram. 3605 FTP 3606 A file transfer protocol. 3608 header 3609 Control information at the beginning of a message, segment, 3610 fragment, packet or block of data. 3612 host 3613 A computer. In particular a source or destination of 3614 messages from the point of view of the communication network. 3616 Identification 3617 An Internet Protocol field. This identifying value assigned 3618 by the sender aids in assembling the fragments of a datagram. 3620 IMP 3621 The Interface Message Processor, the packet switch of the 3622 ARPANET. 3624 internet address 3625 A source or destination address specific to the host level. 3627 internet datagram 3628 The unit of data exchanged between an internet module and the 3629 higher level protocol together with the internet header. 3631 internet fragment 3632 A portion of the data of an internet datagram with an 3633 internet header. 3635 IP 3636 Internet Protocol. 3638 IRS 3639 The Initial Receive Sequence number. The first sequence 3640 number used by the sender on a connection. 3642 ISN 3643 The Initial Sequence Number. The first sequence number used 3644 on a connection, (either ISS or IRS). Selected in a way that 3645 is unique within a given period of time and is unpredictable 3646 to attackers. 3648 ISS 3649 The Initial Send Sequence number. The first sequence number 3650 used by the sender on a connection. 3652 leader 3653 Control information at the beginning of a message or block of 3654 data. In particular, in the ARPANET, the control information 3655 on an ARPANET message at the host-IMP interface. 3657 left sequence 3658 This is the next sequence number to be acknowledged by the 3659 data receiving TCP (or the lowest currently unacknowledged 3660 sequence number) and is sometimes referred to as the left 3661 edge of the send window. 3663 local packet 3664 The unit of transmission within a local network. 3666 module 3667 An implementation, usually in software, of a protocol or 3668 other procedure. 3670 MSL 3671 Maximum Segment Lifetime, the time a TCP segment can exist in 3672 the internetwork system. Arbitrarily defined to be 2 3673 minutes. 3675 octet 3676 An eight bit byte. 3678 Options 3679 An Option field may contain several options, and each option 3680 may be several octets in length. 3682 packet 3683 A package of data with a header which may or may not be 3684 logically complete. More often a physical packaging than a 3685 logical packaging of data. 3687 port 3688 The portion of a socket that specifies which logical input or 3689 output channel of a process is associated with the data. 3691 process 3692 A program in execution. A source or destination of data from 3693 the point of view of the TCP or other host-to-host protocol. 3695 PUSH 3696 A control bit occupying no sequence space, indicating that 3697 this segment contains data that must be pushed through to the 3698 receiving user. 3700 RCV.NXT 3701 receive next sequence number 3703 RCV.UP 3704 receive urgent pointer 3706 RCV.WND 3707 receive window 3709 receive next sequence number 3710 This is the next sequence number the local TCP is expecting 3711 to receive. 3713 receive window 3714 This represents the sequence numbers the local (receiving) 3715 TCP is willing to receive. Thus, the local TCP considers 3716 that segments overlapping the range RCV.NXT to RCV.NXT + 3717 RCV.WND - 1 carry acceptable data or control. Segments 3718 containing sequence numbers entirely outside of this range 3719 are considered duplicates and discarded. 3721 RST 3722 A control bit (reset), occupying no sequence space, 3723 indicating that the receiver should delete the connection 3724 without further interaction. The receiver can determine, 3725 based on the sequence number and acknowledgment fields of the 3726 incoming segment, whether it should honor the reset command 3727 or ignore it. In no case does receipt of a segment 3728 containing RST give rise to a RST in response. 3730 RTP 3731 Real Time Protocol: A host-to-host protocol for communication 3732 of time critical information. 3734 SEG.ACK 3735 segment acknowledgment 3737 SEG.LEN 3738 segment length 3740 SEG.SEQ 3741 segment sequence 3743 SEG.UP 3744 segment urgent pointer field 3746 SEG.WND 3747 segment window field 3749 segment 3750 A logical unit of data, in particular a TCP segment is the 3751 unit of data transfered between a pair of TCP modules. 3753 segment acknowledgment 3754 The sequence number in the acknowledgment field of the 3755 arriving segment. 3757 segment length 3758 The amount of sequence number space occupied by a segment, 3759 including any controls which occupy sequence space. 3761 segment sequence 3762 The number in the sequence field of the arriving segment. 3764 send sequence 3765 This is the next sequence number the local (sending) TCP will 3766 use on the connection. It is initially selected from an 3767 initial sequence number curve (ISN) and is incremented for 3768 each octet of data or sequenced control transmitted. 3770 send window 3771 This represents the sequence numbers which the remote 3772 (receiving) TCP is willing to receive. It is the value of 3773 the window field specified in segments from the remote (data 3774 receiving) TCP. The range of new sequence numbers which may 3775 be emitted by a TCP lies between SND.NXT and SND.UNA + 3776 SND.WND - 1. (Retransmissions of sequence numbers between 3777 SND.UNA and SND.NXT are expected, of course.) 3779 SND.NXT 3780 send sequence 3782 SND.UNA 3783 left sequence 3785 SND.UP 3786 send urgent pointer 3788 SND.WL1 3789 segment sequence number at last window update 3791 SND.WL2 3792 segment acknowledgment number at last window update 3794 SND.WND 3795 send window 3797 socket 3798 An address which specifically includes a port identifier, 3799 that is, the concatenation of an Internet Address with a TCP 3800 port. 3802 Source Address 3803 The source address, usually the network and host identifiers. 3805 SYN 3806 A control bit in the incoming segment, occupying one sequence 3807 number, used at the initiation of a connection, to indicate 3808 where the sequence numbering will start. 3810 TCB 3811 Transmission control block, the data structure that records 3812 the state of a connection. 3814 TCP 3815 Transmission Control Protocol: A host-to-host protocol for 3816 reliable communication in internetwork environments. 3818 TOS 3819 Type of Service, an IPv4 field, that currently carries the 3820 Differentiated Services field [6] containing the 3821 Differentiated Services Code Point (DSCP) value and two 3822 unused bits. 3824 Type of Service 3825 An Internet Protocol field which indicates the type of 3826 service for this internet fragment. 3828 URG 3829 A control bit (urgent), occupying no sequence space, used to 3830 indicate that the receiving user should be notified to do 3831 urgent processing as long as there is data to be consumed 3832 with sequence numbers less than the value indicated in the 3833 urgent pointer. 3835 urgent pointer 3836 A control field meaningful only when the URG bit is on. This 3837 field communicates the value of the urgent pointer which 3838 indicates the data octet associated with the sending user's 3839 urgent call. 3841 4. Changes from RFC 793 3843 This document obsoletes RFC 793 as well as RFC 6093 and 6528, which 3844 updated 793. In all cases, only the normative protocol specification 3845 and requirements have been incorporated into this document, and the 3846 informational text with background and rationale has not been carried 3847 in. The informational content of those documents is still valuable 3848 in learning about and understanding TCP, and they are valid 3849 Informational references, even though their normative content has 3850 been incorporated into this document. 3852 The main body of this document was adapted from RFC 793's Section 3, 3853 titled "FUNCTIONAL SPECIFICATION", with an attempt to keep formatting 3854 and layout as close as possible. 3856 The collection of applicable RFC Errata that have been reported and 3857 either accepted or held for an update to RFC 793 were incorporated 3858 (Errata IDs: 573, 574, 700, 701, 1283, 1561, 1562, 1564, 1565, 1571, 3859 1572, 2296, 2297, 2298, 2748, 2749, 2934, 3213, 3300, 3301). Some 3860 errata were not applicable due to other changes (Errata IDs: 572, 3861 575, 1569, 3305, 3602). 3863 Changes to the specification of the Urgent Pointer described in RFC 3864 1122 and 6093 were incorporated. See RFC 6093 for detailed 3865 discussion of why these changes were necessary. 3867 The discussion of the RTO from RFC 793 was updated to refer to RFC 3868 6298. The RFC 1122 text on the RTO originally replaced the 793 text, 3869 however, RFC 2988 should have updated 1122, and has subsequently been 3870 obsoleted by 6298. 3872 RFC 1122 contains a collection of other changes and clarifications to 3873 RFC 793. The normative items impacting the protocol have been 3874 incorporated here, though some historically useful implementation 3875 advice and informative discussion from RFC 1122 is not included here. 3877 RFC 1122 contains more than just TCP requirements, so this document 3878 can't obsolete RFC 1122 entirely. It is only marked as "updating" 3879 1122, however, it should be understood to effectively obsolete all of 3880 the RFC 1122 material on TCP. 3882 The more secure Initial Sequence Number generation algorithm from RFC 3883 6528 was incorporated. See RFC 6528 for discussion of the attacks 3884 that this mitigates, as well as advice on selecting PRF algorithms 3885 and managing secret key data. 3887 A note based on RFC 6429 was added to explicitly clarify that system 3888 resource mangement concerns allow connection resources to be 3889 reclaimed. RFC 6429 is obsoleted in the sense that this 3890 clarification has been reflected in this update to the base TCP 3891 specification now. 3893 RFC EDITOR'S NOTE: the content below is for detailed change tracking 3894 and planning, and not to be included with the final revision of the 3895 document. 3897 This document started as draft-eddy-rfc793bis-00, that was merely a 3898 proposal and rough plan for updating RFC 793. 3900 The -01 revision of this draft-eddy-rfc793bis incorporates the 3901 content of RFC 793 Section 3 titled "FUNCTIONAL SPECIFICATION". 3902 Other content from RFC 793 has not been incorporated. The -01 3903 revision of this document makes some minor formatting changes to the 3904 RFC 793 content in order to convert the content into XML2RFC format 3905 and account for left-out parts of RFC 793. For instance, figure 3906 numbering differs and some indentation is not exactly the same. 3908 The -02 revision of draft-eddy-rfc793bis incorporates errata that 3909 have been verified: 3911 Errata ID 573: Reported by Bob Braden (note: This errata basically 3912 is just a reminder that RFC 1122 updates 793. Some of the 3913 associated changes are left pending to a separate revision that 3914 incorporates 1122. Bob's mention of PUSH in 793 section 2.8 was 3915 not applicable here because that section was not part of the 3916 "functional specification". Also the 1122 text on the 3917 retransmission timeout also has been updated by subsequent RFCs, 3918 so the change here deviates from Bob's suggestion to apply the 3919 1122 text.) 3920 Errata ID 574: Reported by Yin Shuming 3921 Errata ID 700: Reported by Yin Shuming 3922 Errata ID 701: Reported by Yin Shuming 3923 Errata ID 1283: Reported by Pei-chun Cheng 3924 Errata ID 1561: Reported by Constantin Hagemeier 3925 Errata ID 1562: Reported by Constantin Hagemeier 3926 Errata ID 1564: Reported by Constantin Hagemeier 3927 Errata ID 1565: Reported by Constantin Hagemeier 3928 Errata ID 1571: Reported by Constantin Hagemeier 3929 Errata ID 1572: Reported by Constantin Hagemeier 3930 Errata ID 2296: Reported by Vishwas Manral 3931 Errata ID 2297: Reported by Vishwas Manral 3932 Errata ID 2298: Reported by Vishwas Manral 3933 Errata ID 2748: Reported by Mykyta Yevstifeyev 3934 Errata ID 2749: Reported by Mykyta Yevstifeyev 3935 Errata ID 2934: Reported by Constantin Hagemeier 3936 Errata ID 3213: Reported by EugnJun Yi 3937 Errata ID 3300: Reported by Botong Huang 3938 Errata ID 3301: Reported by Botong Huang 3939 Errata ID 3305: Reported by Botong Huang 3940 Note: Some verified errata were not used in this update, as they 3941 relate to sections of RFC 793 elided from this document. These 3942 include Errata ID 572, 575, and 1569. 3943 Note: Errata ID 3602 was not applied in this revision as it is 3944 duplicative of the 1122 corrections. 3946 Not related to RFC 793 content, this revision also makes small tweaks 3947 to the introductory text, fixes indentation of the pseudoheader 3948 diagram, and notes that the Security Considerations should also 3949 include privacy, when this section is written. 3951 The -03 revision of draft-eddy-rfc793bis revises all discussion of 3952 the urgent pointer in order to comply with RFC 6093, 1122, and 1011. 3953 Since 1122 held requirements on the urgent pointer, the full list of 3954 requirements was brought into an appendix of this document, so that 3955 it can be updated as-needed. 3957 The -04 revision of draft-eddy-rfc793bis includes the ISN generation 3958 changes from RFC 6528. 3960 The -05 revision of draft-eddy-rfc793bis incorporates MSS 3961 requirements and definitions from RFC 879, 1122, and 6691, as well as 3962 option-handling requirements from RFC 1122. 3964 The -00 revision of draft-ietf-tcpm-rfc793bis incorporates several 3965 additional clarifications and updates to the section on segmentation, 3966 many of which are based on feedback from Joe Touch improving from the 3967 initial text on this in the previous revision. 3969 The -01 revision incorporates the change to Reserved bits due to ECN, 3970 as well as many other changes that come from RFC 1122. 3972 The -02 revision has small formating modifications in order to 3973 address xml2rfc warnings about long lines. It was a quick update to 3974 avoid document expiration. TCPM working group discussion in 2015 3975 also indicated that that we should not try to add sections on 3976 implementation advice or similar non-normative information. 3978 The -03 revision incorporates more content from RFC 1122: Passive 3979 OPEN Calls, Time-To-Live, Multihoming, IP Options, ICMP messages, 3980 Data Communications, When to Send Data, When to Send a Window Update, 3981 Managing the Window, Probing Zero Windows, When to Send an ACK 3982 Segment. The section on data communications was re-organized into 3983 clearer subsections (previously headings were embedded in the 793 3984 text), and windows management advice from 793 was removed (as 3985 reviewed by TCPM working group) in favor of the 1122 additions on 3986 SWS, ZWP, and related topics. 3988 The -04 revision includes reference to RFC 6429 on the ZWP condition, 3989 RFC1122 material on TCP Connection Failures, TCP Keep-Alives, 3990 Acknowledging Queued Segments, and Remote Address Validation. RTO 3991 computation is referenced from RFC 6298 rather than RFC 1122. 3993 The -05 revision includes the requirement to implement TCP congestion 3994 control with recommendation to implemente ECN, the RFC 6633 update to 3995 1122, which changed the requirement on responding to source quench 3996 ICMP messages, and discussion of ICMP (and ICMPv6) soft and hard 3997 errors per RFC 5461 (ICMPv6 handling for TCP doesn't seem to be 3998 mentioned elsewhere in standards track). 4000 The -06 revision includes an appendix on "Other Implementation Notes" 4001 to capture widely-deployed fundamental features that are not 4002 contained in the RFC series yet. It also added mention of RFC 6994 4003 and the IANA TCP parameters registry as a reference. It includes 4004 references to RFC 5961 in appropriate places. The references to TOS 4005 were changed to DiffServ field, based on reflecting RFC 2474 as well 4006 as the IPv6 presence of traffic class (carrying DiffServ field) 4007 rather than TOS. 4009 The -07 revision includes reference to RFC 6191, updated security 4010 considerations, discussion of additional implementation 4011 considerations, and clarification of data on the SYN. 4013 The -08 revision includes changes based on: 4015 describing treatment of reserved bits (following TCPM mailing list 4016 thread from July 2014 on "793bis item - reserved bit behavior" 4017 addition a brief TCP key concepts section to make up for not 4018 including the outdated section 2 of RFC 793 4019 changed "TCP" to "host" to resolve conflict between 1122 wording 4020 on whether TCP or the network layer chooses an address when 4021 multihomed 4022 fixed/updated definition of options in glossary 4023 moved note on aggregating ACKs from 1122 to a more appropriate 4024 location 4025 resolved notes on IP precedence and security/compartment 4026 added implementation note on sequence number validation 4027 added note that PUSH does not apply when Nagle is active 4028 added 1122 content on asynchronous reports to replace 793 section 4029 on TCP to user messages 4031 Some other suggested changes that will not be incorporated in this 4032 793 update unless TCPM consensus changes with regard to scope are: 4034 1. look at Tony Sabatini suggestion for describing DO field 4035 2. per discussion with Joe Touch (TAPS list, 6/20/2015), the 4036 description of the API could be revisited 4038 Early in the process of updating RFC 793, Scott Brim mentioned that 4039 this should include a PERPASS/privacy review. This may be something 4040 for the chairs or AD to request during WGLC or IETF LC. 4042 5. IANA Considerations 4044 This memo includes no request to IANA. Existing IANA registries for 4045 TCP parameters are sufficient. 4047 TODO: check whether entries pointing to 793 and other documents 4048 obsoleted by this one should be updated to point to this one instead. 4050 6. Security and Privacy Considerations 4052 The TCP design includes only rudimentary security features that 4053 improve the robustness and reliability of connections and application 4054 data transfer, but there are no built-in capabilities to support any 4055 form of privacy, authentication, or other typical security functions. 4056 Applications typically utilize lower-layer (e.g. IPsec) and upper- 4057 layer (e.g. TLS) protocols to provide security and privacy for TCP 4058 connections and application data carried in TCP. TCP options are 4059 available as well, to support some security capabilities. 4061 Applications using long-lived TCP flows have been vulnerable to 4062 attacks that exploit the processing of control flags described in 4063 earlier TCP specifications [20]. TCP-MD5 was a commonly implemented 4064 TCP option to support authentication for some of these connections, 4065 but had flaws and is now deprecated. The TCP Authentication Option 4066 (TCP AO) [26] provides a capability to protect long-lived TCP 4067 connections from attacks, and has superior properties to TCP-MD5. It 4068 does not provide any privacy for application data, nor for the TCP 4069 headers. 4071 The "tcpcrypt" [43]Experimental extension to TCP provides the ability 4072 to cryptographically protect connection data. Metadata aspects of 4073 the TCP flow are still visible, but the application stream is well- 4074 protected. Within the TCP header, only the urgent pointer and FIN 4075 flag are protected through tcpcrypt. 4077 The TCP Roadmap [36] includes notes about several RFCs related to TCP 4078 security. Many of the enhancements provided by these RFCs have been 4079 integrated into the present document, including ISN generation, 4080 mitigating blind in-window attacks, and improving handling of soft 4081 errors and ICMP packets. These are all discussed in greater detail 4082 in the referenced RFCs that originally described the changes needed 4083 to earlier TCP specifications. Additionally, see RFC 6093 [28] for 4084 discussion of security considerations related to the urgent pointer 4085 field, that has been deprecated. 4087 Since TCP is often used for bulk transfer flows, some attacks are 4088 possible that abuse the TCP congestion control logic. An example is 4089 "ACK-division" attacks. Updates that have been made to the TCP 4090 congestion control specifications include mechanisms like Appropriate 4091 Byte Counting (ABC) that act as mitigations to these attacks. 4093 Other attacks are focused on exhausting the resources of a TCP 4094 server. Examples include SYN flooding [19] or wasting resources on 4095 non-progressing connections [30]. Operating systems commonly 4096 implement mitigations for these attacks. Some common defenses also 4097 utilize proxies, stateful firewalls, and other technologies outside 4098 of the end-host TCP implementation. 4100 7. Acknowledgements 4102 This document is largely a revision of RFC 793, which Jon Postel was 4103 the editor of. Due to his excellent work, it was able to last for 4104 three decades before we felt the need to revise it. 4106 Andre Oppermann was a contributor and helped to edit the first 4107 revision of this document. 4109 We are thankful for the assistance of the IETF TCPM working group 4110 chairs: 4112 Michael Scharf 4113 Yoshifumi Nishida 4114 Pasi Sarolahti 4116 During early discussion of this work on the TCPM mailing list, and at 4117 the IETF 88 meeting in Vancouver, helpful comments, critiques, and 4118 reviews were received from (listed alphebetically): David Borman, 4119 Yuchung Cheng, Martin Duke, Kevin Lahey, Kevin Mason, Matt Mathis, 4120 Hagen Paul Pfeifer, Anthony Sabatini, Joe Touch, Reji Varghese, Lloyd 4121 Wood, and Alex Zimmermann. Joe Touch provided help in clarifying the 4122 description of segment size parameters and PMTUD/PLPMTUD 4123 recommendations. 4125 This document includes content from errata that were reported by 4126 (listed chronologically): Yin Shuming, Bob Braden, Morris M. Keesan, 4127 Pei-chun Cheng, Constantin Hagemeier, Vishwas Manral, Mykyta 4128 Yevstifeyev, EungJun Yi, Botong Huang. 4130 8. References 4132 8.1. Normative References 4134 [1] Postel, J., "Internet Protocol", STD 5, RFC 791, 4135 DOI 10.17487/RFC0791, September 1981, 4136 . 4138 [2] Mogul, J. and S. Deering, "Path MTU discovery", RFC 1191, 4139 DOI 10.17487/RFC1191, November 1990, 4140 . 4142 [3] McCann, J., Deering, S., and J. Mogul, "Path MTU Discovery 4143 for IP version 6", RFC 1981, DOI 10.17487/RFC1981, August 4144 1996, . 4146 [4] Bradner, S., "Key words for use in RFCs to Indicate 4147 Requirement Levels", BCP 14, RFC 2119, 4148 DOI 10.17487/RFC2119, March 1997, 4149 . 4151 [5] Deering, S. and R. Hinden, "Internet Protocol, Version 6 4152 (IPv6) Specification", RFC 2460, DOI 10.17487/RFC2460, 4153 December 1998, . 4155 [6] Nichols, K., Blake, S., Baker, F., and D. Black, 4156 "Definition of the Differentiated Services Field (DS 4157 Field) in the IPv4 and IPv6 Headers", RFC 2474, 4158 DOI 10.17487/RFC2474, December 1998, 4159 . 4161 [7] Borman, D., Deering, S., and R. Hinden, "IPv6 Jumbograms", 4162 RFC 2675, DOI 10.17487/RFC2675, August 1999, 4163 . 4165 [8] Lahey, K., "TCP Problems with Path MTU Discovery", 4166 RFC 2923, DOI 10.17487/RFC2923, September 2000, 4167 . 4169 [9] Ramakrishnan, K., Floyd, S., and D. Black, "The Addition 4170 of Explicit Congestion Notification (ECN) to IP", 4171 RFC 3168, DOI 10.17487/RFC3168, September 2001, 4172 . 4174 [10] Paxson, V., Allman, M., Chu, J., and M. Sargent, 4175 "Computing TCP's Retransmission Timer", RFC 6298, 4176 DOI 10.17487/RFC6298, June 2011, 4177 . 4179 [11] Gont, F., "Deprecation of ICMP Source Quench Messages", 4180 RFC 6633, DOI 10.17487/RFC6633, May 2012, 4181 . 4183 8.2. Informative References 4185 [12] Postel, J., "Transmission Control Protocol", STD 7, 4186 RFC 793, DOI 10.17487/RFC0793, September 1981, 4187 . 4189 [13] Nagle, J., "Congestion Control in IP/TCP Internetworks", 4190 RFC 896, DOI 10.17487/RFC0896, January 1984, 4191 . 4193 [14] Braden, R., Ed., "Requirements for Internet Hosts - 4194 Communication Layers", STD 3, RFC 1122, 4195 DOI 10.17487/RFC1122, October 1989, 4196 . 4198 [15] Almquist, P., "Type of Service in the Internet Protocol 4199 Suite", RFC 1349, DOI 10.17487/RFC1349, July 1992, 4200 . 4202 [16] Braden, R., "T/TCP -- TCP Extensions for Transactions 4203 Functional Specification", RFC 1644, DOI 10.17487/RFC1644, 4204 July 1994, . 4206 [17] Xiao, X., Hannan, A., Paxson, V., and E. Crabbe, "TCP 4207 Processing of the IPv4 Precedence Field", RFC 2873, 4208 DOI 10.17487/RFC2873, June 2000, 4209 . 4211 [18] Mathis, M. and J. Heffner, "Packetization Layer Path MTU 4212 Discovery", RFC 4821, DOI 10.17487/RFC4821, March 2007, 4213 . 4215 [19] Eddy, W., "TCP SYN Flooding Attacks and Common 4216 Mitigations", RFC 4987, DOI 10.17487/RFC4987, August 2007, 4217 . 4219 [20] Touch, J., "Defending TCP Against Spoofing Attacks", 4220 RFC 4953, DOI 10.17487/RFC4953, July 2007, 4221 . 4223 [21] Culley, P., Elzur, U., Recio, R., Bailey, S., and J. 4224 Carrier, "Marker PDU Aligned Framing for TCP 4225 Specification", RFC 5044, DOI 10.17487/RFC5044, October 4226 2007, . 4228 [22] Gont, F., "TCP's Reaction to Soft Errors", RFC 5461, 4229 DOI 10.17487/RFC5461, February 2009, 4230 . 4232 [23] StJohns, M., Atkinson, R., and G. Thomas, "Common 4233 Architecture Label IPv6 Security Option (CALIPSO)", 4234 RFC 5570, DOI 10.17487/RFC5570, July 2009, 4235 . 4237 [24] Allman, M., Paxson, V., and E. Blanton, "TCP Congestion 4238 Control", RFC 5681, DOI 10.17487/RFC5681, September 2009, 4239 . 4241 [25] Sandlund, K., Pelletier, G., and L-E. Jonsson, "The RObust 4242 Header Compression (ROHC) Framework", RFC 5795, 4243 DOI 10.17487/RFC5795, March 2010, 4244 . 4246 [26] Touch, J., Mankin, A., and R. Bonica, "The TCP 4247 Authentication Option", RFC 5925, DOI 10.17487/RFC5925, 4248 June 2010, . 4250 [27] Ramaiah, A., Stewart, R., and M. Dalal, "Improving TCP's 4251 Robustness to Blind In-Window Attacks", RFC 5961, 4252 DOI 10.17487/RFC5961, August 2010, 4253 . 4255 [28] Gont, F. and A. Yourtchenko, "On the Implementation of the 4256 TCP Urgent Mechanism", RFC 6093, DOI 10.17487/RFC6093, 4257 January 2011, . 4259 [29] Gont, F., "Reducing the TIME-WAIT State Using TCP 4260 Timestamps", BCP 159, RFC 6191, DOI 10.17487/RFC6191, 4261 April 2011, . 4263 [30] Bashyam, M., Jethanandani, M., and A. Ramaiah, "TCP Sender 4264 Clarification for Persist Condition", RFC 6429, 4265 DOI 10.17487/RFC6429, December 2011, 4266 . 4268 [31] Gont, F. and S. Bellovin, "Defending against Sequence 4269 Number Attacks", RFC 6528, DOI 10.17487/RFC6528, February 4270 2012, . 4272 [32] Borman, D., "TCP Options and Maximum Segment Size (MSS)", 4273 RFC 6691, DOI 10.17487/RFC6691, July 2012, 4274 . 4276 [33] Touch, J., "Shared Use of Experimental TCP Options", 4277 RFC 6994, DOI 10.17487/RFC6994, August 2013, 4278 . 4280 [34] Borman, D., Braden, B., Jacobson, V., and R. 4281 Scheffenegger, Ed., "TCP Extensions for High Performance", 4282 RFC 7323, DOI 10.17487/RFC7323, September 2014, 4283 . 4285 [35] Cheng, Y., Chu, J., Radhakrishnan, S., and A. Jain, "TCP 4286 Fast Open", RFC 7413, DOI 10.17487/RFC7413, December 2014, 4287 . 4289 [36] Duke, M., Braden, R., Eddy, W., Blanton, E., and A. 4290 Zimmermann, "A Roadmap for Transmission Control Protocol 4291 (TCP) Specification Documents", RFC 7414, 4292 DOI 10.17487/RFC7414, February 2015, 4293 . 4295 [37] Black, D., Ed. and P. Jones, "Differentiated Services 4296 (Diffserv) and Real-Time Communication", RFC 7657, 4297 DOI 10.17487/RFC7657, November 2015, 4298 . 4300 [38] Fairhurst, G. and M. Welzl, "The Benefits of Using 4301 Explicit Congestion Notification (ECN)", RFC 8087, 4302 DOI 10.17487/RFC8087, March 2017, 4303 . 4305 [39] Fairhurst, G., Ed., Trammell, B., Ed., and M. Kuehlewind, 4306 Ed., "Services Provided by IETF Transport Protocols and 4307 Congestion Control Mechanisms", RFC 8095, 4308 DOI 10.17487/RFC8095, March 2017, 4309 . 4311 [40] IANA, "Transmission Control Protocol (TCP) Parameters, 4312 https://www.iana.org/assignments/tcp-parameters/ 4313 tcp-parameters.xhtml", 2017. 4315 [41] Gont, F., "Processing of IP Security/Compartment and 4316 Precedence Information by TCP", draft-gont-tcpm-tcp- 4317 seccomp-prec-00 (work in progress), March 2012. 4319 [42] Gont, F. and D. Borman, "On the Validation of TCP Sequence 4320 Numbers", draft-gont-tcpm-tcp-seq-validation-02 (work in 4321 progress), March 2015. 4323 [43] Bittau, A., Giffin, D., Handley, M., Mazieres, D., Slack, 4324 Q., and E. Smith, "Cryptographic protection of TCP Streams 4325 (tcpcrypt)", draft-ietf-tcpinc-tcpcrypt-09 (work in 4326 progress), November 2017. 4328 [44] Minshall, G., "A Proposed Modification to Nagle's 4329 Algorithm", draft-minshall-nagle-01 (work in progress), 4330 June 1999. 4332 Appendix A. Other Implementation Notes 4334 This section includes additional notes and references on TCP 4335 implementation decisions that are currently not a part of the RFC 4336 series or included within the TCP standard. These items can be 4337 considered by implementers, but there was not yet a consensus to 4338 include them in the standard. 4340 A.1. IP Security Compartment and Precedence 4342 RFC 793 requires checking the IP security compartment and precedence 4343 on incoming TCP segments for consistency within a connection, and 4344 with application requests. Each of these aspects of IP have become 4345 outdated, without specific updates to RFC 793. The issues with 4346 precedence were fixed by [17] which is Standards Track, and so this 4347 present TCP specification includes those changes. However, the state 4348 of IP security options that may be used by MLS systems is not as 4349 clean. 4351 Implementers of MLS systems that use IP security options (e.g. IPSO, 4352 CIPSO, or CALIPSO) should implement any additional logic appropriate 4353 for their requirements. 4355 Reseting connections when incoming packets do not meet expected 4356 security compartment or precedence expectations has been recognized 4357 as a possible attack vector [41], and there has been discussion about 4358 ammending the TCP specification to prevent connections from being 4359 aborted due to non-matching IP security compartment and DiffServ 4360 codepoint values. 4362 A.2. Sequence Number Validation 4364 There are cases where the TCP sequence number validation rules can 4365 prevent ACK fields from being processed. This can result in 4366 connection issues, as described in [42], which includes descriptions 4367 of potential problems in conditions of simultaneous open, self- 4368 connects, simultaneous close, and simultaneous window probes. The 4369 document also describes potential changes to the TCP specification to 4370 mitigate the issue by expanding the acceptable sequence numbers. 4372 In Internet usage of TCP, these conditions are rarely occuring. 4373 Common operating systems include different alternative mitigations, 4374 and the standard has not been updated yet to codify one of them, but 4375 implementers should consider the problems described in [42]. 4377 A.3. Nagle Modification 4379 In common operating systems, both the Nagle algorithm and delayed 4380 acknowledgements are implemented and enabled by default. TCP is used 4381 by many applications that have a request-response style of 4382 communication, where the combination of the Nagle algorithm and 4383 delayed acknowledgements can result in poor application performance. 4384 A modification to the Nagle algorithm is described in [44] that 4385 improves the situation for these applications. 4387 This modification is implemented in some common operating systems, 4388 and does not impact TCP interoperability. Additionally, many 4389 applications simply disable Nagle, since this is generally supported 4390 by a socket option. The TCP standard has not been updated to include 4391 this Nagle modification, but implementers may find it beneficial to 4392 consider. 4394 A.4. Low Water Mark 4396 TODO - mention the low watermark function that is in Linux - 4397 suggested by Michael Welzl 4399 SO_SNDLOWAT and SO_RCVLOWAT would be potential enhancements to the 4400 abstract TCP API 4402 TCP_NOTSENT_LOWAT is what Michael is talking about, that helps a 4403 sending TCP application to help avoid creating large amounts of 4404 buffered data (and corresponding latency). This is useful for 4405 applications that are multiplexing data from multiple upper level 4406 streams onto a connection, especially when streams may be a mix of 4407 interactive/realtime and bulk data transfer. 4409 Appendix B. TCP Requirement Summary 4411 This section is adapted from RFC 1122. 4413 TODO: this needs to be seriously redone, to use 793bis section 4414 numbers instead of 1122 ones, the RFC1122 heading should be removed, 4415 and all 1122 requirements need to be reflected in 793bis text. 4417 TODO: NOTE that PMTUD+PLPMTUD is not included in this table of 4418 recommendations. 4420 | | | | |S| | 4421 | | | | |H| |F 4422 | | | | |O|M|o 4423 | | |S| |U|U|o 4424 | | |H| |L|S|t 4425 | |M|O| |D|T|n 4426 | |U|U|M| | |o 4427 | |S|L|A|N|N|t 4428 |RFC1122 |T|D|Y|O|O|t 4429 FEATURE |SECTION | | | |T|T|e 4430 -------------------------------------------------|--------|-|-|-|-|-|-- 4431 | | | | | | | 4432 Push flag | | | | | | | 4433 Aggregate or queue un-pushed data |4.2.2.2 | | |x| | | 4434 Sender collapse successive PSH flags |4.2.2.2 | |x| | | | 4435 SEND call can specify PUSH |4.2.2.2 | | |x| | | 4436 If cannot: sender buffer indefinitely |4.2.2.2 | | | | |x| 4437 If cannot: PSH last segment |4.2.2.2 |x| | | | | 4438 Notify receiving ALP of PSH |4.2.2.2 | | |x| | |1 4439 Send max size segment when possible |4.2.2.2 | |x| | | | 4440 | | | | | | | 4441 Window | | | | | | | 4442 Treat as unsigned number |4.2.2.3 |x| | | | | 4443 Handle as 32-bit number |4.2.2.3 | |x| | | | 4444 Shrink window from right |4.2.2.16| | | |x| | 4445 Robust against shrinking window |4.2.2.16|x| | | | | 4446 Receiver's window closed indefinitely |4.2.2.17| | |x| | | 4447 Sender probe zero window |4.2.2.17|x| | | | | 4448 First probe after RTO |4.2.2.17| |x| | | | 4449 Exponential backoff |4.2.2.17| |x| | | | 4450 Allow window stay zero indefinitely |4.2.2.17|x| | | | | 4451 Sender timeout OK conn with zero wind |4.2.2.17| | | | |x| 4452 | | | | | | | 4453 Urgent Data | | | | | | | 4454 Pointer indicates first non-urgent octet |4.2.2.4 |x| | | | | 4455 Arbitrary length urgent data sequence |4.2.2.4 |x| | | | | 4456 Inform ALP asynchronously of urgent data |4.2.2.4 |x| | | | |1 4457 ALP can learn if/how much urgent data Q'd |4.2.2.4 |x| | | | |1 4458 | | | | | | | 4459 TCP Options | | | | | | | 4460 Receive TCP option in any segment |4.2.2.5 |x| | | | | 4461 Ignore unsupported options |4.2.2.5 |x| | | | | 4462 Cope with illegal option length |4.2.2.5 |x| | | | | 4463 Implement sending & receiving MSS option |4.2.2.6 |x| | | | | 4464 IPv4 Send MSS option unless 536 |4.2.2.6 | |x| | | | 4465 IPv6 Send MSS option unless 1220 | N/A | |x| | | | 4466 Send MSS option always |4.2.2.6 | | |x| | | 4467 IPv4 Send-MSS default is 536 |4.2.2.6 |x| | | | | 4468 IPv6 Send-MSS default is 1220 | N/A |x| | | | | 4469 Calculate effective send seg size |4.2.2.6 |x| | | | | 4470 MSS accounts for varying MTU | N/A | |x| | | | 4471 | | | | | | | 4473 TCP Checksums | | | | | | | 4474 Sender compute checksum |4.2.2.7 |x| | | | | 4475 Receiver check checksum |4.2.2.7 |x| | | | | 4476 | | | | | | | 4477 ISN Selection | | | | | | | 4478 Include a clock-driven ISN generator component |4.2.2.9 |x| | | | | 4479 Secure ISN generator with a PRF component | N/A | |x| | | | 4480 | | | | | | | 4481 Opening Connections | | | | | | | 4482 Support simultaneous open attempts |4.2.2.10|x| | | | | 4483 SYN-RECEIVED remembers last state |4.2.2.11|x| | | | | 4484 Passive Open call interfere with others |4.2.2.18| | | | |x| 4485 Function: simultan. LISTENs for same port |4.2.2.18|x| | | | | 4486 Ask IP for src address for SYN if necc. |4.2.3.7 |x| | | | | 4487 Otherwise, use local addr of conn. |4.2.3.7 |x| | | | | 4488 OPEN to broadcast/multicast IP Address |4.2.3.14| | | | |x| 4489 Silently discard seg to bcast/mcast addr |4.2.3.14|x| | | | | 4490 | | | | | | | 4491 Closing Connections | | | | | | | 4492 RST can contain data |4.2.2.12| |x| | | | 4493 Inform application of aborted conn |4.2.2.13|x| | | | | 4494 Half-duplex close connections |4.2.2.13| | |x| | | 4495 Send RST to indicate data lost |4.2.2.13| |x| | | | 4496 In TIME-WAIT state for 2MSL seconds |4.2.2.13|x| | | | | 4497 Accept SYN from TIME-WAIT state |4.2.2.13| | |x| | | 4498 Use Timestamps to reduce TIME-WAIT | TODO | | | | | | 4499 | | | | | | | 4500 Retransmissions | | | | | | | 4501 Jacobson Slow Start algorithm |4.2.2.15|x| | | | | 4502 Jacobson Congestion-Avoidance algorithm |4.2.2.15|x| | | | | 4503 Retransmit with same IP ident |4.2.2.15| | |x| | | 4504 Karn's algorithm |4.2.3.1 |x| | | | | 4505 Jacobson's RTO estimation alg. |4.2.3.1 |x| | | | | 4506 Exponential backoff |4.2.3.1 |x| | | | | 4507 SYN RTO calc same as data |4.2.3.1 | |x| | | | 4508 Recommended initial values and bounds |4.2.3.1 | |x| | | | 4509 | | | | | | | 4510 Generating ACK's: | | | | | | | 4511 Queue out-of-order segments |4.2.2.20| |x| | | | 4512 Process all Q'd before send ACK |4.2.2.20|x| | | | | 4513 Send ACK for out-of-order segment |4.2.2.21| | |x| | | 4514 Delayed ACK's |4.2.3.2 | |x| | | | 4515 Delay < 0.5 seconds |4.2.3.2 |x| | | | | 4516 Every 2nd full-sized segment ACK'd |4.2.3.2 |x| | | | | 4517 Receiver SWS-Avoidance Algorithm |4.2.3.3 |x| | | | | 4518 | | | | | | | 4519 Sending data | | | | | | | 4520 Configurable TTL |4.2.2.19|x| | | | | 4521 Sender SWS-Avoidance Algorithm |4.2.3.4 |x| | | | | 4522 Nagle algorithm |4.2.3.4 | |x| | | | 4523 Application can disable Nagle algorithm |4.2.3.4 |x| | | | | 4524 | | | | | | | 4525 Connection Failures: | | | | | | | 4526 Negative advice to IP on R1 retxs |4.2.3.5 |x| | | | | 4527 Close connection on R2 retxs |4.2.3.5 |x| | | | | 4528 ALP can set R2 |4.2.3.5 |x| | | | |1 4529 Inform ALP of R1<=retxs inform ALP |4.2.3.9 | |x| | | | 4554 Dest. Unreach (0,1,5) => abort conn |4.2.3.9 | | | | |x| 4555 Dest. Unreach (2-4) => abort conn |4.2.3.9 | |x| | | | 4556 Source Quench => silent discard |4.2.3.9 | |x| | | | 4557 Time Exceeded => tell ALP, don't abort |4.2.3.9 | |x| | | | 4558 Param Problem => tell ALP, don't abort |4.2.3.9 | |x| | | | 4559 | | | | | | | 4560 Address Validation | | | | | | | 4561 Reject OPEN call to invalid IP address |4.2.3.10|x| | | | | 4562 Reject SYN from invalid IP address |4.2.3.10|x| | | | | 4563 Silently discard SYN to bcast/mcast addr |4.2.3.10|x| | | | | 4564 | | | | | | | 4565 TCP/ALP Interface Services | | | | | | | 4566 Error Report mechanism |4.2.4.1 |x| | | | | 4567 ALP can disable Error Report Routine |4.2.4.1 | |x| | | | 4568 ALP can specify DiffServ field for sending |4.2.4.2 |x| | | | | 4569 Passed unchanged to IP |4.2.4.2 | |x| | | | 4570 ALP can change DiffServ field during connection|4.2.4.2 | |x| | | | 4571 Pass received DiffServ field up to ALP |4.2.4.2 | | |x| | | 4572 FLUSH call |4.2.4.3 | | |x| | | 4573 Optional local IP addr parm. in OPEN |4.2.4.4 |x| | | | | 4574 -------------------------------------------------|--------|-|-|-|-|-|-- 4576 FOOTNOTES: (1) "ALP" means Application-Layer program. 4578 Author's Address 4580 Wesley M. Eddy (editor) 4581 MTI Systems 4582 US 4584 Email: wes@mti-systems.com