selftests/net/forwarding: Add a test case for tc-flower of mixed port and port-range
After this patch: # ./tc_flower_port_range.sh TEST: Port range matching - IPv4 UDP [ OK ] TEST: Port range matching - IPv4 TCP [ OK ] TEST: Port range matching - IPv6 UDP [ OK ] TEST: Port range matching - IPv6 TCP [ OK ] TEST: Port range matching - IPv4 UDP Drop [ OK ] Cc: Qiang Zhang <dtzq01@gmail.com> Cc: Jamal Hadi Salim <jhs@mojatatu.com> Cc: Jiri Pirko <jiri@resnulli.us> Signed-off-by: Cong Wang <xiyou.wangcong@gmail.com> Reviewed-by: Ido Schimmel <idosch@nvidia.com> Tested-by: Ido Schimmel <idosch@nvidia.com> Link: https://patch.msgid.link/20250218043210.732959-3-xiyou.wangcong@gmail.com Signed-off-by: Jakub Kicinski <kuba@kernel.org>
This commit is contained in:
parent
3e5796862c
commit
dfc1580f96
1 changed files with 46 additions and 0 deletions
|
@ -20,6 +20,7 @@ ALL_TESTS="
|
|||
test_port_range_ipv4_tcp
|
||||
test_port_range_ipv6_udp
|
||||
test_port_range_ipv6_tcp
|
||||
test_port_range_ipv4_udp_drop
|
||||
"
|
||||
|
||||
NUM_NETIFS=4
|
||||
|
@ -194,6 +195,51 @@ test_port_range_ipv6_tcp()
|
|||
__test_port_range $proto $ip_proto $sip $dip $mode "$name"
|
||||
}
|
||||
|
||||
test_port_range_ipv4_udp_drop()
|
||||
{
|
||||
local proto=ipv4
|
||||
local ip_proto=udp
|
||||
local sip=192.0.2.1
|
||||
local dip=192.0.2.2
|
||||
local mode="-4"
|
||||
local name="IPv4 UDP Drop"
|
||||
local dmac=$(mac_get $h2)
|
||||
local smac=$(mac_get $h1)
|
||||
local sport_min=2000
|
||||
local sport_max=3000
|
||||
local sport_mid=$((sport_min + (sport_max - sport_min) / 2))
|
||||
local dport=5000
|
||||
|
||||
RET=0
|
||||
|
||||
tc filter add dev $swp1 ingress protocol $proto handle 101 pref 1 \
|
||||
flower src_ip $sip dst_ip $dip ip_proto $ip_proto \
|
||||
src_port $sport_min-$sport_max \
|
||||
dst_port $dport \
|
||||
action drop
|
||||
|
||||
# Test ports outside range - should pass
|
||||
$MZ $mode $h1 -c 1 -q -p 100 -a $smac -b $dmac -A $sip -B $dip \
|
||||
-t $ip_proto "sp=$((sport_min - 1)),dp=$dport"
|
||||
$MZ $mode $h1 -c 1 -q -p 100 -a $smac -b $dmac -A $sip -B $dip \
|
||||
-t $ip_proto "sp=$((sport_max + 1)),dp=$dport"
|
||||
|
||||
# Test ports inside range - should be dropped
|
||||
$MZ $mode $h1 -c 1 -q -p 100 -a $smac -b $dmac -A $sip -B $dip \
|
||||
-t $ip_proto "sp=$sport_min,dp=$dport"
|
||||
$MZ $mode $h1 -c 1 -q -p 100 -a $smac -b $dmac -A $sip -B $dip \
|
||||
-t $ip_proto "sp=$sport_mid,dp=$dport"
|
||||
$MZ $mode $h1 -c 1 -q -p 100 -a $smac -b $dmac -A $sip -B $dip \
|
||||
-t $ip_proto "sp=$sport_max,dp=$dport"
|
||||
|
||||
tc_check_packets "dev $swp1 ingress" 101 3
|
||||
check_err $? "Filter did not drop the expected number of packets"
|
||||
|
||||
tc filter del dev $swp1 ingress protocol $proto pref 1 handle 101 flower
|
||||
|
||||
log_test "Port range matching - $name"
|
||||
}
|
||||
|
||||
setup_prepare()
|
||||
{
|
||||
h1=${NETIFS[p1]}
|
||||
|
|
Loading…
Add table
Reference in a new issue