A method for supporting the switching of the TCP connection forwarding mode on the same host

The forwarding mode switching between the host TCP connection is achieved through the EBPF MAP table and the TCP SOCKET option, which solves the problem of not being able to switch back to the kernel forwarding path and message order guarantee in the existing technology, and realizes efficient TCP forwarding and traffic analysis.

CN117880385BActive Publication Date: 2025-06-27CHINA TELECOM CLOUD TECH CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202311703082.1
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2023-12-12
Publication Date
2025-06-27
Estimated Expiration
2043-12-12

AI Technical Summary

Technical Problem

The existing TCP forwarding scheme of the same host cannot switch back to the kernel forwarding path, resulting in the inability to capture data packets when analyzing TCP traffic, and the order of packets on the receiver cannot be guaranteed when the forwarding mode of the sender is switched.

Method used

It provides a method that supports forwarding mode switching between TCP connections with the host. It realizes forwarding mode switching of specified SOCKET through the EBPF MAP table and TCP SOCKET option to ensure that the traffic is not interrupted during the switching process, and ensure that the receiver receives packets in the order of sending.

Benefits of technology

It realizes flexible switching of TCP connection forwarding mode with the host, taking into account the needs of TCP forwarding performance and traffic acquisition and analysis, and ensures the consistency of packet order at the receiver.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN117880385B_ABST
    Figure CN117880385B_ABST
Patent Text Reader

Abstract

A method for supporting the switching of TCP connection forwarding modes on the same host. By starting SOCKMAP, the quadruple and FD information of the SOCKET are saved to the EBPF MAP table. The newly added EBPF service obtains the FD information from the EBPF MAP table according to the quadruple. The newly added TCP SOCKET option notifies the kernel to switch the forwarding mode, finds the peer SOCKET according to the reverse quadruple, and saves it to the local SCOKET. When the forwarding mode is the kernel protocol stack mode, it is judged whether there are unprocessed packets. If there are, the switching is not allowed; if not, the sending mode and the receiving mode are set. The peer preferentially receives packets from the SOCKMAP queue and then from the kernel protocol stack queue. When the forwarding mode is the SOCKMAP mode, it is first judged whether there are packets in the peer SOCKMAP queue. If there are, the switching is not allowed; if not, the sending mode is set to the SOCKMAP mode and the receiving mode is set to the SOCKMAP mode. Packets are obtained from the kernel protocol stack queue and the SOCKMAP queue in sequence according to the forwarding mode, ensuring that the receiving end receives packets in the order of sending.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the technical field of TCP acceleration and forwarding between the same hosts, and is applicable to systems with a large amount of TCP traffic between the same hosts, such as data centers or CDN acceleration fields. In particular, it relates to a method for supporting the switching of TCP connection forwarding modes between the same hosts. Background Art

[0002] In the server field, multiple application programs are often deployed on the same server, and there is normal TCP traffic interaction between the applications. In the CDN acceleration field, we often deploy a static gateway and a caching application on one machine; when the static gateway receives a request from a client, the static gateway first obtains data from the caching application on the local machine and then returns it to the client. This kind of TCP transmission between the same hosts currently defaults to being forwarded through the kernel protocol stack, and the overall forwarding path is relatively long, consuming more CPU performance. For TCP forwarding between the same hosts, SOCKMAP is used for forwarding proxy.

[0003] SOCKMAP is a TCP traffic forwarding proxy between the same hosts based on EBPF. An SOCKMAP instance will associate a client SOCKET socket and a server SOCKET socket; the kernel will simultaneously allocate a proxy SOCKET for these two SOCKET sockets and mount an EBPF PROG handler for the proxy SOCKET, which is used to trigger a call at the TCP send entry. In the PROG handler, the destination SOCKET is found from the MAP table according to the destination SOCKET information of the data packet, and then the data is forwarded to the SOCKMAP queue of the destination SOCKET. The entire forwarding process does not need to pass through the complete kernel protocol stack path, which can greatly save the CPU performance of the machine.

[0004] In the existing SOCKMAP forwarding solution, once a SOCKET enables SOCKMAP forwarding, there is no way to switch back to the kernel forwarding path. For example, when it is necessary to analyze TCP traffic, since the TCP traffic enabled with SOCKMAP does not pass through the network card, it cannot be captured by tools such as TCPDUMP. When the TCP receiver receives a packet, it is necessary to ensure that the data packets are in order. When the forwarding mode of the sender switches between the SOCKMAP and the kernel protocol stack modes, there may be packets in both the SOCKMAP receive queue and the kernel protocol stack receive queue of the receiver. Summary of the Invention

