避免术语匹配时发生冲突
快速更新过滤器可以包含多个术语,每个术语具有各种匹配条件。但是,在过滤器中配置多个术语时,必须确保这些术语不会重叠或相互冲突。当一个数据包可能匹配这两个术语的所有条件时,两个术语被视为重叠。由于每个术语都指定了不同的匹配作,因此路由器无法确定要执行的作。当术语重叠时,将发生冲突错误,并且当动态配置文件尝试应用过滤器时,会话将失败。错误日志指示重叠的术语。
路由器如何评估过滤器中的术语
路由器在检查术语时创建匹配条件表。该表类似于路由表,基于语句中包含的 match-order 条件。当路由器收到数据包时,路由器将按语句中 match-order 指定的顺序检查数据包的内容。
例如,使用以下匹配顺序示例中的示例配置,路由器首先检查数据包的 source-address,然后 destination-address检查 ,最后 destination-port检查 。如下表所示,过滤器中的两个术语不会重叠,因为每个术语都有不同的 destination-port 规范。然后,路由器会针对与 destination-port 数据包值匹配的术语执行适当的过滤作。
期限 |
源-地址 |
目标地址 |
目标端口 |
行动 |
|---|---|---|---|---|
T55 |
用户地址 |
203.0.113.2/32 |
HTTP地址 |
计数t55_cntr 接受 |
T999 |
用户地址 |
203.0.113.2/32 |
HTTP地址 |
计数t999_cntr 接受 |
匹配顺序示例
firewall {
family inet {
fast-update-filter psf1 {
interface-specific;
match-order [ source-address destination-address destination-port ];
term t55 {
from {
source-address $junos-subscriber-ip-address;
destination-address 203.0.113.2/32;
destination-port http;
}
then {
count t55_cntr;
accept;
}
}
term t999 {
from {
source-address $junos-subscriber-ip-address;
destination-address 203.0.113.2/32;
destination-port https;
}
then {
count t999_cntr;
accept;
}
}
}
}
}
使用隐含通配符
本部分显示如何在匹配配置中使用隐式通配符规范的示例。当过滤器中的术语规范中未配置from该条件时,语句中的match-order条件是隐式通配符。
在术语中使用范围(例如,值范围或通配符)时,范围不得重叠,重叠的范围会产生冲突错误。但是,您可以在一个术语中配置范围,在另一个术语中配置完全匹配。例如,在以下过滤器表中,term t3 中的通配符目标端口值在术语t999t55上不会与目标端口规格重叠,并且因为 和 https 值http完全匹配。
在隐式通配符示例配置中,路由器将语句中的match-order条件视为 destination-port term t3的隐式通配符,因为该术语中未配置任何destination-port值。因此,通配符指定对于术语t3,接受任何destination-port值。过滤器表如下所示:
期限 |
源-地址 |
目标地址 |
目标端口 |
行动 |
|---|---|---|---|---|
T3 |
用户地址 |
203.0.113.2/32 |
any(通配符) |
计数t3_cntr 接受 |
T55 |
用户地址 |
203.0.113.2/32 |
HTTP地址 |
计数t55_cntr 接受 |
T999 |
用户地址 |
203.0.113.2/32 |
HTTP地址 |
计数t999_cntr 接受 |
在以下过滤器配置中,目标端口为 http 的流量与术语 t55 匹配,目标端口为 https 匹配术语 t999的流量。目标端口不在 http 或 https 与术语 t3匹配的流量,即隐含的通配符。
隐含通配符示例
firewall {
family inet {
fast-update-filter psf1 {
interface-specific;
match-order [ source-address destination-address dscp protocol destination-port ];
term t3 {
from {
source-address $junos-subscriber-ip-address;
destination-address 203.0.113.2/32;
}
then {
count t3_cntr;
accept;
}
}
term t55 {
from {
source-address $junos-subscriber-ip-address;
destination-address 203.0.113.2/32;
destination-port http;
}
then {
count t55_cntr;
accept;
}
}
term t999 {
from {
source-address $junos-subscriber-ip-address;
destination-address 203.0.113.2/32;
destination-port https;
}
then {
count t999_cntr;
accept;
}
}
}
}
}
范围重叠引起的冲突
本节显示术语重叠范围的两个示例。在术语中使用范围(例如通配符或值范围)时,范围不得重叠 - 重叠范围会产生冲突错误,并且会话会失败。
在以下筛选器配置中, destination-port 这两个术语中的范围重叠。50 到 80 范围内的端口与 term src0 和 term src1匹配,每个端口指定要执行的不同作。
您可以在一个术语中配置范围,在另一个术语中配置完全匹配。请参阅使用 隐式通配符部分,了解使用通配符表示一个术语中的匹配条件并将通配符用于第二个术语中的条件的完全匹配示例。
期限 |
源-地址 |
目标地址 |
目标端口 |
行动 |
|---|---|---|---|---|
SRC0 |
用户地址 |
203.0.113.2/32 |
0–80 |
计数c1_cntr 接受 |
SRC1 |
用户地址 |
203.0.113.2/32 |
50–100 |
计数c2_cntr 接受 |
重叠范围 示例 1
firewall {
family inet {
fast-update-filter fuf–src {
interface-specific;
match-order [ source-address destination-address destination-port ];
term src0 {
from {
source-address $junos-subscriber-ip-address;
destination-address 203.0.113.2/32;
destination-port 0–80;
}
then {
count c1_cntr;
accept;
}
}
term src1 {
from {
source-address $junos-subscriber-ip-address;
destination-address 203.0.113.2/32;
destination-port 50–100;
}
then {
count c2_cntr;
accept;
}
}
}
在此过滤器配置中, protocol 术语 src21 中的规范并 src22 使用隐含通配符,用于为每个术语配置一个范围。由于不允许重叠范围,因此会导致冲突错误。
期限 |
源-地址 |
目标地址 |
协议 |
目标端口 |
行动 |
|---|---|---|---|---|---|
SRC20 |
用户地址 |
203.0.113.2/32 |
UDP |
any(通配符) |
计数c20_cntr 接受 |
SRC21 |
用户地址 |
203.0.113.2/32 |
any(通配符) |
HTTP地址 |
计数c21_cntr 接受 |
SRC21 |
用户地址 |
203.0.113.2/32 |
any(通配符) |
HTTP地址 |
计数c22_cntr 接受 |
重叠范围 示例 2
firewall {
family inet {
fast-update-filter fuf–src2 {
interface-specific;
match-order [ source-address destination-address protocol destination-port ];
term src20 {
from {
source-address $junos-subscriber-ip-address;
destination-address 203.0.113.2/32;
protocol udp;
}
then {
count c20_cntr;
accept;
}
}
term src21 {
from {
source-address $junos-subscriber-ip-address;
destination-address 203.0.113.2/32;
destination-port http;
}
then {
count c21_cntr;
accept;
}
}
term src22 {
from {
source-address $junos-subscriber-ip-address;
destination-address 203.0.113.2/32;
destination-port https;
}
then {
count c22_cntr;
accept;
}
}
}