Construction method of universal container network data packet acquisition and forwarding system

Through the combination of kernel mode and user mode eBPF modules, a universal container network packet collection and forwarding system is constructed, which solves the problem of difficult determination of packet capture points under various CNI network models, and achieves rapid and accurate collection and analysis of container networks. It simplifies traffic collection and adaptation and provides unified monitoring of multiple container network planes.

CN118573597APending Publication Date: 2024-08-30EAST CHINA NORMAL UNIV +1
View PDF 0 Cites 3 Cited by

Patent Information

Application Number
CN202410627772.1
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-05-21
Publication Date
2024-08-30

AI Technical Summary

Technical Problem

The existing technology is difficult to determine the correct packet capture point under various CNI network models, resulting in container network monitoring problems. Data packets cannot be collected and analyzed quickly and accurately, and traffic collection and adaptation of multiple container network planes cannot be realized.

Method used

A universal container network packet collection and forwarding system is built using the kernel-mode eBPF traffic capture module, user-mode eBPF program deployment module and container traffic analysis and forwarding module. It is compatible with container runtimes such as Docker and Containerd, and can be used in the kernel mode and user mode through the eBPF program. Transfer data packets between them, and uniformly collect network performance indicators under different CNI network models.

Benefits of technology

It realizes the rapid and accurate collection and analysis of data packets under multiple CNI network models, simplifies traffic collection and adaptation, solves the problem of difficulty in determining packet capture points in specific CNI modes, and provides unified monitoring of multiple container network planes. ability.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118573597A
    Figure CN118573597A
Patent Text Reader

Abstract

The invention discloses a construction method of a universal container network data packet acquisition and forwarding system, which is characterized in that the system comprises: a) a kernel mode eBPF flow capture module: executing a BPF program on a specific kernel hook point, capturing data packet information according to a screening rule and transmitting the data packet information to a user space; b) a user mode eBPF program deployment module: for a single or multiple containers specified by a user, creating eBPF hook points in different network spaces by using a netlink socket mode, and loading an eBPF program; and c) a container flow analysis and forwarding module for analyzing and packaging the container data packet captured and transmitted by the eBPF program, and then storing the data locally or reporting the data. Compared with the prior art, the method has the advantages that data packets can be quickly and accurately acquired, identified and analyzed, traffic acquisition covering multiple container network planes is realized, traffic acquisition adaptation work of the multiple container network planes is simplified, and the problem that packet capture points are difficult to determine or find under the multiple different container network planes is solved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the technical field of container network traffic collection and monitoring, and in particular to a method for constructing a universal container network data packet collection and forwarding system based on eBPF technology. Background Art

[0002] With the widespread application of cloud computing, cloud-native architecture has become a key development trend of enterprise IT architecture. In the traditional software development model, applications often adopt a monolithic architecture and are deployed on specific physical servers or virtual machines. This approach has many limitations in terms of resource utilization, scalability, and maintainability. Relatively speaking, cloud-native applications have shown comprehensive advantages, including universal accessibility, high availability, high scalability, monitorability, security, portability, and the ability to continuously evolve and iterate quickly, which has attracted many manufacturers and enterprises to migrate their services to cloud-native platforms. Cloud-native architecture, through the microservice model and relying on cloud infrastructure, has gotten rid of its dependence on the local environment and met the urgent needs of enterprises to deliver business software quickly, continuously, reliably, and at scale. As the successor of Borg, Kubernetes (hereinafter referred to as K8s) has become the mainstream in the market with its innovative application orchestration and scheduling strategies. At the same time, it makes containerized application deployment very convenient and easy to expand and manage, and the container runtime supported by cross-cloud platforms is becoming more and more standardized.

[0003] As the cornerstone and carrier of cloud-native architecture, containers are lightweight and isolated, making container orchestration possible. With the rapid growth of public cloud container services, more and more companies are vigorously promoting the development of container cloud orchestration. Currently, the K8s project and the CNCF community have established unified standards and leadership in the field of container orchestration. While K8s and Docker have caused tremendous changes in the industry, they have also brought new problems that need to be solved.

