Optimization method for solving TCP connection reset caused by multiple identical SYN packets

By using the HASH table and spin lock mechanism during the TCP handshake phase, the TCP connection reset problem caused by multiple identical SYN packets is solved to ensure TCP connection stability and reliability.

CN120238563AActive Publication Date: 2025-07-01KYLIN CORP
View PDF 5 Cites 0 Cited by

Patent Information

Application Number
CN202510713713.0
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-05-30
Publication Date
2025-07-01
Estimated Expiration
2045-05-30

AI Technical Summary

Technical Problem

During the TCP handshake, TCP connection reset issues caused by multiple identical SYN packets, resulting in connection interruption.

Method used

Using the HASH table and spin lock mechanism, the connection information of the processed SYN packet is recorded, and the duplicate SYN packet is judged through hash calculation, and only the first SYN packet is processed to avoid multiple responses to the SYN-ACK packet.

Benefits of technology

It effectively avoids TCP connection reset, ensures that the three-handshake is completed smoothly, and improves the stability and reliability of TCP connection.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120238563A_ABST
    Figure CN120238563A_ABST
Patent Text Reader

Abstract

The invention discloses an optimization method for solving TCP (Transmission Control Protocol) connection reset caused by multiple identical SYN packets, which comprises the following steps of: storing a first HASH table and a second HASH table, the first HASH table comprising a plurality of linked lists, and the second HASH table comprising a plurality of spin locks; the client sends a to-be-processed SYN packet to the server; the server receives a to-be-processed SYN packet and obtains a corresponding linked list and a spin lock; the server side traverses the corresponding linked list and compares the connection information; if the same connection information exists, discarding the SYN packet to be processed and releasing the spin lock; if the same connection information does not exist, marking the to-be-processed SYN packet as a processed SYN packet, storing the connection information to a corresponding linked list, and releasing the spin lock; the server sends the obtained SYN-ACK packet to the client side; the client side receives the SYN-ACK packet; the client obtains an ACK packet and sends the ACK packet to the server; and the server receives the ACK packet.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the technical field of connection optimization, and specifically to an optimization method for solving TCP connection reset caused by multiple identical SYN packets. Background Art

[0002] During the handshake process of the TCP protocol, due to the complexity and uncertainty of the environment, various message interaction situations may occur. For example, when the TCP performs the first handshake, if the server receives two or more identical SYN messages sent by the client at the same time (such as when the communication parties are configured in the bond3 mode), then according to the logic of the current Linux protocol stack, the server will respond with a SYN-ACK message to each SYN message sent by the client. When the server assembles the SYN-ACK message, to avoid attacks, it will randomly generate the sequence number of the message. Usually, the source of this sequence number is the quadruple and the timestamp. For the same connection in the above scenario, the quadruple is the same, but the timestamps of the SYN-ACK messages generated by the server are different, so the finally generated sequence numbers will also be different. Subsequently, the client will also respond with an ACK message to each SYN-ACK message sent by the server. Here, according to the requirements of the TCP protocol, the acknowledgment number of the ACK message is the sequence number of the SYN-ACK message + 1. When the server receives these ACK messages, if the acknowledgment numbers of the ACK messages do not match, the TCP connection will be reset and the connection will be interrupted. Summary of the Invention

[0003] To solve the above problems, the purpose of the present invention is to provide an optimization method for solving TCP connection reset caused by multiple identical SYN packets. When receiving multiple identical SYN packets, the server appropriately processes the multiple identical SYN packets so that it will not send multiple different SYN-ACK packets to respond to the client, avoiding the connection reset problem caused by identical SYN packets.

