Skip to content

Commit 1891cfe

Browse files
committed
Merge branch 'convert-net-selftests-to-run-in-unique-namespace-part-3'
Hangbin Liu says: ==================== Convert net selftests to run in unique namespace (Part 3) Here is the 3rd part of converting net selftests to run in unique namespace. This part converts all srv6 and fib tests. Note that patch 06 is a fix for testing fib_nexthop_multiprefix. Here is the part 1 link: https://lore.kernel.org/netdev/[email protected] And part 2 link: https://lore.kernel.org/netdev/[email protected] ==================== Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Jakub Kicinski <[email protected]>
2 parents fcb2987 + b795db1 commit 1891cfe

13 files changed

+332
-367
lines changed

tools/testing/selftests/net/fcnal-test.sh

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,7 @@
3737
#
3838
# server / client nomenclature relative to ns-A
3939

40-
# Kselftest framework requirement - SKIP code is 4.
41-
ksft_skip=4
42-
40+
source lib.sh
4341
VERBOSE=0
4442

4543
NSA_DEV=eth1
@@ -82,14 +80,6 @@ MCAST=ff02::1
8280
NSA_LINKIP6=
8381
NSB_LINKIP6=
8482

85-
NSA=ns-A
86-
NSB=ns-B
87-
NSC=ns-C
88-
89-
NSA_CMD="ip netns exec ${NSA}"
90-
NSB_CMD="ip netns exec ${NSB}"
91-
NSC_CMD="ip netns exec ${NSC}"
92-
9383
which ping6 > /dev/null 2>&1 && ping6=$(which ping6) || ping6=$(which ping)
9484

9585
# Check if FIPS mode is enabled
@@ -406,9 +396,6 @@ create_ns()
406396
local addr=$2
407397
local addr6=$3
408398

409-
ip netns add ${ns}
410-
411-
ip -netns ${ns} link set lo up
412399
if [ "${addr}" != "-" ]; then
413400
ip -netns ${ns} addr add dev lo ${addr}
414401
fi
@@ -467,13 +454,12 @@ cleanup()
467454
ip -netns ${NSA} link del dev ${NSA_DEV}
468455

469456
ip netns pids ${NSA} | xargs kill 2>/dev/null
470-
ip netns del ${NSA}
457+
cleanup_ns ${NSA}
471458
fi
472459

473460
ip netns pids ${NSB} | xargs kill 2>/dev/null
474-
ip netns del ${NSB}
475461
ip netns pids ${NSC} | xargs kill 2>/dev/null
476-
ip netns del ${NSC} >/dev/null 2>&1
462+
cleanup_ns ${NSB} ${NSC}
477463
}
478464

