Skip to content

Commit dfc1580

Browse files
congwangkuba-moo
authored andcommitted
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 <[email protected]> Cc: Jamal Hadi Salim <[email protected]> Cc: Jiri Pirko <[email protected]> Signed-off-by: Cong Wang <[email protected]> Reviewed-by: Ido Schimmel <[email protected]> Tested-by: Ido Schimmel <[email protected]> Link: https://patch.msgid.link/[email protected] Signed-off-by: Jakub Kicinski <[email protected]>
1 parent 3e57968 commit dfc1580

File tree

1 file changed

+46
-0
lines changed

1 file changed

+46
-0
lines changed

tools/testing/selftests/net/forwarding/tc_flower_port_range.sh

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ ALL_TESTS="
2020
test_port_range_ipv4_tcp
2121
test_port_range_ipv6_udp
2222
test_port_range_ipv6_tcp
23+
test_port_range_ipv4_udp_drop
2324
"
2425

2526
NUM_NETIFS=4
@@ -194,6 +195,51 @@ test_port_range_ipv6_tcp()
194195
__test_port_range $proto $ip_proto $sip $dip $mode "$name"
195196
}
196197

198+
test_port_range_ipv4_udp_drop()
199+
{
200+
local proto=ipv4
201+
local ip_proto=udp
202+
local sip=192.0.2.1
203+
local dip=192.0.2.2
204+
local mode="-4"
205+
local name="IPv4 UDP Drop"
206+
local dmac=$(mac_get $h2)
207+
local smac=$(mac_get $h1)
208+
local sport_min=2000
209+
local sport_max=3000
210+
local sport_mid=$((sport_min + (sport_max - sport_min) / 2))
211+
local dport=5000
212+
213+
RET=0
214+
215+
tc filter add dev $swp1 ingress protocol $proto handle 101 pref 1 \
216+
flower src_ip $sip dst_ip $dip ip_proto $ip_proto \
217+
src_port $sport_min-$sport_max \
218+
dst_port $dport \
219+
action drop
220+
221+
# Test ports outside range - should pass
222+
$MZ $mode $h1 -c 1 -q -p 100 -a $smac -b $dmac -A $sip -B $dip \
223+
-t $ip_proto "sp=$((sport_min - 1)),dp=$dport"
224+
$MZ $mode $h1 -c 1 -q -p 100 -a $smac -b $dmac -A $sip -B $dip \
225+
-t $ip_proto "sp=$((sport_max + 1)),dp=$dport"
226+
227+
# Test ports inside range - should be dropped
228+
$MZ $mode $h1 -c 1 -q -p 100 -a $smac -b $dmac -A $sip -B $dip \
229+
-t $ip_proto "sp=$sport_min,dp=$dport"
230+
$MZ $mode $h1 -c 1 -q -p 100 -a $smac -b $dmac -A $sip -B $dip \
231+
-t $ip_proto "sp=$sport_mid,dp=$dport"
232+
$MZ $mode $h1 -c 1 -q -p 100 -a $smac -b $dmac -A $sip -B $dip \
233+
-t $ip_proto "sp=$sport_max,dp=$dport"
234+
235+
tc_check_packets "dev $swp1 ingress" 101 3
236+
check_err $? "Filter did not drop the expected number of packets"
237+
238+
tc filter del dev $swp1 ingress protocol $proto pref 1 handle 101 flower
239+
240+
log_test "Port range matching - $name"
241+
}
242+
197243
setup_prepare()
198244
{
199245
h1=${NETIFS[p1]}

0 commit comments

Comments
 (0)