Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Analysis of TCP protocol

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Network Security >

Share

Shulou(Shulou.com)06/01 Report--

TCP (Transmission ControlProtocol Transmission Control Protocol) is a connection-oriented, reliable, byte-stream-based transport layer communication protocol defined by RFC 793of IETF. In the simplified computer network OSI model, it performs the functions specified by the fourth transport layer, and the user Datagram Protocol (UDP) is another important transport protocol in the same layer. In the Internet Protocol Family (Internetprotocol suite), the TCP layer is the middle layer above the IP layer and below the application layer. Reliable, pipe-like connections are often needed between the application layers of different hosts, but the IP layer does not provide such a flow mechanism, but provides unreliable packet exchange.

TCP header format

-Source Port is the source port, 16 bits.

-Destination Port is the destination port, 16 bits.

-Sequence Number is the sequence number of the first byte in the packet sent, 32 bits.

-Acknowledgment Number is the confirmation serial number, 32 bits.

-Data Offset is the data offset, 4 bits, and the value of this field is the length of the TCP header (including options) divided by 4.

-Flag bit: 6 bits. URG indicates that the UrgentPointer field is meaningful:

ACK indicates that the AcknowledgmentNumber field is meaningful.

PSH indicates Push function, and RST indicates reset TCP connection

SYN represents a SYN message (used when establishing a TCP connection)

FIN indicates that there is no data to send (used when closing a TCP connection)

Window represents the free space of the receive buffer, 16 bits, which is used to tell the TCP connection peer the maximum big data length it can receive.

-Checksum is the checksum, 16 bits.

-Urgent Pointers is an emergency pointer, 16 bits. This field is meaningful only if the URG flag bit is set, indicating the offset of the emergency data from the serial number (the value of the Sequence Number field).

Connection establishment

TCP is the transport layer protocol in the Internet, which uses the three-way handshake protocol to establish a connection. When the active party issues a SYN connection request, wait for the other party to reply.

SYN+ACK, and finally perform an ACK confirmation on the other party's SYN. This method of establishing a connection prevents incorrect connections, and the flow control protocol used by TCP is a variable-size sliding window protocol.

The process of the TCP three-way handshake is as follows:

The client sends a SYN (SEQ=x) message to the server and enters the SYN_SEND state.

The server receives the SYN message, responds to a SYN (SEQ=y) ACK (ACK=x+1) message, and enters the SYN_RECV state.

The client receives the SYN message from the server, responds to an ACK (ACK=y+1) message, and enters the Established state.

With the completion of the three-way handshake, the TCP client and server have successfully established a connection and can begin to transfer data.

Connection termination

Establishing a connection requires a three-way handshake, while terminating a connection requires a four-way handshake, which is caused by the half-close of TCP. The specific process is shown in the following figure.

(1) an application process first calls close, saying that the end performs "active shutdown" (active close). The TCP on this end then sends a FIN section, indicating that the data has been sent.

(2) the peer receiving the FIN performs a "passive shutdown" (passiveclose), and the FIN is confirmed by the TCP.

Note: the reception of FIN is also passed to the receiving application process as a file Terminator (end-of-file), after any other data that has been queued for the application process to receive, because the reception of FIN means that the receiving application process has no additional data to receive on the corresponding connection.

(3) after a period of time, the application process that receives this file Terminator will call close to close its socket. This causes its TCP to send a FIN as well.

(4) the original sender TCP that receives the final FIN (that is, the end that performs the active shutdown) confirms the FIN.

Since you need a FIN and an ACK in each direction, you usually need four sections.

Window confirmation

One of the functions of TCP is to ensure that each segment reaches its destination. The TCP service at the destination host acknowledges the received data and sends an acknowledgement message to the source application.

Configure TCP

Modify the timeout for establishing a TCP connection

The establishment of a TCP connection requires three handshakes: the active end sends the SYN message first, passively puts the response to the SYN+ACK message, and then the active end responds to the ACK.

After the active end sends SYN, if the passive end does not respond to the SYN+ACK message, the active end will continue to retransmit the SYN message until it exceeds a certain number of retransmissions or timeouts.

After the active end sends the SYN, the passive end responds to the SYN+ACK message, but the active end no longer replies to the ACK, and the passive end will continue to retransmit until a certain number of retransmissions or timeouts are exceeded. (this happens in SYN messages.)

You can configure the timeout for SYN messages (the maximum time it takes to send a SYN message to a successful three-way handshake), that is, the timeout for establishing an TCP connection.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Network Security

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report