479465
cleanup_vrf_dup()
@@ -487,6 +473,8 @@ setup_vrf_dup()
487473
{
488474
# some VRF tests use ns-C which has the same config as
489475
# ns-B but for a device NOT in the VRF
476+
setup_ns NSC
477+
NSC_CMD="ip netns exec ${NSC}"
490478
create_ns ${NSC} "-" "-"
491479
connect_ns ${NSA} ${NSA_DEV2} ${NSA_IP}/24 ${NSA_IP6}/64 \
492480
${NSC} ${NSC_DEV} ${NSB_IP}/24 ${NSB_IP6}/64
@@ -503,6 +491,10 @@ setup()
503491
log_debug "Configuring network namespaces"
504492
set -e
505493

494+
setup_ns NSA NSB
495+
NSA_CMD="ip netns exec ${NSA}"
496+
NSB_CMD="ip netns exec ${NSB}"
497+
506498
create_ns ${NSA} ${NSA_LO_IP}/32 ${NSA_LO_IP6}/128
507499
create_ns ${NSB} ${NSB_LO_IP}/32 ${NSB_LO_IP6}/128
508500
connect_ns ${NSA} ${NSA_DEV} ${NSA_IP}/24 ${NSA_IP6}/64 \
@@ -545,6 +537,10 @@ setup_lla_only()
545537
log_debug "Configuring network namespaces"
546538
set -e
547539

540+
setup_ns NSA NSB NSC
541+
NSA_CMD="ip netns exec ${NSA}"
542+
NSB_CMD="ip netns exec ${NSB}"
543+
NSC_CMD="ip netns exec ${NSC}"
548544
create_ns ${NSA} "-" "-"
549545
create_ns ${NSB} "-" "-"
550546
create_ns ${NSC} "-" "-"

tools/testing/selftests/net/fdb_flush.sh

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
# Check that flush works as expected with all the supported arguments and verify
66
# some combinations of arguments.
77

8+
source lib.sh
9+
810
FLUSH_BY_STATE_TESTS="
911
vxlan_test_flush_by_permanent
1012
vxlan_test_flush_by_nopermanent
@@ -739,10 +741,9 @@ bridge_vxlan_test_flush()
739741

740742
setup()
741743
{
742-
IP="ip -netns ns1"
743-
BRIDGE="bridge -netns ns1"
744-
745-
ip netns add ns1
744+
setup_ns NS
745+
IP="ip -netns ${NS}"
746+
BRIDGE="bridge -netns ${NS}"
746747

747748
$IP link add name vx10 type vxlan id 1000 dstport "$VXPORT"
748749
$IP link add name vx20 type vxlan id 2000 dstport "$VXPORT"
@@ -759,7 +760,7 @@ cleanup()
759760
$IP link del dev vx20
760761
$IP link del dev vx10
761762

762-
ip netns del ns1
763+
cleanup_ns ${NS}
763764
}
764765

765766
################################################################################

tools/testing/selftests/net/fib-onlink-tests.sh

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
# IPv4 and IPv6 onlink tests
55

6+
source lib.sh
67
PAUSE_ON_FAIL=${PAUSE_ON_FAIL:=no}
78
VERBOSE=0
89

@@ -74,9 +75,6 @@ TEST_NET4IN6[2]=10.2.1.254
7475
# mcast address
7576
MCAST6=ff02::1
7677

77-
78-
PEER_NS=bart
79-
PEER_CMD="ip netns exec ${PEER_NS}"
8078
VRF=lisa
8179
VRF_TABLE=1101
8280
PBR_TABLE=101
@@ -176,8 +174,7 @@ setup()
176174
set -e
177175

178176
# create namespace
179-
ip netns add ${PEER_NS}
180-
ip -netns ${PEER_NS} li set lo up
177+
setup_ns PEER_NS
181178

182179
# add vrf table
183180
ip li add ${VRF} type vrf table ${VRF_TABLE}
@@ -219,7 +216,7 @@ setup()
219216
cleanup()
220217
{
221218
# make sure we start from a clean slate
222-
ip netns del ${PEER_NS} 2>/dev/null
219+
cleanup_ns ${PEER_NS} 2>/dev/null
223220
for n in 1 3 5 7; do
224221
ip link del ${NETIFS[p${n}]} 2>/dev/null
225222
done

tools/testing/selftests/net/fib_nexthop_multiprefix.sh

Lines changed: 48 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#
1313
# routing in h0 to hN is done with nexthop objects.
1414

15+
source lib.sh
1516
PAUSE_ON_FAIL=no
1617
VERBOSE=0
1718

@@ -72,12 +73,6 @@ create_ns()
7273
{
7374
local ns=${1}
7475

75-
ip netns del ${ns} 2>/dev/null
76-
77-
ip netns add ${ns}
78-
ip -netns ${ns} addr add 127.0.0.1/8 dev lo
79-
ip -netns ${ns} link set lo up
80-
8176
ip netns exec ${ns} sysctl -q -w net.ipv6.conf.all.keep_addr_on_down=1
8277
case ${ns} in
8378
h*)
@@ -97,7 +92,13 @@ setup()
9792

9893
#set -e
9994

100-
for ns in h0 r1 h1 h2 h3
95+
setup_ns h0 r1 h1 h2 h3
96+
h[0]=$h0
97+
h[1]=$h1
98+
h[2]=$h2
99+
h[3]=$h3
100+
r[1]=$r1
101+
for ns in ${h[0]} ${r[1]} ${h[1]} ${h[2]} ${h[3]}
101102
do
102103
create_ns ${ns}
103104
done
@@ -108,46 +109,43 @@ setup()
108109

109110
for i in 0 1 2 3
110111
do
111-
ip -netns h${i} li add eth0 type veth peer name r1h${i}
112-
ip -netns h${i} li set eth0 up
113-
ip -netns h${i} li set r1h${i} netns r1 name eth${i} up
114-
115-
ip -netns h${i} addr add dev eth0 172.16.10${i}.1/24
116-
ip -netns h${i} -6 addr add dev eth0 2001:db8:10${i}::1/64
117-
ip -netns r1 addr add dev eth${i} 172.16.10${i}.254/24
118-
ip -netns r1 -6 addr add dev eth${i} 2001:db8:10${i}::64/64
112+
ip -netns ${h[$i]} li add eth0 type veth peer name r1h${i}
113+
ip -netns ${h[$i]} li set eth0 up
114+
ip -netns ${h[$i]} li set r1h${i} netns ${r[1]} name eth${i} up
115+
116+
ip -netns ${h[$i]} addr add dev eth0 172.16.10${i}.1/24
117+
ip -netns ${h[$i]} -6 addr add dev eth0 2001:db8:10${i}::1/64
118+
ip -netns ${r[1]} addr add dev eth${i} 172.16.10${i}.254/24
119+
ip -netns ${r[1]} -6 addr add dev eth${i} 2001:db8:10${i}::64/64
119120
done
120121

121-
ip -netns h0 nexthop add id 4 via 172.16.100.254 dev eth0
122-
ip -netns h0 nexthop add id 6 via 2001:db8:100::64 dev eth0
122+
ip -netns ${h[0]} nexthop add id 4 via 172.16.100.254 dev eth0
123+
ip -netns ${h[0]} nexthop add id 6 via 2001:db8:100::64 dev eth0
123124

124-
# routing from h0 to h1-h3 and back
125+
# routing from ${h[0]} to h1-h3 and back
125126
for i in 1 2 3
126127
do
127-
ip -netns h0 ro add 172.16.10${i}.0/24 nhid 4
128-
ip -netns h${i} ro add 172.16.100.0/24 via 172.16.10${i}.254
128+
ip -netns ${h[0]} ro add 172.16.10${i}.0/24 nhid 4
129+
ip -netns ${h[$i]} ro add 172.16.100.0/24 via 172.16.10${i}.254
129130

130-
ip -netns h0 -6 ro add 2001:db8:10${i}::/64 nhid 6
131-
ip -netns h${i} -6 ro add 2001:db8:100::/64 via 2001:db8:10${i}::64
131+
ip -netns ${h[0]} -6 ro add 2001:db8:10${i}::/64 nhid 6
132+
ip -netns ${h[$i]} -6 ro add 2001:db8:100::/64 via 2001:db8:10${i}::64
132133
done
133134

134135
if [ "$VERBOSE" = "1" ]; then
135136
echo
136137
echo "host 1 config"
137-
ip -netns h0 li sh
138-
ip -netns h0 ro sh
139-
ip -netns h0 -6 ro sh
138+
ip -netns ${h[0]} li sh
139+
ip -netns ${h[0]} ro sh
140+
ip -netns ${h[0]} -6 ro sh
140141
fi
141142

142143
#set +e
143144
}
144145

145146
cleanup()
146147
{
147-
for n in h0 r1 h1 h2 h3
148-
do
149-
ip netns del ${n} 2>/dev/null
150-
done
148+
cleanup_all_ns
151149
}
152150

153151
change_mtu()
@@ -156,7 +154,7 @@ change_mtu()
156154
local mtu=$2
157155

158156
run_cmd ip -netns h${hostid} li set eth0 mtu ${mtu}
159-
run_cmd ip -netns r1 li set eth${hostid} mtu ${mtu}
157+
run_cmd ip -netns ${r1} li set eth${hostid} mtu ${mtu}
160158
}
161159

