Data transmission method and device
By hooking system calls in Linux operating system, rewritten as callq*%rax instruction to jump to the hook function, and data transmission is carried out through the QUIC protocol, the problem of delay, head of queue blocking and connection re-establishment during network migration in TCP/IP protocol is solved, and the transmission efficiency and reliability are improved.
Patent Information
- Application Number
- CN202411780125.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-12-05
- Publication Date
- 2025-04-15
AI Technical Summary
The existing TCP/IP protocols have problems in data transmission, such as upgrading difficulties, connection delay, head of queue blocking and connection re-establishment during network migration, resulting in insufficient transmission efficiency and reliability.
By using binary rewriting technology in the Linux operating system to hook system calls, rewrite the system call instruction to callq*%rax instruction, thus jumping to the hook function to execute, and data transmission is performed through the QUIC protocol, replacing the traditional TCP protocol.
This method solves the problems of TCP protocol delay and head of queue blocking when establishing connections, and reduces the delay in connection re-establishment during network migration, improving the efficiency and reliability of data transmission.
Smart Images

Figure CN119835343A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of network communication technology, and in particular to a data transmission method and device. Background Art
[0002] In the data communication process of the Internet Protocol (IP) network, the commonly used transmission protocol is the Transmission Control Protocol (TCP) / IP protocol. With the continuous development of network applications, new requirements are constantly being put forward for the speed and reliability of data transmission. The existing TCP / IP protocol has some shortcomings, including the following four aspects: it is difficult to upgrade TCP, there is a delay in TCP connection establishment, TCP has a head-of-line blocking problem, and network migration requires the re-establishment of TCP connection.
[0003] As for the difficulty of upgrading TCP, since the TCP protocol is implemented in the kernel, the application can only use it and cannot be modified. If you want to upgrade the TCP protocol, you can only upgrade the kernel. Since the kernel upgrade involves the update of the underlying software and runtime library, many new features of the TCP protocol require the support of both the client and the server to take effect. The service program needs to be regressed to see if it is compatible with the new kernel version, so the server kernel upgrade is also conservative and slow. Therefore, even if TCP has a better feature update, it is difficult to promote the upgrade quickly.
[0004] As for the delay when TCP establishes a connection, application protocols based on TCP need to establish a three-way handshake before data transmission, such as HTTP 1.0 / 1.1, HTTP / 2, and HTTPS. Most websites now use HTTPS, which means that after the TCP three-way handshake, the TLS four-way handshake is required before HTTP data transmission can be carried out, which increases the delay of data transmission to a certain extent.
[0005] As for the head-of-line blocking problem of TCP, since TCP is a byte stream protocol, the TCP layer must ensure that the received byte data is complete and in order. If a TCP segment with a lower sequence number is lost during network transmission, even if a TCP segment with a higher sequence number has been received, the application layer cannot read this part of data from the kernel.
[0006] For network migration, it is necessary to re-establish a TCP connection. The HTTP protocol based on the TCP transmission protocol determines a TCP connection through a four-tuple (source IP, source port, destination IP, destination port). So when the network of the mobile device switches from 4G to WIFI, it means that the IP address has changed, so the connection must be disconnected and then the TCP connection must be re-established. The process of establishing a connection includes the delay of the TCP three-way handshake and the TLS four-way handshake, as well as the deceleration process of TCP slow start. The user feels that the network suddenly freezes, so the cost of connection migration is very high.
[0007] Therefore, a new data transmission method is needed. Summary of the invention
[0008] In order to solve the problems existing in the prior art, the embodiments of the present application provide a method, apparatus, computing device, computer storage medium and product including a computer program for data transmission, which can modify the method of data transmission using the TCP protocol to transmission using the UDP protocol, thereby improving transmission efficiency.
[0009] In a first aspect, an embodiment of the present application provides a data transmission method, which is executed on a computing device, and the computing device adopts a Linux operating system and a hardware environment of X86-64 CPUs, and the method includes: configuring an environment variable LD_PRELOAD, and LD_PRELOAD is set to a shared library file that implements a hook function; when loading the hook function shared library specified by the LD_PRELOAD environment variable, using the initialization process of the hook function shared library, rewriting the binary code of the first instruction, and writing a jump program code at memory 0-500; wherein the first instruction is a system call instruction; hooking the system call by binary rewriting; the binary rewriting is specifically used to rewrite the first instruction into a second instruction; jumping to the jump program code based on the second instruction for execution, and then being guided by the jump program code to the hook function for execution, and the hook function calls QUICAPI for communication.
[0010] In some possible implementations, the environment variables are configured, specifically including: setting the LD_PRELOAD environment variable, the environment variable value is the path of the dedicated hook function shared library, which is used to preload the shared library when the user program starts; adding a custom environment variable, and setting the custom environment variable to the path of the hook function library.
[0011] In some possible implementations, the first instruction is rewritten as the second instruction, specifically: the first instruction is a two-byte binary code 0x0f and 0x05; the second instruction is a callq*%rax instruction, specifically a two-byte binary code 0xff and 0xd0; 0x0f and 0x05 are replaced with 0xff and 0xd0.
[0012] In some possible implementations, the jump program code is written, including: releasing the access function at virtual memory address 0-500 by setting / proc / sys / vm / mmap_min_addr to 0; filling from address 0 to N through nop instructions, N represents the maximum system call number; embedding the jump code after the last nop instruction, and the jump code is used to jump to the hook function.
[0013] In some possible implementations, the hook function uses the dlmopen function to load the library file and specifies a new namespace for the library file to avoid deadlock when a system call instruction appears in the hook function.
[0014] In some possible implementations, the hook function is executed, and the hook function calls the QUIC protocol for communication. Specifically, the hook function loads the shared library function through dlmopen, creates an independent thread to run the microservice, and the microservice communicates through the QUIC protocol.
[0015] In some possible implementations, the hook function calls the QUIC protocol for communication, specifically including: the hook function creates environment variables and assigns the parameters stored in the registers during the system call to the environment variables; the microservice obtains the parameters through the environment variables, creates a QUIC socket to establish a communication connection, and completes data communication based on the QUIC protocol.
[0016] In some possible implementations, the hook function and the microservice communicate using a Unix domain socket.
[0017] In a second aspect, an embodiment of the present application provides a data transmission device, which is deployed on a computing device, and the computing device adopts a Linux operating system and a hardware environment of X86-64 CPUs, and the device includes: a configuration module, which is used to configure an environment variable LD_PRELOAD, and LD_PRELOAD is set to a shared library file that implements a hook function; a loading module, which is used to load the hook function shared library specified by the LD_PRELOAD environment variable, and utilize the initialization process of the hook function shared library to rewrite the binary code of the first instruction, and at the same time write a jump program code at 0-500 of the memory; wherein the first instruction is a system call instruction; a processing module, which is used to hook the system call by binary rewriting; the binary rewriting is specifically used to rewrite the first instruction into a second instruction; the processing module is also used to jump to the jump program code for execution based on the second instruction, and then the jump program code is guided to the hook function for execution, and the hook function calls the QUIC API for communication.
[0018] In a third aspect, an embodiment of the present application provides a computer-readable storage medium, comprising computer-readable instructions. When a computer reads and executes the computer-readable instructions, the computer executes the method described in any one of the first aspects.
[0019] In a fourth aspect, an embodiment of the present application provides a computing device, comprising a processor and a memory, wherein the memory stores computer program instructions, and when the computer program instructions are executed by the processor, the method described in any one of the first aspects is executed.
[0020] In a fifth aspect, an embodiment of the present application provides a product comprising a computer program. When the computer program product runs on a processor, the processor executes the method as described in any one of the first aspects. BRIEF DESCRIPTION OF THE DRAWINGS
[0021] In order to more clearly illustrate the technical solutions of the embodiments of the present invention, the accompanying drawings required for use in the description of the embodiments will be briefly introduced below. Obviously, the accompanying drawings described below are only some embodiments of the present invention. For ordinary technicians in this field, other accompanying drawings can be obtained based on these accompanying drawings without paying creative work.
[0022] Figure 1 is a schematic diagram of a system call hook provided by an embodiment of the present application;
[0023] Figure 2 It is a flowchart of a data transmission method provided by an embodiment of the present application;
[0024] Figure 3 This is a schematic diagram of creating a microservice thread by a hook function and calling the quic protocol for communication provided by an embodiment of the present application;
[0025] Figure 4 It is a schematic diagram of the entire data communication process provided by an embodiment of the present application;
[0026] Figure 5 It is a structural schematic diagram of a data transmission device provided in an embodiment of the present application;
[0027] Figure 6 It is a structural diagram of a computing device provided in an embodiment of the present application. DETAILED DESCRIPTION
[0028] 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.
[0029] The term "and / or" in this article is a description of the association relationship of associated objects, indicating that there can be three relationships. For example, A and / or B can represent: A exists alone, A and B exist at the same time, and B exists alone. The symbol " / " in this article indicates that the associated objects are in an or relationship, for example, A / B means A or B.
[0030] The terms "first" and "second" in the specification and claims herein are used to distinguish different objects rather than to describe a specific order of the objects. For example, a first response message and a second response message are used to distinguish different response messages rather than to describe a specific order of the response messages.
[0031] In the embodiments of the present application, words such as "exemplary" or "for example" are used to indicate examples, illustrations or descriptions. Any embodiment or design described as "exemplary" or "for example" in the embodiments of the present application should not be interpreted as being more preferred or more advantageous than other embodiments or designs. Specifically, the use of words such as "exemplary" or "for example" is intended to present related concepts in a specific way.
[0032] In the description of the embodiments of the present application, unless otherwise specified, "multiple" means two or more than two. For example, multiple processing units refer to two or more processing units, etc.; multiple elements refer to two or more elements, etc.
[0033] To facilitate the understanding of the embodiments of the present application, the following will further explain and illustrate specific embodiments in conjunction with the accompanying drawings. The embodiments do not constitute a limitation on the embodiments of the present invention.
[0034] First, the technical terms involved in this application are introduced:
[0035] 1. The hook function is a special callback function that adds a layer of correspondence based on the callback function. This correspondence is called a hook.
[0036] 2. Hooking is a technology that allows a program to intervene and execute a custom code before or after performing a specific operation (such as a system call).
[0037] Next, the technical solution provided by the embodiments of the present application is introduced.
[0038] The TCP protocol is a traditional and widely used transport layer protocol, but with the development of network information technology, the TCP protocol has gradually revealed some shortcomings in the process of data transmission. In view of this, the embodiment of the present application provides a data transmission method, which uses a method for hooking system calls based on binary rewriting technology, and uses a hook function to perform data transmission based on the quick user datagram protocol (user datagram protocol, UDP) Internet connection (quick udpinternet connections, QUIC) protocol after hooking, replacing the commonly used TCP transmission method. This method solves the problems of high performance loss of system hooking technology and inability to completely hook system calls when communicating based on TCP, and significantly improves the efficiency of traditional data transmission based on TCP. In this method, data transmission is based on the QUIC protocol for communication. The QUIC protocol is a transport layer protocol based on UDP. Although the QUIC protocol and the TCP protocol are both responsible for transmitting data in the network, the QUIC protocol has some obvious advantages and improvements over the TCP protocol.
[0039] Among them, the advantages of the QUIC protocol over the TCP protocol include: faster connection establishment, more flexible packet loss handling, and support for connection migration. Since the TCP protocol requires a three-way handshake when establishing a connection, while the QUIC protocol does not require a three-way handshake confirmation when establishing a connection, the waiting time is reduced and the connection establishment is faster than TCP. When transmitting data in the network, data packets may sometimes be lost due to various reasons during data transmission. The TCP protocol stops sending subsequent data when packets are lost and waits for the lost data packets to be retransmitted. The QUIC protocol is more flexible. It continues to send other data packets when packets are lost instead of stopping and waiting. This processing method makes the QUIC protocol more efficient when transmitting large amounts of data or real-time data, and packet loss handling is more flexible. When using a mobile device to switch between different networks, for example, when switching from Wi-Fi to 4G / 5G networks, the TCP connection usually needs to be reestablished. For example, when downloading a file, if the network is switched, the download may be interrupted and need to be restarted. The QUIC protocol supports connection migration, which can maintain the stability of the connection when switching networks, so that data transmission will not be interrupted. For example, if you are using an online game or video call application, even if the network is switched, the game or call connected via the QUIC protocol can continue without being affected.
[0040] The improvements of the QUIC protocol over the TCP protocol include: enhanced security, more sophisticated flow control, and better scalability. In terms of enhanced security, the QUIC protocol encrypts all communication data by default, providing higher security than TCP. In layman's terms, when sending an important letter, the QUIC protocol will automatically add a secure envelope to the letter to ensure that the content of the letter will not be leaked. In terms of more sophisticated flow control, the QUIC protocol provides a more sophisticated flow control mechanism that can better manage data flows in the network. QUIC can more accurately control the size and speed of traffic to avoid waste of traffic. In terms of better scalability, since the QUIC protocol is based on UDP, it is easier to implement various extended functions and innovative technologies, just like when building a Lego model, the QUIC protocol can provide more Lego blocks and creative space, allowing more complex models to be built.
[0041] In general, the QUIC protocol has advantages over the TCP protocol, such as faster connection establishment speed, more flexible packet loss handling, and better connection migration support. At the same time, it has also been improved and optimized in terms of security, flow control, and scalability. These advantages and improvements make the QUIC protocol one of the important choices for future network communications. At present, application software such as HTTP / 3 and NGINX have added support for QUIC protocol program code, and have supported the function of using the QUIC protocol for data transmission, enabling communication through the QUIC protocol.
[0042] However, a large part of the application software currently used still only supports the TCP protocol and performs data transmission through the call of the TCP socket function. Since the TCP / IP protocol is widely used, it is undoubtedly a huge project to improve the codes of many user applications to support the QUIC protocol and use QUIC for data transmission. Although the QUIC protocol has many advantages, it is difficult to achieve the QUIC protocol to completely replace the TCP protocol for data transmission. This method provides a simple method for replacing TCP protocol communication with QUIC protocol communication. This method uses a system call hook to let the program jump to the hook function for execution, and the hook function replaces TCP protocol communication with QUIC protocol communication. Its advantage is that it does not require changes to the user application to realize the use of QUIC protocol for communication, and this method uses the hook function and the QUIC protocol to run in the user state, which greatly improves the operating efficiency. However, it is worth noting that this method is currently only suitable for the Linux operating system and the hardware environment of X86-64 CPUs.
[0043] In this method, due to the various hook mechanisms supported by existing Unix-like system kernels (e.g., ptrace, SUD, PLT / GOT replacement methods, inline-hook methods, etc.), the method used causes unacceptable performance degradation in user space programs that apply hooks. The method of replacing function calls using the LD_PRELOAD mechanism cannot completely hook system calls. Therefore, this method chooses to hook system calls by rewriting the syscall command as the callq*%rax command. For example, please refer to Figure 1 , Figure 1 FIG. 1 is a schematic diagram of a system call hook provided by an embodiment of the present application. Figure 1As shown, the system called function syscall command is a two-byte binary code 0x0f and 0x05, while the callq*%rax command is a two-byte binary code 0xff and 0xd0. In order to rewrite the two-byte binary code 0x0f and 0x05 into the two-byte binary code 0xff and 0xd0 of the callq*%rax command to achieve the purpose of the hook, the execution of the system call is forcibly jumped to the memory address specified in the rax register. In order to ensure that only two-byte binary code is used to replace the two-byte binary code of the system call function syscall, the callq*%rax command is used. Because the binary code of this command occupies two bytes. Use the two-byte callq*%rax jump command binary code to replace the two-byte binary code of the system call function syscall, which can ensure that the code of other content of the program is not affected and the stability of the original program is guaranteed. In addition, the two-byte binary codes 0xff and 0xd0 of the callq*%rax command are used to replace the two-byte binary codes 0x0f and 0x05 of syscall because the callq command can push the next address onto the stack while jumping to other memory addresses to ensure that the program can return smoothly after the hook function is executed. The function that implements the system call hook is compiled into a system call hook shared library, and the hook function is compiled into a hook function shared library. By preloading, the dynamic loading and initialization process of the system call hook shared library is completed before the main() method of the main program starts to execute. At the same time, it is also necessary to set the environment variable LD_PRELOAD to the system call hook shared library. Set the directory where the hook function is located as an environment variable, and use this environment variable to allow the hook function to be loaded smoothly. Let the function of the system call hook shared library correctly obtain the address pointer of the hook function, so that the hook can jump to the hook function smoothly. Since by default, virtual memory addresses 0-500 on Linux are usually reserved memory, address 0 cannot be mapped, and users are usually prohibited from accessing it. Therefore, it is also necessary to set / proc / sys / vm / mmap_min_addr to 0 to release the access function at virtual memory addresses 0-500, and rewrite its content through the mmap() function. Next, use the nop instruction (0x90) to fill in addresses 0 to N (N is the largest system call number). Then, immediately after the last nop instruction, embed the jump code, such as jmp+hook function address, to jump to the hook function, thus completing the setting of the jump module code. The system call is then hooked by the binary rewriting method, and the hook function communicates by calling the QUIC API.
[0044] For example, Figure 2The flowchart of a data transmission method provided by an embodiment of the present application is shown. The method is executed on a computing device, and the computing device adopts a Linux operating system and a hardware environment of X86-64 CPUs. Before the method is implemented, it is necessary to perform environmental configuration work on the operating system of the computing device to implement the function of system call hooking. The function of system call hooking includes binary rewriting and filling in jump codes at memory addresses 0-500. Figure 2 As shown, the method may include the following steps:
[0045] S21: Configure the environment variable LD_PRELOAD, and set LD_PRELOAD to the shared library file that implements the hook function.
[0046] In this embodiment, when the application installed on the computing device by the user is started, the library function needs to be preloaded. When loading the library function, in order to realize the function of system call hooking, the function of realizing system call hooking is compiled into a system call hooking shared library, and the hook function is compiled into a hook function shared library. By preloading, the dynamic loading and initialization process of the system call hooking shared library is completed before the main program main() method starts to execute. At the same time, it is also necessary to set the environment variable LD_PRELOAD to the system call hooking shared library. Set the directory where the hook function is located as an environment variable, and use the environment variable to allow the hook function to be loaded smoothly. Let the function of the system call hooking shared library correctly obtain the address pointer of the hook function, so that the hook can smoothly jump to the hook function for execution.
[0047] S22: When loading the hook function shared library specified by the LD_PRELOAD environment variable, the initialization process of the hook function shared library is used to rewrite the binary code of the first instruction, and at the same time, a jump program code is written at memory 0-500; wherein the first instruction is a system call instruction.
[0048] In this embodiment, when loading the configured environment variables, the jump program code must first be set at memory 0-500. The jump program code is used to guide the application to the hook function for execution. In order to guide the application to the hook function, the original system call (syscall) needs to be rewritten as the callq*%rax command. The system call can be referred to as the first instruction, and the callq*%rax command can be referred to as the second instruction. In addition, since by default, virtual memory addresses 0-500 on Linux are usually reserved memory, address 0 cannot be mapped, and user access is usually prohibited, so it is necessary to open the relevant memory function. Specifically, the opening of memory addresses 0-500 is achieved by setting / proc / sys / vm / mmap_min_addr to 0. At the same time, its content is rewritten by the mmap() function. Specifically, the nop instruction is used to fill from address 0 to N (N is the maximum system call number, usually 500). Then, the jump code is embedded immediately after the last nop instruction, such as jmp+hook function address, to achieve jumping to the hook function.
[0049] S23: hooking the system call by binary rewriting; the binary rewriting is specifically used to rewrite the first instruction into a second instruction.
[0050] In this embodiment, the procfs function is used to find the 2-byte binary code 0x0f 0x05 (the binary code of syscall), and the binary code of the callq*%rax command is used here to replace it. This is because the binary code of the system call function (syscall) occupies 2 bytes. In order to ensure that the other contents of the source program are not changed after rewriting the binary code, only the contents of these two bytes must be rewritten so as not to affect the other contents of the program. The binary code of the callq*%rax command also occupies 2 bytes, so using the binary code of the callq*%rax command to replace the binary code of syscall can ensure that the other parts of the program are not affected. In addition, after using the callq*%rax instruction to jump, the next address of the instruction will be pushed into the stack, so that after the hook function is executed, it can correctly return to the next instruction to continue execution.
[0051] When a system call is made, the system call number is placed in the rax register, and the system call number is 0 to N (N is the largest system call number). Therefore, after the binary of syscall is rewritten into the binary of callq*%rax, the program will jump to the virtual memory between 0 and N (N is the largest system call number) for execution. Since the virtual memory addresses 0 to N are not the virtual memory addresses where the hook function is located, it is necessary to fill in the jump program code at the memory addresses 0 to N. After the program jumps to 0 to N, the subsequent nop instructions will be executed sequentially until all nop instructions are executed and a jump code is reached. Finally, this jump code will jump the program to the real hook function for execution.
[0052] The above hook operation, jump module code setting and hook function call process are compiled into a dynamic library, and LD_PRELOAD is used to preload the dynamic library. It is dynamically completed during the initialization process of the dynamic library, including: rewriting the binary code to establish a system call hook; setting the transition program code; loading the hook function through the dlmopen function. Among them, when using the dlmopen function to load the hook function, since the dlmopen function opens multiple shared libraries in different threads, it is necessary to ensure that each thread has its own independent namespace. Therefore, the dlmopen function can be used to create a new namespace and open the shared library in the namespace. To ensure that different hook functions and system calls run independently and do not affect each other. To prevent deadlock between the hook function and the source program, the application thread can open the hook function by calling the dlmopen() function.
[0053] S24: Jump to the jump program code based on the second instruction for execution, and then be guided by the jump program code to the hook function for execution, and the hook function calls the QUIC API for communication.
[0054] In this embodiment, the callq*%rax command uses the value of the rax register as a parameter. Usually, this register stores the system call number of the syscall command, and its value ranges from 0 to a maximum value of 500. This causes the callq*%rax command to jump to memory address 0-500 for execution. The memory address 0-500 is usually a reserved address, and the loader usually does not load the program here. It is necessary to release the permissions of this memory address, set a transitional jump program code here, and guide the program to the hook function for execution through this code. After the transitional program code is set, the original permission setting is restored. Usually, the socket function of the TCP / IP protocol runs in the kernel state, while the application runs in the user state. Calling the socket function requires switching from the user state to the kernel state. When the application frequently performs data communication, it will frequently switch from the user state to the kernel state, which will consume a lot of system resources, resulting in slow operation and low efficiency. To solve this problem, the transition code directly switches the program to the user state hook function, which avoids the trivial conversion between the user state and the kernel state, thereby greatly improving performance.
[0055] When an application is communicating normally, it needs to call the TCP socket function to transfer data. The TCP socket function is a system call (syscall). Since the system call is hooked, the application jumps to the hook function for execution. The hook function first determines whether it is a socket system call. If it is a socket system call, the QUIC protocol is used to communicate in the hook function. This allows the hook function to play a role, so that the original call to the TCP socket function is transferred to the QUIC socket function. If it is a non-socket type system call, it will be transferred to the relevant system call function in the kernel for processing. Please refer to Figure 3 , Figure 3The schematic diagram shows that a hook function creates a microservice thread and calls the quic protocol for communication. The hook function first uses the dlmopen function to create a microservice module (micro service), which is used as a data transmission agent. The hook function sets the environment variables to pass the TCP socket parameters to the microservice module program using the environment variables. After the microservice module receives the data transmission request of the hook function, it uses the QUIC protocol to initiate a connection to the remote end and transmit data. Among them, the hook function and the microservice module communicate through inter-process communication (IPC). IPC can use unix domain socket. The microservice module communicates with the remote end through the QUIC protocol. The parameters required for the microservice module to open the QUIC socket are obtained through environment variables. That is, when the user application makes a socket system call, the socket parameters will be saved in registers (such as rcx, rdx, rdi, rsi, etc.), and these parameter values are set as environment variables in the hook function, and the parameters are passed to the microsystem module through this environment variable. The microsystem module uses this to establish a QUIC protocol connection with the remote end.
[0056] Specifically, when the system call has parameters, such as a socket system call, the hook function assigns the parameters of the TCP socket system call (available in registers) to the environment variable for use when calling quic socket communication. For example, a socket system call socket (AF_INET, SOCK_STREAM, IPPROTO_IP or IPPROTO_TCP) needs to pass parameters such as AF_INET, SOCK_STREAM, IPPROTO_IP or IPPROTO_TCP to the QUIC protocol, which can be accomplished by passing parameters through environment variables.
[0057] In some embodiments, the hook function uses the dlmopen function to create a microservice thread. When the microservice thread needs to perform QUIC communication, it obtains the socket parameters from the environment variables and starts the QUIC socket to establish a socket connection with the other end to perform QUIC protocol communication.
[0058] In some embodiments, when the hook function needs to open multiple microservice shared libraries in different threads, it is necessary to ensure that each thread has its own independent namespace. Use the dlmopen function to create a new namespace and open the shared library in the namespace.
[0059] In some embodiments, after the microservice thread is started, the hook function uses a unix domain socket (IPC communication) to establish a connection with the microservice. The microservice listens to the service port and waits for the hook function to connect.
[0060] The above functions can be implemented by compiling them into microservice shared libraries and providing them to hook functions for use.
[0061] S25: The hook function execution result is returned to the user program that makes the system call.
[0062] In this embodiment, after completing the QUIC protocol communication, the hook function encapsulates the operation result into the return value of the system call. The processing result is passed back from the hook function to the execution environment of the user application to ensure that the application can receive the same feedback as the TCP Socket call. After the user application receives the return value, it continues to execute subsequent logic according to the result. If the QUIC protocol communication is successful, the application will continue to transmit data or process other network events; if the communication fails, the error handling process may be triggered. The whole process is transparent to the user application. The application does not need to understand the switching of the communication protocol behind it, but only needs to process the return result of the system call.
[0063] For example, Figure 4 FIG. 1 is a schematic diagram showing the entire data communication process provided by an embodiment of the present application. Figure 2 As shown, the system calls the binary code to rewrite the hook operation. The transition program code is set up to prepare for the jump operation. Then the hook function is executed to perform QUIC protocol communication.
[0064] The above is an introduction to the data transmission method provided by the embodiment of the present application. The system call is hooked based on the binary rewriting technology, and the hook function is used to perform data transmission based on the QUIC protocol after hooking. This method allows the user application to use the QUIC protocol for data transmission by using a hook function. When the user application software wants to call the TCP protocol for data transmission, the user application traffic accessing TCP is transferred to the QUIC protocol for data transmission by calling the hook function.
[0065] It is understandable that the size of the sequence number of each step in the above-mentioned embodiments does not mean the order of execution, and the execution order of each process should be determined by its function and internal logic, and should not constitute any limitation on the implementation process of the embodiments of the present application. In addition, in some possible implementations, the steps in the above-mentioned embodiments can be selectively executed according to actual conditions, and can be partially executed or fully executed, which is not limited here. All or part of any features of any embodiment of the present application can be freely and arbitrarily combined without contradiction. The combined technical solution is also within the scope of the present application.
[0066] Based on the method in the above embodiment, the embodiment of the present application also provides a data transmission device. For example, Figure 5 A data transmission device is shown, which is deployed in a computing device. The computing device uses a Linux operating system and a hardware environment of X86-64 CPUs. The data transmission device 500 includes: a configuration module 501, a loading module 502, and a processing module 503.
[0067] Wherein, the configuration module 501 is used to configure the environment variable LD_PRELOAD, and LD_PRELOAD is set to a shared library file that implements the hook function;
[0068] The loading module 502 is used to rewrite the binary code of the first instruction and write the jump program code at memory 0-500 when loading the hook function shared library specified by the LD_PRELOAD environment variable; wherein the first instruction is a system call instruction;
[0069] The processing module 503 is used to hook the system call by binary rewriting; the binary rewriting is specifically used to rewrite the first instruction into a second instruction;
[0070] The processing module 504 is also used to jump to the jump program code for execution based on the second instruction, and then be guided by the jump program code to the hook function for execution, and the hook function calls the QUIC API for communication.
[0071] It should be understood that the above-mentioned device is used to execute the method in the above-mentioned embodiment. The implementation principle and technical effect of the corresponding program module in the device are similar to those described in the above-mentioned method. The working process of the device can refer to the corresponding process in the above-mentioned method, which will not be repeated here.
[0072] The present application also provides a computing device 600. Figure 6As shown, computing device 600 includes: bus 602, processor 604, memory 606 and communication interface 608. Processor 604, memory 606 and communication interface 608 communicate through bus 602. Computing device 600 can be a server or a terminal device. It should be understood that the present application does not limit the number of processors and memories in computing device 600.
[0073] The bus 602 may be a peripheral component interconnect (PCI) bus or an extended industry standard architecture (EISA) bus. The bus may be divided into an address bus, a data bus, a control bus, etc. For ease of representation, Figure 6 The bus 604 is represented by only one line, but does not mean that there is only one bus or one type of bus. The bus 604 may include a path for transmitting information between various components of the computing device 600 (eg, the memory 606, the processor 604, and the communication interface 608).
[0074] The processor 604 may include any one or more of a central processing unit (CPU), a graphics processing unit (GPU), a microprocessor (MP), or a digital signal processor (DSP).
[0075] The memory 606 may include a volatile memory, such as a random access memory (RAM). The processor 604 may also include a non-volatile memory, such as a read-only memory (ROM), a flash memory, a hard disk drive (HDD), or a solid state drive (SSD).
[0076] The memory 606 stores executable program codes, and the processor 604 executes the executable program codes to respectively implement the functions of the configuration module 501, the loading module 502, and the processing module 503, thereby implementing all or part of the steps of the method in the above embodiment. That is, the memory 606 stores instructions for executing all or part of the steps in the method in the above embodiment.
[0077] Alternatively, the memory 606 stores executable codes, and the processor 604 executes the executable codes to respectively implement the functions of the aforementioned data transmission device 500, thereby implementing all or part of the steps in the above-mentioned embodiment method. That is, the memory 606 stores instructions for executing all or part of the steps in the above-mentioned embodiment method.
[0078] The communication interface 608 uses a transceiver module such as, but not limited to, a network interface card or a transceiver to implement communication between the computing device 600 and other devices or communication networks.
[0079] Based on the methods in the above embodiments, an embodiment of the present application provides a computer-readable storage medium, which stores a computer program. When the computer program runs on a processor, the processor executes the methods in the above embodiments.
[0080] Based on the methods in the above embodiments, an embodiment of the present application provides a computer program product. When the computer program product runs on a processor, the processor executes the methods in the above embodiments.
[0081] It is understood that the processor in the embodiments of the present application may be a central processing unit (CPU), or other general-purpose processors, digital signal processors (DSP), application specific integrated circuits (ASIC), field programmable gate arrays (FPGA) or other programmable logic devices, transistor logic devices, hardware components or any combination thereof. The general-purpose processor may be a microprocessor or any conventional processor.
[0082] The method steps in the embodiments of the present application can be implemented by hardware or by a processor executing software instructions. The software instructions can be composed of corresponding software modules, and the software modules can be stored in random access memory (RAM), flash memory, read-only memory (ROM), programmable read-only memory (PROM), erasable programmable read-only memory (EPROM), electrically erasable programmable read-only memory (EEPROM), registers, hard disks, mobile hard disks, CD-ROMs, or any other form of storage medium known in the art. An exemplary storage medium is coupled to the processor so that the processor can read information from the storage medium and write information to the storage medium. Of course, the storage medium can also be a component of the processor. The processor and the storage medium can be located in an ASIC.
[0083] In the above embodiments, it can be implemented in whole or in part by software, hardware, firmware or any combination thereof. When implemented using software, it can be implemented in whole or in part in the form of a computer program product. The computer program product includes one or more computer instructions. When the computer program instructions are loaded and executed on a computer, the process or function described in the embodiment of the present application is generated in whole or in part. The computer may be a general-purpose computer, a special-purpose computer, a computer network, or other programmable device. The computer instructions may be stored in a computer-readable storage medium or transmitted through the computer-readable storage medium. The computer instructions may be transmitted from a website site, computer, server or data center to another website site, computer, server or data center by wired (e.g., coaxial cable, optical fiber, digital subscriber line (DSL)) or wireless (e.g., infrared, wireless, microwave, etc.) means. The computer-readable storage medium may be any available medium that a computer can access or a data storage device such as a server or data center that includes one or more available media integrated. The available medium may be a magnetic medium (e.g., a floppy disk, a hard disk, a tape), an optical medium (e.g., a DVD), or a semiconductor medium (e.g., a solid state disk (SSD)), etc.
[0084] It should be understood that the various numerical numbers involved in the embodiments of the present application are only used for the convenience of description and are not used to limit the scope of the embodiments of the present application.
Claims
1. A data transmission method, characterized in that: The method is executed on a computing device, the computing device adopts a Linux operating system and a hardware environment of X86-64 CPUs, and the method includes: Configure the environment variable LD_PRELOAD, and set LD_PRELOAD to the shared library file that implements the hook function; When loading the hook function shared library specified by the LD_PRELOAD environment variable, rewriting the binary code of the first instruction by utilizing the initialization process of the hook function shared library, and writing the jump program code at memory 0-500; wherein the first instruction is a system call instruction; Hooking the system call by binary rewriting; the binary rewriting is specifically used to rewrite the first instruction into a second instruction; Based on the second instruction, the program jumps to the jump program code for execution, which is then guided by the jump program code to the hook function for execution, and the hook function calls the QUIC API for communication.
2. The method according to claim 1, characterized in that The configuration environment variable specifically includes: setting the LD_PRELOAD environment variable, wherein the value of the environment variable is the path of the dedicated tick function shared library, which is used to preload the shared library when the user program is started; Add a custom environment variable and set the custom environment variable to the path of the hook function library.
3. The method according to claim 1, characterized in that The rewriting of the first instruction into the second instruction is specifically: The first instruction is a two-byte binary code 0x0f and 0x05; The second instruction is a callq*%rax instruction, specifically a two-byte binary code 0xff and 0xd0; Replace 0x0f and 0x05 with 0xff and 0xd0.
4. The method according to claim 1, characterized in that The writing jump program code comprises: By setting / proc / sys / vm / mmap_min_addr to 0, the access function of virtual memory addresses 0-500 is released; Fill the address from 0 to N through the nop instruction, where N represents the maximum system call number; A jump code is embedded after the last nop instruction, and the jump code is used to jump to the hook function.
5. The method according to claim 1, characterized in that The hook function uses the dlmopen function to load the library file and specifies a new namespace for the library file to avoid deadlock when a system call instruction appears in the hook function.
6. The method according to claim 1, characterized in that The hook function is executed, and the hook function calls the QUIC protocol communication, specifically: The hook function loads the shared library function through dlmopen, creates an independent thread to run the microservice, and the microservice communicates through the QUIC protocol.
7. The method according to claim 1, characterized in that The hook function calls the QUIC protocol communication, specifically including: The hook function creates an environment variable and assigns the parameter stored in the register during the system call to the environment variable; The microservice obtains parameters through the environment variables, creates a QUIC socket to establish a communication connection, and completes data communication based on the QUIC protocol.
8. The method according to claim 6 or 7, characterized in that: The hook function communicates with the microservice using unixdomain socket.
9. A data transmission device, characterized in that: Deployed on a computing device, the computing device adopts a Linux operating system and a hardware environment of X86-64 CPUs, and the device includes: Configuration module, used to configure the environment variable LD_PRELOAD, LD_PRELOAD is set to the shared library file that implements the hook function; A loading module, used for rewriting the binary code of the first instruction and writing the jump program code at memory 0-500 when loading the hook function shared library specified by the LD_PRELOAD environment variable; wherein the first instruction is a system call instruction; A processing module, used for hooking the system call by binary rewriting; the binary rewriting is specifically used for rewriting the first instruction into a second instruction; The processing module is also used to jump to the jump program code for execution based on the second instruction, and then be guided by the jump program code to the hook function for execution, and the hook function calls the QUIC API for communication.
10. A computer-readable storage medium, comprising computer-readable instructions, which, when a computer reads and executes the computer-readable instructions, enables the computer to execute the method according to any one of claims 1 to 8.