[0004] An optimization method for solving TCP connection reset caused by multiple identical SYN packets according to the present invention. A TCP connection between the server and the client needs to go through a handshake stage. The optimization method is used for the server and the client to determine and process the SYN packets to be processed during the handshake stage; The optimization method includes the following steps: Step S0: Use a structure to save the first HASH table and the second HASH table. The first HASH table stores multiple linked lists; the linked lists are used to store the connection information of the processed SYN packets, and the second HASH table stores multiple spin locks; each spin lock corresponds to protecting a linked list in the first HASH table; Step S1: The client sends the SYN packet to be processed to the server; Step S2: The thread of the server obtains the HASH value based on the SYN packet to be processed sent by the client, retrieves the linked list corresponding to the HASH value from the first HASH table, and obtains the corresponding spin lock from the second HASH table; Step S3: After the thread of the server obtains the corresponding spin lock from the second HASH table, the thread of the server sequentially extracts the connection information of the processed SYN packets from the linked list corresponding to the HASH value and compares it with the connection information of the SYN packet to be processed; Step S4: If there is connection information of a processed SYN packet in the linked list corresponding to the HASH value that is the same as the connection information of the SYN packet to be processed, the thread of the server discards the SYN packet to be processed, no longer processes the SYN packet to be processed, and releases the corresponding spin lock; Step S5: If there is no connection information of a processed SYN packet in the linked list corresponding to the HASH value that is the same as the connection information of the SYN packet to be processed, the thread of the server marks the SYN packet to be processed as a processed SYN packet, stores the connection information of the processed SYN packet in the linked list corresponding to the HASH value, then releases the corresponding spin lock, and then enters Step S6 to continue processing the marked processed SYN packet; Step S6: The thread of the server obtains a SYN-ACK packet based on the processed SYN packet and sends the SYN-ACK packet to the client; Step S7: The client receives the SYN-ACK packet sent by the thread of the server; Step S8: The client processes the SYN-ACK packet to obtain an ACK packet and sends the ACK packet to the thread of the server; Step S9: The thread of the server receives the ACK packet, and the handshake phase ends.

[0005] A further improvement of the present invention is that Step S2 includes the following steps: Step S21: The thread of the server receives the SYN packet to be processed sent by the client; Step S22: The thread of the server obtains the connection information of the SYN packet to be processed based on the SYN packet to be processed; Step S23: The thread of the server performs HASH calculation based on the connection information of the SYN packet to be processed to obtain the HASH value corresponding to the SYN packet to be processed; Step S24: The thread of the server retrieves the linked list corresponding to the HASH value from the first HASH table based on the HASH value corresponding to the SYN packet to be processed; Step S25: The thread of the server finds the corresponding spin lock from the second HASH table based on the HASH value and requests to obtain the corresponding spin lock.

[0006] A further improvement of the present invention lies in that in step S9, after the thread of the server receives the ACK packet, it further determines whether the ACK packet is legal; if the ACK packet is legal, it indicates that the handshake between the client and the server is successful, and the client and the server establish a TCP connection.

[0007] A further improvement of the present invention lies in that after the client and the server establish a TCP connection, the server re-obtains the corresponding spin lock from the second HASH table based on the HASH value obtained in step S2, and after re-obtaining the spin lock, removes the connection information of the processed SYN packet corresponding to the HASH value from the linked list corresponding to the HASH value. After completion, the corresponding spin lock is released.

[0008] A further improvement of the present invention lies in that the connection information includes quadruple information and network namespace information.

[0009] Advantages of the present invention: In the process of TCP connection, the present invention records the processing of the SYN packet in the first handshake into the linked list of the first HASH table, so as to determine the processing logic of the subsequent SYN packets with the same content that may be received, rather than repeatedly processing all received SYN packets.

[0010] When it is queried that there is already a SYN packet with the same quadruple in the first HASH table, it can be judged that the SYN packets with the same content have been or are being processed. Then, other SYN packets with the same content except the first SYN packet will not be processed at all. Correspondingly, the SYN-ACK packets corresponding to the subsequent SYN packets with the same content will not be sent either. Thus, the sequence number and acknowledgment number of the TCP three-way handshake will not be destroyed, and the TCP connection will be successfully completed. Without this mechanism, the TCP connection may be reset due to the mismatch of the sequence number and acknowledgment number. Description of the drawings

[0011] In order to more clearly illustrate the specific embodiments of the present invention or the technical solutions in the prior art, the following will briefly introduce the drawings required for the description of the specific embodiments or the prior art. Obviously, the following drawings are some embodiments of the present invention. For those of ordinary skill in the art, without creative efforts, other drawings can also be obtained based on these drawings.

