|
| 1 | +#!/bin/bash |
| 2 | +# SPDX-License-Identifier: GPL-2.0 |
| 3 | +# |
| 4 | +# Test bond device ether type changing |
| 5 | +# |
| 6 | + |
| 7 | +ALL_TESTS=" |
| 8 | + bond_test_unsuccessful_enslave_type_change |
| 9 | + bond_test_successful_enslave_type_change |
| 10 | +" |
| 11 | +REQUIRE_MZ=no |
| 12 | +NUM_NETIFS=0 |
| 13 | +lib_dir=$(dirname "$0") |
| 14 | +source "$lib_dir"/net_forwarding_lib.sh |
| 15 | + |
| 16 | +bond_check_flags() |
| 17 | +{ |
| 18 | + local bonddev=$1 |
| 19 | + |
| 20 | + ip -d l sh dev "$bonddev" | grep -q "MASTER" |
| 21 | + check_err $? "MASTER flag is missing from the bond device" |
| 22 | + |
| 23 | + ip -d l sh dev "$bonddev" | grep -q "SLAVE" |
| 24 | + check_err $? "SLAVE flag is missing from the bond device" |
| 25 | +} |
| 26 | + |
| 27 | +# test enslaved bond dev type change from ARPHRD_ETHER and back |
| 28 | +# this allows us to test both MASTER and SLAVE flags at once |
| 29 | +bond_test_enslave_type_change() |
| 30 | +{ |
| 31 | + local test_success=$1 |
| 32 | + local devbond0="test-bond0" |
| 33 | + local devbond1="test-bond1" |
| 34 | + local devbond2="test-bond2" |
| 35 | + local nonethdev="test-noneth0" |
| 36 | + |
| 37 | + # create a non-ARPHRD_ETHER device for testing (e.g. nlmon type) |
| 38 | + ip link add name "$nonethdev" type nlmon |
| 39 | + check_err $? "could not create a non-ARPHRD_ETHER device (nlmon)" |
| 40 | + ip link add name "$devbond0" type bond |
| 41 | + if [ $test_success -eq 1 ]; then |
| 42 | + # we need devbond0 in active-backup mode to successfully enslave nonethdev |
| 43 | + ip link set dev "$devbond0" type bond mode active-backup |
| 44 | + check_err $? "could not change bond mode to active-backup" |
| 45 | + fi |
| 46 | + ip link add name "$devbond1" type bond |
| 47 | + ip link add name "$devbond2" type bond |
| 48 | + ip link set dev "$devbond0" master "$devbond1" |
| 49 | + check_err $? "could not enslave $devbond0 to $devbond1" |
| 50 | + # change bond type to non-ARPHRD_ETHER |
| 51 | + ip link set dev "$nonethdev" master "$devbond0" 1>/dev/null 2>/dev/null |
| 52 | + ip link set dev "$nonethdev" nomaster 1>/dev/null 2>/dev/null |
| 53 | + # restore ARPHRD_ETHER type by enslaving such device |
| 54 | + ip link set dev "$devbond2" master "$devbond0" |
| 55 | + check_err $? "could not enslave $devbond2 to $devbond0" |
| 56 | + ip link set dev "$devbond1" nomaster |
| 57 | + |
| 58 | + bond_check_flags "$devbond0" |
| 59 | + |
| 60 | + # clean up |
| 61 | + ip link del dev "$devbond0" |
| 62 | + ip link del dev "$devbond1" |
| 63 | + ip link del dev "$devbond2" |
| 64 | + ip link del dev "$nonethdev" |
| 65 | +} |
| 66 | + |
| 67 | +bond_test_unsuccessful_enslave_type_change() |
| 68 | +{ |
| 69 | + RET=0 |
| 70 | + |
| 71 | + bond_test_enslave_type_change 0 |
| 72 | + log_test "Change ether type of an enslaved bond device with unsuccessful enslave" |
| 73 | +} |
| 74 | + |
| 75 | +bond_test_successful_enslave_type_change() |
| 76 | +{ |
| 77 | + RET=0 |
| 78 | + |
| 79 | + bond_test_enslave_type_change 1 |
| 80 | + log_test "Change ether type of an enslaved bond device with successful enslave" |
| 81 | +} |
| 82 | + |
| 83 | +tests_run |
| 84 | + |
| 85 | +exit "$EXIT_STATUS" |
0 commit comments