• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/bin/sh
2# SPDX-License-Identifier: GPL-2.0-or-later
3# Copyright (c) 2017-2019 Petr Vorel <pvorel@suse.cz>
4# Copyright (c) 2015-2017 Oracle and/or its affiliates. All Rights Reserved.
5# Copyright (c) International Business Machines  Corp., 2005
6# Author: Mitsuru Chinen <mitch@jp.ibm.com>
7
8IF_CMD='ifconfig'
9TST_SETUP="do_setup"
10TST_CLEANUP="do_cleanup"
11. if-lib.sh
12
13# The interval of the mtu change [second]
14CHANGE_INTERVAL=${CHANGE_INTERVAL:-5}
15
16TST_TIMEOUT=$(((CHANGE_INTERVAL + 30) * MTU_CHANGE_TIMES))
17
18# The array of the value which MTU is changed into sequentially
19# 552 - net.ipv4.route.min_pmtu
20CHANGE_VALUES="784 1142 552 1500 552 1500 552 748 552 1142 1500"
21CHANGE6_VALUES="1280 1445 1335 1390 1500 1280 1500 1280 1335 1500"
22saved_mtu=
23
24do_setup()
25{
26	[ "$TST_IPV6" ] && CHANGE_VALUES=$CHANGE6_VALUES
27	if_setup
28	saved_mtu="$(cat /sys/class/net/$(tst_iface)/mtu)"
29}
30
31do_cleanup()
32{
33	if_cleanup_restore
34	if [ "$saved_mtu" ]; then
35		ip li set $(tst_iface) mtu $saved_mtu
36		tst_rhost_run -c "ip li set $(tst_iface rhost) mtu $saved_mtu"
37	fi
38}
39
40test_body()
41{
42	local cmd="$CMD"
43
44	local iface=$(tst_iface)
45	local iface_rmt=$(tst_iface rhost)
46	[ "$TST_IPV6" ] && local netmask=64 || local netmask=16
47
48	tst_res TINFO "'$cmd' changes MTU $MTU_CHANGE_TIMES times" \
49	               "every $CHANGE_INTERVAL seconds"
50
51	mtu_array_len=$(echo $CHANGE_VALUES | wc -w)
52	local cnt=0
53	while [ $cnt -lt $MTU_CHANGE_TIMES ]; do
54		local nth=$(($cnt % $mtu_array_len))
55		field=$(($nth + 1))
56		cnt=$(($cnt + 1))
57		mtu=$(echo $CHANGE_VALUES | cut -d ' ' -f $field)
58		[ $cnt -eq $MTU_CHANGE_TIMES ] && mtu="$saved_mtu"
59
60		make_background_tcp_traffic
61
62		tst_res TINFO "set MTU to $mtu $cnt/$MTU_CHANGE_TIMES"
63		local ret=0
64		case $cmd in
65		ifconfig) ifconfig $iface mtu $mtu || ret=1
66			tst_rhost_run -c "ifconfig $iface_rmt mtu $mtu"
67		;;
68		ip) ip link set $iface mtu $mtu || ret=1
69			tst_rhost_run -c "ip link set $iface_rmt mtu $mtu"
70		;;
71		esac
72
73		if [ $? -ne 0 -o $ret -ne 0 ]; then
74			tst_res TFAIL "Failed to change the mtu at $cnt time"
75			return
76		fi
77
78		tst_sleep $CHANGE_INTERVAL
79
80		tst_ping $(tst_ipaddr) $(tst_ipaddr rhost) "1 1000 65507"
81	done
82}
83
84tst_run
85