11#! /bin/bash
22# SPDX-License-Identifier: GPL-2.0
33
4+ source lib.sh
45set -o pipefail
56
6- NS=netns-name-test
77DEV=dummy-dev0
88DEV2=dummy-dev1
99ALT_NAME=some-alt-name
1010
1111RET_CODE=0
1212
1313cleanup () {
14- ip netns del $NS
14+ cleanup_ns $NS $test_ns
1515}
1616
1717trap cleanup EXIT
@@ -21,62 +21,62 @@ fail() {
2121 RET_CODE=1
2222}
2323
24- ip netns add $NS
24+ setup_ns NS test_ns
2525
2626#
2727# Test basic move without a rename
2828#
2929ip -netns $NS link add name $DEV type dummy || fail
30- ip -netns $NS link set dev $DEV netns 1 ||
30+ ip -netns $NS link set dev $DEV netns $test_ns ||
3131 fail " Can't perform a netns move"
32- ip link show dev $DEV >> /dev/null || fail " Device not found after move"
33- ip link del $DEV || fail
32+ ip -netns $test_ns link show dev $DEV >> /dev/null || fail " Device not found after move"
33+ ip -netns $test_ns link del $DEV || fail
3434
3535#
3636# Test move with a conflict
3737#
38- ip link add name $DEV type dummy
38+ ip -netns $test_ns link add name $DEV type dummy
3939ip -netns $NS link add name $DEV type dummy || fail
40- ip -netns $NS link set dev $DEV netns 1 2> /dev/null &&
40+ ip -netns $NS link set dev $DEV netns $test_ns 2> /dev/null &&
4141 fail " Performed a netns move with a name conflict"
42- ip link show dev $DEV >> /dev/null || fail " Device not found after move"
42+ ip -netns $test_ns link show dev $DEV >> /dev/null || fail " Device not found after move"
4343ip -netns $NS link del $DEV || fail
44- ip link del $DEV || fail
44+ ip -netns $test_ns link del $DEV || fail
4545
4646#
4747# Test move with a conflict and rename
4848#
49- ip link add name $DEV type dummy
49+ ip -netns $test_ns link add name $DEV type dummy
5050ip -netns $NS link add name $DEV type dummy || fail
51- ip -netns $NS link set dev $DEV netns 1 name $DEV2 ||
51+ ip -netns $NS link set dev $DEV netns $test_ns name $DEV2 ||
5252 fail " Can't perform a netns move with rename"
53- ip link del $DEV2 || fail
54- ip link del $DEV || fail
53+ ip -netns $test_ns link del $DEV2 || fail
54+ ip -netns $test_ns link del $DEV || fail
5555
5656#
5757# Test dup alt-name with netns move
5858#
59- ip link add name $DEV type dummy || fail
60- ip link property add dev $DEV altname $ALT_NAME || fail
59+ ip -netns $test_ns link add name $DEV type dummy || fail
60+ ip -netns $test_ns link property add dev $DEV altname $ALT_NAME || fail
6161ip -netns $NS link add name $DEV2 type dummy || fail
6262ip -netns $NS link property add dev $DEV2 altname $ALT_NAME || fail
6363
64- ip -netns $NS link set dev $DEV2 netns 1 2> /dev/null &&
64+ ip -netns $NS link set dev $DEV2 netns $test_ns 2> /dev/null &&
6565 fail " Moved with alt-name dup"
6666
67- ip link del $DEV || fail
67+ ip -netns $test_ns link del $DEV || fail
6868ip -netns $NS link del $DEV2 || fail
6969
7070#
7171# Test creating alt-name in one net-ns and using in another
7272#
7373ip -netns $NS link add name $DEV type dummy || fail
7474ip -netns $NS link property add dev $DEV altname $ALT_NAME || fail
75- ip -netns $NS link set dev $DEV netns 1 || fail
76- ip link show dev $ALT_NAME >> /dev/null || fail " Can't find alt-name after move"
77- ip -netns $NS link show dev $ALT_NAME 2> /dev/null &&
75+ ip -netns $NS link set dev $DEV netns $test_ns || fail
76+ ip -netns $test_ns link show dev $ALT_NAME >> /dev/null || fail " Can't find alt-name after move"
77+ ip -netns $NS link show dev $ALT_NAME 2> /dev/null &&
7878 fail " Can still find alt-name after move"
79- ip link del $DEV || fail
79+ ip -netns $test_ns link del $DEV || fail
8080
8181echo -ne " $( basename $0 ) \t\t\t\t"
8282if [ $RET_CODE -eq 0 ]; then
0 commit comments