[0004] In the cloud-native architecture, the network is the link that connects microservice components. Its performance and security are crucial to the robustness and reliability of the entire system. Faced with the dynamic expansion capabilities required by cloud-native applications, network monitoring must provide key performance indicators and support automated expansion decision-making processes. In addition, as the scale of cloud-native networks expands, it is particularly important to locate and quickly troubleshoot faults through network monitoring. In addition, the complex structure of cloud-native networks makes them face more network security challenges, and effective network monitoring can detect abnormal traffic patterns and help prevent and respond to potential security threats.

[0005] Modern cloud-native network architectures have the characteristics of container network communications being dominated by east-west traffic, extremely large network scale, complex end-to-end paths, dynamic changes in service topology, and frequent changes in IP addresses. These characteristics pose significant challenges to container network monitoring. At the same time, for container network detection, it is necessary not only to achieve full coverage monitoring of the container network, but also to consider the impact of introducing monitoring on user programs. For example, the isolation and lightweight of containers should be ensured as much as possible, and the impact of monitoring on user load and traffic latency should be reduced. In addition, given the diversity and complexity of container network planes, how to unify the monitoring mode in different container network planes is also a difficulty in cloud-native monitoring.

[0006] eBPF (Extend Berkeley Packet Filter) is a highly flexible and powerful technology that allows developers to safely run precompiled and verified programs in the Linux kernel without changing the kernel source code or loading kernel modules. With the help of a just-in-time compiler (JIT), eBPF runs a virtual machine in the kernel to ensure that only verified safe eBPF instructions are executed by the kernel. At the same time, because eBPF instructions still run in the kernel, there is no need to copy data to user mode, which greatly improves the efficiency of event processing.

[0007] The existing technology has the problem of complex data collection in container networks of various CNI network models, especially the monitoring problem of difficulty in determining the correct packet capture point in a specific CNI mode (such as Cilium). It is difficult to determine or find the packet capture point in various different container network planes, and it is impossible to quickly and accurately collect, identify and analyze data packets, and it is impossible to achieve traffic collection adaptation work for various container network planes. Summary of the invention

[0008] The purpose of the present invention is to propose a construction method of a universal container network data packet collection and forwarding system in view of the deficiencies of the prior art. The system adopts a kernel-state eBPF traffic capture module, a user-state eBPF program deployment module and a container traffic analysis and forwarding module to construct a container network data packet collection and forwarding system. The system takes into account two different container runtimes, Docker and Containerd, and covers a variety of CNI network models such as Flannel, Calico, Weave, Cilium, etc. It can unify the network performance indicator collection of the CNI network plane, and can be compatible with different container runtimes such as Docker and Containerd. It solves the problem of complex collection in container networks of various CNI network models, and especially solves the monitoring problem of difficulty in determining the correct packet capture point under a specific CNI mode (such as Cilium). The method is simple, effective, and has good application prospects and commercial value.

[0009] The specific technical scheme for realizing the purpose of the present invention is: a method for constructing a universal container network data packet collection and forwarding system, which is characterized in that the system includes: a kernel state eBPF traffic capture module, a user state eBPF program deployment module and a container traffic analysis and forwarding module, wherein the kernel state eBPF traffic capture module executes the eBPF program in the kernel, obtains data traffic information and filters the traffic according to predefined data packet protocol screening rules and passes it to the user space; the user state eBPF program deployment module: according to the specified container information, uses the netlink socket method to add a program attachment queue under the namespace virtual network card of the relevant container, and attaches the eBPF program to the queue; the container traffic analysis and forwarding module: based on the traffic sent by eBPF to the user state, determines to perform traffic parsing and storage locally or encapsulate the vxlan header and perform UDP forwarding according to the forwarding information specified by the user state interaction module.

[0010] Furthermore, the execution steps of the kernel-state eBPF traffic capture module are as follows: the inbound traffic capture and outbound traffic capture programs are set at the hook points of the Ingress and Egress of the kernel-state Traffic control layer, respectively, and whether the Ethernet protocol or IP protocol is met is judged from the outside to the inside. The data packets that meet the protocol rules are copied and transferred to the corresponding eBPF PerfRingBuffer, and the user-state eBPF program deployment module is waited for to take out the data packets. At the same time, the kernel-state eBPF traffic capture module is compiled into an executable program to provide the user-state eBPF program deployment module for deployment.

