A method and device for associating upstream and downstream TCP connections in the Linux kernel

By establishing a downstream TCP connection in the Linux kernel state and an upstream TCP connection in the user state, and saving their mapping relationships, the problem of inability to associate upstream and downstream TCP connections in the Linux kernel is solved, achieving consistency of traffic paths and advanced traffic forwarding features.

CN118433238BActive Publication Date: 2024-09-03BEIJING CHAITIN TECH CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202410890216.3
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2024-07-04
Publication Date
2024-09-03
Estimated Expiration
2044-07-04

AI Technical Summary

Technical Problem

In the Linux kernel state, the mapping relationship between the upstream TCP connection and the downstream TCP connection cannot be established, resulting in abnormal traffic forwarding and limiting the implementation of WAF's advanced traffic forwarding features on Linux systems.

Method used

By receiving the downstream TCP connection request in the Linux kernel mode, establish a downstream TCP connection with the client, assign it a unique identifier, and save the private data; initiate an upstream TCP connection request in the user mode, establish an upstream TCP connection with the Web server, and save it. Its mapping relationship with the downstream TCP connection enables the kernel state to obtain the private data of the downstream TCP connection when processing the upstream TCP connection.

Benefits of technology

It achieves the consistency of upstream and downstream traffic paths, avoids abnormal traffic forwarding, and supports the development of advanced traffic forwarding features on WAF.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118433238B
    Figure CN118433238B
Patent Text Reader

Abstract

The present invention discloses a method and device for associating upstream and downstream TCP connections in a Linux kernel, and relates to the field of communication technology, including: establishing a downstream TCP connection with a client in a Linux kernel state, and assigning a unique identifier to it, using the downstream TCP connection unique identifier as an index keyword, and saving the private data of the downstream TCP connection to the Linux kernel; establishing an upstream TCP connection with a Web server in a Linux user state, and assigning a unique identifier to it, obtaining the upstream TCP connection unique identifier and the unique identifier of its associated downstream TCP connection, and saving the mapping relationship between the two to the Linux kernel; when processing network data of the upstream TCP connection in the Linux kernel state, obtaining the private data of the corresponding downstream TCP connection through the upstream and downstream TCP connection information associated with the kernel. The present invention realizes the association of upstream and downstream TCP connections in the Linux kernel, ensures the consistency of the upstream and downstream traffic paths, avoids traffic forwarding anomalies, and further realizes the development of advanced traffic forwarding features on WAF.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of communication technology, and in particular to a method and device for associating upstream and downstream TCP connections in a Linux kernel. Background Art

[0002] WAF (Web Application Firewall) is a device that provides security protection for Web applications. To meet the needs of different network topologies, it supports multiple deployment modes, such as reverse proxy mode, transparent proxy mode, and traffic mirroring mode. For reverse proxy mode and transparent proxy mode, the WAF device can be used as a HTTP seven-layer proxy device to process and forward HTTP requests by establishing TCP connections with the client and server respectively.

[0003] In the prior art, WAF usually uses Linux system as the operating system and implements WAF proxy function through Linux user-state proxy software. It can establish a mapping relationship between upstream and downstream TCP connections in the user-state proxy software. However, in the Linux kernel state, the upstream TCP connection and the downstream TCP connection cannot establish a mapping relationship, and the two cannot be associated, making it difficult to correspond the upstream and downstream traffic paths, resulting in abnormal traffic forwarding. It is also difficult for WAF to further implement various advanced traffic forwarding features based on TCP connections. Summary of the invention

[0004] To address the above defects or deficiencies, the present invention provides a method and device for associating upstream and downstream TCP connections in the Linux kernel, by storing private data of the downstream TCP connection in the Linux kernel and the mapping relationship between the upstream and downstream TCP connections, associating the upstream and downstream TCP connections in the Linux kernel state, and obtaining the private data of the corresponding downstream TCP connection when processing the network data of the upstream TCP connection.

[0005] A first aspect of the present invention provides a method for associating upstream and downstream TCP connections in a Linux kernel, comprising:

[0006] Receive a downstream TCP connection request from a client in a Linux kernel state, establish a downstream TCP connection with the client, and assign a unique identifier to the downstream TCP connection; obtain the unique identifier of the downstream TCP connection, use the unique identifier as an index keyword, and save private data of the downstream TCP connection to a TCP connection data table of the Linux kernel;

[0007] Initiate an upstream TCP connection request with the Web server in Linux user mode, establish an upstream TCP connection with the Web server, and assign a unique identifier to the upstream TCP connection; obtain the unique identifier of the upstream TCP connection and the unique identifier of its associated downstream TCP connection, and save the mapping relationship between the two in the identifier mapping data table of the Linux kernel;

[0008] When processing network data of an upstream TCP connection in the Linux kernel state, obtain a unique identifier of the upstream TCP connection to which the network data belongs, use the unique identifier as an index keyword to query the identifier mapping data table of the Linux kernel to obtain the unique identifier of the downstream TCP connection associated with the upstream TCP connection to which the network data belongs, and then use the obtained unique identifier of the downstream TCP connection as an index keyword to query the TCP connection data table of the Linux kernel to obtain private data of the downstream TCP connection.

[0009] Furthermore, it also includes: the TCP connection data table of the Linux kernel and the identification mapping data table of the Linux kernel are the same data table.

[0010] Furthermore, it also includes: the unique identifier of the upstream and downstream TCP connections is the cookie information allocated by the Linux kernel to each socket.

[0011] Furthermore, the step of obtaining the unique identifier of the downstream TCP connection includes:

[0012] During the third handshake of the downstream TCP connection, a unique identifier of the TCP connection is obtained in the Linux kernel state.

[0013] Furthermore, it also includes: the private data of the downstream TCP connection includes header information of the data message at the second layer of the TCP protocol.

[0014] A second aspect of the present invention provides a device for associating upstream and downstream TCP connections in a Linux kernel, comprising:

[0015] The first module is used to receive a downstream TCP connection request from a client in a Linux kernel state, establish a downstream TCP connection with the client, and assign a unique identifier to the downstream TCP connection; obtain the unique identifier of the downstream TCP connection, use the unique identifier as an index keyword, and save the private data of the downstream TCP connection to a TCP connection data table of the Linux kernel;

[0016] The second module is used to initiate an upstream TCP connection request with the Web server in Linux user mode, establish an upstream TCP connection with the Web server, and assign a unique identifier to the upstream TCP connection; obtain the unique identifier of the upstream TCP connection and the unique identifier of its associated downstream TCP connection, and save the mapping relationship between the two in the identifier mapping data table of the Linux kernel;

[0017] The third module is used to obtain the unique identifier of the upstream TCP connection to which the network data belongs when processing the network data of the upstream TCP connection in the Linux kernel state, and use the unique identifier as an index keyword to query the identifier mapping data table of the Linux kernel to obtain the unique identifier of the downstream TCP connection associated with the upstream TCP connection to which the network data belongs, and then use the obtained unique identifier of the downstream TCP connection as an index keyword to query the TCP connection data table of the Linux kernel to obtain private data of the downstream TCP connection.

[0018] Furthermore, it also includes: the TCP connection data table of the Linux kernel and the identification mapping data table of the Linux kernel are the same data table.

[0019] Furthermore, it also includes: the unique identifier of the upstream and downstream TCP connections is the cookie information allocated by the Linux kernel to each socket.

[0020] Furthermore, the first module is further configured to obtain a unique identifier of the TCP connection in the Linux kernel state during the third handshake of the downstream TCP connection.

[0021] Furthermore, it also includes: the private data of the downstream TCP connection includes header information of the data message at the second layer of the TCP protocol.

[0022] The present invention provides a method and device for associating upstream and downstream TCP connections in the Linux kernel, which realizes storing its private data in the kernel according to the unique identifier of the downstream TCP connection. When the Linux kernel associates the upstream and downstream TCP connections and processes the network data of the upstream TCP connection in the Linux kernel state, the private data of the corresponding downstream TCP connection is obtained through the upstream and downstream TCP connection information associated with the kernel. The consistency of the upstream and downstream traffic paths is ensured, traffic forwarding anomalies are avoided, and advanced traffic forwarding features are further developed on the WAF. BRIEF DESCRIPTION OF THE DRAWINGS

[0023] Other features, objects and advantages of the present application will become more apparent by reading the detailed description of non-limiting embodiments made with reference to the following drawings:

[0024] Figure 1 This is a schematic diagram of the WAF proxy mode structure provided by an embodiment of the present application;

[0025] Figure 2 It is a flowchart of a method for associating upstream and downstream TCP connections in a Linux kernel for a WAF device provided by an embodiment of the present application;

