A method for extracting original network messages based on a new kernel driver module
By adding a network packet probe module and customized device driver to the Linux kernel, the problem of being unable to correspond to physical network adapters in a high-speed network environment is solved, and the capture and analysis of original network packets on a multi-adapter platform are realized and expanded. expands the scope of applications and provides low-cost solutions.
Patent Information
- Application Number
- CN202211556523.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-12-06
- Publication Date
- 2024-09-20
- Estimated Expiration
- 2042-12-06
AI Technical Summary
In a high-speed network environment, the traditional Linux operating system cannot map original network messages to specific physical network adapters in the user mode process, which limits the analysis and application of original network messages, especially in multi-physical network adapter hardware. on the platform.
By adding a network packet probe module and a customized network device driver to the Linux kernel, the user-mode process can obtain the original network packets and their corresponding physical network adapter information, and use the kernel-mode network subsystem and device driver to perform Message capture and processing, providing ioctl and read methods to obtain and configure the message capture function.
It achieves accurate capture and analysis of network original messages on a multi-physical network adapter hardware platform, expands the application scope of network original messages, and provides a low-cost solution for deep network customization, testing and fault analysis.
Smart Images

Figure CN115941531B
Abstract
Description
Technical Field
[0001] The invention belongs to the technical field of Linux operating system kernel, and in particular to a network original message extraction method based on a newly added Linux kernel driver module. Background Art
[0002] Packet capture technology is a technology that monitors and intercepts packets on the network, and can copy the packets intact to the system at the packet capture end. As the front end of network analysis, packet capture technology is widely used in firewalls, intrusion detection systems, and host routers. Traditional packet capture can be implemented by calling the packet capture function library. For example, intrusion detection programs and sniffers all capture packets through the packet function capture library. However, due to the limitations of the operating system protocol stack's multiple memory copies and the underlying interrupt response and some redundant data processing inherent in the general operating system in a high-speed network environment, the function library has low packet capture efficiency and a high packet loss rate. Therefore, it is not suitable for packet capture tasks in a high-speed network environment, and is only suitable for single machines or networks below 100 megabits. In order to meet the needs of gigabit or even higher-speed networks, a dedicated packet capture mechanism is generally used. This dedicated packet capture mechanism has not only made improvements in software, but also made targeted designs and modifications to its packet capture hardware. In terms of software, zero-copy technology is generally used to transform memory management for redundant memory copies in the general operating system protocol stack, and interrupt management is improved to address the problem of too many network card packet reception interrupts. The hardware uses a specific processing chip architecture packet capture network card and a customized operating system kernel to maximize its specialization and improve packet capture performance. The network original message acquisition method provided by the Linux operating system's own mechanism cannot map the network original message to a physical network adapter in the user-mode process when there are multiple physical network adapters on the hardware platform, which limits the further analysis and application of the network original message. Summary of the invention
[0003] The purpose of the present invention is to provide a network original message extraction method based on a newly added kernel driver module in order to solve the problems existing in the prior art.
[0004] The technical solution to achieve the purpose of the present invention is: a network original message extraction method based on a newly added kernel driver module, which is implemented based on the Linux operating system environment and involves a state monitoring and configuration process in the user state, a message capture process, and a network message probe module in the kernel state, a kernel network subsystem, a character device driver, a PCI network card device driver, and a platform network card device driver;
[0005] The PCI network card device driver or the platform network card device driver obtains the original network message from the Ethernet, and sends the original network message to the kernel network subsystem after processing; the kernel network subsystem mounts the original network message processing transaction to the work queue and waits for subsequent processing until the following process is executed: first, the message capture enable flag is judged. If the flag is set to zero, the message capture operation is not performed. If the flag is set to one, the external function ③ is called to perform the message capture operation; the external function ③ copies a copy of the original network message from the skb structure, and together with the device number, it forms a structure variable, which is stored in the circular buffer of the network message probe module, and a semaphore is given, and then the memory occupied by the skb structure is released; when the network original message and the device number are stored in the circular buffer to form a structure variable, the message capture process can obtain the structure variable from the circular buffer of the network message probe module, and the source of the original network message can be matched to a specific network adapter by the device number, and the network original message capture process ends.
[0006] Furthermore, the network message probe module is built based on the character driver model of the Linux kernel to implement the ioctl method and the read method; the ioctl method provides two functions: obtaining the network adapter device number and turning on or off the network original message capture; the read method obtains the structure variable composed of the network original message and the device number from the circular buffer and sends it to the message capture process.
[0007] Furthermore, the circular buffer uses an overwrite write method to utilize the old storage space, and synchronizes the writing of the structure variable initiated by the external function ③ and the reading of the structure variable initiated by the read method through a semaphore; the external function ③ will give a semaphore after writing the structure variable; the read method first obtains the semaphore and then reads data from the circular buffer. If the external function ③ does not give a semaphore, the read method will be blocked until the external function ③ gives a semaphore.
[0008] Furthermore, the status monitoring and configuration process sends a network card enumeration command to the network message probe module through the ioctl method provided by the network message probe module, and the network message probe module obtains the device numbers of all network adapters detected in the current hardware system from the PCI network card device driver or the platform network card device driver through the external function ①.
[0009] Furthermore, the PCI network card device driver enumerates the network adapter in the following manner:
[0010] The PCI network card device driver first registers the PCI platform device driver, then enumerates the PCI devices in the system, identifies the network adapter device and records its device number.
[0011] Furthermore, the platform network card device driver enumerates the network adapter in the following manner:
[0012] The platform network card device driver first registers the platform device driver, then enumerates the platform devices in the system, identifies the network adapter device therein and records its device number.
[0013] Furthermore, the status monitoring and configuration process sends function configuration commands to the network message probe module through the ioctl method provided by the network message probe module, and the network message probe module transmits the configuration command to the kernel network subsystem through the external function ② to realize the opening or closing operation of the message capture function.
[0014] Furthermore, the message capture process obtains message data from the circular buffer register in the network message probe module through the read method provided by the network message probe module.
[0015] Furthermore, the network message probe module injects an external function ② into the kernel network subsystem, and the kernel network subsystem stores the network message together with the network adapter device number into the circular buffer register in the network message probe module through the external function ②.
[0016] Compared with the prior art, the present invention has the following significant advantages:
[0017] 1) The present invention provides a new message capture method for user-mode processes by adding a new network message probe module to the Linux kernel and customizing the Linux kernel network subsystem and network device driver. The method provides information about the physical network adapter that receives the original network message on the basis of obtaining the original network message, thereby expanding the application scope of the original network message.
[0018] 2) The advantage of the present invention is that the user state process uniquely determines the physical network adapter corresponding to the original network message based on the device number. The structure data received in the user state contains both the original network message and the device number. The corresponding physical network adapter is found by the device number, and then the source of the original network message is determined, providing more information for network communication behavior analysis.
[0019] 3) The present invention expands the function of capturing network original messages and provides the information of the physical network adapter that receives the network original messages. Based on this technology, the network original message data forwarding function based on the physical network adapter device number can be realized on a multi-physical network adapter hardware platform running the Linux operating system, further expanding the system function and providing a low-cost technical solution for deep network customization, network testing, network fault analysis, etc.
[0020] The present invention is further described in detail below in conjunction with the accompanying drawings. BRIEF DESCRIPTION OF THE DRAWINGS
[0021] Figure 1 This is a schematic diagram of the technical implementation of the present invention. DETAILED DESCRIPTION
[0022] In order to make the purpose, technical solution and advantages of the present application more clearly understood, the present application is further described in detail below in conjunction with the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are only used to explain the present application and are not used to limit the present application.
[0023] Combination Figure 1 , the present invention proposes a network original message extraction method based on a newly added kernel driver module, the method is implemented based on the Linux operating system environment, and involves a state monitoring and configuration process in the user state, a message capture process, and a network message probe module in the kernel state, a kernel network subsystem, a character device driver, a PCI network card device driver, and a platform network card device driver;
[0024] The PCI network card device driver or platform network card device driver obtains the original network message from the Ethernet through the NAPI method, and sends the original network message to the kernel network subsystem after processing; the kernel network subsystem mounts the original network message processing transaction to the work queue and waits for subsequent processing until the following process is executed: first, the message capture enable flag is judged. If the flag is set to zero, the message capture operation is not performed. If the flag is set to one, the external function ③ is called to perform the message capture operation; the external function ③ copies a copy of the original network message from the skb structure , and together with the device number, form a structure variable, which is stored in the circular buffer of the network message probe module, and a semaphore is given, and then the memory occupied by the skb structure is released; when the network original message and the device number are stored in the circular buffer to form a structure variable, the message capture process can obtain the structure variable from the circular buffer of the network message probe module. Since the structure variable carries the device number, the source of the network original message can be matched to a specific network adapter by the device number, and the network original message capture process ends here.
[0025] Furthermore, in one of the embodiments, the network message probe module is constructed based on the character driver model of the Linux kernel, and implements the ioctl method and the read method; the ioctl method provides two functions of obtaining the network adapter device number and turning on or off the network original message capture; the read method obtains the structure variable composed of the network original message and the device number from the circular buffer, and sends it to the message capture process through the copy_to_user method.
[0026] Furthermore, in one of the embodiments, the circular buffer uses an overwrite write method to utilize the old storage space, and synchronizes the writing of the structure variable initiated by the external function ③ and the reading of the structure variable initiated by the read method through a semaphore; the external function ③ will give a semaphore after writing the structure variable; the read method first obtains the semaphore and then reads data from the circular buffer. If the external function ③ does not give a semaphore, the read method will be blocked until the external function ③ gives a semaphore.
[0027] Furthermore, in one of the embodiments, the status monitoring and configuration process sends a network card enumeration command to the network message probe module through the ioctl() method provided by the network message probe module, and the network message probe module obtains the device numbers of all network adapters detected in the current hardware system from the PCI network card device driver or the platform network card device driver through the external function ①.
[0028] The PCI network card device driver enumerates the network adapter in the following steps:
[0029] The PCI network card device driver first registers the PCI platform device driver, then calls the probe method to enumerate the PCI devices in the system, identifies the network adapter device and records its device number.
[0030] The platform network card device driver enumerates the network adapter in the following steps:
[0031] The platform network card device driver first registers the platform device driver, then calls the probe method to enumerate the platform devices in the system, identifies the network adapter device and records its device number.
[0032] Furthermore, in one of the embodiments, the status monitoring and configuration process sends function configuration commands to the network message probe module through the ioctl() method provided by the network message probe module, and the network message probe module passes the configuration command to the kernel network subsystem through the external function ② to implement the message capture function on or off operation.
[0033] Furthermore, in one of the embodiments, the message capture process obtains message data from a circular buffer register in the network message probe module through a read() method provided by the network message probe module.
[0034] Furthermore, in one of the embodiments, the network message probe module injects an external function ② into the kernel network subsystem, and the kernel network subsystem stores the network message together with the network adapter device number into a circular buffer register in the network message probe module through the external function ②.
[0035] In summary, the present invention expands the function of capturing network original messages and provides information about the physical network adapter that receives network original messages. Based on this technology, the network original message data forwarding function based on the physical network adapter device number can be realized on a multi-physical network adapter hardware platform running the Linux operating system, further expanding the system function and providing a low-cost technical solution for deep network customization, network testing, network fault analysis, etc.
[0036] The above shows and describes the basic principles, main features and advantages of the present invention. Those skilled in the art should understand that the present invention is not limited by the above embodiments, and the above embodiments and descriptions are only for explaining the principles of the present invention. Without departing from the spirit and scope of the present invention, any modification, equivalent replacement, improvement, etc. made within the spirit and principle of the present invention should be included in the protection scope of the present invention.
Claims
1. A network original message extraction method based on a newly added kernel driver module, characterized in that: The method is implemented based on the Linux operating system environment, involving the state monitoring and configuration process in the user state, the message capture process, and the network message probe module, the kernel network subsystem, the PCI network card device driver, the character device driver and the platform network card device driver in the kernel state; The PCI network card device driver or platform network card device driver obtains the original network message from the Ethernet, and sends the original network message to the kernel network subsystem after processing; The kernel network subsystem mounts the original network message processing transaction to the work queue and waits for subsequent processing until the following process is executed: first, the message capture enable flag is judged. If the flag is set to zero, the message capture operation is not performed. If the flag is set to one, the external function ③ is called to perform the message capture operation; External function ③ copies a copy of the original network message from the skb structure, and together with the device number, forms a structure variable, stores it in the circular buffer of the network message probe module, gives a semaphore, and then releases the memory occupied by the skb structure; when the circular buffer is filled with the structure variable composed of the original network message and the device number, the message capture process can obtain the structure variable from the circular buffer of the network message probe module, and the source of the original network message can be mapped to a specific network adapter by the device number, and the original network message capture process ends here.
2. The network original message extraction method based on the newly added kernel driver module according to claim 1 is characterized in that: The network message probe module is built based on the character driver model of the Linux kernel and implements the ioctl method and the read method; the ioctl method provides two functions: obtaining the network adapter device number and turning on or off the network original message capture; the read method obtains the structure variable composed of the network original message and the device number from the circular buffer and sends it to the message capture process.
3. The network original message extraction method based on the newly added kernel driver module according to claim 2 is characterized in that: The circular buffer uses an overwrite write method to utilize the old storage space, and synchronizes the write structure variable initiated by the external function ③ and the read structure variable initiated by the read method through a semaphore; the external function ③ will give a semaphore after writing the structure variable; the read method first obtains the semaphore and then reads data from the circular buffer. If the external function ③ does not give a semaphore, the read method will be blocked until the external function ③ gives a semaphore.
4. The network original message extraction method based on the newly added kernel driver module according to claim 2 is characterized in that: The status monitoring and configuration process sends a network card enumeration command to the network message probe module through the ioctl method provided by the network message probe module. The network message probe module obtains the device numbers of all network adapters detected in the current hardware system from the PCI network card device driver or the platform network card device driver through external function ①.
5. The network original message extraction method based on the newly added kernel driver module according to claim 4 is characterized in that: The PCI network card device driver enumerates the network adapter in the following steps: The PCI network card device driver first registers the PCI platform device driver, then enumerates the PCI devices in the system, identifies the network adapter device and records its device number.
6. The network original message extraction method based on the newly added kernel driver module according to claim 4 is characterized in that: The platform network card device driver enumerates the network adapter in the following steps: The platform network card device driver first registers the platform device driver, then enumerates the platform devices in the system, identifies the network adapter device therein and records its device number.
7. The network original message extraction method based on the newly added kernel driver module according to claim 2 is characterized in that: The status monitoring and configuration process sends function configuration commands to the network message probe module through the ioctl method provided by the network message probe module. The network message probe module transmits the configuration command to the kernel network subsystem through the external function ② to realize the opening or closing operation of the message capture function.
8. The network original message extraction method based on the newly added kernel driver module according to claim 2 is characterized in that: The message capture process obtains message data from the circular buffer register in the network message probe module through the read method provided by the network message probe module.
9. The network original message extraction method based on the newly added kernel driver module according to claim 2 is characterized in that: The network message probe module injects an external function ② into the kernel network subsystem, and the kernel network subsystem stores the network message together with the network adapter device number into the circular buffer register in the network message probe module through the external function ②.
Citation Information
Patent Citations
Method for capturing real-time network data
CN103269284A
Message asynchronous forwarding system based on Linux operating system and method
CN109587082A
Packet processing method and device
WO2017000593A1
Data forwarding method and apparatus based on network bridge of kernel of operating system
WO2018121373A1
