brintos

brintos / linux-shallow public Read only

0
0
Text · 4.7 KiB · 97bb8b2 Raw
284 lines · bash
1#!/bin/bash2# SPDX-License-Identifier: GPL-2.03 4# +--------------------+5# | H1                 |6# |                    |7# |           $h1.10 + |8# |     192.0.2.2/24 | |9# | 2001:db8:1::2/64 | |10# |                  | |11# |              $h1 + |12# |                  | |13# +------------------|-+14#                    |15# +------------------|-+16# | SW               | |17# |            $swp1 + |18# |                  | |19# |         $swp1.10 + |20# |     192.0.2.1/24   |21# | 2001:db8:1::1/64   |22# |                    |23# +--------------------+24 25ALL_TESTS="26	ping_ipv427	ping_ipv628	max_mtu_config_test29	max_mtu_traffic_test30	min_mtu_config_test31	min_mtu_traffic_test32"33 34NUM_NETIFS=235source lib.sh36 37h1_create()38{39	simple_if_init $h140	vlan_create $h1 10 v$h1 192.0.2.2/24 2001:db8:1::2/6441}42 43h1_destroy()44{45	vlan_destroy $h1 10 192.0.2.2/24 2001:db8:1::2/6446	simple_if_fini $h147}48 49switch_create()50{51	ip li set dev $swp1 up52	vlan_create $swp1 10 "" 192.0.2.1/24 2001:db8:1::1/6453}54 55switch_destroy()56{57	ip li set dev $swp1 down58	vlan_destroy $swp1 1059}60 61setup_prepare()62{63	h1=${NETIFS[p1]}64	swp1=${NETIFS[p2]}65 66	vrf_prepare67 68	h1_create69 70	switch_create71 72	forwarding_enable73}74 75cleanup()76{77	pre_cleanup78 79	forwarding_restore80 81	switch_destroy82 83	h1_destroy84 85	vrf_cleanup86}87 88ping_ipv4()89{90	ping_test $h1.10 192.0.2.191}92 93ping_ipv6()94{95	ping6_test $h1.10 2001:db8:1::196}97 98min_max_mtu_get_if()99{100	local dev=$1; shift101	local min_max=$1; shift102 103	ip -d -j link show $dev | jq ".[].$min_max"104}105 106ensure_compatible_min_max_mtu()107{108	local min_max=$1; shift109 110	local mtu=$(min_max_mtu_get_if ${NETIFS[p1]} $min_max)111	local i112 113	for ((i = 2; i <= NUM_NETIFS; ++i)); do114		local current_mtu=$(min_max_mtu_get_if ${NETIFS[p$i]} $min_max)115 116		if [ $current_mtu -ne $mtu ]; then117			return 1118		fi119	done120}121 122mtu_set_if()123{124	local dev=$1; shift125	local mtu=$1; shift126	local should_fail=${1:-0}; shift127 128	mtu_set $dev $mtu 2>/dev/null129	check_err_fail $should_fail $? "Set MTU $mtu for $dev"130}131 132mtu_set_all_if()133{134	local mtu=$1; shift135	local i136 137	for ((i = 1; i <= NUM_NETIFS; ++i)); do138		mtu_set_if ${NETIFS[p$i]} $mtu139		mtu_set_if ${NETIFS[p$i]}.10 $mtu140	done141}142 143mtu_restore_all_if()144{145	local i146 147	for ((i = 1; i <= NUM_NETIFS; ++i)); do148		mtu_restore ${NETIFS[p$i]}.10149		mtu_restore ${NETIFS[p$i]}150	done151}152 153mtu_test_ping4()154{155	local mtu=$1; shift156	local should_fail=$1; shift157 158	# Ping adds 8 bytes for ICMP header and 20 bytes for IP header159	local ping_headers_len=$((20 + 8))160	local pkt_size=$((mtu - ping_headers_len))161 162	ping_do $h1.10 192.0.2.1 "-s $pkt_size -M do"163	check_err_fail $should_fail $? "Ping, packet size: $pkt_size"164}165 166mtu_test_ping6()167{168	local mtu=$1; shift169	local should_fail=$1; shift170 171	# Ping adds 8 bytes for ICMP header and 40 bytes for IPv6 header172	local ping6_headers_len=$((40 + 8))173	local pkt_size=$((mtu - ping6_headers_len))174 175	ping6_do $h1.10 2001:db8:1::1 "-s $pkt_size -M do"176	check_err_fail $should_fail $? "Ping6, packet size: $pkt_size"177}178 179max_mtu_config_test()180{181	local i182 183	RET=0184 185	for ((i = 1; i <= NUM_NETIFS; ++i)); do186		local dev=${NETIFS[p$i]}187		local max_mtu=$(min_max_mtu_get_if $dev "max_mtu")188		local should_fail189 190		should_fail=0191		mtu_set_if $dev $max_mtu $should_fail192		mtu_restore $dev193 194		should_fail=1195		mtu_set_if $dev $((max_mtu + 1)) $should_fail196		mtu_restore $dev197	done198 199	log_test "Test maximum MTU configuration"200}201 202max_mtu_traffic_test()203{204	local should_fail205	local max_mtu206 207	RET=0208 209	if ! ensure_compatible_min_max_mtu "max_mtu"; then210		log_test_xfail "Topology has incompatible maximum MTU values"211		return212	fi213 214	max_mtu=$(min_max_mtu_get_if ${NETIFS[p1]} "max_mtu")215 216	should_fail=0217	mtu_set_all_if $max_mtu218	mtu_test_ping4 $max_mtu $should_fail219	mtu_test_ping6 $max_mtu $should_fail220	mtu_restore_all_if221 222	should_fail=1223	mtu_set_all_if $((max_mtu - 1))224	mtu_test_ping4 $max_mtu $should_fail225	mtu_test_ping6 $max_mtu $should_fail226	mtu_restore_all_if227 228	log_test "Test traffic, packet size is maximum MTU"229}230 231min_mtu_config_test()232{233	local i234 235	RET=0236 237	for ((i = 1; i <= NUM_NETIFS; ++i)); do238		local dev=${NETIFS[p$i]}239		local min_mtu=$(min_max_mtu_get_if $dev "min_mtu")240		local should_fail241 242		should_fail=0243		mtu_set_if $dev $min_mtu $should_fail244		mtu_restore $dev245 246		should_fail=1247		mtu_set_if $dev $((min_mtu - 1)) $should_fail248		mtu_restore $dev249	done250 251	log_test "Test minimum MTU configuration"252}253 254min_mtu_traffic_test()255{256	local should_fail=0257	local min_mtu258 259	RET=0260 261	if ! ensure_compatible_min_max_mtu "min_mtu"; then262		log_test_xfail "Topology has incompatible minimum MTU values"263		return264	fi265 266	min_mtu=$(min_max_mtu_get_if ${NETIFS[p1]} "min_mtu")267	mtu_set_all_if $min_mtu268	mtu_test_ping4 $min_mtu $should_fail269	# Do not test minimum MTU with IPv6, as IPv6 requires higher MTU.270 271	mtu_restore_all_if272 273	log_test "Test traffic, packet size is minimum MTU"274}275 276trap cleanup EXIT277 278setup_prepare279setup_wait280 281tests_run282 283exit $EXIT_STATUS284