Message rule matching method, device, electronic device and readable storage medium

By using the longest prefix matching technology to find the target port group and rule number in network devices, the problem of low packet matching efficiency in the prior art is solved, and faster matching rate and higher processing performance are achieved.

CN112380253BActive Publication Date: 2024-11-22BEIJING KNOWNSEC INFORMATION TECHNOLOGY CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202011259374.7
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2020-11-12
Publication Date
2024-11-22
Estimated Expiration
2040-11-12

AI Technical Summary

Technical Problem

When processing a large number of packets, the method of traversing the port matching rules is low efficiency, resulting in a slower packet matching rate.

Method used

By obtaining the destination port number in the message to be matched, using the preconfigured port matching table entries for the longest prefix matching, finding the target port group and its corresponding rule number, and then obtaining the target message rules without traversing each port .

Benefits of technology

It improves the packet matching rate, reduces the matching time, and improves the processing performance of network devices.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN112380253B_ABST
    Figure CN112380253B_ABST
Patent Text Reader

Abstract

The embodiments of the present application provide a message rule matching method, device, electronic device and readable storage medium, which relate to the field of communication technology. The method obtains a message to be matched, and the message to be matched includes a destination port number. The target port group to which the destination port number belongs and at least one rule number corresponding to the target port group are found from a pre-configured port matching table entry, wherein the port matching table entry includes at least one port group and a correspondence between the port number group and the rule number. Finally, based on the correspondence between the pre-configured rule number and the message rule, the target message rule corresponding to the message to be matched is obtained without traversing each port, so that the time for matching the message rule is shortened and the message matching rate is improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of communication technology, and in particular to a message rule matching method, device, electronic device and readable storage medium. Background Art

[0002] With the continuous development of Internet technology, in order to improve the speed of processing business, the requirements for the performance of network equipment in processing messages are becoming higher and higher, and the requirements for the corresponding message fast matching algorithms are also becoming higher and higher.

[0003] At present, all ports are usually recorded in the configuration table, and the rules corresponding to the ports are traversed when the message is matched, so as to find the matching rules. However, when there are many rules, the rate of using the method of traversing ports to find the rules is low. Summary of the invention

[0004] The present application provides a message rule matching method, device, electronic device and readable storage medium to improve the above-mentioned problems.

[0005] The embodiments of the present application can be implemented as follows:

[0006] In a first aspect, the present application provides a message rule matching method, the method comprising:

[0007] Obtaining a message to be matched, wherein the message to be matched includes a destination port number;

[0008] Find out the target port group to which the destination port number belongs and at least one rule number corresponding to the target port group from a pre-configured port matching table entry, wherein the port matching table entry includes at least one port group and a corresponding relationship between a port number group and a rule number;

[0009] Based on the pre-configured correspondence between the rule number and the message rule, a target message rule corresponding to the message to be matched is obtained.

[0010] In an optional implementation manner, each of the port groups includes a port segment start value and a mask length; the step of searching the target port group to which the destination port number belongs from the pre-configured port matching table includes:

[0011] Obtaining the destination port number in the message to be matched;

[0012] Based on the longest prefix matching principle, compare the value of each port segment starting value in the port matching table entry with the bit of the destination port number bit by bit, and obtain at least one port segment starting value matching the destination port number, and a mask length corresponding to each of the port segment starting values;

[0013] The port group to which the starting value of the port segment that matches the destination port number and has the longest corresponding mask length belongs is taken as the target port group.

[0014] In an optional implementation, the method further includes: splitting and configuring multiple port numbers to obtain a port matching table entry, the step comprising:

[0015] Converting the plurality of port numbers into a binary number consisting of a preset number of bits;

[0016] The port numbers having the same value of the preset bit are divided into a group to obtain a plurality of port groups;

[0017] The number of the preset bits is used as the mask length of each port group, and the starting port number of each port group is used as the starting value of the port segment of the port group;

