brintos

brintos / linux-shallow public Read only

0
0
Text · 4.9 KiB · 3ca20df Raw
207 lines · bash
1#!/bin/bash2# SPDX-License-Identifier: GPL-2.03 4ALL_TESTS="match_cfm_opcode match_cfm_level match_cfm_level_and_opcode"5NUM_NETIFS=26source tc_common.sh7source lib.sh8 9h1_create()10{11	simple_if_init $h112}13 14h1_destroy()15{16	simple_if_fini $h117}18 19h2_create()20{21	simple_if_init $h222	tc qdisc add dev $h2 clsact23}24 25h2_destroy()26{27	tc qdisc del dev $h2 clsact28	simple_if_fini $h229}30 31u8_to_hex()32{33	local u8=$1; shift34 35	printf "%02x" $u836}37 38generate_cfm_hdr()39{40	local mdl=$1; shift41	local op=$1; shift42	local flags=$1; shift43	local tlv_offset=$1; shift44 45	local cfm_hdr=$(:46	               )"$(u8_to_hex $((mdl << 5))):"$( 	: MD level and Version47	               )"$(u8_to_hex $op):"$(			: OpCode48	               )"$(u8_to_hex $flags):"$(		: Flags49	               )"$(u8_to_hex $tlv_offset)"$(		: TLV offset50	               )51 52	echo $cfm_hdr53}54 55match_cfm_opcode()56{57	local ethtype="89 02"; readonly ethtype58	RET=059 60	tc filter add dev $h2 ingress protocol cfm pref 1 handle 101 \61	   flower cfm op 47 action drop62	tc filter add dev $h2 ingress protocol cfm pref 1 handle 102 \63	   flower cfm op 43 action drop64 65	pkt="$ethtype $(generate_cfm_hdr 7 47 0 32)"66	$MZ $h1 -c 1 -p 64 -a $h1mac -b $h2mac "$pkt" -q67	pkt="$ethtype $(generate_cfm_hdr 6 5 0 4)"68	$MZ $h1 -c 1 -p 64 -a $h1mac -b $h2mac "$pkt" -q69 70	tc_check_packets "dev $h2 ingress" 101 171	check_err $? "Did not match on correct opcode"72 73	tc_check_packets "dev $h2 ingress" 102 074	check_err $? "Matched on the wrong opcode"75 76	pkt="$ethtype $(generate_cfm_hdr 0 43 0 12)"77	$MZ $h1 -c 1 -p 64 -a $h1mac -b $h2mac "$pkt" -q78 79	tc_check_packets "dev $h2 ingress" 101 180	check_err $? "Matched on the wrong opcode"81 82	tc_check_packets "dev $h2 ingress" 102 183	check_err $? "Did not match on correct opcode"84 85	tc filter del dev $h2 ingress protocol cfm pref 1 handle 101 flower86	tc filter del dev $h2 ingress protocol cfm pref 1 handle 102 flower87 88	log_test "CFM opcode match test"89}90 91match_cfm_level()92{93	local ethtype="89 02"; readonly ethtype94	RET=095 96	tc filter add dev $h2 ingress protocol cfm pref 1 handle 101 \97	   flower cfm mdl 5 action drop98	tc filter add dev $h2 ingress protocol cfm pref 1 handle 102 \99	   flower cfm mdl 3 action drop100	tc filter add dev $h2 ingress protocol cfm pref 1 handle 103 \101	   flower cfm mdl 0 action drop102 103	pkt="$ethtype $(generate_cfm_hdr 5 42 0 12)"104	$MZ $h1 -c 1 -p 64 -a $h1mac -b $h2mac "$pkt" -q105	pkt="$ethtype $(generate_cfm_hdr 6 1 0 70)"106	$MZ $h1 -c 1 -p 64 -a $h1mac -b $h2mac "$pkt" -q107	pkt="$ethtype $(generate_cfm_hdr 0 1 0 70)"108	$MZ $h1 -c 1 -p 64 -a $h1mac -b $h2mac "$pkt" -q109 110	tc_check_packets "dev $h2 ingress" 101 1111	check_err $? "Did not match on correct level"112 113	tc_check_packets "dev $h2 ingress" 102 0114	check_err $? "Matched on the wrong level"115 116	tc_check_packets "dev $h2 ingress" 103 1117	check_err $? "Did not match on correct level"118 119	pkt="$ethtype $(generate_cfm_hdr 3 0 0 4)"120	$MZ $h1 -c 1 -p 64 -a $h1mac -b $h2mac "$pkt" -q121 122	tc_check_packets "dev $h2 ingress" 101 1123	check_err $? "Matched on the wrong level"124 125	tc_check_packets "dev $h2 ingress" 102 1126	check_err $? "Did not match on correct level"127 128	tc_check_packets "dev $h2 ingress" 103 1129	check_err $? "Matched on the wrong level"130 131	tc filter del dev $h2 ingress protocol cfm pref 1 handle 101 flower132	tc filter del dev $h2 ingress protocol cfm pref 1 handle 102 flower133	tc filter del dev $h2 ingress protocol cfm pref 1 handle 103 flower134 135	log_test "CFM level match test"136}137 138match_cfm_level_and_opcode()139{140	local ethtype="89 02"; readonly ethtype141	RET=0142 143	tc filter add dev $h2 ingress protocol cfm pref 1 handle 101 \144	   flower cfm mdl 5 op 41 action drop145	tc filter add dev $h2 ingress protocol cfm pref 1 handle 102 \146	   flower cfm mdl 7 op 42 action drop147 148	pkt="$ethtype $(generate_cfm_hdr 5 41 0 4)"149	$MZ $h1 -c 1 -p 64 -a $h1mac -b $h2mac "$pkt" -q150	pkt="$ethtype $(generate_cfm_hdr 7 3 0 4)"151	$MZ $h1 -c 1 -p 64 -a $h1mac -b $h2mac "$pkt" -q152	pkt="$ethtype $(generate_cfm_hdr 3 42 0 12)"153	$MZ $h1 -c 1 -p 64 -a $h1mac -b $h2mac "$pkt" -q154 155	tc_check_packets "dev $h2 ingress" 101 1156	check_err $? "Did not match on correct level and opcode"157 158	tc_check_packets "dev $h2 ingress" 102 0159	check_err $? "Matched on the wrong level and opcode"160 161	pkt="$ethtype $(generate_cfm_hdr 7 42 0 12)"162	$MZ $h1 -c 1 -p 64 -a $h1mac -b $h2mac "$pkt" -q163 164	tc_check_packets "dev $h2 ingress" 101 1165	check_err $? "Matched on the wrong level and opcode"166 167	tc_check_packets "dev $h2 ingress" 102 1168	check_err $? "Did not match on correct level and opcode"169 170	tc filter del dev $h2 ingress protocol cfm pref 1 handle 101 flower171	tc filter del dev $h2 ingress protocol cfm pref 1 handle 102 flower172 173	log_test "CFM opcode and level match test"174}175 176setup_prepare()177{178	h1=${NETIFS[p1]}179	h2=${NETIFS[p2]}180	h1mac=$(mac_get $h1)181	h2mac=$(mac_get $h2)182 183	vrf_prepare184 185	h1_create186	h2_create187}188 189cleanup()190{191	pre_cleanup192 193	h2_destroy194	h1_destroy195 196	vrf_cleanup197}198 199trap cleanup EXIT200 201setup_prepare202setup_wait203 204tests_run205 206exit $EXIT_STATUS207