Request message sending method and device, equipment, medium and product
By using eBPF programs in the kernel network protocol stack to intercept and rerout request packets, the flexibility and intrusion problems when sockets bind multiple addresses in the existing technology are solved, and an efficient and flexible request packet sending method is realized.
Patent Information
- Application Number
- CN202411849004.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-12-13
- Publication Date
- 2025-04-25
- Estimated Expiration
- Not applicable · inactive patent
AI Technical Summary
When the prior art realizes that multiple addresses are bound to one socket, it is difficult to flexibly configure the IP address and port bound to the socket, and it is invasive to the service code, which limits the applicability of the method of sending request packets.
The pre-configured eBPF program intercepts the request message in the socket selection logic of the kernel network protocol stack, and determines the target socket of the request message based on the binding relationship between the pre-configured socket and the IP address and port, so as to send the request message to the corresponding target socket.
It realizes that a socket binds multiple addresses to send technical packets without intruding into the service code, avoids the risk of exposure to the public network of internal services, and ensures the flexible configuration of the IP addresses and ports bound to the socket, improving the applicability of the request packet sending method.
Smart Images

Figure CN119892407A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of communication technology, and in particular to a method, device, equipment, medium and product for sending a request message. Background Art
[0002] In application scenarios such as large-scale service systems, a socket is usually bound to multiple addresses to implement message sending, so that each request message with different destination Internet Protocol (IP) addresses and destination ports can be received by one service, thereby reducing resource waste.
[0003] In the related art, a specific IP address (such as INADDR_ANY or 0.0.0.0) is usually used when creating a socket through business code, or a special parameter IP_TRANSPARENT is configured when creating a socket through business code to implement binding of multiple addresses to a socket, so that each request message with different destination IP addresses and destination ports can be received by the socket (that is, by the service related to the socket).
[0004] However, the above implementation method of binding multiple addresses to a socket based on a specific IP address or special parameters has the defects of being difficult to flexibly configure the IP address and port to which the socket is bound or being invasive to the business code, thereby limiting the applicability of the request message sending method. Summary of the invention
[0005] In view of the above problems, the embodiments of the present application provide a method, apparatus, device, medium and product for sending a request message, so as to overcome the above problems or at least partially solve the above problems.
[0006] A first aspect of an embodiment of the present application provides a method for sending a request message, the method comprising:
[0007] Intercepting the request message during the execution of the socket selection logic of the kernel network protocol stack by a first program, wherein the first program is a pre-configured extended Berkeley packet filter eBPF program;
[0008] Determine, through the first program, the target socket corresponding to each of the request messages according to the pre-configured binding relationship between the socket and the IP address and port, and the destination IP address and destination port of each of the intercepted request messages;
[0009] Through the first program, each of the request messages is sent to a target socket corresponding to each of the request messages.
[0010] As a possible implementation mode, intercepting the request message during the execution of the socket selection logic of the kernel network protocol stack by the first program includes:
[0011] By means of the first program, after the steps related to searching for connection status socket in the socket selection logic are executed, each request message processed by the steps related to searching for connection status socket is intercepted;
[0012] The step of sending each of the request messages to a target socket corresponding to each of the request messages through the first program includes:
[0013] By means of the first program, the destination IP address and the destination port of each of the request messages are modified to the IP address and the port used by the target socket corresponding to each of the request messages;
[0014] Through the first program, each of the modified request messages is transmitted to the steps related to searching for a listening state socket in the socket selection logic for processing, so as to send each of the request messages to a target socket corresponding to each of the request messages.
[0015] As a possible implementation manner, the target socket corresponding to each of the request messages is determined by the first program executing the following steps:
[0016] Query whether the destination IP address and destination port of the request message are recorded in the pre-stored address table;
[0017] In the case where the destination IP address and the destination port of the request message are recorded in the address table, the socket bound to the destination IP address and the destination port is searched in the pre-stored socket table to obtain the target socket corresponding to the request message;
[0018] The method further comprises:
[0019] When it is found that the destination IP address and destination port of the request message are not recorded in the address table, the request message is directly transmitted to the steps related to searching the listening status socket for processing through the first program, so as to send the request message according to the destination IP address and destination port of the request message.
[0020] As a possible implementation, the method further includes:
[0021] When the socket bound to the destination IP address and the destination port is not found in the socket table, the request message is discarded through the first program.
[0022] As a possible implementation, the method further includes:
[0023] Loading the first program and the target data structure stored in the configuration file into the kernel through a second program, wherein the second program is a pre-configured user-mode program, and the target data structure supports storing and sharing data between the eBPF program and the user space;
[0024] Acquire, by the second program, a socket for sending a message using the first program according to a preconfigured process identifier of the target process;
[0025] Through the second program, the pre-configured IP address and port are used as the acquired IP address and port to be bound to the socket, and the target data structure is used to store the socket and the IP address and port to be bound to it.
[0026] As a possible implementation manner, when there is only one socket that needs to use the first program to send a message, the target data structure includes:
[0027] The eBPF map of type BPF_MAP_TYPE_HASH is used to store the IP address and port to which the socket needs to be bound;
[0028] An eBPF map of type BPF_MAP_TYPE_SOCKMAP used to store the socket.
[0029] According to a second aspect of an embodiment of the present application, a request message sending device is provided, the device comprising:
[0030] A message interception module, used to intercept request messages during the execution of the socket selection logic of the kernel network protocol stack through a first program, wherein the first program is a pre-configured extended Berkeley packet filter eBPF program;
[0031] A data processing module, configured to determine, through the first program, a target socket corresponding to each of the request messages according to a pre-configured binding relationship between the socket and the IP address and the port, and a destination IP address and a destination port of each of the intercepted request messages;
[0032] The message sending module is used to send each of the request messages to the target socket corresponding to each of the request messages through the first program.
[0033] According to a third aspect of an embodiment of the present application, an electronic device is provided, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein when the processor executes the program, the steps of the request message sending method described in the first aspect are implemented.
[0034] According to a fourth aspect of an embodiment of the present application, a computer-readable storage medium is provided, on which a computer program / instruction is stored. When the computer program / instruction is executed by a processor, the steps of the request message sending method described in the first aspect are implemented.
[0035] A fifth aspect of an embodiment of the present application provides a computer program product, including a computer program / instruction, which, when executed by a processor, implements the request message sending method as described in the first aspect disclosed in the embodiment of the present application.
[0036] The embodiment of the present application includes the following advantages: through the pre-configured eBPF program (i.e., the first program), the message request is intercepted in the kernel network protocol stack, and according to the binding relationship between the pre-configured socket and the IP address and port, and the destination IP address and destination port of each intercepted request message, the target socket corresponding to each request message is determined, and then each request message is sent to the target socket corresponding to each request message. In this way, by using the eBPF program to implement the message sending based on binding multiple addresses to one socket, the intrusion of the business code can be avoided, and based on the binding relationship between the pre-configured socket and the IP address and port, the flexible configuration of the IP address and port bound to the socket (i.e., the target socket) can be guaranteed, thereby improving the applicability of the request message sending method. BRIEF DESCRIPTION OF THE DRAWINGS
[0037] In order to more clearly illustrate the technical solutions of the embodiments of the present application, the drawings required for use in the description of the embodiments of the present application will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative labor.
[0038] Figure 1 This is a schematic diagram of the effect of sending a request message based on a specific IP address in the related technology;
[0039] Figure 2It is a schematic diagram of the effect of sending a request message based on special parameters in the related art;
[0040] Figure 3 It is an implementation flow chart of a method for sending a request message in an embodiment of the present application;
[0041] Figure 4 It is a schematic diagram of processing a request message in a kernel network protocol stack in an embodiment of the present application;
[0042] Figure 5 It is a schematic diagram of the effect of sending a request message based on the first program in an embodiment of the present application;
[0043] Figure 6 is a schematic diagram of a socket selection logic in an embodiment of the present application;
[0044] Figure 7 It is a structural diagram of a request message sending device in an embodiment of the present application;
[0045] Figure 8 It is a schematic diagram of an electronic device in an embodiment of the present application. DETAILED DESCRIPTION
[0046] To facilitate understanding of the technical solutions provided by the present application, the main technical concepts involved in the embodiments of the present application are briefly described below.
[0047] Extended Berkeley Packet Filter (eBPF): is a technology that can run sandboxed programs in the operating system kernel without modifying the kernel code or loading kernel modules.
[0048] Socket: An abstract interface between the application layer and the transport layer in a computer network, used to implement direct data exchange between applications.
[0049] User-mode program: a program running in user mode that can only access restricted resources and execute restricted instruction sets. For example, it cannot write to the storage space of other processes to prevent security risks to the operating system.
[0050] eBPF map: is a special data structure used to store and share data between eBPF programs and user space. eBPF map is a key-value store that allows eBPF programs to store data persistently and share information between the kernel and user space.
[0051] Currently, there are two main ways to implement binding multiple addresses to a socket, as follows:
[0052] Method 1:
[0053] When creating a socket through business code, use a specific IP address (such as INADDR_ANY or 0.0.0.0). This socket will listen to all IP addresses on the relevant machine (such as the server where the relevant service is deployed). The effect diagram of sending a request message based on a specific IP address is as follows Figure 1 shown.
[0054] The relevant business pseudo code is as follows:
[0055] s=socket(AF_INET,SOCK_STREAM,0)
[0056] s.bind(("0.0.0.0",8080))
[0057] s.listen(1)
[0058] It should be noted that the implementation method of binding multiple addresses to a socket based on a specific IP address mainly has the following defects, which affects the applicability of the relevant request message sending method:
[0059] 1. Only one port can be specified for binding, and multiple ports cannot be bound.
[0060] 2. Once the socket is bound to 0.0.0.0, the request message associated with any IP address on the relevant machine will be sent to this socket. However, in actual situations, it may not be necessary to send so many request messages associated with IP addresses, which will cause a waste of IP addresses.
[0061] 3. Socket binding to 0.0.0.0 will create the risk of exposing internal services to the public network.
[0062] 4. The port used by INADDR_ANY is globally exclusive, that is, after one socket is used, other sockets on the related machine cannot be used.
[0063] Method 2:
[0064] When creating a socket through the business code, configure the special parameter IP_TRANSPARENT to use the iptables and TPROXY capabilities of the Linux machine. Specifically, configure routing on the machine to route traffic requesting the destination network segment (i.e., related request messages whose destination IP address belongs to the destination network segment) to the local machine; then, create a TPROXY interception rule on the PREROUTING chain of iptables to redirect traffic; finally, configure the special parameter IP_TRANSPARENT when creating a socket through the business code, so as to implement a socket binding multiple addresses based on the iptables and TPROXY capabilities of the Linux machine. The effect diagram of sending request messages based on special parameters is shown in the figure below. Figure 2 shown.
[0065] The relevant machine settings are as follows:
[0066]
[0067] The relevant business pseudo code is as follows:
[0068] s=socket(AF_INET,SOCK_STREAM,0)
[0069] int optval = 1
[0070] setsockopt(s,SOL_IP,IP_TRANSPARENT,&optval,sizeof(optval))
[0071] s.bind(("0.0.0.0",8080))
[0072] s.listen(1)
[0073] It should be noted that although the implementation method of binding multiple addresses to a socket based on special parameters allows a socket to be bound to multiple IP addresses and ports, and the bound multiple IP addresses can specify a range, because ordinary services generally turn off IP_TRANSPARENT related functions by default, this implementation method requires additionally turning on IP_TRANSPARENT related functions, which is invasive and unfriendly to the business code, and thus affects the applicability of the relevant request message sending method.
[0074] In view of the problems existing in the above-mentioned related technologies, the embodiments of the present application propose a method, device, equipment, medium and product for sending request messages. Through a pre-configured eBPF program (i.e., the first program), the relevant traffic of the request message is intercepted in the Linux kernel, and the intercepted request message is sent according to the binding relationship between the pre-configured socket and the IP address and port. Thus, without intruding the business code or binding a specific IP address, a socket is bound to multiple addresses, which can avoid the risk of exposing internal services to the public network, and the IP address and port bound to the socket are both within a configurable range. In this way, the applicability of the method for sending request messages can be effectively improved.
[0075] In combination with the accompanying drawings, a request message sending method, apparatus, device, medium and product provided in an embodiment of the present application are described in detail through some embodiments and their application scenarios.
[0076] First, refer to Figure 3 As shown, it is an implementation flow chart of a method for sending a request message provided in an embodiment of the present application, and the method comprises the following steps:
[0077] Step S11: intercepting the request message during the execution of the socket selection logic of the kernel network protocol stack through a first program, wherein the first program is a pre-configured extended Berkeley packet filter eBPF program.
[0078] In specific implementation, refer to Figure 4 As shown in the figure, for the request message entering the kernel network protocol stack, a ring buffer is usually used to cache the request traffic (i.e., each request message), and then the alloc_skb function is called to allocate a sk_buff structure (which is a carrier for encapsulating and transmitting data) to each cached request message.
[0079] Then, the PREROUTING chain of the raw table is used to process each packet (i.e., request message) before the connection tracking (conntrack) logic is executed, and then the connection tracking logic is executed to generate a connection record entry for each packet. Then, the PREROUTING chain in the mangle table is used to modify the header information of the packet (such as modifying the survival time, service type, etc.), and then the PREROUTING chain of the nat table is used to process each packet before the routing decision (routing decision) logic is executed, and then the routing decision logic is executed to find an entry that matches the destination address of the packet (such as the destination IP address and the destination port), and the packet is processed according to the matching result (such as executing the routing or discarding of the packet). Then, a filter is used to determine whether to allow the packet to enter (INPUT) according to various conditions, and then the packets allowed to enter are processed through the socket selection (socket lookup) logic, and then the relevant packets are sent to the relevant socket, that is, the relevant packets are transmitted to the receiving buffer (socket receive buffer) of the relevant socket.
[0080] Based on the correlation between each processing logic and the socket in the above-mentioned kernel network protocol stack, this application configures the execution position of the eBPF program in the Linux kernel network protocol stack within the socket selection logic (that is, when the request message arrives at the socket selection logic, it will trigger the execution of the eBPF program). For example, the eBPF program of the BPF_PROG_TYPE_SK_LOOKUP type can be configured to implement the configuration of the eBPF program whose execution position is located within the socket selection logic. In this way, it can be ensured that the configured eBPF program (i.e., the first program) can more reliably obtain the destination IP address and destination port of the request message and other related information for determining the target socket, so as to ensure that each intercepted request message can be correctly sent to the corresponding target socket in the future.
[0081] Step S12: through the first program, according to the pre-configured binding relationship between the socket and the IP address and port, and the destination IP address and destination port of each intercepted request message, determine the target socket corresponding to each request message.
[0082] In specific implementation, the binding relationship between the socket and the IP address and port can be flexibly configured according to user needs, that is, the user can flexibly configure the range of IP addresses and port ranges to which each socket needs to be bound according to actual needs.
[0083] After configuring the binding relationship, a mapping table can be established to store the binding relationship. For example, for each socket, different combinations of the IP address and port to which the socket needs to be bound can be used as keys in the mapping table, and the socket can be used as a value in the mapping table, thereby realizing the storage of the binding relationship in the mapping table in the form of key-value pairs. The mapping table is then written into a storage area that supports access by the first program. The first program can then access the storage area, and use the destination IP address and destination port of each request message as keys to query the mapping table in the storage area, and then use the queried values (i.e., each socket) as the target socket corresponding to each request message.
[0084] Step S13: through the first program, each of the request messages is sent to the target socket corresponding to each of the request messages.
[0085] In specific implementation, the first program can modify the destination IP address and destination port of each request message intercepted during the execution of the socket selection logic to the IP address and port used by the corresponding target socket, and then transmit the modified request messages to the relevant subsequent steps of the socket selection logic for normal processing to continue executing the socket selection logic. After the socket selection logic is executed, the modified request messages will be sent to the receiving buffer of the socket (i.e., the corresponding target socket) corresponding to its current destination IP address and current destination port, thereby realizing the sending of each of the request messages to the target socket corresponding to each of the request messages. The schematic diagram of the effect of request message sending based on the first program is shown in Figure 5 shown.
[0086] By adopting the technical solution of the embodiment of the present application, the message request is intercepted in the kernel network protocol stack through the pre-configured eBPF program (i.e., the first program), and the target socket corresponding to each request message is determined according to the binding relationship between the pre-configured socket and the IP address and port, as well as the destination IP address and destination port of each intercepted request message, and then each of the request messages is sent to the target socket corresponding to each of the request messages. In this way, by using the eBPF program to implement the message sending based on binding multiple addresses to one socket, the intrusion of the business code can be avoided, and based on the binding relationship between the pre-configured socket and the IP address and port, the flexible configuration of the IP address and port bound to the socket (i.e., the target socket) can be guaranteed, thereby improving the applicability of the request message sending method.
[0087] As a possible implementation mode, intercepting the request message during the execution of the socket selection logic of the kernel network protocol stack by the first program includes:
[0088] By means of the first program, after the steps related to searching for connection status socket in the socket selection logic are executed, each request message processed by the steps related to searching for connection status socket is intercepted;
[0089] The step of sending each of the request messages to a target socket corresponding to each of the request messages through the first program includes:
[0090] By means of the first program, the destination IP address and the destination port of each of the request messages are modified to the IP address and the port used by the target socket corresponding to each of the request messages;
[0091] Through the first program, each of the modified request messages is transmitted to the steps related to searching for a listening state socket in the socket selection logic for processing, so as to send each of the request messages to a target socket corresponding to each of the request messages.
[0092] It should be noted that the socket selection logic can usually be divided into two steps, namely:
[0093] Step 1: First use a 4-tuple to find out whether there is a socket in a connected state. If there is a socket in a connected state, the execution of the socket selection logic ends. If there is no socket in a connected state, go to step 2.
[0094] Step 2: Use a 2-tuple to find out if there is a socket in the listening state.
[0095] Considering that the request message needs to be sent based on a socket binding multiple address technology, its destination IP address and destination port are usually virtual IP addresses and ports, that is, the relevant request message is usually processed through step 2 to achieve sending. Therefore, the present application configures the execution position of the first program between step 1 and step 2 to provide an implementation method of intercepting the request message during the execution of the socket selection logic of the kernel network protocol stack by the first program and then sending it to the target socket.
[0096] Specifically, refer to Figure 6As shown in the schematic diagram of the socket selection logic, each request message will be intercepted by the first program (whose execution position is configured between step one and step two) after being processed by step one (i.e., the step related to searching for the connection status socket).
[0097] After the first program modifies the destination IP address and destination port of each intercepted request message to the IP address and port used by the target socket corresponding to each of the request messages, it is then handed over to step two for processing. Then, each of the request messages can be sent to the target socket corresponding to each of the request messages through the original steps of the socket selection logic. In this way, the changes to the socket selection logic can be reduced and the difficulty of implementing the request message sending method provided in the present application can be reduced.
[0098] Optionally, the target socket corresponding to each of the request messages is determined by the first program executing the following steps:
[0099] Query whether the destination IP address and destination port of the request message are recorded in the pre-stored address table;
[0100] In the case where the destination IP address and the destination port of the request message are recorded in the address table, the socket bound to the destination IP address and the destination port is searched in the pre-stored socket table to obtain the target socket corresponding to the request message;
[0101] The method further comprises:
[0102] When it is found that the destination IP address and destination port of the request message are not recorded in the address table, the request message is directly transmitted to the steps related to searching the listening status socket for processing through the first program, so as to send the request message according to the destination IP address and destination port of the request message.
[0103] In a specific implementation, an address table can be established in advance in a storage area that supports access by eBPF programs to store the IP addresses and ports associated with the pre-configured binding relationships (such as the range of related IP addresses and the range of ports), and a socket table can be established in the storage area to store the binding relationships. Thus, the first program can quickly determine whether it is necessary to modify the destination address of the request message to send it to the corresponding target socket by querying whether the address table records the destination IP address and destination port of the currently intercepted request message.
[0104] For the request message whose destination address needs to be modified (corresponding to the situation where the destination IP address and destination port of the request message are recorded in the address table), the first program queries the target socket corresponding to the request message from the socket table based on the destination IP address and destination port of the request message, and then modifies the destination IP address and destination port of the request message to the IP address and port used by the target socket, and sends it to the subsequent steps (such as step two) for further processing to send it to the corresponding target socket.
[0105] For request messages that do not need to modify the destination address (corresponding to the situation where the destination IP address and destination port of the request message are not recorded in the address table), the first program does not modify the destination address of the request message and directly allows it to pass, that is, it directly hands it over to the subsequent steps (such as step two) for further processing, so as to send the request message according to the original socket selection logic.
[0106] In this implementation, the first program can quickly decide whether it is necessary to modify the destination address of the intercepted request message based on the pre-configured address table and socket table, and quickly determine the target socket corresponding to the request message that needs to be modified, thereby improving the processing efficiency of the first program.
[0107] Optionally, the method further comprises:
[0108] When the socket bound to the destination IP address and the destination port is not found in the socket table, that is, when the target socket corresponding to the request message cannot be found, the request message is discarded by the first program to ensure the stable operation of the first program.
[0109] As a possible implementation, the method further includes:
[0110] Loading the first program and the target data structure stored in the configuration file into the kernel through a second program, wherein the second program is a pre-configured user-mode program, and the target data structure supports storing and sharing data between the eBPF program and the user space;
[0111] Through the second program, according to the process identifier of the pre-configured target process (such as one or more specified processes in the client), the socket that needs to use the first program to send the message is obtained (such as obtaining the file descriptor of the relevant socket, based on which the IP address and port used by the socket can be found);
[0112] Through the second program, the pre-configured IP address and port are used as the acquired IP address and port to be bound to the socket, and the target data structure is used to store the socket and the IP address and port to be bound to it.
[0113] In this implementation, the workload of manual configuration can be reduced by having a user-mode program (i.e., the second program) perform configuration-related operations such as compiling, loading the eBPF program (i.e., the first program), and configuring the target data structure (such as the eBPF map) into the kernel.
[0114] Taking the Golang language as an example, a code implementation of the second program is as follows:
[0115]
[0116]
[0117]
[0118] Optionally, when there is only one socket that needs to use the first program to send a message, the target data structure includes:
[0119] The eBPF map of type BPF_MAP_TYPE_HASH is used to store the IP address and port to which the socket needs to be bound;
[0120] An eBPF map of type BPF_MAP_TYPE_SOCKMAP is used to store the socket (e.g., to store the file descriptor of the socket).
[0121] Exemplarily, the pseudo code of the eBPF map of the BPF_MAP_TYPE_HASH type is as follows:
[0122]
[0123]
[0124] The pseudo code of the eBPF map of type BPF_MAP_TYPE_SOCKMAP is as follows:
[0125]
[0126] In this example, after obtaining the destination IP address and destination port from the request message, the first program uses the destination IP address and destination port as the key to query the eBPF map of the BPF_MAP_TYPE_HASH type (i.e., address_map). If the corresponding value is found, it means that the destination IP address and destination port are bound to the single socket. Then, the information of the single socket (such as the socket file descriptor) is obtained from the eBPF map of the BPF_MAP_TYPE_SOCKMAP type (i.e., socket_map), and the request message is sent to the socket accordingly. The pseudo code of the first program may be as follows:
[0127]
[0128]
[0129] For the method embodiments, for the sake of simplicity, they are all described as a series of action combinations, but those skilled in the art should be aware that the embodiments of the present application are not limited by the order of the actions described, because according to the embodiments of the present application, some steps can be performed in other orders or simultaneously. Secondly, those skilled in the art should also be aware that the embodiments described in the specification are all preferred embodiments, and the actions involved are not necessarily required by the embodiments of the present application.
[0130] Second, Figure 7 : is a structural diagram of a request message sending device according to an embodiment of the present application, the device comprising:
[0131] The message interception module 710 is used to intercept the request message during the execution of the socket selection logic of the kernel network protocol stack through a first program, wherein the first program is a pre-configured extended Berkeley packet filter eBPF program;
[0132] The data processing module 720 is used to determine the target socket corresponding to each of the request messages according to the pre-configured binding relationship between the socket and the IP address and the port, and the destination IP address and the destination port of each of the intercepted request messages through the first program;
[0133] The message sending module 730 is used to send each of the request messages to the target socket corresponding to each of the request messages through the first program.
[0134] By adopting the technical solution of the embodiment of the present application, the message request is intercepted in the kernel network protocol stack through the pre-configured eBPF program (i.e., the first program), and the target socket corresponding to each request message is determined according to the binding relationship between the pre-configured socket and the IP address and port, as well as the destination IP address and destination port of each intercepted request message, and then each of the request messages is sent to the target socket corresponding to each of the request messages. In this way, by using the eBPF program to implement the message sending based on binding multiple addresses to one socket, the intrusion of the business code can be avoided, and based on the binding relationship between the pre-configured socket and the IP address and port, the flexible configuration of the IP address and port bound to the socket (i.e., the target socket) can be guaranteed, thereby improving the applicability of the request message sending method.
[0135] Optionally, the message interception module 710 is further configured to intercept, through the first program, each request message processed by the step of searching for the connection status socket in the socket selection logic after the step of searching for the connection status socket is completed;
[0136] The message sending module 730 is further configured to perform the following steps:
[0137] By means of the first program, the destination IP address and the destination port of each of the request messages are modified to the IP address and the port used by the target socket corresponding to each of the request messages;
[0138] Through the first program, each of the modified request messages is transmitted to the steps related to searching for a listening state socket in the socket selection logic for processing, so as to send each of the request messages to a target socket corresponding to each of the request messages.
[0139] Optionally, the data processing module 720 is further configured to perform the following steps on each of the request messages through the first program:
[0140] Query whether the destination IP address and destination port of the request message are recorded in the pre-stored address table;
[0141] In the case where the destination IP address and the destination port of the request message are recorded in the address table, the socket bound to the destination IP address and the destination port is searched in the pre-stored socket table to obtain the target socket corresponding to the request message;
[0142] When it is found that the destination IP address and destination port of the request message are not recorded in the address table, the request message is directly transmitted to the steps related to searching the listening status socket for processing through the first program, so as to send the request message according to the destination IP address and destination port of the request message.
[0143] Optionally, the device further comprises:
[0144] The message discarding module is used to discard the request message through the first program when the socket bound to the destination IP address and the destination port is not found in the socket table.
[0145] Optionally, the device further comprises a configuration module, wherein the configuration module is configured to perform the following steps:
[0146] Loading the first program and the target data structure stored in the configuration file into the kernel through a second program, wherein the second program is a pre-configured user-mode program, and the target data structure supports storing and sharing data between the eBPF program and the user space;
[0147] Acquire, by the second program, a socket for sending a message using the first program according to a pre-configured process identifier of the target process;
[0148] Through the second program, the pre-configured IP address and port are used as the acquired IP address and port to be bound to the socket, and the target data structure is used to store the socket and the IP address and port to be bound to it.
[0149] Optionally, when there is only one socket that needs to use the first program to send a message, the target data structure includes:
[0150] An eBPF map of type BPF_MAP_TYPE_HASH, which is used to store the IP address and port to which the socket is bound;
[0151] An eBPF map of type BPF_MAP_TYPE_SOCKMAP used to store the socket.
[0152] It should be noted that the device embodiment is similar to the method embodiment, so the description is relatively simple, and the relevant parts can be referred to the method embodiment.
[0153] The present application also provides an electronic device, referring to Figure 8 , Figure 8 Schematic diagram of an electronic device proposed in an embodiment of the present application. Figure 8 As shown, the electronic device 100 includes: a memory 110 and a processor 120. The memory 110 and the processor 120 are connected via a bus communication. A computer program is stored in the memory 110. The computer program can be run on the processor 120 to implement the steps in the request message sending method disclosed in the embodiment of the present application.
[0154] The embodiment of the present application also provides a computer-readable storage medium on which a computer program / instruction is stored. When the computer program / instruction is executed by a processor, the request message sending method disclosed in the embodiment of the present application is implemented.
[0155] The embodiment of the present application also provides a computer program product, including a computer program / instruction, which, when executed by a processor, implements the request message sending method disclosed in the embodiment of the present application.
[0156] The various embodiments in this specification are described in a progressive manner, and each embodiment focuses on the differences from other embodiments. The same or similar parts between the various embodiments can be referenced to each other.
[0157] Those skilled in the art will appreciate that the embodiments of the present application can be provided as methods, devices or computer program products. Therefore, the present application can adopt the form of a complete hardware embodiment, a complete software embodiment, or an embodiment in combination with software and hardware. Moreover, the present application can adopt the form of a computer program product implemented on one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) containing computer-usable program code.
[0158] The embodiments of the present application are described with reference to the flowcharts and / or block diagrams of the methods, systems, devices, storage media, and program products according to the embodiments of the present application. It should be understood that each process and / or box in the flowchart and / or block diagram, as well as the combination of the processes and / or boxes in the flowchart and / or block diagram, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, an embedded processor, or other programmable data processing terminal device to generate a machine, so that the instructions executed by the processor of the computer or other programmable data processing terminal device generate instructions for implementing the processes in the flowchart and / or block diagram. Figure 1 A process or multiple processes and / or boxes Figure 1 A device that provides the functions specified in a block or multiple blocks.
[0159] These computer program instructions may also be stored in a computer-readable memory capable of directing a computer or other programmable data processing terminal device to operate in a specific manner, so that the instructions stored in the computer-readable memory produce a manufactured product including an instruction device, which implements the process Figure 1 A process or multiple processes and / or boxes Figure 1 A function specified in one or more boxes.
[0160] These computer program instructions can also be loaded onto a computer or other programmable data processing terminal device so that a series of operating steps are executed on the computer or other programmable terminal device to produce a computer-implemented process, thereby providing instructions for executing on the computer or other programmable terminal device to implement the process. Figure 1 A process or multiple processes and / or boxes Figure 1 The steps for the functions specified in one or more boxes.
[0161] Although the preferred embodiments of the present application have been described, those skilled in the art may make additional changes and modifications to these embodiments once they have learned the basic creative concept. Therefore, the appended claims are intended to be interpreted as including the preferred embodiments and all changes and modifications that fall within the scope of the embodiments of the present application.
[0162] Finally, it should be noted that, in this article, relational terms such as first and second, etc. are only used to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Moreover, the terms "include", "comprise" or any other variants thereof are intended to cover non-exclusive inclusion, so that a process, method, article or terminal device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, article or terminal device. In the absence of further restrictions, the elements defined by the sentence "including one..." do not exclude the existence of other identical elements in the process, method, article or terminal device including the elements.
[0163] The above is a detailed introduction to a request message sending method, device, equipment, medium and product provided by the present application. Specific examples are used in this article to illustrate the principles and implementation methods of the present application. The description of the above embodiments is only used to help understand the method of the present application and its core idea; at the same time, for general technical personnel in this field, according to the idea of the present application, there will be changes in the specific implementation method and application scope. In summary, the content of this specification should not be understood as a limitation on the present application.
Claims
1. A method for sending a request message, characterized in that: The method comprises: Intercepting the request message during the execution of the socket selection logic of the kernel network protocol stack by a first program, wherein the first program is a pre-configured extended Berkeley packet filter eBPF program; Determine, through the first program, the target socket corresponding to each of the request messages according to the pre-configured binding relationship between the socket and the IP address and port, and the destination IP address and destination port of each of the intercepted request messages; Through the first program, each of the request messages is sent to a target socket corresponding to each of the request messages.
2. The method according to claim 1, characterized in that The interception of the request message during the execution of the socket selection logic of the kernel network protocol stack by the first program includes: By means of the first program, after the steps related to searching for connection status socket in the socket selection logic are executed, each request message processed by the steps related to searching for connection status socket is intercepted; The step of sending each of the request messages to a target socket corresponding to each of the request messages through the first program includes: By means of the first program, the destination IP address and the destination port of each of the request messages are modified to the IP address and the port used by the target socket corresponding to each of the request messages; Through the first program, each of the modified request messages is transmitted to the steps related to searching for a listening state socket in the socket selection logic for processing, so as to send each of the request messages to a target socket corresponding to each of the request messages.
3. The method according to claim 2, characterized in that The target socket corresponding to each of the request messages is determined by the first program executing the following steps: Query whether the destination IP address and destination port of the request message are recorded in the pre-stored address table; In the case where the destination IP address and the destination port of the request message are recorded in the address table, the socket bound to the destination IP address and the destination port is searched in the pre-stored socket table to obtain the target socket corresponding to the request message; The method further comprises: When it is found that the destination IP address and destination port of the request message are not recorded in the address table, the request message is directly transmitted to the steps related to searching the listening status socket for processing through the first program, so as to send the request message according to the destination IP address and destination port of the request message.
4. The method according to claim 3, characterized in that The method further comprises: When the socket bound to the destination IP address and the destination port is not found in the socket table, the request message is discarded through the first program.
5. The method according to any one of claims 1 to 4, characterized in that: The method further comprises: Loading the first program and the target data structure stored in the configuration file into the kernel through a second program, wherein the second program is a pre-configured user-mode program, and the target data structure supports storing and sharing data between the eBPF program and the user space; Acquire, by the second program, a socket for sending a message using the first program according to a preconfigured process identifier of the target process; Through the second program, the pre-configured IP address and port are used as the acquired IP address and port to be bound to the socket, and the target data structure is used to store the socket and the IP address and port to be bound to it.
6. The method according to claim 5, characterized in that In the case that there is only one socket that needs to use the first program to send a message, the target data structure includes: The eBPF map of type BPF_MAP_TYPE_HASH is used to store the IP address and port to which the socket needs to be bound; An eBPF map of type BPF_MAP_TYPE_SOCKMAP used to store the socket.
7. A request message sending device, characterized in that: The device comprises: A message interception module, used to intercept request messages during the execution of the socket selection logic of the kernel network protocol stack through a first program, wherein the first program is a pre-configured extended Berkeley packet filter eBPF program; A data processing module, configured to determine, through the first program, a target socket corresponding to each of the request messages according to a pre-configured binding relationship between the socket and the IP address and the port, and a destination IP address and a destination port of each of the intercepted request messages; The message sending module is used to send each of the request messages to the target socket corresponding to each of the request messages through the first program.
8. An electronic device comprising a memory, a processor and a computer program stored in the memory, characterized in that: The processor executes the computer program to implement the request message sending method according to any one of claims 1 to 6.
9. A computer-readable storage medium having a computer program / instruction stored thereon, characterized in that: When the computer program / instruction is executed by a processor, the request message sending method according to any one of claims 1 to 6 is implemented.
10. A computer program product comprising a computer program / instructions, characterized in that When the computer program / instruction is executed by a processor, the request message sending method according to any one of claims 1 to 6 is implemented.
Citation Information
Patent Citations
Data processing method, device and system, readable storage medium and imported network card
CN116545978A
Port monitoring method, device, equipment and medium
CN117692359A
Certificate application method based on http-01 verification, client and program product
CN118473742A
Network address translation method and computing device
CN118612185A
Cited By
Message processing method and device
CN121217851A