[0005] This application aims to solve at least one of the technical problems in the related art to some extent. For this purpose, an object of this application is to propose a method for supporting the switching of the TCP connection forwarding mode with the same host, realizing the separate switching of the forwarding mode for a specified SOCKET, ensuring that the traffic is not interrupted during the switching process, guaranteeing that the receiving end receives in the order of sending, and taking into account both the TCP forwarding performance and the TCP traffic collection and analysis to the greatest extent.

[0006] One aspect of this application provides a method for supporting the switching of the TCP connection forwarding mode with the same host, including:

[0007] Step S100: Start the SOCKMAP service, save the quadruple and FD information of the SOCKET of the SOCKMAP service into the EBPF MAP table, and persist the EBPF MAP table file;

[0008] The SOCKET refers to the SOCKET on the same host. There are n services on the same host, and the services communicate with each other through the network. In a TCP connection, there are a server and a client. Select the specified SOCKET as the local SOCKET. If the local end is the sending end, then the other end SOCKET is the peer SOCKET, and the peer end is the receiving end. The specified SOCKET is the SOCKET of the client or the SOCKET of the server;

[0009] Starting the SOCKMAP service, 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 means that when the three-way handshake stage of the TCP connection between the same hosts occurs, the SOCKMAP service is started. Once the SOCKMAP service is enabled, the EBPF program will intercept this startup process, obtain the quadruples of the client's SOCKET and the server's SOCKET and their corresponding FD information, save them into the EBPF MAP table, and persist the EBPF MAP table file;

[0010] The quadruple of the SOCKET consists of four elements: the source IP and source port number, the destination IP and destination port number;

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

[0012] Step S200: Add an EBPF service. The EBPF service obtains the FD information of the specified SOCKET whose forwarding mode needs to be switched from the EBPF MAP table according to the incoming quadruple, and uses the specified 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 modes include the SOCKMAP mode and the kernel protocol stack mode;

[0015] The specified SOCKET that needs to switch the forwarding mode refers to either the SOCKET of the client or the SOCKET of the server 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, generates a reverse quadruple, and the kernel finds the peer SOCKET from the global TCP_HASHINFO table according to 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 for switching the forwarding mode;

[0018] The reverse quadruple refers to the combination opposite to the quadruple of the local SOCKET, that is, the source IP and source port number become the destination IP and destination port number, and the destination IP and destination port number become the source IP and source port number;

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

[0020] The specific method for the kernel to add 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 peer SOCKET from the global TCP_HASHINFO table according to the reverse quadruple, and saves the peer SOCKET to the data structure of the local SCOKET is as follows:

[0021] When it is necessary to switch the forwarding mode of the specified SOCKE, the EBPF service notifies the kernel by setting a new TCP SOCKET option. The TCP SOCKET option contains the information of the quadruple of the SOCKET. After receiving the notification of switching the forwarding mode, the kernel generates a reverse quadruple according to the information of the quadruple. The kernel uses the information of the reverse quadruple to search for the peer SOCKET in the global TCP_HASHINFO table. Once the peer SOCKET is found, the kernel saves it to the data structure of the local SOCKET;

[0022] Step S400: When switching to the kernel protocol stack mode, check if there are any unprocessed packets. If there are, the switch is not allowed; if not, set the local sending mode and the peer receiving mode. When the peer receives packets, it preferentially receives packets from the SOCKMAP queue and then from the kernel protocol stack queue.

[0023] Receiving packets from the SOCKMAP queue means packets received in the SOCKMAP mode before the switching of the forwarding mode but not yet processed.

[0024] Receiving packets from the kernel protocol stack queue means new packets received from the kernel protocol stack in the kernel protocol stack mode after the switching of the forwarding mode.

[0025] When switching to the kernel protocol stack mode, checking if there are any unprocessed packets. If there are, the switch is not allowed; if not, setting the local sending mode and the peer receiving mode. When the peer receives packets, it preferentially receives packets from the SOCKMAP queue and then from the kernel protocol stack queue specifically means: The SOCKMAP queue is used to store packets received in the SOCKMAP mode, and the kernel protocol stack queue is used to store packets received in the kernel protocol stack mode. Before setting the forwarding mode in the application layer to switch from the SOCKMAP mode to the kernel protocol stack mode, first check if there are any unprocessed packets on the kernel protocol stack path. If there are unprocessed packets, notify the application layer that the switch is not allowed currently; if there are no unprocessed packets, set the sending mode of the local SOCKET to the kernel protocol stack mode, set the receiving mode of the peer SOCKET to the kernel protocol stack mode. When the peer SOCKET receives packets, it preferentially receives packets from the SOCKMAP queue and then from the kernel protocol stack queue.