[0018] Generate a corresponding relationship table based on the plurality of port groups and the plurality of rule numbers;

[0019] Each of the mask lengths and each of the port segment start values ​​are used as table entries in the correspondence table to obtain a port matching table entry.

[0020] In an optional implementation manner, there are multiple rule numbers corresponding to the target port;

[0021] The step of acquiring the target message rule corresponding to the message to be matched based on the pre-configured correspondence between the rule number and the rule comprises:

[0022] Obtaining the priority of each of the rule numbers;

[0023] The rule number with the highest priority is used as the target message rule number;

[0024] Based on the pre-configured correspondence between the rule number and the rule, a target message rule corresponding to the target message rule number is obtained.

[0025] In an optional embodiment, the method further comprises:

[0026] The to-be-matched message is configured based on the target message rule.

[0027] In a second aspect, the present application provides a message rule matching device, the device comprising:

[0028] An acquisition module, used for acquiring a message to be matched, wherein the message to be matched includes a destination port number;

[0029] A search module, used to search for a target port group to which the destination port number belongs and at least one rule number corresponding to the target port group from a pre-configured port matching table entry, wherein the port matching table entry includes at least one port group and a corresponding relationship between a port number group and a rule number;

[0030] Based on the pre-configured correspondence between the rule number and the message rule, a target message rule corresponding to the message to be matched is obtained.

[0031] In an optional implementation, each of the port groups includes a port segment start value and a mask length;

[0032] The search module is used to obtain the destination port number in the message to be matched;

[0033] Based on the longest prefix matching principle, compare the value of each port segment starting value in the port matching table entry with the bit of the destination port number bit by bit, and obtain at least one port segment starting value matching the destination port number, and a mask length corresponding to each of the port segment starting values;

[0034] The port group to which the starting value of the port segment that matches the destination port number and has the longest corresponding mask length belongs is taken as the target port group.

[0035] In an optional embodiment, the device further comprises:

[0036] A configuration module is used to split and configure multiple port numbers to obtain port matching table entries;

[0037] The configuration module is also used to convert the multiple port numbers into binary numbers consisting of a preset number of bits;

[0038] The port numbers having the same value of the preset bit are divided into a group to obtain a plurality of port groups;

[0039] The number of the preset bits is used as the mask length of each port group, and the starting port number of each port group is used as the starting value of the port segment of the port group;

[0040] Generate a corresponding relationship table based on the plurality of port groups and the plurality of rule numbers;

[0041] Each of the mask lengths and each of the port segment start values ​​are used as table entries in the correspondence table to obtain a port matching table entry.

[0042] In a third aspect, the present application provides an electronic device, comprising a processor, a memory and a bus, wherein the memory stores machine-readable instructions executable by the processor, and when the electronic device is running, the processor and the memory communicate through the bus, and the processor executes the machine-readable instructions to perform the steps of the message rule matching method described in any one of the aforementioned implementations.

[0043] In a fourth aspect, the present application provides a readable storage medium, which stores a computer program, and when the computer program is executed, the steps of the message rule matching method described in any one of the aforementioned implementation methods are implemented.

[0044] The embodiments of the present application provide a message rule matching method, device, electronic device and readable storage medium, which matches the destination port segment in the message to be matched with the port matching table entry, finds the target port group to which the destination port segment in the port matching table entry belongs, obtains the rule number corresponding to the target port group, and then obtains the target message rule without traversing each port, thereby shortening the time for matching the message rule and improving the message matching rate.

[0045] In order to make the above-mentioned objects, features and advantages of the present application more obvious and understandable, some examples are given below and described in detail with reference to the attached drawings. BRIEF DESCRIPTION OF THE DRAWINGS

[0046] In order to more clearly illustrate the technical solutions of the embodiments of the present application, the drawings required for use in the embodiments will be briefly introduced below. It should be understood that the following drawings only show certain embodiments of the present application and therefore should not be regarded as limiting the scope. For ordinary technicians in this field, other related drawings can be obtained based on these drawings without paying creative work.

