Method for supporting TCP connection-based forwarding mode switching between identical hosts

Through the EBPF service and kernel TCP SOCKET option notification mechanism, the forwarding mode switching between the host TCP connection is realized, solving the problem of inability to switch back to the kernel forwarding path and the sequence of packets on the receiving end in the existing technology, and achieving efficient TCP forwarding and traffic analysis.

WO2025124176A1PCT designated stage expired Publication Date: 2025-06-19CHINA TELECOM CLOUD TECH CO LTD

Patent Information

Application Number
PCT/CN2024/135815
Authority / Receiving Office
WO · WO
Patent Type
Applications
Current Assignee / Owner
Priority Date
2023-12-12
Filing Date
2024-11-29
Publication Date
2025-06-19

AI Technical Summary

Technical Problem

The existing SOCKMAP forwarding scheme cannot switch back to the kernel forwarding path, resulting in the inability to capture data packets when analyzing TCP traffic, and the forwarding mode switching of the sending side may lead to packet sequence problems at the receiving side.

Method used

A method is proposed to support forwarding mode switching between TCP connections with the host. Through the EBPF service and the kernel TCP SOCKET option notification mechanism, the forwarding mode switching of the specified SOCKET is realized, and during the switching process, the receiver must receive messages in sequence.

Benefits of technology

The forwarding mode switching of the specified SOCKET is implemented without affecting other TCP connections, ensuring that traffic is not interrupted, and taking into account the needs of TCP forwarding performance and traffic acquisition and analysis.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN2024135815_19062025_PF_FP_ABST
    Figure CN2024135815_19062025_PF_FP_ABST
Patent Text Reader

Abstract

Provided in the present application is a method for supporting TCP connection-based forwarding mode switching between identical hosts. The method comprises: starting a SOCKMAP, and storing a quadruple and FD information of a SOCKET in an EBPF MAP table; newly adding an EBPF service, and acquiring the FD information from the EBPF MAP table on the basis of the quadruple; newly adding a TCP SOCKET option, and notifying a kernel that a forwarding mode is switched, searching for a peer-end SOCKET on the basis of a reverse quadruple, and storing the peer-end SOCKET in a local-end SOCKET; when the forwarding mode is a kernel protocol stack mode, determining whether there are messages that have not been processed, and if there are messages that have not been processed, not allowing switching, and if there are no messages that have not been processed, setting a sending mode and a receiving mode, wherein a peer end preferentially receives a message from a SOCKMAP queue, and then receives a message from a kernel protocol stack queue; when the forwarding mode is a SOCKMAP mode, first determining whether there are messages in a peer-end SOCKMAP queue, and if there are messages in the peer-end SOCKMAP queue, not allowing switching, and if there are no messages in the peer-end SOCKMAP queue, setting the sending mode to be the SOCKMAP mode and the receiving mode to be the SOCKMAP mode; and on the basis of the forwarding mode, receiving a message from the kernel protocol stack queue and the SOCKMAP queue in sequence. In this way, a receiving end performing reception according to a sending sequence is ensured.
Need to check novelty before this filing date? Find Prior Art

Description

A method for supporting TCP connection forwarding mode switching within the same host Technical Field

[0001] The present application relates to the technical field of same-host TCP acceleration and forwarding, and is applicable to systems with large TCP traffic between the same hosts, such as data centers or CDN acceleration fields, and particularly to a method for supporting same-host TCP connection forwarding mode switching. Background Art

[0002] In the server world, multiple applications are often deployed on the same server, with regular TCP traffic exchanged between them. In the CDN acceleration field, we often deploy a static gateway and a cache application on the same machine. When the static gateway receives a client request, it first retrieves the data from the local cache application before returning it to the client. This intra-host TCP transmission currently forwards data through the kernel protocol stack by default, resulting in a long forwarding path and high CPU consumption. For intra-host TCP forwarding, SOCKMAP is used as a forwarding proxy.

[0003] SOCKMAP is an EBPF-based proxy for forwarding TCP traffic on the same host. A SOCKMAP instance is associated with a client and server sockets. The kernel also assigns a proxy socket to each of these sockets and attaches an EBPF PROG handler to the proxy socket. This handler triggers a call at the TCP send entry point. The PROG handler uses the destination socket information in the datagram to find the destination socket from the MAP table and forward the data to the destination socket's SOCKMAP queue. This forwarding process eliminates the need to go through the entire kernel protocol stack, significantly reducing CPU usage.

[0004] In the existing SOCKMAP forwarding solution, once a socket is enabled for SOCKMAP forwarding, there is no way to switch back to the kernel forwarding path. For example, when analyzing TCP traffic, SOCKMAP-enabled TCP traffic does not pass through the network card and therefore cannot be captured by tools such as TCPDUMP. When receiving packets, the TCP receiver must ensure that data packets are received in order. When the sender switches between SOCKMAP and kernel protocol stack forwarding modes, packets may be present in both the receiver's SOCKMAP receive queue and the kernel protocol stack receive queue. Summary of the Invention

[0005] This application aims to at least partially address one of the technical problems in the related art. To this end, one purpose of this application is to propose a method for supporting intra-host TCP connection forwarding mode switching, enabling a specific socket to be designated for independent forwarding mode switching, ensuring that traffic is not interrupted during the switching process, ensuring that the receiving end receives traffic in the order it was sent, and maximally balancing TCP forwarding performance and TCP traffic collection and analysis.

[0006] One aspect of the present application provides a method for supporting switching of TCP connection forwarding modes within the same host, comprising:

[0007] Step S100: Start the SOCKMAP service, save the 4-tuple and FD information of the SOCKET of the SOCKMAP service into the EBPF MAP table, and make the EBPF MAP table file persistent;

[0008] The SOCKET refers to the SOCKET on the same host. There are n services on the same host. The services communicate through the network. In a TCP connection, there is a server and a client. The designated SOCKET is selected as the local SOCKET. The local end is the sending end, and the other end SOCKET is the peer SOCKET. The peer end is the receiving end. The designated SOCKET is the client SOCKET or the server SOCKET.