[0026] The sending mode means that the SOCKET processes packets in the SOCKMAP mode.

[0027] The SOCKMAP mode means that the eBPF program can add the SOCKET to the SOCKMAP for reference in the kernel.

[0028] The SOCKMAP queue is a queue used to store unprocessed packets received in the SOCKMAP mode.

[0029] The receiving mode means that the SOCKET processes packets in the kernel protocol stack mode.

[0030] The kernel protocol stack mode means the traditional mode in which packets are processed in the kernel protocol stack.

[0031] The kernel protocol stack queue is the queue for packets received in the kernel protocol stack mode after the SOCKET switches to the forwarding mode;

[0032] The kernel protocol stack path refers to the path for packets to be transmitted from the application layer through the kernel protocol stack;

[0033] Step S500: When switching to the SOCKMAP mode, first check whether there are packets in the SOCKMAP queue of the peer. If there are, switching is not allowed; if not, set the sending mode of the local end to the SOCKMAP mode and the receiving mode of the peer to the SOCKMAP mode;

[0034] When switching to the SOCKMAP mode, first check whether there are packets in the SOCKMAP queue of the peer. If there are, switching is not allowed; if not, set the sending mode of the local end to the SOCKMAP mode and the receiving mode of the peer to the SOCKMAP mode specifically means:

[0035] When the application layer sets the forwarding mode to switch from the kernel protocol stack mode to the SOCKMAP mode, the kernel first checks whether there are still packets in the SOCKMAP queue of the peer as the receiving end that have not been processed by the application layer. If there are packets that have not been processed by the application layer, the application layer is notified that the current forwarding mode switch is not allowed; if there are no packets 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 peer SOCKET is set to the SOCKMAP mode;

[0036] Step S600: Obtain packets from the kernel protocol stack queue and the SOCKMAP queue in sequence according to the forwarding mode;

[0037] The specific method for obtaining packets from the kernel protocol stack queue and the SOCKMAP queue in sequence according to the forwarding mode is:

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

[0039] The statement that when the peer replies with an ACK packet, indicating that the peer has received the packet, the packet will be removed from the retransmission list means that when the receiving end replies with an ACK packet, it indicates that the receiving end has successfully received and processed the packet sent by the sending end. The sending end knows that the packet has successfully arrived and avoids resending the same packet. The packet is put into the retransmission list when it is sent, in case it needs to be retransmitted. When the corresponding ACK packet is received and confirmed, it means that the packet has been successfully sent and no longer needs to be retransmitted. Therefore, the packet is removed from the retransmission list to release the corresponding resources.

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

[0041] A service startup module, used to start the SOCKMAP service, save the quadruple and FD information of the SOCKET of the SOCKMAP service into the EBPF MAP table, and persist the EBPF MAP table file.

[0042] A new service module, used to add an EBPF service. The EBPF service obtains the FD information of the specified SOCKET whose forwarding mode needs to be switched from the EBPF MAP table according to the incoming quadruple, and uses the specified SOCKET as the local SOCKET.

[0043] A forwarding notification module, used for the kernel to add a 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 peer SOCKET from the global TCP_HASHINFO table according to the reverse quadruple and saves the peer SOCKET to the data structure of the local SCOKET.

[0044] The kernel protocol stack mode receiving module is used to determine whether there are unprocessed packets when switching to the kernel protocol stack mode. If there are, 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 packets, it preferentially receives packets from the SOCKMAP queue and then from the kernel protocol stack queue.

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

[0046] The packet receiving module is used to obtain packets 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 on the memory and executable on the processor. When the processor executes the program, it implements the steps in a method for supporting the switching of the forwarding mode of the TCP connection with the host.

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

[0049] A method for supporting the switching of the forwarding mode of the TCP connection with the host proposed by the present application has the following advantages compared with the prior art:

[0050] The method for switching the local TCP traffic transmission path proposed by the present application is mainly applicable to the case 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 the cache nodes of the CDN.

[0051] The kernel provides an entry for mode switching to the application layer by adding TCP socket options; the application layer uses the eBPF program to first obtain the SOCKET information that needs to switch the mode from a MAP table persisted 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 switching can ensure that the traffic is not interrupted.

[0052] By switching the TCP sending mode of the same host, the performance and maintainability of TCP forwarding can be balanced to the greatest extent. When it is necessary to improve the TCP forwarding performance, the forwarding mode is switched to the SOCKMAP mode. When it is necessary to analyze the TCP traffic, the TCP forwarding mode is switched to the kernel protocol stack mode. Brief Description of the Drawings

[0053] Figure 1 It is a flowchart of a method for supporting the switching of TCP connection forwarding modes of the same host provided by this application;