[0012] Figure 1 It is a flow diagram of the present invention. Specific embodiments

[0013] Combined with the embodiments of the present invention, the technical solutions in the embodiments of the present invention are clearly and completely described. Many specific details are set forth in the following description in order to fully understand the present invention. However, the present invention may also be implemented in other ways different from those described herein. Those skilled in the art may make similar extensions without departing from the connotation of the present invention. Therefore, the present invention is not limited by the specific embodiments disclosed below.

[0014] The object of the present invention is to provide an optimization method for solving the TCP connection reset caused by multiple identical SYN packets. When multiple identical SYN packets are received, the server properly processes the multiple identical SYN packets so that it will not send multiple different SYN-ACK packets to respond to the client.

[0015] An optimization method for solving the TCP connection reset caused by multiple identical SYN packets in the present invention is as Figure 1 shown, and the optimization method is used for the server and the client to judge and process the SYN packets to be processed during the handshake phase.

[0016] The optimization method includes the following steps: Step S0: Use a structure to save the first HASH table and the second HASH table. The server addresses from the first HASH table by calculating the connection information of the SYN packet to be processed. The first HASH table stores multiple linked lists, and the linked lists are used to store the connection information of the processed SYN packets. One linked list can store the connection information of multiple processed SYN packets. The connection information mainly includes quadruple information and network namespace information. The reason for using a linked list to save the connection information is to prevent the occurrence of HASH conflicts (for example, different quadruple and network namespace information may generate the same HASH value, and one HASH value corresponds to one linked list in the first HASH table).

[0017] The members of the second HASH table are multiple spin locks. Each spin lock corresponds to protecting one linked list in the first HASH table. After the thread of the server obtains the spin lock, it can obtain the permission to operate the corresponding linked list in the first HASH table.

[0018] Step S1: The client sends the SYN packet to be processed to the server; Step S2: The thread of the server obtains the HASH value based on the SYN packet to be processed sent by the client, and obtains the linked list corresponding to the HASH value from the first HASH table and the corresponding spin lock from the second HASH table.

[0019] This step is refined into the following steps: Step S21: The thread of the server receives the SYN packet to be processed sent by the client; Step S22: The thread of the server obtains the connection information of the SYN packet to be processed based on the SYN packet to be processed; Step S23: The thread of the server performs HASH calculation based on the connection information of the SYN packet to be processed to obtain the HASH value corresponding to the SYN packet to be processed; Step S24: The thread of the server addresses from the first HASH table based on the HASH value corresponding to the SYN packet to be processed to obtain the linked list corresponding to the HASH value.

[0020] Step S25: The thread of the server finds the corresponding spin lock from the second HASH table based on the HASH value and requests to obtain the corresponding spin lock, so as to ensure the uniqueness of the thread of the server operating on the linked list corresponding to the HASH value.

[0021] Step S3: After the thread of the server obtains the corresponding spin lock from the second HASH table, other threads of the server will not be able to obtain the permission to operate on the linked list corresponding to the HASH value by addressing this HASH value. Then, the thread of the server traverses the linked list corresponding to the HASH value, sequentially takes out the connection information of the processed SYN packets saved in the linked list and compares it with the connection information of the SYN packet to be processed, and judges whether there is connection information of a processed SYN packet in the linked list corresponding to the HASH value that is the same as the connection information of the SYN packet to be processed; Step S4: If there is connection information of a processed SYN packet in the linked list corresponding to the HASH value that is the same as the connection information of the SYN packet to be processed, it indicates that the same SYN packet is already being processed in the server, and this SYN packet to be processed does not need to be processed again. The thread of the server discards the SYN packet to be processed and releases the spin lock corresponding to the linked list; no subsequent steps are performed.

[0022] Step S5: If there is no connection information of a processed SYN packet in the linked list corresponding to the HASH value that is the same as the connection information of the SYN packet to be processed, it indicates that there is no same SYN packet being processed in the server, and the SYN packet to be processed is the first SYN packet of this content; the SYN packet to be processed is marked as a processed SYN packet, and its connection information is stored in the linked list corresponding to the HASH value. The thread of the server releases the spin lock corresponding to the linked list from the second HASH table, and then enters Step S6 to continue processing the SYN packet marked as processed.