[0009] The starting of the SOCKMAP service, saving the 4-tuple and FD information of the SOCKMAP service's SOCKET into the EBPF MAP table, and persisting the EBPF MAP table file means that: when the three-way handshake phase of the TCP connection is performed between the same host, the SOCKMAP service is started. Once the SOCKMAP service is enabled, the EBPF program intercepts the startup process, obtains the 4-tuple of the client's SOCKET and the server's SOCKET and their corresponding FD information, saves them into the EBPF MAP table, and persists the EBPF MAP table file.

[0010] The four-tuple of the SOCKET is composed of four elements: source IP and source port number, destination IP and destination port number;

[0011] The FD information refers to the interface between the application and the SOCKET;

[0012] Step S200: Adding an EBPF service. The EBPF service obtains the FD information of the designated socket that needs to switch forwarding mode from the EBPF MAP table according to the input quadruple, and uses the designated socket as the local socket.

[0013] The EBPF service is responsible for obtaining the FD information of the socket that needs to switch the forwarding mode from the EBPF MAP table according to the information of the incoming quadruple;

[0014] The forwarding mode includes SOCKMAP mode and kernel protocol stack mode;

[0015] The designated SOCKET that needs to switch the forwarding mode refers to either the client SOCKET or the server SOCKET that needs to switch the forwarding mode;

[0016] Step S300: The kernel adds a new TCP SOCKET option to notify the kernel to switch the forwarding mode of the local SOCKET and generate a reverse quadruple. The kernel finds the peer SOCKET from the global TCP_HASHINFO table based on the reverse quadruple and saves the peer SOCKET to the data structure of the local SCOKET.

[0017] The TCP SOCKET option is used to implement the switching notification of switching forwarding mode;

[0018] The reverse quadruple is a combination opposite to the quadruple of the local socket, that is, the source IP and source port number become the target IP and target port number, and the target IP and target port number become the source IP and source port number;

[0019] The peer SOCKET refers to the SOCKET at the other end of the local SOCKET that establishes a TCP connection with one end of the local SOCKET. One end of the local SOCKET is the local end, and the other end associated with it is the peer end.

[0020] The kernel adds a new TCP SOCKET option to notify the kernel to switch the forwarding mode of the local SOCKET and generate a reverse quadruple. The kernel finds the opposite SOCKET from the global TCP_HASHINFO table based on the reverse quadruple and saves the opposite SOCKET to the data structure of the local SCOKET. The specific method is as follows:

[0021] When the forwarding mode of a specified socket needs to be switched, the EBPF service notifies the kernel by setting a new TCP socket option. The TCP socket option contains the socket's four-tuple information. After receiving the notification of switching the forwarding mode, the kernel generates a reverse four-tuple based on the four-tuple information. The kernel uses the reverse four-tuple information to search for the peer socket in the global TCP_HASHINFO table. Once the peer socket is found, the kernel saves it to the local socket's data structure.

[0022] Step S400: When switching to the kernel protocol stack mode, it is determined whether there are any unprocessed messages. If so, the switch is not allowed; if not, the sending mode of the local end and the receiving mode of the remote end are set. When the remote end receives, it preferentially receives messages from the SOCKMAP queue and then receives messages from the kernel protocol stack queue.

[0023] The message received from the SOCKMAP queue refers to the message received in the SOCKMAP mode before switching the forwarding mode but not yet processed;

[0024] The receiving of the message from the kernel protocol stack queue refers to a new message received from the kernel protocol stack in the kernel protocol stack mode after switching the forwarding mode;

[0025] When switching to the kernel protocol stack mode, it is determined whether there are any unprocessed messages. If so, switching is not allowed; if not, the sending mode of the local end and the receiving mode of the opposite end are set. When the opposite end receives, it gives priority to receiving messages from the SOCKMAP queue, and then receives messages from the kernel protocol stack queue. Specifically, the SOCKMAP queue is used to store messages received in the SOCKMAP mode, and the kernel protocol stack queue is used to store messages received in the kernel protocol stack mode. Before the application layer sets the forwarding mode to switch from the SOCKMAP mode to the kernel protocol stack mode, it is first determined whether there are any unprocessed messages on the kernel protocol stack path. If there are unprocessed messages, the application layer is notified that switching is not allowed at present; if there are no unprocessed messages, the sending mode of the local SOCKET is set to the kernel protocol stack mode, and the receiving mode of the opposite end SOCKET is set to the kernel protocol stack mode. When the opposite end SOCKET receives messages, it gives priority to receiving messages from the SOCKMAP queue, and then receives messages from the kernel protocol stack queue;

[0026] The sending mode means that SOCKET is processed in SOCKMAP mode when processing messages;

[0027] The SOCKMAP mode means that the EBPF program can add the SOCKET to the SOCKMAP so that it can be referenced in the kernel;

[0028] The SOCKMAP queue is a queue for storing unprocessed messages received in SOCKMAP mode;

[0029] The receiving mode means that the SOCKET is processed by the kernel protocol stack mode when processing messages;

[0030] The kernel protocol stack mode refers to the traditional mode in which messages are processed in the kernel protocol stack;

[0031] The kernel protocol stack queue is a queue of messages received by the SOCKET in the kernel protocol stack mode after the SOCKET switches to the forwarding mode;

[0032] The kernel protocol stack path refers to the path along which the message is transmitted from the application layer through the kernel protocol stack;

[0033] Step S500: When switching to SOCKMAP mode, first determine whether there is a message in the SOCKMAP queue of the other end. If so, do not allow switching; if not, set the sending mode of the local end to SOCKMAP mode and the receiving mode of the other end to SOCKMAP mode;

[0034] When switching to SOCKMAP mode, first determine whether there is a message in the SOCKMAP queue of the other end. If so, the switch is not allowed; if not, set the sending mode of the local end to SOCKMAP mode and the receiving mode of the other end to SOCKMAP mode. Specifically:

[0035] When the application layer switches the forwarding mode from the kernel protocol stack mode to the SOCKMAP mode, the kernel first determines whether there are any messages in the SOCKMAP queue of the receiving end that have not been processed by the application layer. If there are any messages that have not been processed by the application layer, the kernel notifies the application layer that the forwarding mode switch is not allowed at the moment. If there are no messages that have not been processed by the application layer, the sending mode of the local SOCKET is set to the SOCKMAP mode, and the receiving mode of the remote SOCKET is set to the SOCKMAP mode.

[0036] Step S600: According to the forwarding mode, messages are obtained from the kernel protocol stack queue and the SOCKMAP queue in sequence;

[0037] The specific method of obtaining messages from the kernel protocol stack queue and the SOCKMAP queue in sequence according to the forwarding mode is as follows:

[0038] When the forwarding mode is in kernel protocol stack mode, when forwarding messages through the kernel protocol stack, if there is packet loss and retransmission during the message sending process, TCP will first put the message in the retransmission list. When the other end replies with an ACK message, it means that the other end has received the message, and the message will be removed from the retransmission list. When the forwarding mode is switched to SOCKMAP mode, if the message in the original kernel protocol stack mode has not been sent to the other end, the local end needs to determine whether there are still messages on the local retransmission list. If so, it is necessary to notify the other end SOCKET, indicating that although the local end is now in SOCKMAP mode, there are still messages on the kernel protocol stack path that have not reached the other end. The other end needs to receive all the messages in the retransmission list before it can continue to receive new messages from the SOCKMAP queue. When all the messages on the local retransmission list are sent, the local end notifies the other end SOCKET, indicating that the other end can receive messages from the SOCKMAP queue.

[0039] The phrase "when the other end replies with an ACK message, it indicates that the other end has received the message, and the message is removed from the retransmission list" means that: when the receiving end replies with an ACK message, it indicates that the receiving end has successfully received and processed the message from the sending end, and the sending end knows that the message has successfully arrived, thus avoiding sending the same message repeatedly; when the message is sent, it is placed in the retransmission list in case it needs to be retransmitted. When the corresponding ACK message confirmation is received, it indicates that the message has been successfully sent and no longer needs to be retransmitted, so the message is removed from the retransmission list to release corresponding resources.

[0040] One aspect of the present application provides a system for supporting same-host TCP connection forwarding mode switching, including:

[0041] The service startup module is used to start the SOCKMAP service, save the SOCKET quad and FD information of the SOCKMAP service into the EBPF MAP table, and make the EBPF MAP table file persistent;

[0042] A new service module is added to add EBPF services. The EBPF service obtains the FD information of the specified socket that needs to switch the forwarding mode from the EBPF MAP table based on the incoming four-tuple, and uses the specified socket as the local socket.

[0043] The forwarding notification module is used to notify the kernel of the newly added TCP SOCKET option to switch the forwarding mode of the local SOCKET and generate a reverse quadruple. The kernel finds the peer SOCKET from the global TCP_HASHINFO table based on the reverse quadruple and saves the peer SOCKET to the local SCOKET data structure.

[0044] The kernel protocol stack mode receiving module is used to determine whether there are any unprocessed messages when switching to the kernel protocol stack mode. If so, the switch is not allowed; if not, the sending mode of the local end and the receiving mode of the peer end are set. When the peer end receives, it first receives messages from the SOCKMAP queue and then receives messages from the kernel protocol stack queue.

[0045] The SOCKMAP mode receiving module is used to determine whether there is a message in the SOCKMAP queue of the other end when switching to SOCKMAP mode. If so, the switch is not allowed; if not, the sending mode of the local end is set to SOCKMAP mode, and the receiving mode of the other end is set to SOCKMAP mode;

[0046] The message receiving module is used to obtain messages from the kernel protocol stack queue and the SOCKMAP queue in sequence according to the forwarding mode.

[0047] One aspect of the present application provides an electronic device, including a memory, a processor, and a computer program stored in the memory and executable on the processor. When the processor executes the program, it implements the steps in a method for supporting switching of TCP connection forwarding modes within the same host.

[0048] One aspect of the present application provides a readable storage medium storing a computer program, wherein the computer program is suitable for being loaded by a processor to execute steps in a method for supporting switching of a same-host TCP connection forwarding mode.

[0049] The method proposed in this application for supporting same-host TCP connection forwarding mode switching has the following advantages over the existing technology:

[0050] The local TCP traffic transmission path switching method proposed in this application is mainly suitable for situations where the traffic between local machines is large and the system consumption is large, and it is necessary to improve the local traffic performance. At the same time, necessary maintenance and testing means need to be provided when necessary, such as CDN cache nodes.

[0051] The kernel provides mode switching entry to the application layer by adding a TCP socket option. The application layer uses the EBPF program to first obtain the socket information that needs to be switched from a persistent map table in a file, and then notifies the kernel to switch the forwarding mode. The switching process does not affect other TCP connections, and the TCP connection that performs the mode switch can ensure uninterrupted traffic.

[0052] By switching the TCP sending mode on the same host, you can maximize the balance between TCP forwarding performance and maintainability. When you need to improve TCP forwarding performance, switch the forwarding mode to SOCKMAP mode. When you need to analyze TCP traffic, switch the TCP forwarding mode to kernel protocol stack mode. BRIEF DESCRIPTION OF THE DRAWINGS

[0053] FIG1 is a flow chart of a method for supporting switching of TCP connection forwarding modes within the same host provided by the present application;

[0054] FIG2 is a flow chart of an embodiment of a method for supporting switching of TCP connection forwarding modes within the same host provided by the present application;

[0055] FIG3 is a schematic structural diagram of an electronic device provided by the present application;

[0056] FIG4 is a schematic diagram of the structure of a readable storage medium provided by this application. DETAILED DESCRIPTION

[0057] For a better understanding of the present application, various aspects of the present application will be described in more detail with reference to the accompanying drawings. It should be understood that these detailed descriptions are merely descriptions of exemplary embodiments of the present application and are not intended to limit the scope of the present application in any way. Throughout the specification, the same reference numerals refer to the same elements. The expression "and / or" includes any and all combinations of one or more of the associated listed items.

