1*3920431dSJakub Kicinski#!/bin/bash 2*3920431dSJakub Kicinski# SPDX-License-Identifier: GPL-2.0 3*3920431dSJakub Kicinski 4*3920431dSJakub Kicinskiset -o pipefail 5*3920431dSJakub Kicinski 6*3920431dSJakub KicinskiNS=netns-name-test 7*3920431dSJakub KicinskiDEV=dummy-dev0 8*3920431dSJakub KicinskiDEV2=dummy-dev1 9*3920431dSJakub KicinskiALT_NAME=some-alt-name 10*3920431dSJakub Kicinski 11*3920431dSJakub KicinskiRET_CODE=0 12*3920431dSJakub Kicinski 13*3920431dSJakub Kicinskicleanup() { 14*3920431dSJakub Kicinski ip netns del $NS 15*3920431dSJakub Kicinski} 16*3920431dSJakub Kicinski 17*3920431dSJakub Kicinskitrap cleanup EXIT 18*3920431dSJakub Kicinski 19*3920431dSJakub Kicinskifail() { 20*3920431dSJakub Kicinski echo "ERROR: ${1:-unexpected return code} (ret: $_)" >&2 21*3920431dSJakub Kicinski RET_CODE=1 22*3920431dSJakub Kicinski} 23*3920431dSJakub Kicinski 24*3920431dSJakub Kicinskiip netns add $NS 25*3920431dSJakub Kicinski 26*3920431dSJakub Kicinski# 27*3920431dSJakub Kicinski# Test basic move without a rename 28*3920431dSJakub Kicinski# 29*3920431dSJakub Kicinskiip -netns $NS link add name $DEV type dummy || fail 30*3920431dSJakub Kicinskiip -netns $NS link set dev $DEV netns 1 || 31*3920431dSJakub Kicinski fail "Can't perform a netns move" 32*3920431dSJakub Kicinskiip link show dev $DEV >> /dev/null || fail "Device not found after move" 33*3920431dSJakub Kicinskiip link del $DEV || fail 34*3920431dSJakub Kicinski 35*3920431dSJakub Kicinski# 36*3920431dSJakub Kicinski# Test move with a conflict 37*3920431dSJakub Kicinski# 38*3920431dSJakub Kicinskiip link add name $DEV type dummy 39*3920431dSJakub Kicinskiip -netns $NS link add name $DEV type dummy || fail 40*3920431dSJakub Kicinskiip -netns $NS link set dev $DEV netns 1 2> /dev/null && 41*3920431dSJakub Kicinski fail "Performed a netns move with a name conflict" 42*3920431dSJakub Kicinskiip link show dev $DEV >> /dev/null || fail "Device not found after move" 43*3920431dSJakub Kicinskiip -netns $NS link del $DEV || fail 44*3920431dSJakub Kicinskiip link del $DEV || fail 45*3920431dSJakub Kicinski 46*3920431dSJakub Kicinski# 47*3920431dSJakub Kicinski# Test move with a conflict and rename 48*3920431dSJakub Kicinski# 49*3920431dSJakub Kicinskiip link add name $DEV type dummy 50*3920431dSJakub Kicinskiip -netns $NS link add name $DEV type dummy || fail 51*3920431dSJakub Kicinskiip -netns $NS link set dev $DEV netns 1 name $DEV2 || 52*3920431dSJakub Kicinski fail "Can't perform a netns move with rename" 53*3920431dSJakub Kicinskiip link del $DEV2 || fail 54*3920431dSJakub Kicinskiip link del $DEV || fail 55*3920431dSJakub Kicinski 56*3920431dSJakub Kicinski# 57*3920431dSJakub Kicinski# Test dup alt-name with netns move 58*3920431dSJakub Kicinski# 59*3920431dSJakub Kicinskiip link add name $DEV type dummy || fail 60*3920431dSJakub Kicinskiip link property add dev $DEV altname $ALT_NAME || fail 61*3920431dSJakub Kicinskiip -netns $NS link add name $DEV2 type dummy || fail 62*3920431dSJakub Kicinskiip -netns $NS link property add dev $DEV2 altname $ALT_NAME || fail 63*3920431dSJakub Kicinski 64*3920431dSJakub Kicinskiip -netns $NS link set dev $DEV2 netns 1 2> /dev/null && 65*3920431dSJakub Kicinski fail "Moved with alt-name dup" 66*3920431dSJakub Kicinski 67*3920431dSJakub Kicinskiip link del $DEV || fail 68*3920431dSJakub Kicinskiip -netns $NS link del $DEV2 || fail 69*3920431dSJakub Kicinski 70*3920431dSJakub Kicinski# 71*3920431dSJakub Kicinski# Test creating alt-name in one net-ns and using in another 72*3920431dSJakub Kicinski# 73*3920431dSJakub Kicinskiip -netns $NS link add name $DEV type dummy || fail 74*3920431dSJakub Kicinskiip -netns $NS link property add dev $DEV altname $ALT_NAME || fail 75*3920431dSJakub Kicinskiip -netns $NS link set dev $DEV netns 1 || fail 76*3920431dSJakub Kicinskiip link show dev $ALT_NAME >> /dev/null || fail "Can't find alt-name after move" 77*3920431dSJakub Kicinskiip -netns $NS link show dev $ALT_NAME 2> /dev/null && 78*3920431dSJakub Kicinski fail "Can still find alt-name after move" 79*3920431dSJakub Kicinskiip link del $DEV || fail 80*3920431dSJakub Kicinski 81*3920431dSJakub Kicinskiecho -ne "$(basename $0) \t\t\t\t" 82*3920431dSJakub Kicinskiif [ $RET_CODE -eq 0 ]; then 83*3920431dSJakub Kicinski echo "[ OK ]" 84*3920431dSJakub Kicinskielse 85*3920431dSJakub Kicinski echo "[ FAIL ]" 86*3920431dSJakub Kicinskifi 87*3920431dSJakub Kicinskiexit $RET_CODE 88