Data transmission method and device, electronic equipment and storage medium
By installing the packet capture library on the target server and using the preset mode of the network card device to obtain network transmission data packets and store them in the shared space, the zero copy state is achieved, solving the problem of low data transmission efficiency in traditional technology and improving performance and real-time.
Patent Information
- Application Number
- CN202411229111.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-09-03
- Publication Date
- 2025-01-07
AI Technical Summary
Traditional network stacks require multiple copy operations during data transmission, resulting in large CPU overhead and high latency, which cannot meet real-time requirements.
Install and configure the packet capture library on the target server, use the preset mode of the network card device to obtain network transmission data packets and store them in the shared space, so that the target application can directly access it and achieve zero copy state.
It improves the packet capture and processing efficiency, reduces CPU copy overhead, improves data transmission performance, and meets real-time requirements.
Smart Images

Figure CN119276882A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of data transmission, and in particular to a data transmission method and device, electronic equipment, and storage medium. Background Art
[0002] Traditional network stacks require multiple data copy operations when transmitting data from network devices to applications, which increases CPU overhead and latency, resulting in low data transmission efficiency and failure to meet real-time requirements. Summary of the invention
[0003] In view of the above problems, a data transmission method and device, electronic device, and storage medium are proposed to overcome the above problems or at least partially solve the above problems, including:
[0004] A data transmission method, the method comprising:
[0005] Install and configure a packet capture library and a target API interface of a target application program on a target server for accessing data in the packet capture library;
[0006] When the current operation mode of the network card device of the target server is a preset mode of using a data packet capture library to capture data, obtaining a target network transmission data packet through the network card device;
[0007] The target network transmission data packet is stored in the created shared space, so that the target application program calls the target API interface to access the target network transmission data packet in the shared space.
[0008] Optionally, installing and configuring a packet capture library on the target server includes:
[0009] Install a packet capture library on the target server;
[0010] Obtaining a device descriptor corresponding to the network card device of the target server;
[0011] A target API interface for accessing data in the packet capture library is configured for a target application of the target server based on the device descriptor.
[0012] Optionally, it also includes:
[0013] Determine whether the network card device supports the use of the data packet capture library;
[0014] When it is determined that the network card device supports the use of the data packet capture library, when the current operation mode of the network card device of the target server is a preset mode of using the data packet capture library to capture data, the target network transmission data packet is acquired through the network card device.
[0015] Optionally, determining whether the network card device supports the use of the data packet capture library includes:
[0016] Obtaining target code data corresponding to the network card device; the target code data is used to determine whether the network card device supports the use of the data packet capture library according to the operation status;
[0017] Running the target code data to obtain a running status;
[0018] Determine whether the network card device supports the use of the data packet capture library according to the running status.
[0019] Optionally, judging whether the network card device supports the use of the data packet capture library according to the running state includes:
[0020] When the running state is that the system call function of the network card device driver is successfully called, determining that the network card device supports the use of the data packet capture library;
[0021] When the running status is that the system call function call of the network card device driver fails, it is determined that the network card device does not support the use of the data packet capture library.
[0022] Optionally, it also includes:
[0023] Using the packet filtering rules configured in the network card device to filter the captured target network transmission data packets to obtain abnormal data packets;
[0024] Log information is generated based on the abnormal data packet.
[0025] Optionally, the data packet capture library is a Netmap library, and the shared space is a NIC ring.
[0026] A data transmission device, comprising:
[0027] An installation and configuration module, for installing and configuring a packet capture library and a target API interface of a target application for accessing data in the packet capture library on a target server;
[0028] A data packet acquisition module, used for acquiring a target network transmission data packet through the network card device when the current operation mode of the network card device of the target server is a preset mode of capturing data using a data packet capture library;
[0029] The data packet storage module is used to store the target network transmission data packet in the created shared space, so that the target application program calls the target API interface to access the target network transmission data packet in the shared space.
[0030] An electronic device comprises a processor, a memory and a computer program stored in the memory and capable of running on the processor, wherein the computer program implements the above-mentioned data transmission method when executed by the processor.
[0031] A computer-readable storage medium, characterized in that a computer program is stored on the computer-readable storage medium, and when the computer program is executed by a processor, the data transmission method as described above is implemented.
[0032] The embodiments of the present invention have the following advantages:
[0033] In an embodiment of the present invention, a data packet capture library and a target API interface for a target application to access data in the data packet capture library are installed and configured on a target server; when the current operating mode of the network card device of the target server is a preset mode for applying the data packet capture library to capture data, the target network transmission data packet is obtained through the network card device; the target network transmission data packet is stored in a created shared space, so that the target application can call the target API interface to access the target network transmission data packet in the shared space, thereby improving the capture and processing efficiency of the data packet in a zero-copy state. BRIEF DESCRIPTION OF THE DRAWINGS
[0034] In order to more clearly illustrate the technical solution of the present invention, the accompanying drawings required for use in the description of the present invention will be briefly introduced below. Obviously, the accompanying drawings in the following description 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 labor.
[0035] Figure 1 is a flowchart of a data transmission method provided by an embodiment of the present invention;
[0036] Figure 2a is a flowchart of another data transmission method provided by an embodiment of the present invention;
[0037] Figure 2b It is a data architecture diagram in the prior art;
[0038] Figure 2c It is a data architecture diagram provided by an embodiment of the present invention;
[0039] Figure 2d This is a schematic diagram of a data transmission link provided by an embodiment of the present invention;
[0040] Figure 3 It is a structural schematic diagram of a data transmission device provided by an embodiment of the present invention. DETAILED DESCRIPTION
[0041] In order to make the above-mentioned purposes, features and advantages of the present invention more obvious and easy to understand, the present invention is further described in detail below in conjunction with the accompanying drawings and specific embodiments. Obviously, the described embodiments are part of the embodiments of the present invention, rather than all 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.
[0042] Reference Figure 1 , shows a flowchart of a data transmission method provided by an embodiment of the present invention, which may specifically include the following steps:
[0043] Step S101, installing and configuring a data packet capture library and a target API interface of a target application for accessing data in the data packet capture library on a target server;
[0044] Among them, the packet capture library is the Netmap library, which is a high-performance packet capture library that can communicate directly with network hardware to reduce the overhead of packet capture. The shared space is the NIC ring. The NIC ring (Network Interface Card Ring) refers to the ring buffer on the network interface card (NIC) for managing and transmitting data packets. In network packet processing, the data structure composed of the ring buffer allows efficient reception and transmission of external data packets.
[0045] In actual applications, the target server may include hardware devices such as network devices, customer-oriented applications (i.e., user side), and the kernel layer between the network card device and the application. During the data transmission process, the network card device can capture data packets in the local area network and copy the data to the kernel layer, and then transmit it to the target application. During this data process, the data packet needs to transmit data through the kernel layer and needs to undergo multiple copy operations, which leads to increased copies and reduced network performance.
[0046] In an embodiment of the present invention, a data packet capture library can be installed and configured for a target server, and a target API interface can be configured for a target application. The target API interface can be used by the target application to call the data packet capture library to achieve zero copy during data transmission.
[0047] Among them, zero-copy means that when a host, router or other device interacts with a network card device, the CPU does not need to copy data from one memory area to another memory area.
[0048] In one embodiment of the present invention, a data packet capture library is installed and configured on a target server, including: installing the data packet capture library on the target server; obtaining a device descriptor corresponding to a network card device of the target server; and configuring a target API interface for accessing data in the data packet capture library for a target application of the target server based on the device descriptor.
[0049] In actual applications, a data packet capture library may be installed in a target server, so that the data packet capture library may be applied in the target server to realize data capture and transmission.
[0050] Each network card device in the target server has its unique device descriptor, and thus an association relationship between the device descriptor and the target API interface can be established.
[0051] In one embodiment of the present invention, the device descriptor can control the start or stop of data capture. When the device descriptor is opened, nmr = nm_open ("eth0", NULL, 0, NULL), where "eth0" is the name of the network interface that the user wants to capture data packets. After opening the device descriptor, data packets can be captured in a loop, where nm_nextpkt can be used to read data packets, and processing data packets is to process data packet logic according to actual needs. When data capture is not needed, the device descriptor can be closed.
[0052] In the application of the embodiment of the present invention, netmap is a high-speed network I / O architecture based on the zero-copy concept. When the network card runs in the netmap mode, the NIC ring will be disconnected from the host protocol stack, and netmap will copy a NIC ring, which is called the netmap ring. At the same time, netmap will also maintain another pair of rings for interacting with the host protocol stack. The caches pointed to by these rings for storing data packet contents are located in the shared space, and the network card directly stores the data packets in these caches. The application can access the data packet contents in the netmap ring by calling the netmap API, and can also access the cache for storing data packets. That is to say, when the application needs to access the data packet content, it does not need to copy from the kernel space to the user space, and can directly access it, thereby realizing zero copy of the network data packet. In addition, netmap does not expose the key memory areas of the network card registers and the kernel to the application, so the user-state application will not cause the operating system to crash, so relative to some other zero-copy architectures, netmap is safer.
[0053] Step S102, when the current operation mode of the network card device of the target server is a preset mode of capturing data using a data packet capture library, acquiring a target network transmission data packet through the network card device;
[0054] The network card device in the target server can be configured with one or more operation modes. Different operation modes can be applied in different scenarios, and the data packet transmission methods in different operation modes are also different.
[0055] When the network card device is in the preset mode, the target network transmission data packet transmitted in the network can be obtained through the network card device.
[0056] In an example, the operation mode of the network card device in the target server may include a normal mode, a promiscuous mode, and a preset mode in which a data packet capture library is used to capture data.
[0057] Among them, when the network card device is running in normal mode, the network card device only receives broadcast packets and data packets whose destination MAC address matches the local network card. The data packets will flow through the network card driver, be transmitted to the protocol stack of the operating system, and then be processed.
[0058] When the network card device is in promiscuous mode, the network card device will process all data packets passing through the network card device. Promiscuous mode can be used for network monitoring and analysis tools.
[0059] When the network card device is in the preset mode of using the data packet capture library to capture data, the target network transmission data packet can be obtained through the network card device, thereby obtaining data without copying the data. Among them, the preset mode in the embodiment of the present invention can be a Netmap mode.
[0060] Netmap mode is a high-performance network packet processing framework that allows applications to directly access the memory of the network device (NIC), thereby achieving zero-copy data transmission. Netmap significantly improves the performance of packet processing by bypassing the operating system kernel and interacting directly with the NIC.
[0061] The main features of Netmap mode include:
[0062] Zero-copy transmission: Through direct memory access (DMA) and memory mapping technology, Netmap allows data packets to be transmitted directly between the network card and the application without being transferred through the CPU.
[0063] Kernel bypass: Netmap allows applications to bypass the operating system kernel and interact directly with the NIC, reducing the switching overhead between kernel mode and user mode.
[0064] Ring buffer: Netmap uses a ring buffer to manage the sending and receiving of data packets. Applications and NICs share these buffers to achieve efficient data transmission.
[0065] In one embodiment of the present invention, it is determined whether the network card device supports the use of the data packet capture library; when it is determined that the network card device supports the use of the data packet capture library, when the current operating mode of the network card device of the target server is a preset mode for applying the data packet capture library to capture data, the target network transmission data packet is obtained through the network card device.
[0066] In actual applications, not all network card devices can support the use of packet capture libraries. Therefore, before using the network card device on the target server, you can first determine whether the network card device supports the use of packet capture libraries. When it is determined that the network card device supports the use of packet capture libraries, you can enable the preset mode for zero-copy data transmission.
[0067] Specifically, the target code data corresponding to the network card device can be obtained; the target code data is used to determine whether the network card device supports the use of the data packet capture library based on the operating status; after obtaining the target code data, the target code data can be run to obtain the operating status; and then, based on the operating status, it is determined whether the network card device supports the use of the data packet capture library.
[0068] The target code data may be set according to actual needs, and no excessive restrictions are imposed on this in the embodiments of the present invention.
[0069] In one embodiment of the present invention, when the system call function call of the network card device driver is successful, it is determined that the network card device supports the use of the data packet capture library; when the system call function call of the network card device driver fails, it is determined that the network card device does not support the use of the data packet capture library.
[0070] The system call function of the network card device driver may be an ioctl function.
[0071] For example, if the target server has permission to access the / dev / netmap device file and the Netmap library is installed, you can run the following code to determine whether the Netmap library can be applied to the network card device:
[0072]
[0073]
[0074] The above code is used to check whether the Netmap library can work properly. If the ioctl call succeeds, it means that the Netmap library can work on the network card device. If it fails, the target server will print an error message and will not configure the interface to enter Netmap mode.
[0075] Step S103, storing the target network transmission data packet in the created shared space, so that the target application program calls the target API interface to access the target network transmission data packet in the shared space.
[0076] After capturing the target network transmission data packet, the target network transmission data packet can be stored in the created shared space. When the application has data access requirements, the target network transmission data packet in the shared space can be accessed by calling the API interface, thereby eliminating the need for additional copying and improving network transmission efficiency.
[0077] In an embodiment of the present invention, an application can access the data packet content in the netmap ring by calling the netmap API, and can also access the cache used to store data packets. That is to say, when the application needs to access the data packet content, it does not need to copy from the kernel space to the user space, and can directly access it, thereby achieving zero copy of the network data packet and greatly improving the network performance.
[0078] In an embodiment of the present invention, netmap increases the speed of network I / O by the following means:
[0079] (1) Pre-allocate fixed-size data packet storage space to eliminate the system overhead caused by dynamically allocating memory when storing each data packet;
[0080] (2) Allow user-mode programs to directly access the network packet buffer to reduce the overhead of data copying;
[0081] (3) Use a lightweight metadata representation to mask some hardware-related features. This metadata representation supports processing a large number of data packets in one system call, thereby reducing the overhead of system calls. Taking the packet sending speed as an example, netmap can process the line rate of 10G Ethernet (14.88Mpps) on a 900MHz single-core CPU.
[0082] In an embodiment of the present invention, a data packet capture library and a target API interface for a target application to access data in the data packet capture library are installed and configured on a target server; when the current operating mode of the network card device of the target server is a preset mode for applying the data packet capture library to capture data, the target network transmission data packet is obtained through the network card device; the target network transmission data packet is stored in a created shared space, so that the target application can call the target API interface to access the target network transmission data packet in the shared space, thereby improving the capture and processing efficiency of the data packet in a zero-copy state.
[0083] Reference Figure 2a , shows a flowchart of another data transmission method provided by an embodiment of the present invention, which may specifically include the following steps:
[0084] Step S201, installing and configuring a data packet capture library and a target API interface of a target application for accessing data in the data packet capture library on a target server;
[0085] Step S202, when the current operation mode of the network card device of the target server is a preset mode of capturing data using a data packet capture library, acquiring a target network transmission data packet through the network card device;
[0086] Step S203, storing the target network transmission data packet in the created shared space, so that the target application program calls the target API interface to access the target network transmission data packet in the shared space.
[0087] Step S204, filtering the captured target network transmission data packets using the data packet filtering rules configured in the network card device to obtain abnormal data packets;
[0088] Packet filtering rules can be pre-configured in the network card device to filter the captured target network transmission packets, thereby realizing the monitoring of the target network transmission packets.
[0089] Packet filtering rules can be used to identify abnormal packets in the captured target network transmission packets.
[0090] Step S205: generating log information based on the abnormal data packet.
[0091] After determining the abnormal data packets, the abnormal data packets are parsed, and the associated information of the abnormal data packets can be counted, such as the number of abnormal data packets, the cause of the abnormality, the solution, etc. Then, log information can be generated according to the associated information.
[0092] Reference Figure 2b , shows a data architecture diagram in the prior art, including an application, a libpcap operating system, and computer hardware (such as a network card device). The operating system is provided with a BPF mechanism.
[0093] In practical applications, libpcap technology is an open source network packet capture library on UNIX / Linux, which provides a user-level API independent of the operating system. libpcap uses the BPF (Berkeley Packet Filter) mechanism, which is a packet capture mechanism that works in the operating system kernel. It first captures the link layer packets, then filters them, and finally provides the filtered packets to the application layer. However, the BPF mechanism used by the original libpcap technology is limited in its performance in capturing packets.
[0094] Among them, libpcap is a portable framework for network traffic capture. It provides a method to capture network packets on Unix and Unix-like systems (such as Linux, BSD, macOS, etc.). By adding a bypass process at the data link layer, libpcap can perform three operations on the received packets: filtering, statistics, and transfer.
[0095] Reference Figure 2c , shows the data architecture diagram after Netmap replaces BPF mechanism in the embodiment of the present invention. Based on the libpcap method optimized by Netmap technology, the more efficient netmap technology is used to replace the bpf mechanism in the traditional libpcap method, which greatly improves the performance of capturing messages. This optimization can greatly improve the efficiency of capturing and analyzing abnormal messages.
[0096] Reference Figure 2d , showing a schematic diagram of a data transmission link in an embodiment of the present invention. The processing flow of the captured message flow mechanism is as follows: When libpcap performs statistics and transfer operations, the data packet will not be transmitted to the application layer. When the application layer needs to analyze the specific content of the data packet, the data packet needs to be processed and copied layer by layer, that is, Figure 2d The leftmost branch in , its specific process is as follows:
[0097] When a data packet flows through the network card and is captured, libpcap will use the created socket to obtain a copy of the data packet from the link layer driver. The tap function is used to send the data packet to the BPF filter. If there are filtering rules, the BPF filter will filter the data packet according to the defined filtering rules after receiving the data packet. The data packets that meet the filtering rules are placed in the kernel buffer and passed to the user layer buffer, waiting for the application to process them. The data packets that do not meet the filtering rules are discarded. If no filtering rules are set, all data packets are placed in the kernel buffer and then passed to the user layer buffer.
[0098] In an embodiment of the present invention, a data packet capture library and a target API interface for accessing data in the data packet capture library of a target application are installed and configured on a target server; when the current operation mode of the network card device of the target server is a preset mode for applying the data packet capture library to capture data, the target network transmission data packet is obtained through the network card device; the target network transmission data packet is stored in the created shared space, so that the target application calls the target API interface to access the target network transmission data packet in the shared space, and the captured target network transmission data packet is filtered using the configured data packet filtering rules in the network card device to obtain abnormal data packets; log information is generated based on the abnormal data packets, so that while improving network performance, abnormal message information is also captured and filtered and analyzed, and log information is generated for inspection. In this way, network performance can be monitored in real time, fault points can be accurately located, network maintenance and management are greatly simplified, and the fault monitoring technology is superior to the existing fault monitoring technology.
[0099] It should be noted that, for the sake of simplicity, the method embodiments are described as a series of action combinations, but those skilled in the art should be aware that the embodiments of the present invention are not limited by the order of the actions described, because according to the embodiments of the present invention, certain 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 invention.
[0100] Reference Figure 3 , shows a schematic diagram of the structure of a data transmission device provided by an embodiment of the present invention, which may specifically include the following modules:
[0101] An installation and configuration module 301 is used to install and configure a data packet capture library and a target API interface of a target application for accessing data in the data packet capture library on a target server;
[0102] The data packet acquisition module 302 is used to acquire the target network transmission data packet through the network card device when the current operation mode of the network card device of the target server is a preset mode of capturing data using the data packet capture library;
[0103] The data packet storage module 303 is used to store the target network transmission data packet in the created shared space, so that the target application program calls the target API interface to access the target network transmission data packet in the shared space.
[0104] In one embodiment of the present invention, the installation and configuration module 301 may include:
[0105] The database installation submodule is used to install the packet capture library on the target server;
[0106] A device descriptor acquisition submodule, used to acquire the device descriptor corresponding to the network card device of the target server;
[0107] The API interface configuration submodule is used to configure a target API interface for accessing data in the data packet capture library for a target application of the target server based on the device descriptor.
[0108] In one embodiment of the present invention, the device further comprises:
[0109] A determination module, used for determining whether the network card device supports the use of the data packet capture library;
[0110] The execution module is used to, when it is determined that the network card device supports the use of the data packet capture library, execute the acquisition of the target network transmission data packet through the network card device when the current operation mode of the network card device of the target server is a preset mode of capturing data using the data packet capture library.
[0111] In one embodiment of the present invention, the determination module may include:
[0112] The target code data acquisition submodule is used to acquire the target code data corresponding to the network card device; the target code data is used to determine whether the network card device supports the use of the data packet capture library according to the operation status;
[0113] A code running submodule is used to run the target code data to obtain a running status;
[0114] The judging submodule is used to judge whether the network card device supports the use of the data packet capture library according to the running status.
[0115] In one embodiment of the present invention, the judgment submodule may include:
[0116] A call success unit, used for determining that the network card device supports the use of the data packet capture library when the running state is that the system call function of the network card device driver is successfully called;
[0117] The call failure unit is used to determine that the network card device does not support the use of the data packet capture library when the running state is that the system call function call of the network card device driver fails.
[0118] In one embodiment of the present invention, the device further comprises:
[0119] A data packet filtering module, used to filter the captured target network transmission data packets using the data packet filtering rules configured in the network card device to obtain abnormal data packets;
[0120] The log information generating module is used to generate log information based on the abnormal data packet.
[0121] In one embodiment of the present invention, the data packet capture library is a Netmap library, and the shared space is a NIC ring.
[0122] In an embodiment of the present invention, a data packet capture library and a target API interface for a target application to access data in the data packet capture library are installed and configured on a target server; when the current operating mode of the network card device of the target server is a preset mode for applying the data packet capture library to capture data, the target network transmission data packet is acquired through the network card device; the target network transmission data packet is stored in a created shared space, so that the target application can call the target API interface to access the target network transmission data packet in the shared space, thereby improving the capture and processing efficiency of the data packet in a zero-copy state.
[0123] An embodiment of the present invention further provides an electronic device, which may include a processor, a memory, and a computer program stored in the memory and capable of running on the processor, and the computer program implements the above data transmission method when executed by the processor.
[0124] An embodiment of the present invention further provides a computer-readable storage medium, on which a computer program is stored. When the computer program is executed by a processor, the above data transmission method is implemented.
[0125] As for the device embodiment, since it is basically similar to the method embodiment, the description is relatively simple, and the relevant parts can be referred to the partial description of the method embodiment.
[0126] 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.
[0127] Those skilled in the art will appreciate that the embodiments of the present invention may be provided as methods, devices, or computer program products. Therefore, the embodiments of the present invention may take the form of a complete hardware embodiment, a complete software embodiment, or an embodiment combining software and hardware. Moreover, the embodiments of the present invention may take 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 codes.
[0128] The embodiments of the present invention are described with reference to the flowcharts and / or block diagrams of the methods, terminal devices (systems), and computer program products according to the embodiments of the present invention. It should be understood that each process and / or block in the flowchart and / or block diagram, as well as the combination of the processes and / or blocks 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.
[0129] 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.
[0130] 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.
[0131] Although the preferred embodiments of the present invention 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 invention.
[0132] 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", "comprises" 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.
[0133] The above is a detailed introduction to a data transmission method and device, an electronic device, and a storage medium. Specific examples are used in this article to illustrate the principles and implementation methods of the present invention. The description of the above embodiments is only used to help understand the method of the present invention and its core idea; at the same time, for a person skilled in the art, according to the idea of the present invention, 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 invention.
Claims
1. A data transmission method, characterized in that: The method comprises: Install and configure a packet capture library and a target API interface of a target application program on a target server for accessing data in the packet capture library; When the current operation mode of the network card device of the target server is a preset mode of using a data packet capture library to capture data, obtaining a target network transmission data packet through the network card device; The target network transmission data packet is stored in the created shared space, so that the target application program calls the target API interface to access the target network transmission data packet in the shared space.
2. The method according to claim 1, characterized in that The installation and configuration of the packet capture library on the target server includes: Install a packet capture library on the target server; Obtaining a device descriptor corresponding to the network card device of the target server; A target API interface for accessing data in the packet capture library is configured for a target application of the target server based on the device descriptor.
3. The method according to claim 1, characterized in that Also includes: Determine whether the network card device supports the use of the data packet capture library; When it is determined that the network card device supports the use of the data packet capture library, when the current operation mode of the network card device of the target server is a preset mode of using the data packet capture library to capture data, the target network transmission data packet is acquired through the network card device.
4. The method according to claim 3, characterized in that The determining whether the network card device supports the use of the data packet capture library comprises: Obtaining target code data corresponding to the network card device; the target code data is used to determine whether the network card device supports the use of the data packet capture library according to the operation status; Running the target code data to obtain a running status; Determine whether the network card device supports the use of the data packet capture library according to the running status.
5. The method according to claim 4, characterized in that The step of judging whether the network card device supports the use of the data packet capture library according to the running state includes: When the running state is that the system call function of the network card device driver is successfully called, determining that the network card device supports the use of the data packet capture library; When the running status is that the system call function call of the network card device driver fails, it is determined that the network card device does not support the use of the data packet capture library.
6. The method according to claim 1, characterized in that Also includes: Using the packet filtering rules configured in the network card device to filter the captured target network transmission data packets to obtain abnormal data packets; Log information is generated based on the abnormal data packet.
7. The method according to claim 1, characterized in that The data packet capture library is a Netmap library, and the shared space is a NIC ring.
8. A data transmission device, characterized in that: The device comprises: An installation and configuration module, for installing and configuring a packet capture library and a target API interface of a target application for accessing data in the packet capture library on a target server; A data packet acquisition module, used for acquiring a target network transmission data packet through the network card device when the current operation mode of the network card device of the target server is a preset mode of capturing data using a data packet capture library; The data packet storage module is used to store the target network transmission data packet in the created shared space, so that the target application program calls the target API interface to access the target network transmission data packet in the shared space.
9. An electronic device, characterized in that: The method comprises a processor, a memory, and a computer program stored in the memory and capable of running on the processor, wherein when the computer program is executed by the processor, the data transmission method according to any one of claims 1 to 7 is implemented.
10. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the data transmission method according to any one of claims 1 to 7 is implemented.
Citation Information
Cited By
Inter-process communication method, system and device based on logic device and storage medium
CN120353621A