Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

selftests/net: convert srv6_end_dt6_l3vpn_test.sh to run it in unique namespace

As the name \${rt-${rt}} may make reader confuse, convert the variable
hs/rt in setup_rt/hs to hid, rid. Here is the test result after conversion.

]# ./srv6_end_dt6_l3vpn_test.sh

################################################################################
TEST SECTION: IPv6 routers connectivity test
################################################################################

TEST: Routers connectivity: rt-1 -> rt-2 [ OK ]

TEST: Routers connectivity: rt-2 -> rt-1 [ OK ]
...

TEST: Hosts isolation: hs-t200-4 -X-> hs-t100-2 [ OK ]

Tests passed: 18
Tests failed: 0

Signed-off-by: Hangbin Liu <liuhangbin@gmail.com>
Link: https://lore.kernel.org/r/20231213060856.4030084-5-liuhangbin@gmail.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>

authored by

Hangbin Liu and committed by
Jakub Kicinski
792cd1db 7b2d941c

+21 -25
+21 -25
tools/testing/selftests/net/srv6_end_dt6_l3vpn_test.sh
··· 164 164 # +---------------------------------------------------+ 165 165 # 166 166 167 - # Kselftest framework requirement - SKIP code is 4. 168 - ksft_skip=4 167 + source lib.sh 169 168 170 169 readonly LOCALSID_TABLE_ID=90 171 170 readonly IPv6_RT_NETWORK=fd00 ··· 219 220 ip link del veth-rt-1 2>/dev/null || true 220 221 ip link del veth-rt-2 2>/dev/null || true 221 222 222 - # destroy routers rt-* and hosts hs-* 223 - for ns in $(ip netns show | grep -E 'rt-*|hs-*'); do 224 - ip netns del ${ns} || true 225 - done 223 + cleanup_all_ns 226 224 } 227 225 228 226 # Setup the basic networking for the routers 229 227 setup_rt_networking() 230 228 { 231 - local rt=$1 232 - local nsname=rt-${rt} 229 + local id=$1 230 + eval local nsname=\${rt_${id}} 233 231 234 - ip netns add ${nsname} 235 - ip link set veth-rt-${rt} netns ${nsname} 236 - ip -netns ${nsname} link set veth-rt-${rt} name veth0 232 + ip link set veth-rt-${id} netns ${nsname} 233 + ip -netns ${nsname} link set veth-rt-${id} name veth0 237 234 238 235 ip netns exec ${nsname} sysctl -wq net.ipv6.conf.all.accept_dad=0 239 236 ip netns exec ${nsname} sysctl -wq net.ipv6.conf.default.accept_dad=0 240 237 241 - ip -netns ${nsname} addr add ${IPv6_RT_NETWORK}::${rt}/64 dev veth0 nodad 238 + ip -netns ${nsname} addr add ${IPv6_RT_NETWORK}::${id}/64 dev veth0 nodad 242 239 ip -netns ${nsname} link set veth0 up 243 240 ip -netns ${nsname} link set lo up 244 241 ··· 243 248 244 249 setup_hs() 245 250 { 246 - local hs=$1 247 - local rt=$2 251 + local hid=$1 252 + local rid=$2 248 253 local tid=$3 249 - local hsname=hs-t${tid}-${hs} 250 - local rtname=rt-${rt} 254 + eval local hsname=\${hs_t${tid}_${hid}} 255 + eval local rtname=\${rt_${rid}} 251 256 local rtveth=veth-t${tid} 252 257 253 258 # set the networking for the host 254 - ip netns add ${hsname} 255 - 256 259 ip netns exec ${hsname} sysctl -wq net.ipv6.conf.all.accept_dad=0 257 260 ip netns exec ${hsname} sysctl -wq net.ipv6.conf.default.accept_dad=0 258 261 259 262 ip -netns ${hsname} link add veth0 type veth peer name ${rtveth} 260 263 ip -netns ${hsname} link set ${rtveth} netns ${rtname} 261 - ip -netns ${hsname} addr add ${IPv6_HS_NETWORK}::${hs}/64 dev veth0 nodad 264 + ip -netns ${hsname} addr add ${IPv6_HS_NETWORK}::${hid}/64 dev veth0 nodad 262 265 ip -netns ${hsname} link set veth0 up 263 266 ip -netns ${hsname} link set lo up 264 267 ··· 286 293 local rtdst=$4 287 294 local tid=$5 288 295 289 - local hssrc_name=hs-t${tid}-${hssrc} 290 - local hsdst_name=hs-t${tid}-${hsdst} 291 - local rtsrc_name=rt-${rtsrc} 292 - local rtdst_name=rt-${rtdst} 296 + eval local rtsrc_name=\${rt_${rtsrc}} 297 + eval local rtdst_name=\${rt_${rtdst}} 293 298 local rtveth=veth-t${tid} 294 299 local vpn_sid=${VPN_LOCATOR_SERVICE}:${hssrc}${hsdst}:${tid}::6006 295 300 ··· 322 331 { 323 332 ip link add veth-rt-1 type veth peer name veth-rt-2 324 333 # setup the networking for router rt-1 and router rt-2 334 + setup_ns rt_1 rt_2 325 335 setup_rt_networking 1 326 336 setup_rt_networking 2 327 337 328 338 # setup two hosts for the tenant 100. 329 339 # - host hs-1 is directly connected to the router rt-1; 330 340 # - host hs-2 is directly connected to the router rt-2. 341 + setup_ns hs_t100_1 hs_t100_2 331 342 setup_hs 1 1 100 #args: host router tenant 332 343 setup_hs 2 2 100 333 344 334 345 # setup two hosts for the tenant 200 335 346 # - host hs-3 is directly connected to the router rt-1; 336 347 # - host hs-4 is directly connected to the router rt-2. 348 + setup_ns hs_t200_3 hs_t200_4 337 349 setup_hs 3 1 200 338 350 setup_hs 4 2 200 339 351 ··· 355 361 { 356 362 local rtsrc=$1 357 363 local rtdst=$2 364 + eval local nsname=\${rt_${rtsrc}} 358 365 359 - ip netns exec rt-${rtsrc} ping -c 1 -W 1 ${IPv6_RT_NETWORK}::${rtdst} \ 366 + ip netns exec ${nsname} ping -c 1 -W 1 ${IPv6_RT_NETWORK}::${rtdst} \ 360 367 >/dev/null 2>&1 361 368 } 362 369 ··· 375 380 local hssrc=$1 376 381 local hsdst=$2 377 382 local tid=$3 383 + eval local nsname=\${hs_t${tid}_${hssrc}} 378 384 379 - ip netns exec hs-t${tid}-${hssrc} ping -c 1 -W ${PING_TIMEOUT_SEC} \ 385 + ip netns exec ${nsname} ping -c 1 -W ${PING_TIMEOUT_SEC} \ 380 386 ${IPv6_HS_NETWORK}::${hsdst} >/dev/null 2>&1 381 387 } 382 388