[0011] Furthermore, the execution steps of the user-mode eBPF program deployment module are as follows: based on the container name or K8s Pod name given by the user, call the Docker API or Containerd API to dynamically obtain the container running process ID, open the corresponding container process namespace handle, if it is the Docker API, select the first virtual network card device in the current namespace that is not a loopback device, if it is the Containerd API, accurately match the virtual network card device with the same IP by specifying the Pod's IP. Insert the virtual network card device into the Traffic control queue through the netlink socket, and then attach the executable kernel-mode eBPF traffic capture module to the queue to wait for data packets and forward data packets.

[0012] Furthermore, the execution steps of the container traffic analysis and forwarding module are as follows: read the original data packet transmitted from the kernel state from the eBPF PerfRingBuffer. According to the user-specified processing method of the data packet, if local storage is performed, the obtained data packet is parsed and written into the Pcapng file; if forwarding is performed, the vxlan header is encapsulated before the traffic is obtained, and the host machine network protocol stack is used to send it to the remote server through the UDP Socket.

[0013] Compared with the prior art, the present invention is compatible with different container runtimes such as Docker and Containerd, solves the problem of complex data collection in container networks of various CNI network models, and especially solves the monitoring problem of difficulty in determining the correct packet capture point under a specific CNI mode (such as Cilium). It can quickly and accurately collect, identify and analyze data packets, realize traffic collection covering multiple container network planes, and simplify the traffic collection adaptation work for multiple container network planes. BRIEF DESCRIPTION OF THE DRAWINGS

[0014] Figure 1 It is the work flow chart of the present invention; Figure 2 This is a schematic diagram of the structure of a general container network data packet collection and forwarding system; Figure 3 This is a schematic diagram of the workflow of the kernel-mode eBPF traffic capture module; Figure 4 Schematic diagram of the work of deploying modules for user-mode eBPF programs; Figure 5 It is a flow chart of the container traffic analysis and forwarding module of the present invention. DETAILED DESCRIPTION

[0015] The specific implementation methods of the present invention are described in detail below in conjunction with the accompanying drawings. The following invention embodiments will help those skilled in the art to further understand the present invention. It should be noted that, for those of ordinary skill in the art, several changes and improvements can be made without departing from the concept of the present invention, and they still fall within the scope of protection of the present invention. Example

[0016] See also Figure 1 The specific operation steps of the present invention are as follows: Step a: Accept command line information and deploy the eBPF traffic capture program Get container information from the command line, use the Docker / Containerd API to get the container running process to enter the container namespace, search for the appropriate virtual network device and add the traffic control queue, and attach the compiled eBPF traffic capture program to the traffic control queue.

[0017] Step b: Create an eBPF traffic capture program Create an eBPF traffic capture program at the corresponding kernel hook point and use the BPF toolchain to compile the eBPF traffic capture program into executable BPF bytecode.

[0018] Step c: Packet parsing and further processing Parse the data packets passed by the kernel-mode eBPF traffic capture module and save the data packets as Pcapng files or forward them to the backend server according to the user-specified method.

[0019] The present invention supports docking with various other monitoring systems that can process indicator data. The monitoring system can use the traffic forwarded by the forwarding module to analyze business association relationships, identify data packets, perform business access volume statistics, TCP session combing, abnormal traffic detection, monitoring alarms and other applications.

[0020] See also Figure 2 The universal container network data packet collection and forwarding system constructed by the present invention includes: a user-state eBPF program deployment module, a kernel-state eBPF traffic capture module and a container traffic analysis and forwarding module.

[0021] The user-mode eBPF program deployment module receives monitoring container information and traffic operation mode through a command line, selects a specific container in a container cluster through an API, selects a specific network card under a container namespace according to a screening rule, and uses a netlink socket to add a traffic control queue.

[0022] The kernel-mode eBPF traffic capture module searches for available traffic control queues in the kernel-mode and captures the eBPF traffic capture program according to the trafficcontrol queue added by the user-mode eBPF program deployment module. The program automatically copies the packets that meet the packet filtering rules and sends them to the PerfRingBuffer for use by the container traffic analysis and forwarding module.

