TCP/IP Detailed Volume 1: Protocol 17th, 18 TCP: Transmission Control Protocol (2)-Reading notes

Source: Internet
Author: User

Chapter Review:

"TCP/IP Detailed Volume 1: Agreement" 1th Chapter Overview-Reading Notes

"TCP/IP Detailed Volume 1: Protocol" chapter 2nd link layer-Reading notes

"TCP/IP Detailed Volume 1: Protocol" 3rd IP: Internet Protocol (1)-Reading notes

"TCP/IP Detailed Volume 1: Protocol" 3rd IP: Internet Protocol (2)-Reading notes

"TCP/IP Detailed Volume 1: Protocol" 4th ARP: Address Resolution Protocol-Reading notes

"TCP/IP Detailed Volume 1: Protocol" chapter 5th RARP: Reverse Address Resolution Protocol-Reading notes

"TCP/IP Detailed Volume 1: Protocol" chapter 6th icmp:internet Control Message Protocol-reading notes

"TCP/IP Detailed Volume 1: Protocol" 11th UDP: User Datagram Protocol-reading notes

TCP/IP Detailed Volume 1: Protocol 17th, 18 TCP: Transmission Control Protocol (1)-Reading notes

TCP/IP Detailed Volume 1: Protocol 17th, 18 TCP: Transmission Control Protocol (2)-Reading notes

3. Timeout for connection establishment

There are a number of situations that prevent connections from being established. One scenario is that the server host is not in a normal state .

4. Maximum message segment length

The maximum segment Length (MSS) indicates the length of the maximum block data transmitted to the other end by TCP. When a connection is established, both sides of the connection are notified of their respective MSS.

When a connection is established, each party has the MSS option to advertise its expected reception (MSS option can only appear in the SYN message segment). If one party does not receive the MSS value from the other, MSS will default to 536 bytes (this default allows a 20-byte IP header and a 20-byte TCP header to fit the 576-byte IP datagram).

Attention:

(1) Generally speaking, if no fragmentation occurs, the larger the MSS the better. Larger segments allow more data to be transmitted per packet segment, and higher network utilization relative to IP and TCP headers.

(2) when TCP sends a SYN, either because a local application process wants to initiate a connection, or because the host on the other end receives a connection request, it can The MSS value is set to the MTU length on the out-of-interface minus the fixed IP header and TCP first ministerial degree.

(3) If the destination IP address is "non-local (non-local)", MSS usually has a default value of 536.

Description: The method of distinguishing whether the address is local or non-local is local if the network number and subnet number of the destination IP address are the same as the native, if the destination IP address has the same network number as the native and the subnet number is different, it may be local or non-local.

(4) MSS allows the host to limit the length of datagrams sent to the other end. Plus the host can control how long it sends datagrams, which makes it possible to connect to a host on a network with a smaller MTU to avoid fragmentation.

Here is an example of a book (lazy, no setting)

Host Sun initiates a TCP connection to slip and uses the tcpdump command to observe the message segment:

Description

(1)Sun sends a message segment that cannot exceed 256 bytes of data because slip has told it that the MSS value is 256. (Second red box)

(2)slip knows that the MTU length of the outgoing interface is 296, so even though Sun has already told its MSS to be 1460 (the first red box), it will not send a segment of more than 256 bytes of data to avoid segmenting the data.

(3) If both ends of the host are connected to the Ethernet, the use of 536 MSS, but the intermediary network with 296 MTU, the same will appear segmented.

5. Half-shutdown of TCP

TCP provides the ability for one end of a connection to receive data from the other end after it has been sent, that is, half-closed.

Note: very few applications use it, and if you want to use this feature, you need a programming interface to provide a way to illustrate.

An example is given below:

This means: The customer ends sending data (fin is sent) and the server sends an ACK to confirm that the data can still be sent to the customer (the red box in the picture).

6. Status change diagram of TCP

