idnits 2.17.1 draft-eddy-rfc793bis-05.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 2 instances 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 RFC6691, 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 (February 6, 2015) is 3368 days in the past. Is this intentional? Checking references for intended status: Proposed Standard ---------------------------------------------------------------------------- (See RFCs 3967 and 4897 for information about using normative references to lower-maturity documents in RFCs) -- Looks like a reference, but probably isn't: 'RFC1191' on line 1427 -- Looks like a reference, but probably isn't: 'RFC2923' on line 1429 -- Looks like a reference, but probably isn't: 'RFC4821' on line 1431 -- Looks like a reference, but probably isn't: 'RFC5795' on line 1436 -- Looks like a reference, but probably isn't: 'RFC2675' on line 1452 -- Looks like a reference, but probably isn't: 'RFC1981' on line 1454 == Unused Reference: '4' is defined on line 3378, but no explicit reference was found in the text == Unused Reference: '5' is defined on line 3381, but no explicit reference was found in the text == Unused Reference: '6' is defined on line 3384, but no explicit reference was found in the text == Unused Reference: '9' is defined on line 3393, but no explicit reference was found in the text -- Obsolete informational reference (is this intentional?): RFC 793 (ref. '2') (Obsoleted by RFC 9293) -- Obsolete informational reference (is this intentional?): RFC 6093 (ref. '7') (Obsoleted by RFC 9293) -- Obsolete informational reference (is this intentional?): RFC 6528 (ref. '8') (Obsoleted by RFC 9293) -- Obsolete informational reference (is this intentional?): RFC 6691 (ref. '9') (Obsoleted by RFC 9293) Summary: 1 error (**), 0 flaws (~~), 6 warnings (==), 17 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, 6528, 6691 February 6, 2015 5 (if approved) 6 Updates: 1122 (if approved) 7 Intended status: Standards Track 8 Expires: August 10, 2015 10 Transmission Control Protocol Specification 11 draft-eddy-rfc793bis-05 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 [1]. 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 August 10, 2015. 50 Copyright Notice 52 Copyright (c) 2015 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 . . . . . . . . . . . . . . . . . . 4 82 3.1. Header Format . . . . . . . . . . . . . . . . . . . . . . 4 83 3.2. Terminology . . . . . . . . . . . . . . . . . . . . . . . 9 84 3.3. Sequence Numbers . . . . . . . . . . . . . . . . . . . . 13 85 3.4. Establishing a connection . . . . . . . . . . . . . . . . 20 86 3.5. Closing a Connection . . . . . . . . . . . . . . . . . . 27 87 3.6. Precedence and Security . . . . . . . . . . . . . . . . . 29 88 3.7. Segmentation . . . . . . . . . . . . . . . . . . . . . . 30 89 3.7.1. Maximum Segment Size Option . . . . . . . . . . . . . 31 90 3.7.2. Path MTU Discovery . . . . . . . . . . . . . . . . . 32 91 3.7.3. Interfaces with Variable MSS Values . . . . . . . . . 32 92 3.7.4. IPv6 Jumbograms . . . . . . . . . . . . . . . . . . . 32 93 3.8. Data Communication . . . . . . . . . . . . . . . . . . . 32 94 3.9. Interfaces . . . . . . . . . . . . . . . . . . . . . . . 36 95 3.9.1. User/TCP Interface . . . . . . . . . . . . . . . . . 37 96 3.9.2. TCP/Lower-Level Interface . . . . . . . . . . . . . . 43 97 3.10. Event Processing . . . . . . . . . . . . . . . . . . . . 44 98 3.11. Glossary . . . . . . . . . . . . . . . . . . . . . . . . 67 99 4. Changes from RFC 793 . . . . . . . . . . . . . . . . . . . . 72 100 5. IANA Considerations . . . . . . . . . . . . . . . . . . . . . 75 101 6. Security and Privacy Considerations . . . . . . . . . . . . . 75 102 7. Acknowledgements . . . . . . . . . . . . . . . . . . . . . . 76 103 8. References . . . . . . . . . . . . . . . . . . . . . . . . . 76 104 8.1. Normative References . . . . . . . . . . . . . . . . . . 76 105 8.2. Informative References . . . . . . . . . . . . . . . . . 76 106 Appendix A. TCP Requirement Summary . . . . . . . . . . . . . . 77 107 Author's Address . . . . . . . . . . . . . . . . . . . . . . . . 80 109 1. Purpose and Scope 111 In 1981, RFC 793 [2] was released, documenting the Transmission 112 Control Protocol (TCP), and replacing earlier specifications for TCP 113 that had been published in the past. 115 Since then, TCP has been implemented many times, and has been used as 116 a transport protocol for numerous applications on the Internet. 118 For several decades, RFC 793 plus a number of other documents have 119 combined to serve as the specification for TCP [10]. Over time, a 120 number of errata have been identified on RFC 793, as well as 121 deficiencies in security, performance, and other aspects. A number 122 of enhancements has grown and been documented separately. These were 123 never accumulated together into an update to the base specification. 125 The purpose of this document is to bring together all of the IETF 126 Standards Track changes that have been made to the basic TCP 127 functional specification and unify them into an update of the RFC 793 128 protocol specification. Some companion documents are referenced for 129 important algorithms that TCP uses (e.g. for congestion control), but 130 have not been attempted to include in this document. This is a 131 conscious choice, as this base specification can be used with 132 multiple additional algorithms that are developed and incorporated 133 separately, but all TCP implementations need to implement this 134 specification as a common basis in order to interoperate. As some 135 additional TCP features have become quite complicated themselves 136 (e.g. advanced loss recovery and congestion control), future 137 companion documents may attempt to similarly bring these together. 139 In addition to the protocol specification that descibes the TCP 140 segment format, generation, and processing rules that are to be 141 implemented in code, RFC 793 and other updates also contain 142 informative and descriptive text for human readers to understand 143 aspects of the protocol design and operation. This document does not 144 attempt to alter or update this informative text, and is focused only 145 on updating the normative protocol specification. We preserve 146 references to the documentation containing the important explanations 147 and rationale, where appropriate. 149 This document is intended to be useful both in checking existing TCP 150 implementations for conformance, as well as in writing new 151 implementations. 153 2. Introduction 155 RFC 793 contains a discussion of the TCP design goals and provides 156 examples of its operation, including examples of connection 157 establishment, closing connections, and retransmitting packets to 158 repair losses. 160 This document describes the basic functionality expected in modern 161 implementations of TCP, and replaces the protocol specification in 162 RFC 793. It does not replicate or attempt to update the examples and 163 other discussion in RFC 793. Other documents are referenced to 164 provide explanation of the theory of operation, rationale, and 165 detailed discussion of design decisions. This document only focuses 166 on the normative behavior of the protocol. 168 TEMPORARY EDITOR'S NOTE: This is an early revision in the process of 169 updating RFC 793. Many planned changes are not yet incorporated. 171 ***Please do not use this revision as a basis for any work or 172 reference.*** 174 A list of changes from RFC 793 is contained in Section 4. 176 TEMPORARY EDITOR'S NOTE: the current revision of this document does 177 not yet collect all of the changes that will be in the final version. 178 The set of content changes planned for future revisions is kept in 179 Section 4. 181 3. Functional Specification 183 3.1. Header Format 185 TCP segments are sent as internet datagrams. The Internet Protocol 186 header carries several information fields, including the source and 187 destination host addresses [2]. A TCP header follows the internet 188 header, supplying information specific to the TCP protocol. This 189 division allows for the existence of host level protocols other than 190 TCP. 192 TCP Header Format 194 0 1 2 3 195 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 196 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 197 | Source Port | Destination Port | 198 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 199 | Sequence Number | 200 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 201 | Acknowledgment Number | 202 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 203 | Data | |U|A|P|R|S|F| | 204 | Offset| Reserved |R|C|S|S|Y|I| Window | 205 | | |G|K|H|T|N|N| | 206 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 207 | Checksum | Urgent Pointer | 208 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 209 | Options | Padding | 210 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 211 | data | 212 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 214 TCP Header Format 216 Note that one tick mark represents one bit position. 218 Figure 1 220 Source Port: 16 bits 222 The source port number. 224 Destination Port: 16 bits 226 The destination port number. 228 Sequence Number: 32 bits 230 The sequence number of the first data octet in this segment (except 231 when SYN is present). If SYN is present the sequence number is the 232 initial sequence number (ISN) and the first data octet is ISN+1. 234 Acknowledgment Number: 32 bits 236 If the ACK control bit is set this field contains the value of the 237 next sequence number the sender of the segment is expecting to 238 receive. Once a connection is established this is always sent. 240 Data Offset: 4 bits 242 The number of 32 bit words in the TCP Header. This indicates where 243 the data begins. The TCP header (even one including options) is an 244 integral number of 32 bits long. 246 Reserved: 6 bits 248 Reserved for future use. Must be zero. 250 Control Bits: 6 bits (from left to right): 252 URG: Urgent Pointer field significant 253 ACK: Acknowledgment field significant 254 PSH: Push Function 255 RST: Reset the connection 256 SYN: Synchronize sequence numbers 257 FIN: No more data from sender 259 Window: 16 bits 261 The number of data octets beginning with the one indicated in the 262 acknowledgment field which the sender of this segment is willing to 263 accept. 265 Checksum: 16 bits 267 The checksum field is the 16 bit one's complement of the one's 268 complement sum of all 16 bit words in the header and text. If a 269 segment contains an odd number of header and text octets to be 270 checksummed, the last octet is padded on the right with zeros to 271 form a 16 bit word for checksum purposes. The pad is not 272 transmitted as part of the segment. While computing the checksum, 273 the checksum field itself is replaced with zeros. 275 The checksum also covers a 96 bit pseudo header conceptually 276 prefixed to the TCP header. This pseudo header contains the Source 277 Address, the Destination Address, the Protocol, and TCP length. 278 This gives the TCP protection against misrouted segments. This 279 information is carried in the Internet Protocol and is transferred 280 across the TCP/Network interface in the arguments or results of 281 calls by the TCP on the IP. 283 +--------+--------+--------+--------+ 284 | Source Address | 285 +--------+--------+--------+--------+ 286 | Destination Address | 287 +--------+--------+--------+--------+ 288 | zero | PTCL | TCP Length | 289 +--------+--------+--------+--------+ 291 The TCP Length is the TCP header length plus the data length in 292 octets (this is not an explicitly transmitted quantity, but is 293 computed), and it does not count the 12 octets of the pseudo 294 header. 296 Urgent Pointer: 16 bits 298 This field communicates the current value of the urgent pointer as 299 a positive offset from the sequence number in this segment. The 300 urgent pointer points to the sequence number of the octet following 301 the urgent data. This field is only be interpreted in segments 302 with the URG control bit set. 304 Options: variable 306 Options may occupy space at the end of the TCP header and are a 307 multiple of 8 bits in length. All options are included in the 308 checksum. An option may begin on any octet boundary. There are 309 two cases for the format of an option: 311 Case 1: A single octet of option-kind. 313 Case 2: An octet of option-kind, an octet of option-length, and 314 the actual option-data octets. 316 The option-length counts the two octets of option-kind and option- 317 length as well as the option-data octets. 319 Note that the list of options may be shorter than the data offset 320 field might imply. The content of the header beyond the End-of- 321 Option option must be header padding (i.e., zero). 323 Currently defined options include (kind indicated in octal): 325 Kind Length Meaning 326 ---- ------ ------- 327 0 - End of option list. 328 1 - No-Operation. 329 2 4 Maximum Segment Size. 331 A TCP MUST be able to receive a TCP option in any segment. A TCP 332 MUST ignore without error any TCP option it does not implement, 333 assuming that the option has a length field (all TCP options except 334 End of option list and No-Operation have length fields). TCP MUST 335 be prepared to handle an illegal option length (e.g., zero) without 336 crashing; a suggested procedure is to reset the connection and log 337 the reason. 339 Specific Option Definitions 341 End of Option List 343 +--------+ 344 |00000000| 345 +--------+ 346 Kind=0 348 This option code indicates the end of the option list. This 349 might not coincide with the end of the TCP header according to 350 the Data Offset field. This is used at the end of all options, 351 not the end of each option, and need only be used if the end of 352 the options would not otherwise coincide with the end of the TCP 353 header. 355 No-Operation 357 +--------+ 358 |00000001| 359 +--------+ 360 Kind=1 362 This option code may be used between options, for example, to 363 align the beginning of a subsequent option on a word boundary. 364 There is no guarantee that senders will use this option, so 365 receivers must be prepared to process options even if they do 366 not begin on a word boundary. 368 Maximum Segment Size (MSS) 370 +--------+--------+---------+--------+ 371 |00000010|00000100| max seg size | 372 +--------+--------+---------+--------+ 373 Kind=2 Length=4 375 Maximum Segment Size Option Data: 16 bits 377 If this option is present, then it communicates the maximum 378 receive segment size at the TCP which sends this segment. This 379 field may be sent in the initial connection request (i.e., in 380 segments with the SYN control bit set) and must not be sent in 381 other segments. If this option is not used, any segment size is 382 allowed. 384 Padding: variable 386 The TCP header padding is used to ensure that the TCP header ends 387 and data begins on a 32 bit boundary. The padding is composed of 388 zeros. 390 3.2. Terminology 392 Before we can discuss very much about the operation of the TCP we 393 need to introduce some detailed terminology. The maintenance of a 394 TCP connection requires the remembering of several variables. We 395 conceive of these variables being stored in a connection record 396 called a Transmission Control Block or TCB. Among the variables 397 stored in the TCB are the local and remote socket numbers, the 398 security and precedence of the connection, pointers to the user's 399 send and receive buffers, pointers to the retransmit queue and to the 400 current segment. In addition several variables relating to the send 401 and receive sequence numbers are stored in the TCB. 403 Send Sequence Variables 405 SND.UNA - send unacknowledged 406 SND.NXT - send next 407 SND.WND - send window 408 SND.UP - send urgent pointer 409 SND.WL1 - segment sequence number used for last window update 410 SND.WL2 - segment acknowledgment number used for last window 411 update 412 ISS - initial send sequence number 414 Receive Sequence Variables 416 RCV.NXT - receive next 417 RCV.WND - receive window 418 RCV.UP - receive urgent pointer 419 IRS - initial receive sequence number 421 The following diagrams may help to relate some of these variables to 422 the sequence space. 424 Send Sequence Space 426 1 2 3 4 427 ----------|----------|----------|---------- 428 SND.UNA SND.NXT SND.UNA 429 +SND.WND 431 1 - old sequence numbers which have been acknowledged 432 2 - sequence numbers of unacknowledged data 433 3 - sequence numbers allowed for new data transmission 434 4 - future sequence numbers which are not yet allowed 436 Send Sequence Space 438 Figure 2 440 The send window is the portion of the sequence space labeled 3 in 441 Figure 2. 443 Receive Sequence Space 445 1 2 3 446 ----------|----------|---------- 447 RCV.NXT RCV.NXT 448 +RCV.WND 450 1 - old sequence numbers which have been acknowledged 451 2 - sequence numbers allowed for new reception 452 3 - future sequence numbers which are not yet allowed 454 Receive Sequence Space 456 Figure 3 458 The receive window is the portion of the sequence space labeled 2 in 459 Figure 3. 461 There are also some variables used frequently in the discussion that 462 take their values from the fields of the current segment. 464 Current Segment Variables 466 SEG.SEQ - segment sequence number 467 SEG.ACK - segment acknowledgment number 468 SEG.LEN - segment length 469 SEG.WND - segment window 470 SEG.UP - segment urgent pointer 471 SEG.PRC - segment precedence value 473 A connection progresses through a series of states during its 474 lifetime. The states are: LISTEN, SYN-SENT, SYN-RECEIVED, 475 ESTABLISHED, FIN-WAIT-1, FIN-WAIT-2, CLOSE-WAIT, CLOSING, LAST-ACK, 476 TIME-WAIT, and the fictional state CLOSED. CLOSED is fictional 477 because it represents the state when there is no TCB, and therefore, 478 no connection. Briefly the meanings of the states are: 480 LISTEN - represents waiting for a connection request from any 481 remote TCP and port. 483 SYN-SENT - represents waiting for a matching connection request 484 after having sent a connection request. 486 SYN-RECEIVED - represents waiting for a confirming connection 487 request acknowledgment after having both received and sent a 488 connection request. 490 ESTABLISHED - represents an open connection, data received can be 491 delivered to the user. The normal state for the data transfer 492 phase of the connection. 494 FIN-WAIT-1 - represents waiting for a connection termination 495 request from the remote TCP, or an acknowledgment of the 496 connection termination request previously sent. 498 FIN-WAIT-2 - represents waiting for a connection termination 499 request from the remote TCP. 501 CLOSE-WAIT - represents waiting for a connection termination 502 request from the local user. 504 CLOSING - represents waiting for a connection termination request 505 acknowledgment from the remote TCP. 507 LAST-ACK - represents waiting for an acknowledgment of the 508 connection termination request previously sent to the remote TCP 509 (this termination request sent to the remote TCP already included 510 an acknowledgment of the termination request sent from the remote 511 TCP). 513 TIME-WAIT - represents waiting for enough time to pass to be sure 514 the remote TCP received the acknowledgment of its connection 515 termination request. 517 CLOSED - represents no connection state at all. 519 A TCP connection progresses from one state to another in response to 520 events. The events are the user calls, OPEN, SEND, RECEIVE, CLOSE, 521 ABORT, and STATUS; the incoming segments, particularly those 522 containing the SYN, ACK, RST and FIN flags; and timeouts. 524 The state diagram in Figure 4 illustrates only state changes, 525 together with the causing events and resulting actions, but addresses 526 neither error conditions nor actions which are not connected with 527 state changes. In a later section, more detail is offered with 528 respect to the reaction of the TCP to events. 530 NOTA BENE: this diagram is only a summary and must not be taken as 531 the total specification. 533 +---------+ ---------\ active OPEN 534 | CLOSED | \ ----------- 535 +---------+<---------\ \ create TCB 536 | ^ \ \ snd SYN 537 passive OPEN | | CLOSE \ \ 538 ------------ | | ---------- \ \ 539 create TCB | | delete TCB \ \ 540 V | \ \ 541 rcv RST (note 1) +---------+ CLOSE | \ 542 -------------------->| LISTEN | ---------- | | 543 / +---------+ delete TCB | | 544 / rcv SYN | | SEND | | 545 / ----------- | | ------- | V 546 +---------+ snd SYN,ACK / \ snd SYN +---------+ 547 | |<----------------- ------------------>| | 548 | SYN | rcv SYN | SYN | 549 | RCVD |<-----------------------------------------------| SENT | 550 | | snd SYN,ACK | | 551 | |------------------ -------------------| | 552 +---------+ rcv ACK of SYN \ / rcv SYN,ACK +---------+ 553 | -------------- | | ----------- 554 | x | | snd ACK 555 | V V 556 | CLOSE +---------+ 557 | ------- | ESTAB | 558 | snd FIN +---------+ 559 | CLOSE | | rcv FIN 560 V ------- | | ------- 561 +---------+ snd FIN / \ snd ACK +---------+ 562 | FIN |<----------------- ------------------>| CLOSE | 563 | WAIT-1 |------------------ | WAIT | 564 +---------+ rcv FIN \ +---------+ 565 | rcv ACK of FIN ------- | CLOSE | 566 | -------------- snd ACK | ------- | 567 V x V snd FIN V 568 +---------+ +---------+ +---------+ 569 |FINWAIT-2| | CLOSING | | LAST-ACK| 570 +---------+ +---------+ +---------+ 571 | rcv ACK of FIN | rcv ACK of FIN | 572 | rcv FIN -------------- | Timeout=2MSL -------------- | 573 | ------- x V ------------ x V 574 \ snd ACK +---------+delete TCB +---------+ 575 ------------------------>|TIME WAIT|------------------>| CLOSED | 576 +---------+ +---------+ 578 note 1: The transition from SYN-RCVD to LISTEN on receiving a RST is 579 conditional on having reached SYN-RCVD after a passive open. 581 note 2: An unshown transition exists from FIN-WAIT-1 to TIME-WAIT if 582 a FIN is received and the local FIN is also acknowledged. 584 TCP Connection State Diagram 586 Figure 4 588 3.3. Sequence Numbers 590 A fundamental notion in the design is that every octet of data sent 591 over a TCP connection has a sequence number. Since every octet is 592 sequenced, each of them can be acknowledged. The acknowledgment 593 mechanism employed is cumulative so that an acknowledgment of 594 sequence number X indicates that all octets up to but not including X 595 have been received. This mechanism allows for straight-forward 596 duplicate detection in the presence of retransmission. Numbering of 597 octets within a segment is that the first data octet immediately 598 following the header is the lowest numbered, and the following octets 599 are numbered consecutively. 601 It is essential to remember that the actual sequence number space is 602 finite, though very large. This space ranges from 0 to 2**32 - 1. 603 Since the space is finite, all arithmetic dealing with sequence 604 numbers must be performed modulo 2**32. This unsigned arithmetic 605 preserves the relationship of sequence numbers as they cycle from 606 2**32 - 1 to 0 again. There are some subtleties to computer modulo 607 arithmetic, so great care should be taken in programming the 608 comparison of such values. The symbol "=<" means "less than or 609 equal" (modulo 2**32). 611 The typical kinds of sequence number comparisons which the TCP must 612 perform include: 614 (a) Determining that an acknowledgment refers to some sequence 615 number sent but not yet acknowledged. 617 (b) Determining that all sequence numbers occupied by a segment 618 have been acknowledged (e.g., to remove the segment from a 619 retransmission queue). 621 (c) Determining that an incoming segment contains sequence numbers 622 which are expected (i.e., that the segment "overlaps" the receive 623 window). 625 In response to sending data the TCP will receive acknowledgments. 626 The following comparisons are needed to process the acknowledgments. 628 SND.UNA = oldest unacknowledged sequence number 630 SND.NXT = next sequence number to be sent 632 SEG.ACK = acknowledgment from the receiving TCP (next sequence 633 number expected by the receiving TCP) 635 SEG.SEQ = first sequence number of a segment 637 SEG.LEN = the number of octets occupied by the data in the segment 638 (counting SYN and FIN) 640 SEG.SEQ+SEG.LEN-1 = last sequence number of a segment 642 A new acknowledgment (called an "acceptable ack"), is one for which 643 the inequality below holds: 645 SND.UNA < SEG.ACK =< SND.NXT 647 A segment on the retransmission queue is fully acknowledged if the 648 sum of its sequence number and length is less or equal than the 649 acknowledgment value in the incoming segment. 651 When data is received the following comparisons are needed: 653 RCV.NXT = next sequence number expected on an incoming segments, 654 and is the left or lower edge of the receive window 656 RCV.NXT+RCV.WND-1 = last sequence number expected on an incoming 657 segment, and is the right or upper edge of the receive window 659 SEG.SEQ = first sequence number occupied by the incoming segment 661 SEG.SEQ+SEG.LEN-1 = last sequence number occupied by the incoming 662 segment 664 A segment is judged to occupy a portion of valid receive sequence 665 space if 667 RCV.NXT =< SEG.SEQ < RCV.NXT+RCV.WND 669 or 671 RCV.NXT =< SEG.SEQ+SEG.LEN-1 < RCV.NXT+RCV.WND 673 The first part of this test checks to see if the beginning of the 674 segment falls in the window, the second part of the test checks to 675 see if the end of the segment falls in the window; if the segment 676 passes either part of the test it contains data in the window. 678 Actually, it is a little more complicated than this. Due to zero 679 windows and zero length segments, we have four cases for the 680 acceptability of an incoming segment: 682 Segment Receive Test 683 Length Window 684 ------- ------- ------------------------------------------- 686 0 0 SEG.SEQ = RCV.NXT 688 0 >0 RCV.NXT =< SEG.SEQ < RCV.NXT+RCV.WND 690 >0 0 not acceptable 692 >0 >0 RCV.NXT =< SEG.SEQ < RCV.NXT+RCV.WND 693 or RCV.NXT =< SEG.SEQ+SEG.LEN-1 < RCV.NXT+RCV.WND 695 Note that when the receive window is zero no segments should be 696 acceptable except ACK segments. Thus, it is be possible for a TCP to 697 maintain a zero receive window while transmitting data and receiving 698 ACKs. However, even when the receive window is zero, a TCP must 699 process the RST and URG fields of all incoming segments. 701 We have taken advantage of the numbering scheme to protect certain 702 control information as well. This is achieved by implicitly 703 including some control flags in the sequence space so they can be 704 retransmitted and acknowledged without confusion (i.e., one and only 705 one copy of the control will be acted upon). Control information is 706 not physically carried in the segment data space. Consequently, we 707 must adopt rules for implicitly assigning sequence numbers to 708 control. The SYN and FIN are the only controls requiring this 709 protection, and these controls are used only at connection opening 710 and closing. For sequence number purposes, the SYN is considered to 711 occur before the first actual data octet of the segment in which it 712 occurs, while the FIN is considered to occur after the last actual 713 data octet in a segment in which it occurs. The segment length 714 (SEG.LEN) includes both data and sequence space occupying controls. 715 When a SYN is present then SEG.SEQ is the sequence number of the SYN. 717 Initial Sequence Number Selection 719 The protocol places no restriction on a particular connection being 720 used over and over again. A connection is defined by a pair of 721 sockets. New instances of a connection will be referred to as 722 incarnations of the connection. The problem that arises from this is 723 -- "how does the TCP identify duplicate segments from previous 724 incarnations of the connection?" This problem becomes apparent if 725 the connection is being opened and closed in quick succession, or if 726 the connection breaks with loss of memory and is then reestablished. 728 To avoid confusion we must prevent segments from one incarnation of a 729 connection from being used while the same sequence numbers may still 730 be present in the network from an earlier incarnation. We want to 731 assure this, even if a TCP crashes and loses all knowledge of the 732 sequence numbers it has been using. When new connections are 733 created, an initial sequence number (ISN) generator is employed which 734 selects a new 32 bit ISN. There are security issues that result if 735 an off-path attacker is able to predict or guess ISN values. 737 The recommended ISN generator is based on the combination of a 738 (possibly fictitious) 32 bit clock whose low order bit is incremented 739 roughly every 4 microseconds, and a pseudorandom hash function (PRF). 740 The clock component is intended to insure that with a Maximum Segment 741 Lifetime (MSL), generated ISNs will be unique, since it cycles 742 approximately every 4.55 hours, which is much longer than the MSL. 744 TCP SHOULD generate its Initial Sequence Numbers with the expression: 746 ISN = M + F(localip, localport, remoteip, remoteport, secretkey) 748 where M is the 4 microsecond timer, and F() is a pseudorandom 749 function (PRF) of the connection's identifying parameters ("localip, 750 localport, remoteip, remoteport") and a secret key ("secretkey"). 751 F() MUST NOT be computable from the outside, or an attacker could 752 still guess at sequence numbers from the ISN used for some other 753 connection. The PRF could be implemented as a cryptographic has of 754 the concatenation of the TCP connection parameters and some secret 755 data. For discussion of the selection of a specific hash algorithm 756 and management of the secret key data, please see Section 3 of [8]. 758 For each connection there is a send sequence number and a receive 759 sequence number. The initial send sequence number (ISS) is chosen by 760 the data sending TCP, and the initial receive sequence number (IRS) 761 is learned during the connection establishing procedure. 763 For a connection to be established or initialized, the two TCPs must 764 synchronize on each other's initial sequence numbers. This is done 765 in an exchange of connection establishing segments carrying a control 766 bit called "SYN" (for synchronize) and the initial sequence numbers. 767 As a shorthand, segments carrying the SYN bit are also called "SYNs". 768 Hence, the solution requires a suitable mechanism for picking an 769 initial sequence number and a slightly involved handshake to exchange 770 the ISN's. 772 The synchronization requires each side to send it's own initial 773 sequence number and to receive a confirmation of it in acknowledgment 774 from the other side. Each side must also receive the other side's 775 initial sequence number and send a confirming acknowledgment. 777 1) A --> B SYN my sequence number is X 778 2) A <-- B ACK your sequence number is X 779 3) A <-- B SYN my sequence number is Y 780 4) A --> B ACK your sequence number is Y 782 Because steps 2 and 3 can be combined in a single message this is 783 called the three way (or three message) handshake. 785 A three way handshake is necessary because sequence numbers are not 786 tied to a global clock in the network, and TCPs may have different 787 mechanisms for picking the ISN's. The receiver of the first SYN has 788 no way of knowing whether the segment was an old delayed one or not, 789 unless it remembers the last sequence number used on the connection 790 (which is not always possible), and so it must ask the sender to 791 verify this SYN. The three way handshake and the advantages of a 792 clock-driven scheme are discussed in [3]. 794 Knowing When to Keep Quiet 796 To be sure that a TCP does not create a segment that carries a 797 sequence number which may be duplicated by an old segment remaining 798 in the network, the TCP must keep quiet for a maximum segment 799 lifetime (MSL) before assigning any sequence numbers upon starting up 800 or recovering from a crash in which memory of sequence numbers in use 801 was lost. For this specification the MSL is taken to be 2 minutes. 802 This is an engineering choice, and may be changed if experience 803 indicates it is desirable to do so. Note that if a TCP is 804 reinitialized in some sense, yet retains its memory of sequence 805 numbers in use, then it need not wait at all; it must only be sure to 806 use sequence numbers larger than those recently used. 808 The TCP Quiet Time Concept 810 This specification provides that hosts which "crash" without 811 retaining any knowledge of the last sequence numbers transmitted on 812 each active (i.e., not closed) connection shall delay emitting any 813 TCP segments for at least the agreed Maximum Segment Lifetime (MSL) 814 in the internet system of which the host is a part. In the 815 paragraphs below, an explanation for this specification is given. 816 TCP implementors may violate the "quiet time" restriction, but only 817 at the risk of causing some old data to be accepted as new or new 818 data rejected as old duplicated by some receivers in the internet 819 system. 821 TCPs consume sequence number space each time a segment is formed and 822 entered into the network output queue at a source host. The 823 duplicate detection and sequencing algorithm in the TCP protocol 824 relies on the unique binding of segment data to sequence space to the 825 extent that sequence numbers will not cycle through all 2**32 values 826 before the segment data bound to those sequence numbers has been 827 delivered and acknowledged by the receiver and all duplicate copies 828 of the segments have "drained" from the internet. Without such an 829 assumption, two distinct TCP segments could conceivably be assigned 830 the same or overlapping sequence numbers, causing confusion at the 831 receiver as to which data is new and which is old. Remember that 832 each segment is bound to as many consecutive sequence numbers as 833 there are octets of data and SYN or FIN flags in the segment. 835 Under normal conditions, TCPs keep track of the next sequence number 836 to emit and the oldest awaiting acknowledgment so as to avoid 837 mistakenly using a sequence number over before its first use has been 838 acknowledged. This alone does not guarantee that old duplicate data 839 is drained from the net, so the sequence space has been made very 840 large to reduce the probability that a wandering duplicate will cause 841 trouble upon arrival. At 2 megabits/sec. it takes 4.5 hours to use 842 up 2**32 octets of sequence space. Since the maximum segment 843 lifetime in the net is not likely to exceed a few tens of seconds, 844 this is deemed ample protection for foreseeable nets, even if data 845 rates escalate to l0's of megabits/sec. At 100 megabits/sec, the 846 cycle time is 5.4 minutes which may be a little short, but still 847 within reason. 849 The basic duplicate detection and sequencing algorithm in TCP can be 850 defeated, however, if a source TCP does not have any memory of the 851 sequence numbers it last used on a given connection. For example, if 852 the TCP were to start all connections with sequence number 0, then 853 upon crashing and restarting, a TCP might re-form an earlier 854 connection (possibly after half-open connection resolution) and emit 855 packets with sequence numbers identical to or overlapping with 856 packets still in the network which were emitted on an earlier 857 incarnation of the same connection. In the absence of knowledge 858 about the sequence numbers used on a particular connection, the TCP 859 specification recommends that the source delay for MSL seconds before 860 emitting segments on the connection, to allow time for segments from 861 the earlier connection incarnation to drain from the system. 863 Even hosts which can remember the time of day and used it to select 864 initial sequence number values are not immune from this problem 865 (i.e., even if time of day is used to select an initial sequence 866 number for each new connection incarnation). 868 Suppose, for example, that a connection is opened starting with 869 sequence number S. Suppose that this connection is not used much and 870 that eventually the initial sequence number function (ISN(t)) takes 871 on a value equal to the sequence number, say S1, of the last segment 872 sent by this TCP on a particular connection. Now suppose, at this 873 instant, the host crashes, recovers, and establishes a new 874 incarnation of the connection. The initial sequence number chosen is 875 S1 = ISN(t) -- last used sequence number on old incarnation of 876 connection! If the recovery occurs quickly enough, any old 877 duplicates in the net bearing sequence numbers in the neighborhood of 878 S1 may arrive and be treated as new packets by the receiver of the 879 new incarnation of the connection. 881 The problem is that the recovering host may not know for how long it 882 crashed nor does it know whether there are still old duplicates in 883 the system from earlier connection incarnations. 885 One way to deal with this problem is to deliberately delay emitting 886 segments for one MSL after recovery from a crash- this is the "quiet 887 time" specification. Hosts which prefer to avoid waiting are willing 888 to risk possible confusion of old and new packets at a given 889 destination may choose not to wait for the "quite time". 890 Implementors may provide TCP users with the ability to select on a 891 connection by connection basis whether to wait after a crash, or may 892 informally implement the "quite time" for all connections. 893 Obviously, even where a user selects to "wait," this is not necessary 894 after the host has been "up" for at least MSL seconds. 896 To summarize: every segment emitted occupies one or more sequence 897 numbers in the sequence space, the numbers occupied by a segment are 898 "busy" or "in use" until MSL seconds have passed, upon crashing a 899 block of space-time is occupied by the octets and SYN or FIN flags of 900 the last emitted segment, if a new connection is started too soon and 901 uses any of the sequence numbers in the space-time footprint of the 902 last segment of the previous connection incarnation, there is a 903 potential sequence number overlap area which could cause confusion at 904 the receiver. 906 3.4. Establishing a connection 908 The "three-way handshake" is the procedure used to establish a 909 connection. This procedure normally is initiated by one TCP and 910 responded to by another TCP. The procedure also works if two TCP 911 simultaneously initiate the procedure. When simultaneous attempt 912 occurs, each TCP receives a "SYN" segment which carries no 913 acknowledgment after it has sent a "SYN". Of course, the arrival of 914 an old duplicate "SYN" segment can potentially make it appear, to the 915 recipient, that a simultaneous connection initiation is in progress. 916 Proper use of "reset" segments can disambiguate these cases. 918 Several examples of connection initiation follow. Although these 919 examples do not show connection synchronization using data-carrying 920 segments, this is perfectly legitimate, so long as the receiving TCP 921 doesn't deliver the data to the user until it is clear the data is 922 valid (i.e., the data must be buffered at the receiver until the 923 connection reaches the ESTABLISHED state). The three-way handshake 924 reduces the possibility of false connections. It is the 925 implementation of a trade-off between memory and messages to provide 926 information for this checking. 928 The simplest three-way handshake is shown in Figure 5 below. The 929 figures should be interpreted in the following way. Each line is 930 numbered for reference purposes. Right arrows (-->) indicate 931 departure of a TCP segment from TCP A to TCP B, or arrival of a 932 segment at B from A. Left arrows (<--), indicate the reverse. 933 Ellipsis (...) indicates a segment which is still in the network 934 (delayed). An "XXX" indicates a segment which is lost or rejected. 935 Comments appear in parentheses. TCP states represent the state AFTER 936 the departure or arrival of the segment (whose contents are shown in 937 the center of each line). Segment contents are shown in abbreviated 938 form, with sequence number, control flags, and ACK field. Other 939 fields such as window, addresses, lengths, and text have been left 940 out in the interest of clarity. 942 TCP A TCP B 944 1. CLOSED LISTEN 946 2. SYN-SENT --> --> SYN-RECEIVED 948 3. ESTABLISHED <-- <-- SYN-RECEIVED 950 4. ESTABLISHED --> --> ESTABLISHED 952 5. ESTABLISHED --> --> ESTABLISHED 954 Basic 3-Way Handshake for Connection Synchronization 956 Figure 5 958 In line 2 of Figure 5, TCP A begins by sending a SYN segment 959 indicating that it will use sequence numbers starting with sequence 960 number 100. In line 3, TCP B sends a SYN and acknowledges the SYN it 961 received from TCP A. Note that the acknowledgment field indicates 962 TCP B is now expecting to hear sequence 101, acknowledging the SYN 963 which occupied sequence 100. 965 At line 4, TCP A responds with an empty segment containing an ACK for 966 TCP B's SYN; and in line 5, TCP A sends some data. Note that the 967 sequence number of the segment in line 5 is the same as in line 4 968 because the ACK does not occupy sequence number space (if it did, we 969 would wind up ACKing ACK's!). 971 Simultaneous initiation is only slightly more complex, as is shown in 972 Figure 6. Each TCP cycles from CLOSED to SYN-SENT to SYN-RECEIVED to 973 ESTABLISHED. 975 TCP A TCP B 977 1. CLOSED CLOSED 979 2. SYN-SENT --> ... 981 3. SYN-RECEIVED <-- <-- SYN-SENT 983 4. ... --> SYN-RECEIVED 985 5. SYN-RECEIVED --> ... 987 6. ESTABLISHED <-- <-- SYN-RECEIVED 989 7. ... --> ESTABLISHED 991 Simultaneous Connection Synchronization 993 Figure 6 995 The principle reason for the three-way handshake is to prevent old 996 duplicate connection initiations from causing confusion. To deal 997 with this, a special control message, reset, has been devised. If 998 the receiving TCP is in a non-synchronized state (i.e., SYN-SENT, 999 SYN-RECEIVED), it returns to LISTEN on receiving an acceptable reset. 1000 If the TCP is in one of the synchronized states (ESTABLISHED, FIN- 1001 WAIT-1, FIN-WAIT-2, CLOSE-WAIT, CLOSING, LAST-ACK, TIME-WAIT), it 1002 aborts the connection and informs its user. We discuss this latter 1003 case under "half-open" connections below. 1005 TCP A TCP B 1007 1. CLOSED LISTEN 1009 2. SYN-SENT --> ... 1011 3. (duplicate) ... --> SYN-RECEIVED 1013 4. SYN-SENT <-- <-- SYN-RECEIVED 1015 5. SYN-SENT --> --> LISTEN 1017 6. ... --> SYN-RECEIVED 1019 7. SYN-SENT <-- <-- SYN-RECEIVED 1021 8. ESTABLISHED --> --> ESTABLISHED 1023 Recovery from Old Duplicate SYN 1025 Figure 7 1027 As a simple example of recovery from old duplicates, consider 1028 Figure 7. At line 3, an old duplicate SYN arrives at TCP B. TCP B 1029 cannot tell that this is an old duplicate, so it responds normally 1030 (line 4). TCP A detects that the ACK field is incorrect and returns 1031 a RST (reset) with its SEQ field selected to make the segment 1032 believable. TCP B, on receiving the RST, returns to the LISTEN 1033 state. When the original SYN (pun intended) finally arrives at line 1034 6, the synchronization proceeds normally. If the SYN at line 6 had 1035 arrived before the RST, a more complex exchange might have occurred 1036 with RST's sent in both directions. 1038 Half-Open Connections and Other Anomalies 1040 An established connection is said to be "half-open" if one of the 1041 TCPs has closed or aborted the connection at its end without the 1042 knowledge of the other, or if the two ends of the connection have 1043 become desynchronized owing to a crash that resulted in loss of 1044 memory. Such connections will automatically become reset if an 1045 attempt is made to send data in either direction. However, half-open 1046 connections are expected to be unusual, and the recovery procedure is 1047 mildly involved. 1049 If at site A the connection no longer exists, then an attempt by the 1050 user at site B to send any data on it will result in the site B TCP 1051 receiving a reset control message. Such a message indicates to the 1052 site B TCP that something is wrong, and it is expected to abort the 1053 connection. 1055 Assume that two user processes A and B are communicating with one 1056 another when a crash occurs causing loss of memory to A's TCP. 1057 Depending on the operating system supporting A's TCP, it is likely 1058 that some error recovery mechanism exists. When the TCP is up again, 1059 A is likely to start again from the beginning or from a recovery 1060 point. As a result, A will probably try to OPEN the connection again 1061 or try to SEND on the connection it believes open. In the latter 1062 case, it receives the error message "connection not open" from the 1063 local (A's) TCP. In an attempt to establish the connection, A's TCP 1064 will send a segment containing SYN. This scenario leads to the 1065 example shown in Figure 8. After TCP A crashes, the user attempts to 1066 re-open the connection. TCP B, in the meantime, thinks the 1067 connection is open. 1069 TCP A TCP B 1071 1. (CRASH) (send 300,receive 100) 1073 2. CLOSED ESTABLISHED 1075 3. SYN-SENT --> --> (??) 1077 4. (!!) <-- <-- ESTABLISHED 1079 5. SYN-SENT --> --> (Abort!!) 1081 6. SYN-SENT CLOSED 1083 7. SYN-SENT --> --> 1085 Half-Open Connection Discovery 1087 Figure 8 1089 When the SYN arrives at line 3, TCP B, being in a synchronized state, 1090 and the incoming segment outside the window, responds with an 1091 acknowledgment indicating what sequence it next expects to hear (ACK 1092 100). TCP A sees that this segment does not acknowledge anything it 1093 sent and, being unsynchronized, sends a reset (RST) because it has 1094 detected a half-open connection. TCP B aborts at line 5. TCP A will 1095 continue to try to establish the connection; the problem is now 1096 reduced to the basic 3-way handshake of Figure 5. 1098 An interesting alternative case occurs when TCP A crashes and TCP B 1099 tries to send data on what it thinks is a synchronized connection. 1101 This is illustrated in Figure 9. In this case, the data arriving at 1102 TCP A from TCP B (line 2) is unacceptable because no such connection 1103 exists, so TCP A sends a RST. The RST is acceptable so TCP B 1104 processes it and aborts the connection. 1106 TCP A TCP B 1108 1. (CRASH) (send 300,receive 100) 1110 2. (??) <-- <-- ESTABLISHED 1112 3. --> --> (ABORT!!) 1114 Active Side Causes Half-Open Connection Discovery 1116 Figure 9 1118 In Figure 10, we find the two TCPs A and B with passive connections 1119 waiting for SYN. An old duplicate arriving at TCP B (line 2) stirs B 1120 into action. A SYN-ACK is returned (line 3) and causes TCP A to 1121 generate a RST (the ACK in line 3 is not acceptable). TCP B accepts 1122 the reset and returns to its passive LISTEN state. 1124 TCP A TCP B 1126 1. LISTEN LISTEN 1128 2. ... --> SYN-RECEIVED 1130 3. (??) <-- <-- SYN-RECEIVED 1132 4. --> --> (return to LISTEN!) 1134 5. LISTEN LISTEN 1136 Old Duplicate SYN Initiates a Reset on two Passive Sockets 1138 Figure 10 1140 A variety of other cases are possible, all of which are accounted for 1141 by the following rules for RST generation and processing. 1143 Reset Generation 1144 As a general rule, reset (RST) must be sent whenever a segment 1145 arrives which apparently is not intended for the current connection. 1146 A reset must not be sent if it is not clear that this is the case. 1148 There are three groups of states: 1150 1. If the connection does not exist (CLOSED) then a reset is sent 1151 in response to any incoming segment except another reset. In 1152 particular, SYNs addressed to a non-existent connection are 1153 rejected by this means. 1155 If the incoming segment has the ACK bit set, the reset takes its 1156 sequence number from the ACK field of the segment, otherwise the 1157 reset has sequence number zero and the ACK field is set to the sum 1158 of the sequence number and segment length of the incoming segment. 1159 The connection remains in the CLOSED state. 1161 2. If the connection is in any non-synchronized state (LISTEN, 1162 SYN-SENT, SYN-RECEIVED), and the incoming segment acknowledges 1163 something not yet sent (the segment carries an unacceptable ACK), 1164 or if an incoming segment has a security level or compartment 1165 which does not exactly match the level and compartment requested 1166 for the connection, a reset is sent. 1168 If our SYN has not been acknowledged and the precedence level of 1169 the incoming segment is higher than the precedence level requested 1170 then either raise the local precedence level (if allowed by the 1171 user and the system) or send a reset; or if the precedence level 1172 of the incoming segment is lower than the precedence level 1173 requested then continue as if the precedence matched exactly (if 1174 the remote TCP cannot raise the precedence level to match ours 1175 this will be detected in the next segment it sends, and the 1176 connection will be terminated then). If our SYN has been 1177 acknowledged (perhaps in this incoming segment) the precedence 1178 level of the incoming segment must match the local precedence 1179 level exactly, if it does not a reset must be sent. 1181 If the incoming segment has an ACK field, the reset takes its 1182 sequence number from the ACK field of the segment, otherwise the 1183 reset has sequence number zero and the ACK field is set to the sum 1184 of the sequence number and segment length of the incoming segment. 1185 The connection remains in the same state. 1187 3. If the connection is in a synchronized state (ESTABLISHED, 1188 FIN-WAIT-1, FIN-WAIT-2, CLOSE-WAIT, CLOSING, LAST-ACK, TIME-WAIT), 1189 any unacceptable segment (out of window sequence number or 1190 unacceptable acknowledgment number) must elicit only an empty 1191 acknowledgment segment containing the current send-sequence number 1192 and an acknowledgment indicating the next sequence number expected 1193 to be received, and the connection remains in the same state. 1195 If an incoming segment has a security level, or compartment, or 1196 precedence which does not exactly match the level, and 1197 compartment, and precedence requested for the connection,a reset 1198 is sent and the connection goes to the CLOSED state. The reset 1199 takes its sequence number from the ACK field of the incoming 1200 segment. 1202 Reset Processing 1204 In all states except SYN-SENT, all reset (RST) segments are validated 1205 by checking their SEQ-fields. A reset is valid if its sequence 1206 number is in the window. In the SYN-SENT state (a RST received in 1207 response to an initial SYN), the RST is acceptable if the ACK field 1208 acknowledges the SYN. 1210 The receiver of a RST first validates it, then changes state. If the 1211 receiver was in the LISTEN state, it ignores it. If the receiver was 1212 in SYN-RECEIVED state and had previously been in the LISTEN state, 1213 then the receiver returns to the LISTEN state, otherwise the receiver 1214 aborts the connection and goes to the CLOSED state. If the receiver 1215 was in any other state, it aborts the connection and advises the user 1216 and goes to the CLOSED state. 1218 3.5. Closing a Connection 1220 CLOSE is an operation meaning "I have no more data to send." The 1221 notion of closing a full-duplex connection is subject to ambiguous 1222 interpretation, of course, since it may not be obvious how to treat 1223 the receiving side of the connection. We have chosen to treat CLOSE 1224 in a simplex fashion. The user who CLOSEs may continue to RECEIVE 1225 until he is told that the other side has CLOSED also. Thus, a 1226 program could initiate several SENDs followed by a CLOSE, and then 1227 continue to RECEIVE until signaled that a RECEIVE failed because the 1228 other side has CLOSED. We assume that the TCP will signal a user, 1229 even if no RECEIVEs are outstanding, that the other side has closed, 1230 so the user can terminate his side gracefully. A TCP will reliably 1231 deliver all buffers SENT before the connection was CLOSED so a user 1232 who expects no data in return need only wait to hear the connection 1233 was CLOSED successfully to know that all his data was received at the 1234 destination TCP. Users must keep reading connections they close for 1235 sending until the TCP says no more data. 1237 There are essentially three cases: 1239 1) The user initiates by telling the TCP to CLOSE the connection 1240 2) The remote TCP initiates by sending a FIN control signal 1242 3) Both users CLOSE simultaneously 1244 Case 1: Local user initiates the close 1246 In this case, a FIN segment can be constructed and placed on the 1247 outgoing segment queue. No further SENDs from the user will be 1248 accepted by the TCP, and it enters the FIN-WAIT-1 state. RECEIVEs 1249 are allowed in this state. All segments preceding and including 1250 FIN will be retransmitted until acknowledged. When the other TCP 1251 has both acknowledged the FIN and sent a FIN of its own, the first 1252 TCP can ACK this FIN. Note that a TCP receiving a FIN will ACK 1253 but not send its own FIN until its user has CLOSED the connection 1254 also. 1256 Case 2: TCP receives a FIN from the network 1258 If an unsolicited FIN arrives from the network, the receiving TCP 1259 can ACK it and tell the user that the connection is closing. The 1260 user will respond with a CLOSE, upon which the TCP can send a FIN 1261 to the other TCP after sending any remaining data. The TCP then 1262 waits until its own FIN is acknowledged whereupon it deletes the 1263 connection. If an ACK is not forthcoming, after the user timeout 1264 the connection is aborted and the user is told. 1266 Case 3: both users close simultaneously 1268 A simultaneous CLOSE by users at both ends of a connection causes 1269 FIN segments to be exchanged. When all segments preceding the 1270 FINs have been processed and acknowledged, each TCP can ACK the 1271 FIN it has received. Both will, upon receiving these ACKs, delete 1272 the connection. 1274 TCP A TCP B 1276 1. ESTABLISHED ESTABLISHED 1278 2. (Close) 1279 FIN-WAIT-1 --> --> CLOSE-WAIT 1281 3. FIN-WAIT-2 <-- <-- CLOSE-WAIT 1283 4. (Close) 1284 TIME-WAIT <-- <-- LAST-ACK 1286 5. TIME-WAIT --> --> CLOSED 1288 6. (2 MSL) 1289 CLOSED 1291 Normal Close Sequence 1293 Figure 11 1295 TCP A TCP B 1297 1. ESTABLISHED ESTABLISHED 1299 2. (Close) (Close) 1300 FIN-WAIT-1 --> ... FIN-WAIT-1 1301 <-- <-- 1302 ... --> 1304 3. CLOSING --> ... CLOSING 1305 <-- <-- 1306 ... --> 1308 4. TIME-WAIT TIME-WAIT 1309 (2 MSL) (2 MSL) 1310 CLOSED CLOSED 1312 Simultaneous Close Sequence 1314 Figure 12 1316 3.6. Precedence and Security 1318 The intent is that connection be allowed only between ports operating 1319 with exactly the same security and compartment values and at the 1320 higher of the precedence level requested by the two ports. 1322 The precedence and security parameters used in TCP are exactly those 1323 defined in the Internet Protocol (IP) [2]. Throughout this TCP 1324 specification the term "security/compartment" is intended to indicate 1325 the security parameters used in IP including security, compartment, 1326 user group, and handling restriction. 1328 A connection attempt with mismatched security/compartment values or a 1329 lower precedence value must be rejected by sending a reset. 1330 Rejecting a connection due to too low a precedence only occurs after 1331 an acknowledgment of the SYN has been received. 1333 Note that TCP modules which operate only at the default value of 1334 precedence will still have to check the precedence of incoming 1335 segments and possibly raise the precedence level they use on the 1336 connection. 1338 The security parameters may be used even in a non-secure environment 1339 (the values would indicate unclassified data), thus hosts in non- 1340 secure environments must be prepared to receive the security 1341 parameters, though they need not send them. 1343 3.7. Segmentation 1345 The term "segmentation" refers to the activity TCP performs when 1346 ingesting a stream of bytes from a sending application and 1347 packetizing that stream of bytes into TCP segments. 1349 For efficiency and performance reasons, it is desirable to send large 1350 segments that contain as many bytes of payload data as possible. 1351 However, packets that are too long will either be fragmented or 1352 dropped within the network. Some firewalls or middleboxes may drop 1353 fragmented packets. In either case, when packets are dropped, the 1354 connection can fail; hence, it is best for a TCP implementation to 1355 avoid generating fragments. 1357 To enable a TCP sender to maximize the size of segments that it 1358 sends, without generating fragments, TCP includes the Maximum Segment 1359 Size option to convey endpoint information, and TCP implementations 1360 also support Path MTU Discovery to discover the limits and 1361 capabilites of intermediate networks. 1363 When TCP is used in a situation where either the IP or TCP headers 1364 are not minimum, the sender must reduce the amount of TCP data in any 1365 given packet by the number of octets used by the IP and TCP options. 1366 The rationale for this is explained in RFC 6691. 1368 3.7.1. Maximum Segment Size Option 1370 TCP MUST implement both sending and receiving the Maximum Segment 1371 Size option. 1373 TCP SHOULD send an MSS (Maximum Segment Size) option in every SYN 1374 segment when its receive MSS differs from the default 536, and MAY 1375 send it always. 1377 If an MSS option is not received at connection setup, TCP MUST assume 1378 a default send MSS of 536 (576-40). 1380 The maximum size of a segment that TCP really sends, the "effective 1381 send MSS," MUST be the smaller of the send MSS (which reflects the 1382 available reassembly buffer size at the remote host) and the largest 1383 size permitted by the IP layer: 1385 Eff.snd.MSS = 1387 min(SendMSS+20, MMS_S) - TCPhdrsize - IPoptionsize 1389 where: 1391 o SendMSS is the MSS value received from the remote host, or the 1392 default 536 if no MSS option is received. 1394 o MMS_S is the maximum size for a transport-layer message that TCP 1395 may send. 1397 o TCPhdrsize is the size of the fixed TCP header; this is normally 1398 20, but may be larger if TCP options are to be sent. 1400 o IPoptionsize is the size of any IP options that TCP will pass to 1401 the IP layer with the current message. 1403 The MSS value to be sent in an MSS option should be equal to the 1404 effective MTU minus the fixed IP and TCP headers. By ignoring both 1405 IP and TCP options when calculating the value for the MSS option, if 1406 there are any IP or TCP options to be sent in a packet, then the 1407 sender must decrease the size of the TCP data accordingly. RFC 6691 1408 discusses this in greater detail. 1410 The MSS value to be sent in an MSS option must be less than or equal 1411 to: 1413 MMS_R - 20 1415 where MMS_R is the maximum size for a transport-layer message that 1416 can be received (and reassembled). TCP obtains MMS_R and MMS_S from 1417 the IP layer; see the generic call GET_MAXSIZES in Section 3.4 of RFC 1418 1122. 1420 3.7.2. Path MTU Discovery 1422 The TCP MSS option specifies an upper bound for the size of packets 1423 that can be received. Hence, setting the value in the MSS option too 1424 small can impact the ability for Path MTU Discovery to find a larger 1425 path MTU. For more information on Path MTU Discovery, see: 1427 o "Path MTU Discovery" [RFC1191] 1429 o "TCP Problems with Path MTU Discovery" [RFC2923] 1431 o "Packetization Layer Path MTU Discovery" [RFC4821] 1433 3.7.3. Interfaces with Variable MSS Values 1435 The effective MTU can sometimes vary, as when used with variable 1436 compression, e.g., RObust Header Compression (ROHC) [RFC5795]. It is 1437 tempting for TCP to want to advertise the largest possible MSS, to 1438 support the most efficient use of compressed payloads. 1439 Unfortunately, some compression schemes occasionally need to transmit 1440 full headers (and thus smaller payloads) to resynchronize state at 1441 their endpoint compressors/decompressors. If the largest MTU is used 1442 to calculate the value to advertise in the MSS option, TCP 1443 retransmission may interfere with compressor resynchronization. 1445 As a result, when the effective MTU of an interface varies, TCP 1446 SHOULD use the smallest effective MTU of the interface to calculate 1447 the value to advertise in the MSS option. 1449 3.7.4. IPv6 Jumbograms 1451 In order to support TCP over IPv6 jumbograms, implementations need to 1452 be able to send TCP segments larger than 64K. RFC 2675 [RFC2675] 1453 defines that a value of 65,535 is to be treated as infinity, and Path 1454 MTU Discovery [RFC1981] is used to determine the actual MSS. 1456 3.8. Data Communication 1458 Once the connection is established data is communicated by the 1459 exchange of segments. Because segments may be lost due to errors 1460 (checksum test failure), or network congestion, TCP uses 1461 retransmission (after a timeout) to ensure delivery of every segment. 1462 Duplicate segments may arrive due to network or TCP retransmission. 1464 As discussed in the section on sequence numbers the TCP performs 1465 certain tests on the sequence and acknowledgment numbers in the 1466 segments to verify their acceptability. 1468 The sender of data keeps track of the next sequence number to use in 1469 the variable SND.NXT. The receiver of data keeps track of the next 1470 sequence number to expect in the variable RCV.NXT. The sender of 1471 data keeps track of the oldest unacknowledged sequence number in the 1472 variable SND.UNA. If the data flow is momentarily idle and all data 1473 sent has been acknowledged then the three variables will be equal. 1475 When the sender creates a segment and transmits it the sender 1476 advances SND.NXT. When the receiver accepts a segment it advances 1477 RCV.NXT and sends an acknowledgment. When the data sender receives 1478 an acknowledgment it advances SND.UNA. The extent to which the 1479 values of these variables differ is a measure of the delay in the 1480 communication. The amount by which the variables are advanced is the 1481 length of the data and SYN or FIN flags in the segment. Note that 1482 once in the ESTABLISHED state all segments must carry current 1483 acknowledgment information. 1485 The CLOSE user call implies a push function, as does the FIN control 1486 flag in an incoming segment. 1488 Retransmission Timeout 1490 NOTE: TODO this needs to be updated in light of 1122 4.2.2.15 and 1491 errata 573; this will be done as part of RFC 1122 incorporation into 1492 this document. 1493 Because of the variability of the networks that compose an 1494 internetwork system and the wide range of uses of TCP connections the 1495 retransmission timeout must be dynamically determined. One procedure 1496 for determining a retransmission timeout is given here as an 1497 illustration. 1499 An Example Retransmission Timeout Procedure 1501 Measure the elapsed time between sending a data octet with a 1502 particular sequence number and receiving an acknowledgment that 1503 covers that sequence number (segments sent do not have to match 1504 segments received). This measured elapsed time is the Round Trip 1505 Time (RTT). Next compute a Smoothed Round Trip Time (SRTT) as: 1507 SRTT = ( ALPHA * SRTT ) + ((1-ALPHA) * RTT) 1509 and based on this, compute the retransmission timeout (RTO) as: 1511 RTO = min[UBOUND,max[LBOUND,(BETA*SRTT)]] 1513 where UBOUND is an upper bound on the timeout (e.g., 1 minute), 1514 LBOUND is a lower bound on the timeout (e.g., 1 second), ALPHA is 1515 a smoothing factor (e.g., .8 to .9), and BETA is a delay variance 1516 factor (e.g., 1.3 to 2.0). 1518 The Communication of Urgent Information 1520 As a result of implementation differences and middlebox interactions, 1521 new applications SHOULD NOT employ the TCP urgent mechanism. 1522 However, TCP implementations MUST still include support for the 1523 urgent mechanism. Details can be found in RFC 6093 [7]. 1525 The objective of the TCP urgent mechanism is to allow the sending 1526 user to stimulate the receiving user to accept some urgent data and 1527 to permit the receiving TCP to indicate to the receiving user when 1528 all the currently known urgent data has been received by the user. 1530 This mechanism permits a point in the data stream to be designated as 1531 the end of urgent information. Whenever this point is in advance of 1532 the receive sequence number (RCV.NXT) at the receiving TCP, that TCP 1533 must tell the user to go into "urgent mode"; when the receive 1534 sequence number catches up to the urgent pointer, the TCP must tell 1535 user to go into "normal mode". If the urgent pointer is updated 1536 while the user is in "urgent mode", the update will be invisible to 1537 the user. 1539 The method employs a urgent field which is carried in all segments 1540 transmitted. The URG control flag indicates that the urgent field is 1541 meaningful and must be added to the segment sequence number to yield 1542 the urgent pointer. The absence of this flag indicates that there is 1543 no urgent data outstanding. 1545 To send an urgent indication the user must also send at least one 1546 data octet. If the sending user also indicates a push, timely 1547 delivery of the urgent information to the destination process is 1548 enhanced. 1550 A TCP MUST support a sequence of urgent data of any length. [3] 1552 A TCP MUST inform the application layer asynchronously whenever it 1553 receives an Urgent pointer and there was previously no pending urgent 1554 data, or whenvever the Urgent pointer advances in the data stream. 1555 There MUST be a way for the application to learn how much urgent data 1556 remains to be read from the connection, or at least to determine 1557 whether or not more urgent data remains to be read. [3] 1559 Managing the Window 1560 The window sent in each segment indicates the range of sequence 1561 numbers the sender of the window (the data receiver) is currently 1562 prepared to accept. There is an assumption that this is related to 1563 the currently available data buffer space available for this 1564 connection. 1566 Indicating a large window encourages transmissions. If more data 1567 arrives than can be accepted, it will be discarded. This will result 1568 in excessive retransmissions, adding unnecessarily to the load on the 1569 network and the TCPs. Indicating a small window may restrict the 1570 transmission of data to the point of introducing a round trip delay 1571 between each new segment transmitted. 1573 The mechanisms provided allow a TCP to advertise a large window and 1574 to subsequently advertise a much smaller window without having 1575 accepted that much data. This, so called "shrinking the window," is 1576 strongly discouraged. The robustness principle dictates that TCPs 1577 will not shrink the window themselves, but will be prepared for such 1578 behavior on the part of other TCPs. 1580 The sending TCP must be prepared to accept from the user and send at 1581 least one octet of new data even if the send window is zero. The 1582 sending TCP must regularly retransmit to the receiving TCP even when 1583 the window is zero. Two minutes is recommended for the 1584 retransmission interval when the window is zero. This retransmission 1585 is essential to guarantee that when either TCP has a zero window the 1586 re-opening of the window will be reliably reported to the other. 1588 When the receiving TCP has a zero window and a segment arrives it 1589 must still send an acknowledgment showing its next expected sequence 1590 number and current window (zero). 1592 The sending TCP packages the data to be transmitted into segments 1593 which fit the current window, and may repackage segments on the 1594 retransmission queue. Such repackaging is not required, but may be 1595 helpful. 1597 In a connection with a one-way data flow, the window information will 1598 be carried in acknowledgment segments that all have the same sequence 1599 number so there will be no way to reorder them if they arrive out of 1600 order. This is not a serious problem, but it will allow the window 1601 information to be on occasion temporarily based on old reports from 1602 the data receiver. A refinement to avoid this problem is to act on 1603 the window information from segments that carry the highest 1604 acknowledgment number (that is segments with acknowledgment number 1605 equal or greater than the highest previously received). 1607 The window management procedure has significant influence on the 1608 communication performance. The following comments are suggestions to 1609 implementers. 1611 Window Management Suggestions 1613 Allocating a very small window causes data to be transmitted in 1614 many small segments when better performance is achieved using 1615 fewer large segments. 1617 One suggestion for avoiding small windows is for the receiver to 1618 defer updating a window until the additional allocation is at 1619 least X percent of the maximum allocation possible for the 1620 connection (where X might be 20 to 40). 1622 Another suggestion is for the sender to avoid sending small 1623 segments by waiting until the window is large enough before 1624 sending data. If the user signals a push function then the data 1625 must be sent even if it is a small segment. 1627 Note that the acknowledgments should not be delayed or unnecessary 1628 retransmissions will result. One strategy would be to send an 1629 acknowledgment when a small segment arrives (with out updating the 1630 window information), and then to send another acknowledgment with 1631 new window information when the window is larger. 1633 The segment sent to probe a zero window may also begin a break up 1634 of transmitted data into smaller and smaller segments. If a 1635 segment containing a single data octet sent to probe a zero window 1636 is accepted, it consumes one octet of the window now available. 1637 If the sending TCP simply sends as much as it can whenever the 1638 window is non zero, the transmitted data will be broken into 1639 alternating big and small segments. As time goes on, occasional 1640 pauses in the receiver making window allocation available will 1641 result in breaking the big segments into a small and not quite so 1642 big pair. And after a while the data transmission will be in 1643 mostly small segments. 1645 The suggestion here is that the TCP implementations need to 1646 actively attempt to combine small window allocations into larger 1647 windows, since the mechanisms for managing the window tend to lead 1648 to many small windows in the simplest minded implementations. 1650 3.9. Interfaces 1652 There are of course two interfaces of concern: the user/TCP interface 1653 and the TCP/lower-level interface. We have a fairly elaborate model 1654 of the user/TCP interface, but the interface to the lower level 1655 protocol module is left unspecified here, since it will be specified 1656 in detail by the specification of the lower level protocol. For the 1657 case that the lower level is IP we note some of the parameter values 1658 that TCPs might use. 1660 3.9.1. User/TCP Interface 1662 The following functional description of user commands to the TCP is, 1663 at best, fictional, since every operating system will have different 1664 facilities. Consequently, we must warn readers that different TCP 1665 implementations may have different user interfaces. However, all 1666 TCPs must provide a certain minimum set of services to guarantee that 1667 all TCP implementations can support the same protocol hierarchy. 1668 This section specifies the functional interfaces required of all TCP 1669 implementations. 1671 TCP User Commands 1673 The following sections functionally characterize a USER/TCP 1674 interface. The notation used is similar to most procedure or 1675 function calls in high level languages, but this usage is not 1676 meant to rule out trap type service calls (e.g., SVCs, UUOs, 1677 EMTs). 1679 The user commands described below specify the basic functions the 1680 TCP must perform to support interprocess communication. 1681 Individual implementations must define their own exact format, and 1682 may provide combinations or subsets of the basic functions in 1683 single calls. In particular, some implementations may wish to 1684 automatically OPEN a connection on the first SEND or RECEIVE 1685 issued by the user for a given connection. 1687 In providing interprocess communication facilities, the TCP must 1688 not only accept commands, but must also return information to the 1689 processes it serves. The latter consists of: 1691 (a) general information about a connection (e.g., interrupts, 1692 remote close, binding of unspecified foreign socket). 1694 (b) replies to specific user commands indicating success or 1695 various types of failure. 1697 Open 1699 Format: OPEN (local port, foreign socket, active/passive [, 1700 timeout] [, precedence] [, security/compartment] [, options]) 1701 -> local connection name 1702 We assume that the local TCP is aware of the identity of the 1703 processes it serves and will check the authority of the process 1704 to use the connection specified. Depending upon the 1705 implementation of the TCP, the local network and TCP 1706 identifiers for the source address will either be supplied by 1707 the TCP or the lower level protocol (e.g., IP). These 1708 considerations are the result of concern about security, to the 1709 extent that no TCP be able to masquerade as another one, and so 1710 on. Similarly, no process can masquerade as another without 1711 the collusion of the TCP. 1713 If the active/passive flag is set to passive, then this is a 1714 call to LISTEN for an incoming connection. A passive open may 1715 have either a fully specified foreign socket to wait for a 1716 particular connection or an unspecified foreign socket to wait 1717 for any call. A fully specified passive call can be made 1718 active by the subsequent execution of a SEND. 1720 A transmission control block (TCB) is created and partially 1721 filled in with data from the OPEN command parameters. 1723 On an active OPEN command, the TCP will begin the procedure to 1724 synchronize (i.e., establish) the connection at once. 1726 The timeout, if present, permits the caller to set up a timeout 1727 for all data submitted to TCP. If data is not successfully 1728 delivered to the destination within the timeout period, the TCP 1729 will abort the connection. The present global default is five 1730 minutes. 1732 The TCP or some component of the operating system will verify 1733 the users authority to open a connection with the specified 1734 precedence or security/compartment. The absence of precedence 1735 or security/compartment specification in the OPEN call 1736 indicates the default values must be used. 1738 TCP will accept incoming requests as matching only if the 1739 security/compartment information is exactly the same and only 1740 if the precedence is equal to or higher than the precedence 1741 requested in the OPEN call. 1743 The precedence for the connection is the higher of the values 1744 requested in the OPEN call and received from the incoming 1745 request, and fixed at that value for the life of the 1746 connection.Implementers may want to give the user control of 1747 this precedence negotiation. For example, the user might be 1748 allowed to specify that the precedence must be exactly matched, 1749 or that any attempt to raise the precedence be confirmed by the 1750 user. 1752 A local connection name will be returned to the user by the 1753 TCP. The local connection name can then be used as a short 1754 hand term for the connection defined by the pair. 1757 Send 1759 Format: SEND (local connection name, buffer address, byte 1760 count, PUSH flag, URGENT flag [,timeout]) 1762 This call causes the data contained in the indicated user 1763 buffer to be sent on the indicated connection. If the 1764 connection has not been opened, the SEND is considered an 1765 error. Some implementations may allow users to SEND first; in 1766 which case, an automatic OPEN would be done. If the calling 1767 process is not authorized to use this connection, an error is 1768 returned. 1770 If the PUSH flag is set, the data must be transmitted promptly 1771 to the receiver, and the PUSH bit will be set in the last TCP 1772 segment created from the buffer. If the PUSH flag is not set, 1773 the data may be combined with data from subsequent SENDs for 1774 transmission efficiency. 1776 New applications SHOULD NOT set the URGENT flag [7] due to 1777 implementation differences and middlebox issues. 1779 If the URGENT flag is set, segments sent to the destination TCP 1780 will have the urgent pointer set. The receiving TCP will 1781 signal the urgent condition to the receiving process if the 1782 urgent pointer indicates that data preceding the urgent pointer 1783 has not been consumed by the receiving process. The purpose of 1784 urgent is to stimulate the receiver to process the urgent data 1785 and to indicate to the receiver when all the currently known 1786 urgent data has been received. The number of times the sending 1787 user's TCP signals urgent will not necessarily be equal to the 1788 number of times the receiving user will be notified of the 1789 presence of urgent data. 1791 If no foreign socket was specified in the OPEN, but the 1792 connection is established (e.g., because a LISTENing connection 1793 has become specific due to a foreign segment arriving for the 1794 local socket), then the designated buffer is sent to the 1795 implied foreign socket. Users who make use of OPEN with an 1796 unspecified foreign socket can make use of SEND without ever 1797 explicitly knowing the foreign socket address. 1799 However, if a SEND is attempted before the foreign socket 1800 becomes specified, an error will be returned. Users can use 1801 the STATUS call to determine the status of the connection. In 1802 some implementations the TCP may notify the user when an 1803 unspecified socket is bound. 1805 If a timeout is specified, the current user timeout for this 1806 connection is changed to the new one. 1808 In the simplest implementation, SEND would not return control 1809 to the sending process until either the transmission was 1810 complete or the timeout had been exceeded. However, this 1811 simple method is both subject to deadlocks (for example, both 1812 sides of the connection might try to do SENDs before doing any 1813 RECEIVEs) and offers poor performance, so it is not 1814 recommended. A more sophisticated implementation would return 1815 immediately to allow the process to run concurrently with 1816 network I/O, and, furthermore, to allow multiple SENDs to be in 1817 progress. Multiple SENDs are served in first come, first 1818 served order, so the TCP will queue those it cannot service 1819 immediately. 1821 We have implicitly assumed an asynchronous user interface in 1822 which a SEND later elicits some kind of SIGNAL or pseudo- 1823 interrupt from the serving TCP. An alternative is to return a 1824 response immediately. For instance, SENDs might return 1825 immediate local acknowledgment, even if the segment sent had 1826 not been acknowledged by the distant TCP. We could 1827 optimistically assume eventual success. If we are wrong, the 1828 connection will close anyway due to the timeout. In 1829 implementations of this kind (synchronous), there will still be 1830 some asynchronous signals, but these will deal with the 1831 connection itself, and not with specific segments or buffers. 1833 In order for the process to distinguish among error or success 1834 indications for different SENDs, it might be appropriate for 1835 the buffer address to be returned along with the coded response 1836 to the SEND request. TCP-to-user signals are discussed below, 1837 indicating the information which should be returned to the 1838 calling process. 1840 Receive 1842 Format: RECEIVE (local connection name, buffer address, byte 1843 count) -> byte count, urgent flag, push flag 1844 This command allocates a receiving buffer associated with the 1845 specified connection. If no OPEN precedes this command or the 1846 calling process is not authorized to use this connection, an 1847 error is returned. 1849 In the simplest implementation, control would not return to the 1850 calling program until either the buffer was filled, or some 1851 error occurred, but this scheme is highly subject to deadlocks. 1852 A more sophisticated implementation would permit several 1853 RECEIVEs to be outstanding at once. These would be filled as 1854 segments arrive. This strategy permits increased throughput at 1855 the cost of a more elaborate scheme (possibly asynchronous) to 1856 notify the calling program that a PUSH has been seen or a 1857 buffer filled. 1859 If enough data arrive to fill the buffer before a PUSH is seen, 1860 the PUSH flag will not be set in the response to the RECEIVE. 1861 The buffer will be filled with as much data as it can hold. If 1862 a PUSH is seen before the buffer is filled the buffer will be 1863 returned partially filled and PUSH indicated. 1865 If there is urgent data the user will have been informed as 1866 soon as it arrived via a TCP-to-user signal. The receiving 1867 user should thus be in "urgent mode". If the URGENT flag is 1868 on, additional urgent data remains. If the URGENT flag is off, 1869 this call to RECEIVE has returned all the urgent data, and the 1870 user may now leave "urgent mode". Note that data following the 1871 urgent pointer (non-urgent data) cannot be delivered to the 1872 user in the same buffer with preceding urgent data unless the 1873 boundary is clearly marked for the user. 1875 To distinguish among several outstanding RECEIVEs and to take 1876 care of the case that a buffer is not completely filled, the 1877 return code is accompanied by both a buffer pointer and a byte 1878 count indicating the actual length of the data received. 1880 Alternative implementations of RECEIVE might have the TCP 1881 allocate buffer storage, or the TCP might share a ring buffer 1882 with the user. 1884 Close 1886 Format: CLOSE (local connection name) 1888 This command causes the connection specified to be closed. If 1889 the connection is not open or the calling process is not 1890 authorized to use this connection, an error is returned. 1891 Closing connections is intended to be a graceful operation in 1892 the sense that outstanding SENDs will be transmitted (and 1893 retransmitted), as flow control permits, until all have been 1894 serviced. Thus, it should be acceptable to make several SEND 1895 calls, followed by a CLOSE, and expect all the data to be sent 1896 to the destination. It should also be clear that users should 1897 continue to RECEIVE on CLOSING connections, since the other 1898 side may be trying to transmit the last of its data. Thus, 1899 CLOSE means "I have no more to send" but does not mean "I will 1900 not receive any more." It may happen (if the user level 1901 protocol is not well thought out) that the closing side is 1902 unable to get rid of all its data before timing out. In this 1903 event, CLOSE turns into ABORT, and the closing TCP gives up. 1905 The user may CLOSE the connection at any time on his own 1906 initiative, or in response to various prompts from the TCP 1907 (e.g., remote close executed, transmission timeout exceeded, 1908 destination inaccessible). 1910 Because closing a connection requires communication with the 1911 foreign TCP, connections may remain in the closing state for a 1912 short time. Attempts to reopen the connection before the TCP 1913 replies to the CLOSE command will result in error responses. 1915 Close also implies push function. 1917 Status 1919 Format: STATUS (local connection name) -> status data 1921 This is an implementation dependent user command and could be 1922 excluded without adverse effect. Information returned would 1923 typically come from the TCB associated with the connection. 1925 This command returns a data block containing the following 1926 information: 1928 local socket, 1929 foreign socket, 1930 local connection name, 1931 receive window, 1932 send window, 1933 connection state, 1934 number of buffers awaiting acknowledgment, 1935 number of buffers pending receipt, 1936 urgent state, 1937 precedence, 1938 security/compartment, 1939 and transmission timeout. 1941 Depending on the state of the connection, or on the 1942 implementation itself, some of this information may not be 1943 available or meaningful. If the calling process is not 1944 authorized to use this connection, an error is returned. This 1945 prevents unauthorized processes from gaining information about 1946 a connection. 1948 Abort 1950 Format: ABORT (local connection name) 1952 This command causes all pending SENDs and RECEIVES to be 1953 aborted, the TCB to be removed, and a special RESET message to 1954 be sent to the TCP on the other side of the connection. 1955 Depending on the implementation, users may receive abort 1956 indications for each outstanding SEND or RECEIVE, or may simply 1957 receive an ABORT-acknowledgment. 1959 TCP-to-User Messages 1961 It is assumed that the operating system environment provides a 1962 means for the TCP to asynchronously signal the user program. 1963 When the TCP does signal a user program, certain information is 1964 passed to the user. Often in the specification the information 1965 will be an error message. In other cases there will be 1966 information relating to the completion of processing a SEND or 1967 RECEIVE or other user call. 1969 The following information is provided: 1971 Local Connection Name Always 1972 Response String Always 1973 Buffer Address Send & Receive 1974 Byte count (counts bytes received) Receive 1975 Push flag Receive 1976 Urgent flag Receive 1978 3.9.2. TCP/Lower-Level Interface 1980 The TCP calls on a lower level protocol module to actually send and 1981 receive information over a network. One case is that of the ARPA 1982 internetwork system where the lower level module is the Internet 1983 Protocol (IP) [2]. 1985 If the lower level protocol is IP it provides arguments for a type of 1986 service and for a time to live. TCP uses the following settings for 1987 these parameters: 1989 Type of Service = Precedence: given by user, Delay: normal, 1990 Throughput: normal, Reliability: normal; or binary XXX00000, where 1991 XXX are the three bits determining precedence, e.g. 000 means 1992 routine precedence. 1994 Time to Live = one minute, or 00111100. 1996 Note that the assumed maximum segment lifetime is two minutes. 1997 Here we explicitly ask that a segment be destroyed if it cannot 1998 be delivered by the internet system within one minute. 2000 If the lower level is IP (or other protocol that provides this 2001 feature) and source routing is used, the interface must allow the 2002 route information to be communicated. This is especially important 2003 so that the source and destination addresses used in the TCP checksum 2004 be the originating source and ultimate destination. It is also 2005 important to preserve the return route to answer connection requests. 2007 Any lower level protocol will have to provide the source address, 2008 destination address, and protocol fields, and some way to determine 2009 the "TCP length", both to provide the functional equivalent service 2010 of IP and to be used in the TCP checksum. 2012 3.10. Event Processing 2014 The processing depicted in this section is an example of one possible 2015 implementation. Other implementations may have slightly different 2016 processing sequences, but they should differ from those in this 2017 section only in detail, not in substance. 2019 The activity of the TCP can be characterized as responding to events. 2020 The events that occur can be cast into three categories: user calls, 2021 arriving segments, and timeouts. This section describes the 2022 processing the TCP does in response to each of the events. In many 2023 cases the processing required depends on the state of the connection. 2025 Events that occur: 2027 User Calls 2029 OPEN 2030 SEND 2031 RECEIVE 2032 CLOSE 2033 ABORT 2034 STATUS 2036 Arriving Segments 2037 SEGMENT ARRIVES 2039 Timeouts 2041 USER TIMEOUT 2042 RETRANSMISSION TIMEOUT 2043 TIME-WAIT TIMEOUT 2045 The model of the TCP/user interface is that user commands receive an 2046 immediate return and possibly a delayed response via an event or 2047 pseudo interrupt. In the following descriptions, the term "signal" 2048 means cause a delayed response. 2050 Error responses are given as character strings. For example, user 2051 commands referencing connections that do not exist receive "error: 2052 connection not open". 2054 Please note in the following that all arithmetic on sequence numbers, 2055 acknowledgment numbers, windows, et cetera, is modulo 2**32 the size 2056 of the sequence number space. Also note that "=<" means less than or 2057 equal to (modulo 2**32). 2059 A natural way to think about processing incoming segments is to 2060 imagine that they are first tested for proper sequence number (i.e., 2061 that their contents lie in the range of the expected "receive window" 2062 in the sequence number space) and then that they are generally queued 2063 and processed in sequence number order. 2065 When a segment overlaps other already received segments we 2066 reconstruct the segment to contain just the new data, and adjust the 2067 header fields to be consistent. 2069 Note that if no state change is mentioned the TCP stays in the same 2070 state. 2072 OPEN Call 2074 CLOSED STATE (i.e., TCB does not exist) 2076 Create a new transmission control block (TCB) to hold 2077 connection state information. Fill in local socket identifier, 2078 foreign socket, precedence, security/compartment, and user 2079 timeout information. Note that some parts of the foreign 2080 socket may be unspecified in a passive OPEN and are to be 2081 filled in by the parameters of the incoming SYN segment. 2082 Verify the security and precedence requested are allowed for 2083 this user, if not return "error: precedence not allowed" or 2084 "error: security/compartment not allowed." If passive enter 2085 the LISTEN state and return. If active and the foreign socket 2086 is unspecified, return "error: foreign socket unspecified"; if 2087 active and the foreign socket is specified, issue a SYN 2088 segment. An initial send sequence number (ISS) is selected. A 2089 SYN segment of the form is sent. Set 2090 SND.UNA to ISS, SND.NXT to ISS+1, enter SYN-SENT state, and 2091 return. 2093 If the caller does not have access to the local socket 2094 specified, return "error: connection illegal for this process". 2095 If there is no room to create a new connection, return "error: 2096 insufficient resources". 2098 LISTEN STATE 2100 If active and the foreign socket is specified, then change the 2101 connection from passive to active, select an ISS. Send a SYN 2102 segment, set SND.UNA to ISS, SND.NXT to ISS+1. Enter SYN-SENT 2103 state. Data associated with SEND may be sent with SYN segment 2104 or queued for transmission after entering ESTABLISHED state. 2105 The urgent bit if requested in the command must be sent with 2106 the data segments sent as a result of this command. If there 2107 is no room to queue the request, respond with "error: 2108 insufficient resources". If Foreign socket was not specified, 2109 then return "error: foreign socket unspecified". 2111 SYN-SENT STATE 2112 SYN-RECEIVED STATE 2113 ESTABLISHED STATE 2114 FIN-WAIT-1 STATE 2115 FIN-WAIT-2 STATE 2116 CLOSE-WAIT STATE 2117 CLOSING STATE 2118 LAST-ACK STATE 2119 TIME-WAIT STATE 2121 Return "error: connection already exists". 2123 SEND Call 2125 CLOSED STATE (i.e., TCB does not exist) 2127 If the user does not have access to such a connection, then 2128 return "error: connection illegal for this process". 2130 Otherwise, return "error: connection does not exist". 2132 LISTEN STATE 2134 If the foreign socket is specified, then change the connection 2135 from passive to active, select an ISS. Send a SYN segment, set 2136 SND.UNA to ISS, SND.NXT to ISS+1. Enter SYN-SENT state. Data 2137 associated with SEND may be sent with SYN segment or queued for 2138 transmission after entering ESTABLISHED state. The urgent bit 2139 if requested in the command must be sent with the data segments 2140 sent as a result of this command. If there is no room to queue 2141 the request, respond with "error: insufficient resources". If 2142 Foreign socket was not specified, then return "error: foreign 2143 socket unspecified". 2145 SYN-SENT STATE 2146 SYN-RECEIVED STATE 2148 Queue the data for transmission after entering ESTABLISHED 2149 state. If no space to queue, respond with "error: insufficient 2150 resources". 2152 ESTABLISHED STATE 2153 CLOSE-WAIT STATE 2155 Segmentize the buffer and send it with a piggybacked 2156 acknowledgment (acknowledgment value = RCV.NXT). If there is 2157 insufficient space to remember this buffer, simply return 2158 "error: insufficient resources". 2160 If the urgent flag is set, then SND.UP <- SND.NXT and set the 2161 urgent pointer in the outgoing segments. 2163 FIN-WAIT-1 STATE 2164 FIN-WAIT-2 STATE 2165 CLOSING STATE 2166 LAST-ACK STATE 2167 TIME-WAIT STATE 2169 Return "error: connection closing" and do not service request. 2171 RECEIVE Call 2173 CLOSED STATE (i.e., TCB does not exist) 2175 If the user does not have access to such a connection, return 2176 "error: connection illegal for this process". 2178 Otherwise return "error: connection does not exist". 2180 LISTEN STATE 2181 SYN-SENT STATE 2182 SYN-RECEIVED STATE 2184 Queue for processing after entering ESTABLISHED state. If 2185 there is no room to queue this request, respond with "error: 2186 insufficient resources". 2188 ESTABLISHED STATE 2189 FIN-WAIT-1 STATE 2190 FIN-WAIT-2 STATE 2192 If insufficient incoming segments are queued to satisfy the 2193 request, queue the request. If there is no queue space to 2194 remember the RECEIVE, respond with "error: insufficient 2195 resources". 2197 Reassemble queued incoming segments into receive buffer and 2198 return to user. Mark "push seen" (PUSH) if this is the case. 2200 If RCV.UP is in advance of the data currently being passed to 2201 the user notify the user of the presence of urgent data. 2203 When the TCP takes responsibility for delivering data to the 2204 user that fact must be communicated to the sender via an 2205 acknowledgment. The formation of such an acknowledgment is 2206 described below in the discussion of processing an incoming 2207 segment. 2209 CLOSE-WAIT STATE 2211 Since the remote side has already sent FIN, RECEIVEs must be 2212 satisfied by text already on hand, but not yet delivered to the 2213 user. If no text is awaiting delivery, the RECEIVE will get a 2214 "error: connection closing" response. Otherwise, any remaining 2215 text can be used to satisfy the RECEIVE. 2217 CLOSING STATE 2218 LAST-ACK STATE 2219 TIME-WAIT STATE 2221 Return "error: connection closing". 2223 CLOSE Call 2225 CLOSED STATE (i.e., TCB does not exist) 2227 If the user does not have access to such a connection, return 2228 "error: connection illegal for this process". 2230 Otherwise, return "error: connection does not exist". 2232 LISTEN STATE 2234 Any outstanding RECEIVEs are returned with "error: closing" 2235 responses. Delete TCB, enter CLOSED state, and return. 2237 SYN-SENT STATE 2239 Delete the TCB and return "error: closing" responses to any 2240 queued SENDs, or RECEIVEs. 2242 SYN-RECEIVED STATE 2244 If no SENDs have been issued and there is no pending data to 2245 send, then form a FIN segment and send it, and enter FIN-WAIT-1 2246 state; otherwise queue for processing after entering 2247 ESTABLISHED state. 2249 ESTABLISHED STATE 2251 Queue this until all preceding SENDs have been segmentized, 2252 then form a FIN segment and send it. In any case, enter FIN- 2253 WAIT-1 state. 2255 FIN-WAIT-1 STATE 2256 FIN-WAIT-2 STATE 2258 Strictly speaking, this is an error and should receive a 2259 "error: connection closing" response. An "ok" response would 2260 be acceptable, too, as long as a second FIN is not emitted (the 2261 first FIN may be retransmitted though). 2263 CLOSE-WAIT STATE 2265 Queue this request until all preceding SENDs have been 2266 segmentized; then send a FIN segment, enter LAST-ACK state. 2268 CLOSING STATE 2269 LAST-ACK STATE 2270 TIME-WAIT STATE 2271 Respond with "error: connection closing". 2273 ABORT Call 2275 CLOSED STATE (i.e., TCB does not exist) 2277 If the user should not have access to such a connection, return 2278 "error: connection illegal for this process". 2280 Otherwise return "error: connection does not exist". 2282 LISTEN STATE 2284 Any outstanding RECEIVEs should be returned with "error: 2285 connection reset" responses. Delete TCB, enter CLOSED state, 2286 and return. 2288 SYN-SENT STATE 2290 All queued SENDs and RECEIVEs should be given "connection 2291 reset" notification, delete the TCB, enter CLOSED state, and 2292 return. 2294 SYN-RECEIVED STATE 2295 ESTABLISHED STATE 2296 FIN-WAIT-1 STATE 2297 FIN-WAIT-2 STATE 2298 CLOSE-WAIT STATE 2300 Send a reset segment: 2302 2304 All queued SENDs and RECEIVEs should be given "connection 2305 reset" notification; all segments queued for transmission 2306 (except for the RST formed above) or retransmission should be 2307 flushed, delete the TCB, enter CLOSED state, and return. 2309 CLOSING STATE LAST-ACK STATE TIME-WAIT STATE 2311 Respond with "ok" and delete the TCB, enter CLOSED state, and 2312 return. 2314 STATUS Call 2316 CLOSED STATE (i.e., TCB does not exist) 2318 If the user should not have access to such a connection, return 2319 "error: connection illegal for this process". 2321 Otherwise return "error: connection does not exist". 2323 LISTEN STATE 2325 Return "state = LISTEN", and the TCB pointer. 2327 SYN-SENT STATE 2329 Return "state = SYN-SENT", and the TCB pointer. 2331 SYN-RECEIVED STATE 2333 Return "state = SYN-RECEIVED", and the TCB pointer. 2335 ESTABLISHED STATE 2337 Return "state = ESTABLISHED", and the TCB pointer. 2339 FIN-WAIT-1 STATE 2341 Return "state = FIN-WAIT-1", and the TCB pointer. 2343 FIN-WAIT-2 STATE 2345 Return "state = FIN-WAIT-2", and the TCB pointer. 2347 CLOSE-WAIT STATE 2349 Return "state = CLOSE-WAIT", and the TCB pointer. 2351 CLOSING STATE 2353 Return "state = CLOSING", and the TCB pointer. 2355 LAST-ACK STATE 2357 Return "state = LAST-ACK", and the TCB pointer. 2359 TIME-WAIT STATE 2361 Return "state = TIME-WAIT", and the TCB pointer. 2363 SEGMENT ARRIVES 2365 If the state is CLOSED (i.e., TCB does not exist) then 2367 all data in the incoming segment is discarded. An incoming 2368 segment containing a RST is discarded. An incoming segment not 2369 containing a RST causes a RST to be sent in response. The 2370 acknowledgment and sequence field values are selected to make 2371 the reset sequence acceptable to the TCP that sent the 2372 offending segment. 2374 If the ACK bit is off, sequence number zero is used, 2376 2378 If the ACK bit is on, 2380 2382 Return. 2384 If the state is LISTEN then 2386 first check for an RST 2388 An incoming RST should be ignored. Return. 2390 second check for an ACK 2392 Any acknowledgment is bad if it arrives on a connection 2393 still in the LISTEN state. An acceptable reset segment 2394 should be formed for any arriving ACK-bearing segment. The 2395 RST should be formatted as follows: 2397 2399 Return. 2401 third check for a SYN 2403 If the SYN bit is set, check the security. If the security/ 2404 compartment on the incoming segment does not exactly match 2405 the security/compartment in the TCB then send a reset and 2406 return. 2408 2410 If the SEG.PRC is greater than the TCB.PRC then if allowed 2411 by the user and the system set TCB.PRC<-SEG.PRC, if not 2412 allowed send a reset and return. 2414 2416 If the SEG.PRC is less than the TCB.PRC then continue. 2418 Set RCV.NXT to SEG.SEQ+1, IRS is set to SEG.SEQ and any 2419 other control or text should be queued for processing later. 2420 ISS should be selected and a SYN segment sent of the form: 2422 2424 SND.NXT is set to ISS+1 and SND.UNA to ISS. The connection 2425 state should be changed to SYN-RECEIVED. Note that any 2426 other incoming control or data (combined with SYN) will be 2427 processed in the SYN-RECEIVED state, but processing of SYN 2428 and ACK should not be repeated. If the listen was not fully 2429 specified (i.e., the foreign socket was not fully 2430 specified), then the unspecified fields should be filled in 2431 now. 2433 fourth other text or control 2435 Any other control or text-bearing segment (not containing 2436 SYN) must have an ACK and thus would be discarded by the ACK 2437 processing. An incoming RST segment could not be valid, 2438 since it could not have been sent in response to anything 2439 sent by this incarnation of the connection. So you are 2440 unlikely to get here, but if you do, drop the segment, and 2441 return. 2443 If the state is SYN-SENT then 2445 first check the ACK bit 2447 If the ACK bit is set 2449 If SEG.ACK =< ISS, or SEG.ACK > SND.NXT, send a reset 2450 (unless the RST bit is set, if so drop the segment and 2451 return) 2453 2455 and discard the segment. Return. 2457 If SND.UNA < SEG.ACK =< SND.NXT then the ACK is 2458 acceptable. (TODO: in processing Errata ID 3300, it was 2459 noted that some stacks in the wild that do not send data 2460 on the SYN are just checking that SEG.ACK == SND.NXT ... 2461 think about whether anything should be said about that 2462 here) 2464 second check the RST bit 2466 If the RST bit is set 2468 If the ACK was acceptable then signal the user "error: 2469 connection reset", drop the segment, enter CLOSED state, 2470 delete TCB, and return. Otherwise (no ACK) drop the 2471 segment and return. 2473 third check the security and precedence 2475 If the security/compartment in the segment does not exactly 2476 match the security/compartment in the TCB, send a reset 2478 If there is an ACK 2480 2482 Otherwise 2484 2486 If there is an ACK 2488 The precedence in the segment must match the precedence 2489 in the TCB, if not, send a reset 2491 2493 If there is no ACK 2495 If the precedence in the segment is higher than the 2496 precedence in the TCB then if allowed by the user and the 2497 system raise the precedence in the TCB to that in the 2498 segment, if not allowed to raise the prec then send a 2499 reset. 2501 2503 If the precedence in the segment is lower than the 2504 precedence in the TCB continue. 2506 If a reset was sent, discard the segment and return. 2508 fourth check the SYN bit 2510 This step should be reached only if the ACK is ok, or there 2511 is no ACK, and it the segment did not contain a RST. 2513 If the SYN bit is on and the security/compartment and 2514 precedence are acceptable then, RCV.NXT is set to SEG.SEQ+1, 2515 IRS is set to SEG.SEQ. SND.UNA should be advanced to equal 2516 SEG.ACK (if there is an ACK), and any segments on the 2517 retransmission queue which are thereby acknowledged should 2518 be removed. 2520 If SND.UNA > ISS (our SYN has been ACKed), change the 2521 connection state to ESTABLISHED, form an ACK segment 2523 2525 and send it. Data or controls which were queued for 2526 transmission may be included. If there are other controls 2527 or text in the segment then continue processing at the sixth 2528 step below where the URG bit is checked, otherwise return. 2530 Otherwise enter SYN-RECEIVED, form a SYN,ACK segment 2532 2534 and send it. Set the variables: 2536 SND.WND <- SEG.WND 2537 SND.WL1 <- SEG.SEQ 2538 SND.WL2 <- SEG.ACK 2540 If there are other controls or text in the segment, queue 2541 them for processing after the ESTABLISHED state has been 2542 reached, return. 2544 fifth, if neither of the SYN or RST bits is set then drop the 2545 segment and return. 2547 Otherwise, 2549 first check sequence number 2551 SYN-RECEIVED STATE 2552 ESTABLISHED STATE 2553 FIN-WAIT-1 STATE 2554 FIN-WAIT-2 STATE 2555 CLOSE-WAIT STATE 2556 CLOSING STATE 2557 LAST-ACK STATE 2558 TIME-WAIT STATE 2560 Segments are processed in sequence. Initial tests on 2561 arrival are used to discard old duplicates, but further 2562 processing is done in SEG.SEQ order. If a segment's 2563 contents straddle the boundary between old and new, only the 2564 new parts should be processed. 2566 There are four cases for the acceptability test for an 2567 incoming segment: 2569 Segment Receive Test 2570 Length Window 2571 ------- ------- ------------------------------------------- 2573 0 0 SEG.SEQ = RCV.NXT 2575 0 >0 RCV.NXT =< SEG.SEQ < RCV.NXT+RCV.WND 2577 >0 0 not acceptable 2579 >0 >0 RCV.NXT =< SEG.SEQ < RCV.NXT+RCV.WND 2580 or RCV.NXT =< SEG.SEQ+SEG.LEN-1 < RCV.NXT+RCV.WND 2582 If the RCV.WND is zero, no segments will be acceptable, but 2583 special allowance should be made to accept valid ACKs, URGs 2584 and RSTs. 2586 If an incoming segment is not acceptable, an acknowledgment 2587 should be sent in reply (unless the RST bit is set, if so 2588 drop the segment and return): 2590 2592 After sending the acknowledgment, drop the unacceptable 2593 segment and return. 2595 In the following it is assumed that the segment is the 2596 idealized segment that begins at RCV.NXT and does not exceed 2597 the window. One could tailor actual segments to fit this 2598 assumption by trimming off any portions that lie outside the 2599 window (including SYN and FIN), and only processing further 2600 if the segment then begins at RCV.NXT. Segments with higher 2601 beginning sequence numbers should be held for later 2602 processing. 2604 second check the RST bit, 2606 SYN-RECEIVED STATE 2608 If the RST bit is set 2610 If this connection was initiated with a passive OPEN 2611 (i.e., came from the LISTEN state), then return this 2612 connection to LISTEN state and return. The user need 2613 not be informed. If this connection was initiated 2614 with an active OPEN (i.e., came from SYN-SENT state) 2615 then the connection was refused, signal the user 2616 "connection refused". In either case, all segments on 2617 the retransmission queue should be removed. And in 2618 the active OPEN case, enter the CLOSED state and 2619 delete the TCB, and return. 2621 ESTABLISHED 2622 FIN-WAIT-1 2623 FIN-WAIT-2 2624 CLOSE-WAIT 2626 If the RST bit is set then, any outstanding RECEIVEs and 2627 SEND should receive "reset" responses. All segment 2628 queues should be flushed. Users should also receive an 2629 unsolicited general "connection reset" signal. Enter the 2630 CLOSED state, delete the TCB, and return. 2632 CLOSING STATE 2633 LAST-ACK STATE 2634 TIME-WAIT 2636 If the RST bit is set then, enter the CLOSED state, 2637 delete the TCB, and return. 2639 third check security and precedence 2641 SYN-RECEIVED 2643 If the security/compartment and precedence in the segment 2644 do not exactly match the security/compartment and 2645 precedence in the TCB then send a reset, and return. 2647 ESTABLISHED 2648 FIN-WAIT-1 2649 FIN-WAIT-2 2650 CLOSE-WAIT 2651 CLOSING 2652 LAST-ACK 2653 TIME-WAIT 2655 If the security/compartment and precedence in the segment 2656 do not exactly match the security/compartment and 2657 precedence in the TCB then send a reset, any outstanding 2658 RECEIVEs and SEND should receive "reset" responses. All 2659 segment queues should be flushed. Users should also 2660 receive an unsolicited general "connection reset" signal. 2661 Enter the CLOSED state, delete the TCB, and return. 2663 Note this check is placed following the sequence check to 2664 prevent a segment from an old connection between these ports 2665 with a different security or precedence from causing an 2666 abort of the current connection. 2668 fourth, check the SYN bit, 2670 SYN-RECEIVED 2671 ESTABLISHED STATE 2672 FIN-WAIT STATE-1 2673 FIN-WAIT STATE-2 2674 CLOSE-WAIT STATE 2675 CLOSING STATE 2676 LAST-ACK STATE 2677 TIME-WAIT STATE 2679 TODO: need to incorporate RFC 1122 4.2.2.20(e) here 2681 If the SYN is in the window it is an error, send a reset, 2682 any outstanding RECEIVEs and SEND should receive "reset" 2683 responses, all segment queues should be flushed, the user 2684 should also receive an unsolicited general "connection 2685 reset" signal, enter the CLOSED state, delete the TCB, 2686 and return. 2688 If the SYN is not in the window this step would not be 2689 reached and an ack would have been sent in the first step 2690 (sequence number check). 2692 fifth check the ACK field, 2694 if the ACK bit is off drop the segment and return 2695 if the ACK bit is on 2697 SYN-RECEIVED STATE 2699 If SND.UNA < SEG.ACK =< SND.NXT then enter ESTABLISHED 2700 state and continue processing with variables below set 2701 to: 2703 SND.WND <- SEG.WND 2704 SND.WL1 <- SEG.SEQ 2705 SND.WL2 <- SEG.ACK 2707 If the segment acknowledgment is not acceptable, 2708 form a reset segment, 2710 2712 and send it. 2714 ESTABLISHED STATE 2716 If SND.UNA < SEG.ACK =< SND.NXT then, set SND.UNA <- 2717 SEG.ACK. Any segments on the retransmission queue 2718 which are thereby entirely acknowledged are removed. 2719 Users should receive positive acknowledgments for 2720 buffers which have been SENT and fully acknowledged 2721 (i.e., SEND buffer should be returned with "ok" 2722 response). If the ACK is a duplicate (SEG.ACK =< 2723 SND.UNA), it can be ignored. If the ACK acks 2724 something not yet sent (SEG.ACK > SND.NXT) then send 2725 an ACK, drop the segment, and return. 2727 If SND.UNA =< SEG.ACK =< SND.NXT, the send window 2728 should be updated. If (SND.WL1 < SEG.SEQ or (SND.WL1 2729 = SEG.SEQ and SND.WL2 =< SEG.ACK)), set SND.WND <- 2730 SEG.WND, set SND.WL1 <- SEG.SEQ, and set SND.WL2 <- 2731 SEG.ACK. 2733 Note that SND.WND is an offset from SND.UNA, that 2734 SND.WL1 records the sequence number of the last 2735 segment used to update SND.WND, and that SND.WL2 2736 records the acknowledgment number of the last segment 2737 used to update SND.WND. The check here prevents using 2738 old segments to update the window. 2740 FIN-WAIT-1 STATE 2741 In addition to the processing for the ESTABLISHED 2742 state, if our FIN is now acknowledged then enter FIN- 2743 WAIT-2 and continue processing in that state. 2745 FIN-WAIT-2 STATE 2747 In addition to the processing for the ESTABLISHED 2748 state, if the retransmission queue is empty, the 2749 user's CLOSE can be acknowledged ("ok") but do not 2750 delete the TCB. 2752 CLOSE-WAIT STATE 2754 Do the same processing as for the ESTABLISHED state. 2756 CLOSING STATE 2758 In addition to the processing for the ESTABLISHED 2759 state, if the ACK acknowledges our FIN then enter the 2760 TIME-WAIT state, otherwise ignore the segment. 2762 LAST-ACK STATE 2764 The only thing that can arrive in this state is an 2765 acknowledgment of our FIN. If our FIN is now 2766 acknowledged, delete the TCB, enter the CLOSED state, 2767 and return. 2769 TIME-WAIT STATE 2771 The only thing that can arrive in this state is a 2772 retransmission of the remote FIN. Acknowledge it, and 2773 restart the 2 MSL timeout. 2775 sixth, check the URG bit, 2777 ESTABLISHED STATE 2778 FIN-WAIT-1 STATE 2779 FIN-WAIT-2 STATE 2781 If the URG bit is set, RCV.UP <- max(RCV.UP,SEG.UP), and 2782 signal the user that the remote side has urgent data if 2783 the urgent pointer (RCV.UP) is in advance of the data 2784 consumed. If the user has already been signaled (or is 2785 still in the "urgent mode") for this continuous sequence 2786 of urgent data, do not signal the user again. 2788 CLOSE-WAIT STATE 2789 CLOSING STATE 2790 LAST-ACK STATE 2791 TIME-WAIT 2793 This should not occur, since a FIN has been received from 2794 the remote side. Ignore the URG. 2796 seventh, process the segment text, 2798 ESTABLISHED STATE 2799 FIN-WAIT-1 STATE 2800 FIN-WAIT-2 STATE 2802 Once in the ESTABLISHED state, it is possible to deliver 2803 segment text to user RECEIVE buffers. Text from segments 2804 can be moved into buffers until either the buffer is full 2805 or the segment is empty. If the segment empties and 2806 carries an PUSH flag, then the user is informed, when the 2807 buffer is returned, that a PUSH has been received. 2809 When the TCP takes responsibility for delivering the data 2810 to the user it must also acknowledge the receipt of the 2811 data. 2813 Once the TCP takes responsibility for the data it 2814 advances RCV.NXT over the data accepted, and adjusts 2815 RCV.WND as appropriate to the current buffer 2816 availability. The total of RCV.NXT and RCV.WND should 2817 not be reduced. 2819 Please note the window management suggestions in section 2820 3.7. 2822 Send an acknowledgment of the form: 2824 2826 This acknowledgment should be piggybacked on a segment 2827 being transmitted if possible without incurring undue 2828 delay. 2830 CLOSE-WAIT STATE 2831 CLOSING STATE 2832 LAST-ACK STATE 2833 TIME-WAIT STATE 2835 This should not occur, since a FIN has been received from 2836 the remote side. Ignore the segment text. 2838 eighth, check the FIN bit, 2840 Do not process the FIN if the state is CLOSED, LISTEN or 2841 SYN-SENT since the SEG.SEQ cannot be validated; drop the 2842 segment and return. 2844 If the FIN bit is set, signal the user "connection closing" 2845 and return any pending RECEIVEs with same message, advance 2846 RCV.NXT over the FIN, and send an acknowledgment for the 2847 FIN. Note that FIN implies PUSH for any segment text not 2848 yet delivered to the user. 2850 SYN-RECEIVED STATE 2851 ESTABLISHED STATE 2853 Enter the CLOSE-WAIT state. 2855 FIN-WAIT-1 STATE 2857 If our FIN has been ACKed (perhaps in this segment), 2858 then enter TIME-WAIT, start the time-wait timer, turn 2859 off the other timers; otherwise enter the CLOSING 2860 state. 2862 FIN-WAIT-2 STATE 2864 Enter the TIME-WAIT state. Start the time-wait timer, 2865 turn off the other timers. 2867 CLOSE-WAIT STATE 2869 Remain in the CLOSE-WAIT state. 2871 CLOSING STATE 2873 Remain in the CLOSING state. 2875 LAST-ACK STATE 2877 Remain in the LAST-ACK state. 2879 TIME-WAIT STATE 2881 Remain in the TIME-WAIT state. Restart the 2 MSL 2882 time-wait timeout. 2884 and return. 2886 USER TIMEOUT 2888 USER TIMEOUT 2890 For any state if the user timeout expires, flush all queues, 2891 signal the user "error: connection aborted due to user timeout" 2892 in general and for any outstanding calls, delete the TCB, enter 2893 the CLOSED state and return. 2895 RETRANSMISSION TIMEOUT 2897 For any state if the retransmission timeout expires on a 2898 segment in the retransmission queue, send the segment at the 2899 front of the retransmission queue again, reinitialize the 2900 retransmission timer, and return. 2902 TIME-WAIT TIMEOUT 2904 If the time-wait timeout expires on a connection delete the 2905 TCB, enter the CLOSED state and return. 2907 3.11. Glossary 2909 1822 BBN Report 1822, "The Specification of the Interconnection of 2910 a Host and an IMP". The specification of interface between a 2911 host and the ARPANET. 2913 ACK 2914 A control bit (acknowledge) occupying no sequence space, 2915 which indicates that the acknowledgment field of this segment 2916 specifies the next sequence number the sender of this segment 2917 is expecting to receive, hence acknowledging receipt of all 2918 previous sequence numbers. 2920 ARPANET message 2921 The unit of transmission between a host and an IMP in the 2922 ARPANET. The maximum size is about 1012 octets (8096 bits). 2924 ARPANET packet 2925 A unit of transmission used internally in the ARPANET between 2926 IMPs. The maximum size is about 126 octets (1008 bits). 2928 connection 2929 A logical communication path identified by a pair of sockets. 2931 datagram 2932 A message sent in a packet switched computer communications 2933 network. 2935 Destination Address 2936 The destination address, usually the network and host 2937 identifiers. 2939 FIN 2940 A control bit (finis) occupying one sequence number, which 2941 indicates that the sender will send no more data or control 2942 occupying sequence space. 2944 fragment 2945 A portion of a logical unit of data, in particular an 2946 internet fragment is a portion of an internet datagram. 2948 FTP 2949 A file transfer protocol. 2951 header 2952 Control information at the beginning of a message, segment, 2953 fragment, packet or block of data. 2955 host 2956 A computer. In particular a source or destination of 2957 messages from the point of view of the communication network. 2959 Identification 2960 An Internet Protocol field. This identifying value assigned 2961 by the sender aids in assembling the fragments of a datagram. 2963 IMP 2964 The Interface Message Processor, the packet switch of the 2965 ARPANET. 2967 internet address 2968 A source or destination address specific to the host level. 2970 internet datagram 2971 The unit of data exchanged between an internet module and the 2972 higher level protocol together with the internet header. 2974 internet fragment 2975 A portion of the data of an internet datagram with an 2976 internet header. 2978 IP 2979 Internet Protocol. 2981 IRS 2982 The Initial Receive Sequence number. The first sequence 2983 number used by the sender on a connection. 2985 ISN 2986 The Initial Sequence Number. The first sequence number used 2987 on a connection, (either ISS or IRS). Selected in a way that 2988 is unique within a given period of time and is unpredictable 2989 to attackers. 2991 ISS 2992 The Initial Send Sequence number. The first sequence number 2993 used by the sender on a connection. 2995 leader 2996 Control information at the beginning of a message or block of 2997 data. In particular, in the ARPANET, the control information 2998 on an ARPANET message at the host-IMP interface. 3000 left sequence 3001 This is the next sequence number to be acknowledged by the 3002 data receiving TCP (or the lowest currently unacknowledged 3003 sequence number) and is sometimes referred to as the left 3004 edge of the send window. 3006 local packet 3007 The unit of transmission within a local network. 3009 module 3010 An implementation, usually in software, of a protocol or 3011 other procedure. 3013 MSL 3014 Maximum Segment Lifetime, the time a TCP segment can exist in 3015 the internetwork system. Arbitrarily defined to be 2 3016 minutes. 3018 octet 3019 An eight bit byte. 3021 Options 3022 An Option field may contain several options, and each option 3023 may be several octets in length. The options are used 3024 primarily in testing situations; for example, to carry 3025 timestamps. Both the Internet Protocol and TCP provide for 3026 options fields. 3028 packet 3029 A package of data with a header which may or may not be 3030 logically complete. More often a physical packaging than a 3031 logical packaging of data. 3033 port 3034 The portion of a socket that specifies which logical input or 3035 output channel of a process is associated with the data. 3037 process 3038 A program in execution. A source or destination of data from 3039 the point of view of the TCP or other host-to-host protocol. 3041 PUSH 3042 A control bit occupying no sequence space, indicating that 3043 this segment contains data that must be pushed through to the 3044 receiving user. 3046 RCV.NXT 3047 receive next sequence number 3049 RCV.UP 3050 receive urgent pointer 3052 RCV.WND 3053 receive window 3055 receive next sequence number 3056 This is the next sequence number the local TCP is expecting 3057 to receive. 3059 receive window 3060 This represents the sequence numbers the local (receiving) 3061 TCP is willing to receive. Thus, the local TCP considers 3062 that segments overlapping the range RCV.NXT to RCV.NXT + 3063 RCV.WND - 1 carry acceptable data or control. Segments 3064 containing sequence numbers entirely outside of this range 3065 are considered duplicates and discarded. 3067 RST 3068 A control bit (reset), occupying no sequence space, 3069 indicating that the receiver should delete the connection 3070 without further interaction. The receiver can determine, 3071 based on the sequence number and acknowledgment fields of the 3072 incoming segment, whether it should honor the reset command 3073 or ignore it. In no case does receipt of a segment 3074 containing RST give rise to a RST in response. 3076 RTP 3077 Real Time Protocol: A host-to-host protocol for communication 3078 of time critical information. 3080 SEG.ACK 3081 segment acknowledgment 3083 SEG.LEN 3084 segment length 3086 SEG.PRC 3087 segment precedence value 3089 SEG.SEQ 3090 segment sequence 3092 SEG.UP 3093 segment urgent pointer field 3095 SEG.WND 3096 segment window field 3098 segment 3099 A logical unit of data, in particular a TCP segment is the 3100 unit of data transfered between a pair of TCP modules. 3102 segment acknowledgment 3103 The sequence number in the acknowledgment field of the 3104 arriving segment. 3106 segment length 3107 The amount of sequence number space occupied by a segment, 3108 including any controls which occupy sequence space. 3110 segment sequence 3111 The number in the sequence field of the arriving segment. 3113 send sequence 3114 This is the next sequence number the local (sending) TCP will 3115 use on the connection. It is initially selected from an 3116 initial sequence number curve (ISN) and is incremented for 3117 each octet of data or sequenced control transmitted. 3119 send window 3120 This represents the sequence numbers which the remote 3121 (receiving) TCP is willing to receive. It is the value of 3122 the window field specified in segments from the remote (data 3123 receiving) TCP. The range of new sequence numbers which may 3124 be emitted by a TCP lies between SND.NXT and SND.UNA + 3125 SND.WND - 1. (Retransmissions of sequence numbers between 3126 SND.UNA and SND.NXT are expected, of course.) 3128 SND.NXT 3129 send sequence 3131 SND.UNA 3132 left sequence 3134 SND.UP 3135 send urgent pointer 3137 SND.WL1 3138 segment sequence number at last window update 3140 SND.WL2 3141 segment acknowledgment number at last window update 3143 SND.WND 3144 send window 3146 socket 3147 An address which specifically includes a port identifier, 3148 that is, the concatenation of an Internet Address with a TCP 3149 port. 3151 Source Address 3152 The source address, usually the network and host identifiers. 3154 SYN 3155 A control bit in the incoming segment, occupying one sequence 3156 number, used at the initiation of a connection, to indicate 3157 where the sequence numbering will start. 3159 TCB 3160 Transmission control block, the data structure that records 3161 the state of a connection. 3163 TCB.PRC 3164 The precedence of the connection. 3166 TCP 3167 Transmission Control Protocol: A host-to-host protocol for 3168 reliable communication in internetwork environments. 3170 TOS 3171 Type of Service, an Internet Protocol field. 3173 Type of Service 3174 An Internet Protocol field which indicates the type of 3175 service for this internet fragment. 3177 URG 3178 A control bit (urgent), occupying no sequence space, used to 3179 indicate that the receiving user should be notified to do 3180 urgent processing as long as there is data to be consumed 3181 with sequence numbers less than the value indicated in the 3182 urgent pointer. 3184 urgent pointer 3185 A control field meaningful only when the URG bit is on. This 3186 field communicates the value of the urgent pointer which 3187 indicates the data octet associated with the sending user's 3188 urgent call. 3190 4. Changes from RFC 793 3192 This document obsoletes RFC 793 as well as RFC 6093 and 6528, which 3193 updated 793. In all cases, only the normative protocol specification 3194 and requirements have been incorporated into this document, and the 3195 informational text with background and rationale has not been carried 3196 in. The informational content of those documents is still valuable 3197 in learning about and understanding TCP, and they are valid 3198 Informational references, even though their normative content has 3199 been incorporated into this document. 3201 The main body of this document was adapted from RFC 793's Section 3, 3202 titled "FUNCTIONAL SPECIFICATION", with an attempt to keep formatting 3203 and layout as close as possible. 3205 The collection of applicable RFC Errata that have been reported and 3206 either accepted or held for an update to RFC 793 were incorporated 3207 (Errata IDs: 573, 574, 700, 701, 1283, 1561, 1562, 1564, 1565, 1571, 3208 1572, 2296, 2297, 2298, 2748, 2749, 2934, 3213, 3300, 3301). Some 3209 errata were not applicable due to other changes (Errata IDs: 572, 3210 575, 1569, 3602). TODO: 3305 3212 Changes to the specification of the Urgent Pointer described in RFC 3213 1122 and 6093 were incorporated. See RFC 6093 for detailed 3214 discussion of why these changes were necessary. 3216 The more secure Initial Sequence Number generation algorithm from RFC 3217 6528 was incorporated. See RFC 6528 for discussion of the attacks 3218 that this mitigates, as well as advice on selecting PRF algorithms 3219 and managing secret key data. 3221 RFC EDITOR'S NOTE: the content below is for detailed change tracking 3222 and planning, and not to be included with the final revision of the 3223 document. 3225 The -00 revision of this document was merely a proposal and rough 3226 plan for updating RFC 793. 3228 The -01 revision of this document incorporates the content of RFC 793 3229 Section 3 titled "FUNCTIONAL SPECIFICATION". Other content from RFC 3230 793 has not been incorporated. The -01 revision of this document 3231 makes some minor formatting changes to the RFC 793 content in order 3232 to convert the content into XML2RFC format and account for left-out 3233 parts of RFC 793. For instance, figure numbering differs and some 3234 indentation is not exactly the same. 3236 The -02 revision of this document incorporates errata that have been 3237 verified: 3239 Errata ID 573: Reported by Bob Braden (note: This errata basically 3240 is just a reminder that RFC 1122 updates 793. Some of the 3241 associated changes are left pending to a separate revision that 3242 incorporates 1122. Bob's mention of PUSH in 793 section 2.8 was 3243 not applicable here because that section was not part of the 3244 "functional specification". Also the 1122 text on the 3245 retransmission timeout also has been updated by subsequent RFCs, 3246 so the change here deviates from Bob's suggestion to apply the 3247 1122 text.) 3248 Errata ID 574: Reported by Yin Shuming 3249 Errata ID 700: Reported by Yin Shuming 3250 Errata ID 701: Reported by Yin Shuming 3251 Errata ID 1283: Reported by Pei-chun Cheng 3252 Errata ID 1561: Reported by Constantin Hagemeier 3253 Errata ID 1562: Reported by Constantin Hagemeier 3254 Errata ID 1564: Reported by Constantin Hagemeier 3255 Errata ID 1565: Reported by Constantin Hagemeier 3256 Errata ID 1571: Reported by Constantin Hagemeier 3257 Errata ID 1572: Reported by Constantin Hagemeier 3258 Errata ID 2296: Reported by Vishwas Manral 3259 Errata ID 2297: Reported by Vishwas Manral 3260 Errata ID 2298: Reported by Vishwas Manral 3261 Errata ID 2748: Reported by Mykyta Yevstifeyev 3262 Errata ID 2749: Reported by Mykyta Yevstifeyev 3263 Errata ID 2934: Reported by Constantin Hagemeier 3264 Errata ID 3213: Reported by EugnJun Yi 3265 Errata ID 3300: Reported by Botong Huang 3266 Errata ID 3301: Reported by Botong Huang 3267 Note: Some verified errata were not used in this update, as they 3268 relate to sections of RFC 793 elided from this document. These 3269 include Errata ID 572, 575, and 1569. 3270 Note: Errata ID 3602 was not applied in this revision as it is 3271 duplicative of the 1122 corrections. 3272 There is an errata 3305 currently reported that need to be 3273 verified, held, or rejected by the ADs; it is addressing the same 3274 issue as draft-gont-tcpm-tcp-seq-validation and was not attempted 3275 to be applied to this document. 3277 Not related to RFC 793 content, this revision also makes small tweaks 3278 to the introductory text, fixes indentation of the pseudoheader 3279 diagram, and notes that the Security Considerations should also 3280 include privacy, when this section is written. 3282 The -03 revision of this document revises all discussion of the 3283 urgent pointer in order to comply with RFC 6093, 1122, and 1011. 3284 Since 1122 held requirements on the urgent pointer, the full list of 3285 requirements was brought into an appendix of this document, so that 3286 it can be updated as-needed. 3288 The -04 revision of this document includes the ISN generation changes 3289 from RFC 6528. 3291 The -05 revision of this document incorporates MSS requirements and 3292 definitions from RFC 879, 1122, and 6691, as well as option-handling 3293 requirements from RFC 1122. 3295 TODO: Incomplete list of planned changes - these need to be added to 3296 and made more specific, as the document proceeds: 3298 1. incorporate 1122 additions 3299 2. point to major additional docs like 1323bis and 5681 3300 3. incorporate relevant parts of 3168 (ECN) 3301 4. incorporate Fernando's new number-checking fixes (if past the 3302 IESG in time) 3303 5. point to PMTUD? 3304 6. point to 5461 (soft errors) 3305 7. mention 5961 state machine option 3306 8. mention 6161 (reducing TIME-WAIT) 3307 9. incorporate 6429 (ZWP/persist) 3308 10. look at Tony Sabatini suggestion for describing DO field 3309 11. clearly specify treatment of reserved bits (see TCPM thread on 3310 EDO draft April 25, 2014) 3311 12. look at possible mention of draft-minshall-nagle (e.g. as in 3312 Linux) 3313 13. make sure that clarifications in RFC 1011 are captured 3314 14. per TCPM discussion, discussion of checking reserved bits may 3315 need to be altered from 793 3316 15. MSL acronymn is defined multiple times 3318 5. IANA Considerations 3320 This memo includes no request to IANA. Existing IANA registries for 3321 TCP parameters are sufficient. 3323 TODO: check whether entries pointing to 793 and other documents 3324 obsoleted by this one should be updated to point to this one instead. 3326 6. Security and Privacy Considerations 3328 TODO 3330 See RFC 6093 [7] for discussion of security considerations related to 3331 the urgent pointer field. 3333 Editor's Note: Scott Brim mentioned that this should include a 3334 PERPASS/privacy review. 3336 7. Acknowledgements 3338 This document is largely a revision of RFC 793, which Jon Postel was 3339 the editor of. Due to his excellent work, it was able to last for 3340 three decades before we felt the need to revise it. 3342 Andre Oppermann was a contributor and helped to edit the first 3343 revision of this document. 3345 We are thankful for the assistance of the IETF TCPM working group 3346 chairs: 3348 Michael Scharf 3349 Yoshifumi Nishida 3350 Pasi Sarolahti 3352 On the TCPM mailing list, and at the IETF 88 meeting in Vancouver, 3353 helpful comments, critiques, and reviews were received from (listed 3354 alphebetically): David Borman, Yuchung Cheng, Martin Duke, Kevin 3355 Lahey, Kevin Mason, Matt Mathis, Hagen Paul Pfeifer, Anthony 3356 Sabatini, Joe Touch, Reji Varghese, Lloyd Wood, and Alex Zimmermann. 3358 This document includes content from errata that were reported by 3359 (listed chronologically): Yin Shuming, Bob Braden, Morris M. Keesan, 3360 Pei-chun Cheng, Constantin Hagemeier, Vishwas Manral, Mykyta 3361 Yevstifeyev, EungJun Yi, Botong Huang. 3363 8. References 3365 8.1. Normative References 3367 [1] Bradner, S., "Key words for use in RFCs to Indicate 3368 Requirement Levels", BCP 14, RFC 2119, March 1997. 3370 8.2. Informative References 3372 [2] Postel, J., "Transmission Control Protocol", STD 7, RFC 3373 793, September 1981. 3375 [3] Braden, R., "Requirements for Internet Hosts - 3376 Communication Layers", STD 3, RFC 1122, October 1989. 3378 [4] Mogul, J. and S. Deering, "Path MTU discovery", RFC 1191, 3379 November 1990. 3381 [5] Lahey, K., "TCP Problems with Path MTU Discovery", RFC 3382 2923, September 2000. 3384 [6] Mathis, M. and J. Heffner, "Packetization Layer Path MTU 3385 Discovery", RFC 4821, March 2007. 3387 [7] Gont, F. and A. Yourtchenko, "On the Implementation of the 3388 TCP Urgent Mechanism", RFC 6093, January 2011. 3390 [8] Gont, F. and S. Bellovin, "Defending against Sequence 3391 Number Attacks", RFC 6528, February 2012. 3393 [9] Borman, D., "TCP Options and Maximum Segment Size (MSS)", 3394 RFC 6691, July 2012. 3396 [10] Duke, M., Braden, R., Eddy, W., Blanton, E., and A. 3397 Zimmermann, "A Roadmap for Transmission Control Protocol 3398 (TCP) Specification Documents", RFC 7414, February 2015. 3400 Appendix A. TCP Requirement Summary 3402 This section is adapted from RFC 1122. 3404 TODO: this needs to be seriously redone, to use 793bis section 3405 numbers instead of 1122 ones, and all 1122 requirements need to be 3406 reflected in 793bis text. 3408 RFC EDITOR'S NOTE: 793bis in the heading below should be replaced by 3409 the number of this RFC 3411 | | | | |S| | 3412 | | | | |H| |F 3413 | | | | |O|M|o 3414 | | |S| |U|U|o 3415 | | |H| |L|S|t 3416 | |M|O| |D|T|n 3417 | |U|U|M| | |o 3418 | |S|L|A|N|N|t 3419 |RFC1122 |T|D|Y|O|O|t 3420 FEATURE |SECTION | | | |T|T|e 3421 -------------------------------------------------|--------|-|-|-|-|-|-- 3422 | | | | | | | 3423 Push flag | | | | | | | 3424 Aggregate or queue un-pushed data |4.2.2.2 | | |x| | | 3425 Sender collapse successive PSH flags |4.2.2.2 | |x| | | | 3426 SEND call can specify PUSH |4.2.2.2 | | |x| | | 3427 If cannot: sender buffer indefinitely |4.2.2.2 | | | | |x| 3428 If cannot: PSH last segment |4.2.2.2 |x| | | | | 3429 Notify receiving ALP of PSH |4.2.2.2 | | |x| | |1 3430 Send max size segment when possible |4.2.2.2 | |x| | | | 3431 | | | | | | | 3432 Window | | | | | | | 3433 Treat as unsigned number |4.2.2.3 |x| | | | | 3434 Handle as 32-bit number |4.2.2.3 | |x| | | | 3435 Shrink window from right |4.2.2.16| | | |x| | 3436 Robust against shrinking window |4.2.2.16|x| | | | | 3437 Receiver's window closed indefinitely |4.2.2.17| | |x| | | 3438 Sender probe zero window |4.2.2.17|x| | | | | 3439 First probe after RTO |4.2.2.17| |x| | | | 3440 Exponential backoff |4.2.2.17| |x| | | | 3441 Allow window stay zero indefinitely |4.2.2.17|x| | | | | 3442 Sender timeout OK conn with zero wind |4.2.2.17| | | | |x| 3443 | | | | | | | 3444 Urgent Data | | | | | | | 3445 Pointer indicates first non-urgent octet |4.2.2.4 |x| | | | | 3446 Arbitrary length urgent data sequence |4.2.2.4 |x| | | | | 3447 Inform ALP asynchronously of urgent data |4.2.2.4 |x| | | | |1 3448 ALP can learn if/how much urgent data Q'd |4.2.2.4 |x| | | | |1 3449 | | | | | | | 3450 TCP Options | | | | | | | 3451 Receive TCP option in any segment |4.2.2.5 |x| | | | | 3452 Ignore unsupported options |4.2.2.5 |x| | | | | 3453 Cope with illegal option length |4.2.2.5 |x| | | | | 3454 Implement sending & receiving MSS option |4.2.2.6 |x| | | | | 3455 Send MSS option unless 536 |4.2.2.6 | |x| | | | 3456 Send MSS option always |4.2.2.6 | | |x| | | 3457 Send-MSS default is 536 |4.2.2.6 |x| | | | | 3458 Calculate effective send seg size |4.2.2.6 |x| | | | | 3459 | | | | | | | 3460 TCP Checksums | | | | | | | 3461 Sender compute checksum |4.2.2.7 |x| | | | | 3462 Receiver check checksum |4.2.2.7 |x| | | | | 3463 | | | | | | | 3464 ISN Selection | | | | | | | 3465 Include a clock-driven ISN generator component |4.2.2.9 |x| | | | | 3466 Secure ISN generator with a PRF component | N/A | |x| | | | 3467 | | | | | | | 3468 Opening Connections | | | | | | | 3469 Support simultaneous open attempts |4.2.2.10|x| | | | | 3470 SYN-RCVD remembers last state |4.2.2.11|x| | | | | 3471 Passive Open call interfere with others |4.2.2.18| | | | |x| 3472 Function: simultan. LISTENs for same port |4.2.2.18|x| | | | | 3473 Ask IP for src address for SYN if necc. |4.2.3.7 |x| | | | | 3474 Otherwise, use local addr of conn. |4.2.3.7 |x| | | | | 3475 OPEN to broadcast/multicast IP Address |4.2.3.14| | | | |x| 3476 Silently discard seg to bcast/mcast addr |4.2.3.14|x| | | | | 3477 | | | | | | | 3478 Closing Connections | | | | | | | 3479 RST can contain data |4.2.2.12| |x| | | | 3480 Inform application of aborted conn |4.2.2.13|x| | | | | 3481 Half-duplex close connections |4.2.2.13| | |x| | | 3482 Send RST to indicate data lost |4.2.2.13| |x| | | | 3483 In TIME-WAIT state for 2xMSL seconds |4.2.2.13|x| | | | | 3484 Accept SYN from TIME-WAIT state |4.2.2.13| | |x| | | 3485 | | | | | | | 3486 Retransmissions | | | | | | | 3487 Jacobson Slow Start algorithm |4.2.2.15|x| | | | | 3488 Jacobson Congestion-Avoidance algorithm |4.2.2.15|x| | | | | 3489 Retransmit with same IP ident |4.2.2.15| | |x| | | 3490 Karn's algorithm |4.2.3.1 |x| | | | | 3491 Jacobson's RTO estimation alg. |4.2.3.1 |x| | | | | 3492 Exponential backoff |4.2.3.1 |x| | | | | 3493 SYN RTO calc same as data |4.2.3.1 | |x| | | | 3494 Recommended initial values and bounds |4.2.3.1 | |x| | | | 3495 | | | | | | | 3496 Generating ACK's: | | | | | | | 3497 Queue out-of-order segments |4.2.2.20| |x| | | | 3498 Process all Q'd before send ACK |4.2.2.20|x| | | | | 3499 Send ACK for out-of-order segment |4.2.2.21| | |x| | | 3500 Delayed ACK's |4.2.3.2 | |x| | | | 3501 Delay < 0.5 seconds |4.2.3.2 |x| | | | | 3502 Every 2nd full-sized segment ACK'd |4.2.3.2 |x| | | | | 3503 Receiver SWS-Avoidance Algorithm |4.2.3.3 |x| | | | | 3504 | | | | | | | 3505 Sending data | | | | | | | 3506 Configurable TTL |4.2.2.19|x| | | | | 3507 Sender SWS-Avoidance Algorithm |4.2.3.4 |x| | | | | 3508 Nagle algorithm |4.2.3.4 | |x| | | | 3509 Application can disable Nagle algorithm |4.2.3.4 |x| | | | | 3510 | | | | | | | 3511 Connection Failures: | | | | | | | 3512 Negative advice to IP on R1 retxs |4.2.3.5 |x| | | | | 3513 Close connection on R2 retxs |4.2.3.5 |x| | | | | 3514 ALP can set R2 |4.2.3.5 |x| | | | |1 3515 Inform ALP of R1<=retxs inform ALP |4.2.3.9 | |x| | | | 3540 Dest. Unreach (0,1,5) => abort conn |4.2.3.9 | | | | |x| 3541 Dest. Unreach (2-4) => abort conn |4.2.3.9 | |x| | | | 3542 Source Quench => slow start |4.2.3.9 | |x| | | | 3543 Time Exceeded => tell ALP, don't abort |4.2.3.9 | |x| | | | 3544 Param Problem => tell ALP, don't abort |4.2.3.9 | |x| | | | 3545 | | | | | | | 3546 Address Validation | | | | | | | 3547 Reject OPEN call to invalid IP address |4.2.3.10|x| | | | | 3548 Reject SYN from invalid IP address |4.2.3.10|x| | | | | 3549 Silently discard SYN to bcast/mcast addr |4.2.3.10|x| | | | | 3550 | | | | | | | 3551 TCP/ALP Interface Services | | | | | | | 3552 Error Report mechanism |4.2.4.1 |x| | | | | 3553 ALP can disable Error Report Routine |4.2.4.1 | |x| | | | 3554 ALP can specify TOS for sending |4.2.4.2 |x| | | | | 3555 Passed unchanged to IP |4.2.4.2 | |x| | | | 3556 ALP can change TOS during connection |4.2.4.2 | |x| | | | 3557 Pass received TOS up to ALP |4.2.4.2 | | |x| | | 3558 FLUSH call |4.2.4.3 | | |x| | | 3559 Optional local IP addr parm. in OPEN |4.2.4.4 |x| | | | | 3560 -------------------------------------------------|--------|-|-|-|-|-|-- 3562 FOOTNOTES: (1) "ALP" means Application-Layer program. 3564 Author's Address 3566 Wesley M. Eddy (editor) 3567 MTI Systems 3568 US 3570 Email: wes@mti-systems.com