[0054] Figure 2 It is a flowchart of an embodiment of a method for supporting the switching of TCP connection forwarding modes of the same host provided by this application;

[0055] Figure 3 It is a schematic structural diagram of an electronic device provided by this application;

[0056] Figure 4 It is a schematic structural diagram of a readable storage medium provided by this application. Detailed Embodiments

[0057] To better understand this application, more detailed descriptions of various aspects of this application will be made with reference to the accompanying drawings. It should be understood that these detailed descriptions are only descriptions of the exemplary embodiments of this application and do not limit the scope of this 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 drawings, for ease of illustration, the sizes, dimensions, and shapes of the elements have been slightly adjusted. The drawings are only examples and are not drawn strictly to scale. As used herein, terms such as "substantially", "approximately", and similar terms are used as terms indicating approximation and not as terms indicating degree, and are intended to illustrate the inherent deviations in measured or calculated values that would be recognized by those of ordinary skill in the art. Additionally, in this application, the order of description of the various step processes does not necessarily represent the order in which these processes occur in actual operation, unless otherwise clearly specified or derivable from the context.

[0059] It should also be understood that expressions such as "including", "comprising", "having", "containing" and / or "consisting of" are open-ended rather than closed-ended expressions in this specification, which means that the stated features, elements and / or components exist, but do not exclude the existence of one or more other features, elements, components and / or their combinations. In addition, when an expression such as "at least one of..." appears after a list of listed features, it modifies the entire list of features rather than just an individual element in the list. In addition, when describing the embodiments of the present application, the use of "may" means "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 terms used herein (including engineering terms and technical terms) have the same meaning as the ordinary understanding of those of ordinary skill in the art to which this application pertains. It should also be understood that, unless clearly stated otherwise in this application, words defined in common dictionaries should be interpreted as having a meaning consistent with their meaning in the context of the relevant art and should not be interpreted in an idealized or overly formal sense.

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

[0062] Embodiment 1

[0063] As Figure 1 shown, it is a method flowchart of a method for supporting the switching of the TCP connection forwarding mode with the same host provided by the present application, including:

[0064] Step S100: Start the SOCKMAP service, save the quadruple and FD information of the SOCKET of the SOCKMAP service into the EBPF MAP table, and persist the EBPF MAP table file;

[0065] The SOCKET refers to the SOCKET on the same host. There are n services on the same host, and the services communicate with each other through the network. In a TCP connection, there is a server and a client. Select the specified SOCKET as the local SOCKET. If the local is the sender, then the other end SOCKET is the peer SOCKET, and the peer is the receiver. The specified SOCKET is the SOCKET of the client or the SOCKET of the server;

[0066] Starting the SOCKMAP service, saving the quadruple and FD information of the SOCKET of the SOCKMAP service into the EBPFMAP table, and persisting the EBPF MAP table file means that: during the three-way handshake stage of a TCP connection between the same host, the SOCKMAP service is started. Once the SOCKMAP service is enabled, the EBPF program intercepts this startup process, obtains the quadruples of the client's SOCKET and the server's SOCKET, as well as their corresponding FD information, and saves them into the EBPF MAP table, and persists the EBPF MAP table file;

[0067] The SOCKMAP is a special type of EBPF MAP. The 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 proxy. A SOCKMAP instance associates a client's SOCKET socket and a server's SOCKET socket. The KEY information of the client's SOCKET and the server's SOCKET is stored in an EBPF MAP table of the BPF_MAP_TYPE_SOCKHASH type;

[0069] The quadruple of the SOCKET consists 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: Add an 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 quadruple, and uses the specified 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, and is used 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 modes include the SOCKMAP mode and the kernel protocol stack mode;

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

[0076] Step S300: The kernel adds a TCP SOCKET option to notify the kernel to switch the forwarding mode of the local SOCKET, generates a reverse quadruple, and the kernel finds the peer SOCKET from the global TCP_HASHINFO table according to the reverse quadruple, and saves the peer SOCKET to the data structure of the local SCOKET;

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

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

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

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

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

[0082] The TCP_HASHINFO table can find the SOCKET associated with the TCP connection in the table through the quadruple information;

[0083] The specific method for the kernel to add a 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 peer SOCKET from the global TCP_HASHINFO table according to the reverse quadruple, and saves the peer SOCKET to the data structure of the local SCOKET is as follows:

[0084] When it is necessary to switch the forwarding mode of a specified SOCKET, the eBPF service notifies the kernel by setting a new TCP SOCKET option, and the TCP SOCKET option contains information about the quadruple of the SOCKET. After receiving the notification to switch the forwarding mode, the kernel generates a reverse quadruple based on the quadruple information, and the kernel uses the information of the reverse quadruple to look up the peer SOCKET in the global TCP_HASHINFO table. Once the peer SOCKET is found, the kernel saves it into the data structure of the local SOCKET;

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

[0086] Receiving packets from the SOCKMAP queue means packets that were received in the SOCKMAP mode before switching the forwarding mode but have not been processed yet;

[0087] Receiving packets from the kernel protocol stack queue means new packets 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, check if there are any unprocessed packets. If so, switching is not allowed; if not, set the sending mode of the local end and the receiving mode of the peer end. When the peer end receives packets, it preferentially receives packets from the SOCKMAP queue and then from the kernel protocol stack queue specifically refers to: The SOCKMAP queue is used to store packets received in the SOCKMAP mode, and the kernel protocol stack queue is used to store packets received in the kernel protocol stack mode. Before setting the forwarding mode in the application layer to switch from the SOCKMAP mode to the kernel protocol stack mode, first check if there are any unprocessed packets on the kernel protocol stack path. If there are unprocessed packets, notify the application layer that switching is not allowed currently; if there are no unprocessed packets, set the sending mode of the local SOCKET to the kernel protocol stack mode, set the receiving mode of the peer SOCKET to the kernel protocol stack mode. When the peer SOCKET receives packets, it preferentially receives packets from the SOCKMAP queue and then from the kernel protocol stack queue;

[0089] The sending mode means that the SOCKET processes packets in the SOCKMAP mode;

[0090] The SOCKMAP mode means that the eBPF program can add the SOCKET to the SOCKMAP for reference in the kernel;

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

[0092] The receiving mode means that when the SOCKET processes packets, it is processed by the kernel protocol stack mode;

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

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

[0095] The kernel protocol stack path refers to the path by which packets are transmitted from the application layer through the kernel protocol stack;

[0096] Step S500: When switching to the SOCKMAP mode, first determine whether there are packets in the SOCKMAP queue of the peer. If there are, switching is not allowed; if not, set the sending mode of the local end to the SOCKMAP mode and the receiving mode of the peer to the SOCKMAP mode;

[0097] When switching to the SOCKMAP mode, first determine whether there are packets in the SOCKMAP queue of the peer. If there are, switching is not allowed; if not, set the sending mode of the local end to the SOCKMAP mode and the receiving mode of the peer to the SOCKMAP mode specifically means:

[0098] 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 still packets in the SOCKMAP queue of the peer as the receiving end that have not been processed by the application layer. If there are packets that have not been processed by the application layer, the application layer is notified that the forwarding mode cannot be switched currently; if there are no packets that have not been processed by the application layer, set the sending mode of the local SOCKET to the SOCKMAP mode and the receiving mode of the peer SOCKET to the SOCKMAP mode;

[0099] First determining whether there are packets in the SOCKMAP queue of the peer means that the kernel determines whether there are packets in the SOCKMAP queue of the peer SOCKET currently considering switching the forwarding mode that have not been received by the receiving end;

[0100] Step S600: Obtain packets from the kernel protocol stack queue and the SOCKMAP queue in sequence according to the forwarding mode;

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

[0102] When the forwarding mode is in the kernel protocol stack mode and packets are forwarded through the kernel protocol stack, there is a phenomenon of packet loss and retransmission during the packet sending process. TCP will first put the packet into the retransmission list. When the peer replies with an ACK packet, indicating that the peer has received the packet, the packet is removed from the retransmission list; when the forwarding mode switches to the SOCKMAP mode, if the packets in the original kernel protocol stack mode have not been sent to the peer yet, the local end needs to determine whether there are still packets on the local retransmission list. If so, it needs to notify the peer SOCKET, indicating that although the local end is now in the SOCKMAP mode, there are still packets on the kernel protocol stack path that have not reached the peer, and the peer needs to receive all the packets in the retransmission list before it can continue to receive new packets from the SOCKMAP queue; when all the packets on the local retransmission list have been sent, the local end notifies the peer SOCKET, indicating that the peer can receive packets 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 packet has not been acknowledged by the peer, it puts the packet into the retransmission list;

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

[0105] When the peer replies with an ACK packet, indicating that the peer has received the packet, and then the packet is removed from the retransmission list means that when the receiving end replies with an ACK packet, it indicates that the receiving end has successfully received and processed the packet sent by the sending end. The sending end knows that the packet has reached successfully, avoiding the repeated sending of the same packet; the packet is put into the retransmission list when it is sent, in case it needs to be retransmitted. When the corresponding ACK packet is received and confirmed, it means that the packet has been successfully sent and no longer needs to be retransmitted. Therefore, the packet is removed from the retransmission list to release the corresponding resources.