[0026] Figure 3 This is a schematic diagram of the WAF transparent proxy mode structure of two TCP connection paths provided by an embodiment of the present application;

[0027] Figure 4 It is a structural diagram of a device for associating upstream and downstream TCP connections in a Linux kernel provided by an embodiment of the present application;

[0028] Figure 5 It is a structural schematic diagram of an electronic device provided by an embodiment of the present application. DETAILED DESCRIPTION

[0029] In order to make the purpose, technical solution and advantages of the embodiments of the present invention clearer, the technical solution in the embodiments of the present invention will be clearly and completely described below in conjunction with the drawings in the embodiments of the present invention. Obviously, the described embodiments are part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.

[0030] The terms used in the embodiments of the present invention are only for the purpose of describing specific embodiments, and are not intended to limit the present invention. The singular forms "a", "said" and "the" used in the embodiments of the present invention and the appended claims are also intended to include plural forms, unless the context clearly indicates other meanings.

[0031] It should be understood that although the terms first, second, third, etc. may be used to describe the acquisition modules in the embodiments of the present invention, the acquisition modules should not be limited to these terms. These terms are only used to distinguish the acquisition modules from each other.

[0032] The word "if" as used herein may be interpreted as "at the time of" or "when" or "in response to determining" or "in response to detecting", depending on the context. Similarly, the phrases "if it is determined" or "if (stated condition or event) is detected" may be interpreted as "when it is determined" or "in response to determining" or "when detecting (stated condition or event)" or "in response to detecting (stated condition or event)", depending on the context.

[0033] It should be noted that the directional words such as "upper", "lower", "left", and "right" described in the embodiments of the present invention are described at the angles shown in the drawings and should not be understood as limiting the embodiments of the present invention. In addition, in the context, it should also be understood that when it is mentioned that an element is formed "on" or "under" another element, it can not only be formed directly "on" or "under" another element, but also be formed "on" or "under" another element indirectly through an intermediate element.

[0034] WAF is a device that provides security protection for web applications. It can detect and forward traffic. To meet the needs of different business scenarios, WAF supports multiple deployment methods, such as reverse proxy mode, where the client establishes a TCP connection with WAF. After WAF receives the client's traffic request, it connects to the server with its own IP address; transparent proxy mode, where the client directly requests access to the server, WAF establishes a connection with the client with the server IP, and with the server with the client IP, intercepting and forwarding client requests. In proxy mode, it is easy to hide and protect the real server, and WAF, as an intermediate proxy server, provides security protection for traffic requests according to its own policies.

[0035] refer to Figure 1 , the steps for WAF to process HTTP requests in proxy mode are as follows:

[0036] WAF receives TCP connections from clients, which are called downstream TCP connections;

[0037] WAF receives HTTP requests sent by clients from downstream TCP connections;

[0038] WAF detects HTTP requests;

[0039] WAF initiates a TCP connection to the server, which is called an upstream TCP connection;

[0040] The WAF re-forwards the HTTP request through the upstream TCP connection.

[0041] WAF usually uses Linux system as operating system and implements HTTP proxy function through user-mode proxy software. Therefore, in the prior art, downstream TCP connection with the client and upstream TCP connection with the server are established in user space, and the upstream and downstream TCP connections can be matched through user-mode proxy software. However, in the Linux kernel, each upstream and downstream TCP connection is independent of each other, and the mapping relationship of TCP connections cannot be established in the kernel. This limits the WAF proxy mode from realizing more traffic forwarding features based on TCP connections.

[0042] To solve the above problems, see Figure 2As shown, this embodiment provides a method for associating upstream and downstream TCP connections in a Linux kernel for a WAF device, including:

[0043] Step S101, receiving a downstream TCP connection request from a client in a Linux kernel state, establishing a downstream TCP connection with the client, and assigning a unique identifier to the downstream TCP connection; obtaining the unique identifier of the downstream TCP connection, using the unique identifier as an index keyword, and saving private data of the downstream TCP connection to a TCP connection data table of the Linux kernel;

