idnits 2.17.1 draft-ietf-tcpm-rfc793bis-07.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 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. -- The draft header indicates that this document obsoletes RFC6528, 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 (November 12, 2017) is 2349 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: '38' is defined on line 4312, 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 1644 (ref. '15') (Obsoleted by RFC 6247) -- Obsolete informational reference (is this intentional?): RFC 6093 (ref. '25') (Obsoleted by RFC 9293) -- Obsolete informational reference (is this intentional?): RFC 6429 (ref. '27') (Obsoleted by RFC 9293) -- Obsolete informational reference (is this intentional?): RFC 6528 (ref. '28') (Obsoleted by RFC 9293) -- Obsolete informational reference (is this intentional?): RFC 6691 (ref. '29') (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 (==), 13 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, 6093, 6429, 6528, November 12, 2017 5 6691 (if approved) 6 Updates: 5961, 1122 (if approved) 7 Intended status: Standards Track 8 Expires: May 16, 2018 10 Transmission Control Protocol Specification 11 draft-ietf-tcpm-rfc793bis-07 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, 6093, 6429, 6528, 23 and 6691. It updates RFC 1122, and should be considered as a 24 replacement for the portions of that document dealing with TCP 25 requirements. It updates RFC 5961 due to a small clarification in 26 reset handling while in the SYN-RECEIVED state. (TODO: double-check 27 this list for all actual RFCs when finished) 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 May 16, 2018. 55 Copyright Notice 57 Copyright (c) 2017 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 3. Functional Specification . . . . . . . . . . . . . . . . . . 5 87 3.1. Header Format . . . . . . . . . . . . . . . . . . . . . . 5 88 3.2. Terminology . . . . . . . . . . . . . . . . . . . . . . . 10 89 3.3. Sequence Numbers . . . . . . . . . . . . . . . . . . . . 15 90 3.4. Establishing a connection . . . . . . . . . . . . . . . . 21 91 3.4.1. Remote Address Validation . . . . . . . . . . . . . . 28 92 3.5. Closing a Connection . . . . . . . . . . . . . . . . . . 28 93 3.5.1. Half-Closed Connections . . . . . . . . . . . . . . . 31 94 3.6. Precedence and Security . . . . . . . . . . . . . . . . . 31 95 3.7. Segmentation . . . . . . . . . . . . . . . . . . . . . . 32 96 3.7.1. Maximum Segment Size Option . . . . . . . . . . . . . 33 97 3.7.2. Path MTU Discovery . . . . . . . . . . . . . . . . . 35 98 3.7.3. Interfaces with Variable MTU Values . . . . . . . . . 35 99 3.7.4. Nagle Algorithm . . . . . . . . . . . . . . . . . . . 36 100 3.7.5. IPv6 Jumbograms . . . . . . . . . . . . . . . . . . . 36 101 3.8. Data Communication . . . . . . . . . . . . . . . . . . . 36 102 3.8.1. Retransmission Timeout . . . . . . . . . . . . . . . 37 103 3.8.2. TCP Congestion Control . . . . . . . . . . . . . . . 37 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 . . . . . . . 39 107 3.8.6. Managing the Window . . . . . . . . . . . . . . . . . 40 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 . . . . . . . . . . . . . . . . . . . . 55 112 3.11. Glossary . . . . . . . . . . . . . . . . . . . . . . . . 81 113 4. Changes from RFC 793 . . . . . . . . . . . . . . . . . . . . 87 114 5. IANA Considerations . . . . . . . . . . . . . . . . . . . . . 90 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 . . . . . . . . . . . . . 96 121 A.1. IP Security Compartment and Precedence . . . . . . . . . 96 122 A.2. Sequence Number Validation . . . . . . . . . . . . . . . 97 123 A.3. Nagle Modification . . . . . . . . . . . . . . . . . . . 97 124 A.4. Low Water Mark . . . . . . . . . . . . . . . . . . . . . 97 125 Appendix B. TCP Requirement Summary . . . . . . . . . . . . . . 98 126 Author's Address . . . . . . . . . . . . . . . . . . . . . . . . 101 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 [33]. 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" [33] 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. [21]) 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 [31], 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 3. Functional Specification 214 3.1. Header Format 216 TCP segments are sent as internet datagrams. The Internet Protocol 217 (IP) header carries several information fields, including the source 218 and destination host addresses [1] [5]. A TCP header follows the 219 internet header, supplying information specific to the TCP protocol. 220 This division allows for the existence of host level protocols other 221 than TCP. (Editorial TODO - this last sentence makes sense in 793 222 context, but may be a candidate to remove here? ... additionally, 223 Section 2 of 793 is not includeed here, but some parts may be useful, 224 to quickly define basic concepts of ports, bytestream service, etc. 225 at high-level before delving into protocol details?) 227 TCP Header Format 228 0 1 2 3 229 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 230 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 231 | Source Port | Destination Port | 232 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 233 | Sequence Number | 234 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 235 | Acknowledgment Number | 236 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 237 | Data | |C|E|U|A|P|R|S|F| | 238 | Offset| Rsrvd |W|C|R|C|S|S|Y|I| Window | 239 | | |R|E|G|K|H|T|N|N| | 240 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 241 | Checksum | Urgent Pointer | 242 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 243 | Options | Padding | 244 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 245 | data | 246 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 248 TCP Header Format 250 Note that one tick mark represents one bit position. 252 Figure 1 254 Source Port: 16 bits 256 The source port number. 258 Destination Port: 16 bits 260 The destination port number. 262 Sequence Number: 32 bits 264 The sequence number of the first data octet in this segment (except 265 when SYN is present). If SYN is present the sequence number is the 266 initial sequence number (ISN) and the first data octet is ISN+1. 268 Acknowledgment Number: 32 bits 270 If the ACK control bit is set this field contains the value of the 271 next sequence number the sender of the segment is expecting to 272 receive. Once a connection is established this is always sent. 274 Data Offset: 4 bits 275 The number of 32 bit words in the TCP Header. This indicates where 276 the data begins. The TCP header (even one including options) is an 277 integral number of 32 bits long. 279 Rsrvd - Reserved: 4 bits 281 Reserved for future use. Must be zero in generated segments and 282 must be ignored in received segments. TODO -- no RFC reference for 283 this sentence ... do we want this change or should we keep the 284 prior 793 description which is only "Must be zero." ... need to 285 discuss on TCPM list 287 Control Bits: 8 bits (from left to right): 289 CWR: Congestion Window Reduced (see [9]) 290 ECE: ECN-Echo (see [9]) 291 URG: Urgent Pointer field significant 292 ACK: Acknowledgment field significant 293 PSH: Push Function 294 RST: Reset the connection 295 SYN: Synchronize sequence numbers 296 FIN: No more data from sender 298 Window: 16 bits 300 The number of data octets beginning with the one indicated in the 301 acknowledgment field which the sender of this segment is willing to 302 accept. 304 The window size MUST be treated as an unsigned number, or else 305 large window sizes will appear like negative windows and TCP will 306 now work. It is RECOMMENDED that implementations will reserve 307 32-bit fields for the send and receive window sizes in the 308 connection record and do all window computations with 32 bits. 310 Checksum: 16 bits 312 The checksum field is the 16 bit one's complement of the one's 313 complement sum of all 16 bit words in the header and text. If a 314 segment contains an odd number of header and text octets to be 315 checksummed, the last octet is padded on the right with zeros to 316 form a 16 bit word for checksum purposes. The pad is not 317 transmitted as part of the segment. While computing the checksum, 318 the checksum field itself is replaced with zeros. 320 The checksum also covers a pseudo header conceptually prefixed to 321 the TCP header. The pseudo header is 96 bits for IPv4 and 320 bits 322 for IPv6. For IPv4, this pseudo header contains the Source 323 Address, the Destination Address, the Protocol, and TCP length. 324 This gives the TCP protection against misrouted segments. This 325 information is carried in IPv4 and is transferred across the TCP/ 326 Network interface in the arguments or results of calls by the TCP 327 on the IP. 329 +--------+--------+--------+--------+ 330 | Source Address | 331 +--------+--------+--------+--------+ 332 | Destination Address | 333 +--------+--------+--------+--------+ 334 | zero | PTCL | TCP Length | 335 +--------+--------+--------+--------+ 337 The TCP Length is the TCP header length plus the data length in 338 octets (this is not an explicitly transmitted quantity, but is 339 computed), and it does not count the 12 octets of the pseudo 340 header. 342 For IPv6, the pseudo header is contained in section 8.1 of RFC 2460 343 [5], and contains the IPv6 Source Address and Destination Address, 344 an Upper Layer Packet Length (a 32-bit value otherwise equivalent 345 to TCP Length in the IPv4 pseudo header), three bytes of zero- 346 padding, and a Next Header value (differing from the IPv6 header 347 value in the case of extension headers present in between IPv6 and 348 TCP). 350 The TCP checksum is never optional. The sender MUST generate it 351 and the receiver MUST check it. 353 Urgent Pointer: 16 bits 355 This field communicates the current value of the urgent pointer as 356 a positive offset from the sequence number in this segment. The 357 urgent pointer points to the sequence number of the octet following 358 the urgent data. This field is only be interpreted in segments 359 with the URG control bit set. 361 Options: variable 363 Options may occupy space at the end of the TCP header and are a 364 multiple of 8 bits in length. All options are included in the 365 checksum. An option may begin on any octet boundary. There are 366 two cases for the format of an option: 368 Case 1: A single octet of option-kind. 370 Case 2: An octet of option-kind, an octet of option-length, and 371 the actual option-data octets. 373 The option-length counts the two octets of option-kind and option- 374 length as well as the option-data octets. 376 Note that the list of options may be shorter than the data offset 377 field might imply. The content of the header beyond the End-of- 378 Option option must be header padding (i.e., zero). 380 The list of all currently defined options is managed by IANA [35], 381 and each option is defined in other RFCs, as indicated there. That 382 set includes experimental options that can be extended to support 383 multiple concurrent uses [30]. 385 A given TCP implementation can support any currently defined 386 options, but the following options MUST be supported (kind 387 indicated in octal): 389 Kind Length Meaning 390 ---- ------ ------- 391 0 - End of option list. 392 1 - No-Operation. 393 2 4 Maximum Segment Size. 395 A TCP MUST be able to receive a TCP option in any segment. 396 A TCP MUST ignore without error any TCP option it does not 397 implement, assuming that the option has a length field (all TCP 398 options except End of option list and No-Operation have length 399 fields). TCP MUST be prepared to handle an illegal option length 400 (e.g., zero) without crashing; a suggested procedure is to reset 401 the connection and log the reason. 403 Specific Option Definitions 405 End of Option List 407 +--------+ 408 |00000000| 409 +--------+ 410 Kind=0 412 This option code indicates the end of the option list. This 413 might not coincide with the end of the TCP header according to 414 the Data Offset field. This is used at the end of all options, 415 not the end of each option, and need only be used if the end of 416 the options would not otherwise coincide with the end of the TCP 417 header. 419 No-Operation 421 +--------+ 422 |00000001| 423 +--------+ 424 Kind=1 426 This option code may be used between options, for example, to 427 align the beginning of a subsequent option on a word boundary. 428 There is no guarantee that senders will use this option, so 429 receivers must be prepared to process options even if they do 430 not begin on a word boundary. 432 Maximum Segment Size (MSS) 434 +--------+--------+---------+--------+ 435 |00000010|00000100| max seg size | 436 +--------+--------+---------+--------+ 437 Kind=2 Length=4 439 Maximum Segment Size Option Data: 16 bits 441 If this option is present, then it communicates the maximum 442 receive segment size at the TCP which sends this segment. This 443 value is limited by the IP reassembly limit. This field may be 444 sent in the initial connection request (i.e., in segments with 445 the SYN control bit set) and must not be sent in other segments. 446 If this option is not used, any segment size is allowed. A more 447 complete description of this option is in Section 3.7.1. 449 Padding: variable 451 The TCP header padding is used to ensure that the TCP header ends 452 and data begins on a 32 bit boundary. The padding is composed of 453 zeros. 455 3.2. Terminology 457 Before we can discuss very much about the operation of the TCP we 458 need to introduce some detailed terminology. The maintenance of a 459 TCP connection requires the remembering of several variables. We 460 conceive of these variables being stored in a connection record 461 called a Transmission Control Block or TCB. Among the variables 462 stored in the TCB are the local and remote socket numbers, the 463 security and precedence of the connection, pointers to the user's 464 send and receive buffers, pointers to the retransmit queue and to the 465 current segment. In addition several variables relating to the send 466 and receive sequence numbers are stored in the TCB. 468 Send Sequence Variables 470 SND.UNA - send unacknowledged 471 SND.NXT - send next 472 SND.WND - send window 473 SND.UP - send urgent pointer 474 SND.WL1 - segment sequence number used for last window update 475 SND.WL2 - segment acknowledgment number used for last window 476 update 477 ISS - initial send sequence number 479 Receive Sequence Variables 481 RCV.NXT - receive next 482 RCV.WND - receive window 483 RCV.UP - receive urgent pointer 484 IRS - initial receive sequence number 486 The following diagrams may help to relate some of these variables to 487 the sequence space. 489 Send Sequence Space 491 1 2 3 4 492 ----------|----------|----------|---------- 493 SND.UNA SND.NXT SND.UNA 494 +SND.WND 496 1 - old sequence numbers which have been acknowledged 497 2 - sequence numbers of unacknowledged data 498 3 - sequence numbers allowed for new data transmission 499 4 - future sequence numbers which are not yet allowed 501 Send Sequence Space 503 Figure 2 505 The send window is the portion of the sequence space labeled 3 in 506 Figure 2. 508 Receive Sequence Space 510 1 2 3 511 ----------|----------|---------- 512 RCV.NXT RCV.NXT 513 +RCV.WND 515 1 - old sequence numbers which have been acknowledged 516 2 - sequence numbers allowed for new reception 517 3 - future sequence numbers which are not yet allowed 519 Receive Sequence Space 521 Figure 3 523 The receive window is the portion of the sequence space labeled 2 in 524 Figure 3. 526 There are also some variables used frequently in the discussion that 527 take their values from the fields of the current segment. 529 Current Segment Variables 531 SEG.SEQ - segment sequence number 532 SEG.ACK - segment acknowledgment number 533 SEG.LEN - segment length 534 SEG.WND - segment window 535 SEG.UP - segment urgent pointer 536 SEG.PRC - segment precedence value 538 A connection progresses through a series of states during its 539 lifetime. The states are: LISTEN, SYN-SENT, SYN-RECEIVED, 540 ESTABLISHED, FIN-WAIT-1, FIN-WAIT-2, CLOSE-WAIT, CLOSING, LAST-ACK, 541 TIME-WAIT, and the fictional state CLOSED. CLOSED is fictional 542 because it represents the state when there is no TCB, and therefore, 543 no connection. Briefly the meanings of the states are: 545 LISTEN - represents waiting for a connection request from any 546 remote TCP and port. 548 SYN-SENT - represents waiting for a matching connection request 549 after having sent a connection request. 551 SYN-RECEIVED - represents waiting for a confirming connection 552 request acknowledgment after having both received and sent a 553 connection request. 555 ESTABLISHED - represents an open connection, data received can be 556 delivered to the user. The normal state for the data transfer 557 phase of the connection. 559 FIN-WAIT-1 - represents waiting for a connection termination 560 request from the remote TCP, or an acknowledgment of the 561 connection termination request previously sent. 563 FIN-WAIT-2 - represents waiting for a connection termination 564 request from the remote TCP. 566 CLOSE-WAIT - represents waiting for a connection termination 567 request from the local user. 569 CLOSING - represents waiting for a connection termination request 570 acknowledgment from the remote TCP. 572 LAST-ACK - represents waiting for an acknowledgment of the 573 connection termination request previously sent to the remote TCP 574 (this termination request sent to the remote TCP already included 575 an acknowledgment of the termination request sent from the remote 576 TCP). 578 TIME-WAIT - represents waiting for enough time to pass to be sure 579 the remote TCP received the acknowledgment of its connection 580 termination request. 582 CLOSED - represents no connection state at all. 584 A TCP connection progresses from one state to another in response to 585 events. The events are the user calls, OPEN, SEND, RECEIVE, CLOSE, 586 ABORT, and STATUS; the incoming segments, particularly those 587 containing the SYN, ACK, RST and FIN flags; and timeouts. 589 The state diagram in Figure 4 illustrates only state changes, 590 together with the causing events and resulting actions, but addresses 591 neither error conditions nor actions which are not connected with 592 state changes. In a later section, more detail is offered with 593 respect to the reaction of the TCP to events. Some state names are 594 abbreviated or hyphenated differently in the diagram from how they 595 appear elsewhere in the document. 597 NOTA BENE: This diagram is only a summary and must not be taken as 598 the total specification. Many details are not included. 600 +---------+ ---------\ active OPEN 601 | CLOSED | \ ----------- 602 +---------+<---------\ \ create TCB 603 | ^ \ \ snd SYN 604 passive OPEN | | CLOSE \ \ 605 ------------ | | ---------- \ \ 606 create TCB | | delete TCB \ \ 607 V | \ \ 608 rcv RST (note 1) +---------+ CLOSE | \ 609 -------------------->| LISTEN | ---------- | | 610 / +---------+ delete TCB | | 611 / rcv SYN | | SEND | | 612 / ----------- | | ------- | V 613 +--------+ snd SYN,ACK / \ snd SYN +--------+ 614 | |<----------------- ------------------>| | 615 | SYN | rcv SYN | SYN | 616 | RCVD |<-----------------------------------------------| SENT | 617 | | snd SYN,ACK | | 618 | |------------------ -------------------| | 619 +--------+ rcv ACK of SYN \ / rcv SYN,ACK +--------+ 620 | -------------- | | ----------- 621 | x | | snd ACK 622 | V V 623 | CLOSE +---------+ 624 | ------- | ESTAB | 625 | snd FIN +---------+ 626 | CLOSE | | rcv FIN 627 V ------- | | ------- 628 +---------+ snd FIN / \ snd ACK +---------+ 629 | FIN |<----------------- ------------------>| CLOSE | 630 | WAIT-1 |------------------ | WAIT | 631 +---------+ rcv FIN \ +---------+ 632 | rcv ACK of FIN ------- | CLOSE | 633 | -------------- snd ACK | ------- | 634 V x V snd FIN V 635 +---------+ +---------+ +---------+ 636 |FINWAIT-2| | CLOSING | | LAST-ACK| 637 +---------+ +---------+ +---------+ 638 | rcv ACK of FIN | rcv ACK of FIN | 639 | rcv FIN -------------- | Timeout=2MSL -------------- | 640 | ------- x V ------------ x V 641 \ snd ACK +---------+delete TCB +---------+ 642 ------------------------>|TIME WAIT|------------------>| CLOSED | 643 +---------+ +---------+ 645 note 1: The transition from SYN-RECEIVED to LISTEN on receiving a RST is 646 conditional on having reached SYN-RECEIVED after a passive open. 648 note 2: An unshown transition exists from FIN-WAIT-1 to TIME-WAIT if 649 a FIN is received and the local FIN is also acknowledged. 651 TCP Connection State Diagram 653 Figure 4 655 3.3. Sequence Numbers 657 A fundamental notion in the design is that every octet of data sent 658 over a TCP connection has a sequence number. Since every octet is 659 sequenced, each of them can be acknowledged. The acknowledgment 660 mechanism employed is cumulative so that an acknowledgment of 661 sequence number X indicates that all octets up to but not including X 662 have been received. This mechanism allows for straight-forward 663 duplicate detection in the presence of retransmission. Numbering of 664 octets within a segment is that the first data octet immediately 665 following the header is the lowest numbered, and the following octets 666 are numbered consecutively. 668 It is essential to remember that the actual sequence number space is 669 finite, though very large. This space ranges from 0 to 2**32 - 1. 670 Since the space is finite, all arithmetic dealing with sequence 671 numbers must be performed modulo 2**32. This unsigned arithmetic 672 preserves the relationship of sequence numbers as they cycle from 673 2**32 - 1 to 0 again. There are some subtleties to computer modulo 674 arithmetic, so great care should be taken in programming the 675 comparison of such values. The symbol "=<" means "less than or 676 equal" (modulo 2**32). 678 The typical kinds of sequence number comparisons which the TCP must 679 perform include: 681 (a) Determining that an acknowledgment refers to some sequence 682 number sent but not yet acknowledged. 684 (b) Determining that all sequence numbers occupied by a segment 685 have been acknowledged (e.g., to remove the segment from a 686 retransmission queue). 688 (c) Determining that an incoming segment contains sequence numbers 689 which are expected (i.e., that the segment "overlaps" the receive 690 window). 692 In response to sending data the TCP will receive acknowledgments. 693 The following comparisons are needed to process the acknowledgments. 695 SND.UNA = oldest unacknowledged sequence number 697 SND.NXT = next sequence number to be sent 698 SEG.ACK = acknowledgment from the receiving TCP (next sequence 699 number expected by the receiving TCP) 701 SEG.SEQ = first sequence number of a segment 703 SEG.LEN = the number of octets occupied by the data in the segment 704 (counting SYN and FIN) 706 SEG.SEQ+SEG.LEN-1 = last sequence number of a segment 708 A new acknowledgment (called an "acceptable ack"), is one for which 709 the inequality below holds: 711 SND.UNA < SEG.ACK =< SND.NXT 713 A segment on the retransmission queue is fully acknowledged if the 714 sum of its sequence number and length is less or equal than the 715 acknowledgment value in the incoming segment. 717 When data is received the following comparisons are needed: 719 RCV.NXT = next sequence number expected on an incoming segments, 720 and is the left or lower edge of the receive window 722 RCV.NXT+RCV.WND-1 = last sequence number expected on an incoming 723 segment, and is the right or upper edge of the receive window 725 SEG.SEQ = first sequence number occupied by the incoming segment 727 SEG.SEQ+SEG.LEN-1 = last sequence number occupied by the incoming 728 segment 730 A segment is judged to occupy a portion of valid receive sequence 731 space if 733 RCV.NXT =< SEG.SEQ < RCV.NXT+RCV.WND 735 or 737 RCV.NXT =< SEG.SEQ+SEG.LEN-1 < RCV.NXT+RCV.WND 739 The first part of this test checks to see if the beginning of the 740 segment falls in the window, the second part of the test checks to 741 see if the end of the segment falls in the window; if the segment 742 passes either part of the test it contains data in the window. 744 Actually, it is a little more complicated than this. Due to zero 745 windows and zero length segments, we have four cases for the 746 acceptability of an incoming segment: 748 Segment Receive Test 749 Length Window 750 ------- ------- ------------------------------------------- 752 0 0 SEG.SEQ = RCV.NXT 754 0 >0 RCV.NXT =< SEG.SEQ < RCV.NXT+RCV.WND 756 >0 0 not acceptable 758 >0 >0 RCV.NXT =< SEG.SEQ < RCV.NXT+RCV.WND 759 or RCV.NXT =< SEG.SEQ+SEG.LEN-1 < RCV.NXT+RCV.WND 761 Note that when the receive window is zero no segments should be 762 acceptable except ACK segments. Thus, it is be possible for a TCP to 763 maintain a zero receive window while transmitting data and receiving 764 ACKs. However, even when the receive window is zero, a TCP must 765 process the RST and URG fields of all incoming segments. 767 We have taken advantage of the numbering scheme to protect certain 768 control information as well. This is achieved by implicitly 769 including some control flags in the sequence space so they can be 770 retransmitted and acknowledged without confusion (i.e., one and only 771 one copy of the control will be acted upon). Control information is 772 not physically carried in the segment data space. Consequently, we 773 must adopt rules for implicitly assigning sequence numbers to 774 control. The SYN and FIN are the only controls requiring this 775 protection, and these controls are used only at connection opening 776 and closing. For sequence number purposes, the SYN is considered to 777 occur before the first actual data octet of the segment in which it 778 occurs, while the FIN is considered to occur after the last actual 779 data octet in a segment in which it occurs. The segment length 780 (SEG.LEN) includes both data and sequence space occupying controls. 781 When a SYN is present then SEG.SEQ is the sequence number of the SYN. 783 Initial Sequence Number Selection 785 The protocol places no restriction on a particular connection being 786 used over and over again. A connection is defined by a pair of 787 sockets. New instances of a connection will be referred to as 788 incarnations of the connection. The problem that arises from this is 789 -- "how does the TCP identify duplicate segments from previous 790 incarnations of the connection?" This problem becomes apparent if 791 the connection is being opened and closed in quick succession, or if 792 the connection breaks with loss of memory and is then reestablished. 794 To avoid confusion we must prevent segments from one incarnation of a 795 connection from being used while the same sequence numbers may still 796 be present in the network from an earlier incarnation. We want to 797 assure this, even if a TCP crashes and loses all knowledge of the 798 sequence numbers it has been using. When new connections are 799 created, an initial sequence number (ISN) generator is employed which 800 selects a new 32 bit ISN. There are security issues that result if 801 an off-path attacker is able to predict or guess ISN values. 803 The recommended ISN generator is based on the combination of a 804 (possibly fictitious) 32 bit clock whose low order bit is incremented 805 roughly every 4 microseconds, and a pseudorandom hash function (PRF). 806 The clock component is intended to insure that with a Maximum Segment 807 Lifetime (MSL), generated ISNs will be unique, since it cycles 808 approximately every 4.55 hours, which is much longer than the MSL. 809 This recommended algorithm is further described in RFC 1948 and 810 builds on the basic clock-driven algorithm from RFC 793. 812 A TCP MUST use a clock-driven selection of initial sequence numbers, 813 and SHOULD generate its Initial Sequence Numbers with the expression: 815 ISN = M + F(localip, localport, remoteip, remoteport, secretkey) 817 where M is the 4 microsecond timer, and F() is a pseudorandom 818 function (PRF) of the connection's identifying parameters ("localip, 819 localport, remoteip, remoteport") and a secret key ("secretkey"). 820 F() MUST NOT be computable from the outside, or an attacker could 821 still guess at sequence numbers from the ISN used for some other 822 connection. The PRF could be implemented as a cryptographic has of 823 the concatenation of the TCP connection parameters and some secret 824 data. For discussion of the selection of a specific hash algorithm 825 and management of the secret key data, please see Section 3 of [28]. 827 For each connection there is a send sequence number and a receive 828 sequence number. The initial send sequence number (ISS) is chosen by 829 the data sending TCP, and the initial receive sequence number (IRS) 830 is learned during the connection establishing procedure. 832 For a connection to be established or initialized, the two TCPs must 833 synchronize on each other's initial sequence numbers. This is done 834 in an exchange of connection establishing segments carrying a control 835 bit called "SYN" (for synchronize) and the initial sequence numbers. 836 As a shorthand, segments carrying the SYN bit are also called "SYNs". 837 Hence, the solution requires a suitable mechanism for picking an 838 initial sequence number and a slightly involved handshake to exchange 839 the ISN's. 841 The synchronization requires each side to send it's own initial 842 sequence number and to receive a confirmation of it in acknowledgment 843 from the other side. Each side must also receive the other side's 844 initial sequence number and send a confirming acknowledgment. 846 1) A --> B SYN my sequence number is X 847 2) A <-- B ACK your sequence number is X 848 3) A <-- B SYN my sequence number is Y 849 4) A --> B ACK your sequence number is Y 851 Because steps 2 and 3 can be combined in a single message this is 852 called the three way (or three message) handshake. 854 A three way handshake is necessary because sequence numbers are not 855 tied to a global clock in the network, and TCPs may have different 856 mechanisms for picking the ISN's. The receiver of the first SYN has 857 no way of knowing whether the segment was an old delayed one or not, 858 unless it remembers the last sequence number used on the connection 859 (which is not always possible), and so it must ask the sender to 860 verify this SYN. The three way handshake and the advantages of a 861 clock-driven scheme are discussed in [3]. 863 Knowing When to Keep Quiet 865 To be sure that a TCP does not create a segment that carries a 866 sequence number which may be duplicated by an old segment remaining 867 in the network, the TCP must keep quiet for an MSL before assigning 868 any sequence numbers upon starting up or recovering from a crash in 869 which memory of sequence numbers in use was lost. For this 870 specification the MSL is taken to be 2 minutes. This is an 871 engineering choice, and may be changed if experience indicates it is 872 desirable to do so. Note that if a TCP is reinitialized in some 873 sense, yet retains its memory of sequence numbers in use, then it 874 need not wait at all; it must only be sure to use sequence numbers 875 larger than those recently used. 877 The TCP Quiet Time Concept 879 This specification provides that hosts which "crash" without 880 retaining any knowledge of the last sequence numbers transmitted on 881 each active (i.e., not closed) connection shall delay emitting any 882 TCP segments for at least the agreed MSL in the internet system of 883 which the host is a part. In the paragraphs below, an explanation 884 for this specification is given. TCP implementors may violate the 885 "quiet time" restriction, but only at the risk of causing some old 886 data to be accepted as new or new data rejected as old duplicated by 887 some receivers in the internet system. 889 TCPs consume sequence number space each time a segment is formed and 890 entered into the network output queue at a source host. The 891 duplicate detection and sequencing algorithm in the TCP protocol 892 relies on the unique binding of segment data to sequence space to the 893 extent that sequence numbers will not cycle through all 2**32 values 894 before the segment data bound to those sequence numbers has been 895 delivered and acknowledged by the receiver and all duplicate copies 896 of the segments have "drained" from the internet. Without such an 897 assumption, two distinct TCP segments could conceivably be assigned 898 the same or overlapping sequence numbers, causing confusion at the 899 receiver as to which data is new and which is old. Remember that 900 each segment is bound to as many consecutive sequence numbers as 901 there are octets of data and SYN or FIN flags in the segment. 903 Under normal conditions, TCPs keep track of the next sequence number 904 to emit and the oldest awaiting acknowledgment so as to avoid 905 mistakenly using a sequence number over before its first use has been 906 acknowledged. This alone does not guarantee that old duplicate data 907 is drained from the net, so the sequence space has been made very 908 large to reduce the probability that a wandering duplicate will cause 909 trouble upon arrival. At 2 megabits/sec. it takes 4.5 hours to use 910 up 2**32 octets of sequence space. Since the maximum segment 911 lifetime in the net is not likely to exceed a few tens of seconds, 912 this is deemed ample protection for foreseeable nets, even if data 913 rates escalate to l0's of megabits/sec. At 100 megabits/sec, the 914 cycle time is 5.4 minutes which may be a little short, but still 915 within reason. 917 The basic duplicate detection and sequencing algorithm in TCP can be 918 defeated, however, if a source TCP does not have any memory of the 919 sequence numbers it last used on a given connection. For example, if 920 the TCP were to start all connections with sequence number 0, then 921 upon crashing and restarting, a TCP might re-form an earlier 922 connection (possibly after half-open connection resolution) and emit 923 packets with sequence numbers identical to or overlapping with 924 packets still in the network which were emitted on an earlier 925 incarnation of the same connection. In the absence of knowledge 926 about the sequence numbers used on a particular connection, the TCP 927 specification recommends that the source delay for MSL seconds before 928 emitting segments on the connection, to allow time for segments from 929 the earlier connection incarnation to drain from the system. 931 Even hosts which can remember the time of day and used it to select 932 initial sequence number values are not immune from this problem 933 (i.e., even if time of day is used to select an initial sequence 934 number for each new connection incarnation). 936 Suppose, for example, that a connection is opened starting with 937 sequence number S. Suppose that this connection is not used much and 938 that eventually the initial sequence number function (ISN(t)) takes 939 on a value equal to the sequence number, say S1, of the last segment 940 sent by this TCP on a particular connection. Now suppose, at this 941 instant, the host crashes, recovers, and establishes a new 942 incarnation of the connection. The initial sequence number chosen is 943 S1 = ISN(t) -- last used sequence number on old incarnation of 944 connection! If the recovery occurs quickly enough, any old 945 duplicates in the net bearing sequence numbers in the neighborhood of 946 S1 may arrive and be treated as new packets by the receiver of the 947 new incarnation of the connection. 949 The problem is that the recovering host may not know for how long it 950 crashed nor does it know whether there are still old duplicates in 951 the system from earlier connection incarnations. 953 One way to deal with this problem is to deliberately delay emitting 954 segments for one MSL after recovery from a crash- this is the "quiet 955 time" specification. Hosts which prefer to avoid waiting are willing 956 to risk possible confusion of old and new packets at a given 957 destination may choose not to wait for the "quite time". 958 Implementors may provide TCP users with the ability to select on a 959 connection by connection basis whether to wait after a crash, or may 960 informally implement the "quite time" for all connections. 961 Obviously, even where a user selects to "wait," this is not necessary 962 after the host has been "up" for at least MSL seconds. 964 To summarize: every segment emitted occupies one or more sequence 965 numbers in the sequence space, the numbers occupied by a segment are 966 "busy" or "in use" until MSL seconds have passed, upon crashing a 967 block of space-time is occupied by the octets and SYN or FIN flags of 968 the last emitted segment, if a new connection is started too soon and 969 uses any of the sequence numbers in the space-time footprint of the 970 last segment of the previous connection incarnation, there is a 971 potential sequence number overlap area which could cause confusion at 972 the receiver. 974 3.4. Establishing a connection 976 The "three-way handshake" is the procedure used to establish a 977 connection. This procedure normally is initiated by one TCP and 978 responded to by another TCP. The procedure also works if two TCP 979 simultaneously initiate the procedure. When simultaneous attempt 980 occurs, each TCP receives a "SYN" segment which carries no 981 acknowledgment after it has sent a "SYN". Of course, the arrival of 982 an old duplicate "SYN" segment can potentially make it appear, to the 983 recipient, that a simultaneous connection initiation is in progress. 984 Proper use of "reset" segments can disambiguate these cases. 986 Several examples of connection initiation follow. Although these 987 examples do not show connection synchronization using data-carrying 988 segments, this is perfectly legitimate, so long as the receiving TCP 989 doesn't deliver the data to the user until it is clear the data is 990 valid (i.e., the data must be buffered at the receiver until the 991 connection reaches the ESTABLISHED state). The three-way handshake 992 reduces the possibility of false connections. It is the 993 implementation of a trade-off between memory and messages to provide 994 information for this checking. 996 The simplest three-way handshake is shown in Figure 5 below. The 997 figures should be interpreted in the following way. Each line is 998 numbered for reference purposes. Right arrows (-->) indicate 999 departure of a TCP segment from TCP A to TCP B, or arrival of a 1000 segment at B from A. Left arrows (<--), indicate the reverse. 1001 Ellipsis (...) indicates a segment which is still in the network 1002 (delayed). An "XXX" indicates a segment which is lost or rejected. 1003 Comments appear in parentheses. TCP states represent the state AFTER 1004 the departure or arrival of the segment (whose contents are shown in 1005 the center of each line). Segment contents are shown in abbreviated 1006 form, with sequence number, control flags, and ACK field. Other 1007 fields such as window, addresses, lengths, and text have been left 1008 out in the interest of clarity. 1010 TCP A TCP B 1012 1. CLOSED LISTEN 1014 2. SYN-SENT --> --> SYN-RECEIVED 1016 3. ESTABLISHED <-- <-- SYN-RECEIVED 1018 4. ESTABLISHED --> --> ESTABLISHED 1020 5. ESTABLISHED --> --> ESTABLISHED 1022 Basic 3-Way Handshake for Connection Synchronization 1024 Figure 5 1026 In line 2 of Figure 5, TCP A begins by sending a SYN segment 1027 indicating that it will use sequence numbers starting with sequence 1028 number 100. In line 3, TCP B sends a SYN and acknowledges the SYN it 1029 received from TCP A. Note that the acknowledgment field indicates 1030 TCP B is now expecting to hear sequence 101, acknowledging the SYN 1031 which occupied sequence 100. 1033 At line 4, TCP A responds with an empty segment containing an ACK for 1034 TCP B's SYN; and in line 5, TCP A sends some data. Note that the 1035 sequence number of the segment in line 5 is the same as in line 4 1036 because the ACK does not occupy sequence number space (if it did, we 1037 would wind up ACKing ACK's!). 1039 Simultaneous initiation is only slightly more complex, as is shown in 1040 Figure 6. Each TCP cycles from CLOSED to SYN-SENT to SYN-RECEIVED to 1041 ESTABLISHED. 1043 TCP A TCP B 1045 1. CLOSED CLOSED 1047 2. SYN-SENT --> ... 1049 3. SYN-RECEIVED <-- <-- SYN-SENT 1051 4. ... --> SYN-RECEIVED 1053 5. SYN-RECEIVED --> ... 1055 6. ESTABLISHED <-- <-- SYN-RECEIVED 1057 7. ... --> ESTABLISHED 1059 Simultaneous Connection Synchronization 1061 Figure 6 1063 A TCP MUST support simultaneous open attempts. 1065 Note that a TCP implementation MUST keep track of whether a 1066 connection has reached SYN-RECEIVED state as the result of a passive 1067 OPEN or an active OPEN. 1069 The principle reason for the three-way handshake is to prevent old 1070 duplicate connection initiations from causing confusion. To deal 1071 with this, a special control message, reset, has been devised. If 1072 the receiving TCP is in a non-synchronized state (i.e., SYN-SENT, 1073 SYN-RECEIVED), it returns to LISTEN on receiving an acceptable reset. 1074 If the TCP is in one of the synchronized states (ESTABLISHED, FIN- 1075 WAIT-1, FIN-WAIT-2, CLOSE-WAIT, CLOSING, LAST-ACK, TIME-WAIT), it 1076 aborts the connection and informs its user. We discuss this latter 1077 case under "half-open" connections below. 1079 TCP A TCP B 1081 1. CLOSED LISTEN 1083 2. SYN-SENT --> ... 1085 3. (duplicate) ... --> SYN-RECEIVED 1087 4. SYN-SENT <-- <-- SYN-RECEIVED 1089 5. SYN-SENT --> --> LISTEN 1091 6. ... --> SYN-RECEIVED 1093 7. SYN-SENT <-- <-- SYN-RECEIVED 1095 8. ESTABLISHED --> --> ESTABLISHED 1097 Recovery from Old Duplicate SYN 1099 Figure 7 1101 As a simple example of recovery from old duplicates, consider 1102 Figure 7. At line 3, an old duplicate SYN arrives at TCP B. TCP B 1103 cannot tell that this is an old duplicate, so it responds normally 1104 (line 4). TCP A detects that the ACK field is incorrect and returns 1105 a RST (reset) with its SEQ field selected to make the segment 1106 believable. TCP B, on receiving the RST, returns to the LISTEN 1107 state. When the original SYN (pun intended) finally arrives at line 1108 6, the synchronization proceeds normally. If the SYN at line 6 had 1109 arrived before the RST, a more complex exchange might have occurred 1110 with RST's sent in both directions. 1112 Half-Open Connections and Other Anomalies 1114 An established connection is said to be "half-open" if one of the 1115 TCPs has closed or aborted the connection at its end without the 1116 knowledge of the other, or if the two ends of the connection have 1117 become desynchronized owing to a crash that resulted in loss of 1118 memory. Such connections will automatically become reset if an 1119 attempt is made to send data in either direction. However, half-open 1120 connections are expected to be unusual, and the recovery procedure is 1121 mildly involved. 1123 If at site A the connection no longer exists, then an attempt by the 1124 user at site B to send any data on it will result in the site B TCP 1125 receiving a reset control message. Such a message indicates to the 1126 site B TCP that something is wrong, and it is expected to abort the 1127 connection. 1129 Assume that two user processes A and B are communicating with one 1130 another when a crash occurs causing loss of memory to A's TCP. 1131 Depending on the operating system supporting A's TCP, it is likely 1132 that some error recovery mechanism exists. When the TCP is up again, 1133 A is likely to start again from the beginning or from a recovery 1134 point. As a result, A will probably try to OPEN the connection again 1135 or try to SEND on the connection it believes open. In the latter 1136 case, it receives the error message "connection not open" from the 1137 local (A's) TCP. In an attempt to establish the connection, A's TCP 1138 will send a segment containing SYN. This scenario leads to the 1139 example shown in Figure 8. After TCP A crashes, the user attempts to 1140 re-open the connection. TCP B, in the meantime, thinks the 1141 connection is open. 1143 TCP A TCP B 1145 1. (CRASH) (send 300,receive 100) 1147 2. CLOSED ESTABLISHED 1149 3. SYN-SENT --> --> (??) 1151 4. (!!) <-- <-- ESTABLISHED 1153 5. SYN-SENT --> --> (Abort!!) 1155 6. SYN-SENT CLOSED 1157 7. SYN-SENT --> --> 1159 Half-Open Connection Discovery 1161 Figure 8 1163 When the SYN arrives at line 3, TCP B, being in a synchronized state, 1164 and the incoming segment outside the window, responds with an 1165 acknowledgment indicating what sequence it next expects to hear (ACK 1166 100). TCP A sees that this segment does not acknowledge anything it 1167 sent and, being unsynchronized, sends a reset (RST) because it has 1168 detected a half-open connection. TCP B aborts at line 5. TCP A will 1169 continue to try to establish the connection; the problem is now 1170 reduced to the basic 3-way handshake of Figure 5. 1172 An interesting alternative case occurs when TCP A crashes and TCP B 1173 tries to send data on what it thinks is a synchronized connection. 1174 This is illustrated in Figure 9. In this case, the data arriving at 1175 TCP A from TCP B (line 2) is unacceptable because no such connection 1176 exists, so TCP A sends a RST. The RST is acceptable so TCP B 1177 processes it and aborts the connection. 1179 TCP A TCP B 1181 1. (CRASH) (send 300,receive 100) 1183 2. (??) <-- <-- ESTABLISHED 1185 3. --> --> (ABORT!!) 1187 Active Side Causes Half-Open Connection Discovery 1189 Figure 9 1191 In Figure 10, we find the two TCPs A and B with passive connections 1192 waiting for SYN. An old duplicate arriving at TCP B (line 2) stirs B 1193 into action. A SYN-ACK is returned (line 3) and causes TCP A to 1194 generate a RST (the ACK in line 3 is not acceptable). TCP B accepts 1195 the reset and returns to its passive LISTEN state. 1197 TCP A TCP B 1199 1. LISTEN LISTEN 1201 2. ... --> SYN-RECEIVED 1203 3. (??) <-- <-- SYN-RECEIVED 1205 4. --> --> (return to LISTEN!) 1207 5. LISTEN LISTEN 1209 Old Duplicate SYN Initiates a Reset on two Passive Sockets 1211 Figure 10 1213 A variety of other cases are possible, all of which are accounted for 1214 by the following rules for RST generation and processing. 1216 Reset Generation 1217 As a general rule, reset (RST) must be sent whenever a segment 1218 arrives which apparently is not intended for the current connection. 1219 A reset must not be sent if it is not clear that this is the case. 1221 There are three groups of states: 1223 1. If the connection does not exist (CLOSED) then a reset is sent 1224 in response to any incoming segment except another reset. In 1225 particular, SYNs addressed to a non-existent connection are 1226 rejected by this means. 1228 If the incoming segment has the ACK bit set, the reset takes its 1229 sequence number from the ACK field of the segment, otherwise the 1230 reset has sequence number zero and the ACK field is set to the sum 1231 of the sequence number and segment length of the incoming segment. 1232 The connection remains in the CLOSED state. 1234 2. If the connection is in any non-synchronized state (LISTEN, 1235 SYN-SENT, SYN-RECEIVED), and the incoming segment acknowledges 1236 something not yet sent (the segment carries an unacceptable ACK), 1237 or if an incoming segment has a security level or compartment 1238 which does not exactly match the level and compartment requested 1239 for the connection, a reset is sent. 1241 If our SYN has not been acknowledged and the precedence level of 1242 the incoming segment is higher than the precedence level requested 1243 then either raise the local precedence level (if allowed by the 1244 user and the system) or send a reset; or if the precedence level 1245 of the incoming segment is lower than the precedence level 1246 requested then continue as if the precedence matched exactly (if 1247 the remote TCP cannot raise the precedence level to match ours 1248 this will be detected in the next segment it sends, and the 1249 connection will be terminated then). If our SYN has been 1250 acknowledged (perhaps in this incoming segment) the precedence 1251 level of the incoming segment must match the local precedence 1252 level exactly, if it does not a reset must be sent. 1254 If the incoming segment has an ACK field, the reset takes its 1255 sequence number from the ACK field of the segment, otherwise the 1256 reset has sequence number zero and the ACK field is set to the sum 1257 of the sequence number and segment length of the incoming segment. 1258 The connection remains in the same state. 1260 3. If the connection is in a synchronized state (ESTABLISHED, 1261 FIN-WAIT-1, FIN-WAIT-2, CLOSE-WAIT, CLOSING, LAST-ACK, TIME-WAIT), 1262 any unacceptable segment (out of window sequence number or 1263 unacceptable acknowledgment number) must elicit only an empty 1264 acknowledgment segment containing the current send-sequence number 1265 and an acknowledgment indicating the next sequence number expected 1266 to be received, and the connection remains in the same state. 1268 If an incoming segment has a security level, or compartment, or 1269 precedence which does not exactly match the level, and 1270 compartment, and precedence requested for the connection,a reset 1271 is sent and the connection goes to the CLOSED state. The reset 1272 takes its sequence number from the ACK field of the incoming 1273 segment. 1275 Reset Processing 1277 In all states except SYN-SENT, all reset (RST) segments are validated 1278 by checking their SEQ-fields. A reset is valid if its sequence 1279 number is in the window. In the SYN-SENT state (a RST received in 1280 response to an initial SYN), the RST is acceptable if the ACK field 1281 acknowledges the SYN. 1283 The receiver of a RST first validates it, then changes state. If the 1284 receiver was in the LISTEN state, it ignores it. If the receiver was 1285 in SYN-RECEIVED state and had previously been in the LISTEN state, 1286 then the receiver returns to the LISTEN state, otherwise the receiver 1287 aborts the connection and goes to the CLOSED state. If the receiver 1288 was in any other state, it aborts the connection and advises the user 1289 and goes to the CLOSED state. 1291 TCP SHOULD allow a received RST segment to include data. 1293 3.4.1. Remote Address Validation 1295 TODO - figure out if this section would fit better elsewhere, for 1296 instance in the more detailed description of the OPEN call later on 1298 A TCP implementation MUST reject as an error a local OPEN call for an 1299 invalid remote IP address (e.g., a broadcast or multicast address). 1301 An incoming SYN with an invalid source address must be ignored either 1302 by TCP or by the IP layer (see Section 3.2.1.3 of [14]). 1304 A TCP implementation MUST silently discard an incoming SYN segment 1305 that is addressed to a broadcast or multicast address. 1307 3.5. Closing a Connection 1309 CLOSE is an operation meaning "I have no more data to send." The 1310 notion of closing a full-duplex connection is subject to ambiguous 1311 interpretation, of course, since it may not be obvious how to treat 1312 the receiving side of the connection. We have chosen to treat CLOSE 1313 in a simplex fashion. The user who CLOSEs may continue to RECEIVE 1314 until he is told that the other side has CLOSED also. Thus, a 1315 program could initiate several SENDs followed by a CLOSE, and then 1316 continue to RECEIVE until signaled that a RECEIVE failed because the 1317 other side has CLOSED. We assume that the TCP will signal a user, 1318 even if no RECEIVEs are outstanding, that the other side has closed, 1319 so the user can terminate his side gracefully. A TCP will reliably 1320 deliver all buffers SENT before the connection was CLOSED so a user 1321 who expects no data in return need only wait to hear the connection 1322 was CLOSED successfully to know that all his data was received at the 1323 destination TCP. Users must keep reading connections they close for 1324 sending until the TCP says no more data. 1326 There are essentially three cases: 1328 1) The user initiates by telling the TCP to CLOSE the connection 1330 2) The remote TCP initiates by sending a FIN control signal 1332 3) Both users CLOSE simultaneously 1334 Case 1: Local user initiates the close 1336 In this case, a FIN segment can be constructed and placed on the 1337 outgoing segment queue. No further SENDs from the user will be 1338 accepted by the TCP, and it enters the FIN-WAIT-1 state. RECEIVEs 1339 are allowed in this state. All segments preceding and including 1340 FIN will be retransmitted until acknowledged. When the other TCP 1341 has both acknowledged the FIN and sent a FIN of its own, the first 1342 TCP can ACK this FIN. Note that a TCP receiving a FIN will ACK 1343 but not send its own FIN until its user has CLOSED the connection 1344 also. 1346 Case 2: TCP receives a FIN from the network 1348 If an unsolicited FIN arrives from the network, the receiving TCP 1349 can ACK it and tell the user that the connection is closing. The 1350 user will respond with a CLOSE, upon which the TCP can send a FIN 1351 to the other TCP after sending any remaining data. The TCP then 1352 waits until its own FIN is acknowledged whereupon it deletes the 1353 connection. If an ACK is not forthcoming, after the user timeout 1354 the connection is aborted and the user is told. 1356 Case 3: both users close simultaneously 1358 A simultaneous CLOSE by users at both ends of a connection causes 1359 FIN segments to be exchanged. When all segments preceding the 1360 FINs have been processed and acknowledged, each TCP can ACK the 1361 FIN it has received. Both will, upon receiving these ACKs, delete 1362 the connection. 1364 TCP A TCP B 1366 1. ESTABLISHED ESTABLISHED 1368 2. (Close) 1369 FIN-WAIT-1 --> --> CLOSE-WAIT 1371 3. FIN-WAIT-2 <-- <-- CLOSE-WAIT 1373 4. (Close) 1374 TIME-WAIT <-- <-- LAST-ACK 1376 5. TIME-WAIT --> --> CLOSED 1378 6. (2 MSL) 1379 CLOSED 1381 Normal Close Sequence 1383 Figure 11 1385 TCP A TCP B 1387 1. ESTABLISHED ESTABLISHED 1389 2. (Close) (Close) 1390 FIN-WAIT-1 --> ... FIN-WAIT-1 1391 <-- <-- 1392 ... --> 1394 3. CLOSING --> ... CLOSING 1395 <-- <-- 1396 ... --> 1398 4. TIME-WAIT TIME-WAIT 1399 (2 MSL) (2 MSL) 1400 CLOSED CLOSED 1402 Simultaneous Close Sequence 1404 Figure 12 1406 A TCP connection may terminate in two ways: (1) the normal TCP close 1407 sequence using a FIN handshake, and (2) an "abort" in which one or 1408 more RST segments are sent and the connection state is immediately 1409 discarded. If a TCP connection is closed by the remote site, the 1410 local application MUST be informed whether it closed normally or was 1411 aborted. 1413 3.5.1. Half-Closed Connections 1415 The normal TCP close sequence delivers buffered data reliably in both 1416 directions. Since the two directions of a TCP connection are closed 1417 independently, it is possible for a connection to be "half closed," 1418 i.e., closed in only one direction, and a host is permitted to 1419 continue sending data in the open direction on a half-closed 1420 connection. 1422 A host MAY implement a "half-duplex" TCP close sequence, so that an 1423 application that has called CLOSE cannot continue to read data from 1424 the connection. If such a host issues a CLOSE call while received 1425 data is still pending in TCP, or if new data is received after CLOSE 1426 is called, its TCP SHOULD send a RST to show that data was lost. 1428 When a connection is closed actively, it MUST linger in TIME-WAIT 1429 state for a time 2xMSL (Maximum Segment Lifetime). However, it MAY 1430 accept a new SYN from the remote TCP to reopen the connection 1431 directly from TIME-WAIT state, if it: 1433 (1) assigns its initial sequence number for the new connection to 1434 be larger than the largest sequence number it used on the previous 1435 connection incarnation, and 1437 (2) returns to TIME-WAIT state if the SYN turns out to be an old 1438 duplicate. 1440 When the TCP Timestamp options are available, an improved algorithm 1441 is described in [26] in order to support higher connection 1442 establishment rates. This algorithm for reducing TIME-WAIT is a Best 1443 Current Practice that SHOULD be implemented, since timestamp options 1444 are commonly used, and using them to reduce TIME-WAIT provides 1445 benefits for busy Internet servers. 1447 3.6. Precedence and Security 1449 TODO - talk to TCPM about what to do about precedence and security 1450 compartment throughout the document ... security compartment material 1451 for IPv4 may be fine nearly as-is, but precedence was a subset of 1452 what DSCP includes and it's not clear that running code actually does 1453 what 793 says about precedence anyways, especially since now as a 1454 DSCP it doesn't make sense to do greater-than comparisons on, nor to 1455 reset connections if it changes. 1457 The intent is that connection be allowed only between ports operating 1458 with exactly the same security and compartment values and at the 1459 higher of the precedence level requested by the two ports. 1461 The precedence and security parameters used in TCP are exactly those 1462 defined in the Internet Protocol (IP) [1]. Throughout this TCP 1463 specification the term "security/compartment" is intended to indicate 1464 the security parameters used in IP including security, compartment, 1465 user group, and handling restriction. 1467 A connection attempt with mismatched security/compartment values or a 1468 lower precedence value must be rejected by sending a reset. 1469 Rejecting a connection due to too low a precedence only occurs after 1470 an acknowledgment of the SYN has been received. 1472 Note that TCP modules which operate only at the default value of 1473 precedence will still have to check the precedence of incoming 1474 segments and possibly raise the precedence level they use on the 1475 connection. 1477 The security parameters may be used even in a non-secure environment 1478 (the values would indicate unclassified data), thus hosts in non- 1479 secure environments must be prepared to receive the security 1480 parameters, though they need not send them. 1482 3.7. Segmentation 1484 The term "segmentation" refers to the activity TCP performs when 1485 ingesting a stream of bytes from a sending application and 1486 packetizing that stream of bytes into TCP segments. Individual TCP 1487 segments often do not correspond one-for-one to individual send (or 1488 socket write) calls from the application. Applications may perform 1489 writes at the granularity of messages in the upper layer protocol, 1490 but TCP guarantees no boundary coherence between the TCP segments 1491 sent and received versus user application data read or write buffer 1492 boundaries. In some specific protocols, such as RDMA using DDP and 1493 MPA [19], there are performance optimizations possible when the 1494 relation between TCP segments and application data units can be 1495 controlled, and MPA includes a specific mechanism for detecting and 1496 verifying this relationship between TCP segments and application 1497 message data strcutures, but this is specific to applications like 1498 RDMA. In general, multiple goals influence the sizing of TCP 1499 segments created by a TCP implementation. 1501 Goals driving the sending of larger segments include: 1503 o Reducing the number of packets in flight within the network. 1505 o Increasing processing efficiency and potential performance by 1506 enabling a smaller number of interrupts and inter-layer 1507 interactions. 1509 o Limiting the overhead of TCP headers. 1511 Note that the performance benefits of sending larger segments may 1512 decrease as the size increases, and there may be boundaries where 1513 advantages are reversed. For instance, on some machines 1025 bytes 1514 within a segment could lead to worse performance than 1024 bytes, due 1515 purely to data alignment on copy operations. 1517 Goals driving the sending of smaller segments include: 1519 o Avoiding sending segments larger than the smallest MTU within an 1520 IP network path, because this results in either packet loss or 1521 fragmentation. Making matters worse, some firewalls or 1522 middleboxes may drop fragmented packets or ICMP messages related 1523 related to fragmentation. 1525 o Preventing delays to the application data stream, especially when 1526 TCP is waiting on the application to generate more data, or when 1527 the application is waiting on an event or input from its peer in 1528 order to generate more data. 1530 o Enabling "fate sharing" between TCP segments and lower-layer data 1531 units (e.g. below IP, for links with cell or frame sizes smaller 1532 than the IP MTU). 1534 Towards meeting these competing sets of goals, TCP includes several 1535 mechanisms, including the Maximum Segment Size option, Path MTU 1536 Discovery, the Nagle algorithm, and support for IPv6 Jumbograms, as 1537 discussed in the following subsections. 1539 3.7.1. Maximum Segment Size Option 1541 TCP MUST implement both sending and receiving the MSS option. 1543 TCP SHOULD send an MSS option in every SYN segment when its receive 1544 MSS differs from the default 536 for IPv4 or 1220 for IPv6, and MAY 1545 send it always. 1547 If an MSS option is not received at connection setup, TCP MUST assume 1548 a default send MSS of 536 (576-40) for IPv4 or 1220 (1280 - 60) for 1549 IPv6. 1551 The maximum size of a segment that TCP really sends, the "effective 1552 send MSS," MUST be the smaller of the send MSS (which reflects the 1553 available reassembly buffer size at the remote host, the EMTU_R [14]) 1554 and the largest transmission size permitted by the IP layer (EMTU_S 1555 [14]): 1557 Eff.snd.MSS = 1559 min(SendMSS+20, MMS_S) - TCPhdrsize - IPoptionsize 1561 where: 1563 o SendMSS is the MSS value received from the remote host, or the 1564 default 536 for IPv4 or 1220 for IPv6, if no MSS option is 1565 received. 1567 o MMS_S is the maximum size for a transport-layer message that TCP 1568 may send. 1570 o TCPhdrsize is the size of the fixed TCP header and any options. 1571 This is 20 in the (rare) case that no options are present, but may 1572 be larger if TCP options are to be sent. Note that some options 1573 may not be included on all segments, but that for each segment 1574 sent, the sender should adjust the data length accordingly, within 1575 the Eff.snd.MSS. 1577 o IPoptionsize is the size of any IP options associated with a TCP 1578 connection. Note that some options may not be included on all 1579 packets, but that for each segment sent, the sender should adjust 1580 the data length accordingly, within the Eff.snd.MSS. 1582 The MSS value to be sent in an MSS option should be equal to the 1583 effective MTU minus the fixed IP and TCP headers. By ignoring both 1584 IP and TCP options when calculating the value for the MSS option, if 1585 there are any IP or TCP options to be sent in a packet, then the 1586 sender must decrease the size of the TCP data accordingly. RFC 6691 1587 [29] discusses this in greater detail. 1589 The MSS value to be sent in an MSS option must be less than or equal 1590 to: 1592 MMS_R - 20 1594 where MMS_R is the maximum size for a transport-layer message that 1595 can be received (and reassembled at the IP layer). TCP obtains MMS_R 1596 and MMS_S from the IP layer; see the generic call GET_MAXSIZES in 1597 Section 3.4 of RFC 1122. These are defined in terms of their IP MTU 1598 equivalents, EMTU_R and EMTU_S [14]. 1600 When TCP is used in a situation where either the IP or TCP headers 1601 are not fixed, the sender must reduce the amount of TCP data in any 1602 given packet by the number of octets used by the IP and TCP options. 1603 This has been a point of confusion historically, as explained in RFC 1604 6691, Section 3.1. 1606 3.7.2. Path MTU Discovery 1608 A TCP implementation may be aware of the MTU on directly connected 1609 links, but will rarely have insight about MTUs across an entire 1610 network path. For IPv4, RFC 1122 provides an IP-layer recommendation 1611 on the default effective MTU for sending to be less than or equal to 1612 576 for destinations not directly connected. For IPv6, this would be 1613 1280. In all cases, however, implementation of Path MTU Discovery 1614 (PMTUD) and Packetization Layer Path MTU Discovery (PLPMTUD) is 1615 strongly recommended in order for TCP to improve segmentation 1616 decisions. Both PMTUD and PLPMTUD help TCP choose segment sizes that 1617 avoid both on-path (for IPv4) and source fragmentation (IPv4 and 1618 IPv6). 1620 PMTUD for IPv4 [2] or IPv6 [3] is implemented in conjunction between 1621 TCP, IP, and ICMP protocols. It relies both on avoiding source 1622 fragmentation and setting the IPv4 DF (don't fragment) flag, the 1623 latter to inhibit on-path fragmentation. It relies on ICMP errors 1624 from routers along the path, whenever a segment is too large to 1625 traverse a link. Several adjustments to a TCP implementation with 1626 PMTUD are described in RFC 2923 in order to deal with problems 1627 experienced in practice [8]. PLPMTUD [16] is a Standards Track 1628 improvement to PMTUD that relaxes the requirement for ICMP support 1629 across a path, and improves performance in cases where ICMP is not 1630 consistently conveyed, but still tries to avoid source fragmentation. 1631 The mechanisms in all four of these RFCs are recommended to be 1632 included in TCP implementations. 1634 The TCP MSS option specifies an upper bound for the size of packets 1635 that can be received. Hence, setting the value in the MSS option too 1636 small can impact the ability for PMTUD or PLPMTUD to find a larger 1637 path MTU. RFC 1191 discusses this implication of many older TCP 1638 implementations setting MSS to 536 for non-local destinations, rather 1639 than deriving it from the MTUs of connected interfaces as 1640 recommended. 1642 3.7.3. Interfaces with Variable MTU Values 1644 The effective MTU can sometimes vary, as when used with variable 1645 compression, e.g., RObust Header Compression (ROHC) [22]. It is 1646 tempting for TCP to want to advertise the largest possible MSS, to 1647 support the most efficient use of compressed payloads. 1649 Unfortunately, some compression schemes occasionally need to transmit 1650 full headers (and thus smaller payloads) to resynchronize state at 1651 their endpoint compressors/decompressors. If the largest MTU is used 1652 to calculate the value to advertise in the MSS option, TCP 1653 retransmission may interfere with compressor resynchronization. 1655 As a result, when the effective MTU of an interface varies, TCP 1656 SHOULD use the smallest effective MTU of the interface to calculate 1657 the value to advertise in the MSS option. 1659 3.7.4. Nagle Algorithm 1661 The "Nagle algorithm" was described in RFC 896 [13] and was 1662 recommended in RFC 1122 [14] for mitigation of an early problem of 1663 too many small packets being generated. It has been implemented in 1664 most current TCP code bases, sometimes with minor variations. 1666 If there is unacknowledged data (i.e., SND.NXT > SND.UNA), then the 1667 sending TCP buffers all user data (regardless of the PSH bit), until 1668 the outstanding data has been acknowledged or until the TCP can send 1669 a full-sized segment (Eff.snd.MSS bytes). 1671 TODO - see if SEND description later should be updated to reflect 1672 this 1674 A TCP SHOULD implement the Nagle Algorithm to coalesce short 1675 segments. However, there MUST be a way for an application to disable 1676 the Nagle algorithm on an individual connection. In all cases, 1677 sending data is also subject to the limitation imposed by the Slow 1678 Start algorithm [21]. 1680 3.7.5. IPv6 Jumbograms 1682 In order to support TCP over IPv6 jumbograms, implementations need to 1683 be able to send TCP segments larger than the 64KB limit that the MSS 1684 option can convey. RFC 2675 [7] defines that an MSS value of 65,535 1685 bytes is to be treated as infinity, and Path MTU Discovery [3] is 1686 used to determine the actual MSS. 1688 3.8. Data Communication 1690 Once the connection is established data is communicated by the 1691 exchange of segments. Because segments may be lost due to errors 1692 (checksum test failure), or network congestion, TCP uses 1693 retransmission (after a timeout) to ensure delivery of every segment. 1694 Duplicate segments may arrive due to network or TCP retransmission. 1695 As discussed in the section on sequence numbers the TCP performs 1696 certain tests on the sequence and acknowledgment numbers in the 1697 segments to verify their acceptability. 1699 The sender of data keeps track of the next sequence number to use in 1700 the variable SND.NXT. The receiver of data keeps track of the next 1701 sequence number to expect in the variable RCV.NXT. The sender of 1702 data keeps track of the oldest unacknowledged sequence number in the 1703 variable SND.UNA. If the data flow is momentarily idle and all data 1704 sent has been acknowledged then the three variables will be equal. 1706 When the sender creates a segment and transmits it the sender 1707 advances SND.NXT. When the receiver accepts a segment it advances 1708 RCV.NXT and sends an acknowledgment. When the data sender receives 1709 an acknowledgment it advances SND.UNA. The extent to which the 1710 values of these variables differ is a measure of the delay in the 1711 communication. The amount by which the variables are advanced is the 1712 length of the data and SYN or FIN flags in the segment. Note that 1713 once in the ESTABLISHED state all segments must carry current 1714 acknowledgment information. 1716 The CLOSE user call implies a push function, as does the FIN control 1717 flag in an incoming segment. 1719 3.8.1. Retransmission Timeout 1721 Because of the variability of the networks that compose an 1722 internetwork system and the wide range of uses of TCP connections the 1723 retransmission timeout (RTO) must be dynamically determined. 1725 The RTO MUST be computed according to the algorithm in [10], 1726 including Karn's algorithm for taking RTT samples. 1728 RFC 793 contains an early example procedure for computing the RTO. 1729 This was then replaced by the algorithm described in RFC 1122, and 1730 subsequently updated in RFC 2988, and then again in RFC 6298. 1732 If a retransmitted packet is identical to the original packet (which 1733 implies not only that the data boundaries have not changed, but also 1734 that the window and acknowledgment fields of the header have not 1735 changed), then the same IP Identification field MAY be used (see 1736 Section 3.2.1.5 of RFC 1122). 1738 3.8.2. TCP Congestion Control 1740 RFC 1122 required implementation of Van Jacobson's congestion control 1741 algorithm combining slow start with congestion avoidance. RFC 2581 1742 provided IETF Standards Track description of this, along with fast 1743 retransmit and fast recovery. RFC 5681 is the current description of 1744 these algorithms and is the current standard for TCP congestion 1745 control. 1747 A TCP MUST implement RFC 5681. 1749 Explicit Congestion Notification (ECN) was defined in RFC 3168 and is 1750 an IETF Standards Track enhancement that has many benefits [34]. 1752 A TCP SHOULD implement ECN as described in RFC 3168. 1754 3.8.3. TCP Connection Failures 1756 Excessive retransmission of the same segment by TCP indicates some 1757 failure of the remote host or the Internet path. This failure may be 1758 of short or long duration. The following procedure MUST be used to 1759 handle excessive retransmissions of data segments: 1761 (a) There are two thresholds R1 and R2 measuring the amount of 1762 retransmission that has occurred for the same segment. R1 and R2 1763 might be measured in time units or as a count of retransmissions. 1765 (b) When the number of transmissions of the same segment reaches 1766 or exceeds threshold R1, pass negative advice (see [14] 1767 Section 3.3.1.4) to the IP layer, to trigger dead-gateway 1768 diagnosis. 1770 (c) When the number of transmissions of the same segment reaches a 1771 threshold R2 greater than R1, close the connection. 1773 (d) An application MUST be able to set the value for R2 for a 1774 particular connection. For example, an interactive application 1775 might set R2 to "infinity," giving the user control over when to 1776 disconnect. 1778 (d) TCP SHOULD inform the application of the delivery problem 1779 (unless such information has been disabled by the application; see 1780 RFC1122 Section 4.2.4.1 - TODO update to error reporting 1781 description in this document), when R1 is reached and before R2. 1782 This will allow a remote login (User Telnet) application program 1783 to inform the user, for example. 1785 The value of R1 SHOULD correspond to at least 3 retransmissions, at 1786 the current RTO. The value of R2 SHOULD correspond to at least 100 1787 seconds. 1789 An attempt to open a TCP connection could fail with excessive 1790 retransmissions of the SYN segment or by receipt of a RST segment or 1791 an ICMP Port Unreachable. SYN retransmissions MUST be handled in the 1792 general way just described for data retransmissions, including 1793 notification of the application layer. 1795 However, the values of R1 and R2 may be different for SYN and data 1796 segments. In particular, R2 for a SYN segment MUST be set large 1797 enough to provide retransmission of the segment for at least 3 1798 minutes. The application can close the connection (i.e., give up on 1799 the open attempt) sooner, of course. 1801 3.8.4. TCP Keep-Alives 1803 Implementors MAY include "keep-alives" in their TCP implementations, 1804 although this practice is not universally accepted. If keep-alives 1805 are included, the application MUST be able to turn them on or off for 1806 each TCP connection, and they MUST default to off. 1808 Keep-alive packets MUST only be sent when no data or acknowledgement 1809 packets have been received for the connection within an interval. 1810 This interval MUST be configurable and MUST default to no less than 1811 two hours. 1813 It is extremely important to remember that ACK segments that contain 1814 no data are not reliably transmitted by TCP. Consequently, if a 1815 keep-alive mechanism is implemented it MUST NOT interpret failure to 1816 respond to any specific probe as a dead connection. 1818 An implementation SHOULD send a keep-alive segment with no data; 1819 however, it MAY be configurable to send a keep-alive segment 1820 containing one garbage octet, for compatibility with erroneous TCP 1821 implementations. 1823 3.8.5. The Communication of Urgent Information 1825 As a result of implementation differences and middlebox interactions, 1826 new applications SHOULD NOT employ the TCP urgent mechanism. 1827 However, TCP implementations MUST still include support for the 1828 urgent mechanism. Details can be found in RFC 6093 [25]. 1830 The objective of the TCP urgent mechanism is to allow the sending 1831 user to stimulate the receiving user to accept some urgent data and 1832 to permit the receiving TCP to indicate to the receiving user when 1833 all the currently known urgent data has been received by the user. 1835 This mechanism permits a point in the data stream to be designated as 1836 the end of urgent information. Whenever this point is in advance of 1837 the receive sequence number (RCV.NXT) at the receiving TCP, that TCP 1838 must tell the user to go into "urgent mode"; when the receive 1839 sequence number catches up to the urgent pointer, the TCP must tell 1840 user to go into "normal mode". If the urgent pointer is updated 1841 while the user is in "urgent mode", the update will be invisible to 1842 the user. 1844 The method employs a urgent field which is carried in all segments 1845 transmitted. The URG control flag indicates that the urgent field is 1846 meaningful and must be added to the segment sequence number to yield 1847 the urgent pointer. The absence of this flag indicates that there is 1848 no urgent data outstanding. 1850 To send an urgent indication the user must also send at least one 1851 data octet. If the sending user also indicates a push, timely 1852 delivery of the urgent information to the destination process is 1853 enhanced. 1855 A TCP MUST support a sequence of urgent data of any length. [14] 1857 A TCP MUST inform the application layer asynchronously whenever it 1858 receives an Urgent pointer and there was previously no pending urgent 1859 data, or whenvever the Urgent pointer advances in the data stream. 1860 There MUST be a way for the application to learn how much urgent data 1861 remains to be read from the connection, or at least to determine 1862 whether or not more urgent data remains to be read. [14] 1864 3.8.6. Managing the Window 1866 The window sent in each segment indicates the range of sequence 1867 numbers the sender of the window (the data receiver) is currently 1868 prepared to accept. There is an assumption that this is related to 1869 the currently available data buffer space available for this 1870 connection. 1872 The sending TCP packages the data to be transmitted into segments 1873 which fit the current window, and may repackage segments on the 1874 retransmission queue. Such repackaging is not required, but may be 1875 helpful. 1877 In a connection with a one-way data flow, the window information will 1878 be carried in acknowledgment segments that all have the same sequence 1879 number so there will be no way to reorder them if they arrive out of 1880 order. This is not a serious problem, but it will allow the window 1881 information to be on occasion temporarily based on old reports from 1882 the data receiver. A refinement to avoid this problem is to act on 1883 the window information from segments that carry the highest 1884 acknowledgment number (that is segments with acknowledgment number 1885 equal or greater than the highest previously received). 1887 Indicating a large window encourages transmissions. If more data 1888 arrives than can be accepted, it will be discarded. This will result 1889 in excessive retransmissions, adding unnecessarily to the load on the 1890 network and the TCPs. Indicating a small window may restrict the 1891 transmission of data to the point of introducing a round trip delay 1892 between each new segment transmitted. 1894 The mechanisms provided allow a TCP to advertise a large window and 1895 to subsequently advertise a much smaller window without having 1896 accepted that much data. This, so called "shrinking the window," is 1897 strongly discouraged. The robustness principle dictates that TCPs 1898 will not shrink the window themselves, but will be prepared for such 1899 behavior on the part of other TCPs. 1901 A TCP receiver SHOULD NOT shrink the window, i.e., move the right 1902 window edge to the left. However, a sending TCP MUST be robust 1903 against window shrinking, which may cause the "useable window" (see 1904 Section 3.8.6.2.1) to become negative. 1906 If this happens, the sender SHOULD NOT send new data, but SHOULD 1907 retransmit normally the old unacknowledged data between SND.UNA and 1908 SND.UNA+SND.WND. The sender MAY also retransmit old data beyond 1909 SND.UNA+SND.WND, but SHOULD NOT time out the connection if data 1910 beyond the right window edge is not acknowledged. If the window 1911 shrinks to zero, the TCP MUST probe it in the standard way (described 1912 below). 1914 3.8.6.1. Zero Window Probing 1916 The sending TCP must be prepared to accept from the user and send at 1917 least one octet of new data even if the send window is zero. The 1918 sending TCP must regularly retransmit to the receiving TCP even when 1919 the window is zero, in order to "probe" the window. Two minutes is 1920 recommended for the retransmission interval when the window is zero. 1921 This retransmission is essential to guarantee that when either TCP 1922 has a zero window the re-opening of the window will be reliably 1923 reported to the other. This is referred to as Zero-Window Probing 1924 (ZWP) in other documents. 1926 Probing of zero (offered) windows MUST be supported. 1928 A TCP MAY keep its offered receive window closed indefinitely. As 1929 long as the receiving TCP continues to send acknowledgments in 1930 response to the probe segments, the sending TCP MUST allow the 1931 connection to stay open. This enables TCP to function in scenarios 1932 such as the "printer ran out of paper" situation described in 1933 Section 4.2.2.17 of RFC1122. The behavior is subject to the 1934 implementation's resource management concerns, as noted in [27]. 1936 When the receiving TCP has a zero window and a segment arrives it 1937 must still send an acknowledgment showing its next expected sequence 1938 number and current window (zero). 1940 3.8.6.2. Silly Window Syndrome Avoidance 1942 The "Silly Window Syndrome" (SWS) is a stable pattern of small 1943 incremental window movements resulting in extremely poor TCP 1944 performance. Algorithms to avoid SWS are described below for both 1945 the sending side and the receiving side. RFC 1122 contains more 1946 detailed discussion of the SWS problem. Note that the Nagle 1947 algorithm and the sender SWS avoidance algorithm play complementary 1948 roles in improving performance. The Nagle algorithm discourages 1949 sending tiny segments when the data to be sent increases in small 1950 increments, while the SWS avoidance algorithm discourages small 1951 segments resulting from the right window edge advancing in small 1952 increments. 1954 3.8.6.2.1. Sender's Algorithm - When to Send Data 1956 A TCP MUST include a SWS avoidance algorithm in the sender. 1958 A TCP SHOULD implement the Nagle Algorithm to coalesce short 1959 segments. However, there MUST be a way for an application to disable 1960 the Nagle algorithm on an individual connection. In all cases, 1961 sending data is also subject to the limitation imposed by the Slow 1962 Start algorithm. 1964 The sender's SWS avoidance algorithm is more difficult than the 1965 receivers's, because the sender does not know (directly) the 1966 receiver's total buffer space RCV.BUFF. An approach which has been 1967 found to work well is for the sender to calculate Max(SND.WND), the 1968 maximum send window it has seen so far on the connection, and to use 1969 this value as an estimate of RCV.BUFF. Unfortunately, this can only 1970 be an estimate; the receiver may at any time reduce the size of 1971 RCV.BUFF. To avoid a resulting deadlock, it is necessary to have a 1972 timeout to force transmission of data, overriding the SWS avoidance 1973 algorithm. In practice, this timeout should seldom occur. 1975 The "useable window" is: 1977 U = SND.UNA + SND.WND - SND.NXT 1979 i.e., the offered window less the amount of data sent but not 1980 acknowledged. If D is the amount of data queued in the sending TCP 1981 but not yet sent, then the following set of rules is recommended. 1983 Send data: 1985 (1) if a maximum-sized segment can be sent, i.e, if: 1987 min(D,U) >= Eff.snd.MSS; 1989 (2) or if the data is pushed and all queued data can be sent now, 1990 i.e., if: 1992 [SND.NXT = SND.UNA and] PUSHED and D <= U 1994 (the bracketed condition is imposed by the Nagle algorithm); 1996 (3) or if at least a fraction Fs of the maximum window can be sent, 1997 i.e., if: 1999 [SND.NXT = SND.UNA and] 2001 min(D.U) >= Fs * Max(SND.WND); 2003 (4) or if data is PUSHed and the override timeout occurs. 2005 Here Fs is a fraction whose recommended value is 1/2. The override 2006 timeout should be in the range 0.1 - 1.0 seconds. It may be 2007 convenient to combine this timer with the timer used to probe zero 2008 windows (Section Section 3.8.6.1). 2010 3.8.6.2.2. Receiver's Algorithm - When to Send a Window Update 2012 A TCP MUST include a SWS avoidance algorithm in the receiver. 2014 The receiver's SWS avoidance algorithm determines when the right 2015 window edge may be advanced; this is customarily known as "updating 2016 the window". This algorithm combines with the delayed ACK algorithm 2017 (see Section 3.8.6.3) to determine when an ACK segment containing the 2018 current window will really be sent to the receiver. 2020 The solution to receiver SWS is to avoid advancing the right window 2021 edge RCV.NXT+RCV.WND in small increments, even if data is received 2022 from the network in small segments. 2024 Suppose the total receive buffer space is RCV.BUFF. At any given 2025 moment, RCV.USER octets of this total may be tied up with data that 2026 has been received and acknowledged but which the user process has not 2027 yet consumed. When the connection is quiescent, RCV.WND = RCV.BUFF 2028 and RCV.USER = 0. 2030 Keeping the right window edge fixed as data arrives and is 2031 acknowledged requires that the receiver offer less than its full 2032 buffer space, i.e., the receiver must specify a RCV.WND that keeps 2033 RCV.NXT+RCV.WND constant as RCV.NXT increases. Thus, the total 2034 buffer space RCV.BUFF is generally divided into three parts: 2036 |<------- RCV.BUFF ---------------->| 2037 1 2 3 2038 ----|---------|------------------|------|---- 2039 RCV.NXT ^ 2040 (Fixed) 2042 1 - RCV.USER = data received but not yet consumed; 2043 2 - RCV.WND = space advertised to sender; 2044 3 - Reduction = space available but not yet 2045 advertised. 2047 The suggested SWS avoidance algorithm for the receiver is to keep 2048 RCV.NXT+RCV.WND fixed until the reduction satisfies: 2050 RCV.BUFF - RCV.USER - RCV.WND >= 2052 min( Fr * RCV.BUFF, Eff.snd.MSS ) 2054 where Fr is a fraction whose recommended value is 1/2, and 2055 Eff.snd.MSS is the effective send MSS for the connection (see 2056 Section 3.7.1). When the inequality is satisfied, RCV.WND is set to 2057 RCV.BUFF-RCV.USER. 2059 Note that the general effect of this algorithm is to advance RCV.WND 2060 in increments of Eff.snd.MSS (for realistic receive buffers: 2061 Eff.snd.MSS < RCV.BUFF/2). Note also that the receiver must use its 2062 own Eff.snd.MSS, assuming it is the same as the sender's. 2064 3.8.6.3. Delayed Acknowledgements - When to Send an ACK Segment 2066 A host that is receiving a stream of TCP data segments can increase 2067 efficiency in both the Internet and the hosts by sending fewer than 2068 one ACK (acknowledgment) segment per data segment received; this is 2069 known as a "delayed ACK". 2071 A TCP SHOULD implement a delayed ACK, but an ACK should not be 2072 excessively delayed; in particular, the delay MUST be less than 0.5 2073 seconds, and in a stream of full-sized segments there SHOULD be an 2074 ACK for at least every second segment. Excessive delays on ACK's can 2075 disturb the round-trip timing and packet "clocking" algorithms. 2077 3.9. Interfaces 2079 There are of course two interfaces of concern: the user/TCP interface 2080 and the TCP/lower-level interface. We have a fairly elaborate model 2081 of the user/TCP interface, but the interface to the lower level 2082 protocol module is left unspecified here, since it will be specified 2083 in detail by the specification of the lower level protocol. For the 2084 case that the lower level is IP we note some of the parameter values 2085 that TCPs might use. 2087 3.9.1. User/TCP Interface 2089 The following functional description of user commands to the TCP is, 2090 at best, fictional, since every operating system will have different 2091 facilities. Consequently, we must warn readers that different TCP 2092 implementations may have different user interfaces. However, all 2093 TCPs must provide a certain minimum set of services to guarantee that 2094 all TCP implementations can support the same protocol hierarchy. 2095 This section specifies the functional interfaces required of all TCP 2096 implementations. 2098 TCP User Commands 2100 The following sections functionally characterize a USER/TCP 2101 interface. The notation used is similar to most procedure or 2102 function calls in high level languages, but this usage is not 2103 meant to rule out trap type service calls (e.g., SVCs, UUOs, 2104 EMTs). 2106 The user commands described below specify the basic functions the 2107 TCP must perform to support interprocess communication. 2108 Individual implementations must define their own exact format, and 2109 may provide combinations or subsets of the basic functions in 2110 single calls. In particular, some implementations may wish to 2111 automatically OPEN a connection on the first SEND or RECEIVE 2112 issued by the user for a given connection. 2114 In providing interprocess communication facilities, the TCP must 2115 not only accept commands, but must also return information to the 2116 processes it serves. The latter consists of: 2118 (a) general information about a connection (e.g., interrupts, 2119 remote close, binding of unspecified foreign socket). 2121 (b) replies to specific user commands indicating success or 2122 various types of failure. 2124 Open 2125 Format: OPEN (local port, foreign socket, active/passive [, 2126 timeout] [, precedence] [, security/compartment] [local IP 2127 address,] [, options]) -> local connection name 2129 We assume that the local TCP is aware of the identity of the 2130 processes it serves and will check the authority of the process 2131 to use the connection specified. Depending upon the 2132 implementation of the TCP, the local network and TCP 2133 identifiers for the source address will either be supplied by 2134 the TCP or the lower level protocol (e.g., IP). These 2135 considerations are the result of concern about security, to the 2136 extent that no TCP be able to masquerade as another one, and so 2137 on. Similarly, no process can masquerade as another without 2138 the collusion of the TCP. 2140 If the active/passive flag is set to passive, then this is a 2141 call to LISTEN for an incoming connection. A passive open may 2142 have either a fully specified foreign socket to wait for a 2143 particular connection or an unspecified foreign socket to wait 2144 for any call. A fully specified passive call can be made 2145 active by the subsequent execution of a SEND. 2147 A transmission control block (TCB) is created and partially 2148 filled in with data from the OPEN command parameters. 2150 Every passive OPEN call either creates a new connection record 2151 in LISTEN state, or it returns an error; it MUST NOT affect any 2152 previously created connection record. 2154 A TCP that supports multiple concurrent users MUST provide an 2155 OPEN call that will functionally allow an application to LISTEN 2156 on a port while a connection block with the same local port is 2157 in SYN-SENT or SYN-RECEIVED state. 2159 On an active OPEN command, the TCP will begin the procedure to 2160 synchronize (i.e., establish) the connection at once. 2162 The timeout, if present, permits the caller to set up a timeout 2163 for all data submitted to TCP. If data is not successfully 2164 delivered to the destination within the timeout period, the TCP 2165 will abort the connection. The present global default is five 2166 minutes. 2168 The TCP or some component of the operating system will verify 2169 the users authority to open a connection with the specified 2170 precedence or security/compartment. The absence of precedence 2171 or security/compartment specification in the OPEN call 2172 indicates the default values must be used. 2174 TCP will accept incoming requests as matching only if the 2175 security/compartment information is exactly the same and only 2176 if the precedence is equal to or higher than the precedence 2177 requested in the OPEN call. 2179 The precedence for the connection is the higher of the values 2180 requested in the OPEN call and received from the incoming 2181 request, and fixed at that value for the life of the 2182 connection.Implementers may want to give the user control of 2183 this precedence negotiation. For example, the user might be 2184 allowed to specify that the precedence must be exactly matched, 2185 or that any attempt to raise the precedence be confirmed by the 2186 user. 2188 A local connection name will be returned to the user by the 2189 TCP. The local connection name can then be used as a short 2190 hand term for the connection defined by the pair. 2193 The optional "local IP address" parameter MUST be supported to 2194 allow the specification of the local IP address. This enables 2195 applications that need to select the local IP address used when 2196 multihoming is present. 2198 A passive OPEN call with a specified "local IP address" 2199 parameter will await an incoming connection request to that 2200 address. If the parameter is unspecified, a passive OPEN will 2201 await an incoming connection request to any local IP address, 2202 and then bind the local IP address of the connection to the 2203 particular address that is used. 2205 For an active OPEN call, a specified "local IP address" 2206 parameter MUST be used for opening the connection. If the 2207 parameter is unspecified, the TCP will choose an appropriate 2208 local IP address (see RFC 1122 section 3.3.4.2). 2210 TODO - the previous and next paragraphs are mildly in conflict. 2211 Previous paragraph says that the TCP chooses an address, but 2212 next paragraph says that it asks IP to choose ... need to make 2213 this consistent 2215 If an application on a multihomed host does not specify the 2216 local IP address when actively opening a TCP connection, then 2217 the TCP MUST ask the IP layer to select a local IP address 2218 before sending the (first) SYN. See the function GET_SRCADDR() 2219 in Section 3.4 of RFC 1122. 2221 At all other times, a previous segment has either been sent or 2222 received on this connection, and TCP MUST use the same local 2223 address is used that was used in those previous segments. 2225 Send 2227 Format: SEND (local connection name, buffer address, byte 2228 count, PUSH flag, URGENT flag [,timeout]) 2230 This call causes the data contained in the indicated user 2231 buffer to be sent on the indicated connection. If the 2232 connection has not been opened, the SEND is considered an 2233 error. Some implementations may allow users to SEND first; in 2234 which case, an automatic OPEN would be done. For example, this 2235 might be one way for application data to be included in SYN 2236 segments. If the calling process is not authorized to use this 2237 connection, an error is returned. 2239 If the PUSH flag is set, the data must be transmitted promptly 2240 to the receiver, and the PUSH bit will be set in the last TCP 2241 segment created from the buffer. If the PUSH flag is not set, 2242 the data may be combined with data from subsequent SENDs for 2243 transmission efficiency. 2245 New applications SHOULD NOT set the URGENT flag [25] due to 2246 implementation differences and middlebox issues. 2248 If the URGENT flag is set, segments sent to the destination TCP 2249 will have the urgent pointer set. The receiving TCP will 2250 signal the urgent condition to the receiving process if the 2251 urgent pointer indicates that data preceding the urgent pointer 2252 has not been consumed by the receiving process. The purpose of 2253 urgent is to stimulate the receiver to process the urgent data 2254 and to indicate to the receiver when all the currently known 2255 urgent data has been received. The number of times the sending 2256 user's TCP signals urgent will not necessarily be equal to the 2257 number of times the receiving user will be notified of the 2258 presence of urgent data. 2260 If no foreign socket was specified in the OPEN, but the 2261 connection is established (e.g., because a LISTENing connection 2262 has become specific due to a foreign segment arriving for the 2263 local socket), then the designated buffer is sent to the 2264 implied foreign socket. Users who make use of OPEN with an 2265 unspecified foreign socket can make use of SEND without ever 2266 explicitly knowing the foreign socket address. 2268 However, if a SEND is attempted before the foreign socket 2269 becomes specified, an error will be returned. Users can use 2270 the STATUS call to determine the status of the connection. In 2271 some implementations the TCP may notify the user when an 2272 unspecified socket is bound. 2274 If a timeout is specified, the current user timeout for this 2275 connection is changed to the new one. 2277 In the simplest implementation, SEND would not return control 2278 to the sending process until either the transmission was 2279 complete or the timeout had been exceeded. However, this 2280 simple method is both subject to deadlocks (for example, both 2281 sides of the connection might try to do SENDs before doing any 2282 RECEIVEs) and offers poor performance, so it is not 2283 recommended. A more sophisticated implementation would return 2284 immediately to allow the process to run concurrently with 2285 network I/O, and, furthermore, to allow multiple SENDs to be in 2286 progress. Multiple SENDs are served in first come, first 2287 served order, so the TCP will queue those it cannot service 2288 immediately. 2290 We have implicitly assumed an asynchronous user interface in 2291 which a SEND later elicits some kind of SIGNAL or pseudo- 2292 interrupt from the serving TCP. An alternative is to return a 2293 response immediately. For instance, SENDs might return 2294 immediate local acknowledgment, even if the segment sent had 2295 not been acknowledged by the distant TCP. We could 2296 optimistically assume eventual success. If we are wrong, the 2297 connection will close anyway due to the timeout. In 2298 implementations of this kind (synchronous), there will still be 2299 some asynchronous signals, but these will deal with the 2300 connection itself, and not with specific segments or buffers. 2302 In order for the process to distinguish among error or success 2303 indications for different SENDs, it might be appropriate for 2304 the buffer address to be returned along with the coded response 2305 to the SEND request. TCP-to-user signals are discussed below, 2306 indicating the information which should be returned to the 2307 calling process. 2309 Receive 2311 Format: RECEIVE (local connection name, buffer address, byte 2312 count) -> byte count, urgent flag, push flag 2314 This command allocates a receiving buffer associated with the 2315 specified connection. If no OPEN precedes this command or the 2316 calling process is not authorized to use this connection, an 2317 error is returned. 2319 In the simplest implementation, control would not return to the 2320 calling program until either the buffer was filled, or some 2321 error occurred, but this scheme is highly subject to deadlocks. 2322 A more sophisticated implementation would permit several 2323 RECEIVEs to be outstanding at once. These would be filled as 2324 segments arrive. This strategy permits increased throughput at 2325 the cost of a more elaborate scheme (possibly asynchronous) to 2326 notify the calling program that a PUSH has been seen or a 2327 buffer filled. 2329 If enough data arrive to fill the buffer before a PUSH is seen, 2330 the PUSH flag will not be set in the response to the RECEIVE. 2331 The buffer will be filled with as much data as it can hold. If 2332 a PUSH is seen before the buffer is filled the buffer will be 2333 returned partially filled and PUSH indicated. 2335 If there is urgent data the user will have been informed as 2336 soon as it arrived via a TCP-to-user signal. The receiving 2337 user should thus be in "urgent mode". If the URGENT flag is 2338 on, additional urgent data remains. If the URGENT flag is off, 2339 this call to RECEIVE has returned all the urgent data, and the 2340 user may now leave "urgent mode". Note that data following the 2341 urgent pointer (non-urgent data) cannot be delivered to the 2342 user in the same buffer with preceding urgent data unless the 2343 boundary is clearly marked for the user. 2345 To distinguish among several outstanding RECEIVEs and to take 2346 care of the case that a buffer is not completely filled, the 2347 return code is accompanied by both a buffer pointer and a byte 2348 count indicating the actual length of the data received. 2350 Alternative implementations of RECEIVE might have the TCP 2351 allocate buffer storage, or the TCP might share a ring buffer 2352 with the user. 2354 Close 2356 Format: CLOSE (local connection name) 2358 This command causes the connection specified to be closed. If 2359 the connection is not open or the calling process is not 2360 authorized to use this connection, an error is returned. 2361 Closing connections is intended to be a graceful operation in 2362 the sense that outstanding SENDs will be transmitted (and 2363 retransmitted), as flow control permits, until all have been 2364 serviced. Thus, it should be acceptable to make several SEND 2365 calls, followed by a CLOSE, and expect all the data to be sent 2366 to the destination. It should also be clear that users should 2367 continue to RECEIVE on CLOSING connections, since the other 2368 side may be trying to transmit the last of its data. Thus, 2369 CLOSE means "I have no more to send" but does not mean "I will 2370 not receive any more." It may happen (if the user level 2371 protocol is not well thought out) that the closing side is 2372 unable to get rid of all its data before timing out. In this 2373 event, CLOSE turns into ABORT, and the closing TCP gives up. 2375 The user may CLOSE the connection at any time on his own 2376 initiative, or in response to various prompts from the TCP 2377 (e.g., remote close executed, transmission timeout exceeded, 2378 destination inaccessible). 2380 Because closing a connection requires communication with the 2381 foreign TCP, connections may remain in the closing state for a 2382 short time. Attempts to reopen the connection before the TCP 2383 replies to the CLOSE command will result in error responses. 2385 Close also implies push function. 2387 Status 2389 Format: STATUS (local connection name) -> status data 2391 This is an implementation dependent user command and could be 2392 excluded without adverse effect. Information returned would 2393 typically come from the TCB associated with the connection. 2395 This command returns a data block containing the following 2396 information: 2398 local socket, 2399 foreign socket, 2400 local connection name, 2401 receive window, 2402 send window, 2403 connection state, 2404 number of buffers awaiting acknowledgment, 2405 number of buffers pending receipt, 2406 urgent state, 2407 precedence, 2408 security/compartment, 2409 and transmission timeout. 2411 Depending on the state of the connection, or on the 2412 implementation itself, some of this information may not be 2413 available or meaningful. If the calling process is not 2414 authorized to use this connection, an error is returned. This 2415 prevents unauthorized processes from gaining information about 2416 a connection. 2418 Abort 2420 Format: ABORT (local connection name) 2422 This command causes all pending SENDs and RECEIVES to be 2423 aborted, the TCB to be removed, and a special RESET message to 2424 be sent to the TCP on the other side of the connection. 2425 Depending on the implementation, users may receive abort 2426 indications for each outstanding SEND or RECEIVE, or may simply 2427 receive an ABORT-acknowledgment. 2429 Flush 2431 Some TCP implementations have included a FLUSH call, which will 2432 empty the TCP send queue of any data for which the user has 2433 issued SEND calls but which is still to the right of the 2434 current send window. That is, it flushes as much queued send 2435 data as possible without losing sequence number 2436 synchronization. 2438 Set Differentiated Services Field (IPv4 TOS or IPv6 Traffic Class) 2440 The application layer MUST be able to specify the 2441 Differentiated Services field for segments that are sent on a 2442 connection. The Differentiated Services field includes the 2443 6-bit Differentiated Services Code Point (DSCP) value. It is 2444 not required, but the application SHOULD be able to change the 2445 Differentiated Services field during the connection lifetime. 2446 TCP SHOULD pass the current Differentiated Services field value 2447 without change to the IP layer, when it sends segments on the 2448 connection. 2450 The Differentiated Services field will be specified 2451 independently in each direction on the connection, so that the 2452 receiver application will specify the Differentiated Services 2453 field used for ACK segments. 2455 TCP MAY pass the most recently received Differentiated Services 2456 field up to the application. 2458 TCP-to-User Messages 2459 It is assumed that the operating system environment provides a 2460 means for the TCP to asynchronously signal the user program. 2461 When the TCP does signal a user program, certain information is 2462 passed to the user. Often in the specification the information 2463 will be an error message. In other cases there will be 2464 information relating to the completion of processing a SEND or 2465 RECEIVE or other user call. 2467 The following information is provided: 2469 Local Connection Name Always 2470 Response String Always 2471 Buffer Address Send & Receive 2472 Byte count (counts bytes received) Receive 2473 Push flag Receive 2474 Urgent flag Receive 2476 3.9.2. TCP/Lower-Level Interface 2478 The TCP calls on a lower level protocol module to actually send and 2479 receive information over a network. The two current standard 2480 Internet Protocol (IP) versions layered below TCP are IPv4 [1] and 2481 IPv6 [5]. 2483 If the lower level protocol is IPv4 it provides arguments for a type 2484 of service (used within the Differentiated Services field) and for a 2485 time to live. TCP uses the following settings for these parameters: 2487 Type of Service = Precedence: given by user, Delay: normal, 2488 Throughput: normal, Reliability: normal; or binary XXX00000, where 2489 XXX are the three bits determining precedence, e.g. 000 means 2490 routine precedence. TODO - this is pretty much wrong with regard 2491 to DiffServ, I think we should just say that the user can specify 2492 diffserv field (superset of DSCP) and mostly leave it at that, but 2493 will check with TCPM. It may also be worth noting that 1122 2494 permits DSCP to change during a connection (section 4.2.4.2) but 2495 the API might not allow it, and the application doesn't know about 2496 individual TCP segments anyways, so this could only be done on a 2497 "coarse" granularity at best. David Black noted that 7657 (sec 2498 5.1, 5.3, and 6) discuss this. Summary from Joe Touch is that it 2499 generally SHOULD NOT be changed, but the RFC series currently 2500 seems to be lacking any mention of when it might be appropriate to 2501 change (it's SHOUND NOT and not MUST NOT). 2503 Time to Live (TTL): The TTL value used to send TCP segments MUST 2504 be configurable. 2506 Note that RFC 793 specified one minute (60 seconds) as a 2507 constant for the TTL, because the assumed maximum segment 2508 lifetime was two minutes. This was intended to explicitly ask 2509 that a segment be destroyed if it cannot be delivered by the 2510 internet system within one minute. RFC 1122 changed this 2511 specification to require that the TTL be configurable. 2513 Any lower level protocol will have to provide the source address, 2514 destination address, and protocol fields, and some way to determine 2515 the "TCP length", both to provide the functional equivalent service 2516 of IP and to be used in the TCP checksum. 2518 When received options are passed up to TCP from the IP layer, TCP 2519 MUST ignore options that it does not understand. 2521 A TCP MAY support the Time Stamp and Record Route options. 2523 3.9.2.1. Source Routing 2525 If the lower level is IP (or other protocol that provides this 2526 feature) and source routing is used, the interface must allow the 2527 route information to be communicated. This is especially important 2528 so that the source and destination addresses used in the TCP checksum 2529 be the originating source and ultimate destination. It is also 2530 important to preserve the return route to answer connection requests. 2532 An application MUST be able to specify a source route when it 2533 actively opens a TCP connection, and this MUST take precedence over a 2534 source route received in a datagram. 2536 When a TCP connection is OPENed passively and a packet arrives with a 2537 completed IP Source Route option (containing a return route), TCP 2538 MUST save the return route and use it for all segments sent on this 2539 connection. If a different source route arrives in a later segment, 2540 the later definition SHOULD override the earlier one. 2542 3.9.2.2. ICMP Messages 2544 TCP MUST act on an ICMP error message passed up from the IP layer, 2545 directing it to the connection that created the error. The necessary 2546 demultiplexing information can be found in the IP header contained 2547 within the ICMP message. 2549 This applies to ICMPv6 in addition to IPv4 ICMP. 2551 [20] contains discussion of specific ICMP and ICMPv6 messages 2552 classified as either "soft" or "hard" errors that may bear different 2553 responses. Treatment for classes of ICMP messages is described 2554 below: 2556 Source Quench 2557 TCP MUST silently discard any received ICMP Source Quench messages. 2558 See [11] for discussion. 2560 Soft Errors 2561 For ICMP these include: Destination Unreachable -- codes 0, 1, 5, 2562 Time Exceeded -- codes 0, 1, and Parameter Problem. 2563 For ICMPv6 these include: Destination Unreachable -- codes 0 and 3, 2564 Time Exceeded -- codes 0, 1, and Parameter Problem -- codes 0, 1, 2 2565 Since these Unreachable messages indicate soft error conditions, 2566 TCP MUST NOT abort the connection, and it SHOULD make the 2567 information available to the application. 2569 Hard Errors 2570 For ICMP these include Destination Unreachable -- codes 2-4"> 2571 These are hard error conditions, so TCP SHOULD abort the 2572 connection. [20] notes that some implementations do not abort 2573 connections when an ICMP hard error is received for a connection 2574 that is in any of the synchronized states. 2576 Note that [20] section 4 describes widespread implementation behavior 2577 that treats soft errors as hard errors during connection 2578 establishment. 2580 3.10. Event Processing 2582 The processing depicted in this section is an example of one possible 2583 implementation. Other implementations may have slightly different 2584 processing sequences, but they should differ from those in this 2585 section only in detail, not in substance. 2587 The activity of the TCP can be characterized as responding to events. 2588 The events that occur can be cast into three categories: user calls, 2589 arriving segments, and timeouts. This section describes the 2590 processing the TCP does in response to each of the events. In many 2591 cases the processing required depends on the state of the connection. 2593 Events that occur: 2595 User Calls 2597 OPEN 2598 SEND 2599 RECEIVE 2600 CLOSE 2601 ABORT 2602 STATUS 2604 Arriving Segments 2606 SEGMENT ARRIVES 2608 Timeouts 2610 USER TIMEOUT 2611 RETRANSMISSION TIMEOUT 2612 TIME-WAIT TIMEOUT 2614 The model of the TCP/user interface is that user commands receive an 2615 immediate return and possibly a delayed response via an event or 2616 pseudo interrupt. In the following descriptions, the term "signal" 2617 means cause a delayed response. 2619 Error responses are given as character strings. For example, user 2620 commands referencing connections that do not exist receive "error: 2621 connection not open". 2623 Please note in the following that all arithmetic on sequence numbers, 2624 acknowledgment numbers, windows, et cetera, is modulo 2**32 the size 2625 of the sequence number space. Also note that "=<" means less than or 2626 equal to (modulo 2**32). 2628 A natural way to think about processing incoming segments is to 2629 imagine that they are first tested for proper sequence number (i.e., 2630 that their contents lie in the range of the expected "receive window" 2631 in the sequence number space) and then that they are generally queued 2632 and processed in sequence number order. 2634 When a segment overlaps other already received segments we 2635 reconstruct the segment to contain just the new data, and adjust the 2636 header fields to be consistent. 2638 Note that if no state change is mentioned the TCP stays in the same 2639 state. 2641 OPEN Call 2643 CLOSED STATE (i.e., TCB does not exist) 2645 Create a new transmission control block (TCB) to hold 2646 connection state information. Fill in local socket identifier, 2647 foreign socket, precedence, security/compartment, and user 2648 timeout information. Note that some parts of the foreign 2649 socket may be unspecified in a passive OPEN and are to be 2650 filled in by the parameters of the incoming SYN segment. 2651 Verify the security and precedence requested are allowed for 2652 this user, if not return "error: precedence not allowed" or 2653 "error: security/compartment not allowed." If passive enter 2654 the LISTEN state and return. If active and the foreign socket 2655 is unspecified, return "error: foreign socket unspecified"; if 2656 active and the foreign socket is specified, issue a SYN 2657 segment. An initial send sequence number (ISS) is selected. A 2658 SYN segment of the form is sent. Set 2659 SND.UNA to ISS, SND.NXT to ISS+1, enter SYN-SENT state, and 2660 return. 2662 If the caller does not have access to the local socket 2663 specified, return "error: connection illegal for this process". 2664 If there is no room to create a new connection, return "error: 2665 insufficient resources". 2667 LISTEN STATE 2669 If active and the foreign socket is specified, then change the 2670 connection from passive to active, select an ISS. Send a SYN 2671 segment, set SND.UNA to ISS, SND.NXT to ISS+1. Enter SYN-SENT 2672 state. Data associated with SEND may be sent with SYN segment 2673 or queued for transmission after entering ESTABLISHED state. 2674 The urgent bit if requested in the command must be sent with 2675 the data segments sent as a result of this command. If there 2676 is no room to queue the request, respond with "error: 2677 insufficient resources". If Foreign socket was not specified, 2678 then return "error: foreign socket unspecified". 2680 SYN-SENT STATE 2681 SYN-RECEIVED STATE 2682 ESTABLISHED STATE 2683 FIN-WAIT-1 STATE 2684 FIN-WAIT-2 STATE 2685 CLOSE-WAIT STATE 2686 CLOSING STATE 2687 LAST-ACK STATE 2688 TIME-WAIT STATE 2690 Return "error: connection already exists". 2692 SEND Call 2694 CLOSED STATE (i.e., TCB does not exist) 2696 If the user does not have access to such a connection, then 2697 return "error: connection illegal for this process". 2699 Otherwise, return "error: connection does not exist". 2701 LISTEN STATE 2703 If the foreign socket is specified, then change the connection 2704 from passive to active, select an ISS. Send a SYN segment, set 2705 SND.UNA to ISS, SND.NXT to ISS+1. Enter SYN-SENT state. Data 2706 associated with SEND may be sent with SYN segment or queued for 2707 transmission after entering ESTABLISHED state. The urgent bit 2708 if requested in the command must be sent with the data segments 2709 sent as a result of this command. If there is no room to queue 2710 the request, respond with "error: insufficient resources". If 2711 Foreign socket was not specified, then return "error: foreign 2712 socket unspecified". 2714 SYN-SENT STATE 2715 SYN-RECEIVED STATE 2717 Queue the data for transmission after entering ESTABLISHED 2718 state. If no space to queue, respond with "error: insufficient 2719 resources". 2721 ESTABLISHED STATE 2722 CLOSE-WAIT STATE 2724 Segmentize the buffer and send it with a piggybacked 2725 acknowledgment (acknowledgment value = RCV.NXT). If there is 2726 insufficient space to remember this buffer, simply return 2727 "error: insufficient resources". 2729 If the urgent flag is set, then SND.UP <- SND.NXT and set the 2730 urgent pointer in the outgoing segments. 2732 FIN-WAIT-1 STATE 2733 FIN-WAIT-2 STATE 2734 CLOSING STATE 2735 LAST-ACK STATE 2736 TIME-WAIT STATE 2738 Return "error: connection closing" and do not service request. 2740 RECEIVE Call 2742 CLOSED STATE (i.e., TCB does not exist) 2744 If the user does not have access to such a connection, return 2745 "error: connection illegal for this process". 2747 Otherwise return "error: connection does not exist". 2749 LISTEN STATE 2750 SYN-SENT STATE 2751 SYN-RECEIVED STATE 2753 Queue for processing after entering ESTABLISHED state. If 2754 there is no room to queue this request, respond with "error: 2755 insufficient resources". 2757 ESTABLISHED STATE 2758 FIN-WAIT-1 STATE 2759 FIN-WAIT-2 STATE 2761 If insufficient incoming segments are queued to satisfy the 2762 request, queue the request. If there is no queue space to 2763 remember the RECEIVE, respond with "error: insufficient 2764 resources". 2766 Reassemble queued incoming segments into receive buffer and 2767 return to user. Mark "push seen" (PUSH) if this is the case. 2769 If RCV.UP is in advance of the data currently being passed to 2770 the user notify the user of the presence of urgent data. 2772 When the TCP takes responsibility for delivering data to the 2773 user that fact must be communicated to the sender via an 2774 acknowledgment. The formation of such an acknowledgment is 2775 described below in the discussion of processing an incoming 2776 segment. 2778 CLOSE-WAIT STATE 2780 Since the remote side has already sent FIN, RECEIVEs must be 2781 satisfied by text already on hand, but not yet delivered to the 2782 user. If no text is awaiting delivery, the RECEIVE will get a 2783 "error: connection closing" response. Otherwise, any remaining 2784 text can be used to satisfy the RECEIVE. 2786 CLOSING STATE 2787 LAST-ACK STATE 2788 TIME-WAIT STATE 2790 Return "error: connection closing". 2792 CLOSE Call 2794 CLOSED STATE (i.e., TCB does not exist) 2796 If the user does not have access to such a connection, return 2797 "error: connection illegal for this process". 2799 Otherwise, return "error: connection does not exist". 2801 LISTEN STATE 2803 Any outstanding RECEIVEs are returned with "error: closing" 2804 responses. Delete TCB, enter CLOSED state, and return. 2806 SYN-SENT STATE 2808 Delete the TCB and return "error: closing" responses to any 2809 queued SENDs, or RECEIVEs. 2811 SYN-RECEIVED STATE 2813 If no SENDs have been issued and there is no pending data to 2814 send, then form a FIN segment and send it, and enter FIN-WAIT-1 2815 state; otherwise queue for processing after entering 2816 ESTABLISHED state. 2818 ESTABLISHED STATE 2820 Queue this until all preceding SENDs have been segmentized, 2821 then form a FIN segment and send it. In any case, enter FIN- 2822 WAIT-1 state. 2824 FIN-WAIT-1 STATE 2825 FIN-WAIT-2 STATE 2827 Strictly speaking, this is an error and should receive a 2828 "error: connection closing" response. An "ok" response would 2829 be acceptable, too, as long as a second FIN is not emitted (the 2830 first FIN may be retransmitted though). 2832 CLOSE-WAIT STATE 2834 Queue this request until all preceding SENDs have been 2835 segmentized; then send a FIN segment, enter LAST-ACK state. 2837 CLOSING STATE 2838 LAST-ACK STATE 2839 TIME-WAIT STATE 2840 Respond with "error: connection closing". 2842 ABORT Call 2844 CLOSED STATE (i.e., TCB does not exist) 2846 If the user should not have access to such a connection, return 2847 "error: connection illegal for this process". 2849 Otherwise return "error: connection does not exist". 2851 LISTEN STATE 2853 Any outstanding RECEIVEs should be returned with "error: 2854 connection reset" responses. Delete TCB, enter CLOSED state, 2855 and return. 2857 SYN-SENT STATE 2859 All queued SENDs and RECEIVEs should be given "connection 2860 reset" notification, delete the TCB, enter CLOSED state, and 2861 return. 2863 SYN-RECEIVED STATE 2864 ESTABLISHED STATE 2865 FIN-WAIT-1 STATE 2866 FIN-WAIT-2 STATE 2867 CLOSE-WAIT STATE 2869 Send a reset segment: 2871 2873 All queued SENDs and RECEIVEs should be given "connection 2874 reset" notification; all segments queued for transmission 2875 (except for the RST formed above) or retransmission should be 2876 flushed, delete the TCB, enter CLOSED state, and return. 2878 CLOSING STATE LAST-ACK STATE TIME-WAIT STATE 2880 Respond with "ok" and delete the TCB, enter CLOSED state, and 2881 return. 2883 STATUS Call 2885 CLOSED STATE (i.e., TCB does not exist) 2887 If the user should not have access to such a connection, return 2888 "error: connection illegal for this process". 2890 Otherwise return "error: connection does not exist". 2892 LISTEN STATE 2894 Return "state = LISTEN", and the TCB pointer. 2896 SYN-SENT STATE 2898 Return "state = SYN-SENT", and the TCB pointer. 2900 SYN-RECEIVED STATE 2902 Return "state = SYN-RECEIVED", and the TCB pointer. 2904 ESTABLISHED STATE 2906 Return "state = ESTABLISHED", and the TCB pointer. 2908 FIN-WAIT-1 STATE 2910 Return "state = FIN-WAIT-1", and the TCB pointer. 2912 FIN-WAIT-2 STATE 2914 Return "state = FIN-WAIT-2", and the TCB pointer. 2916 CLOSE-WAIT STATE 2918 Return "state = CLOSE-WAIT", and the TCB pointer. 2920 CLOSING STATE 2922 Return "state = CLOSING", and the TCB pointer. 2924 LAST-ACK STATE 2926 Return "state = LAST-ACK", and the TCB pointer. 2928 TIME-WAIT STATE 2930 Return "state = TIME-WAIT", and the TCB pointer. 2932 SEGMENT ARRIVES 2934 If the state is CLOSED (i.e., TCB does not exist) then 2936 all data in the incoming segment is discarded. An incoming 2937 segment containing a RST is discarded. An incoming segment not 2938 containing a RST causes a RST to be sent in response. The 2939 acknowledgment and sequence field values are selected to make 2940 the reset sequence acceptable to the TCP that sent the 2941 offending segment. 2943 If the ACK bit is off, sequence number zero is used, 2945 2947 If the ACK bit is on, 2949 2951 Return. 2953 If the state is LISTEN then 2955 first check for an RST 2957 An incoming RST should be ignored. Return. 2959 second check for an ACK 2961 Any acknowledgment is bad if it arrives on a connection 2962 still in the LISTEN state. An acceptable reset segment 2963 should be formed for any arriving ACK-bearing segment. The 2964 RST should be formatted as follows: 2966 2968 Return. 2970 third check for a SYN 2972 If the SYN bit is set, check the security. If the security/ 2973 compartment on the incoming segment does not exactly match 2974 the security/compartment in the TCB then send a reset and 2975 return. 2977 2979 If the SEG.PRC is greater than the TCB.PRC then if allowed 2980 by the user and the system set TCB.PRC<-SEG.PRC, if not 2981 allowed send a reset and return. 2983 2985 If the SEG.PRC is less than the TCB.PRC then continue. 2987 Set RCV.NXT to SEG.SEQ+1, IRS is set to SEG.SEQ and any 2988 other control or text should be queued for processing later. 2989 ISS should be selected and a SYN segment sent of the form: 2991 2993 SND.NXT is set to ISS+1 and SND.UNA to ISS. The connection 2994 state should be changed to SYN-RECEIVED. Note that any 2995 other incoming control or data (combined with SYN) will be 2996 processed in the SYN-RECEIVED state, but processing of SYN 2997 and ACK should not be repeated. If the listen was not fully 2998 specified (i.e., the foreign socket was not fully 2999 specified), then the unspecified fields should be filled in 3000 now. 3002 fourth other text or control 3004 Any other control or text-bearing segment (not containing 3005 SYN) must have an ACK and thus would be discarded by the ACK 3006 processing. An incoming RST segment could not be valid, 3007 since it could not have been sent in response to anything 3008 sent by this incarnation of the connection. So you are 3009 unlikely to get here, but if you do, drop the segment, and 3010 return. 3012 If the state is SYN-SENT then 3014 first check the ACK bit 3016 If the ACK bit is set 3018 If SEG.ACK =< ISS, or SEG.ACK > SND.NXT, send a reset 3019 (unless the RST bit is set, if so drop the segment and 3020 return) 3022 3024 and discard the segment. Return. 3026 If SND.UNA < SEG.ACK =< SND.NXT then the ACK is 3027 acceptable. (TODO: in processing Errata ID 3300, it was 3028 noted that some stacks in the wild that do not send data 3029 on the SYN are just checking that SEG.ACK == SND.NXT ... 3030 think about whether anything should be said about that 3031 here) 3033 second check the RST bit 3035 If the RST bit is set 3037 A potential blind reset attack is described in RFC 5961 3038 [24], with the mitigation that a TCP implementation 3039 SHOULD first check that the sequence number exactly 3040 matches RCV.NXT prior to executing the action in the next 3041 paragraph. 3043 If the ACK was acceptable then signal the user "error: 3044 connection reset", drop the segment, enter CLOSED state, 3045 delete TCB, and return. Otherwise (no ACK) drop the 3046 segment and return. 3048 third check the security and precedence 3050 If the security/compartment in the segment does not exactly 3051 match the security/compartment in the TCB, send a reset 3053 If there is an ACK 3055 3057 Otherwise 3059 3061 If there is an ACK 3063 The precedence in the segment must match the precedence 3064 in the TCB, if not, send a reset 3066 3068 If there is no ACK 3070 If the precedence in the segment is higher than the 3071 precedence in the TCB then if allowed by the user and the 3072 system raise the precedence in the TCB to that in the 3073 segment, if not allowed to raise the prec then send a 3074 reset. 3076 3078 If the precedence in the segment is lower than the 3079 precedence in the TCB continue. 3081 If a reset was sent, discard the segment and return. 3083 fourth check the SYN bit 3085 This step should be reached only if the ACK is ok, or there 3086 is no ACK, and it the segment did not contain a RST. 3088 If the SYN bit is on and the security/compartment and 3089 precedence are acceptable then, RCV.NXT is set to SEG.SEQ+1, 3090 IRS is set to SEG.SEQ. SND.UNA should be advanced to equal 3091 SEG.ACK (if there is an ACK), and any segments on the 3092 retransmission queue which are thereby acknowledged should 3093 be removed. 3095 If SND.UNA > ISS (our SYN has been ACKed), change the 3096 connection state to ESTABLISHED, form an ACK segment 3098 3100 and send it. Data or controls which were queued for 3101 transmission may be included. If there are other controls 3102 or text in the segment then continue processing at the sixth 3103 step below where the URG bit is checked, otherwise return. 3105 Otherwise enter SYN-RECEIVED, form a SYN,ACK segment 3107 3109 and send it. Set the variables: 3111 SND.WND <- SEG.WND 3112 SND.WL1 <- SEG.SEQ 3113 SND.WL2 <- SEG.ACK 3115 If there are other controls or text in the segment, queue 3116 them for processing after the ESTABLISHED state has been 3117 reached, return. 3119 Note that it is legal to send and receive application data 3120 on SYN segments (this is the "text in the segment" mentioned 3121 above. There has been significant misinformation and 3122 misunderstanding of this topic historically. Some firewalls 3123 and security devices consider this suspicious. However, the 3124 capability was used in T/TCP [15] and is used in TCP Fast 3125 Open (TFO) [32], so is important for implementations and 3126 network devices to permit. 3128 fifth, if neither of the SYN or RST bits is set then drop the 3129 segment and return. 3131 Otherwise, 3133 first check sequence number 3135 SYN-RECEIVED STATE 3136 ESTABLISHED STATE 3137 FIN-WAIT-1 STATE 3138 FIN-WAIT-2 STATE 3139 CLOSE-WAIT STATE 3140 CLOSING STATE 3141 LAST-ACK STATE 3142 TIME-WAIT STATE 3144 Segments are processed in sequence. Initial tests on 3145 arrival are used to discard old duplicates, but further 3146 processing is done in SEG.SEQ order. If a segment's 3147 contents straddle the boundary between old and new, only the 3148 new parts should be processed. 3150 There are four cases for the acceptability test for an 3151 incoming segment: 3153 Segment Receive Test 3154 Length Window 3155 ------- ------- ------------------------------------------- 3157 0 0 SEG.SEQ = RCV.NXT 3159 0 >0 RCV.NXT =< SEG.SEQ < RCV.NXT+RCV.WND 3161 >0 0 not acceptable 3163 >0 >0 RCV.NXT =< SEG.SEQ < RCV.NXT+RCV.WND 3164 or RCV.NXT =< SEG.SEQ+SEG.LEN-1 < RCV.NXT+RCV.WND 3166 If the RCV.WND is zero, no segments will be acceptable, but 3167 special allowance should be made to accept valid ACKs, URGs 3168 and RSTs. 3170 If an incoming segment is not acceptable, an acknowledgment 3171 should be sent in reply (unless the RST bit is set, if so 3172 drop the segment and return): 3174 3176 After sending the acknowledgment, drop the unacceptable 3177 segment and return. 3179 Note that for the TIME-WAIT state, there is an improved 3180 algorithm described in [26] for handling incoming SYN 3181 segments, that utilizes timestamps rather than relying on 3182 the sequence number check described here. When the improved 3183 algorithm is implemented, the logic above is not applicable 3184 for incoming SYN segments with timestamp options, received 3185 on a connection in the TIME-WAIT state. 3187 In the following it is assumed that the segment is the 3188 idealized segment that begins at RCV.NXT and does not exceed 3189 the window. One could tailor actual segments to fit this 3190 assumption by trimming off any portions that lie outside the 3191 window (including SYN and FIN), and only processing further 3192 if the segment then begins at RCV.NXT. Segments with higher 3193 beginning sequence numbers should be held for later 3194 processing. 3196 In general, the processing of received segments MUST be 3197 implemented to aggregate ACK segments whenever possible. 3198 For example, if the TCP is processing a series of queued 3199 segments, it MUST process them all before sending any ACK 3200 segments. (TODO - see if there's a better place for this 3201 paragraph - taken from RFC1122) 3203 second check the RST bit, 3205 RFC 5961 section 3 describes a potential blind reset attack 3206 and optional mitigation approach that SHOULD be implemented. 3207 For stacks implementing RFC 5961, the three checks below 3208 apply, otherwise processesing for these states is indicated 3209 further below. 3211 1) If the RST bit is set and the sequence number is 3212 outside the current receive window, silently drop the 3213 segment. 3215 2) If the RST bit is set and the sequence number exactly 3216 matches the next expected sequence number (RCV.NXT), then 3217 TCP MUST reset the connection in the manner prescribed 3218 below according to the connection state. 3220 3) If the RST bit is set and the sequence number does not 3221 exactly match the next expected sequence value, yet is 3222 within the current receive window, TCP MUST send an 3223 acknowledgement (challenge ACK): 3225 3227 After sending the challenge ACK, TCP MUST drop the 3228 unacceptable segment and stop processing the incoming 3229 packet further. Note that RFC 5961 and Errata ID 4772 3230 contain additional considerations for ACK throttling in 3231 an implementation. 3233 SYN-RECEIVED STATE 3235 If the RST bit is set 3237 If this connection was initiated with a passive OPEN 3238 (i.e., came from the LISTEN state), then return this 3239 connection to LISTEN state and return. The user need 3240 not be informed. If this connection was initiated 3241 with an active OPEN (i.e., came from SYN-SENT state) 3242 then the connection was refused, signal the user 3243 "connection refused". In either case, all segments on 3244 the retransmission queue should be removed. And in 3245 the active OPEN case, enter the CLOSED state and 3246 delete the TCB, and return. 3248 ESTABLISHED 3249 FIN-WAIT-1 3250 FIN-WAIT-2 3251 CLOSE-WAIT 3253 If the RST bit is set then, any outstanding RECEIVEs and 3254 SEND should receive "reset" responses. All segment 3255 queues should be flushed. Users should also receive an 3256 unsolicited general "connection reset" signal. Enter the 3257 CLOSED state, delete the TCB, and return. 3259 CLOSING STATE 3260 LAST-ACK STATE 3261 TIME-WAIT 3262 If the RST bit is set then, enter the CLOSED state, 3263 delete the TCB, and return. 3265 third check security and precedence 3267 SYN-RECEIVED 3269 If the security/compartment and precedence in the segment 3270 do not exactly match the security/compartment and 3271 precedence in the TCB then send a reset, and return. 3273 ESTABLISHED 3274 FIN-WAIT-1 3275 FIN-WAIT-2 3276 CLOSE-WAIT 3277 CLOSING 3278 LAST-ACK 3279 TIME-WAIT 3281 If the security/compartment and precedence in the segment 3282 do not exactly match the security/compartment and 3283 precedence in the TCB then send a reset, any outstanding 3284 RECEIVEs and SEND should receive "reset" responses. All 3285 segment queues should be flushed. Users should also 3286 receive an unsolicited general "connection reset" signal. 3287 Enter the CLOSED state, delete the TCB, and return. 3289 Note this check is placed following the sequence check to 3290 prevent a segment from an old connection between these ports 3291 with a different security or precedence from causing an 3292 abort of the current connection. 3294 fourth, check the SYN bit, 3296 SYN-RECEIVED 3298 If the connection was initiated with a passive OPEN, then 3299 return this connection to the LISTEN state and return. 3300 Otherwise, handle per the directions for synchronized 3301 states below. 3303 ESTABLISHED STATE 3304 FIN-WAIT STATE-1 3305 FIN-WAIT STATE-2 3306 CLOSE-WAIT STATE 3307 CLOSING STATE 3308 LAST-ACK STATE 3309 TIME-WAIT STATE 3311 If the SYN bit is set in these synchronized states, it 3312 may be either a legitimate new connection attempt (e.g. 3313 in the case of TIME-WAIT), an error where the connection 3314 should be reset, or the result of an attack attempt, as 3315 described in RFC 5961 [24]. For the TIME-WAIT state, new 3316 connections can be accepted if the timestamp option is 3317 used and meets expectations (per [26]). For all other 3318 caess, RFC 5961 provides a mitigation that SHOULD be 3319 implemented, though there are alternatives (see 3320 Section 6). RFC 5961 recommends that in these 3321 synchronized states, if the SYN bit is set, irrespective 3322 of the sequence number, TCP MUST send a "challenge ACK" 3323 to the remote peer: 3325 3327 After sending the acknowledgement, TCP MUST drop the 3328 unacceptable segment and stop processing further. Note 3329 that RFC 5961 and Errata ID 4772 contain additional ACK 3330 throttling notes for an implementation. 3332 For implementations that do not follow RFC 5961, the 3333 original RFC 793 behavior follows in this paragraph. If 3334 the SYN is in the window it is an error, send a reset, 3335 any outstanding RECEIVEs and SEND should receive "reset" 3336 responses, all segment queues should be flushed, the user 3337 should also receive an unsolicited general "connection 3338 reset" signal, enter the CLOSED state, delete the TCB, 3339 and return. 3341 If the SYN is not in the window this step would not be 3342 reached and an ack would have been sent in the first step 3343 (sequence number check). 3345 fifth check the ACK field, 3347 if the ACK bit is off drop the segment and return 3349 if the ACK bit is on 3351 RFC 5961 section 5 describes a potential blind data 3352 injection attack, and mitigation that implementations MAY 3353 choose to include. TCP stacks that implement RFC 5961 3354 MUST add an input check that the ACK value is acceptable 3355 only if it is in the range of ((SND.UNA - MAX.SND.WND) =< 3356 SEG.ACK =< SND.NXT). All incoming segments whose ACK 3357 value doesn't satisfy the above condition MUST be 3358 discarded and an ACK sent back. The new state variable 3359 MAX.SND.WND is defined as the largest window that the 3360 local sender has ever received from its peer (subject to 3361 window scaling) or may be hard-coded to a maximum 3362 permissible window value. When the ACK value is 3363 acceptable, the processing per-state below applies: 3365 SYN-RECEIVED STATE 3367 If SND.UNA < SEG.ACK =< SND.NXT then enter ESTABLISHED 3368 state and continue processing with variables below set 3369 to: 3371 SND.WND <- SEG.WND 3372 SND.WL1 <- SEG.SEQ 3373 SND.WL2 <- SEG.ACK 3375 If the segment acknowledgment is not acceptable, 3376 form a reset segment, 3378 3380 and send it. 3382 ESTABLISHED STATE 3384 If SND.UNA < SEG.ACK =< SND.NXT then, set SND.UNA <- 3385 SEG.ACK. Any segments on the retransmission queue 3386 which are thereby entirely acknowledged are removed. 3387 Users should receive positive acknowledgments for 3388 buffers which have been SENT and fully acknowledged 3389 (i.e., SEND buffer should be returned with "ok" 3390 response). If the ACK is a duplicate (SEG.ACK =< 3391 SND.UNA), it can be ignored. If the ACK acks 3392 something not yet sent (SEG.ACK > SND.NXT) then send 3393 an ACK, drop the segment, and return. 3395 If SND.UNA =< SEG.ACK =< SND.NXT, the send window 3396 should be updated. If (SND.WL1 < SEG.SEQ or (SND.WL1 3397 = SEG.SEQ and SND.WL2 =< SEG.ACK)), set SND.WND <- 3398 SEG.WND, set SND.WL1 <- SEG.SEQ, and set SND.WL2 <- 3399 SEG.ACK. 3401 Note that SND.WND is an offset from SND.UNA, that 3402 SND.WL1 records the sequence number of the last 3403 segment used to update SND.WND, and that SND.WL2 3404 records the acknowledgment number of the last segment 3405 used to update SND.WND. The check here prevents using 3406 old segments to update the window. 3408 FIN-WAIT-1 STATE 3410 In addition to the processing for the ESTABLISHED 3411 state, if our FIN is now acknowledged then enter FIN- 3412 WAIT-2 and continue processing in that state. 3414 FIN-WAIT-2 STATE 3416 In addition to the processing for the ESTABLISHED 3417 state, if the retransmission queue is empty, the 3418 user's CLOSE can be acknowledged ("ok") but do not 3419 delete the TCB. 3421 CLOSE-WAIT STATE 3423 Do the same processing as for the ESTABLISHED state. 3425 CLOSING STATE 3427 In addition to the processing for the ESTABLISHED 3428 state, if the ACK acknowledges our FIN then enter the 3429 TIME-WAIT state, otherwise ignore the segment. 3431 LAST-ACK STATE 3433 The only thing that can arrive in this state is an 3434 acknowledgment of our FIN. If our FIN is now 3435 acknowledged, delete the TCB, enter the CLOSED state, 3436 and return. 3438 TIME-WAIT STATE 3440 The only thing that can arrive in this state is a 3441 retransmission of the remote FIN. Acknowledge it, and 3442 restart the 2 MSL timeout. 3444 sixth, check the URG bit, 3446 ESTABLISHED STATE 3447 FIN-WAIT-1 STATE 3448 FIN-WAIT-2 STATE 3450 If the URG bit is set, RCV.UP <- max(RCV.UP,SEG.UP), and 3451 signal the user that the remote side has urgent data if 3452 the urgent pointer (RCV.UP) is in advance of the data 3453 consumed. If the user has already been signaled (or is 3454 still in the "urgent mode") for this continuous sequence 3455 of urgent data, do not signal the user again. 3457 CLOSE-WAIT STATE 3458 CLOSING STATE 3459 LAST-ACK STATE 3460 TIME-WAIT 3462 This should not occur, since a FIN has been received from 3463 the remote side. Ignore the URG. 3465 seventh, process the segment text, 3467 ESTABLISHED STATE 3468 FIN-WAIT-1 STATE 3469 FIN-WAIT-2 STATE 3471 Once in the ESTABLISHED state, it is possible to deliver 3472 segment text to user RECEIVE buffers. Text from segments 3473 can be moved into buffers until either the buffer is full 3474 or the segment is empty. If the segment empties and 3475 carries an PUSH flag, then the user is informed, when the 3476 buffer is returned, that a PUSH has been received. 3478 When the TCP takes responsibility for delivering the data 3479 to the user it must also acknowledge the receipt of the 3480 data. 3482 Once the TCP takes responsibility for the data it 3483 advances RCV.NXT over the data accepted, and adjusts 3484 RCV.WND as appropriate to the current buffer 3485 availability. The total of RCV.NXT and RCV.WND should 3486 not be reduced. 3488 A TCP MAY send an ACK segment acknowledging RCV.NXT when 3489 a valid segment arrives that is in the window but not at 3490 the left window edge. 3492 Please note the window management suggestions in section 3493 3.7. 3495 Send an acknowledgment of the form: 3497 3499 This acknowledgment should be piggybacked on a segment 3500 being transmitted if possible without incurring undue 3501 delay. 3503 CLOSE-WAIT STATE 3504 CLOSING STATE 3505 LAST-ACK STATE 3506 TIME-WAIT STATE 3508 This should not occur, since a FIN has been received from 3509 the remote side. Ignore the segment text. 3511 eighth, check the FIN bit, 3513 Do not process the FIN if the state is CLOSED, LISTEN or 3514 SYN-SENT since the SEG.SEQ cannot be validated; drop the 3515 segment and return. 3517 If the FIN bit is set, signal the user "connection closing" 3518 and return any pending RECEIVEs with same message, advance 3519 RCV.NXT over the FIN, and send an acknowledgment for the 3520 FIN. Note that FIN implies PUSH for any segment text not 3521 yet delivered to the user. 3523 SYN-RECEIVED STATE 3524 ESTABLISHED STATE 3526 Enter the CLOSE-WAIT state. 3528 FIN-WAIT-1 STATE 3530 If our FIN has been ACKed (perhaps in this segment), 3531 then enter TIME-WAIT, start the time-wait timer, turn 3532 off the other timers; otherwise enter the CLOSING 3533 state. 3535 FIN-WAIT-2 STATE 3537 Enter the TIME-WAIT state. Start the time-wait timer, 3538 turn off the other timers. 3540 CLOSE-WAIT STATE 3542 Remain in the CLOSE-WAIT state. 3544 CLOSING STATE 3546 Remain in the CLOSING state. 3548 LAST-ACK STATE 3550 Remain in the LAST-ACK state. 3552 TIME-WAIT STATE 3554 Remain in the TIME-WAIT state. Restart the 2 MSL 3555 time-wait timeout. 3557 and return. 3559 USER TIMEOUT 3561 USER TIMEOUT 3563 For any state if the user timeout expires, flush all queues, 3564 signal the user "error: connection aborted due to user timeout" 3565 in general and for any outstanding calls, delete the TCB, enter 3566 the CLOSED state and return. 3568 RETRANSMISSION TIMEOUT 3570 For any state if the retransmission timeout expires on a 3571 segment in the retransmission queue, send the segment at the 3572 front of the retransmission queue again, reinitialize the 3573 retransmission timer, and return. 3575 TIME-WAIT TIMEOUT 3577 If the time-wait timeout expires on a connection delete the 3578 TCB, enter the CLOSED state and return. 3580 3.11. Glossary 3582 1822 BBN Report 1822, "The Specification of the Interconnection of 3583 a Host and an IMP". The specification of interface between a 3584 host and the ARPANET. 3586 ACK 3587 A control bit (acknowledge) occupying no sequence space, 3588 which indicates that the acknowledgment field of this segment 3589 specifies the next sequence number the sender of this segment 3590 is expecting to receive, hence acknowledging receipt of all 3591 previous sequence numbers. 3593 ARPANET message 3594 The unit of transmission between a host and an IMP in the 3595 ARPANET. The maximum size is about 1012 octets (8096 bits). 3597 ARPANET packet 3598 A unit of transmission used internally in the ARPANET between 3599 IMPs. The maximum size is about 126 octets (1008 bits). 3601 connection 3602 A logical communication path identified by a pair of sockets. 3604 datagram 3605 A message sent in a packet switched computer communications 3606 network. 3608 Destination Address 3609 The destination address, usually the network and host 3610 identifiers. 3612 FIN 3613 A control bit (finis) occupying one sequence number, which 3614 indicates that the sender will send no more data or control 3615 occupying sequence space. 3617 fragment 3618 A portion of a logical unit of data, in particular an 3619 internet fragment is a portion of an internet datagram. 3621 FTP 3622 A file transfer protocol. 3624 header 3625 Control information at the beginning of a message, segment, 3626 fragment, packet or block of data. 3628 host 3629 A computer. In particular a source or destination of 3630 messages from the point of view of the communication network. 3632 Identification 3633 An Internet Protocol field. This identifying value assigned 3634 by the sender aids in assembling the fragments of a datagram. 3636 IMP 3637 The Interface Message Processor, the packet switch of the 3638 ARPANET. 3640 internet address 3641 A source or destination address specific to the host level. 3643 internet datagram 3644 The unit of data exchanged between an internet module and the 3645 higher level protocol together with the internet header. 3647 internet fragment 3648 A portion of the data of an internet datagram with an 3649 internet header. 3651 IP 3652 Internet Protocol. 3654 IRS 3655 The Initial Receive Sequence number. The first sequence 3656 number used by the sender on a connection. 3658 ISN 3659 The Initial Sequence Number. The first sequence number used 3660 on a connection, (either ISS or IRS). Selected in a way that 3661 is unique within a given period of time and is unpredictable 3662 to attackers. 3664 ISS 3665 The Initial Send Sequence number. The first sequence number 3666 used by the sender on a connection. 3668 leader 3669 Control information at the beginning of a message or block of 3670 data. In particular, in the ARPANET, the control information 3671 on an ARPANET message at the host-IMP interface. 3673 left sequence 3674 This is the next sequence number to be acknowledged by the 3675 data receiving TCP (or the lowest currently unacknowledged 3676 sequence number) and is sometimes referred to as the left 3677 edge of the send window. 3679 local packet 3680 The unit of transmission within a local network. 3682 module 3683 An implementation, usually in software, of a protocol or 3684 other procedure. 3686 MSL 3687 Maximum Segment Lifetime, the time a TCP segment can exist in 3688 the internetwork system. Arbitrarily defined to be 2 3689 minutes. 3691 octet 3692 An eight bit byte. 3694 Options 3695 An Option field may contain several options, and each option 3696 may be several octets in length. The options are used 3697 primarily in testing situations; for example, to carry 3698 timestamps. Both the Internet Protocol and TCP provide for 3699 options fields. -- TODO not primarily testing anymore! 3701 packet 3702 A package of data with a header which may or may not be 3703 logically complete. More often a physical packaging than a 3704 logical packaging of data. 3706 port 3707 The portion of a socket that specifies which logical input or 3708 output channel of a process is associated with the data. 3710 process 3711 A program in execution. A source or destination of data from 3712 the point of view of the TCP or other host-to-host protocol. 3714 PUSH 3715 A control bit occupying no sequence space, indicating that 3716 this segment contains data that must be pushed through to the 3717 receiving user. 3719 RCV.NXT 3720 receive next sequence number 3722 RCV.UP 3723 receive urgent pointer 3725 RCV.WND 3726 receive window 3728 receive next sequence number 3729 This is the next sequence number the local TCP is expecting 3730 to receive. 3732 receive window 3733 This represents the sequence numbers the local (receiving) 3734 TCP is willing to receive. Thus, the local TCP considers 3735 that segments overlapping the range RCV.NXT to RCV.NXT + 3736 RCV.WND - 1 carry acceptable data or control. Segments 3737 containing sequence numbers entirely outside of this range 3738 are considered duplicates and discarded. 3740 RST 3741 A control bit (reset), occupying no sequence space, 3742 indicating that the receiver should delete the connection 3743 without further interaction. The receiver can determine, 3744 based on the sequence number and acknowledgment fields of the 3745 incoming segment, whether it should honor the reset command 3746 or ignore it. In no case does receipt of a segment 3747 containing RST give rise to a RST in response. 3749 RTP 3750 Real Time Protocol: A host-to-host protocol for communication 3751 of time critical information. 3753 SEG.ACK 3754 segment acknowledgment 3756 SEG.LEN 3757 segment length 3759 SEG.PRC 3760 segment precedence value 3762 SEG.SEQ 3763 segment sequence 3765 SEG.UP 3766 segment urgent pointer field 3768 SEG.WND 3769 segment window field 3771 segment 3772 A logical unit of data, in particular a TCP segment is the 3773 unit of data transfered between a pair of TCP modules. 3775 segment acknowledgment 3776 The sequence number in the acknowledgment field of the 3777 arriving segment. 3779 segment length 3780 The amount of sequence number space occupied by a segment, 3781 including any controls which occupy sequence space. 3783 segment sequence 3784 The number in the sequence field of the arriving segment. 3786 send sequence 3787 This is the next sequence number the local (sending) TCP will 3788 use on the connection. It is initially selected from an 3789 initial sequence number curve (ISN) and is incremented for 3790 each octet of data or sequenced control transmitted. 3792 send window 3793 This represents the sequence numbers which the remote 3794 (receiving) TCP is willing to receive. It is the value of 3795 the window field specified in segments from the remote (data 3796 receiving) TCP. The range of new sequence numbers which may 3797 be emitted by a TCP lies between SND.NXT and SND.UNA + 3798 SND.WND - 1. (Retransmissions of sequence numbers between 3799 SND.UNA and SND.NXT are expected, of course.) 3801 SND.NXT 3802 send sequence 3804 SND.UNA 3805 left sequence 3807 SND.UP 3808 send urgent pointer 3810 SND.WL1 3811 segment sequence number at last window update 3813 SND.WL2 3814 segment acknowledgment number at last window update 3816 SND.WND 3817 send window 3819 socket 3820 An address which specifically includes a port identifier, 3821 that is, the concatenation of an Internet Address with a TCP 3822 port. 3824 Source Address 3825 The source address, usually the network and host identifiers. 3827 SYN 3828 A control bit in the incoming segment, occupying one sequence 3829 number, used at the initiation of a connection, to indicate 3830 where the sequence numbering will start. 3832 TCB 3833 Transmission control block, the data structure that records 3834 the state of a connection. 3836 TCB.PRC 3837 The precedence of the connection. 3839 TCP 3840 Transmission Control Protocol: A host-to-host protocol for 3841 reliable communication in internetwork environments. 3843 TOS 3844 Type of Service, an IPv4 field, that currently carries the 3845 Differentiated Services field [6] containing the 3846 Differentiated Services Code Point (DSCP) value and two 3847 unused bits. 3849 Type of Service 3850 An Internet Protocol field which indicates the type of 3851 service for this internet fragment. 3853 URG 3854 A control bit (urgent), occupying no sequence space, used to 3855 indicate that the receiving user should be notified to do 3856 urgent processing as long as there is data to be consumed 3857 with sequence numbers less than the value indicated in the 3858 urgent pointer. 3860 urgent pointer 3861 A control field meaningful only when the URG bit is on. This 3862 field communicates the value of the urgent pointer which 3863 indicates the data octet associated with the sending user's 3864 urgent call. 3866 4. Changes from RFC 793 3868 This document obsoletes RFC 793 as well as RFC 6093 and 6528, which 3869 updated 793. In all cases, only the normative protocol specification 3870 and requirements have been incorporated into this document, and the 3871 informational text with background and rationale has not been carried 3872 in. The informational content of those documents is still valuable 3873 in learning about and understanding TCP, and they are valid 3874 Informational references, even though their normative content has 3875 been incorporated into this document. 3877 The main body of this document was adapted from RFC 793's Section 3, 3878 titled "FUNCTIONAL SPECIFICATION", with an attempt to keep formatting 3879 and layout as close as possible. 3881 The collection of applicable RFC Errata that have been reported and 3882 either accepted or held for an update to RFC 793 were incorporated 3883 (Errata IDs: 573, 574, 700, 701, 1283, 1561, 1562, 1564, 1565, 1571, 3884 1572, 2296, 2297, 2298, 2748, 2749, 2934, 3213, 3300, 3301). Some 3885 errata were not applicable due to other changes (Errata IDs: 572, 3886 575, 1569, 3602). TODO: 3305 3888 Changes to the specification of the Urgent Pointer described in RFC 3889 1122 and 6093 were incorporated. See RFC 6093 for detailed 3890 discussion of why these changes were necessary. 3892 The discussion of the RTO from RFC 793 was updated to refer to RFC 3893 6298. The RFC 1122 text on the RTO originally replaced the 793 text, 3894 however, RFC 2988 should have updated 1122, and has subsequently been 3895 obsoleted by 6298. 3897 RFC 1122 contains a collection of other changes and clarifications to 3898 RFC 793. The normative items impacting the protocol have been 3899 incorporated here, though some historically useful implementation 3900 advice and informative discussion from RFC 1122 is not included here. 3902 RFC 1122 contains more than just TCP requirements, so this document 3903 can't obsolete RFC 1122 entirely. It is only marked as "updating" 3904 1122, however, it should be understood to effectively obsolete all of 3905 the RFC 1122 material on TCP. 3907 The more secure Initial Sequence Number generation algorithm from RFC 3908 6528 was incorporated. See RFC 6528 for discussion of the attacks 3909 that this mitigates, as well as advice on selecting PRF algorithms 3910 and managing secret key data. 3912 A note based on RFC 6429 was added to explicitly clarify that system 3913 resource mangement concerns allow connection resources to be 3914 reclaimed. RFC 6429 is obsoleted in the sense that this 3915 clarification has been reflected in this update to the base TCP 3916 specification now. 3918 RFC EDITOR'S NOTE: the content below is for detailed change tracking 3919 and planning, and not to be included with the final revision of the 3920 document. 3922 This document started as draft-eddy-rfc793bis-00, that was merely a 3923 proposal and rough plan for updating RFC 793. 3925 The -01 revision of this draft-eddy-rfc793bis incorporates the 3926 content of RFC 793 Section 3 titled "FUNCTIONAL SPECIFICATION". 3927 Other content from RFC 793 has not been incorporated. The -01 3928 revision of this document makes some minor formatting changes to the 3929 RFC 793 content in order to convert the content into XML2RFC format 3930 and account for left-out parts of RFC 793. For instance, figure 3931 numbering differs and some indentation is not exactly the same. 3933 The -02 revision of draft-eddy-rfc793bis incorporates errata that 3934 have been verified: 3936 Errata ID 573: Reported by Bob Braden (note: This errata basically 3937 is just a reminder that RFC 1122 updates 793. Some of the 3938 associated changes are left pending to a separate revision that 3939 incorporates 1122. Bob's mention of PUSH in 793 section 2.8 was 3940 not applicable here because that section was not part of the 3941 "functional specification". Also the 1122 text on the 3942 retransmission timeout also has been updated by subsequent RFCs, 3943 so the change here deviates from Bob's suggestion to apply the 3944 1122 text.) 3945 Errata ID 574: Reported by Yin Shuming 3946 Errata ID 700: Reported by Yin Shuming 3947 Errata ID 701: Reported by Yin Shuming 3948 Errata ID 1283: Reported by Pei-chun Cheng 3949 Errata ID 1561: Reported by Constantin Hagemeier 3950 Errata ID 1562: Reported by Constantin Hagemeier 3951 Errata ID 1564: Reported by Constantin Hagemeier 3952 Errata ID 1565: Reported by Constantin Hagemeier 3953 Errata ID 1571: Reported by Constantin Hagemeier 3954 Errata ID 1572: Reported by Constantin Hagemeier 3955 Errata ID 2296: Reported by Vishwas Manral 3956 Errata ID 2297: Reported by Vishwas Manral 3957 Errata ID 2298: Reported by Vishwas Manral 3958 Errata ID 2748: Reported by Mykyta Yevstifeyev 3959 Errata ID 2749: Reported by Mykyta Yevstifeyev 3960 Errata ID 2934: Reported by Constantin Hagemeier 3961 Errata ID 3213: Reported by EugnJun Yi 3962 Errata ID 3300: Reported by Botong Huang 3963 Errata ID 3301: Reported by Botong Huang 3964 Note: Some verified errata were not used in this update, as they 3965 relate to sections of RFC 793 elided from this document. These 3966 include Errata ID 572, 575, and 1569. 3967 Note: Errata ID 3602 was not applied in this revision as it is 3968 duplicative of the 1122 corrections. 3969 There is an errata 3305 currently reported that need to be 3970 verified, held, or rejected by the ADs; it is addressing the same 3971 issue as draft-gont-tcpm-tcp-seq-validation and was not attempted 3972 to be applied to this document. 3974 Not related to RFC 793 content, this revision also makes small tweaks 3975 to the introductory text, fixes indentation of the pseudoheader 3976 diagram, and notes that the Security Considerations should also 3977 include privacy, when this section is written. 3979 The -03 revision of draft-eddy-rfc793bis revises all discussion of 3980 the urgent pointer in order to comply with RFC 6093, 1122, and 1011. 3981 Since 1122 held requirements on the urgent pointer, the full list of 3982 requirements was brought into an appendix of this document, so that 3983 it can be updated as-needed. 3985 The -04 revision of draft-eddy-rfc793bis includes the ISN generation 3986 changes from RFC 6528. 3988 The -05 revision of draft-eddy-rfc793bis incorporates MSS 3989 requirements and definitions from RFC 879, 1122, and 6691, as well as 3990 option-handling requirements from RFC 1122. 3992 The -00 revision of draft-ietf-tcpm-rfc793bis incorporates several 3993 additional clarifications and updates to the section on segmentation, 3994 many of which are based on feedback from Joe Touch improving from the 3995 initial text on this in the previous revision. 3997 The -01 revision incorporates the change to Reserved bits due to ECN, 3998 as well as many other changes that come from RFC 1122. 4000 The -02 revision has small formating modifications in order to 4001 address xml2rfc warnings about long lines. It was a quick update to 4002 avoid document expiration. TCPM working group discussion in 2015 4003 also indicated that that we should not try to add sections on 4004 implementation advice or similar non-normative information. 4006 The -03 revision incorporates more content from RFC 1122: Passive 4007 OPEN Calls, Time-To-Live, Multihoming, IP Options, ICMP messages, 4008 Data Communications, When to Send Data, When to Send a Window Update, 4009 Managing the Window, Probing Zero Windows, When to Send an ACK 4010 Segment. The section on data communications was re-organized into 4011 clearer subsections (previously headings were embedded in the 793 4012 text), and windows management advice from 793 was removed (as 4013 reviewed by TCPM working group) in favor of the 1122 additions on 4014 SWS, ZWP, and related topics. 4016 The -04 revision includes reference to RFC 6429 on the ZWP condition, 4017 RFC1122 material on TCP Connection Failures, TCP Keep-Alives, 4018 Acknowledging Queued Segments, and Remote Address Validation. RTO 4019 computation is referenced from RFC 6298 rather than RFC 1122. 4021 The -05 revision includes the requirement to implement TCP congestion 4022 control with recommendation to implemente ECN, the RFC 6633 update to 4023 1122, which changed the requirement on responding to source quench 4024 ICMP messages, and discussion of ICMP (and ICMPv6) soft and hard 4025 errors per RFC 5461 (ICMPv6 handling for TCP doesn't seem to be 4026 mentioned elsewhere in standards track). 4028 The -06 revision includes an appendix on "Other Implementation Notes" 4029 to capture widely-deployed fundamental features that are not 4030 contained in the RFC series yet. It also added mention of RFC 6994 4031 and the IANA TCP parameters registry as a reference. It includes 4032 references to RFC 5961 in appropriate places. The references to TOS 4033 were changed to DiffServ field, based on reflecting RFC 2474 as well 4034 as the IPv6 presence of traffic class (carrying DiffServ field) 4035 rather than TOS. 4037 The -07 revision includes reference to RFC 6191, updated security 4038 considerations, discussion of additional implementation 4039 considerations, and clarification of data on the SYN. 4041 Some other suggested changes that will not be incorporated in this 4042 793 update unless TCPM consensus changes with regard to scope are: 4044 1. look at Tony Sabatini suggestion for describing DO field 4045 2. clearly specify treatment of reserved bits (see TCPM thread on 4046 EDO draft April 25, 2014) -- TODO - an attempt at this is 4047 actually in -06, but needs to be confirmed by TCPM explicitly 4048 since there is no RFC reference 4049 3. per discussion with Joe Touch (TAPS list, 6/20/2015), the 4050 description of the API could be revisited 4052 5. IANA Considerations 4054 This memo includes no request to IANA. Existing IANA registries for 4055 TCP parameters are sufficient. 4057 TODO: check whether entries pointing to 793 and other documents 4058 obsoleted by this one should be updated to point to this one instead. 4060 6. Security and Privacy Considerations 4062 The TCP design includes only rudimentary security features that 4063 improve the robustness and reliability of connections and application 4064 data transfer, but there are no built-in capabilities to support any 4065 form of privacy, authentication, or other typical security functions. 4066 Applications typically utilize lower-layer (e.g. IPsec) and upper- 4067 layer (e.g. TLS) protocols to provide security and privacy for TCP 4068 connections and application data carried in TCP. TCP options are 4069 available as well, to support some security capabilities. 4071 Applications using long-lived TCP flows have been vulnerable to 4072 attacks that exploit the processing of control flags described in 4073 earlier TCP specifications [18]. TCP-MD5 was a commonly implemented 4074 TCP option to support authentication for some of these connections, 4075 but had flaws and is now deprecated. The TCP Authentication Option 4076 (TCP AO) [23] provides a capability to protect long-lived TCP 4077 connections from attacks, and has superior properties to TCP-MD5. It 4078 does not provide any privacy for application data, nor for the TCP 4079 headers. 4081 The "tcpcrypt" [38]Experimental extension to TCP provides the ability 4082 to cryptographically protect connection data. Metadata aspects of 4083 the TCP flow are still visible, but the application stream is well- 4084 protected. Within the TCP header, only the urgent pointer and FIN 4085 flag are protected through tcpcrypt. 4087 The TCP Roadmap [33] includes notes about several RFCs related to TCP 4088 security. Many of the enhancements provided by these RFCs have been 4089 integrated into the present document, including ISN generation, 4090 mitigating blind in-window attacks, and improving handling of soft 4091 errors and ICMP packets. These are all discussed in greater detail 4092 in the referenced RFCs that originally described the changes needed 4093 to earlier TCP specifications. Additionally, see RFC 6093 [25] for 4094 discussion of security considerations related to the urgent pointer 4095 field, that has been deprecated. 4097 Since TCP is often used for bulk transfer flows, some attacks are 4098 possible that abuse the TCP congestion control logic. An example is 4099 "ACK-division" attacks. Updates that have been made to the TCP 4100 congestion control specifications include mechanisms like Appropriate 4101 Byte Counting (ABC) that act as mitigations to these attacks. 4103 Other attacks are focused on exhausting the resources of a TCP 4104 server. Examples include SYN flooding [17] or wasting resources on 4105 non-progressing connections [27]. Operating systems commonly 4106 implement mitigations for these attacks. Some common defenses also 4107 utilize proxies, stateful firewalls, and other technologies outside 4108 of the end-host TCP implementation. 4110 TODO Editor's Note: Scott Brim mentioned that this should include a 4111 PERPASS/privacy review ... Is this relevant anymore? Is it something 4112 for the chairs or AD to request during WGLC or IETF LC? 4114 7. Acknowledgements 4116 This document is largely a revision of RFC 793, which Jon Postel was 4117 the editor of. Due to his excellent work, it was able to last for 4118 three decades before we felt the need to revise it. 4120 Andre Oppermann was a contributor and helped to edit the first 4121 revision of this document. 4123 We are thankful for the assistance of the IETF TCPM working group 4124 chairs: 4126 Michael Scharf 4127 Yoshifumi Nishida 4128 Pasi Sarolahti 4130 During early discussion of this work on the TCPM mailing list, and at 4131 the IETF 88 meeting in Vancouver, helpful comments, critiques, and 4132 reviews were received from (listed alphebetically): David Borman, 4133 Yuchung Cheng, Martin Duke, Kevin Lahey, Kevin Mason, Matt Mathis, 4134 Hagen Paul Pfeifer, Anthony Sabatini, Joe Touch, Reji Varghese, Lloyd 4135 Wood, and Alex Zimmermann. Joe Touch provided help in clarifying the 4136 description of segment size parameters and PMTUD/PLPMTUD 4137 recommendations. 4139 This document includes content from errata that were reported by 4140 (listed chronologically): Yin Shuming, Bob Braden, Morris M. Keesan, 4141 Pei-chun Cheng, Constantin Hagemeier, Vishwas Manral, Mykyta 4142 Yevstifeyev, EungJun Yi, Botong Huang. 4144 8. References 4146 8.1. Normative References 4148 [1] Postel, J., "Internet Protocol", STD 5, RFC 791, 4149 DOI 10.17487/RFC0791, September 1981, 4150 . 4152 [2] Mogul, J. and S. Deering, "Path MTU discovery", RFC 1191, 4153 DOI 10.17487/RFC1191, November 1990, 4154 . 4156 [3] McCann, J., Deering, S., and J. Mogul, "Path MTU Discovery 4157 for IP version 6", RFC 1981, DOI 10.17487/RFC1981, August 4158 1996, . 4160 [4] Bradner, S., "Key words for use in RFCs to Indicate 4161 Requirement Levels", BCP 14, RFC 2119, 4162 DOI 10.17487/RFC2119, March 1997, 4163 . 4165 [5] Deering, S. and R. Hinden, "Internet Protocol, Version 6 4166 (IPv6) Specification", RFC 2460, DOI 10.17487/RFC2460, 4167 December 1998, . 4169 [6] Nichols, K., Blake, S., Baker, F., and D. Black, 4170 "Definition of the Differentiated Services Field (DS 4171 Field) in the IPv4 and IPv6 Headers", RFC 2474, 4172 DOI 10.17487/RFC2474, December 1998, 4173 . 4175 [7] Borman, D., Deering, S., and R. Hinden, "IPv6 Jumbograms", 4176 RFC 2675, DOI 10.17487/RFC2675, August 1999, 4177 . 4179 [8] Lahey, K., "TCP Problems with Path MTU Discovery", 4180 RFC 2923, DOI 10.17487/RFC2923, September 2000, 4181 . 4183 [9] Ramakrishnan, K., Floyd, S., and D. Black, "The Addition 4184 of Explicit Congestion Notification (ECN) to IP", 4185 RFC 3168, DOI 10.17487/RFC3168, September 2001, 4186 . 4188 [10] Paxson, V., Allman, M., Chu, J., and M. Sargent, 4189 "Computing TCP's Retransmission Timer", RFC 6298, 4190 DOI 10.17487/RFC6298, June 2011, 4191 . 4193 [11] Gont, F., "Deprecation of ICMP Source Quench Messages", 4194 RFC 6633, DOI 10.17487/RFC6633, May 2012, 4195 . 4197 8.2. Informative References 4199 [12] Postel, J., "Transmission Control Protocol", STD 7, 4200 RFC 793, DOI 10.17487/RFC0793, September 1981, 4201 . 4203 [13] Nagle, J., "Congestion Control in IP/TCP Internetworks", 4204 RFC 896, DOI 10.17487/RFC0896, January 1984, 4205 . 4207 [14] Braden, R., Ed., "Requirements for Internet Hosts - 4208 Communication Layers", STD 3, RFC 1122, 4209 DOI 10.17487/RFC1122, October 1989, 4210 . 4212 [15] Braden, R., "T/TCP -- TCP Extensions for Transactions 4213 Functional Specification", RFC 1644, DOI 10.17487/RFC1644, 4214 July 1994, . 4216 [16] Mathis, M. and J. Heffner, "Packetization Layer Path MTU 4217 Discovery", RFC 4821, DOI 10.17487/RFC4821, March 2007, 4218 . 4220 [17] Eddy, W., "TCP SYN Flooding Attacks and Common 4221 Mitigations", RFC 4987, DOI 10.17487/RFC4987, August 2007, 4222 . 4224 [18] Touch, J., "Defending TCP Against Spoofing Attacks", 4225 RFC 4953, DOI 10.17487/RFC4953, July 2007, 4226 . 4228 [19] Culley, P., Elzur, U., Recio, R., Bailey, S., and J. 4229 Carrier, "Marker PDU Aligned Framing for TCP 4230 Specification", RFC 5044, DOI 10.17487/RFC5044, October 4231 2007, . 4233 [20] Gont, F., "TCP's Reaction to Soft Errors", RFC 5461, 4234 DOI 10.17487/RFC5461, February 2009, 4235 . 4237 [21] Allman, M., Paxson, V., and E. Blanton, "TCP Congestion 4238 Control", RFC 5681, DOI 10.17487/RFC5681, September 2009, 4239 . 4241 [22] 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 [23] Touch, J., Mankin, A., and R. Bonica, "The TCP 4247 Authentication Option", RFC 5925, DOI 10.17487/RFC5925, 4248 June 2010, . 4250 [24] 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 [25] Gont, F. and A. Yourtchenko, "On the Implementation of the 4256 TCP Urgent Mechanism", RFC 6093, DOI 10.17487/RFC6093, 4257 January 2011, . 4259 [26] Gont, F., "Reducing the TIME-WAIT State Using TCP 4260 Timestamps", BCP 159, RFC 6191, DOI 10.17487/RFC6191, 4261 April 2011, . 4263 [27] 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 [28] Gont, F. and S. Bellovin, "Defending against Sequence 4269 Number Attacks", RFC 6528, DOI 10.17487/RFC6528, February 4270 2012, . 4272 [29] Borman, D., "TCP Options and Maximum Segment Size (MSS)", 4273 RFC 6691, DOI 10.17487/RFC6691, July 2012, 4274 . 4276 [30] Touch, J., "Shared Use of Experimental TCP Options", 4277 RFC 6994, DOI 10.17487/RFC6994, August 2013, 4278 . 4280 [31] 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 [32] Cheng, Y., Chu, J., Radhakrishnan, S., and A. Jain, "TCP 4286 Fast Open", RFC 7413, DOI 10.17487/RFC7413, December 2014, 4287 . 4289 [33] 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 [34] Fairhurst, G. and M. Welzl, "The Benefits of Using 4296 Explicit Congestion Notification (ECN)", RFC 8087, 4297 DOI 10.17487/RFC8087, March 2017, 4298 . 4300 [35] IANA, "Transmission Control Protocol (TCP) Parameters, 4301 https://www.iana.org/assignments/tcp-parameters/ 4302 tcp-parameters.xhtml", 2017. 4304 [36] Gont, F., "Processing of IP Security/Compartment and 4305 Precedence Information by TCP", draft-gont-tcpm-tcp- 4306 seccomp-prec-00 (work in progress), March 2012. 4308 [37] Gont, F. and D. Borman, "On the Validation of TCP Sequence 4309 Numbers", draft-gont-tcpm-tcp-seq-validation-02 (work in 4310 progress), March 2015. 4312 [38] Bittau, A., Giffin, D., Handley, M., Mazieres, D., Slack, 4313 Q., and E. Smith, "Cryptographic protection of TCP Streams 4314 (tcpcrypt)", draft-ietf-tcpinc-tcpcrypt-09 (work in 4315 progress), November 2017. 4317 [39] Minshall, G., "A Proposed Modification to Nagle's 4318 Algorithm", draft-minshall-nagle-01 (work in progress), 4319 June 1999. 4321 Appendix A. Other Implementation Notes 4323 This section includes additional notes and references on TCP 4324 implementation decisions that are currently not a part of the RFC 4325 series or included within the TCP standard. These items can be 4326 considered by implementers, but there was not yet a consensus to 4327 include them in the standard. 4329 A.1. IP Security Compartment and Precedence 4331 The TCP standard requires checking the IP security compartment and 4332 precedence on incoming TCP segments for consistency within a 4333 connection. 4335 In common Internet usage of TCP, the IP security compartment is not 4336 used. IP precedence has been deprecated with the introduction of 4337 DiffServ many years ago. 4339 Reseting connections when incoming packets do not meet expected 4340 security compartment and precedence expectations has been recognized 4341 as a possible attack vector [36], and the document advises ammending 4342 the TCP specification to prevent connections from being aborted due 4343 to non-matching IP security compartment and DiffServ codepoint 4344 values. 4346 A.2. Sequence Number Validation 4348 There are cases where the TCP sequence number validation rules can 4349 prevent ACK fields from being processed. This can result in 4350 connection issues, as described in [37], which includes descriptions 4351 of potential problems in conditions of simultaneous open, self- 4352 connects, simultaneous close, and simultaneous window probes. The 4353 document also describes potential changes to the TCP specification to 4354 mitigate the issue by expanding the acceptable sequence numbers. 4356 In Internet usage of TCP, these conditions are rarely occuring. 4357 Common operating systems include different alternative mitigations, 4358 and the standard has not been updated yet to codify one of them, but 4359 implementers should consider the problems described in [37]. 4361 A.3. Nagle Modification 4363 In common operating systems, both the Nagle algorithm and delayed 4364 acknowledgements are implemented and enabled by default. TCP is used 4365 by many applications that have a request-response style of 4366 communication, where the combination of the Nagle algorithm and 4367 delayed acknowledgements can result in poor application performance. 4368 A modification to the Nagle algorithm is described in [39] that 4369 improves the situation for these applications. 4371 This modification is implemented in some common operating systems, 4372 and does not impact TCP interoperability. Additionally, many 4373 applications simply disable Nagle, since this is generally supported 4374 by a socket option. The TCP standard has not been updated to include 4375 this Nagle modification, but implementers may find it beneficial to 4376 consider. 4378 A.4. Low Water Mark 4380 TODO - mention the low watermark function that is in Linux - 4381 suggested by Michael Welzl 4383 SO_SNDLOWAT and SO_RCVLOWAT would be potential enhancements to the 4384 abstract TCP API 4386 TCP_NOTSENT_LOWAT is what Michael is talking about, that helps a 4387 sending TCP application to help avoid creating large amounts of 4388 buffered data (and corresponding latency). This is useful for 4389 applications that are multiplexing data from multiple upper level 4390 streams onto a connection, especially when streams may be a mix of 4391 interactive/realtime and bulk data transfer. 4393 Appendix B. TCP Requirement Summary 4395 This section is adapted from RFC 1122. 4397 TODO: this needs to be seriously redone, to use 793bis section 4398 numbers instead of 1122 ones, the RFC1122 heading should be removed, 4399 and all 1122 requirements need to be reflected in 793bis text. 4401 TODO: NOTE that PMTUD+PLPMTUD is not included in this table of 4402 recommendations. 4404 | | | | |S| | 4405 | | | | |H| |F 4406 | | | | |O|M|o 4407 | | |S| |U|U|o 4408 | | |H| |L|S|t 4409 | |M|O| |D|T|n 4410 | |U|U|M| | |o 4411 | |S|L|A|N|N|t 4412 |RFC1122 |T|D|Y|O|O|t 4413 FEATURE |SECTION | | | |T|T|e 4414 -------------------------------------------------|--------|-|-|-|-|-|-- 4415 | | | | | | | 4416 Push flag | | | | | | | 4417 Aggregate or queue un-pushed data |4.2.2.2 | | |x| | | 4418 Sender collapse successive PSH flags |4.2.2.2 | |x| | | | 4419 SEND call can specify PUSH |4.2.2.2 | | |x| | | 4420 If cannot: sender buffer indefinitely |4.2.2.2 | | | | |x| 4421 If cannot: PSH last segment |4.2.2.2 |x| | | | | 4422 Notify receiving ALP of PSH |4.2.2.2 | | |x| | |1 4423 Send max size segment when possible |4.2.2.2 | |x| | | | 4424 | | | | | | | 4425 Window | | | | | | | 4426 Treat as unsigned number |4.2.2.3 |x| | | | | 4427 Handle as 32-bit number |4.2.2.3 | |x| | | | 4428 Shrink window from right |4.2.2.16| | | |x| | 4429 Robust against shrinking window |4.2.2.16|x| | | | | 4430 Receiver's window closed indefinitely |4.2.2.17| | |x| | | 4431 Sender probe zero window |4.2.2.17|x| | | | | 4432 First probe after RTO |4.2.2.17| |x| | | | 4433 Exponential backoff |4.2.2.17| |x| | | | 4434 Allow window stay zero indefinitely |4.2.2.17|x| | | | | 4435 Sender timeout OK conn with zero wind |4.2.2.17| | | | |x| 4436 | | | | | | | 4438 Urgent Data | | | | | | | 4439 Pointer indicates first non-urgent octet |4.2.2.4 |x| | | | | 4440 Arbitrary length urgent data sequence |4.2.2.4 |x| | | | | 4441 Inform ALP asynchronously of urgent data |4.2.2.4 |x| | | | |1 4442 ALP can learn if/how much urgent data Q'd |4.2.2.4 |x| | | | |1 4443 | | | | | | | 4444 TCP Options | | | | | | | 4445 Receive TCP option in any segment |4.2.2.5 |x| | | | | 4446 Ignore unsupported options |4.2.2.5 |x| | | | | 4447 Cope with illegal option length |4.2.2.5 |x| | | | | 4448 Implement sending & receiving MSS option |4.2.2.6 |x| | | | | 4449 IPv4 Send MSS option unless 536 |4.2.2.6 | |x| | | | 4450 IPv6 Send MSS option unless 1220 | N/A | |x| | | | 4451 Send MSS option always |4.2.2.6 | | |x| | | 4452 IPv4 Send-MSS default is 536 |4.2.2.6 |x| | | | | 4453 IPv6 Send-MSS default is 1220 | N/A |x| | | | | 4454 Calculate effective send seg size |4.2.2.6 |x| | | | | 4455 MSS accounts for varying MTU | N/A | |x| | | | 4456 | | | | | | | 4457 TCP Checksums | | | | | | | 4458 Sender compute checksum |4.2.2.7 |x| | | | | 4459 Receiver check checksum |4.2.2.7 |x| | | | | 4460 | | | | | | | 4461 ISN Selection | | | | | | | 4462 Include a clock-driven ISN generator component |4.2.2.9 |x| | | | | 4463 Secure ISN generator with a PRF component | N/A | |x| | | | 4464 | | | | | | | 4465 Opening Connections | | | | | | | 4466 Support simultaneous open attempts |4.2.2.10|x| | | | | 4467 SYN-RECEIVED remembers last state |4.2.2.11|x| | | | | 4468 Passive Open call interfere with others |4.2.2.18| | | | |x| 4469 Function: simultan. LISTENs for same port |4.2.2.18|x| | | | | 4470 Ask IP for src address for SYN if necc. |4.2.3.7 |x| | | | | 4471 Otherwise, use local addr of conn. |4.2.3.7 |x| | | | | 4472 OPEN to broadcast/multicast IP Address |4.2.3.14| | | | |x| 4473 Silently discard seg to bcast/mcast addr |4.2.3.14|x| | | | | 4474 | | | | | | | 4475 Closing Connections | | | | | | | 4476 RST can contain data |4.2.2.12| |x| | | | 4477 Inform application of aborted conn |4.2.2.13|x| | | | | 4478 Half-duplex close connections |4.2.2.13| | |x| | | 4479 Send RST to indicate data lost |4.2.2.13| |x| | | | 4480 In TIME-WAIT state for 2MSL seconds |4.2.2.13|x| | | | | 4481 Accept SYN from TIME-WAIT state |4.2.2.13| | |x| | | 4482 Use Timestamps to reduce TIME-WAIT | TODO | | | | | | 4483 | | | | | | | 4484 Retransmissions | | | | | | | 4485 Jacobson Slow Start algorithm |4.2.2.15|x| | | | | 4486 Jacobson Congestion-Avoidance algorithm |4.2.2.15|x| | | | | 4487 Retransmit with same IP ident |4.2.2.15| | |x| | | 4488 Karn's algorithm |4.2.3.1 |x| | | | | 4489 Jacobson's RTO estimation alg. |4.2.3.1 |x| | | | | 4490 Exponential backoff |4.2.3.1 |x| | | | | 4491 SYN RTO calc same as data |4.2.3.1 | |x| | | | 4492 Recommended initial values and bounds |4.2.3.1 | |x| | | | 4493 | | | | | | | 4494 Generating ACK's: | | | | | | | 4495 Queue out-of-order segments |4.2.2.20| |x| | | | 4496 Process all Q'd before send ACK |4.2.2.20|x| | | | | 4497 Send ACK for out-of-order segment |4.2.2.21| | |x| | | 4498 Delayed ACK's |4.2.3.2 | |x| | | | 4499 Delay < 0.5 seconds |4.2.3.2 |x| | | | | 4500 Every 2nd full-sized segment ACK'd |4.2.3.2 |x| | | | | 4501 Receiver SWS-Avoidance Algorithm |4.2.3.3 |x| | | | | 4502 | | | | | | | 4503 Sending data | | | | | | | 4504 Configurable TTL |4.2.2.19|x| | | | | 4505 Sender SWS-Avoidance Algorithm |4.2.3.4 |x| | | | | 4506 Nagle algorithm |4.2.3.4 | |x| | | | 4507 Application can disable Nagle algorithm |4.2.3.4 |x| | | | | 4508 | | | | | | | 4509 Connection Failures: | | | | | | | 4510 Negative advice to IP on R1 retxs |4.2.3.5 |x| | | | | 4511 Close connection on R2 retxs |4.2.3.5 |x| | | | | 4512 ALP can set R2 |4.2.3.5 |x| | | | |1 4513 Inform ALP of R1<=retxs inform ALP |4.2.3.9 | |x| | | | 4538 Dest. Unreach (0,1,5) => abort conn |4.2.3.9 | | | | |x| 4539 Dest. Unreach (2-4) => abort conn |4.2.3.9 | |x| | | | 4540 Source Quench => silent discard |4.2.3.9 | |x| | | | 4541 Time Exceeded => tell ALP, don't abort |4.2.3.9 | |x| | | | 4542 Param Problem => tell ALP, don't abort |4.2.3.9 | |x| | | | 4543 | | | | | | | 4544 Address Validation | | | | | | | 4545 Reject OPEN call to invalid IP address |4.2.3.10|x| | | | | 4546 Reject SYN from invalid IP address |4.2.3.10|x| | | | | 4547 Silently discard SYN to bcast/mcast addr |4.2.3.10|x| | | | | 4548 | | | | | | | 4549 TCP/ALP Interface Services | | | | | | | 4550 Error Report mechanism |4.2.4.1 |x| | | | | 4551 ALP can disable Error Report Routine |4.2.4.1 | |x| | | | 4552 ALP can specify DiffServ field for sending |4.2.4.2 |x| | | | | 4553 Passed unchanged to IP |4.2.4.2 | |x| | | | 4554 ALP can change DiffServ field during connection|4.2.4.2 | |x| | | | 4555 Pass received DiffServ field up to ALP |4.2.4.2 | | |x| | | 4556 FLUSH call |4.2.4.3 | | |x| | | 4557 Optional local IP addr parm. in OPEN |4.2.4.4 |x| | | | | 4558 -------------------------------------------------|--------|-|-|-|-|-|-- 4560 FOOTNOTES: (1) "ALP" means Application-Layer program. 4562 Author's Address 4564 Wesley M. Eddy (editor) 4565 MTI Systems 4566 US 4568 Email: wes@mti-systems.com