1#!/bin/bash 2# SPDX-License-Identifier: GPL-2.0 3# 4# author: Andrea Mayer <andrea.mayer@uniroma2.it> 5# 6# This script is designed for testing the SRv6 H.L2Encaps.Red behavior. 7# 8# Below is depicted the IPv6 network of an operator which offers L2 VPN 9# services to hosts, enabling them to communicate with each other. 10# In this example, hosts hs-1 and hs-2 are connected through an L2 VPN service. 11# Currently, the SRv6 subsystem in Linux allows hosts hs-1 and hs-2 to exchange 12# full L2 frames as long as they carry IPv4/IPv6. 13# 14# Routers rt-1,rt-2,rt-3 and rt-4 implement L2 VPN services 15# leveraging the SRv6 architecture. The key components for such VPNs are: 16# 17# i) The SRv6 H.L2Encaps.Red behavior applies SRv6 Policies on traffic 18# received by connected hosts, initiating the VPN tunnel. Such a behavior 19# is an optimization of the SRv6 H.L2Encap aiming to reduce the 20# length of the SID List carried in the pushed SRH. Specifically, the 21# H.L2Encaps.Red removes the first SID contained in the SID List (i.e. SRv6 22# Policy) by storing it into the IPv6 Destination Address. When a SRv6 23# Policy is made of only one SID, the SRv6 H.L2Encaps.Red behavior omits 24# the SRH at all and pushes that SID directly into the IPv6 DA; 25# 26# ii) The SRv6 End behavior advances the active SID in the SID List 27# carried by the SRH; 28# 29# iii) The SRv6 End.DX2 behavior is used for removing the SRv6 Policy 30# and, thus, it terminates the VPN tunnel. The decapsulated L2 frame is 31# sent over the interface connected with the destination host. 32# 33# cafe::1 cafe::2 34# 10.0.0.1 10.0.0.2 35# +--------+ +--------+ 36# | | | | 37# | hs-1 | | hs-2 | 38# | | | | 39# +---+----+ +--- +---+ 40# cafe::/64 | | cafe::/64 41# 10.0.0.0/24 | | 10.0.0.0/24 42# +---+----+ +----+---+ 43# | | fcf0:0:1:2::/64 | | 44# | rt-1 +-------------------+ rt-2 | 45# | | | | 46# +---+----+ +----+---+ 47# | . . | 48# | fcf0:0:1:3::/64 . | 49# | . . | 50# | . . | 51# fcf0:0:1:4::/64 | . | fcf0:0:2:3::/64 52# | . . | 53# | . . | 54# | fcf0:0:2:4::/64 . | 55# | . . | 56# +---+----+ +----+---+ 57# | | | | 58# | rt-4 +-------------------+ rt-3 | 59# | | fcf0:0:3:4::/64 | | 60# +---+----+ +----+---+ 61# 62# 63# Every fcf0:0:x:y::/64 network interconnects the SRv6 routers rt-x with rt-y 64# in the IPv6 operator network. 65# 66# Local SID table 67# =============== 68# 69# Each SRv6 router is configured with a Local SID table in which SIDs are 70# stored. Considering the given SRv6 router rt-x, at least two SIDs are 71# configured in the Local SID table: 72# 73# Local SID table for SRv6 router rt-x 74# +----------------------------------------------------------+ 75# |fcff:x::e is associated with the SRv6 End behavior | 76# |fcff:x::d2 is associated with the SRv6 End.DX2 behavior | 77# +----------------------------------------------------------+ 78# 79# The fcff::/16 prefix is reserved by the operator for implementing SRv6 VPN 80# services. Reachability of SIDs is ensured by proper configuration of the IPv6 81# operator's network and SRv6 routers. 82# 83# SRv6 Policies 84# ============= 85# 86# An SRv6 ingress router applies SRv6 policies to the traffic received from a 87# connected host. SRv6 policy enforcement consists of encapsulating the 88# received traffic into a new IPv6 packet with a given SID List contained in 89# the SRH. 90# 91# L2 VPN between hs-1 and hs-2 92# ---------------------------- 93# 94# Hosts hs-1 and hs-2 are connected using a dedicated L2 VPN. 95# Specifically, packets generated from hs-1 and directed towards hs-2 are 96# handled by rt-1 which applies the following SRv6 Policies: 97# 98# i.a) L2 traffic, SID List=fcff:2::d2 99# 100# Policy (i.a) steers tunneled L2 traffic through SRv6 router rt-2. 101# The H.L2Encaps.Red omits the presence of SRH at all, since the SID List 102# consists of only one SID (fcff:2::d2) that can be stored directly in the IPv6 103# DA. 104# 105# On the reverse path (i.e. from hs-2 to hs-1), rt-2 applies the following 106# policies: 107# 108# i.b) L2 traffic, SID List=fcff:4::e,fcff:3::e,fcff:1::d2 109# 110# Policy (i.b) steers tunneled L2 traffic through the SRv6 routers 111# rt-4,rt-3,rt2. The H.L2Encaps.Red reduces the SID List in the SRH by removing 112# the first SID (fcff:4::e) and pushing it into the IPv6 DA. 113# 114# In summary: 115# hs-1->hs-2 |IPv6 DA=fcff:2::d2|eth|...| (i.a) 116# hs-2->hs-1 |IPv6 DA=fcff:4::e|SRH SIDs=fcff:3::e,fcff:1::d2|eth|...| (i.b) 117# 118 119source lib.sh 120 121readonly DUMMY_DEVNAME="dum0" 122readonly RT2HS_DEVNAME="veth-hs" 123readonly HS_VETH_NAME="veth0" 124readonly LOCALSID_TABLE_ID=90 125readonly IPv6_RT_NETWORK=fcf0:0 126readonly IPv6_HS_NETWORK=cafe 127readonly IPv4_HS_NETWORK=10.0.0 128readonly VPN_LOCATOR_SERVICE=fcff 129readonly MAC_PREFIX=00:00:00:c0:01 130readonly END_FUNC=000e 131readonly DX2_FUNC=00d2 132 133PING_TIMEOUT_SEC=4 134PAUSE_ON_FAIL=${PAUSE_ON_FAIL:=no} 135 136# IDs of routers and hosts are initialized during the setup of the testing 137# network 138ROUTERS='' 139HOSTS='' 140 141SETUP_ERR=1 142 143ret=${ksft_skip} 144nsuccess=0 145nfail=0 146 147log_test() 148{ 149 log_test_expected "$1" "$2" "$3" 150} 151 152print_log_test_results() 153{ 154 printf "\nTests passed: %3d\n" "${nsuccess}" 155 printf "Tests failed: %3d\n" "${nfail}" 156 157 # when a test fails, the value of 'ret' is set to 1 (error code). 158 # Conversely, when all tests are passed successfully, the 'ret' value 159 # is set to 0 (success code). 160 if [ "${ret}" -ne 1 ]; then 161 ret=0 162 fi 163} 164 165log_section() 166{ 167 echo 168 echo "################################################################################" 169 echo "TEST SECTION: $*" 170 echo "################################################################################" 171} 172 173test_command_or_ksft_skip() 174{ 175 local cmd="$1" 176 177 if [ ! -x "$(command -v "${cmd}")" ]; then 178 echo "SKIP: Could not run test without \"${cmd}\" tool"; 179 exit "${ksft_skip}" 180 fi 181} 182 183get_rtname() 184{ 185 local rtid="$1" 186 187 echo "rt_${rtid}" 188} 189 190get_hsname() 191{ 192 local hsid="$1" 193 194 echo "hs_${hsid}" 195} 196 197create_router() 198{ 199 local rtid="$1" 200 local nsname 201 202 nsname="$(get_rtname "${rtid}")" 203 setup_ns "${nsname}" 204} 205 206create_host() 207{ 208 local hsid="$1" 209 local nsname 210 211 nsname="$(get_hsname "${hsid}")" 212 setup_ns "${nsname}" 213} 214 215cleanup() 216{ 217 cleanup_all_ns 218 219 # check whether the setup phase was completed successfully or not. In 220 # case of an error during the setup phase of the testing environment, 221 # the selftest is considered as "skipped". 222 if [ "${SETUP_ERR}" -ne 0 ]; then 223 echo "SKIP: Setting up the testing environment failed" 224 exit "${ksft_skip}" 225 fi 226 227 exit "${ret}" 228} 229 230add_link_rt_pairs() 231{ 232 local rt="$1" 233 local rt_neighs="$2" 234 local neigh 235 local nsname 236 local neigh_nsname 237 238 eval nsname=\${$(get_rtname "${rt}")} 239 240 for neigh in ${rt_neighs}; do 241 eval neigh_nsname=\${$(get_rtname "${neigh}")} 242 243 ip link add "veth-rt-${rt}-${neigh}" netns "${nsname}" \ 244 type veth peer name "veth-rt-${neigh}-${rt}" \ 245 netns "${neigh_nsname}" 246 done 247} 248 249get_network_prefix() 250{ 251 local rt="$1" 252 local neigh="$2" 253 local p="${rt}" 254 local q="${neigh}" 255 256 if [ "${p}" -gt "${q}" ]; then 257 p="${q}"; q="${rt}" 258 fi 259 260 echo "${IPv6_RT_NETWORK}:${p}:${q}" 261} 262 263# Setup the basic networking for the routers 264setup_rt_networking() 265{ 266 local rt="$1" 267 local rt_neighs="$2" 268 local nsname 269 local net_prefix 270 local devname 271 local neigh 272 273 eval nsname=\${$(get_rtname "${rt}")} 274 275 for neigh in ${rt_neighs}; do 276 devname="veth-rt-${rt}-${neigh}" 277 278 net_prefix="$(get_network_prefix "${rt}" "${neigh}")" 279 280 ip -netns "${nsname}" addr \ 281 add "${net_prefix}::${rt}/64" dev "${devname}" nodad 282 283 ip -netns "${nsname}" link set "${devname}" up 284 done 285 286 ip -netns "${nsname}" link add "${DUMMY_DEVNAME}" type dummy 287 288 ip -netns "${nsname}" link set "${DUMMY_DEVNAME}" up 289 ip -netns "${nsname}" link set lo up 290 291 ip netns exec "${nsname}" sysctl -wq net.ipv6.conf.all.accept_dad=0 292 ip netns exec "${nsname}" sysctl -wq net.ipv6.conf.default.accept_dad=0 293 ip netns exec "${nsname}" sysctl -wq net.ipv6.conf.all.forwarding=1 294 ip netns exec "${nsname}" sysctl -wq net.ipv4.ip_forward=1 295} 296 297# Setup local SIDs for an SRv6 router 298setup_rt_local_sids() 299{ 300 local rt="$1" 301 local rt_neighs="$2" 302 local net_prefix 303 local devname 304 local nsname 305 local neigh 306 307 eval nsname=\${$(get_rtname "${rt}")} 308 309 for neigh in ${rt_neighs}; do 310 devname="veth-rt-${rt}-${neigh}" 311 312 net_prefix="$(get_network_prefix "${rt}" "${neigh}")" 313 314 # set underlay network routes for SIDs reachability 315 ip -netns "${nsname}" -6 route \ 316 add "${VPN_LOCATOR_SERVICE}:${neigh}::/32" \ 317 table "${LOCALSID_TABLE_ID}" \ 318 via "${net_prefix}::${neigh}" dev "${devname}" 319 done 320 321 # Local End behavior (note that dev "${DUMMY_DEVNAME}" is a dummy 322 # interface) 323 ip -netns "${nsname}" -6 route \ 324 add "${VPN_LOCATOR_SERVICE}:${rt}::${END_FUNC}" \ 325 table "${LOCALSID_TABLE_ID}" \ 326 encap seg6local action End dev "${DUMMY_DEVNAME}" 327 328 # all SIDs for VPNs start with a common locator. Routes and SRv6 329 # Endpoint behaviors instances are grouped together in the 'localsid' 330 # table. 331 ip -netns "${nsname}" -6 rule add \ 332 to "${VPN_LOCATOR_SERVICE}::/16" \ 333 lookup "${LOCALSID_TABLE_ID}" prio 999 334} 335 336# build and install the SRv6 policy into the ingress SRv6 router. 337# args: 338# $1 - destination host (i.e. cafe::x host) 339# $2 - SRv6 router configured for enforcing the SRv6 Policy 340# $3 - SRv6 routers configured for steering traffic (End behaviors) 341# $4 - SRv6 router configured for removing the SRv6 Policy (router connected 342# to the destination host) 343# $5 - encap mode (full or red) 344# $6 - traffic type (IPv6 or IPv4) 345__setup_rt_policy() 346{ 347 local dst="$1" 348 local encap_rt="$2" 349 local end_rts="$3" 350 local dec_rt="$4" 351 local mode="$5" 352 local traffic="$6" 353 local nsname 354 local policy='' 355 local n 356 357 eval nsname=\${$(get_rtname "${encap_rt}")} 358 359 for n in ${end_rts}; do 360 policy="${policy}${VPN_LOCATOR_SERVICE}:${n}::${END_FUNC}," 361 done 362 363 policy="${policy}${VPN_LOCATOR_SERVICE}:${dec_rt}::${DX2_FUNC}" 364 365 # add SRv6 policy to incoming traffic sent by connected hosts 366 if [ "${traffic}" -eq 6 ]; then 367 ip -netns "${nsname}" -6 route \ 368 add "${IPv6_HS_NETWORK}::${dst}" \ 369 encap seg6 mode "${mode}" segs "${policy}" \ 370 dev dum0 371 else 372 ip -netns "${nsname}" -4 route \ 373 add "${IPv4_HS_NETWORK}.${dst}" \ 374 encap seg6 mode "${mode}" segs "${policy}" \ 375 dev dum0 376 fi 377} 378 379# see __setup_rt_policy 380setup_rt_policy_ipv6() 381{ 382 __setup_rt_policy "$1" "$2" "$3" "$4" "$5" 6 383} 384 385#see __setup_rt_policy 386setup_rt_policy_ipv4() 387{ 388 __setup_rt_policy "$1" "$2" "$3" "$4" "$5" 4 389} 390 391setup_decap() 392{ 393 local rt="$1" 394 local nsname 395 396 eval nsname=\${$(get_rtname "${rt}")} 397 398 # Local End.DX2 behavior 399 ip -netns "${nsname}" -6 route \ 400 add "${VPN_LOCATOR_SERVICE}:${rt}::${DX2_FUNC}" \ 401 table "${LOCALSID_TABLE_ID}" \ 402 encap seg6local action End.DX2 oif "${RT2HS_DEVNAME}" \ 403 dev "${RT2HS_DEVNAME}" 404} 405 406setup_hs() 407{ 408 local hs="$1" 409 local rt="$2" 410 local hsname 411 local rtname 412 413 eval hsname=\${$(get_hsname "${hs}")} 414 eval rtname=\${$(get_rtname "${rt}")} 415 416 ip netns exec "${hsname}" sysctl -wq net.ipv6.conf.all.accept_dad=0 417 ip netns exec "${hsname}" sysctl -wq net.ipv6.conf.default.accept_dad=0 418 419 ip -netns "${hsname}" link add "${HS_VETH_NAME}" type veth \ 420 peer name "${RT2HS_DEVNAME}" netns "${rtname}" 421 422 ip -netns "${hsname}" addr add "${IPv6_HS_NETWORK}::${hs}/64" \ 423 dev "${HS_VETH_NAME}" nodad 424 ip -netns "${hsname}" addr add "${IPv4_HS_NETWORK}.${hs}/24" \ 425 dev "${HS_VETH_NAME}" 426 427 ip -netns "${hsname}" link set "${HS_VETH_NAME}" up 428 ip -netns "${hsname}" link set lo up 429 430 ip -netns "${rtname}" addr add "${IPv6_HS_NETWORK}::254/64" \ 431 dev "${RT2HS_DEVNAME}" nodad 432 ip -netns "${rtname}" addr \ 433 add "${IPv4_HS_NETWORK}.254/24" dev "${RT2HS_DEVNAME}" 434 435 ip -netns "${rtname}" link set "${RT2HS_DEVNAME}" up 436} 437 438# set an auto-generated mac address 439# args: 440# $1 - name of the node (e.g.: hs-1, rt-3, etc) 441# $2 - id of the node (e.g.: 1 for hs-1, 3 for rt-3, etc) 442# $3 - host part of the IPv6 network address 443# $4 - name of the network interface to which the generated mac address must 444# be set. 445set_mac_address() 446{ 447 local nodename="$1" 448 local nodeid="$2" 449 local host="$3" 450 local ifname="$4" 451 local nsname 452 453 eval nsname=\${${nodename}} 454 455 ip -netns "${nsname}" link set dev "${ifname}" down 456 457 ip -netns "${nsname}" link set address "${MAC_PREFIX}:${nodeid}" \ 458 dev "${ifname}" 459 460 # the IPv6 address must be set once again after the MAC address has 461 # been changed. 462 ip -netns "${nsname}" addr add "${IPv6_HS_NETWORK}::${host}/64" \ 463 dev "${ifname}" nodad 464 465 ip -netns "${nsname}" link set dev "${ifname}" up 466} 467 468set_host_l2peer() 469{ 470 local hssrc="$1" 471 local hsdst="$2" 472 local ipprefix="$3" 473 local proto="$4" 474 local hssrc_name 475 local ipaddr 476 477 eval hssrc_name=\${$(get_hsname "${hssrc}")} 478 479 if [ "${proto}" -eq 6 ]; then 480 ipaddr="${ipprefix}::${hsdst}" 481 else 482 ipaddr="${ipprefix}.${hsdst}" 483 fi 484 485 ip -netns "${hssrc_name}" route add "${ipaddr}" dev "${HS_VETH_NAME}" 486 487 ip -netns "${hssrc_name}" neigh \ 488 add "${ipaddr}" lladdr "${MAC_PREFIX}:${hsdst}" \ 489 dev "${HS_VETH_NAME}" 490} 491 492# setup an SRv6 L2 VPN between host hs-x and hs-y (currently, the SRv6 493# subsystem only supports L2 frames whose layer-3 is IPv4/IPv6). 494# args: 495# $1 - source host 496# $2 - SRv6 routers configured for steering tunneled traffic 497# $3 - destination host 498setup_l2vpn() 499{ 500 local hssrc="$1" 501 local end_rts="$2" 502 local hsdst="$3" 503 local rtsrc="${hssrc}" 504 local rtdst="${hsdst}" 505 506 # set fixed mac for source node and the neigh MAC address 507 set_mac_address "hs_${hssrc}" "${hssrc}" "${hssrc}" "${HS_VETH_NAME}" 508 set_host_l2peer "${hssrc}" "${hsdst}" "${IPv6_HS_NETWORK}" 6 509 set_host_l2peer "${hssrc}" "${hsdst}" "${IPv4_HS_NETWORK}" 4 510 511 # we have to set the mac address of the veth-host (on ingress router) 512 # to the mac address of the remote peer (L2 VPN destination host). 513 # Otherwise, traffic coming from the source host is dropped at the 514 # ingress router. 515 set_mac_address "rt_${rtsrc}" "${hsdst}" 254 "${RT2HS_DEVNAME}" 516 517 # set the SRv6 Policies at the ingress router 518 setup_rt_policy_ipv6 "${hsdst}" "${rtsrc}" "${end_rts}" "${rtdst}" \ 519 l2encap.red 6 520 setup_rt_policy_ipv4 "${hsdst}" "${rtsrc}" "${end_rts}" "${rtdst}" \ 521 l2encap.red 4 522 523 # set the decap behavior 524 setup_decap "${rtsrc}" 525} 526 527setup() 528{ 529 local i 530 531 # create routers 532 ROUTERS="1 2 3 4"; readonly ROUTERS 533 for i in ${ROUTERS}; do 534 create_router "${i}" 535 done 536 537 # create hosts 538 HOSTS="1 2"; readonly HOSTS 539 for i in ${HOSTS}; do 540 create_host "${i}" 541 done 542 543 # set up the links for connecting routers 544 add_link_rt_pairs 1 "2 3 4" 545 add_link_rt_pairs 2 "3 4" 546 add_link_rt_pairs 3 "4" 547 548 # set up the basic connectivity of routers and routes required for 549 # reachability of SIDs. 550 setup_rt_networking 1 "2 3 4" 551 setup_rt_networking 2 "1 3 4" 552 setup_rt_networking 3 "1 2 4" 553 setup_rt_networking 4 "1 2 3" 554 555 # set up the hosts connected to routers 556 setup_hs 1 1 557 setup_hs 2 2 558 559 # set up default SRv6 Endpoints (i.e. SRv6 End and SRv6 End.DX2) 560 setup_rt_local_sids 1 "2 3 4" 561 setup_rt_local_sids 2 "1 3 4" 562 setup_rt_local_sids 3 "1 2 4" 563 setup_rt_local_sids 4 "1 2 3" 564 565 # create a L2 VPN between hs-1 and hs-2. 566 # NB: currently, H.L2Encap* enables tunneling of L2 frames whose 567 # layer-3 is IPv4/IPv6. 568 # 569 # the network path between hs-1 and hs-2 traverses several routers 570 # depending on the direction of traffic. 571 # 572 # Direction hs-1 -> hs-2 (H.L2Encaps.Red) 573 # - rt-2 (SRv6 End.DX2 behavior) 574 # 575 # Direction hs-2 -> hs-1 (H.L2Encaps.Red) 576 # - rt-4,rt-3 (SRv6 End behaviors) 577 # - rt-1 (SRv6 End.DX2 behavior) 578 setup_l2vpn 1 "" 2 579 setup_l2vpn 2 "4 3" 1 580 581 # testing environment was set up successfully 582 SETUP_ERR=0 583} 584 585check_rt_connectivity() 586{ 587 local rtsrc="$1" 588 local rtdst="$2" 589 local prefix 590 local rtsrc_nsname 591 592 eval rtsrc_nsname=\${$(get_rtname "${rtsrc}")} 593 594 prefix="$(get_network_prefix "${rtsrc}" "${rtdst}")" 595 596 ip netns exec "${rtsrc_nsname}" ping -c 1 -W "${PING_TIMEOUT_SEC}" \ 597 "${prefix}::${rtdst}" >/dev/null 2>&1 598} 599 600check_and_log_rt_connectivity() 601{ 602 local rtsrc="$1" 603 local rtdst="$2" 604 605 check_rt_connectivity "${rtsrc}" "${rtdst}" 606 log_test $? 0 "Routers connectivity: rt-${rtsrc} -> rt-${rtdst}" 607} 608 609check_hs_ipv6_connectivity() 610{ 611 local hssrc="$1" 612 local hsdst="$2" 613 local hssrc_nsname 614 615 eval hssrc_nsname=\${$(get_hsname "${hssrc}")} 616 617 ip netns exec "${hssrc_nsname}" ping -c 1 -W "${PING_TIMEOUT_SEC}" \ 618 "${IPv6_HS_NETWORK}::${hsdst}" >/dev/null 2>&1 619} 620 621check_hs_ipv4_connectivity() 622{ 623 local hssrc="$1" 624 local hsdst="$2" 625 local hssrc_nsname 626 627 eval hssrc_nsname=\${$(get_hsname "${hssrc}")} 628 629 ip netns exec "${hssrc_nsname}" ping -c 1 -W "${PING_TIMEOUT_SEC}" \ 630 "${IPv4_HS_NETWORK}.${hsdst}" >/dev/null 2>&1 631} 632 633check_and_log_hs2gw_connectivity() 634{ 635 local hssrc="$1" 636 637 check_hs_ipv6_connectivity "${hssrc}" 254 638 log_test $? 0 "IPv6 Hosts connectivity: hs-${hssrc} -> gw" 639 640 check_hs_ipv4_connectivity "${hssrc}" 254 641 log_test $? 0 "IPv4 Hosts connectivity: hs-${hssrc} -> gw" 642} 643 644check_and_log_hs_ipv6_connectivity() 645{ 646 local hssrc="$1" 647 local hsdst="$2" 648 649 check_hs_ipv6_connectivity "${hssrc}" "${hsdst}" 650 log_test $? 0 "IPv6 Hosts connectivity: hs-${hssrc} -> hs-${hsdst}" 651} 652 653check_and_log_hs_ipv4_connectivity() 654{ 655 local hssrc="$1" 656 local hsdst="$2" 657 658 check_hs_ipv4_connectivity "${hssrc}" "${hsdst}" 659 log_test $? 0 "IPv4 Hosts connectivity: hs-${hssrc} -> hs-${hsdst}" 660} 661 662check_and_log_hs_connectivity() 663{ 664 local hssrc="$1" 665 local hsdst="$2" 666 667 check_and_log_hs_ipv4_connectivity "${hssrc}" "${hsdst}" 668 check_and_log_hs_ipv6_connectivity "${hssrc}" "${hsdst}" 669} 670 671router_tests() 672{ 673 local i 674 local j 675 676 log_section "IPv6 routers connectivity test" 677 678 for i in ${ROUTERS}; do 679 for j in ${ROUTERS}; do 680 if [ "${i}" -eq "${j}" ]; then 681 continue 682 fi 683 684 check_and_log_rt_connectivity "${i}" "${j}" 685 done 686 done 687} 688 689host2gateway_tests() 690{ 691 local hs 692 693 log_section "IPv4/IPv6 connectivity test among hosts and gateways" 694 695 for hs in ${HOSTS}; do 696 check_and_log_hs2gw_connectivity "${hs}" 697 done 698} 699 700host_vpn_tests() 701{ 702 log_section "SRv6 L2 VPN connectivity test hosts (h1 <-> h2)" 703 704 check_and_log_hs_connectivity 1 2 705 check_and_log_hs_connectivity 2 1 706} 707 708test_dummy_dev_or_ksft_skip() 709{ 710 local test_netns 711 712 test_netns="dummy-$(mktemp -u XXXXXXXX)" 713 714 if ! ip netns add "${test_netns}"; then 715 echo "SKIP: Cannot set up netns for testing dummy dev support" 716 exit "${ksft_skip}" 717 fi 718 719 modprobe dummy &>/dev/null || true 720 if ! ip -netns "${test_netns}" link \ 721 add "${DUMMY_DEVNAME}" type dummy; then 722 echo "SKIP: dummy dev not supported" 723 724 ip netns del "${test_netns}" 725 exit "${ksft_skip}" 726 fi 727 728 ip netns del "${test_netns}" 729} 730 731test_iproute2_supp_or_ksft_skip() 732{ 733 if ! ip route help 2>&1 | grep -qo "l2encap.red"; then 734 echo "SKIP: Missing SRv6 l2encap.red support in iproute2" 735 exit "${ksft_skip}" 736 fi 737} 738 739if [ "$(id -u)" -ne 0 ]; then 740 echo "SKIP: Need root privileges" 741 exit "${ksft_skip}" 742fi 743 744# required programs to carry out this selftest 745test_command_or_ksft_skip ip 746test_command_or_ksft_skip ping 747test_command_or_ksft_skip sysctl 748test_command_or_ksft_skip grep 749 750test_iproute2_supp_or_ksft_skip 751test_dummy_dev_or_ksft_skip 752 753set -e 754trap cleanup EXIT 755 756setup 757set +e 758 759router_tests 760host2gateway_tests 761host_vpn_tests 762 763print_log_test_results 764