162160
################################################################################
@@ -168,23 +166,23 @@ validate_v4_exception()
168166
local mtu=$2
169167
local ping_sz=$3
170168
local dst="172.16.10${i}.1"
171-
local h0=172.16.100.1
172-
local r1=172.16.100.254
169+
local h0_ip=172.16.100.1
170+
local r1_ip=172.16.100.254
173171
local rc
174172

175173
if [ ${ping_sz} != "0" ]; then
176-
run_cmd ip netns exec h0 ping -s ${ping_sz} -c5 -w5 ${dst}
174+
run_cmd ip netns exec ${h0} ping -s ${ping_sz} -c5 -w5 ${dst}
177175
fi
178176

179177
if [ "$VERBOSE" = "1" ]; then
180178
echo "Route get"
181-
ip -netns h0 ro get ${dst}
179+
ip -netns ${h0} ro get ${dst}
182180
echo "Searching for:"
183181
echo " cache .* mtu ${mtu}"
184182
echo
185183
fi
186184

187-
ip -netns h0 ro get ${dst} | \
185+
ip -netns ${h0} ro get ${dst} | \
188186
grep -q "cache .* mtu ${mtu}"
189187
rc=$?
190188

@@ -197,24 +195,24 @@ validate_v6_exception()
197195
local mtu=$2
198196
local ping_sz=$3
199197
local dst="2001:db8:10${i}::1"
200-
local h0=2001:db8:100::1
201-
local r1=2001:db8:100::64
198+
local h0_ip=2001:db8:100::1
199+
local r1_ip=2001:db8:100::64
202200
local rc
203201