[0106] Embodiment 2

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

[0108] On the cache node of the CDN, enable the SOCKMAP service for both the CDN gateway and the CDN cache services. In this way, the CDN gateway and the CDN cache will interact through the SOCKMAP method, and at the same time, the SOCKET information of the CDN gateway and the CDN cache will be saved into the EBPF MAP table.

[0109] The APP program through eBPF obtains the stored SOCKET information 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 peer from the global TCP_HASHINFO table according to the quadruple (source IP, source port, destination IP, destination port) information, and then judges whether the current conditions are met according to the mode to be switched currently. When the switching conditions are not met, it returns to the application layer to retry later; when the switching conditions are met, it modifies the sending mode of the local end and the receiving mode of the peer end.

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

[0113] Embodiment 3

[0114] A system for supporting the switching of the TCP connection forwarding mode on the same host provided by the present application includes:

[0115] A service startup module, which is used to start the SOCKMAP service, save the quadruple and FD information of the SOCKET of the SOCKMAP service into the eBPF MAP table, and persist the eBPF MAP table file;

[0116] A new service module, which is used to add an eBPF service. The eBPF service obtains the FD information of the specified SOCKET whose forwarding mode needs to be switched from the eBPF MAP table according to the incoming quadruple, and uses the specified SOCKET as the local SOCKET;

[0117] A forwarding notification module, which is used to notify the kernel to switch the forwarding mode of the local SOCKET by adding a TCP SOCKET option to the kernel, generate a reverse quadruple, and the kernel finds the peer SOCKET from the global TCP_HASHINFO table according to the reverse quadruple and saves the peer SOCKET to the data structure of the local SCOKET;

[0118] A kernel protocol stack mode receiving module, which is used to judge whether there are unprocessed packets when switching to the kernel protocol stack mode. If so, switching is not allowed; if not, it sets the sending mode of the local end and the receiving mode of the peer end. When the peer end receives, it preferentially receives packets from the SOCKMAP queue and then from the kernel protocol stack queue;

[0119] The SOCKMAP mode receiving module is used to, when switching to the SOCKMAP mode, first determine whether there is a message in the SOCKMAP queue of the peer end. If there is, the switching is not allowed; if not, set the sending mode of the local end to the SOCKMAP mode and set the receiving mode of the peer end to the 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] Embodiment 4

[0122] Figure 3 It is a schematic structural diagram of an electronic device provided by an embodiment of the present application. As Figure 3 shown, according to another aspect of the present application, an electronic device is further provided. The electronic device may include one or more processors and one or more memories. Among them, computer-readable code is stored in the memory, and when the computer-readable code is run by one or more processors, it can execute a method for supporting the switching of the TCP connection forwarding mode with the host as described above.

[0123] The method or system according to the embodiment of the present application can also be implemented by means of Figure 3 the architecture of the electronic device shown in the electronic device. As Figure 3As shown in the figure, 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, input / output components, a hard disk, etc. The storage device in the electronic device, such as ROM or hard disk, may store a method for supporting the switching of the TCP connection forwarding mode with the host. A method for supporting the switching of the TCP connection forwarding mode with the host may, for example, include: starting the SOCKMAP service, 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, the EBPF service obtaining the FD information of the specified SOCKET whose forwarding mode needs to be switched from the EBPF MAP table according to the incoming quadruple, taking the specified SOCKET as the local SOCKET, the kernel adding a TCP SOCKET option to notify the kernel to switch the forwarding mode of the local SOCKET, generating a reverse quadruple, the kernel finding the peer SOCKET from the global TCP_HASHINFO table according to the reverse quadruple, and saving the peer SOCKET onto the data structure of the local SCOKET. When switching to the kernel protocol stack mode, it is judged whether there are unprocessed packets. If so, the switching 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 preferentially receives packets from the SOCKMAP queue and then from the kernel protocol stack queue. When switching to the SOCKMAP mode, it is first judged whether there are packets in the SOCKMAP queue of the peer end. 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 peer end is set to the SOCKMAP mode. According to the forwarding mode, packets are obtained from the kernel protocol stack queue and the SOCKMAP queue in sequence. Further, the electronic device may also include a user interface. Of course, Figure 3 The architecture shown is only exemplary. When implementing different devices, one or more components in the electronic device shown may be omitted according to actual needs. Figure 3

[0124] Embodiment 5

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

