brintos

brintos / linux-shallow public Read only

0
0
Text · 3.7 KiB · 79775b1 Raw
163 lines · bash
1#!/bin/bash2# SPDX-License-Identifier: GPL-2.03 4ALL_TESTS="tunnel_key_nofrag_test"5 6NUM_NETIFS=47source tc_common.sh8source lib.sh9 10tcflags="skip_hw"11 12h1_create()13{14	simple_if_init $h1 192.0.2.1/2415	forwarding_enable16	mtu_set $h1 150017	tunnel_create h1-et vxlan 192.0.2.1 192.0.2.2 dev $h1 dstport 0 external18	tc qdisc add dev h1-et clsact19	mtu_set h1-et 123020	mtu_restore $h121	mtu_set $h1 100022}23 24h1_destroy()25{26	tc qdisc del dev h1-et clsact27	tunnel_destroy h1-et28	forwarding_restore29	mtu_restore $h130	simple_if_fini $h1 192.0.2.1/2431}32 33h2_create()34{35	simple_if_init $h2 192.0.2.2/2436}37 38h2_destroy()39{40	simple_if_fini $h2 192.0.2.2/2441}42 43switch_create()44{45	simple_if_init $swp1 192.0.2.2/2446	tc qdisc add dev $swp1 clsact47	simple_if_init $swp2 192.0.2.1/2448}49 50switch_destroy()51{52	simple_if_fini $swp2 192.0.2.1/2453	tc qdisc del dev $swp1 clsact54	simple_if_fini $swp1 192.0.2.2/2455}56 57setup_prepare()58{59	h1=${NETIFS[p1]}60	swp1=${NETIFS[p2]}61 62	swp2=${NETIFS[p3]}63	h2=${NETIFS[p4]}64 65	h1mac=$(mac_get $h1)66	h2mac=$(mac_get $h2)67 68	swp1origmac=$(mac_get $swp1)69	swp2origmac=$(mac_get $swp2)70	ip link set $swp1 address $h2mac71	ip link set $swp2 address $h1mac72 73	vrf_prepare74 75	h1_create76	h2_create77	switch_create78 79	if ! tc action add action tunnel_key help 2>&1 | grep -q nofrag; then80		log_test "SKIP: iproute doesn't support nofrag"81		exit $ksft_skip82	fi83}84 85cleanup()86{87	pre_cleanup88 89	switch_destroy90	h2_destroy91	h1_destroy92 93	vrf_cleanup94 95	ip link set $swp2 address $swp2origmac96	ip link set $swp1 address $swp1origmac97}98 99tunnel_key_nofrag_test()100{101	RET=0102	local i103 104	tc filter add dev $swp1 ingress protocol ip pref 100 handle 100 \105		flower src_ip 192.0.2.1 dst_ip 192.0.2.2 ip_proto udp \106		ip_flags nofrag action drop107	tc filter add dev $swp1 ingress protocol ip pref 101 handle 101 \108		flower src_ip 192.0.2.1 dst_ip 192.0.2.2 ip_proto udp \109		ip_flags firstfrag action drop110	tc filter add dev $swp1 ingress protocol ip pref 102 handle 102 \111		flower src_ip 192.0.2.1 dst_ip 192.0.2.2 ip_proto udp \112		ip_flags nofirstfrag action drop113 114	# test 'nofrag' set115	tc filter add dev h1-et egress protocol all pref 1 handle 1 matchall $tcflags \116		action tunnel_key set src_ip 192.0.2.1 dst_ip 192.0.2.2 id 42 nofrag index 10117	$MZ h1-et -c 1 -p 930 -a 00:aa:bb:cc:dd:ee -b 00:ee:dd:cc:bb:aa -t ip -q118	tc_check_packets "dev $swp1 ingress" 100 1119	check_err $? "packet smaller than MTU was not tunneled"120 121	$MZ h1-et -c 1 -p 931 -a 00:aa:bb:cc:dd:ee -b 00:ee:dd:cc:bb:aa -t ip -q122	tc_check_packets "dev $swp1 ingress" 100 1123	check_err $? "packet bigger than MTU matched nofrag (nofrag was set)"124	tc_check_packets "dev $swp1 ingress" 101 0125	check_err $? "packet bigger than MTU matched firstfrag (nofrag was set)"126	tc_check_packets "dev $swp1 ingress" 102 0127	check_err $? "packet bigger than MTU matched nofirstfrag (nofrag was set)"128 129	# test 'nofrag' cleared130	tc actions change action tunnel_key set src_ip 192.0.2.1 dst_ip 192.0.2.2 id 42 index 10131	$MZ h1-et -c 1 -p 931 -a 00:aa:bb:cc:dd:ee -b 00:ee:dd:cc:bb:aa -t ip -q132	tc_check_packets "dev $swp1  ingress" 100 1133	check_err $? "packet bigger than MTU matched nofrag (nofrag was unset)"134	tc_check_packets "dev $swp1  ingress" 101 1135	check_err $? "packet bigger than MTU didn't match firstfrag (nofrag was unset) "136	tc_check_packets "dev $swp1 ingress" 102 1137	check_err $? "packet bigger than MTU didn't match nofirstfrag (nofrag was unset) "138 139	for i in 100 101 102; do140		tc filter del dev $swp1 ingress protocol ip pref $i handle $i flower141	done142	tc filter del dev h1-et egress pref 1 handle 1 matchall143 144	log_test "tunnel_key nofrag ($tcflags)"145}146 147trap cleanup EXIT148 149setup_prepare150setup_wait151 152tests_run153 154tc_offload_check155if [[ $? -ne 0 ]]; then156	log_info "Could not test offloaded functionality"157else158	tcflags="skip_sw"159	tests_run160fi161 162exit $EXIT_STATUS163