idnits 2.17.1 draft-ietf-tcpm-rfc793bis-04.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 1 instance of lines with non-RFC2606-compliant FQDNs in the document. == There are 1 instance of lines with non-RFC6890-compliant IPv4 addresses in the document. If these are example addresses, they should be changed. -- The draft header indicates that this document obsoletes RFC6093, but the abstract doesn't seem to mention this, which it should. -- The draft header indicates that this document obsoletes 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. -- The draft header indicates that this document updates RFC1122, but the abstract doesn't seem to mention this, which it should. Miscellaneous warnings: ---------------------------------------------------------------------------- == The copyright year in the IETF Trust and authors Copyright Line does not match the current year (Using the creation date from RFC1122, updated by this document, for RFC5378 checks: 1989-10-01) -- The document seems to contain a disclaimer for pre-RFC5378 work, and may have content which was first submitted before 10 November 2008. The disclaimer is necessary when there are original authors that you have been unable to contact, or if some do not wish to grant the BCP78 rights to the IETF Trust. If you are able to get all authors (current and original) to grant those rights, you can and should remove the disclaimer; otherwise, the disclaimer is needed and you can ignore this comment. (See the Legal Provisions document at https://trustee.ietf.org/license-info for more information.) -- The document date (December 8, 2016) is 2696 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) ** Obsolete normative reference: RFC 1981 (ref. '3') (Obsoleted by RFC 8201) ** Downref: Normative reference to an Informational RFC: RFC 2923 (ref. '6') -- Obsolete informational reference (is this intentional?): RFC 793 (ref. '8') (Obsoleted by RFC 9293) -- Obsolete informational reference (is this intentional?): RFC 896 (ref. '9') (Obsoleted by RFC 7805) -- Obsolete informational reference (is this intentional?): RFC 6093 (ref. '15') (Obsoleted by RFC 9293) -- Obsolete informational reference (is this intentional?): RFC 6429 (ref. '16') (Obsoleted by RFC 9293) -- Obsolete informational reference (is this intentional?): RFC 6528 (ref. '17') (Obsoleted by RFC 9293) -- Obsolete informational reference (is this intentional?): RFC 6691 (ref. '18') (Obsoleted by RFC 9293) Summary: 3 errors (**), 0 flaws (~~), 3 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, December 8, 2016 5 6691 (if approved) 6 Updates: 1122 (if approved) 7 Intended status: Standards Track 8 Expires: June 11, 2017 10 Transmission Control Protocol Specification 11 draft-ietf-tcpm-rfc793bis-04 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 and several other RFCs (TODO: list 23 all actual RFCs when finished). 25 RFC EDITOR NOTE: If approved for publication as an RFC, this should 26 be marked additionally as "STD: 7" and replace RFC 793 in that role. 28 Requirements Language 30 The key words "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT", 31 "SHOULD", "SHOULD NOT", "RECOMMENDED", "MAY", and "OPTIONAL" in this 32 document are to be interpreted as described in RFC 2119 [4]. 34 Status of This Memo 36 This Internet-Draft is submitted in full conformance with the 37 provisions of BCP 78 and BCP 79. 39 Internet-Drafts are working documents of the Internet Engineering 40 Task Force (IETF). Note that other groups may also distribute 41 working documents as Internet-Drafts. The list of current Internet- 42 Drafts is at http://datatracker.ietf.org/drafts/current/. 44 Internet-Drafts are draft documents valid for a maximum of six months 45 and may be updated, replaced, or obsoleted by other documents at any 46 time. It is inappropriate to use Internet-Drafts as reference 47 material or to cite them other than as "work in progress." 48 This Internet-Draft will expire on June 11, 2017. 50 Copyright Notice 52 Copyright (c) 2016 IETF Trust and the persons identified as the 53 document authors. All rights reserved. 55 This document is subject to BCP 78 and the IETF Trust's Legal 56 Provisions Relating to IETF Documents 57 (http://trustee.ietf.org/license-info) in effect on the date of 58 publication of this document. Please review these documents 59 carefully, as they describe your rights and restrictions with respect 60 to this document. Code Components extracted from this document must 61 include Simplified BSD License text as described in Section 4.e of 62 the Trust Legal Provisions and are provided without warranty as 63 described in the Simplified BSD License. 65 This document may contain material from IETF Documents or IETF 66 Contributions published or made publicly available before November 67 10, 2008. The person(s) controlling the copyright in some of this 68 material may not have granted the IETF Trust the right to allow 69 modifications of such material outside the IETF Standards Process. 70 Without obtaining an adequate license from the person(s) controlling 71 the copyright in such materials, this document may not be modified 72 outside the IETF Standards Process, and derivative works of it may 73 not be created outside the IETF Standards Process, except to format 74 it for publication as an RFC or to translate it into languages other 75 than English. 77 Table of Contents 79 1. Purpose and Scope . . . . . . . . . . . . . . . . . . . . . . 3 80 2. Introduction . . . . . . . . . . . . . . . . . . . . . . . . 4 81 3. Functional Specification . . . . . . . . . . . . . . . . . . 5 82 3.1. Header Format . . . . . . . . . . . . . . . . . . . . . . 5 83 3.2. Terminology . . . . . . . . . . . . . . . . . . . . . . . 10 84 3.3. Sequence Numbers . . . . . . . . . . . . . . . . . . . . 15 85 3.4. Establishing a connection . . . . . . . . . . . . . . . . 21 86 3.4.1. Remote Address Validation . . . . . . . . . . . . . . 28 87 3.5. Closing a Connection . . . . . . . . . . . . . . . . . . 28 88 3.5.1. Half-Closed Connections . . . . . . . . . . . . . . . 31 89 3.6. Precedence and Security . . . . . . . . . . . . . . . . . 31 90 3.7. Segmentation . . . . . . . . . . . . . . . . . . . . . . 32 91 3.7.1. Maximum Segment Size Option . . . . . . . . . . . . . 33 92 3.7.2. Path MTU Discovery . . . . . . . . . . . . . . . . . 34 93 3.7.3. Interfaces with Variable MTU Values . . . . . . . . . 35 94 3.7.4. Nagle Algorithm . . . . . . . . . . . . . . . . . . . 35 95 3.7.5. IPv6 Jumbograms . . . . . . . . . . . . . . . . . . . 36 97 3.8. Data Communication . . . . . . . . . . . . . . . . . . . 36 98 3.8.1. Retransmission Timeout . . . . . . . . . . . . . . . 37 99 3.8.2. TCP Connection Failures . . . . . . . . . . . . . . . 37 100 3.8.3. TCP Keep-Alives . . . . . . . . . . . . . . . . . . . 38 101 3.8.4. The Communication of Urgent Information . . . . . . . 38 102 3.8.5. Managing the Window . . . . . . . . . . . . . . . . . 39 103 3.9. Interfaces . . . . . . . . . . . . . . . . . . . . . . . 44 104 3.9.1. User/TCP Interface . . . . . . . . . . . . . . . . . 44 105 3.9.2. TCP/Lower-Level Interface . . . . . . . . . . . . . . 52 106 3.10. Event Processing . . . . . . . . . . . . . . . . . . . . 54 107 3.11. Glossary . . . . . . . . . . . . . . . . . . . . . . . . 78 108 4. Changes from RFC 793 . . . . . . . . . . . . . . . . . . . . 83 109 5. IANA Considerations . . . . . . . . . . . . . . . . . . . . . 87 110 6. Security and Privacy Considerations . . . . . . . . . . . . . 87 111 7. Acknowledgements . . . . . . . . . . . . . . . . . . . . . . 88 112 8. References . . . . . . . . . . . . . . . . . . . . . . . . . 88 113 8.1. Normative References . . . . . . . . . . . . . . . . . . 88 114 8.2. Informative References . . . . . . . . . . . . . . . . . 89 115 Appendix A. TCP Requirement Summary . . . . . . . . . . . . . . 90 116 Author's Address . . . . . . . . . . . . . . . . . . . . . . . . 94 118 1. Purpose and Scope 120 In 1981, RFC 793 [8] was released, documenting the Transmission 121 Control Protocol (TCP), and replacing earlier specifications for TCP 122 that had been published in the past. 124 Since then, TCP has been implemented many times, and has been used as 125 a transport protocol for numerous applications on the Internet. 127 For several decades, RFC 793 plus a number of other documents have 128 combined to serve as the specification for TCP [20]. Over time, a 129 number of errata have been identified on RFC 793, as well as 130 deficiencies in security, performance, and other aspects. A number 131 of enhancements has grown and been documented separately. These were 132 never accumulated together into an update to the base specification. 134 The purpose of this document is to bring together all of the IETF 135 Standards Track changes that have been made to the basic TCP 136 functional specification and unify them into an update of the RFC 793 137 protocol specification. Some companion documents are referenced for 138 important algorithms that TCP uses (e.g. for congestion control), but 139 have not been attempted to include in this document. This is a 140 conscious choice, as this base specification can be used with 141 multiple additional algorithms that are developed and incorporated 142 separately, but all TCP implementations need to implement this 143 specification as a common basis in order to interoperate. As some 144 additional TCP features have become quite complicated themselves 145 (e.g. advanced loss recovery and congestion control), future 146 companion documents may attempt to similarly bring these together. 148 In addition to the protocol specification that descibes the TCP 149 segment format, generation, and processing rules that are to be 150 implemented in code, RFC 793 and other updates also contain 151 informative and descriptive text for human readers to understand 152 aspects of the protocol design and operation. This document does not 153 attempt to alter or update this informative text, and is focused only 154 on updating the normative protocol specification. We preserve 155 references to the documentation containing the important explanations 156 and rationale, where appropriate. 158 This document is intended to be useful both in checking existing TCP 159 implementations for conformance, as well as in writing new 160 implementations. 162 2. Introduction 164 RFC 793 contains a discussion of the TCP design goals and provides 165 examples of its operation, including examples of connection 166 establishment, closing connections, and retransmitting packets to 167 repair losses. 169 This document describes the basic functionality expected in modern 170 implementations of TCP, and replaces the protocol specification in 171 RFC 793. It does not replicate or attempt to update the examples and 172 other discussion in RFC 793. Other documents are referenced to 173 provide explanation of the theory of operation, rationale, and 174 detailed discussion of design decisions. This document only focuses 175 on the normative behavior of the protocol. 177 The "TCP Roadmap" [20] provides a more extensive guide to the RFCs 178 that define TCP and describe various important algorithms. The TCP 179 Roadmap contains sections on strongly encouraged enhancements that 180 improve performance and other aspects of TCP beyond the basic 181 operation specified in this document. As one example, implementing 182 congestion control (e.g. [13]) is a TCP requirement, but is a complex 183 topic on its own, and not described in detail in this document, as 184 there are many options and possibilities that do not impact basic 185 interoperability. Similarly, most common TCP implementations today 186 include the high-performance extensions in [19], but these are not 187 strictly required or discussed in this document. 189 TEMPORARY EDITOR'S NOTE: This is an early revision in the process of 190 updating RFC 793. Many planned changes are not yet incorporated. 192 ***Please do not use this revision as a basis for any work or 193 reference.*** 195 A list of changes from RFC 793 is contained in Section 4. 197 TEMPORARY EDITOR'S NOTE: the current revision of this document does 198 not yet collect all of the changes that will be in the final version. 199 The set of content changes planned for future revisions is kept in 200 Section 4. 202 3. Functional Specification 204 3.1. Header Format 206 TCP segments are sent as internet datagrams. The Internet Protocol 207 header carries several information fields, including the source and 208 destination host addresses [1]. A TCP header follows the internet 209 header, supplying information specific to the TCP protocol. This 210 division allows for the existence of host level protocols other than 211 TCP. (Editorial TODO - this last sentence makes sense in 793 212 context, but may be a candidate to remove here? ... additionally, 213 Section 2 of 793 is not includeed here, but some parts may be useful, 214 to quickly define basic concepts of ports, bytestream service, etc. 215 at high-level before delving into protocol details?) 217 TCP Header Format 218 0 1 2 3 219 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 220 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 221 | Source Port | Destination Port | 222 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 223 | Sequence Number | 224 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 225 | Acknowledgment Number | 226 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 227 | Data | |U|A|P|R|S|F| | 228 | Offset| Reserved |R|C|S|S|Y|I| Window | 229 | | |G|K|H|T|N|N| | 230 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 231 | Checksum | Urgent Pointer | 232 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 233 | Options | Padding | 234 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 235 | data | 236 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 238 TCP Header Format 240 Note that one tick mark represents one bit position. 242 Figure 1 244 Source Port: 16 bits 246 The source port number. 248 Destination Port: 16 bits 250 The destination port number. 252 Sequence Number: 32 bits 254 The sequence number of the first data octet in this segment (except 255 when SYN is present). If SYN is present the sequence number is the 256 initial sequence number (ISN) and the first data octet is ISN+1. 258 Acknowledgment Number: 32 bits 260 If the ACK control bit is set this field contains the value of the 261 next sequence number the sender of the segment is expecting to 262 receive. Once a connection is established this is always sent. 264 Data Offset: 4 bits 265 The number of 32 bit words in the TCP Header. This indicates where 266 the data begins. The TCP header (even one including options) is an 267 integral number of 32 bits long. 269 Reserved: 4 bits 271 Reserved for future use. Must be zero. 273 Control Bits: 8 bits (from left to right): 275 CWR: Congestion Window Reduced 276 ECE: ECN-Echo 277 URG: Urgent Pointer field significant 278 ACK: Acknowledgment field significant 279 PSH: Push Function 280 RST: Reset the connection 281 SYN: Synchronize sequence numbers 282 FIN: No more data from sender 284 Window: 16 bits 286 The number of data octets beginning with the one indicated in the 287 acknowledgment field which the sender of this segment is willing to 288 accept. 290 The window size MUST be treated as an unsigned number, or else 291 large window sizes will appear like negative windows and TCP will 292 now work. It is RECOMMENDED that implementations will reserve 293 32-bit fields for the send and receive window sizes in the 294 connection record and do all window computations with 32 bits. 296 Checksum: 16 bits 298 The checksum field is the 16 bit one's complement of the one's 299 complement sum of all 16 bit words in the header and text. If a 300 segment contains an odd number of header and text octets to be 301 checksummed, the last octet is padded on the right with zeros to 302 form a 16 bit word for checksum purposes. The pad is not 303 transmitted as part of the segment. While computing the checksum, 304 the checksum field itself is replaced with zeros. 306 The checksum also covers a 96 bit pseudo header conceptually 307 prefixed to the TCP header. This pseudo header contains the Source 308 Address, the Destination Address, the Protocol, and TCP length. 309 This gives the TCP protection against misrouted segments. This 310 information is carried in the Internet Protocol and is transferred 311 across the TCP/Network interface in the arguments or results of 312 calls by the TCP on the IP. (TODO: this is IPv4-specific, need to 313 mention IPv6 psuedoheader as well) 315 +--------+--------+--------+--------+ 316 | Source Address | 317 +--------+--------+--------+--------+ 318 | Destination Address | 319 +--------+--------+--------+--------+ 320 | zero | PTCL | TCP Length | 321 +--------+--------+--------+--------+ 323 The TCP Length is the TCP header length plus the data length in 324 octets (this is not an explicitly transmitted quantity, but is 325 computed), and it does not count the 12 octets of the pseudo 326 header. 328 The TCP checksum is never optional. The sender MUST generate it 329 and the receiver MUST check it. 331 Urgent Pointer: 16 bits 333 This field communicates the current value of the urgent pointer as 334 a positive offset from the sequence number in this segment. The 335 urgent pointer points to the sequence number of the octet following 336 the urgent data. This field is only be interpreted in segments 337 with the URG control bit set. 339 Options: variable 341 Options may occupy space at the end of the TCP header and are a 342 multiple of 8 bits in length. All options are included in the 343 checksum. An option may begin on any octet boundary. There are 344 two cases for the format of an option: 346 Case 1: A single octet of option-kind. 348 Case 2: An octet of option-kind, an octet of option-length, and 349 the actual option-data octets. 351 The option-length counts the two octets of option-kind and option- 352 length as well as the option-data octets. 354 Note that the list of options may be shorter than the data offset 355 field might imply. The content of the header beyond the End-of- 356 Option option must be header padding (i.e., zero). 358 Currently defined options include (kind indicated in octal): 360 Kind Length Meaning 361 ---- ------ ------- 362 0 - End of option list. 363 1 - No-Operation. 364 2 4 Maximum Segment Size. 366 TODO - I think we may need to include designated experimental 367 options and RFC 6994 reference here 369 A TCP MUST be able to receive a TCP option in any segment. 370 A TCP MUST ignore without error any TCP option it does not 371 implement, assuming that the option has a length field (all TCP 372 options except End of option list and No-Operation have length 373 fields). TCP MUST be prepared to handle an illegal option length 374 (e.g., zero) without crashing; a suggested procedure is to reset 375 the connection and log the reason. 377 Specific Option Definitions 379 End of Option List 381 +--------+ 382 |00000000| 383 +--------+ 384 Kind=0 386 This option code indicates the end of the option list. This 387 might not coincide with the end of the TCP header according to 388 the Data Offset field. This is used at the end of all options, 389 not the end of each option, and need only be used if the end of 390 the options would not otherwise coincide with the end of the TCP 391 header. 393 No-Operation 395 +--------+ 396 |00000001| 397 +--------+ 398 Kind=1 400 This option code may be used between options, for example, to 401 align the beginning of a subsequent option on a word boundary. 402 There is no guarantee that senders will use this option, so 403 receivers must be prepared to process options even if they do 404 not begin on a word boundary. 406 Maximum Segment Size (MSS) 408 +--------+--------+---------+--------+ 409 |00000010|00000100| max seg size | 410 +--------+--------+---------+--------+ 411 Kind=2 Length=4 413 Maximum Segment Size Option Data: 16 bits 415 If this option is present, then it communicates the maximum 416 receive segment size at the TCP which sends this segment. This 417 field may be sent in the initial connection request (i.e., in 418 segments with the SYN control bit set) and must not be sent in 419 other segments. If this option is not used, any segment size is 420 allowed. A more complete description of this option is in 421 Section 3.7.1. 423 Padding: variable 425 The TCP header padding is used to ensure that the TCP header ends 426 and data begins on a 32 bit boundary. The padding is composed of 427 zeros. 429 3.2. Terminology 431 Before we can discuss very much about the operation of the TCP we 432 need to introduce some detailed terminology. The maintenance of a 433 TCP connection requires the remembering of several variables. We 434 conceive of these variables being stored in a connection record 435 called a Transmission Control Block or TCB. Among the variables 436 stored in the TCB are the local and remote socket numbers, the 437 security and precedence of the connection, pointers to the user's 438 send and receive buffers, pointers to the retransmit queue and to the 439 current segment. In addition several variables relating to the send 440 and receive sequence numbers are stored in the TCB. 442 Send Sequence Variables 444 SND.UNA - send unacknowledged 445 SND.NXT - send next 446 SND.WND - send window 447 SND.UP - send urgent pointer 448 SND.WL1 - segment sequence number used for last window update 449 SND.WL2 - segment acknowledgment number used for last window 450 update 451 ISS - initial send sequence number 453 Receive Sequence Variables 455 RCV.NXT - receive next 456 RCV.WND - receive window 457 RCV.UP - receive urgent pointer 458 IRS - initial receive sequence number 460 The following diagrams may help to relate some of these variables to 461 the sequence space. 463 Send Sequence Space 465 1 2 3 4 466 ----------|----------|----------|---------- 467 SND.UNA SND.NXT SND.UNA 468 +SND.WND 470 1 - old sequence numbers which have been acknowledged 471 2 - sequence numbers of unacknowledged data 472 3 - sequence numbers allowed for new data transmission 473 4 - future sequence numbers which are not yet allowed 475 Send Sequence Space 477 Figure 2 479 The send window is the portion of the sequence space labeled 3 in 480 Figure 2. 482 Receive Sequence Space 484 1 2 3 485 ----------|----------|---------- 486 RCV.NXT RCV.NXT 487 +RCV.WND 489 1 - old sequence numbers which have been acknowledged 490 2 - sequence numbers allowed for new reception 491 3 - future sequence numbers which are not yet allowed 493 Receive Sequence Space 495 Figure 3 497 The receive window is the portion of the sequence space labeled 2 in 498 Figure 3. 500 There are also some variables used frequently in the discussion that 501 take their values from the fields of the current segment. 503 Current Segment Variables 505 SEG.SEQ - segment sequence number 506 SEG.ACK - segment acknowledgment number 507 SEG.LEN - segment length 508 SEG.WND - segment window 509 SEG.UP - segment urgent pointer 510 SEG.PRC - segment precedence value 512 A connection progresses through a series of states during its 513 lifetime. The states are: LISTEN, SYN-SENT, SYN-RECEIVED, 514 ESTABLISHED, FIN-WAIT-1, FIN-WAIT-2, CLOSE-WAIT, CLOSING, LAST-ACK, 515 TIME-WAIT, and the fictional state CLOSED. CLOSED is fictional 516 because it represents the state when there is no TCB, and therefore, 517 no connection. Briefly the meanings of the states are: 519 LISTEN - represents waiting for a connection request from any 520 remote TCP and port. 522 SYN-SENT - represents waiting for a matching connection request 523 after having sent a connection request. 525 SYN-RECEIVED - represents waiting for a confirming connection 526 request acknowledgment after having both received and sent a 527 connection request. 529 ESTABLISHED - represents an open connection, data received can be 530 delivered to the user. The normal state for the data transfer 531 phase of the connection. 533 FIN-WAIT-1 - represents waiting for a connection termination 534 request from the remote TCP, or an acknowledgment of the 535 connection termination request previously sent. 537 FIN-WAIT-2 - represents waiting for a connection termination 538 request from the remote TCP. 540 CLOSE-WAIT - represents waiting for a connection termination 541 request from the local user. 543 CLOSING - represents waiting for a connection termination request 544 acknowledgment from the remote TCP. 546 LAST-ACK - represents waiting for an acknowledgment of the 547 connection termination request previously sent to the remote TCP 548 (this termination request sent to the remote TCP already included 549 an acknowledgment of the termination request sent from the remote 550 TCP). 552 TIME-WAIT - represents waiting for enough time to pass to be sure 553 the remote TCP received the acknowledgment of its connection 554 termination request. 556 CLOSED - represents no connection state at all. 558 A TCP connection progresses from one state to another in response to 559 events. The events are the user calls, OPEN, SEND, RECEIVE, CLOSE, 560 ABORT, and STATUS; the incoming segments, particularly those 561 containing the SYN, ACK, RST and FIN flags; and timeouts. 563 The state diagram in Figure 4 illustrates only state changes, 564 together with the causing events and resulting actions, but addresses 565 neither error conditions nor actions which are not connected with 566 state changes. In a later section, more detail is offered with 567 respect to the reaction of the TCP to events. 569 NOTA BENE: this diagram is only a summary and must not be taken as 570 the total specification. 572 +---------+ ---------\ active OPEN 573 | CLOSED | \ ----------- 574 +---------+<---------\ \ create TCB 575 | ^ \ \ snd SYN 576 passive OPEN | | CLOSE \ \ 577 ------------ | | ---------- \ \ 578 create TCB | | delete TCB \ \ 579 V | \ \ 580 rcv RST (note 1) +---------+ CLOSE | \ 581 -------------------->| LISTEN | ---------- | | 582 / +---------+ delete TCB | | 583 / rcv SYN | | SEND | | 584 / ----------- | | ------- | V 585 +--------+ snd SYN,ACK / \ snd SYN +--------+ 586 | |<----------------- ------------------>| | 587 | SYN | rcv SYN | SYN | 588 | RCVD |<-----------------------------------------------| SENT | 589 | | snd SYN,ACK | | 590 | |------------------ -------------------| | 591 +--------+ rcv ACK of SYN \ / rcv SYN,ACK +--------+ 592 | -------------- | | ----------- 593 | x | | snd ACK 594 | V V 595 | CLOSE +---------+ 596 | ------- | ESTAB | 597 | snd FIN +---------+ 598 | CLOSE | | rcv FIN 599 V ------- | | ------- 600 +---------+ snd FIN / \ snd ACK +---------+ 601 | FIN |<----------------- ------------------>| CLOSE | 602 | WAIT-1 |------------------ | WAIT | 603 +---------+ rcv FIN \ +---------+ 604 | rcv ACK of FIN ------- | CLOSE | 605 | -------------- snd ACK | ------- | 606 V x V snd FIN V 607 +---------+ +---------+ +---------+ 608 |FINWAIT-2| | CLOSING | | LAST-ACK| 609 +---------+ +---------+ +---------+ 610 | rcv ACK of FIN | rcv ACK of FIN | 611 | rcv FIN -------------- | Timeout=2MSL -------------- | 612 | ------- x V ------------ x V 613 \ snd ACK +---------+delete TCB +---------+ 614 ------------------------>|TIME WAIT|------------------>| CLOSED | 615 +---------+ +---------+ 617 note 1: The transition from SYN-RCVD to LISTEN on receiving a RST is 618 conditional on having reached SYN-RCVD after a passive open. 620 note 2: An unshown transition exists from FIN-WAIT-1 to TIME-WAIT if 621 a FIN is received and the local FIN is also acknowledged. 623 TCP Connection State Diagram 624 Figure 4 626 3.3. Sequence Numbers 628 A fundamental notion in the design is that every octet of data sent 629 over a TCP connection has a sequence number. Since every octet is 630 sequenced, each of them can be acknowledged. The acknowledgment 631 mechanism employed is cumulative so that an acknowledgment of 632 sequence number X indicates that all octets up to but not including X 633 have been received. This mechanism allows for straight-forward 634 duplicate detection in the presence of retransmission. Numbering of 635 octets within a segment is that the first data octet immediately 636 following the header is the lowest numbered, and the following octets 637 are numbered consecutively. 639 It is essential to remember that the actual sequence number space is 640 finite, though very large. This space ranges from 0 to 2**32 - 1. 641 Since the space is finite, all arithmetic dealing with sequence 642 numbers must be performed modulo 2**32. This unsigned arithmetic 643 preserves the relationship of sequence numbers as they cycle from 644 2**32 - 1 to 0 again. There are some subtleties to computer modulo 645 arithmetic, so great care should be taken in programming the 646 comparison of such values. The symbol "=<" means "less than or 647 equal" (modulo 2**32). 649 The typical kinds of sequence number comparisons which the TCP must 650 perform include: 652 (a) Determining that an acknowledgment refers to some sequence 653 number sent but not yet acknowledged. 655 (b) Determining that all sequence numbers occupied by a segment 656 have been acknowledged (e.g., to remove the segment from a 657 retransmission queue). 659 (c) Determining that an incoming segment contains sequence numbers 660 which are expected (i.e., that the segment "overlaps" the receive 661 window). 663 In response to sending data the TCP will receive acknowledgments. 664 The following comparisons are needed to process the acknowledgments. 666 SND.UNA = oldest unacknowledged sequence number 668 SND.NXT = next sequence number to be sent 670 SEG.ACK = acknowledgment from the receiving TCP (next sequence 671 number expected by the receiving TCP) 672 SEG.SEQ = first sequence number of a segment 674 SEG.LEN = the number of octets occupied by the data in the segment 675 (counting SYN and FIN) 677 SEG.SEQ+SEG.LEN-1 = last sequence number of a segment 679 A new acknowledgment (called an "acceptable ack"), is one for which 680 the inequality below holds: 682 SND.UNA < SEG.ACK =< SND.NXT 684 A segment on the retransmission queue is fully acknowledged if the 685 sum of its sequence number and length is less or equal than the 686 acknowledgment value in the incoming segment. 688 When data is received the following comparisons are needed: 690 RCV.NXT = next sequence number expected on an incoming segments, 691 and is the left or lower edge of the receive window 693 RCV.NXT+RCV.WND-1 = last sequence number expected on an incoming 694 segment, and is the right or upper edge of the receive window 696 SEG.SEQ = first sequence number occupied by the incoming segment 698 SEG.SEQ+SEG.LEN-1 = last sequence number occupied by the incoming 699 segment 701 A segment is judged to occupy a portion of valid receive sequence 702 space if 704 RCV.NXT =< SEG.SEQ < RCV.NXT+RCV.WND 706 or 708 RCV.NXT =< SEG.SEQ+SEG.LEN-1 < RCV.NXT+RCV.WND 710 The first part of this test checks to see if the beginning of the 711 segment falls in the window, the second part of the test checks to 712 see if the end of the segment falls in the window; if the segment 713 passes either part of the test it contains data in the window. 715 Actually, it is a little more complicated than this. Due to zero 716 windows and zero length segments, we have four cases for the 717 acceptability of an incoming segment: 719 Segment Receive Test 720 Length Window 721 ------- ------- ------------------------------------------- 723 0 0 SEG.SEQ = RCV.NXT 725 0 >0 RCV.NXT =< SEG.SEQ < RCV.NXT+RCV.WND 727 >0 0 not acceptable 729 >0 >0 RCV.NXT =< SEG.SEQ < RCV.NXT+RCV.WND 730 or RCV.NXT =< SEG.SEQ+SEG.LEN-1 < RCV.NXT+RCV.WND 732 Note that when the receive window is zero no segments should be 733 acceptable except ACK segments. Thus, it is be possible for a TCP to 734 maintain a zero receive window while transmitting data and receiving 735 ACKs. However, even when the receive window is zero, a TCP must 736 process the RST and URG fields of all incoming segments. 738 We have taken advantage of the numbering scheme to protect certain 739 control information as well. This is achieved by implicitly 740 including some control flags in the sequence space so they can be 741 retransmitted and acknowledged without confusion (i.e., one and only 742 one copy of the control will be acted upon). Control information is 743 not physically carried in the segment data space. Consequently, we 744 must adopt rules for implicitly assigning sequence numbers to 745 control. The SYN and FIN are the only controls requiring this 746 protection, and these controls are used only at connection opening 747 and closing. For sequence number purposes, the SYN is considered to 748 occur before the first actual data octet of the segment in which it 749 occurs, while the FIN is considered to occur after the last actual 750 data octet in a segment in which it occurs. The segment length 751 (SEG.LEN) includes both data and sequence space occupying controls. 752 When a SYN is present then SEG.SEQ is the sequence number of the SYN. 754 Initial Sequence Number Selection 756 The protocol places no restriction on a particular connection being 757 used over and over again. A connection is defined by a pair of 758 sockets. New instances of a connection will be referred to as 759 incarnations of the connection. The problem that arises from this is 760 -- "how does the TCP identify duplicate segments from previous 761 incarnations of the connection?" This problem becomes apparent if 762 the connection is being opened and closed in quick succession, or if 763 the connection breaks with loss of memory and is then reestablished. 765 To avoid confusion we must prevent segments from one incarnation of a 766 connection from being used while the same sequence numbers may still 767 be present in the network from an earlier incarnation. We want to 768 assure this, even if a TCP crashes and loses all knowledge of the 769 sequence numbers it has been using. When new connections are 770 created, an initial sequence number (ISN) generator is employed which 771 selects a new 32 bit ISN. There are security issues that result if 772 an off-path attacker is able to predict or guess ISN values. 774 The recommended ISN generator is based on the combination of a 775 (possibly fictitious) 32 bit clock whose low order bit is incremented 776 roughly every 4 microseconds, and a pseudorandom hash function (PRF). 777 The clock component is intended to insure that with a Maximum Segment 778 Lifetime (MSL), generated ISNs will be unique, since it cycles 779 approximately every 4.55 hours, which is much longer than the MSL. 780 This recommended algorithm is further described in RFC 1948 and 781 builds on the basic clock-driven algorithm from RFC 793. 783 A TCP MUST use a clock-driven selection of initial sequence numbers, 784 and SHOULD generate its Initial Sequence Numbers with the expression: 786 ISN = M + F(localip, localport, remoteip, remoteport, secretkey) 788 where M is the 4 microsecond timer, and F() is a pseudorandom 789 function (PRF) of the connection's identifying parameters ("localip, 790 localport, remoteip, remoteport") and a secret key ("secretkey"). 791 F() MUST NOT be computable from the outside, or an attacker could 792 still guess at sequence numbers from the ISN used for some other 793 connection. The PRF could be implemented as a cryptographic has of 794 the concatenation of the TCP connection parameters and some secret 795 data. For discussion of the selection of a specific hash algorithm 796 and management of the secret key data, please see Section 3 of [17]. 798 For each connection there is a send sequence number and a receive 799 sequence number. The initial send sequence number (ISS) is chosen by 800 the data sending TCP, and the initial receive sequence number (IRS) 801 is learned during the connection establishing procedure. 803 For a connection to be established or initialized, the two TCPs must 804 synchronize on each other's initial sequence numbers. This is done 805 in an exchange of connection establishing segments carrying a control 806 bit called "SYN" (for synchronize) and the initial sequence numbers. 807 As a shorthand, segments carrying the SYN bit are also called "SYNs". 808 Hence, the solution requires a suitable mechanism for picking an 809 initial sequence number and a slightly involved handshake to exchange 810 the ISN's. 812 The synchronization requires each side to send it's own initial 813 sequence number and to receive a confirmation of it in acknowledgment 814 from the other side. Each side must also receive the other side's 815 initial sequence number and send a confirming acknowledgment. 817 1) A --> B SYN my sequence number is X 818 2) A <-- B ACK your sequence number is X 819 3) A <-- B SYN my sequence number is Y 820 4) A --> B ACK your sequence number is Y 822 Because steps 2 and 3 can be combined in a single message this is 823 called the three way (or three message) handshake. 825 A three way handshake is necessary because sequence numbers are not 826 tied to a global clock in the network, and TCPs may have different 827 mechanisms for picking the ISN's. The receiver of the first SYN has 828 no way of knowing whether the segment was an old delayed one or not, 829 unless it remembers the last sequence number used on the connection 830 (which is not always possible), and so it must ask the sender to 831 verify this SYN. The three way handshake and the advantages of a 832 clock-driven scheme are discussed in [3]. 834 Knowing When to Keep Quiet 836 To be sure that a TCP does not create a segment that carries a 837 sequence number which may be duplicated by an old segment remaining 838 in the network, the TCP must keep quiet for an MSL before assigning 839 any sequence numbers upon starting up or recovering from a crash in 840 which memory of sequence numbers in use was lost. For this 841 specification the MSL is taken to be 2 minutes. This is an 842 engineering choice, and may be changed if experience indicates it is 843 desirable to do so. Note that if a TCP is reinitialized in some 844 sense, yet retains its memory of sequence numbers in use, then it 845 need not wait at all; it must only be sure to use sequence numbers 846 larger than those recently used. 848 The TCP Quiet Time Concept 850 This specification provides that hosts which "crash" without 851 retaining any knowledge of the last sequence numbers transmitted on 852 each active (i.e., not closed) connection shall delay emitting any 853 TCP segments for at least the agreed MSL in the internet system of 854 which the host is a part. In the paragraphs below, an explanation 855 for this specification is given. TCP implementors may violate the 856 "quiet time" restriction, but only at the risk of causing some old 857 data to be accepted as new or new data rejected as old duplicated by 858 some receivers in the internet system. 860 TCPs consume sequence number space each time a segment is formed and 861 entered into the network output queue at a source host. The 862 duplicate detection and sequencing algorithm in the TCP protocol 863 relies on the unique binding of segment data to sequence space to the 864 extent that sequence numbers will not cycle through all 2**32 values 865 before the segment data bound to those sequence numbers has been 866 delivered and acknowledged by the receiver and all duplicate copies 867 of the segments have "drained" from the internet. Without such an 868 assumption, two distinct TCP segments could conceivably be assigned 869 the same or overlapping sequence numbers, causing confusion at the 870 receiver as to which data is new and which is old. Remember that 871 each segment is bound to as many consecutive sequence numbers as 872 there are octets of data and SYN or FIN flags in the segment. 874 Under normal conditions, TCPs keep track of the next sequence number 875 to emit and the oldest awaiting acknowledgment so as to avoid 876 mistakenly using a sequence number over before its first use has been 877 acknowledged. This alone does not guarantee that old duplicate data 878 is drained from the net, so the sequence space has been made very 879 large to reduce the probability that a wandering duplicate will cause 880 trouble upon arrival. At 2 megabits/sec. it takes 4.5 hours to use 881 up 2**32 octets of sequence space. Since the maximum segment 882 lifetime in the net is not likely to exceed a few tens of seconds, 883 this is deemed ample protection for foreseeable nets, even if data 884 rates escalate to l0's of megabits/sec. At 100 megabits/sec, the 885 cycle time is 5.4 minutes which may be a little short, but still 886 within reason. 888 The basic duplicate detection and sequencing algorithm in TCP can be 889 defeated, however, if a source TCP does not have any memory of the 890 sequence numbers it last used on a given connection. For example, if 891 the TCP were to start all connections with sequence number 0, then 892 upon crashing and restarting, a TCP might re-form an earlier 893 connection (possibly after half-open connection resolution) and emit 894 packets with sequence numbers identical to or overlapping with 895 packets still in the network which were emitted on an earlier 896 incarnation of the same connection. In the absence of knowledge 897 about the sequence numbers used on a particular connection, the TCP 898 specification recommends that the source delay for MSL seconds before 899 emitting segments on the connection, to allow time for segments from 900 the earlier connection incarnation to drain from the system. 902 Even hosts which can remember the time of day and used it to select 903 initial sequence number values are not immune from this problem 904 (i.e., even if time of day is used to select an initial sequence 905 number for each new connection incarnation). 907 Suppose, for example, that a connection is opened starting with 908 sequence number S. Suppose that this connection is not used much and 909 that eventually the initial sequence number function (ISN(t)) takes 910 on a value equal to the sequence number, say S1, of the last segment 911 sent by this TCP on a particular connection. Now suppose, at this 912 instant, the host crashes, recovers, and establishes a new 913 incarnation of the connection. The initial sequence number chosen is 914 S1 = ISN(t) -- last used sequence number on old incarnation of 915 connection! If the recovery occurs quickly enough, any old 916 duplicates in the net bearing sequence numbers in the neighborhood of 917 S1 may arrive and be treated as new packets by the receiver of the 918 new incarnation of the connection. 920 The problem is that the recovering host may not know for how long it 921 crashed nor does it know whether there are still old duplicates in 922 the system from earlier connection incarnations. 924 One way to deal with this problem is to deliberately delay emitting 925 segments for one MSL after recovery from a crash- this is the "quiet 926 time" specification. Hosts which prefer to avoid waiting are willing 927 to risk possible confusion of old and new packets at a given 928 destination may choose not to wait for the "quite time". 929 Implementors may provide TCP users with the ability to select on a 930 connection by connection basis whether to wait after a crash, or may 931 informally implement the "quite time" for all connections. 932 Obviously, even where a user selects to "wait," this is not necessary 933 after the host has been "up" for at least MSL seconds. 935 To summarize: every segment emitted occupies one or more sequence 936 numbers in the sequence space, the numbers occupied by a segment are 937 "busy" or "in use" until MSL seconds have passed, upon crashing a 938 block of space-time is occupied by the octets and SYN or FIN flags of 939 the last emitted segment, if a new connection is started too soon and 940 uses any of the sequence numbers in the space-time footprint of the 941 last segment of the previous connection incarnation, there is a 942 potential sequence number overlap area which could cause confusion at 943 the receiver. 945 3.4. Establishing a connection 947 The "three-way handshake" is the procedure used to establish a 948 connection. This procedure normally is initiated by one TCP and 949 responded to by another TCP. The procedure also works if two TCP 950 simultaneously initiate the procedure. When simultaneous attempt 951 occurs, each TCP receives a "SYN" segment which carries no 952 acknowledgment after it has sent a "SYN". Of course, the arrival of 953 an old duplicate "SYN" segment can potentially make it appear, to the 954 recipient, that a simultaneous connection initiation is in progress. 955 Proper use of "reset" segments can disambiguate these cases. 957 Several examples of connection initiation follow. Although these 958 examples do not show connection synchronization using data-carrying 959 segments, this is perfectly legitimate, so long as the receiving TCP 960 doesn't deliver the data to the user until it is clear the data is 961 valid (i.e., the data must be buffered at the receiver until the 962 connection reaches the ESTABLISHED state). The three-way handshake 963 reduces the possibility of false connections. It is the 964 implementation of a trade-off between memory and messages to provide 965 information for this checking. 967 The simplest three-way handshake is shown in Figure 5 below. The 968 figures should be interpreted in the following way. Each line is 969 numbered for reference purposes. Right arrows (-->) indicate 970 departure of a TCP segment from TCP A to TCP B, or arrival of a 971 segment at B from A. Left arrows (<--), indicate the reverse. 972 Ellipsis (...) indicates a segment which is still in the network 973 (delayed). An "XXX" indicates a segment which is lost or rejected. 974 Comments appear in parentheses. TCP states represent the state AFTER 975 the departure or arrival of the segment (whose contents are shown in 976 the center of each line). Segment contents are shown in abbreviated 977 form, with sequence number, control flags, and ACK field. Other 978 fields such as window, addresses, lengths, and text have been left 979 out in the interest of clarity. 981 TCP A TCP B 983 1. CLOSED LISTEN 985 2. SYN-SENT --> --> SYN-RECEIVED 987 3. ESTABLISHED <-- <-- SYN-RECEIVED 989 4. ESTABLISHED --> --> ESTABLISHED 991 5. ESTABLISHED --> --> ESTABLISHED 993 Basic 3-Way Handshake for Connection Synchronization 995 Figure 5 997 In line 2 of Figure 5, TCP A begins by sending a SYN segment 998 indicating that it will use sequence numbers starting with sequence 999 number 100. In line 3, TCP B sends a SYN and acknowledges the SYN it 1000 received from TCP A. Note that the acknowledgment field indicates 1001 TCP B is now expecting to hear sequence 101, acknowledging the SYN 1002 which occupied sequence 100. 1004 At line 4, TCP A responds with an empty segment containing an ACK for 1005 TCP B's SYN; and in line 5, TCP A sends some data. Note that the 1006 sequence number of the segment in line 5 is the same as in line 4 1007 because the ACK does not occupy sequence number space (if it did, we 1008 would wind up ACKing ACK's!). 1010 Simultaneous initiation is only slightly more complex, as is shown in 1011 Figure 6. Each TCP cycles from CLOSED to SYN-SENT to SYN-RECEIVED to 1012 ESTABLISHED. 1014 TCP A TCP B 1016 1. CLOSED CLOSED 1018 2. SYN-SENT --> ... 1020 3. SYN-RECEIVED <-- <-- SYN-SENT 1022 4. ... --> SYN-RECEIVED 1024 5. SYN-RECEIVED --> ... 1026 6. ESTABLISHED <-- <-- SYN-RECEIVED 1028 7. ... --> ESTABLISHED 1030 Simultaneous Connection Synchronization 1032 Figure 6 1034 A TCP MUST support simultaneous open attempts. 1036 Note that a TCP implementation MUST keep track of whether a 1037 connection has reached SYN_RCVD state as the result of a passive OPEN 1038 or an active OPEN. 1040 The principle reason for the three-way handshake is to prevent old 1041 duplicate connection initiations from causing confusion. To deal 1042 with this, a special control message, reset, has been devised. If 1043 the receiving TCP is in a non-synchronized state (i.e., SYN-SENT, 1044 SYN-RECEIVED), it returns to LISTEN on receiving an acceptable reset. 1045 If the TCP is in one of the synchronized states (ESTABLISHED, FIN- 1046 WAIT-1, FIN-WAIT-2, CLOSE-WAIT, CLOSING, LAST-ACK, TIME-WAIT), it 1047 aborts the connection and informs its user. We discuss this latter 1048 case under "half-open" connections below. 1050 TCP A TCP B 1052 1. CLOSED LISTEN 1054 2. SYN-SENT --> ... 1056 3. (duplicate) ... --> SYN-RECEIVED 1058 4. SYN-SENT <-- <-- SYN-RECEIVED 1060 5. SYN-SENT --> --> LISTEN 1062 6. ... --> SYN-RECEIVED 1064 7. SYN-SENT <-- <-- SYN-RECEIVED 1066 8. ESTABLISHED --> --> ESTABLISHED 1068 Recovery from Old Duplicate SYN 1070 Figure 7 1072 As a simple example of recovery from old duplicates, consider 1073 Figure 7. At line 3, an old duplicate SYN arrives at TCP B. TCP B 1074 cannot tell that this is an old duplicate, so it responds normally 1075 (line 4). TCP A detects that the ACK field is incorrect and returns 1076 a RST (reset) with its SEQ field selected to make the segment 1077 believable. TCP B, on receiving the RST, returns to the LISTEN 1078 state. When the original SYN (pun intended) finally arrives at line 1079 6, the synchronization proceeds normally. If the SYN at line 6 had 1080 arrived before the RST, a more complex exchange might have occurred 1081 with RST's sent in both directions. 1083 Half-Open Connections and Other Anomalies 1085 An established connection is said to be "half-open" if one of the 1086 TCPs has closed or aborted the connection at its end without the 1087 knowledge of the other, or if the two ends of the connection have 1088 become desynchronized owing to a crash that resulted in loss of 1089 memory. Such connections will automatically become reset if an 1090 attempt is made to send data in either direction. However, half-open 1091 connections are expected to be unusual, and the recovery procedure is 1092 mildly involved. 1094 If at site A the connection no longer exists, then an attempt by the 1095 user at site B to send any data on it will result in the site B TCP 1096 receiving a reset control message. Such a message indicates to the 1097 site B TCP that something is wrong, and it is expected to abort the 1098 connection. 1100 Assume that two user processes A and B are communicating with one 1101 another when a crash occurs causing loss of memory to A's TCP. 1102 Depending on the operating system supporting A's TCP, it is likely 1103 that some error recovery mechanism exists. When the TCP is up again, 1104 A is likely to start again from the beginning or from a recovery 1105 point. As a result, A will probably try to OPEN the connection again 1106 or try to SEND on the connection it believes open. In the latter 1107 case, it receives the error message "connection not open" from the 1108 local (A's) TCP. In an attempt to establish the connection, A's TCP 1109 will send a segment containing SYN. This scenario leads to the 1110 example shown in Figure 8. After TCP A crashes, the user attempts to 1111 re-open the connection. TCP B, in the meantime, thinks the 1112 connection is open. 1114 TCP A TCP B 1116 1. (CRASH) (send 300,receive 100) 1118 2. CLOSED ESTABLISHED 1120 3. SYN-SENT --> --> (??) 1122 4. (!!) <-- <-- ESTABLISHED 1124 5. SYN-SENT --> --> (Abort!!) 1126 6. SYN-SENT CLOSED 1128 7. SYN-SENT --> --> 1130 Half-Open Connection Discovery 1132 Figure 8 1134 When the SYN arrives at line 3, TCP B, being in a synchronized state, 1135 and the incoming segment outside the window, responds with an 1136 acknowledgment indicating what sequence it next expects to hear (ACK 1137 100). TCP A sees that this segment does not acknowledge anything it 1138 sent and, being unsynchronized, sends a reset (RST) because it has 1139 detected a half-open connection. TCP B aborts at line 5. TCP A will 1140 continue to try to establish the connection; the problem is now 1141 reduced to the basic 3-way handshake of Figure 5. 1143 An interesting alternative case occurs when TCP A crashes and TCP B 1144 tries to send data on what it thinks is a synchronized connection. 1146 This is illustrated in Figure 9. In this case, the data arriving at 1147 TCP A from TCP B (line 2) is unacceptable because no such connection 1148 exists, so TCP A sends a RST. The RST is acceptable so TCP B 1149 processes it and aborts the connection. 1151 TCP A TCP B 1153 1. (CRASH) (send 300,receive 100) 1155 2. (??) <-- <-- ESTABLISHED 1157 3. --> --> (ABORT!!) 1159 Active Side Causes Half-Open Connection Discovery 1161 Figure 9 1163 In Figure 10, we find the two TCPs A and B with passive connections 1164 waiting for SYN. An old duplicate arriving at TCP B (line 2) stirs B 1165 into action. A SYN-ACK is returned (line 3) and causes TCP A to 1166 generate a RST (the ACK in line 3 is not acceptable). TCP B accepts 1167 the reset and returns to its passive LISTEN state. 1169 TCP A TCP B 1171 1. LISTEN LISTEN 1173 2. ... --> SYN-RECEIVED 1175 3. (??) <-- <-- SYN-RECEIVED 1177 4. --> --> (return to LISTEN!) 1179 5. LISTEN LISTEN 1181 Old Duplicate SYN Initiates a Reset on two Passive Sockets 1183 Figure 10 1185 A variety of other cases are possible, all of which are accounted for 1186 by the following rules for RST generation and processing. 1188 Reset Generation 1189 As a general rule, reset (RST) must be sent whenever a segment 1190 arrives which apparently is not intended for the current connection. 1191 A reset must not be sent if it is not clear that this is the case. 1193 There are three groups of states: 1195 1. If the connection does not exist (CLOSED) then a reset is sent 1196 in response to any incoming segment except another reset. In 1197 particular, SYNs addressed to a non-existent connection are 1198 rejected by this means. 1200 If the incoming segment has the ACK bit set, the reset takes its 1201 sequence number from the ACK field of the segment, otherwise the 1202 reset has sequence number zero and the ACK field is set to the sum 1203 of the sequence number and segment length of the incoming segment. 1204 The connection remains in the CLOSED state. 1206 2. If the connection is in any non-synchronized state (LISTEN, 1207 SYN-SENT, SYN-RECEIVED), and the incoming segment acknowledges 1208 something not yet sent (the segment carries an unacceptable ACK), 1209 or if an incoming segment has a security level or compartment 1210 which does not exactly match the level and compartment requested 1211 for the connection, a reset is sent. 1213 If our SYN has not been acknowledged and the precedence level of 1214 the incoming segment is higher than the precedence level requested 1215 then either raise the local precedence level (if allowed by the 1216 user and the system) or send a reset; or if the precedence level 1217 of the incoming segment is lower than the precedence level 1218 requested then continue as if the precedence matched exactly (if 1219 the remote TCP cannot raise the precedence level to match ours 1220 this will be detected in the next segment it sends, and the 1221 connection will be terminated then). If our SYN has been 1222 acknowledged (perhaps in this incoming segment) the precedence 1223 level of the incoming segment must match the local precedence 1224 level exactly, if it does not a reset must be sent. 1226 If the incoming segment has an ACK field, the reset takes its 1227 sequence number from the ACK field of the segment, otherwise the 1228 reset has sequence number zero and the ACK field is set to the sum 1229 of the sequence number and segment length of the incoming segment. 1230 The connection remains in the same state. 1232 3. If the connection is in a synchronized state (ESTABLISHED, 1233 FIN-WAIT-1, FIN-WAIT-2, CLOSE-WAIT, CLOSING, LAST-ACK, TIME-WAIT), 1234 any unacceptable segment (out of window sequence number or 1235 unacceptable acknowledgment number) must elicit only an empty 1236 acknowledgment segment containing the current send-sequence number 1237 and an acknowledgment indicating the next sequence number expected 1238 to be received, and the connection remains in the same state. 1240 If an incoming segment has a security level, or compartment, or 1241 precedence which does not exactly match the level, and 1242 compartment, and precedence requested for the connection,a reset 1243 is sent and the connection goes to the CLOSED state. The reset 1244 takes its sequence number from the ACK field of the incoming 1245 segment. 1247 Reset Processing 1249 In all states except SYN-SENT, all reset (RST) segments are validated 1250 by checking their SEQ-fields. A reset is valid if its sequence 1251 number is in the window. In the SYN-SENT state (a RST received in 1252 response to an initial SYN), the RST is acceptable if the ACK field 1253 acknowledges the SYN. 1255 The receiver of a RST first validates it, then changes state. If the 1256 receiver was in the LISTEN state, it ignores it. If the receiver was 1257 in SYN-RECEIVED state and had previously been in the LISTEN state, 1258 then the receiver returns to the LISTEN state, otherwise the receiver 1259 aborts the connection and goes to the CLOSED state. If the receiver 1260 was in any other state, it aborts the connection and advises the user 1261 and goes to the CLOSED state. 1263 TCP SHOULD allow a received RST segment to include data. 1265 3.4.1. Remote Address Validation 1267 TODO - figure out if this section would fit better elsewhere, for 1268 instance in the more detailed description of the OPEN call later on 1270 A TCP implementation MUST reject as an error a local OPEN call for an 1271 invalid remote IP address (e.g., a broadcast or multicast address). 1273 An incoming SYN with an invalid source address must be ignored either 1274 by TCP or by the IP layer (see Section 3.2.1.3 of [10]). 1276 A TCP implementation MUST silently discard an incoming SYN segment 1277 that is addressed to a broadcast or multicast address. 1279 3.5. Closing a Connection 1281 CLOSE is an operation meaning "I have no more data to send." The 1282 notion of closing a full-duplex connection is subject to ambiguous 1283 interpretation, of course, since it may not be obvious how to treat 1284 the receiving side of the connection. We have chosen to treat CLOSE 1285 in a simplex fashion. The user who CLOSEs may continue to RECEIVE 1286 until he is told that the other side has CLOSED also. Thus, a 1287 program could initiate several SENDs followed by a CLOSE, and then 1288 continue to RECEIVE until signaled that a RECEIVE failed because the 1289 other side has CLOSED. We assume that the TCP will signal a user, 1290 even if no RECEIVEs are outstanding, that the other side has closed, 1291 so the user can terminate his side gracefully. A TCP will reliably 1292 deliver all buffers SENT before the connection was CLOSED so a user 1293 who expects no data in return need only wait to hear the connection 1294 was CLOSED successfully to know that all his data was received at the 1295 destination TCP. Users must keep reading connections they close for 1296 sending until the TCP says no more data. 1298 There are essentially three cases: 1300 1) The user initiates by telling the TCP to CLOSE the connection 1302 2) The remote TCP initiates by sending a FIN control signal 1304 3) Both users CLOSE simultaneously 1306 Case 1: Local user initiates the close 1308 In this case, a FIN segment can be constructed and placed on the 1309 outgoing segment queue. No further SENDs from the user will be 1310 accepted by the TCP, and it enters the FIN-WAIT-1 state. RECEIVEs 1311 are allowed in this state. All segments preceding and including 1312 FIN will be retransmitted until acknowledged. When the other TCP 1313 has both acknowledged the FIN and sent a FIN of its own, the first 1314 TCP can ACK this FIN. Note that a TCP receiving a FIN will ACK 1315 but not send its own FIN until its user has CLOSED the connection 1316 also. 1318 Case 2: TCP receives a FIN from the network 1320 If an unsolicited FIN arrives from the network, the receiving TCP 1321 can ACK it and tell the user that the connection is closing. The 1322 user will respond with a CLOSE, upon which the TCP can send a FIN 1323 to the other TCP after sending any remaining data. The TCP then 1324 waits until its own FIN is acknowledged whereupon it deletes the 1325 connection. If an ACK is not forthcoming, after the user timeout 1326 the connection is aborted and the user is told. 1328 Case 3: both users close simultaneously 1330 A simultaneous CLOSE by users at both ends of a connection causes 1331 FIN segments to be exchanged. When all segments preceding the 1332 FINs have been processed and acknowledged, each TCP can ACK the 1333 FIN it has received. Both will, upon receiving these ACKs, delete 1334 the connection. 1336 TCP A TCP B 1338 1. ESTABLISHED ESTABLISHED 1340 2. (Close) 1341 FIN-WAIT-1 --> --> CLOSE-WAIT 1343 3. FIN-WAIT-2 <-- <-- CLOSE-WAIT 1345 4. (Close) 1346 TIME-WAIT <-- <-- LAST-ACK 1348 5. TIME-WAIT --> --> CLOSED 1350 6. (2 MSL) 1351 CLOSED 1353 Normal Close Sequence 1355 Figure 11 1357 TCP A TCP B 1359 1. ESTABLISHED ESTABLISHED 1361 2. (Close) (Close) 1362 FIN-WAIT-1 --> ... FIN-WAIT-1 1363 <-- <-- 1364 ... --> 1366 3. CLOSING --> ... CLOSING 1367 <-- <-- 1368 ... --> 1370 4. TIME-WAIT TIME-WAIT 1371 (2 MSL) (2 MSL) 1372 CLOSED CLOSED 1374 Simultaneous Close Sequence 1376 Figure 12 1378 A TCP connection may terminate in two ways: (1) the normal TCP close 1379 sequence using a FIN handshake, and (2) an "abort" in which one or 1380 more RST segments are sent and the connection state is immediately 1381 discarded. If a TCP connection is closed by the remote site, the 1382 local application MUST be informed whether it closed normally or was 1383 aborted. 1385 3.5.1. Half-Closed Connections 1387 The normal TCP close sequence delivers buffered data reliably in both 1388 directions. Since the two directions of a TCP connection are closed 1389 independently, it is possible for a connection to be "half closed," 1390 i.e., closed in only one direction, and a host is permitted to 1391 continue sending data in the open direction on a half-closed 1392 connection. 1394 A host MAY implement a "half-duplex" TCP close sequence, so that an 1395 application that has called CLOSE cannot continue to read data from 1396 the connection. If such a host issues a CLOSE call while received 1397 data is still pending in TCP, or if new data is received after CLOSE 1398 is called, its TCP SHOULD send a RST to show that data was lost. 1400 When a connection is closed actively, it MUST linger in TIME-WAIT 1401 state for a time 2xMSL (Maximum Segment Lifetime). However, it MAY 1402 accept a new SYN from the remote TCP to reopen the connection 1403 directly from TIME-WAIT state, if it: 1405 (1) assigns its initial sequence number for the new connection to 1406 be larger than the largest sequence number it used on the previous 1407 connection incarnation, and 1409 (2) returns to TIME-WAIT state if the SYN turns out to be an old 1410 duplicate. 1412 3.6. Precedence and Security 1414 The intent is that connection be allowed only between ports operating 1415 with exactly the same security and compartment values and at the 1416 higher of the precedence level requested by the two ports. 1418 The precedence and security parameters used in TCP are exactly those 1419 defined in the Internet Protocol (IP) [1]. Throughout this TCP 1420 specification the term "security/compartment" is intended to indicate 1421 the security parameters used in IP including security, compartment, 1422 user group, and handling restriction. 1424 A connection attempt with mismatched security/compartment values or a 1425 lower precedence value must be rejected by sending a reset. 1426 Rejecting a connection due to too low a precedence only occurs after 1427 an acknowledgment of the SYN has been received. 1429 Note that TCP modules which operate only at the default value of 1430 precedence will still have to check the precedence of incoming 1431 segments and possibly raise the precedence level they use on the 1432 connection. 1434 The security parameters may be used even in a non-secure environment 1435 (the values would indicate unclassified data), thus hosts in non- 1436 secure environments must be prepared to receive the security 1437 parameters, though they need not send them. 1439 3.7. Segmentation 1441 The term "segmentation" refers to the activity TCP performs when 1442 ingesting a stream of bytes from a sending application and 1443 packetizing that stream of bytes into TCP segments. Individual TCP 1444 segments often do not correspond one-for-one to individual send (or 1445 socket write) calls from the application. Applications may perform 1446 writes at the granularity of messages in the upper layer protocol, 1447 but TCP guarantees no boundary coherence between the TCP segments 1448 sent and received versus user application data read or write buffer 1449 boundaries. In some specific protocols, such as RDMA using DDP and 1450 MPA [12], there are performance optimizations possible when the 1451 relation between TCP segments and application data units can be 1452 controlled, and MPA includes a specific mechanism for detecting and 1453 verifying this relationship between TCP segments and application 1454 message data strcutures, but this is specific to applications like 1455 RDMA. In general, multiple goals influence the sizing of TCP 1456 segments created by a TCP implementation. 1458 Goals driving the sending of larger segments include: 1460 o Reducing the number of packets in flight within the network. 1462 o Increasing processing efficiency and potential performance by 1463 enabling a smaller number of interrupts and inter-layer 1464 interactions. 1466 o Limiting the overhead of TCP headers. 1468 Note that the performance benefits of sending larger segments may 1469 decrease as the size increases, and there may be boundaries where 1470 advantages are reversed. For instance, on some machines 1025 bytes 1471 within a segment could lead to worse performance than 1024 bytes, due 1472 purely to data alignment on copy operations. 1474 Goals driving the sending of smaller segments include: 1476 o Avoiding sending segments larger than the smallest MTU within an 1477 IP network path, because this results in either packet loss or 1478 fragmentation. Making matters worse, some firewalls or 1479 middleboxes may drop fragmented packets or ICMP messages related 1480 related to fragmentation. 1482 o Preventing delays to the application data stream, especially when 1483 TCP is waiting on the application to generate more data, or when 1484 the application is waiting on an event or input from its peer in 1485 order to generate more data. 1487 o Enabling "fate sharing" between TCP segments and lower-layer data 1488 units (e.g. below IP, for links with cell or frame sizes smaller 1489 than the IP MTU). 1491 Towards meeting these competing sets of goals, TCP includes several 1492 mechanisms, including the Maximum Segment Size option, Path MTU 1493 Discovery, the Nagle algorithm, and support for IPv6 Jumbograms, as 1494 discussed in the following subsections. 1496 3.7.1. Maximum Segment Size Option 1498 TCP MUST implement both sending and receiving the MSS option. 1500 TCP SHOULD send an MSS option in every SYN segment when its receive 1501 MSS differs from the default 536 for IPv4 or 1220 for IPv6, and MAY 1502 send it always. 1504 If an MSS option is not received at connection setup, TCP MUST assume 1505 a default send MSS of 536 (576-40) for IPv4 or 1220 (1280 - 60) for 1506 IPv6. 1508 The maximum size of a segment that TCP really sends, the "effective 1509 send MSS," MUST be the smaller of the send MSS (which reflects the 1510 available reassembly buffer size at the remote host) and the largest 1511 size permitted by the IP layer: 1513 Eff.snd.MSS = 1515 min(SendMSS+20, MMS_S) - TCPhdrsize - IPoptionsize 1517 where: 1519 o SendMSS is the MSS value received from the remote host, or the 1520 default 536 for IPv4 or 1220 for IPv6, if no MSS option is 1521 received. 1523 o MMS_S is the maximum size for a transport-layer message that TCP 1524 may send. 1526 o TCPhdrsize is the size of the fixed TCP header and any options. 1527 This is 20 in the (rare) case that no options are present, but may 1528 be larger if TCP options are to be sent. Note that some options 1529 may not be included on all segments, but that for each segment 1530 sent, the sender should adjust the data length accordingly, within 1531 the Eff.snd.MSS. 1533 o IPoptionsize is the size of any IP options associated with a TCP 1534 connection. Note that some options may not be included on all 1535 packets, but that for each segment sent, the sender should adjust 1536 the data length accordingly, within the Eff.snd.MSS. 1538 The MSS value to be sent in an MSS option should be equal to the 1539 effective MTU minus the fixed IP and TCP headers. By ignoring both 1540 IP and TCP options when calculating the value for the MSS option, if 1541 there are any IP or TCP options to be sent in a packet, then the 1542 sender must decrease the size of the TCP data accordingly. RFC 6691 1543 [18] discusses this in greater detail. 1545 The MSS value to be sent in an MSS option must be less than or equal 1546 to: 1548 MMS_R - 20 1550 where MMS_R is the maximum size for a transport-layer message that 1551 can be received (and reassembled). TCP obtains MMS_R and MMS_S from 1552 the IP layer; see the generic call GET_MAXSIZES in Section 3.4 of RFC 1553 1122. 1555 When TCP is used in a situation where either the IP or TCP headers 1556 are not fixed, the sender must reduce the amount of TCP data in any 1557 given packet by the number of octets used by the IP and TCP options. 1558 This has been a point of confusion historically, as explained in RFC 1559 6691, Section 3.1. 1561 3.7.2. Path MTU Discovery 1563 A TCP implementation may be aware of the MTU on directly connected 1564 links, but will rarely have insight about MTUs across an entire 1565 network path. For IPv4, RFC 1122 provides an IP-layer recommendation 1566 on the default effective MTU for sending to be less than or equal to 1567 576 for destinations not directly connected. For IPv6, this would be 1568 1280. In all cases, however, implementation of Path MTU Discovery 1569 (PMTUD) and Packetization Layer Path MTU Discovery (PLPMTUD) is 1570 strongly recommended in order for TCP to improve segmentation 1571 decisions. 1573 PMTUD for IPv4 [2] or IPv6 [3] is implemented in conjunction between 1574 TCP, IP, and ICMP protocols. Several adjustments to a TCP 1575 implementation with PMTUD are described in RFC 2923 in order to deal 1576 with problems experienced in practice [6]. PLPMTUD [11] is a 1577 Standards Track improvement to PMTUD that relaxes the requirement for 1578 ICMP support across a path, and improves performance in cases where 1579 ICMP is not consistently conveyed. The mechanisms in all four of 1580 these RFCs are recommended to be included in TCP implementations. 1582 The TCP MSS option specifies an upper bound for the size of packets 1583 that can be received. Hence, setting the value in the MSS option too 1584 small can impact the ability for PMTUD or PLPMTUD to find a larger 1585 path MTU. RFC 1191 discusses this implication of many older TCP 1586 implementations setting MSS to 536 for non-local destinations, rather 1587 than deriving it from the MTUs of connected interfaces as 1588 recommended. 1590 3.7.3. Interfaces with Variable MTU Values 1592 The effective MTU can sometimes vary, as when used with variable 1593 compression, e.g., RObust Header Compression (ROHC) [14]. It is 1594 tempting for TCP to want to advertise the largest possible MSS, to 1595 support the most efficient use of compressed payloads. 1596 Unfortunately, some compression schemes occasionally need to transmit 1597 full headers (and thus smaller payloads) to resynchronize state at 1598 their endpoint compressors/decompressors. If the largest MTU is used 1599 to calculate the value to advertise in the MSS option, TCP 1600 retransmission may interfere with compressor resynchronization. 1602 As a result, when the effective MTU of an interface varies, TCP 1603 SHOULD use the smallest effective MTU of the interface to calculate 1604 the value to advertise in the MSS option. 1606 3.7.4. Nagle Algorithm 1608 The "Nagle algorithm" was described in RFC 896 [9] and was 1609 recommended in RFC 1122 [10] for mitigation of an early problem of 1610 too many small packets being generated. It has been implemented in 1611 most current TCP code bases, sometimes with minor variations. 1613 If there is unacknowledged data (i.e., SND.NXT > SND.UNA), then the 1614 sending TCP buffers all user data (regardless of the PSH bit), until 1615 the outstanding data has been acknowledged or until the TCP can send 1616 a full-sized segment (Eff.snd.MSS bytes). 1618 TODO - see if SEND description later should be updated to reflect 1619 this 1621 A TCP SHOULD implement the Nagle Algorithm to coalesce short 1622 segments. However, there MUST be a way for an application to disable 1623 the Nagle algorithm on an individual connection. In all cases, 1624 sending data is also subject to the limitation imposed by the Slow 1625 Start algorithm [13]. 1627 3.7.5. IPv6 Jumbograms 1629 In order to support TCP over IPv6 jumbograms, implementations need to 1630 be able to send TCP segments larger than the 64KB limit that the MSS 1631 option can convey. RFC 2675 [5] defines that an MSS value of 65,535 1632 bytes is to be treated as infinity, and Path MTU Discovery [3] is 1633 used to determine the actual MSS. 1635 3.8. Data Communication 1637 Once the connection is established data is communicated by the 1638 exchange of segments. Because segments may be lost due to errors 1639 (checksum test failure), or network congestion, TCP uses 1640 retransmission (after a timeout) to ensure delivery of every segment. 1641 Duplicate segments may arrive due to network or TCP retransmission. 1642 As discussed in the section on sequence numbers the TCP performs 1643 certain tests on the sequence and acknowledgment numbers in the 1644 segments to verify their acceptability. 1646 The sender of data keeps track of the next sequence number to use in 1647 the variable SND.NXT. The receiver of data keeps track of the next 1648 sequence number to expect in the variable RCV.NXT. The sender of 1649 data keeps track of the oldest unacknowledged sequence number in the 1650 variable SND.UNA. If the data flow is momentarily idle and all data 1651 sent has been acknowledged then the three variables will be equal. 1653 When the sender creates a segment and transmits it the sender 1654 advances SND.NXT. When the receiver accepts a segment it advances 1655 RCV.NXT and sends an acknowledgment. When the data sender receives 1656 an acknowledgment it advances SND.UNA. The extent to which the 1657 values of these variables differ is a measure of the delay in the 1658 communication. The amount by which the variables are advanced is the 1659 length of the data and SYN or FIN flags in the segment. Note that 1660 once in the ESTABLISHED state all segments must carry current 1661 acknowledgment information. 1663 The CLOSE user call implies a push function, as does the FIN control 1664 flag in an incoming segment. 1666 3.8.1. Retransmission Timeout 1668 Because of the variability of the networks that compose an 1669 internetwork system and the wide range of uses of TCP connections the 1670 retransmission timeout (RTO) must be dynamically determined. 1672 The RTO MUST be computed according to the algorithm in [7], including 1673 Karn's algorithm for taking RTT samples. 1675 RFC 793 contains an early example procedure for computing the RTO. 1676 This was then replaced by the algorithm described in RFC 1122, and 1677 subsequently updated in RFC 2988, and then again in RFC 6298. 1679 If a retransmitted packet is identical to the original packet (which 1680 implies not only that the data boundaries have not changed, but also 1681 that the window and acknowledgment fields of the header have not 1682 changed), then the same IP Identification field MAY be used (see 1683 Section 3.2.1.5 of RFC 1122). 1685 3.8.2. TCP Connection Failures 1687 Excessive retransmission of the same segment by TCP indicates some 1688 failure of the remote host or the Internet path. This failure may be 1689 of short or long duration. The following procedure MUST be used to 1690 handle excessive retransmissions of data segments: 1692 (a) There are two thresholds R1 and R2 measuring the amount of 1693 retransmission that has occurred for the same segment. R1 and R2 1694 might be measured in time units or as a count of retransmissions. 1696 (b) When the number of transmissions of the same segment reaches 1697 or exceeds threshold R1, pass negative advice (see [10] 1698 Section 3.3.1.4) to the IP layer, to trigger dead-gateway 1699 diagnosis. 1701 (c) When the number of transmissions of the same segment reaches a 1702 threshold R2 greater than R1, close the connection. 1704 (d) An application MUST be able to set the value for R2 for a 1705 particular connection. For example, an interactive application 1706 might set R2 to "infinity," giving the user control over when to 1707 disconnect. 1709 (d) TCP SHOULD inform the application of the delivery problem 1710 (unless such information has been disabled by the application; see 1711 RFC1122 Section 4.2.4.1 - TODO update to error reporting 1712 description in this document), when R1 is reached and before R2. 1714 This will allow a remote login (User Telnet) application program 1715 to inform the user, for example. 1717 The value of R1 SHOULD correspond to at least 3 retransmissions, at 1718 the current RTO. The value of R2 SHOULD correspond to at least 100 1719 seconds. 1721 An attempt to open a TCP connection could fail with excessive 1722 retransmissions of the SYN segment or by receipt of a RST segment or 1723 an ICMP Port Unreachable. SYN retransmissions MUST be handled in the 1724 general way just described for data retransmissions, including 1725 notification of the application layer. 1727 However, the values of R1 and R2 may be different for SYN and data 1728 segments. In particular, R2 for a SYN segment MUST be set large 1729 enough to provide retransmission of the segment for at least 3 1730 minutes. The application can close the connection (i.e., give up on 1731 the open attempt) sooner, of course. 1733 3.8.3. TCP Keep-Alives 1735 Implementors MAY include "keep-alives" in their TCP implementations, 1736 although this practice is not universally accepted. If keep-alives 1737 are included, the application MUST be able to turn them on or off for 1738 each TCP connection, and they MUST default to off. 1740 Keep-alive packets MUST only be sent when no data or acknowledgement 1741 packets have been received for the connection within an interval. 1742 This interval MUST be configurable and MUST default to no less than 1743 two hours. 1745 It is extremely important to remember that ACK segments that contain 1746 no data are not reliably transmitted by TCP. Consequently, if a 1747 keep-alive mechanism is implemented it MUST NOT interpret failure to 1748 respond to any specific probe as a dead connection. 1750 An implementation SHOULD send a keep-alive segment with no data; 1751 however, it MAY be configurable to send a keep-alive segment 1752 containing one garbage octet, for compatibility with erroneous TCP 1753 implementations. 1755 3.8.4. The Communication of Urgent Information 1757 As a result of implementation differences and middlebox interactions, 1758 new applications SHOULD NOT employ the TCP urgent mechanism. 1759 However, TCP implementations MUST still include support for the 1760 urgent mechanism. Details can be found in RFC 6093 [15]. 1762 The objective of the TCP urgent mechanism is to allow the sending 1763 user to stimulate the receiving user to accept some urgent data and 1764 to permit the receiving TCP to indicate to the receiving user when 1765 all the currently known urgent data has been received by the user. 1767 This mechanism permits a point in the data stream to be designated as 1768 the end of urgent information. Whenever this point is in advance of 1769 the receive sequence number (RCV.NXT) at the receiving TCP, that TCP 1770 must tell the user to go into "urgent mode"; when the receive 1771 sequence number catches up to the urgent pointer, the TCP must tell 1772 user to go into "normal mode". If the urgent pointer is updated 1773 while the user is in "urgent mode", the update will be invisible to 1774 the user. 1776 The method employs a urgent field which is carried in all segments 1777 transmitted. The URG control flag indicates that the urgent field is 1778 meaningful and must be added to the segment sequence number to yield 1779 the urgent pointer. The absence of this flag indicates that there is 1780 no urgent data outstanding. 1782 To send an urgent indication the user must also send at least one 1783 data octet. If the sending user also indicates a push, timely 1784 delivery of the urgent information to the destination process is 1785 enhanced. 1787 A TCP MUST support a sequence of urgent data of any length. [10] 1789 A TCP MUST inform the application layer asynchronously whenever it 1790 receives an Urgent pointer and there was previously no pending urgent 1791 data, or whenvever the Urgent pointer advances in the data stream. 1792 There MUST be a way for the application to learn how much urgent data 1793 remains to be read from the connection, or at least to determine 1794 whether or not more urgent data remains to be read. [10] 1796 3.8.5. Managing the Window 1798 The window sent in each segment indicates the range of sequence 1799 numbers the sender of the window (the data receiver) is currently 1800 prepared to accept. There is an assumption that this is related to 1801 the currently available data buffer space available for this 1802 connection. 1804 The sending TCP packages the data to be transmitted into segments 1805 which fit the current window, and may repackage segments on the 1806 retransmission queue. Such repackaging is not required, but may be 1807 helpful. 1809 In a connection with a one-way data flow, the window information will 1810 be carried in acknowledgment segments that all have the same sequence 1811 number so there will be no way to reorder them if they arrive out of 1812 order. This is not a serious problem, but it will allow the window 1813 information to be on occasion temporarily based on old reports from 1814 the data receiver. A refinement to avoid this problem is to act on 1815 the window information from segments that carry the highest 1816 acknowledgment number (that is segments with acknowledgment number 1817 equal or greater than the highest previously received). 1819 Indicating a large window encourages transmissions. If more data 1820 arrives than can be accepted, it will be discarded. This will result 1821 in excessive retransmissions, adding unnecessarily to the load on the 1822 network and the TCPs. Indicating a small window may restrict the 1823 transmission of data to the point of introducing a round trip delay 1824 between each new segment transmitted. 1826 The mechanisms provided allow a TCP to advertise a large window and 1827 to subsequently advertise a much smaller window without having 1828 accepted that much data. This, so called "shrinking the window," is 1829 strongly discouraged. The robustness principle dictates that TCPs 1830 will not shrink the window themselves, but will be prepared for such 1831 behavior on the part of other TCPs. 1833 A TCP receiver SHOULD NOT shrink the window, i.e., move the right 1834 window edge to the left. However, a sending TCP MUST be robust 1835 against window shrinking, which may cause the "useable window" (see 1836 Section 3.8.5.2.1) to become negative. 1838 If this happens, the sender SHOULD NOT send new data, but SHOULD 1839 retransmit normally the old unacknowledged data between SND.UNA and 1840 SND.UNA+SND.WND. The sender MAY also retransmit old data beyond 1841 SND.UNA+SND.WND, but SHOULD NOT time out the connection if data 1842 beyond the right window edge is not acknowledged. If the window 1843 shrinks to zero, the TCP MUST probe it in the standard way (described 1844 below). 1846 3.8.5.1. Zero Window Probing 1848 The sending TCP must be prepared to accept from the user and send at 1849 least one octet of new data even if the send window is zero. The 1850 sending TCP must regularly retransmit to the receiving TCP even when 1851 the window is zero, in order to "probe" the window. Two minutes is 1852 recommended for the retransmission interval when the window is zero. 1853 This retransmission is essential to guarantee that when either TCP 1854 has a zero window the re-opening of the window will be reliably 1855 reported to the other. This is referred to as Zero-Window Probing 1856 (ZWP) in other documents. 1858 Probing of zero (offered) windows MUST be supported. 1860 A TCP MAY keep its offered receive window closed indefinitely. As 1861 long as the receiving TCP continues to send acknowledgments in 1862 response to the probe segments, the sending TCP MUST allow the 1863 connection to stay open. This enables TCP to function in scenarios 1864 such as the "printer ran out of paper" situation described in 1865 Section 4.2.2.17 of RFC1122. The behavior is subject to the 1866 implementation's resource management concerns, as noted in [16]. 1868 When the receiving TCP has a zero window and a segment arrives it 1869 must still send an acknowledgment showing its next expected sequence 1870 number and current window (zero). 1872 3.8.5.2. Silly Window Syndrome Avoidance 1874 The "Silly Window Syndrome" (SWS) is a stable pattern of small 1875 incremental window movements resulting in extremely poor TCP 1876 performance. Algorithms to avoid SWS are described below for both 1877 the sending side and the receiving side. RFC 1122 contains more 1878 detailed discussion of the SWS problem. Note that the Nagle 1879 algorithm and the sender SWS avoidance algorithm play complementary 1880 roles in improving performance. The Nagle algorithm discourages 1881 sending tiny segments when the data to be sent increases in small 1882 increments, while the SWS avoidance algorithm discourages small 1883 segments resulting from the right window edge advancing in small 1884 increments. 1886 3.8.5.2.1. Sender's Algorithm - When to Send Data 1888 A TCP MUST include a SWS avoidance algorithm in the sender. 1890 A TCP SHOULD implement the Nagle Algorithm to coalesce short 1891 segments. However, there MUST be a way for an application to disable 1892 the Nagle algorithm on an individual connection. In all cases, 1893 sending data is also subject to the limitation imposed by the Slow 1894 Start algorithm. 1896 The sender's SWS avoidance algorithm is more difficult than the 1897 receivers's, because the sender does not know (directly) the 1898 receiver's total buffer space RCV.BUFF. An approach which has been 1899 found to work well is for the sender to calculate Max(SND.WND), the 1900 maximum send window it has seen so far on the connection, and to use 1901 this value as an estimate of RCV.BUFF. Unfortunately, this can only 1902 be an estimate; the receiver may at any time reduce the size of 1903 RCV.BUFF. To avoid a resulting deadlock, it is necessary to have a 1904 timeout to force transmission of data, overriding the SWS avoidance 1905 algorithm. In practice, this timeout should seldom occur. 1907 The "useable window" is: 1909 U = SND.UNA + SND.WND - SND.NXT 1911 i.e., the offered window less the amount of data sent but not 1912 acknowledged. If D is the amount of data queued in the sending TCP 1913 but not yet sent, then the following set of rules is recommended. 1915 Send data: 1917 (1) if a maximum-sized segment can be sent, i.e, if: 1919 min(D,U) >= Eff.snd.MSS; 1921 (2) or if the data is pushed and all queued data can be sent now, 1922 i.e., if: 1924 [SND.NXT = SND.UNA and] PUSHED and D <= U 1926 (the bracketed condition is imposed by the Nagle algorithm); 1928 (3) or if at least a fraction Fs of the maximum window can be sent, 1929 i.e., if: 1931 [SND.NXT = SND.UNA and] 1933 min(D.U) >= Fs * Max(SND.WND); 1935 (4) or if data is PUSHed and the override timeout occurs. 1937 Here Fs is a fraction whose recommended value is 1/2. The override 1938 timeout should be in the range 0.1 - 1.0 seconds. It may be 1939 convenient to combine this timer with the timer used to probe zero 1940 windows (Section Section 3.8.5.1). 1942 3.8.5.2.2. Receiver's Algorithm - When to Send a Window Update 1944 A TCP MUST include a SWS avoidance algorithm in the receiver. 1946 The receiver's SWS avoidance algorithm determines when the right 1947 window edge may be advanced; this is customarily known as "updating 1948 the window". This algorithm combines with the delayed ACK algorithm 1949 (see Section 3.8.5.3) to determine when an ACK segment containing the 1950 current window will really be sent to the receiver. 1952 The solution to receiver SWS is to avoid advancing the right window 1953 edge RCV.NXT+RCV.WND in small increments, even if data is received 1954 from the network in small segments. 1956 Suppose the total receive buffer space is RCV.BUFF. At any given 1957 moment, RCV.USER octets of this total may be tied up with data that 1958 has been received and acknowledged but which the user process has not 1959 yet consumed. When the connection is quiescent, RCV.WND = RCV.BUFF 1960 and RCV.USER = 0. 1962 Keeping the right window edge fixed as data arrives and is 1963 acknowledged requires that the receiver offer less than its full 1964 buffer space, i.e., the receiver must specify a RCV.WND that keeps 1965 RCV.NXT+RCV.WND constant as RCV.NXT increases. Thus, the total 1966 buffer space RCV.BUFF is generally divided into three parts: 1968 |<------- RCV.BUFF ---------------->| 1969 1 2 3 1970 ----|---------|------------------|------|---- 1971 RCV.NXT ^ 1972 (Fixed) 1974 1 - RCV.USER = data received but not yet consumed; 1975 2 - RCV.WND = space advertised to sender; 1976 3 - Reduction = space available but not yet 1977 advertised. 1979 The suggested SWS avoidance algorithm for the receiver is to keep 1980 RCV.NXT+RCV.WND fixed until the reduction satisfies: 1982 RCV.BUFF - RCV.USER - RCV.WND >= 1984 min( Fr * RCV.BUFF, Eff.snd.MSS ) 1986 where Fr is a fraction whose recommended value is 1/2, and 1987 Eff.snd.MSS is the effective send MSS for the connection (see 1988 Section 3.7.1). When the inequality is satisfied, RCV.WND is set to 1989 RCV.BUFF-RCV.USER. 1991 Note that the general effect of this algorithm is to advance RCV.WND 1992 in increments of Eff.snd.MSS (for realistic receive buffers: 1993 Eff.snd.MSS < RCV.BUFF/2). Note also that the receiver must use its 1994 own Eff.snd.MSS, assuming it is the same as the sender's. 1996 3.8.5.3. Delayed Acknowledgements - When to Send an ACK Segment 1998 A host that is receiving a stream of TCP data segments can increase 1999 efficiency in both the Internet and the hosts by sending fewer than 2000 one ACK (acknowledgment) segment per data segment received; this is 2001 known as a "delayed ACK". 2003 A TCP SHOULD implement a delayed ACK, but an ACK should not be 2004 excessively delayed; in particular, the delay MUST be less than 0.5 2005 seconds, and in a stream of full-sized segments there SHOULD be an 2006 ACK for at least every second segment. Excessive delays on ACK's can 2007 disturb the round-trip timing and packet "clocking" algorithms. 2009 3.9. Interfaces 2011 There are of course two interfaces of concern: the user/TCP interface 2012 and the TCP/lower-level interface. We have a fairly elaborate model 2013 of the user/TCP interface, but the interface to the lower level 2014 protocol module is left unspecified here, since it will be specified 2015 in detail by the specification of the lower level protocol. For the 2016 case that the lower level is IP we note some of the parameter values 2017 that TCPs might use. 2019 3.9.1. User/TCP Interface 2021 The following functional description of user commands to the TCP is, 2022 at best, fictional, since every operating system will have different 2023 facilities. Consequently, we must warn readers that different TCP 2024 implementations may have different user interfaces. However, all 2025 TCPs must provide a certain minimum set of services to guarantee that 2026 all TCP implementations can support the same protocol hierarchy. 2027 This section specifies the functional interfaces required of all TCP 2028 implementations. 2030 TCP User Commands 2032 The following sections functionally characterize a USER/TCP 2033 interface. The notation used is similar to most procedure or 2034 function calls in high level languages, but this usage is not 2035 meant to rule out trap type service calls (e.g., SVCs, UUOs, 2036 EMTs). 2038 The user commands described below specify the basic functions the 2039 TCP must perform to support interprocess communication. 2040 Individual implementations must define their own exact format, and 2041 may provide combinations or subsets of the basic functions in 2042 single calls. In particular, some implementations may wish to 2043 automatically OPEN a connection on the first SEND or RECEIVE 2044 issued by the user for a given connection. 2046 In providing interprocess communication facilities, the TCP must 2047 not only accept commands, but must also return information to the 2048 processes it serves. The latter consists of: 2050 (a) general information about a connection (e.g., interrupts, 2051 remote close, binding of unspecified foreign socket). 2053 (b) replies to specific user commands indicating success or 2054 various types of failure. 2056 Open 2058 Format: OPEN (local port, foreign socket, active/passive [, 2059 timeout] [, precedence] [, security/compartment] [local IP 2060 address,] [, options]) -> local connection name 2062 We assume that the local TCP is aware of the identity of the 2063 processes it serves and will check the authority of the process 2064 to use the connection specified. Depending upon the 2065 implementation of the TCP, the local network and TCP 2066 identifiers for the source address will either be supplied by 2067 the TCP or the lower level protocol (e.g., IP). These 2068 considerations are the result of concern about security, to the 2069 extent that no TCP be able to masquerade as another one, and so 2070 on. Similarly, no process can masquerade as another without 2071 the collusion of the TCP. 2073 If the active/passive flag is set to passive, then this is a 2074 call to LISTEN for an incoming connection. A passive open may 2075 have either a fully specified foreign socket to wait for a 2076 particular connection or an unspecified foreign socket to wait 2077 for any call. A fully specified passive call can be made 2078 active by the subsequent execution of a SEND. 2080 A transmission control block (TCB) is created and partially 2081 filled in with data from the OPEN command parameters. 2083 Every passive OPEN call either creates a new connection record 2084 in LISTEN state, or it returns an error; it MUST NOT affect any 2085 previously created connection record. 2087 A TCP that supports multiple concurrent users MUST provide an 2088 OPEN call that will functionally allow an application to LISTEN 2089 on a port while a connection block with the same local port is 2090 in SYN-SENT or SYN-RECEIVED state. 2092 On an active OPEN command, the TCP will begin the procedure to 2093 synchronize (i.e., establish) the connection at once. 2095 The timeout, if present, permits the caller to set up a timeout 2096 for all data submitted to TCP. If data is not successfully 2097 delivered to the destination within the timeout period, the TCP 2098 will abort the connection. The present global default is five 2099 minutes. 2101 The TCP or some component of the operating system will verify 2102 the users authority to open a connection with the specified 2103 precedence or security/compartment. The absence of precedence 2104 or security/compartment specification in the OPEN call 2105 indicates the default values must be used. 2107 TCP will accept incoming requests as matching only if the 2108 security/compartment information is exactly the same and only 2109 if the precedence is equal to or higher than the precedence 2110 requested in the OPEN call. 2112 The precedence for the connection is the higher of the values 2113 requested in the OPEN call and received from the incoming 2114 request, and fixed at that value for the life of the 2115 connection.Implementers may want to give the user control of 2116 this precedence negotiation. For example, the user might be 2117 allowed to specify that the precedence must be exactly matched, 2118 or that any attempt to raise the precedence be confirmed by the 2119 user. 2121 A local connection name will be returned to the user by the 2122 TCP. The local connection name can then be used as a short 2123 hand term for the connection defined by the pair. 2126 The optional "local IP address" parameter MUST be supported to 2127 allow the specification of the local IP address. This enables 2128 applications that need to select the local IP address used when 2129 multihoming is present. 2131 A passive OPEN call with a specified "local IP address" 2132 parameter will await an incoming connection request to that 2133 address. If the parameter is unspecified, a passive OPEN will 2134 await an incoming connection request to any local IP address, 2135 and then bind the local IP address of the connection to the 2136 particular address that is used. 2138 For an active OPEN call, a specified "local IP address" 2139 parameter MUST be used for opening the connection. If the 2140 parameter is unspecified, the TCP will choose an appropriate 2141 local IP address (see RFC 1122 section 3.3.4.2). 2143 TODO - the previous and next paragraphs are mildly in conflict. 2144 Previous paragraph says that the TCP chooses an address, but 2145 next paragraph says that it asks IP to choose ... need to make 2146 this consistent 2148 If an application on a multihomed host does not specify the 2149 local IP address when actively opening a TCP connection, then 2150 the TCP MUST ask the IP layer to select a local IP address 2151 before sending the (first) SYN. See the function GET_SRCADDR() 2152 in Section 3.4 of RFC 1122. 2154 At all other times, a previous segment has either been sent or 2155 received on this connection, and TCP MUST use the same local 2156 address is used that was used in those previous segments. 2158 Send 2160 Format: SEND (local connection name, buffer address, byte 2161 count, PUSH flag, URGENT flag [,timeout]) 2163 This call causes the data contained in the indicated user 2164 buffer to be sent on the indicated connection. If the 2165 connection has not been opened, the SEND is considered an 2166 error. Some implementations may allow users to SEND first; in 2167 which case, an automatic OPEN would be done. If the calling 2168 process is not authorized to use this connection, an error is 2169 returned. 2171 If the PUSH flag is set, the data must be transmitted promptly 2172 to the receiver, and the PUSH bit will be set in the last TCP 2173 segment created from the buffer. If the PUSH flag is not set, 2174 the data may be combined with data from subsequent SENDs for 2175 transmission efficiency. 2177 New applications SHOULD NOT set the URGENT flag [15] due to 2178 implementation differences and middlebox issues. 2180 If the URGENT flag is set, segments sent to the destination TCP 2181 will have the urgent pointer set. The receiving TCP will 2182 signal the urgent condition to the receiving process if the 2183 urgent pointer indicates that data preceding the urgent pointer 2184 has not been consumed by the receiving process. The purpose of 2185 urgent is to stimulate the receiver to process the urgent data 2186 and to indicate to the receiver when all the currently known 2187 urgent data has been received. The number of times the sending 2188 user's TCP signals urgent will not necessarily be equal to the 2189 number of times the receiving user will be notified of the 2190 presence of urgent data. 2192 If no foreign socket was specified in the OPEN, but the 2193 connection is established (e.g., because a LISTENing connection 2194 has become specific due to a foreign segment arriving for the 2195 local socket), then the designated buffer is sent to the 2196 implied foreign socket. Users who make use of OPEN with an 2197 unspecified foreign socket can make use of SEND without ever 2198 explicitly knowing the foreign socket address. 2200 However, if a SEND is attempted before the foreign socket 2201 becomes specified, an error will be returned. Users can use 2202 the STATUS call to determine the status of the connection. In 2203 some implementations the TCP may notify the user when an 2204 unspecified socket is bound. 2206 If a timeout is specified, the current user timeout for this 2207 connection is changed to the new one. 2209 In the simplest implementation, SEND would not return control 2210 to the sending process until either the transmission was 2211 complete or the timeout had been exceeded. However, this 2212 simple method is both subject to deadlocks (for example, both 2213 sides of the connection might try to do SENDs before doing any 2214 RECEIVEs) and offers poor performance, so it is not 2215 recommended. A more sophisticated implementation would return 2216 immediately to allow the process to run concurrently with 2217 network I/O, and, furthermore, to allow multiple SENDs to be in 2218 progress. Multiple SENDs are served in first come, first 2219 served order, so the TCP will queue those it cannot service 2220 immediately. 2222 We have implicitly assumed an asynchronous user interface in 2223 which a SEND later elicits some kind of SIGNAL or pseudo- 2224 interrupt from the serving TCP. An alternative is to return a 2225 response immediately. For instance, SENDs might return 2226 immediate local acknowledgment, even if the segment sent had 2227 not been acknowledged by the distant TCP. We could 2228 optimistically assume eventual success. If we are wrong, the 2229 connection will close anyway due to the timeout. In 2230 implementations of this kind (synchronous), there will still be 2231 some asynchronous signals, but these will deal with the 2232 connection itself, and not with specific segments or buffers. 2234 In order for the process to distinguish among error or success 2235 indications for different SENDs, it might be appropriate for 2236 the buffer address to be returned along with the coded response 2237 to the SEND request. TCP-to-user signals are discussed below, 2238 indicating the information which should be returned to the 2239 calling process. 2241 Receive 2243 Format: RECEIVE (local connection name, buffer address, byte 2244 count) -> byte count, urgent flag, push flag 2246 This command allocates a receiving buffer associated with the 2247 specified connection. If no OPEN precedes this command or the 2248 calling process is not authorized to use this connection, an 2249 error is returned. 2251 In the simplest implementation, control would not return to the 2252 calling program until either the buffer was filled, or some 2253 error occurred, but this scheme is highly subject to deadlocks. 2254 A more sophisticated implementation would permit several 2255 RECEIVEs to be outstanding at once. These would be filled as 2256 segments arrive. This strategy permits increased throughput at 2257 the cost of a more elaborate scheme (possibly asynchronous) to 2258 notify the calling program that a PUSH has been seen or a 2259 buffer filled. 2261 If enough data arrive to fill the buffer before a PUSH is seen, 2262 the PUSH flag will not be set in the response to the RECEIVE. 2263 The buffer will be filled with as much data as it can hold. If 2264 a PUSH is seen before the buffer is filled the buffer will be 2265 returned partially filled and PUSH indicated. 2267 If there is urgent data the user will have been informed as 2268 soon as it arrived via a TCP-to-user signal. The receiving 2269 user should thus be in "urgent mode". If the URGENT flag is 2270 on, additional urgent data remains. If the URGENT flag is off, 2271 this call to RECEIVE has returned all the urgent data, and the 2272 user may now leave "urgent mode". Note that data following the 2273 urgent pointer (non-urgent data) cannot be delivered to the 2274 user in the same buffer with preceding urgent data unless the 2275 boundary is clearly marked for the user. 2277 To distinguish among several outstanding RECEIVEs and to take 2278 care of the case that a buffer is not completely filled, the 2279 return code is accompanied by both a buffer pointer and a byte 2280 count indicating the actual length of the data received. 2282 Alternative implementations of RECEIVE might have the TCP 2283 allocate buffer storage, or the TCP might share a ring buffer 2284 with the user. 2286 Close 2288 Format: CLOSE (local connection name) 2289 This command causes the connection specified to be closed. If 2290 the connection is not open or the calling process is not 2291 authorized to use this connection, an error is returned. 2292 Closing connections is intended to be a graceful operation in 2293 the sense that outstanding SENDs will be transmitted (and 2294 retransmitted), as flow control permits, until all have been 2295 serviced. Thus, it should be acceptable to make several SEND 2296 calls, followed by a CLOSE, and expect all the data to be sent 2297 to the destination. It should also be clear that users should 2298 continue to RECEIVE on CLOSING connections, since the other 2299 side may be trying to transmit the last of its data. Thus, 2300 CLOSE means "I have no more to send" but does not mean "I will 2301 not receive any more." It may happen (if the user level 2302 protocol is not well thought out) that the closing side is 2303 unable to get rid of all its data before timing out. In this 2304 event, CLOSE turns into ABORT, and the closing TCP gives up. 2306 The user may CLOSE the connection at any time on his own 2307 initiative, or in response to various prompts from the TCP 2308 (e.g., remote close executed, transmission timeout exceeded, 2309 destination inaccessible). 2311 Because closing a connection requires communication with the 2312 foreign TCP, connections may remain in the closing state for a 2313 short time. Attempts to reopen the connection before the TCP 2314 replies to the CLOSE command will result in error responses. 2316 Close also implies push function. 2318 Status 2320 Format: STATUS (local connection name) -> status data 2322 This is an implementation dependent user command and could be 2323 excluded without adverse effect. Information returned would 2324 typically come from the TCB associated with the connection. 2326 This command returns a data block containing the following 2327 information: 2329 local socket, 2330 foreign socket, 2331 local connection name, 2332 receive window, 2333 send window, 2334 connection state, 2335 number of buffers awaiting acknowledgment, 2336 number of buffers pending receipt, 2337 urgent state, 2338 precedence, 2339 security/compartment, 2340 and transmission timeout. 2342 Depending on the state of the connection, or on the 2343 implementation itself, some of this information may not be 2344 available or meaningful. If the calling process is not 2345 authorized to use this connection, an error is returned. This 2346 prevents unauthorized processes from gaining information about 2347 a connection. 2349 Abort 2351 Format: ABORT (local connection name) 2353 This command causes all pending SENDs and RECEIVES to be 2354 aborted, the TCB to be removed, and a special RESET message to 2355 be sent to the TCP on the other side of the connection. 2356 Depending on the implementation, users may receive abort 2357 indications for each outstanding SEND or RECEIVE, or may simply 2358 receive an ABORT-acknowledgment. 2360 Flush 2362 Some TCP implementations have included a FLUSH call, which will 2363 empty the TCP send queue of any data for which the user has 2364 issued SEND calls but which is still to the right of the 2365 current send window. That is, it flushes as much queued send 2366 data as possible without losing sequence number 2367 synchronization. 2369 Set TOS 2371 The application layer MUST be able to specify the Type-of- 2372 Service (TOS) for segments that are sent on a connection. It 2373 not required, but the application SHOULD be able to change the 2374 TOS during the connection lifetime. TCP SHOULD pass the 2375 current TOS value without change to the IP layer, when it sends 2376 segments on the connection. 2378 The TOS will be specified independently in each direction on 2379 the connection, so that the receiver application will specify 2380 the TOS used for ACK segments. 2382 TCP MAY pass the most recently received TOS up to the 2383 application. 2385 TCP-to-User Messages 2387 It is assumed that the operating system environment provides a 2388 means for the TCP to asynchronously signal the user program. 2389 When the TCP does signal a user program, certain information is 2390 passed to the user. Often in the specification the information 2391 will be an error message. In other cases there will be 2392 information relating to the completion of processing a SEND or 2393 RECEIVE or other user call. 2395 The following information is provided: 2397 Local Connection Name Always 2398 Response String Always 2399 Buffer Address Send & Receive 2400 Byte count (counts bytes received) Receive 2401 Push flag Receive 2402 Urgent flag Receive 2404 3.9.2. TCP/Lower-Level Interface 2406 The TCP calls on a lower level protocol module to actually send and 2407 receive information over a network. One case is that of the ARPA 2408 internetwork system where the lower level module is the Internet 2409 Protocol (IP) [1]. 2411 If the lower level protocol is IP it provides arguments for a type of 2412 service and for a time to live. TCP uses the following settings for 2413 these parameters: 2415 Type of Service = Precedence: given by user, Delay: normal, 2416 Throughput: normal, Reliability: normal; or binary XXX00000, where 2417 XXX are the three bits determining precedence, e.g. 000 means 2418 routine precedence. 2420 Time to Live (TTL): The TTL value used to send TCP segments MUST 2421 be configurable. 2423 Note that RFC 793 specified one minute (60 seconds) as a 2424 constant for the TTL, because the assumed maximum segment 2425 lifetime was two minutes. This was intended to explicitly ask 2426 that a segment be destroyed if it cannot be delivered by the 2427 internet system within one minute. RFC 1122 changed this 2428 specification to require that the TTL be configurable. 2430 Any lower level protocol will have to provide the source address, 2431 destination address, and protocol fields, and some way to determine 2432 the "TCP length", both to provide the functional equivalent service 2433 of IP and to be used in the TCP checksum. 2435 When received options are passed up to TCP from the IP layer, TCP 2436 MUST ignore options that it does not understand. 2438 A TCP MAY support the Time Stamp and Record Route options. 2440 3.9.2.1. Source Routing 2442 If the lower level is IP (or other protocol that provides this 2443 feature) and source routing is used, the interface must allow the 2444 route information to be communicated. This is especially important 2445 so that the source and destination addresses used in the TCP checksum 2446 be the originating source and ultimate destination. It is also 2447 important to preserve the return route to answer connection requests. 2449 An application MUST be able to specify a source route when it 2450 actively opens a TCP connection, and this MUST take precedence over a 2451 source route received in a datagram. 2453 When a TCP connection is OPENed passively and a packet arrives with a 2454 completed IP Source Route option (containing a return route), TCP 2455 MUST save the return route and use it for all segments sent on this 2456 connection. If a different source route arrives in a later segment, 2457 the later definition SHOULD override the earlier one. 2459 3.9.2.2. ICMP Messages 2461 TODO - this section is verbatim from 1122, currently. It should be 2462 revised to match the soft-errors RFC, and other updates (e.g. source 2463 quench deprecation) 2465 TCP MUST act on an ICMP error message passed up from the IP layer, 2466 directing it to the connection that created the error. The necessary 2467 demultiplexing information can be found in the IP header contained 2468 within the ICMP message. 2470 Source Quench 2471 TCP MUST react to a Source Quench by slowing transmission on the 2472 connection. The RECOMMENDED procedure is for a Source Quench to 2473 trigger a "slow start," as if a retransmission timeout had 2474 occurred. 2476 Destination Unreachable -- codes 0, 1, 5 2477 Since these Unreachable messages indicate soft error conditions, 2478 TCP MUST NOT abort the connection, and it SHOULD make the 2479 information available to the application. 2481 Destination Unreachable -- codes 2-4 2482 These are hard error conditions, so TCP SHOULD abort the 2483 connection. 2485 Time Exceeded -- codes 0, 1 2486 This should be handled the same way as Destination Unreachable 2487 codes 0, 1, 5 (see above). 2489 Parameter Problem 2490 This should be handled the same way as Destination Unreachable 2491 codes 0, 1, 5 (see above). 2493 3.10. Event Processing 2495 The processing depicted in this section is an example of one possible 2496 implementation. Other implementations may have slightly different 2497 processing sequences, but they should differ from those in this 2498 section only in detail, not in substance. 2500 The activity of the TCP can be characterized as responding to events. 2501 The events that occur can be cast into three categories: user calls, 2502 arriving segments, and timeouts. This section describes the 2503 processing the TCP does in response to each of the events. In many 2504 cases the processing required depends on the state of the connection. 2506 Events that occur: 2508 User Calls 2510 OPEN 2511 SEND 2512 RECEIVE 2513 CLOSE 2514 ABORT 2515 STATUS 2517 Arriving Segments 2519 SEGMENT ARRIVES 2521 Timeouts 2523 USER TIMEOUT 2524 RETRANSMISSION TIMEOUT 2525 TIME-WAIT TIMEOUT 2527 The model of the TCP/user interface is that user commands receive an 2528 immediate return and possibly a delayed response via an event or 2529 pseudo interrupt. In the following descriptions, the term "signal" 2530 means cause a delayed response. 2532 Error responses are given as character strings. For example, user 2533 commands referencing connections that do not exist receive "error: 2534 connection not open". 2536 Please note in the following that all arithmetic on sequence numbers, 2537 acknowledgment numbers, windows, et cetera, is modulo 2**32 the size 2538 of the sequence number space. Also note that "=<" means less than or 2539 equal to (modulo 2**32). 2541 A natural way to think about processing incoming segments is to 2542 imagine that they are first tested for proper sequence number (i.e., 2543 that their contents lie in the range of the expected "receive window" 2544 in the sequence number space) and then that they are generally queued 2545 and processed in sequence number order. 2547 When a segment overlaps other already received segments we 2548 reconstruct the segment to contain just the new data, and adjust the 2549 header fields to be consistent. 2551 Note that if no state change is mentioned the TCP stays in the same 2552 state. 2554 OPEN Call 2556 CLOSED STATE (i.e., TCB does not exist) 2558 Create a new transmission control block (TCB) to hold 2559 connection state information. Fill in local socket identifier, 2560 foreign socket, precedence, security/compartment, and user 2561 timeout information. Note that some parts of the foreign 2562 socket may be unspecified in a passive OPEN and are to be 2563 filled in by the parameters of the incoming SYN segment. 2564 Verify the security and precedence requested are allowed for 2565 this user, if not return "error: precedence not allowed" or 2566 "error: security/compartment not allowed." If passive enter 2567 the LISTEN state and return. If active and the foreign socket 2568 is unspecified, return "error: foreign socket unspecified"; if 2569 active and the foreign socket is specified, issue a SYN 2570 segment. An initial send sequence number (ISS) is selected. A 2571 SYN segment of the form is sent. Set 2572 SND.UNA to ISS, SND.NXT to ISS+1, enter SYN-SENT state, and 2573 return. 2575 If the caller does not have access to the local socket 2576 specified, return "error: connection illegal for this process". 2577 If there is no room to create a new connection, return "error: 2578 insufficient resources". 2580 LISTEN STATE 2582 If active and the foreign socket is specified, then change the 2583 connection from passive to active, select an ISS. Send a SYN 2584 segment, set SND.UNA to ISS, SND.NXT to ISS+1. Enter SYN-SENT 2585 state. Data associated with SEND may be sent with SYN segment 2586 or queued for transmission after entering ESTABLISHED state. 2587 The urgent bit if requested in the command must be sent with 2588 the data segments sent as a result of this command. If there 2589 is no room to queue the request, respond with "error: 2590 insufficient resources". If Foreign socket was not specified, 2591 then return "error: foreign socket unspecified". 2593 SYN-SENT STATE 2594 SYN-RECEIVED STATE 2595 ESTABLISHED STATE 2596 FIN-WAIT-1 STATE 2597 FIN-WAIT-2 STATE 2598 CLOSE-WAIT STATE 2599 CLOSING STATE 2600 LAST-ACK STATE 2601 TIME-WAIT STATE 2603 Return "error: connection already exists". 2605 SEND Call 2607 CLOSED STATE (i.e., TCB does not exist) 2609 If the user does not have access to such a connection, then 2610 return "error: connection illegal for this process". 2612 Otherwise, return "error: connection does not exist". 2614 LISTEN STATE 2616 If the foreign socket is specified, then change the connection 2617 from passive to active, select an ISS. Send a SYN segment, set 2618 SND.UNA to ISS, SND.NXT to ISS+1. Enter SYN-SENT state. Data 2619 associated with SEND may be sent with SYN segment or queued for 2620 transmission after entering ESTABLISHED state. The urgent bit 2621 if requested in the command must be sent with the data segments 2622 sent as a result of this command. If there is no room to queue 2623 the request, respond with "error: insufficient resources". If 2624 Foreign socket was not specified, then return "error: foreign 2625 socket unspecified". 2627 SYN-SENT STATE 2628 SYN-RECEIVED STATE 2630 Queue the data for transmission after entering ESTABLISHED 2631 state. If no space to queue, respond with "error: insufficient 2632 resources". 2634 ESTABLISHED STATE 2635 CLOSE-WAIT STATE 2637 Segmentize the buffer and send it with a piggybacked 2638 acknowledgment (acknowledgment value = RCV.NXT). If there is 2639 insufficient space to remember this buffer, simply return 2640 "error: insufficient resources". 2642 If the urgent flag is set, then SND.UP <- SND.NXT and set the 2643 urgent pointer in the outgoing segments. 2645 FIN-WAIT-1 STATE 2646 FIN-WAIT-2 STATE 2647 CLOSING STATE 2648 LAST-ACK STATE 2649 TIME-WAIT STATE 2651 Return "error: connection closing" and do not service request. 2653 RECEIVE Call 2655 CLOSED STATE (i.e., TCB does not exist) 2657 If the user does not have access to such a connection, return 2658 "error: connection illegal for this process". 2660 Otherwise return "error: connection does not exist". 2662 LISTEN STATE 2663 SYN-SENT STATE 2664 SYN-RECEIVED STATE 2666 Queue for processing after entering ESTABLISHED state. If 2667 there is no room to queue this request, respond with "error: 2668 insufficient resources". 2670 ESTABLISHED STATE 2671 FIN-WAIT-1 STATE 2672 FIN-WAIT-2 STATE 2674 If insufficient incoming segments are queued to satisfy the 2675 request, queue the request. If there is no queue space to 2676 remember the RECEIVE, respond with "error: insufficient 2677 resources". 2679 Reassemble queued incoming segments into receive buffer and 2680 return to user. Mark "push seen" (PUSH) if this is the case. 2682 If RCV.UP is in advance of the data currently being passed to 2683 the user notify the user of the presence of urgent data. 2685 When the TCP takes responsibility for delivering data to the 2686 user that fact must be communicated to the sender via an 2687 acknowledgment. The formation of such an acknowledgment is 2688 described below in the discussion of processing an incoming 2689 segment. 2691 CLOSE-WAIT STATE 2693 Since the remote side has already sent FIN, RECEIVEs must be 2694 satisfied by text already on hand, but not yet delivered to the 2695 user. If no text is awaiting delivery, the RECEIVE will get a 2696 "error: connection closing" response. Otherwise, any remaining 2697 text can be used to satisfy the RECEIVE. 2699 CLOSING STATE 2700 LAST-ACK STATE 2701 TIME-WAIT STATE 2703 Return "error: connection closing". 2705 CLOSE Call 2707 CLOSED STATE (i.e., TCB does not exist) 2709 If the user does not have access to such a connection, return 2710 "error: connection illegal for this process". 2712 Otherwise, return "error: connection does not exist". 2714 LISTEN STATE 2716 Any outstanding RECEIVEs are returned with "error: closing" 2717 responses. Delete TCB, enter CLOSED state, and return. 2719 SYN-SENT STATE 2721 Delete the TCB and return "error: closing" responses to any 2722 queued SENDs, or RECEIVEs. 2724 SYN-RECEIVED STATE 2726 If no SENDs have been issued and there is no pending data to 2727 send, then form a FIN segment and send it, and enter FIN-WAIT-1 2728 state; otherwise queue for processing after entering 2729 ESTABLISHED state. 2731 ESTABLISHED STATE 2733 Queue this until all preceding SENDs have been segmentized, 2734 then form a FIN segment and send it. In any case, enter FIN- 2735 WAIT-1 state. 2737 FIN-WAIT-1 STATE 2738 FIN-WAIT-2 STATE 2740 Strictly speaking, this is an error and should receive a 2741 "error: connection closing" response. An "ok" response would 2742 be acceptable, too, as long as a second FIN is not emitted (the 2743 first FIN may be retransmitted though). 2745 CLOSE-WAIT STATE 2747 Queue this request until all preceding SENDs have been 2748 segmentized; then send a FIN segment, enter LAST-ACK state. 2750 CLOSING STATE 2751 LAST-ACK STATE 2752 TIME-WAIT STATE 2753 Respond with "error: connection closing". 2755 ABORT Call 2757 CLOSED STATE (i.e., TCB does not exist) 2759 If the user should not have access to such a connection, return 2760 "error: connection illegal for this process". 2762 Otherwise return "error: connection does not exist". 2764 LISTEN STATE 2766 Any outstanding RECEIVEs should be returned with "error: 2767 connection reset" responses. Delete TCB, enter CLOSED state, 2768 and return. 2770 SYN-SENT STATE 2772 All queued SENDs and RECEIVEs should be given "connection 2773 reset" notification, delete the TCB, enter CLOSED state, and 2774 return. 2776 SYN-RECEIVED STATE 2777 ESTABLISHED STATE 2778 FIN-WAIT-1 STATE 2779 FIN-WAIT-2 STATE 2780 CLOSE-WAIT STATE 2782 Send a reset segment: 2784 2786 All queued SENDs and RECEIVEs should be given "connection 2787 reset" notification; all segments queued for transmission 2788 (except for the RST formed above) or retransmission should be 2789 flushed, delete the TCB, enter CLOSED state, and return. 2791 CLOSING STATE LAST-ACK STATE TIME-WAIT STATE 2793 Respond with "ok" and delete the TCB, enter CLOSED state, and 2794 return. 2796 STATUS Call 2798 CLOSED STATE (i.e., TCB does not exist) 2800 If the user should not have access to such a connection, return 2801 "error: connection illegal for this process". 2803 Otherwise return "error: connection does not exist". 2805 LISTEN STATE 2807 Return "state = LISTEN", and the TCB pointer. 2809 SYN-SENT STATE 2811 Return "state = SYN-SENT", and the TCB pointer. 2813 SYN-RECEIVED STATE 2815 Return "state = SYN-RECEIVED", and the TCB pointer. 2817 ESTABLISHED STATE 2819 Return "state = ESTABLISHED", and the TCB pointer. 2821 FIN-WAIT-1 STATE 2823 Return "state = FIN-WAIT-1", and the TCB pointer. 2825 FIN-WAIT-2 STATE 2827 Return "state = FIN-WAIT-2", and the TCB pointer. 2829 CLOSE-WAIT STATE 2831 Return "state = CLOSE-WAIT", and the TCB pointer. 2833 CLOSING STATE 2835 Return "state = CLOSING", and the TCB pointer. 2837 LAST-ACK STATE 2839 Return "state = LAST-ACK", and the TCB pointer. 2841 TIME-WAIT STATE 2843 Return "state = TIME-WAIT", and the TCB pointer. 2845 SEGMENT ARRIVES 2847 If the state is CLOSED (i.e., TCB does not exist) then 2849 all data in the incoming segment is discarded. An incoming 2850 segment containing a RST is discarded. An incoming segment not 2851 containing a RST causes a RST to be sent in response. The 2852 acknowledgment and sequence field values are selected to make 2853 the reset sequence acceptable to the TCP that sent the 2854 offending segment. 2856 If the ACK bit is off, sequence number zero is used, 2858 2860 If the ACK bit is on, 2862 2864 Return. 2866 If the state is LISTEN then 2868 first check for an RST 2870 An incoming RST should be ignored. Return. 2872 second check for an ACK 2874 Any acknowledgment is bad if it arrives on a connection 2875 still in the LISTEN state. An acceptable reset segment 2876 should be formed for any arriving ACK-bearing segment. The 2877 RST should be formatted as follows: 2879 2881 Return. 2883 third check for a SYN 2885 If the SYN bit is set, check the security. If the security/ 2886 compartment on the incoming segment does not exactly match 2887 the security/compartment in the TCB then send a reset and 2888 return. 2890 2892 If the SEG.PRC is greater than the TCB.PRC then if allowed 2893 by the user and the system set TCB.PRC<-SEG.PRC, if not 2894 allowed send a reset and return. 2896 2898 If the SEG.PRC is less than the TCB.PRC then continue. 2900 Set RCV.NXT to SEG.SEQ+1, IRS is set to SEG.SEQ and any 2901 other control or text should be queued for processing later. 2902 ISS should be selected and a SYN segment sent of the form: 2904 2906 SND.NXT is set to ISS+1 and SND.UNA to ISS. The connection 2907 state should be changed to SYN-RECEIVED. Note that any 2908 other incoming control or data (combined with SYN) will be 2909 processed in the SYN-RECEIVED state, but processing of SYN 2910 and ACK should not be repeated. If the listen was not fully 2911 specified (i.e., the foreign socket was not fully 2912 specified), then the unspecified fields should be filled in 2913 now. 2915 fourth other text or control 2917 Any other control or text-bearing segment (not containing 2918 SYN) must have an ACK and thus would be discarded by the ACK 2919 processing. An incoming RST segment could not be valid, 2920 since it could not have been sent in response to anything 2921 sent by this incarnation of the connection. So you are 2922 unlikely to get here, but if you do, drop the segment, and 2923 return. 2925 If the state is SYN-SENT then 2927 first check the ACK bit 2929 If the ACK bit is set 2931 If SEG.ACK =< ISS, or SEG.ACK > SND.NXT, send a reset 2932 (unless the RST bit is set, if so drop the segment and 2933 return) 2935 2937 and discard the segment. Return. 2939 If SND.UNA < SEG.ACK =< SND.NXT then the ACK is 2940 acceptable. (TODO: in processing Errata ID 3300, it was 2941 noted that some stacks in the wild that do not send data 2942 on the SYN are just checking that SEG.ACK == SND.NXT ... 2943 think about whether anything should be said about that 2944 here) 2946 second check the RST bit 2948 If the RST bit is set 2950 If the ACK was acceptable then signal the user "error: 2951 connection reset", drop the segment, enter CLOSED state, 2952 delete TCB, and return. Otherwise (no ACK) drop the 2953 segment and return. 2955 third check the security and precedence 2957 If the security/compartment in the segment does not exactly 2958 match the security/compartment in the TCB, send a reset 2960 If there is an ACK 2962 2964 Otherwise 2966 2968 If there is an ACK 2970 The precedence in the segment must match the precedence 2971 in the TCB, if not, send a reset 2973 2975 If there is no ACK 2977 If the precedence in the segment is higher than the 2978 precedence in the TCB then if allowed by the user and the 2979 system raise the precedence in the TCB to that in the 2980 segment, if not allowed to raise the prec then send a 2981 reset. 2983 2985 If the precedence in the segment is lower than the 2986 precedence in the TCB continue. 2988 If a reset was sent, discard the segment and return. 2990 fourth check the SYN bit 2992 This step should be reached only if the ACK is ok, or there 2993 is no ACK, and it the segment did not contain a RST. 2995 If the SYN bit is on and the security/compartment and 2996 precedence are acceptable then, RCV.NXT is set to SEG.SEQ+1, 2997 IRS is set to SEG.SEQ. SND.UNA should be advanced to equal 2998 SEG.ACK (if there is an ACK), and any segments on the 2999 retransmission queue which are thereby acknowledged should 3000 be removed. 3002 If SND.UNA > ISS (our SYN has been ACKed), change the 3003 connection state to ESTABLISHED, form an ACK segment 3005 3007 and send it. Data or controls which were queued for 3008 transmission may be included. If there are other controls 3009 or text in the segment then continue processing at the sixth 3010 step below where the URG bit is checked, otherwise return. 3012 Otherwise enter SYN-RECEIVED, form a SYN,ACK segment 3014 3016 and send it. Set the variables: 3018 SND.WND <- SEG.WND 3019 SND.WL1 <- SEG.SEQ 3020 SND.WL2 <- SEG.ACK 3022 If there are other controls or text in the segment, queue 3023 them for processing after the ESTABLISHED state has been 3024 reached, return. 3026 fifth, if neither of the SYN or RST bits is set then drop the 3027 segment and return. 3029 Otherwise, 3031 first check sequence number 3033 SYN-RECEIVED STATE 3034 ESTABLISHED STATE 3035 FIN-WAIT-1 STATE 3036 FIN-WAIT-2 STATE 3037 CLOSE-WAIT STATE 3038 CLOSING STATE 3039 LAST-ACK STATE 3040 TIME-WAIT STATE 3042 Segments are processed in sequence. Initial tests on 3043 arrival are used to discard old duplicates, but further 3044 processing is done in SEG.SEQ order. If a segment's 3045 contents straddle the boundary between old and new, only the 3046 new parts should be processed. 3048 There are four cases for the acceptability test for an 3049 incoming segment: 3051 Segment Receive Test 3052 Length Window 3053 ------- ------- ------------------------------------------- 3055 0 0 SEG.SEQ = RCV.NXT 3057 0 >0 RCV.NXT =< SEG.SEQ < RCV.NXT+RCV.WND 3059 >0 0 not acceptable 3061 >0 >0 RCV.NXT =< SEG.SEQ < RCV.NXT+RCV.WND 3062 or RCV.NXT =< SEG.SEQ+SEG.LEN-1 < RCV.NXT+RCV.WND 3064 If the RCV.WND is zero, no segments will be acceptable, but 3065 special allowance should be made to accept valid ACKs, URGs 3066 and RSTs. 3068 If an incoming segment is not acceptable, an acknowledgment 3069 should be sent in reply (unless the RST bit is set, if so 3070 drop the segment and return): 3072 3074 After sending the acknowledgment, drop the unacceptable 3075 segment and return. 3077 In the following it is assumed that the segment is the 3078 idealized segment that begins at RCV.NXT and does not exceed 3079 the window. One could tailor actual segments to fit this 3080 assumption by trimming off any portions that lie outside the 3081 window (including SYN and FIN), and only processing further 3082 if the segment then begins at RCV.NXT. Segments with higher 3083 beginning sequence numbers should be held for later 3084 processing. 3086 In general, the processing of received segments MUST be 3087 implemented to aggregate ACK segments whenever possible. 3088 For example, if the TCP is processing a series of queued 3089 segments, it MUST process them all before sending any ACK 3090 segments. (TODO - see if there's a better place for this 3091 paragraph - taken from RFC1122) 3093 second check the RST bit, 3095 SYN-RECEIVED STATE 3097 If the RST bit is set 3099 If this connection was initiated with a passive OPEN 3100 (i.e., came from the LISTEN state), then return this 3101 connection to LISTEN state and return. The user need 3102 not be informed. If this connection was initiated 3103 with an active OPEN (i.e., came from SYN-SENT state) 3104 then the connection was refused, signal the user 3105 "connection refused". In either case, all segments on 3106 the retransmission queue should be removed. And in 3107 the active OPEN case, enter the CLOSED state and 3108 delete the TCB, and return. 3110 ESTABLISHED 3111 FIN-WAIT-1 3112 FIN-WAIT-2 3113 CLOSE-WAIT 3115 If the RST bit is set then, any outstanding RECEIVEs and 3116 SEND should receive "reset" responses. All segment 3117 queues should be flushed. Users should also receive an 3118 unsolicited general "connection reset" signal. Enter the 3119 CLOSED state, delete the TCB, and return. 3121 CLOSING STATE 3122 LAST-ACK STATE 3123 TIME-WAIT 3125 If the RST bit is set then, enter the CLOSED state, 3126 delete the TCB, and return. 3128 third check security and precedence 3129 SYN-RECEIVED 3131 If the security/compartment and precedence in the segment 3132 do not exactly match the security/compartment and 3133 precedence in the TCB then send a reset, and return. 3135 ESTABLISHED 3136 FIN-WAIT-1 3137 FIN-WAIT-2 3138 CLOSE-WAIT 3139 CLOSING 3140 LAST-ACK 3141 TIME-WAIT 3143 If the security/compartment and precedence in the segment 3144 do not exactly match the security/compartment and 3145 precedence in the TCB then send a reset, any outstanding 3146 RECEIVEs and SEND should receive "reset" responses. All 3147 segment queues should be flushed. Users should also 3148 receive an unsolicited general "connection reset" signal. 3149 Enter the CLOSED state, delete the TCB, and return. 3151 Note this check is placed following the sequence check to 3152 prevent a segment from an old connection between these ports 3153 with a different security or precedence from causing an 3154 abort of the current connection. 3156 fourth, check the SYN bit, 3158 SYN-RECEIVED 3159 ESTABLISHED STATE 3160 FIN-WAIT STATE-1 3161 FIN-WAIT STATE-2 3162 CLOSE-WAIT STATE 3163 CLOSING STATE 3164 LAST-ACK STATE 3165 TIME-WAIT STATE 3167 TODO: need to incorporate RFC 1122 4.2.2.20(e) here 3169 If the SYN is in the window it is an error, send a reset, 3170 any outstanding RECEIVEs and SEND should receive "reset" 3171 responses, all segment queues should be flushed, the user 3172 should also receive an unsolicited general "connection 3173 reset" signal, enter the CLOSED state, delete the TCB, 3174 and return. 3176 If the SYN is not in the window this step would not be 3177 reached and an ack would have been sent in the first step 3178 (sequence number check). 3180 fifth check the ACK field, 3182 if the ACK bit is off drop the segment and return 3184 if the ACK bit is on 3186 SYN-RECEIVED STATE 3188 If SND.UNA < SEG.ACK =< SND.NXT then enter ESTABLISHED 3189 state and continue processing with variables below set 3190 to: 3192 SND.WND <- SEG.WND 3193 SND.WL1 <- SEG.SEQ 3194 SND.WL2 <- SEG.ACK 3196 If the segment acknowledgment is not acceptable, 3197 form a reset segment, 3199 3201 and send it. 3203 ESTABLISHED STATE 3205 If SND.UNA < SEG.ACK =< SND.NXT then, set SND.UNA <- 3206 SEG.ACK. Any segments on the retransmission queue 3207 which are thereby entirely acknowledged are removed. 3208 Users should receive positive acknowledgments for 3209 buffers which have been SENT and fully acknowledged 3210 (i.e., SEND buffer should be returned with "ok" 3211 response). If the ACK is a duplicate (SEG.ACK =< 3212 SND.UNA), it can be ignored. If the ACK acks 3213 something not yet sent (SEG.ACK > SND.NXT) then send 3214 an ACK, drop the segment, and return. 3216 If SND.UNA =< SEG.ACK =< SND.NXT, the send window 3217 should be updated. If (SND.WL1 < SEG.SEQ or (SND.WL1 3218 = SEG.SEQ and SND.WL2 =< SEG.ACK)), set SND.WND <- 3219 SEG.WND, set SND.WL1 <- SEG.SEQ, and set SND.WL2 <- 3220 SEG.ACK. 3222 Note that SND.WND is an offset from SND.UNA, that 3223 SND.WL1 records the sequence number of the last 3224 segment used to update SND.WND, and that SND.WL2 3225 records the acknowledgment number of the last segment 3226 used to update SND.WND. The check here prevents using 3227 old segments to update the window. 3229 FIN-WAIT-1 STATE 3231 In addition to the processing for the ESTABLISHED 3232 state, if our FIN is now acknowledged then enter FIN- 3233 WAIT-2 and continue processing in that state. 3235 FIN-WAIT-2 STATE 3237 In addition to the processing for the ESTABLISHED 3238 state, if the retransmission queue is empty, the 3239 user's CLOSE can be acknowledged ("ok") but do not 3240 delete the TCB. 3242 CLOSE-WAIT STATE 3244 Do the same processing as for the ESTABLISHED state. 3246 CLOSING STATE 3248 In addition to the processing for the ESTABLISHED 3249 state, if the ACK acknowledges our FIN then enter the 3250 TIME-WAIT state, otherwise ignore the segment. 3252 LAST-ACK STATE 3254 The only thing that can arrive in this state is an 3255 acknowledgment of our FIN. If our FIN is now 3256 acknowledged, delete the TCB, enter the CLOSED state, 3257 and return. 3259 TIME-WAIT STATE 3261 The only thing that can arrive in this state is a 3262 retransmission of the remote FIN. Acknowledge it, and 3263 restart the 2 MSL timeout. 3265 sixth, check the URG bit, 3267 ESTABLISHED STATE 3268 FIN-WAIT-1 STATE 3269 FIN-WAIT-2 STATE 3270 If the URG bit is set, RCV.UP <- max(RCV.UP,SEG.UP), and 3271 signal the user that the remote side has urgent data if 3272 the urgent pointer (RCV.UP) is in advance of the data 3273 consumed. If the user has already been signaled (or is 3274 still in the "urgent mode") for this continuous sequence 3275 of urgent data, do not signal the user again. 3277 CLOSE-WAIT STATE 3278 CLOSING STATE 3279 LAST-ACK STATE 3280 TIME-WAIT 3282 This should not occur, since a FIN has been received from 3283 the remote side. Ignore the URG. 3285 seventh, process the segment text, 3287 ESTABLISHED STATE 3288 FIN-WAIT-1 STATE 3289 FIN-WAIT-2 STATE 3291 Once in the ESTABLISHED state, it is possible to deliver 3292 segment text to user RECEIVE buffers. Text from segments 3293 can be moved into buffers until either the buffer is full 3294 or the segment is empty. If the segment empties and 3295 carries an PUSH flag, then the user is informed, when the 3296 buffer is returned, that a PUSH has been received. 3298 When the TCP takes responsibility for delivering the data 3299 to the user it must also acknowledge the receipt of the 3300 data. 3302 Once the TCP takes responsibility for the data it 3303 advances RCV.NXT over the data accepted, and adjusts 3304 RCV.WND as appropriate to the current buffer 3305 availability. The total of RCV.NXT and RCV.WND should 3306 not be reduced. 3308 A TCP MAY send an ACK segment acknowledging RCV.NXT when 3309 a valid segment arrives that is in the window but not at 3310 the left window edge. 3312 Please note the window management suggestions in section 3313 3.7. 3315 Send an acknowledgment of the form: 3317 3319 This acknowledgment should be piggybacked on a segment 3320 being transmitted if possible without incurring undue 3321 delay. 3323 CLOSE-WAIT STATE 3324 CLOSING STATE 3325 LAST-ACK STATE 3326 TIME-WAIT STATE 3328 This should not occur, since a FIN has been received from 3329 the remote side. Ignore the segment text. 3331 eighth, check the FIN bit, 3333 Do not process the FIN if the state is CLOSED, LISTEN or 3334 SYN-SENT since the SEG.SEQ cannot be validated; drop the 3335 segment and return. 3337 If the FIN bit is set, signal the user "connection closing" 3338 and return any pending RECEIVEs with same message, advance 3339 RCV.NXT over the FIN, and send an acknowledgment for the 3340 FIN. Note that FIN implies PUSH for any segment text not 3341 yet delivered to the user. 3343 SYN-RECEIVED STATE 3344 ESTABLISHED STATE 3346 Enter the CLOSE-WAIT state. 3348 FIN-WAIT-1 STATE 3350 If our FIN has been ACKed (perhaps in this segment), 3351 then enter TIME-WAIT, start the time-wait timer, turn 3352 off the other timers; otherwise enter the CLOSING 3353 state. 3355 FIN-WAIT-2 STATE 3357 Enter the TIME-WAIT state. Start the time-wait timer, 3358 turn off the other timers. 3360 CLOSE-WAIT STATE 3362 Remain in the CLOSE-WAIT state. 3364 CLOSING STATE 3366 Remain in the CLOSING state. 3368 LAST-ACK STATE 3370 Remain in the LAST-ACK state. 3372 TIME-WAIT STATE 3374 Remain in the TIME-WAIT state. Restart the 2 MSL 3375 time-wait timeout. 3377 and return. 3379 USER TIMEOUT 3381 USER TIMEOUT 3383 For any state if the user timeout expires, flush all queues, 3384 signal the user "error: connection aborted due to user timeout" 3385 in general and for any outstanding calls, delete the TCB, enter 3386 the CLOSED state and return. 3388 RETRANSMISSION TIMEOUT 3390 For any state if the retransmission timeout expires on a 3391 segment in the retransmission queue, send the segment at the 3392 front of the retransmission queue again, reinitialize the 3393 retransmission timer, and return. 3395 TIME-WAIT TIMEOUT 3397 If the time-wait timeout expires on a connection delete the 3398 TCB, enter the CLOSED state and return. 3400 3.11. Glossary 3402 1822 BBN Report 1822, "The Specification of the Interconnection of 3403 a Host and an IMP". The specification of interface between a 3404 host and the ARPANET. 3406 ACK 3407 A control bit (acknowledge) occupying no sequence space, 3408 which indicates that the acknowledgment field of this segment 3409 specifies the next sequence number the sender of this segment 3410 is expecting to receive, hence acknowledging receipt of all 3411 previous sequence numbers. 3413 ARPANET message 3414 The unit of transmission between a host and an IMP in the 3415 ARPANET. The maximum size is about 1012 octets (8096 bits). 3417 ARPANET packet 3418 A unit of transmission used internally in the ARPANET between 3419 IMPs. The maximum size is about 126 octets (1008 bits). 3421 connection 3422 A logical communication path identified by a pair of sockets. 3424 datagram 3425 A message sent in a packet switched computer communications 3426 network. 3428 Destination Address 3429 The destination address, usually the network and host 3430 identifiers. 3432 FIN 3433 A control bit (finis) occupying one sequence number, which 3434 indicates that the sender will send no more data or control 3435 occupying sequence space. 3437 fragment 3438 A portion of a logical unit of data, in particular an 3439 internet fragment is a portion of an internet datagram. 3441 FTP 3442 A file transfer protocol. 3444 header 3445 Control information at the beginning of a message, segment, 3446 fragment, packet or block of data. 3448 host 3449 A computer. In particular a source or destination of 3450 messages from the point of view of the communication network. 3452 Identification 3453 An Internet Protocol field. This identifying value assigned 3454 by the sender aids in assembling the fragments of a datagram. 3456 IMP 3457 The Interface Message Processor, the packet switch of the 3458 ARPANET. 3460 internet address 3461 A source or destination address specific to the host level. 3463 internet datagram 3464 The unit of data exchanged between an internet module and the 3465 higher level protocol together with the internet header. 3467 internet fragment 3468 A portion of the data of an internet datagram with an 3469 internet header. 3471 IP 3472 Internet Protocol. 3474 IRS 3475 The Initial Receive Sequence number. The first sequence 3476 number used by the sender on a connection. 3478 ISN 3479 The Initial Sequence Number. The first sequence number used 3480 on a connection, (either ISS or IRS). Selected in a way that 3481 is unique within a given period of time and is unpredictable 3482 to attackers. 3484 ISS 3485 The Initial Send Sequence number. The first sequence number 3486 used by the sender on a connection. 3488 leader 3489 Control information at the beginning of a message or block of 3490 data. In particular, in the ARPANET, the control information 3491 on an ARPANET message at the host-IMP interface. 3493 left sequence 3494 This is the next sequence number to be acknowledged by the 3495 data receiving TCP (or the lowest currently unacknowledged 3496 sequence number) and is sometimes referred to as the left 3497 edge of the send window. 3499 local packet 3500 The unit of transmission within a local network. 3502 module 3503 An implementation, usually in software, of a protocol or 3504 other procedure. 3506 MSL 3507 Maximum Segment Lifetime, the time a TCP segment can exist in 3508 the internetwork system. Arbitrarily defined to be 2 3509 minutes. 3511 octet 3512 An eight bit byte. 3514 Options 3515 An Option field may contain several options, and each option 3516 may be several octets in length. The options are used 3517 primarily in testing situations; for example, to carry 3518 timestamps. Both the Internet Protocol and TCP provide for 3519 options fields. 3521 packet 3522 A package of data with a header which may or may not be 3523 logically complete. More often a physical packaging than a 3524 logical packaging of data. 3526 port 3527 The portion of a socket that specifies which logical input or 3528 output channel of a process is associated with the data. 3530 process 3531 A program in execution. A source or destination of data from 3532 the point of view of the TCP or other host-to-host protocol. 3534 PUSH 3535 A control bit occupying no sequence space, indicating that 3536 this segment contains data that must be pushed through to the 3537 receiving user. 3539 RCV.NXT 3540 receive next sequence number 3542 RCV.UP 3543 receive urgent pointer 3545 RCV.WND 3546 receive window 3548 receive next sequence number 3549 This is the next sequence number the local TCP is expecting 3550 to receive. 3552 receive window 3553 This represents the sequence numbers the local (receiving) 3554 TCP is willing to receive. Thus, the local TCP considers 3555 that segments overlapping the range RCV.NXT to RCV.NXT + 3556 RCV.WND - 1 carry acceptable data or control. Segments 3557 containing sequence numbers entirely outside of this range 3558 are considered duplicates and discarded. 3560 RST 3561 A control bit (reset), occupying no sequence space, 3562 indicating that the receiver should delete the connection 3563 without further interaction. The receiver can determine, 3564 based on the sequence number and acknowledgment fields of the 3565 incoming segment, whether it should honor the reset command 3566 or ignore it. In no case does receipt of a segment 3567 containing RST give rise to a RST in response. 3569 RTP 3570 Real Time Protocol: A host-to-host protocol for communication 3571 of time critical information. 3573 SEG.ACK 3574 segment acknowledgment 3576 SEG.LEN 3577 segment length 3579 SEG.PRC 3580 segment precedence value 3582 SEG.SEQ 3583 segment sequence 3585 SEG.UP 3586 segment urgent pointer field 3588 SEG.WND 3589 segment window field 3591 segment 3592 A logical unit of data, in particular a TCP segment is the 3593 unit of data transfered between a pair of TCP modules. 3595 segment acknowledgment 3596 The sequence number in the acknowledgment field of the 3597 arriving segment. 3599 segment length 3600 The amount of sequence number space occupied by a segment, 3601 including any controls which occupy sequence space. 3603 segment sequence 3604 The number in the sequence field of the arriving segment. 3606 send sequence 3607 This is the next sequence number the local (sending) TCP will 3608 use on the connection. It is initially selected from an 3609 initial sequence number curve (ISN) and is incremented for 3610 each octet of data or sequenced control transmitted. 3612 send window 3613 This represents the sequence numbers which the remote 3614 (receiving) TCP is willing to receive. It is the value of 3615 the window field specified in segments from the remote (data 3616 receiving) TCP. The range of new sequence numbers which may 3617 be emitted by a TCP lies between SND.NXT and SND.UNA + 3618 SND.WND - 1. (Retransmissions of sequence numbers between 3619 SND.UNA and SND.NXT are expected, of course.) 3621 SND.NXT 3622 send sequence 3624 SND.UNA 3625 left sequence 3627 SND.UP 3628 send urgent pointer 3630 SND.WL1 3631 segment sequence number at last window update 3633 SND.WL2 3634 segment acknowledgment number at last window update 3636 SND.WND 3637 send window 3639 socket 3640 An address which specifically includes a port identifier, 3641 that is, the concatenation of an Internet Address with a TCP 3642 port. 3644 Source Address 3645 The source address, usually the network and host identifiers. 3647 SYN 3648 A control bit in the incoming segment, occupying one sequence 3649 number, used at the initiation of a connection, to indicate 3650 where the sequence numbering will start. 3652 TCB 3653 Transmission control block, the data structure that records 3654 the state of a connection. 3656 TCB.PRC 3657 The precedence of the connection. 3659 TCP 3660 Transmission Control Protocol: A host-to-host protocol for 3661 reliable communication in internetwork environments. 3663 TOS 3664 Type of Service, an Internet Protocol field. 3666 Type of Service 3667 An Internet Protocol field which indicates the type of 3668 service for this internet fragment. 3670 URG 3671 A control bit (urgent), occupying no sequence space, used to 3672 indicate that the receiving user should be notified to do 3673 urgent processing as long as there is data to be consumed 3674 with sequence numbers less than the value indicated in the 3675 urgent pointer. 3677 urgent pointer 3678 A control field meaningful only when the URG bit is on. This 3679 field communicates the value of the urgent pointer which 3680 indicates the data octet associated with the sending user's 3681 urgent call. 3683 4. Changes from RFC 793 3685 This document obsoletes RFC 793 as well as RFC 6093 and 6528, which 3686 updated 793. In all cases, only the normative protocol specification 3687 and requirements have been incorporated into this document, and the 3688 informational text with background and rationale has not been carried 3689 in. The informational content of those documents is still valuable 3690 in learning about and understanding TCP, and they are valid 3691 Informational references, even though their normative content has 3692 been incorporated into this document. 3694 The main body of this document was adapted from RFC 793's Section 3, 3695 titled "FUNCTIONAL SPECIFICATION", with an attempt to keep formatting 3696 and layout as close as possible. 3698 The collection of applicable RFC Errata that have been reported and 3699 either accepted or held for an update to RFC 793 were incorporated 3700 (Errata IDs: 573, 574, 700, 701, 1283, 1561, 1562, 1564, 1565, 1571, 3701 1572, 2296, 2297, 2298, 2748, 2749, 2934, 3213, 3300, 3301). Some 3702 errata were not applicable due to other changes (Errata IDs: 572, 3703 575, 1569, 3602). TODO: 3305 3705 Changes to the specification of the Urgent Pointer described in RFC 3706 1122 and 6093 were incorporated. See RFC 6093 for detailed 3707 discussion of why these changes were necessary. 3709 The discussion of the RTO from RFC 793 was updated to refer to RFC 3710 6298. The RFC 1122 text on the RTO originally replaced the 793 text, 3711 however, RFC 2988 should have updated 1122, and has subsequently been 3712 obsoleted by 6298. 3714 RFC 1122 contains a collection of other changes and clarifications to 3715 RFC 793. The normative items impacting the protocol have been 3716 incorporated here, though some historically useful implementation 3717 advice and informative discussion from RFC 1122 is not included here. 3719 RFC 1122 contains more than just TCP requirements, so this document 3720 can't obsolete RFC 1122 entirely. It is only marked as "updating" 3721 1122, however, it should be understood to effectively obsolete all of 3722 the RFC 1122 material on TCP. 3724 The more secure Initial Sequence Number generation algorithm from RFC 3725 6528 was incorporated. See RFC 6528 for discussion of the attacks 3726 that this mitigates, as well as advice on selecting PRF algorithms 3727 and managing secret key data. 3729 A note based on RFC 6429 was added to explicitly clarify that system 3730 resource mangement concerns allow connection resources to be 3731 reclaimed. RFC 6429 is obsoleted in the sense that this 3732 clarification has been reflected in this update to the base TCP 3733 specification now. 3735 RFC EDITOR'S NOTE: the content below is for detailed change tracking 3736 and planning, and not to be included with the final revision of the 3737 document. 3739 This document started as draft-eddy-rfc793bis-00, that was merely a 3740 proposal and rough plan for updating RFC 793. 3742 The -01 revision of this draft-eddy-rfc793bis incorporates the 3743 content of RFC 793 Section 3 titled "FUNCTIONAL SPECIFICATION". 3744 Other content from RFC 793 has not been incorporated. The -01 3745 revision of this document makes some minor formatting changes to the 3746 RFC 793 content in order to convert the content into XML2RFC format 3747 and account for left-out parts of RFC 793. For instance, figure 3748 numbering differs and some indentation is not exactly the same. 3750 The -02 revision of draft-eddy-rfc793bis incorporates errata that 3751 have been verified: 3753 Errata ID 573: Reported by Bob Braden (note: This errata basically 3754 is just a reminder that RFC 1122 updates 793. Some of the 3755 associated changes are left pending to a separate revision that 3756 incorporates 1122. Bob's mention of PUSH in 793 section 2.8 was 3757 not applicable here because that section was not part of the 3758 "functional specification". Also the 1122 text on the 3759 retransmission timeout also has been updated by subsequent RFCs, 3760 so the change here deviates from Bob's suggestion to apply the 3761 1122 text.) 3762 Errata ID 574: Reported by Yin Shuming 3763 Errata ID 700: Reported by Yin Shuming 3764 Errata ID 701: Reported by Yin Shuming 3765 Errata ID 1283: Reported by Pei-chun Cheng 3766 Errata ID 1561: Reported by Constantin Hagemeier 3767 Errata ID 1562: Reported by Constantin Hagemeier 3768 Errata ID 1564: Reported by Constantin Hagemeier 3769 Errata ID 1565: Reported by Constantin Hagemeier 3770 Errata ID 1571: Reported by Constantin Hagemeier 3771 Errata ID 1572: Reported by Constantin Hagemeier 3772 Errata ID 2296: Reported by Vishwas Manral 3773 Errata ID 2297: Reported by Vishwas Manral 3774 Errata ID 2298: Reported by Vishwas Manral 3775 Errata ID 2748: Reported by Mykyta Yevstifeyev 3776 Errata ID 2749: Reported by Mykyta Yevstifeyev 3777 Errata ID 2934: Reported by Constantin Hagemeier 3778 Errata ID 3213: Reported by EugnJun Yi 3779 Errata ID 3300: Reported by Botong Huang 3780 Errata ID 3301: Reported by Botong Huang 3781 Note: Some verified errata were not used in this update, as they 3782 relate to sections of RFC 793 elided from this document. These 3783 include Errata ID 572, 575, and 1569. 3784 Note: Errata ID 3602 was not applied in this revision as it is 3785 duplicative of the 1122 corrections. 3786 There is an errata 3305 currently reported that need to be 3787 verified, held, or rejected by the ADs; it is addressing the same 3788 issue as draft-gont-tcpm-tcp-seq-validation and was not attempted 3789 to be applied to this document. 3791 Not related to RFC 793 content, this revision also makes small tweaks 3792 to the introductory text, fixes indentation of the pseudoheader 3793 diagram, and notes that the Security Considerations should also 3794 include privacy, when this section is written. 3796 The -03 revision of draft-eddy-rfc793bis revises all discussion of 3797 the urgent pointer in order to comply with RFC 6093, 1122, and 1011. 3798 Since 1122 held requirements on the urgent pointer, the full list of 3799 requirements was brought into an appendix of this document, so that 3800 it can be updated as-needed. 3802 The -04 revision of draft-eddy-rfc793bis includes the ISN generation 3803 changes from RFC 6528. 3805 The -05 revision of draft-eddy-rfc793bis incorporates MSS 3806 requirements and definitions from RFC 879, 1122, and 6691, as well as 3807 option-handling requirements from RFC 1122. 3809 The -00 revision of draft-ietf-tcpm-rfc793bis incorporates several 3810 additional clarifications and updates to the section on segmentation, 3811 many of which are based on feedback from Joe Touch improving from the 3812 initial text on this in the previous revision. 3814 The -01 revision incorporates the change to Reserved bits due to ECN, 3815 as well as many other changes that come from RFC 1122. 3817 The -02 revision has small formating modifications in order to 3818 address xml2rfc warnings about long lines. It was a quick update to 3819 avoid document expiration. TCPM working group discussion in 2015 3820 also indicated that that we should not try to add sections on 3821 implementation advice or similar non-normative information. 3823 The -03 revision incorporates more content from RFC 1122: Passive 3824 OPEN Calls, Time-To-Live, Multihoming, IP Options, ICMP messages, 3825 Data Communications, When to Send Data, When to Send a Window Update, 3826 Managing the Window, Probing Zero Windows, When to Send an ACK 3827 Segment. The section on data communications was re-organized into 3828 clearer subsections (previously headings were embedded in the 793 3829 text), and windows management advice from 793 was removed (as 3830 reviewed by TCPM working group) in favor of the 1122 additions on 3831 SWS, ZWP, and related topics. 3833 The -04 revision includes reference to RFC 6429 on the ZWP condition, 3834 RFC1122 material on TCP Connection Failures, TCP Keep-Alives, 3835 Acknowledging Queued Segments, and Remote Address Validation. RTO 3836 computation is referenced from RFC 6298 rather than RFC 1122. 3838 TODO list of other planned changes (these can be added to or made 3839 more specific, as the document proceeds): 3841 1. incorporate relevant parts of 3168 (ECN) - beyond just indicating 3842 the names of the 2 bits already done 3843 2. point to 5461 (soft errors) 3844 3. mention 5961 state machine option 3845 4. mention 6161 (reducing TIME-WAIT) 3846 5. TOS material does not take DSCP changes into account 3847 6. there is inconsistency between use of SYN_RCVD and SYNC-RECEIVED 3848 in diagrams and text in various places 3849 7. make sure that clarifications in RFC 1011 are captured 3851 TODO list of other potential changes, if there is TCPM consensus: 3853 1. see draft-gont-tcpm-tcp-seccomp-prec 3854 2. incorporate Fernando's new number-checking fixes (if past the 3855 IESG in time) 3856 3. look at Tony Sabatini suggestion for describing DO field 3857 4. clearly specify treatment of reserved bits (see TCPM thread on 3858 EDO draft April 25, 2014) 3859 5. look at possible mention of draft-minshall-nagle (e.g. as in 3860 Linux) 3861 6. per discussion with Joe Touch (TAPS list, 6/20/2015), the 3862 description of the API could be revisited 3864 5. IANA Considerations 3866 This memo includes no request to IANA. Existing IANA registries for 3867 TCP parameters are sufficient. 3869 TODO: check whether entries pointing to 793 and other documents 3870 obsoleted by this one should be updated to point to this one instead. 3872 6. Security and Privacy Considerations 3874 TODO 3875 See RFC 6093 [15] for discussion of security considerations related 3876 to the urgent pointer field. 3878 Editor's Note: Scott Brim mentioned that this should include a 3879 PERPASS/privacy review. 3881 7. Acknowledgements 3883 This document is largely a revision of RFC 793, which Jon Postel was 3884 the editor of. Due to his excellent work, it was able to last for 3885 three decades before we felt the need to revise it. 3887 Andre Oppermann was a contributor and helped to edit the first 3888 revision of this document. 3890 We are thankful for the assistance of the IETF TCPM working group 3891 chairs: 3893 Michael Scharf 3894 Yoshifumi Nishida 3895 Pasi Sarolahti 3897 During early discussion of this work on the TCPM mailing list, and at 3898 the IETF 88 meeting in Vancouver, helpful comments, critiques, and 3899 reviews were received from (listed alphebetically): David Borman, 3900 Yuchung Cheng, Martin Duke, Kevin Lahey, Kevin Mason, Matt Mathis, 3901 Hagen Paul Pfeifer, Anthony Sabatini, Joe Touch, Reji Varghese, Lloyd 3902 Wood, and Alex Zimmermann. 3904 This document includes content from errata that were reported by 3905 (listed chronologically): Yin Shuming, Bob Braden, Morris M. Keesan, 3906 Pei-chun Cheng, Constantin Hagemeier, Vishwas Manral, Mykyta 3907 Yevstifeyev, EungJun Yi, Botong Huang. 3909 8. References 3911 8.1. Normative References 3913 [1] Postel, J., "Internet Protocol", STD 5, RFC 791, 3914 DOI 10.17487/RFC0791, September 1981, 3915 . 3917 [2] Mogul, J. and S. Deering, "Path MTU discovery", RFC 1191, 3918 DOI 10.17487/RFC1191, November 1990, 3919 . 3921 [3] McCann, J., Deering, S., and J. Mogul, "Path MTU Discovery 3922 for IP version 6", RFC 1981, DOI 10.17487/RFC1981, August 3923 1996, . 3925 [4] Bradner, S., "Key words for use in RFCs to Indicate 3926 Requirement Levels", BCP 14, RFC 2119, 3927 DOI 10.17487/RFC2119, March 1997, 3928 . 3930 [5] Borman, D., Deering, S., and R. Hinden, "IPv6 Jumbograms", 3931 RFC 2675, DOI 10.17487/RFC2675, August 1999, 3932 . 3934 [6] Lahey, K., "TCP Problems with Path MTU Discovery", 3935 RFC 2923, DOI 10.17487/RFC2923, September 2000, 3936 . 3938 [7] Paxson, V., Allman, M., Chu, J., and M. Sargent, 3939 "Computing TCP's Retransmission Timer", RFC 6298, 3940 DOI 10.17487/RFC6298, June 2011, 3941 . 3943 8.2. Informative References 3945 [8] Postel, J., "Transmission Control Protocol", STD 7, 3946 RFC 793, DOI 10.17487/RFC0793, September 1981, 3947 . 3949 [9] Nagle, J., "Congestion Control in IP/TCP Internetworks", 3950 RFC 896, DOI 10.17487/RFC0896, January 1984, 3951 . 3953 [10] Braden, R., Ed., "Requirements for Internet Hosts - 3954 Communication Layers", STD 3, RFC 1122, 3955 DOI 10.17487/RFC1122, October 1989, 3956 . 3958 [11] Mathis, M. and J. Heffner, "Packetization Layer Path MTU 3959 Discovery", RFC 4821, DOI 10.17487/RFC4821, March 2007, 3960 . 3962 [12] Culley, P., Elzur, U., Recio, R., Bailey, S., and J. 3963 Carrier, "Marker PDU Aligned Framing for TCP 3964 Specification", RFC 5044, DOI 10.17487/RFC5044, October 3965 2007, . 3967 [13] Allman, M., Paxson, V., and E. Blanton, "TCP Congestion 3968 Control", RFC 5681, DOI 10.17487/RFC5681, September 2009, 3969 . 3971 [14] Sandlund, K., Pelletier, G., and L-E. Jonsson, "The RObust 3972 Header Compression (ROHC) Framework", RFC 5795, 3973 DOI 10.17487/RFC5795, March 2010, 3974 . 3976 [15] Gont, F. and A. Yourtchenko, "On the Implementation of the 3977 TCP Urgent Mechanism", RFC 6093, DOI 10.17487/RFC6093, 3978 January 2011, . 3980 [16] Bashyam, M., Jethanandani, M., and A. Ramaiah, "TCP Sender 3981 Clarification for Persist Condition", RFC 6429, 3982 DOI 10.17487/RFC6429, December 2011, 3983 . 3985 [17] Gont, F. and S. Bellovin, "Defending against Sequence 3986 Number Attacks", RFC 6528, DOI 10.17487/RFC6528, February 3987 2012, . 3989 [18] Borman, D., "TCP Options and Maximum Segment Size (MSS)", 3990 RFC 6691, DOI 10.17487/RFC6691, July 2012, 3991 . 3993 [19] Borman, D., Braden, B., Jacobson, V., and R. 3994 Scheffenegger, Ed., "TCP Extensions for High Performance", 3995 RFC 7323, DOI 10.17487/RFC7323, September 2014, 3996 . 3998 [20] Duke, M., Braden, R., Eddy, W., Blanton, E., and A. 3999 Zimmermann, "A Roadmap for Transmission Control Protocol 4000 (TCP) Specification Documents", RFC 7414, 4001 DOI 10.17487/RFC7414, February 2015, 4002 . 4004 Appendix A. TCP Requirement Summary 4006 This section is adapted from RFC 1122. 4008 TODO: this needs to be seriously redone, to use 793bis section 4009 numbers instead of 1122 ones, the RFC1122 heading should be removed, 4010 and all 1122 requirements need to be reflected in 793bis text. 4012 TODO: NOTE that PMTUD+PLPMTUD is not included in this table of 4013 recommendations. 4015 | | | | |S| | 4016 | | | | |H| |F 4017 | | | | |O|M|o 4018 | | |S| |U|U|o 4019 | | |H| |L|S|t 4020 | |M|O| |D|T|n 4021 | |U|U|M| | |o 4022 | |S|L|A|N|N|t 4023 |RFC1122 |T|D|Y|O|O|t 4024 FEATURE |SECTION | | | |T|T|e 4025 -------------------------------------------------|--------|-|-|-|-|-|-- 4026 | | | | | | | 4027 Push flag | | | | | | | 4028 Aggregate or queue un-pushed data |4.2.2.2 | | |x| | | 4029 Sender collapse successive PSH flags |4.2.2.2 | |x| | | | 4030 SEND call can specify PUSH |4.2.2.2 | | |x| | | 4031 If cannot: sender buffer indefinitely |4.2.2.2 | | | | |x| 4032 If cannot: PSH last segment |4.2.2.2 |x| | | | | 4033 Notify receiving ALP of PSH |4.2.2.2 | | |x| | |1 4034 Send max size segment when possible |4.2.2.2 | |x| | | | 4035 | | | | | | | 4036 Window | | | | | | | 4037 Treat as unsigned number |4.2.2.3 |x| | | | | 4038 Handle as 32-bit number |4.2.2.3 | |x| | | | 4039 Shrink window from right |4.2.2.16| | | |x| | 4040 Robust against shrinking window |4.2.2.16|x| | | | | 4041 Receiver's window closed indefinitely |4.2.2.17| | |x| | | 4042 Sender probe zero window |4.2.2.17|x| | | | | 4043 First probe after RTO |4.2.2.17| |x| | | | 4044 Exponential backoff |4.2.2.17| |x| | | | 4045 Allow window stay zero indefinitely |4.2.2.17|x| | | | | 4046 Sender timeout OK conn with zero wind |4.2.2.17| | | | |x| 4047 | | | | | | | 4048 Urgent Data | | | | | | | 4049 Pointer indicates first non-urgent octet |4.2.2.4 |x| | | | | 4050 Arbitrary length urgent data sequence |4.2.2.4 |x| | | | | 4051 Inform ALP asynchronously of urgent data |4.2.2.4 |x| | | | |1 4052 ALP can learn if/how much urgent data Q'd |4.2.2.4 |x| | | | |1 4053 | | | | | | | 4054 TCP Options | | | | | | | 4055 Receive TCP option in any segment |4.2.2.5 |x| | | | | 4056 Ignore unsupported options |4.2.2.5 |x| | | | | 4057 Cope with illegal option length |4.2.2.5 |x| | | | | 4058 Implement sending & receiving MSS option |4.2.2.6 |x| | | | | 4059 IPv4 Send MSS option unless 536 |4.2.2.6 | |x| | | | 4060 IPv6 Send MSS option unless 1220 | N/A | |x| | | | 4061 Send MSS option always |4.2.2.6 | | |x| | | 4062 IPv4 Send-MSS default is 536 |4.2.2.6 |x| | | | | 4063 IPv6 Send-MSS default is 1220 | N/A |x| | | | | 4064 Calculate effective send seg size |4.2.2.6 |x| | | | | 4065 MSS accounts for varying MTU | N/A | |x| | | | 4066 | | | | | | | 4067 TCP Checksums | | | | | | | 4068 Sender compute checksum |4.2.2.7 |x| | | | | 4069 Receiver check checksum |4.2.2.7 |x| | | | | 4070 | | | | | | | 4071 ISN Selection | | | | | | | 4072 Include a clock-driven ISN generator component |4.2.2.9 |x| | | | | 4073 Secure ISN generator with a PRF component | N/A | |x| | | | 4074 | | | | | | | 4075 Opening Connections | | | | | | | 4076 Support simultaneous open attempts |4.2.2.10|x| | | | | 4077 SYN-RCVD remembers last state |4.2.2.11|x| | | | | 4078 Passive Open call interfere with others |4.2.2.18| | | | |x| 4079 Function: simultan. LISTENs for same port |4.2.2.18|x| | | | | 4080 Ask IP for src address for SYN if necc. |4.2.3.7 |x| | | | | 4081 Otherwise, use local addr of conn. |4.2.3.7 |x| | | | | 4082 OPEN to broadcast/multicast IP Address |4.2.3.14| | | | |x| 4083 Silently discard seg to bcast/mcast addr |4.2.3.14|x| | | | | 4084 | | | | | | | 4085 Closing Connections | | | | | | | 4086 RST can contain data |4.2.2.12| |x| | | | 4087 Inform application of aborted conn |4.2.2.13|x| | | | | 4088 Half-duplex close connections |4.2.2.13| | |x| | | 4089 Send RST to indicate data lost |4.2.2.13| |x| | | | 4090 In TIME-WAIT state for 2MSL seconds |4.2.2.13|x| | | | | 4091 Accept SYN from TIME-WAIT state |4.2.2.13| | |x| | | 4092 | | | | | | | 4093 Retransmissions | | | | | | | 4094 Jacobson Slow Start algorithm |4.2.2.15|x| | | | | 4095 Jacobson Congestion-Avoidance algorithm |4.2.2.15|x| | | | | 4096 Retransmit with same IP ident |4.2.2.15| | |x| | | 4097 Karn's algorithm |4.2.3.1 |x| | | | | 4098 Jacobson's RTO estimation alg. |4.2.3.1 |x| | | | | 4099 Exponential backoff |4.2.3.1 |x| | | | | 4100 SYN RTO calc same as data |4.2.3.1 | |x| | | | 4101 Recommended initial values and bounds |4.2.3.1 | |x| | | | 4102 | | | | | | | 4103 Generating ACK's: | | | | | | | 4104 Queue out-of-order segments |4.2.2.20| |x| | | | 4105 Process all Q'd before send ACK |4.2.2.20|x| | | | | 4106 Send ACK for out-of-order segment |4.2.2.21| | |x| | | 4107 Delayed ACK's |4.2.3.2 | |x| | | | 4108 Delay < 0.5 seconds |4.2.3.2 |x| | | | | 4109 Every 2nd full-sized segment ACK'd |4.2.3.2 |x| | | | | 4110 Receiver SWS-Avoidance Algorithm |4.2.3.3 |x| | | | | 4111 | | | | | | | 4112 Sending data | | | | | | | 4113 Configurable TTL |4.2.2.19|x| | | | | 4114 Sender SWS-Avoidance Algorithm |4.2.3.4 |x| | | | | 4115 Nagle algorithm |4.2.3.4 | |x| | | | 4116 Application can disable Nagle algorithm |4.2.3.4 |x| | | | | 4117 | | | | | | | 4118 Connection Failures: | | | | | | | 4119 Negative advice to IP on R1 retxs |4.2.3.5 |x| | | | | 4120 Close connection on R2 retxs |4.2.3.5 |x| | | | | 4121 ALP can set R2 |4.2.3.5 |x| | | | |1 4122 Inform ALP of R1<=retxs inform ALP |4.2.3.9 | |x| | | | 4147 Dest. Unreach (0,1,5) => abort conn |4.2.3.9 | | | | |x| 4148 Dest. Unreach (2-4) => abort conn |4.2.3.9 | |x| | | | 4149 Source Quench => slow start |4.2.3.9 | |x| | | | 4150 Time Exceeded => tell ALP, don't abort |4.2.3.9 | |x| | | | 4151 Param Problem => tell ALP, don't abort |4.2.3.9 | |x| | | | 4152 | | | | | | | 4153 Address Validation | | | | | | | 4154 Reject OPEN call to invalid IP address |4.2.3.10|x| | | | | 4155 Reject SYN from invalid IP address |4.2.3.10|x| | | | | 4156 Silently discard SYN to bcast/mcast addr |4.2.3.10|x| | | | | 4157 | | | | | | | 4158 TCP/ALP Interface Services | | | | | | | 4159 Error Report mechanism |4.2.4.1 |x| | | | | 4160 ALP can disable Error Report Routine |4.2.4.1 | |x| | | | 4161 ALP can specify TOS for sending |4.2.4.2 |x| | | | | 4162 Passed unchanged to IP |4.2.4.2 | |x| | | | 4163 ALP can change TOS during connection |4.2.4.2 | |x| | | | 4164 Pass received TOS up to ALP |4.2.4.2 | | |x| | | 4165 FLUSH call |4.2.4.3 | | |x| | | 4166 Optional local IP addr parm. in OPEN |4.2.4.4 |x| | | | | 4167 -------------------------------------------------|--------|-|-|-|-|-|-- 4169 FOOTNOTES: (1) "ALP" means Application-Layer program. 4171 Author's Address 4173 Wesley M. Eddy (editor) 4174 MTI Systems 4175 US 4177 Email: wes@mti-systems.com