1
1
#! /bin/bash
2
2
# SPDX-License-Identifier: GPL-2.0
3
3
4
+ source lib.sh
4
5
set -o pipefail
5
6
6
- NS=netns-name-test
7
7
DEV=dummy-dev0
8
8
DEV2=dummy-dev1
9
9
ALT_NAME=some-alt-name
10
10
11
11
RET_CODE=0
12
12
13
13
cleanup () {
14
- ip netns del $NS
14
+ cleanup_ns $NS $test_ns
15
15
}
16
16
17
17
trap cleanup EXIT
@@ -21,62 +21,62 @@ fail() {
21
21
RET_CODE=1
22
22
}
23
23
24
- ip netns add $NS
24
+ setup_ns NS test_ns
25
25
26
26
#
27
27
# Test basic move without a rename
28
28
#
29
29
ip -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 ||
31
31
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
34
34
35
35
#
36
36
# Test move with a conflict
37
37
#
38
- ip link add name $DEV type dummy
38
+ ip -netns $test_ns link add name $DEV type dummy
39
39
ip -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 &&
41
41
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"
43
43
ip -netns $NS link del $DEV || fail
44
- ip link del $DEV || fail
44
+ ip -netns $test_ns link del $DEV || fail
45
45
46
46
#
47
47
# Test move with a conflict and rename
48
48
#
49
- ip link add name $DEV type dummy
49
+ ip -netns $test_ns link add name $DEV type dummy
50
50
ip -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 ||
52
52
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
55
55
56
56
#
57
57
# Test dup alt-name with netns move
58
58
#
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
61
61
ip -netns $NS link add name $DEV2 type dummy || fail
62
62
ip -netns $NS link property add dev $DEV2 altname $ALT_NAME || fail
63
63
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 &&
65
65
fail " Moved with alt-name dup"
66
66
67
- ip link del $DEV || fail
67
+ ip -netns $test_ns link del $DEV || fail
68
68
ip -netns $NS link del $DEV2 || fail
69
69
70
70
#
71
71
# Test creating alt-name in one net-ns and using in another
72
72
#
73
73
ip -netns $NS link add name $DEV type dummy || fail
74
74
ip -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 &&
78
78
fail " Can still find alt-name after move"
79
- ip link del $DEV || fail
79
+ ip -netns $test_ns link del $DEV || fail
80
80
81
81
echo -ne " $( basename $0 ) \t\t\t\t"
82
82
if [ $RET_CODE -eq 0 ]; then
0 commit comments