• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/bin/sh
2# SPDX-License-Identifier: GPL-2.0-or-later
3# Copyright (c) 2019 Petr Vorel <pvorel@suse.cz>
4# Copyright (c) International Business Machines Corp., 2006
5# Author: Mitsuru Chinen <mitch@jp.ibm.com>
6#
7# Change route interface
8# lhost: 10.23.x.2, gw (on rhost): 10.23.x.1, rhost: 10.23.0.1, switching ifaces on lhost
9
10TST_TESTFUNC="test_if"
11. route-lib.sh
12TST_CLEANUP="cleanup"
13
14add_macvlan()
15{
16	local action="add"
17	local OPTIND
18	while getopts d opt; do
19		case "$opt" in
20		d) action="del";;
21		esac
22	done
23	shift $((OPTIND - 1))
24
25	local iface="$1"
26	local type="${2:-lhost}"
27
28	cmd="ip link $action $iface link $(tst_iface $type) type macvlan mode bridge"
29	if [ $type = "lhost" ]; then
30		ROD $cmd
31		[ "$action" = "add" ] || return
32		LHOST_IFACES="$LHOST_IFACES $iface"
33	else
34		tst_rhost_run -s -c "$cmd"
35		[ "$action" = "add" ] || return
36		RHOST_IFACES="$RHOST_IFACES $iface"
37	fi
38	tst_init_iface $type 1
39}
40
41setup()
42{
43	tst_res TINFO "change IPv$TST_IPVER route interface $NS_TIMES times"
44
45	rt="$(tst_ipaddr_un -p 0)"
46	rhost="$(tst_ipaddr_un 0 1)"
47	tst_add_ipaddr -s -q -a $rhost rhost
48
49	if [ $(tst_get_ifaces_cnt) -lt 2 ]; then
50		new_liface="ltp_mv2"
51		tst_res TINFO "2 or more local ifaces required, adding $new_liface"
52		add_macvlan $new_liface
53	fi
54
55	if [ $(tst_get_ifaces_cnt rhost) -lt 2 ]; then
56		new_riface="ltp_mv1"
57		tst_res TINFO "2 or more remote ifaces required, adding $new_riface"
58		add_macvlan $new_riface rhost
59	fi
60
61
62}
63
64test_if()
65{
66	local gw="$(tst_ipaddr_un -n1 $1 1)"
67	local lhost="$(tst_ipaddr_un -n1 $1 2)"
68	local link_num="$(($1 % $(tst_get_ifaces_cnt)))"
69	local iface="$(tst_iface lhost $link_num)"
70
71	tst_res TINFO "testing route over interface '$iface' with gateway '$gw'"
72
73	tst_add_ipaddr -s -q -a $lhost lhost $link_num
74	tst_add_ipaddr -s -q -a $gw rhost $link_num
75	ROD ip route add $rt dev $iface via $gw
76	EXPECT_PASS_BRK ping$TST_IPV6 -c1 -I $lhost $rhost \>/dev/null
77	ROD ip route del $rt dev $iface via $gw
78	tst_del_ipaddr -s -q -a $lhost lhost $link_num
79	tst_del_ipaddr -s -q -a $gw rhost $link_num
80}
81
82cleanup()
83{
84	[ "$new_liface" ] && add_macvlan -d $new_liface
85	[ "$new_riface" ] && add_macvlan -d $new_riface rhost
86	route_cleanup
87}
88
89tst_run
90