0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034
0035
0036
0037
0038
0039
0040
0041
0042
0043
0044
0045
0046
0047
0048
0049
0050
0051
0052
0053
0054
0055
0056
0057
0058
0059
0060
0061
0062
0063
0064
0065
0066
0067
0068
0069
0070
0071
0072
0073
0074
0075
0076
0077
0078
0079
0080
0081
0082
0083
0084
0085
0086
0087
0088
0089
0090
0091
0092
0093
0094
0095
0096
0097
0098
0099
0100
0101
0102
0103
0104
0105
0106
0107
0108
0109
0110
0111
0112
0113
0114
0115
0116
0117
0118
0119
0120
0121
0122
0123
0124
0125
0126
0127
0128
0129
0130
0131
0132
0133
0134
0135
0136
0137
0138
0139
0140
0141
0142
0143
0144
0145
0146
0147
0148
0149
0150
0151
0152
0153
0154
0155
0156
0157
0158
0159
0160
0161
0162
0163
0164
0165
0166
0167
0168 ksft_skip=4
0169
0170 readonly LOCALSID_TABLE_ID=90
0171 readonly IPv6_RT_NETWORK=fd00
0172 readonly IPv6_HS_NETWORK=cafe
0173 readonly VPN_LOCATOR_SERVICE=fc00
0174 PING_TIMEOUT_SEC=4
0175
0176 ret=0
0177
0178 PAUSE_ON_FAIL=${PAUSE_ON_FAIL:=no}
0179
0180 log_test()
0181 {
0182 local rc=$1
0183 local expected=$2
0184 local msg="$3"
0185
0186 if [ ${rc} -eq ${expected} ]; then
0187 nsuccess=$((nsuccess+1))
0188 printf "\n TEST: %-60s [ OK ]\n" "${msg}"
0189 else
0190 ret=1
0191 nfail=$((nfail+1))
0192 printf "\n TEST: %-60s [FAIL]\n" "${msg}"
0193 if [ "${PAUSE_ON_FAIL}" = "yes" ]; then
0194 echo
0195 echo "hit enter to continue, 'q' to quit"
0196 read a
0197 [ "$a" = "q" ] && exit 1
0198 fi
0199 fi
0200 }
0201
0202 print_log_test_results()
0203 {
0204 if [ "$TESTS" != "none" ]; then
0205 printf "\nTests passed: %3d\n" ${nsuccess}
0206 printf "Tests failed: %3d\n" ${nfail}
0207 fi
0208 }
0209
0210 log_section()
0211 {
0212 echo
0213 echo "################################################################################"
0214 echo "TEST SECTION: $*"
0215 echo "################################################################################"
0216 }
0217
0218 cleanup()
0219 {
0220 ip link del veth-rt-1 2>/dev/null || true
0221 ip link del veth-rt-2 2>/dev/null || true
0222
0223
0224 for ns in $(ip netns show | grep -E 'rt-*|hs-*'); do
0225 ip netns del ${ns} || true
0226 done
0227 }
0228
0229
0230 setup_rt_networking()
0231 {
0232 local rt=$1
0233 local nsname=rt-${rt}
0234
0235 ip netns add ${nsname}
0236 ip link set veth-rt-${rt} netns ${nsname}
0237 ip -netns ${nsname} link set veth-rt-${rt} name veth0
0238
0239 ip netns exec ${nsname} sysctl -wq net.ipv6.conf.all.accept_dad=0
0240 ip netns exec ${nsname} sysctl -wq net.ipv6.conf.default.accept_dad=0
0241
0242 ip -netns ${nsname} addr add ${IPv6_RT_NETWORK}::${rt}/64 dev veth0 nodad
0243 ip -netns ${nsname} link set veth0 up
0244 ip -netns ${nsname} link set lo up
0245
0246 ip netns exec ${nsname} sysctl -wq net.ipv6.conf.all.forwarding=1
0247 }
0248
0249 setup_hs()
0250 {
0251 local hs=$1
0252 local rt=$2
0253 local tid=$3
0254 local hsname=hs-t${tid}-${hs}
0255 local rtname=rt-${rt}
0256 local rtveth=veth-t${tid}
0257
0258
0259 ip netns add ${hsname}
0260
0261 ip netns exec ${hsname} sysctl -wq net.ipv6.conf.all.accept_dad=0
0262 ip netns exec ${hsname} sysctl -wq net.ipv6.conf.default.accept_dad=0
0263
0264 ip -netns ${hsname} link add veth0 type veth peer name ${rtveth}
0265 ip -netns ${hsname} link set ${rtveth} netns ${rtname}
0266 ip -netns ${hsname} addr add ${IPv6_HS_NETWORK}::${hs}/64 dev veth0 nodad
0267 ip -netns ${hsname} link set veth0 up
0268 ip -netns ${hsname} link set lo up
0269
0270
0271
0272 ip -netns ${rtname} link add vrf-${tid} type vrf table ${tid}
0273 ip -netns ${rtname} link set vrf-${tid} up
0274
0275 ip netns exec ${rtname} sysctl -wq net.ipv6.conf.all.accept_dad=0
0276 ip netns exec ${rtname} sysctl -wq net.ipv6.conf.default.accept_dad=0
0277
0278
0279 ip -netns ${rtname} link set ${rtveth} master vrf-${tid}
0280 ip -netns ${rtname} addr add ${IPv6_HS_NETWORK}::254/64 dev ${rtveth} nodad
0281 ip -netns ${rtname} link set ${rtveth} up
0282
0283 ip netns exec ${rtname} sysctl -wq net.ipv6.conf.${rtveth}.proxy_ndp=1
0284
0285 ip netns exec ${rtname} sh -c "echo 1 > /proc/sys/net/vrf/strict_mode"
0286 }
0287
0288 setup_vpn_config()
0289 {
0290 local hssrc=$1
0291 local rtsrc=$2
0292 local hsdst=$3
0293 local rtdst=$4
0294 local tid=$5
0295
0296 local hssrc_name=hs-t${tid}-${hssrc}
0297 local hsdst_name=hs-t${tid}-${hsdst}
0298 local rtsrc_name=rt-${rtsrc}
0299 local rtdst_name=rt-${rtdst}
0300 local rtveth=veth-t${tid}
0301 local vpn_sid=${VPN_LOCATOR_SERVICE}:${hssrc}${hsdst}:${tid}::6006
0302
0303 ip -netns ${rtsrc_name} -6 neigh add proxy ${IPv6_HS_NETWORK}::${hsdst} dev ${rtveth}
0304
0305
0306
0307 ip -netns ${rtsrc_name} -6 route add ${IPv6_HS_NETWORK}::${hsdst}/128 vrf vrf-${tid} \
0308 encap seg6 mode encap segs ${vpn_sid} dev veth0
0309 ip -netns ${rtsrc_name} -6 route add ${vpn_sid}/128 vrf vrf-${tid} \
0310 via fd00::${rtdst} dev veth0
0311
0312
0313
0314 ip -netns ${rtdst_name} -6 route add ${vpn_sid}/128 table ${LOCALSID_TABLE_ID} \
0315 encap seg6local action End.DT6 vrftable ${tid} dev vrf-${tid}
0316
0317
0318
0319
0320
0321
0322 if [ -z "$(ip -netns ${rtdst_name} -6 rule show | \
0323 grep "to ${VPN_LOCATOR_SERVICE}::/16 lookup ${LOCALSID_TABLE_ID}")" ]; then
0324 ip -netns ${rtdst_name} -6 rule add \
0325 to ${VPN_LOCATOR_SERVICE}::/16 \
0326 lookup ${LOCALSID_TABLE_ID} prio 999
0327 fi
0328 }
0329
0330 setup()
0331 {
0332 ip link add veth-rt-1 type veth peer name veth-rt-2
0333
0334 setup_rt_networking 1
0335 setup_rt_networking 2
0336
0337
0338
0339
0340 setup_hs 1 1 100
0341 setup_hs 2 2 100
0342
0343
0344
0345
0346 setup_hs 3 1 200
0347 setup_hs 4 2 200
0348
0349
0350
0351 setup_vpn_config 1 1 2 2 100
0352 setup_vpn_config 2 2 1 1 100
0353
0354
0355
0356 setup_vpn_config 3 1 4 2 200
0357 setup_vpn_config 4 2 3 1 200
0358 }
0359
0360 check_rt_connectivity()
0361 {
0362 local rtsrc=$1
0363 local rtdst=$2
0364
0365 ip netns exec rt-${rtsrc} ping -c 1 -W 1 ${IPv6_RT_NETWORK}::${rtdst} \
0366 >/dev/null 2>&1
0367 }
0368
0369 check_and_log_rt_connectivity()
0370 {
0371 local rtsrc=$1
0372 local rtdst=$2
0373
0374 check_rt_connectivity ${rtsrc} ${rtdst}
0375 log_test $? 0 "Routers connectivity: rt-${rtsrc} -> rt-${rtdst}"
0376 }
0377
0378 check_hs_connectivity()
0379 {
0380 local hssrc=$1
0381 local hsdst=$2
0382 local tid=$3
0383
0384 ip netns exec hs-t${tid}-${hssrc} ping -c 1 -W ${PING_TIMEOUT_SEC} \
0385 ${IPv6_HS_NETWORK}::${hsdst} >/dev/null 2>&1
0386 }
0387
0388 check_and_log_hs_connectivity()
0389 {
0390 local hssrc=$1
0391 local hsdst=$2
0392 local tid=$3
0393
0394 check_hs_connectivity ${hssrc} ${hsdst} ${tid}
0395 log_test $? 0 "Hosts connectivity: hs-t${tid}-${hssrc} -> hs-t${tid}-${hsdst} (tenant ${tid})"
0396 }
0397
0398 check_and_log_hs_isolation()
0399 {
0400 local hssrc=$1
0401 local tidsrc=$2
0402 local hsdst=$3
0403 local tiddst=$4
0404
0405 check_hs_connectivity ${hssrc} ${hsdst} ${tidsrc}
0406
0407 log_test $? 1 "Hosts isolation: hs-t${tidsrc}-${hssrc} -X-> hs-t${tiddst}-${hsdst}"
0408 }
0409
0410
0411 check_and_log_hs2gw_connectivity()
0412 {
0413 local hssrc=$1
0414 local tid=$2
0415
0416 check_hs_connectivity ${hssrc} 254 ${tid}
0417 log_test $? 0 "Hosts connectivity: hs-t${tid}-${hssrc} -> gw (tenant ${tid})"
0418 }
0419
0420 router_tests()
0421 {
0422 log_section "IPv6 routers connectivity test"
0423
0424 check_and_log_rt_connectivity 1 2
0425 check_and_log_rt_connectivity 2 1
0426 }
0427
0428 host2gateway_tests()
0429 {
0430 log_section "IPv6 connectivity test among hosts and gateway"
0431
0432 check_and_log_hs2gw_connectivity 1 100
0433 check_and_log_hs2gw_connectivity 2 100
0434
0435 check_and_log_hs2gw_connectivity 3 200
0436 check_and_log_hs2gw_connectivity 4 200
0437 }
0438
0439 host_vpn_tests()
0440 {
0441 log_section "SRv6 VPN connectivity test among hosts in the same tenant"
0442
0443 check_and_log_hs_connectivity 1 2 100
0444 check_and_log_hs_connectivity 2 1 100
0445
0446 check_and_log_hs_connectivity 3 4 200
0447 check_and_log_hs_connectivity 4 3 200
0448 }
0449
0450 host_vpn_isolation_tests()
0451 {
0452 local i
0453 local j
0454 local k
0455 local tmp
0456 local l1="1 2"
0457 local l2="3 4"
0458 local t1=100
0459 local t2=200
0460
0461 log_section "SRv6 VPN isolation test among hosts in different tentants"
0462
0463 for k in 0 1; do
0464 for i in ${l1}; do
0465 for j in ${l2}; do
0466 check_and_log_hs_isolation ${i} ${t1} ${j} ${t2}
0467 done
0468 done
0469
0470
0471 tmp="${l1}"; l1="${l2}"; l2="${tmp}"
0472 tmp=${t1}; t1=${t2}; t2=${tmp}
0473 done
0474 }
0475
0476 if [ "$(id -u)" -ne 0 ];then
0477 echo "SKIP: Need root privileges"
0478 exit $ksft_skip
0479 fi
0480
0481 if [ ! -x "$(command -v ip)" ]; then
0482 echo "SKIP: Could not run test without ip tool"
0483 exit $ksft_skip
0484 fi
0485
0486 modprobe vrf &>/dev/null
0487 if [ ! -e /proc/sys/net/vrf/strict_mode ]; then
0488 echo "SKIP: vrf sysctl does not exist"
0489 exit $ksft_skip
0490 fi
0491
0492 cleanup &>/dev/null
0493
0494 setup
0495
0496 router_tests
0497 host2gateway_tests
0498 host_vpn_tests
0499 host_vpn_isolation_tests
0500
0501 print_log_test_results
0502
0503 cleanup &>/dev/null
0504
0505 exit ${ret}