if-match
Use if-match to configure a match rule for a DHCPv6 user class.
Use undo if-match to delete a match rule for a DHCP user class.
Syntax
if-match rule rule-number { option option-code [ ascii ascii-string [ offset offset | partial ] | hex hex-string [ mask mask | offset offset length length | partial ] ] | relay-agent gateway-ipv6-address }
undo if-match rule rule-number
Default
No match rules are configured for the DHCPv6 user class.
Views
DHCPv6 user class view
Predefined user roles
network-admin
mdc-admin
Parameters
rule rule-number: Assigns the match rule an ID in the range of 1 to 16. A smaller ID represents a higher match priority.
option option-code: Specifies a DHCPv6 option by its number in the range of 1 to 65535.
ascii ascii-string: Specifies an ASCII string of 1 to 128 characters.
offset offset: Specifies the offset in bytes after which the match operation starts. The value range is 0 to 65534. If you specify an ASCII string, a packet matches the rule if the option content after the offset is the same as the ASCII string. If you specify a hexadecimal number, a packet matches the rule if the option content of the specified length after the offset is the same as the hexadecimal number.
partial: Enables partial match. A packet matches the rule if the specified option in the packet contains the ASCII string or hexadecimal number specified in the rule. For example, if you specify abc in the rule, option content xabc, xyzabca, xabcyz, and abcxyz all match the rule.
hex hex-string: Specifies a hexadecimal number. The length of the hexadecimal number must be an even number in the range of 2 to 256.
mask mask: Specifies the mask for the match operation. The mask is a hexadecimal number whose length is an even number in the range of 2 to 256 and must be the same as the hex-string length. The DHCPv6 server selects option content of the mask length from the start and ANDs the selected option content and the specified hexadecimal number with the mask. The packet matches the rule if the two AND operation results are the same.
length length: Specifies the length of the option content to be matched, in the range of 1 to 128 bytes. The length must be the same as the hex-string length.
relay-agent gateway-ipv6-address: Specifies a link-address field value. The value is an IPv6 address. A packet matches the rule if its link-address field value is the same as that in the rule.
Usage guidelines
If a DHCPv6 request sent by a DHCPv6 client matches a rule in a DHCPv6 user class, the DHCPv6 client matches the user class.
You can configure multiple match rules for a DHCPv6 user class. Each match rule is uniquely identified by a rule ID within its type (option or relay agent address).
If the rule that you are configuring has the same ID and type as an existing rule, the new rule overwrites the existing rule.
If the rule that you are configuring has the same ID as an existing rule but a different type, the new rule takes effect and coexists with the existing rule. As a best practice, do not assign the same ID to rules of different types.
Rules of different IDs cannot have the same rule content.
When you configure an if-match option rule, follow these guidelines:
To match packets that contain an option, specify only the option-code argument.
To match a hexadecimal number by AND operations, specify the option option-code hex hex-string mask mask options.
To match a hexadecimal number directly, specify the option option-code hex hex-string [ offset offset length length | partial ] options. If you do not specify the offset, length, or partial parameter, a packet matches a rule if the option content starts with the hexadecimal number.
To match an ASCII string, specify the option option-code ascii ascii-string [ offset offset | partial ] options. If you do not specify the offset or partial parameter, a packet matches a rule if the option content starts with the ASCII string.
Examples
# Configure match rule 1 for the DHCPv6 user class exam to match DHCPv6 requests that contain Option 16.
<Sysname> system-view [Sysname] ipv6 dhcp class exam [Sysname-dhcp6-class-exam] if-match rule 1 option 16
# Configure match rule 2 for the DHCPv6 user class exam. The rule matches DHCPv6 requests in which the highest bit of the fourth byte in Option 16 is the hexadecimal number 1.
<Sysname> system-view [Sysname] ipv6 dhcp class exam [Sysname-dhcp6-class-exam] if-match rule 2 option 16 hex 00000080 mask 00000080
# Configure match rule 3 for the DHCPv6 user class exam. The rule matches DHCPv6 requests in which the first three bytes of Option 16 are the hexadecimal number 13ae92.
<Sysname> system-view [Sysname] ipv6 dhcp class exam [Sysname-dhcp6-class-exam] if-match rule 3 option 16 hex 13ae92 offset 0 length 3
# Configure match rule 4 for the DHCPv6 user class exam. The rule matches DHCPv6 requests in which the Option 16 contains the hexadecimal number 13ae.
<Sysname> system-view [Sysname] ipv6 dhcp class exam [Sysname-dhcp6-class-exam] if-match rule 5 option 16 hex 13ae partial
# Configure match rule 5 for the DHCPv6 user class exam to match DHCPv6 requests in which the link-address field is 2001::1.
<Sysname> system-view [Sysname] ipv6 dhcp class exam [Sysname-dhcp6-class-exam] if-match rule 5 relay-agent 2001::1
Related commands
ipv6 dhcp class