[0044] Specifically, the WAF device receives a TCP connection establishment request initiated by the client in the Linux kernel state, and establishes a TCP connection through a three-way handshake. The TCP connection between the client and the WAF is called a downstream TCP connection. In this embodiment, the first handshake is the client sending a SYN data packet, the flag bit SYN=1, and a randomly generated sequence number a. The WAF receives and learns that the client requests to establish a connection. At this time, the SYN data packet has no corresponding socket, and the unique identifier of the downstream TCP connection cannot be generated. The unique identifier is the cookie information assigned by the Linux kernel to each socket. A TCP connection can be uniquely identified in the Linux kernel through the cookie;

[0045] After the second handshake confirms the connection for WAF, the flags SYN=1, ACK=1 are set, the confirmation sequence number ack=a+1, the sequence number b is randomly generated, and this SYN / ACK packet is sent to the client to indicate the connection is confirmed. If WAF confirms the connection, it creates a socket for the downstream TCP connection in kernel state and assigns the corresponding cookie. Exemplarily, eBPF (extended Berkeley Packet Filter) is mounted on the ingress processing path of the Linux network data packet through the traffic controller. Through eBPF, programs can be run in the Linux kernel without modifying the kernel code. The eBPF program is executed in the Linux kernel state to create a socket for the current downstream TCP connection and assign a cookie.

[0046] The third handshake is when the client receives the confirmation correctly, sets the flag ACK=1, confirms the sequence number ack=b+1, and sends this ACK data packet to the WAF. After the WAF receives the confirmation correctly, it successfully establishes the downstream TCP connection, and data can be transmitted between the client and the WAF. When the third handshake is established for the downstream TCP connection, the Linux kernel has created a socket for the downstream TCP connection and assigned the corresponding cookie, so the cookie of the downstream TCP connection can be correctly obtained. The cookie of the downstream TCP connection is obtained in the Linux kernel state, and the cookie is used as the index keyword to save all the private data of the downstream TCP connection to the TCP connection data table of the Linux kernel. Exemplarily, after the third handshake, the eBPF program is executed in the Linux kernel state to obtain the cookie of the downstream TCP connection, and the cookie is used as the index keyword to obtain the private data of the downstream TCP connection, such as the header information of the data packet of the TCP protocol at the second layer, and the private data is stored in the eBPF map of the Linux kernel. This map is called the TCP connection data table.

[0047] Step S102, initiating an upstream TCP connection request with the Web server in Linux user mode, establishing an upstream TCP connection with the Web server, and assigning a unique identifier to the upstream TCP connection; obtaining the unique identifier of the upstream TCP connection and the unique identifier of its associated downstream TCP connection, and saving the mapping relationship between the two in the identifier mapping data table of the Linux kernel;

[0048] Specifically, WAF initiates an upstream TCP connection request with the Web server in Linux user mode, and establishes an upstream TCP connection with the Web server through a three-way handshake in Linux user mode in the same manner as described in step S101, and creates a socket for the upstream TCP connection and assigns a unique identifier.

[0049] The upstream TCP connection is mapped one-to-one with the downstream TCP connection through Linux user-state software. Optionally, the user-state software includes Nginx, HaProxy, etc., and the "SO_COOKIE" socket option is called through the "getsockopt()" system to read the cookie of the upstream TCP connection and the cookie of the downstream TCP connection from the kernel respectively, and a corresponding cookie mapping relationship is established between the two according to the corresponding upstream and downstream TCP connections, and the cookie mapping relationship between the upstream TCP connection and the corresponding downstream TCP connection is written into the eBPF map of the Linux kernel. This map is called an identification mapping data table, which realizes the association of the upstream and downstream TCP connections in the Linux kernel.

[0050] Step S103, when processing the network data of the upstream TCP connection in the Linux kernel state, obtain the unique identifier of the upstream TCP connection to which the network data belongs, use the unique identifier as the index keyword to query the identifier mapping data table of the Linux kernel to obtain the unique identifier of the downstream TCP connection associated with the upstream TCP connection to which the network data belongs, and then use the obtained unique identifier of the downstream TCP connection as the index keyword to query the TCP connection data table of the Linux kernel to obtain the private data of the downstream TCP connection.

[0051] Specifically, this embodiment stores private data of the downstream TCP connection in the Linux kernel, writes a mapping relationship between unique identifiers of the upstream and downstream TCP connections, associates the upstream and downstream TCP connections in the Linux kernel, and then obtains the private data of the corresponding downstream TCP connection when processing a data packet of the upstream TCP connection in the Linux kernel state. Exemplarily, the steps of obtaining the private data of the corresponding downstream TCP connection when processing a data packet of the upstream TCP connection in the Linux kernel state include:

[0052] In Linux kernel state, call the eBPF program to obtain the cookie of the upstream TCP connection to which the processed data packet belongs through the "bpf_get_socket_cookie" function;

[0053] Using the cookie of the upstream TCP connection as the index keyword, query the identifier mapping data table to obtain the corresponding downstream TCP connection cookie;

[0054] The cookie of the downstream TCP connection is used as an index keyword to query the TCP connection data table to obtain the private data of the downstream TCP connection.

[0055] By associating upstream and downstream TCP connections in the Linux kernel and saving private data for each TCP connection in the kernel for calling, WAF can further develop advanced features. For example, a connection-based network forwarding function can be implemented: in the kernel state, after receiving the downstream TCP connection from the client, some network forwarding information of the downstream TCP connection can be saved, such as network interface information, layer 2 network information, etc.; when WAF then initiates an upstream TCP connection to the server, since the mapping relationship between the upstream and downstream TCP connections is saved in the kernel state, the network forwarding information of the downstream TCP connection corresponding to the current upstream TCP connection can be queried, and the network forwarding behavior of WAF can be customized; the diagnostic debugging function is implemented: since more information about the TCP connection can be output in the kernel state, after establishing the mapping relationship between the upstream and downstream TCP connections in the kernel, it is more convenient to perform fault diagnosis on abnormal traffic of a client in the kernel state.

[0056] The following introduces the application scenario of the method for associating upstream and downstream TCP connections in the Linux kernel. In the transparent proxy mode of WAF, it is necessary to maintain the transparency of the traffic, that is, after passing through the WAF transparent proxy, the layer 2 network header of the traffic cannot be changed. The layer 2 network header is the header information of the data message of the TCP protocol at the second layer. Using the method for associating upstream and downstream TCP connections in the kernel proposed in this embodiment, it can be ensured based on the connection granularity that the layer 2 network header used by the upstream and downstream TCP connections remains unchanged after passing through the WAF proxy.

[0057] Exemplarily, the method for associating upstream and downstream TCP connections in the Linux kernel of this embodiment can be applied to Figure 3 In the network architecture shown, the client and the server need to establish two TCP connections, but the two TCP connections reach the WAF through two different routers, that is, two different network forwarding paths. Therefore, the two downstream TCP connections have different layer 2 network headers. In order to transparently proxy TCP traffic, the layer 2 network headers of the upstream and downstream TCP connections of the WAF need to maintain a one-to-one correspondence: the upstream TCP connection 1 needs to use the layer 2 network header 1 corresponding to the downstream TCP connection 1, and the upstream TCP connection 2 needs to use the layer 2 network header 2 corresponding to the downstream TCP connection 2. The steps for achieving a one-to-one correspondence between the layer 2 network headers of the upstream and downstream TCP connections through the method of this embodiment are:

[0058] When WAF receives each downstream TCP connection, it allocates a cookie to each downstream TCP connection through the eBPF program in the Linux kernel state, and saves the corresponding layer 2 network header of the downstream TCP connection to the TCP connection data table;

[0059] The cookie mapping relationship of the upstream and downstream TCP connections is saved to the identification mapping data table through the user-mode proxy software;

[0060] When WAF establishes an upstream TCP connection with the server, it queries the kernel's identification mapping data table to obtain the cookie of the downstream TCP connection corresponding to the upstream TCP connection. By querying the TCP connection data table through the cookie of the downstream TCP connection, the original Layer 2 network header can be obtained.

[0061] In the application scenario of WAF transparent proxy mode, the Linux kernel associates the upstream and downstream TCP connections. The private data of the corresponding downstream TCP connection can be obtained through the cookie of the upstream TCP connection, so that the second-layer network header of each pair of upstream and downstream TCP connections can correspond to each other, ensuring the consistency of the round-trip traffic path.

[0062] The present embodiment provides a method for associating upstream and downstream TCP connections in the Linux kernel for a WAF device, which implements the storage of private data of the downstream TCP connection in the kernel according to the cookie, corresponds to the upstream and downstream TCP connections in the Linux user state and writes into the kernel identification mapping data table, implements the association of upstream and downstream TCP connections in the Linux kernel, ensures the consistency of the round-trip paths of upstream and downstream traffic, avoids traffic forwarding anomalies, enables the private data of the corresponding downstream TCP connection to be obtained when processing the network data of the upstream TCP connection in the Linux kernel state, and further implements the development of various advanced traffic forwarding features on the WAF.

