Skip to content

Commit ff3fbcd

Browse files
shualikuba-moo
authored andcommitted
selftests: tc: Add generic erspan_opts matching support for tc-flower
Add test cases to tc_flower.sh to validate generic matching on ERSPAN options. Both ERSPAN Type II and Type III are covered. Also add check_tc_erspan_support() to verify whether tc supports erspan_opts. Signed-off-by: Li Shuang <shuali@redhat.com> Reviewed-by: Xin Long <lucien.xin@gmail.com> Link: https://patch.msgid.link/1f354a1afd60f29bbbf02bd60cb52ecfc0b6bd17.1752848172.git.shuali@redhat.com Signed-off-by: Jakub Kicinski <kuba@kernel.org>
1 parent dd500e4 commit ff3fbcd

File tree

2 files changed

+65
-1
lines changed

2 files changed

+65
-1
lines changed

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,20 @@ check_tc_version()
142142
fi
143143
}
144144

145+
check_tc_erspan_support()
146+
{
147+
local dev=$1; shift
148+
149+
tc filter add dev $dev ingress pref 1 handle 1 flower \
150+
erspan_opts 1:0:0:0 &> /dev/null
151+
if [[ $? -ne 0 ]]; then
152+
echo "SKIP: iproute2 too old; tc is missing erspan support"
153+
return $ksft_skip
154+
fi
155+
tc filter del dev $dev ingress pref 1 handle 1 flower \
156+
erspan_opts 1:0:0:0 &> /dev/null
157+
}
158+
145159
# Old versions of tc don't understand "mpls_uc"
146160
check_tc_mpls_support()
147161
{

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

Lines changed: 51 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ ALL_TESTS="match_dst_mac_test match_src_mac_test match_dst_ip_test \
66
match_ip_tos_test match_indev_test match_ip_ttl_test
77
match_mpls_label_test \
88
match_mpls_tc_test match_mpls_bos_test match_mpls_ttl_test \
9-
match_mpls_lse_test"
9+
match_mpls_lse_test match_erspan_opts_test"
1010
NUM_NETIFS=2
1111
source tc_common.sh
1212
source lib.sh
@@ -676,6 +676,56 @@ match_mpls_lse_test()
676676
log_test "mpls lse match ($tcflags)"
677677
}
678678

679+
match_erspan_opts_test()
680+
{
681+
RET=0
682+
683+
check_tc_erspan_support $h2 || return 0
684+
685+
# h1 erspan setup
686+
tunnel_create erspan1 erspan 192.0.2.1 192.0.2.2 dev $h1 seq key 1001 \
687+
tos C ttl 64 erspan_ver 1 erspan 6789 # ERSPAN Type II
688+
tunnel_create erspan2 erspan 192.0.2.1 192.0.2.2 dev $h1 seq key 1002 \
689+
tos C ttl 64 erspan_ver 2 erspan_dir egress erspan_hwid 63 \
690+
# ERSPAN Type III
691+
ip link set dev erspan1 master v$h1
692+
ip link set dev erspan2 master v$h1
693+
# h2 erspan setup
694+
ip link add ep-ex type erspan ttl 64 external # To collect tunnel info
695+
ip link set ep-ex up
696+
ip link set dev ep-ex master v$h2
697+
tc qdisc add dev ep-ex clsact
698+
699+
# ERSPAN Type II [decap direction]
700+
tc filter add dev ep-ex ingress protocol ip handle 101 flower \
701+
$tcflags enc_src_ip 192.0.2.1 enc_dst_ip 192.0.2.2 \
702+
enc_key_id 1001 erspan_opts 1:6789:0:0 \
703+
action drop
704+
# ERSPAN Type III [decap direction]
705+
tc filter add dev ep-ex ingress protocol ip handle 102 flower \
706+
$tcflags enc_src_ip 192.0.2.1 enc_dst_ip 192.0.2.2 \
707+
enc_key_id 1002 erspan_opts 2:0:1:63 action drop
708+
709+
ep1mac=$(mac_get erspan1)
710+
$MZ erspan1 -c 1 -p 64 -a $ep1mac -b $h2mac -t ip -q
711+
tc_check_packets "dev ep-ex ingress" 101 1
712+
check_err $? "ERSPAN Type II"
713+
714+
ep2mac=$(mac_get erspan2)
715+
$MZ erspan2 -c 1 -p 64 -a $ep1mac -b $h2mac -t ip -q
716+
tc_check_packets "dev ep-ex ingress" 102 1
717+
check_err $? "ERSPAN Type III"
718+
719+
# h2 erspan cleanup
720+
tc qdisc del dev ep-ex clsact
721+
tunnel_destroy ep-ex
722+
# h1 erspan cleanup
723+
tunnel_destroy erspan2 # ERSPAN Type III
724+
tunnel_destroy erspan1 # ERSPAN Type II
725+
726+
log_test "erspan_opts match ($tcflags)"
727+
}
728+
679729
setup_prepare()
680730
{
681731
h1=${NETIFS[p1]}

0 commit comments

Comments
 (0)