blob: 0a7b78c63c37ad8f2cf2ded63ad9a0d106ca13dc (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
|
#!/bin/bash
# SPDX-License-Identifier: GPL-2.0
#
# Test the protodown mechanism. Verify basic protodown toggling, protodown
# reasons, operational state when the lower device carrier changes, and correct
# operational state when the lower device has no carrier.
# shellcheck disable=SC1091,SC2034,SC2154,SC2317
source lib.sh
require_command jq
ALL_TESTS="
protodown_basic_macvlan
protodown_basic_vxlan
protodown_reasons
protodown_lower_toggle
protodown_lower_down
"
operstate_get()
{
local ns=$1; shift
local dev=$1; shift
ip -n "$ns" -j link show dev "$dev" | jq -r '.[].operstate'
}
operstate_check()
{
local ns=$1; shift
local dev=$1; shift
local expected=$1; shift
local current
current=$(operstate_get "$ns" "$dev")
[ "$current" = "$expected" ]
}
setup_prepare()
{
setup_ns NS
defer cleanup_all_ns
ip -n "$NS" link add name dummy0 up type dummy
ip -n "$NS" link add name macvlan0 link dummy0 up type macvlan mode bridge
ip -n "$NS" link add name vxlan0 up type vxlan id 10010 dstport 4789
}
protodown_basic()
{
local dev=$1; shift
ip -n "$NS" link set dev "$dev" protodown on
check_err $? "Failed to set protodown on"
busywait "$BUSYWAIT_TIMEOUT" operstate_check "$NS" "$dev" DOWN
check_err $? "Operational state is not DOWN after setting protodown"
ip -n "$NS" link set dev "$dev" protodown off
check_err $? "Failed to set protodown off"
busywait "$BUSYWAIT_TIMEOUT" operstate_check "$NS" "$dev" UP
check_err $? "Operational state is not UP after clearing protodown"
}
protodown_basic_macvlan()
{
RET=0
protodown_basic macvlan0
log_test "Basic protodown on/off with macvlan"
}
protodown_basic_vxlan()
{
RET=0
protodown_basic vxlan0
log_test "Basic protodown on/off with vxlan"
}
protodown_reasons()
{
RET=0
ip -n "$NS" link set dev macvlan0 protodown on
ip -n "$NS" link set dev macvlan0 protodown_reason 0 on
check_err $? "Failed to set protodown reason bit 0"
# Cannot clear protodown while reasons are active.
ip -n "$NS" link set dev macvlan0 protodown off 2>/dev/null
check_fail $? "Clearing protodown succeeded with active reasons"
ip -n "$NS" link set dev macvlan0 protodown_reason 0 off
check_err $? "Failed to clear protodown reason bit 0"
# Can clear protodown when no reasons are active.
ip -n "$NS" link set dev macvlan0 protodown off
check_err $? "Failed to clear protodown with no active reasons"
busywait "$BUSYWAIT_TIMEOUT" operstate_check "$NS" macvlan0 UP
check_err $? "Operational state is not UP after clearing protodown"
log_test "Protodown reasons"
}
protodown_lower_toggle()
{
RET=0
ip -n "$NS" link set dev macvlan0 protodown on
busywait "$BUSYWAIT_TIMEOUT" operstate_check "$NS" macvlan0 DOWN
check_err $? "Operational state is not DOWN after setting protodown"
# Toggle carrier on the lower device. The macvlan should stay DOWN
# because protodown is on.
ip -n "$NS" link set dev dummy0 carrier off
ip -n "$NS" link set dev dummy0 carrier on
busywait "$BUSYWAIT_TIMEOUT" operstate_check "$NS" dummy0 UP
check_err $? "Lower device is not UP after carrier on"
busywait "$BUSYWAIT_TIMEOUT" operstate_check "$NS" macvlan0 DOWN
check_err $? "Macvlan operational state is not DOWN despite protodown"
# Clear protodown and verify the macvlan comes back up.
ip -n "$NS" link set dev macvlan0 protodown off
busywait "$BUSYWAIT_TIMEOUT" operstate_check "$NS" macvlan0 UP
check_err $? "Operational state is not UP after clearing protodown"
log_test "Protodown with lower device toggled"
}
protodown_lower_down()
{
RET=0
# Bring the lower device carrier down first.
ip -n "$NS" link set dev dummy0 carrier off
busywait "$BUSYWAIT_TIMEOUT" operstate_check "$NS" macvlan0 LOWERLAYERDOWN
check_err $? "Macvlan is not LOWERLAYERDOWN with lower carrier off"
# Toggle protodown on and off while lower has no carrier. The macvlan
# should not transition to UP.
ip -n "$NS" link set dev macvlan0 protodown on
busywait "$BUSYWAIT_TIMEOUT" operstate_check "$NS" macvlan0 LOWERLAYERDOWN
check_err $? "Macvlan is not LOWERLAYERDOWN after setting protodown"
ip -n "$NS" link set dev macvlan0 protodown off
busywait "$BUSYWAIT_TIMEOUT" operstate_check "$NS" macvlan0 LOWERLAYERDOWN
check_err $? "Macvlan is not LOWERLAYERDOWN after clearing protodown"
# Bring the lower device carrier up. The macvlan should transition to
# UP.
ip -n "$NS" link set dev dummy0 carrier on
busywait "$BUSYWAIT_TIMEOUT" operstate_check "$NS" dummy0 UP
check_err $? "Lower device is not UP after carrier on"
busywait "$BUSYWAIT_TIMEOUT" operstate_check "$NS" macvlan0 UP
check_err $? "Macvlan is not UP after lower device is UP"
log_test "Protodown with lower device down"
}
trap defer_scopes_cleanup EXIT
setup_prepare
tests_run
exit "$EXIT_STATUS"
|