[0023] The container traffic analysis and forwarding module reads the captured data packets from the PerfRingBuffer in sequence and stores or forwards them according to the user-specified rules. The above three modules run independently of the container network plane. No matter what kind of container network plane, including Docker's own Brige, MACVlan and IPVlan modes and K8s's Flannel, Calico and Cilium modes, as long as the underlying container runtime supports Docker or Containerd API, it can anchor the internal packet capture point of the container, thereby unifying the container network plane and making the outer veth interface transparent, that is, when the veth peer cannot be determined or there is no vethpeer, the packet capture point can still be accurately determined and the packet can be captured.

[0024] The execution steps of the user-mode eBPF program deployment module include: Step a: First, obtain the container-related information specified by the user according to the command line parameters, such as the container name or Pod name, and determine its running process ID through the Docker or Containerd API; Step b: Determine the running namespace according to the process ID and obtain the namespace handle; Step c: Operate the namespace handle and use the netlink socket to join the traffic control queue on the specific virtual network card in the namespace; Step d: Load the compiled BPF bytecode on the traffic control queue; Step e: The eBPF traffic capture program runs to automatically capture data packets; See also Figure 3 , obtain container-related information through command line parameters, such as specifying the Pod type, and promptly access the K8sApi Server to request the latest Pod list on the current node, filter out the Pod list to be captured according to the filtering rules and take out the container ID list; if it is a Docker type container, directly obtain the container ID list through the Docker API. Then, according to different container runtimes (Docker or Containerd), determine the corresponding container network namespace at different network namespace (Namespace, hereinafter referred to as ns) mount points, enter the network namespace through the container process ID, obtain the network card list, determine the virtual network card device according to the filtering rules and add the trafficcontrol queue. Attach the eBPF packet capture program to the Egrees and Ingress packet capture points of the traffic control queue, and start the eBPF packet capture program to collect network data packets.

[0025] The execution steps of the kernel state eBPF traffic capture module include: Step a: Define the data structure to be captured and anchor the packet capture location; Step b: Parse the data packet and check whether it complies with the Ethernet frame and IP protocol. If it does not comply, directly upload the data packet to the upper layer protocol or transfer it to the network card; Step c: Extract key information (such as data length, timestamp, source IP and destination IP) and add it to the packet header; Step d: Send the processed data packet to perfRingBuffer; Step e: Use the BPF toolchain to compile the eBPF program into BPF bytecode for use by the user-mode eBPF program deployment module.

[0026] See also Figure 4 , the kernel-state eBPF traffic capture module first defines the data structure of the traffic to be captured, which is set as the timestamp, program running process ID, captured traffic length, used protocol and source IP and destination IP. And define the anchor position, which is set as the Ingress and Egress hook points of the traffic control layer. Parse each data packet passing through the trafficcontrol queue to determine whether it meets the screening conditions, which is set as whether it meets the Ethernet protocol and IP protocol. If it does not meet the conditions, directly upload or drop the data packet without affecting its original path. If it meets the conditions, copy the traffic and fill the pre-defined data structure, send the data to perfRingBuffer, and wait for the container traffic analysis and forwarding module to read the data. Finally, use the BPF tool chain to compile the eBPF program into BPF bytecode for use by the user-state eBPF program deployment module.

[0027] The execution steps of the container traffic analysis and forwarding module include: Step a: Select to store locally or forward traffic based on user specifications; Step b: Select storage flow: Get the traffic in the eBPF PerfRingBuffer and parse the traffic; 2. Parse the original data packet and its length and put it into the buffer queue; If the buffer queue is full, it will be written to the specified Pcapng file.

[0028] Step c: Select forwarding traffic: Establish a UDP link based on the IP address and port specified by the user; Get the original traffic and encapsulate the vxlan header directly on PerfRingBuffer; Send a data packet.