[0058] In the accompanying drawings, the size, dimensions, and shapes of the elements have been slightly adjusted for ease of illustration. The accompanying drawings are for illustration only and are not drawn strictly to scale. As used herein, the terms "substantially," "approximately," and similar terms are used to indicate approximations, not degrees, and are intended to illustrate inherent deviations in measurements or calculations that would be recognized by a person of ordinary skill in the art. In addition, in this application, the order in which the steps are described does not necessarily represent the order in which these steps would occur in actual operation, unless otherwise specified or inferred from the context.

[0059] It should also be understood that expressions such as "comprises," "including," "having," "includes," and / or "comprising" are open rather than closed expressions in this specification, indicating the presence of the stated features, elements, and / or components, but do not exclude the presence of one or more other features, elements, components, and / or combinations thereof. In addition, when expressions such as "at least one of..." appear after a list of listed features, they modify the entire list of features rather than just the individual elements in the list. In addition, when describing embodiments of the present application, "may" is used to mean "one or more embodiments of the present application." And, the term "exemplary" is intended to refer to an example or illustration.

[0060] Unless otherwise defined, all words used herein (including engineering terms and scientific and technological terms) have the same meaning as commonly understood by those skilled in the art to which this application belongs. It should also be understood that, unless otherwise specified in this application, words defined in commonly used dictionaries should be interpreted as having the same meaning as they do in the context of the relevant technology, and should not be interpreted in an idealized or overly formal sense.

[0061] It should be noted that, in the absence of conflict, the embodiments and features of the embodiments in this application can be combined with each other. The present application will be described in detail below with reference to the accompanying drawings and in combination with the embodiments.

[0062] Example 1

[0063] As shown in FIG1 , a method flow chart of a method for supporting same-host TCP connection forwarding mode switching provided by the present application includes:

[0064] Step S100: Start the SOCKMAP service, save the 4-tuple and FD information of the SOCKET of the SOCKMAP service into the EBPF MAP table, and make the EBPF MAP table file persistent;

[0065] The SOCKET refers to the SOCKET on the same host. There are n services on the same host. The services communicate through the network. In a TCP connection, there is a server and a client. The designated SOCKET is selected as the local SOCKET. The local end is the sending end, and the other end SOCKET is the peer SOCKET. The peer end is the receiving end. The designated SOCKET is the client SOCKET or the server SOCKET.

[0066] The starting of the SOCKMAP service, saving the 4-tuple and FD information of the SOCKMAP service's SOCKET into the EBPF MAP table, and persisting the EBPF MAP table file means that: when the three-way handshake phase of the TCP connection is performed between the same host, the SOCKMAP service is started. Once the SOCKMAP service is enabled, the EBPF program intercepts the startup process, obtains the 4-tuple of the client's SOCKET and the server's SOCKET and their corresponding FD information, saves them into the EBPF MAP table, and persists the EBPF MAP table file.

[0067] The SOCKMAP is a special EBPF MAP type. SOCKMAP is used to maintain the mapping of associated SOCKETs in the kernel. An associated SOCKET refers to a pair of SOCKETs that establish a TCP connection relationship.

[0068] The SOCKMAP is an EBPF-based same-host TCP traffic forwarding agent. A SOCKMAP instance is associated with a client SOCKET socket and a server SOCKET socket. The key information of the client SOCKET and the server SOCKET is stored in an EBPF MAP table of type BPF_MAP_TYPE_SOCKHASH.

[0069] The four-tuple of the SOCKET is composed of four elements: source IP and source port number, destination IP and destination port number;

[0070] The FD information refers to the interface between the application and the SOCKET;

[0071] Step S200: Adding an EBPF service. The EBPF service obtains the FD information of the designated socket that needs to switch forwarding mode from the EBPF MAP table according to the input quadruple, and uses the designated socket as the local socket.

[0072] The EBPF service is a kernel extension technology that can inject small programs into the kernel without modifying the kernel source code to perform specific network filtering and operations at runtime.

[0073] The EBPF service is responsible for obtaining the FD information of the socket that needs to switch the forwarding mode from the EBPF MAP table according to the information of the incoming quadruple;

[0074] The forwarding mode includes SOCKMAP mode and kernel protocol stack mode;

[0075] The designated SOCKET that needs to switch the forwarding mode refers to either the client SOCKET or the server SOCKET that needs to switch the forwarding mode;

[0076] Step S300: The kernel adds a new TCP SOCKET option to notify the kernel to switch the forwarding mode of the local SOCKET and generate a reverse quadruple. The kernel finds the peer SOCKET from the global TCP_HASHINFO table based on the reverse quadruple and saves the peer SOCKET to the data structure of the local SCOKET.

[0077] TCP SOCKET option refers to: an option set on a TCP SOCKET that can affect the behavior of the SOCKET;

[0078] The TCP SOCKET option is used to implement the switching notification of switching forwarding mode;

[0079] The reverse quadruple is a combination opposite to the quadruple of the local socket, that is, the source IP and source port number become the target IP and target port number, and the target IP and target port number become the source IP and source port number;

[0080] The peer SOCKET refers to the SOCKET at the other end of the local SOCKET that establishes a TCP connection with one end of the local SOCKET. One end of the local SOCKET is the local end, and the other end associated with it is the peer end.

[0081] The TCP_HASHINFO table is a global TCP hash table;

[0082] The TCP_HASHINFO table can search for the SOCKET associated with the TCP connection in the table through the information of the four-tuple;

[0083] The kernel adds a new TCP SOCKET option to notify the kernel to switch the forwarding mode of the local SOCKET and generate a reverse quadruple. The kernel finds the opposite SOCKET from the global TCP_HASHINFO table based on the reverse quadruple and saves the opposite SOCKET to the data structure of the local SCOKET. The specific method is as follows:

[0084] When the forwarding mode of a specified socket needs to be switched, the EBPF service notifies the kernel by setting a new TCP socket option. The TCP socket option contains the socket's four-tuple information. After receiving the notification of switching the forwarding mode, the kernel generates a reverse four-tuple based on the four-tuple information. The kernel uses the reverse four-tuple information to search for the peer socket in the global TCP_HASHINFO table. Once the peer socket is found, the kernel saves it to the local socket's data structure.

[0085] Step S400: When switching to the kernel protocol stack mode, it is determined whether there are any unprocessed messages. If so, the switch is not allowed; if not, the sending mode of the local end and the receiving mode of the remote end are set. When the remote end receives, it preferentially receives messages from the SOCKMAP queue and then receives messages from the kernel protocol stack queue.

[0086] The message received from the SOCKMAP queue refers to the message received in the SOCKMAP mode before switching the forwarding mode but not yet processed;

[0087] The receiving of the message from the kernel protocol stack queue refers to a new message received from the kernel protocol stack in the kernel protocol stack mode after switching the forwarding mode;

[0088] When switching to the kernel protocol stack mode, it is determined whether there are any unprocessed messages. If so, switching is not allowed; if not, the sending mode of the local end and the receiving mode of the opposite end are set. When the opposite end receives, it gives priority to receiving messages from the SOCKMAP queue, and then receives messages from the kernel protocol stack queue. Specifically, the SOCKMAP queue is used to store messages received in the SOCKMAP mode, and the kernel protocol stack queue is used to store messages received in the kernel protocol stack mode. Before the application layer sets the forwarding mode to switch from the SOCKMAP mode to the kernel protocol stack mode, it is first determined whether there are any unprocessed messages on the kernel protocol stack path. If there are unprocessed messages, the application layer is notified that switching is not allowed at present; if there are no unprocessed messages, the sending mode of the local SOCKET is set to the kernel protocol stack mode, and the receiving mode of the opposite end SOCKET is set to the kernel protocol stack mode. When the opposite end SOCKET receives messages, it gives priority to receiving messages from the SOCKMAP queue, and then receives messages from the kernel protocol stack queue;

[0089] The sending mode means that SOCKET is processed in SOCKMAP mode when processing messages;

[0090] The SOCKMAP mode means that the EBPF program can add the SOCKET to the SOCKMAP so that it can be referenced in the kernel;

[0091] The SOCKMAP queue is a queue for storing unprocessed messages received in SOCKMAP mode;

[0092] The receiving mode means that the SOCKET is processed by the kernel protocol stack mode when processing messages;

[0093] The kernel protocol stack mode refers to the traditional mode in which messages are processed in the kernel protocol stack;

[0094] The kernel protocol stack queue is a queue of messages received by the SOCKET in the kernel protocol stack mode after the SOCKET switches to the forwarding mode;

[0095] The kernel protocol stack path refers to the path along which the message is transmitted from the application layer through the kernel protocol stack;

[0096] Step S500: When switching to SOCKMAP mode, first determine whether there is a message in the SOCKMAP queue of the other end. If so, do not allow switching; if not, set the sending mode of the local end to SOCKMAP mode and the receiving mode of the other end to SOCKMAP mode;

[0097] When switching to SOCKMAP mode, first determine whether there is a message in the SOCKMAP queue of the other end. If so, the switch is not allowed; if not, set the sending mode of the local end to SOCKMAP mode and the receiving mode of the other end to SOCKMAP mode. Specifically:

[0098] When the application layer switches the forwarding mode from the kernel protocol stack mode to the SOCKMAP mode, the kernel first determines whether there are any messages in the SOCKMAP queue of the receiving end that have not been processed by the application layer. If there are any messages that have not been processed by the application layer, the kernel notifies the application layer that the forwarding mode switch is not allowed at the moment. If there are no messages that have not been processed by the application layer, the sending mode of the local SOCKET is set to the SOCKMAP mode, and the receiving mode of the remote SOCKET is set to the SOCKMAP mode.

[0099] The first step of determining whether there is a message in the SOCKMAP queue of the opposite end refers to the kernel determining whether there is a message in the SOCKMAP queue of the opposite end SOCKET currently considering switching the forwarding mode that has not been received by the receiving end;

[0100] Step S600: According to the forwarding mode, messages are obtained from the kernel protocol stack queue and the SOCKMAP queue in sequence;

[0101] The specific method of obtaining messages from the kernel protocol stack queue and the SOCKMAP queue in sequence according to the forwarding mode is as follows:

[0102] When the forwarding mode is in kernel protocol stack mode, when forwarding messages through the kernel protocol stack, if there is packet loss and retransmission during the message sending process, TCP will first put the message in the retransmission list. When the other end replies with an ACK message, it means that the other end has received the message, and the message will be removed from the retransmission list. When the forwarding mode is switched to SOCKMAP mode, if the message in the original kernel protocol stack mode has not been sent to the other end, the local end needs to determine whether there are still messages on the local retransmission list. If so, it is necessary to notify the other end SOCKET, indicating that although the local end is now in SOCKMAP mode, there are still messages on the kernel protocol stack path that have not reached the other end. The other end needs to receive all the messages in the retransmission list before it can continue to receive new messages from the SOCKMAP queue. When all the messages on the local retransmission list are sent, the local end notifies the other end SOCKET, indicating that the other end can receive messages from the SOCKMAP queue.

[0103] The retransmission list is a local data structure used to store packets that are lost during TCP transmission and need to be retransmitted. When TCP finds that a message has not been confirmed by the other end, it puts the message into the retransmission list;

[0104] The ACK message is a symbol representing confirmation in the TCP protocol. TCP uses the ACK message to confirm that the data sent by the other party has been successfully received;

[0105] The phrase "when the other end replies with an ACK message, it indicates that the other end has received the message, and the message is removed from the retransmission list" means that: when the receiving end replies with an ACK message, it indicates that the receiving end has successfully received and processed the message from the sending end, and the sending end knows that the message has successfully arrived, thus avoiding sending the same message repeatedly; when the message is sent, it is placed in the retransmission list in case it needs to be retransmitted. When the corresponding ACK message confirmation is received, it indicates that the message has been successfully sent and no longer needs to be retransmitted, so the message is removed from the retransmission list to release corresponding resources.

[0106] Example 2

[0107] As shown in FIG2 , a flowchart of an embodiment of a method for supporting switching of TCP connection forwarding modes within the same host includes:

[0108] On the CDN cache node, enable the SOCKMAP service for the CDN gateway and CDN cache services. This way, the CDN gateway and CDN cache will interact through SOCKMAP, and the SOCKET information of the CDN gateway and CDN cache will be saved in the EBPF MAP table.

[0109] Through the EBPF APP program, the stored SOCKET information is obtained from the EBPF MAP table according to the specified IP port number information.

[0110] The EBPF program notifies the kernel to switch the forwarding mode of the socket through the newly added kernel TCP set option interface.

[0111] After receiving the switching request, the kernel obtains the SOCKET information of the other end from the global TCP_HASHINFO table based on the four-tuple information (source IP, source port, destination IP, destination port), and then determines whether the current conditions are met based on the mode that needs to be switched. If the switching conditions are not met, it returns to the application layer and tries again later; if the switching conditions are met, it modifies the sending mode of this end and the receiving mode of the other end.

[0112] The receiving end obtains messages from the kernel protocol stack receiving queue and SOCKMAP receiving queue in sequence according to the current receiving mode and the information set by the sending end, ensuring that the order of received messages is consistent with the order of sending.

[0113] Example 3

[0114] This application provides a system that supports switching TCP connection forwarding modes within the same host, including:

[0115] The service startup module is used to start the SOCKMAP service, save the SOCKET quad and FD information of the SOCKMAP service into the EBPF MAP table, and make the EBPF MAP table file persistent;

[0116] A new service module is added to add EBPF services. The EBPF service obtains the FD information of the specified socket that needs to switch the forwarding mode from the EBPF MAP table based on the incoming four-tuple, and uses the specified socket as the local socket.

[0117] The forwarding notification module is used to notify the kernel of the newly added TCP SOCKET option to switch the forwarding mode of the local SOCKET and generate a reverse quadruple. The kernel finds the peer SOCKET from the global TCP_HASHINFO table based on the reverse quadruple and saves the peer SOCKET to the local SCOKET data structure.

[0118] The kernel protocol stack mode receiving module is used to determine whether there are any unprocessed messages when switching to the kernel protocol stack mode. If so, the switch is not allowed; if not, the sending mode of the local end and the receiving mode of the peer end are set. When the peer end receives, it first receives messages from the SOCKMAP queue and then receives messages from the kernel protocol stack queue.

[0119] The SOCKMAP mode receiving module is used to determine whether there is a message in the SOCKMAP queue of the other end when switching to SOCKMAP mode. If so, the switch is not allowed; if not, the sending mode of the local end is set to SOCKMAP mode, and the receiving mode of the other end is set to SOCKMAP mode;

[0120] The message receiving module is used to obtain messages from the kernel protocol stack queue and the SOCKMAP queue in sequence according to the forwarding mode.

[0121] Example 4

[0122] Figure 3 is a schematic diagram of the structure of an electronic device provided by one embodiment of the present application. As shown in Figure 3, according to another aspect of the present application, an electronic device is also provided. The electronic device may include one or more processors and one or more memories. The memories may store computer-readable code, which, when executed by the one or more processors, may execute the method described above for supporting same-host TCP connection forwarding mode switching.

[0123] The method or system according to the embodiment of the present application can also be implemented with the aid of the architecture of the electronic device shown in FIG3 . As shown in FIG3 , the electronic device may include a bus, one or more CPUs, a read-only memory (ROM), a random access memory (RAM), a communication port connected to a network, an input / output component, a hard disk, and the like. A storage device in the electronic device, such as a ROM or a hard disk, can store a method for supporting the switching of the forwarding mode of a TCP connection with the same host provided by the present application. A method for supporting the switching of the forwarding mode of a TCP connection with the same host may, for example, include: starting a SOCKMAP service, and saving the quadruple and FD information of the SOCKET of the SOCKMAP service into the EBPF MAP table, and persisting the EBPF MAP table file, adding a new EBPF service, and the EBPF service obtains the FD information of the specified SOCKET that needs to switch the forwarding mode from the EBPF MAP table according to the incoming quadruple, and uses the specified SOCKET as the local SOCKET, and the kernel adds a new TCP SOCKET Option notifies the kernel to switch the forwarding mode of the local SOCKET and generate a reverse quad. The kernel finds the opposite SOCKET from the global TCP_HASHINFO table based on the reverse quad and saves the opposite SOCKET to the data structure of the local SCOKET. When switching to the kernel protocol stack mode, it determines whether there are any unprocessed messages. If so, the switch is not allowed. If not, the sending mode of the local end and the receiving mode of the opposite end are set. When the opposite end receives, it first receives the message from the SOCKMAP queue and then receives the message from the kernel protocol stack queue. When switching to SOCKMAP mode, it first determines whether there is a message in the SOCKMAP queue of the opposite end. If so, the switch is not allowed. If not, the sending mode of the local end is set to SOCKMAP mode and the receiving mode of the opposite end is set to SOCKMAP mode. According to the forwarding mode, the message is obtained from the kernel protocol stack queue and the SOCKMAP queue in sequence. Furthermore, the electronic device may also include a user interface. Of course, the architecture shown in Figure 3 is only exemplary. When implementing different devices, one or more components of the electronic device shown in Figure 3 can be omitted according to actual needs.

[0124] Example 5

[0125] FIG4 is a schematic diagram of the structure of a readable storage medium provided by an embodiment of the present application. As shown in FIG4 , a readable storage medium according to an embodiment of the present application is shown. Computer-readable instructions are stored on the computer-readable storage medium. When the computer-readable instructions are executed by the processor, a method for supporting switching of the forwarding mode of a same-host TCP connection according to an embodiment of the present application described with reference to the above figures can be executed. The storage medium includes, but is not limited to, volatile memory and / or non-volatile memory. Volatile memory may include, for example, random access memory (RAM) and cache memory. Non-volatile memory may include, for example, read-only memory (ROM), hard disk, flash memory, etc.