[0023] Step S6: The thread of the server normally processes the processed SYN packet to obtain a SYN-ACK packet, and sends the obtained SYN-ACK packet to the client; Step S7: The client receives the SYN-ACK packet sent by the thread of the server; Step S8: The client processes the SYN-ACK packet to obtain an ACK packet and sends the ACK packet to the thread of the server. Step S9: The thread of the server receives the ACK packet, and the handshake phase ends.

[0024] In this step, after the thread of the server receives the ACK packet, it further determines whether the ACK packet is legal; if the ACK packet is legal, it indicates that the handshake between the client and the server is successful, and the client and the server establish a TCP connection.

[0025] After the client and the server establish a TCP connection, the server re-obtains the corresponding spin lock from the second HASH table based on the HASH value obtained in Step S2. After re-obtaining the corresponding spin lock, it removes the connection information of the processed SYN packet corresponding to the HASH value from the linked list corresponding to the HASH value. Finally, it releases the corresponding spin lock from the second HASH table again.

[0026] After the comparison in Step S4 and Step S5, the thread of the server will send at most one SYN-ACK packet in response to the same SYN packet, and the subsequent ACK packet responded by the client will also meet the requirements. Therefore, TCP connection reset will not occur.

[0027] Abbreviations: TCP: TCP is a connection-oriented and reliable transport layer communication protocol located above the IP protocol. It establishes a connection through a three-way handshake, numbers and acknowledges data packets during data transmission to ensure that data is accurately transmitted between different host applications, and is widely used in network application scenarios such as web browsing, email, and file transfer.

[0028] Reset: In a TCP connection, reset is an operation to abnormally terminate the connection. When a situation that does not conform to the TCP protocol rules occurs, such as receiving an invalid sequence number or an incorrect combination of flag bits in an error packet, the receiving party may send an RST packet to interrupt the connection, which will stop the ongoing data transmission. The occurrence of TCP connection reset will bring a bad experience to users.

[0029] HASH table: The HASH table, also known as the hash table, is a data structure. It uses a hash function to map keys to storage locations for storing and retrieving data. In network protocol processing, the hash value can be calculated based on certain characteristics of the SYN packet and relevant information can be stored to quickly determine whether the same SYN packet has been received, improving processing efficiency.

[0030] SYN-ACK: SYN-ACK is the type of response data packet sent by the server to the client's SYN packet. It not only indicates the agreement to establish a connection for synchronization but also confirms the client's connection request. It contains the new sequence number generated by the server and the confirmation information for the client's SYN packet, playing a crucial role in the three-way handshake.

[0031] ACK: ACK is a flag used in the TCP protocol to confirm the receipt of data packets. During the three-way handshake for connection establishment, the client sends an ACK packet after receiving the SYN-ACK packet. During data transmission, the receiving party sends an ACK packet after receiving a data packet, and its acknowledgment number indicates the sequence number of the next data packet expected to be received, ensuring the reliability of data transmission.

[0032] Quadruple: The quadruple in a network connection consists of the source IP address, source port number, destination IP address, and destination port number, which is used to uniquely identify a connection in the network.

[0033] bond3: Bond can bind multiple network cards together, allowing two or more interfaces to act as one interface to increase network bandwidth and provide network link redundancy. When one of the network cards fails, the server's services will not be interrupted. Bond3 is the third mode of the bond function. Its characteristic is that when sending data, the data to be sent will be sent out in broadcast mode from each slave sub-interface, and when receiving data, the received data will be broadcast to each sub-interface.

[0034] The above are only the preferred embodiments of the present invention. The protection scope of the present invention is not limited to the above embodiments. All technical solutions falling within the concept of the present invention belong to the protection scope of the present invention. It should be noted that for those of ordinary skill in the art, without departing from the principle of the present invention, several improvements and refinements should also be regarded as within the protection scope of the present invention.

Claims

