CN112380253A - Message rule matching method and device, electronic equipment and readable storage medium - Google Patents

Message rule matching method and device, electronic equipment and readable storage medium Download PDF

Info

Publication number
CN112380253A
CN112380253A CN202011259374.7A CN202011259374A CN112380253A CN 112380253 A CN112380253 A CN 112380253A CN 202011259374 A CN202011259374 A CN 202011259374A CN 112380253 A CN112380253 A CN 112380253A
Authority
CN
China
Prior art keywords
port
rule
message
target
matching
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Pending
Application number
CN202011259374.7A
Other languages
Chinese (zh)
Inventor
陈金战
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Beijing Knownsec Information Technology Co Ltd
Original Assignee
Beijing Knownsec Information Technology Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Beijing Knownsec Information Technology Co Ltd filed Critical Beijing Knownsec Information Technology Co Ltd
Priority to CN202011259374.7A priority Critical patent/CN112380253A/en
Publication of CN112380253A publication Critical patent/CN112380253A/en
Pending legal-status Critical Current

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/20Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
    • G06F16/24Querying
    • G06F16/245Query processing
    • G06F16/2455Query execution
    • G06F16/24564Applying rules; Deductive queries
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/20Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
    • G06F16/22Indexing; Data structures therefor; Storage structures
    • G06F16/2282Tablespace storage structures; Management thereof
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/20Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
    • G06F16/24Querying
    • G06F16/242Query formulation
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/20Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
    • G06F16/24Querying
    • G06F16/245Query processing
    • G06F16/2455Query execution

Abstract

The embodiment of the application provides a message rule matching method and device, electronic equipment and a readable storage medium, and relates to the technical field of communication. The method comprises the steps of obtaining a message to be matched, wherein the message to be matched comprises a target port number. And searching a target port group to which the target 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 comprises at least one port group and a corresponding relation between the port number group and the rule number. And finally, acquiring a target message rule corresponding to the message to be matched based on the corresponding relation between the preset rule number and the message rule without traversing each port, so that the time for matching the message rule is shortened, and the message matching rate is improved.

Description