[0126] In addition, according to the implementation mode of the present application, the process described in the above reference flowchart can be implemented as a computer software program. For example, the present application provides a non-temporary machine-readable storage medium, the non-temporary machine-readable storage medium stores machine-readable instructions, and the machine-readable instructions can be executed by a processor to execute instructions corresponding to the method steps provided by the present application, for example: starting the SOCKMAP service, and saving the four-tuple and FD information of the SOCKET of the SOCKMAP service to the EBPF MAP table, and persisting the EBPF MAP table file, adding a new EBPF service, the EBPF service obtains the FD information of the specified SOCKET that needs to switch the forwarding mode from the EBPF MAP table according to the incoming four-tuple, and uses the specified SOCKET as the local SOCKET, and the kernel adds a TCP SOCKET Option notifies the kernel to switch the forwarding mode of the local SOCKET and generate a reverse quad. The kernel finds the opposite SOCKET from the global TCP_HASHINFO table based on the reverse quad and saves the opposite SOCKET to the data structure of the local SCOKET. When switching to the kernel protocol stack mode, it determines whether there are any unprocessed messages. If so, the switch is not allowed. If not, the sending mode of the local end and the receiving mode of the opposite end are set. When the opposite end receives, it first receives the message from the SOCKMAP queue and then receives the message from the kernel protocol stack queue. When switching to SOCKMAP mode, it first determines whether there is a message in the opposite SOCKMAP queue. If so, the switch is not allowed. If not, the sending mode of the local end is set to SOCKMAP mode and the receiving mode of the opposite end is set to SOCKMAP mode. According to the forwarding mode, the messages are obtained from the kernel protocol stack queue and the SOCKMAP queue in sequence. When the computer program is executed by the central processing unit (CPU), the above functions defined in the method of the present application are executed.

[0127] The methods, apparatuses, and devices of the present application may be implemented in many ways. For example, the methods, apparatuses, and devices of the present application may be implemented by software, hardware, firmware, or any combination of software, hardware, and firmware. The above order of steps for the method is for illustration only, and the steps of the method of the present application are not limited to the order specifically described above unless otherwise specified. In addition, in some embodiments, the present application may also be implemented as programs recorded in a recording medium, which include machine-readable instructions for implementing the methods according to the present application. Therefore, the present application also covers recording media that store programs for executing the methods according to the present application.

[0128] In addition, the parts of the above technical solutions provided in the embodiments of the present application that are consistent with the implementation principles of the corresponding technical solutions in the prior art are not described in detail to avoid excessive redundancy.

[0129] The above-described specific embodiments further illustrate the objectives, technical solutions, and beneficial effects of the present invention. It should be understood that the above description is merely a specific embodiment of the present invention and is not intended to limit the present invention. Any modifications, equivalent substitutions, improvements, etc. made within the spirit and principles of the present invention shall be included within the scope of protection of the present invention.

Claims

1. A method for supporting same-host TCP connection forwarding mode switching, characterized in that: include: Start the SOCKMAP service, save the quaternary group and FD information of the SOCKET of the SOCKMAP service into the EBPF MAP table, and make the EBPF MAP table file persistent; Added EBPF service. The EBPF service obtains the FD information of the specified SOCKET that needs to switch the forwarding mode from the EBPF MAP table according to the incoming four-tuple, and uses the specified SOCKET as the local SOCKET. The kernel adds a new TCP SOCKET option to notify the kernel to switch the forwarding mode of the local SOCKET and generate a reverse quadruple. The kernel finds the peer SOCKET from the global TCP_HASHINFO table based on the reverse quadruple and saves the peer SOCKET to the data structure of the local SCOKET. When switching to the kernel protocol stack mode, determine whether there are unprocessed messages. If so, the switch is not allowed; if not, set the sending mode of the local end and the receiving mode of the other end. When the other end receives, it will first receive messages from the SOCKMAP queue and then receive messages from the kernel protocol stack queue. When switching to SOCKMAP mode, first determine whether there is a message in the SOCKMAP queue of the other end. If so, the switch is not allowed; if not, set the sending mode of the local end to SOCKMAP mode, and the receiving mode of the other end to SOCKMAP mode; According to the forwarding mode, the message is obtained from the kernel protocol stack queue and the SOCKMAP queue in sequence.

2. A method for supporting same-host TCP connection forwarding mode switching as claimed in claim 1, characterized in that: The SOCKET refers to the SOCKET on the same host. There are n services on the same host. The services communicate through the network. In a TCP connection, there are a server and a client. Select the designated SOCKET as the local SOCKET, the local end is the sending end, and the other end SOCKET is the opposite end SOCKET, the opposite end is the receiving end. The designated SOCKET is the client's SOCKET or the server's SOCKET.

3. A method for supporting same-host TCP connection forwarding mode switching as claimed in claim 2, characterized in that: The starting of the SOCKMAP service, saving the four-tuple and FD information of the SOCKET of the SOCKMAP service in the EBPF MAP table, and persisting the EBPF MAP table file means: when the three-way handshake phase of the TCP connection is performed between the same host, the SOCKMAP service is started. Once the SOCKMAP service is enabled, the EBPF program will intercept the startup process, obtain the four-tuple of the client's SOCKET and the server's SOCKET and their corresponding FD information, and save them in the EBPF MAP table, and persist the EBPF MAP table file.

4. A method for supporting same-host TCP connection forwarding mode switching as claimed in claim 3, characterized in that: The kernel adds a new TCP SOCKET option to notify the kernel to switch the forwarding mode of the local SOCKET, generate a reverse quadruple, and the kernel finds the opposite SOCKET from the global TCP_HASHINFO table according to the reverse quadruple, and saves the opposite SOCKET to the data structure of the local SCOKET. The specific method is as follows: when the forwarding mode of the specified SOCKE needs to be switched, the EBPF service notifies the kernel by setting a new TCP SOCKET option, and the TCP SOCKET option includes the information of the quadruple of the SOCKET. After the kernel receives the notification of switching the forwarding mode, it generates a reverse quadruple according to the information of the quadruple, and the kernel uses the information of the reverse quadruple to search for the opposite SOCKET in the global TCP_HASHINFO table. Once the opposite SOCKET is found, the kernel saves it to the data structure of the local SOCKET.

