WO2023071714A1 - 报文的分段解析方法、装置、设备和存储介质 - Google Patents

报文的分段解析方法、装置、设备和存储介质 Download PDF

Info

Publication number
WO2023071714A1
WO2023071714A1 PCT/CN2022/123455 CN2022123455W WO2023071714A1 WO 2023071714 A1 WO2023071714 A1 WO 2023071714A1 CN 2022123455 W CN2022123455 W CN 2022123455W WO 2023071714 A1 WO2023071714 A1 WO 2023071714A1
Authority
WO
WIPO (PCT)
Prior art keywords
header
stage
parsing
field
analysis
Prior art date
Application number
PCT/CN2022/123455
Other languages
English (en)
French (fr)
Inventor
谢友玲
韩一漫
姜珊
Original Assignee
中移(苏州)软件技术有限公司
中国移动通信集团有限公司
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by 中移(苏州)软件技术有限公司, 中国移动通信集团有限公司 filed Critical 中移(苏州)软件技术有限公司
Publication of WO2023071714A1 publication Critical patent/WO2023071714A1/zh

Links

Images

Classifications

    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L69/00Network arrangements, protocols or services independent of the application payload and not provided for in the other groups of this subclass
    • H04L69/18Multiprotocol handlers, e.g. single devices capable of handling multiple protocols
    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L69/00Network arrangements, protocols or services independent of the application payload and not provided for in the other groups of this subclass
    • H04L69/22Parsing or analysis of headers