Message rule matching method and device, electronic equipment and readable storage medium
Technical Field
The present application relates to the field of communications technologies, and in particular, to a method and an apparatus for matching a message rule, an electronic device, and a readable storage medium.
Background
With the continuous development of internet technology, in order to increase the speed of processing services, the requirements on the performance of network devices for processing messages are higher and higher, and then the requirements on the corresponding message fast matching algorithm are higher and higher.
At present, all ports are often recorded in a configuration table entry, and rules corresponding to the ports are traversed when messages are matched, so that rules which can be matched are found out. However, when there are more rules, the rate is lower using the method of traversing ports to find rules.
Disclosure of Invention
The application provides a message rule matching method, a message rule matching device, electronic equipment and a readable storage medium, so as to solve the problems.
The embodiment of the application can be realized as follows:
in a first aspect, the present application provides a method for matching a message rule, where the method includes:
acquiring a message to be matched, wherein the message to be matched comprises a destination port number;
searching a target port group to which the target 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 comprises at least one port group and a corresponding relation between the port number group and the rule number;
and acquiring a target message rule corresponding to the message to be matched based on the corresponding relation between the rule number and the message rule which is configured in advance.
In an alternative embodiment, each of the port groups includes a port segment start value and a mask length; the step of finding out the target port group to which the target port number belongs from the pre-configured port matching table entry includes:
acquiring a destination port number in the message to be matched;
based on the longest prefix matching principle, comparing the numerical value of the bit of each port section initial value and the target port number in the port matching table entry bit by bit to obtain at least one port section initial value matched with the target port number and a mask length corresponding to each port section initial value;
and taking the port group which is matched with the destination port number and to which the port segment initial value with the longest corresponding mask length belongs as a target port group.
In an alternative embodiment, the method further comprises: splitting and configuring a plurality of port numbers to obtain a port matching table entry, wherein the step comprises the following steps:
converting the plurality of port numbers into binary numbers consisting of a preset number of bits;
dividing the port numbers with consistent numerical values of preset bits into a group to obtain a plurality of port groups;
taking the number of the preset bits as the mask length of each port group, and taking the starting port number of each port group as the starting value of the port segment of the port group;
generating a corresponding relation table based on the plurality of port groups and the plurality of rule numbers;
and taking each mask length and each port segment initial value as an item of the corresponding relation table to obtain a port matching item.
In an optional embodiment, the number of the rules corresponding to the target port is multiple;
the step of obtaining the target message rule corresponding to the message to be matched based on the pre-configured corresponding relationship between the rule number and the rule comprises the following steps:
acquiring the priority of each rule number;
taking the rule number with the highest priority as the rule number of the target message;
and acquiring a target message rule corresponding to the target message rule number based on the corresponding relation between the rule number and the rule configured in advance.
In an alternative embodiment, the method further comprises:
and configuring the message to be matched based on the target message rule.
In a second aspect, the present application provides a packet rule matching apparatus, where the apparatus includes:
the device comprises an acquisition module, a matching module and a matching module, wherein the acquisition module is used for acquiring a message to be matched, and the message to be matched comprises a target port number;
the searching module is used for searching a target port group to which the target 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 comprises at least one port group and a corresponding relation between the port number group and the rule number;
and acquiring a target message rule corresponding to the message to be matched based on the corresponding relation between the rule number and the message rule which is configured in advance.
In an alternative embodiment, each of the port groups includes a port segment start value and a mask length;
the searching module is used for acquiring a destination port number in the message to be matched;
based on the longest prefix matching principle, comparing the numerical value of the bit of each port section initial value and the target port number in the port matching table entry bit by bit to obtain at least one port section initial value matched with the target port number and a mask length corresponding to each port section initial value;
and taking the port group which is matched with the destination port number and to which the port segment initial value with the longest corresponding mask length belongs as a target port group.
In an alternative embodiment, the apparatus further comprises:
the configuration module is used for splitting and configuring the plurality of port numbers to obtain port matching table entries;
the configuration module is also used for converting the plurality of port numbers into binary numbers consisting of bits with preset number;
dividing the port numbers with consistent numerical values of preset bits into a group to obtain a plurality of port groups;
taking the number of the preset bits as the mask length of each port group, and taking the starting port number of each port group as the starting value of the port segment of the port group;
generating a corresponding relation table based on the plurality of port groups and the plurality of rule numbers;
and taking each mask length and each port segment initial value as an item of the corresponding relation table to obtain a port matching item.
In a third aspect, the present application provides an electronic device, where the electronic device includes a processor, a memory, and a bus, where the memory stores machine-readable instructions executable by the processor, and when the electronic device runs, the processor and the memory communicate with each other through the bus, and the processor executes the machine-readable instructions to perform the steps of the message rule matching method according to any one of the foregoing embodiments.
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 according to any one of the foregoing embodiments are implemented.
The embodiment of the application provides a message rule matching method and device, electronic equipment and a readable storage medium, a target port section in a message to be matched is matched with a port matching table item, a target port group to which the target port section belongs in the port matching table item is searched, a rule number corresponding to the target port group is obtained, and a target message rule is further obtained without traversing each port, so that the time for matching the message rule is shortened, and the message matching rate is improved.
In order to make the aforementioned objects, features and advantages of the present application more comprehensible, several embodiments accompanied with figures are described in detail below.
Drawings
In order to more clearly illustrate the technical solutions of the embodiments of the present application, the drawings that are required to be used in the embodiments will be briefly described below, it should be understood that the following drawings only illustrate some embodiments of the present application and therefore should not be considered as limiting the scope, and for those skilled in the art, other related drawings can be obtained from the drawings without inventive effort.
Fig. 1 is a block diagram of an electronic device according to an embodiment of the present disclosure.
Fig. 2 is a flowchart of a message rule matching method according to an embodiment of the present application.
Fig. 3 is a second flowchart of a message rule matching method according to an embodiment of the present application.
Fig. 4 is a functional module block diagram of a message rule matching apparatus according to an embodiment of the present application.
Icon: 100-an electronic device; 110-a memory; 120-a processor; 130-message rule matching means; 131-an acquisition module; 132-a lookup module; 133-a corresponding module; 134-configuration module; 140-a communication unit.
Detailed Description
In order to make the objects, technical solutions and advantages of the embodiments of the present application clearer, the technical solutions in the embodiments of the present application will be clearly and completely described below with reference to the drawings in the embodiments of the present application, and it is obvious that the described embodiments are some embodiments of the present application, but not all embodiments. The components of the embodiments of the present application, generally described and illustrated in the figures herein, can be arranged and designed in a wide variety of different configurations.
Thus, the following detailed description of the embodiments of the present application, presented in the accompanying drawings, is not intended to limit the scope of the claimed application, but is merely representative of selected embodiments of the application. All other embodiments, which can be derived by a person skilled in the art from the embodiments given herein without making any creative effort, shall fall within the protection scope of the present application.
It should be noted that: like reference numbers and letters refer to like items in the following figures, and thus, once an item is defined in one figure, it need not be further defined and explained in subsequent figures.
In the description of the present application, it should be noted that if the terms "upper", "lower", "inside", "outside", etc. are used for indicating the orientation or positional relationship based on the orientation or positional relationship shown in the drawings or the orientation or positional relationship which the present invention product is usually put into use, it is only for convenience of describing the present application and simplifying the description, but it is not intended to indicate or imply that the referred device or element must have a specific orientation, be constructed in a specific orientation and be operated, and thus, should not be construed as limiting the present application.
Furthermore, the appearances of the terms "first," "second," and the like, if any, are used solely to distinguish one from another and are not to be construed as indicating or implying relative importance.
It should be noted that the features of the embodiments of the present application may be combined with each other without conflict.
As introduced in the background art, with the continuous development of internet technology, the performance requirement for processing messages by network devices is higher and higher, and the requirement for the corresponding message fast matching algorithm is higher and higher.
At present, all ports are often recorded in a configuration table entry, each port corresponds to one rule, each port is traversed when messages are matched, and a corresponding matching rule is found out. However, when there are more rules, the rate is lower using the method of traversing ports to match rules.
In view of this, embodiments of the present application provide a message rule matching method, an apparatus, an electronic device, and a readable storage medium, where a target rule is found by matching a message to be matched with a port matching entry, and traversal is not required, so that matching time is shortened, and matching rate is improved.
Referring to fig. 1, fig. 1 is a block diagram of an electronic device 100 according to an embodiment of the present disclosure. The device may include a processor 120, a memory 110, a message rule matching apparatus 130, and a communication unit 140, where the memory 110 stores machine-readable instructions executable by the processor 120, when the electronic device 100 operates, the processor 120 and the memory 110 communicate with each other through a bus, and the processor 120 executes the machine-readable instructions and performs the steps of the message rule matching method.
The elements of the memory 110, the processor 120 and the communication unit 140 are electrically connected to each other directly or indirectly to realize the transmission or interaction of signals.
For example, the 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 functional module which can be stored in the memory 110 in the form of software or firmware (firmware). The processor 120 is used to execute an executable module stored in the memory 110, such as a software functional module or a computer program included in the message rule matching apparatus 130.
The Memory 110 may be, but is not limited to, a Random ACCess Memory (RAM), a Read Only Memory (ROM), a Programmable Read-Only Memory (PROM), an Erasable Read-Only Memory (EPROM), an electrically Erasable Read-Only Memory (EEPROM), and the like.
The processor 120 may be an integrated circuit chip having signal processing capabilities. The Processor 120 may be a general-purpose Processor, and includes a Central Processing Unit (CPU), a Network Processor (NP), and so on.
But may also be a Digital Signal Processor (DSP), an Application Specific Integrated Circuit (ASIC), a Field Programmable Gate Array (FPGA) or other programmable logic device, discrete gate or transistor logic device, discrete hardware components. The various methods, steps, and logic blocks disclosed in the embodiments of the present application may be implemented or performed. A general purpose processor may be a microprocessor or the processor may be any conventional processor or the like.
In the embodiment of the present application, the memory 110 is used for storing a program, and the processor 120 is used for executing the program after receiving the execution instruction. The method defined by the process disclosed in any of the embodiments of the present application can be applied to the processor 120, or implemented by the processor 120.
The communication unit 140 is used to establish a communication connection between the electronic apparatus 100 and another electronic apparatus via a network, and to transmit and receive data via the network.
In some embodiments, the network may be any type of wired or wireless network, or combination thereof. Merely by way of example, 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, a Near Field Communication (NFC) Network, or the like, or any combination thereof.
In the embodiment of the present application, the specific type of the electronic device 100 is not limited, and for example, the electronic device may be, but is not limited to, a smart phone, a Personal Computer (PC), a tablet PC, a Personal Digital Assistant (PDA), a Mobile Internet Device (MID), a web server, a data server, a gateway device, and other devices having a processing function.
It will be appreciated that the configuration shown in figure 1 is merely illustrative. Electronic device 100 may also have more or fewer components than shown in FIG. 1, or a different configuration than shown in FIG. 1. The components shown in fig. 1 may be implemented in hardware, software, or a combination thereof.
Based on the implementation architecture of the electronic device 100, an embodiment of the present application provides a message rule matching method, please refer to fig. 2 in combination, and fig. 2 is one of flowcharts of the message rule matching method provided in the embodiment of the present application. The following is described in detail with reference to the specific flow shown in fig. 2.
Step S1, obtaining the message to be matched, wherein the message to be matched comprises the destination port number.
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.
The port matching table entry comprises at least one port group and the corresponding relation between the port group and the rule number.
Step S3, based on the corresponding relationship between the preset rule number and the message rule, the target message rule corresponding to the message to be matched is obtained.
As a possible implementation, the electronic device 100 may be a network switching device, and the message rule may be an ACL rule configured in advance. The ACL rules are used to filter messages identifying different services.
For example, the network switching device obtains a message to be matched, obtains a destination port number 3 included in the message to be matched, and finds out that a destination port group to which the destination port number belongs is 1 from a pre-configured port matching table entry, and a rule number corresponding to the destination port group 1 is 123. And finally, acquiring the target message rule corresponding to the rule number 123.
According to the method and the device for matching the message rule, the target port group to which the target port section belongs in the port matching table entry is searched by matching the target port section in the message to be matched with the port matching table entry, the rule number corresponding to the target port group is obtained, and the target message rule is further obtained without traversing each port, so that the time for matching the message rule is shortened, and the matching rate is improved.
Optionally, each port group includes a port segment start value and a mask length. Matching search can be performed based on the port segment start value and the mask length to obtain a target port group to which the target port number belongs.
On the basis of the above, as an optional implementation manner, step S2 may be implemented in the following manner to find out the target port group to which the destination port number belongs:
and acquiring the destination port number in the message to be matched. Based on the Longest Prefix Match (LPM), comparing the start value of each port segment in the port matching table entry with the bit value of the destination port number bit by bit to obtain at least one start value of the port segment matched with the destination port number and the mask length corresponding to each start value of the port segment. And taking the port group which is matched with the destination port number and to which the port segment initial value with the longest corresponding mask length belongs as the target port group.
For example, the destination port number is 5, and as shown in table 1, the port segment start value includes 3, 4, and 6, and the corresponding binary values are 0011B, 0100B, and 0110B. The mask length corresponding to the start value of each port segment is 2, 3 and 2 respectively.
TABLE 1
Port group Port segment start value Mask length Rule numbering
3 3(0011B) 2 123
4 4(0100B) 3 123,124
6 6(0110B) 2 124
Wherein, the destination port number 5 can be represented as 0101 by using a binary representation method.
The value of each bit of the destination port number and the port segment start value is matched bit by bit, and it can be known that the bit of the destination port number 5 matched with the port segment start value 3 is 1 bit, the corresponding mask length is 2, the bit of the destination port number 5 matched with the port segment start value 4 is 3 bits, the corresponding mask length is 3, the bit of the destination port number 6 matched with the port segment start value 3 is 2 bits, and the corresponding mask length is 2. As can be seen from the comparison, the port segment with the longest mask length has an initial value of 4, and the port group thereof is port group 4, so that port group 4 is the target port group.
As a possible implementation manner, the rule numbers corresponding to the target ports are multiple, and at this time, the step S3 may be implemented by the following manner to obtain the target message rule corresponding to the message to be matched:
the priority of each rule number is obtained. And taking the rule number with the highest priority as the rule number of the target message. And acquiring the target message rule corresponding to the target message rule number based on the corresponding relation between the preset rule number and the rule.
Also using the above example, if the destination port number is 5, and as shown in table 1, the port segment start value includes 3, 4, and 6, the corresponding binary values are 0011B, 0100B, and 0110B. The mask length corresponding to the start value of each port segment is 2, 3 and 2 respectively. From the above analysis, the target port set is port set 4, and the corresponding rule numbers include 123 and 124.
At this time, the priority of the rule number 123 and the rule number 124 may be acquired, for example, the priority may be divided into 5 levels, and from 1 to 5, 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. Comparing, it can be seen that the rule number 123 has the highest priority, and then the rule number 123 is used as the target message rule number. Finally, based on the relation, the target packet rule corresponding to the target packet rule number 123 is obtained.
Thus, the target rule is selected from the rule numbers through the priority set in advance, and the target message rule is determined.
Further, after the target message rule is obtained, the message to be matched can be configured based on the target message rule.
It can be understood that, in different implementation scenarios, the manner of configuring the message to be matched based on the target message rule may be different.
Referring to fig. 3, before step S1, the present application may also perform configuration of the port matching entry in advance.
Step S0, splitting and configuring the plurality of port numbers to obtain a port matching entry.
As an alternative embodiment, step S0 can be implemented by:
the plurality of port numbers are converted into a binary number consisting of a preset number of bits. And dividing the port numbers with consistent numerical values of the preset bits into a group to obtain a plurality of port groups. And taking the number of preset bits as the mask length of each port group, and taking the starting port number of each port group as the starting value of the port segment of the port group. And generating a corresponding relation table based on the plurality of port groups and the plurality of rule numbers. And taking each mask length and each port segment initial value as the table entry of the corresponding relation table to obtain a port matching table entry.
The following detailed examples of how the ports 3, 4, 5, 6 and 7 are divided will help to understand the above dividing manner. As shown in table 2, the port numbers (i.e., the ports shown in table 2) converting the ports into binary numbers including 4 bits are shown in the table, respectively. For example, the binary number of port number 3 is 0011, the value of the third bit (i.e., bit3) is 0, the value of the second bit (i.e., bit2) is 0, the value of the first bit (i.e., bit1) is 1, and the value of the zeroth bit (i.e., bit0) is 1. The other port numbers are also shown in table 2 after being converted into binary numbers, and are not exemplified here.
TABLE 2
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
If the number of the preset bits is 2, the number of each port converted into the binary number is compared to know that the values of bit3 and bit2 of the port 3 are different from the values of bit3 and bit2 of other port numbers, and the values of bit3 and bit2 of the port 4, the port 5, the port 6 and the port 7 are the same, so that the port 3 can be independently divided into a port group, the mask length of the port group is 4 as the number of the preset bits, and the starting value of the port section is 3 as the starting value of the port group is as the same as the port number; the port 4, the port 5, the port 6 and the port 7 are divided into a port group, the mask length of the port group is the same as the number of preset bits and is 2, and the port segment initial value of the port group is the same as the port with the minimum port number in the port group and is 4.
If the number of the preset bits is 3, the number of the port numbers converted into binary numbers is compared to know that the numerical values of bit3, bit2 and bit1 of the port 3 are different from the numerical values of bit3, bit2 and bit1 of other port numbers; the values of bit3, bit2 and bit1 of the port 4 and the port 5 are all the same and are 010; the first three bits of port 6 and port 7 have the same value, which is 011. Therefore, the ports 3 can be individually divided into a port group, the mask length of the port group is the same as the number of preset bits and is 4, and the port section initial value of the port group is the same as the minimum port number and is 4; dividing the ports 4 and 5 into a port group, wherein the mask length of the port group is the same as the number of preset bits and is 3, and the port section initial value of the port group is the same as the port with the minimum port number in the port group and is 4; the ports 6 and 7 are divided into a port group, the mask length of the port group is the same as the number of preset bits and is 3, and the port segment initial value of the port group is the same as the port with the minimum port number in the port group and is 5.
As an optional implementation manner, the port numbers with the consistent numerical values of the preset bits may be further divided into one group in the following manner, so as to obtain a plurality of port groups.
Acquiring a port number of a port to be divided, and calculating according to the following formula to obtain a first division boundary value:
A÷2nb, where B is an integer, a is a port number of a port to be partitioned, n is a first partition boundary value, and n is (0, 1, … 15).
Judging whether the total number of the ports to be divided is more than or equal to 2nWherein n is a first division boundary value.
If the total number is greater than or equal to 2nThen [ port to be divided, port to be divided + 2%n-1]And taking the port group as a port group, taking the next remaining port to be divided as a port to be divided, and executing the step of obtaining the port number of the port to be divided again until all the ports are divided.
If the total number is less than 2nThen it will be calculated according to the following formulaObtaining a second partition boundary value:
A÷2mand C is less than or equal to C, wherein A is the port number of the port to be divided, m is the second division boundary value, and C is the total number.
Will [ port to be divided, port to be divided +2m-1]And taking the port group as a port group, taking the next remaining port to be divided as a port to be divided, and executing the step of obtaining the port number of the port to be divided again until all the ports are divided.
How ports 3, 4 and 5 are divided is also exemplified in detail below to help understand the above division.
Firstly, the port 3 is divided, that is, the port number of the port to be divided is 3. According to the formula, n is 0. The total number of the ports to be divided is 3 (port 3+ port 4+ port 5), and the judgment shows that the total number 3 is more than 20Thus, can be [3, 3+2 ]0-1]As a port group, i.e., port 3 alone as a port group.
Next, the 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 the ports to be divided is 2 (port 4+ port 5), and the judgment shows that the total number is equal to 21Thus, can be [4, 4+2 ]1-1]As one port group, that is, the port 4 and the port 5 are collectively one port group.
Based on the same inventive concept, please refer to fig. 4 in combination, an embodiment of the present application further provides a message rule matching apparatus corresponding to the message rule matching method, and the apparatus includes:
the obtaining module 131 is configured to obtain a message to be matched, where the message to be matched includes a destination port number.
The searching module 132 is configured to search a target port group to which a target port number belongs and at least one rule number corresponding to the target port group from a pre-configured port matching entry, where the port matching entry includes the at least one port group and a corresponding relationship between the port number group and the rule number.
The corresponding module 133 is configured to obtain a target packet rule corresponding to the packet to be matched based on a corresponding relationship between the pre-configured rule number and the packet rule.
As an alternative embodiment, each port group includes a port segment start value and a mask length. The searching module 132 is configured to obtain a destination port number in the message to be matched. Based on the longest prefix matching principle, comparing the starting value of each port segment in the port matching table entry with the bit value of the destination port number bit by bit to obtain at least one starting value of the port segment matched with the destination port number and the mask length corresponding to each starting value of the port segment. And taking the port group which is matched with the destination port number and to which the port segment initial value with the longest corresponding mask length belongs as the target port group.
As an optional implementation, the apparatus further comprises: the configuration module 134 is configured to split and configure a plurality of port numbers to obtain a port matching entry.
The configuration module 134 is further configured to convert the plurality of port numbers into binary numbers comprising a predetermined number of bits. And dividing the port numbers with consistent numerical values of the preset bits into a group to obtain a plurality of port groups. And taking the number of preset bits as the mask length of each port group, and taking the starting port number of each port group as the starting value of the port segment of the port group. And generating a corresponding relation table based on the plurality of port groups and the plurality of rule numbers. And taking each mask length and each port segment initial value as the table entry of the corresponding relation table to obtain a port matching table entry.
Because the problem solving principle of the device in the embodiment of the present application is similar to that of the message rule matching method in the embodiment of the present application, the implementation principle of the device may refer to the implementation principle of the method, and repeated details are not repeated.
The embodiment of the present application also provides a readable storage medium, in which a computer program is stored, and when the computer program is executed, the method for matching message rules is implemented.
In summary, the embodiment of the present application provides a message rule matching method, an apparatus, an electronic device 100, and a readable storage medium, where the method obtains a message to be matched, where the message to be matched includes a destination port number. And then searching a target port group to which the target 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 comprises at least one port group and a corresponding relation between the port number group and the rule number. And finally, acquiring a target message rule corresponding to the message to be matched based on the corresponding relation between the preset rule number and the message rule without traversing each port number, so that the time for matching the message is shortened, and the matching rate is improved.
The above description is only for the specific embodiments of the present application, but the scope of the present application is not limited thereto, and any changes or substitutions that can be easily conceived by those skilled in the art within the technical scope of the present application should be covered within the scope of the present application. Therefore, the protection scope of the present application shall be subject to the protection scope of the claims.