[0047] Figure 1 A structural block diagram of an electronic device provided in an embodiment of the present application.

[0048] Figure 2 One of the flowcharts of the message rule matching method provided in the embodiment of the present application.

[0049] Figure 3 The second flowchart of the message rule matching method provided in the embodiment of the present application.

[0050] Figure 4 A functional module block diagram of the message rule matching device provided in an embodiment of the present application.

[0051] Icons: 100 - electronic device; 110 - memory; 120 - processor; 130 - message rule matching device; 131 - acquisition module; 132 - search module; 133 - corresponding module; 134 - configuration module; 140 - communication unit. DETAILED DESCRIPTION

[0052] In order to make the purpose, technical solution and advantages of the embodiments of the present application clearer, the technical solution in the embodiments of the present application will be clearly and completely described below in conjunction with the drawings in the embodiments of the present application. Obviously, the described embodiments are part of the embodiments of the present application, rather than all the embodiments. The components of the embodiments of the present application described and shown in the drawings here can be arranged and designed in various different configurations.

[0053] Therefore, the following detailed description of the embodiments of the present application provided in the accompanying drawings is not intended to limit the scope of the present application for which protection is sought, but merely represents selected embodiments of the present application. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in the field without creative work are within the scope of protection of the present application.

[0054] It should be noted that similar reference numerals and letters denote similar items in the following drawings, and therefore, once an item is defined in one drawing, further definition and explanation thereof is not required in subsequent drawings.

[0055] In the description of the present application, it should be noted that if the terms "upper", "lower", "inside", "outside", etc. appear to indicate an orientation or position relationship, it is based on the orientation or position relationship shown in the drawings, or is the orientation or position relationship in which the product of the invention is usually placed when used. It is only for the convenience of describing the present application and simplifying the description, and does not indicate or imply that the device or element referred to must have a specific orientation, be constructed and operated in a specific orientation, and therefore cannot be understood as a limitation on the present application.

[0056] In addition, the terms “first”, “second”, etc., if used, are merely used to distinguish between the descriptions and should not be understood as indicating or implying relative importance.

[0057] It should be noted that, in the absence of conflict, the features in the embodiments of the present application may be combined with each other.

[0058] As introduced in the background technology, with the continuous development of Internet technology, the performance requirements for network devices to process messages are getting higher and higher, and accordingly, the requirements for corresponding message fast matching algorithms are also getting higher and higher.

[0059] At present, all ports are usually recorded in the configuration table, each port corresponds to a rule, and each port is traversed when the message is matched, and the corresponding matching rule is found. However, when there are many rules, the method of traversing ports to match the rules has a low rate.

[0060] In view of this, the embodiments of the present application provide a message rule matching method, device, electronic device and readable storage medium, which can find the target rule by matching the message to be matched with the port matching table entry without traversal, thereby shortening the matching time and improving the matching rate.

[0061] See also Figure 1 , Figure 1 The present invention provides a structural block diagram of an electronic device 100 provided in an embodiment of the present application. The device may include a processor 120, a memory 110, a message rule matching device 130 and a communication unit 140. The memory 110 stores machine-readable instructions executable by the processor 120. When the electronic device 100 is running, the processor 120 and the memory 110 communicate through a bus, and the processor 120 executes the machine-readable instructions and performs the steps of the message rule matching method.

[0062] The memory 110 , the processor 120 , and the communication unit 140 are electrically connected to each other directly or indirectly to achieve signal transmission or interaction.

[0063] For example, these components may be electrically connected to each other via one or more communication buses or signal lines. The message rule matching device 130 includes at least one software function module that can be stored in the memory 110 in the form of software or firmware. The processor 120 is used to execute the executable module stored in the memory 110, such as the software function module or computer program included in the message rule matching device 130.