[0063] Another embodiment of the present invention further provides a device 200 for associating upstream and downstream TCP connections in a Linux kernel, see Figure 4 As shown, including:

[0064] The first module 201 is used to receive a downstream TCP connection request from a client in a Linux kernel state, establish a downstream TCP connection with the client, and assign a unique identifier to the downstream TCP connection; obtain the unique identifier of the downstream TCP connection, use the unique identifier as an index keyword, and save private data of the downstream TCP connection into a TCP connection data table of the Linux kernel;

[0065] The second module 202 is used to initiate an upstream TCP connection request with the Web server in the Linux user state, establish an upstream TCP connection with the Web server, and assign a unique identifier to the upstream TCP connection; obtain the unique identifier of the upstream TCP connection and the unique identifier of the associated downstream TCP connection, and save the mapping relationship between the two in the identifier mapping data table of the Linux kernel;

[0066] The third module 203 is used to obtain the unique identifier of the upstream TCP connection to which the network data belongs when processing the network data of the upstream TCP connection in the Linux kernel state, and use the unique identifier as an index keyword to query the identifier mapping data table of the Linux kernel to obtain the unique identifier of the downstream TCP connection associated with the upstream TCP connection to which the network data belongs, and then use the obtained unique identifier of the downstream TCP connection as an index keyword to query the TCP connection data table of the Linux kernel to obtain private data of the downstream TCP connection.

[0067] Furthermore, it also includes: the TCP connection data table of the Linux kernel and the identification mapping data table of the Linux kernel are the same data table.

[0068] Furthermore, it also includes: the unique identifier of the upstream and downstream TCP connections is the cookie information allocated by the Linux kernel to each socket.

[0069] Furthermore, the first module 201 is further configured to obtain a unique identifier of the TCP connection in the Linux kernel state during the third handshake of the downstream TCP connection.

[0070] Furthermore, it also includes: the private data of the downstream TCP connection includes header information of the data message at the second layer of the TCP protocol.

[0071] It should be noted that the device 200 for associating upstream and downstream TCP connections in the Linux kernel provided in this embodiment corresponds to a technical solution that can be used to execute various method embodiments. Its implementation principle and technical effects are similar to the method and will not be repeated here.

[0072] See also Figure 5 Another embodiment of the present invention further provides an electronic device 300 for associating upstream and downstream TCP connections in a Linux kernel. The electronic device 300 in this embodiment is a WAF device.

[0073] like Figure 5 As shown, the electronic device 300 may include a processing device (e.g., a central processing unit, a graphics processing unit, etc.) 301, which can perform various appropriate actions and processes according to a program stored in a read-only memory (ROM) 302 or a program loaded from a storage device 308 to a random access memory (RAM) 303 to implement the method of each embodiment described in the present invention. In the RAM 303, various programs and data required for the operation of the electronic device 300 are also stored. The processing device 301, the ROM 302, and the RAM 303 are connected to each other via a bus 304. An input / output (I / O) interface 305 is also connected to the bus 304.

[0074] Typically, the following devices may be connected to the I / O interface 305: an input device 306 including, for example, a touch screen, a touch pad, a keyboard, a mouse, a camera, a microphone, an accelerometer, a gyroscope, etc.; an output device 307 including, for example, a liquid crystal display (LCD), a speaker, a vibrator, etc.; a storage device 308 including, for example, a magnetic tape, a hard disk, etc.; and a communication device 309. The communication device 309 may allow the electronic device 300 to communicate with other devices wirelessly or by wire to exchange data. Figure 5 The electronic device 300 is shown with various devices, but it should be understood that it is not required to implement or possess all the devices shown. More or fewer devices may be implemented or possessed instead.

[0075] In particular, according to an embodiment of the present invention, the process described above with reference to the flowchart can be implemented as a computer software program. For example, an embodiment of the present invention includes a computer program product, which includes a computer program carried on a non-transitory computer-readable medium, and the computer program includes a program code for executing the method shown in the flowchart, thereby implementing the method described above. In such an embodiment, the computer program can be downloaded and installed from the network through the communication device 309, or installed from the storage device 308, or installed from the ROM 302. When the computer program is executed by the processing device 301, the above-mentioned functions defined in the method of the embodiment of the present invention are executed.