Definitions

  • the present disclosure relates to the field of network technology but is not limited to the field of network technology, and in particular, relates to a segment analysis method, device, device and storage medium of a message.
  • the current mainstream method for parsing data packets is to develop a specific parsing module according to the data type, wherein the data format and data length are fixed, and multiple parsing modules need to be added to process multiple types of data packets.
  • This type of parsing method has low versatility and is suitable for application scenarios with low data complexity.
  • the data to be processed by each layer of this type of analysis method includes all data packets, the length of the data to be processed is longer, which reduces the analysis speed of the system. For communication systems with different types of data packet transmission Not very flexible, which will greatly reduce the processing speed of system parsing.
  • Embodiments of the present disclosure provide a message segmentation analysis method, device, equipment and storage medium.
  • a segment analysis method of a message is provided, and the message to be analyzed includes: a header; the method includes:
  • the parsing configuration information analyze the header at the nth stage to obtain the nth stage parsing result, wherein, when the n is less than N, the nth stage parsing result includes: the header information parsed at the nth stage , the type of the next layer header to be parsed in the message and the offset address of the next stage of parsing; wherein, the N is the maximum number of parsing stages of the header;
  • the header type of the next layer is the header type analyzed in the n+1 stage, performing the n+1 stage analysis on the header according to the offset address;
  • a segment analysis device for a message includes: a header; the device includes a stage analysis module; the stage analysis module is configured to:
  • the parsing configuration information analyze the header at the nth stage to obtain the nth stage parsing result, wherein, when the n is less than N, the nth stage parsing result includes: the header information parsed at the nth stage , the type of the next layer header to be parsed in the message and the offset address of the next stage of parsing; wherein, the N is the maximum number of parsing stages of the header;
  • the header type of the next layer is the header type analyzed in the n+1 stage, performing the n+1 stage analysis on the header according to the offset address;
  • a computer device including a memory, a processor, and a computer program stored on the memory and operable on the processor.
  • the processor executes the program, it implements any one of the first aspect The steps of the fragment analysis method of the message.
  • a computer-readable storage medium on which a computer program is stored, and when the computer program is executed by a processor, the steps of the message segment analysis method described in any one of the first aspect are implemented.
  • the segmented analysis method, device, device, and storage medium of the message obtained by the embodiments of the present disclosure obtain the analysis result of the nth stage by performing the nth stage analysis on the header included in the message according to the analysis configuration information.
  • the nth stage analysis When the nth stage analysis When the header type of the next layer to be parsed in the result is not the header type parsed in the n+1 stage, skip the n+1 stage parsing of the header and enter the n+2 stage parsing.
  • the header type of the first layer is the header type analyzed in the n+1 stage
  • the header is analyzed in the n+1 stage according to the offset address of the next stage included in the analysis result of the n stage, and when the N stage analysis is completed or before
  • the N-1 layer protocol analysis determines to skip the N-stage analysis, stop the segment analysis of the header.
  • FIG. 1 is a schematic flow diagram of a segmented analysis method for a message provided by an embodiment of the present disclosure
  • FIG. 2 is another schematic flow diagram of a method for analyzing segments of a message provided by an embodiment of the present disclosure
  • FIG. 3 is another schematic flow diagram of a message segmentation analysis method provided by an embodiment of the present disclosure.
  • FIG. 4 is another schematic flow diagram of a message segmentation analysis method provided by an embodiment of the present disclosure.
  • FIG. 5 is another schematic flow diagram of a message segmentation analysis method provided by an embodiment of the present disclosure.
  • FIG. 6 is a flow chart of a specific example of a message segmentation analysis method provided by an embodiment of the present disclosure
  • FIG. 7 is a schematic structural diagram of an apparatus for analyzing message segments provided by an embodiment of the present disclosure.
  • Fig. 8 is a schematic structural diagram of a stage analysis module in the device shown in Fig. 7;
  • FIG. 9 is a schematic structural diagram of a computer device provided by an embodiment of the present disclosure.
  • a data packet When data is transmitted over a network, a data packet consists of a header and a body. When a packet reaches its destination, because the packet is processed and unpacked in the reverse order corresponding to each protocol layer, the data header needs to be parsed out.
  • an analysis module with a fixed data format and data length is often selected to analyze the header information of the data packet.
  • ARP Address Resolution Protocol
  • Address Resolution Protocol Address Resolution Protocol
  • ICMP Internet Control Message Protocol, Internet Control Message Protocol
  • this type of analysis method is universal Low, suitable for application scenarios with low data complexity.
  • the layered analysis steps are performed on the header field of the network data packet corresponding to each layer of the protocol, so as to achieve the purpose of generalization.
  • VXLAN virtual extensible local area network, virtual extended local area network
  • OpenFlow OpenFlow
  • Open vSwitch virtualized OpenFlow switch
  • QinQ QinQ technology
  • QinQ technology is based on the Ethernet protocol, and there will be multiple VLAN TAGs (virtual local area network tags). This analysis method cannot further analyze according to the protocol type.
  • the data to be processed by each layer of the above-mentioned analysis method includes all data packets, the length of data to be processed at each stage is relatively long, which reduces the analysis speed of the system. For communication systems with different types of data packet transmission It is not very flexible, which will greatly reduce the processing speed of system analysis.
  • the embodiment of the present disclosure provides a segment analysis method of a message, as shown in FIG. 1, the segment analysis method of the message may include:
  • the parsing configuration information perform n-stage parsing on the header included in the message to obtain the n-stage parsing result, wherein, when n is less than N, the n-stage parsing result includes: the header information parsed in the n-stage, the message The header type of the next layer to be parsed in the text and the offset address of the next stage of parsing; where N is the maximum number of parsing stages of the header.
  • the nth stage is used for parsing the protocol header of the nth layer in the network layered architecture.
  • packets can be parsed in stages from outside to inside. Each stage is capable of parsing multiple protocol headers.
  • the layering method of the network layered architecture includes the OSI (Open System Interconnect, Open System Interconnect) seven-layer model and the TCP/IP (Transmission Control Protocol/Internet Protocol, Transmission Control Protocol/Internet Protocol) four-layer model.
  • Each stage is pre-configured with corresponding parsing configuration information, and the parsing configuration information is also called stage preset information.
  • the parsing configuration information of each stage is saved in the stage preset information table.
  • the parsing configuration information of the nth stage is used to perform the nth stage parsing on the header included in the packet to obtain the nth stage parsing result.
  • the next layer header type refers to the protocol type of the next layer header.
  • the header type of the next layer to be parsed in the message included in the analysis result of the nth stage refers to the header type of any layer from the n+1th layer to the Nth layer in the message.
  • the header type of the next layer is a header type that can be parsed at the n+2 layer, the packet will not be processed after entering the n+1 stage, and will directly flow to the n+2 stage for analysis.
  • the offset address of the next stage refers to the header offset of the next stage, and is used to point to the starting position of the next layer protocol header in the data packet.
  • the analysis result of the nth stage also includes header information and key information of the nth layer, such as for Ethernet Network header, its key information includes source MAC address and destination MAC address, and so on.
  • stage parsing results of this stage such as the obtained header information and key information, will be stored in the corresponding location, and then jump to the next stage.
  • the header type of the next layer is not the header type analyzed in the n+1 stage, skip the n+1 stage parsing of the header, and enter the n+2 stage parsing.
  • the header type of the next layer is not included in the stage preset information of the (n+1) stage, and it is determined that the header type of the next layer is not the header type parsed in the (n+1) stage.
  • the header type of the next layer is the header type analyzed in the n+1 stage, and the n+1 stage analysis is performed on the header according to the offset address.
  • the header type of the next layer is included in the preset information table in the (n+1) stage, and it is determined that the header type of the next layer is the header type parsed in the (n+1) stage.
  • the header type of the next layer header to be parsed included in the analysis result of the nth stage of the header is not the header type analyzed in the n+1st stage, the header is skipped.
  • the one-stage analysis in the embodiments of the present disclosure may correspond to the analysis of a layer-1 protocol of network transmission of data packets.
  • the message may contain up to 4 layers of protocols, namely application layer protocol, transport layer protocol, network layer protocol and data link layer protocol.
  • the N may be equal to 4, that is, one stage corresponds to header parsing of one layer.
  • a layer may include multiple different protocols, and the header types carried in the header are different.
  • the header types corresponding to this layer may include but not limited to: TCP headers and UDP (User Datagram Protocol, User Datagram Protocol) headers.
  • the header types corresponding to this layer may include but not limited to: ICMP header, ARP header, RARP (Reverse Address Resolution Protocol, reverse address translation protocol) header.
  • the header type of the next layer to be parsed is the header type parsed in the n+1 stage
  • the header is analyzed in the n+1 stage according to the offset address of the next stage included in the analysis result of the n stage, and when the stage n is completed
  • the N-stage analysis or the previous N-1 layer protocol analysis determines to skip the N-stage analysis, stop the segmentation analysis of the header this time, so that no matter which headers the current message carries that can be parsed, it can be parsed. Therefore, for messages carrying different types of headers, each stage can analyze the messages in a unified way. In this way, when parsing multiple types of data packets in segments, there is no need to add multiple parsing modules, and only one parsing module needs to be written.
  • the parsing code at each stage is the same, thus reducing the amount of code development, increasing versatility, realizing generalized data parsing, and greatly saving system logic resources.
  • the parsing speed of the data message can be greatly improved.
  • the parsing configuration information includes: field parsing information and stage flow information.
  • the analysis configuration information of the nth stage includes: field analysis information and stage transfer information of the nth stage.
  • the field parsing information at the nth stage includes: header types that can be parsed at the nth stage and header field fields corresponding to each header type.
  • the stage transfer information includes: the header type of the next layer to be parsed in the message and the offset address of the next stage. There is a corresponding relationship between the stage flow information and the header field.
  • parsing the configuration information may also include other configuration information, such as a header structure.
  • the header type included in the parsing configuration information of each stage, the header field field corresponding to each header type, and the stage flow information table can be encapsulated into a function, so that the user can combine the application scenario and call the upper layer software to
  • the parsed header type and the number of stages of parsing are modified to achieve configurability and facilitate upgrade iterations to meet the packet parsing requirements of different applications.
  • the header is analyzed in the nth stage to obtain the nth stage analysis result, which may include:
  • the header field field includes: frame type, header length, header number and/or mask.
  • network transmission data is transmitted by frame
  • different frame types are used to indicate specific formats used by different protocol types to transmit data on the network
  • different frame types have different offsets.
  • the header length refers to the protocol length, for example, the Ethernet header length is 14 bytes, and the IPv4 (Internet Protocol version 4, Internet Protocol version 4) header length is 20 bytes.
  • the header number is used to uniquely identify the header type.
  • the mask is used to indicate the bits that need to be reserved and/or the bits that need to be cleared in the field (Field) of the header.
  • the preset header field fields corresponding to different header types are stored in a preset header field field table, and the preset header field field table can be referred to in Table 1 below.
  • the header field field table shown in Table 1 includes the frame types that may be included in each protocol type. In this way, for QinQ technology, the application scenario of the Layer 2 tunneling protocol with two layers of VLAN Tags in the message can be included in the header field field. Multiple frame types are set under each protocol type, and the offsets of different frame types are different.
  • the preset header field field contains frame types that different protocol types may contain, so, for the characteristics of multiple VLAN TAGs of QinQ, multiple frame types can be set in the preset header field field field, each VLAN header can be obtained, so that the frame type can be used to refine the analysis of the data type, so that subsequent analysis can be performed more accurately, and it can meet the data header analysis of complex application scenarios using QinQ and other technologies.
  • the header is parsed to obtain the header field corresponding to the header type to be parsed according to the header field corresponding to each header type in the field parsing information of the nth stage.
  • stage transfer information of the nth stage according to the header field, and determine the header type of the next layer to be parsed and the offset address to be parsed in the next stage.
  • the stage flow information of each stage is stored in a preset stage flow information table.
  • the preset stage flow information table may be shown in Table 2 below but is not limited to Table 2.
  • the stage flow information table shown in Table 2 includes the next layer header types of different header types, the offset address of the next stage, and can also include the action flag bit whether the current data segment is parsed or not, and the action flag position is 1 Indicates that the analysis of the current data segment is completed, and the position of the action flag is 0, indicating that the analysis of the current data segment is not completed.
  • you can obtain the header type of the next layer to be parsed, the offset address of the next stage, and the current data by looking up the stage flow information corresponding to the header field field in the preset stage flow information table The action flag bit whether the section is parsed or not.
  • performing n+1 stage parsing on the header according to the offset address may include:
  • header field field to be parsed included in the header is a valid field included in the header field field table at stage n+1, parse the content of the header field field to be parsed included in the header.
  • the header field field to be parsed contained in the header can be compared with the preset header field field table to determine whether the header field field to be parsed is the same as the header field field.
  • a field in a certain row in the table matches, and if they match, it is determined that the header field field to be parsed is a valid field, otherwise, it is determined that the header field field to be parsed is an invalid field.
  • the to-be-parsed header field included in the header is a valid field, continue to parse the header to obtain the content of the to-be-parsed header field.
  • the method may further include:
  • header field to be parsed included in the header is an invalid field not included in the header field table of the n+1th stage, stop parsing at the n+1th stage.
  • the parsing at the n+1th stage is stopped, and the judgment is directly skipped to the n+2th stage.
  • the method may also include:
  • the processable packet length may be the maximum length among header lengths corresponding to different header types.
  • the value of the report length that can be processed is 64 bytes, but it is not limited thereto in the embodiments of the present disclosure.
  • the preset length can be set according to actual applications, for example, the preset length is set to be the same as the length of the report that can be processed.
  • start segment analysis of the header from the first data segment start segment analysis of the header from the first data segment.
  • step 101 executes step 101 to step 104 to analyze the segmented header, and when the first data segment is parsed, continue to analyze the header segment of the second data segment, according to And so on, until the header parsing of all data segments is completed.
  • the parsing results of the segment parsing of each data segment may be spliced to finally obtain the header parsing result of the data packet.
  • the data packet is divided into a plurality of fixed-length data segments according to the processable report length of segment analysis, and each data segment is analyzed in stages in turn, so that it can deal with complex protocols with variable length data packets, And further speed up the speed of data analysis.
  • the header type of the next layer is the header type analyzed in the n+1 stage, and the n+1 stage analysis is performed on the header according to the offset address, which may include:
  • this data segment is parsed at the n+1 stage, if it is determined according to the offset address parsed in the next stage, the header length of the next layer header type, and the parse length indicated by the field parsing information in the n+1 stage, the to-be When the parsed field part is located in the next data segment, the n+1 stage analysis is performed in combination with the current data segment and the next data segment.
  • this data segment is parsed at the n+1 stage, whether the sum of the header length of the header type of the next layer and the header offset is greater than the parsing length indicated by the field parsing information of the n+1 stage , to determine whether the field to be parsed is partially located in the next data segment, and when the field to be parsed is partially located in the next data segment, it can be determined that the header to be parsed spans the current data segment and the next data segment.
  • the parsed header information is divided into this data segment and the next data segment.
  • the sum of the header length of the header type of the next layer and the header offset is less than or equal to the analysis length indicated by the field analysis information of the n+1 stage, and it is determined that all the fields to be analyzed are located in the next data segment.
  • the headers to be parsed in one stage may be located in different data segments. At this time, there is a cross-segment analysis of header parsing in this stage.
  • performing the n+1th stage analysis in combination with this data segment and the next data segment may include:
  • next data segment After the next data segment enters the n+1 stage of unfinished parsing, according to the length of the first part of the field and the header length of the header type of the next layer, continue to analyze the next data segment at the n+1 stage and get instructions The second part field of the analysis result of the n+1 stage.
  • the header length of the header type of the next layer and the length of the first part of the field, continue to perform n+1 stage parsing on the next data segment to obtain the second part of the field.
  • the first part of the field is shifted to the left
  • the second part of the field is shifted to the right
  • the right-shifted second part of the field is spliced behind the left-shifted first part of the field to obtain a complete The header parsing result of .
  • the first part of the field is obtained by first analyzing the n+1 stage of this data segment, and then enters the unfinished parsing in the next data segment After the n+1th stage, analyze the next data segment at the n+1st stage to get the second part of the field, and then splicing the second part of the field to the first part of the field, so that the complete n+1th part can be obtained Phase analysis results.
  • the header type of the next layer is the header type analyzed in the n+1 stage, and the n+1 stage analysis is performed on the header according to the offset address, which may include:
  • this data segment is parsed at the n+1 stage, if it is determined according to the offset address parsed in the next stage, the header length of the next layer header type, and the parse length indicated by the field parsing information in the n+1 stage, the to-be When the parsed fields are all located in this data segment, the n+1 stage analysis is performed on this data segment to obtain the n+1 stage analysis result.
  • the header may be cut. After the offset is obtained by adding the header offset to the header length corresponding to the type of the next layer of the message to be parsed If the length after the header offset is greater than the length of the data segment, the header at this stage has spanned two data segments, and it needs to be combined with the next data segment to extract the header. Extract headers.
  • FIG. 6 is a flow chart of a specific example of a packet segment analysis method provided by an embodiment of the present disclosure. The method may include the steps of:
  • the flag bit of the nth stage indicates that the parsing is completed in the nth stage, that is, the nth stage operation is Prev_Stg_Done, then the n+1 stage needs to start parsing. If the operation of the nth stage is waiting (Wait), in this case, the n+1 stage needs to wait, or if the nth stage operation is a no operation instruction (NO Operation, NOP), then the n+1 stage does not need Do anything, just send packets without any parsing.
  • step 3 Check whether the header type belongs to the header type analyzed in the n+1 stage, if so, execute step 3, otherwise, enter the header analysis in the n+2 stage.
  • Each stage will preset a variety of parseable header types, and set numbers for the header types. You can check whether the number of the header type is the header type parsed in the n+1 stage to determine whether it is in the n+1 stage. The parsing operation is performed in stage 1. If the number is not the header type parsed in stage n+1, it will not be processed and directly flow to the next stage.
  • Each header type is preset with a corresponding header length, and the header length of the header type is obtained according to the input header type.
  • step 4 Combining the header length and header offset of the header type, it is judged whether the header type spans the data segment. If yes, go to step 5, otherwise go to step 6.
  • step 9 8. Check whether the header field field matches the preset header field field table, and if it matches, perform step 9; otherwise, discard the invalid header.
  • Ethernet layer may only pass through Ethernet, or may pass through one VLAN or two VLANs.
  • the network layer may include ARP, IPv4 and IPv6 (Internet Protocol version 6, Internet Protocol version 6) protocols, and the transport layer may include ICMP, UDP, TCP and GRE (Generic Routing Encapsulation, general routing encapsulation) protocol.
  • ARP Address Resolution Protocol
  • IPv4 and IPv6 Internet Protocol version 6, Internet Protocol version 6
  • the transport layer may include ICMP, UDP, TCP and GRE (Generic Routing Encapsulation, general routing encapsulation) protocol.
  • ICMP Internet Protocol version 6, Internet Protocol version 6
  • UDP User Datagram Protocol version 6
  • TCP Transmission Control Protocol
  • GRE Generic Routing Encapsulation, general routing encapsulation
  • the header offset is 0 and the flag bit of whether the analysis of the previous stage is completed is 1.
  • the content settings in the stage preset information table are shown in Table 3 below.
  • Table 3 Phase Preset Information for Phase 1
  • stage header type header length serial number header field table Stage transfer information table Phase 1 ethernet 14 0 As shown in Table 4 below As shown in Table 5 below
  • the header structure of the Ethernet header is shown in Table 6 below.
  • the Ethernet header of the data packet is obtained after header analysis in the first stage, and then the corresponding Ethernet frame type, source mac address and destination mac address are obtained according to the structure of the Ethernet header.
  • the header offset of 0 bytes and the length of the Ethernet header is 14 bytes, which is less than the length of the data packet of 64 bytes, it is judged that the header does not cross the data segment, so when the Ethernet header is parsed, the first Action flag bit 1 for phase 1.
  • the header type input to the next stage is IPv4, the header offset is 14 and the flag bit of whether the parsing is completed in the previous stage is 1.
  • the IP header will be parsed, specifically corresponding to the IP protocol included in the data packet, and the content settings in the stage preset information table are shown in Table 7 below.
  • stage header type header length serial number header field table Stage transfer information table Phase 2 IPv4 20 1 As shown in Table 8 below As shown in Table 9 below
  • header structure of the IPv4 header is shown in Table 10 below.
  • the IPv4 header of the data packet is obtained, and then the corresponding key information including the source IP address and the destination IP address is obtained according to the structure of the IPv4 header.
  • the header offset of 14 bytes and the length of the Ethernet header is 34 bytes, which is less than the length of the data packet of 64 bytes, it is judged that the header does not cross the data segment, so when the IPv4 header is parsed, the 2nd Phase action flag bit 1.
  • the input header type to the next stage is TCP
  • the offset of the header is 34 and the flag bit of whether the analysis is completed in the previous stage is 1.
  • the IP header will be parsed, specifically corresponding to the IP protocol included in the data packet, and the content settings in the stage preset information table are shown in Table 11 below.
  • Table 11 Phase Preset Information for Phase 3
  • TCP 20 5 As shown in Table 12 below As shown in Table 13 below
  • Table 12 Header Field Fields of the TCP Header
  • Headers of type TCP header do not have frame types.
  • Table 14 The structure of the default TCP header
  • the TCP header of the data packet is obtained, and then according to the structure of the TCP header, the corresponding key information including the source port number and the destination port number are obtained.
  • the sum of the header offset of 34 bytes and the length of the Ethernet header is 54 bytes, which is less than the length of the data packet of 64 bytes, it is judged that the header does not cross the data segment, so when the Ethernet header is parsed, the current Phase action flag bit 1.
  • the header offset is 54 and the flag bit of whether the parsing is completed in the previous stage is 1.
  • the header parsing of the message will not be performed, and the data flow will be directly transferred to the next stage until the last stage.
  • the data packet is analyzed by the segment, the corresponding Ethernet header, IPv4 header and TCP header are obtained, and the key information source MAC address and destination MAC address, source IP address and destination IP address, source port number and destination port are obtained number, which is convenient for subsequent data forwarding and processing.
  • a segment analysis device for a message is provided; the message to be analyzed includes: a header; as shown in FIG. 7 , the device includes a stage analysis module 701; the stage analysis module 701 is configured to:
  • the parsing configuration information analyze the header at the nth stage to obtain the nth stage parsing result, wherein, when n is less than N, the nth stage parsing result includes: the header information parsed in the nth stage, the next One-layer header type and the offset address of the next stage of parsing; where N is the maximum number of parsing stages of the header;
  • the header type of the next layer is not the header type analyzed in the n+1 stage, skip the n+1 stage solution to the header, and enter the n+2 stage analysis;
  • the header type of the next layer is the header type analyzed in the n+1 stage, and the header is analyzed in the n+1 stage according to the offset address;
  • the parsing configuration information includes: field parsing information and stage flow information;
  • the stage resolution module 701 is configured to:
  • the header field field analysis is performed on the header; wherein, the header field field includes: frame type, header length, header number and/or mask;
  • the stage parsing module 701 is configured to:
  • header field field to be parsed included in the header is a valid field included in the header field field table at stage n+1, then the content of the header field field to be parsed included in the header is parsed.
  • the stage parsing module 701 is further configured to:
  • the parsing of the n+1th stage is stopped.
  • the device further includes a data division module 700 and a result splicing module 702;
  • the data division module 700 is configured to divide the data packet into a plurality of data segments according to a preset length when the received data packet is larger than the processable report length of segment analysis;
  • the stage parsing module 701 is configured to start segment parsing of the header from the first data segment
  • the result splicing module 702 is configured to splice the parsing results of the segmentation parsing of multiple data segments to obtain the parsing results of the headers.
  • the stage parsing module 701 is configured to:
  • this data segment is parsed at the n+1 stage, if it is determined according to the offset address parsed in the next stage, the header length of the next layer header type, and the parse length indicated by the field parsing information in the n+1 stage, the to-be When the parsed field part is located in the next data segment, the n+1 stage analysis is performed in combination with the current data segment and the next data segment.
  • the stage parsing module 701 is configured to:
  • next data segment After the next data segment enters the n+1 stage of unfinished parsing, according to the length of the first part of the field and the header length of the next layer header type, continue to analyze the next data segment at the n+1 stage, and get the indication nth The second part of the field of the parsing result of the +1 stage;
  • the second part of the field is spliced to the back of the first part of the field to obtain the analysis result of the n+1 stage.
  • the stage parsing module 701 is configured to:
  • this data segment is parsed at the n+1 stage, if it is determined according to the offset address parsed in the next stage, the header length of the next layer header type, and the parse length indicated by the field parsing information in the n+1 stage, the to-be When the parsed fields are all located in this data segment, the n+1 stage analysis is performed on this data segment to obtain the n+1 stage analysis result.
  • stage parsing module in the packet fragment parsing device provided by the embodiment of the present disclosure will be further described.
  • the stage parsing module includes a pre-judgment unit, a header extraction unit and a next-stage information item extraction unit. in:
  • the pre-judgment unit is configured to judge according to the header type, header offset, and last-stage parsing completion flag included in the input parsing information of the current stage, combined with the stage preset information corresponding to the current stage in the stage preset information table Whether the header type needs to be parsed, determine the header length corresponding to the header type that needs to be parsed, and obtain a cross-field flag bit used to indicate whether header parsing needs to be performed across data segments.
  • the stage preset information table is generated by receiving the user's message parsing configuration information, and the message parsing configuration information includes the header types that can be parsed at each stage, the header length corresponding to each header type, and the corresponding The header field field and the stage flow information table corresponding to each header field.
  • the header extraction unit is configured to perform header extraction according to the header length corresponding to the header type in the pre-judgment result and the cross-field flag bit when the pre-judgment result of the pre-judgment module indicates that the header type can be parsed, and obtain the header of the header type, The header field field and the key information corresponding to the header.
  • the next stage information item extraction unit is configured to extract the header type of the next stage included in the stage flow information table according to the header field field obtained by the header extraction unit for the current stage and in combination with the header field field in the stage preset information table , the offset of the header, and give the flag bit indicating whether the parsing is currently completed or not.
  • the segment analysis device of the message provided by the above-mentioned embodiment realizes the segment analysis method of the message
  • the division of the above-mentioned program modules is only used as an example for illustration.
  • the above-mentioned The processing assignment is accomplished by different program modules, that is, the internal structure of the segment analysis device for messages is divided into different program modules, so as to complete all or part of the processing described above.
  • the device provided by the above embodiment and the embodiment of the corresponding method belong to the same idea, and the specific implementation process thereof is detailed in the method embodiment, and will not be repeated here.
  • FIG. 9 is a schematic structural diagram of a computer device provided by an embodiment of the present disclosure; as shown in FIG. 9 , the computer device 900 includes: a processor 901 and a memory 902 for storing computer programs that can run on the processor; wherein, When the processor 901 is used to run a computer program, it performs the following operations:
  • the header included in the message is parsed at the nth stage to obtain the nth stage parsing result, wherein, when n is less than N, the nth stage parsing result includes: the header information parsed at the nth stage, the message content The header type of the next layer to be parsed and the offset address of the next stage of parsing; where N is the maximum number of parsing stages of the header;
  • the header type of the next layer is not the header type analyzed in the n+1 stage, skip the n+1 stage parsing of the header, and enter the n+2 stage parsing;
  • the header type of the next layer is the header type analyzed in the n+1 stage, and the header is analyzed in the n+1 stage according to the offset address;
  • the computer device 900 may further include: at least one network interface 903 .
  • Various components in computer device 900 are coupled together by bus system 904 .
  • the bus system 904 is used to realize connection and communication between these components.
  • the bus system 904 also includes a power bus, a control bus and a status signal bus.
  • the various buses are labeled bus system 904 in FIG. 9 for clarity of illustration.
  • the network interface 903 is used for wired or wireless communication between the computer device 900 and other devices.
  • the memory 902 in the disclosed embodiment is used to store various types of data to support the operation of the computer device 900 .
  • the methods disclosed in the foregoing embodiments of the present disclosure may be applied to the processor 901 or implemented by the processor 901 .
  • the processor 901 may be an integrated circuit chip with signal processing capability. In the implementation process, each step of the above method may be completed by an integrated logic circuit of hardware in the processor 901 or instructions in the form of software.
  • the aforementioned processor 901 may be a general-purpose processor, a digital signal processor (DSP, DiGital Signal Processor), or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, and the like.
  • DSP Digital signal processor
  • DiGital Signal Processor DiGital Signal Processor
  • the processor 901 may implement or execute various methods, steps, and logic block diagrams disclosed in the embodiments of the present disclosure.
  • a general purpose processor may be a microprocessor or any conventional processor or the like.
  • the steps of the method disclosed in the embodiments of the present disclosure may be directly implemented by a hardware decoding processor, or implemented by a combination of hardware and software modules in the decoding processor.
  • the software module may be located in a storage medium, the storage medium is located in the memory 902, and the processor 901 reads the information in the memory 902, and completes the steps of the foregoing method in combination with its hardware.
  • the computer device 900 may be implemented by one or more Application Specific Integrated Circuit (ASIC, Application Specific Integrated Circuit), DSP, Programmable Logic Device (PLD, Programmable Logic Device), Complex Programmable Logic Device (CPLD , Complex Programmable Logic Device), field-programmable gate array (FPGA, Field-Programmable Gate Array), general-purpose processor, controller, microcontroller (MCU, Micro Controller Unit), microprocessor (Microprocessor), or other electronic The component is implemented for performing the aforementioned method.
  • ASIC Application Specific Integrated Circuit
  • DSP Programmable Logic Device
  • PLD Programmable Logic Device
  • CPLD Complex Programmable Logic Device
  • FPGA Field-Programmable Gate Array
  • controller controller
  • microcontroller MCU, Micro Controller Unit
  • microprocessor Microprocessor
  • An embodiment of the present disclosure also provides a computer-readable storage medium, on which a computer program is stored; when the computer-readable storage medium is applied to a message segment analysis method, when the computer program is run by a processor, the following operations are performed:
  • the header included in the message is parsed at the nth stage to obtain the nth stage parsing result, wherein, when n is less than N, the nth stage parsing result includes: the header information parsed at the nth stage, the message content The header type of the next layer to be parsed and the offset address of the next stage of parsing; where N is the maximum number of parsing stages of the header;
  • the header type of the next layer is not the header type analyzed in the n+1 stage, skip the n+1 stage parsing of the header, and enter the n+2 stage parsing;
  • the header type of the next layer is the header type analyzed in the n+1 stage, and the header is analyzed in the n+1 stage according to the offset address;
  • the disclosed devices and methods may be implemented in other ways.
  • the device embodiments described above are only illustrative.
  • the division of units is only a logical function division.
  • the coupling, or direct coupling, or communication connection between the components shown or discussed may be through some interfaces, and the indirect coupling or communication connection of devices or units may be electrical, mechanical or other forms of.
  • the units described above as separate components may or may not be physically separated, and the components displayed as units may or may not be physical units, that is, they may be located in one place or distributed to multiple network units; Part or all of the units can be selected according to actual needs to achieve the purpose of the solution of this embodiment.
  • each functional unit in each embodiment of the present disclosure may be integrated into one processing unit, or each unit may be used as a single unit, or two or more units may be integrated into one unit; the above-mentioned integration
  • the unit can be realized in the form of hardware or in the form of hardware plus software functional unit.
  • the above-mentioned integrated units of the present disclosure are realized in the form of software function modules and sold or used as independent products, they may also be stored in a computer-readable storage medium.
  • the computer software products are stored in a storage medium, including several instructions for A computer device (which may be a personal computer, a server, or a network device, etc.) is made to execute all or part of the methods in various embodiments of the present disclosure.
  • the aforementioned storage medium includes: various media capable of storing program codes such as removable storage devices, ROM, RAM, magnetic disks or optical disks.