5. A method for supporting same-host TCP connection forwarding mode switching as claimed in claim 4, characterized in that: When switching to the kernel protocol stack mode, it is determined whether there are any unprocessed messages. If so, switching is not allowed; if not, the sending mode of this end and the receiving mode of the other end are set. When the other end receives, it gives priority to receiving messages from the SOCKMAP queue, and then receives messages from the kernel protocol stack queue. Specifically, the SOCKMAP queue is used to store messages received in the SOCKMAP mode, and the kernel protocol stack queue is used to store messages received in the kernel protocol stack mode. Before the application layer sets the forwarding mode to switch from the SOCKMAP mode to the kernel protocol stack mode, it is first determined whether there are any unprocessed messages on the kernel protocol stack path. If there are unprocessed messages, the application layer is notified that switching is not allowed at present; if there are no unprocessed messages, the sending mode of the local SOCKET is set to the kernel protocol stack mode, and the receiving mode of the other end SOCKET is set to the kernel protocol stack mode. When the other end SOCKET receives messages, it gives priority to receiving messages from the SOCKMAP queue, and then receives messages from the kernel protocol stack queue.

6. A method for supporting same-host TCP connection forwarding mode switching as claimed in claim 5, characterized in that: When switching to SOCKMAP mode, first determine whether there are messages in the SOCKMAP queue of the other end. If so, switching is not allowed; if not, set the sending mode of this end to SOCKMAP mode, and set the receiving mode of the other end to SOCKMAP mode. Specifically, when the application layer sets the forwarding mode to switch from the kernel protocol stack mode to the SOCKMAP mode, the kernel first determines whether there are messages in the SOCKMAP queue of the other end as the receiving end that have not been processed by the application layer. If there are messages that have not been processed by the application layer, notify the application layer that switching the forwarding mode is not allowed at present; if there are no messages that have not been processed by the application layer, set the sending mode of the SOCKET of this end to SOCKMAP mode, and set the receiving mode of the SOCKET of the other end to SOCKMAP mode.

7. A method for supporting same-host TCP connection forwarding mode switching as claimed in claim 6, characterized in that: The specific method of obtaining messages from the kernel protocol stack queue and the SOCKMAP queue in sequence according to the forwarding mode is: When the forwarding mode is in the kernel protocol stack mode, when forwarding messages through the kernel protocol stack, there is a phenomenon of packet loss and retransmission during the message sending process. TCP will first put the message into the retransmission list. When the other end replies with an ACK message, it means that the other end has received the message, and then the message will be removed from the retransmission list. When the forwarding mode is switched to SOCKMAP mode, if the original message in the kernel protocol stack mode has not been sent to the peer end, the local end needs to determine whether there are still messages in the local retransmission list. If so, it needs to notify the peer end SOCKET, indicating that although the local end is now in SOCKMAP mode, there are still messages on the kernel protocol stack path that have not reached the peer end. The peer end needs to receive all the messages in the retransmission list before it can continue to receive new messages from the SOCKMAP queue; When all the messages on the local retransmission list are sent, the local end notifies the peer SOCKET, indicating that the peer can receive messages from the SOCKMAP queue.

8. A system that supports switching of TCP connection forwarding modes within the same host, characterized in that: include: The service startup module is used to start the SOCKMAP service, save the four-tuple and FD information of the SOCKET of the SOCKMAP service into the EBPF MAP table, and make the EBPF MAP table file persistent; A new service module is added to add EBPF service. The EBPF service obtains the FD information of the specified SOCKET that needs to switch the forwarding mode from the EBPF MAP table according to the incoming four-tuple, and uses the specified SOCKET as the local SOCKET. The forwarding notification module is used to notify the kernel to switch the forwarding mode of the local SOCKET when the kernel adds a new TCP SOCKET option, and generate a reverse quadruple. The kernel finds the opposite SOCKET from the global TCP_HASHINFO table based on the reverse quadruple, and saves the opposite SOCKET to the data structure of the local SCOKET. The kernel protocol stack mode receiving module is used to determine whether there are unprocessed messages when switching to the kernel protocol stack mode. If there are, switching is not allowed; if not, the sending mode of the local end and the receiving mode of the opposite end are set. When the opposite end receives, it first receives messages from the SOCKMAP queue and then receives messages from the kernel protocol stack queue. The SOCKMAP mode receiving module is used to determine whether there is a message in the SOCKMAP queue of the other end when switching to the SOCKMAP mode. If so, the switching is not allowed; if not, the sending mode of the local end is set to the SOCKMAP mode, and the receiving mode of the other end is set to the SOCKMAP mode; The message receiving module is used to obtain messages from the kernel protocol stack queue and the SOCKMAP queue in sequence according to the forwarding mode.

9. An electronic device, characterized in that: The invention comprises a memory, a processor and a computer program stored in the memory and executable on the processor. When the processor executes the program, the steps in the method for supporting the switching of the forwarding mode of the TCP connection with the same host as described in any one of claims 1 to 7 are implemented.

10. A readable storage medium, characterized in that: The readable storage medium stores a computer program, and the computer program is suitable for being loaded by a processor to execute the steps in a method for supporting same-host TCP connection forwarding mode switching as described in any one of claims 1-7.

Citation Information

Patent Citations

  • TCP service oriented flow control method and access network element

    CN106341348A

  • Message receiving and transmitting implementation method of switch management network port

    CN114070805A

  • TOE acceleration system for improving application network performance

    CN116866449A

  • Cross machine request forwarding

    US20230068635A1

Cited By

  • EBPF-based seven-layer protocol data extraction method, system and device and medium

    CN120980145A