[0029] See also Figure 5 , the container traffic analysis and forwarding module first reads the data packet information from the PerfRingBuffer, and reads the user-selected traffic processing method from the command line. If you choose to store traffic, the traffic is parsed to obtain the original traffic length, source IP, destination IP, timestamp and other related information, packaged into a tcPacket and put into the buffer queue. When the buffer queue is full, all tcPackets in the buffer queue are written to the specified Pcapng file and the buffer queue is cleared. If you choose to forward traffic, a UDP link is established according to the IP customization and port specified by the user, the original traffic is read from the data packet, and the vxlan header is directly encapsulated in the front end of the original traffic. The traffic to be sent is placed in the object pool, waiting for the UDP link to send the traffic.

[0030] The above embodiments are only for further explanation of the present invention, and are not intended to limit the present invention. Any equivalent implementation of the present invention should be included in the scope of the claims of the present invention.

Claims

1. A method for constructing a universal container network data packet collection and forwarding system, characterized in that: A kernel-state eBPF traffic capture module, a user-state eBPF program deployment module, and a container traffic analysis and forwarding module are used to construct a computer program system for network data packet collection and forwarding. The kernel-state eBPF traffic capture module executes a BPF program in the kernel to obtain data traffic information, filter data packets according to predefined screening rules, and pass them to the user space; the user-state eBPF program deployment module adds a program attachment hook point under the namespace virtual network card of the relevant container by using the netlink socket method according to the specified container information, and attaches eBPF to the hook point; the container traffic analysis and forwarding module determines whether to parse and store the data packet locally or encapsulate the vxlan header and perform UDP forwarding based on the data packet sent to the user state by eBPF according to the forwarding information of the user-state interaction module.

2. The method for constructing a universal container network data packet collection and forwarding system according to claim 1 is characterized in that: The computer program system for collecting and forwarding network data packets specifically operates as follows: Step a: Accept command line information and deploy the eBPF traffic capture program Get container information from the command line, and use the Docker / Containerd API to get the container running process to enter the container namespace, search for the appropriate virtual network device and add the traffic control queue, and attach the compiled eBPF traffic capture program to the traffic control queue; Step b: Create an eBPF traffic capture program Create an eBPF traffic capture program at the corresponding kernel hook point and use the BPF toolchain to compile the eBPF traffic capture program into executable BPF bytecode; Step c: Packet parsing and further processing Parse the data packets passed by the kernel-mode eBPF traffic capture module and save the data packets as Pcapng files or forward them to the backend server according to the user-specified method.

3. The method for constructing a universal container network data packet collection and forwarding system according to claim 1 is characterized in that: The execution steps of the kernel state eBPF traffic capture module include: a) Determine the auxiliary hook function point of the kernel-mode eBPF capture program and the data packet data structure transferred to the user-mode; b) According to the packet filtering rules, the packets that do not meet the filtering rules are directly sent to the upper network stack or the lower network card, and the packets that meet the rules are copied; c) Send the copy data packet to user space.

4. The method for constructing a universal container network data packet collection and forwarding system according to claim 1 is characterized in that: The execution steps of the user-mode eBPF program deployment module include: a) Use the Docker container API or the Containerd container API to determine the process ID of the running process based on the container name or Pod name specified by the user; b) Open the namespace handle for the process in the system according to the running process ID, traverse all virtual network devices under the namespace according to the namespace handle, and determine the eBPF attached virtual network device according to the screening rules; c) Use the netlink socket method to generate a traffic control network queue on a certain virtual network device through the namespace handle; d) Attach the eBPF program to the generated traffic control network queue and start the eBPF program.

5. The method for constructing a universal container network data packet collection and forwarding system according to claim 1 is characterized in that: The execution steps of the container traffic analysis and forwarding module include: a) Read the packets captured by the eBPF program from the eBPF PerfRingBuffer; b) Determine whether to save or operate the data packet; c) Save: copy the data packet to the memory, unpack the data packet, read the header information of the link layer, network layer and transport layer, and write it into the PCAPNG file; d) Forwarding: Directly encapsulate the vxlan header of the data packet read by the eBPF PerfRingBuffer, create a UDP socket according to the IP address and port number specified by the user, put the encapsulated data packet into the object pool and forward it through the UDP socket.

Citation Information

Cited By

  • Knative automatic capacity expansion method and system based on eBPF program

    CN119484546A

  • Flow collection method and device

    CN121000642A

  • Network traffic multi-level security protection model, system, method, equipment and medium

    CN121283684A