[0076] The above description is only a preferred embodiment of the present invention. Those skilled in the art should understand that the scope of disclosure involved in the present invention is not limited to the technical solution formed by a specific combination of the above technical features, but also should cover other technical solutions formed by any combination of the above technical features or their equivalent features without departing from the above disclosed concept. For example, the above features are replaced with the technical features with similar functions disclosed in the present invention (but not limited to) to form a technical solution.

Claims

1. A method for associating upstream and downstream TCP connections in a Linux kernel, for use in a WAF device, characterized in that: include: Receive a downstream TCP connection request from a client in Linux kernel state, establish a downstream TCP connection with the client, and assign a unique identifier to the downstream TCP connection; During the third handshake of the downstream TCP connection, obtaining a unique identifier of the downstream TCP connection in the Linux kernel state, using the unique identifier as an index keyword, and saving private data of the downstream TCP connection in a TCP connection data table of the Linux kernel; The unique identifier of the downstream TCP connection is the cookie information allocated by the Linux kernel to each socket; Initiate an upstream TCP connection request with the Web server in Linux user mode, establish an upstream TCP connection with the Web server, and assign a unique identifier to the upstream TCP connection; Obtaining a unique identifier of the upstream TCP connection and a unique identifier of its associated downstream TCP connection, and saving a mapping relationship between the two in an identifier mapping data table of the Linux kernel; The unique identifier of the upstream TCP connection is the cookie information allocated by the Linux kernel to each socket; When processing network data of an upstream TCP connection in the Linux kernel state, obtain a unique identifier of the upstream TCP connection to which the network data belongs, use the unique identifier as an index keyword to query the identifier mapping data table of the Linux kernel to obtain the unique identifier of the downstream TCP connection associated with the upstream TCP connection to which the network data belongs, and then use the obtained unique identifier of the downstream TCP connection as an index keyword to query the TCP connection data table of the Linux kernel to obtain private data of the downstream TCP connection.

2. A method for associating upstream and downstream TCP connections in a Linux kernel according to claim 1, characterized in that: The TCP connection data table of the Linux kernel and the identification mapping data table of the Linux kernel are the same data table.

3. A method for associating upstream and downstream TCP connections in a Linux kernel according to claim 1, characterized in that: The private data of the downstream TCP connection includes header information of a data message at the second layer of the TCP protocol.

4. A device for associating upstream and downstream TCP connections in a Linux kernel, characterized in that: include: The first module is used to receive a downstream TCP connection request from a client in a Linux kernel state, establish a downstream TCP connection with the client, and assign a unique identifier to the downstream TCP connection; During the third handshake of the downstream TCP connection, obtaining a unique identifier of the downstream TCP connection in the Linux kernel state, using the unique identifier as an index keyword, and saving private data of the downstream TCP connection in a TCP connection data table of the Linux kernel; The unique identifier of the downstream TCP connection is the cookie information allocated by the Linux kernel to each socket; The second module is used to initiate an upstream TCP connection request with the Web server in Linux user mode, establish an upstream TCP connection with the Web server, and assign a unique identifier to the upstream TCP connection; Obtaining a unique identifier of the upstream TCP connection and a unique identifier of its associated downstream TCP connection, and saving a mapping relationship between the two in an identifier mapping data table of the Linux kernel; The unique identifier of the upstream TCP connection is the cookie information allocated by the Linux kernel to each socket; The third module is used to obtain the unique identifier of the upstream TCP connection to which the network data belongs when processing the network data of the upstream TCP connection in the Linux kernel state, and use the unique identifier as an index keyword to query the identifier mapping data table of the Linux kernel to obtain the unique identifier of the downstream TCP connection associated with the upstream TCP connection to which the network data belongs, and then use the obtained unique identifier of the downstream TCP connection as an index keyword to query the TCP connection data table of the Linux kernel to obtain private data of the downstream TCP connection.

5. A device for associating upstream and downstream TCP connections in a Linux kernel according to claim 4, characterized in that: The TCP connection data table of the Linux kernel and the identification mapping data table of the Linux kernel are the same data table.

6. A device for associating upstream and downstream TCP connections in a Linux kernel according to claim 4, characterized in that: The private data of the downstream TCP connection includes header information of a data message at the second layer of the TCP protocol.