The present invention discloses a rule matching method including: receiving a packet; detecting feature information in content of the packet, and determining whether the detected feature information in the packet conforms to a classification characteristic of one rule group among a plurality of preset rule groups; if yes, determining a state machine corresponding to the one rule group as a first state machine; and determining whether the first state machine is stored in an on-chip memory, and if yes, using the first state machine to match the packet to obtain a matching result; and if no, when an off-chip memory stores the first state machine, loading the first state machine from the off-chip memory into the on-chip memory, and using the first state machine to match the packet to obtain a matching result. Embodiments of the present invention enable a product to achieve better performance.
Please help me write a proper abstract based on the patent claims. CLAIM: 1. A rule matching method, comprising: receiving a packet; detecting feature information in content of the packet, and determining whether the detected feature information in the packet conforms to a classification characteristic of one rule group among a plurality of preset rule groups, wherein each rule group in the plurality of rule groups is obtained by grouping one or more rules according to a predetermined classification characteristic, and each rule group after compiling corresponds to one state machine, wherein the state machine is configured to match the packet, wherein a state machine commonly used in matching is stored in an on-chip memory with a relatively high read/write speed, and other state machines are stored in an off-chip memory with a relatively low read/write speed; and when the detected feature information conforms to a classification characteristics of one rule group among the plurality of preset rule groups, determining a state machine corresponding to the one rule group as a first state machine; determining whether the first state machine is stored in the on-chip memory, and if the first state machine is stored in the on-chip memory, using the first state machine to match the packet to obtain a matching result; and if the first state machine is not stored in the on-chip memory, when the off-chip memory stores the first state machine, loading the first state machine from the off-chip memory into the on-chip memory, and using the first state machine to match the packet to obtain a matching result. 2. The method according to claim 1, wherein grouping according to a predetermined classification characteristic comprises: determining a distinctive feature of each rule in one or more rules so that as many other rules without the distinctive feature as possible exist in the one or more rules, and grouping rules with a same distinctive feature into one group, wherein the distinctive feature is one or more consecutive characters with a predetermined quantity starting from an offset. 3. The method according to claim 2, further comprising: selecting a predetermined quantity of consecutive characters in the distinctive feature as a keyword of the rule group, and storing the keyword in a storage space corresponding to the offset; and performing a hash operation on the keyword of the rule group to obtain a predetermined hash value corresponding to the rule group, and storing the keyword in a storage address corresponding to the predetermined hash value, wherein the predetermined hash value and the storage address conform to a predetermined correspondence; and wherein detecting feature information in content of the packet, and determining whether the detected feature information in the packet conforms to a classification characteristic of one rule group among a plurality of preset rule groups comprises: calculating a current hash value of the predetermined quantity of consecutive characters on each offset in the packet, checking whether the predetermined quantity of consecutive characters exist in a current storage address corresponding to the current hash value, wherein the current hash value and the current storage address conform to the predetermined correspondence, if the predetermined quantity of consecutive characters exist in the current storage address corresponding to the current hash value, determining that the detected feature information in the packet conforms to a classification characteristic of one rule group among the plurality of preset rule groups, and if the predetermined quantity of consecutive characters do not exist in the current storage address corresponding to the current hash value, determining that the detected feature information in the packet conforms to a classification characteristic of no preset rule group. 4. The method according to claim 3, further comprising: when a plurality of distinctive features exists in one or more rules, selecting the predetermined quantity of consecutive characters in one distinctive feature among the plurality of distinctive features as a keyword of the rule group, wherein the number of keywords stored in a storage space corresponding to an offset of the selected one distinctive feature is as small as possible, compared with keywords stored in storage spaces corresponding to offsets of other distinctive features than the one distinctive feature among the plurality of distinctive features. 5. The method according to claim 1, wherein grouping according to a predetermined classification characteristic comprises: grouping one or more rules with as many same characters as possible starting from a same offset into one group. 6. The method according to claim 1, wherein grouping according to a predetermined classification characteristic comprises: grouping rules according to whether the rules are of a protocol type and/or whether the rules are hot rules, to obtain one or more rule sets, wherein one rule set comprises one or more rules; and grouping one or more rules with as many same characters as possible starting from a same offset in rules comprised in each rule set into one group. 7. The method according to claim 5, wherein the method further comprises: generating a feature table corresponding to each rule group, wherein the feature table comprises a plurality of two-dimensional entries and each two-dimensional entry comprises an offset and a character; when a rule in the rule group has a specific character at a specific offset, setting a value of a two-dimensional entry corresponding to the specific offset and the specific character to a valid value; and when no rule in the rule group has a specific character at a specific offset, setting a value of a two-dimensional entry corresponding to the specific offset and the specific character to an invalid value; generating a result bit corresponding to each rule group; and the detecting feature information in content of the packet, and determining whether the detected feature information in the packet conforms to a classification characteristic of one rule group among a plurality of preset rule groups comprises: matching each character at each offset in the packet with the two-dimensional entries in the feature table corresponding to each rule group; if a value of a two-dimensional entry comprising a current offset and a current character is valid, the matching succeeds; and a value of a two-dimensional entry comprising a current offset and a current character is invalid, the matching fails; when matching is performed for the first time, setting a value of a result bit corresponding to the rule group for matching to a value of the matching result, wherein the matching result is 1 when the matching succeeds, and the matching result is 0 when the matching fails; and when matching is performed not for the first time, updating the value of the result bit corresponding to the rule group for matching, wherein an updated value is a value obtained by performing an “AND” operation on a previous value and the matching result; when the result bit is finally 1, determining that the feature information in the packet conforms to a classification characteristic of one rule group among the plurality of preset rule groups; and when the result bit is finally 0, determining that the feature information in the packet conforms to a classification characteristic of no preset rule group. 8. The method according to claim 6, wherein the method further comprises: generating a feature table corresponding to each rule group, wherein the feature table comprises a plurality of two-dimensional entries and each two-dimensional entry comprises an offset and a character; when a rule in the rule group has a specific character at a specific offset, setting a value of a two-dimensional entry corresponding to the specific offset and the specific character to a valid value; and when no rule in the rule group has a specific character at a specific offset, setting a value of a two-dimensional entry corresponding to the specific offset and the specific character to an invalid value; generating a result bit corresponding to each rule group; and wherein detecting feature information in content of the packet, and determining whether the detected feature information in the packet conforms to a classification characteristic of one rule group among a plurality of preset rule groups comprises: matching each character at each offset in the packet with the two-dimensional entries in the feature table corresponding to each rule group; if a value of a two-dimensional entry comprising a current offset and a current character is valid, the matching succeeds; and a value of a two-dimensional entry comprising a current offset and a current character is invalid, the matching fails, when matching is performed for the first time, setting a value of a result bit corresponding to the rule group for matching to a value of the matching result, wherein the matching result is 1 when the matching succeeds, and the matching result is 0 when the matching fails; and when matching is performed not for the first time, updating the value of the result bit corresponding to the rule group for matching, wherein an updated value is a value obtained by performing an “AND” operation on a previous value and the matching result, when the result bit is finally 1, determining that the feature information in the packet conforms to a classification characteristic of one rule group among the plurality of preset rule groups, and when the result bit is finally 0, determining that the feature information in the packet conforms to a classification characteristic of no preset rule group. 9. The method according to claim 1, wherein: the on-chip memory comprises a static on-chip memory and a cache, content in the static on-chip memory is not updated during program running, and content in the cache is updated during program running; and determining whether the first state machine is stored in the on-chip memory comprises: determining whether the first state machine is stored in the static on-chip memory, and if the first state machine is stored in the static on-chip memory, determining that the first state machine is stored in the on-chip memory, and if the first state machine is not stored in the static on-chip memory, further determining whether the first state machine is stored in the cache, and if the first state machine is stored in the cache, determining that the first state machine is stored in the on-chip memory; and if the first state machine is not stored in the cache, determining that the first state machine is stored in the off-chip memory. 10. The method according to claim 1, wherein using the first state machine to match the packet comprises: using the first state machine to match the packet based on a multithread technology. 11. A rule matching apparatus, comprising: a receiving unit, configured to receive a packet; a detecting unit, configured to detect feature information in the packet received by the receiving unit, and determine whether the detected feature information in the packet conforms to a classification characteristic of one rule group among a plurality of preset rule groups, and send a detection result to a matching unit, wherein there are a plurality of rule groups which are obtained by grouping one or more rules according to predetermined classification characteristics, and each rule group after compiling corresponds to one state machine and one state machine identifier, wherein the state machine is configured to match the packet, wherein a state machine commonly used in matching is stored in an on-chip memory with a relatively high read/write speed, and other state machines are stored in an off-chip memory with a relatively low read/write speed; and the matching unit, configured to determine, when it is learned from the detection result sent by the detecting unit that the feature information detected by the detecting unit conforms to a classification characteristic of one rule group among the plurality of preset rule groups, a state machine corresponding to the one rule group as a first state machine; and determine whether the first state machine is stored in the on-chip memory, and if the first state machine is stored in the on-chip memory, use the first state machine to match the packet to obtain a matching result; and if the first state machine is not stored in the on-chip memory, when the off-chip memory stores the first state machine, load the first state machine from the off-chip memory into the on-chip memory and use the first state machine to match the packet to obtain a matching result. 12. The apparatus according to claim 11, further comprising a first grouping unit, wherein the first grouping unit is configured to: determine a distinctive feature of each rule in one or more rules so that as many other rules without the distinctive feature as possible exist in the one or more rules, and group rules with a same distinctive feature into one group, wherein the distinctive feature is one or more consecutive characters with a predetermined quantity starting from an offset. 13. The apparatus according to claim 12, further comprising: a keyword processing unit, configured to select a predetermined quantity of consecutive characters in the distinctive feature as a keyword of the rule group and store the keyword in a storage space corresponding to the offset; and a hash value calculating unit, configured to perform a hash operation on the keyword of the rule group obtained by the keyword processing unit by processing, to obtain a predetermined hash value corresponding to the rule group, and store the keyword in a storage address corresponding to the predetermined hash value, wherein the predetermined hash value and the storage address conform to a predetermined correspondence; wherein the detecting unit comprises: a hash value calculating subunit, configured to calculate a current hash value of the predetermined quantity of consecutive characters on each offset in the packet, a searching unit, configured to check whether the predetermined quantity of consecutive characters exist in a current storage address corresponding to the current hash value obtained by the hash value calculating subunit, wherein the current hash value and the current storage address conform to the predetermined correspondence, and a first determining unit, configured to, if the predetermined quantity of consecutive characters exist in the current storage address corresponding to the current hash value obtained by the hash value calculating subunit, determine that the detected feature information in the packet conforms to a classification characteristic of one rule group among the plurality of preset rule groups; and if the predetermined quantity of consecutive characters do not exist in the current storage address corresponding to the current hash value obtained by the hash value calculating subunit, determine that the detected feature information in the packet conforms to a classification characteristic of no preset rule group. 14. The apparatus according to claim 13, wherein the first grouping unit is further configured to, when a plurality of distinctive features exist in one or more rules, select the predetermined quantity of consecutive characters in one distinctive feature among the plurality of distinctive features as a keyword of the rule group, wherein the number of keywords stored in a storage space corresponding to an offset of the selected one distinctive feature is as small as possible, compared with keywords stored in storage spaces corresponding to offsets in other distinctive features than the one distinctive feature among the plurality of distinctive features. 15. The apparatus according to claim 11, further comprising a second grouping unit, configured to group one or more rules with as many same characters as possible starting from a same offset into one group. 16. The apparatus according to claim 11, further comprising a third grouping unit, configured to: group rules according to whether the rules are of a protocol type and/or whether the rules are hot rules, to obtain one or more rule sets, wherein one rule set comprises one or more rules; and group one or more rules with as many same characters as possible starting from a same offset in rules comprised in each rule set into one group. 17. The apparatus according to claim 15, further comprising: a feature table generating unit, configured to generate a feature table corresponding to each rule group, wherein the feature table comprises a plurality of two-dimensional entries and each two-dimensional entry comprises an offset and a character; when a rule in the rule group has a specific character at a specific offset, set a value of a two-dimensional entry corresponding to the specific offset and the specific character to a valid value; and when no rule in the rule group has a specific character at a specific offset, set a value of a two-dimensional entry corresponding to the specific offset and the specific character to an invalid value; a result bit generating unit, configured to generate a result bit corresponding to each rule group; and wherein the detecting unit comprises: a feature table matching unit, configured to match each character at each offset in the packet with the two-dimensional entries in the feature table corresponding to each rule group; if a value of a two-dimensional entry comprising a current offset and a current character is valid, the matching succeeds; and otherwise, the matching fails, a result bit setting unit, configured to, when matching is performed for the first time, set a value of a result bit generated by the result bit generating unit corresponding to the rule group for matching to a value of the matching result, wherein the matching result is 1 when the feature table matching unit determines that the matching succeeds, and the matching result is 0 when the feature table matching unit determines that the matching fails; and when matching is performed not for the first time, update the value of the result bit corresponding to the rule group for matching, wherein an updated value is a value obtained by performing an “AND” operation on a previous value and the matching result, and a second determining unit, configured to determine, when the result bit is finally 1 after the processing by the result bit setting unit, that the feature information in the packet conforms to a classification characteristic of one rule group among the plurality of preset rule groups; and when the result bit is finally 0, determine that the feature information in the packet conforms to a classification characteristic of no preset rule group. 18. The apparatus according to claim 16, further comprising: a feature table generating unit, configured to generate a feature table corresponding to each rule group, wherein the feature table comprises a plurality of two-dimensional entries and each two-dimensional entry comprises an offset and a character; when a rule in the rule group has a specific character at a specific offset, set a value of a two-dimensional entry corresponding to the specific offset and the specific character to a valid value; and when no rule in the rule group has a specific character at a specific offset, set a value of a two-dimensional entry corresponding to the specific offset and the specific character to an invalid value; a result bit generating unit, configured to generate a result bit corresponding to each rule group; and wherein the detecting unit comprises: a feature table matching unit, configured to match each character at each offset in the packet with the two-dimensional entries in the feature table corresponding to each rule group; if a value of a two-dimensional entry comprising a current offset and a current character is valid, the matching succeeds; and otherwise, the matching fails, a result bit setting unit, configured to, when matching is performed for the first time, set a value of a result bit generated by the result bit generating unit corresponding to the rule group for matching to a value of the matching result, wherein the matching result is 1 when the feature table matching unit determines that the matching succeeds, and the matching result is 0 when the feature table matching unit determines that the matching fails; and when matching is performed not for the first time, update the value of the result bit corresponding to the rule group for matching, wherein an updated value is a value obtained by performing an “AND” operation on a previous value and the matching result, and a second determining unit, configured to determine, when the result bit is finally 1 after the processing by the result bit setting unit, that the feature information in the packet conforms to a classification characteristic of one rule group among the plurality of preset rule groups; and when the result bit is finally 0, determine that the feature information in the packet conforms to a classification characteristic of no preset rule group. 19. The apparatus according to claim 11, wherein the on-chip memory comprises a static on-chip memory and a cache, content in the static on-chip memory is not updated during program running, and content in the cache is updated during program running; and the detecting unit comprises: a memory determining unit, configured to determine whether the first state machine is stored in the static on-chip memory, and if the first state machine is stored in the static on-chip memory, determine that the first state machine is stored in the on-chip memory; and if the first state machine is not stored in the static on-chip memory, further determine whether the first state machine is stored in the cache, and if the first state machine is stored in the cache, determine that the first state machine is stored in the on-chip memory; and if the first state machine is not stored in the cache, determine that the first state machine is stored in the off-chip memory. 20. The apparatus according to claim 11, wherein the matching unit uses the first state machine to match the packet based on a multithread technology.