A packet parsing method and device based on a state machine and electronic equipment
By using a state machine-based message parsing method, the link layer encapsulation format of the message is parsed and distributed to the corresponding state machine. This solves the problems of universality and understandability of existing message parsing methods and achieves a parsing process that is widely applicable and easy to modify.
Patent Information
- Application Number
- CN202310662625.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2023-06-05
- Publication Date
- 2025-11-11
- Estimated Expiration
- 2043-06-05
AI Technical Summary
Existing message parsing methods can only parse messages of one standard, making them unusable. Furthermore, the parsing process is obscure and difficult to understand, hindering modification and error checking.
A state machine-based message parsing method is adopted. The link layer encapsulation format of the message is parsed through the first state machine, and the unparsed fields are sent to the corresponding target state machine for further parsing until the destination MAC address and link layer protocol of the message are obtained.
It achieves broad applicability to packets encapsulated in different link layers, and the parsing process is easy to understand, modify, and check for errors.
Smart Images

Figure CN119094633B_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of message parsing technology, and more specifically, to a message parsing method, apparatus, and electronic device based on a state machine. Background Technology
[0002] A message is a data unit exchanged and transmitted in a network, and it is also a unit of network transmission. A message contains complete data information to be sent, and its length does not need to be consistent. During transmission, messages are continuously encapsulated into packets, frames, and groups for transmission.
[0003] Currently, when parsing messages, each existing message parsing method can only parse messages of one standard. Since there are many message standards, this causes a problem of message parsing methods not being universally applicable. Therefore, before parsing a message, it is necessary to use other methods to identify the message standard of the message to be parsed, and then select the corresponding message parsing method according to the message standard. Existing message parsing methods have a limited scope of application, and the process of parsing messages is obscure and difficult to understand, which is not conducive to modification and error checking. Summary of the Invention
[0004] One objective of this application is to provide a new technical solution for a message parsing method, apparatus, and electronic device based on a state machine.
[0005] According to a first aspect of this application, a state machine-based message parsing method is provided, the method comprising:
[0006] The first state machine receives a first message, which includes multiple fields;
[0007] The first state machine parses the first target field in the first message to obtain the 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 the first target state machine corresponding to the link layer encapsulation format, wherein the second message is a message composed of fields other than the first target field in the first message;
[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 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 fields other than the second target field in the second message.
[0011] Optionally, the destination MAC address satisfies any of the following preset conditions:
[0012] The destination MAC address is the local machine 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] 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, including:
[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 following: IP protocol, ARP protocol, and RARP protocol.
[0020] 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, including:
[0021] When the link layer protocol is IP, the first target state machine sends the third message to the IP state machine;
[0022] When the link layer protocol is ARP, the first target state machine sends the third message to the ARP state machine;
[0023] When the link layer protocol is RARP, the first target state machine sends the third message to the RARP state machine.
[0024] Optionally, when the link layer protocol is IP, 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 destination field in the third message to obtain the IP protocol type, time-to-live (TTL) value, and header length value of the third message.
[0026] When the time-to-live value is a preset time-to-live value and the header length value is greater than the preset length value, the IP state machine parses the required and optional fields in the third message respectively to obtain the source IP, destination IP, header checksum, transmission path and transmission time of the third message;
[0027] When the time-to-live value is a preset time-to-live value and the header length value is less than or equal to a preset length value, the IP state machine sends a fourth message to a third target state machine corresponding to the IP protocol type according to the IP protocol type. The fourth message is a message composed of fields other than the third target field in the third message.
[0028] Optionally, the IP protocol type is any one of ICMP, UDP, or TCP protocols;
[0029] 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, including:
[0030] When the IP protocol type is ICMP, 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, checksum and application layer data of the fourth message;
[0031] When the IP protocol type is UDP, the IP state machine sends the fourth packet to the UDP state machine, wherein the UDP state machine is used to parse the fourth packet to obtain the application layer data of the fourth packet;
[0032] When the IP protocol type is TCP, the IP state machine sends the fourth message to the TCP state machine, whereby the TCP state machine parses the fourth message to obtain the source port, destination port, sequence number, acknowledgment number, offset, and window size of the fourth message.
[0033] Optionally, when the link layer protocol is ARP, after the first target state machine sends the third message to the ARP state machine, the method further includes:
[0034] If 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;
[0035] The ARP state machine obtains the local routing table, and if the MAC address corresponding to the IP address exists in the local routing table, it generates a target ARP reply packet based on the third packet, the second packet, and the first packet.
[0036] If 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 RARP, after the first target state machine sends the third message to the RARP state machine, the method further includes:
[0038] If 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;
[0039] The RARP state machine obtains its local routing table, and if the IP address corresponding to the MAC address exists in the local routing table, it generates a target RARP response message based on the third message, the second message, and the first message.
[0040] If the third message is a RARP reply message, the RARP state machine obtains its local routing table and updates the local routing table according to the third message.
[0041] According to a second aspect of this application, a state machine-based message parsing apparatus is also provided, the apparatus comprising a first state machine, a first target state machine, and a second target state machine:
[0042] The first state machine is configured to receive a first message, the first message including multiple fields; and to parse the first target field in the first message to obtain the link layer encapsulation format of the first message; and to send a second message to the 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 fields other than the first target field in the first message;
[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, if the destination MAC address meets a preset condition, to 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 for the second target field.
[0044] According to a third aspect of this application, an electronic device is also provided, including a state machine-based message parsing apparatus as described in the second aspect.
[0045] One beneficial effect of this application's embodiments is that, by parsing the first target field in the first message using a first state machine to obtain the link layer encapsulation format of the first message, a 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. The first target state machine then parses the second target field in the second message to obtain the destination MAC address and link layer protocol of the second message. If the destination MAC address meets preset conditions, a 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, allowing the second target state machine to parse the third message. This application parses the first message using a 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. This makes the message parsing method applicable to messages with different link layer encapsulation formats, thus having a wide range of applications. Furthermore, this message parsing method is mainly implemented based on a state machine, making the message parsing process easy to understand, modify, and debug.
[0046] Other features and advantages of the embodiments of this application will become clear from the following detailed description of exemplary embodiments with reference to the accompanying drawings. Attached Figure Description
[0047] The accompanying drawings, which are incorporated in and form part of this specification, illustrate embodiments of the present application and, together with their description, serve to explain the principles of the embodiments of the present application.
[0048] Figure 1 This is one of the flowcharts illustrating a state machine-based message parsing method provided in this application embodiment;
[0049] Figure 2 A second flowchart illustrating a state machine-based message parsing method provided in this application embodiment;
[0050] Figure 3The third flowchart illustrates a message parsing method based on a state machine, as provided in this application embodiment.
[0051] Figure 4 This is a schematic diagram of a message parsing device based on a state machine, provided in an embodiment of this application. Detailed Implementation
[0052] Various exemplary embodiments of this application will now be described in detail with reference to the accompanying drawings. It should be noted that, unless otherwise specifically stated, the relative arrangement, numerical expressions, and values of the components and steps set forth in these embodiments do not limit the scope of the invention.
[0053] The following description of at least one exemplary embodiment is merely illustrative and is in no way intended to limit the invention or its application or use.
[0054] Techniques, methods, and equipment known to those skilled in the art may not be discussed in detail, but where appropriate, such techniques, methods, and equipment should be considered part of the specification.
[0055] In all the examples shown and discussed herein, any specific values should be interpreted as merely exemplary and not as limitations. Therefore, other examples of exemplary embodiments may have different values.
[0056] It should be noted that similar labels and letters in the following figures indicate similar items; therefore, once an item is defined in one figure, it does not need to be discussed further in subsequent figures.
[0057] <Method Implementation>
[0058] The message parsing method based on a state machine provided in this application will be described in detail below with reference to the accompanying drawings, through specific embodiments and application scenarios.
[0059] like Figure 1 As shown, this is one of the flowcharts illustrating a state machine-based message parsing method provided in this application embodiment. This embodiment mainly uses the application of this method to a message parsing device as an example for illustration. Figure 1 As shown, the message parsing method may include the following steps 1100 to 1500, which will be described in detail below.
[0060] Step 1100: The first state machine receives the first message, which includes multiple fields.
[0061] In this embodiment, the first message is an RFC-based message, which is encapsulated by multiple fields.
[0062] Step 1200: The first state machine parses the first target field in the first message to obtain the 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 the second message to the first target state machine corresponding to the link layer encapsulation format, wherein the second message is a message composed of fields other than the first target field in the first message.
[0065] In this embodiment, it should be noted that the second message is a message composed of the 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, where A1, A2, A3, A4, A5, and A6 are fields in the first message. In step 1200, the first state machine parses A1 to obtain the link layer encapsulation format of the first message, where A1 is the first target field in the first message. Then, the fields A2, A3, A4, A5, and A6 in the first message form the second message. 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, if 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, if 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 any encapsulation format other than RFC894, RFC802 or RFC893, the first state machine ends the parsing and transmission of the first message.
[0076] In this embodiment, the second message is sent to the RFC894, RFC802, or RFC893 state machine corresponding to the link layer encapsulation format of the first message through the first state machine. This facilitates the classification of the second message according to the encapsulation format of the first link layer, and the second message is parsed through the RFC894, RFC802, or RFC893 state machine that matches the type of the second message. The parsing speed is fast and the applicability is wide.
[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, RFC802 state machine, and RFC893 state machine are all used to parse the second destination 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, RFC802 state machine, and RFC893 state machine can also parse the second destination field in the second message to obtain the source MAC address of the second message. The source MAC address of the second message is temporarily stored as a global variable in the first state machine.
[0080] Among them, global variables can affect the discrimination results of the first state machine, as well as 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 fields other than the second target field in the second message.
[0082] In one embodiment, the destination MAC address satisfies any of the following preset conditions: 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 simultaneously by the second electronic device to the first electronic device and other electronic devices, the broadcast address is an address specifically used for sending to the first electronic device and other electronic devices simultaneously.
[0086] In this embodiment, if the destination MAC address does not meet the preset conditions, the first target state machine stops sending the third message and ends the parsing of the first message.
[0087] In one embodiment, the link layer protocol is any one of the IP protocol, ARP protocol, and RARP protocol.
[0088] In this embodiment, it should be noted that when the link layer protocol is a protocol other than IP, ARP, or RARP, the first target state machine ends the parsing and sending of the first message.
[0089] Step 1500: If 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: If the link layer protocol is IP, 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 destination field in the third message to obtain the IP protocol type, time-to-live (TTL) value, and header length value of the third message.
[0093] Step 1512: When the time-to-live value is a preset time-to-live value and the header length value is greater than the preset length value, the IP state machine parses the required and optional fields in the third message respectively to obtain the source IP, destination IP, header checksum, 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 it. For example, the preset survival time value is zero.
[0095] The preset length value is pre-defined, and this embodiment does not impose specific limitations on it. For example, the preset length value is 5.
[0096] Required fields are those corresponding to the preset length value in the third message, while optional fields are the other fields in the third message besides the required fields. For example, if the third message includes 8 fields and the preset length value of the third message is 5, then the required fields are 5 of the 8 fields, and the remaining 3 fields are optional fields.
[0097] In this embodiment, when the time-to-live (TTL) value is a preset TTL value and the header length value is greater than a preset length value, the IP state machine parses the necessary fields in the third packet to obtain the source IP, destination IP, and header checksum of the third packet.
[0098] In this embodiment, when the time-to-live value is a preset time-to-live 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 time-to-live value is a preset time-to-live value and the header length value is less than or equal to a 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. The fourth message is a message composed of fields other than the third target field in the third message.
[0100] In this embodiment, when the time-to-live value is a preset time-to-live value and the header length value is less than or equal to a 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 of the third message.
[0101] In one embodiment, the IP protocol type is any one of ICMP, UDP, or TCP protocols.
[0102] In one embodiment, step 1513 specifically includes steps 15131 to 15133.
[0103] Step 15131: When the IP protocol type is ICMP, 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, checksum and application layer data of the fourth message.
[0104] Step 15132: When the IP protocol type is UDP, 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 the application layer data of the fourth message.
[0105] Step 15133: When the IP protocol type is TCP, the IP state machine sends the fourth packet to the TCP state machine, wherein the TCP state machine is used to parse the fourth packet to obtain the source port, destination port, packet sequence number, packet acknowledgment number, offset, and window size of the fourth packet.
[0106] In this embodiment, when the IP protocol type is TCP, the IP state machine sends the fourth message to the TCP state machine. The TCP state machine parses the fourth message and can also obtain the flag and checksum of the fourth message.
[0107] Step 1520: If the link layer protocol is ARP, the first target state machine sends the third message to the ARP state machine.
[0108] In one embodiment, in step 1520, after the first target state machine sends the third message to the ARP state machine when the link layer protocol is ARP, the message parsing method further includes steps 1521 and 1522.
[0109] Step 1521: If the third packet is an ARP request packet, the ARP state machine parses the third packet to obtain the IP address of the third packet; and the ARP state machine obtains the local routing table, and if the MAC address corresponding to the IP address exists in the local routing table, it generates a target ARP reply packet based on the third packet, the second packet, and the first packet.
[0110] In this embodiment, the local routing table is the 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 response message based on the message information of the third message, the second message, and the first message, and sends the target ARP response message to the target electronic device, thereby responding to the first message sent by the target electronic device. The target electronic device is the electronic device that sent the first message to the first electronic device.
[0112] Step 1522: If 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 can update its local routing table based on the third message.
[0114] In this embodiment, it should be noted that the ARP state machine has an ARP message discrimination state, which 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: If the link layer protocol is RARP, 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 RARP, 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: If 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 its local routing table, and if the IP address corresponding to the MAC address exists in the local routing table, it generates a target RARP response message based on 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 based on the 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: If the third message is a RARP reply message, the RARP state machine obtains the 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 can update its local routing table based on the third message.
[0121] In this embodiment, it should be noted that the RARP state machine has a RARP message discrimination state, which is used to determine whether the third message received by the RARP state machine is a request message or a response message.
[0122] In this embodiment, a first state machine parses the first target field in the first message to obtain the link layer encapsulation format of the first message. A second message, consisting of the remaining unparsed fields in the first message, is then sent to the first target state machine corresponding to its link layer encapsulation format. 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. If the destination MAC address meets a preset condition, a third message, consisting of the remaining 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. This application uses a first state machine to parse the first message to obtain its link layer encapsulation format, and then sends the second message to different first target state machines according to the link layer encapsulation format of the first message. This allows the message parsing method to be applicable to messages with different link layer encapsulation formats, resulting in a wide range of applications. Furthermore, this message parsing method is mainly implemented based on a state machine, making the message parsing process easy to understand, modify, and debug.
[0123] <Equipment Example>
[0124] Figure 4 This is a schematic block diagram of a device according to one 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 configured to receive a first message, the first message including multiple fields; and to parse a first target field in the first message to obtain a link layer encapsulation format of the first message; and to 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 fields other than the first target field in the first message.
[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, if the destination MAC address meets a preset condition, to 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 for the second target field.
[0127] In this embodiment, the message parsing device provided by this application can implement the above-mentioned message parsing method. It 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. This makes the message parsing method applicable to messages with different link layer encapsulation formats, with a wide range of applications. Moreover, the message parsing method is mainly based on the state machine, making the message parsing process easy to understand, and convenient for modification and error checking.
[0128] In one embodiment, this application also provides an electronic device that includes the aforementioned message parsing apparatus.
[0129] In this embodiment, the electronic device may be, but is not limited to, various smartphones, personal computers, laptops, tablets, and other devices.
[0130] This invention can be a system, method, and / or computer program product. A computer program product may include a computer-readable storage medium having computer-readable program instructions loaded thereon for causing a processor to implement various aspects of the invention.
[0131] Computer-readable storage media can be tangible devices capable of holding and storing instructions for use by an instruction execution device. Computer-readable storage media can be, for example—but not limited to—electrical storage devices, magnetic storage devices, optical storage devices, electromagnetic storage devices, semiconductor storage devices, or any suitable combination thereof. More specific examples (a non-exhaustive list) of computer-readable storage media include: portable computer disks, hard disks, random access memory (RAM), read-only memory (ROM), erasable programmable read-only memory (EPROM or flash memory), static random access memory (SRAM), portable compact disc read-only memory (CD-ROM), digital multifunction disc (DVD), memory sticks, floppy disks, mechanical encoding devices, such as punch cards or recessed protrusions storing instructions thereon, and any suitable combination thereof. The computer-readable storage media used herein are not to be construed as transient signals themselves, such as radio waves or other freely propagating electromagnetic waves, electromagnetic waves propagating through waveguides or other transmission media (e.g., light pulses through fiber optic cables), or electrical signals transmitted through wires.
[0132] The computer-readable program instructions described herein can be downloaded from computer-readable storage media to various computing / processing devices, or downloaded via a network, such as the Internet, local area network, wide area network, and / or wireless network, to an external computer or external storage device. The network may include copper transmission cables, fiber optic transmission, wireless transmission, routers, firewalls, switches, gateway computers, and / or edge servers. A network adapter card or network interface in each computing / processing device receives the computer-readable program instructions from the network and forwards them to the computer-readable storage media in the respective computing / processing device.
[0133] The computer program instructions used to perform the operations of this invention may be assembly instructions, instruction set architecture (ISA) instructions, machine instructions, machine-dependent 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 the "C" language or similar programming languages. The computer-readable program instructions may be executed entirely on the user's computer, partially on the user's computer, as a standalone software package, partially on the user's computer and partially on a remote computer, or entirely on a remote computer or server. In cases involving 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., via the Internet using an Internet service provider). In some embodiments, electronic circuitry, such as programmable logic circuitry, field-programmable gate arrays (FPGAs), or programmable logic arrays (PLAs), is personalized by utilizing state information from the computer-readable program instructions. This electronic circuitry can execute the computer-readable program instructions to implement various aspects of the invention.
[0134] Various aspects of the present invention are described herein with reference to flowchart illustrations and / or block diagrams of methods, apparatus (systems), and computer program products according to embodiments of the invention. It should be understood that each block of the flowchart illustrations and / or block diagrams, and combinations of blocks in the flowchart illustrations and / or block diagrams, 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 apparatus to produce a machine such that, when executed by the processor of the computer or other programmable data processing apparatus, they create means for implementing the functions / actions specified in one or more blocks of the flowchart and / or block diagram. These computer-readable program instructions can also be stored in a computer-readable storage medium that causes a computer, programmable data processing apparatus, and / or other device to operate in a particular manner; thus, the computer-readable medium storing the instructions comprises an article of manufacture that includes instructions for implementing aspects of the functions / actions specified in one or more blocks of 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 to cause a series of operational steps to be 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 perform the functions / actions specified in one or more boxes of a flowchart and / or block diagram.
[0137] The flowcharts and block diagrams in the accompanying drawings illustrate the architecture, functionality, and operation of possible implementations of systems, methods, and computer program products according to various embodiments of the present invention. In this regard, each block in a flowchart or block diagram may represent a module, segment, or portion of an instruction containing one or more executable instructions for implementing a specified logical function. In some alternative implementations, the functions marked in the blocks may occur in a different order than those marked in the drawings. For example, two consecutive blocks may actually be executed substantially in parallel, and they may sometimes be executed in reverse order, depending on the functions involved. It should also be noted that each block in the block diagrams and / or flowcharts, and combinations of blocks in the block diagrams and / or flowcharts, can be implemented using a dedicated hardware-based system that performs the specified function or action, or using a combination of dedicated hardware and computer instructions. It will be known to those skilled in the art that implementation in hardware, implementation in software, and implementation using a combination of software and hardware are equivalent.
[0138] The various embodiments of the present invention have been described above. These descriptions are exemplary and not exhaustive, and are not limited to the disclosed embodiments. Many modifications and variations will be apparent to those skilled in the art without departing from the scope and spirit of the described embodiments. The terminology used herein is chosen to best explain the principles, practical application, or technical improvements to the embodiments in the market, or to enable others skilled in the art to understand the embodiments disclosed herein. The scope of the invention is defined by the appended claims.
Claims
1. A message parsing method based on a state machine, characterized in that, The method includes: The first state machine receives a first message, which includes multiple fields; The first state machine parses the first target field in the first message to obtain the link layer encapsulation format of the first message; 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, wherein the second message is a message composed of fields other than the first target field in the first message; 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 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 fields other than the second target field in the second message.
2. The method according to claim 1, characterized in that, The destination MAC address meets any of the following preset conditions: The destination MAC address is the local machine 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; 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, including: 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 can be any one of the following: IP protocol, ARP protocol, or RARP protocol: 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, including: When the link layer protocol is IP, the first target state machine sends the third message to the IP state machine; When the link layer protocol is ARP, the first target state machine sends the third message to the ARP state machine; When the link layer protocol is RARP, the first target state machine sends the third message to the RARP state machine.
5. The method according to claim 4, characterized in that, When the link layer protocol is IP, 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 destination field in the third message to obtain the IP protocol type, time-to-live (TTL) value, and header length value of the third message. When the time-to-live value is a preset time-to-live value and the header length value is greater than the preset length value, the IP state machine parses the required and optional fields in the third message respectively to obtain the source IP, destination IP, header checksum, transmission path and transmission time of the third message; When the time-to-live value is a preset time-to-live value and the header length value is less than or equal to a preset length value, the IP state machine sends a fourth message to a third target state machine corresponding to the IP protocol type according to the IP protocol type. The fourth message is a message composed of fields other than the third target field in the third message.
6. The method according to claim 5, characterized in that, The IP protocol type is any one of ICMP, UDP, or TCP; 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, including: When the IP protocol type is ICMP, 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, checksum and application layer data of the fourth message; When the IP protocol type is UDP, the IP state machine sends the fourth packet to the UDP state machine, wherein the UDP state machine is used to parse the fourth packet to obtain the application layer data of the fourth packet; When the IP protocol type is TCP, the IP state machine sends the fourth message to the TCP state machine, whereby the TCP state machine parses the fourth message to obtain the source port, destination port, sequence number, acknowledgment number, offset, and window size of the fourth message.
7. The method according to claim 4, characterized in that, When the link layer protocol is ARP, after the first target state machine sends the third message to the ARP state machine, the method further includes: If 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; The ARP state machine obtains the local routing table, and if the MAC address corresponding to the IP address exists in the local routing table, it generates a target ARP reply packet based on the third packet, the second packet, and the first packet. If 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, When the link layer protocol is RARP, after the first target state machine sends the third message to the RARP state machine, the method further includes: If 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; The RARP state machine obtains its local routing table, and if the IP address corresponding to the MAC address exists in the local routing table, it generates a target RARP response message based on the third message, the second message, and the first message. If the third message is a RARP reply message, the RARP state machine obtains its 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 device includes a first state machine, a first target state machine, and a second target state machine. The first state machine is configured to receive a first message, the first message including multiple fields; and to parse the first target field in the first message to obtain the link layer encapsulation format of the first message; and to send a second message to the 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 fields other than the first target field in the first message; 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, if the destination MAC address meets a preset condition, to 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 for the second target field.
10. An electronic device, characterized in that, The electronic device includes the state machine-based message parsing device as described in claim 9.
Citation Information
Patent Citations
Method and system for detecting multi-hop link
CN104468286A
Header parsing apparatus and method
CN112136108A