The following diagram I did not study carefully, it should contain all the rules about initiating and terminating TCP connections.

(1)2MSL waiting status

The TIME_WAIT state is also known as a 2MSL wait state. Each specific TCP implementation must select a message segment Maximum lifetime MSL (Maximum Segment Lifetime). It is the maximum time that any message segment is discarded before it is in the network.

Note: The MSL is a limited time, and we know that the TCP segment is transmitted over the network with an IP datagram, and that the IP datagram is limited to its lifetime by the TTL field. RFC 793 indicates that the MSL is 2 minutes. The common values in the implementation are 30 seconds, 1 minutes, or 2 minutes.

For a given MSL value, the principle is that when TCP performs an active shutdown, and then returns the last ACK, the connection must remain in the TIME_WAIT state for a time of twice times the MSL. This allows TCP to send the final ACK again in case the ACK is lost (the other end times out and the last fin is sent again).

Description

1) It is normal for the customer to perform an active shutdown and enter the time_wait. The server typically performs a passive shutdown and does not enter the TIME_WAIT state.

2) TCP connection during 2MSL wait, this connected socket (the client's IP address and port number, the server's IP address and port number) can no longer be used. This connection can only be used after the end of 2MSL.

(2) The concept of quiet time

If a host in the 2MSL waiting port fails, it restarts in MSL seconds and immediately uses the socket at 2MSL before the failure to establish a new connection. Packets that are late from the connection before the failure are mistakenly treated as belonging to a new connected message segment after a reboot.

To prevent this, RFC 793 states that TCP cannot establish any connections in the MSL seconds after a reboot, known as quiet Time (quiet).

(3)fin_wait_2 status

As shown in the figure above: fin_wait_2 status, the customer has already issued FIN and the other end has confirmed it.

Unless the customer sets a semi-shutdown, it waits for the application layer at the other end to realize that it has received a file Terminator description and sends us a fin to close the connection. Only in this way will our side enter the TIME_WAIT state from the fin_wait_2 state.

7. Reset Message Segment

The RST bits in the TCP header are used for "reset", and TCP emits a reset message segment whenever a message segment is sent to a "base connection" error.

Description:A reference connection is a connection indicated by the destination IP address and port number, as well as the source IP address and port number.

(1) connection request to a port that does not exist

A common situation in which a reset occurs is when a connection request arrives and no process is listening to the destination port.

Note: for UDP, when a data is reported to the destination port, the port is not in use, it produces an ICMP Port unreachable information, and for TCP, a reset is used.

The figure means that the host BSDI sends a SYN to port 20000 of SVR4, and then SVR4 tells BSDI a reset connection information.

(2) abnormal termination of a connection

The normal way to terminate a connection is for one party to send fin. This is also known as ordered release , because Fin is sent after all queued data has been sent, and there is no data loss under normal circumstances. But it is also possible to send a reset message segment instead of fin to release a connection halfway. This is also known as an exception release .

Terminating an exception a connection has two advantages for an application:

1) discard any outgoing data and send the reset message segment immediately;

2) The receiver of the RST distinguishes between an abnormal shutdown or a graceful shutdown at the other end.

Special attention: The RST message segment does not cause any response at the other end, and the other end does not confirm at all. The party receiving the RST terminates the connection and notifies the application layer that the connection is reset.

(3) detect half-open connection

If a party has closed or abnormally terminated the connection and the other party does not yet know, the TCP connection is called semi-open .

Description

1) A host exception at either end can cause a semi-open connection. As long as the data is not transferred on the semi-open connection, the side that is still connected does not detect that the other party has an exception.

2) Another common reason for semi-open connections is when the client host suddenly shuts down instead of the normal end customer application.

8. Open at the same time

It is possible for two applications to actively open each other at the same time, albeit with minimal likelihood of occurring. Each party must send a SYN, and these SYN must be passed to each other. This requires each party to use a port that is known to each other as a local port, known as opening simultaneously.