[0064] Among them, the memory 110 can be, but is not limited to, random access memory (Random ACCess memory, RAM), read only memory (Read Only Memory, ROM), programmable read-only memory (Programmable Read-Only Memory, PROM), erasable programmable read-only memory (Erasable Programmable Read-Only Memory, EPROM), electrically erasable read-only memory (Electric Erasable Programmable Read-Only Memory, EEPROM), etc.

[0065] The processor 120 may be an integrated circuit chip with signal processing capability. The processor 120 may be a general-purpose processor, including a central processing unit (CPU), a network processor (NP), and the like.

[0066] It can also be a digital signal processor (DSP), an application specific integrated circuit (ASIC), a field programmable gate array (FPGA) or other programmable logic devices, discrete gates or transistor logic devices, discrete hardware components. It can implement or execute the disclosed methods, steps and logic block diagrams in the embodiments of the present application. The general processor can be a microprocessor or the processor can also be any conventional processor, etc.

[0067] In the embodiment of the present application, the memory 110 is used to store the program, and the processor 120 is used to execute the program after receiving the execution instruction. The process definition method disclosed in any implementation of the embodiment of the present application can be applied to the processor 120 or implemented by the processor 120.

[0068] The communication unit 140 is used to establish a communication connection between the electronic device 100 and other electronic devices through a network, and to send and receive data through the network.

[0069] In some embodiments, the network may be any type of wired or wireless network, or a combination thereof. By way of example only, the network may include a wired network, a wireless network, a fiber optic network, a telecommunications network, an intranet, the Internet, a local area network (LAN), a wide area network (WAN), a wireless local area network (WLAN), a metropolitan area network (MAN), a wide area network (WAN), a public switched telephone network (PSTN), a Bluetooth network, a ZigBee network, or a near field communication (NFC) network, or any combination thereof.

[0070] In the embodiment of the present application, the specific type of the electronic device 100 is not limited. For example, it can be, but not limited to, a smart phone, a personal computer (PC), a tablet computer, a personal digital assistant (PDA), a mobile Internet device (MID), a web server, a data server, a gateway device, and other devices with processing functions.

[0071] Understandably, Figure 1 The structure shown is for illustration only. The electronic device 100 may also have Figure 1 More or fewer components than shown, or with Figure 1 Different configurations shown. Figure 1 The components shown may be implemented in hardware, software or a combination thereof.

[0072] Based on the implementation architecture of the electronic device 100, the present application embodiment provides a message rule matching method, please refer to 2, Figure 2 This is one of the flow charts of the message rule matching method provided in the embodiment of the present application. Figure 2 The specific process shown is described in detail.

[0073] Step S1, obtaining a message to be matched, wherein the message to be matched includes a destination port number.

[0074] Step S2: Find out the target port group to which the destination port number belongs and at least one rule number corresponding to the target port group from the pre-configured port matching table entry.

[0075] The port matching table entry includes at least one port group and a corresponding relationship between the port group and the rule number.

[0076] Step S3: based on the correspondence between the pre-configured rule number and the message rule, obtain the target message rule corresponding to the message to be matched.

[0077] As a possible implementation, the electronic device 100 may be a network switching device, and the message rule may be a pre-configured ACL rule. The ACL rule is used to filter and identify messages of different services.

[0078] For example, the network switching device obtains the message to be matched, obtains the destination port number 3 included in the message to be matched, finds out from the pre-configured port matching table that the destination port number belongs to the target port group 1, and the rule number corresponding to the target port group 1 is 123. Finally, the target message rule corresponding to the rule number 123 is obtained.

[0079] The embodiment of the present application matches the destination port segment in the message to be matched with the port matching table entry, finds the target port group to which the destination port segment in the port matching table entry belongs, obtains the rule number corresponding to the target port group, and then obtains the target message rule without traversing each port, thereby shortening the time for matching the message rule and improving the matching rate.

