Message analysis method and device based on state machine, and electronic equipment
Through the state machine-based message analysis method, the link layer encapsulation format and destination MAC address of the message are parsed, and different link layer encapsulation formats and protocols are applied, which solves the singularity and complexity of the message analysis method in the existing technology. The problem has achieved a message analysis process that is widely applicable and easy to understand.
Patent Information
- Application Number
- CN202310662625.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2023-06-05
- Publication Date
- 2024-12-06
- Estimated Expiration
- 2043-06-05
AI Technical Summary
The existing packet analysis method can only parse a standard packet and cannot be generalized, and the complex resolution process is not conducive to modification and error checking.
Using the state machine-based message analysis method, the link layer encapsulation format and destination MAC address are resolved by the target field in the received message, and the message is sent to the corresponding state machine for further analysis based on this information, and different link layers are applicable. Encapsulation format and protocol.
It realizes the universality of the message analysis method and simplification of the analysis process, which is easy to understand and modify, and has a wide range of applications.
Smart Images

Figure CN119094633A_ABST
Abstract
Description
Technical Field
[0001] The embodiments of the present application relate to the technical field of message parsing, and more specifically, to a message parsing method, device and electronic device based on a state machine. Background Art
[0002] A message is a unit of data exchanged and transmitted in a network, and is also a unit of network transmission. A message contains the complete data information to be sent, and its length does not need to be consistent. During the transmission process, the message will be continuously encapsulated into groups, packets, and frames for transmission.
[0003] At present, when parsing a message, an existing message parsing method can only parse a standard message. Since there are many message standards, the message parsing method cannot be universal. Therefore, before parsing the message, other methods are needed to identify the message standard of the message to be parsed, and then select the corresponding message parsing method according to the message standard of the message to be parsed to parse the message to be parsed. The existing message parsing method has a small scope of application, and the process of parsing the message is obscure and difficult to understand, which is not conducive to modification and error checking. Summary of the invention
[0004] One purpose of the embodiments of the present application is to provide a new technical solution for a message parsing method, device and electronic device based on a state machine.
[0005] According to a first aspect of the present application, a state machine-based message parsing method is provided, the method comprising:
[0006] The first state machine receives a first message, wherein the first message includes a plurality of fields;
[0007] The first state machine parses the first target field in the first message to obtain a link layer encapsulation format of the first message;
[0008] According to the link layer encapsulation format, the first state machine sends the second message to a first target state machine corresponding to the link layer encapsulation format, wherein the second message is a message composed of other fields in the first message except the first target field;
[0009] The first target state machine parses the second target field in the second message to obtain the destination MAC address and link layer protocol of the second message;
[0010] When the destination MAC address meets the preset conditions, the first target state machine sends the third message to the second target state machine corresponding to the link layer protocol according to the link layer protocol, wherein the third message is a message composed of other fields in the second message except the second target field.
[0011] Optionally, the destination MAC address satisfies a preset condition including any one of the following:
[0012] The destination MAC address is the local address;
[0013] The destination MAC address is a broadcast address.
[0014] Optionally, the link layer encapsulation format is any one of RFC894, RFC802 or RFC893;
[0015] The first state machine sending the second message to a first target state machine corresponding to the link layer encapsulation format according to the link layer encapsulation format includes:
[0016] When the link layer encapsulation format is RFC894, the first state machine sends the second message to the RFC894 state machine;
[0017] When the link layer encapsulation format is RFC802, the first state machine sends the second message to the RFC802 state machine;
[0018] When the link layer encapsulation format is RFC893, the first state machine sends the second message to the RFC893 state machine.
[0019] Optionally, the link layer protocol is any one of the IP protocol, the ARP protocol, and the RARP protocol:
[0020] The first target state machine sends the third message to a second target state machine corresponding to the link layer protocol according to the link layer protocol, including:
[0021] When the link layer protocol is the IP protocol, the first target state machine sends the third message to the IP state machine;
[0022] When the link layer protocol is the ARP protocol, the first target state machine sends the third message to the ARP state machine;
[0023] When the link layer protocol is the RARP protocol, the first target state machine sends the third message to the RARP state machine.
[0024] Optionally, when the link layer protocol is the IP protocol, after the first target state machine sends the third message to the IP state machine, the method further includes:
[0025] The IP state machine parses the third target field in the third message to obtain the IP protocol type, lifetime value and header length value of the third message;
[0026] When the lifetime value is a preset lifetime value and the header length value is greater than the preset length value, the IP state machine parses the required fields and the optional fields in the third message respectively to obtain the source IP, destination IP, header check, sending path and sending time of the third message;
[0027] When the lifetime value is a preset lifetime value and the header length value is less than or equal to the preset length value, the IP state machine sends the fourth message to a third target state machine corresponding to the IP protocol type according to the IP protocol type, wherein the fourth message is a message composed of other fields in the third message except the third target field.
[0028] Optionally, the IP protocol type is any one of ICMP protocol, UDP protocol or TCP protocol;
[0029] The IP state machine sends the fourth message to a third target state machine corresponding to the IP protocol type according to the IP protocol type, including:
[0030] When the IP protocol type is the ICMP protocol, the IP state machine sends the fourth message to the ICMP state machine, wherein the ICMP state machine is used to parse the fourth message to obtain the message type, code number, check code and application layer data of the fourth message;
[0031] In the case where the IP protocol type is the UDP protocol, the IP state machine sends the fourth message to the UDP state machine, wherein the UDP state machine is used to parse the fourth message to obtain application layer data of the fourth message;
[0032] When the IP protocol type is the TCP protocol, the IP state machine sends the fourth message to the TCP state machine, wherein the TCP state machine is used to parse the fourth message to obtain the source port, destination port, message sequence number, message confirmation number, offset and window size of the fourth message.
[0033] Optionally, when the link layer protocol is an ARP protocol, after the first target state machine sends the third message to the ARP state machine, the method further includes:
[0034] In the case where the third message is an ARP request message, the ARP state machine parses the third message to obtain an IP address of the third message;
[0035] The ARP state machine obtains a local routing table, and generates a target ARP reply message according to the third message, the second message, and the first message when a MAC address corresponding to the IP address exists in the local routing table;
[0036] In the case that the third message is an ARP reply message, the ARP state machine obtains the local routing table and updates the local routing table according to the third message.
[0037] Optionally, when the link layer protocol is the RARP protocol, after the first target state machine sends the third message to the RARP state machine, the method further includes:
[0038] In the case where the third message is a RARP request message, the RARP state machine parses the third message to obtain a MAC address of the third message;
[0039] The RARP state machine obtains a local routing table, and generates a target RARP response message according to the third message, the second message, and the first message when the IP address corresponding to the MAC address exists in the local routing table;
[0040] In the case that the third message is a RARP response message, the RARP state machine obtains the local routing table and updates the local routing table according to the third message.
[0041] According to a second aspect of the present application, a state machine-based message parsing device is also provided, the device comprising a first state machine, a first target state machine, and a second target state machine:
[0042] The first state machine is used to receive a first message, the first message including a plurality of fields; and is also used to parse a first target field in the first message to obtain a link layer encapsulation format of the first message; and send a second message to a first target state machine corresponding to the link layer encapsulation format according to the link layer encapsulation format, wherein the second message is a message composed of other fields in the first message except the first target field;
[0043] The first target state machine is used to parse the second target field in the second message to obtain the destination MAC address and link layer protocol of the second message; and, when the destination MAC address meets a preset condition, send a third message to the second target state machine corresponding to the link layer protocol according to the link layer protocol, wherein the third message is a message composed of other fields in the second message except the second target field.
[0044] According to a third aspect of the present application, an electronic device is also provided, comprising the state machine-based message parsing device as described in the second aspect.
[0045] A beneficial effect of an embodiment of the present application is that the first target field in the first message is parsed by the first state machine to obtain the link layer encapsulation format of the first message, and the second message composed of other unparsed fields in the first message is sent to the first target state machine corresponding to its link layer encapsulation format, so that the first target state machine parses the second target field in the second message to obtain the destination MAC address and link layer protocol of the second message, and when the destination MAC address meets the preset conditions, according to the link layer protocol, the third message composed of other unparsed fields in the second message is sent to the second target state machine corresponding to the link layer protocol, so that the second target state machine parses the third message. The present application parses the first message by the first state machine to obtain the link layer encapsulation format of the first message, and then sends the second message to a different first target state machine according to the link layer encapsulation format of the first message, so that the message parsing method can be applied to messages with different link layer encapsulation formats, with a wide range of applications, and the message parsing method is mainly implemented based on the state machine, the message parsing process is easy to understand, and modification and error checking are convenient.
[0046] Other features and advantages of the embodiments of the present application will become apparent from the following detailed description of exemplary embodiments of the present application with reference to the accompanying drawings. BRIEF DESCRIPTION OF THE DRAWINGS
[0047] The accompanying drawings, which are incorporated in and constitute a part of the specification, illustrate embodiments of the present application and, together with the description, serve to explain the principles of the embodiments of the present application.
[0048] Figure 1 This is one of the flow charts of a message parsing method based on a state machine provided in an embodiment of the present application;
[0049] Figure 2 A second flow chart of a message parsing method based on a state machine provided in an embodiment of the present application;
[0050] Figure 3A third flowchart of a message parsing method based on a state machine provided in an embodiment of the present application;
[0051] Figure 4 A schematic diagram of the structure of a message parsing device based on a state machine provided in an embodiment of the present application. DETAILED DESCRIPTION
[0052] Various exemplary embodiments of the present application will now be described in detail with reference to the accompanying drawings. It should be noted that the relative arrangement of components and steps, numerical expressions and numerical values set forth in these embodiments do not limit the scope of the present invention unless otherwise specifically stated.
[0053] The following description of at least one exemplary embodiment is merely illustrative in nature and is in no way intended to limit the invention, its application, or uses.
[0054] Technologies, methods, and equipment known to ordinary technicians in the relevant art may not be discussed in detail, but where appropriate, the technologies, methods, and equipment should be considered as part of the specification.
[0055] In all examples shown and discussed herein, any specific values should be interpreted as merely exemplary and not limiting. Therefore, other examples of the exemplary embodiments may have different values.
[0056] It should be noted that like reference numerals and letters refer to similar items in the following figures, and therefore, once an item is defined in one figure, it need not be further discussed in subsequent figures.
[0057] <Method Example>
[0058] The following, in conjunction with the accompanying drawings, describes in detail the state machine-based message parsing method provided in the embodiment of the present application through specific embodiments and their application scenarios.
[0059] like Figure 1 As shown, it is one of the flow charts of a message parsing method based on a state machine provided in an embodiment of the present application. This embodiment mainly uses the method applied to a message parsing device as an example. Figure 1 As shown, the message parsing method may include the following steps 1100 to 1500, which are described in detail below.
[0060] Step 1100: A first state machine receives a first message, where the first message includes multiple fields.
[0061] In this embodiment, the first message is an RFC-based message, and the first message is encapsulated by multiple fields.
[0062] Step 1200: The first state machine parses the first target field in the first message to obtain a link layer encapsulation format of the first message.
[0063] In this embodiment, the first target field carries information about the link layer encapsulation format of the first message, and the first state machine is used to parse the first target field in the first message to obtain the link layer encapsulation format of the first message.
[0064] Step 1300: According to the link layer encapsulation format, the first state machine sends a second message to a first target state machine corresponding to the link layer encapsulation format, wherein the second message is a message composed of other fields in the first message except the first target field.
[0065] In this embodiment, it should be noted that the second message is a message composed of unparsed fields in the first message.
[0066] For example, in step 1100, the first message received by the first state machine is A1, A2, A3, A4, A5 and A6, and A1, A2, A3, A4, A5 and A6 are respectively a field in the first message; in step 1200, the first state machine parses A1 to obtain the link layer encapsulation format of the first message, wherein A1 is the first target field in the first message, and the A2, A3, A4, A5 and A6 fields in the first message constitute the second message, and the first state machine sends the second message to the state machine corresponding to the link layer encapsulation format of the first message according to the link layer encapsulation format of the first message.
[0067] In one embodiment, the link layer encapsulation format is any one of RFC894, RFC802 or RFC893.
[0068] Step 1300, according to the link layer encapsulation format, the first state machine sends the second message to the first target state machine corresponding to the link layer encapsulation format, specifically including steps 1310 to 1330.
[0069] Step 1310: When the link layer encapsulation format is RFC894, the first state machine sends the second message to the RFC894 state machine.
[0070] In this embodiment, when the link layer encapsulation format of the first message parsed by the first state machine is the RFC894 encapsulation format, the first state machine sends the second message to the RFC894 state machine so that the RFC894 state machine can parse the second message.
[0071] Step 1320: When the link layer encapsulation format is RFC802, the first state machine sends the second message to the RFC802 state machine.
[0072] In this embodiment, when the link layer encapsulation format of the first message parsed by the first state machine is the RFC802 (1042) encapsulation format, the first state machine sends the second message to the RFC802 state machine so that the RFC802 state machine can parse the second message.
[0073] Step 1330: When the link layer encapsulation format is RFC893, the first state machine sends the second message to the RFC893 state machine.
[0074] In this embodiment, when the link layer encapsulation format of the first message parsed by the first state machine is the RFC893 encapsulation format, the first state machine sends the second message to the RFC893 state machine so that the RFC893 state machine can parse the second message.
[0075] In this embodiment, it should be noted that when the link layer encapsulation format of the first message is other encapsulation formats except RFC894, RFC802 or RFC893, the first state machine ends parsing and sending the first message.
[0076] In this embodiment, the second message is sent to the RFC894 state machine, RFC802 state machine or RFC893 state machine corresponding to the link layer encapsulation format of the first message through the first state machine, so as to classify the second message according to the encapsulation format of the first link layer, and parse the second message through the RFC894 state machine, RFC802 state machine or RFC893 matching the type of the second message, with fast parsing speed and wide application range.
[0077] Step 1400: The first target state machine parses the second target field in the second message to obtain the destination MAC address and link layer protocol of the second message.
[0078] In this embodiment, the RFC894 state machine, the RFC802 state machine, and the RFC893 state machine are all used to parse the second target field in the second message to obtain the destination MAC address of the second message and the link layer protocol of the second message.
[0079] In this embodiment, it should be noted that the RFC894 state machine, the RFC802 state machine and the RFC893 state machine can also parse the second target field in the second message to obtain the source MAC address of the second message, and the source MAC address of the second message is temporarily stored in the first state machine as a global variable.
[0080] The global variable may affect the first state machine, and the determination results of the first target state machine, the second target state machine, and the third target state machine associated with the first state machine.
[0081] Step 1500, when the destination MAC address meets the preset conditions, the first target state machine sends the third message to the second target state machine corresponding to the link layer protocol according to the link layer protocol, wherein the third message is a message composed of other fields in the second message except the second target field.
[0082] In an embodiment, the destination MAC address satisfies a preset condition including any one of the following: the destination MAC address is a local address; the destination MAC address is a broadcast address.
[0083] In this embodiment, the message parsing device corresponding to the message parsing method is installed on the first electronic device. When the first electronic device communicates with the second electronic device, the first electronic device communicates with the second electronic device through the message parsing device and the message parsing device corresponding to the second electronic device.
[0084] The local address refers to the MAC address of the first electronic device corresponding to the message parsing device.
[0085] In the case where the first message is a message sent by the second electronic device to the first electronic device and other electronic devices at the same time, the broadcast address is an address specifically used to send to the first electronic device and other electronic devices at the same time.
[0086] In this embodiment, when the destination MAC address does not meet the preset condition, the first target state machine stops sending the third message and ends parsing the first message.
[0087] In one embodiment, the link layer protocol is any one of the IP protocol, the ARP protocol, and the RARP protocol.
[0088] In this embodiment, it should be noted that, when the link layer protocol is other than the IP protocol, the ARP protocol, and the RARP protocol, the first target state machine ends parsing and sending the first message.
[0089] Step 1500, when the destination MAC address meets the preset conditions, the first target state machine sends the third message to the second target state machine corresponding to the link layer protocol according to the link layer protocol, specifically including steps 1510 to 1530.
[0090] Step 1510: When the link layer protocol is the IP protocol, the first target state machine sends the third message to the IP state machine.
[0091] In one embodiment, after step 1510, the message parsing method further includes steps 1511 to 1513.
[0092] Step 1511: The IP state machine parses the third target field in the third message to obtain the IP protocol type, lifetime value, and header length value of the third message.
[0093] Step 1512, when the lifetime value is the preset lifetime value and the header length value is greater than the preset length value, the IP state machine parses the required fields and optional fields in the third message respectively to obtain the source IP, destination IP, header check, sending path and sending time of the third message.
[0094] The preset survival time value is pre-set, and this embodiment does not specifically limit this. For example, the preset survival time value is zero.
[0095] The preset length value is pre-set and is not specifically limited in this embodiment. For example, the preset length value is 5.
[0096] Among them, the required fields are fields corresponding to the preset length value in the third message, and the optional fields are other fields in the third message except the required fields. For example, the third message includes 8 fields, and the preset length value of the third message is 5, then the required fields are 5 fields among the 8 fields, and the 3 fields among the 8 fields except the 5 required fields are all optional fields.
[0097] In this embodiment, when the lifetime value is a preset lifetime value and the header length value is greater than the preset length value, the IP state machine parses the required fields in the third message to obtain the source IP of the third message, the destination IP of the third message and the header checksum of the third message.
[0098] In this embodiment, when the lifetime value is the preset lifetime value and the header length value is greater than the preset length value, the IP state machine parses the optional fields in the third message to obtain the sending path and sending time of the third message.
[0099] Step 1513, when the lifetime value is a preset lifetime value and the header length value is less than or equal to the preset length value, the IP state machine sends the fourth message to the third target state machine corresponding to the IP protocol type according to the IP protocol type, wherein the fourth message is a message composed of other fields in the third message except the third target field.
[0100] In this embodiment, when the lifetime value is a preset lifetime value and the header length value is less than or equal to the preset length value, the IP state machine sends the fourth message to the ICMP state machine, UDP state machine or UDP state machine corresponding to the IP protocol type according to the IP protocol type of the third message.
[0101] In one embodiment, the IP protocol type is any one of the ICMP protocol, the UDP protocol or the TCP protocol.
[0102] In one embodiment, step 1513 specifically includes steps 15131 to 15133.
[0103] Step 15131, when the IP protocol type is the ICMP protocol, the IP state machine sends the fourth message to the ICMP state machine, wherein the ICMP state machine is used to parse the fourth message to obtain the message type, code number, check code and application layer data of the fourth message.
[0104] Step 15132, when the IP protocol type is the UDP protocol, the IP state machine sends the fourth message to the UDP state machine, wherein the UDP state machine is used to parse the fourth message to obtain application layer data of the fourth message.
[0105] Step 15133, when the IP protocol type is the TCP protocol, the IP state machine sends the fourth message to the TCP state machine, wherein the TCP state machine is used to parse the fourth message to obtain the source port, destination port, message sequence number, message confirmation number, offset and window size of the fourth message.
[0106] In this embodiment, when the IP protocol type is the TCP protocol, the IP state machine sends the fourth message to the TCP state machine, and the TCP state machine parses the fourth message and can also obtain the flag of the fourth message and the checksum of the fourth message.
[0107] Step 1520: When the link layer protocol is the ARP protocol, the first target state machine sends the third message to the ARP state machine.
[0108] In one embodiment, in step 1520, when the link layer protocol is the ARP protocol, after the first target state machine sends the third message to the ARP state machine, the message parsing method further includes steps 1521 and 1522.
[0109] Step 1521, when the third message is an ARP request message, the ARP state machine parses the third message to obtain the IP address of the third message; and, when the ARP state machine obtains the local routing table, and when the MAC address corresponding to the IP address exists in the local routing table, the ARP state machine generates a target ARP reply message according to the third message, the second message and the first message.
[0110] In this embodiment, the local routing table is a routing table of the first electronic device.
[0111] In this embodiment, when the third message is an ARP request message, the ARP state machine generates a target ARP reply message according to the message information of the third message, the second message and the first message, and sends the target ARP reply message to the target electronic device to respond to the first message sent by the target electronic device. The target electronic device is an electronic device that sends the first message to the first electronic device.
[0112] Step 1522: When the third message is an ARP reply message, the ARP state machine obtains the local routing table and updates the local routing table according to the third message.
[0113] In this embodiment, when the third message is an ARP reply message, the ARP state machine may update the local routing table according to the third message.
[0114] In this embodiment, it should be noted that an ARP message determination state is provided in the ARP state machine, and the ARP message determination state is used to determine whether the third message received by the ARP state machine is a request message or a response message.
[0115] Step 1530: When the link layer protocol is the RARP protocol, the first target state machine sends the third message to the RARP state machine.
[0116] In one embodiment, in step 1530, when the link layer protocol is the RARP protocol, after the first target state machine sends the third message to the RARP state machine, the message parsing method further includes steps 1531 and 1532.
[0117] Step 1531, when the third message is a RARP request message, the RARP state machine parses the third message to obtain the MAC address of the third message; and the RARP state machine obtains the local routing table, and when there is an IP address corresponding to the MAC address in the local routing table, generates a target RARP response message according to the third message, the second message and the first message.
[0118] In this embodiment, when the third message is a RARP request message, the RARP state machine generates a target RARP response message according to message information of the third message, the second message and the first message, and sends the target RARP response message to the target electronic device.
[0119] Step 1532: When the third message is a RARP response message, the RARP state machine obtains a local routing table and updates the local routing table according to the third message.
[0120] In this embodiment, when the third message is an ARP reply message, the ARP state machine may update the local routing table according to the third message.
[0121] In this embodiment, it should be noted that a RARP message determination state is provided in the RARP state machine, and the RARP message determination state is used to determine whether the third message received by the RARP state machine is a request message or a response message.
[0122] In an embodiment of the present application, the first target field in the first message is parsed by the first state machine to obtain the link layer encapsulation format of the first message, and the second message composed of other unparsed fields in the first message is sent to the first target state machine corresponding to its link layer encapsulation format, so that the first target state machine parses the second target field in the second message to obtain the destination MAC address and link layer protocol of the second message, and when the destination MAC address meets the preset conditions, according to the link layer protocol, the third message composed of other unparsed fields in the second message is sent to the second target state machine corresponding to the link layer protocol, so that the second target state machine parses the third message. The present application parses the first message by the first state machine to obtain the link layer encapsulation format of the first message, and then sends the second message to different first target state machines according to the link layer encapsulation format of the first message, so that the message parsing method can be applied to messages with different link layer encapsulation formats, has a wide range of applications, and the message parsing method is mainly implemented based on the state machine, the message parsing process is easy to understand, and convenient to modify and check errors.
[0123] <Equipment Embodiment>
[0124] Figure 4 is a functional block diagram of an apparatus according to an embodiment. Figure 4 As shown, the message parsing device may include a first state machine 401 , a first target state machine 402 , and a second target state machine 403 .
[0125] In one embodiment, a first state machine 401 is used to receive a first message, which includes multiple fields; it is also used to parse a first target field in the first message to obtain a link layer encapsulation format of the first message; according to the link layer encapsulation format, a second message is sent to a first target state machine corresponding to the link layer encapsulation format, wherein the second message is a message composed of other fields in the first message except the first target field.
[0126] In one embodiment, the first target state machine 402 is used to parse the second target field in the second message to obtain the destination MAC address and link layer protocol of the second message; and, when the destination MAC address meets a preset condition, send a third message to the second target state machine 403 corresponding to the link layer protocol according to the link layer protocol, wherein the third message is a message composed of other fields in the second message except the second target field.
[0127] In this embodiment, the message parsing device provided by the present application, since it can implement the above-mentioned message parsing method, can parse the first message through the first state machine to obtain the link layer encapsulation format of the first message, and then send the second message to different first target state machines according to the link layer encapsulation format of the first message, so that the message parsing method can be applied to messages with different link layer encapsulation formats, and has a wide range of applications. Moreover, the message parsing method is mainly implemented based on the state machine, and the message parsing process is easy to understand, and convenient to modify and check errors.
[0128] In one embodiment, the present application further provides an electronic device, which includes the above-mentioned message parsing device.
[0129] In this embodiment, the electronic device may be, but is not limited to, various smart phones, personal computers, laptop computers, tablet computers, and other devices.
[0130] The present invention may be a system, a method and / or a computer program product. The computer program product may include a computer-readable storage medium carrying computer-readable program instructions for causing a processor to implement various aspects of the present invention.
[0131] A computer-readable storage medium may be a tangible device that can hold and store instructions used by an instruction execution device. A computer-readable storage medium may be, for example, but not limited to, an electrical storage device, a magnetic storage device, an optical storage device, an electromagnetic storage device, a semiconductor storage device, or any suitable combination of the foregoing. More specific examples of computer-readable storage media (a non-exhaustive list) include: a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), a static random access memory (SRAM), a portable compact disk read-only memory (CD-ROM), a digital versatile disk (DVD), a memory stick, a floppy disk, a mechanical encoding device, such as a punch card or a raised structure in a groove on which instructions are stored, and any suitable combination of the foregoing. As used herein, a computer-readable storage medium is not to be interpreted as a transient signal per se, such as a radio wave or other freely propagating electromagnetic wave, an electromagnetic wave propagating through a waveguide or other transmission medium (e.g., a light pulse through a fiber optic cable), or an electrical signal transmitted through a wire.
[0132] The computer-readable program instructions described herein can be downloaded from a computer-readable storage medium to each computing / processing device, or downloaded to an external computer or external storage device via a network, such as the Internet, a local area network, a wide area network, and / or a wireless network. The network can include copper transmission cables, optical fiber transmissions, wireless transmissions, routers, firewalls, switches, gateway computers, and / or edge servers. The network adapter card or network interface in each computing / processing device receives the computer-readable program instructions from the network and forwards the computer-readable program instructions for storage in the computer-readable storage medium in each computing / processing device.
[0133] The computer program instructions for performing the operation of the present invention may be assembly instructions, instruction set architecture (ISA) instructions, machine instructions, machine-related instructions, microcode, firmware instructions, state setting data, or source code or object code written in any combination of one or more programming languages, including object-oriented programming languages, such as Smalltalk, C++, etc., and conventional procedural programming languages, such as "C" language or similar programming languages. Computer-readable program instructions may be executed entirely on a user's computer, partially on a user's computer, as an independent software package, partially on a user's computer, partially on a remote computer, or entirely on a remote computer or server. In the case of a remote computer, the remote computer may be connected to the user's computer via any type of network, including a local area network (LAN) or a wide area network (WAN), or may be connected to an external computer (e.g., using an Internet service provider to connect via the Internet). In some embodiments, an electronic circuit, such as a programmable logic circuit, a field programmable gate array (FPGA), or a programmable logic array (PLA), may be personalized by utilizing the state information of the computer-readable program instructions, and the electronic circuit may execute the computer-readable program instructions, thereby realizing various aspects of the present invention.
[0134] Various aspects of the present invention are described herein with reference to the flow charts and / or block diagrams of the methods, devices (systems) and computer program products according to embodiments of the present invention. It should be understood that each box of the flow chart and / or block diagram and the combination of each box in the flow chart and / or block diagram can be implemented by computer-readable program instructions.
[0135] These computer-readable program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, or other programmable data processing device, thereby producing a machine, so that when these instructions are executed by the processor of the computer or other programmable data processing device, a device that implements the functions / actions specified in one or more boxes in the flowchart and / or block diagram is generated. These computer-readable program instructions can also be stored in a computer-readable storage medium, and these instructions cause the computer, programmable data processing device, and / or other equipment to work in a specific manner, so that the computer-readable medium storing the instructions includes a manufactured product, which includes instructions for implementing various aspects of the functions / actions specified in one or more boxes in the flowchart and / or block diagram.
[0136] Computer-readable program instructions may also be loaded onto a computer, other programmable data processing apparatus, or other device so that a series of operating steps are performed on the computer, other programmable data processing apparatus, or other device to produce a computer-implemented process, thereby causing the instructions executed on the computer, other programmable data processing apparatus, or other device to implement the functions / actions specified in one or more boxes in the flowchart and / or block diagram.
[0137] The flow charts and block diagrams in the accompanying drawings show the possible architecture, functions and operations of the systems, methods and computer program products according to multiple embodiments of the present invention. In this regard, each box in the flow chart or block diagram can represent a part of a module, a program segment or an instruction, and a part of the module, a program segment or an instruction contains one or more executable instructions for realizing the specified logical function. In some alternative implementations, the functions marked in the box can also occur in a different order from the order marked in the accompanying drawings. For example, two consecutive boxes can actually be executed substantially in parallel, and they can sometimes be executed in the opposite order, depending on the functions involved. It should also be noted that each box in the block diagram and / or flow chart, and the combination of the boxes in the block diagram and / or flow chart can be implemented by a dedicated hardware-based system that performs the specified function or action, or can be implemented by a combination of dedicated hardware and computer instructions. It is well known to those skilled in the art that it is equivalent to implement it by hardware, implement it by software, and implement it by combining software and hardware.
[0138] Embodiments of the present invention have been described above, and the above description is exemplary, not exhaustive, and is not limited to the disclosed embodiments. Many modifications and variations will be apparent to those of ordinary skill in the art without departing from the scope and spirit of the described embodiments. The selection of terms used herein is intended to best explain the principles of the embodiments, practical applications, or technical improvements in the marketplace, or to enable other persons of ordinary skill in the art to understand the embodiments disclosed herein. The scope of the present invention is defined by the appended claims.
Claims
1. A message parsing method based on a state machine, characterized in that: The method comprises: The first state machine receives a first message, wherein the first message includes a plurality of fields; The first state machine parses the first target field in the first message to obtain a link layer encapsulation format of the first message; According to the link layer encapsulation format, the first state machine sends the second message to a first target state machine corresponding to the link layer encapsulation format, wherein the second message is a message composed of other fields in the first message except the first target field; The first target state machine parses the second target field in the second message to obtain the destination MAC address and link layer protocol of the second message; When the destination MAC address meets the preset conditions, the first target state machine sends the third message to the second target state machine corresponding to the link layer protocol according to the link layer protocol, wherein the third message is a message composed of other fields in the second message except the second target field.
2. The method according to claim 1, characterized in that The destination MAC address satisfies any of the following conditions: The destination MAC address is the local address; The destination MAC address is a broadcast address.
3. The method according to claim 1, characterized in that The link layer encapsulation format is any one of RFC894, RFC802 or RFC893; The first state machine sending the second message to a first target state machine corresponding to the link layer encapsulation format according to the link layer encapsulation format includes: When the link layer encapsulation format is RFC894, the first state machine sends the second message to the RFC894 state machine; When the link layer encapsulation format is RFC802, the first state machine sends the second message to the RFC802 state machine; When the link layer encapsulation format is RFC893, the first state machine sends the second message to the RFC893 state machine.
4. The method according to claim 1, characterized in that: The link layer protocol is any one of the IP protocol, the ARP protocol, and the RARP protocol: The first target state machine sends the third message to a second target state machine corresponding to the link layer protocol according to the link layer protocol, including: When the link layer protocol is the IP protocol, the first target state machine sends the third message to the IP state machine; When the link layer protocol is the ARP protocol, the first target state machine sends the third message to the ARP state machine; When the link layer protocol is the RARP protocol, the first target state machine sends the third message to the RARP state machine.
5. The method according to claim 4, characterized in that In the case where the link layer protocol is the IP protocol, after the first target state machine sends the third message to the IP state machine, the method further includes: The IP state machine parses the third target field in the third message to obtain the IP protocol type, lifetime value and header length value of the third message; When the lifetime value is a preset lifetime value and the header length value is greater than the preset length value, the IP state machine parses the required fields and the optional fields in the third message respectively to obtain the source IP, destination IP, header check, sending path and sending time of the third message; When the lifetime value is a preset lifetime value and the header length value is less than or equal to the preset length value, the IP state machine sends the fourth message to a third target state machine corresponding to the IP protocol type according to the IP protocol type, wherein the fourth message is a message composed of other fields in the third message except the third target field.
6. The method according to claim 5, characterized in that The IP protocol type is any one of the ICMP protocol, UDP protocol or TCP protocol; The IP state machine sends the fourth message to a third target state machine corresponding to the IP protocol type according to the IP protocol type, including: When the IP protocol type is the ICMP protocol, the IP state machine sends the fourth message to the ICMP state machine, wherein the ICMP state machine is used to parse the fourth message to obtain the message type, code number, check code and application layer data of the fourth message; In the case where the IP protocol type is the UDP protocol, the IP state machine sends the fourth message to the UDP state machine, wherein the UDP state machine is used to parse the fourth message to obtain application layer data of the fourth message; When the IP protocol type is the TCP protocol, the IP state machine sends the fourth message to the TCP state machine, wherein the TCP state machine is used to parse the fourth message to obtain the source port, destination port, message sequence number, message confirmation number, offset and window size of the fourth message.
7. The method according to claim 4, characterized in that In the case where the link layer protocol is the ARP protocol, after the first target state machine sends the third message to the ARP state machine, the method further includes: In the case where the third message is an ARP request message, the ARP state machine parses the third message to obtain an IP address of the third message; The ARP state machine obtains a local routing table, and generates a target ARP reply message according to the third message, the second message, and the first message when a MAC address corresponding to the IP address exists in the local routing table; In the case that the third message is an ARP reply message, the ARP state machine obtains the local routing table and updates the local routing table according to the third message.
8. The method according to claim 4, characterized in that In the case where the link layer protocol is the RARP protocol, after the first target state machine sends the third message to the RARP state machine, the method further includes: In the case where the third message is a RARP request message, the RARP state machine parses the third message to obtain a MAC address of the third message; The RARP state machine obtains a local routing table, and generates a target RARP response message according to the third message, the second message, and the first message when the IP address corresponding to the MAC address exists in the local routing table; In the case that the third message is a RARP response message, the RARP state machine obtains a local routing table, and updates the local routing table according to the third message.
9. A message parsing device based on a state machine, characterized in that: The apparatus comprises a first state machine, a first target state machine and a second target state machine: The first state machine is used to receive a first message, the first message including a plurality of fields; and is also used to parse a first target field in the first message to obtain a link layer encapsulation format of the first message; and send a second message to a first target state machine corresponding to the link layer encapsulation format according to the link layer encapsulation format, wherein the second message is a message composed of other fields in the first message except the first target field; The first target state machine is used to parse the second target field in the second message to obtain the destination MAC address and link layer protocol of the second message; and, when the destination MAC address meets a preset condition, send a third message to the second target state machine corresponding to the link layer protocol according to the link layer protocol, wherein the third message is a message composed of other fields in the second message except the second target field.
10. An electronic device, characterized in that: The electronic device comprises the message parsing device based on the state machine as claimed in claim 9.
Citation Information
Patent Citations
Method and system for detecting multi-hop link
CN104468286A
Header parsing apparatus and method
CN112136108A
Message data analysis method, device and equipment
CN114006956A
Three-layer local forwarding method and device
WO2014067450A1
