brintos

brintos / linux-shallow public Read only

0
0
Text · 3.7 KiB · 6bf9d5a Raw
181 lines · bash
1# SPDX-License-Identifier: GPL-2.02 3mirror_install()4{5	local from_dev=$1; shift6	local direction=$1; shift7	local to_dev=$1; shift8	local filter=$1; shift9 10	tc filter add dev $from_dev $direction \11	   pref 1000 $filter \12	   action mirred egress mirror dev $to_dev13}14 15mirror_uninstall()16{17	local from_dev=$1; shift18	local direction=$1; shift19 20	tc filter del dev $swp1 $direction pref 100021}22 23is_ipv6()24{25	local addr=$1; shift26 27	[[ -z ${addr//[0-9a-fA-F:]/} ]]28}29 30mirror_test()31{32	local vrf_name=$1; shift33	local sip=$1; shift34	local dip=$1; shift35	local dev=$1; shift36	local pref=$1; shift37	local expect=$1; shift38 39	if is_ipv6 $dip; then40		local proto=-641		local type="icmp6 type=128" # Echo request.42	else43		local proto=44		local type="icmp echoreq"45	fi46 47	if [[ -z ${expect//[[:digit:]]/} ]]; then48		expect="== $expect"49	fi50 51	local t0=$(tc_rule_stats_get $dev $pref)52	$MZ $proto $vrf_name ${sip:+-A $sip} -B $dip -a own -b bc -q \53	    -c 10 -d 100msec -t $type54	sleep 0.555	local t1=$(tc_rule_stats_get $dev $pref)56	local delta=$((t1 - t0))57	((delta $expect))58	check_err $? "Expected to capture $expect packets, got $delta."59}60 61do_test_span_dir_ips()62{63	local expect=$1; shift64	local dev=$1; shift65	local ip1=$1; shift66	local ip2=$1; shift67	local forward_type=${1-8}; shift68	local backward_type=${1-0}; shift69 70	icmp_capture_install $dev "type $forward_type"71	mirror_test v$h1 $ip1 $ip2 $dev 100 $expect72	icmp_capture_uninstall $dev73 74	icmp_capture_install $dev "type $backward_type"75	mirror_test v$h2 $ip2 $ip1 $dev 100 $expect76	icmp_capture_uninstall $dev77}78 79quick_test_span_dir_ips()80{81	local dev=$1; shift82	local ip1=$1; shift83	local ip2=$1; shift84	local forward_type=${1-8}; shift85	local backward_type=${1-0}; shift86 87	do_test_span_dir_ips 10 "$dev" "$ip1" "$ip2" \88			     "$forward_type" "$backward_type"89}90 91test_span_dir_ips()92{93	local dev=$1; shift94	local forward_type=$1; shift95	local backward_type=$1; shift96	local ip1=$1; shift97	local ip2=$1; shift98 99	quick_test_span_dir_ips "$dev" "$ip1" "$ip2" \100				"$forward_type" "$backward_type"101 102	icmp_capture_install $dev "type $forward_type"103	mirror_test v$h1 $ip1 $ip2 $dev 100 10104	icmp_capture_uninstall $dev105 106	icmp_capture_install $dev "type $backward_type"107	mirror_test v$h2 $ip2 $ip1 $dev 100 10108	icmp_capture_uninstall $dev109}110 111test_span_dir()112{113	local dev=$1; shift114	local forward_type=$1; shift115	local backward_type=$1; shift116 117	test_span_dir_ips "$dev" "$forward_type" "$backward_type" \118			  192.0.2.1 192.0.2.2119}120 121do_test_span_vlan_dir_ips()122{123	local expect=$1; shift124	local dev=$1; shift125	local vid=$1; shift126	local ul_proto=$1; shift127	local ip1=$1; shift128	local ip2=$1; shift129 130	# Install the capture as skip_hw to avoid double-counting of packets.131	# The traffic is meant for local box anyway, so will be trapped to132	# kernel.133	vlan_capture_install $dev "skip_hw vlan_id $vid vlan_ethtype $ul_proto"134	mirror_test v$h1 $ip1 $ip2 $dev 100 "$expect"135	mirror_test v$h2 $ip2 $ip1 $dev 100 "$expect"136	vlan_capture_uninstall $dev137}138 139quick_test_span_vlan_dir_ips()140{141	local dev=$1; shift142	local vid=$1; shift143	local ul_proto=$1; shift144	local ip1=$1; shift145	local ip2=$1; shift146 147	do_test_span_vlan_dir_ips '>= 10' "$dev" "$vid" "$ul_proto" \148				  "$ip1" "$ip2"149}150 151fail_test_span_vlan_dir_ips()152{153	local dev=$1; shift154	local vid=$1; shift155	local ul_proto=$1; shift156	local ip1=$1; shift157	local ip2=$1; shift158 159	do_test_span_vlan_dir_ips 0 "$dev" "$vid" "$ul_proto" "$ip1" "$ip2"160}161 162quick_test_span_vlan_dir()163{164	local dev=$1; shift165	local vid=$1; shift166	local ul_proto=$1; shift167 168	quick_test_span_vlan_dir_ips "$dev" "$vid" "$ul_proto" \169				     192.0.2.1 192.0.2.2170}171 172fail_test_span_vlan_dir()173{174	local dev=$1; shift175	local vid=$1; shift176	local ul_proto=$1; shift177 178	fail_test_span_vlan_dir_ips "$dev" "$vid" "$ul_proto" \179				    192.0.2.1 192.0.2.2180}181