Strategy matching method and device
The method and device improve policy matching speed and efficiency by dividing IP addresses into non-overlapping sub-range segments and using ordered search algorithms, addressing memory and speed issues in traditional dictionary tree methods.
Patent Information
- Application Number
- CN202411181017.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-08-26
- Publication Date
- 2024-12-03
- Estimated Expiration
- Not applicable · inactive patent
AI Technical Summary
Traditional methods for policy matching in network security devices that involve converting IP addresses into network segments and using dictionary trees consume excessive time and memory, especially when dealing with large numbers of IP addresses, leading to slowed search speeds and potential memory exhaustion.
A policy matching method and device that constructs an IP policy group using a set algorithm to divide IP addresses into non-overlapping sub-range segments, ordering these segments, and using search algorithms like binary search or balanced binary trees to quickly identify corresponding security policies.
This approach enhances policy search speed and reduces memory consumption by avoiding overlap between IP address sub-range segments, ensuring accurate and efficient policy matching without multiple inaccurate hits.
Smart Images

Figure CN119071061A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of communication technology, and in particular to a strategy matching method and device. Background Art
[0002] In network security protection, security policies can support referencing IP addresses as filtering conditions for security protection. However, when a large number of IP addresses are configured in a large number of security policies in network security devices, the traditional solution of checking policies one by one can no longer meet the requirements of high performance. Therefore, a fast query mechanism is needed for a given IP address to achieve fast policy matching.
[0003] In the current policy matching scheme, the network security device uniformly converts the IP address into a network segment, constructs a dictionary tree (Trie) acceleration table, and uses the acceleration table to quickly match the IP address. However, in this method, when the security policy references a large number of IP addresses, constructing the above dictionary tree acceleration table is not only time-consuming, but also consumes a large amount of memory, and even causes the memory of the network security device to be exhausted; and when matching policies based on the acceleration table, it will also affect the policy search speed. Summary of the invention
[0004] In view of this, the present application provides a policy matching method and device to improve the matching speed of policy matching based on IP addresses.
[0005] Specifically, the present application is implemented through the following technical solutions:
[0006] According to a first aspect of the present application, a policy matching method is provided, which is applied to a network security device, and the method includes:
[0007] Receive business messages;
[0008] Using the target IP address in the service message, the IP policy group is queried according to a search algorithm that matches the IP policy group, and the target security policy corresponding to the target IP address sub-range segment hit by the target IP address is determined; the IP policy group is constructed according to a set algorithm based on a plurality of pre-configured IP addresses and the security policy corresponding to each IP address, wherein the keyword of the IP policy group is the IP address sub-range segment obtained by dividing the IP address range segment to which each IP address belongs, the key value of the IP policy group is the security policy corresponding to the IP address range segment to which each IP address sub-range segment belongs, and the IP address sub-range segments in the IP policy group are ordered, and there is no overlap between the IP address sub-range segments;
[0009] The target security policy is used to perform policy matching processing on the service message.
[0010] According to a second aspect of the present application, a policy matching device is provided, which is applied to a network security device, and the device includes:
[0011] A receiving unit, used for receiving a service message;
[0012] A query unit, used to query the IP policy group by using the target IP address in the service message according to a search algorithm matching the IP policy group, and determine the target security policy corresponding to the target IP address sub-range segment hit by the target IP address; the IP policy group is constructed according to a set algorithm based on a plurality of pre-configured IP addresses and the security policy corresponding to each IP address, wherein the keyword of the IP policy group is the IP address sub-range segment obtained by dividing the IP address range segment to which each IP address belongs, the key value of the IP policy group is the security policy corresponding to the IP address range segment to which each IP address sub-range segment belongs, and the IP address sub-range segments in the IP policy group are ordered, and there is no overlap between the IP address sub-range segments;
[0013] The matching unit is used to perform policy matching processing on the service message by using the target security policy.
[0014] According to the third aspect of the present application, an electronic device is provided, including a processor and a machine-readable storage medium, the machine-readable storage medium storing a computer program that can be executed by the processor, and the processor is prompted by the computer program to execute the method provided in the first aspect of the embodiment of the present application.
[0015] According to the fourth aspect of the present application, a machine-readable storage medium is provided, which stores a computer program. When called and executed by a processor, the computer program prompts the processor to execute the method provided in the first aspect of the embodiment of the present application.
[0016] Beneficial effects of the embodiments of the present application:
[0017] The policy matching method and device provided in the embodiment of the present application receive a business message; use the target IP address in the business message to query the IP policy group according to the search algorithm matching the IP policy group, and determine the target security policy corresponding to the target IP address sub-range segment hit by the target IP address; use the target security policy to perform policy matching processing on the business message.
[0018] Since the above-mentioned IP policy group is constructed according to a set algorithm based on a plurality of pre-configured IP addresses and the security policy corresponding to each IP address, and the policy search is performed based on the search algorithm corresponding to the IP policy group, the security policy search speed can be guaranteed when the policy search is performed based on the appropriate search algorithm; moreover, the keyword of the above-mentioned IP policy group is the IP address sub-range segment obtained by dividing the IP address range segment to which each IP address belongs, and the key value of the IP policy group is the security policy corresponding to the IP address range segment to which each IP address sub-range segment belongs, and the IP address sub-range segments in the IP policy group are ordered, so that when the policy search is performed based on the ordered IP policy group, the policy search speed can be further improved; furthermore, there is no overlap between the IP address sub-range segments of the IP policy group, so that when the policy search is performed based on the target IP address, the situation of hitting at least two IP address sub-range segments can be avoided, thereby avoiding the occurrence of multiple inaccurate security policies found due to matching multiple IP address sub-range segments. BRIEF DESCRIPTION OF THE DRAWINGS
[0019] Figure 1 It is a flow chart of a strategy matching method provided in an embodiment of the present application;
[0020] Figure 2 It is a logical diagram of the division of an IP address sub-range segment provided in an embodiment of the present application;
[0021] Figure 3 It is a structural diagram of a strategy matching device provided in an embodiment of the present application;
[0022] Figure 4 It is a hardware structure diagram of an electronic device for implementing a strategy matching method provided in an embodiment of the present application. DETAILED DESCRIPTION
[0023] Here, exemplary embodiments will be described in detail, and examples thereof are shown in the accompanying drawings. When the following description refers to the accompanying drawings, unless otherwise indicated, the same numbers in different drawings represent the same or similar elements. The embodiments described in the following exemplary embodiments do not represent all embodiments consistent with the present application. Instead, they are only examples of devices and methods consistent with some aspects of the present application.
[0024] The terms used in this application are only for the purpose of describing specific embodiments and are not intended to limit this application. The singular forms of "a", "said" and "the" used in this application are also intended to include plural forms, unless the context clearly indicates other meanings. It should also be understood that the term "and / or" used in this article refers to and includes any or all possible combinations of one or more corresponding listed items.
[0025] It should be understood that although the terms first, second, third, etc. may be used in the present application to describe various information, these information should not be limited to these terms. These terms are only used to distinguish the same type of information from each other. For example, without departing from the scope of the present application, the first information may also be referred to as the second information, and similarly, the second information may also be referred to as the first information. Depending on the context, the word "if" as used herein may be interpreted as "at the time of" or "when" or "in response to determining".
[0026] The strategy matching method provided in this application is described in detail below.
[0027] See also Figure 1 , Figure 1 This is a flow chart of a policy matching method provided by the present application. The method can be applied to a network security device, which can be, but is not limited to, a firewall device, a security gateway, etc. When the network security device implements the method, the following steps may be included:
[0028] Step 101: receiving a service message;
[0029] Step 102: using the target IP address in the service message, querying the IP policy group according to a search algorithm that matches the IP policy group, and determining the target security policy corresponding to the target IP address sub-range segment hit by the target IP address.
[0030] Among them, the above-mentioned IP policy group is constructed according to a set algorithm based on multiple pre-configured IP addresses and the security policy corresponding to each IP address, wherein the keyword of the IP policy group is the IP address sub-range segment obtained by dividing the IP address range segment to which each IP address belongs, and the key value of the IP policy group is the security policy corresponding to the IP address range segment to which each IP address sub-range segment belongs, and the IP address sub-range segments in the IP policy group are ordered; wherein there is no overlap between the multiple IP address sub-range segments obtained by dividing the IP address range segment to which each IP address belongs.
[0031] In this step, after the service message enters the network security device, if the current matching rule in the network security device is based on the IP address for policy matching, the network security device can extract the target IP address from the service message and obtain the pre-generated IP policy group. Since the network security device knows the generation method of the IP policy group, it can use the search algorithm that matches the generation method of the IP policy group to match the IP address of the service message with the IP policy group, in order to improve the policy matching speed.
[0032] Optionally, the target IP address may be, but is not limited to, a source IP address and / or a destination IP address. When the IP address is a source IP address or a destination IP address, the IP policy group is generated based on the source IP address or the destination IP address and the corresponding security policy according to the above method; and when the IP address is a source IP address and a destination IP address, the keywords of the IP policy group may be a source IP address subrange and a destination IP address subrange.
[0033] For ease of understanding, the IP address can be taken as a single IP address (source IP address or destination IP address) as an example for explanation. In order to improve the policy matching speed, this embodiment proposes to convert the correspondence between the pre-configured security policy and the IP address to convert it into the correspondence between the IP address range segment to which the IP address belongs and the security policy. In this way, compared with the traversal of each IP address, the matching speed of the IP address based on the address range will be faster; in addition, in order to further improve the policy matching speed, this embodiment also proposes to divide each IP address range segment into multiple non-overlapping IP address sub-range segments, and then generate an IP policy group based on the IP address sub-range segment and the corresponding security policy. In this way, by dividing into non-overlapping IP address sub-range segments, the occurrence of search conflicts in the search process is avoided. Moreover, in order to improve the search speed, this embodiment also proposes that when constructing the IP policy group, it is constructed in the order between the IP address sub-range segments to ensure that the IP address sub-range segments included in the IP policy group are ordered, so that when searching based on the IP policy group, the search speed of the security policy can be improved.
[0034] Specifically, different algorithms can be used when generating IP policy groups based on IP address sub-range segments and corresponding security policies; accordingly, when different algorithms are used to generate IP policy groups, corresponding search algorithms are also provided when matching IP addresses, which are designed to improve the matching speed.
[0035] On this basis, after extracting the IP address from the business message, the IP address matching process can be performed based on the IP policy group generation method and the search algorithm matching the IP policy group, so as to quickly find the target security policy corresponding to the target IP address sub-range segment hit by the target IP address.
[0036] Step 103: Perform policy matching processing on the service message using the target security policy.
[0037] In this step, after the target security policy is determined, policy matching processing can be performed on the service message based on the target security policy to evaluate the security of the service message.
[0038] In implementing the above-mentioned policy matching method, a business message is received; using the target IP address in the business message, the IP policy group is queried according to a search algorithm that matches the IP policy group to determine the target security policy corresponding to the target IP address sub-range segment hit by the target IP address; and the business message is subjected to policy matching processing using the target security policy. Since the above-mentioned IP policy group is constructed according to a set algorithm based on a plurality of pre-configured IP addresses and the security policy corresponding to each IP address, and the policy search is performed based on the search algorithm corresponding to the IP policy group, when the policy search is performed based on the appropriate search algorithm, the search speed of the security policy can be guaranteed; moreover, the keyword of the above-mentioned IP policy group is the IP address sub-range segment obtained by dividing the IP address range segment to which each IP address belongs, and the key value of the IP policy group is the security policy corresponding to the IP address range segment to which each IP address sub-range segment belongs, and the IP address sub-range segments in the IP policy group are ordered, so that when the policy search is performed based on the ordered IP policy group, the policy search speed can be further improved; furthermore, there is no overlap between the IP address sub-range segments in the IP policy group, so that when the policy search is performed based on the target IP address, the situation of hitting at least two IP address sub-range segments can be avoided, thereby avoiding the occurrence of multiple inaccurate security policies found due to matching multiple IP address sub-range segments.
[0039] Optionally, based on the above embodiment, in one embodiment, step 102 may be performed according to the following process: when the IP policy group adopts an array structure, a binary search algorithm is used to query the IP policy group using the target IP address in the service message.
[0040] Specifically, after obtaining each IP address sub-range, it can be written into the set array structure in order based on each IP address sub-range and the corresponding security policy to ensure that the obtained IP policy group is ordered; for example, when writing in order from small to large, the IP address sub-range segment where the smaller IP address is located and its corresponding security policy are arranged in front of the set array structure, and the IP address sub-range segment where the larger IP address is located and its corresponding security policy are arranged behind the set data structure, thus, an ordered IP policy group is obtained. For ease of understanding, the IP policy group shown in Table 1 can be used as an example for explanation. In Table 1, the IP address of the right endpoint of range segment 1 is smaller than the IP address of the left endpoint of range segment 2, and the IP address of the right endpoint of range segment 2 is smaller than the IP address of the left endpoint of range segment 3, and so on.
[0041] Table 1
[0042] Keywords: IP address subrange Key value: Security policy Range 1 Security Policy 1 Range 2 Security Policy 2 Range 3 Security Strategy 3 …… ……
[0043] On this basis, when matching based on the target IP address in the service message, a binary search method can be used to search for security policies. For example, the IP address sub-range segments in the IP policy group are arranged in order from small to large, then the target IP address is first matched with the IP address sub-range segment in the middle position in the IP policy group. When the IP address sub-range segment is not hit, it can also be determined whether the target IP address is greater than or less than the IP address in the IP address sub-range segment. Based on this, the interval where the target IP address is located is confirmed. Taking the IP address in the IP address sub-range segment as an example, it can be determined that the target IP address is located in the interval between the starting position and the middle position in the IP policy group. Based on this interval, a binary search is performed again, and the above search process is repeated until the IP address sub-range segment hit by the target IP address is found, or no match is successful. When the hit IP address sub-range segment is found, the security policy indicated by the key value corresponding to the hit IP address sub-range segment is recorded as the above target security policy.
[0044] If the match is not successful, it means that there is no IP address sub-range segment including the target IP address in the current IP policy group. In this case, the search failure can be output. Then, the network security device can execute other security policy matching rules or output an alarm to facilitate the operation and maintenance personnel to perform related operations.
[0045] Optionally, in another embodiment, step 102 can also be performed according to the following process: when the IP policy group is an IP policy tree constructed by using a balanced binary tree algorithm based on the IP address sub-range segment of each IP address and the security policy corresponding to the IP address sub-range segment, then for the current query node, determine whether the target IP address is within the IP address sub-range segment corresponding to the query node; if so, determine the security policy corresponding to the query node as the target security policy; if not, when the target IP address is greater than the IP address of the right endpoint of the IP address sub-range segment corresponding to the query node, then when the right subtree of the query node is not empty, then use the right subtree as the query node, and continue to execute the step of determining whether the target IP address is within the IP address sub-range segment corresponding to the query node for the current query node; when the target IP address is less than the IP address of the left endpoint of the IP address sub-range segment corresponding to the query node, then when the left subtree of the search node is not empty, then use the left subtree as the query node, and continue to execute the step of determining whether the target IP address is within the IP address sub-range segment corresponding to the query node for the current query node.
[0046] Specifically, in addition to the traditional smooth binary tree, the above-mentioned balanced binary tree can also be a red-black tree, which is a self-balancing binary tree. Since the above-mentioned balanced binary tree is a tree structure, and each subtree in the balanced binary tree can be set to be ordered or unordered. In order to improve the policy search speed, in this application, when using a balanced binary tree to generate an IP policy group based on an IP address subrange and a corresponding security policy, each subtree can be set to be ordered, and then the corresponding IP address subrange segment and security policy are loaded onto each subtree, thereby obtaining an ordered tree-structured IP policy group.
[0047] On this basis, when performing a policy search based on the target IP address, the aforementioned process can be followed. Specifically, each tree in the tree-structured IP policy group can be regarded as a node. When searching for the first time, the root node can be set as the current query node. For the sake of convenience, the IP address sub-range segment corresponding to the query node is recorded as sub-range segment 1, and the security policy corresponding to the query node is recorded as security policy 1. Based on this, the target IP address can be matched with the keyword of the query node---sub-range segment 1. When the match is successful, it indicates that the target IP address belongs to the sub-range segment 1, and then the key value of the query node---security policy 1 can be output, which is the hit target security policy.
[0048] If the match is not successful, it means that the current target IP address is not within the above-mentioned sub-range segment 1, and then the target IP address can be compared with the IP address of the endpoint of sub-range segment 1. If the target IP address is greater than the IP address of the right endpoint of sub-range segment 1, since the IP address of the right subtree is greater than the IP address of the left subtree, it can be determined whether the right subtree of the current query node is empty. If it is empty, it indicates that the match failed; and when the right subtree is not empty, the right subtree can be used as the current query node, and the above judgment process is repeated until a matching IP address sub-range segment is found, or the match fails.
[0049] Similarly, if the target IP address is smaller than the IP address of the left endpoint of sub-range segment 1, since the IP address of the left subtree is smaller than the IP address of the right subtree, it can be determined whether the left subtree of the current query node is empty. If it is empty, it indicates that the match fails. If the left subtree is not empty, the left subtree can be used as the current query node and the above judgment process is repeated until a matching IP address sub-range segment is found or the match fails. In this way, the security policy corresponding to the target IP address can be quickly found.
[0050] Optionally, based on any of the above embodiments, in this embodiment, the method for determining the above-mentioned IP address sub-range segment may be: obtaining a pre-configured plurality of IP addresses and a security policy corresponding to each IP address; for each IP address, determining the network segment to which the IP address belongs as the IP address range segment corresponding to the IP address; determining the intersection between at least two IP address range segments to obtain several first IP address sub-range segments, wherein only one identical IP address sub-range segment among the several first IP address sub-range segments is retained; for each IP address range segment, removing the first IP address sub-range segment in the IP address range segment, and forming a second IP address sub-range segment with IP addresses smaller than the IP address at the left endpoint of the first IP address sub-range segment, and forming a third IP address sub-range segment with IP addresses larger than the IP address at the right endpoint of the first IP address sub-range segment.
[0051] Specifically, the multiple IP addresses shown in Table 2 and the security policies corresponding to each IP address can be used as an example for explanation. Based on each IP address in Table 2, the network segment corresponding to the IP address can be determined. The network segment is the IP address range segment corresponding to the IP address. The correspondence between the obtained IP address range segment and the security policy can be referred to as shown in Table 3.
[0052] Table 2
[0053] Security policy name ip address POLICY1 192.168.1.0 / 24 POLICY2 192.168.1.100 POLICY3 192.168.0.0 / 16 ... ... POLICY999 192.170.1.1 POLICY1000 192.0.0.0 / 8
[0054] Table 3
[0055]
[0056]
[0057] In Table 3, for 192.168.1.0 / 24, it shows that the first 24 bits of the IP address are more important, and the last 8 bits are not important. Therefore, the network segment range can be from 0 to 2. 8 -1=255, therefore, the network segment corresponding to the IP address is 192.168.1.0-192.168.1.255, and accordingly, the IP address range of the IP address is 192.168.1.0-192.168.1.255. The above 192.168.1.100 is a fixed IP address, therefore, the network segment corresponding to the IP address only includes the IP address, that is, there may be a situation where the IP address range includes a single IP address, therefore, the IP address range corresponding to the IP address is 192.168.1.100-192.168.1.100.
[0058] Furthermore, after determining the IP address ranges corresponding to each IP address, the process of dividing the non-overlapping IP address sub-ranges can be performed. Figure 2 The following is an example of the division logic diagram shown. Figure 2 There are 3 IP address ranges in the , such as IP address range 1 is represented by line segment 1, IP address range 2 is represented by line segment 2, and IP address range 3 is represented by line segment 3. On this basis, when dividing the IP address sub-ranges, you can first determine Figure 2 From the intersection of at least two segments among segment 1, segment 2, and segment 3, we can see that the intersection of segment 1, segment 2, and segment 3 is sub-segment 2, and the intersection of segment 1 and segment 3 is sub-segment 3. Based on the above description, sub-segment 2 and sub-segment 3 are the above-mentioned first IP address sub-range segment, and only one sub-segment 2 and one sub-segment 3 are retained in the first IP address sub-range segment. On this basis, the security policy corresponding to sub-segment 2 includes security policy 1 of segment 1, security policy 2 of segment 2, and security policy 3 of segment 3. Similarly, the above-mentioned sub-segment 3 is also the above-mentioned first IP address sub-range segment, and the security policy corresponding to sub-segment 3 includes security policy 1 of segment 1 and security policy 3 of segment 3.
[0059] On this basis, for segment 1, based on the first IP address sub-range segment determined above, segment 1 can be divided into sub-segment 2, sub-segment 3 and sub-segment 4, and the IP address of sub-segment 4 is greater than the IP address of the right endpoint of sub-segment 3, therefore, sub-segment 4 is the third IP address sub-range segment; similarly, for segment 2, based on the first IP address sub-range segment determined above, segment 2 can be divided into sub-segment 1 and sub-segment 2, and sub-segment 1 is located on the left side of sub-segment 2, that is, the IP address of sub-segment 1 is less than the IP address of the left endpoint of sub-segment 2, therefore, sub-segment 1 is the second IP address sub-range segment; for segment 3, based on the first IP address sub-range segment determined above, segment 3 can be divided into sub-segment 2 and sub-segment 3, since sub-segment 2 and sub-segment 3 are both sub-segments of the intersection, segment 3 does not have the second IP address sub-range segment and the third IP address sub-range segment. Based on this, the IP address sub-range segments of each IP address are obtained, and no overlap is achieved between the obtained IP address sub-range segments.
[0060] Further, after the IP address sub-range is obtained, each identical IP address sub-range segment corresponds to a security policy group, and the security policy group includes the security policies corresponding to the IP address range segments to which the identical IP address sub-range segment belongs respectively;
[0061] Specifically, Figure 2 Take this as an example to illustrate: Figure 2Sub-segment 2 and sub-segment 3 are both the same IP address sub-range segments. Since sub-segment 2 belongs to segment 1, segment 2 and segment 3 respectively, based on the above description, the corresponding security policy group of sub-segment 2 can include security policy 1, security policy 2 and security policy 3; similarly, the security policy group corresponding to sub-segment 3 can include security policy 1 and security policy 3.
[0062] To facilitate understanding of this embodiment, the IP address sub-range segments obtained by dividing the IP address range segments in Table 3 shown in Table 4 may be taken as an example for description.
[0063] Table 4
[0064]
[0065]
[0066] Furthermore, the obtained correspondence between the non-overlapping IP address sub-range segments and the security policies / security policy groups may be as shown in Table 5.
[0067] Table 5
[0068] No overlapping IP address subranges Security policy name 192.0.0.0-192.167.255.255 {POLICY1000} 192.168.0.0-192.168.0.255 {POLICY3, POLICY1000} 192.168.1.0-192.168.1.99 {POLICY1, POLICY3, POLICY1000} 192.168.1.100-192.168.1.100 {POLICY1, POLICY2, POLICY3, POLICY1000} 192.168.1.101-192.168.1.255 {POLICY1, POLICY3, POLICY1000} 192.168.2.0-192.168.255.255 {POLICY3, POLICY1000} 192.169.0.0-192.170.1.0 {POLICY1000} 192.170.1.1-192.170.1.1 {POLICY999, POLICY1000} 192.170.1.2-192.255.255.255 {POLICY1000}
[0069] As can be seen from Table 5, some IP address sub-ranges correspond to multiple security policies, which can be represented in the form of a security policy group in a collective form.
[0070] Furthermore, an IP policy group can be constructed according to the following process: using a set algorithm, each first IP address sub-range segment is used as a keyword, the security policy group of the first IP address sub-range segment is used as a key value, each second IP address sub-range segment is used as a keyword, the security policy corresponding to the second IP address sub-range segment is used as a key value, and each third IP address sub-range segment is used as a keyword, the security policy corresponding to the third IP address sub-range segment is used as a key value to construct an IP policy group.
[0071] Specifically, this embodiment provides two methods for constructing IP policy groups, a construction method corresponding to an array structure and a construction method corresponding to a balanced binary tree or a red-black tree. Specifically, when the IP policy group is stored in an array structure, each IP address sub-range segment is sorted, and then the IP address sub-range segment and the corresponding security policy are written into the array structure in order, thereby obtaining an IP policy group of the array structure; and when the IP policy group is a tree structure, taking a balanced binary tree as an example, the balanced binary tree can be set to be ordered, and then the IP address sub-range segment and the corresponding security policy are mounted in order on the corresponding tree, thereby obtaining an IP policy group of the tree structure.
[0072] At this point, since the IP address sub-range segments in the IP policy group in this embodiment are non-overlapping and arranged in order, when performing policy search based on the target IP address, the policy search speed can be improved, and the problem of long time consumption and large memory resource consumption in building IP policy groups under massive IP addresses is solved. At the same time, since the IP policy group saves memory, the delay problem of configuration taking effect is alleviated.
[0073] Based on the same inventive concept, the present application also provides a strategy matching device corresponding to the above strategy matching method. The implementation of the strategy matching device can refer to the description of the above strategy matching method, which will not be discussed here one by one.
[0074] See also Figure 3 , Figure 3 A policy matching device provided by an exemplary embodiment of the present application is applied to a network security device, and the device includes:
[0075] The receiving unit 301 is used to receive a service message;
[0076] A query unit 302 is used to query the IP policy group using the target IP address in the service message according to a search algorithm matching the IP policy group, and determine the target security policy corresponding to the target IP address sub-range segment hit by the target IP address; the IP policy group is constructed according to a set algorithm based on a plurality of pre-configured IP addresses and the security policy corresponding to each IP address, wherein the keyword of the IP policy group is the IP address sub-range segment obtained by dividing the IP address range segment to which each IP address belongs, the key value of the IP policy group is the security policy corresponding to the IP address range segment to which each IP address sub-range segment belongs, and the IP address sub-range segments in the IP policy group are ordered, and there is no overlap between the IP address sub-range segments;
[0077] The matching unit 303 is used to perform policy matching processing on the service message by using the target security policy.
[0078] Since the above-mentioned IP policy group is constructed according to a set algorithm based on a plurality of pre-configured IP addresses and the security policy corresponding to each IP address, and the policy search is performed based on the search algorithm corresponding to the IP policy group, the security policy search speed can be guaranteed when the policy search is performed based on the appropriate search algorithm; moreover, the keyword of the above-mentioned IP policy group is the IP address sub-range segment obtained by dividing the IP address range segment to which each IP address belongs, and the key value of the IP policy group is the security policy corresponding to the IP address range segment to which each IP address sub-range segment belongs, and the IP address sub-range segments in the IP policy group are ordered, so that when the policy search is performed based on the ordered IP policy group, the policy search speed can be further improved; furthermore, there is no overlap between the IP address sub-range segments of the IP policy group, so that when the policy search is performed based on the target IP address, the situation of hitting at least two IP address sub-range segments can be avoided, thereby avoiding the occurrence of multiple inaccurate security policies found due to matching multiple IP address sub-range segments.
[0079] Optionally, in one embodiment, the above-mentioned search unit 302 is specifically used to use a binary search algorithm when the IP policy group adopts an array structure, and use the target IP address in the service message to query the IP policy group.
[0080] In another embodiment, the searching unit 302 is specifically configured to:
[0081] When the IP policy group is an IP policy tree constructed by using a balanced binary tree algorithm based on the IP address sub-range of each IP address and the security policy corresponding to the IP address sub-range, then for the current query node, it is determined whether the target IP address is within the IP address sub-range corresponding to the query node;
[0082] If yes, determining the security policy corresponding to the query node as the target security policy;
[0083] If not, when the target IP address is greater than the IP address of the right endpoint of the IP address sub-range segment corresponding to the query node, then when the right subtree of the query node is not empty, the right subtree is used as the query node, and the step of determining whether the target IP address is within the IP address sub-range segment corresponding to the query node is continued for the current query node; when the target IP address is less than the IP address of the left endpoint of the IP address sub-range segment corresponding to the query node, then when the left subtree of the search node is not empty, the left subtree is used as the query node, and the step of determining whether the target IP address is within the IP address sub-range segment corresponding to the query node is continued for the current query node.
[0084] Optionally, in this embodiment, the above device may further include:
[0085] An acquisition unit (not shown in the figure), used to acquire a plurality of pre-configured IP addresses and a security policy corresponding to each IP address;
[0086] A first determining unit (not shown in the figure) is used to determine, for each IP address, the network segment to which the IP address belongs as the IP address range segment corresponding to the IP address;
[0087] A second determining unit (not shown in the figure) is used to determine the intersection between every at least two IP address range segments to obtain a plurality of first IP address sub-range segments, wherein only one identical IP address sub-range segment is retained among the plurality of first IP address sub-range segments;
[0088] A constituting unit (not shown in the figure) is used to remove the first IP address sub-range segment in each IP address range segment, constitute a second IP address sub-range segment with IP addresses smaller than the IP address at the left endpoint of the first IP address sub-range segment, and constitute a third IP address sub-range segment with IP addresses greater than the IP address at the right endpoint of the first IP address sub-range segment.
[0089] Optionally, in this embodiment, each identical IP address sub-range segment corresponds to a security policy group, and the security policy group includes security policies corresponding to the IP address range segments to which the identical IP address sub-range segment belongs respectively;
[0090] On this basis, the above device may further include:
[0091] A construction unit (not shown in the figure) is used to use a set algorithm to take each first IP address sub-range segment as a keyword, the security policy group of the first IP address sub-range segment as a key value, each second IP address sub-range segment as a keyword, the security policy corresponding to the second IP address sub-range segment as a key value, and each third IP address sub-range segment as a keyword, the security policy corresponding to the third IP address sub-range segment as a key value to construct an IP policy group.
[0092] Based on the same inventive concept, an embodiment of the present application provides an electronic device, which may be the above-mentioned network security device, etc. Figure 4As shown, the electronic device may include a processor 401 and a machine-readable storage medium 402, the machine-readable storage medium 402 stores a computer program that can be executed by the processor 401, and the processor 401 is prompted by the computer program to execute the policy matching method provided in any embodiment of the present application. In addition, the electronic device also includes a communication interface 403 and a communication bus 404, wherein the processor 401, the communication interface 403, and the machine-readable storage medium 402 communicate with each other through the communication bus 404.
[0093] The communication bus mentioned in the above electronic device can be a Peripheral Component Interconnect (PCI) bus or an Extended Industry Standard Architecture (EISA) bus, etc. The communication bus can be divided into an address bus, a data bus, a control bus, etc. For ease of representation, only one thick line is used in the figure, but it does not mean that there is only one bus or one type of bus.
[0094] The communication interface is used for communication between the above electronic device and other devices.
[0095] The machine-readable storage medium 402 may be a memory, which may include a random access memory (RAM), a DDR SRAM (Double Data Rate Synchronous Dynamic Random Access Memory), or a non-volatile memory (NVM), such as at least one disk memory. Optionally, the memory may also be at least one storage device located away from the processor.
[0096] The above-mentioned processor can be a general-purpose processor, including a central processing unit (CPU), a network processor (NP), etc.; 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 gate or transistor logic devices, discrete hardware components.
[0097] In addition, this embodiment also provides a machine-readable storage medium, which stores a computer program. When called and executed by a processor, the computer program prompts the processor to execute the method provided by any embodiment of the present application.
[0098] As for the electronic device and machine-readable storage medium embodiments, since the method contents involved are basically similar to the aforementioned method embodiments, the description is relatively simple, and the relevant parts can be referred to the partial description of the method embodiments.
[0099] It should be noted that, in this article, relational terms such as first and second, etc. are only used to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Moreover, the terms "include", "comprise" or any other variants thereof are intended to cover non-exclusive inclusion, so that a process, method, article or device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, article or device. In the absence of further restrictions, the elements defined by the sentence "comprise a ..." do not exclude the existence of other identical elements in the process, method, article or device including the elements.
[0100] The implementation process of the functions and effects of each unit / module in the above-mentioned device is specifically described in the implementation process of the corresponding steps in the above-mentioned method, and will not be repeated here.
[0101] For the device embodiments, since they basically correspond to the method embodiments, the relevant parts can refer to the partial description of the method embodiments. The device embodiments described above are merely schematic, wherein the units / modules described as separate components may or may not be physically separated, and the components displayed as units / modules may or may not be physical units / modules, that is, they may be located in one place, or they may be distributed on multiple network units / modules. Some or all of the units / modules may be selected according to actual needs to achieve the purpose of the present application. A person of ordinary skill in the art can understand and implement it without creative work.
[0102] The above description is only a preferred embodiment of the present application and is not intended to limit the present application. Any modifications, equivalent substitutions, improvements, etc. made within the spirit and principles of the present application shall be included in the scope of protection of the present application.
Claims
1. A strategy matching method, It is characterized in that Applied to a network security device, the method comprises: Receive business messages; Using the target IP address in the service message, the IP policy group is queried according to a search algorithm that matches the IP policy group, and the target security policy corresponding to the target IP address sub-range segment hit by the target IP address is determined; the IP policy group is constructed according to a set algorithm based on a plurality of pre-configured IP addresses and the security policy corresponding to each IP address, wherein the keyword of the IP policy group is the IP address sub-range segment obtained by dividing the IP address range segment to which each IP address belongs, the key value of the IP policy group is the security policy corresponding to the IP address range segment to which each IP address sub-range segment belongs, and the IP address sub-range segments in the IP policy group are ordered, and there is no overlap between the IP address sub-range segments; The target security policy is used to perform policy matching processing on the service message.
2. The method according to claim 1, It is characterized in that Using the target IP address in the service message, querying the IP policy group according to the search algorithm that matches the IP policy group includes: When the IP policy group adopts an array structure, a binary search algorithm is used to query the IP policy group using the target IP address in the service message.
3. The method according to claim 1, It is characterized in that Using the target IP address in the service message, querying the IP policy group according to the search algorithm matching the IP policy group, determining the target security policy corresponding to the target IP address sub-range segment hit by the target IP address, including: When the IP policy group is an IP policy tree constructed by using a balanced binary tree algorithm based on the IP address sub-range of each IP address and the security policy corresponding to the IP address sub-range, then for the current query node, it is determined whether the target IP address is within the IP address sub-range corresponding to the query node; If yes, determining the security policy corresponding to the query node as the target security policy; If not, when the target IP address is greater than the IP address of the right endpoint of the IP address sub-range segment corresponding to the query node, then when the right subtree of the query node is not empty, the right subtree is used as the query node, and the step of determining whether the target IP address is within the IP address sub-range segment corresponding to the query node is continued for the current query node; when the target IP address is less than the IP address of the left endpoint of the IP address sub-range segment corresponding to the query node, then when the left subtree of the search node is not empty, the left subtree is used as the query node, and the step of determining whether the target IP address is within the IP address sub-range segment corresponding to the query node is continued for the current query node.
4. The method according to claim 1, It is characterized in that The method for determining the IP address sub-range segment is as follows: Get multiple pre-configured IP addresses and the security policy corresponding to each IP address; For each IP address, the network segment to which the IP address belongs is determined as the IP address range segment corresponding to the IP address; Determine the intersection between at least two IP address range segments to obtain a plurality of first IP address sub-range segments, wherein only one identical IP address sub-range segment is retained among the plurality of first IP address sub-range segments; For each IP address range segment, remove the first IP address sub-range segment in the IP address range segment, and use the IP addresses smaller than the IP address at the left endpoint of the first IP address sub-range segment to form a second IP address sub-range segment, and use the IP addresses greater than the IP address at the right endpoint of the first IP address sub-range segment to form a third IP address sub-range segment.
5. The method according to claim 4, It is characterized in that Each identical IP address sub-range corresponds to a security policy group, and the security policy group includes the security policies corresponding to the IP address ranges to which the identical IP address sub-range belongs. The construction method of the ip policy group is: Using the set algorithm, each first IP address sub-range segment is used as a keyword, the security policy group of the first IP address sub-range segment is used as a key value, each second IP address sub-range segment is used as a keyword, the security policy corresponding to the second IP address sub-range segment is used as a key value, and each third IP address sub-range segment is used as a keyword, and the security policy corresponding to the third IP address sub-range segment is used as a key value to construct an IP policy group.
6. A strategy matching device, It is characterized in that Applied in network security equipment, the device comprises: A receiving unit, used for receiving a service message; A query unit, used to query the IP policy group by using the target IP address in the service message according to a search algorithm matching the IP policy group, and determine the target security policy corresponding to the target IP address sub-range segment hit by the target IP address; the IP policy group is constructed according to a set algorithm based on a plurality of pre-configured IP addresses and the security policy corresponding to each IP address, wherein the keyword of the IP policy group is the IP address sub-range segment obtained by dividing the IP address range segment to which each IP address belongs, the key value of the IP policy group is the security policy corresponding to the IP address range segment to which each IP address sub-range segment belongs, and the IP address sub-range segments in the IP policy group are ordered, and there is no overlap between the IP address sub-range segments; The matching unit is used to perform policy matching processing on the service message by using the target security policy.
7. The device according to claim 6, It is characterized in that The search unit is specifically used to use a binary search algorithm when the IP policy group adopts an array structure, and use the target IP address in the service message to query the IP policy group.
8. The device according to claim 6, It is characterized in that The searching unit is specifically used for: When the IP policy group is an IP policy tree constructed by using a balanced binary tree algorithm based on the IP address sub-range of each IP address and the security policy corresponding to the IP address sub-range, then for the current query node, it is determined whether the target IP address is within the IP address sub-range corresponding to the query node; If yes, determining the security policy corresponding to the query node as the target security policy; If not, when the target IP address is greater than the IP address of the right endpoint of the IP address sub-range segment corresponding to the query node, then when the right subtree of the query node is not empty, the right subtree is used as the query node, and the step of determining whether the target IP address is within the IP address sub-range segment corresponding to the query node is continued for the current query node; when the target IP address is less than the IP address of the left endpoint of the IP address sub-range segment corresponding to the query node, then when the left subtree of the search node is not empty, the left subtree is used as the query node, and the step of determining whether the target IP address is within the IP address sub-range segment corresponding to the query node is continued for the current query node.
9. The device according to claim 6, It is characterized in that Also includes: An acquisition unit, used to acquire a plurality of pre-configured IP addresses and a security policy corresponding to each IP address; A first determining unit is used to determine, for each IP address, a network segment to which the IP address belongs as an IP address range segment corresponding to the IP address; A second determining unit is used to determine the intersection between every at least two IP address range segments to obtain a plurality of first IP address sub-range segments, wherein only one identical IP address sub-range segment is retained among the plurality of first IP address sub-range segments; The composition unit is used to remove the first IP address sub-range segment in each IP address range segment, form a second IP address sub-range segment with IP addresses smaller than the IP address at the left endpoint of the first IP address sub-range segment, and form a third IP address sub-range segment with IP addresses larger than the IP address at the right endpoint of the first IP address sub-range segment.
10. The device according to claim 6, It is characterized in that Each identical IP address sub-range corresponds to a security policy group, and the security policy group includes the security policies corresponding to the IP address ranges to which the identical IP address sub-range belongs. The device further comprises: The construction unit is used to use a set algorithm to take each first IP address sub-range segment as a keyword, the security policy group of the first IP address sub-range segment as a key value, each second IP address sub-range segment as a keyword, the security policy corresponding to the second IP address sub-range segment as a key value, and each third IP address sub-range segment as a keyword, the security policy corresponding to the third IP address sub-range segment as a key value to construct an IP policy group.
Citation Information
Patent Citations
Message processing method and device and computer readable storage medium
CN107707477A
Route generation method, device and system
CN108282404A
IP address field conflict detection method and device and electronic equipment
CN115987949A
Policy routing implementation method and device, and storage medium
WO2023246161A1
Cited By
Method for storing overlapped IP segment types based on LPM and storage medium
CN119621827A
Security policy division method and device, storage medium and computing equipment
CN121567468A
A security policy division method and device, a storage medium and a computing device
CN121567468B