Landscapes

  • Engineering & Computer Science (AREA)
  • Computer Security & Cryptography (AREA)
  • Computer Networks & Wireless Communication (AREA)
  • Signal Processing (AREA)
  • Data Exchanges In Wide-Area Networks (AREA)

Abstract

本公开涉及一种报文的分段解析方法、装置、设备和存储介质。本公开通过根据解析配置信息对报文包括的报头进行第n阶段解析得到第n阶段解析结果,当第n阶段解析结果包括的待解析的下一层报头类型不是第n+1阶段解析的报头类型时,跳过对报头的第n+1阶段解,并进入到第n+2阶段解析,当待解析的下一层报头类型是第n+1阶段解析的报头类型时,根据第n阶段解析结果包括的下一阶段的偏移地址对报头进行第n+1阶段解析,以及当完成第N阶段解析或前N-1层协议解析确定跳过第N阶段解析时,停止对报头的本次分段解析。

Description

报文的分段解析方法、装置、设备和存储介质
本公开是基于申请号为:202111242584.X、申请日为2021年10月25的中国在先专利申请提出的,并且要求该中国在先专利申请的优先权,该中国在先专利申请的全部内容在此引入本公开作为参考。
技术领域
本公开涉及网络技术领域但不限于网络技术领域,尤其涉及一种报文的分段解析方法、装置、设备和存储介质。
背景技术
对于多层网络结构,其不同层完成不同功能,每层有众多协议组成。正确解析数据包是数据传输中的重要一环,无论是数据处理还是数据转发都需要解析数据包,获取该数据包相应的报头信息,如MAC(medium access control,介质访问控制)地址、网络协议(Internet Protocol,IP)协议、IP地址等。
目前主流的解析数据包的方法是:根据数据类型,开发特定的解析模块,其中数据格式和数据长度固定,如需处理多类型的数据包需要添加多个解析模块。这类解析方法通用性低,适用于数据复杂度低的应用场景。此外,这类解析方法由于每层所需要处理的数据是包含全部的数据报文,导致所需要处理的数据长度较长,降低了系统的解析速度,对于数据包传输类型不同的通信系统来说并不是很灵活,这将大大降低系统解析的处理速度。
发明内容
本公开实施例提供一种报文的分段解析方法、装置、设备和存储介质。
本公开的技术方案是这样实现的:
第一方面,提供了一种报文的分段解析方法,待解析的报文包括:报头;所述方法包括:
根据解析配置信息,对所述报头进行第n阶段解析得到第n阶段解析结果,其中,当所述n小于N时,所述第n阶段解析结果包括:所述第n阶段解析出的报头信息、所述报文内待解析的下一层报头类型及下一阶段解析的偏移地址;其中,所述N为所述报头的最大解析阶段数;
当所述下一层报头类型不是第n+1阶段解析的报头类型,跳过对所述报头的第n+1阶段解析,并进入到第n+2阶段解析;
当所述下一层报头类型是第n+1阶段解析的报头类型,根据所述偏移地址对所述报头进行第n+1阶段解析;
当完成所述第N阶段解析或前N-1层协议解析确定跳过第N阶段解析时,停止对所述报头的本次分段解析。
第二方面,提供了一种报文的分段解析装置,待解析的报文包括:报头;所述装置包括阶段解析模块;所述阶段解析模块被配置为:
根据解析配置信息,对所述报头进行第n阶段解析得到第n阶段解析结果,其中,当所述n小于N时,所述第n阶段解析结果包括:所述第n阶段解析出的报头信息、所述报文内待解析的下一层报头类型及下一阶段解析的偏移地址;其中,所述N为所述报头的最大解析阶段数;
当所述下一层报头类型不是第n+1阶段解析的报头类型,跳过对所述报头的第n+1阶段解,并进入到第n+2阶段解析;
当所述下一层报头类型是第n+1阶段解析的报头类型,根据所述偏移地址对所述报头进行第n+1阶段解析;
当完成所述第N阶段解析或前N-1层协议解析确定跳过第N阶段解析时,停止对所述报头的本次分段解析。
第三方面,提供了一种计算机设备,包括存储器、处理器及存储在存储器上并可在处理器上运行的计算机程序,所述处理器执行所述程序时实现第一方面任一项所述报文的分段解析方法的步骤。
第四方面,提供了一种计算机可读存储介质,其上存储有计算机程序,所述计算机程序被处理器执行时实现第一方面任一项所述报文的分段解析方法的步骤。
本公开实施例所提供的报文的分段解析方法、装置、设备和存储介质,通过根据解析配置信息对报文包括的报头进行第n阶段解析得到第n阶段解析结果,当第n阶段解析结果包括的待解析的下一层报头类型不是第n+1阶段解析的报头类型时,跳过对报头的第n+1阶段解析,并进入到第n+2阶段解析,当待解析的下一层报头类型是第n+1阶段解析的报头类型时,根据第n阶段解析结果包括的下一阶段的偏移地址对报头进行第n+1阶段解析,以及当完成第N阶段解析或前N-1层协议解析确定跳过第N阶段解析时,停止对报头的本次分段解析。如此,一方面,不管当前报文携带哪些阶段能够解析的报头,都能够被解析到,故针对携带不同类型报头的报文在不同阶段都可以采用通用解析方式,这样,在分段解析多类型的数据包时,无需添加多个解析模块,只需编写一个解析模块,每个阶段的解析代码都是相同的,由此减少了解析代码的开发量,增加了通用性。另一方面,在没有携带对应阶段的报头时跳过对应阶段,节省不必要阶段报头的解析消耗。又一方面,跳过了不必要解析的报头阶段,能够极大地提高数据解析速度。
应当理解的是,以上的一般描述和后文的细节描述仅是示例性和解释性的,并不能限制本公开实施例。
附图说明
图1为本公开实施例提供的报文的分段解析方法的一个流程示意图;
图2为本公开实施例提供的报文的分段解析方法的另一个流程示意图;
图3为本公开实施例提供的报文的分段解析方法的又一个流程示意图;
图4为本公开实施例提供的报文的分段解析方法的再一个流程示意图;
图5为本公开实施例提供的报文的分段解析方法的再一个流程示意图;
图6为本公开实施例提供的报文的分段解析方法的具体示例流程图;
图7为本公开实施例提供的报文的分段解析装置的一个结构示意图;
图8为图7所示装置中的阶段解析模块的具体结构示意图;
图9为本公开实施例提供的计算机设备的结构示意图。
具体实施方式
为使本公开的目的、技术方案和优点更加清楚明白,下面将结合本公开实施例中的附图,对本公开实施例中的技术方案进行清楚、完整地描述,显然,所描述的实施例仅仅是本公开一部分实施例,而不是全部的实施例。基于本公开中的实施例,本领域普通技术人员在没有做出创造性劳动前提下所获得的所有其他实施例,都属于本公开保护的范围。在不冲突的情况下,本公开中的实施例及实施例中的特征可以相互任意组合。在附图的流程图示出的步骤可以在诸如一组计算机可执行指令的计算机系统中执行。并且,虽然在流程图中示出了逻辑顺序,但是在某些情况下,可以以不同于此处的顺序执行所示出或描述的步骤。
可以理解的是,本公开对各个实施例的描述着重强调各个实施例之间的不同之处,其相同或相似之处可以相互参考,为了简洁,不再一一赘述。
在网络中传输数据时,数据包包括报头和正文。当数据包到达其目标时,因为该数据包是以每个协议层的对应相反顺序处理和解包的,需要将数据报头解析出来。
主流的数据解析方法时,往往选用数据格式和数据长度固定的解析模块,对数据包的报头信息进行解析。如根据以太网报头、ARP(Address Resolution Protocol,地址解析协议)报头、ICMP(Internet Control Message Protocol,网际控制报文协议)等报头的结构体,分别编写对应的解析模块,这类解析方式通用性低,适用于数据复杂度低的应用场景。
另外,根据开放式系统互联七层结构由低到高的顺序,依次对网络数据报文的头部字段中与每层对应协议的数据包头执行分层解析步骤,能够达到通用化的目的。但随着VXLAN(virtual extensible local area network,虚拟扩展局域网)等重叠隧道协议、OpenFlow(开放流)、虚拟化开放流交换机(Open vSwitch,OVS)等虚拟交换技术和QinQ技术的引入,使得网络中数据平面的复杂性急剧增加,解析的复杂度和升级难度上升,这种解析的方法,已经无法满足这些复杂应用场景的数据报头解析。例如QinQ技术基于以太网协议,会有多个VLAN TAG(虚拟局域网标签),这种解析方法则无法根据协议类型进一步解析。
此外,由于上述解析方法每层所需要处理的数据是包含全部的数据报文,每个阶段所需要处理的数据长度较长,降低了系统的解析速度,对于数据包传输类型不同的通信系统来说并不是很灵活,这将大大降低系统解析的处理速度。
为此,本公开实施例提供了一种报文的分段解析方法,参阅图1所示,该报文的分段解析方法可以包括:
101,根据解析配置信息,对报文包括的报头进行第n阶段解析得到第n阶段解析结果,其中,当n小于N时,第n阶段解析结果包括:第n阶段解析出的报头信息、报文内待解析的下一层报头类型及下一阶段解析的偏移地址;其中,N为报头的最大解析阶段数。
第n阶段用于对应解析网络分层架构中的第n层的协议报头。根据网络分层架构,可以对报文依次由外到内进行分阶段解析。每个阶段能够解析多种协议报头。网络分层架构的分层方式包括OSI(Open System Interconnect,开放式系统互联)七层模型和TCP/IP(Transmission Control Protocol/Internet Protocol,传输控制协议/网际协议)四层模型。
每一阶段分别预先配置有对应的解析配置信息,解析配置信息也称为阶段预设信息。各个阶段的解析配置信息保存在阶段预设信息表中。第n阶段的解析配置信息,用于对报文包括的报头进行第n阶段解析得到第n阶段解析结果。
下一层报头类型是指下一层报头的协议类型。这里,需要说明的是,第n阶段解析结果包括的报文内待解析的下一层报头类型,是指报文内的第n+1层至第N层中的任意一层的报头类型。例如,当下一层报头类型是第n+2层能够解析的报头类型时,报文进入第n+1阶段后不做处理,直接流转到第n+2阶段解析。
下一阶段的偏移地址是指下一阶段的报头偏移量,用于指向数据包中的下一层协议报头的起始位置。
可以理解的是,第n阶段解析结果除了包括报文内待解析的下一层报头类型及下一阶段解析的偏移地址之外,还包括第n层的报头信息及关键信息,比如针对以太网报头,其关键信息包括源MAC地址和目的MAC地址,等等。
需要说明的是,每当一个阶段完成解析,会将该阶段的阶段解析结果,例如获取的报头信息以及关键信息存储到相应的位置,然后跳转到下一个阶段。
102,当下一层报头类型不是第n+1阶段解析的报头类型,跳过对报头的第n+1阶段解析,并进入到第n+2阶段解析。
在一些示例中,当下一层报头类型未包含在第n+1阶段的阶段预设信息中,确定下一层报头类型不是第n+1阶段解析的报头类型。
103,当下一层报头类型是第n+1阶段解析的报头类型,根据偏移地址对报头进行第n+1阶段解析。
在一些示例中,当下一层报头类型包含在第n+1阶段的预设信息表中,确定下一层报头类型是第n+1阶段解析的报头类型。
104,当完成第N阶段解析或前N-1层协议解析确定跳过第N阶段解析时,停止对报头的本次分段解析。
本公开实施例所提供的报文的分段解析方法,当报头的第n阶段解析结果包括的待解析的下一 层报头类型不是第n+1阶段解析的报头类型时,跳过对报头的第n+1阶段解析,并进入到第n+2阶段解析。
本公开实施例中的一个阶段解析可以对应于数据包的网络传输的一层协议的解析。
若报文是按照TCP/IP协议传输的,则该报文最多可能包含4层协议,分别是应用层协议、传输层协议、网络层协议和数据链路层协议。此时,所述N可等于4,即一个阶段对应于一个层的报头解析。
一个层可能包括多种不同的协议,则携带在报头中的报头类型就不同。例如,以传输层为例,该层对应的报头类型可包括但不限于:TCP报头和UDP(User Datagram Protocol,用户数据报协议)报头。以网络层为例,该层对应的包头类型可包括但不限于:ICMP报头、ARP报头、RARP(Reverse Address Resolution Protocol,反向地址转换协议)报头。
当待解析的下一层报头类型是第n+1阶段解析的报头类型时,根据第n阶段解析结果包括的下一阶段的偏移地址对报头进行第n+1阶段解析,以及当完成第N阶段解析或前N-1层协议解析确定跳过第N阶段解析时,停止对报头的本次分段解析,如此,不管当前报文携带哪些阶段能够解析的报头,都能够被解析到,故针对携带不同类型报头的报文,每个阶段能够以统一的解析方式对报文进行解析,这样,在分段解析多类型的数据包时,无需添加多个解析模块,只需编写一个解析模块,每个阶段的解析代码都是相同的,由此减少了代码开发量,增加了通用性,实现了通用化的数据解析,大大节省了系统的逻辑资源。另外,由于无需在每个阶段处理报文包含的全部数据,因此能够极大地提高数据报文的解析速度。
在一个实施例中,解析配置信息包括:字段解析信息及阶段流转信息。
第n阶段的解析配置信息包括:第n阶段的字段解析信息及阶段流转信息。
第n阶段的字段解析信息包括:第n阶段能够解析的报头类型及各个报头类型对应的报头域字段。
阶段流转信息包括:报文内待解析的下一层报头类型及下一阶段的偏移地址。阶段流转信息与报头域字段具有对应关系。
可以理解的是,解析配置信息还可以包括其他配置信息,例如报头结构体。
本实施例中,可以将每个阶段的解析配置信息包括的报头类型、每种报头类型对应的报头域字段以及阶段流转信息表都封装成函数,这样使得用户可以结合应用场景,调用上层软件对解析的报头类型和解析的阶段数进行修改,实现可配置化,方便升级迭代满足不同的应用的报文解析需求。
如图2所示,上述步骤101中,根据解析配置信息,对报头进行第n阶段解析得到第n阶段解析结果,可以包括:
201,根据第n阶段的字段解析信息以及第n阶段待解析的报头类型,对报头进行报头域字段解析;其中,报头域字段包括:帧类型、报头长度、报头编号和/或掩码。
其中,网络传输数据是按帧进行传输的,不同的帧类型用于指示不同的协议类型在网络传输数据所使用的具体格式,不同的帧类型的偏移量不同。
报头长度是指协议长度,例如,以太网报头长度为14字节,IPv4(Internet Protocol version 4,互联网协议第4版)报头长度为20字节。报头编号用于唯一标识报头类型。
掩码(Mask)用于指示报头的域(Field)需要保留的位和/或需要清除的位。
可以理解的是,在实际应用时,报头域字段中可以仅包括帧类型和掩码。
在一个示例中,不同报头类型对应的预设报头域字段保存在预设的报头域字段表中,预设的报头域字段表可以参见如下表1所示。
表1:预设的报头域字段表
Figure PCTCN2022123455-appb-000001
在表1所示的报头域字段表中包含每个协议类型可能包含的帧类型,这样针对QinQ技术,报文带有两层VLAN Tag的二层隧道协议的应用场景,可以在报头域字段的每个协议类型下设置多个帧类型,不同帧类型的偏移量不同。
本实施例中,由于预设的报头域字段中包含不同协议类型可能包含的帧类型,如此,针对QinQ的多个VLAN TAG的特性,可以通过在预设的报头域字段中设置多个帧类型字段,能够获取每个VLAN报头,这样利用帧类型能够更细化数据类型的解析,从而更加准确地进行后续解析,能够满足使用QinQ等技术的复杂应用场景的数据报头解析。
在一些示例中,在步骤201中,根据第n阶段的字段解析信息中的各个报头类型对应的报头域字段,对报头进行解析获得待解析的报头类型对应的报头域字段。
202,根据报头域字段查询第n阶段的阶段流转信息,确定待解析的下一层报头类型和下一阶段解析的偏移地址。
在一个示例中,各个阶段的阶段流转信息保存在预设的阶段流转信息表中。预设的阶段流转信息表可如下表2所示但不限于表2所示。
表2:预设的阶段流转信息表
Figure PCTCN2022123455-appb-000002
Figure PCTCN2022123455-appb-000003
如表2所示的阶段流转信息表中包括不同报头类型的下一层报头类型、下一个阶段的偏移地址,此外还可以包括当前数据段是否解析完成的动作标志位,动作标志位置为1表示当前数据段解析完成,动作标志位置为0表示当前数据段解析未完成。这样在获得报头域字段后,可以通过在预设的阶段流转信息表中查找该报头域字段对应的阶段流转信息,获取待解析的下一层报头类型、下一个阶段的偏移地址和当前数据段是否解析完成的动作标志位。
在一个实施例中,如图3所示,上述步骤103中,根据偏移地址对报头进行第n+1阶段解析,可以包括:
301,在进行第n+1阶段解析时,将报头包含的待解析的报头域字段与第n+1阶段的报头域字段表匹配。
302,若报头包含的待解析的报头域字段为包含在第n+1阶段的报头域字段表的有效字段,则解析报头包含的待解析的报头域字段的内容。
本实施例中,在进行第n+1阶段解析时,可以将报头包含的待解析的报头域字段与预设的报头域字段表作对比,确定待解析的报头域字段是否与该报头域字段表中的某一行字段相符,若相符,则确定待解析的报头域字段为有效字段,否则确定待解析的报头域字段为无效字段。当报头包含的待解析的报头域字段为有效字段,则继续对报头进行解析出待解析的报头域字段的内容。
在一个实施例中,继续参见图3所示,方法还可以包括:
303,若报头包含的待解析的报头域字段为不包含在第n+1阶段的报头域字段表的无效字段,则停止第n+1阶段的解析。
本实施例中,当确定报头包含的待解析的报头域字段为无效字段时,则停止第n+1阶段的解析,并直接跳转到第n+2阶段进行判断。
在一个实施例中,如图4所示,方法还可以包括:
401,当接收的数据包大于分段解析的可处理报长时,将数据包按照预设长度划分为多个数据段。
可处理报长可以是不同报头类型对应的报头长度中的最大长度。这里,可处理报长取值为64字节,但本公开实施例中并不限于此。
这里,预设长度可以根据实际应用进行设定,例如将预设长度设定为与可处理报长相同的长度。
402,从第1个数据段开始进行报头的分段解析。
在一些示例中,从第1个数据段开始,执行步骤101至步骤104进行报头的分段解析,当第1个数据段解析完成,继续对第2个数据段进行报头的分段解析,依此类推,直至完成所有数据段的报头解析。
403,拼接多个数据段的分段解析的解析结果,得到报头的解析结果。
在一些示例中,当该数据包所有数据段都依次完成分阶段解析后,可对各个数据段的分段解析的解析结果拼接,最终获得该数据包的报头解析结果。
本公开实施例中,按照分段解析的可处理报长,将数据包分成多个固定长度的数据段,每个数据段依次进行分阶段解析,如此能够应对复杂的协议长度不定的数据包,并进一步地加快了数据解析的速度。
在一个实施例中,上述步骤103中,当下一层报头类型是第n+1阶段解析的报头类型,根据偏移地址对报头进行第n+1阶段解析,可以包括:
在本数据段进行第n+1阶段解析时,若根据下一阶段解析的偏移地址、下一层报头类型的报头长度和第n+1阶段的字段解析信息指示的解析长度,确定出待解析的字段部分位于下一个数据段时,结合本数据段及下一数据段进行第n+1阶段解析。
在一些示例中,在本数据段进行第n+1阶段解析时,根据下一层报头类型的报头长度与报头偏移量的和值是否大于第n+1阶段的字段解析信息指示的解析长度,确定待解析的字段是否部分位于下一个数据段,当待解析的字段部分位于下一个数据段,可以确定待解析的报头跨越本数据段和下一个数据段。
当下一层报头类型的报头长度与报头偏移量的和值大于第n+1阶段的字段解析信息指示的解析长度时,确定待解析的字段部分位于下一个数据段,也即是,确定待解析的报头信息被分割到本数据段及下一个数据段。
当下一层报头类型的报头长度与报头偏移量的和值小于或等于第n+1阶段的字段解析信息指示的解析长度,确定出待解析的字段全部位于下一个数据段。
由于数据分段,可能一个阶段待解析的报头会分别位于不同的数据段,此时就存在该阶段报头解析的跨段解析。
在一个实施例中,如图5所示,上述步骤中,结合本数据段及下一数据段进行第n+1阶段解析,可以包括:
501,根据偏移地址对本数据段进行第n+1阶段解析,得到指示第n+1阶段解析结果的第一部分字段,并确定第n+1阶段未完成解析。
502,在下一个数据段进入未完成解析的第n+1阶段后,根据第一部分字段的长度以及下一层报头类型的报头长度,继续对下一个数据段进行第n+1阶段解析,得到指示第n+1阶段解析结果的第二部分字段。
在一些示例中,根据下一层报头类型的报头长度与第一部分字段的长度之间的差值,继续对下一个数据段进行第n+1阶段解析,得到第二部分字段。
503,将第二部分字段拼接到第一部分字段的后面,得到第n+1阶段解析结果。
在一些示例中,将第一部分字段向左偏移,第二部分字段向右偏移,并将右偏移后的第二部分字段拼接到向左偏移后的第一部分字段的后面,得到完整的报头解析结果。
本实施例中,由于待解析的报头信息被分割到本数据段及下一个数据段,通过先对本数据段进行第n+1阶段解析,得到第一部分字段,然后在下一个数据段进入未完成解析的第n+1阶段后,对下一个数据段进行第n+1阶段解析,得到第二部分字段,再将第二部分字段拼接到第一部分字段之后,如此能够获取到完整的第n+1阶段解析结果。
在一个实施例中,上述步骤103中,当下一层报头类型是第n+1阶段解析的报头类型,根据偏移地址对报头进行第n+1阶段解析,可以包括:
在本数据段进行第n+1阶段解析时,若根据下一阶段解析的偏移地址、下一层报头类型的报头长度和第n+1阶段的字段解析信息指示的解析长度,确定出待解析的字段全部位于本数据段时,对本数据段进行第n+1阶段解析,得到第n+1阶段解析结果。
本实施例中,当确定出待解析的字段全部位于本数据段,只需对本数据段进行第n+1阶段解析,即可获取到完整的第n+1阶段解析结果。
综上,本公开实施例中,将数据包分段处理后,会存在报头被切割的情况,通过根据待解析的下一层报长类型对应的报头长度加上报头偏移量获得偏移后的长度,报头偏移后的长度如果大于数据段的长度,则该阶段的报头跨越了两个数据段,需要结合下一个数据段提取报头,没有跨越则直接根据报头偏移量从当前数据段提取报头。
下面,将结合相关具体示例说明本公开实施例提供的报文的分段解析方法。
参见图6所示,图6为本公开实施例提供的报文的分段解析方法的一个具体示例流程图。该方法可以包括如下步骤:
1、在本数据段进行第n+1阶段解析时,获取第n阶段解析结果中的待解析的下一层报头类型、报头偏移量及上个阶段是否解析完成的标志位。
第n阶段的标志位指示第n阶段完成了解析,即第n阶段操作是Prev_Stg_Done,那么第n+1阶段需要开始解析。若第n阶段操作是等待(Wait),在这种情况下,第n+1阶段需要等待,或者如果第n阶段操作是空操作指令(NO Operation,NOP),那么第n+1阶段不需要做任何事情,只需要发送数据包而不进行任何解析。
2、校验该报头类型是否属于第n+1阶段解析的报头类型,若是,则执行步骤3,否则,进入第n+2阶段的报头解析。
每个阶段都会预设多种可解析的报头类型,并给报头类型都设置了编号,可以通过校验报头类型的编号是否为第n+1阶段解析的报头类型,来判断是否在第n+1阶段进行解析操作,如果该编号不是第n+1阶段解析的报头类型,则不做处理直接流转到下一个阶段。
3、计算该报头类型的报头长度。
每种报头类型预设有对应的报头长度,根据输入的报头类型获得该报头类型的报头长度。
4、结合报头类型的报头长度及报头偏移量,判断报头类型是否跨越数据段。若为是,则执行步骤5,否则执行步骤6。
5、根据报头偏移量并结合当前数据段和下个数据段提取报头。
6、根据报头偏移量从当前数据段中提取报头。
7、根据报头类型和提取的报头获取报头域字段。
8、校验该报头域字段是否与预设的报头域字段表相符合,相符合,则执行步骤9,否则丢弃无效报头。
9、根据报头域字段找到对应的第n+2阶段的阶段信息表。
在获得有效的报头域字段后,查找对应的阶段流转信息表,获取下个阶段的报头类型、报头偏移量和当前数据段是否解析完成的标志位。
下面,将继续结合具体示例说明本公开实施例提供的报文的分段解析方法。
假设每个阶段解析的数据长度为64字节,以一个数据包穿越以太网、IPv4层协议和TCP层协议为例,由外到内的层层解析数据包。以太网层可能只经过以太网、也可能穿越一个VLAN或者两个VLAN,网络层可能包括ARP、IPv4和IPv6(Internet Protocol version 6,互联网协议第6版)协议,传输层可能包括ICMP、UDP、TCP和GRE(Generic Routing Encapsulation,通用路由封装)协议。阶段预设信息表中对这些协议都有不同的解析配置信息,以太网层解析的目的是获得源MAC地址和目的MAC地址,网络层的报头解析是为了获得源IP地址和目的IP地址,传输层的报头解析是为了获得源端口号和目的端口号。
一、第1阶段的报头解析
将数据包进入第1阶段,并初始化输入第1阶段的报头类型是以太网,报头偏移量为0和上一个阶段是否解析完成的标志位为1。具体的对应于该数据包所包含的以太网协议,阶段预设信息表中的内容设置如下表3所示。
表3:第1阶段的阶段预设信息
阶段 报头类型 报头长度 编号 报头域字段表 阶段流转信息表
第1阶段 以太网 14 0 如下表4所示 如下表5所示
表4:以太网报头的报头域字段
报头类型 帧类型[0] 掩码[0] 帧类型[0] 掩码[0] 帧类型[0] 掩码[0]
以太网 以太网0 16'hffff 0 0 0 0
表5:以太网报头的阶段流转信息
报头类型 动作标志位 下一个阶段报头类型 下一个阶段报头偏移量
以太网 1 IPv4 14
其中,以太网报头的报头结构体如下表6所示。
表6:预设的以太网报头的结构体
Figure PCTCN2022123455-appb-000004
经过第1阶段的报头解析后获得该数据包的以太网报头,然后根据以太网报头的结构体获得对应的以太网帧类型、源mac地址和目的mac地址。其中根据报头偏移量0字节和以太网报头的长度之和为14字节,小于64字节的数据包长度,判断该报头未跨越数据段,所以当以太网报头解析完成后,将第1阶段的动作标志位置1。在并向下一个阶段输入报头类型是IPv4,报头偏移量为14和上一个阶段是否解析完成的标志位为1。
二、第2阶段的报头解析
本阶段将解析IP报头,具体对应于该数据包所包含的IP协议,阶段预设信息表中的内容设置如下表7所示。
表7:第2阶段的阶段预设信息
阶段 报头类型 报头长度 编号 报头域字段表 阶段流转信息表
第2阶段 IPv4 20 1 如下表8所示 如下表9所示
表8:IPv4报头的报头域字段
报头类型 帧类型[0] 掩码[0] 帧类型[0] 掩码[0] 帧类型[0] 掩码[0]
IPv4 IPv40 16'h00ff 0 0 0 0
表9:IPv4报头的阶段流转信息
报头类型 动作标志位 下一层报头类型 下一个阶段报头偏移量
IPv4 1 TCP 34
其中,IPv4报头的报头结构体如下表10所示。
表10:预设的IPv4报头的结构体
Figure PCTCN2022123455-appb-000005
经过第2阶段的报头解析后获得该数据包的IPv4报头,然后根据IPv4报头的结构体获得对应的关键信息包括源IP地址和目的IP地址。其中根据报头偏移量14字节和以太网报头的长度之和为34字节,小于64字节的数据包长度,判断该报头未跨越数据段,所以当IPv4报头解析完成后,将第2阶段的动作标志位置1。并向下一个阶段输入报头类型是TCP,报头偏移量为34和上一个阶段是否解析完成的标志位为1。
三、第3阶段的报头解析
第3阶段将解析IP报头,具体对应于该数据包所包含的IP协议,阶段预设信息表中的内容设置如下表11所示。
表11:第3阶段的阶段预设信息
报头类型 报头长度 编号 报头域字段 阶段流转信息表
TCP 20 5 如下表12所示 如下表13所示
表12:TCP报头的报头域字段
报头类型 帧类型[0] 掩码[0] 帧类型[0] 掩码[0] 帧类型[0] 掩码[0]
TCP 0 0 0 0 0 0
注:TCP报头类型的报头没有帧类型。
表13:TCP报头的阶段流转信息
报头类型 动作标志位 下一层报头类型 下一个阶段报头偏移量
TCP 1 负载 54
其中,TCP报头的预设的结构体如表14所示。
表14:预设的TCP报头的结构体
Figure PCTCN2022123455-appb-000006
经过第3阶段的报头解析后获得该数据包的TCP报头,然后根据TCP报头的结构体,获得对应的关键信息包括源端口号和目的端口号。其中根据报头偏移量34字节和以太网报头的长度之和为54字节,小于64字节的数据包长度,判断该报头未跨越数据段,所以当以太网报头解析完成后,将当前阶段的动作标志位置1。并向下一个阶段输入报头类型是负载,报头偏移量为54和上一个阶段是否解析完成的标志位为1。
当解析到负载部分时,将不再进行报文的报头解析,直接将数据流转到下一个阶段,直至最后一个阶段。该数据包经过该分段解析后,获得了相应的以太网报头、IPv4报头和TCP报头,并获得关键信息源MAC地址和目的MAC地址、源IP地址和目的IP地址和源端口号和目的端口号,便于后续的数据的转发和处理。
在一个实施例中,提供了一种报文的分段解析装置;待解析的报文包括:报头;如图7所示,装置包括阶段解析模块701;阶段解析模块701被配置为:
根据解析配置信息,对报头进行第n阶段解析得到第n阶段解析结果,其中,当n小于N时,第n阶段解析结果包括:第n阶段解析出的报头信息、报文内待解析的下一层报头类型及下一阶段解析的偏移地址;其中,N为报头的最大解析阶段数;
当下一层报头类型不是第n+1阶段解析的报头类型,跳过对报头的第n+1阶段解,并进入到第n+2阶段解析;
当下一层报头类型是第n+1阶段解析的报头类型,根据偏移地址对报头进行第n+1阶段解析;
当完成第N阶段解析或前N-1层协议解析确定跳过第N阶段解析时,停止对报头的本次分段解析。
在一个实施例中,解析配置信息包括:字段解析信息及阶段流转信息;
阶段解析模块701被配置为:
根据第n阶段的字段解析信息以及第n阶段待解析的报头类型,对报头进行报头域字段解析;其中,报头域字段包括:帧类型、报头长度、报头编号和/或掩码;
根据报头域字段查询第n阶段的阶段流转信息,确定待解析的下一层报头类型和下一阶段解析的偏移地址。
在一个实施例中,阶段解析模块701被配置为:
在进行第n+1阶段解析时,将报头包含的待解析的报头域字段与第n+1阶段的报头域字段表匹配;
若报头包含的待解析的报头域字段为包含在第n+1阶段的报头域字段表的有效字段,则解析报头包含的待解析的报头域字段的内容。
在一个实施例中,阶段解析模块701还被配置为:
若报头包含的待解析的报头域字段为不包含在第n+1阶段的报头域字段表的无效字段,则停止第n+1阶段的解析。
在一个实施例中,装置还包括数据划分模块700和结果拼接模块702;
数据划分模块700,被配置为当接收的数据包大于分段解析的可处理报长时,将数据包按照预设长度划分为多个数据段;
阶段解析模块701,被配置为从第1个数据段开始进行报头的分段解析;
结果拼接模块702,被配置为拼接多个数据段的分段解析的解析结果,得到报头的解析结果。
在一个实施例中,阶段解析模块701被配置为:
在本数据段进行第n+1阶段解析时,若根据下一阶段解析的偏移地址、下一层报头类型的报头长度和第n+1阶段的字段解析信息指示的解析长度,确定出待解析的字段部分位于下一个数据段时,结合本数据段及下一数据段进行第n+1阶段解析。
在一个实施例中,阶段解析模块701被配置为:
根据偏移地址对本数据段进行第n+1阶段解析,得到指示第n+1阶段解析结果的第一部分字段,并确定第n+1阶段未完成解析;
在下一个数据段进入未完成解析的第n+1阶段后,根据第一部分字段的长度以及下一层报头类型的报头长度,继续对下一个数据段进行第n+1阶段解析,得到指示第n+1阶段解析结果的第二部分字段;
将第二部分字段拼接到第一部分字段的后面,得到第n+1阶段解析结果。
在一个实施例中,阶段解析模块701被配置为:
在本数据段进行第n+1阶段解析时,若根据下一阶段解析的偏移地址、下一层报头类型的报头长度和第n+1阶段的字段解析信息指示的解析长度,确定出待解析的字段全部位于本数据段时,对本数据段进行第n+1阶段解析,得到第n+1阶段解析结果。
接下来,将结合图8,进一步对本公开实施例提供的报文的分段解析装置中的阶段解析模块进 行说明。
如图8所示,阶段解析模块包括预判单元、报头提取单元和下阶段信息项提取单元。其中:
预判单元,被配置为根据输入的当前阶段的解析信息包括的报头类型、报头偏移量以及上阶段解析完成标志位,结合阶段预设信息表中的当前阶段对应的阶段预设信息,判断该报头类型是否需要解析,并确定需要解析的报头类型对应的报头长度,以及获取用于指示是否需要跨越数据段进行报头解析的跨字段标志位。
其中,阶段预设信息表是通过接收用户的报文解析配置信息生成的,报文解析配置信息包括每个阶段可解析的报头类型、每个报头类型对应的报头长度、每个报头类型对应的报头域字段、每个报头域对应的阶段流转信息表。
报头提取单元,被配置为当预判模块的预判结果指示该报头类型可解析时,根据预判结果中的报头类型对应的报头长度及跨字段标志位进行报头提取,获取报头类型的报头、报头域字段和该报头对应的关键信息。
下阶段信息项提取单元,被配置为根据报头提取单元针对当前阶段所获得的报头域字段,并结合阶段预设信息表中的报头域字段,提取阶段流转信息表包括的下一个阶段的报头类型、报头偏移量,并给出是当前否解析完成的标志位。
需要说明的是:上述实施例提供的报文的分段解析装置在实现报文的分段解析方法时,仅以上述各程序模块的划分进行举例说明,实际应用中,可以根据需要而将上述处理分配由不同的程序模块完成,即将报文的分段解析装置的内部结构划分成不同的程序模块,以完成以上描述的全部或者部分处理。另外,上述实施例提供的装置与相应方法的实施例属于同一构思,其具体实现过程详见方法实施例,这里不再赘述。
图9为本公开实施例提供的一种计算机设备的结构示意图;如图9所示,计算机设备900包括:处理器901和用于存储能够在处理器上运行的计算机程序的存储器902;其中,处理器901用于运行计算机程序时,执行如下操作:
根据解析配置信息,对报文包括的报头进行第n阶段解析得到第n阶段解析结果,其中,当n小于N时,第n阶段解析结果包括:第n阶段解析出的报头信息、报文内待解析的下一层报头类型及下一阶段解析的偏移地址;其中,N为报头的最大解析阶段数;
当下一层报头类型不是第n+1阶段解析的报头类型,跳过对报头的第n+1阶段解析,并进入到第n+2阶段解析;
当下一层报头类型是第n+1阶段解析的报头类型,根据偏移地址对报头进行第n+1阶段解析;
当完成第N阶段解析或前N-1层协议解析确定跳过第N阶段解析时,停止对报头的本次分段解析。
实际应用时,计算机设备900还可以包括:至少一个网络接口903。计算机设备900中的各个组件通过总线系统904耦合在一起。可理解,总线系统904用于实现这些组件之间的连接通信。总线系统904除包括数据总线之外,还包括电源总线、控制总线和状态信号总线。但是为了清楚说明 起见,在图9中将各种总线都标为总线系统904。其中,处理器901的个数可以为至少一个。网络接口903用于计算机设备900与其他设备之间有线或无线方式的通信。
本公开实施例中的存储器902用于存储各种类型的数据以支持计算机设备900的操作。
上述本公开实施例揭示的方法可以应用于处理器901中,或者由处理器901实现。处理器901可能是一种集成电路芯片,具有信号的处理能力。在实现过程中,上述方法的各步骤可以通过处理器901中的硬件的集成逻辑电路或者软件形式的指令完成。上述的处理器901可以是通用处理器、数字信号处理器(DSP,DiGital Signal Processor),或者其他可编程逻辑器件、分立门或者晶体管逻辑器件、分立硬件组件等。处理器901可以实现或者执行本公开实施例中的公开的各方法、步骤及逻辑框图。通用处理器可以是微处理器或者任何常规的处理器等。结合本公开实施例所公开的方法的步骤,可以直接体现为硬件译码处理器执行完成,或者用译码处理器中的硬件及软件模块组合执行完成。软件模块可以位于存储介质中,该存储介质位于存储器902,处理器901读取存储器902中的信息,结合其硬件完成前述方法的步骤。
在示例性实施例中,计算机设备900可以被一个或多个应用专用集成电路(ASIC,Application Specific Integrated Circuit)、DSP、可编程逻辑器件(PLD,Programmable Logic Device)、复杂可编程逻辑器件(CPLD,Complex Programmable Logic Device)、现场可编程门阵列(FPGA,Field-Programmable Gate Array)、通用处理器、控制器、微控制器(MCU,Micro Controller Unit)、微处理器(Microprocessor)、或其他电子元件实现,用于执行前述方法。
本公开实施例还提供了一种计算机可读存储介质,其上存储有计算机程序;计算机可读存储介质应用于报文的分段解析方法时,计算机程序被处理器运行时,执行如下操作:
根据解析配置信息,对报文包括的报头进行第n阶段解析得到第n阶段解析结果,其中,当n小于N时,第n阶段解析结果包括:第n阶段解析出的报头信息、报文内待解析的下一层报头类型及下一阶段解析的偏移地址;其中,N为报头的最大解析阶段数;
当下一层报头类型不是第n+1阶段解析的报头类型,跳过对报头的第n+1阶段解析,并进入到第n+2阶段解析;
当下一层报头类型是第n+1阶段解析的报头类型,根据偏移地址对报头进行第n+1阶段解析;
当完成第N阶段解析或前N-1层协议解析确定跳过第N阶段解析时,停止对报头的本次分段解析。
在本公开所提供的几个实施例中,应该理解到,所揭露的装置和方法,可以通过其它的方式实现。以上所描述的设备实施例仅仅是示意性的,例如,单元的划分,仅仅为一种逻辑功能划分,实际实现时可以有另外的划分方式,如:多个单元或组件可以结合,或可以集成到另一个系统,或一些特征可以忽略,或不执行。另外,所显示或讨论的各组成部分相互之间的耦合、或直接耦合、或通信连接可以是通过一些接口,设备或单元的间接耦合或通信连接,可以是电性的、机械的或其它形式的。
上述作为分离部件说明的单元可以是、或也可以不是物理上分开的,作为单元显示的部件可以 是、或也可以不是物理单元,即可以位于一个地方,也可以分布到多个网络单元上;可以根据实际的需要选择其中的部分或全部单元来实现本实施例方案的目的。
另外,在本公开各实施例中的各功能单元可以全部集成在一个处理单元中,也可以是各单元分别单独作为一个单元,也可以两个或两个以上单元集成在一个单元中;上述集成的单元既可以采用硬件的形式实现,也可以采用硬件加软件功能单元的形式实现。
本领域普通技术人员可以理解:实现上述方法实施例的全部或部分步骤可以通过程序指令相关的硬件来完成,前述的程序可以存储于一计算机可读取存储介质中,该程序在执行时,执行包括上述方法实施例的步骤;而前述的存储介质包括:移动存储设备、只读存储器(ROM,Read-Only Memory)、随机存取存储器(RAM,Random Access Memory)、磁碟或者光盘等各种可以存储程序代码的介质。
或者,本公开上述集成的单元如果以软件功能模块的形式实现并作为独立的产品销售或使用时,也可以存储在一个计算机可读取存储介质中。基于这样的理解,本公开实施例的技术方案本质上或者说对现有技术做出贡献的部分可以以软件产品的形式体现出来,该计算机软件产品存储在一个存储介质中,包括若干指令用以使得一台计算机设备(可以是个人计算机、服务器、或者网络设备等)执行本公开各个实施例方法的全部或部分。而前述的存储介质包括:移动存储设备、ROM、RAM、磁碟或者光盘等各种可以存储程序代码的介质。
需要说明的是:“第一”、“第二”等是用于区别类似的对象,而不必用于描述特定的顺序或先后次序。
另外,本公开实施例所记载的技术方案之间,在不冲突的情况下,可以任意组合。
以上,仅为本公开的具体实施方式,但本公开的保护范围并不局限于此,任何熟悉本技术领域的技术人员在本公开揭露的技术范围内,可轻易想到变化或替换,都应涵盖在本公开的保护范围之内。因此,本公开的保护范围应以权利要求的保护范围为准。

Claims (11)

  1. 一种报文的分段解析方法,其中,待解析的报文包括:报头;所述方法包括:
    根据解析配置信息,对所述报头进行第n阶段解析得到第n阶段解析结果,其中,当所述n小于N时,所述第n阶段解析结果包括:所述第n阶段解析出的报头信息、所述报文内待解析的下一层报头类型及下一阶段解析的偏移地址;其中,所述N为所述报头的最大解析阶段数;
    当所述下一层报头类型不是第n+1阶段解析的报头类型,跳过对所述报头的第n+1阶段解析,并进入到第n+2阶段解析;
    当所述下一层报头类型是第n+1阶段解析的报头类型,根据所述偏移地址对所述报头进行第n+1阶段解析;
    当完成所述第N阶段解析或前N-1层协议解析确定跳过第N阶段解析时,停止对所述报头的本次分段解析。
  2. 根据权利要求1所述的方法,其中,所述解析配置信息包括:字段解析信息及阶段流转信息;
    所述根据解析配置信息,对所述报头进行第n阶段解析得到第n阶段解析结果,包括:
    根据第n阶段的字段解析信息以及第n阶段待解析的报头类型,对所述报头进行报头域字段解析;其中,所述报头域字段包括:帧类型、报头长度、报头编号和/或掩码;
    根据所述报头域字段查询所述第n阶段的阶段流转信息,确定待解析的所述下一层报头类型和所述下一阶段解析的偏移地址。
  3. 根据权利要求2所述的方法,其中,所述根据所述偏移地址对所述报头进行第n+1阶段解析,包括:
    在进行第n+1阶段解析时,将所述报头包含的待解析的报头域字段与所述第n+1阶段的报头域字段表匹配;
    若所述报头包含的待解析的报头域字段为包含在所述第n+1阶段的报头域字段表的有效字段,则解析所述报头包含的待解析的报头域字段的内容。
  4. 根据权利要求3所述的方法,其中,所述方法还包括:
    若所述报头包含的待解析的报头域字段为不包含在所述第n+1阶段的报头域字段表的无效字段,则停止所述第n+1阶段的解析。
  5. 根据权利要求1至4任一所述的方法,其中,所述方法还包括:
    当接收的数据包大于分段解析的可处理报长时,将所述数据包按照预设长度划分为多个数据段;
    从第1个所述数据段开始进行所述报头的分段解析;
    拼接多个所述数据段的分段解析的解析结果,得到所述报头的解析结果。
  6. 根据权利要求5所述的方法,其中,所述当所述下一层报头类型是第n+1阶段解析的报头类型,根据所述偏移地址对所述报头进行第n+1阶段解析,包括:
    在本数据段进行第n+1阶段解析时,若根据所述下一阶段解析的偏移地址、所述下一层报头类 型的报头长度和第n+1阶段的字段解析信息指示的解析长度,确定出待解析的字段部分位于下一个数据段时,结合所述本数据段及所述下一数据段进行第n+1阶段解析。
  7. 根据权利要求6所述的方法,其中,所述结合所述本数据段及所述下一数据段进行第n+1阶段解析,包括:
    根据所述偏移地址对所述本数据段进行第n+1阶段解析,得到指示所述第n+1阶段解析结果的第一部分字段,并确定所述第n+1阶段未完成解析;
    在所述下一个数据段进入未完成解析的所述第n+1阶段后,根据所述第一部分字段的长度以及所述下一层报头类型的报头长度,继续对所述下一个数据段进行第n+1阶段解析,得到指示所述第n+1阶段解析结果的第二部分字段;
    将所述第二部分字段拼接到所述第一部分字段的后面,得到所述第n+1阶段解析结果。
  8. 根据权利要求5所述的方法,其中,所述当所述下一层报头类型是第n+1阶段解析的报头类型,根据所述偏移地址对所述报头进行第n+1阶段解析,包括:
    在本数据段进行第n+1阶段解析时,若根据所述下一阶段解析的偏移地址、所述下一层报头类型的报头长度和第n+1阶段的字段解析信息指示的解析长度,确定出待解析的字段全部位于所述本数据段时,对所述本数据段进行第n+1阶段解析,得到所述第n+1阶段解析结果。
  9. 一种报文的分段解析装置,其中,待解析的报文包括:报头;所述装置包括阶段解析模块;所述阶段解析模块被配置为:
    根据解析配置信息,对所述报头进行第n阶段解析得到第n阶段解析结果,其中,当所述n小于N时,所述第n阶段解析结果包括:所述第n阶段解析出的报头信息、所述报文内待解析的下一层报头类型及下一阶段解析的偏移地址;其中,所述N为所述报头的最大解析阶段数;
    当所述下一层报头类型不是第n+1阶段解析的报头类型,跳过所述阶段解析模块对所述报头的第n+1阶段解,并进入到第n+2阶段解析;
    当所述下一层报头类型是第n+1阶段解析的报头类型,执行所述阶段解析模块根据所述偏移地址对所述报头进行第n+1阶段解析;
    当完成所述第N阶段解析或前N-1层协议解析确定跳过第N阶段解析时,停止所述阶段解析模块对所述报头的本次分段解析。
  10. 一种计算机设备,包括存储器、处理器及存储在存储器上并可在处理器上运行的计算机程序,其中,所述处理器执行所述程序时实现权利要求1至8任一项所述报文的分段解析方法的步骤。
  11. 一种计算机可读存储介质,其上存储有计算机程序,其中,所述计算机程序被处理器执行时实现权利要求1至8任一项所述报文的分段解析方法的步骤。
PCT/CN2022/123455 2021-10-25 2022-09-30 报文的分段解析方法、装置、设备和存储介质 WO2023071714A1 (zh)

Applications Claiming Priority (2)

Application Number Priority Date Filing Date Title
CN202111242584.XA CN116033044A (zh) 2021-10-25 2021-10-25 报文的分段解析方法、装置、设备和存储介质
CN202111242584.X 2021-10-25

Publications (1)

Publication Number Publication Date
WO2023071714A1 true WO2023071714A1 (zh) 2023-05-04

Family

ID=86078140

Family Applications (1)

Application Number Title Priority Date Filing Date
PCT/CN2022/123455 WO2023071714A1 (zh) 2021-10-25 2022-09-30 报文的分段解析方法、装置、设备和存储介质

Country Status (2)

Country Link
CN (1) CN116033044A (zh)
WO (1) WO2023071714A1 (zh)

Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN104702600A (zh) * 2015-03-02 2015-06-10 国家计算机网络与信息安全管理中心 网络数据报文解析方法及装置
US20150341265A1 (en) * 2014-05-22 2015-11-26 International Business Machines Corporation Skipping and parsing internet protocol version 6 extension headers to reach upper layer headers
CN106549817A (zh) * 2015-09-21 2017-03-29 深圳市中兴微电子技术有限公司 报文识别方法及装置
CN111245723A (zh) * 2020-03-10 2020-06-05 盛科网络(苏州)有限公司 一种分段路由ipfix的芯片实现方法及装置
CN112136108A (zh) * 2018-10-31 2020-12-25 华为技术有限公司 一种报头解析装置及方法

Patent Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20150341265A1 (en) * 2014-05-22 2015-11-26 International Business Machines Corporation Skipping and parsing internet protocol version 6 extension headers to reach upper layer headers
CN104702600A (zh) * 2015-03-02 2015-06-10 国家计算机网络与信息安全管理中心 网络数据报文解析方法及装置
CN106549817A (zh) * 2015-09-21 2017-03-29 深圳市中兴微电子技术有限公司 报文识别方法及装置
CN112136108A (zh) * 2018-10-31 2020-12-25 华为技术有限公司 一种报头解析装置及方法
CN111245723A (zh) * 2020-03-10 2020-06-05 盛科网络(苏州)有限公司 一种分段路由ipfix的芯片实现方法及装置

Also Published As

Publication number Publication date
CN116033044A (zh) 2023-04-28

Similar Documents

Publication Publication Date Title
US10764181B2 (en) Pipelined evaluations for algorithmic forwarding route lookup
US10673650B2 (en) Programmable tunnel creation for hardware-based packet processing
US8743882B1 (en) Packet header altering device
EP3014819B1 (en) Method for packet tunneling through software defined network method of intelligently controlling flow of a packet through software defined network and system
US11729300B2 (en) Generating programmatically defined fields of metadata for network packets
US9860168B1 (en) Network packet header modification for hardware-based packet processing
US7843915B2 (en) Packet filtering by applying filter rules to a packet bytestream
WO2015125801A1 (ja) ネットワーク制御方法、ネットワークシステムと装置及びプログラム
US9154586B2 (en) Method for parsing network packets having future defined tags
US9819587B1 (en) Indirect destination determinations to forward tunneled network packets
US8014282B2 (en) Hashing packet contents to determine a processor
CN106713144A (zh) 一种报文出口信息的读写方法及转发引擎
WO2020087400A1 (zh) 一种报头解析装置及方法
US9906443B1 (en) Forwarding table updates during live packet stream processing
US10887234B1 (en) Programmatic selection of load balancing output amongst forwarding paths
CN108737239B (zh) 一种报文转发方法及装置
WO2023071714A1 (zh) 报文的分段解析方法、装置、设备和存储介质
US9954817B2 (en) Software receive side scaling for packet re-dispatching
US7706409B2 (en) System and method for parsing, filtering, and computing the checksum in a host Ethernet adapter (HEA)
US10608937B1 (en) Determining destination resolution stages for forwarding decisions
US11962673B2 (en) Packet tunneling and decapsulation with split-horizon attributes
CN114363273A (zh) 处理报文的方法和芯片
CN117240947B (zh) 一种报文处理方法、装置及介质
CN116471344B (zh) 一种数据报文的关键字提取方法、装置及介质
EP4099644A1 (en) Packet processing method and related apparatus

Legal Events

Date Code Title Description
121 Ep: the epo has been informed by wipo that ep was designated in this application

Ref document number: 22885596

Country of ref document: EP

Kind code of ref document: A1