[0080] Optionally, each port group includes a port segment start value and a mask length. A matching search may be performed based on the port segment start value and the mask length to obtain the target port group to which the destination port number belongs.

[0081] Based on the above, as an optional implementation, step S2 can be implemented in the following way to find out the target port group to which the destination port number belongs:

[0082] Get the destination port number in the message to be matched. Based on the longest prefix match principle (LPM), compare the bit values ​​of each port segment start value in the port matching table entry and the destination port number bit by bit, and obtain at least one port segment start value that matches the destination port number, and the mask length corresponding to each of the port segment start values. The port group to which the port segment start value that matches the destination port number and has the longest corresponding mask length belongs is used as the target port group.

[0083] For example, the destination port number is 5. At the same time, as shown in Table 1, the port segment start values ​​include 3, 4, and 6, and the corresponding binary values ​​are 0011B, 0100B, and 0110B. The mask lengths corresponding to the start values ​​of each port segment are 2, 3, and 2, respectively.

[0084] Table 1

[0085] Port Group Port segment start value Mask length Rule Number 3 3(0011B) 2 123 4 4(0100B) 3 123,124 6 6(0110B) 2 124

[0086] The destination port number 5 can be represented as 0101 using a binary representation method.

[0087] By matching the destination port number and the value of each bit of the port segment start value bit by bit, we can know that the destination port number 5 matches the port segment start value 3 with 1 bit, and the corresponding mask length is 2, the destination port number 5 matches the port segment start value 4 with 3 bits, and the corresponding mask length is 3, the destination port number 6 matches the port segment start value 3 with 2 bits, and the corresponding mask length is 2. By comparison, we can know that the port segment start value with the longest mask length is 4, and its port group is port group 4, so port group 4 is the target port group.

[0088] As a possible implementation, there are multiple rule numbers corresponding to the target port. In this case, step S3 can be implemented in the following manner to obtain the target message rule corresponding to the message to be matched:

[0089] Get the priority of each rule number. Use the rule number with the highest priority as the target message rule number. Based on the pre-configured correspondence between rule numbers and rules, get the target message rule corresponding to the target message rule number.

[0090] Using the above example, if the destination port number is 5, and as shown in Table 1, the port segment start values ​​include 3, 4, and 6, and the corresponding binary values ​​are 0011B, 0100B, and 0110B. The mask lengths corresponding to the start values ​​of each port segment are 2, 3, and 2, respectively. From the above analysis, it can be seen that the target port group is port group 4, and its corresponding rule numbers include 123 and 124.

[0091] At this time, the priorities of rule number 123 and rule number 124 can be obtained. For example, the priorities can be divided into 5 levels, from 1 to 5, and the larger the number, the higher the priority. Assume that the priority of rule number 123 is 4 and the priority of rule number 124 is 3. By comparison, it can be seen that rule number 123 has the highest priority, so rule number 123 is used as the target message rule number. Finally, based on the for relationship, the target message rule corresponding to the target message rule number 123 is obtained.

[0092] In this way, a target rule is selected from a plurality of rule numbers by using a priority set in advance, thereby determining a target message rule.

[0093] Furthermore, after obtaining the target message rule, the message to be matched may be configured based on the target message rule.

[0094] It is understandable that in different implementation scenarios, the manner of configuring the matching messages based on the target message rule may be different.

[0095] Please refer to Figure 3 Before step S1, the present application may also pre-configure the port matching table entries.

[0096] Step S0, splitting and configuring multiple port numbers to obtain port matching table entries.

[0097] As an optional implementation, step S0 may be implemented in the following manner:

[0098] Convert multiple port numbers into binary numbers consisting of a preset number of bits. Group the port numbers with the same value of the preset bits into a group to obtain multiple port groups. Use the number of preset bits as the mask length of each port group, and use the starting port number of each port group as the starting value of the port segment of the port group. Generate a correspondence table based on multiple port groups and multiple rule numbers. Use each mask length and each port segment starting value as table items of the correspondence table to obtain a port matching table item.

[0099] The following is a detailed example of how to divide port 3, port 4, port 5, port 6 and port 7 to help understand the above division method. As shown in Table 2, the port number (i.e., the port shown in Table 2) is converted into a binary number including 4 bits as shown in the table. For example, the binary number of port number 3 is 0011, the value of its third bit (i.e., bit3) is 0, the value of its second bit (i.e., bit2) is 0, the value of its first bit (i.e., bit1) is 1, and the value of its zeroth bit (i.e., bit0) is 1. The other port numbers are also converted into binary numbers as shown in Table 2, and are not listed here.

[0100] Table 2

[0101] port bit3 bit2 bit1 bit0 3 0 0 1 1 4 0 1 0 0 5 0 1 0 1 6 0 1 1 0 7 0 1 1 1

[0102] If the number of preset bits is 2, by comparing each port number converted to binary numbers, it can be seen that the values ​​of bit3 and bit2 of port 3 are different from the values ​​of bit3 and bit2 of other port numbers, and the values ​​of bit3 and bit2 of port 4, port 5, port 6 and port 7 are the same. Therefore, port 3 can be divided into a port group separately, and its mask length is the same as the number of preset bits, which is 4, and its port segment starting value is the same as the port number, which is 3; port 4, port 5, port 6 and port 7 are divided into a port group, and its mask length is the same as the number of preset bits, which is 2, and its port segment starting value is the same as the port with the smallest port number in the port group, which is 4.

[0103] If the number of preset bits is 3, by comparing each port number converted to binary, it can be seen that the values ​​of bit3, bit2 and bit1 of port 3 are different from the values ​​of bit3, bit2 and bit1 of other port numbers; the values ​​of bit3, bit2 and bit1 of port 4 and port 5 are the same, which is 010; the values ​​of the first three bits of port 6 and port 7 are the same, which is 011. Therefore, port 3 can be divided into a port group separately, and its mask length is the same as the number of preset bits, which is 4, and its port segment start value is the same as the smallest port number, which is 4; port 4 and port 5 are divided into a port group, and its mask length is the same as the number of preset bits, which is 3, and its port segment start value is the same as the port with the smallest port number in the port group, which is 4; port 6 and port 7 are divided into a port group, and its mask length is the same as the number of preset bits, which is 3, and its port segment start value is the same as the port with the smallest port number in the port group, which is 5.

[0104] As an optional implementation manner, port numbers with consistent values ​​of preset bits may be grouped into one group to obtain multiple port groups.

[0105] Get the port number of the port to be divided, and calculate the first division boundary value according to the following formula:

[0106] A÷2 n =B, where B is an integer, A is the port number of the port to be divided, n is the first division boundary value, and n=(0, 1, ...15).

[0107] Determine whether the total number of ports to be divided is greater than or equal to 2 n , where n is the first partition boundary value.

[0108] If the total number is greater than or equal to 2 n , then [port to be divided, port to be divided + 2 n -1] as a port group, and the next remaining port to be divided is used as the port to be divided, and the step of obtaining the port number of the port to be divided is performed again until each port is divided.

[0109] If the total number is less than 2 n , then the second partition boundary value will be calculated according to the following formula:

[0110] A÷2 m ≤C, where A is the port number of the port to be divided, m is the second division boundary value, and C is the total number.

[0111] [port to be allocated, port to be allocated + 2 m-1] as a port group, and the next remaining port to be divided is used as the port to be divided, and the step of obtaining the port number of the port to be divided is performed again until each port is divided.

[0112] The following also provides a detailed example of how to divide port 3, port 4 and port 5 to help understand the above division method.

[0113] First, divide port 3, that is, the port number of the port to be divided is 3. According to the formula, n is 0. The total number of ports to be divided is 3 (port 3 + port 4 + port 5). It can be seen that the total number 3 is greater than 2. 0 , so [3, 3+2 0 -1] as a port group, that is, port 3 is regarded as a port group alone.

[0114] Next, port 4 is divided, that is, the port number of the port to be divided is 4. According to the formula, n is 1. The total number of ports to be divided is 2 (port 4 + port 5). It can be seen that the total number is equal to 2. 1 , so [4, 4+2 1 -1] as a port group, that is, port 4 and port 5 are collectively regarded as a port group.

[0115] Based on the same invention concept, please refer to Figure 4 In an embodiment of the present application, a message rule matching device corresponding to the above message rule matching method is also provided, and the device includes:

[0116] The acquisition module 131 is used to acquire the message to be matched, where the message to be matched includes a destination port number.

[0117] The search module 132 is used to search the target port group to which the destination port number belongs and at least one rule number corresponding to the target port group from the pre-configured port matching table entry, wherein the port matching table entry includes at least one port group and the correspondence between the port number group and the rule number.

[0118] The corresponding module 133 is used to obtain the target message rule corresponding to the message to be matched based on the pre-configured correspondence between the rule number and the message rule.

[0119] As an optional implementation, each port group includes a port segment start value and a mask length. The search module 132 is used to obtain the destination port number in the message to be matched. Based on the longest prefix matching principle, the value of each port segment start value in the port matching table item is compared bit by bit with the value of the bit of the destination port number, and at least one port segment start value matching the destination port number and the mask length corresponding to each of the port segment start values ​​are obtained. The port group to which the port segment start value matching the destination port number and corresponding to the longest mask length belongs is taken as the target port group.

[0120] As an optional implementation, the device further includes: a configuration module 134, configured to split and configure multiple port numbers to obtain port matching table entries.

[0121] The configuration module 134 is also used to convert multiple port numbers into binary numbers consisting of a preset number of bits. Port numbers with the same value of the preset bits are divided into a group to obtain multiple port groups. The number of preset bits is used as the mask length of each port group, and the starting port number of each port group is used as the starting value of the port segment of the port group. A correspondence table is generated based on multiple port groups and multiple rule numbers. Each mask length and each port segment starting value are used as table items of the correspondence table to obtain a port matching table item.

[0122] Since the principle of solving the problem by the device in the embodiment of the present application is similar to the above-mentioned message rule matching method in the embodiment of the present application, the implementation principle of the device can refer to the implementation principle of the method, and the repeated parts will not be repeated.

[0123] An embodiment of the present application also provides a readable storage medium, in which a computer program is stored. When the computer program is executed, the above-mentioned message rule matching method is implemented.

[0124] In summary, the embodiments of the present application provide a message rule matching method, device, electronic device 100 and readable storage medium, the method obtains a message to be matched, and the message to be matched includes a destination port number. Then, the target port group to which the destination port number belongs and at least one rule number corresponding to the target port group are found from the pre-configured port matching table entry, wherein the port matching table entry includes at least one port group and a correspondence between the port number group and the rule number. Finally, based on the correspondence between the pre-configured rule number and the message rule, the target message rule corresponding to the message to be matched is obtained without traversing each port number, so that the time for matching the message is shortened and the matching rate is improved.

[0125] The above is only a specific implementation of the present application, but the protection scope of the present application is not limited thereto. Any changes or substitutions that can be easily thought of by a person skilled in the art within the technical scope disclosed in the present application should be included in the protection scope of the present application. Therefore, the protection scope of the present application shall be based on the protection scope of the claims.

Claims

1. A message rule matching method, It is characterized in that The method comprises: Obtaining a message to be matched, wherein the message to be matched includes a destination port number; Find out the target port group to which the destination port number belongs and at least one rule number corresponding to the target port group from a pre-configured port matching table entry, wherein the port matching table entry includes at least one port group and a corresponding relationship between a port number group and a rule number; Based on the pre-configured correspondence between the rule number and the message rule, obtaining the target message rule corresponding to the message to be matched; Each of the port groups includes a port segment start value and a mask length; the step of finding the target port group to which the destination port number belongs from the pre-configured port matching table includes: Obtaining the destination port number in the message to be matched; Based on the longest prefix matching principle, compare the value of each port segment starting value in the port matching table entry with the bit of the destination port number bit by bit, and obtain at least one port segment starting value matching the destination port number, and a mask length corresponding to each of the port segment starting values; The port group to which the starting value of the port segment that matches the destination port number and has the longest corresponding mask length belongs is taken as the target port group.

2. The message rule matching method according to claim 1, It is characterized in that The method further includes: splitting and configuring a plurality of port numbers to obtain a port matching table entry, the steps including: Converting the plurality of port numbers into a binary number consisting of a preset number of bits; The port numbers having the same value of the preset bit are divided into a group to obtain a plurality of port groups; The number of the preset bits is used as the mask length of each port group, and the starting port number of each port group is used as the starting value of the port segment of the port group; Generate a corresponding relationship table based on the plurality of port groups and the plurality of rule numbers; Each of the mask lengths and each of the port segment start values ​​are used as table entries in the correspondence table to obtain a port matching table entry.

3. The message rule matching method according to claim 1, It is characterized in that There are multiple rule numbers corresponding to the target port; The step of acquiring the target message rule corresponding to the message to be matched based on the pre-configured correspondence between the rule number and the rule comprises: Obtaining the priority of each rule number; The rule number with the highest priority is used as the target message rule number; Based on the pre-configured correspondence between the rule number and the rule, a target message rule corresponding to the target message rule number is obtained.

4. The message rule matching method according to claim 1, It is characterized in that The method further comprises: The to-be-matched message is configured based on the target message rule.

5. A message rule matching device, It is characterized in that The device comprises: An acquisition module, used for acquiring a message to be matched, wherein the message to be matched includes a destination port number; A search module, used to search for a target port group to which the destination port number belongs and at least one rule number corresponding to the target port group from a pre-configured port matching table entry, wherein the port matching table entry includes at least one port group and a corresponding relationship between a port number group and a rule number; Based on the pre-configured correspondence between the rule number and the message rule, obtaining the target message rule corresponding to the message to be matched; Each of the port groups includes a port segment start value and a mask length; the search module is used to obtain the destination port number in the message to be matched; Based on the longest prefix matching principle, compare the value of each port segment starting value in the port matching table entry with the bit of the destination port number bit by bit, and obtain at least one port segment starting value matching the destination port number, and a mask length corresponding to each of the port segment starting values; The port group to which the starting value of the port segment that matches the destination port number and has the longest corresponding mask length belongs is taken as the target port group.

6. The message rule matching device according to claim 5, It is characterized in that The device also includes: A configuration module is used to split and configure multiple port numbers to obtain port matching table entries; The configuration module is also used to convert the multiple port numbers into binary numbers consisting of a preset number of bits; The port numbers having the same value of the preset bit are divided into a group to obtain a plurality of port groups; The number of the preset bits is used as the mask length of each port group, and the starting port number of each port group is used as the starting value of the port segment of the port group; Generate a corresponding relationship table based on the plurality of port groups and the plurality of rule numbers; Each of the mask lengths and each of the port segment start values ​​are used as table entries in the correspondence table to obtain a port matching table entry.

7. An electronic device, It is characterized in that The electronic device includes a processor, a memory and a bus, the memory stores machine-readable instructions executable by the processor, and when the electronic device is running, the processor and the memory communicate through the bus, and the processor executes the machine-readable instructions to perform the steps of the message rule matching method described in any one of claims 1-4.

8. A readable storage medium, It is characterized in that The readable storage medium stores a computer program, and when the computer program is executed, the steps of the message rule matching method according to any one of claims 1 to 4 are implemented.