XDP-based high-performance flow collector
By combining the user mode management module and the kernel EBPF module in the traffic collector, dynamically compiling and mounting the EBPF program to XDP solves the contradiction between the performance and versatility of existing tools and achieves high performance, versatility and precision. Configured traffic sampling is suitable for large traffic scenarios and reduces system load.
Patent Information
- Application Number
- CN202410854160.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-06-28
- Publication Date
- 2024-10-29
- Estimated Expiration
- 2044-06-28
AI Technical Summary
Existing traffic sampling tools struggle to achieve both performance and versatility. Tools based on libpcap have serious performance bottlenecks in large traffic scenarios, resulting in high system load and packet loss. While tools based on DPDK have high performance, they have poor versatility and are difficult to use. Complex, requiring specialized network cards and development skills.
Using a high-performance traffic collector based on XDP, combined with the user-mode management module and the kernel EBPF module, dynamically compile the tcpdump capture filter statement to generate an EBPF program, mount it to the XDP program, and send data packets directly through the ring buffer. Avoid the kernel protocol stack and support fine configuration and high-performance sampling.
It implements high-performance traffic sampling and supports tcpdump capture and filtering syntax without additional learning costs. It is suitable for large traffic scenarios and has strong compatibility. It can dynamically adjust the sampling rate and ratio without the need for dedicated network card support, providing more refined traffic filtering and matching. .
Smart Images

