1#!/bin/bash 2# SPDX-License-Identifier: GPL-2.0 3# 4# Check that route PMTU values match expectations, and that initial device MTU 5# values are assigned correctly 6# 7# Tests currently implemented: 8# 9# - pmtu_ipv4 10# Set up two namespaces, A and B, with two paths between them over routers 11# R1 and R2 (also implemented with namespaces), with different MTUs: 12# 13# segment a_r1 segment b_r1 a_r1: 2000 14# .--------------R1--------------. b_r1: 1400 15# A B a_r2: 2000 16# '--------------R2--------------' b_r2: 1500 17# segment a_r2 segment b_r2 18# 19# Check that PMTU exceptions with the correct PMTU are created. Then 20# decrease and increase the MTU of the local link for one of the paths, 21# A to R1, checking that route exception PMTU changes accordingly over 22# this path. Also check that locked exceptions are created when an ICMP 23# message advertising a PMTU smaller than net.ipv4.route.min_pmtu is 24# received 25# 26# - pmtu_ipv6 27# Same as pmtu_ipv4, except for locked PMTU tests, using IPv6 28# 29# - pmtu_ipv4_dscp_icmp_exception 30# Set up the same network topology as pmtu_ipv4, but use non-default 31# routing table in A. A fib-rule is used to jump to this routing table 32# based on DSCP. Send ICMPv4 packets with the expected DSCP value and 33# verify that ECN doesn't interfere with the creation of PMTU exceptions. 34# 35# - pmtu_ipv4_dscp_udp_exception 36# Same as pmtu_ipv4_dscp_icmp_exception, but use UDP instead of ICMP. 37# 38# - pmtu_ipv4_vxlan4_exception 39# Set up the same network topology as pmtu_ipv4, create a VXLAN tunnel 40# over IPv4 between A and B, routed via R1. On the link between R1 and B, 41# set a MTU lower than the VXLAN MTU and the MTU on the link between A and 42# R1. Send IPv4 packets, exceeding the MTU between R1 and B, over VXLAN 43# from A to B and check that the PMTU exception is created with the right 44# value on A 45# 46# - pmtu_ipv6_vxlan4_exception 47# Same as pmtu_ipv4_vxlan4_exception, but send IPv6 packets from A to B 48# 49# - pmtu_ipv4_vxlan6_exception 50# Same as pmtu_ipv4_vxlan4_exception, but use IPv6 transport from A to B 51# 52# - pmtu_ipv6_vxlan6_exception 53# Same as pmtu_ipv4_vxlan6_exception, but send IPv6 packets from A to B 54# 55# - pmtu_ipv4_geneve4_exception 56# Same as pmtu_ipv4_vxlan4_exception, but using a GENEVE tunnel instead of 57# VXLAN 58# 59# - pmtu_ipv6_geneve4_exception 60# Same as pmtu_ipv6_vxlan4_exception, but using a GENEVE tunnel instead of 61# VXLAN 62# 63# - pmtu_ipv4_geneve6_exception 64# Same as pmtu_ipv4_vxlan6_exception, but using a GENEVE tunnel instead of 65# VXLAN 66# 67# - pmtu_ipv6_geneve6_exception 68# Same as pmtu_ipv6_vxlan6_exception, but using a GENEVE tunnel instead of 69# VXLAN 70# 71# - pmtu_ipv{4,6}_br_vxlan{4,6}_exception 72# Set up three namespaces, A, B, and C, with routing between A and B over 73# R1. R2 is unused in these tests. A has a veth connection to C, and is 74# connected to B via a VXLAN endpoint, which is directly bridged to C. 75# MTU on the B-R1 link is lower than other MTUs. 76# 77# Check that both C and A are able to communicate with B over the VXLAN 78# tunnel, and that PMTU exceptions with the correct values are created. 79# 80# segment a_r1 segment b_r1 b_r1: 4000 81# .--------------R1--------------. everything 82# C---veth A B else: 5000 83# ' bridge | 84# '---- - - - - - VXLAN - - - - - - - ' 85# 86# - pmtu_ipv{4,6}_br_geneve{4,6}_exception 87# Same as pmtu_ipv{4,6}_br_vxlan{4,6}_exception, with a GENEVE tunnel 88# instead. 89# 90# - pmtu_ipv{4,6}_ovs_vxlan{4,6}_exception 91# Set up two namespaces, B, and C, with routing between the init namespace 92# and B over R1. A and R2 are unused in these tests. The init namespace 93# has a veth connection to C, and is connected to B via a VXLAN endpoint, 94# which is handled by Open vSwitch and bridged to C. MTU on the B-R1 link 95# is lower than other MTUs. 96# 97# Check that C is able to communicate with B over the VXLAN tunnel, and 98# that PMTU exceptions with the correct values are created. 99# 100# segment a_r1 segment b_r1 b_r1: 4000 101# .--------------R1--------------. everything 102# C---veth init B else: 5000 103# '- ovs | 104# '---- - - - - - VXLAN - - - - - - - ' 105# 106# - pmtu_ipv{4,6}_ovs_geneve{4,6}_exception 107# Same as pmtu_ipv{4,6}_ovs_vxlan{4,6}_exception, with a GENEVE tunnel 108# instead. 109# 110# - pmtu_ipv{4,6}_fou{4,6}_exception 111# Same as pmtu_ipv4_vxlan4, but using a direct IPv4/IPv6 encapsulation 112# (FoU) over IPv4/IPv6, instead of VXLAN 113# 114# - pmtu_ipv{4,6}_fou{4,6}_exception 115# Same as pmtu_ipv4_vxlan4, but using a generic UDP IPv4/IPv6 116# encapsulation (GUE) over IPv4/IPv6, instead of VXLAN 117# 118# - pmtu_ipv{4,6}_ipv{4,6}_exception 119# Same as pmtu_ipv4_vxlan4, but using a IPv4/IPv6 tunnel over IPv4/IPv6, 120# instead of VXLAN 121# 122# - pmtu_vti4_exception 123# Set up vti tunnel on top of veth, with xfrm states and policies, in two 124# namespaces with matching endpoints. Check that route exception is not 125# created if link layer MTU is not exceeded, then exceed it and check that 126# exception is created with the expected PMTU. The approach described 127# below for IPv6 doesn't apply here, because, on IPv4, administrative MTU 128# changes alone won't affect PMTU 129# 130# - pmtu_vti4_udp_exception 131# Same as pmtu_vti4_exception, but using ESP-in-UDP 132# 133# - pmtu_vti4_udp_routed_exception 134# Set up vti tunnel on top of veth connected through routing namespace and 135# add xfrm states and policies with ESP-in-UDP encapsulation. Check that 136# route exception is not created if link layer MTU is not exceeded, then 137# lower MTU on second part of routed environment and check that exception 138# is created with the expected PMTU. 139# 140# - pmtu_vti6_exception 141# Set up vti6 tunnel on top of veth, with xfrm states and policies, in two 142# namespaces with matching endpoints. Check that route exception is 143# created by exceeding link layer MTU with ping to other endpoint. Then 144# decrease and increase MTU of tunnel, checking that route exception PMTU 145# changes accordingly 146# 147# - pmtu_vti6_udp_exception 148# Same as pmtu_vti6_exception, but using ESP-in-UDP 149# 150# - pmtu_vti6_udp_routed_exception 151# Same as pmtu_vti6_udp_routed_exception but with routing between vti 152# endpoints 153# 154# - pmtu_vti4_default_mtu 155# Set up vti4 tunnel on top of veth, in two namespaces with matching 156# endpoints. Check that MTU assigned to vti interface is the MTU of the 157# lower layer (veth) minus additional lower layer headers (zero, for veth) 158# minus IPv4 header length 159# 160# - pmtu_vti6_default_mtu 161# Same as above, for IPv6 162# 163# - pmtu_vti4_link_add_mtu 164# Set up vti4 interface passing MTU value at link creation, check MTU is 165# configured, and that link is not created with invalid MTU values 166# 167# - pmtu_vti6_link_add_mtu 168# Same as above, for IPv6 169# 170# - pmtu_vti6_link_change_mtu 171# Set up two dummy interfaces with different MTUs, create a vti6 tunnel 172# and check that configured MTU is used on link creation and changes, and 173# that MTU is properly calculated instead when MTU is not configured from 174# userspace 175# 176# - cleanup_ipv4_exception 177# Similar to pmtu_ipv4_vxlan4_exception, but explicitly generate PMTU 178# exceptions on multiple CPUs and check that the veth device tear-down 179# happens in a timely manner 180# 181# - cleanup_ipv6_exception 182# Same as above, but use IPv6 transport from A to B 183# 184# - list_flush_ipv4_exception 185# Using the same topology as in pmtu_ipv4, create exceptions, and check 186# they are shown when listing exception caches, gone after flushing them 187# 188# - list_flush_ipv6_exception 189# Using the same topology as in pmtu_ipv6, create exceptions, and check 190# they are shown when listing exception caches, gone after flushing them 191# 192# - pmtu_ipv4_route_change 193# Use the same topology as in pmtu_ipv4, but issue a route replacement 194# command and delete the corresponding device afterward. This tests for 195# proper cleanup of the PMTU exceptions by the route replacement path. 196# Device unregistration should complete successfully 197# 198# - pmtu_ipv6_route_change 199# Same as above but with IPv6 200# 201# - pmtu_ipv4_mp_exceptions 202# Use the same topology as in pmtu_ipv4, but add routeable addresses 203# on host A and B on lo reachable via both routers. Host A and B 204# addresses have multipath routes to each other, b_r1 mtu = 1500. 205# Check that PMTU exceptions are created for both paths. 206 207source lib.sh 208source net_helper.sh 209 210PAUSE_ON_FAIL=no 211VERBOSE=0 212TRACING=0 213 214# Some systems don't have a ping6 binary anymore 215which ping6 > /dev/null 2>&1 && ping6=$(which ping6) || ping6=$(which ping) 216 217# Name Description re-run with nh 218tests=" 219 pmtu_ipv4_exception ipv4: PMTU exceptions 1 220 pmtu_ipv6_exception ipv6: PMTU exceptions 1 221 pmtu_ipv4_dscp_icmp_exception ICMPv4 with DSCP and ECN: PMTU exceptions 1 222 pmtu_ipv4_dscp_udp_exception UDPv4 with DSCP and ECN: PMTU exceptions 1 223 pmtu_ipv4_vxlan4_exception IPv4 over vxlan4: PMTU exceptions 1 224 pmtu_ipv6_vxlan4_exception IPv6 over vxlan4: PMTU exceptions 1 225 pmtu_ipv4_vxlan6_exception IPv4 over vxlan6: PMTU exceptions 1 226 pmtu_ipv6_vxlan6_exception IPv6 over vxlan6: PMTU exceptions 1 227 pmtu_ipv4_geneve4_exception IPv4 over geneve4: PMTU exceptions 1 228 pmtu_ipv6_geneve4_exception IPv6 over geneve4: PMTU exceptions 1 229 pmtu_ipv4_geneve6_exception IPv4 over geneve6: PMTU exceptions 1 230 pmtu_ipv6_geneve6_exception IPv6 over geneve6: PMTU exceptions 1 231 pmtu_ipv4_br_vxlan4_exception IPv4, bridged vxlan4: PMTU exceptions 1 232 pmtu_ipv6_br_vxlan4_exception IPv6, bridged vxlan4: PMTU exceptions 1 233 pmtu_ipv4_br_vxlan6_exception IPv4, bridged vxlan6: PMTU exceptions 1 234 pmtu_ipv6_br_vxlan6_exception IPv6, bridged vxlan6: PMTU exceptions 1 235 pmtu_ipv4_br_geneve4_exception IPv4, bridged geneve4: PMTU exceptions 1 236 pmtu_ipv6_br_geneve4_exception IPv6, bridged geneve4: PMTU exceptions 1 237 pmtu_ipv4_br_geneve6_exception IPv4, bridged geneve6: PMTU exceptions 1 238 pmtu_ipv6_br_geneve6_exception IPv6, bridged geneve6: PMTU exceptions 1 239 pmtu_ipv4_ovs_vxlan4_exception IPv4, OVS vxlan4: PMTU exceptions 1 240 pmtu_ipv6_ovs_vxlan4_exception IPv6, OVS vxlan4: PMTU exceptions 1 241 pmtu_ipv4_ovs_vxlan6_exception IPv4, OVS vxlan6: PMTU exceptions 1 242 pmtu_ipv6_ovs_vxlan6_exception IPv6, OVS vxlan6: PMTU exceptions 1 243 pmtu_ipv4_ovs_geneve4_exception IPv4, OVS geneve4: PMTU exceptions 1 244 pmtu_ipv6_ovs_geneve4_exception IPv6, OVS geneve4: PMTU exceptions 1 245 pmtu_ipv4_ovs_geneve6_exception IPv4, OVS geneve6: PMTU exceptions 1 246 pmtu_ipv6_ovs_geneve6_exception IPv6, OVS geneve6: PMTU exceptions 1 247 pmtu_ipv4_fou4_exception IPv4 over fou4: PMTU exceptions 1 248 pmtu_ipv6_fou4_exception IPv6 over fou4: PMTU exceptions 1 249 pmtu_ipv4_fou6_exception IPv4 over fou6: PMTU exceptions 1 250 pmtu_ipv6_fou6_exception IPv6 over fou6: PMTU exceptions 1 251 pmtu_ipv4_gue4_exception IPv4 over gue4: PMTU exceptions 1 252 pmtu_ipv6_gue4_exception IPv6 over gue4: PMTU exceptions 1 253 pmtu_ipv4_gue6_exception IPv4 over gue6: PMTU exceptions 1 254 pmtu_ipv6_gue6_exception IPv6 over gue6: PMTU exceptions 1 255 pmtu_ipv4_ipv4_exception IPv4 over IPv4: PMTU exceptions 1 256 pmtu_ipv6_ipv4_exception IPv6 over IPv4: PMTU exceptions 1 257 pmtu_ipv4_ipv6_exception IPv4 over IPv6: PMTU exceptions 1 258 pmtu_ipv6_ipv6_exception IPv6 over IPv6: PMTU exceptions 1 259 pmtu_vti6_exception vti6: PMTU exceptions 0 260 pmtu_vti4_exception vti4: PMTU exceptions 0 261 pmtu_vti6_udp_exception vti6: PMTU exceptions (ESP-in-UDP) 0 262 pmtu_vti4_udp_exception vti4: PMTU exceptions (ESP-in-UDP) 0 263 pmtu_vti6_udp_routed_exception vti6: PMTU exceptions, routed (ESP-in-UDP) 0 264 pmtu_vti4_udp_routed_exception vti4: PMTU exceptions, routed (ESP-in-UDP) 0 265 pmtu_vti4_default_mtu vti4: default MTU assignment 0 266 pmtu_vti6_default_mtu vti6: default MTU assignment 0 267 pmtu_vti4_link_add_mtu vti4: MTU setting on link creation 0 268 pmtu_vti6_link_add_mtu vti6: MTU setting on link creation 0 269 pmtu_vti6_link_change_mtu vti6: MTU changes on link changes 0 270 cleanup_ipv4_exception ipv4: cleanup of cached exceptions 1 271 cleanup_ipv6_exception ipv6: cleanup of cached exceptions 1 272 list_flush_ipv4_exception ipv4: list and flush cached exceptions 1 273 list_flush_ipv6_exception ipv6: list and flush cached exceptions 1 274 pmtu_ipv4_route_change ipv4: PMTU exception w/route replace 1 275 pmtu_ipv6_route_change ipv6: PMTU exception w/route replace 1 276 pmtu_ipv4_mp_exceptions ipv4: PMTU multipath nh exceptions 1" 277 278# Addressing and routing for tests with routers: four network segments, with 279# index SEGMENT between 1 and 4, a common prefix (PREFIX4 or PREFIX6) and an 280# identifier ID, which is 1 for hosts (A and B), 2 for routers (R1 and R2). 281# Addresses are: 282# - IPv4: PREFIX4.SEGMENT.ID (/24) 283# - IPv6: PREFIX6:SEGMENT::ID (/64) 284prefix4="10.0" 285prefix6="fc00" 286a_r1=1 287a_r2=2 288b_r1=3 289b_r2=4 290# ns peer segment 291routing_addrs=" 292 A R1 ${a_r1} 293 A R2 ${a_r2} 294 B R1 ${b_r1} 295 B R2 ${b_r2} 296" 297# Traffic from A to B goes through R1 by default, and through R2, if destined to 298# B's address on the b_r2 segment. 299# Traffic from B to A goes through R1. 300# ns destination gateway 301routes=" 302 A default ${prefix4}.${a_r1}.2 303 A ${prefix4}.${b_r2}.1 ${prefix4}.${a_r2}.2 304 B default ${prefix4}.${b_r1}.2 305 306 A default ${prefix6}:${a_r1}::2 307 A ${prefix6}:${b_r2}::1 ${prefix6}:${a_r2}::2 308 B default ${prefix6}:${b_r1}::2 309" 310USE_NH="no" 311# ns family nh id destination gateway 312nexthops=" 313 A 4 41 ${prefix4}.${a_r1}.2 veth_A-R1 314 A 4 42 ${prefix4}.${a_r2}.2 veth_A-R2 315 B 4 41 ${prefix4}.${b_r1}.2 veth_B-R1 316 317 A 6 61 ${prefix6}:${a_r1}::2 veth_A-R1 318 A 6 62 ${prefix6}:${a_r2}::2 veth_A-R2 319 B 6 61 ${prefix6}:${b_r1}::2 veth_B-R1 320" 321 322# nexthop id correlates to id in nexthops config above 323# ns family prefix nh id 324routes_nh=" 325 A 4 default 41 326 A 4 ${prefix4}.${b_r2}.1 42 327 B 4 default 41 328 329 A 6 default 61 330 A 6 ${prefix6}:${b_r2}::1 62 331 B 6 default 61 332" 333 334policy_mark=0x04 335rt_table=main 336 337veth4_a_addr="192.168.1.1" 338veth4_b_addr="192.168.1.2" 339veth4_c_addr="192.168.2.10" 340veth4_mask="24" 341veth6_a_addr="fd00:1::a" 342veth6_b_addr="fd00:1::b" 343veth6_c_addr="fd00:2::c" 344veth6_mask="64" 345 346tunnel4_a_addr="192.168.2.1" 347tunnel4_b_addr="192.168.2.2" 348tunnel4_mask="24" 349tunnel6_a_addr="fd00:2::a" 350tunnel6_b_addr="fd00:2::b" 351tunnel6_mask="64" 352 353host4_a_addr="192.168.99.99" 354host4_b_addr="192.168.88.88" 355 356dummy6_0_prefix="fc00:1000::" 357dummy6_1_prefix="fc00:1001::" 358dummy6_mask="64" 359 360err_buf= 361tcpdump_pids= 362nettest_pids= 363socat_pids= 364tmpoutfile= 365 366err() { 367 err_buf="${err_buf}${1} 368" 369} 370 371err_flush() { 372 echo -n "${err_buf}" 373 err_buf= 374} 375 376run_cmd() { 377 cmd="$*" 378 379 if [ "$VERBOSE" = "1" ]; then 380 printf " COMMAND: $cmd\n" 381 fi 382 383 out="$($cmd 2>&1)" 384 rc=$? 385 if [ "$VERBOSE" = "1" -a -n "$out" ]; then 386 echo " $out" 387 echo 388 fi 389 390 return $rc 391} 392 393run_cmd_bg() { 394 cmd="$*" 395 396 if [ "$VERBOSE" = "1" ]; then 397 printf " COMMAND: %s &\n" "${cmd}" 398 fi 399 400 $cmd 2>&1 & 401} 402 403# Find the auto-generated name for this namespace 404nsname() { 405 eval echo \$NS_$1 406} 407 408setup_fou_or_gue() { 409 outer="${1}" 410 inner="${2}" 411 encap="${3}" 412 413 if [ "${outer}" = "4" ]; then 414 modprobe fou || return $ksft_skip 415 a_addr="${prefix4}.${a_r1}.1" 416 b_addr="${prefix4}.${b_r1}.1" 417 if [ "${inner}" = "4" ]; then 418 type="ipip" 419 ipproto="4" 420 else 421 type="sit" 422 ipproto="41" 423 fi 424 else 425 modprobe fou6 || return $ksft_skip 426 a_addr="${prefix6}:${a_r1}::1" 427 b_addr="${prefix6}:${b_r1}::1" 428 if [ "${inner}" = "4" ]; then 429 type="ip6tnl" 430 mode="mode ipip6" 431 ipproto="4 -6" 432 else 433 type="ip6tnl" 434 mode="mode ip6ip6" 435 ipproto="41 -6" 436 fi 437 fi 438 439 run_cmd ${ns_a} ip fou add port 5555 ipproto ${ipproto} || return $ksft_skip 440 run_cmd ${ns_a} ip link add ${encap}_a type ${type} ${mode} local ${a_addr} remote ${b_addr} encap ${encap} encap-sport auto encap-dport 5556 || return $ksft_skip 441 442 run_cmd ${ns_b} ip fou add port 5556 ipproto ${ipproto} 443 run_cmd ${ns_b} ip link add ${encap}_b type ${type} ${mode} local ${b_addr} remote ${a_addr} encap ${encap} encap-sport auto encap-dport 5555 444 445 if [ "${inner}" = "4" ]; then 446 run_cmd ${ns_a} ip addr add ${tunnel4_a_addr}/${tunnel4_mask} dev ${encap}_a 447 run_cmd ${ns_b} ip addr add ${tunnel4_b_addr}/${tunnel4_mask} dev ${encap}_b 448 else 449 run_cmd ${ns_a} ip addr add ${tunnel6_a_addr}/${tunnel6_mask} dev ${encap}_a 450 run_cmd ${ns_b} ip addr add ${tunnel6_b_addr}/${tunnel6_mask} dev ${encap}_b 451 fi 452 453 run_cmd ${ns_a} ip link set ${encap}_a up 454 run_cmd ${ns_b} ip link set ${encap}_b up 455} 456 457setup_fou44() { 458 setup_fou_or_gue 4 4 fou 459} 460 461setup_fou46() { 462 setup_fou_or_gue 4 6 fou 463} 464 465setup_fou64() { 466 setup_fou_or_gue 6 4 fou 467} 468 469setup_fou66() { 470 setup_fou_or_gue 6 6 fou 471} 472 473setup_gue44() { 474 setup_fou_or_gue 4 4 gue 475} 476 477setup_gue46() { 478 setup_fou_or_gue 4 6 gue 479} 480 481setup_gue64() { 482 setup_fou_or_gue 6 4 gue 483} 484 485setup_gue66() { 486 setup_fou_or_gue 6 6 gue 487} 488 489setup_ipvX_over_ipvY() { 490 inner=${1} 491 outer=${2} 492 493 if [ "${outer}" -eq 4 ]; then 494 a_addr="${prefix4}.${a_r1}.1" 495 b_addr="${prefix4}.${b_r1}.1" 496 if [ "${inner}" -eq 4 ]; then 497 type="ipip" 498 mode="ipip" 499 else 500 type="sit" 501 mode="ip6ip" 502 fi 503 else 504 a_addr="${prefix6}:${a_r1}::1" 505 b_addr="${prefix6}:${b_r1}::1" 506 type="ip6tnl" 507 if [ "${inner}" -eq 4 ]; then 508 mode="ipip6" 509 else 510 mode="ip6ip6" 511 fi 512 fi 513 514 run_cmd ${ns_a} ip link add ip_a type ${type} local ${a_addr} remote ${b_addr} mode ${mode} || return $ksft_skip 515 run_cmd ${ns_b} ip link add ip_b type ${type} local ${b_addr} remote ${a_addr} mode ${mode} 516 517 run_cmd ${ns_a} ip link set ip_a up 518 run_cmd ${ns_b} ip link set ip_b up 519 520 if [ "${inner}" = "4" ]; then 521 run_cmd ${ns_a} ip addr add ${tunnel4_a_addr}/${tunnel4_mask} dev ip_a 522 run_cmd ${ns_b} ip addr add ${tunnel4_b_addr}/${tunnel4_mask} dev ip_b 523 else 524 run_cmd ${ns_a} ip addr add ${tunnel6_a_addr}/${tunnel6_mask} dev ip_a 525 run_cmd ${ns_b} ip addr add ${tunnel6_b_addr}/${tunnel6_mask} dev ip_b 526 fi 527} 528 529setup_ip4ip4() { 530 setup_ipvX_over_ipvY 4 4 531} 532 533setup_ip6ip4() { 534 setup_ipvX_over_ipvY 6 4 535} 536 537setup_ip4ip6() { 538 setup_ipvX_over_ipvY 4 6 539} 540 541setup_ip6ip6() { 542 setup_ipvX_over_ipvY 6 6 543} 544 545setup_namespaces() { 546 setup_ns NS_A NS_B NS_C NS_R1 NS_R2 547 for n in ${NS_A} ${NS_B} ${NS_C} ${NS_R1} ${NS_R2}; do 548 # Disable DAD, so that we don't have to wait to use the 549 # configured IPv6 addresses 550 ip netns exec ${n} sysctl -q net/ipv6/conf/default/accept_dad=0 551 done 552 ns_a="ip netns exec ${NS_A}" 553 ns_b="ip netns exec ${NS_B}" 554 ns_c="ip netns exec ${NS_C}" 555 ns_r1="ip netns exec ${NS_R1}" 556 ns_r2="ip netns exec ${NS_R2}" 557} 558 559setup_veth() { 560 run_cmd ${ns_a} ip link add veth_a type veth peer name veth_b || return 1 561 run_cmd ${ns_a} ip link set veth_b netns ${NS_B} 562 563 run_cmd ${ns_a} ip addr add ${veth4_a_addr}/${veth4_mask} dev veth_a 564 run_cmd ${ns_b} ip addr add ${veth4_b_addr}/${veth4_mask} dev veth_b 565 566 run_cmd ${ns_a} ip addr add ${veth6_a_addr}/${veth6_mask} dev veth_a 567 run_cmd ${ns_b} ip addr add ${veth6_b_addr}/${veth6_mask} dev veth_b 568 569 run_cmd ${ns_a} ip link set veth_a up 570 run_cmd ${ns_b} ip link set veth_b up 571} 572 573setup_vti() { 574 proto=${1} 575 veth_a_addr="${2}" 576 veth_b_addr="${3}" 577 vti_a_addr="${4}" 578 vti_b_addr="${5}" 579 vti_mask=${6} 580 581 [ ${proto} -eq 6 ] && vti_type="vti6" || vti_type="vti" 582 583 run_cmd ${ns_a} ip link add vti${proto}_a type ${vti_type} local ${veth_a_addr} remote ${veth_b_addr} key 10 || return 1 584 run_cmd ${ns_b} ip link add vti${proto}_b type ${vti_type} local ${veth_b_addr} remote ${veth_a_addr} key 10 585 586 run_cmd ${ns_a} ip addr add ${vti_a_addr}/${vti_mask} dev vti${proto}_a 587 run_cmd ${ns_b} ip addr add ${vti_b_addr}/${vti_mask} dev vti${proto}_b 588 589 run_cmd ${ns_a} ip link set vti${proto}_a up 590 run_cmd ${ns_b} ip link set vti${proto}_b up 591} 592 593setup_vti4() { 594 setup_vti 4 ${veth4_a_addr} ${veth4_b_addr} ${tunnel4_a_addr} ${tunnel4_b_addr} ${tunnel4_mask} 595} 596 597setup_vti6() { 598 setup_vti 6 ${veth6_a_addr} ${veth6_b_addr} ${tunnel6_a_addr} ${tunnel6_b_addr} ${tunnel6_mask} 599} 600 601setup_vti4routed() { 602 setup_vti 4 ${prefix4}.${a_r1}.1 ${prefix4}.${b_r1}.1 ${tunnel4_a_addr} ${tunnel4_b_addr} ${tunnel4_mask} 603} 604 605setup_vti6routed() { 606 setup_vti 6 ${prefix6}:${a_r1}::1 ${prefix6}:${b_r1}::1 ${tunnel6_a_addr} ${tunnel6_b_addr} ${tunnel6_mask} 607} 608 609setup_vxlan_or_geneve() { 610 type="${1}" 611 a_addr="${2}" 612 b_addr="${3}" 613 opts="${4}" 614 br_if_a="${5}" 615 616 if [ "${type}" = "vxlan" ]; then 617 opts="${opts} ttl 64 dstport 4789" 618 opts_a="local ${a_addr}" 619 opts_b="local ${b_addr}" 620 else 621 opts_a="" 622 opts_b="" 623 fi 624 625 run_cmd ${ns_a} ip link add ${type}_a type ${type} id 1 ${opts_a} remote ${b_addr} ${opts} || return 1 626 run_cmd ${ns_b} ip link add ${type}_b type ${type} id 1 ${opts_b} remote ${a_addr} ${opts} 627 628 if [ -n "${br_if_a}" ]; then 629 run_cmd ${ns_a} ip addr add ${tunnel4_a_addr}/${tunnel4_mask} dev ${br_if_a} 630 run_cmd ${ns_a} ip addr add ${tunnel6_a_addr}/${tunnel6_mask} dev ${br_if_a} 631 run_cmd ${ns_a} ip link set ${type}_a master ${br_if_a} 632 else 633 run_cmd ${ns_a} ip addr add ${tunnel4_a_addr}/${tunnel4_mask} dev ${type}_a 634 run_cmd ${ns_a} ip addr add ${tunnel6_a_addr}/${tunnel6_mask} dev ${type}_a 635 fi 636 637 run_cmd ${ns_b} ip addr add ${tunnel4_b_addr}/${tunnel4_mask} dev ${type}_b 638 run_cmd ${ns_b} ip addr add ${tunnel6_b_addr}/${tunnel6_mask} dev ${type}_b 639 640 run_cmd ${ns_a} ip link set ${type}_a up 641 run_cmd ${ns_b} ip link set ${type}_b up 642} 643 644setup_geneve4() { 645 setup_vxlan_or_geneve geneve ${prefix4}.${a_r1}.1 ${prefix4}.${b_r1}.1 "df set" 646} 647 648setup_vxlan4() { 649 setup_vxlan_or_geneve vxlan ${prefix4}.${a_r1}.1 ${prefix4}.${b_r1}.1 "df set" 650} 651 652setup_geneve6() { 653 setup_vxlan_or_geneve geneve ${prefix6}:${a_r1}::1 ${prefix6}:${b_r1}::1 "" 654} 655 656setup_vxlan6() { 657 setup_vxlan_or_geneve vxlan ${prefix6}:${a_r1}::1 ${prefix6}:${b_r1}::1 "" 658} 659 660setup_bridged_geneve4() { 661 setup_vxlan_or_geneve geneve ${prefix4}.${a_r1}.1 ${prefix4}.${b_r1}.1 "df set" "br0" 662} 663 664setup_bridged_vxlan4() { 665 setup_vxlan_or_geneve vxlan ${prefix4}.${a_r1}.1 ${prefix4}.${b_r1}.1 "df set" "br0" 666} 667 668setup_bridged_geneve6() { 669 setup_vxlan_or_geneve geneve ${prefix6}:${a_r1}::1 ${prefix6}:${b_r1}::1 "" "br0" 670} 671 672setup_bridged_vxlan6() { 673 setup_vxlan_or_geneve vxlan ${prefix6}:${a_r1}::1 ${prefix6}:${b_r1}::1 "" "br0" 674} 675 676setup_xfrm() { 677 proto=${1} 678 veth_a_addr="${2}" 679 veth_b_addr="${3}" 680 encap=${4} 681 682 run_cmd ${ns_a} ip -${proto} xfrm state add src ${veth_a_addr} dst ${veth_b_addr} spi 0x1000 proto esp aead 'rfc4106(gcm(aes))' 0x0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f 128 mode tunnel ${encap} || return 1 683 run_cmd ${ns_a} ip -${proto} xfrm state add src ${veth_b_addr} dst ${veth_a_addr} spi 0x1001 proto esp aead 'rfc4106(gcm(aes))' 0x0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f 128 mode tunnel ${encap} 684 run_cmd ${ns_a} ip -${proto} xfrm policy add dir out mark 10 tmpl src ${veth_a_addr} dst ${veth_b_addr} proto esp mode tunnel 685 run_cmd ${ns_a} ip -${proto} xfrm policy add dir in mark 10 tmpl src ${veth_b_addr} dst ${veth_a_addr} proto esp mode tunnel 686 687 run_cmd ${ns_b} ip -${proto} xfrm state add src ${veth_a_addr} dst ${veth_b_addr} spi 0x1000 proto esp aead 'rfc4106(gcm(aes))' 0x0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f 128 mode tunnel ${encap} 688 run_cmd ${ns_b} ip -${proto} xfrm state add src ${veth_b_addr} dst ${veth_a_addr} spi 0x1001 proto esp aead 'rfc4106(gcm(aes))' 0x0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f 128 mode tunnel ${encap} 689 run_cmd ${ns_b} ip -${proto} xfrm policy add dir out mark 10 tmpl src ${veth_b_addr} dst ${veth_a_addr} proto esp mode tunnel 690 run_cmd ${ns_b} ip -${proto} xfrm policy add dir in mark 10 tmpl src ${veth_a_addr} dst ${veth_b_addr} proto esp mode tunnel 691} 692 693setup_nettest_xfrm() { 694 check_gen_prog "nettest" 695 696 [ ${1} -eq 6 ] && proto="-6" || proto="" 697 port=${2} 698 699 run_cmd_bg "${ns_a}" nettest "${proto}" -q -D -s -x -p "${port}" -t 5 700 nettest_pids="${nettest_pids} $!" 701 702 run_cmd_bg "${ns_b}" nettest "${proto}" -q -D -s -x -p "${port}" -t 5 703 nettest_pids="${nettest_pids} $!" 704} 705 706setup_xfrm4() { 707 setup_xfrm 4 ${veth4_a_addr} ${veth4_b_addr} 708} 709 710setup_xfrm6() { 711 setup_xfrm 6 ${veth6_a_addr} ${veth6_b_addr} 712} 713 714setup_xfrm4udp() { 715 setup_xfrm 4 ${veth4_a_addr} ${veth4_b_addr} "encap espinudp 4500 4500 0.0.0.0" && \ 716 setup_nettest_xfrm 4 4500 717} 718 719setup_xfrm6udp() { 720 setup_xfrm 6 ${veth6_a_addr} ${veth6_b_addr} "encap espinudp 4500 4500 0.0.0.0" && \ 721 setup_nettest_xfrm 6 4500 722} 723 724setup_xfrm4udprouted() { 725 setup_xfrm 4 ${prefix4}.${a_r1}.1 ${prefix4}.${b_r1}.1 "encap espinudp 4500 4500 0.0.0.0" && \ 726 setup_nettest_xfrm 4 4500 727} 728 729setup_xfrm6udprouted() { 730 setup_xfrm 6 ${prefix6}:${a_r1}::1 ${prefix6}:${b_r1}::1 "encap espinudp 4500 4500 0.0.0.0" && \ 731 setup_nettest_xfrm 6 4500 732} 733 734setup_routing_old() { 735 for i in ${routes}; do 736 [ "${ns}" = "" ] && ns="${i}" && continue 737 [ "${addr}" = "" ] && addr="${i}" && continue 738 [ "${gw}" = "" ] && gw="${i}" 739 740 ns_name="$(nsname ${ns})" 741 742 ip -n "${ns_name}" route add "${addr}" table "${rt_table}" via "${gw}" 743 744 ns=""; addr=""; gw="" 745 done 746} 747 748setup_routing_new() { 749 for i in ${nexthops}; do 750 [ "${ns}" = "" ] && ns="${i}" && continue 751 [ "${fam}" = "" ] && fam="${i}" && continue 752 [ "${nhid}" = "" ] && nhid="${i}" && continue 753 [ "${gw}" = "" ] && gw="${i}" && continue 754 [ "${dev}" = "" ] && dev="${i}" 755 756 ns_name="$(nsname ${ns})" 757 758 ip -n ${ns_name} -${fam} nexthop add id ${nhid} via ${gw} dev ${dev} 759 760 ns=""; fam=""; nhid=""; gw=""; dev="" 761 762 done 763 764 for i in ${routes_nh}; do 765 [ "${ns}" = "" ] && ns="${i}" && continue 766 [ "${fam}" = "" ] && fam="${i}" && continue 767 [ "${addr}" = "" ] && addr="${i}" && continue 768 [ "${nhid}" = "" ] && nhid="${i}" 769 770 ns_name="$(nsname ${ns})" 771 772 ip -n "${ns_name}" -"${fam}" route add "${addr}" table "${rt_table}" nhid "${nhid}" 773 774 ns=""; fam=""; addr=""; nhid="" 775 done 776} 777 778setup_routing() { 779 for i in ${NS_R1} ${NS_R2}; do 780 ip netns exec ${i} sysctl -q net/ipv4/ip_forward=1 781 ip netns exec ${i} sysctl -q net/ipv6/conf/all/forwarding=1 782 done 783 784 for i in ${routing_addrs}; do 785 [ "${ns}" = "" ] && ns="${i}" && continue 786 [ "${peer}" = "" ] && peer="${i}" && continue 787 [ "${segment}" = "" ] && segment="${i}" 788 789 ns_name="$(nsname ${ns})" 790 peer_name="$(nsname ${peer})" 791 if="veth_${ns}-${peer}" 792 ifpeer="veth_${peer}-${ns}" 793 794 # Create veth links 795 ip link add ${if} up netns ${ns_name} type veth peer name ${ifpeer} netns ${peer_name} || return 1 796 ip -n ${peer_name} link set dev ${ifpeer} up 797 798 # Add addresses 799 ip -n ${ns_name} addr add ${prefix4}.${segment}.1/24 dev ${if} 800 ip -n ${ns_name} addr add ${prefix6}:${segment}::1/64 dev ${if} 801 802 ip -n ${peer_name} addr add ${prefix4}.${segment}.2/24 dev ${ifpeer} 803 ip -n ${peer_name} addr add ${prefix6}:${segment}::2/64 dev ${ifpeer} 804 805 ns=""; peer=""; segment="" 806 done 807 808 if [ "$USE_NH" = "yes" ]; then 809 setup_routing_new 810 else 811 setup_routing_old 812 fi 813 814 return 0 815} 816 817setup_policy_routing() { 818 setup_routing 819 820 ip -netns "${NS_A}" -4 rule add dsfield "${policy_mark}" \ 821 table "${rt_table}" 822 823 # Set the IPv4 Don't Fragment bit with tc, since socat doesn't seem to 824 # have an option do to it. 825 tc -netns "${NS_A}" qdisc replace dev veth_A-R1 root prio 826 tc -netns "${NS_A}" qdisc replace dev veth_A-R2 root prio 827 tc -netns "${NS_A}" filter add dev veth_A-R1 \ 828 protocol ipv4 flower ip_proto udp \ 829 action pedit ex munge ip df set 0x40 pipe csum ip and udp 830 tc -netns "${NS_A}" filter add dev veth_A-R2 \ 831 protocol ipv4 flower ip_proto udp \ 832 action pedit ex munge ip df set 0x40 pipe csum ip and udp 833} 834 835setup_bridge() { 836 run_cmd ${ns_a} ip link add br0 type bridge || return $ksft_skip 837 run_cmd ${ns_a} ip link set br0 up 838 839 run_cmd ${ns_c} ip link add veth_C-A type veth peer name veth_A-C 840 run_cmd ${ns_c} ip link set veth_A-C netns ${NS_A} 841 842 run_cmd ${ns_a} ip link set veth_A-C up 843 run_cmd ${ns_c} ip link set veth_C-A up 844 run_cmd ${ns_c} ip addr add ${veth4_c_addr}/${veth4_mask} dev veth_C-A 845 run_cmd ${ns_c} ip addr add ${veth6_c_addr}/${veth6_mask} dev veth_C-A 846 run_cmd ${ns_a} ip link set veth_A-C master br0 847} 848 849setup_ovs_via_internal_utility() { 850 type="${1}" 851 a_addr="${2}" 852 b_addr="${3}" 853 dport="${4}" 854 855 run_cmd python3 ./openvswitch/ovs-dpctl.py add-if ovs_br0 ${type}_a -t ${type} || return 1 856 857 ports=$(python3 ./openvswitch/ovs-dpctl.py show) 858 br0_port=$(echo "$ports" | grep -E "\sovs_br0" | sed -e 's@port @@' | cut -d: -f1 | xargs) 859 type_a_port=$(echo "$ports" | grep ${type}_a | sed -e 's@port @@' | cut -d: -f1 | xargs) 860 veth_a_port=$(echo "$ports" | grep veth_A | sed -e 's@port @@' | cut -d: -f1 | xargs) 861 862 v4_a_tun="${prefix4}.${a_r1}.1" 863 v4_b_tun="${prefix4}.${b_r1}.1" 864 865 v6_a_tun="${prefix6}:${a_r1}::1" 866 v6_b_tun="${prefix6}:${b_r1}::1" 867 868 if [ "${v4_a_tun}" = "${a_addr}" ]; then 869 run_cmd python3 ./openvswitch/ovs-dpctl.py add-flow ovs_br0 \ 870 "recirc_id(0),in_port(${veth_a_port}),eth(),eth_type(0x0800),ipv4()" \ 871 "set(tunnel(tun_id=1,dst=${v4_b_tun},ttl=64,tp_dst=${dport},flags(df|csum))),${type_a_port}" 872 run_cmd python3 ./openvswitch/ovs-dpctl.py add-flow ovs_br0 \ 873 "recirc_id(0),in_port(${veth_a_port}),eth(),eth_type(0x86dd),ipv6()" \ 874 "set(tunnel(tun_id=1,dst=${v4_b_tun},ttl=64,tp_dst=${dport},flags(df|csum))),${type_a_port}" 875 run_cmd python3 ./openvswitch/ovs-dpctl.py add-flow ovs_br0 \ 876 "recirc_id(0),tunnel(tun_id=1,src=${v4_b_tun},dst=${v4_a_tun}),in_port(${type_a_port}),eth(),eth_type(0x0800),ipv4()" \ 877 "${veth_a_port}" 878 run_cmd python3 ./openvswitch/ovs-dpctl.py add-flow ovs_br0 \ 879 "recirc_id(0),tunnel(tun_id=1,src=${v4_b_tun},dst=${v4_a_tun}),in_port(${type_a_port}),eth(),eth_type(0x86dd),ipv6()" \ 880 "${veth_a_port}" 881 run_cmd python3 ./openvswitch/ovs-dpctl.py add-flow ovs_br0 \ 882 "recirc_id(0),tunnel(tun_id=1,src=${v4_b_tun},dst=${v4_a_tun}),in_port(${type_a_port}),eth(),eth_type(0x0806),arp()" \ 883 "${veth_a_port}" 884 run_cmd python3 ./openvswitch/ovs-dpctl.py add-flow ovs_br0 \ 885 "recirc_id(0),in_port(${veth_a_port}),eth(),eth_type(0x0806),arp(sip=${veth4_c_addr},tip=${tunnel4_b_addr})" \ 886 "set(tunnel(tun_id=1,dst=${v4_b_tun},ttl=64,tp_dst=${dport},flags(df|csum))),${type_a_port}" 887 else 888 run_cmd python3 ./openvswitch/ovs-dpctl.py add-flow ovs_br0 \ 889 "recirc_id(0),in_port(${veth_a_port}),eth(),eth_type(0x0800),ipv4()" \ 890 "set(tunnel(tun_id=1,ipv6_dst=${v6_b_tun},ttl=64,tp_dst=${dport},flags(df|csum))),${type_a_port}" 891 run_cmd python3 ./openvswitch/ovs-dpctl.py add-flow ovs_br0 \ 892 "recirc_id(0),in_port(${veth_a_port}),eth(),eth_type(0x86dd),ipv6()" \ 893 "set(tunnel(tun_id=1,ipv6_dst=${v6_b_tun},ttl=64,tp_dst=${dport},flags(df|csum))),${type_a_port}" 894 run_cmd python3 ./openvswitch/ovs-dpctl.py add-flow ovs_br0 \ 895 "recirc_id(0),tunnel(tun_id=1,ipv6_src=${v6_b_tun},ipv6_dst=${v6_a_tun}),in_port(${type_a_port}),eth(),eth_type(0x0800),ipv4()" \ 896 "${veth_a_port}" 897 run_cmd python3 ./openvswitch/ovs-dpctl.py add-flow ovs_br0 \ 898 "recirc_id(0),tunnel(tun_id=1,ipv6_src=${v6_b_tun},ipv6_dst=${v6_a_tun}),in_port(${type_a_port}),eth(),eth_type(0x86dd),ipv6()" \ 899 "${veth_a_port}" 900 run_cmd python3 ./openvswitch/ovs-dpctl.py add-flow ovs_br0 \ 901 "recirc_id(0),tunnel(tun_id=1,ipv6_src=${v6_b_tun},ipv6_dst=${v6_a_tun}),in_port(${type_a_port}),eth(),eth_type(0x0806),arp()" \ 902 "${veth_a_port}" 903 run_cmd python3 ./openvswitch/ovs-dpctl.py add-flow ovs_br0 \ 904 "recirc_id(0),in_port(${veth_a_port}),eth(),eth_type(0x0806),arp(sip=${veth4_c_addr},tip=${tunnel4_b_addr})" \ 905 "set(tunnel(tun_id=1,ipv6_dst=${v6_b_tun},ttl=64,tp_dst=${dport},flags(df|csum))),${type_a_port}" 906 fi 907} 908 909setup_ovs_via_vswitchd() { 910 type="${1}" 911 b_addr="${2}" 912 913 run_cmd ovs-vsctl add-port ovs_br0 ${type}_a -- \ 914 set interface ${type}_a type=${type} \ 915 options:remote_ip=${b_addr} options:key=1 options:csum=true || return 1 916} 917 918setup_ovs_vxlan_or_geneve() { 919 type="${1}" 920 a_addr="${2}" 921 b_addr="${3}" 922 dport="6081" 923 924 if [ "${type}" = "vxlan" ]; then 925 dport="4789" 926 opts="${opts} ttl 64 dstport 4789" 927 opts_b="local ${b_addr}" 928 fi 929 930 setup_ovs_via_internal_utility "${type}" "${a_addr}" "${b_addr}" \ 931 "${dport}" || \ 932 setup_ovs_via_vswitchd "${type}" "${b_addr}" || return 1 933 934 run_cmd ${ns_b} ip link add ${type}_b type ${type} id 1 ${opts_b} remote ${a_addr} ${opts} || return 1 935 936 run_cmd ${ns_b} ip addr add ${tunnel4_b_addr}/${tunnel4_mask} dev ${type}_b 937 run_cmd ${ns_b} ip addr add ${tunnel6_b_addr}/${tunnel6_mask} dev ${type}_b 938 939 run_cmd ip link set ${type}_a up 940 run_cmd ${ns_b} ip link set ${type}_b up 941} 942 943setup_ovs_geneve4() { 944 setup_ovs_vxlan_or_geneve geneve ${prefix4}.${a_r1}.1 ${prefix4}.${b_r1}.1 945} 946 947setup_ovs_vxlan4() { 948 setup_ovs_vxlan_or_geneve vxlan ${prefix4}.${a_r1}.1 ${prefix4}.${b_r1}.1 949} 950 951setup_ovs_geneve6() { 952 setup_ovs_vxlan_or_geneve geneve ${prefix6}:${a_r1}::1 ${prefix6}:${b_r1}::1 953} 954 955setup_ovs_vxlan6() { 956 setup_ovs_vxlan_or_geneve vxlan ${prefix6}:${a_r1}::1 ${prefix6}:${b_r1}::1 957} 958 959setup_ovs_br_internal() { 960 run_cmd python3 ./openvswitch/ovs-dpctl.py add-dp ovs_br0 || \ 961 return 1 962} 963 964setup_ovs_br_vswitchd() { 965 run_cmd ovs-vsctl add-br ovs_br0 || return 1 966} 967 968setup_ovs_add_if() { 969 ifname="${1}" 970 run_cmd python3 ./openvswitch/ovs-dpctl.py add-if ovs_br0 \ 971 "${ifname}" || \ 972 run_cmd ovs-vsctl add-port ovs_br0 "${ifname}" 973} 974 975setup_ovs_bridge() { 976 setup_ovs_br_internal || setup_ovs_br_vswitchd || return $ksft_skip 977 run_cmd ip link set ovs_br0 up 978 979 run_cmd ${ns_c} ip link add veth_C-A type veth peer name veth_A-C 980 run_cmd ${ns_c} ip link set veth_A-C netns 1 981 982 run_cmd ip link set veth_A-C up 983 run_cmd ${ns_c} ip link set veth_C-A up 984 run_cmd ${ns_c} ip addr add ${veth4_c_addr}/${veth4_mask} dev veth_C-A 985 run_cmd ${ns_c} ip addr add ${veth6_c_addr}/${veth6_mask} dev veth_C-A 986 setup_ovs_add_if veth_A-C 987 988 # Move veth_A-R1 to init 989 run_cmd ${ns_a} ip link set veth_A-R1 netns 1 990 run_cmd ip addr add ${prefix4}.${a_r1}.1/${veth4_mask} dev veth_A-R1 991 run_cmd ip addr add ${prefix6}:${a_r1}::1/${veth6_mask} dev veth_A-R1 992 run_cmd ip link set veth_A-R1 up 993 run_cmd ip route add ${prefix4}.${b_r1}.1 via ${prefix4}.${a_r1}.2 994 run_cmd ip route add ${prefix6}:${b_r1}::1 via ${prefix6}:${a_r1}::2 995} 996 997setup_multipath_new() { 998 # Set up host A with multipath routes to host B host4_b_addr 999 run_cmd ${ns_a} ip addr add ${host4_a_addr} dev lo 1000 run_cmd ${ns_a} ip nexthop add id 401 via ${prefix4}.${a_r1}.2 dev veth_A-R1 1001 run_cmd ${ns_a} ip nexthop add id 402 via ${prefix4}.${a_r2}.2 dev veth_A-R2 1002 run_cmd ${ns_a} ip nexthop add id 403 group 401/402 1003 run_cmd ${ns_a} ip route add ${host4_b_addr} src ${host4_a_addr} nhid 403 1004 1005 # Set up host B with multipath routes to host A host4_a_addr 1006 run_cmd ${ns_b} ip addr add ${host4_b_addr} dev lo 1007 run_cmd ${ns_b} ip nexthop add id 401 via ${prefix4}.${b_r1}.2 dev veth_B-R1 1008 run_cmd ${ns_b} ip nexthop add id 402 via ${prefix4}.${b_r2}.2 dev veth_B-R2 1009 run_cmd ${ns_b} ip nexthop add id 403 group 401/402 1010 run_cmd ${ns_b} ip route add ${host4_a_addr} src ${host4_b_addr} nhid 403 1011} 1012 1013setup_multipath_old() { 1014 # Set up host A with multipath routes to host B host4_b_addr 1015 run_cmd ${ns_a} ip addr add ${host4_a_addr} dev lo 1016 run_cmd ${ns_a} ip route add ${host4_b_addr} \ 1017 src ${host4_a_addr} \ 1018 nexthop via ${prefix4}.${a_r1}.2 weight 1 \ 1019 nexthop via ${prefix4}.${a_r2}.2 weight 1 1020 1021 # Set up host B with multipath routes to host A host4_a_addr 1022 run_cmd ${ns_b} ip addr add ${host4_b_addr} dev lo 1023 run_cmd ${ns_b} ip route add ${host4_a_addr} \ 1024 src ${host4_b_addr} \ 1025 nexthop via ${prefix4}.${b_r1}.2 weight 1 \ 1026 nexthop via ${prefix4}.${b_r2}.2 weight 1 1027} 1028 1029setup_multipath() { 1030 if [ "$USE_NH" = "yes" ]; then 1031 setup_multipath_new 1032 else 1033 setup_multipath_old 1034 fi 1035 1036 # Set up routers with routes to dummies 1037 run_cmd ${ns_r1} ip route add ${host4_a_addr} via ${prefix4}.${a_r1}.1 1038 run_cmd ${ns_r2} ip route add ${host4_a_addr} via ${prefix4}.${a_r2}.1 1039 run_cmd ${ns_r1} ip route add ${host4_b_addr} via ${prefix4}.${b_r1}.1 1040 run_cmd ${ns_r2} ip route add ${host4_b_addr} via ${prefix4}.${b_r2}.1 1041} 1042 1043setup() { 1044 [ "$(id -u)" -ne 0 ] && echo " need to run as root" && return $ksft_skip 1045 1046 for arg do 1047 eval setup_${arg} || { echo " ${arg} not supported"; return 1; } 1048 done 1049} 1050 1051trace() { 1052 [ $TRACING -eq 0 ] && return 1053 1054 for arg do 1055 [ "${ns_cmd}" = "" ] && ns_cmd="${arg}" && continue 1056 ${ns_cmd} tcpdump --immediate-mode -s 0 -i "${arg}" -w "${name}_${arg}.pcap" 2> /dev/null & 1057 tcpdump_pids="${tcpdump_pids} $!" 1058 ns_cmd= 1059 done 1060 sleep 1 1061} 1062 1063cleanup_del_ovs_internal() { 1064 # squelch the output of the del-if commands since it can be wordy 1065 python3 ./openvswitch/ovs-dpctl.py del-if ovs_br0 -d true vxlan_a >/dev/null 2>&1 1066 python3 ./openvswitch/ovs-dpctl.py del-if ovs_br0 -d true geneve_a >/dev/null 2>&1 1067 python3 ./openvswitch/ovs-dpctl.py del-dp ovs_br0 >/dev/null 2>&1 1068} 1069 1070cleanup_del_ovs_vswitchd() { 1071 ovs-vsctl --if-exists del-port vxlan_a 2>/dev/null 1072 ovs-vsctl --if-exists del-br ovs_br0 2>/dev/null 1073} 1074 1075cleanup() { 1076 for pid in ${tcpdump_pids}; do 1077 kill ${pid} 1078 done 1079 tcpdump_pids= 1080 1081 for pid in ${nettest_pids}; do 1082 kill ${pid} 1083 done 1084 nettest_pids= 1085 1086 for pid in ${socat_pids}; do 1087 kill "${pid}" 1088 done 1089 socat_pids= 1090 1091 cleanup_all_ns 1092 1093 ip link del veth_A-C 2>/dev/null 1094 ip link del veth_A-R1 2>/dev/null 1095 cleanup_del_ovs_internal 1096 cleanup_del_ovs_vswitchd 1097 rm -f "$tmpoutfile" 1098} 1099 1100mtu() { 1101 ns_cmd="${1}" 1102 dev="${2}" 1103 mtu="${3}" 1104 1105 ${ns_cmd} ip link set dev ${dev} mtu ${mtu} 1106} 1107 1108mtu_parse() { 1109 input="${1}" 1110 1111 next=0 1112 for i in ${input}; do 1113 [ ${next} -eq 1 -a "${i}" = "lock" ] && next=2 && continue 1114 [ ${next} -eq 1 ] && echo "${i}" && return 1115 [ ${next} -eq 2 ] && echo "lock ${i}" && return 1116 [ "${i}" = "mtu" ] && next=1 1117 done 1118} 1119 1120link_get() { 1121 ns_cmd="${1}" 1122 name="${2}" 1123 1124 ${ns_cmd} ip link show dev "${name}" 1125} 1126 1127link_get_mtu() { 1128 ns_cmd="${1}" 1129 name="${2}" 1130 1131 mtu_parse "$(link_get "${ns_cmd}" ${name})" 1132} 1133 1134route_get_dst_exception() { 1135 ns_cmd="${1}"; shift 1136 1137 ${ns_cmd} ip route get "$@" 1138} 1139 1140route_get_dst_pmtu_from_exception() { 1141 ns_cmd="${1}"; shift 1142 1143 mtu_parse "$(route_get_dst_exception "${ns_cmd}" "$@")" 1144} 1145 1146check_pmtu_value() { 1147 expected="${1}" 1148 value="${2}" 1149 event="${3}" 1150 1151 [ "${expected}" = "any" ] && [ -n "${value}" ] && return 0 1152 [ "${value}" = "${expected}" ] && return 0 1153 [ -z "${value}" ] && err " PMTU exception wasn't created after ${event}" && return 1 1154 [ -z "${expected}" ] && err " PMTU exception shouldn't exist after ${event}" && return 1 1155 err " found PMTU exception with incorrect MTU ${value}, expected ${expected}, after ${event}" 1156 return 1 1157} 1158 1159test_pmtu_ipvX() { 1160 family=${1} 1161 1162 setup namespaces routing || return $ksft_skip 1163 trace "${ns_a}" veth_A-R1 "${ns_r1}" veth_R1-A \ 1164 "${ns_r1}" veth_R1-B "${ns_b}" veth_B-R1 \ 1165 "${ns_a}" veth_A-R2 "${ns_r2}" veth_R2-A \ 1166 "${ns_r2}" veth_R2-B "${ns_b}" veth_B-R2 1167 1168 if [ ${family} -eq 4 ]; then 1169 ping=ping 1170 dst1="${prefix4}.${b_r1}.1" 1171 dst2="${prefix4}.${b_r2}.1" 1172 else 1173 ping=${ping6} 1174 dst1="${prefix6}:${b_r1}::1" 1175 dst2="${prefix6}:${b_r2}::1" 1176 fi 1177 1178 # Set up initial MTU values 1179 mtu "${ns_a}" veth_A-R1 2000 1180 mtu "${ns_r1}" veth_R1-A 2000 1181 mtu "${ns_r1}" veth_R1-B 1400 1182 mtu "${ns_b}" veth_B-R1 1400 1183 1184 mtu "${ns_a}" veth_A-R2 2000 1185 mtu "${ns_r2}" veth_R2-A 2000 1186 mtu "${ns_r2}" veth_R2-B 1500 1187 mtu "${ns_b}" veth_B-R2 1500 1188 1189 # Create route exceptions 1190 run_cmd ${ns_a} ${ping} -q -M want -i 0.1 -w 1 -s 1800 ${dst1} 1191 run_cmd ${ns_a} ${ping} -q -M want -i 0.1 -w 1 -s 1800 ${dst2} 1192 1193 # Check that exceptions have been created with the correct PMTU 1194 pmtu_1="$(route_get_dst_pmtu_from_exception "${ns_a}" ${dst1})" 1195 check_pmtu_value "1400" "${pmtu_1}" "exceeding MTU" || return 1 1196 pmtu_2="$(route_get_dst_pmtu_from_exception "${ns_a}" ${dst2})" 1197 check_pmtu_value "1500" "${pmtu_2}" "exceeding MTU" || return 1 1198 1199 # Decrease local MTU below PMTU, check for PMTU decrease in route exception 1200 mtu "${ns_a}" veth_A-R1 1300 1201 mtu "${ns_r1}" veth_R1-A 1300 1202 pmtu_1="$(route_get_dst_pmtu_from_exception "${ns_a}" ${dst1})" 1203 check_pmtu_value "1300" "${pmtu_1}" "decreasing local MTU" || return 1 1204 # Second exception shouldn't be modified 1205 pmtu_2="$(route_get_dst_pmtu_from_exception "${ns_a}" ${dst2})" 1206 check_pmtu_value "1500" "${pmtu_2}" "changing local MTU on a link not on this path" || return 1 1207 1208 # Increase MTU, check for PMTU increase in route exception 1209 mtu "${ns_a}" veth_A-R1 1700 1210 mtu "${ns_r1}" veth_R1-A 1700 1211 pmtu_1="$(route_get_dst_pmtu_from_exception "${ns_a}" ${dst1})" 1212 check_pmtu_value "1700" "${pmtu_1}" "increasing local MTU" || return 1 1213 # Second exception shouldn't be modified 1214 pmtu_2="$(route_get_dst_pmtu_from_exception "${ns_a}" ${dst2})" 1215 check_pmtu_value "1500" "${pmtu_2}" "changing local MTU on a link not on this path" || return 1 1216 1217 # Skip PMTU locking tests for IPv6 1218 [ $family -eq 6 ] && return 0 1219 1220 # Decrease remote MTU on path via R2, get new exception 1221 mtu "${ns_r2}" veth_R2-B 400 1222 mtu "${ns_b}" veth_B-R2 400 1223 run_cmd ${ns_a} ${ping} -q -M want -i 0.1 -w 1 -s 1400 ${dst2} 1224 pmtu_2="$(route_get_dst_pmtu_from_exception "${ns_a}" ${dst2})" 1225 check_pmtu_value "lock 552" "${pmtu_2}" "exceeding MTU, with MTU < min_pmtu" || return 1 1226 1227 # Decrease local MTU below PMTU 1228 mtu "${ns_a}" veth_A-R2 500 1229 mtu "${ns_r2}" veth_R2-A 500 1230 pmtu_2="$(route_get_dst_pmtu_from_exception "${ns_a}" ${dst2})" 1231 check_pmtu_value "500" "${pmtu_2}" "decreasing local MTU" || return 1 1232 1233 # Increase local MTU 1234 mtu "${ns_a}" veth_A-R2 1500 1235 mtu "${ns_r2}" veth_R2-A 1500 1236 pmtu_2="$(route_get_dst_pmtu_from_exception "${ns_a}" ${dst2})" 1237 check_pmtu_value "1500" "${pmtu_2}" "increasing local MTU" || return 1 1238 1239 # Get new exception 1240 run_cmd ${ns_a} ${ping} -q -M want -i 0.1 -w 1 -s 1400 ${dst2} 1241 pmtu_2="$(route_get_dst_pmtu_from_exception "${ns_a}" ${dst2})" 1242 check_pmtu_value "lock 552" "${pmtu_2}" "exceeding MTU, with MTU < min_pmtu" || return 1 1243} 1244 1245test_pmtu_ipv4_exception() { 1246 test_pmtu_ipvX 4 1247} 1248 1249test_pmtu_ipv6_exception() { 1250 test_pmtu_ipvX 6 1251} 1252 1253test_pmtu_ipv4_dscp_icmp_exception() { 1254 rt_table=100 1255 1256 setup namespaces policy_routing || return $ksft_skip 1257 trace "${ns_a}" veth_A-R1 "${ns_r1}" veth_R1-A \ 1258 "${ns_r1}" veth_R1-B "${ns_b}" veth_B-R1 \ 1259 "${ns_a}" veth_A-R2 "${ns_r2}" veth_R2-A \ 1260 "${ns_r2}" veth_R2-B "${ns_b}" veth_B-R2 1261 1262 # Set up initial MTU values 1263 mtu "${ns_a}" veth_A-R1 2000 1264 mtu "${ns_r1}" veth_R1-A 2000 1265 mtu "${ns_r1}" veth_R1-B 1400 1266 mtu "${ns_b}" veth_B-R1 1400 1267 1268 mtu "${ns_a}" veth_A-R2 2000 1269 mtu "${ns_r2}" veth_R2-A 2000 1270 mtu "${ns_r2}" veth_R2-B 1500 1271 mtu "${ns_b}" veth_B-R2 1500 1272 1273 len=$((2000 - 20 - 8)) # Fills MTU of veth_A-R1 1274 1275 dst1="${prefix4}.${b_r1}.1" 1276 dst2="${prefix4}.${b_r2}.1" 1277 1278 # Create route exceptions 1279 dsfield=${policy_mark} # No ECN bit set (Not-ECT) 1280 run_cmd "${ns_a}" ping -q -M want -Q "${dsfield}" -c 1 -w 1 -s "${len}" "${dst1}" 1281 1282 dsfield=$(printf "%#x" $((policy_mark + 0x02))) # ECN=2 (ECT(0)) 1283 run_cmd "${ns_a}" ping -q -M want -Q "${dsfield}" -c 1 -w 1 -s "${len}" "${dst2}" 1284 1285 # Check that exceptions have been created with the correct PMTU 1286 pmtu_1="$(route_get_dst_pmtu_from_exception "${ns_a}" "${dst1}" dsfield "${policy_mark}")" 1287 check_pmtu_value "1400" "${pmtu_1}" "exceeding MTU" || return 1 1288 1289 pmtu_2="$(route_get_dst_pmtu_from_exception "${ns_a}" "${dst2}" dsfield "${policy_mark}")" 1290 check_pmtu_value "1500" "${pmtu_2}" "exceeding MTU" || return 1 1291} 1292 1293test_pmtu_ipv4_dscp_udp_exception() { 1294 rt_table=100 1295 1296 if ! which socat > /dev/null 2>&1; then 1297 echo "'socat' command not found; skipping tests" 1298 return $ksft_skip 1299 fi 1300 1301 setup namespaces policy_routing || return $ksft_skip 1302 trace "${ns_a}" veth_A-R1 "${ns_r1}" veth_R1-A \ 1303 "${ns_r1}" veth_R1-B "${ns_b}" veth_B-R1 \ 1304 "${ns_a}" veth_A-R2 "${ns_r2}" veth_R2-A \ 1305 "${ns_r2}" veth_R2-B "${ns_b}" veth_B-R2 1306 1307 # Set up initial MTU values 1308 mtu "${ns_a}" veth_A-R1 2000 1309 mtu "${ns_r1}" veth_R1-A 2000 1310 mtu "${ns_r1}" veth_R1-B 1400 1311 mtu "${ns_b}" veth_B-R1 1400 1312 1313 mtu "${ns_a}" veth_A-R2 2000 1314 mtu "${ns_r2}" veth_R2-A 2000 1315 mtu "${ns_r2}" veth_R2-B 1500 1316 mtu "${ns_b}" veth_B-R2 1500 1317 1318 len=$((2000 - 20 - 8)) # Fills MTU of veth_A-R1 1319 1320 dst1="${prefix4}.${b_r1}.1" 1321 dst2="${prefix4}.${b_r2}.1" 1322 1323 # Create route exceptions 1324 run_cmd_bg "${ns_b}" socat UDP-LISTEN:50000 OPEN:/dev/null,wronly=1 1325 socat_pids="${socat_pids} $!" 1326 1327 dsfield=${policy_mark} # No ECN bit set (Not-ECT) 1328 run_cmd "${ns_a}" socat OPEN:/dev/zero,rdonly=1,readbytes="${len}" \ 1329 UDP:"${dst1}":50000,tos="${dsfield}" 1330 1331 dsfield=$(printf "%#x" $((policy_mark + 0x02))) # ECN=2 (ECT(0)) 1332 run_cmd "${ns_a}" socat OPEN:/dev/zero,rdonly=1,readbytes="${len}" \ 1333 UDP:"${dst2}":50000,tos="${dsfield}" 1334 1335 # Check that exceptions have been created with the correct PMTU 1336 pmtu_1="$(route_get_dst_pmtu_from_exception "${ns_a}" "${dst1}" dsfield "${policy_mark}")" 1337 check_pmtu_value "1400" "${pmtu_1}" "exceeding MTU" || return 1 1338 pmtu_2="$(route_get_dst_pmtu_from_exception "${ns_a}" "${dst2}" dsfield "${policy_mark}")" 1339 check_pmtu_value "1500" "${pmtu_2}" "exceeding MTU" || return 1 1340} 1341 1342test_pmtu_ipvX_over_vxlanY_or_geneveY_exception() { 1343 type=${1} 1344 family=${2} 1345 outer_family=${3} 1346 ll_mtu=4000 1347 1348 if [ ${outer_family} -eq 4 ]; then 1349 setup namespaces routing ${type}4 || return $ksft_skip 1350 # IPv4 header UDP header VXLAN/GENEVE header Ethernet header 1351 exp_mtu=$((${ll_mtu} - 20 - 8 - 8 - 14)) 1352 else 1353 setup namespaces routing ${type}6 || return $ksft_skip 1354 # IPv6 header UDP header VXLAN/GENEVE header Ethernet header 1355 exp_mtu=$((${ll_mtu} - 40 - 8 - 8 - 14)) 1356 fi 1357 1358 trace "${ns_a}" ${type}_a "${ns_b}" ${type}_b \ 1359 "${ns_a}" veth_A-R1 "${ns_r1}" veth_R1-A \ 1360 "${ns_b}" veth_B-R1 "${ns_r1}" veth_R1-B 1361 1362 if [ ${family} -eq 4 ]; then 1363 ping=ping 1364 dst=${tunnel4_b_addr} 1365 else 1366 ping=${ping6} 1367 dst=${tunnel6_b_addr} 1368 fi 1369 1370 # Create route exception by exceeding link layer MTU 1371 mtu "${ns_a}" veth_A-R1 $((${ll_mtu} + 1000)) 1372 mtu "${ns_r1}" veth_R1-A $((${ll_mtu} + 1000)) 1373 mtu "${ns_b}" veth_B-R1 ${ll_mtu} 1374 mtu "${ns_r1}" veth_R1-B ${ll_mtu} 1375 1376 mtu "${ns_a}" ${type}_a $((${ll_mtu} + 1000)) 1377 mtu "${ns_b}" ${type}_b $((${ll_mtu} + 1000)) 1378 run_cmd ${ns_a} ${ping} -q -M want -i 0.1 -w 1 -s $((${ll_mtu} + 500)) ${dst} 1379 1380 # Check that exception was created 1381 pmtu="$(route_get_dst_pmtu_from_exception "${ns_a}" ${dst})" 1382 check_pmtu_value ${exp_mtu} "${pmtu}" "exceeding link layer MTU on ${type} interface" 1383} 1384 1385test_pmtu_ipv4_vxlan4_exception() { 1386 test_pmtu_ipvX_over_vxlanY_or_geneveY_exception vxlan 4 4 1387} 1388 1389test_pmtu_ipv6_vxlan4_exception() { 1390 test_pmtu_ipvX_over_vxlanY_or_geneveY_exception vxlan 6 4 1391} 1392 1393test_pmtu_ipv4_geneve4_exception() { 1394 test_pmtu_ipvX_over_vxlanY_or_geneveY_exception geneve 4 4 1395} 1396 1397test_pmtu_ipv6_geneve4_exception() { 1398 test_pmtu_ipvX_over_vxlanY_or_geneveY_exception geneve 6 4 1399} 1400 1401test_pmtu_ipv4_vxlan6_exception() { 1402 test_pmtu_ipvX_over_vxlanY_or_geneveY_exception vxlan 4 6 1403} 1404 1405test_pmtu_ipv6_vxlan6_exception() { 1406 test_pmtu_ipvX_over_vxlanY_or_geneveY_exception vxlan 6 6 1407} 1408 1409test_pmtu_ipv4_geneve6_exception() { 1410 test_pmtu_ipvX_over_vxlanY_or_geneveY_exception geneve 4 6 1411} 1412 1413test_pmtu_ipv6_geneve6_exception() { 1414 test_pmtu_ipvX_over_vxlanY_or_geneveY_exception geneve 6 6 1415} 1416 1417test_pmtu_ipvX_over_bridged_vxlanY_or_geneveY_exception() { 1418 type=${1} 1419 family=${2} 1420 outer_family=${3} 1421 ll_mtu=4000 1422 1423 if [ ${outer_family} -eq 4 ]; then 1424 setup namespaces routing bridge bridged_${type}4 || return $ksft_skip 1425 # IPv4 header UDP header VXLAN/GENEVE header Ethernet header 1426 exp_mtu=$((${ll_mtu} - 20 - 8 - 8 - 14)) 1427 else 1428 setup namespaces routing bridge bridged_${type}6 || return $ksft_skip 1429 # IPv6 header UDP header VXLAN/GENEVE header Ethernet header 1430 exp_mtu=$((${ll_mtu} - 40 - 8 - 8 - 14)) 1431 fi 1432 1433 trace "${ns_a}" ${type}_a "${ns_b}" ${type}_b \ 1434 "${ns_a}" veth_A-R1 "${ns_r1}" veth_R1-A \ 1435 "${ns_b}" veth_B-R1 "${ns_r1}" veth_R1-B \ 1436 "${ns_a}" br0 "${ns_a}" veth-A-C \ 1437 "${ns_c}" veth_C-A 1438 1439 if [ ${family} -eq 4 ]; then 1440 ping=ping 1441 dst=${tunnel4_b_addr} 1442 else 1443 ping=${ping6} 1444 dst=${tunnel6_b_addr} 1445 fi 1446 1447 # Create route exception by exceeding link layer MTU 1448 mtu "${ns_a}" veth_A-R1 $((${ll_mtu} + 1000)) 1449 mtu "${ns_a}" br0 $((${ll_mtu} + 1000)) 1450 mtu "${ns_a}" veth_A-C $((${ll_mtu} + 1000)) 1451 mtu "${ns_c}" veth_C-A $((${ll_mtu} + 1000)) 1452 mtu "${ns_r1}" veth_R1-A $((${ll_mtu} + 1000)) 1453 mtu "${ns_b}" veth_B-R1 ${ll_mtu} 1454 mtu "${ns_r1}" veth_R1-B ${ll_mtu} 1455 1456 mtu "${ns_a}" ${type}_a $((${ll_mtu} + 1000)) 1457 mtu "${ns_b}" ${type}_b $((${ll_mtu} + 1000)) 1458 1459 run_cmd ${ns_c} ${ping} -q -M want -i 0.1 -c 10 -s $((${ll_mtu} + 500)) ${dst} || return 1 1460 run_cmd ${ns_a} ${ping} -q -M want -i 0.1 -w 1 -s $((${ll_mtu} + 500)) ${dst} || return 1 1461 1462 # Check that exceptions were created 1463 pmtu="$(route_get_dst_pmtu_from_exception "${ns_c}" ${dst})" 1464 check_pmtu_value ${exp_mtu} "${pmtu}" "exceeding link layer MTU on bridged ${type} interface" 1465 pmtu="$(route_get_dst_pmtu_from_exception "${ns_a}" ${dst})" 1466 check_pmtu_value ${exp_mtu} "${pmtu}" "exceeding link layer MTU on locally bridged ${type} interface" 1467 1468 tmpoutfile=$(mktemp) 1469 1470 # Flush Exceptions, retry with TCP 1471 run_cmd ${ns_a} ip route flush cached ${dst} 1472 run_cmd ${ns_b} ip route flush cached ${dst} 1473 run_cmd ${ns_c} ip route flush cached ${dst} 1474 1475 for target in "${ns_a}" "${ns_c}" ; do 1476 if [ ${family} -eq 4 ]; then 1477 TCPDST=TCP:${dst}:50000 1478 else 1479 TCPDST="TCP:[${dst}]:50000" 1480 fi 1481 ${ns_b} socat -T 3 -u -6 TCP-LISTEN:50000,reuseaddr STDOUT > $tmpoutfile & 1482 local socat_pid=$! 1483 1484 wait_local_port_listen ${NS_B} 50000 tcp 1485 1486 dd if=/dev/zero status=none bs=1M count=1 | ${target} socat -T 3 -u STDIN $TCPDST,connect-timeout=3 1487 1488 wait ${socat_pid} 1489 size=$(du -sb $tmpoutfile) 1490 size=${size%%/tmp/*} 1491 1492 [ $size -ne 1048576 ] && err "File size $size mismatches expected value in locally bridged vxlan test" && return 1 1493 done 1494 1495 rm -f "$tmpoutfile" 1496 1497 # Check that exceptions were created 1498 pmtu="$(route_get_dst_pmtu_from_exception "${ns_c}" ${dst})" 1499 check_pmtu_value ${exp_mtu} "${pmtu}" "tcp: exceeding link layer MTU on bridged ${type} interface" 1500 pmtu="$(route_get_dst_pmtu_from_exception "${ns_a}" ${dst})" 1501 check_pmtu_value ${exp_mtu} "${pmtu}" "tcp exceeding link layer MTU on locally bridged ${type} interface" 1502} 1503 1504test_pmtu_ipv4_br_vxlan4_exception() { 1505 test_pmtu_ipvX_over_bridged_vxlanY_or_geneveY_exception vxlan 4 4 1506} 1507 1508test_pmtu_ipv6_br_vxlan4_exception() { 1509 test_pmtu_ipvX_over_bridged_vxlanY_or_geneveY_exception vxlan 6 4 1510} 1511 1512test_pmtu_ipv4_br_geneve4_exception() { 1513 test_pmtu_ipvX_over_bridged_vxlanY_or_geneveY_exception geneve 4 4 1514} 1515 1516test_pmtu_ipv6_br_geneve4_exception() { 1517 test_pmtu_ipvX_over_bridged_vxlanY_or_geneveY_exception geneve 6 4 1518} 1519 1520test_pmtu_ipv4_br_vxlan6_exception() { 1521 test_pmtu_ipvX_over_bridged_vxlanY_or_geneveY_exception vxlan 4 6 1522} 1523 1524test_pmtu_ipv6_br_vxlan6_exception() { 1525 test_pmtu_ipvX_over_bridged_vxlanY_or_geneveY_exception vxlan 6 6 1526} 1527 1528test_pmtu_ipv4_br_geneve6_exception() { 1529 test_pmtu_ipvX_over_bridged_vxlanY_or_geneveY_exception geneve 4 6 1530} 1531 1532test_pmtu_ipv6_br_geneve6_exception() { 1533 test_pmtu_ipvX_over_bridged_vxlanY_or_geneveY_exception geneve 6 6 1534} 1535 1536test_pmtu_ipvX_over_ovs_vxlanY_or_geneveY_exception() { 1537 type=${1} 1538 family=${2} 1539 outer_family=${3} 1540 ll_mtu=4000 1541 1542 if [ "${type}" = "vxlan" ]; then 1543 tun_a="vxlan_sys_4789" 1544 elif [ "${type}" = "geneve" ]; then 1545 tun_a="genev_sys_6081" 1546 fi 1547 1548 if [ ${outer_family} -eq 4 ]; then 1549 setup namespaces routing ovs_bridge ovs_${type}4 || return $ksft_skip 1550 # IPv4 header UDP header VXLAN/GENEVE header Ethernet header 1551 exp_mtu=$((${ll_mtu} - 20 - 8 - 8 - 14)) 1552 else 1553 setup namespaces routing ovs_bridge ovs_${type}6 || return $ksft_skip 1554 # IPv6 header UDP header VXLAN/GENEVE header Ethernet header 1555 exp_mtu=$((${ll_mtu} - 40 - 8 - 8 - 14)) 1556 fi 1557 1558 trace "" ${type}_a "${ns_b}" ${type}_b \ 1559 "" veth_A-R1 "${ns_r1}" veth_R1-A \ 1560 "${ns_b}" veth_B-R1 "${ns_r1}" veth_R1-B \ 1561 "" ovs_br0 "" veth-A_C \ 1562 "${ns_c}" veth_C-A "" "${tun_a}" 1563 1564 if [ ${family} -eq 4 ]; then 1565 ping=ping 1566 dst=${tunnel4_b_addr} 1567 else 1568 ping=${ping6} 1569 dst=${tunnel6_b_addr} 1570 fi 1571 1572 # Create route exception by exceeding link layer MTU 1573 mtu "" veth_A-R1 $((${ll_mtu} + 1000)) 1574 mtu "" ovs_br0 $((${ll_mtu} + 1000)) 1575 mtu "" veth_A-C $((${ll_mtu} + 1000)) 1576 mtu "${ns_c}" veth_C-A $((${ll_mtu} + 1000)) 1577 mtu "${ns_r1}" veth_R1-A $((${ll_mtu} + 1000)) 1578 mtu "${ns_b}" veth_B-R1 ${ll_mtu} 1579 mtu "${ns_r1}" veth_R1-B ${ll_mtu} 1580 1581 mtu "" ${tun_a} $((${ll_mtu} + 1000)) 2>/dev/null || \ 1582 mtu "" ${type}_a $((${ll_mtu} + 1000)) 2>/dev/null 1583 mtu "${ns_b}" ${type}_b $((${ll_mtu} + 1000)) 1584 1585 run_cmd ${ns_c} ${ping} -q -M want -i 0.1 -c 20 -s $((${ll_mtu} + 500)) ${dst} || return 1 1586 1587 # Check that exceptions were created 1588 pmtu="$(route_get_dst_pmtu_from_exception "${ns_c}" ${dst})" 1589 check_pmtu_value ${exp_mtu} "${pmtu}" "exceeding link layer MTU on Open vSwitch ${type} interface" 1590} 1591 1592test_pmtu_ipv4_ovs_vxlan4_exception() { 1593 test_pmtu_ipvX_over_ovs_vxlanY_or_geneveY_exception vxlan 4 4 1594} 1595 1596test_pmtu_ipv6_ovs_vxlan4_exception() { 1597 test_pmtu_ipvX_over_ovs_vxlanY_or_geneveY_exception vxlan 6 4 1598} 1599 1600test_pmtu_ipv4_ovs_geneve4_exception() { 1601 test_pmtu_ipvX_over_ovs_vxlanY_or_geneveY_exception geneve 4 4 1602} 1603 1604test_pmtu_ipv6_ovs_geneve4_exception() { 1605 test_pmtu_ipvX_over_ovs_vxlanY_or_geneveY_exception geneve 6 4 1606} 1607 1608test_pmtu_ipv4_ovs_vxlan6_exception() { 1609 test_pmtu_ipvX_over_ovs_vxlanY_or_geneveY_exception vxlan 4 6 1610} 1611 1612test_pmtu_ipv6_ovs_vxlan6_exception() { 1613 test_pmtu_ipvX_over_ovs_vxlanY_or_geneveY_exception vxlan 6 6 1614} 1615 1616test_pmtu_ipv4_ovs_geneve6_exception() { 1617 test_pmtu_ipvX_over_ovs_vxlanY_or_geneveY_exception geneve 4 6 1618} 1619 1620test_pmtu_ipv6_ovs_geneve6_exception() { 1621 test_pmtu_ipvX_over_ovs_vxlanY_or_geneveY_exception geneve 6 6 1622} 1623 1624test_pmtu_ipvX_over_fouY_or_gueY() { 1625 inner_family=${1} 1626 outer_family=${2} 1627 encap=${3} 1628 ll_mtu=4000 1629 1630 setup namespaces routing ${encap}${outer_family}${inner_family} || return $ksft_skip 1631 trace "${ns_a}" ${encap}_a "${ns_b}" ${encap}_b \ 1632 "${ns_a}" veth_A-R1 "${ns_r1}" veth_R1-A \ 1633 "${ns_b}" veth_B-R1 "${ns_r1}" veth_R1-B 1634 1635 if [ ${inner_family} -eq 4 ]; then 1636 ping=ping 1637 dst=${tunnel4_b_addr} 1638 else 1639 ping=${ping6} 1640 dst=${tunnel6_b_addr} 1641 fi 1642 1643 if [ "${encap}" = "gue" ]; then 1644 encap_overhead=4 1645 else 1646 encap_overhead=0 1647 fi 1648 1649 if [ ${outer_family} -eq 4 ]; then 1650 # IPv4 header UDP header 1651 exp_mtu=$((${ll_mtu} - 20 - 8 - ${encap_overhead})) 1652 else 1653 # IPv6 header Option 4 UDP header 1654 exp_mtu=$((${ll_mtu} - 40 - 8 - 8 - ${encap_overhead})) 1655 fi 1656 1657 # Create route exception by exceeding link layer MTU 1658 mtu "${ns_a}" veth_A-R1 $((${ll_mtu} + 1000)) 1659 mtu "${ns_r1}" veth_R1-A $((${ll_mtu} + 1000)) 1660 mtu "${ns_b}" veth_B-R1 ${ll_mtu} 1661 mtu "${ns_r1}" veth_R1-B ${ll_mtu} 1662 1663 mtu "${ns_a}" ${encap}_a $((${ll_mtu} + 1000)) 1664 mtu "${ns_b}" ${encap}_b $((${ll_mtu} + 1000)) 1665 run_cmd ${ns_a} ${ping} -q -M want -i 0.1 -w 1 -s $((${ll_mtu} + 500)) ${dst} 1666 1667 # Check that exception was created 1668 pmtu="$(route_get_dst_pmtu_from_exception "${ns_a}" ${dst})" 1669 check_pmtu_value ${exp_mtu} "${pmtu}" "exceeding link layer MTU on ${encap} interface" 1670} 1671 1672test_pmtu_ipv4_fou4_exception() { 1673 test_pmtu_ipvX_over_fouY_or_gueY 4 4 fou 1674} 1675 1676test_pmtu_ipv6_fou4_exception() { 1677 test_pmtu_ipvX_over_fouY_or_gueY 6 4 fou 1678} 1679 1680test_pmtu_ipv4_fou6_exception() { 1681 test_pmtu_ipvX_over_fouY_or_gueY 4 6 fou 1682} 1683 1684test_pmtu_ipv6_fou6_exception() { 1685 test_pmtu_ipvX_over_fouY_or_gueY 6 6 fou 1686} 1687 1688test_pmtu_ipv4_gue4_exception() { 1689 test_pmtu_ipvX_over_fouY_or_gueY 4 4 gue 1690} 1691 1692test_pmtu_ipv6_gue4_exception() { 1693 test_pmtu_ipvX_over_fouY_or_gueY 6 4 gue 1694} 1695 1696test_pmtu_ipv4_gue6_exception() { 1697 test_pmtu_ipvX_over_fouY_or_gueY 4 6 gue 1698} 1699 1700test_pmtu_ipv6_gue6_exception() { 1701 test_pmtu_ipvX_over_fouY_or_gueY 6 6 gue 1702} 1703 1704test_pmtu_ipvX_over_ipvY_exception() { 1705 inner=${1} 1706 outer=${2} 1707 ll_mtu=4000 1708 1709 setup namespaces routing ip${inner}ip${outer} || return $ksft_skip 1710 1711 trace "${ns_a}" ip_a "${ns_b}" ip_b \ 1712 "${ns_a}" veth_A-R1 "${ns_r1}" veth_R1-A \ 1713 "${ns_b}" veth_B-R1 "${ns_r1}" veth_R1-B 1714 1715 if [ ${inner} -eq 4 ]; then 1716 ping=ping 1717 dst=${tunnel4_b_addr} 1718 else 1719 ping=${ping6} 1720 dst=${tunnel6_b_addr} 1721 fi 1722 1723 if [ ${outer} -eq 4 ]; then 1724 # IPv4 header 1725 exp_mtu=$((${ll_mtu} - 20)) 1726 else 1727 # IPv6 header Option 4 1728 exp_mtu=$((${ll_mtu} - 40 - 8)) 1729 fi 1730 1731 # Create route exception by exceeding link layer MTU 1732 mtu "${ns_a}" veth_A-R1 $((${ll_mtu} + 1000)) 1733 mtu "${ns_r1}" veth_R1-A $((${ll_mtu} + 1000)) 1734 mtu "${ns_b}" veth_B-R1 ${ll_mtu} 1735 mtu "${ns_r1}" veth_R1-B ${ll_mtu} 1736 1737 mtu "${ns_a}" ip_a $((${ll_mtu} + 1000)) || return 1738 mtu "${ns_b}" ip_b $((${ll_mtu} + 1000)) || return 1739 run_cmd ${ns_a} ${ping} -q -M want -i 0.1 -w 1 -s $((${ll_mtu} + 500)) ${dst} 1740 1741 # Check that exception was created 1742 pmtu="$(route_get_dst_pmtu_from_exception "${ns_a}" ${dst})" 1743 check_pmtu_value ${exp_mtu} "${pmtu}" "exceeding link layer MTU on ip${inner}ip${outer} interface" 1744} 1745 1746test_pmtu_ipv4_ipv4_exception() { 1747 test_pmtu_ipvX_over_ipvY_exception 4 4 1748} 1749 1750test_pmtu_ipv6_ipv4_exception() { 1751 test_pmtu_ipvX_over_ipvY_exception 6 4 1752} 1753 1754test_pmtu_ipv4_ipv6_exception() { 1755 test_pmtu_ipvX_over_ipvY_exception 4 6 1756} 1757 1758test_pmtu_ipv6_ipv6_exception() { 1759 test_pmtu_ipvX_over_ipvY_exception 6 6 1760} 1761 1762test_pmtu_vti4_exception() { 1763 setup namespaces veth vti4 xfrm4 || return $ksft_skip 1764 trace "${ns_a}" veth_a "${ns_b}" veth_b \ 1765 "${ns_a}" vti4_a "${ns_b}" vti4_b 1766 1767 veth_mtu=1500 1768 vti_mtu=$((veth_mtu - 20)) 1769 1770 # SPI SN IV ICV pad length next header 1771 esp_payload_rfc4106=$((vti_mtu - 4 - 4 - 8 - 16 - 1 - 1)) 1772 ping_payload=$((esp_payload_rfc4106 - 28)) 1773 1774 mtu "${ns_a}" veth_a ${veth_mtu} 1775 mtu "${ns_b}" veth_b ${veth_mtu} 1776 mtu "${ns_a}" vti4_a ${vti_mtu} 1777 mtu "${ns_b}" vti4_b ${vti_mtu} 1778 1779 # Send DF packet without exceeding link layer MTU, check that no 1780 # exception is created 1781 run_cmd ${ns_a} ping -q -M want -i 0.1 -w 1 -s ${ping_payload} ${tunnel4_b_addr} 1782 pmtu="$(route_get_dst_pmtu_from_exception "${ns_a}" ${tunnel4_b_addr})" 1783 check_pmtu_value "" "${pmtu}" "sending packet smaller than PMTU (IP payload length ${esp_payload_rfc4106})" || return 1 1784 1785 # Now exceed link layer MTU by one byte, check that exception is created 1786 # with the right PMTU value 1787 run_cmd ${ns_a} ping -q -M want -i 0.1 -w 1 -s $((ping_payload + 1)) ${tunnel4_b_addr} 1788 pmtu="$(route_get_dst_pmtu_from_exception "${ns_a}" ${tunnel4_b_addr})" 1789 check_pmtu_value "${esp_payload_rfc4106}" "${pmtu}" "exceeding PMTU (IP payload length $((esp_payload_rfc4106 + 1)))" 1790} 1791 1792test_pmtu_vti6_exception() { 1793 setup namespaces veth vti6 xfrm6 || return $ksft_skip 1794 trace "${ns_a}" veth_a "${ns_b}" veth_b \ 1795 "${ns_a}" vti6_a "${ns_b}" vti6_b 1796 fail=0 1797 1798 # Create route exception by exceeding link layer MTU 1799 mtu "${ns_a}" veth_a 4000 1800 mtu "${ns_b}" veth_b 4000 1801 mtu "${ns_a}" vti6_a 5000 1802 mtu "${ns_b}" vti6_b 5000 1803 run_cmd ${ns_a} ${ping6} -q -i 0.1 -w 1 -s 60000 ${tunnel6_b_addr} 1804 1805 # Check that exception was created 1806 pmtu="$(route_get_dst_pmtu_from_exception "${ns_a}" ${tunnel6_b_addr})" 1807 check_pmtu_value any "${pmtu}" "creating tunnel exceeding link layer MTU" || return 1 1808 1809 # Decrease tunnel MTU, check for PMTU decrease in route exception 1810 mtu "${ns_a}" vti6_a 3000 1811 pmtu="$(route_get_dst_pmtu_from_exception "${ns_a}" ${tunnel6_b_addr})" 1812 check_pmtu_value "3000" "${pmtu}" "decreasing tunnel MTU" || fail=1 1813 1814 # Increase tunnel MTU, check for PMTU increase in route exception 1815 mtu "${ns_a}" vti6_a 9000 1816 pmtu="$(route_get_dst_pmtu_from_exception "${ns_a}" ${tunnel6_b_addr})" 1817 check_pmtu_value "9000" "${pmtu}" "increasing tunnel MTU" || fail=1 1818 1819 return ${fail} 1820} 1821 1822test_pmtu_vti4_udp_exception() { 1823 setup namespaces veth vti4 xfrm4udp || return $ksft_skip 1824 trace "${ns_a}" veth_a "${ns_b}" veth_b \ 1825 "${ns_a}" vti4_a "${ns_b}" vti4_b 1826 1827 veth_mtu=1500 1828 vti_mtu=$((veth_mtu - 20)) 1829 1830 # UDP SPI SN IV ICV pad length next header 1831 esp_payload_rfc4106=$((vti_mtu - 8 - 4 - 4 - 8 - 16 - 1 - 1)) 1832 ping_payload=$((esp_payload_rfc4106 - 28)) 1833 1834 mtu "${ns_a}" veth_a ${veth_mtu} 1835 mtu "${ns_b}" veth_b ${veth_mtu} 1836 mtu "${ns_a}" vti4_a ${vti_mtu} 1837 mtu "${ns_b}" vti4_b ${vti_mtu} 1838 1839 # Send DF packet without exceeding link layer MTU, check that no 1840 # exception is created 1841 run_cmd ${ns_a} ping -q -M want -i 0.1 -w 1 -s ${ping_payload} ${tunnel4_b_addr} 1842 pmtu="$(route_get_dst_pmtu_from_exception "${ns_a}" ${tunnel4_b_addr})" 1843 check_pmtu_value "" "${pmtu}" "sending packet smaller than PMTU (IP payload length ${esp_payload_rfc4106})" || return 1 1844 1845 # Now exceed link layer MTU by one byte, check that exception is created 1846 # with the right PMTU value 1847 run_cmd ${ns_a} ping -q -M want -i 0.1 -w 1 -s $((ping_payload + 1)) ${tunnel4_b_addr} 1848 pmtu="$(route_get_dst_pmtu_from_exception "${ns_a}" ${tunnel4_b_addr})" 1849 check_pmtu_value "${esp_payload_rfc4106}" "${pmtu}" "exceeding PMTU (IP payload length $((esp_payload_rfc4106 + 1)))" 1850} 1851 1852test_pmtu_vti6_udp_exception() { 1853 setup namespaces veth vti6 xfrm6udp || return $ksft_skip 1854 trace "${ns_a}" veth_a "${ns_b}" veth_b \ 1855 "${ns_a}" vti6_a "${ns_b}" vti6_b 1856 fail=0 1857 1858 # Create route exception by exceeding link layer MTU 1859 mtu "${ns_a}" veth_a 4000 1860 mtu "${ns_b}" veth_b 4000 1861 mtu "${ns_a}" vti6_a 5000 1862 mtu "${ns_b}" vti6_b 5000 1863 run_cmd ${ns_a} ${ping6} -q -i 0.1 -w 1 -s 60000 ${tunnel6_b_addr} 1864 1865 # Check that exception was created 1866 pmtu="$(route_get_dst_pmtu_from_exception "${ns_a}" ${tunnel6_b_addr})" 1867 check_pmtu_value any "${pmtu}" "creating tunnel exceeding link layer MTU" || return 1 1868 1869 # Decrease tunnel MTU, check for PMTU decrease in route exception 1870 mtu "${ns_a}" vti6_a 3000 1871 pmtu="$(route_get_dst_pmtu_from_exception "${ns_a}" ${tunnel6_b_addr})" 1872 check_pmtu_value "3000" "${pmtu}" "decreasing tunnel MTU" || fail=1 1873 1874 # Increase tunnel MTU, check for PMTU increase in route exception 1875 mtu "${ns_a}" vti6_a 9000 1876 pmtu="$(route_get_dst_pmtu_from_exception "${ns_a}" ${tunnel6_b_addr})" 1877 check_pmtu_value "9000" "${pmtu}" "increasing tunnel MTU" || fail=1 1878 1879 return ${fail} 1880} 1881 1882test_pmtu_vti4_udp_routed_exception() { 1883 setup namespaces routing vti4routed xfrm4udprouted || return $ksft_skip 1884 trace "${ns_a}" veth_A-R1 "${ns_b}" veth_B-R1 \ 1885 "${ns_a}" vti4_a "${ns_b}" vti4_b 1886 1887 veth_mtu=1500 1888 vti_mtu=$((veth_mtu - 20)) 1889 1890 # UDP SPI SN IV ICV pad length next header 1891 esp_payload_rfc4106=$((vti_mtu - 8 - 4 - 4 - 8 - 16 - 1 - 1)) 1892 ping_payload=$((esp_payload_rfc4106 - 28)) 1893 1894 mtu "${ns_a}" veth_A-R1 ${veth_mtu} 1895 mtu "${ns_r1}" veth_R1-A ${veth_mtu} 1896 mtu "${ns_b}" veth_B-R1 ${veth_mtu} 1897 mtu "${ns_r1}" veth_R1-B ${veth_mtu} 1898 1899 mtu "${ns_a}" vti4_a ${vti_mtu} 1900 mtu "${ns_b}" vti4_b ${vti_mtu} 1901 1902 # Send DF packet without exceeding link layer MTU, check that no 1903 # exception is created 1904 run_cmd ${ns_a} ping -q -M want -i 0.1 -w 1 -s ${ping_payload} ${tunnel4_b_addr} 1905 pmtu="$(route_get_dst_pmtu_from_exception "${ns_a}" ${tunnel4_b_addr})" 1906 check_pmtu_value "" "${pmtu}" "sending packet smaller than PMTU (IP payload length ${esp_payload_rfc4106})" || return 1 1907 1908 # Now decrease link layer MTU by 8 bytes on R1, check that exception is created 1909 # with the right PMTU value 1910 mtu "${ns_r1}" veth_R1-B $((veth_mtu - 8)) 1911 run_cmd ${ns_a} ping -q -M want -i 0.1 -w 1 -s $((ping_payload)) ${tunnel4_b_addr} 1912 pmtu="$(route_get_dst_pmtu_from_exception "${ns_a}" ${tunnel4_b_addr})" 1913 check_pmtu_value "$((esp_payload_rfc4106 - 8))" "${pmtu}" "exceeding PMTU (IP payload length $((esp_payload_rfc4106)))" 1914} 1915 1916test_pmtu_vti6_udp_routed_exception() { 1917 setup namespaces routing vti6routed xfrm6udprouted || return $ksft_skip 1918 trace "${ns_a}" veth_A-R1 "${ns_b}" veth_B-R1 \ 1919 "${ns_a}" vti6_a "${ns_b}" vti6_b 1920 1921 veth_mtu=1500 1922 vti_mtu=$((veth_mtu - 40)) 1923 1924 # UDP SPI SN IV ICV pad length next header 1925 esp_payload_rfc4106=$((vti_mtu - 8 - 4 - 4 - 8 - 16 - 1 - 1)) 1926 ping_payload=$((esp_payload_rfc4106 - 48)) 1927 1928 mtu "${ns_a}" veth_A-R1 ${veth_mtu} 1929 mtu "${ns_r1}" veth_R1-A ${veth_mtu} 1930 mtu "${ns_b}" veth_B-R1 ${veth_mtu} 1931 mtu "${ns_r1}" veth_R1-B ${veth_mtu} 1932 1933 # mtu "${ns_a}" vti6_a ${vti_mtu} 1934 # mtu "${ns_b}" vti6_b ${vti_mtu} 1935 1936 run_cmd ${ns_a} ${ping6} -q -M want -i 0.1 -w 1 -s ${ping_payload} ${tunnel6_b_addr} 1937 1938 # Check that exception was not created 1939 pmtu="$(route_get_dst_pmtu_from_exception "${ns_a}" ${tunnel6_b_addr})" 1940 check_pmtu_value "" "${pmtu}" "sending packet smaller than PMTU (IP payload length ${esp_payload_rfc4106})" || return 1 1941 1942 # Now decrease link layer MTU by 8 bytes on R1, check that exception is created 1943 # with the right PMTU value 1944 mtu "${ns_r1}" veth_R1-B $((veth_mtu - 8)) 1945 run_cmd ${ns_a} ${ping6} -q -M want -i 0.1 -w 1 -s $((ping_payload)) ${tunnel6_b_addr} 1946 pmtu="$(route_get_dst_pmtu_from_exception "${ns_a}" ${tunnel6_b_addr})" 1947 check_pmtu_value "$((esp_payload_rfc4106 - 8))" "${pmtu}" "exceeding PMTU (IP payload length $((esp_payload_rfc4106)))" 1948 1949} 1950 1951test_pmtu_vti4_default_mtu() { 1952 setup namespaces veth vti4 || return $ksft_skip 1953 1954 # Check that MTU of vti device is MTU of veth minus IPv4 header length 1955 veth_mtu="$(link_get_mtu "${ns_a}" veth_a)" 1956 vti4_mtu="$(link_get_mtu "${ns_a}" vti4_a)" 1957 if [ $((veth_mtu - vti4_mtu)) -ne 20 ]; then 1958 err " vti MTU ${vti4_mtu} is not veth MTU ${veth_mtu} minus IPv4 header length" 1959 return 1 1960 fi 1961} 1962 1963test_pmtu_vti6_default_mtu() { 1964 setup namespaces veth vti6 || return $ksft_skip 1965 1966 # Check that MTU of vti device is MTU of veth minus IPv6 header length 1967 veth_mtu="$(link_get_mtu "${ns_a}" veth_a)" 1968 vti6_mtu="$(link_get_mtu "${ns_a}" vti6_a)" 1969 if [ $((veth_mtu - vti6_mtu)) -ne 40 ]; then 1970 err " vti MTU ${vti6_mtu} is not veth MTU ${veth_mtu} minus IPv6 header length" 1971 return 1 1972 fi 1973} 1974 1975test_pmtu_vti4_link_add_mtu() { 1976 setup namespaces || return $ksft_skip 1977 1978 run_cmd ${ns_a} ip link add vti4_a type vti local ${veth4_a_addr} remote ${veth4_b_addr} key 10 1979 [ $? -ne 0 ] && err " vti not supported" && return $ksft_skip 1980 run_cmd ${ns_a} ip link del vti4_a 1981 1982 fail=0 1983 1984 min=68 1985 max=$((65535 - 20)) 1986 # Check invalid values first 1987 for v in $((min - 1)) $((max + 1)); do 1988 run_cmd ${ns_a} ip link add vti4_a mtu ${v} type vti local ${veth4_a_addr} remote ${veth4_b_addr} key 10 1989 # This can fail, or MTU can be adjusted to a proper value 1990 [ $? -ne 0 ] && continue 1991 mtu="$(link_get_mtu "${ns_a}" vti4_a)" 1992 if [ ${mtu} -lt ${min} -o ${mtu} -gt ${max} ]; then 1993 err " vti tunnel created with invalid MTU ${mtu}" 1994 fail=1 1995 fi 1996 run_cmd ${ns_a} ip link del vti4_a 1997 done 1998 1999 # Now check valid values 2000 for v in ${min} 1300 ${max}; do 2001 run_cmd ${ns_a} ip link add vti4_a mtu ${v} type vti local ${veth4_a_addr} remote ${veth4_b_addr} key 10 2002 mtu="$(link_get_mtu "${ns_a}" vti4_a)" 2003 run_cmd ${ns_a} ip link del vti4_a 2004 if [ "${mtu}" != "${v}" ]; then 2005 err " vti MTU ${mtu} doesn't match configured value ${v}" 2006 fail=1 2007 fi 2008 done 2009 2010 return ${fail} 2011} 2012 2013test_pmtu_vti6_link_add_mtu() { 2014 setup namespaces || return $ksft_skip 2015 2016 run_cmd ${ns_a} ip link add vti6_a type vti6 local ${veth6_a_addr} remote ${veth6_b_addr} key 10 2017 [ $? -ne 0 ] && err " vti6 not supported" && return $ksft_skip 2018 run_cmd ${ns_a} ip link del vti6_a 2019 2020 fail=0 2021 2022 min=68 # vti6 can carry IPv4 packets too 2023 max=$((65535 - 40)) 2024 # Check invalid values first 2025 for v in $((min - 1)) $((max + 1)); do 2026 run_cmd ${ns_a} ip link add vti6_a mtu ${v} type vti6 local ${veth6_a_addr} remote ${veth6_b_addr} key 10 2027 # This can fail, or MTU can be adjusted to a proper value 2028 [ $? -ne 0 ] && continue 2029 mtu="$(link_get_mtu "${ns_a}" vti6_a)" 2030 if [ ${mtu} -lt ${min} -o ${mtu} -gt ${max} ]; then 2031 err " vti6 tunnel created with invalid MTU ${v}" 2032 fail=1 2033 fi 2034 run_cmd ${ns_a} ip link del vti6_a 2035 done 2036 2037 # Now check valid values 2038 for v in 68 1280 1300 $((65535 - 40)); do 2039 run_cmd ${ns_a} ip link add vti6_a mtu ${v} type vti6 local ${veth6_a_addr} remote ${veth6_b_addr} key 10 2040 mtu="$(link_get_mtu "${ns_a}" vti6_a)" 2041 run_cmd ${ns_a} ip link del vti6_a 2042 if [ "${mtu}" != "${v}" ]; then 2043 err " vti6 MTU ${mtu} doesn't match configured value ${v}" 2044 fail=1 2045 fi 2046 done 2047 2048 return ${fail} 2049} 2050 2051test_pmtu_vti6_link_change_mtu() { 2052 setup namespaces || return $ksft_skip 2053 2054 run_cmd ${ns_a} ip link add dummy0 mtu 1500 type dummy 2055 [ $? -ne 0 ] && err " dummy not supported" && return $ksft_skip 2056 run_cmd ${ns_a} ip link add dummy1 mtu 3000 type dummy 2057 run_cmd ${ns_a} ip link set dummy0 up 2058 run_cmd ${ns_a} ip link set dummy1 up 2059 2060 run_cmd ${ns_a} ip addr add ${dummy6_0_prefix}1/${dummy6_mask} dev dummy0 2061 run_cmd ${ns_a} ip addr add ${dummy6_1_prefix}1/${dummy6_mask} dev dummy1 2062 2063 fail=0 2064 2065 # Create vti6 interface bound to device, passing MTU, check it 2066 run_cmd ${ns_a} ip link add vti6_a mtu 1300 type vti6 remote ${dummy6_0_prefix}2 local ${dummy6_0_prefix}1 2067 mtu="$(link_get_mtu "${ns_a}" vti6_a)" 2068 if [ ${mtu} -ne 1300 ]; then 2069 err " vti6 MTU ${mtu} doesn't match configured value 1300" 2070 fail=1 2071 fi 2072 2073 # Move to another device with different MTU, without passing MTU, check 2074 # MTU is adjusted 2075 run_cmd ${ns_a} ip link set vti6_a type vti6 remote ${dummy6_1_prefix}2 local ${dummy6_1_prefix}1 2076 mtu="$(link_get_mtu "${ns_a}" vti6_a)" 2077 if [ ${mtu} -ne $((3000 - 40)) ]; then 2078 err " vti MTU ${mtu} is not dummy MTU 3000 minus IPv6 header length" 2079 fail=1 2080 fi 2081 2082 # Move it back, passing MTU, check MTU is not overridden 2083 run_cmd ${ns_a} ip link set vti6_a mtu 1280 type vti6 remote ${dummy6_0_prefix}2 local ${dummy6_0_prefix}1 2084 mtu="$(link_get_mtu "${ns_a}" vti6_a)" 2085 if [ ${mtu} -ne 1280 ]; then 2086 err " vti6 MTU ${mtu} doesn't match configured value 1280" 2087 fail=1 2088 fi 2089 2090 return ${fail} 2091} 2092 2093check_command() { 2094 cmd=${1} 2095 2096 if ! which ${cmd} > /dev/null 2>&1; then 2097 err " missing required command: '${cmd}'" 2098 return 1 2099 fi 2100 return 0 2101} 2102 2103check_running() { 2104 pid=${1} 2105 cmd=${2} 2106 2107 [ "$(cat /proc/${pid}/cmdline 2>/dev/null | tr -d '\0')" = "${cmd}" ] 2108} 2109 2110test_cleanup_vxlanX_exception() { 2111 outer="${1}" 2112 encap="vxlan" 2113 ll_mtu=4000 2114 2115 check_command taskset || return $ksft_skip 2116 cpu_list=$(grep -m 2 processor /proc/cpuinfo | cut -d ' ' -f 2) 2117 2118 setup namespaces routing ${encap}${outer} || return $ksft_skip 2119 trace "${ns_a}" ${encap}_a "${ns_b}" ${encap}_b \ 2120 "${ns_a}" veth_A-R1 "${ns_r1}" veth_R1-A \ 2121 "${ns_b}" veth_B-R1 "${ns_r1}" veth_R1-B 2122 2123 # Create route exception by exceeding link layer MTU 2124 mtu "${ns_a}" veth_A-R1 $((${ll_mtu} + 1000)) 2125 mtu "${ns_r1}" veth_R1-A $((${ll_mtu} + 1000)) 2126 mtu "${ns_b}" veth_B-R1 ${ll_mtu} 2127 mtu "${ns_r1}" veth_R1-B ${ll_mtu} 2128 2129 mtu "${ns_a}" ${encap}_a $((${ll_mtu} + 1000)) 2130 mtu "${ns_b}" ${encap}_b $((${ll_mtu} + 1000)) 2131 2132 # Fill exception cache for multiple CPUs (2) 2133 # we can always use inner IPv4 for that 2134 for cpu in ${cpu_list}; do 2135 run_cmd taskset --cpu-list ${cpu} ${ns_a} ping -q -M want -i 0.1 -w 1 -s $((${ll_mtu} + 500)) ${tunnel4_b_addr} 2136 done 2137 2138 ${ns_a} ip link del dev veth_A-R1 & 2139 iplink_pid=$! 2140 for i in $(seq 1 20); do 2141 check_running ${iplink_pid} "iplinkdeldevveth_A-R1" || return 0 2142 sleep 0.1 2143 done 2144 err " can't delete veth device in a timely manner, PMTU dst likely leaked" 2145 return 1 2146} 2147 2148test_cleanup_ipv6_exception() { 2149 test_cleanup_vxlanX_exception 6 2150} 2151 2152test_cleanup_ipv4_exception() { 2153 test_cleanup_vxlanX_exception 4 2154} 2155 2156run_test() { 2157 ( 2158 tname="$1" 2159 tdesc="$2" 2160 2161 unset IFS 2162 2163 # Since cleanup() relies on variables modified by this subshell, it 2164 # has to run in this context. 2165 trap cleanup EXIT 2166 2167 if [ "$VERBOSE" = "1" ]; then 2168 printf "\n##########################################################################\n\n" 2169 fi 2170 2171 eval test_${tname} 2172 ret=$? 2173 2174 if [ $ret -eq 0 ]; then 2175 printf "TEST: %-60s [ OK ]\n" "${tdesc}" 2176 elif [ $ret -eq 1 ]; then 2177 printf "TEST: %-60s [FAIL]\n" "${tdesc}" 2178 if [ "${PAUSE_ON_FAIL}" = "yes" ]; then 2179 echo 2180 echo "Pausing. Hit enter to continue" 2181 read a 2182 fi 2183 err_flush 2184 exit 1 2185 elif [ $ret -eq $ksft_skip ]; then 2186 printf "TEST: %-60s [SKIP]\n" "${tdesc}" 2187 err_flush 2188 fi 2189 2190 return $ret 2191 ) 2192 ret=$? 2193 case $ret in 2194 0) 2195 all_skipped=false 2196 [ $exitcode -eq $ksft_skip ] && exitcode=0 2197 ;; 2198 $ksft_skip) 2199 [ $all_skipped = true ] && exitcode=$ksft_skip 2200 ;; 2201 *) 2202 all_skipped=false 2203 exitcode=1 2204 ;; 2205 esac 2206 2207 return $ret 2208} 2209 2210run_test_nh() { 2211 tname="$1" 2212 tdesc="$2" 2213 2214 USE_NH=yes 2215 run_test "${tname}" "${tdesc} - nexthop objects" 2216 USE_NH=no 2217} 2218 2219test_list_flush_ipv4_exception() { 2220 setup namespaces routing || return $ksft_skip 2221 trace "${ns_a}" veth_A-R1 "${ns_r1}" veth_R1-A \ 2222 "${ns_r1}" veth_R1-B "${ns_b}" veth_B-R1 \ 2223 "${ns_a}" veth_A-R2 "${ns_r2}" veth_R2-A \ 2224 "${ns_r2}" veth_R2-B "${ns_b}" veth_B-R2 2225 2226 dst_prefix1="${prefix4}.${b_r1}." 2227 dst2="${prefix4}.${b_r2}.1" 2228 2229 # Set up initial MTU values 2230 mtu "${ns_a}" veth_A-R1 2000 2231 mtu "${ns_r1}" veth_R1-A 2000 2232 mtu "${ns_r1}" veth_R1-B 1500 2233 mtu "${ns_b}" veth_B-R1 1500 2234 2235 mtu "${ns_a}" veth_A-R2 2000 2236 mtu "${ns_r2}" veth_R2-A 2000 2237 mtu "${ns_r2}" veth_R2-B 1500 2238 mtu "${ns_b}" veth_B-R2 1500 2239 2240 fail=0 2241 2242 # Add 100 addresses for veth endpoint on B reached by default A route 2243 for i in $(seq 100 199); do 2244 run_cmd ${ns_b} ip addr add "${dst_prefix1}${i}" dev veth_B-R1 2245 done 2246 2247 # Create 100 cached route exceptions for path via R1, one via R2. Note 2248 # that with IPv4 we need to actually cause a route lookup that matches 2249 # the exception caused by ICMP, in order to actually have a cached 2250 # route, so we need to ping each destination twice 2251 for i in $(seq 100 199); do 2252 run_cmd ${ns_a} ping -q -M want -i 0.1 -c 2 -s 1800 "${dst_prefix1}${i}" 2253 done 2254 run_cmd ${ns_a} ping -q -M want -i 0.1 -c 2 -s 1800 "${dst2}" 2255 2256 if [ "$(${ns_a} ip -oneline route list cache | wc -l)" -ne 101 ]; then 2257 err " can't list cached exceptions" 2258 fail=1 2259 fi 2260 2261 run_cmd ${ns_a} ip route flush cache 2262 pmtu1="$(route_get_dst_pmtu_from_exception "${ns_a}" ${dst_prefix}1)" 2263 pmtu2="$(route_get_dst_pmtu_from_exception "${ns_a}" ${dst_prefix}2)" 2264 if [ -n "${pmtu1}" ] || [ -n "${pmtu2}" ] || \ 2265 [ -n "$(${ns_a} ip route list cache)" ]; then 2266 err " can't flush cached exceptions" 2267 fail=1 2268 fi 2269 2270 return ${fail} 2271} 2272 2273test_list_flush_ipv6_exception() { 2274 setup namespaces routing || return $ksft_skip 2275 trace "${ns_a}" veth_A-R1 "${ns_r1}" veth_R1-A \ 2276 "${ns_r1}" veth_R1-B "${ns_b}" veth_B-R1 \ 2277 "${ns_a}" veth_A-R2 "${ns_r2}" veth_R2-A \ 2278 "${ns_r2}" veth_R2-B "${ns_b}" veth_B-R2 2279 2280 dst_prefix1="${prefix6}:${b_r1}::" 2281 dst2="${prefix6}:${b_r2}::1" 2282 2283 # Set up initial MTU values 2284 mtu "${ns_a}" veth_A-R1 2000 2285 mtu "${ns_r1}" veth_R1-A 2000 2286 mtu "${ns_r1}" veth_R1-B 1500 2287 mtu "${ns_b}" veth_B-R1 1500 2288 2289 mtu "${ns_a}" veth_A-R2 2000 2290 mtu "${ns_r2}" veth_R2-A 2000 2291 mtu "${ns_r2}" veth_R2-B 1500 2292 mtu "${ns_b}" veth_B-R2 1500 2293 2294 fail=0 2295 2296 # Add 100 addresses for veth endpoint on B reached by default A route 2297 for i in $(seq 100 199); do 2298 run_cmd ${ns_b} ip addr add "${dst_prefix1}${i}" dev veth_B-R1 2299 done 2300 2301 # Create 100 cached route exceptions for path via R1, one via R2 2302 for i in $(seq 100 199); do 2303 run_cmd ${ns_a} ping -q -M want -i 0.1 -w 1 -s 1800 "${dst_prefix1}${i}" 2304 done 2305 run_cmd ${ns_a} ping -q -M want -i 0.1 -w 1 -s 1800 "${dst2}" 2306 if [ "$(${ns_a} ip -oneline -6 route list cache | wc -l)" -ne 101 ]; then 2307 err " can't list cached exceptions" 2308 fail=1 2309 fi 2310 2311 run_cmd ${ns_a} ip -6 route flush cache 2312 pmtu1="$(route_get_dst_pmtu_from_exception "${ns_a}" "${dst_prefix1}100")" 2313 pmtu2="$(route_get_dst_pmtu_from_exception "${ns_a}" ${dst2})" 2314 if [ -n "${pmtu1}" ] || [ -n "${pmtu2}" ] || \ 2315 [ -n "$(${ns_a} ip -6 route list cache)" ]; then 2316 err " can't flush cached exceptions" 2317 fail=1 2318 fi 2319 2320 return ${fail} 2321} 2322 2323test_pmtu_ipvX_route_change() { 2324 family=${1} 2325 2326 setup namespaces routing || return 2 2327 trace "${ns_a}" veth_A-R1 "${ns_r1}" veth_R1-A \ 2328 "${ns_r1}" veth_R1-B "${ns_b}" veth_B-R1 \ 2329 "${ns_a}" veth_A-R2 "${ns_r2}" veth_R2-A \ 2330 "${ns_r2}" veth_R2-B "${ns_b}" veth_B-R2 2331 2332 if [ ${family} -eq 4 ]; then 2333 ping=ping 2334 dst1="${prefix4}.${b_r1}.1" 2335 dst2="${prefix4}.${b_r2}.1" 2336 gw="${prefix4}.${a_r1}.2" 2337 else 2338 ping=${ping6} 2339 dst1="${prefix6}:${b_r1}::1" 2340 dst2="${prefix6}:${b_r2}::1" 2341 gw="${prefix6}:${a_r1}::2" 2342 fi 2343 2344 # Set up initial MTU values 2345 mtu "${ns_a}" veth_A-R1 2000 2346 mtu "${ns_r1}" veth_R1-A 2000 2347 mtu "${ns_r1}" veth_R1-B 1400 2348 mtu "${ns_b}" veth_B-R1 1400 2349 2350 mtu "${ns_a}" veth_A-R2 2000 2351 mtu "${ns_r2}" veth_R2-A 2000 2352 mtu "${ns_r2}" veth_R2-B 1500 2353 mtu "${ns_b}" veth_B-R2 1500 2354 2355 # Create route exceptions 2356 run_cmd ${ns_a} ${ping} -q -M want -i 0.1 -w 1 -s 1800 ${dst1} 2357 run_cmd ${ns_a} ${ping} -q -M want -i 0.1 -w 1 -s 1800 ${dst2} 2358 2359 # Check that exceptions have been created with the correct PMTU 2360 pmtu_1="$(route_get_dst_pmtu_from_exception "${ns_a}" ${dst1})" 2361 check_pmtu_value "1400" "${pmtu_1}" "exceeding MTU" || return 1 2362 pmtu_2="$(route_get_dst_pmtu_from_exception "${ns_a}" ${dst2})" 2363 check_pmtu_value "1500" "${pmtu_2}" "exceeding MTU" || return 1 2364 2365 # Replace the route from A to R1 2366 run_cmd ${ns_a} ip route change default via ${gw} 2367 2368 # Delete the device in A 2369 run_cmd ${ns_a} ip link del "veth_A-R1" 2370} 2371 2372test_pmtu_ipv4_route_change() { 2373 test_pmtu_ipvX_route_change 4 2374} 2375 2376test_pmtu_ipv6_route_change() { 2377 test_pmtu_ipvX_route_change 6 2378} 2379 2380test_pmtu_ipv4_mp_exceptions() { 2381 setup namespaces routing multipath || return $ksft_skip 2382 2383 trace "${ns_a}" veth_A-R1 "${ns_r1}" veth_R1-A \ 2384 "${ns_r1}" veth_R1-B "${ns_b}" veth_B-R1 \ 2385 "${ns_a}" veth_A-R2 "${ns_r2}" veth_R2-A \ 2386 "${ns_r2}" veth_R2-B "${ns_b}" veth_B-R2 2387 2388 # Set up initial MTU values 2389 mtu "${ns_a}" veth_A-R1 2000 2390 mtu "${ns_r1}" veth_R1-A 2000 2391 mtu "${ns_r1}" veth_R1-B 1500 2392 mtu "${ns_b}" veth_B-R1 1500 2393 2394 mtu "${ns_a}" veth_A-R2 2000 2395 mtu "${ns_r2}" veth_R2-A 2000 2396 mtu "${ns_r2}" veth_R2-B 1500 2397 mtu "${ns_b}" veth_B-R2 1500 2398 2399 # Ping and expect two nexthop exceptions for two routes 2400 run_cmd ${ns_a} ping -q -M want -i 0.1 -c 1 -s 1800 "${host4_b_addr}" 2401 2402 # Check that exceptions have been created with the correct PMTU 2403 pmtu_a_R1="$(route_get_dst_pmtu_from_exception "${ns_a}" "${host4_b_addr}" oif veth_A-R1)" 2404 pmtu_a_R2="$(route_get_dst_pmtu_from_exception "${ns_a}" "${host4_b_addr}" oif veth_A-R2)" 2405 2406 check_pmtu_value "1500" "${pmtu_a_R1}" "exceeding MTU (veth_A-R1)" || return 1 2407 check_pmtu_value "1500" "${pmtu_a_R2}" "exceeding MTU (veth_A-R2)" || return 1 2408} 2409 2410usage() { 2411 echo 2412 echo "$0 [OPTIONS] [TEST]..." 2413 echo "If no TEST argument is given, all tests will be run." 2414 echo 2415 echo "Options" 2416 echo " --trace: capture traffic to TEST_INTERFACE.pcap" 2417 echo 2418 echo "Available tests${tests}" 2419 exit 1 2420} 2421 2422################################################################################ 2423# 2424exitcode=0 2425desc=0 2426all_skipped=true 2427 2428while getopts :ptv o 2429do 2430 case $o in 2431 p) PAUSE_ON_FAIL=yes;; 2432 v) VERBOSE=1;; 2433 t) if which tcpdump > /dev/null 2>&1; then 2434 TRACING=1 2435 else 2436 echo "=== tcpdump not available, tracing disabled" 2437 fi 2438 ;; 2439 *) usage;; 2440 esac 2441done 2442shift $(($OPTIND-1)) 2443 2444IFS=" 2445" 2446 2447for arg do 2448 # Check first that all requested tests are available before running any 2449 command -v > /dev/null "test_${arg}" || { echo "=== Test ${arg} not found"; usage; } 2450done 2451 2452trap cleanup EXIT 2453 2454# start clean 2455cleanup 2456 2457HAVE_NH=no 2458ip nexthop ls >/dev/null 2>&1 2459[ $? -eq 0 ] && HAVE_NH=yes 2460 2461name="" 2462desc="" 2463rerun_nh=0 2464for t in ${tests}; do 2465 [ "${name}" = "" ] && name="${t}" && continue 2466 [ "${desc}" = "" ] && desc="${t}" && continue 2467 2468 if [ "${HAVE_NH}" = "yes" ]; then 2469 rerun_nh="${t}" 2470 fi 2471 2472 run_this=1 2473 for arg do 2474 [ "${arg}" != "${arg#--*}" ] && continue 2475 [ "${arg}" = "${name}" ] && run_this=1 && break 2476 run_this=0 2477 done 2478 if [ $run_this -eq 1 ]; then 2479 run_test "${name}" "${desc}" 2480 # if test was skipped no need to retry with nexthop objects 2481 [ $? -eq $ksft_skip ] && rerun_nh=0 2482 2483 if [ "${rerun_nh}" = "1" ]; then 2484 run_test_nh "${name}" "${desc}" 2485 fi 2486 fi 2487 name="" 2488 desc="" 2489 rerun_nh=0 2490done 2491 2492exit ${exitcode} 2493