Network packet parsing methods, devices and electronic equipment
By using FPGA hardware for packet header parsing, the problem of CPU performance degradation in high-throughput scenarios is solved, achieving efficient and flexible network packet parsing and improving device performance and resource utilization.
Patent Information
- Application Number
- CN202611545208.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2026-09-30
- Publication Date
- 2026-11-17
AI Technical Summary
In high-throughput scenarios, existing network devices suffer from excessive CPU utilization and overall performance degradation due to the need for the CPU to process protocol stack logic packet by packet. This is especially true when dealing with a large number of short packets or parsing multiple protocols, which exacerbates the processing pressure.
FPGA is used for message parsing. By extracting a preset length of data from the message header, the protocol layer is parsed using a configuration module and multiple parsing modules. The parsing path is determined by matching field values with feature items. The parsing continues only when the next protocol layer exists, thus avoiding invalid operations.
It reduces CPU resource consumption, improves device performance, saves hardware resources, and enhances packet parsing efficiency and flexibility, while supporting flexible configuration of multiple protocols.
Smart Images

Figure CN123123490A_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of network communication technology, and in particular to network message parsing methods, apparatus and electronic equipment. Background Technology
[0002] In the field of network communication, network devices need to parse and identify received packets in order to extract key information (such as MAC address, IP address, port number, etc.) from the packet header for use by subsequent business modules such as forwarding decisions, security detection, and traffic management.
[0003] Currently, mainstream network devices typically rely on CPU chips to perform packet parsing and identification. With the continuous increase in network bandwidth and the growing complexity of service types, the CPU needs to process protocol stack logic (including header parsing, checksum calculation, routing decisions, etc.) packet by packet. In high-throughput scenarios, this consumes a large amount of CPU chip resources, leading to excessive CPU utilization and a decline in overall device performance. The processing pressure on the CPU will be further exacerbated, especially when there are a large number of short packets in the network or an increase in the types of packets that need to be parsed. Summary of the Invention
[0004] In view of this, this application provides a method, apparatus, and electronic device for parsing network packets, so as to improve the parsing efficiency of network packets and save hardware resources.
[0005] The technical solution provided in this application is as follows: According to an embodiment of the first aspect of this application, a network packet parsing method is provided, the method being applied to a Field Programmable Gate Array (FPGA), the method comprising: Extract a preset length of data from the header of the current network packet as the data to be parsed. The first protocol layer in the current data to be parsed is taken as the current protocol layer, and the current protocol layer parsing operation is performed. The current protocol layer parsing operation includes: reading the field value at a preset position from the header of the current protocol layer, determining the parsing path of the current protocol layer according to the matching result of the field value and several feature items stored in the configuration module, and parsing the header of the current protocol layer according to the determined parsing path to obtain the current protocol layer information. If it is determined based on the current protocol layer information that there is a next protocol layer that needs to be parsed, then the header of the current protocol layer is removed from the current data to be parsed, and the remaining data after removal is taken as the current data to be parsed. Then, the process returns to the step of taking the first protocol layer in the current data to be parsed as the current protocol layer and performing the parsing operation of the current protocol layer. If it is determined that there is no next protocol layer based on the current protocol layer information, the parsed protocol layer information is output so as to forward the current network packet based on the protocol layer information.
[0006] According to an embodiment of a second aspect of this application, a network packet parsing apparatus is provided, the apparatus comprising: The interception module is used to intercept a preset length of data in the header of the current network packet as the current data to be parsed; The configuration module is used to store several feature items corresponding to each protocol layer; Multiple parsing modules are cascaded sequentially. Each parsing module is used to take the first protocol layer in the current data to be parsed as the current protocol layer and perform a current protocol layer parsing operation. The current protocol layer parsing operation includes: reading a field value at a preset position from the header of the current protocol layer; determining the parsing path of the current protocol layer based on the matching result of the field value and several feature items stored in the configuration module; parsing the header of the current protocol layer according to the determined parsing path to obtain the current protocol layer information; if it is determined from the current protocol layer information that there is a next protocol layer that needs to be parsed, then the header of the current protocol layer is stripped from the current data to be parsed, and the remaining data after stripping is taken as the current data to be parsed, and the process returns to the step of taking the first protocol layer in the current data to be parsed as the current protocol layer and performing the current protocol layer parsing operation; if it is determined from the current protocol layer information that there is no next protocol layer, then the parsed protocol layer information is output so as to forward the current network packet based on the protocol layer information. An external interface is used to receive several feature items corresponding to each protocol layer and store them in the configuration module; The multiple parsing modules process different parsing stages of different network packets within the same clock cycle.
[0007] According to an embodiment of a third aspect of this application, an electronic device is provided, including a field-programmable gate array (FPGA) and a processor; The processor is used to provide configuration information to the FPGA; The FPGA is used to perform the method as described in the first aspect.
[0008] As can be seen from the above technical solutions, this application performs message parsing through FPGA hardware, eliminating the need for the CPU to process protocol stack logic packet by packet, thereby freeing up CPU resources and improving the overall performance of the device. By parsing only the preset length of data in the message header, the amount of data processing at each parsing stage is reduced, saving hardware resources. Furthermore, when parsing each protocol layer, the parsing path is determined based on the matching result of the field value read from the preset position in the header of the current protocol layer and the feature items in the configuration module, allowing for flexible configuration of parsing rules. After parsing, it is determined whether there is a next protocol layer based on the current protocol layer information; only if it exists is stripped and parsing continued, avoiding invalid operations and improving message parsing efficiency. Attached Figure Description
[0009] The accompanying drawings, which are incorporated in and form a part of this specification, illustrate embodiments consistent with this application and, together with the specification, serve to explain the principles of this application.
[0010] Figure 1 A flowchart illustrating the method provided in this application embodiment; Figure 2 This is a schematic diagram of the execution framework provided in the embodiments of this application; Figure 3 This is a schematic diagram of the link layer parsing module parsing process provided in an embodiment of this application; Figure 4 This is a schematic diagram of the network layer parsing module parsing process provided in an embodiment of this application; Figure 5 This is a schematic diagram of the parsing process of the transport layer parsing module provided in an embodiment of this application; Figure 6 This is a structural diagram of the device provided in the embodiments of this application; Figure 7 This is a schematic diagram of the structure of an electronic device provided in an embodiment of this application. Detailed Implementation
[0011] To enable those skilled in the art to better understand the technical solutions provided in the embodiments of this application, and to make the above-mentioned objectives, features and advantages of the embodiments of this application more apparent and understandable, the technical solutions in the embodiments of this application will be further described in detail below with reference to the accompanying drawings.
[0012] The technical solutions of the embodiments of this application will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only a part of the embodiments of this application, and not all of them. All other embodiments obtained by those skilled in the art based on the embodiments of this application without creative effort are within the scope of protection of this application.
[0013] First, the following explanation is provided for some of the terms that may be involved in the embodiments of this application: FPGA: Field Programmable Gate Array, is a type of programmable integrated circuit chip.
[0014] Link Layer: The second layer in the Open Systems Interconnection (OSI) model, responsible for transmitting data frames over physical links. In this embodiment, the information carried in the link layer protocol header includes, but is not limited to, source MAC address, destination MAC address, Ethernet type, VLAN tag, MPLS tag, etc.
[0015] Network Layer: The third layer in the Open Systems Interconnection (OSI) model, responsible for packet routing and forwarding. In this embodiment, the information carried in the network layer protocol header includes, but is not limited to, source IP address, destination IP address, protocol number, and TTL.
[0016] Transport Layer: The fourth layer in the Open Systems Interconnection (OSI) model, responsible for end-to-end data transmission. In this embodiment, the information carried in the transport layer protocol header includes, but is not limited to, source port number, destination port number, and checksum.
[0017] MPLS: Multi-Protocol Label Switching.
[0018] VLAN: Virtual Local Area Network.
[0019] QinQ: A technology that uses two layers of IEEE 802.1Q tags for encapsulation, also known as 802.1Q tunneling technology.
[0020] GRE: Generic Routing Encapsulation.
[0021] IPv6 extension headers: In the IPv6 protocol, extension headers that can follow the basic header include hop-by-hop options header, routing header, fragmentation header, destination options header, etc.
[0022] LUT: Look-Up Table, is a type of storage unit inside an FPGA, with a storage granularity smaller than RAM.
[0023] In network communication equipment, packet parsing is a fundamental step in operations such as forwarding, security, and traffic management. Taking a typical router or switch as an example, when a packet enters the device through an ingress port, the device first needs to identify the destination MAC address in the packet header and then look it up in the Layer 2 forwarding table. If Layer 3 forwarding is required, the destination IP address needs to be read further to look up the routing table. If the device also functions as a firewall, the source IP, destination IP, source port, destination port, and protocol type need to be extracted and matched against preset security policies. All these operations rely on accurate parsing of the packet header.
[0024] Currently, the aforementioned parsing work is typically handled by the CPU chip. The CPU runs protocol stack software, sequentially reading the header fields of each layer of the message and performing operations such as field comparison, checksum calculation, and table lookup matching. This software processing approach offers good flexibility, allowing for software upgrades to support new protocol types. However, the CPU's processing power is limited by its serial execution architecture, facing significant challenges in high-throughput scenarios.
[0025] In view of this, this application provides a network packet parsing method to improve packet parsing efficiency while saving hardware resources.
[0026] Please refer to Figure 1 , Figure 1 A flowchart illustrating the method provided in this application embodiment.
[0027] In this embodiment, the method can be applied to a Field Programmable Gate Array (FPGA).
[0028] like Figure 1 As shown, the method may include the following steps: Step 101: Extract the preset length data from the header of the current network packet as the current data to be parsed.
[0029] In this embodiment of the application, after the FPGA receives a network packet, it does not send the entire packet to the parsing module, but instead extracts data of a preset length from the packet header as the data to be parsed.
[0030] The header information of each protocol layer in a network packet (including the link layer header, network layer header, transport layer header, and various extended headers) is located in the packet header. Extracting the header data allows access to all the crucial information needed for parsing, eliminating the need to process the entire packet. This reduces the data processing workload of the parsing module and saves internal storage and bandwidth resources within the FPGA. In practical applications, this preset length can be configured according to the actual length of the network packet header. For example, the preset length can be 1024 bits.
[0031] In one embodiment, before extracting the preset length data from the header of the current network packet, the input packet can be stored in a cache, and the preset length data from the header of the input packet can be read from the cache as the current data to be parsed. The input packet is then used for forwarding.
[0032] In this way, the message parsing process and the message forwarding process can be carried out in parallel without affecting each other. The parsing process only needs to extract key information from the message header without modifying the content of the original message. Therefore, the original message can be forwarded directly through the forwarding channel without waiting for parsing to complete, thereby reducing forwarding latency.
[0033] Please see Figure 2 , Figure 2 This is a schematic diagram of the execution framework provided for an embodiment of this application.
[0034] like Figure 2As shown, after the input message enters the FPGA, it is sent to the message forwarding channel for subsequent message forwarding; on the other hand, it is sent to the message parsing module for parsing. The message parsing module first extracts the first 1024 bits of the message header, and then sequentially processes the data through the link layer, removes the link layer message header, the network layer, removes the network layer message header, and the transport layer, finally outputting the message parsing information.
[0035] The configuration module receives specific configuration requirements from users through an external interface, customizing the parsing behavior of the message parsing module. Throughout the process, message forwarding and message parsing are independent and parallel, without affecting each other.
[0036] Step 102: Take the first protocol layer in the current data to be parsed as the current protocol layer, and perform the current protocol layer parsing operation. The current protocol layer parsing operation includes: reading the field value at a preset position from the header of the current protocol layer, determining the parsing path of the current protocol layer according to the matching result of the field value and several feature items stored in the configuration module, and parsing the header of the current protocol layer according to the determined parsing path to obtain the current protocol layer information.
[0037] Specifically, the parsing module in the FPGA takes the first protocol layer in the data to be parsed as the current protocol layer. For example, if the data to be parsed starts from the link layer header, the link layer is taken as the current protocol layer.
[0038] The parsing module reads field values from a preset position in the current protocol layer header. This preset position can be a fixed offset, such as the offset position of the Ethernet type in the link layer header. The preset position can also be configured by the user through the configuration module. For example, the user can write a preset position parameter to the configuration module via an external interface. The configuration module stores this parameter in a configuration register or LUT, and the parsing module reads this preset position from the configuration module during parsing.
[0039] The parsing module matches the field values it reads with several feature items stored in the configuration module. These feature items are obtained by disassembling the complete protocol parsing template of the network packet.
[0040] In related schemes, each message type corresponds to a complete protocol parsing template, which is stored in RAM, consuming a large amount of storage resources. This application breaks down the complete protocol parsing template into several small-granularity feature items, which are stored in the configuration module.
[0041] As an example, the configuration module may include multiple lookup tables (LUTs), and several feature items are stored in the LUTs. The storage granularity of the LUTs is smaller than that of RAM, thereby achieving feature matching with a smaller storage space.
[0042] Based on the matching results, the parsing module determines the parsing path for the current protocol layer.
[0043] Specifically, if a field value matches a feature item, the parsing path of the current protocol layer is determined to be a customized parsing path. The customized parsing path includes: extracting fields from the header of the current protocol layer according to the field offset and field length indicated by the configuration module to obtain the information of the current protocol layer.
[0044] In one embodiment, an example of a custom parsing path application scenario is as follows: The user configures a feature item with the source MAC address as AA:BB:CC:DD:EE:FF. When the packet source MAC matches this feature item, the parsing module extracts the specified field according to the user-defined field offset, such as extracting the custom tag field with an offset of 20-23 bytes.
[0045] If the field values do not match the feature items, the parsing path of the current protocol layer is determined to be the standard parsing path. The standard parsing path includes: parsing the header of the current protocol layer according to the protocol format corresponding to the current protocol layer, extracting the protocol fields corresponding to the current protocol layer, and obtaining the information of the current protocol layer.
[0046] It should be noted that, in this embodiment of the application, the protocol layer of the current network packet can be the link layer, or it can be the link layer and the network layer in the order of parsing, or it can be the link layer, the network layer and the transport layer in the order of parsing.
[0047] The number of protocol layers that need to be parsed may vary depending on the type of message. For example, a pure Layer 2 message (such as an ARP message) only needs to be parsed at the link layer, without needing to parse the network and transport layers; while a regular TCP / IP message needs to be parsed at the link layer, network layer, and transport layer in sequence.
[0048] Step 103: If it is determined based on the current protocol layer information that there is a next protocol layer that needs to be parsed, then the header of the current protocol layer is removed from the current data to be parsed, and the remaining data after removal is taken as the current data to be parsed. Then, the process returns to the step of taking the first protocol layer in the current data to be parsed as the current protocol layer and performing the parsing operation of the current protocol layer.
[0049] Specifically, the parsing module determines whether there is a next protocol layer that needs to be parsed based on the current protocol layer information. If so, it removes the header of the current protocol layer from the current data to be parsed, uses the remaining data as the new data to be parsed, and takes the first protocol layer in the new data as the current protocol layer, then returns to step 102. This process is repeated until there is no next protocol layer that needs to be parsed.
[0050] The following sections will provide a detailed explanation of the specific decision-making logic for the link layer and the network layer.
[0051] (1) Link layer judgment logic When the current protocol layer is the link layer, the current protocol layer information includes at least the Ethernet type. The parsing module determines whether there is a network layer that needs to be parsed further based on the Ethernet type.
[0052] Specifically, if the Ethernet type in the current protocol layer information is IPv4 or IPv6, then it is determined that there is a network layer that needs to be further resolved.
[0053] At this point, the parsing module removes the link layer header from the current data to be parsed, uses the remaining data after removal as the new data to be parsed, and uses the network layer as the current protocol layer, then returns to step 102.
[0054] If the Ethernet type is MPLS protocol type, then parse the MPLS label stack and determine whether there is a network layer that needs to be parsed further based on the inner protocol type after the MPLS label stack.
[0055] The MPLS label stack parsing process includes: after parsing each layer of MPLS labels, reading the stack bottom flag in that layer's label; if the stack bottom flag indicates that the current label is the stack bottom label, parsing stops; if the stack bottom flag indicates that the current label is not the stack bottom label, parsing continues to the next layer of MPLS labels, until the stack bottom label is parsed or the specified number of layers is reached. The parsing module also extracts the label information of each layer of labels in the MPLS label stack and uses this label information as part of the current protocol layer information. As an example, the specified number of layers can be three.
[0056] In addition, if the current protocol layer is the link layer, the standard resolution path also includes the processing of VLAN tags. Specifically, if the link layer header contains a VLAN tag, the protocol type field after the VLAN tag is taken as the Ethernet type; if the link layer header contains two layers of VLAN tags (i.e., QinQ encapsulation), the protocol type field after the two layers of VLAN tags is taken as the Ethernet type.
[0057] Please see Figure 3 , Figure 3 This is a schematic diagram of the parsing process of the link layer parsing module provided in an embodiment of this application.
[0058] like Figure 3 As shown, the process specifically includes: Perform Hig header determination. It should be noted that Hig header determination is an exemplary step for identifying messages with Hig encapsulation. For other types of messages, this step can be omitted or replaced with other header identification steps, and this application does not limit this.
[0059] Perform VLAN determination. Specifically, check whether the link layer header contains a VLAN tag (e.g., Ethernet type 0x8100).
[0060] If a VLAN tag is included, the position of the subsequent protocol type field is determined based on the position of the VLAN tag. If the link layer header contains one VLAN tag, the protocol type field after the VLAN tag is taken as the Ethernet type; if it contains two VLAN tags (i.e., QinQ encapsulation), the protocol type field after both VLAN tags is taken as the Ethernet type.
[0061] Furthermore, different branches are entered based on the Ethernet type: If the Ethernet type is 0x8847 (MPLS unicast) or 0x8848 (MPLS multicast), then proceed to the MPLS label resolution branch.
[0062] In the MPLS label parsing branch, each layer of MPLS labels is parsed sequentially: after parsing each layer of MPLS labels, the stack bottom flag S in that layer of labels is read.
[0063] If S=1, it indicates that the current label is the bottom label of the stack, so the parsing stops and the information after the MPLS_1S header is output (i.e., the remaining data after stripping one layer of MPLS labels). If S=0, continue parsing the next layer of MPLS tags and check its S bit again; If S=1 for the second-level label, then output the information after the MPLS_2S header; If S=0 for the second-level tag, then continue parsing the third-level tag; If S=1 for the third-level label, then output the information after the MPLS_3S header; If S=0 for the third-layer label, it indicates that the number of MPLS label layers exceeds the preset maximum number of layers (three layers in this example). In this case, pass-through processing can be performed or the case can be handled as an exception.
[0064] During the parsing of the MPLS label stack, label information (such as label value, traffic category, etc.) of each layer of labels is also extracted and used as part of the current protocol layer information.
[0065] After parsing the MPLS label stack, determine whether there is a network layer that needs to be parsed further based on the type of the inner protocol following the MPLS label stack.
[0066] If the Ethernet type is 0x0800 (IPv4) or 0x86DD (IPv6), it is determined that there is a network layer that needs to be further resolved. At this time, the information after the ethvlan header is output, that is, the remaining data after stripping the link layer header (including the Ethernet header and possible VLAN tags). The remaining data is used as the current data to be resolved, and the network layer is used as the current protocol layer to continue the resolution operation.
[0067] If the Ethernet type is another protocol type, it is determined that there is no network layer that needs to be parsed further. In this case, the parsed protocol layer information is output to forward the current network packets based on the protocol layer information.
[0068] It should be noted that, Figure 3 The features such as Hig header determination, MPLS unicast (0x8847), MPLS multicast (0x8848), MPLS_1S, MPLS_2S, MPLS_3S, and pass-through that appear in the document are specific exemplary descriptions of link layer parsing, and this application does not limit them.
[0069] For example, the maximum number of resolution layers in the MPLS tag stack can be configured according to actual needs, and is not limited to three layers; the number of VLAN tag layers can also be determined according to the actual encapsulation situation.
[0070] (2) Network layer judgment logic When the current protocol layer is the network layer, the current protocol layer information includes at least the protocol number. The parsing module determines whether there are transport layers that need to be parsed further based on the protocol number.
[0071] Specifically, if the protocol number in the current protocol layer information is a TCP protocol number, a UDP protocol number, or an ICMP protocol number, then it is determined that there is a transport layer that needs to be further parsed. At this time, the parsing module removes the network layer header from the current data to be parsed, uses the remaining data after removal as the new current data to be parsed, and uses the transport layer as the current protocol layer, returning to step 102.
[0072] If the protocol number is the tunnel protocol number, then parse the tunnel header, peel off the current protocol layer header and the tunnel header to obtain the inner layer data to be parsed, take the first protocol layer in the inner layer data to be parsed as the current protocol layer, and return to execute step 102.
[0073] The tunnel protocol number can include the GRE protocol number and the IPinIP protocol number, etc. Through the above-mentioned tunnel loop resolution method, this application can support tunnel protocols such as GRE tunnels and IPinIP tunnels, as well as complex scenarios such as tunnel nesting (such as GRE over IPinIP, GRE over GRE, etc.).
[0074] In addition, when the current protocol layer is the network layer, the standard resolution path also includes specific resolution methods for IPv4 and IPv6.
[0075] Specifically, if the network layer header is in IPv4 protocol format, the source IP address, destination IP address, and protocol number are extracted as the current protocol layer information.
[0076] If the network layer header is in IPv6 protocol format, then each extension header is read sequentially after the IPv6 base header. The position of the next header is determined according to the next header field in the current header, until the protocol type indicated by the next header field in the current header is not an extension header type. Then, the source IP address, destination IP address and protocol number are extracted as the current protocol layer information.
[0077] In the IPv6 protocol, the base header may be followed by zero or one extension headers. Each extension header contains a Next Header field, indicating the location of the next extension header or upper-layer protocol header. The parsing module reads the Next Header field of each extension header in a loop, jumping to and parsing each extension header in turn, until it reaches the upper-layer protocol header.
[0078] Please see Figure 4 , Figure 4 This is a schematic diagram of the network layer parsing module parsing process provided in an embodiment of this application. Figure 4 As shown, the parsing process of the network layer parsing module is as follows.
[0079] First, the parsing path is determined. Specifically, the network layer parsing module reads the field values at preset positions from the network layer header and matches these values with several feature items stored in the configuration module. If a match is successful, the parsing path is determined to be a customized parsing path, and the packet information is parsed according to a special packet template. The network layer information and the remaining packets are then directly passed to the next-level parsing module. If a match is unsuccessful, the parsing path is determined to be a standard parsing path, and the subsequent standard parsing process continues.
[0080] After determining the standard resolution path, the resolution module determines whether the current packet is an IPv6 packet.
[0081] If it is an IPv6 packet, the IPv6 extension header information is parsed. Specifically, each extension header is read sequentially after the IPv6 base header. The position of the next header is determined according to the next header field in the current header, until the protocol type indicated by the next header field in the current header is not an extension header type. Then, the IPv6 extension header is stripped, the key IP information is parsed, and the network layer header is stripped to extract the source IP address, destination IP address, and protocol number as the current protocol layer information.
[0082] If it is not an IPv6 packet, then it is further determined whether it is an IPv4 packet; if it is an IPv4 packet, then the key IP information is directly parsed and the network layer header is stripped off, and the source IP address, destination IP address and protocol number are extracted as the current protocol layer information; if it is neither an IPv6 packet nor an IPv4 packet, then the network layer information and the remaining packet are directly passed to the next level parsing module.
[0083] After parsing the key IP information and stripping the network layer header, the parsing module determines the subsequent processing method based on the protocol number.
[0084] Specifically, determine whether it is a GRE message: if it is a GRE message, extract the GRE header information and strip the GRE header, then parse the inner key IP information, then strip the inner IP header and input the remaining message into the next level, and finally pass the network layer information and the remaining message to the next level parsing module.
[0085] If it is not a GRE packet, then it continues to determine if it is an IPinIP packet. If it is, then it parses the inner key IP information, then strips the inner IP header and inputs the remaining packet into the next level, and finally passes the network layer information and the remaining packet to the next level parsing module. If it is neither a GRE packet nor an IPinIP packet, then it determines that the protocol number is another protocol number, there is no transport layer that needs to be parsed, and it directly passes the network layer information and the remaining packet to the next level parsing module.
[0086] It should be noted that after performing inner-layer parsing on GRE or IPinIP packets, it is necessary to determine again whether the inner packet is IPv6 in order to correctly process the extension header of the inner IPv6 packet.
[0087] When the current protocol layer is the transport layer, the parsing module parses the transport layer header according to the transport layer protocol format.
[0088] Please see Figure 5 , Figure 5 This is a schematic diagram of the parsing process of the transport layer parsing module provided in an embodiment of this application.
[0089] like Figure 5 As shown, the parsing process of the transport layer parsing module is as follows: The transport layer parsing module retrieves the transport layer protocol type field (labeled 14_type in the diagram) from the network layer header. This field indicates the protocol type used by the transport layer. In a specific implementation, this field can be the protocol number field in the network layer header.
[0090] Enter different branches based on the value of the protocol number field: If the value of the protocol number field is 8'd6 (i.e., the decimal value 6, corresponding to the TCP protocol number), then the transport layer protocol type is determined to be TCP. Extract the TCP flag bits and port information from the TCP header, including the source port number (sport), destination port number (dport), etc., which correspond to "Tcp flag / port" in the figure.
[0091] If the value of the protocol number field is 8'd17 (i.e., the decimal value 17, corresponding to the UDP protocol number), then the transport layer protocol type is determined to be UDP. The port information and length information in the UDP header are extracted, including the source port number (sport), the destination port number (dport), and the UDP length (udp_len), which corresponds to "Port / udp_len" in the figure.
[0092] If the value of the protocol number field is the ICMP protocol number (i.e., the decimal value 1), then the transport layer protocol type is determined to be ICMP. Extract information such as the type and code from the ICMP header, which corresponds to "Type / code" in the figure.
[0093] If the protocol number field takes a different value, it will be processed according to the RAWIP method. RAWIP means that non-standard protocol messages are processed as raw data, that is, no further protocol parsing is performed, and the remaining data is directly output as the parsing result. This corresponds to "Other - RAWIP" in the diagram.
[0094] Since the transport layer is the last layer, after completing the above parsing, the parsing module determines that there is no next protocol layer that needs to be parsed, and outputs the parsed protocol layer information.
[0095] It should be noted that, Figure 5 The "8'd6" in the text represents the 8-digit decimal value 6, "8'd17" represents the 8-digit decimal value 17, "14_type" represents the transport layer protocol type field, and "RAWIP" represents an exemplary processing method for non-standard protocol messages.
[0096] Step 104: If it is determined that there is no next protocol layer based on the current protocol layer information, then the parsed protocol layer information is output so as to forward the current network packet based on the protocol layer information.
[0097] Specifically, when the parsing module determines that there is no next protocol layer that needs to be parsed, it outputs the information of each parsed protocol layer. This information can be used by subsequent business modules (such as the forwarding engine, security engine, traffic management module, etc.).
[0098] In this embodiment, the parsed protocol layer information is used to forward current network packets. For example, the forwarding engine can look up the forwarding table based on the parsed destination MAC address, destination IP address, and other information to determine the outgoing port of the packet and complete the packet forwarding.
[0099] It should be noted that, in this embodiment, the link layer parsing operation, network layer parsing operation, and transport layer parsing operation are executed separately by multiple parsing modules in the FPGA. These multiple parsing modules are cascaded sequentially, and each module processes different network packets within the same clock cycle. This pipelined parallel processing method significantly improves the throughput of packet parsing.
[0100] Furthermore, in this embodiment of the application, before extracting the preset length data in the header of the current network packet, the input packet can be stored in a cache, and the preset length data in the header of the input packet can be read from the cache as the current data to be parsed. The input packet is then used for forwarding.
[0101] In this way, the message parsing process and the message forwarding process can be carried out in parallel without affecting each other. The parsing process only needs to extract key information from the message header without modifying the content of the original message. Therefore, the original message can be forwarded directly through the forwarding channel without waiting for parsing to complete, thereby reducing forwarding latency.
[0102] It should be noted that, in this embodiment of the application, the several feature items stored in the configuration module are divided according to the protocol layer.
[0103] Specifically, when the current protocol layer is the link layer, the configuration module stores several feature items including one or more of the source MAC address, destination MAC address, Ethernet type, and VLAN identifier; when the current protocol layer is the network layer, the feature items include one or more of the source IP address, destination IP address, and protocol number; when the current protocol layer is the transport layer, the feature items include one or more of the source port number and destination port number.
[0104] In this way, users can flexibly customize the message parsing rules of each protocol layer through the configuration module, and realize customized parsing of private traffic or special messages, further improving the flexibility and scalability of the solution.
[0105] This concludes the discussion on... Figure 1 Description of the method.
[0106] This application performs message parsing via FPGA hardware, eliminating the need for CPU to process protocol stack logic packet by packet, thus freeing up CPU resources and improving overall device performance. By parsing only a preset length of data in the message header, the amount of data processing at each parsing stage is reduced, saving hardware resources. Furthermore, when parsing each protocol layer, the parsing path is determined based on the matching results of field values read from a preset position in the header of the current protocol layer and feature items in the configuration module, allowing for flexible configuration of parsing rules. After parsing, the existence of the next protocol layer is determined based on the current protocol layer information; stripping and further parsing are only performed if the next protocol layer exists, avoiding invalid operations and improving message parsing efficiency.
[0107] The following is based on Figure 2 The proposed solution in this application is described in its entirety.
[0108] Please see Figure 2 , Figure 2 This is a schematic diagram illustrating the execution framework of the network packet parsing method provided in the embodiments of this application.
[0109] like Figure 2 As shown, after the input message enters the FPGA, it is sent to the message forwarding channel for subsequent message forwarding; on the other hand, it is sent to the message parsing module for parsing. The message parsing module first extracts the first 1024 bits of the message header, and then sequentially processes the data through the link layer, removes the link layer message header, the network layer, removes the network layer message header, and the transport layer, finally outputting the message parsing information.
[0110] The configuration module receives specific configuration requirements from users through an external interface, customizing the parsing behavior of the message parsing module. Throughout the process, message forwarding and message parsing are independent and parallel, without affecting each other.
[0111] It should be noted that the link layer parsing operation, network layer parsing operation, and transport layer parsing operation are executed separately by the link layer parsing circuit, network layer parsing circuit, and transport layer parsing circuit in the FPGA. These three parsing circuits are cascaded sequentially inside the FPGA to form a hardware pipeline architecture.
[0112] Within the same clock cycle, the three parsing circuits can handle different parsing stages of different packets. That is, while the first packet is being processed in the network layer parsing circuit, the second packet can be processed simultaneously in the link layer parsing circuit, and the third packet can be processed simultaneously in the transport layer parsing circuit. Through this pipelined parallel processing method, the throughput of packet parsing is significantly improved.
[0113] Furthermore, in this embodiment, the key information at the link layer and the key information at the network layer also include information such as Ethernet type and protocol type used to determine whether further parsing is required.
[0114] If it is determined based on the key information at the link layer that no network layer parsing operation is required, then the key information at the link layer is output directly, and subsequent network layer parsing and transport layer parsing are not performed.
[0115] If it is determined based on the key network layer information that no transport layer parsing operation is required, then the key link layer information and key network layer information are output, and no further transport layer parsing is performed.
[0116] The key information at the link layer here refers to the current protocol layer information corresponding to the link layer, and the key information at the network layer refers to the current protocol layer information corresponding to the network layer.
[0117] In this way, the parsing process can be terminated early for packets that do not require complete Layer 3 parsing (such as pure Layer 2 packets), avoiding invalid data operations and further saving hardware resources.
[0118] Please refer to Figure 6 , Figure 6 This is a structural diagram of the device provided in an embodiment of this application. Figure 6 As shown, the device includes an interception module 601, a configuration module 602, a parsing module 603, and an external interface 604. Specifically, the device includes: The interception module 601 is used to intercept a preset length of data in the header of the current network packet as the current data to be parsed; Configuration module 602 is used to store several feature items corresponding to each protocol layer; Multiple parsing modules 603 are cascaded sequentially. Each parsing module is used to take the first protocol layer in the current data to be parsed as the current protocol layer and perform a current protocol layer parsing operation. The current protocol layer parsing operation includes: reading a field value at a preset position from the header of the current protocol layer; determining the parsing path of the current protocol layer based on the matching result of the field value and several feature items stored in the configuration module; parsing the header of the current protocol layer according to the determined parsing path to obtain the current protocol layer information; if it is determined from the current protocol layer information that there is a next protocol layer that needs to be parsed, then the header of the current protocol layer is stripped from the current data to be parsed, and the remaining data after stripping is taken as the current data to be parsed, and the process returns to the step of taking the first protocol layer in the current data to be parsed as the current protocol layer and performing the current protocol layer parsing operation; if it is determined from the current protocol layer information that there is no next protocol layer, then the parsed protocol layer information is output to forward the current network packet based on the protocol layer information. External interface 604 is used to receive several feature items corresponding to each protocol layer and store them in the configuration module; Among them, the multiple parsing modules process different parsing modules of different network packets within the same clock cycle.
[0119] As an example, when the parsing module 603 determines the parsing path of the current protocol layer based on the matching results of the field values and several feature items stored in the configuration module, it is specifically used for: If the field value matches the feature item, the parsing path of the current protocol layer is determined to be a customized parsing path; the customized parsing path includes: extracting fields from the header of the current protocol layer according to the field offset and field length indicated by the configuration module to obtain the current protocol layer information; If the field value does not match the feature item, the parsing path of the current protocol layer is determined to be the standard parsing path; the standard parsing path includes: parsing the header of the current protocol layer according to the protocol format corresponding to the current protocol layer, extracting the protocol fields corresponding to the current protocol layer, and obtaining the information of the current protocol layer.
[0120] As one example, the protocol layer of the current network packet is the link layer; Alternatively, the protocol layers of the current network message are, in the order of parsing, the link layer and the network layer; Alternatively, the protocol layers of the current network message can be, in the order of parsing, the link layer, the network layer, and the transport layer.
[0121] As an example, when the current protocol layer is the link layer, the current protocol layer information includes at least the Ethernet type. When the parsing module 603 determines, based on the current protocol layer information, that there is a next protocol layer that needs to be parsed, it specifically performs the following: If the Ethernet type in the current protocol layer information is IPv4 or IPv6, then it is determined that there is a network layer that needs to be further parsed. If the Ethernet type is MPLS protocol type, then the MPLS label stack is parsed, and it is determined whether there is a network layer that needs to be parsed further based on the inner protocol type after the MPLS label stack. Parsing the MPLS label stack includes: after parsing each layer of MPLS labels, reading the stack bottom flag in that layer of labels; if the stack bottom flag indicates that the current label is the stack bottom label, then parsing stops; if the stack bottom flag indicates that the current label is not the stack bottom label, then parsing the next layer of MPLS labels continues until the stack bottom label is parsed or the number of parsed layers reaches a specified number; the label information of each layer of labels in the MPLS label stack is extracted, and the label information is used as part of the current protocol layer information. If the Ethernet type is another protocol type, then it is determined that there is no network layer that needs to be further parsed.
[0122] As an example, when the current protocol layer is the link layer, the current protocol layer information includes the Ethernet type, and the standard resolution path includes: If the link layer header contains a VLAN tag, then the protocol type field following the VLAN tag is taken as the Ethernet type; If the link layer header contains two VLAN tags, then the protocol type field following the two VLAN tags is taken as the Ethernet type.
[0123] As an example, when the current protocol layer is the network layer, the current protocol layer information includes at least the protocol number. The parsing module 603, when determining based on the current protocol layer information that there is a next protocol layer that needs to be parsed, specifically performs the following: If the protocol number in the current protocol layer information is a TCP protocol number, a UDP protocol number, or an ICMP protocol number, then it is determined that there is a transport layer that needs to be further parsed. If the protocol number is a tunnel protocol number, then parse the tunnel header, peel off the current protocol layer header and the tunnel header to obtain the inner layer data to be parsed, take the first protocol layer in the inner layer data to be parsed as the current protocol layer, and return to the step of performing the parsing operation of the current protocol layer; If the protocol number is another protocol number, then it is determined that there is no transport layer that needs to be further parsed.
[0124] As an example, when the current protocol layer is the network layer, the standard resolution path includes: If the network layer header is in IPv4 protocol format, then the source IP address, destination IP address, and protocol number are extracted as the current protocol layer information; If the network layer header is in IPv6 protocol format, then each extension header is read sequentially after the IPv6 base header. The position of the next header is determined according to the next header field in the current header, until the protocol type indicated by the next header field in the current header is not an extension header type. Then, the source IP address, destination IP address and protocol number are extracted as the current protocol layer information.
[0125] As an example, several feature items are obtained by splitting the complete protocol parsing template of the network packet. The configuration module includes multiple lookup tables (LUTs), and the several feature items are stored in the LUTs. When the current protocol layer is the link layer, the configuration module stores several feature items including one or more of the following: source MAC address, destination MAC address, Ethernet type, and VLAN identifier. When the current protocol layer is the network layer, the feature includes one or more of the source IP address, destination IP address, and protocol number; When the current protocol layer is the transport layer, the feature includes one or more of the source port number and the destination port number.
[0126] This concludes the discussion on... Figure 6 Description of the device.
[0127] This application also provides embodiments that... Figure 6 Hardware structure description of the illustrated device. This hardware structure is... Figure 7 The structure in the illustrated electronic device. Please refer to [link / reference]. Figure 7 , Figure 7 This is a structural diagram of an electronic device provided in an embodiment of this application. Figure 7 As shown, the electronic device may include a field-programmable gate array (FPGA) and a processor; the processor is used to provide configuration information to the FPGA; the FPGA is used to execute the methods disclosed in the above examples of this application.
[0128] The above are merely embodiments of this application and are not intended to limit the scope of this application. Various modifications and variations can be made to this application by those skilled in the art. Any modifications, equivalent substitutions, improvements, etc., made within the spirit and principles of this application should be included within the scope of the claims of this application.
Claims
1. A method for parsing network packets, characterized in that, This method is applied to Field Programmable Gate Arrays (FPGAs), and includes: Extract a preset length of data from the header of the current network packet as the data to be parsed. The first protocol layer in the current data to be parsed is taken as the current protocol layer, and the current protocol layer parsing operation is performed. The current protocol layer parsing operation includes: reading the field value at a preset position from the header of the current protocol layer, determining the parsing path of the current protocol layer according to the matching result of the field value and several feature items stored in the configuration module, and parsing the header of the current protocol layer according to the determined parsing path to obtain the current protocol layer information. If it is determined based on the current protocol layer information that there is a next protocol layer that needs to be parsed, then the header of the current protocol layer is removed from the current data to be parsed, and the remaining data after removal is taken as the current data to be parsed. Then, the process returns to the step of taking the first protocol layer in the current data to be parsed as the current protocol layer and performing the parsing operation of the current protocol layer. If it is determined that there is no next protocol layer based on the current protocol layer information, the parsed protocol layer information is output so as to forward the current network packet based on the protocol layer information.
2. The method according to claim 1, characterized in that, The step of determining the parsing path of the current protocol layer based on the matching results of the field value and several feature items stored in the configuration module includes: If the field value matches the feature item, the parsing path of the current protocol layer is determined to be a customized parsing path; the customized parsing path includes: extracting fields from the header of the current protocol layer according to the field offset and field length indicated by the configuration module to obtain the current protocol layer information; If the field value does not match the feature item, the parsing path of the current protocol layer is determined to be the standard parsing path; the standard parsing path includes: parsing the header of the current protocol layer according to the protocol format corresponding to the current protocol layer, extracting the protocol fields corresponding to the current protocol layer, and obtaining the information of the current protocol layer.
3. The method according to claim 1, characterized in that, The protocol layer of the current network message is the link layer; Alternatively, the protocol layers of the current network message are, in the order of parsing, the link layer and the network layer; Alternatively, the protocol layers of the current network message can be, in the order of parsing, the link layer, the network layer, and the transport layer.
4. The method according to claim 1, characterized in that, When the current protocol layer is a link layer, the current protocol layer information includes at least the Ethernet type. Determining, based on the current protocol layer information, that there exists a next protocol layer that needs to be parsed further includes: If the Ethernet type in the current protocol layer information is IPv4 or IPv6, then it is determined that there is a network layer that needs to be further parsed. If the Ethernet type is MPLS protocol type, then the MPLS label stack is parsed, and it is determined whether there is a network layer that needs to be parsed further based on the inner protocol type after the MPLS label stack. Parsing the MPLS label stack includes: after parsing each layer of MPLS labels, reading the stack bottom flag in that layer of labels; if the stack bottom flag indicates that the current label is the stack bottom label, then parsing stops; if the stack bottom flag indicates that the current label is not the stack bottom label, then parsing the next layer of MPLS labels continues until the stack bottom label is parsed or the number of parsed layers reaches a specified number; the label information of each layer of labels in the MPLS label stack is extracted, and the label information is used as part of the current protocol layer information. If the Ethernet type is another protocol type, then it is determined that there is no network layer that needs to be further parsed.
5. The method according to claim 2, characterized in that, When the current protocol layer is the link layer, the current protocol layer information includes the Ethernet type, and the standard resolution path includes: If the link layer header contains a VLAN tag, then the protocol type field following the VLAN tag is taken as the Ethernet type; If the link layer header contains two VLAN tags, then the protocol type field following the two VLAN tags is taken as the Ethernet type.
6. The method according to claim 1, characterized in that, When the current protocol layer is the network layer, the current protocol layer information includes at least the protocol number. Determining, based on the current protocol layer information, that there exists a next protocol layer that needs to be parsed further includes: If the protocol number in the current protocol layer information is a TCP protocol number, a UDP protocol number, or an ICMP protocol number, then it is determined that there is a transport layer that needs to be further parsed. If the protocol number is a tunnel protocol number, then parse the tunnel header, peel off the current protocol layer header and the tunnel header to obtain the inner layer data to be parsed, take the first protocol layer in the inner layer data to be parsed as the current protocol layer, and return to the step of performing the parsing operation of the current protocol layer; If the protocol number is another protocol number, then it is determined that there is no transport layer that needs to be further parsed.
7. The method according to claim 2, characterized in that, When the current protocol layer is the network layer, the standard resolution path includes: If the network layer header is in IPv4 protocol format, then the source IP address, destination IP address, and protocol number are extracted as the current protocol layer information; If the network layer header is in IPv6 protocol format, then each extension header is read sequentially after the IPv6 base header. The position of the next header is determined according to the next header field in the current header, until the protocol type indicated by the next header field in the current header is not an extension header type. Then, the source IP address, destination IP address and protocol number are extracted as the current protocol layer information.
8. The method according to claim 2, characterized in that, Several feature items are obtained by splitting the complete protocol parsing template of the network packet. The configuration module includes multiple lookup tables (LUTs), and the several feature items are stored in the LUTs. When the current protocol layer is the link layer, the configuration module stores several feature items including one or more of the following: source MAC address, destination MAC address, Ethernet type, and VLAN identifier. When the current protocol layer is the network layer, the feature includes one or more of the source IP address, destination IP address, and protocol number; When the current protocol layer is the transport layer, the feature includes one or more of the source port number and the destination port number.
9. A network packet parsing device, characterized in that, The device includes: The interception module is used to intercept a preset length of data in the header of the current network packet as the current data to be parsed; The configuration module is used to store several feature items corresponding to each protocol layer; Multiple parsing modules are cascaded sequentially. Each parsing module is used to take the first protocol layer in the current data to be parsed as the current protocol layer and perform a current protocol layer parsing operation. The current protocol layer parsing operation includes: reading a field value at a preset position from the header of the current protocol layer; determining the parsing path of the current protocol layer based on the matching result of the field value and several feature items stored in the configuration module; parsing the header of the current protocol layer according to the determined parsing path to obtain the current protocol layer information; if it is determined from the current protocol layer information that there is a next protocol layer that needs to be parsed, then the header of the current protocol layer is stripped from the current data to be parsed, and the remaining data after stripping is taken as the current data to be parsed, and the process returns to the step of taking the first protocol layer in the current data to be parsed as the current protocol layer and performing the current protocol layer parsing operation; if it is determined from the current protocol layer information that there is no next protocol layer, then the parsed protocol layer information is output so as to forward the current network packet based on the protocol layer information. An external interface is used to receive several feature items corresponding to each protocol layer and store them in the configuration module; Among them, the multiple parsing modules process different parsing modules of different network packets within the same clock cycle.
10. An electronic device, characterized in that, This includes field-programmable gate arrays (FPGAs) and processors; The processor is used to provide configuration information to the FPGA; The FPGA is used to perform the method as described in any one of claims 1 to 8.
