Network data packet forwarding method and device based on network card drive, and storage medium
By adding the network device structure pointer and the network data packet sending function pointer to the network card driver layer, the forwarding of network data packets is directly implemented in the network card driver layer, which solves the network data packet processing delay and performance problems in the existing technology, and achieves a better Efficient packet forwarding.
Patent Information
- Application Number
- CN202411395567.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-10-08
- Publication Date
- 2025-01-24
AI Technical Summary
In the application scenarios of vehicle-mounted V2X communications, network data packets need to be multi-layered analysis and encapsulated through the network protocol stack, resulting in increased communication delay, decreased system performance, increased risk of network data packet corruption and packet loss.
By adding a network device structure pointer and network data packet sending function pointer to each network card, bypass the Linux kernel network protocol stack, and directly realize the reposting of the network data packet at the network card drive layer.
Reduce communication delay, improve system performance, avoid damage to network data packets, and reduce the risk of packet loss.
Smart Images

Figure CN119363688A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of network communication technology, and in particular to a network data packet forwarding method, device and storage medium based on a network card driver. Background Art
[0002] With the widespread application of the Linux kernel in the development of in-vehicle equipment, the network protocol stack of the Linux system has become an important foundation for network data processing. The network protocol stack based on the seven-layer network model processes and transmits various network data packets through layered network protocols. However, in specific application scenarios, such as in-vehicle V2X communication, the data packet does not need to be parsed in the current device, but needs to be directly forwarded to the target device for processing.
[0003] The existing network packet processing process requires data packets to go through multiple layers of parsing and encapsulation of the network protocol stack, from the physical layer to the application layer, and then back to the physical layer for forwarding. This layer-by-layer processing increases data transmission latency and system resource consumption, especially when large amounts of data or high-frequency data transmission are involved, which significantly reduces system performance and increases the risk of packet loss and data corruption.
[0004] In order to solve these problems, the prior art usually uses the iptables tool to set packet forwarding rules in the Linux system. However, iptables works at the network layer, and the data packets still need to enter the network protocol stack for processing, which cannot effectively avoid the delay caused by the protocol stack. Therefore, the prior art cannot bypass the network protocol stack and directly perform efficient data packet forwarding at the data link layer, resulting in increased communication delay, decreased system performance, and increased risk of network data packet damage and packet loss. Summary of the invention
[0005] In view of this, the embodiments of the present application provide a network data packet forwarding method, device and storage medium based on a network card driver to solve the problems of increased communication delay, decreased system performance, increased risk of network data packet damage and packet loss in the prior art.
[0006] According to a first aspect of an embodiment of the present application, a network data packet forwarding method based on a network card driver is provided, comprising: adding a network device structure pointer and a network data packet sending function pointer to a private data structure corresponding to the network device of each network card; during the initialization process of the network card driver, establishing a mapping relationship between the network device structure pointer of each network card and the network device structure of the corresponding network card, and establishing a mapping relationship between the network data packet sending function pointer of each network card and the network data packet sending function of the corresponding network card; when the interrupt function of any network card receives the network data packet, the destination address or media access control address of the network data packet is judged, and the receiving network card and the target network card are determined according to the judgment result; the network device structure pointer in the private data structure of the receiving network card is used to search for the network device structure of the target network card, and the network data packet sending function of the target network card is called to send the network data packet through the target network card.
[0007] According to a second aspect of an embodiment of the present application, a network data packet forwarding device based on a network card driver is provided, comprising: an adding module, configured to add a network device structure pointer and a network data packet sending function pointer in a private data structure corresponding to the network device of each network card; an establishing module, configured to establish a mapping relationship between the network device structure pointer of each network card and the network device structure of the corresponding network card during the initialization process of the network card driver, and to establish a mapping relationship between the network data packet sending function pointer of each network card and the network data packet sending function of the corresponding network card; a judging module, configured to judge the destination address or media access control address of the network data packet when the interrupt function of any network card receives the network data packet, and determine the receiving network card and the target network card according to the judgment result; a sending module, configured to use the network device structure pointer in the private data structure of the receiving network card to search for the network device structure of the target network card, and call the network data packet sending function of the target network card to send the network data packet through the target network card.
[0008] According to a third aspect of an embodiment of the present application, an electronic device is provided, including a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the steps of the above method are implemented when the processor executes the computer program.
[0009] According to a fourth aspect of an embodiment of the present application, a readable storage medium is provided, which stores a computer program, and when the computer program is executed by a processor, the steps of the above method are implemented.
[0010] At least one of the above technical solutions adopted in the embodiments of the present application can achieve the following beneficial effects:
[0011] By adding a network device structure pointer and a network data packet sending function pointer to the private data structure corresponding to the network device of each network card; during the initialization process of the network card driver, a mapping relationship between the network device structure pointer of each network card and the network device structure of the corresponding network card is established, and a mapping relationship between the network data packet sending function pointer of each network card and the network data packet sending function of the corresponding network card is established; when the interrupt function of any network card receives a network data packet, the destination address or media access control address of the network data packet is judged, and the receiving network card and the target network card are determined according to the judgment result; the network device structure pointer in the private data structure of the receiving network card is used to search for the network device structure of the target network card, and the network data packet sending function of the target network card is called to send the network data packet through the target network card. This application can reduce communication delay, improve system performance, avoid network data packet damage, and reduce the risk of packet loss. BRIEF DESCRIPTION OF THE DRAWINGS
[0012] In order to more clearly illustrate the technical solutions in the embodiments of the present application, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative work.
[0013] Figure 1 It is a structural diagram of a seven-layer network model in the prior art provided by an embodiment of the present application;
[0014] Figure 2 It is a structural diagram of another network seven-layer model in the prior art provided by an embodiment of the present application;
[0015] Figure 3 It is a schematic diagram of the flow of network data packet transmission in the prior art provided by an embodiment of the present application;
[0016] Figure 4 It is a flowchart of using a tool provided in an embodiment of the present application to set forwarding rules on a Linux system to implement network data packet transmission;
[0017] Figure 5 It is a flowchart of a network data packet forwarding method based on a network card driver provided in an embodiment of the present application;
[0018] Figure 6 It is a schematic diagram of the process of normally forwarding network packets in the prior art provided by the embodiment of the present application;
[0019] Figure 7 It is a schematic diagram of the process of assigning values to a network device structure pointer and a network data packet sending function pointer provided by an embodiment of the present application;
[0020] Figure 8 It is a schematic diagram of the process of network data packet forwarding between network card A and network card B provided in an embodiment of the present application;
[0021] Fig. 9 It is a structural schematic diagram of a network data packet forwarding device based on a network card driver provided in an embodiment of the present application;
[0022] Fig.10 It is a schematic diagram of the structure of an electronic device provided in an embodiment of the present application. DETAILED DESCRIPTION
[0023] In the following description, specific details such as specific system structures, technologies, etc. are provided for the purpose of illustration rather than limitation, so as to provide a thorough understanding of the embodiments of the present application. However, it should be clear to those skilled in the art that the present application may also be implemented in other embodiments without these specific details. In other cases, detailed descriptions of well-known systems, devices, circuits, and methods are omitted to prevent unnecessary details from obstructing the description of the present application.
[0024] In modern vehicle-mounted devices, the Linux kernel is widely used, especially when dealing with network communications, relying on the Linux built-in network protocol stack. Currently, the Linux kernel is widely used as the kernel of the operating system in the development of vehicle-mounted devices. The Linux kernel provides a complete network protocol stack based on the seven-layer network model and supports a variety of network protocols and technologies. Figure 1 Schematic diagram of a seven-layer network model in the prior art provided by the embodiment of the present application. Figure 1 As shown in the figure, the seven-layer network model is composed of multiple levels of protocols, including application layer, presentation layer, session layer, transport layer, network layer, data link layer, and physical layer. In order to simplify the model, the session layer and presentation layer are usually summarized into the application layer.
[0025] The physical layer is the bottom layer of the OSI model and is responsible for transmitting the original bit stream. It defines the physical connection of the network and the transmission method of electrical signals. At the physical layer, data is transmitted in binary form through physical media, such as network cables and optical fibers. Common physical layer protocols include Ethernet, RS-232, etc.
[0026] The data link layer is responsible for organizing the bit stream into data frames and reliably transmitting them on the transmission medium provided by the physical layer. It solves the problem of reliable communication between directly connected nodes. The data link layer usually includes two sublayers: the logical link control (LLC) sublayer and the media access control (MAC) sublayer. Common data link layer protocols include Ethernet, Wi-Fi (IEEE 802.11), etc.
[0027] The network layer is responsible for routing and forwarding data packets, transferring data packets from the source host to the destination host. It uses IP addresses to address and locate data packets, and determines the best path for data packets through routing selection algorithms. The typical protocol of the network layer is the Internet Protocol (IP).
[0028] The transport layer is responsible for providing end-to-end reliable data transmission services, ensuring reliable transmission of data between source and target applications. The transport layer can use two common protocols: Transmission Control Protocol (TCP) and User Datagram Protocol (UDP).
[0029] The application layer is the highest layer of the OSI model and provides the interface between users and network services. It contains many different protocols to support various applications, such as email (SMTP), file transfer (FTP), domain name system (DNS), web browsing (HTTP), etc.
[0030] These protocols work together to ensure the correct transmission and processing of data packets. The received network data packets need to be parsed layer by layer through the network protocol stack before they can be processed by the application layer. At the same time, the data packets sent out must also be encapsulated and forwarded layer by layer through the network protocol stack before they are finally sent out through the physical layer (optical fiber or network cable).
[0031] The Linux network card driver is responsible for part of the work of the data link layer. The most important thing is to drive the network device (usually called the network card) to send data, or to submit the data received by the network device to the upper layer. In simpler terms, it is responsible for the sending and receiving of network data. The network device driver plays a connecting role here, so that the upper network protocol layer does not need to care about the hardware details of the underlying layer. In addition, the driver itself is basically unrelated to the protocol and does not need to parse network data packets. It is only responsible for sending and receiving data packets. Figure 2 Schematic diagram of another network seven-layer model in the prior art provided by the embodiment of the present application. Figure 2 As shown, combined with the Linux network card driver, the data link layer can be further subdivided into the network protocol interface layer, the network device interface layer, and the device driver function layer.
[0032] The network protocol interface layer provides a unified data packet sending and receiving interface to the network layer protocol. Regardless of whether the upper layer protocol is ARP or IP, data is sent through the dev_queue_xmit() function and received through the netif_rx() function. The existence of this layer makes the upper layer protocol independent of specific devices.
[0033] The network device interface layer provides the network protocol interface layer with a unified structure net_device for describing specific network device properties and operations. This structure is a container for various functions in the device driver function layer.
[0034] The function interfaces designed in this layer of the device driver function layer are specific members of the net_device data structure of the network device interface layer. They are programs that drive the network device hardware to complete corresponding actions. They start the sending operation through the hard_start_xmit() function and trigger the receiving operation through the interrupt on the network device.
[0035] In the prior art, the network data packet transmission process is as follows:
[0036] 1. Receiving process:
[0037] 1. The network card reads the data frame into the RingBuffer cache in the memory through DMA, and then initiates an interrupt notification to the CPU;
[0038] 2. The CPU responds to the interrupt request and calls the interrupt processing function registered when the network card is started to receive the data frame, and then triggers the soft interrupt;
[0039] 3. The soft interrupt processing function encapsulates the data frame into the socket buffer skb_buff, calls the data packet receiving function of net_device, and calls the data packet receiving function netif_rx() of the network protocol interface layer in this function to send the data packet to the network protocol stack for processing;
[0040] 4. After being parsed and processed by the network layer and transport layer in the network protocol stack, it finally reaches the application layer, which performs the final processing.
[0041] 2. Sending process:
[0042] 1. The application layer calls the system call Socket function provided by the Linux system to send the data packet to the network protocol stack;
[0043] 2. After being processed and encapsulated by the transport layer and network layer in the network protocol stack, it is sent to the data link layer;
[0044] 3. The data link layer calls dev_queue_xmit() of the network protocol interface layer to send data packets. The interface calls the data packet sending function of the network device net_device;
[0045] 4. The device driver function layer assigns a value to the hard_start_xmit() member of the data packet sending function of the net_device structure of the network device interface layer, that is, it provides a function for sending data frames to the physical layer, and transmits data to other network devices through the network card through this interface.
[0046] The existing technology has the following defects in specific application scenarios: In certain specific business scenarios, the application layer sometimes does not need to parse and process these network data packets, but needs to forward these data packets again through the network protocol stack before reaching the device that actually needs to parse and process these data packets. However, if the data packet must first enter the network protocol stack, go through layer-by-layer parsing to reach the application layer, and then the application layer sends the data packet to the protocol stack, which then processes and encapsulates it layer by layer and sends it out through the network device driver, this will inevitably increase the transmission delay of the network data packet and the burden on the system.
[0047] Figure 3 FIG. 1 is a flow chart of network data packet transmission in the prior art provided by the embodiment of the present application. Figure 3 As shown, for example, in automobile V2X communication, the road test unit RSU needs to pull map data from the cloud via Ethernet, but the unit does not parse and process the data, but forwards the data to the on-board unit OBU for processing via Ethernet. This increases the transmission delay of the map data packet, and the forwarding and transmission of the application layer also introduces the risk of packet loss and data corruption. Especially in scenarios with frequent transmission and large data volume transmission, a large amount of memory space will be consumed to cache data packets, occupying too many CPU resources. This reduces the performance of the entire system, increases user waiting time, and reduces the user experience.
[0048] Figure 4 1 is a flow chart of using a tool provided in an embodiment of the present application to set forwarding rules on a Linux system to implement network data packet transmission. Figure 4 As shown in the figure, the traditional solution is to use the iptables tool to set forwarding rules on the Linux system to forward and transmit network data packets. When a data enters the network card, the data packet will first enter the prerouting chain. The kernel determines whether it needs to be forwarded to the next linked list forward or input based on the destination IP of the data packet; if it is to the local machine: the arriving data packet will go to the INPUT chain. If it is a data packet that needs to be forwarded, the local machine is a server with routing function at this time, and it will match the forward and postrouting rule linked lists at one time. If it is allowed, it will be forwarded, otherwise it will be discarded; but this method will also introduce some delay, because the iptables tool works in the network layer of the seven-layer network model, and the network data packet also needs to enter the Linux network protocol stack.
[0049] In view of the problems existing in the prior art, this application proposes a method for reducing network transmission delay by bypassing the Linux kernel network protocol stack. The technical problem to be solved by this application is that the existing automotive V2X devices frequently forward and transmit large amounts of network data packets through the Linux network protocol stack, which leads to increased communication delay, reduced system performance, increased risk of network data packet corruption and packet loss. A method for forwarding and transmitting network data packets by bypassing the Linux network protocol stack is provided. This method works at the data link layer in the seven-layer network model and is implemented by adding network data forwarding code to the network card driver in the Linux kernel.
[0050] The contents of the technical solution of the present application are described in detail below with reference to the accompanying drawings and specific embodiments.
[0051] Figure 5 Schematic diagram of the flow of the network data packet forwarding method based on the network card driver provided in the embodiment of the present application. Figure 5 As shown, the network data packet forwarding method based on the network card driver may specifically include:
[0052] S501, adding a network device structure pointer and a network data packet sending function pointer to a private data structure corresponding to a network device of each network card;
[0053] S502, during the initialization process of the network card driver, a mapping relationship between a network device structure pointer of each network card and a network device structure of the corresponding network card is established, and a mapping relationship between a network data packet sending function pointer of each network card and a network data packet sending function of the corresponding network card is established;
[0054] S503, when the interrupt function of any network card receives the network data packet, the destination address or the media access control address of the network data packet is judged, and the receiving network card and the target network card are determined according to the judgment result;
[0055] S504, using the network device structure pointer in the private data structure of the receiving network card to search for the network device structure of the target network card, and calling the network data packet sending function of the target network card to send the network data packet through the target network card.
[0056] First, the existing normal process of forwarding network packets is explained in detail with reference to the accompanying drawings. Figure 6 1 is a schematic diagram of a normal forwarding process of a network packet in the prior art provided by an embodiment of the present application. Figure 6As shown in the figure, taking a device with two Ethernet cards A and B as an example, after network card A receives network data, the default practice is to call the netif_rx function to send the network data packet to the network protocol stack after the interrupt function receives the network data packet. After the protocol stack parses from bottom to top, it is sent to the application layer. The application layer determines that it needs to be sent through network card B, and then it passes through the network protocol stack from top to bottom, and is sent after being encapsulated by the protocol stack. The two network card devices will have corresponding device driver codes in the Linux driver. In the driver code, the net_device structure is used to represent the network device. The structure contains the device private data structure priv, which is used to describe the data information of the device. Under normal circumstances, after receiving the network data packet, network card A will call the receiving function of network card A, and the receiving function will pass it to the kernel network protocol stack for parsing.
[0057] In some embodiments, before adding the network device structure pointer and the network data packet sending function pointer to the private data structure corresponding to the network device of each network card, the method further includes:
[0058] In the initialization function of the network card driver, a private data structure is created and initialized for the network device structure of each network card, wherein the private data structure is used to represent the device information storage space corresponding to each network card.
[0059] Specifically, in order to achieve efficient network packet forwarding based on the network card driver, it is first necessary to create and initialize the corresponding private data structure priv for each network card. The private data structure is used to store device information related to the network card, including a network device structure pointer and a network packet sending function pointer, so as to subsequently achieve packet forwarding between network cards.
[0060] First, in the initialization function of the network card driver, a specific memory allocation function is called for each network card to allocate memory space for the private data structure priv of the network card and initialize the structure. The private data structure is mainly used to store the device information of the network card, such as the MAC address of the network card, the device status, and the connection relationship with another network card.
[0061] Next, in the process of initializing the private data structure, add the following two key pointers:
[0062] Network device structure pointer net_device*: This pointer is used to point to the network device structure of another network card. Through this pointer, the current network card can access the device information of the target network card.
[0063] Network data packet sending function pointer tx_func*: This pointer points to the network data packet sending function of another network card, so that the current network card can call the sending function of the target network card through this pointer and directly forward the data packet to the target network card.
[0064] For example, in a typical dual-NIC system, in the private data structure priv of NIC A, the network device structure pointer net_device*p_dev_b is set to point to the device structure of NIC B, and the network packet sending function pointer tx_func*tx_func_b is set to point to the sending function of NIC B. Similarly, in the private data structure priv of NIC B, the network device structure pointer net_device*p_dev_a points to the device structure of NIC A, and the network packet sending function pointer tx_func*tx_func_a points to the sending function of NIC A.
[0065] In this way, a direct communication connection is established between NIC A and NIC B, so that when NIC A receives a data packet to be forwarded, it can find NIC B through its p_dev_b pointer and call tx_func_b to directly send the data packet, and vice versa. This mechanism effectively bypasses the Linux network protocol stack, reduces the transmission delay of data packets, and improves system performance.
[0066] After the initialization process is completed, the network card driver layer has the ability to directly forward data packets without going through complex protocol stack analysis, which greatly improves the forwarding efficiency of data packets in the network.
[0067] In some embodiments, in a private data structure corresponding to a network device of each network card, a network device structure pointer and a network data packet sending function pointer are added, including:
[0068] In the private data structure corresponding to the network device of each network card, a pointer to the network device structure of another network card and a pointer to the network data packet sending function of another network card are added, wherein the network device structure pointer is used to describe the device information of the target network card, and the network data packet sending function pointer is used to drive the target network card to perform a data packet sending operation.
[0069] Specifically, in order to achieve direct forwarding of network packets between network cards and bypass the kernel protocol stack processing, two key pointers need to be added to the private data structure priv corresponding to the network device of each network card: the network device structure pointer and the network packet sending function pointer. These two pointers are used for direct communication between network cards. Specifically, the network device structure pointer is used to point to the device information of another network card, and the network packet sending function pointer is used to drive the target network card to perform packet sending operations.
[0070] In an example, first add pointers to network card A and network card B: add two pointers to the private data structure priv of network card A and network card B respectively:
[0071] Network device structure pointer net_device*: This pointer is used to point to the network device structure of the target network card. For example, in the private data structure priv of network card A, add net_device*p_dev_b to point to the device information of network card B. Similarly, in the priv of network card B, add net_device*p_dev_a to point to the device information of network card A.
[0072] Network packet sending function pointer tx_func*: This pointer is used to point to the sending function of the target network card, so that the current network card can directly send the data packet to the target network card by calling the sending function of the target network card. For example, in the priv of network card A, add tx_func*tx_func_b to point to the sending function of network card B. Similarly, add tx_func*tx_func_a in the priv of network card B to point to the sending function of network card A.
[0073] Furthermore, the function of the network device structure pointer is as follows: when NIC A receives a data packet that needs to be forwarded through NIC B, NIC A can find the network device structure of NIC B through the p_dev_b pointer in its private data structure, thereby obtaining the device information of NIC B. In this way, NIC A can quickly locate the target NIC (i.e. NIC B) without going through the complex processing of the network protocol stack.
[0074] Furthermore, the function pointer of the network packet sending function is as follows: after finding the device information of NIC B, NIC A sends the data packet directly to NIC B by calling the sending function pointed to by the tx_func_b pointer. The same logic applies to the case where NIC B forwards the data packet to NIC A. Through this mechanism, data packets can be quickly transmitted between NICs, bypassing the multi-layer processing of the kernel protocol stack, and reducing the transmission delay of data packets.
[0075] The following describes the process of adding a network device structure pointer and a network data packet sending function pointer to a private data structure corresponding to a network device of a network card in the present application in conjunction with a specific operation flow example, which may specifically include the following contents:
[0076] When NIC A receives a network data packet and determines that the destination address of the data packet needs to be forwarded through NIC B, NIC A will find the network device structure net_device dev_b of NIC B through the p_dev_b pointer. Then, NIC A calls the sending function pointed to by the tx_func_b pointer, passing the data packet structure pointer sk_buff and the device structure pointer dev_b of NIC B as parameters, and sends the data packet directly through NIC B.
[0077] Similarly, when NIC B receives a data packet and needs to forward it through NIC A, NIC B will find the device information of NIC A through the p_dev_a pointer, and call the tx_func_a sending function to send the data packet through NIC A.
[0078] By adding a network device structure pointer and a network data packet sending function pointer to the private data structure priv of each network card, network card A and network card B can establish a direct communication connection. The key to this embodiment is to bypass the processing level of the kernel protocol stack and directly complete the forwarding of data packets at the network card driver layer, which greatly reduces the transmission delay and improves the overall performance of network communication.
[0079] In some embodiments, establishing a mapping relationship between a network device structure pointer of each network card and a network device structure of the corresponding network card, and establishing a mapping relationship between a network data packet sending function pointer of each network card and a network data packet sending function of the corresponding network card, includes:
[0080] Based on the preset first pointer mapping relationship, assigning a value to the network device structure pointer of each network card so as to point the network device structure pointer of each network card to the network device structure of the corresponding network card;
[0081] Based on the preset second pointer mapping relationship, assigning a value to the network data packet sending function pointer of each network card, so that the network data packet sending function pointer of each network card points to the network data packet sending function of the corresponding network card;
[0082] Among them, based on the assigned network device structure pointer and network data packet sending function pointer, any network card can access the device information of the corresponding network card through the network device structure pointer, and call the network data packet sending function of the corresponding network card to forward the network data packet.
[0083] Specifically, in order to achieve direct communication between network card A and network card B and avoid multiple layers of processing in the network protocol stack during data packet transmission, it is necessary to assign values to the network device structure pointer and network data packet sending function pointer of each network card respectively. The assignment process is implemented through a preset pointer mapping relationship, so that the network card can find the other party's device information through these pointers and forward data packets.
[0084] The following takes the application scenario of two network cards as an example, and explains in detail the implementation process of assigning the network device structure pointer and the network data packet sending function pointer of each network card in combination with the attached drawings.
[0085] Figure 7 Schematic diagram of the process of assigning values to a network device structure pointer and a network data packet sending function pointer provided by an embodiment of the present application. Figure 7 As shown in the figure, in the initialization function of the network card driver, the system will allocate a corresponding private data structure priv for each network card, which contains the network device structure pointer net_device* and the network data packet sending function pointer tx_func* that need to be assigned. These pointers will be assigned values through the preset mapping relationship during the initialization process.
[0086] Based on the preset first pointer mapping relationship, assign values to the network device structure pointers of network card A and network card B. Specifically, assign the network device structure pointer net_device*p_dev_b of network card A to the network device structure net_device dev_b of network card B, so that network card A can access the device information of network card B through the pointer. Similarly, assign the network device structure pointer net_device*p_dev_a of network card B to the network device structure net_device dev_a of network card A.
[0087] Through this bidirectional pointer mapping, network card A and network card B can quickly find each other's device information through their respective pointers when receiving data packets that need to be forwarded, thereby achieving a direct connection between network cards.
[0088] Furthermore, based on the preset second pointer mapping relationship, the network data packet sending function pointers tx_func* of network card A and network card B are assigned values. Specifically, the network data packet sending function pointer tx_func_b of network card A is assigned to the sending function pointing to network card B, so that when network card A needs to forward a data packet to network card B, it can call the sending function of network card B. Similarly, the network data packet sending function pointer tx_func_a of network card B is assigned to the sending function pointing to network card A, so that network card B can call the sending function of network card A through the pointer.
[0089] Through this bidirectional assignment of function pointers, network card A and network card B can not only find each other's device information, but also directly call each other's sending function to complete the data packet forwarding operation.
[0090] Furthermore, after the assignment is completed, a direct communication path is formed between NIC A and NIC B. When NIC A receives a data packet that needs to be forwarded through NIC B, NIC A will find the device information of NIC B through its p_dev_b pointer, and call the sending function pointed to by the tx_func_b pointer to send the data packet directly to NIC B. Vice versa, when NIC B receives a data packet that needs to be forwarded through NIC A, NIC B will find the device information of NIC A through its p_dev_a pointer, and call the tx_func_a sending function to send the data packet to NIC A.
[0091] Through this pointer mapping and assignment mechanism, data packets can be quickly transmitted between network cards, bypassing the multi-layer processing of the Linux network protocol stack, effectively reducing data transmission delays and improving network transmission efficiency.
[0092] The key point of this embodiment is to establish a direct connection between network card A and network card B through the assignment of network device structure pointer and network data packet sending function pointer, so as to ensure that the data packet can complete the forwarding operation quickly and efficiently. Through the above pointer mapping relationship, the communication process between network cards is simplified, which greatly improves the transmission performance of network data packets.
[0093] In some embodiments, when the interrupt function of any network card receives a network data packet, the destination address or media access control address of the network data packet is determined, including:
[0094] When the interrupt function of any network card receives a network data packet, the interrupt function is used to store the network data packet into a buffer area in the memory;
[0095] Calling the receiving function of the network card and parsing the header information of the network data packet according to a predetermined rule to obtain the destination address or media access control address of the network data packet;
[0096] Determine the destination address or media access control address of the network data packet, and determine the network card used to receive the network data packet and the network card used to forward the network data packet;
[0097] The network card used to receive network data packets is used as the receiving network card, and the network card used to forward network data packets is used as the target network card.
[0098] Specifically, in order to achieve efficient forwarding of network data packets, the system needs to determine the destination address or media access control address (MAC address) of the network card when it receives the network data packet, so as to determine the receiving network card and the target forwarding network card of the data packet. Specifically, when the interrupt function of any network card receives the network data packet, a series of steps are performed to determine the transmission path of the data packet to ensure that the data packet can be forwarded correctly.
[0099] Furthermore, when any network card (such as network card A) receives a network data packet through a physical link, the interrupt processing mechanism of the network card is triggered first. At this time, the interrupt function of the network card will be called, and the received data packet will be stored in the buffer area (such as RingBuffer) in the memory through DMA. This operation is to ensure that the data packet can be stored in time when the interrupt function is triggered and avoid data loss.
[0100] Further, the receiving function is called to parse the packet header. After the network packet is successfully stored in the buffer area, the receiving function net_device of the network card is called, and the system starts to parse the header information of the network packet. Specifically, the receiving function parses the packet layer by layer according to predetermined rules (such as protocol format) and extracts key information in the packet, including the destination IP address and the media access control address (MAC address).
[0101] Furthermore, after the receiving function parses the destination address or MAC address of the network data packet, the system will judge the address. The purpose of the judgment is to determine whether the data packet needs to be processed on the current device or whether it needs to be forwarded through another network card. For example:
[0102] If the destination address of the network data packet matches the current network card A, the system will hand the data packet over to the upper layer protocol of the current network card for processing.
[0103] If the destination address of the network data packet does not belong to the current network card A, but is associated with another network card (such as network card B), the system will determine that the data packet needs to be forwarded through network card B.
[0104] Furthermore, based on the above judgment, the system will respectively determine the network card that receives the network data packet and the target network card for forwarding the data packet. For example:
[0105] Receiving network card: a network card used to receive data packets, that is, the network card that initially captures the network data packets through the interrupt function. In this embodiment, it is network card A.
[0106] Target network card: the network card used to forward the data packet. In this embodiment, if the destination address of the data packet indicates that it needs to be forwarded through network card B, the system will determine network card B as the target network card.
[0107] Subsequent operations: Once the receiving network card and the target network card are determined, the system will find the target network card through the pointer in the private data structure of the receiving network card, and call the network data packet sending function of the target network card to send the network data packet through the target network card. This operation skips the multi-layer processing of the Linux kernel's network protocol stack and directly completes the forwarding at the data link layer, significantly reducing the transmission delay of the data packet.
[0108] Through the method of the above embodiment, after the network data packet is received by the network card, its destination address or MAC address can be quickly parsed and determined to determine whether the data packet needs to be forwarded to another network card for processing. This greatly improves the efficiency of data packet transmission, especially for high-frequency and large-data volume network transmission scenarios.
[0109] In some embodiments, judging a destination address or a media access control address of a network data packet and determining a network card for receiving the network data packet and a network card for forwarding the network data packet includes:
[0110] When it is determined that the destination address or the media access control address of the network data packet does not match the current receiving network card, it is determined that the network data packet is forwarded through the corresponding network card of the current receiving network card, the corresponding network card of the current receiving network card is used as the target network card, and the network data packet is passed to the target network card so that the target network card calls the network data packet sending function to perform a forwarding operation on the network data packet.
[0111] Specifically, when the network card receives a network data packet, the system needs to determine whether the data packet should be processed or forwarded by the current network card based on the destination address or media access control address (MAC address) of the network data packet. If the address of the current receiving network card does not match the destination address of the network data packet, the system will perform a forwarding operation and determine the target network card for forwarding.
[0112] First, when any network card (such as network card A) receives a network data packet through its interrupt processing function, it first stores the data packet in the buffer area in the memory (such as RingBuffer), and then calls the receiving function net_device of network card A to parse the header information of the data packet and extract the destination IP address or MAC address of the data packet.
[0113] Furthermore, the destination address or MAC address is determined. After parsing the destination address or MAC address of the network data packet, the receiving function will compare the address with the address of the current receiving network card (network card A). The system will make a judgment based on this:
[0114] Matching situation: If the destination address or MAC address matches the address of the current receiving network card A, the system determines that the data packet should be processed by network card A and handed over to the upper layer protocol stack for processing.
[0115] Mismatch situation: If the destination address or MAC address does not match the address of network card A, the system determines that the data packet should not be processed by network card A and needs to be forwarded through the corresponding network card of network card A (that is, network card B).
[0116] Furthermore, the target network card is determined and the forwarding operation is performed. When it is determined that the network data packet needs to be forwarded through another network card (network card B), the system uses the corresponding network card (network card B) of network card A as the target network card. The receiving network card A finds the device information net_device dev_b of network card B through the network device structure pointer net_device*p_dev_b in its private data structure, and passes the network data packet to the sending function tx_func_b of network card B.
[0117] Network card B calls its sending function tx_func_b, encapsulates the received network data packet, and transmits it to the final destination device or network node through the physical layer.
[0118] Furthermore, the forwarding operation is performed: after NIC A hands the data packet to NIC B, NIC B calls its sending function to pass the data packet out based on the known network device information and data packet structure. This process bypasses the multi-layer parsing and encapsulation of the kernel network protocol stack and directly completes the data packet forwarding at the data link layer, greatly reducing the transmission delay and improving the forwarding efficiency.
[0119] Through the above-mentioned method of this implementation, the network card system in this application can efficiently process network data packets with unmatched addresses and determine the correct target network card for forwarding. This mechanism is particularly suitable for scenarios that require frequent and large-scale data packet transmission, avoiding the additional delay caused by protocol stack processing, thereby improving the overall network communication performance.
[0120] In some embodiments, the network device structure pointer in the private data structure of the receiving network card is used to search for the network device structure of the target network card, and the network data packet sending function of the target network card is called to send the network data packet through the target network card, including:
[0121] Using the network device structure pointer of the receiving network card to search for the network device structure of the corresponding target network card;
[0122] According to the network device structure of the target network card, the network data packet sending function of the target network card is called, and the pointer of the network data packet structure and the network device structure pointer of the target network card are used as parameters of the network data packet sending function;
[0123] The target network card transmits the network data packet to the external network or target device through the physical link according to the received network data packet structure and device information to complete the sending of the network data packet.
[0124] Specifically, in order to improve the forwarding efficiency of network data packets, the system uses the network device structure pointer in the private data structure of the receiving network card to quickly find the device information of the target network card, and calls the network data packet sending function of the target network card to realize direct forwarding of data packets without processing through the kernel protocol stack.
[0125] The following takes the application scenario of two network cards as an example and combines the accompanying drawings to explain in detail the process of bypassing the kernel to transmit network data packets provided by the embodiment of the present application.
[0126] Figure 8 Schematic diagram of the process of forwarding network data packets between network card A and network card B provided in the embodiment of the present application. Figure 8 As shown, for example, in one example, when the receiving network card (such as network card A) determines that a network data packet needs to be forwarded through another network card (such as network card B), the network device structure net_device dev_b of the target network card (network card B) is first searched through the network device structure pointer net_device*p_dev_b in the private data structure of network card A. This step enables network card A to directly obtain the device information of network card B, skipping the multi-level parsing process in the protocol stack.
[0127] Call the target network card's network packet sending function. After finding the device structure dev_b of the B network card, the A network card will call the B network card's network packet sending function tx_func_b to pass the data packet to the B network card for sending. To this end, the A network card passes the following two key parameters to the sending function:
[0128] Parameter 1, network data packet structure pointer sk_buff: used to contain the content of the network data packet to be forwarded.
[0129] Parameter 2, the network device structure pointer dev_b of the target network card: contains the device information of the target network card, which is used to indicate which device the data packet needs to be sent through.
[0130] Furthermore, after receiving the data packet and device information, NIC B processes the data packet through its network data packet sending function tx_func_b, and transmits the network data packet to the external network or target device through a physical link. For example, NIC B will send the data packet to the final receiving device or the next network node through physical media such as Ethernet and optical fiber. This process does not go through the Linux kernel's network protocol stack, which significantly reduces the processing delay of the data packet.
[0131] For example, in another example, when NIC B is the receiving NIC and determines that the data packet needs to be forwarded through NIC A, NIC B searches for the device structure dev_a of NIC A through net_device*p_dev_a in its private data structure and calls the network data packet sending function tx_func_a of NIC A. NIC B passes the network data packet structure sk_buff and the device structure dev_a of NIC A as parameters to NIC A, thereby realizing the reverse transmission of the data packet.
[0132] Through the above mechanism, network cards can exchange data packets directly without relying on complex network protocol stacks. This design that bypasses the protocol stack greatly reduces the number of times data packets are transmitted in the operating system, reduces CPU usage, and improves transmission efficiency. Especially in high-frequency and large-data volume scenarios, this solution effectively reduces communication latency and reduces the risk of packet loss and data corruption caused by excessive processing of data packets in the kernel layer.
[0133] This embodiment illustrates how to achieve direct data transmission between network cards through the pointer mechanism in the private data structure. In this way, the system not only improves the forwarding efficiency of network data packets, but also effectively optimizes the transmission process of the entire data link layer, ensuring a significant improvement in network performance.
[0134] According to the technical solution provided in the embodiments of the present application, the technical solution of the present application has at least the following advantages:
[0135] By adding a direct communication channel between local network cards in the data link layer of the seven-layer network model, the forwarding efficiency of network data packets is effectively improved. Specifically, this technical solution introduces a new mechanism in the Linux network card driver, which enables different network cards to establish a communication channel through the net_device pointer in their respective network device structures, thereby achieving efficient forwarding of network data packets.
[0136] By directly calling the target network card's network packet sending function at the network card driver layer for forwarding, the data packet does not need to enter the multi-layer processing of the Linux kernel protocol stack, which greatly reduces the data packet transmission path and processing time, thereby significantly reducing communication latency.
[0137] When receiving a data packet, the system can quickly determine whether the data packet needs to be forwarded to another network card by judging the destination IP address or MAC address. The target network card is directly found through the net_device pointer, and its sending function is called to achieve efficient forwarding of data packets, reducing the occupation of system resources, especially in high-load, large-data transmission scenarios, and improving overall communication efficiency.
[0138] The technical solution of the present application realizes direct communication at the data link layer by bypassing the Linux kernel protocol stack, simplifies the traditional multi-layer network protocol processing flow, thereby effectively reducing the occupancy of CPU and memory resources and optimizing system performance.
[0139] Therefore, in summary, the technical solution of the present application creates a direct communication channel between local network cards at the network card driver layer, so that network data packets can be forwarded efficiently and quickly between different network cards, significantly improving the efficiency of data transmission. It is particularly suitable for application scenarios that require frequent forwarding of data packets, and effectively improves system performance and user experience.
[0140] The following is an embodiment of the device of the present application, which can be used to execute the embodiment of the method of the present application. For details not disclosed in the embodiment of the device of the present application, please refer to the embodiment of the method of the present application.
[0141] Fig. 9 Schematic diagram of the structure of the network data packet forwarding device based on the network card driver provided in the embodiment of the present application. Fig. 9 As shown, the network data packet forwarding device based on the network card driver includes:
[0142] An adding module 901 is configured to add a network device structure pointer and a network data packet sending function pointer to a private data structure corresponding to a network device of each network card;
[0143] Establishing module 902, configured to establish a mapping relationship between a network device structure pointer of each network card and a network device structure of the corresponding network card during the initialization process of the network card driver, and establish a mapping relationship between a network data packet sending function pointer of each network card and a network data packet sending function of the corresponding network card;
[0144] The judgment module 903 is configured to judge the destination address or media access control address of the network data packet after the interrupt function of any network card receives the network data packet, and determine the receiving network card and the target network card according to the judgment result;
[0145] The sending module 904 is configured to use the network device structure pointer in the private data structure of the receiving network card to find the network device structure of the target network card, and call the network data packet sending function of the target network card to send the network data packet through the target network card.
[0146] In some embodiments, Fig. 9 The creation module 905 creates and initializes a private data structure for the network device structure of each network card in the initialization function of the network card driver before adding a network device structure pointer and a network data packet sending function pointer to the private data structure corresponding to the network device of each network card, wherein the private data structure is used to represent the device information storage space corresponding to each network card.
[0147] In some embodiments, Fig. 9 The adding module 901 adds a pointer to the network device structure of another network card and a pointer to the network data packet sending function of another network card in the private data structure corresponding to the network device of each network card, wherein the network device structure pointer is used to describe the device information of the target network card, and the network data packet sending function pointer is used to drive the target network card to perform a data packet sending operation.
[0148] In some embodiments, Fig. 9 The establishment module 902 assigns a value to the network device structure pointer of each network card based on a preset first pointer mapping relationship, so that the network device structure pointer of each network card points to the network device structure of the corresponding network card; assigns a value to the network data packet sending function pointer of each network card based on a preset second pointer mapping relationship, so that the network data packet sending function pointer of each network card points to the network data packet sending function of the corresponding network card; wherein, based on the assigned network device structure pointer and network data packet sending function pointer, any network card can access the device information of the corresponding network card through the network device structure pointer, and call the network data packet sending function of the corresponding network card to forward the network data packet.
[0149] In some embodiments, Fig. 9 The judgment module 903, when the interrupt function of any network card receives a network data packet, uses the interrupt function to store the network data packet into a cache area in the memory; calls the receiving function of the network card, and parses the header information of the network data packet according to a predetermined rule to obtain the destination address or media access control address of the network data packet; judges the destination address or media access control address of the network data packet to determine the network card used to receive the network data packet and the network card used to forward the network data packet; uses the network card used to receive the network data packet as the receiving network card, and uses the network card used to forward the network data packet as the target network card.
[0150] In some embodiments, Fig. 9 When determining that the destination address or the media access control address of the network data packet does not match the current receiving network card, the determination module 903 determines that the network data packet is forwarded through the corresponding network card of the current receiving network card, takes the corresponding network card of the current receiving network card as the target network card, and passes the network data packet to the target network card so that the target network card calls the network data packet sending function to perform a forwarding operation on the network data packet.
[0151] In some embodiments, Fig. 9 The sending module 904 uses the network device structure pointer of the receiving network card to search for the corresponding network device structure of the target network card; according to the network device structure of the target network card, the network data packet sending function of the target network card is called, and the pointer of the network data packet structure and the network device structure pointer of the target network card are used as parameters of the network data packet sending function; the target network card is used to transmit the network data packet to the external network or the target device through the physical link according to the received network data packet structure and device information, so as to complete the sending of the network data packet.
[0152] It should be understood that the size of the serial numbers of the steps in the above embodiments does not mean the order of execution. 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.
[0153] Fig.10 1 is a schematic diagram of the structure of the electronic device 10 provided in the embodiment of the present application. Fig.10 As shown, the electronic device 10 of this embodiment includes: a processor 1001, a memory 1002, and a computer program 1003 stored in the memory 1002 and executable on the processor 1001. When the processor 1001 executes the computer program 1003, the steps in the above-mentioned method embodiments are implemented. Alternatively, when the processor 1001 executes the computer program 1003, the functions of the modules / units in the above-mentioned device embodiments are implemented.
[0154] Exemplarily, the computer program 1003 may be divided into one or more modules / units, which are stored in the memory 1002 and executed by the processor 1001 to complete the present application. The one or more modules / units may be a series of computer program instruction segments capable of completing specific functions, which are used to describe the execution process of the computer program 1003 in the electronic device 10.
[0155] The electronic device 10 may be a desktop computer, a notebook, a PDA, a cloud server, or other electronic device. The electronic device 10 may include, but is not limited to, a processor 1001 and a memory 1002. Those skilled in the art will appreciate that Fig.10It is only an example of the electronic device 10 and does not constitute a limitation of the electronic device 10. It may include more or fewer components than shown in the figure, or a combination of certain components, or different components. For example, the electronic device may also include input and output devices, network access devices, buses, etc.
[0156] The processor 1001 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, discrete gate or transistor logic devices, discrete hardware components, etc. A general-purpose processor may be a microprocessor or the processor may be any conventional processor, etc.
[0157] The memory 1002 may be an internal storage unit of the electronic device 10, for example, a hard disk or memory of the electronic device 10. The memory 1002 may also be an external storage device of the electronic device 10, for example, a plug-in hard disk, a smart memory card (Smart Media Card, SMC), a secure digital (Secure Digital, SD) card, a flash card (FlashCard), etc. equipped on the electronic device 10. Further, the memory 1002 may also include both an internal storage unit of the electronic device 10 and an external storage device. The memory 1002 is used to store computer programs and other programs and data required by the electronic device. The memory 1002 may also be used to temporarily store data that has been output or is to be output.
[0158] The technicians in the relevant field can clearly understand that for the convenience and simplicity of description, only the division of the above-mentioned functional units and modules is used as an example for illustration. In practical applications, the above-mentioned function allocation can be completed by different functional units and modules as needed, that is, the internal structure of the device can be divided into different functional units or modules to complete all or part of the functions described above. The functional units and modules in the embodiment can be integrated in a processing unit, or each unit can exist physically separately, or two or more units can be integrated in one unit. The above-mentioned integrated unit can be implemented in the form of hardware or in the form of software functional units. In addition, the specific names of the functional units and modules are only for the convenience of distinguishing each other, and are not used to limit the scope of protection of this application. The specific working process of the units and modules in the above-mentioned system can refer to the corresponding process in the aforementioned method embodiment, which will not be repeated here.
[0159] In the above embodiments, the description of each embodiment has its own emphasis. For parts that are not described or recorded in detail in a certain embodiment, reference can be made to the relevant descriptions of other embodiments.
[0160] Those of ordinary skill in the art will appreciate that the units and algorithm steps of each example described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, or a combination of computer software and electronic hardware. Whether these functions are performed in hardware or software depends on the specific application and design constraints of the technical solution. Professional and technical personnel can use different methods to implement the described functions for each specific application, but such implementation should not be considered to be beyond the scope of this application.
[0161] In the embodiments provided in the present application, it should be understood that the disclosed devices / computer equipment and methods can be implemented in other ways. For example, the device / computer equipment embodiments described above are only schematic. For example, the division of modules or units is only a logical function division. There may be other division methods in actual implementation. Multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be through some interfaces, indirect coupling or communication connection of devices or units, which can be electrical, mechanical or other forms.
[0162] The units described as separate components may or may not be physically separated, and the components shown as units may or may not be physical units, that is, they may be located in one place or distributed on multiple network units. Some or all of the units may be selected according to actual needs to achieve the purpose of the solution of this embodiment.
[0163] In addition, each functional unit in each embodiment of the present application may be integrated into one processing unit, or each unit may exist physically separately, or two or more units may be integrated into one unit. The above-mentioned integrated unit may be implemented in the form of hardware or in the form of software functional units.
[0164] If the integrated module / unit is implemented in the form of a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the present application implements all or part of the processes in the above-mentioned embodiment method, and can also be completed by instructing the relevant hardware through a computer program. The computer program can be stored in a computer-readable storage medium, and the computer program can implement the steps of the above-mentioned various method embodiments when executed by the processor. The computer program may include computer program code, which may be in source code form, object code form, executable file or some intermediate form. Computer-readable media may include: any entity or device capable of carrying computer program code, recording medium, U disk, mobile hard disk, disk, optical disk, computer memory, read-only memory (ROM), random access memory (RAM), electric carrier signal, telecommunication signal and software distribution medium, etc.
[0165] The above embodiments are only used to illustrate the technical solutions of the present application, rather than to limit them. Although the present application has been described in detail with reference to the aforementioned embodiments, those skilled in the art should understand that they can still modify the technical solutions described in the aforementioned embodiments, or make equivalent replacements for some of the technical features therein. These modifications or replacements do not deviate the essence of the corresponding technical solutions from the spirit and scope of the technical solutions of the embodiments of the present application, and should all be included in the protection scope of the present application.
Claims
1. A network data packet forwarding method based on a network card driver, characterized in that: include: In the private data structure corresponding to the network device of each network card, add the network device structure pointer and the network data packet sending function pointer; During the initialization process of the network card driver, a mapping relationship between the network device structure pointer of each network card and the network device structure of the corresponding network card is established, and a mapping relationship between the network data packet sending function pointer of each network card and the network data packet sending function of the corresponding network card is established; When the interrupt function of any network card receives a network data packet, the destination address or media access control address of the network data packet is judged, and the receiving network card and the target network card are determined according to the judgment result; The network device structure pointer in the private data structure of the receiving network card is used to search for the network device structure of the target network card, and the network data packet sending function of the target network card is called to send the network data packet through the target network card.
2. The method according to claim 1, characterized in that: Before adding the network device structure pointer and the network data packet sending function pointer to the private data structure corresponding to the network device of each network card, the method further includes: In the initialization function of the network card driver, a private data structure is created and initialized for the network device structure of each network card, wherein the private data structure is used to represent the device information storage space corresponding to each network card.
3. The method according to claim 1, characterized in that The method of adding a network device structure pointer and a network data packet sending function pointer to a private data structure corresponding to the network device of each network card includes: In the private data structure corresponding to the network device of each network card, a pointer to the network device structure of another network card and a pointer to the network data packet sending function of another network card are added, wherein the network device structure pointer is used to describe the device information of the target network card, and the network data packet sending function pointer is used to drive the target network card to perform a data packet sending operation.
4. The method according to claim 1, characterized in that: The step of establishing a mapping relationship between a network device structure pointer of each network card and a network device structure of the corresponding network card, and establishing a mapping relationship between a network data packet sending function pointer of each network card and a network data packet sending function of the corresponding network card, includes: Based on a preset first pointer mapping relationship, assigning a value to a network device structure pointer of each network card, so that the network device structure pointer of each network card points to the network device structure of the corresponding network card; Based on the preset second pointer mapping relationship, assigning a value to the network data packet sending function pointer of each network card, so that the network data packet sending function pointer of each network card points to the network data packet sending function of the corresponding network card; Among them, based on the assigned network device structure pointer and network data packet sending function pointer, any of the network cards can access the device information of the corresponding network card through the network device structure pointer, and call the network data packet sending function of the corresponding network card to forward the network data packet.
5. The method according to claim 1, characterized in that When the interrupt function of any network card receives a network data packet, the destination address or the media access control address of the network data packet is judged, including: When an interrupt function of any of the network cards receives a network data packet, the network data packet is stored in a buffer area in the memory using the interrupt function; Calling the receiving function of the network card, and parsing the header information of the network data packet according to a predetermined rule to obtain the destination address or media access control address of the network data packet; Determine the destination address or media access control address of the network data packet, and determine the network card used to receive the network data packet and the network card used to forward the network data packet; The network card used for receiving the network data packet is used as the receiving network card, and the network card used for forwarding the network data packet is used as the target network card.
6. The method according to claim 5, characterized in that The step of judging the destination address or the media access control address of the network data packet and determining the network card for receiving the network data packet and the network card for forwarding the network data packet includes: When it is determined that the destination address or the media access control address of the network data packet does not match the current receiving network card, it is determined that the network data packet is forwarded through the corresponding network card of the current receiving network card, the corresponding network card of the current receiving network card is used as the target network card, and the network data packet is passed to the target network card so that the target network card calls the network data packet sending function to perform a forwarding operation on the network data packet.
7. The method according to claim 1, characterized in that The method of using the network device structure pointer in the private data structure of the receiving network card to search for the network device structure of the target network card, and calling the network data packet sending function of the target network card to send the network data packet through the target network card includes: Using the network device structure pointer of the receiving network card to search for the network device structure of the corresponding target network card; According to the network device structure of the target network card, a network data packet sending function of the target network card is called, and a pointer to the network data packet structure and a pointer to the network device structure of the target network card are used as parameters of the network data packet sending function; The target network card transmits the network data packet to an external network or a target device through a physical link according to the received network data packet structure and device information, so as to complete the sending of the network data packet.
8. A network data packet forwarding device based on a network card driver, characterized in that: include: An adding module is configured to add a network device structure pointer and a network data packet sending function pointer to a private data structure corresponding to a network device of each network card; An establishment module is configured to establish a mapping relationship between a network device structure pointer of each network card and a network device structure of the corresponding network card during the initialization process of the network card driver, and to establish a mapping relationship between a network data packet sending function pointer of each network card and a network data packet sending function of the corresponding network card; A judgment module is configured to judge the destination address or media access control address of the network data packet after the interrupt function of any network card receives the network data packet, and determine the receiving network card and the target network card according to the judgment result; The sending module is configured to use the network device structure pointer in the private data structure of the receiving network card to search for the network device structure of the target network card, and call the network data packet sending function of the target network card to send the network data packet through the target network card.
9. An electronic device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, characterized in that: When the processor executes the computer program, the steps of the method according to any one of claims 1 to 7 are implemented.
10. A readable storage medium storing a computer program, characterized in that: When the computer program is executed by a processor, the steps of the method according to any one of claims 1 to 7 are implemented.
Citation Information
Cited By
Packet capture method and device, storage medium and program product
CN119697075A
Computing equipment starting method and device, equipment and storage medium
CN121433757A