[0126] In addition, according to an embodiment of the present application, the process described above with reference to the flowchart can be implemented as a computer software program. For example, the present application provides a non-transitory machine-readable storage medium storing machine-readable instructions that can be run by a processor to execute instructions corresponding to the method steps provided by the present application, such as: starting the SOCKMAP service, saving the quadruple 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 obtaining the FD information of the specified SOCKET whose forwarding mode needs to be switched from the EBPF MAP table according to the incoming quadruple, taking the specified SOCKET as the local SOCKET, the kernel adding a TCP SOCKET option to notify the kernel to switch the forwarding mode of the local SOCKET, generating a reverse quadruple, the kernel finding the peer SOCKET from the global TCP_HASHINFO table according to the reverse quadruple, and saving the peer SOCKET to the data structure of the local SCOKET. When switching to the kernel protocol stack mode, it is judged whether there are unprocessed packets. 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 preferentially receives packets from the SOCKMAP queue and then from the kernel protocol stack queue. When switching to the SOCKMAP mode, it is first judged whether there are packets in the SOCKMAP queue of the peer end. If so, the switch is not allowed; if not, the sending mode of the local end is set to the SOCKMAP mode, and the receiving mode of the peer end is set to the SOCKMAP mode. According to the forwarding mode, packets are obtained from the kernel protocol stack queue and the SOCKMAP queue in sequence. When the computer program is executed by a 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 can be implemented in many ways. For example, the methods, apparatuses, and devices of the present application can be implemented by software, hardware, firmware, or any combination of software, hardware, and firmware. The above order of steps for the method is only for illustration, and the steps of the method of the present application are not limited to the specific order described above, unless otherwise specifically stated. In addition, in some embodiments, the present application can also be implemented as a program recorded in a recording medium, and these programs include machine-readable instructions for implementing the method according to the present application. Therefore, the present application also covers a recording medium storing a program for executing the method according to the present application.

[0128] In addition, 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 repetition.

[0129] As described above, the specific embodiments have further elaborated on the purpose, technical solutions, and beneficial effects of the present invention. It should be understood that the above description is only the specific embodiments of the present invention and is not used to limit the present invention. Any modifications, equivalent replacements, improvements, etc. made within the spirit and principles of the present invention shall be included in the protection scope of the present invention.

Claims

1. A method for supporting the switching of TCP connection forwarding modes on the same host, characterized in that, Including: Start the SOCKMAP service, save the quadruple and FD information of the SOCKET of the SOCKMAP service into the EBPF MAP table, and persist the EBPF MAP table file; Add a new EBPF service. The EBPF service obtains the FD information of the specified SOCKET whose forwarding mode needs to be switched from the EBPF MAP table according to the incoming quadruple, and uses the specified SOCKET as the local SOCKET; The kernel adds a TCP SOCKET option to notify the kernel to switch the forwarding mode of the local SOCKET, generates a reverse quadruple, and the kernel finds the peer SOCKET from the global TCP_HASHINFO table according to the reverse quadruple, and saves the peer SOCKET to the data structure of the local SCOKET; When switching to the kernel protocol stack mode, check whether there are unprocessed packets. If so, switching is not allowed; if not, set the sending mode of the local end and the receiving mode of the peer end. When the peer end receives, it preferentially receives packets from the SOCKMAP queue and then from the kernel protocol stack queue; When switching to the SOCKMAP mode, first check whether there are packets in the SOCKMAP queue of the peer end. If so, switching is not allowed; if not, set the sending mode of the local end to the SOCKMAP mode and the receiving mode of the peer end to the SOCKMAP mode; Obtain packets from the kernel protocol stack queue and the SOCKMAP queue in sequence according to the forwarding mode.

2. The method for supporting the switching of the TCP connection forwarding mode with the same host as claimed in claim 1, wherein The SOCKET refers to the SOCKET on the same host. There are n services on the same host, and the services communicate with each other through the network. In a TCP connection, there are a server and a client. Select a specified SOCKET as the local SOCKET. If the local end is the sending end, then the other end SOCKET is the peer SOCKET, and the peer end is the receiving end. The specified SOCKET is the SOCKET of the client or the server.

3. The method for supporting the switching of the TCP connection forwarding mode with the same host according to claim 2, characterized in that, The start of the SOCKMAP service, 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 means that when the three-way handshake stage of the TCP connection between the same hosts starts the SOCKMAP service, once the SOCKMAP service is enabled, the EBPF program will intercept this startup process, obtain the quadruples of the client's SOCKET and the server's SOCKET and their corresponding FD information, and save them into the EBPF MAP table, and persist the EBPF MAP table file.