Claims (10)

1. A message rule matching method is characterized in that the method comprises the following steps:
acquiring a message to be matched, wherein the message to be matched comprises a destination port number;
searching a target port group to which the target 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 comprises at least one port group and a corresponding relation between the port number group and the rule number;
and acquiring a target message rule corresponding to the message to be matched based on the corresponding relation between the rule number and the message rule which is configured in advance.
2. The message rule matching method according to claim 1, wherein each of the port groups includes a port segment start value and a mask length; the step of finding out the target port group to which the target port number belongs from the pre-configured port matching table entry includes:
acquiring a destination port number in the message to be matched;
based on the longest prefix matching principle, comparing the numerical value of the bit of each port section initial value and the target port number in the port matching table entry bit by bit to obtain at least one port section initial value matched with the target port number and a mask length corresponding to each port section initial value;
and taking the port group which is matched with the destination port number and to which the port segment initial value with the longest corresponding mask length belongs as a target port group.
3. The message rule matching method according to claim 2, wherein the method further comprises: splitting and configuring a plurality of port numbers to obtain a port matching table entry, wherein the step comprises the following steps:
converting the plurality of port numbers into binary numbers consisting of a preset number of bits;
dividing the port numbers with consistent numerical values of preset bits into a group to obtain a plurality of port groups;
taking the number of the preset bits as the mask length of each port group, and taking the starting port number of each port group as the starting value of the port segment of the port group;
generating a corresponding relation table based on the plurality of port groups and the plurality of rule numbers;
and taking each mask length and each port segment initial value as an item of the corresponding relation table to obtain a port matching item.
4. The message rule matching method according to claim 1, wherein a plurality of rule numbers are assigned to the target ports;
the step of obtaining the target message rule corresponding to the message to be matched based on the pre-configured corresponding relationship between the rule number and the rule comprises the following steps:
acquiring the priority of each rule number;
taking the rule number with the highest priority as the rule number of the target message;
and acquiring a target message rule corresponding to the target message rule number based on the corresponding relation between the rule number and the rule configured in advance.
5. The message rule matching method according to claim 1, wherein the method further comprises:
and configuring the message to be matched based on the target message rule.
6. A message rule matching apparatus, the apparatus comprising:
the device comprises an acquisition module, a matching module and a matching module, wherein the acquisition module is used for acquiring a message to be matched, and the message to be matched comprises a target port number;
the searching module is used for searching a target port group to which the target 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 comprises at least one port group and a corresponding relation between the port number group and the rule number;
and acquiring a target message rule corresponding to the message to be matched based on the corresponding relation between the rule number and the message rule which is configured in advance.
7. The message rule matching device according to claim 6, wherein each port group includes a port segment start value and a mask length;
the searching module is used for acquiring a destination port number in the message to be matched;
based on the longest prefix matching principle, comparing the numerical value of the bit of each port section initial value and the target port number in the port matching table entry bit by bit to obtain at least one port section initial value matched with the target port number and a mask length corresponding to each port section initial value;
and taking the port group which is matched with the destination port number and to which the port segment initial value with the longest corresponding mask length belongs as a target port group.
8. The message rule matching device according to claim 7, wherein the device further comprises:
the configuration module is used for splitting and configuring the plurality of port numbers to obtain port matching table entries;
the configuration module is also used for converting the plurality of port numbers into binary numbers consisting of bits with preset number;
dividing the port numbers with consistent numerical values of preset bits into a group to obtain a plurality of port groups;
taking the number of the preset bits as the mask length of each port group, and taking the starting port number of each port group as the starting value of the port segment of the port group;
generating a corresponding relation table based on the plurality of port groups and the plurality of rule numbers;
and taking each mask length and each port segment initial value as an item of the corresponding relation table to obtain a port matching item.
9. An electronic device, comprising a processor, a memory and a bus, wherein the memory stores machine-readable instructions executable by the processor, when the electronic device is running, the processor and the memory communicate via the bus, and the processor executes the machine-readable instructions to perform the steps of the message rule matching method according to any one of claims 1 to 5.
10. A readable storage medium, characterized in that the readable storage medium stores a computer program which, when executed, implements the steps of the message rule matching method according to any one of claims 1 to 5.
CN202011259374.7A 2020-11-12 2020-11-12 Message rule matching method and device, electronic equipment and readable storage medium Pending CN112380253A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202011259374.7A CN112380253A (en) 2020-11-12 2020-11-12 Message rule matching method and device, electronic equipment and readable storage medium

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202011259374.7A CN112380253A (en) 2020-11-12 2020-11-12 Message rule matching method and device, electronic equipment and readable storage medium