204202
if [ ${ping_sz} != "0" ]; then
205-
run_cmd ip netns exec h0 ${ping6} -s ${ping_sz} -c5 -w5 ${dst}
203+
run_cmd ip netns exec ${h0} ${ping6} -s ${ping_sz} -c5 -w5 ${dst}
206204
fi
207205

208206
if [ "$VERBOSE" = "1" ]; then
209207
echo "Route get"
210-
ip -netns h0 -6 ro get ${dst}
208+
ip -netns ${h0} -6 ro get ${dst}
211209
echo "Searching for:"
212-
echo " ${dst} from :: via ${r1} dev eth0 src ${h0} .* mtu ${mtu}"
210+
echo " ${dst}.* via ${r1_ip} dev eth0 src ${h0_ip} .* mtu ${mtu}"
213211
echo
214212
fi
215213

216-
ip -netns h0 -6 ro get ${dst} | \
217-
grep -q "${dst} from :: via ${r1} dev eth0 src ${h0} .* mtu ${mtu}"
214+
ip -netns ${h0} -6 ro get ${dst} | \
215+
grep -q "${dst}.* via ${r1_ip} dev eth0 src ${h0_ip} .* mtu ${mtu}"
218216
rc=$?
219217

220218
log_test $rc 0 "IPv6: host 0 to host ${i}, mtu ${mtu}"
@@ -242,11 +240,11 @@ for i in 1 2 3
242240
do
243241
# generate a cached route per-cpu
244242
for c in ${cpus}; do
245-
run_cmd taskset -c ${c} ip netns exec h0 ping -c1 -w1 172.16.10${i}.1
246-
[ $? -ne 0 ] && printf "\nERROR: ping to h${i} failed\n" && ret=1
243+
run_cmd taskset -c ${c} ip netns exec ${h0} ping -c1 -w1 172.16.10${i}.1
244+
[ $? -ne 0 ] && printf "\nERROR: ping to ${h[$i]} failed\n" && ret=1
247245

248-
run_cmd taskset -c ${c} ip netns exec h0 ${ping6} -c1 -w1 2001:db8:10${i}::1
249-
[ $? -ne 0 ] && printf "\nERROR: ping6 to h${i} failed\n" && ret=1
246+
run_cmd taskset -c ${c} ip netns exec ${h0} ${ping6} -c1 -w1 2001:db8:10${i}::1
247+
[ $? -ne 0 ] && printf "\nERROR: ping6 to ${h[$i]} failed\n" && ret=1
250248

251249
[ $ret -ne 0 ] && break
252250
done
@@ -282,11 +280,11 @@ if [ $ret -eq 0 ]; then
282280
validate_v6_exception 3 1400 0
283281

284282
# targeted deletes to trigger cleanup paths in kernel
285-
ip -netns h0 ro del 172.16.102.0/24 nhid 4
286-
ip -netns h0 -6 ro del 2001:db8:102::/64 nhid 6
283+
ip -netns ${h0} ro del 172.16.102.0/24 nhid 4
284+
ip -netns ${h0} -6 ro del 2001:db8:102::/64 nhid 6
287285

288-
ip -netns h0 nexthop del id 4
289-
ip -netns h0 nexthop del id 6
286+
ip -netns ${h0} nexthop del id 4
287+
ip -netns ${h0} nexthop del id 6
290288
fi
291289

292290
cleanup

0 commit comments

Comments
 (0)