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.