TCP only establishes one connection instead of two connections for simultaneous opening. When the appearance is open simultaneously:

Both ends send the SYN almost simultaneously and enter the Syn_sent state. When each end receives a SYN, the state changes to SYN_RCVD, and they both send a SYN and confirm the received Syn. When both sides receive the SYN and the corresponding ACK, the state changes to established.

Attention:

(1) an open connection needs to Exchange 4 message segments , one more than the normal three handshake.

(2) for simultaneous open connections, we do not refer to any end as a customer or server, because each end is both a client and a server.

9. Close at the same time

It is also possible for both parties to perform a proactive shutdown, and TCP also allows the shutdown at the same time.

The simultaneous shutdown process is:

(1) when the application layer issues a close command, both ends change from established to fin_wait_1. This will cause each side to send a fin, two fin after the network transmission, respectively, to reach the other end.

(2) after receiving fin, the status is changed from Fin_wait_1 to closing and the final ACK is sent.

(3) when the last ACK is received, the state changes to time_wait.

Note: simultaneous shutdown and normal shutdown are the same number of message segment exchanges.

10. TCP Options

The TCP header can contain the Options section.

Option Description:

(1) the start of each option is a 1-byte kind field that describes the type of option.

(2)the option for kind fields 0 and 1 only accounts for 1 bytes. The other options are the Len byte after the kind byte, which indicates the length of the total length, including the kind byte and the Len byte.

(3) The reason for setting the No Action option is to allow the sender to populate the field as a multiple of 4 bytes.

11, the design of TCP server

Most TCP server processes are concurrent. When a new connection request arrives at the server, the server accepts the request and invokes a new process to process the new client request.

(1) TCP Server port number

When different processes connect to the server, the server port number is the same.

(2) Limited local IP address

When a local IP address is restricted, connection requests from different links may be rejected by the TCP kernel.

(3) limit the remote IP address

The server must not indicate a remote socket, wait for the connection request to arrive, and then check the client's IP address and port number.

Figure 18-22 (This picture I have not read) summarizes the three types of address bindings that are made when a TCP server is connected. In three cases, the Lport is a well-known port for the server, and the local IP must be the IP address of a native interface.

(4) incoming connection request queue

A concurrent server calls a new process to process each client request, so the server in the passive connection request should always be ready to process the next incoming connection request. However, it is still possible to reach multiple connection requests when the server is creating a new process, or when the operating system is busy processing the higher-priority processes.

The following rules are used in the TCP implementation of Berkeley:

1) waiting for one end of the connection request to have a fixed-length connection queue in which the connection has been accepted by TCP (that is, three handshake has been completed), but not yet accepted by the application layer.

Note: TCP accepts a connection to put it into this queue, and the application layer accepts the connection to move it out of the queue.

2) The application layer will indicate the maximum length of the queue, which is often referred to as the backlog value. Its value range is an integer between 0~5, including 0 and 5 (most applications will indicate this value as 5).

3) When a connection request (SYN) arrives, TCP uses an algorithm that determines whether to receive the connection based on the number of connections in the current connection queue.

4) If there is space in the connection queue for the endpoint of the TCP listener for the new connection request, the TCP module confirms the SYN and completes the connection establishment.

Attention:

(i) the application layer will not be aware of this new connection until it receives a third message segment in the three handshake.

(ii) when the client process is actively opened but the server's application layer is unaware of the new connection, it may assume that the server process is ready to receive the data. If so, the server's TCP only puts the received data into the buffer queue.

5) If there is no space in the connection queue for a new connection request, TCP will ignore the received SYN and not send back any segments (that is, do not send back the RST). If the application tier cannot accept connections that have been accepted by TCP in a timely manner, these connections may fill the entire connection queue, and the client's active opening will eventually time out.

TCP/IP Detailed Volume 1: Protocol 17th, 18 TCP: Transmission Control Protocol (2)-Reading notes

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.