1. An optimization method for solving TCP connection reset caused by multiple identical SYN packets, characterized in that Establishing a TCP connection between the server and the client requires going through a handshake phase, and the optimization method is used for the server and the client to judge and process the SYN packets to be processed during the handshake phase; The optimization method includes the following steps: Step S0: Use a structure to save the first HASH table and the second HASH table. The first HASH table stores multiple linked lists; the linked lists are used to store the connection information of the processed SYN packets, and the second HASH table stores multiple spin locks; each spin lock corresponds to protecting a linked list in the first HASH table; Step S1: The client sends the SYN packet to be processed to the server; Step S2: The thread of the server obtains the HASH value based on the SYN packet to be processed sent by the client, obtains the linked list corresponding to the HASH value from the first HASH table, and obtains the corresponding spin lock from the second HASH table; Step S3: After the thread of the server obtains the corresponding spin lock from the second HASH table, the thread of the server sequentially takes out the connection information of the processed SYN packets from the linked list corresponding to the HASH value and compares it with the connection information of the SYN packet to be processed; Step S4: If there is connection information of a processed SYN packet in the linked list corresponding to the HASH value that is the same as the connection information of the SYN packet to be processed, the thread of the server discards the SYN packet to be processed, no longer processes the SYN packet to be processed, and releases the corresponding spin lock; Step S5: If there is no connection information of a processed SYN packet in the linked list corresponding to the HASH value that is the same as the connection information of the SYN packet to be processed, the thread of the server marks the SYN packet to be processed as a processed SYN packet, stores the connection information of the processed SYN packet into the linked list corresponding to the HASH value, then releases the corresponding spin lock, and then enters Step S6 to continue processing the marked processed SYN packet; Step S6: The thread of the server obtains a SYN-ACK packet based on the processed SYN packet and sends the SYN-ACK packet to the client; Step S7: The client receives the SYN-ACK packet sent by the thread of the server; Step S8: The client processes the SYN-ACK packet to obtain an ACK packet and sends the ACK packet to the thread of the server; Step S9: The thread of the server receives the ACK packet, and the handshake phase ends.

2. The optimized method for solving TCP connection reset caused by multiple identical SYN packets according to claim 1, characterized in that Step S2 includes the following steps: Step S21: The thread of the server receives the SYN packet to be processed sent by the client; Step S22: The thread of the server obtains the connection information of the SYN packet to be processed based on the SYN packet to be processed; Step S23: The thread of the server performs HASH calculation based on the connection information of the SYN packet to be processed to obtain the HASH value corresponding to the SYN packet to be processed; Step S24: The thread of the server obtains the linked list corresponding to the HASH value from the first HASH table based on the HASH value corresponding to the SYN packet to be processed; Step S25: The thread on the server side finds the corresponding spin lock from the second HASH table based on the HASH value and requests to acquire the corresponding spin lock.

3. The optimization method for solving TCP connection reset caused by multiple identical SYN packets according to claim 2, characterized in that In step S9, after the thread on the server side receives the ACK packet, it further determines whether the ACK packet is legal; if the ACK packet is legal, it indicates that the handshake between the client and the server is successful, and the client and the server establish a TCP connection.

4. A method for optimizing the solution of TCP connection reset caused by multiple identical SYN packets according to claim 3, characterized in that, After the client and the server establish a TCP connection, the server re-obtains the corresponding spin lock from the second HASH table based on the HASH value obtained in step S2. After re-obtaining the spin lock, it removes the connection information of the processed SYN packet corresponding to the HASH value from the linked list corresponding to the HASH value. After completion, it releases the corresponding spin lock.

5. A method for optimizing the solution to TCP connection reset caused by multiple identical SYN packets according to claim 1, characterized in that, The connection information includes quadruple information and network namespace information.

Citation Information

Patent Citations

  • Method and device for allocating resources

    CN105099952A

  • Data packet detection processing method and equipment

    CN113098727A

  • Single packet authorization verification method based on TCP option

    CN115865370A

  • TCP message transmission method and device

    CN117812136A

  • Method for authenticating communication traffic, communication system and protective apparatus

    US20120227088A1