Figure CN118869261A_ABST
Abstract
Description
Technical Field
[0001] The invention belongs to the field of network technology and security, and in particular relates to a high-performance flow collector based on XDP. Background Art
[0002] With the popularization and development of Internet applications, network traffic has grown rapidly, and network security issues have become increasingly prominent. Sampling and analyzing traffic transmitted in the network can timely detect and respond to security incidents such as network attacks, intrusions, malicious code, etc., reduce potential risks, and protect the integrity, availability, and confidentiality of the network.
[0003] Currently, there are two mainstream traffic packet sampling tools:
[0004] (1) Sampling tools based on libpcap, such as tcpdump: simple syntax, powerful functions, support for a wide range of filters, strong versatility and applicable to all Linux distributions, but relatively weak performance and not suitable for high-traffic scenarios.
[0005] (2) Sampling tools based on DPDK: high performance and low latency, bypassing the kernel protocol stack to achieve very high throughput, but very complex to use, high deployment and learning costs, poor versatility, requiring a specific Intel network card to work, and cannot coexist with the kernel firewall module and are prone to conflict.
[0006] The existing sampling technology cannot achieve both performance and versatility. The biggest problem when using the libpcap-based sampling method is the performance bottleneck. Long-term continuous sampling is very likely to interfere with normal business, and the sampling rate and maximum sampling rate cannot be directly set. Sampling in large traffic scenarios will directly increase the system load and cause packet loss. Using DPDK to collect traffic can achieve high performance and low latency, but the biggest problem is that it has poor versatility and requires adaptation to a special Intel network card, a high learning threshold, and special development and debugging skills are required for detailed configuration, and the maintenance cost is high. Summary of the invention
[0007] In view of the above deficiencies in the prior art, the purpose of the invention is to provide a high-performance traffic collector based on XDP, which can provide a capture and filtering syntax consistent with tcpdump and a general traffic sampler solution with DPDK high performance, thereby solving the problem that the above-mentioned performance and versatility cannot be achieved at the same time.
[0008] The present invention proposes a high-performance flow collector based on XDP, comprising: a user state management module and a kernel EBPF module, wherein:
[0009] The user state management module is located in the user space, and a sampling management program is deployed on the user state management module. The sampling management program is used to dynamically compile the input tcpdump capture filter statement and generate an EBPF program, and then send the EBPF program to the kernel EBPF module;
[0010] The kernel EBPF module is located in the kernel space, and a high-performance data path XDP program is deployed on the kernel EBPF module. The kernel EBPF module is used to receive the EBPF program from the user state management module and mount the EBPF program on the XDP program. The XDP program sends the data packet directly to the sampling management program through a ring buffer without passing through the kernel protocol stack.
[0011] Furthermore, after the sampling management program is started, it loads and parses the configuration file, compiles the filter field of the configuration file into EBPF bytecode, inserts it into the pre-developed EBPF template, and compiles it into an obj file together, and then loads the compiled obj file to the network card driver XDP mount point, writes the ratio and max_rate in the configuration file into the EBPF-MAP data structure, and the XDP program reads the EBPF-MAP data structure to perform sampling according to the ratio and maximum rate. The sampling management program obtains the sampled data from the ring buffer ringbuffer for subsequent analysis.
[0012] Furthermore, the configuration file includes:
[0013] nic file: used to describe the network card to be sampled;
[0014] Ratio file: used to describe the sampling ratio;
[0015] max_rate file: used to describe the maximum sampling rate;
[0016] Filter file: used to describe the data packets of interest.
[0017] Furthermore, the sampling management program loads the compiled obj file to the network card XDP mount point specified by the nic field of the configuration file.
[0018] Furthermore, compiling the filter field of the configuration file into EBPF bytecode and inserting it into the pre-developed EBPF template includes:
[0019] When compiling the tcpdump filter statement of the filter field into EBPF instructions, it is first compiled into CBPF instructions, then the CBPF instructions are converted into EBPF programs, and the compiled EBPF programs are loaded into the kernel.
[0020] Furthermore, the EBPF template was developed, including: the EBPF template program is responsible for filtering data packets according to the configured ratio and max_rate, and then jumps to the EBPF program compiled by the filter through the bpf_tail_call instruction. If a hit occurs, the ring buffer is used to manage the process sending data.
[0021] Furthermore, after obtaining the sampled data from the ring buffer ringbuffer for analysis, the sampling management program performs security analysis or serialization files on the collected data packets in real time.
[0022] Furthermore, the user state management module is further configured with a business program, wherein after the data packet enters the protocol stack, sk_buff data is allocated for maintaining the socket buffer state and description information, which is sent to the business program by the protocol stack through the socket.
[0023] Furthermore, the XDP-based high-performance traffic collector is deployed on the load balancer at the traffic inlet to collect all traffic arriving at the load balancer, including all data packets constructed by the scanner.
[0024] Furthermore, the XDP-based high-performance traffic collector is deployed on each server to collect the traffic reaching each server.
[0025] The beneficial effects of the present invention are as follows:
[0026] The high-performance flow collector based on XDP proposed in the present invention has the following beneficial effects:
[0027] 1. High performance: The performance far exceeds tcpdump and is more suitable for sampling in large traffic scenarios. The main reason for high performance is that the XDP program can be called in the network card driver without going through the kernel protocol stack, and the sampled data has a shorter path in the kernel.
[0028] 2. High versatility: Fully supports the capture filter syntax of tcpdump, without additional learning cost. The capture filter syntax is exactly the same as tcpdump, and no additional learning cost is required like DPDK. The main reason for supporting tcpdump filter syntax is that the parsed CBPF program can be easily converted to an EBPF program.
[0029] 3. Fine configuration: Set the sampling ratio and maximum sampling rate through the configuration file, mainly with the help of the EBPF program to obtain the configuration from the user state through EBPF-MAP. The existing tcpdump only supports full collection of traffic passing through the filter.
[0030] 4. Strong compatibility: No need to adapt to a dedicated Intel network card like DPDK, XDP is natively supported since Linux 4.8.
[0031] 5. Strong controllability: XDP's EBPF program can achieve more refined matching when filtering traffic. BRIEF DESCRIPTION OF THE DRAWINGS
[0032] The accompanying drawings are only used to illustrate specific embodiments and are not considered to limit the present invention. In the entire drawings, the same reference symbols represent the same components. Obviously, the drawings described below are only some embodiments recorded in the embodiments of the present invention. For those of ordinary skill in the art, other drawings can also be obtained based on these drawings.
[0033] Figure 1 This is a structural diagram of a high-performance flow collector based on XDP according to an embodiment of the present invention;
[0034] Figure 2 This is a diagram of the XDP traffic capture architecture of an embodiment of the present invention;
[0035] Figure 3 A sampling management program processing flow chart of an embodiment of the present invention;
[0036] Figure 4 A flowchart of the sampling management program deployment according to an embodiment of the present invention. DETAILED DESCRIPTION
[0037] In order to enable those skilled in the art to better understand the technical solutions in the embodiments of the present invention, the technical solutions of the present invention will be clearly and completely described below in conjunction with the accompanying drawings. Obviously, the described embodiments are part of the embodiments of the present invention, rather than all of the embodiments. It should be understood that these descriptions are only exemplary and are not intended to limit the scope of the present invention. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in the field without making creative work should fall within the scope of protection of the present invention.
[0038] Furthermore, in the following description, descriptions of well-known structures and technologies are omitted to avoid unnecessarily obscuring the concepts disclosed in the present invention.
[0039] In the description of the present invention, it should be noted that, unless otherwise clearly specified and limited, the orientation or position relationship indicated by the terms "center", "upper", "lower", "left", "right", "vertical", "horizontal", "inside", "outside", etc. is based on the orientation or position relationship shown in the drawings, which is only for the convenience of describing the present invention and simplifying the description, and does not indicate or imply that the device or element referred to must have a specific orientation, be constructed and operated in a specific orientation, and therefore cannot be understood as a limitation of the present invention. In addition, the terms "first", "second", and "third" are only used for descriptive purposes and cannot be understood as indicating or implying relative importance. The terms "installed", "connected", and "connected" should be understood in a broad sense, for example, it can be a fixed connection, a detachable connection, or an integral connection; it can be a mechanical connection or an electrical connection; it can be a direct connection, or it can be indirectly connected through an intermediate medium, or it can be a connection between the two elements. For those of ordinary skill in the art, the specific meanings of the above terms in the present invention can be understood according to specific circumstances.
[0040] Exemplary embodiments will be described in detail herein, examples of which are shown in the accompanying drawings. When the following description refers to the drawings, unless otherwise indicated, the same numbers in different drawings represent the same or similar elements. The embodiments described in the following exemplary embodiments do not represent all embodiments consistent with the present invention. Instead, they are merely examples of methods and systems consistent with some aspects of the present invention as detailed in the appended claims.
[0041] The technical terms involved in the present invention are explained below:
[0042] CBPF (Classic Berkeley Packet Filter) is a simple and effective packet filtering language and execution engine based on an instruction set.
[0043] EBPF (Extended Berkeley Packet Filter): It is a powerful virtual machine technology in the Linux kernel. It provides a set of secure runtime constraints and verification mechanisms to ensure system stability while extending kernel functions.
[0044] XDP (eXpress Data Path): A high-performance packet processing technology. It is a subsystem in the Linux kernel that is used to perform raw packet processing on the hardware interface of network devices.
[0045] Libpcap (Packet Capture Library): a library for network packet capture and analysis;
[0046] DPDK (Data Plane Development Kit): An open source software development tool set for building high-performance data plane applications.
[0047] EBPF-MAP (extended Berkeley Packet Filter) Map is a data structure used to store and share data in eBPF programs. It is similar to a dictionary or hash table in a conventional programming language, which can associate key-value pairs so that they can be read and modified in different parts of the eBPF program.
[0048] The present invention proposes a high-performance traffic collector based on XDP, which provides a universal traffic sampler solution with capture and filtering syntax consistent with tcpdump and DPDK high performance, solving the problem that the above-mentioned performance and versatility cannot be achieved at the same time.
[0049] like Figure 1 As shown, the high-performance traffic collector based on XDP according to an embodiment of the present invention includes: a user state management module 100 and a kernel EBPF module 200 .
[0050] like Figure 2 As shown, the user state management module 100 is located in the user space, and a sampling management program is deployed on the user state management module 100. The kernel EBPF module 200 is located in the kernel space, and a high-performance data path XDP program is deployed on the kernel EBPF module 200. Among them, the XDP program can send the data packet of interest directly to the sampling management program through the ring buffer without passing through the kernel protocol stack, so it can provide very excellent performance. At the same time, since Linux 4.8 and above versions all support XDP, the present invention is more versatile than DPDK.
[0051] Specifically, the sampling management program is used to dynamically compile the input tcpdump capture filter statement and generate an EBPF program, and then send the EBPF program to the kernel EBPF module.
[0052] like Figure 3 As shown, first, the sampling management program is started and the parsing configuration file is loaded.
[0053] In an embodiment of the present invention, the configuration file includes:
[0054] nic file: used to describe the network card to be sampled;
[0055] Ratio file: used to describe the sampling ratio;
[0056] max_rate file: used to describe the maximum sampling rate;
[0057] Filter file: used to describe the data packets of interest.
[0058] The present invention adopts a syntax completely consistent with that of tcpdump, so the use of the present invention is basically completely consistent with that of tcpdump and is easy to use.
[0059] Then, the sampling manager compiles the filter field of the configuration file into EBPF bytecode and inserts it into the pre-developed EBPF template and compiles it into an obj file together. The compiled obj file is then loaded into the network card driver XDP mount point, and the ratio and max_rate in the configuration file are written into the EBPF-MAP data structure.
[0060] The kernel EBPF module receives the EBPF program from the user-mode management module and mounts the EBPF program onto the XDP program. The XDP program sends the data packet directly to the sampling management program through the ring buffer without passing through the kernel protocol stack.
[0061] Specifically, the XDP program reads the EBPF-MAP data structure to sample according to the ratio and maximum rate, and the sampling management program obtains the sampled data from the ring buffer for subsequent analysis.
[0062] In an embodiment of the present invention, the sampling management program loads the compiled obj file to the network card XDP mount point specified by the nic field of the configuration file.
[0063] In an embodiment of the present invention, compiling the filter field of the configuration file into EBPF bytecode and inserting it into a pre-developed EBPF template includes:
[0064] When compiling the tcpdump filter statement of the filter field into EBPF instructions, it is first compiled into CBPF instructions, and then the CBPF instructions are converted into EBPF programs, and the compiled EBPF programs are loaded into the kernel.
[0065] In an embodiment of the present invention, an EBPF template is developed, including: the EBPF template program is responsible for filtering data packets according to the configured ratio and max_rate, and then jumps to the EBPF program compiled by the filter through the bpf_tail_call instruction, and if a hit occurs, the ring buffer is used to manage the process to send data. Here, it means that when the received data packet hits the tcpdump syntax filter configured by the user, the EBPF program sends the data packet from the kernel to the user-mode management program through the ring buffer.
[0066] After obtaining the sampled data from the ring buffer, the sampling management program performs security analysis or serializes the collected data packets in real time.
[0067] In addition, reference Figure 2 In the Linux kernel, a data packet is described using the data structure sk_buff. The user-mode management module is further configured with a service program. The skb_buff is allocated as soon as the data packet enters the protocol stack, and then the skb_buff is used for processing throughout the protocol stack path. The skb_buff is used to maintain the socket buffer status and description information. The payload of the sk_buff is eventually sent to the service program by the protocol stack through the socket.
[0068] refer to Figure 2 The data packet first enters the XDP program to perform its work, and then enters the protocol stack. When entering the protocol stack, skb_buff will be allocated, and this skb_buff will be used for processing in the entire protocol stack path.
[0069] like Figure 4 As shown, the XDP-based high-performance traffic collector provided by the present invention can be deployed on the load balancer at the traffic entrance or on each server.
[0070] (1) The XDP-based high-performance traffic collector provided by the present invention is deployed on the load balancer at the traffic inlet to collect all traffic arriving at the load balancer, including all data packets constructed by the scanner.
[0071] (2) The high-performance XDP-based traffic collector provided by the present invention is deployed on each server to collect the traffic reaching each server.
[0072] The high-performance flow collector based on XDP proposed in the present invention can provide a universal flow sampler solution with capture and filter syntax consistent with tcpdump and high performance of DPDK, solving the problem that the above performance and versatility cannot be achieved at the same time. The present invention is mainly composed of a user state management program and a kernel EBPF program. The user state management program dynamically compiles the input tcpdump capture filter statement and generates an EBPF program, and then mounts the EBPF program to XDP. Since the XDP program can be executed by the network card driver and does not pass through the kernel protocol stack, it has the performance of DPDK. In addition, the EBPF program can provide more sophisticated configuration than tcpdump, such as dynamically adjusting the sampling rate and sampling rate.
[0073] The high-performance flow collector based on XDP proposed in the present invention has the following beneficial effects:
[0074] 1. High performance: The performance far exceeds tcpdump and is more suitable for sampling in large traffic scenarios. The main reason for high performance is that the XDP program can be called in the network card driver without going through the kernel protocol stack, and the sampled data has a shorter path in the kernel.
[0075] 2. High versatility: Fully supports the capture filter syntax of tcpdump, without additional learning cost. The capture filter syntax is exactly the same as tcpdump, and no additional learning cost is required like DPDK. The main reason for supporting tcpdump filter syntax is that the parsed CBPF program can be easily converted to an EBPF program.
[0076] 3. Fine configuration: Set the sampling ratio and maximum sampling rate through the configuration file, mainly with the help of the EBPF program to obtain the configuration from the user state through EBPF-MAP. The existing tcpdump only supports full collection of traffic passing through the filter.
[0077] 4. Strong compatibility: No need to adapt to a dedicated Intel network card like DPDK, XDP is natively supported since Linux 4.8.
[0078] 5. Strong controllability: XDP's EBPF program can achieve more refined matching when filtering traffic.
[0079] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the embodiments of the present invention, rather than to limit them. Although the present invention has been described in detail with reference to the above embodiments, those skilled in the art should understand that they can still modify the technical solutions recorded in the above embodiments, or replace some of the technical features therein by equivalents; and these modifications or replacements do not make the essence of the corresponding technical solutions deviate from the spirit and scope of the technical solutions of the embodiments of the present invention. Any changes or replacements that can be easily thought of by those skilled in the art within the technical scope disclosed in the present invention should be covered within the protection scope of the present invention.
Claims
1. A high-performance traffic collector based on XDP, It is characterized in that include: User state management module and kernel EBPF module, among which, The user state management module is located in the user space, and a sampling management program is deployed on the user state management module. The sampling management program is used to dynamically compile the input tcpdump capture filter statement and generate an EBPF program, and then send the EBPF program to the kernel EBPF module; The kernel EBPF module is located in the kernel space, and a high-performance data path XDP program is deployed on the kernel EBPF module. The kernel EBPF module is used to receive the EBPF program from the user state management module and mount the EBPF program on the XDP program. The XDP program sends the data packet directly to the sampling management program through a ring buffer without passing through the kernel protocol stack.
2. A high-performance flow collector based on XDP according to claim 1, It is characterized in that After the sampling management program is started, it loads and parses the configuration file, compiles the filter field of the configuration file into EBPF bytecode, inserts it into the pre-developed EBPF template, and compiles it into an obj file together, then loads the compiled obj file to the network card driver XDP mount point, writes the ratio and max_rate in the configuration file into the EBPF-MAP data structure, and the XDP program reads the EBPF-MAP data structure to perform sampling according to the ratio and maximum rate. The sampling management program obtains the sampled data from the ring buffer ringbuffer for subsequent analysis.
3. A high-performance flow collector based on XDP according to claim 2, It is characterized in that The configuration file includes: nic file: used to describe the network card to be sampled; Ratio file: used to describe the sampling ratio; max_rate file: used to describe the maximum sampling rate; Filter file: used to describe the data packets of interest.
4. A high-performance flow collector based on XDP according to claim 2, It is characterized in that The sampling management program loads the compiled obj file to the network card XDP mount point specified by the nic field of the configuration file.
5. A high-performance flow collector based on XDP according to claim 2, It is characterized in that The filter field of the configuration file is compiled into EBPF bytecode and inserted into the pre-developed EBPF template, including: When compiling the tcpdump filter statement of the filter field into EBPF instructions, it is first compiled into CBPF instructions, and then the CBPF instructions are converted into EBPF programs, and the compiled EBPF programs are loaded into the kernel.
6. A high-performance flow collector based on XDP according to claim 2 or 5, It is characterized in that The EBPF template has been developed, including: the EBPF template program is responsible for filtering packets according to the configured ratio and max_rate, and then jumps to the EBPF program compiled by the filter through the bpf_tail_call instruction. If a hit occurs, the ring buffer ringbuffer is used to manage the process to send data.
7. The high-performance flow collector based on XDP according to claim 2, It is characterized in that After obtaining the sampled data from the ring buffer ringbuffer for analysis, the sampling management program performs security analysis or serialization files on the collected data packets in real time.
8. The high-performance flow collector based on XDP according to claim 1, It is characterized in that The user state management module is further configured with a business program, wherein after the data packet enters the protocol stack, sk_buff data is allocated for maintaining the socket buffer state and description information, and the payload of sk_buff is finally sent to the business program by the protocol stack through the socket.
9. The high-performance flow collector based on XDP according to claim 1, It is characterized in that The XDP-based high-performance traffic collector is deployed on the load balancer at the traffic inlet to collect all traffic arriving at the load balancer, including all data packets constructed by the scanner.
10. The high-performance flow collector based on XDP according to claim 1, It is characterized in that The XDP-based high-performance traffic collector is deployed on each server to collect the traffic reaching each server.
Citation Information
Patent Citations
Flow collection method and device based on eBPF
CN114006839A
Database firewall implementation method and system based on XDP technology
CN115277042A
EBPF-based network high-speed forwarding relay method and system
CN116886422A
Data packet filtering method and apparatus, and electronic device and computer-readable storage medium
WO2022267815A1
Cited By
Intelligent deep packet inspection system and method based on eBPF
CN122496322A