4. The method for supporting the switching of the TCP connection forwarding mode with the same host as claimed in claim 3, wherein The newly added TCP SOCKET option in the kernel notifies the kernel to switch the forwarding mode of the local SOCKET, generates a reverse quadruple, and the specific method for the kernel to find the peer SOCKET from the global TCP_HASHINFO table according to the reverse quadruple and save the peer SOCKET to the data structure of the local SCOKET is as follows: when it is necessary to switch the forwarding mode of a specified SOCKE, the eBPF service notifies the kernel by setting a new TCP SOCKET option, and the TCP SOCKET option contains the information of the quadruple of the SOCKET. After receiving the notification of switching the forwarding mode, the kernel generates a reverse quadruple according to the information of the quadruple. The kernel uses the information of the reverse quadruple to search for the peer SOCKET in the global TCP_HASHINFO table. Once the peer SOCKET is found, the kernel saves it to the data structure of the local SOCKET.

5. The method for supporting the switching of the TCP connection forwarding mode with the same host as claimed in claim 4, wherein When switching to the kernel protocol stack mode, it is necessary to judge whether there are unprocessed packets. If there are, the switch is not allowed; if not, set the sending mode of the local end and the receiving mode of the peer end. When the peer end receives packets, it preferentially receives packets from the SOCKMAP queue and then from the kernel protocol stack queue, which specifically means: the SOCKMAP queue is used to store the packets received in the SOCKMAP mode, and the kernel protocol stack queue is used to store the packets received in the kernel protocol stack mode. Before setting the forwarding mode in the application layer to switch from the SOCKMAP mode to the kernel protocol stack mode, first judge whether there are unprocessed packets on the kernel protocol stack path. If there are unprocessed packets, notify the application layer that the switch is not allowed currently; if there are no unprocessed packets, set the sending mode of the local SOCKET to the kernel protocol stack mode, set the receiving mode of the peer SOCKET to the kernel protocol stack mode. When the peer SOCKET receives packets, it preferentially receives packets from the SOCKMAP queue and then from the kernel protocol stack queue.

6. The method for supporting the switching of the TCP connection forwarding mode with the same host according to claim 5, characterized in that When switching to the SOCKMAP mode, first judge whether there are packets in the SOCKMAP queue of the peer end. If there are, the switch is not allowed; if not, set the sending mode of the local end to the SOCKMAP mode and the receiving mode of the peer end to the SOCKMAP mode, which specifically means: when the application layer sets the forwarding mode to switch from the kernel protocol stack mode to the SOCKMAP mode, the kernel first judges whether there are still packets in the SOCKMAP queue of the peer end that have not been processed by the application layer. If there are packets that have not been processed by the application layer, notify the application layer that the forwarding mode switch is not allowed currently; if there are no packets that have not been processed by the application layer, set the sending mode of the local SOCKET to the SOCKMAP mode and set the receiving mode of the peer SOCKET to the SOCKMAP mode.

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

8. A system that supports the switching of the TCP connection forwarding mode with the same host, characterized in that, Including: A service startup module, which is used to start the SOCKMAP service, save the quadruple and FD information of the SOCKET of the SOCKMAP service into the EBPF MAP table, and persist the EBPF MAP table file. A new service module, which is used to add an 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 quadruple, and uses the specified SOCKET as the local SOCKET. A forwarding notification module, which is used for the kernel to add a 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 peer SOCKET from the global TCP_HASHINFO table according to the reverse quadruple and saves the peer SOCKET to the data structure of the local SCOKET. A kernel protocol stack mode receiving module, which is used to determine whether there are unprocessed packets when switching to the kernel protocol stack mode. If so, the switch is not allowed; if not, it sets the sending mode of the local end and the receiving mode of the peer. When the peer receives, it preferentially receives packets from the SOCKMAP queue and then from the kernel protocol stack queue. A SOCKMAP mode receiving module, which is used to determine whether there are packets in the peer's SOCKMAP queue when switching to the SOCKMAP mode. If so, the switch is not allowed; if not, it sets the sending mode of the local end to the SOCKMAP mode and the receiving mode of the peer to the SOCKMAP mode. A packet receiving module, which is used to obtain packets from the kernel protocol stack queue and the SOCKMAP queue in sequence according to the forwarding mode.

9. An electronic device, characterized in that, Including a memory, a processor, and a computer program stored on the memory and executable on the processor. When the processor executes the program, it realizes the steps in a method for supporting the switching of the forwarding mode of the TCP connection on the same host as described in any one of claims 1-7.

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 the switching of the TCP connection forwarding mode with a host according to any one of claims 1-7.

Citation Information

Patent Citations

  • Reverse proxy methods and devices, and computer readable storage medium

    CN109547519A

  • Data packet filtering method and apparatus, and electronic device and computer-readable storage medium

    WO2022267815A1