Publications (1)

Publication Number Publication Date
CN112380253A true CN112380253A (en) 2021-02-19

Family

ID=74583036

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202011259374.7A Pending CN112380253A (en) 2020-11-12 2020-11-12 Message rule matching method and device, electronic equipment and readable storage medium

Country Status (1)

Country Link
CN (1) CN112380253A (en)

Cited By (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN116232992A (en) * 2022-12-16 2023-06-06 中国联合网络通信集团有限公司 Data forwarding method, device, equipment and storage medium
CN117439898A (en) * 2023-12-22 2024-01-23 深圳万物安全科技有限公司 Network device identification method, network device identification device, and storage medium
WO2024016863A1 (en) * 2022-07-20 2024-01-25 华为技术有限公司 Rule lookup method and apparatus, device and computer-readable storage medium
CN116232992B (en) * 2022-12-16 2024-05-14 中国联合网络通信集团有限公司 Data forwarding method, device, equipment and storage medium

Cited By (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
WO2024016863A1 (en) * 2022-07-20 2024-01-25 华为技术有限公司 Rule lookup method and apparatus, device and computer-readable storage medium
CN116232992A (en) * 2022-12-16 2023-06-06 中国联合网络通信集团有限公司 Data forwarding method, device, equipment and storage medium
CN116232992B (en) * 2022-12-16 2024-05-14 中国联合网络通信集团有限公司 Data forwarding method, device, equipment and storage medium
CN117439898A (en) * 2023-12-22 2024-01-23 深圳万物安全科技有限公司 Network device identification method, network device identification device, and storage medium
CN117439898B (en) * 2023-12-22 2024-03-12 深圳万物安全科技有限公司 Network device identification method, network device identification device, and storage medium

Similar Documents

Publication Publication Date Title
Goloboff Calculating SPR distances between trees
CN112380253A (en) Message rule matching method and device, electronic equipment and readable storage medium
EP3562257B1 (en) Wireless fidelity (wi-fi) connection method and related product
CN112804206A (en) Message matching method and device based on search tree and electronic equipment
CN108805565B (en) Block chain based commitment presence proving method, device and readable storage medium
CN108875006A (en) Determine method and device regional belonging to IP address
CN109905413A (en) A kind of matching process and device of IP address
CN103309893A (en) Character string comparing method and device
CN104572994B (en) Method and apparatus for searching for data
CN110099112A (en) Date storage method, device, medium and terminal device based on point to point network
CN106817390B (en) User data sharing method and device
US20200092169A1 (en) Method for Obtaining Standard Configuration Template of Network Device, and Computing Device
US8380991B2 (en) Hash function based on polymorphic code
CN117134967A (en) Method, device, equipment and storage medium for detecting abnormal network service of host
US9985868B2 (en) Transformation of unstructured network infrastructures into structured virtual topologies suitable for specific routing algorithms
US9201982B2 (en) Priority search trees
CN111597139A (en) Communication method, system, equipment and medium of GPU
KR100720190B1 (en) Fast rule lookup with arbitrary ip range configurations
CN114745311B (en) Network vulnerability two-dimensional boundary condition searching method based on dichotomy
CN105634999B (en) A kind of aging method and device of Media Access Control address
Walter et al. Working on the problem of sorting by transpositions on genome rearrangements
Chechik et al. Reachability and shortest paths in the broadcast CONGEST model
CN115396320A (en) Method, device, equipment and storage medium for determining port connection relation
CN112468480B (en) Data association method, device, equipment and computer storage medium
CN109379214B (en) Configuration method and device of Flexe link

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination