1#!/bin/sh 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_vxlan4_exception 30# Set up the same network topology as pmtu_ipv4, create a VXLAN tunnel 31# over IPv4 between A and B, routed via R1. On the link between R1 and B, 32# set a MTU lower than the VXLAN MTU and the MTU on the link between A and 33# R1. Send IPv4 packets, exceeding the MTU between R1 and B, over VXLAN 34# from A to B and check that the PMTU exception is created with the right 35# value on A 36# 37# - pmtu_ipv6_vxlan4_exception 38# Same as pmtu_ipv4_vxlan4_exception, but send IPv6 packets from A to B 39# 40# - pmtu_ipv4_vxlan6_exception 41# Same as pmtu_ipv4_vxlan4_exception, but use IPv6 transport from A to B 42# 43# - pmtu_ipv6_vxlan6_exception 44# Same as pmtu_ipv4_vxlan6_exception, but send IPv6 packets from A to B 45# 46# - pmtu_ipv4_geneve4_exception 47# Same as pmtu_ipv4_vxlan4_exception, but using a GENEVE tunnel instead of 48# VXLAN 49# 50# - pmtu_ipv6_geneve4_exception 51# Same as pmtu_ipv6_vxlan4_exception, but using a GENEVE tunnel instead of 52# VXLAN 53# 54# - pmtu_ipv4_geneve6_exception 55# Same as pmtu_ipv4_vxlan6_exception, but using a GENEVE tunnel instead of 56# VXLAN 57# 58# - pmtu_ipv6_geneve6_exception 59# Same as pmtu_ipv6_vxlan6_exception, but using a GENEVE tunnel instead of 60# VXLAN 61# 62# - pmtu_ipv{4,6}_br_vxlan{4,6}_exception 63# Set up three namespaces, A, B, and C, with routing between A and B over 64# R1. R2 is unused in these tests. A has a veth connection to C, and is 65# connected to B via a VXLAN endpoint, which is directly bridged to C. 66# MTU on the B-R1 link is lower than other MTUs. 67# 68# Check that both C and A are able to communicate with B over the VXLAN 69# tunnel, and that PMTU exceptions with the correct values are created. 70# 71# segment a_r1 segment b_r1 b_r1: 4000 72# .--------------R1--------------. everything 73# C---veth A B else: 5000 74# ' bridge | 75# '---- - - - - - VXLAN - - - - - - - ' 76# 77# - pmtu_ipv{4,6}_br_geneve{4,6}_exception 78# Same as pmtu_ipv{4,6}_br_vxlan{4,6}_exception, with a GENEVE tunnel 79# instead. 80# 81# - pmtu_ipv{4,6}_ovs_vxlan{4,6}_exception 82# Set up two namespaces, B, and C, with routing between the init namespace 83# and B over R1. A and R2 are unused in these tests. The init namespace 84# has a veth connection to C, and is connected to B via a VXLAN endpoint, 85# which is handled by Open vSwitch and bridged to C. MTU on the B-R1 link 86# is lower than other MTUs. 87# 88# Check that C is able to communicate with B over the VXLAN tunnel, and 89# that PMTU exceptions with the correct values are created. 90# 91# segment a_r1 segment b_r1 b_r1: 4000 92# .--------------R1--------------. everything 93# C---veth init B else: 5000 94# '- ovs | 95# '---- - - - - - VXLAN - - - - - - - ' 96# 97# - pmtu_ipv{4,6}_ovs_geneve{4,6}_exception 98# Same as pmtu_ipv{4,6}_ovs_vxlan{4,6}_exception, with a GENEVE tunnel 99# instead. 100# 101# - pmtu_ipv{4,6}_fou{4,6}_exception 102# Same as pmtu_ipv4_vxlan4, but using a direct IPv4/IPv6 encapsulation 103# (FoU) over IPv4/IPv6, instead of VXLAN 104# 105# - pmtu_ipv{4,6}_fou{4,6}_exception 106# Same as pmtu_ipv4_vxlan4, but using a generic UDP IPv4/IPv6 107# encapsulation (GUE) over IPv4/IPv6, instead of VXLAN 108# 109# - pmtu_ipv{4,6}_ipv{4,6}_exception 110# Same as pmtu_ipv4_vxlan4, but using a IPv4/IPv6 tunnel over IPv4/IPv6, 111# instead of VXLAN 112# 113# - pmtu_vti4_exception 114# Set up vti tunnel on top of veth, with xfrm states and policies, in two 115# namespaces with matching endpoints. Check that route exception is not 116# created if link layer MTU is not exceeded, then exceed it and check that 117# exception is created with the expected PMTU. The approach described 118# below for IPv6 doesn't apply here, because, on IPv4, administrative MTU 119# changes alone won't affect PMTU 120# 121# - pmtu_vti6_exception 122# Set up vti6 tunnel on top of veth, with xfrm states and policies, in two 123# namespaces with matching endpoints. Check that route exception is 124# created by exceeding link layer MTU with ping to other endpoint. Then 125# decrease and increase MTU of tunnel, checking that route exception PMTU 126# changes accordingly 127# 128# - pmtu_vti4_default_mtu 129# Set up vti4 tunnel on top of veth, in two namespaces with matching 130# endpoints. Check that MTU assigned to vti interface is the MTU of the 131# lower layer (veth) minus additional lower layer headers (zero, for veth) 132# minus IPv4 header length 133# 134# - pmtu_vti6_default_mtu 135# Same as above, for IPv6 136# 137# - pmtu_vti4_link_add_mtu 138# Set up vti4 interface passing MTU value at link creation, check MTU is 139# configured, and that link is not created with invalid MTU values 140# 141# - pmtu_vti6_link_add_mtu 142# Same as above, for IPv6 143# 144# - pmtu_vti6_link_change_mtu 145# Set up two dummy interfaces with different MTUs, create a vti6 tunnel 146# and check that configured MTU is used on link creation and changes, and 147# that MTU is properly calculated instead when MTU is not configured from 148# userspace 149# 150# - cleanup_ipv4_exception 151# Similar to pmtu_ipv4_vxlan4_exception, but explicitly generate PMTU 152# exceptions on multiple CPUs and check that the veth device tear-down 153# happens in a timely manner 154# 155# - cleanup_ipv6_exception 156# Same as above, but use IPv6 transport from A to B 157# 158# - list_flush_ipv4_exception 159# Using the same topology as in pmtu_ipv4, create exceptions, and check 160# they are shown when listing exception caches, gone after flushing them 161# 162# - list_flush_ipv6_exception 163# Using the same topology as in pmtu_ipv6, create exceptions, and check 164# they are shown when listing exception caches, gone after flushing them 165# 166# - pmtu_ipv4_route_change 167# Use the same topology as in pmtu_ipv4, but issue a route replacement 168# command and delete the corresponding device afterward. This tests for 169# proper cleanup of the PMTU exceptions by the route replacement path. 170# Device unregistration should complete successfully 171# 172# - pmtu_ipv6_route_change 173# Same as above but with IPv6 174 175# Kselftest framework requirement - SKIP code is 4. 176ksft_skip=4 177 178PAUSE_ON_FAIL=no 179VERBOSE=0 180TRACING=0 181 182# Some systems don't have a ping6 binary anymore 183which ping6 > /dev/null 2>&1 && ping6=$(which ping6) || ping6=$(which ping) 184 185# Name Description re-run with nh 186tests=" 187 pmtu_ipv4_exception ipv4: PMTU exceptions 1 188 pmtu_ipv6_exception ipv6: PMTU exceptions 1 189 pmtu_ipv4_vxlan4_exception IPv4 over vxlan4: PMTU exceptions 1 190 pmtu_ipv6_vxlan4_exception IPv6 over vxlan4: PMTU exceptions 1 191 pmtu_ipv4_vxlan6_exception IPv4 over vxlan6: PMTU exceptions 1 192 pmtu_ipv6_vxlan6_exception IPv6 over vxlan6: PMTU exceptions 1 193 pmtu_ipv4_geneve4_exception IPv4 over geneve4: PMTU exceptions 1 194 pmtu_ipv6_geneve4_exception IPv6 over geneve4: PMTU exceptions 1 195 pmtu_ipv4_geneve6_exception IPv4 over geneve6: PMTU exceptions 1 196 pmtu_ipv6_geneve6_exception IPv6 over geneve6: PMTU exceptions 1 197 pmtu_ipv4_br_vxlan4_exception IPv4, bridged vxlan4: PMTU exceptions 1 198 pmtu_ipv6_br_vxlan4_exception IPv6, bridged vxlan4: PMTU exceptions 1 199 pmtu_ipv4_br_vxlan6_exception IPv4, bridged vxlan6: PMTU exceptions 1 200 pmtu_ipv6_br_vxlan6_exception IPv6, bridged vxlan6: PMTU exceptions 1 201 pmtu_ipv4_br_geneve4_exception IPv4, bridged geneve4: PMTU exceptions 1 202 pmtu_ipv6_br_geneve4_exception IPv6, bridged geneve4: PMTU exceptions 1 203 pmtu_ipv4_br_geneve6_exception IPv4, bridged geneve6: PMTU exceptions 1 204 pmtu_ipv6_br_geneve6_exception IPv6, bridged geneve6: PMTU exceptions 1 205 pmtu_ipv4_ovs_vxlan4_exception IPv4, OVS vxlan4: PMTU exceptions 1 206 pmtu_ipv6_ovs_vxlan4_exception IPv6, OVS vxlan4: PMTU exceptions 1 207 pmtu_ipv4_ovs_vxlan6_exception IPv4, OVS vxlan6: PMTU exceptions 1 208 pmtu_ipv6_ovs_vxlan6_exception IPv6, OVS vxlan6: PMTU exceptions 1 209 pmtu_ipv4_ovs_geneve4_exception IPv4, OVS geneve4: PMTU exceptions 1 210 pmtu_ipv6_ovs_geneve4_exception IPv6, OVS geneve4: PMTU exceptions 1 211 pmtu_ipv4_ovs_geneve6_exception IPv4, OVS geneve6: PMTU exceptions 1 212 pmtu_ipv6_ovs_geneve6_exception IPv6, OVS geneve6: PMTU exceptions 1 213 pmtu_ipv4_fou4_exception IPv4 over fou4: PMTU exceptions 1 214 pmtu_ipv6_fou4_exception IPv6 over fou4: PMTU exceptions 1 215 pmtu_ipv4_fou6_exception IPv4 over fou6: PMTU exceptions 1 216 pmtu_ipv6_fou6_exception IPv6 over fou6: PMTU exceptions 1 217 pmtu_ipv4_gue4_exception IPv4 over gue4: PMTU exceptions 1 218 pmtu_ipv6_gue4_exception IPv6 over gue4: PMTU exceptions 1 219 pmtu_ipv4_gue6_exception IPv4 over gue6: PMTU exceptions 1 220 pmtu_ipv6_gue6_exception IPv6 over gue6: PMTU exceptions 1 221 pmtu_ipv4_ipv4_exception IPv4 over IPv4: PMTU exceptions 1 222 pmtu_ipv6_ipv4_exception IPv6 over IPv4: PMTU exceptions 1 223 pmtu_ipv4_ipv6_exception IPv4 over IPv6: PMTU exceptions 1 224 pmtu_ipv6_ipv6_exception IPv6 over IPv6: PMTU exceptions 1 225 pmtu_vti6_exception vti6: PMTU exceptions 0 226 pmtu_vti4_exception vti4: PMTU exceptions 0 227 pmtu_vti4_default_mtu vti4: default MTU assignment 0 228 pmtu_vti6_default_mtu vti6: default MTU assignment 0 229 pmtu_vti4_link_add_mtu vti4: MTU setting on link creation 0 230 pmtu_vti6_link_add_mtu vti6: MTU setting on link creation 0 231 pmtu_vti6_link_change_mtu vti6: MTU changes on link changes 0 232 cleanup_ipv4_exception ipv4: cleanup of cached exceptions 1 233 cleanup_ipv6_exception ipv6: cleanup of cached exceptions 1 234 list_flush_ipv4_exception ipv4: list and flush cached exceptions 1 235 list_flush_ipv6_exception ipv6: list and flush cached exceptions 1 236 pmtu_ipv4_route_change ipv4: PMTU exception w/route replace 1 237 pmtu_ipv6_route_change ipv6: PMTU exception w/route replace 1" 238 239NS_A="ns-A" 240NS_B="ns-B" 241NS_C="ns-C" 242NS_R1="ns-R1" 243NS_R2="ns-R2" 244ns_a="ip netns exec ${NS_A}" 245ns_b="ip netns exec ${NS_B}" 246ns_c="ip netns exec ${NS_C}" 247ns_r1="ip netns exec ${NS_R1}" 248ns_r2="ip netns exec ${NS_R2}" 249 250# Addressing and routing for tests with routers: four network segments, with 251# index SEGMENT between 1 and 4, a common prefix (PREFIX4 or PREFIX6) and an 252# identifier ID, which is 1 for hosts (A and B), 2 for routers (R1 and R2). 253# Addresses are: 254# - IPv4: PREFIX4.SEGMENT.ID (/24) 255# - IPv6: PREFIX6:SEGMENT::ID (/64) 256prefix4="10.0" 257prefix6="fc00" 258a_r1=1 259a_r2=2 260b_r1=3 261b_r2=4 262# ns peer segment 263routing_addrs=" 264 A R1 ${a_r1} 265 A R2 ${a_r2} 266 B R1 ${b_r1} 267 B R2 ${b_r2} 268" 269# Traffic from A to B goes through R1 by default, and through R2, if destined to 270# B's address on the b_r2 segment. 271# Traffic from B to A goes through R1. 272# ns destination gateway 273routes=" 274 A default ${prefix4}.${a_r1}.2 275 A ${prefix4}.${b_r2}.1 ${prefix4}.${a_r2}.2 276 B default ${prefix4}.${b_r1}.2 277 278 A default ${prefix6}:${a_r1}::2 279 A ${prefix6}:${b_r2}::1 ${prefix6}:${a_r2}::2 280 B default ${prefix6}:${b_r1}::2 281" 282 283USE_NH="no" 284# ns family nh id destination gateway 285nexthops=" 286 A 4 41 ${prefix4}.${a_r1}.2 veth_A-R1 287 A 4 42 ${prefix4}.${a_r2}.2 veth_A-R2 288 B 4 41 ${prefix4}.${b_r1}.2 veth_B-R1 289 290 A 6 61 ${prefix6}:${a_r1}::2 veth_A-R1 291 A 6 62 ${prefix6}:${a_r2}::2 veth_A-R2 292 B 6 61 ${prefix6}:${b_r1}::2 veth_B-R1 293" 294 295# nexthop id correlates to id in nexthops config above 296# ns family prefix nh id 297routes_nh=" 298 A 4 default 41 299 A 4 ${prefix4}.${b_r2}.1 42 300 B 4 default 41 301 302 A 6 default 61 303 A 6 ${prefix6}:${b_r2}::1 62 304 B 6 default 61 305" 306 307veth4_a_addr="192.168.1.1" 308veth4_b_addr="192.168.1.2" 309veth4_c_addr="192.168.2.10" 310veth4_mask="24" 311veth6_a_addr="fd00:1::a" 312veth6_b_addr="fd00:1::b" 313veth6_c_addr="fd00:2::c" 314veth6_mask="64" 315 316tunnel4_a_addr="192.168.2.1" 317tunnel4_b_addr="192.168.2.2" 318tunnel4_mask="24" 319tunnel6_a_addr="fd00:2::a" 320tunnel6_b_addr="fd00:2::b" 321tunnel6_mask="64" 322 323dummy6_0_prefix="fc00:1000::" 324dummy6_1_prefix="fc00:1001::" 325dummy6_mask="64" 326 327err_buf= 328tcpdump_pids= 329 330err() { 331 err_buf="${err_buf}${1} 332" 333} 334 335err_flush() { 336 echo -n "${err_buf}" 337 err_buf= 338} 339 340run_cmd() { 341 cmd="$*" 342 343 if [ "$VERBOSE" = "1" ]; then 344 printf " COMMAND: $cmd\n" 345 fi 346 347 out="$($cmd 2>&1)" 348 rc=$? 349 if [ "$VERBOSE" = "1" -a -n "$out" ]; then 350 echo " $out" 351 echo 352 fi 353 354 return $rc 355} 356 357# Find the auto-generated name for this namespace 358nsname() { 359 eval echo \$NS_$1 360} 361 362setup_fou_or_gue() { 363 outer="${1}" 364 inner="${2}" 365 encap="${3}" 366 367 if [ "${outer}" = "4" ]; then 368 modprobe fou || return 2 369 a_addr="${prefix4}.${a_r1}.1" 370 b_addr="${prefix4}.${b_r1}.1" 371 if [ "${inner}" = "4" ]; then 372 type="ipip" 373 ipproto="4" 374 else 375 type="sit" 376 ipproto="41" 377 fi 378 else 379 modprobe fou6 || return 2 380 a_addr="${prefix6}:${a_r1}::1" 381 b_addr="${prefix6}:${b_r1}::1" 382 if [ "${inner}" = "4" ]; then 383 type="ip6tnl" 384 mode="mode ipip6" 385 ipproto="4 -6" 386 else 387 type="ip6tnl" 388 mode="mode ip6ip6" 389 ipproto="41 -6" 390 fi 391 fi 392 393 run_cmd ${ns_a} ip fou add port 5555 ipproto ${ipproto} || return 2 394 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 2 395 396 run_cmd ${ns_b} ip fou add port 5556 ipproto ${ipproto} 397 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 398 399 if [ "${inner}" = "4" ]; then 400 run_cmd ${ns_a} ip addr add ${tunnel4_a_addr}/${tunnel4_mask} dev ${encap}_a 401 run_cmd ${ns_b} ip addr add ${tunnel4_b_addr}/${tunnel4_mask} dev ${encap}_b 402 else 403 run_cmd ${ns_a} ip addr add ${tunnel6_a_addr}/${tunnel6_mask} dev ${encap}_a 404 run_cmd ${ns_b} ip addr add ${tunnel6_b_addr}/${tunnel6_mask} dev ${encap}_b 405 fi 406 407 run_cmd ${ns_a} ip link set ${encap}_a up 408 run_cmd ${ns_b} ip link set ${encap}_b up 409} 410 411setup_fou44() { 412 setup_fou_or_gue 4 4 fou 413} 414 415setup_fou46() { 416 setup_fou_or_gue 4 6 fou 417} 418 419setup_fou64() { 420 setup_fou_or_gue 6 4 fou 421} 422 423setup_fou66() { 424 setup_fou_or_gue 6 6 fou 425} 426 427setup_gue44() { 428 setup_fou_or_gue 4 4 gue 429} 430 431setup_gue46() { 432 setup_fou_or_gue 4 6 gue 433} 434 435setup_gue64() { 436 setup_fou_or_gue 6 4 gue 437} 438 439setup_gue66() { 440 setup_fou_or_gue 6 6 gue 441} 442 443setup_ipvX_over_ipvY() { 444 inner=${1} 445 outer=${2} 446 447 if [ "${outer}" -eq 4 ]; then 448 a_addr="${prefix4}.${a_r1}.1" 449 b_addr="${prefix4}.${b_r1}.1" 450 if [ "${inner}" -eq 4 ]; then 451 type="ipip" 452 mode="ipip" 453 else 454 type="sit" 455 mode="ip6ip" 456 fi 457 else 458 a_addr="${prefix6}:${a_r1}::1" 459 b_addr="${prefix6}:${b_r1}::1" 460 type="ip6tnl" 461 if [ "${inner}" -eq 4 ]; then 462 mode="ipip6" 463 else 464 mode="ip6ip6" 465 fi 466 fi 467 468 run_cmd ${ns_a} ip link add ip_a type ${type} local ${a_addr} remote ${b_addr} mode ${mode} || return 2 469 run_cmd ${ns_b} ip link add ip_b type ${type} local ${b_addr} remote ${a_addr} mode ${mode} 470 471 run_cmd ${ns_a} ip link set ip_a up 472 run_cmd ${ns_b} ip link set ip_b up 473 474 if [ "${inner}" = "4" ]; then 475 run_cmd ${ns_a} ip addr add ${tunnel4_a_addr}/${tunnel4_mask} dev ip_a 476 run_cmd ${ns_b} ip addr add ${tunnel4_b_addr}/${tunnel4_mask} dev ip_b 477 else 478 run_cmd ${ns_a} ip addr add ${tunnel6_a_addr}/${tunnel6_mask} dev ip_a 479 run_cmd ${ns_b} ip addr add ${tunnel6_b_addr}/${tunnel6_mask} dev ip_b 480 fi 481} 482 483setup_ip4ip4() { 484 setup_ipvX_over_ipvY 4 4 485} 486 487setup_ip6ip4() { 488 setup_ipvX_over_ipvY 6 4 489} 490 491setup_ip4ip6() { 492 setup_ipvX_over_ipvY 4 6 493} 494 495setup_ip6ip6() { 496 setup_ipvX_over_ipvY 6 6 497} 498 499setup_namespaces() { 500 for n in ${NS_A} ${NS_B} ${NS_C} ${NS_R1} ${NS_R2}; do 501 ip netns add ${n} || return 1 502 503 # Disable DAD, so that we don't have to wait to use the 504 # configured IPv6 addresses 505 ip netns exec ${n} sysctl -q net/ipv6/conf/default/accept_dad=0 506 done 507} 508 509setup_veth() { 510 run_cmd ${ns_a} ip link add veth_a type veth peer name veth_b || return 1 511 run_cmd ${ns_a} ip link set veth_b netns ${NS_B} 512 513 run_cmd ${ns_a} ip addr add ${veth4_a_addr}/${veth4_mask} dev veth_a 514 run_cmd ${ns_b} ip addr add ${veth4_b_addr}/${veth4_mask} dev veth_b 515 516 run_cmd ${ns_a} ip addr add ${veth6_a_addr}/${veth6_mask} dev veth_a 517 run_cmd ${ns_b} ip addr add ${veth6_b_addr}/${veth6_mask} dev veth_b 518 519 run_cmd ${ns_a} ip link set veth_a up 520 run_cmd ${ns_b} ip link set veth_b up 521} 522 523setup_vti() { 524 proto=${1} 525 veth_a_addr="${2}" 526 veth_b_addr="${3}" 527 vti_a_addr="${4}" 528 vti_b_addr="${5}" 529 vti_mask=${6} 530 531 [ ${proto} -eq 6 ] && vti_type="vti6" || vti_type="vti" 532 533 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 534 run_cmd ${ns_b} ip link add vti${proto}_b type ${vti_type} local ${veth_b_addr} remote ${veth_a_addr} key 10 535 536 run_cmd ${ns_a} ip addr add ${vti_a_addr}/${vti_mask} dev vti${proto}_a 537 run_cmd ${ns_b} ip addr add ${vti_b_addr}/${vti_mask} dev vti${proto}_b 538 539 run_cmd ${ns_a} ip link set vti${proto}_a up 540 run_cmd ${ns_b} ip link set vti${proto}_b up 541} 542 543setup_vti4() { 544 setup_vti 4 ${veth4_a_addr} ${veth4_b_addr} ${tunnel4_a_addr} ${tunnel4_b_addr} ${tunnel4_mask} 545} 546 547setup_vti6() { 548 setup_vti 6 ${veth6_a_addr} ${veth6_b_addr} ${tunnel6_a_addr} ${tunnel6_b_addr} ${tunnel6_mask} 549} 550 551setup_vxlan_or_geneve() { 552 type="${1}" 553 a_addr="${2}" 554 b_addr="${3}" 555 opts="${4}" 556 br_if_a="${5}" 557 558 if [ "${type}" = "vxlan" ]; then 559 opts="${opts} ttl 64 dstport 4789" 560 opts_a="local ${a_addr}" 561 opts_b="local ${b_addr}" 562 else 563 opts_a="" 564 opts_b="" 565 fi 566 567 run_cmd ${ns_a} ip link add ${type}_a type ${type} id 1 ${opts_a} remote ${b_addr} ${opts} || return 1 568 run_cmd ${ns_b} ip link add ${type}_b type ${type} id 1 ${opts_b} remote ${a_addr} ${opts} 569 570 if [ -n "${br_if_a}" ]; then 571 run_cmd ${ns_a} ip addr add ${tunnel4_a_addr}/${tunnel4_mask} dev ${br_if_a} 572 run_cmd ${ns_a} ip addr add ${tunnel6_a_addr}/${tunnel6_mask} dev ${br_if_a} 573 run_cmd ${ns_a} ip link set ${type}_a master ${br_if_a} 574 else 575 run_cmd ${ns_a} ip addr add ${tunnel4_a_addr}/${tunnel4_mask} dev ${type}_a 576 run_cmd ${ns_a} ip addr add ${tunnel6_a_addr}/${tunnel6_mask} dev ${type}_a 577 fi 578 579 run_cmd ${ns_b} ip addr add ${tunnel4_b_addr}/${tunnel4_mask} dev ${type}_b 580 run_cmd ${ns_b} ip addr add ${tunnel6_b_addr}/${tunnel6_mask} dev ${type}_b 581 582 run_cmd ${ns_a} ip link set ${type}_a up 583 run_cmd ${ns_b} ip link set ${type}_b up 584} 585 586setup_geneve4() { 587 setup_vxlan_or_geneve geneve ${prefix4}.${a_r1}.1 ${prefix4}.${b_r1}.1 "df set" 588} 589 590setup_vxlan4() { 591 setup_vxlan_or_geneve vxlan ${prefix4}.${a_r1}.1 ${prefix4}.${b_r1}.1 "df set" 592} 593 594setup_geneve6() { 595 setup_vxlan_or_geneve geneve ${prefix6}:${a_r1}::1 ${prefix6}:${b_r1}::1 "" 596} 597 598setup_vxlan6() { 599 setup_vxlan_or_geneve vxlan ${prefix6}:${a_r1}::1 ${prefix6}:${b_r1}::1 "" 600} 601 602setup_bridged_geneve4() { 603 setup_vxlan_or_geneve geneve ${prefix4}.${a_r1}.1 ${prefix4}.${b_r1}.1 "df set" "br0" 604} 605 606setup_bridged_vxlan4() { 607 setup_vxlan_or_geneve vxlan ${prefix4}.${a_r1}.1 ${prefix4}.${b_r1}.1 "df set" "br0" 608} 609 610setup_bridged_geneve6() { 611 setup_vxlan_or_geneve geneve ${prefix6}:${a_r1}::1 ${prefix6}:${b_r1}::1 "" "br0" 612} 613 614setup_bridged_vxlan6() { 615 setup_vxlan_or_geneve vxlan ${prefix6}:${a_r1}::1 ${prefix6}:${b_r1}::1 "" "br0" 616} 617 618setup_xfrm() { 619 proto=${1} 620 veth_a_addr="${2}" 621 veth_b_addr="${3}" 622 623 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 || return 1 624 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 625 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 626 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 627 628 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 629 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 630 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 631 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 632} 633 634setup_xfrm4() { 635 setup_xfrm 4 ${veth4_a_addr} ${veth4_b_addr} 636} 637 638setup_xfrm6() { 639 setup_xfrm 6 ${veth6_a_addr} ${veth6_b_addr} 640} 641 642setup_routing_old() { 643 for i in ${routes}; do 644 [ "${ns}" = "" ] && ns="${i}" && continue 645 [ "${addr}" = "" ] && addr="${i}" && continue 646 [ "${gw}" = "" ] && gw="${i}" 647 648 ns_name="$(nsname ${ns})" 649 650 ip -n ${ns_name} route add ${addr} via ${gw} 651 652 ns=""; addr=""; gw="" 653 done 654} 655 656setup_routing_new() { 657 for i in ${nexthops}; do 658 [ "${ns}" = "" ] && ns="${i}" && continue 659 [ "${fam}" = "" ] && fam="${i}" && continue 660 [ "${nhid}" = "" ] && nhid="${i}" && continue 661 [ "${gw}" = "" ] && gw="${i}" && continue 662 [ "${dev}" = "" ] && dev="${i}" 663 664 ns_name="$(nsname ${ns})" 665 666 ip -n ${ns_name} -${fam} nexthop add id ${nhid} via ${gw} dev ${dev} 667 668 ns=""; fam=""; nhid=""; gw=""; dev="" 669 670 done 671 672 for i in ${routes_nh}; do 673 [ "${ns}" = "" ] && ns="${i}" && continue 674 [ "${fam}" = "" ] && fam="${i}" && continue 675 [ "${addr}" = "" ] && addr="${i}" && continue 676 [ "${nhid}" = "" ] && nhid="${i}" 677 678 ns_name="$(nsname ${ns})" 679 680 ip -n ${ns_name} -${fam} route add ${addr} nhid ${nhid} 681 682 ns=""; fam=""; addr=""; nhid="" 683 done 684} 685 686setup_routing() { 687 for i in ${NS_R1} ${NS_R2}; do 688 ip netns exec ${i} sysctl -q net/ipv4/ip_forward=1 689 ip netns exec ${i} sysctl -q net/ipv6/conf/all/forwarding=1 690 done 691 692 for i in ${routing_addrs}; do 693 [ "${ns}" = "" ] && ns="${i}" && continue 694 [ "${peer}" = "" ] && peer="${i}" && continue 695 [ "${segment}" = "" ] && segment="${i}" 696 697 ns_name="$(nsname ${ns})" 698 peer_name="$(nsname ${peer})" 699 if="veth_${ns}-${peer}" 700 ifpeer="veth_${peer}-${ns}" 701 702 # Create veth links 703 ip link add ${if} up netns ${ns_name} type veth peer name ${ifpeer} netns ${peer_name} || return 1 704 ip -n ${peer_name} link set dev ${ifpeer} up 705 706 # Add addresses 707 ip -n ${ns_name} addr add ${prefix4}.${segment}.1/24 dev ${if} 708 ip -n ${ns_name} addr add ${prefix6}:${segment}::1/64 dev ${if} 709 710 ip -n ${peer_name} addr add ${prefix4}.${segment}.2/24 dev ${ifpeer} 711 ip -n ${peer_name} addr add ${prefix6}:${segment}::2/64 dev ${ifpeer} 712 713 ns=""; peer=""; segment="" 714 done 715 716 if [ "$USE_NH" = "yes" ]; then 717 setup_routing_new 718 else 719 setup_routing_old 720 fi 721 722 return 0 723} 724 725setup_bridge() { 726 run_cmd ${ns_a} ip link add br0 type bridge || return 2 727 run_cmd ${ns_a} ip link set br0 up 728 729 run_cmd ${ns_c} ip link add veth_C-A type veth peer name veth_A-C 730 run_cmd ${ns_c} ip link set veth_A-C netns ns-A 731 732 run_cmd ${ns_a} ip link set veth_A-C up 733 run_cmd ${ns_c} ip link set veth_C-A up 734 run_cmd ${ns_c} ip addr add ${veth4_c_addr}/${veth4_mask} dev veth_C-A 735 run_cmd ${ns_c} ip addr add ${veth6_c_addr}/${veth6_mask} dev veth_C-A 736 run_cmd ${ns_a} ip link set veth_A-C master br0 737} 738 739setup_ovs_vxlan_or_geneve() { 740 type="${1}" 741 a_addr="${2}" 742 b_addr="${3}" 743 744 if [ "${type}" = "vxlan" ]; then 745 opts="${opts} ttl 64 dstport 4789" 746 opts_b="local ${b_addr}" 747 fi 748 749 run_cmd ovs-vsctl add-port ovs_br0 ${type}_a -- \ 750 set interface ${type}_a type=${type} \ 751 options:remote_ip=${b_addr} options:key=1 options:csum=true || return 1 752 753 run_cmd ${ns_b} ip link add ${type}_b type ${type} id 1 ${opts_b} remote ${a_addr} ${opts} || return 1 754 755 run_cmd ${ns_b} ip addr add ${tunnel4_b_addr}/${tunnel4_mask} dev ${type}_b 756 run_cmd ${ns_b} ip addr add ${tunnel6_b_addr}/${tunnel6_mask} dev ${type}_b 757 758 run_cmd ${ns_b} ip link set ${type}_b up 759} 760 761setup_ovs_geneve4() { 762 setup_ovs_vxlan_or_geneve geneve ${prefix4}.${a_r1}.1 ${prefix4}.${b_r1}.1 763} 764 765setup_ovs_vxlan4() { 766 setup_ovs_vxlan_or_geneve vxlan ${prefix4}.${a_r1}.1 ${prefix4}.${b_r1}.1 767} 768 769setup_ovs_geneve6() { 770 setup_ovs_vxlan_or_geneve geneve ${prefix6}:${a_r1}::1 ${prefix6}:${b_r1}::1 771} 772 773setup_ovs_vxlan6() { 774 setup_ovs_vxlan_or_geneve vxlan ${prefix6}:${a_r1}::1 ${prefix6}:${b_r1}::1 775} 776 777setup_ovs_bridge() { 778 run_cmd ovs-vsctl add-br ovs_br0 || return 2 779 run_cmd ip link set ovs_br0 up 780 781 run_cmd ${ns_c} ip link add veth_C-A type veth peer name veth_A-C 782 run_cmd ${ns_c} ip link set veth_A-C netns 1 783 784 run_cmd ip link set veth_A-C up 785 run_cmd ${ns_c} ip link set veth_C-A up 786 run_cmd ${ns_c} ip addr add ${veth4_c_addr}/${veth4_mask} dev veth_C-A 787 run_cmd ${ns_c} ip addr add ${veth6_c_addr}/${veth6_mask} dev veth_C-A 788 run_cmd ovs-vsctl add-port ovs_br0 veth_A-C 789 790 # Move veth_A-R1 to init 791 run_cmd ${ns_a} ip link set veth_A-R1 netns 1 792 run_cmd ip addr add ${prefix4}.${a_r1}.1/${veth4_mask} dev veth_A-R1 793 run_cmd ip addr add ${prefix6}:${a_r1}::1/${veth6_mask} dev veth_A-R1 794 run_cmd ip link set veth_A-R1 up 795 run_cmd ip route add ${prefix4}.${b_r1}.1 via ${prefix4}.${a_r1}.2 796 run_cmd ip route add ${prefix6}:${b_r1}::1 via ${prefix6}:${a_r1}::2 797} 798 799setup() { 800 [ "$(id -u)" -ne 0 ] && echo " need to run as root" && return $ksft_skip 801 802 for arg do 803 eval setup_${arg} || { echo " ${arg} not supported"; return 1; } 804 done 805} 806 807trace() { 808 [ $TRACING -eq 0 ] && return 809 810 for arg do 811 [ "${ns_cmd}" = "" ] && ns_cmd="${arg}" && continue 812 ${ns_cmd} tcpdump --immediate-mode -s 0 -i "${arg}" -w "${name}_${arg}.pcap" 2> /dev/null & 813 tcpdump_pids="${tcpdump_pids} $!" 814 ns_cmd= 815 done 816 sleep 1 817} 818 819cleanup() { 820 for pid in ${tcpdump_pids}; do 821 kill ${pid} 822 done 823 tcpdump_pids= 824 825 for n in ${NS_A} ${NS_B} ${NS_C} ${NS_R1} ${NS_R2}; do 826 ip netns del ${n} 2> /dev/null 827 done 828 829 ip link del veth_A-C 2>/dev/null 830 ip link del veth_A-R1 2>/dev/null 831 ovs-vsctl --if-exists del-port vxlan_a 2>/dev/null 832 ovs-vsctl --if-exists del-br ovs_br0 2>/dev/null 833} 834 835mtu() { 836 ns_cmd="${1}" 837 dev="${2}" 838 mtu="${3}" 839 840 ${ns_cmd} ip link set dev ${dev} mtu ${mtu} 841} 842 843mtu_parse() { 844 input="${1}" 845 846 next=0 847 for i in ${input}; do 848 [ ${next} -eq 1 -a "${i}" = "lock" ] && next=2 && continue 849 [ ${next} -eq 1 ] && echo "${i}" && return 850 [ ${next} -eq 2 ] && echo "lock ${i}" && return 851 [ "${i}" = "mtu" ] && next=1 852 done 853} 854 855link_get() { 856 ns_cmd="${1}" 857 name="${2}" 858 859 ${ns_cmd} ip link show dev "${name}" 860} 861 862link_get_mtu() { 863 ns_cmd="${1}" 864 name="${2}" 865 866 mtu_parse "$(link_get "${ns_cmd}" ${name})" 867} 868 869route_get_dst_exception() { 870 ns_cmd="${1}" 871 dst="${2}" 872 873 ${ns_cmd} ip route get "${dst}" 874} 875 876route_get_dst_pmtu_from_exception() { 877 ns_cmd="${1}" 878 dst="${2}" 879 880 mtu_parse "$(route_get_dst_exception "${ns_cmd}" ${dst})" 881} 882 883check_pmtu_value() { 884 expected="${1}" 885 value="${2}" 886 event="${3}" 887 888 [ "${expected}" = "any" ] && [ -n "${value}" ] && return 0 889 [ "${value}" = "${expected}" ] && return 0 890 [ -z "${value}" ] && err " PMTU exception wasn't created after ${event}" && return 1 891 [ -z "${expected}" ] && err " PMTU exception shouldn't exist after ${event}" && return 1 892 err " found PMTU exception with incorrect MTU ${value}, expected ${expected}, after ${event}" 893 return 1 894} 895 896test_pmtu_ipvX() { 897 family=${1} 898 899 setup namespaces routing || return 2 900 trace "${ns_a}" veth_A-R1 "${ns_r1}" veth_R1-A \ 901 "${ns_r1}" veth_R1-B "${ns_b}" veth_B-R1 \ 902 "${ns_a}" veth_A-R2 "${ns_r2}" veth_R2-A \ 903 "${ns_r2}" veth_R2-B "${ns_b}" veth_B-R2 904 905 if [ ${family} -eq 4 ]; then 906 ping=ping 907 dst1="${prefix4}.${b_r1}.1" 908 dst2="${prefix4}.${b_r2}.1" 909 else 910 ping=${ping6} 911 dst1="${prefix6}:${b_r1}::1" 912 dst2="${prefix6}:${b_r2}::1" 913 fi 914 915 # Set up initial MTU values 916 mtu "${ns_a}" veth_A-R1 2000 917 mtu "${ns_r1}" veth_R1-A 2000 918 mtu "${ns_r1}" veth_R1-B 1400 919 mtu "${ns_b}" veth_B-R1 1400 920 921 mtu "${ns_a}" veth_A-R2 2000 922 mtu "${ns_r2}" veth_R2-A 2000 923 mtu "${ns_r2}" veth_R2-B 1500 924 mtu "${ns_b}" veth_B-R2 1500 925 926 # Create route exceptions 927 run_cmd ${ns_a} ${ping} -q -M want -i 0.1 -w 1 -s 1800 ${dst1} 928 run_cmd ${ns_a} ${ping} -q -M want -i 0.1 -w 1 -s 1800 ${dst2} 929 930 # Check that exceptions have been created with the correct PMTU 931 pmtu_1="$(route_get_dst_pmtu_from_exception "${ns_a}" ${dst1})" 932 check_pmtu_value "1400" "${pmtu_1}" "exceeding MTU" || return 1 933 pmtu_2="$(route_get_dst_pmtu_from_exception "${ns_a}" ${dst2})" 934 check_pmtu_value "1500" "${pmtu_2}" "exceeding MTU" || return 1 935 936 # Decrease local MTU below PMTU, check for PMTU decrease in route exception 937 mtu "${ns_a}" veth_A-R1 1300 938 mtu "${ns_r1}" veth_R1-A 1300 939 pmtu_1="$(route_get_dst_pmtu_from_exception "${ns_a}" ${dst1})" 940 check_pmtu_value "1300" "${pmtu_1}" "decreasing local MTU" || return 1 941 # Second exception shouldn't be modified 942 pmtu_2="$(route_get_dst_pmtu_from_exception "${ns_a}" ${dst2})" 943 check_pmtu_value "1500" "${pmtu_2}" "changing local MTU on a link not on this path" || return 1 944 945 # Increase MTU, check for PMTU increase in route exception 946 mtu "${ns_a}" veth_A-R1 1700 947 mtu "${ns_r1}" veth_R1-A 1700 948 pmtu_1="$(route_get_dst_pmtu_from_exception "${ns_a}" ${dst1})" 949 check_pmtu_value "1700" "${pmtu_1}" "increasing local MTU" || return 1 950 # Second exception shouldn't be modified 951 pmtu_2="$(route_get_dst_pmtu_from_exception "${ns_a}" ${dst2})" 952 check_pmtu_value "1500" "${pmtu_2}" "changing local MTU on a link not on this path" || return 1 953 954 # Skip PMTU locking tests for IPv6 955 [ $family -eq 6 ] && return 0 956 957 # Decrease remote MTU on path via R2, get new exception 958 mtu "${ns_r2}" veth_R2-B 400 959 mtu "${ns_b}" veth_B-R2 400 960 run_cmd ${ns_a} ${ping} -q -M want -i 0.1 -w 1 -s 1400 ${dst2} 961 pmtu_2="$(route_get_dst_pmtu_from_exception "${ns_a}" ${dst2})" 962 check_pmtu_value "lock 552" "${pmtu_2}" "exceeding MTU, with MTU < min_pmtu" || return 1 963 964 # Decrease local MTU below PMTU 965 mtu "${ns_a}" veth_A-R2 500 966 mtu "${ns_r2}" veth_R2-A 500 967 pmtu_2="$(route_get_dst_pmtu_from_exception "${ns_a}" ${dst2})" 968 check_pmtu_value "500" "${pmtu_2}" "decreasing local MTU" || return 1 969 970 # Increase local MTU 971 mtu "${ns_a}" veth_A-R2 1500 972 mtu "${ns_r2}" veth_R2-A 1500 973 pmtu_2="$(route_get_dst_pmtu_from_exception "${ns_a}" ${dst2})" 974 check_pmtu_value "1500" "${pmtu_2}" "increasing local MTU" || return 1 975 976 # Get new exception 977 run_cmd ${ns_a} ${ping} -q -M want -i 0.1 -w 1 -s 1400 ${dst2} 978 pmtu_2="$(route_get_dst_pmtu_from_exception "${ns_a}" ${dst2})" 979 check_pmtu_value "lock 552" "${pmtu_2}" "exceeding MTU, with MTU < min_pmtu" || return 1 980} 981 982test_pmtu_ipv4_exception() { 983 test_pmtu_ipvX 4 984} 985 986test_pmtu_ipv6_exception() { 987 test_pmtu_ipvX 6 988} 989 990test_pmtu_ipvX_over_vxlanY_or_geneveY_exception() { 991 type=${1} 992 family=${2} 993 outer_family=${3} 994 ll_mtu=4000 995 996 if [ ${outer_family} -eq 4 ]; then 997 setup namespaces routing ${type}4 || return 2 998 # IPv4 header UDP header VXLAN/GENEVE header Ethernet header 999 exp_mtu=$((${ll_mtu} - 20 - 8 - 8 - 14)) 1000 else 1001 setup namespaces routing ${type}6 || return 2 1002 # IPv6 header UDP header VXLAN/GENEVE header Ethernet header 1003 exp_mtu=$((${ll_mtu} - 40 - 8 - 8 - 14)) 1004 fi 1005 1006 trace "${ns_a}" ${type}_a "${ns_b}" ${type}_b \ 1007 "${ns_a}" veth_A-R1 "${ns_r1}" veth_R1-A \ 1008 "${ns_b}" veth_B-R1 "${ns_r1}" veth_R1-B 1009 1010 if [ ${family} -eq 4 ]; then 1011 ping=ping 1012 dst=${tunnel4_b_addr} 1013 else 1014 ping=${ping6} 1015 dst=${tunnel6_b_addr} 1016 fi 1017 1018 # Create route exception by exceeding link layer MTU 1019 mtu "${ns_a}" veth_A-R1 $((${ll_mtu} + 1000)) 1020 mtu "${ns_r1}" veth_R1-A $((${ll_mtu} + 1000)) 1021 mtu "${ns_b}" veth_B-R1 ${ll_mtu} 1022 mtu "${ns_r1}" veth_R1-B ${ll_mtu} 1023 1024 mtu "${ns_a}" ${type}_a $((${ll_mtu} + 1000)) 1025 mtu "${ns_b}" ${type}_b $((${ll_mtu} + 1000)) 1026 run_cmd ${ns_a} ${ping} -q -M want -i 0.1 -w 1 -s $((${ll_mtu} + 500)) ${dst} 1027 1028 # Check that exception was created 1029 pmtu="$(route_get_dst_pmtu_from_exception "${ns_a}" ${dst})" 1030 check_pmtu_value ${exp_mtu} "${pmtu}" "exceeding link layer MTU on ${type} interface" 1031} 1032 1033test_pmtu_ipv4_vxlan4_exception() { 1034 test_pmtu_ipvX_over_vxlanY_or_geneveY_exception vxlan 4 4 1035} 1036 1037test_pmtu_ipv6_vxlan4_exception() { 1038 test_pmtu_ipvX_over_vxlanY_or_geneveY_exception vxlan 6 4 1039} 1040 1041test_pmtu_ipv4_geneve4_exception() { 1042 test_pmtu_ipvX_over_vxlanY_or_geneveY_exception geneve 4 4 1043} 1044 1045test_pmtu_ipv6_geneve4_exception() { 1046 test_pmtu_ipvX_over_vxlanY_or_geneveY_exception geneve 6 4 1047} 1048 1049test_pmtu_ipv4_vxlan6_exception() { 1050 test_pmtu_ipvX_over_vxlanY_or_geneveY_exception vxlan 4 6 1051} 1052 1053test_pmtu_ipv6_vxlan6_exception() { 1054 test_pmtu_ipvX_over_vxlanY_or_geneveY_exception vxlan 6 6 1055} 1056 1057test_pmtu_ipv4_geneve6_exception() { 1058 test_pmtu_ipvX_over_vxlanY_or_geneveY_exception geneve 4 6 1059} 1060 1061test_pmtu_ipv6_geneve6_exception() { 1062 test_pmtu_ipvX_over_vxlanY_or_geneveY_exception geneve 6 6 1063} 1064 1065test_pmtu_ipvX_over_bridged_vxlanY_or_geneveY_exception() { 1066 type=${1} 1067 family=${2} 1068 outer_family=${3} 1069 ll_mtu=4000 1070 1071 if [ ${outer_family} -eq 4 ]; then 1072 setup namespaces routing bridge bridged_${type}4 || return 2 1073 # IPv4 header UDP header VXLAN/GENEVE header Ethernet header 1074 exp_mtu=$((${ll_mtu} - 20 - 8 - 8 - 14)) 1075 else 1076 setup namespaces routing bridge bridged_${type}6 || return 2 1077 # IPv6 header UDP header VXLAN/GENEVE header Ethernet header 1078 exp_mtu=$((${ll_mtu} - 40 - 8 - 8 - 14)) 1079 fi 1080 1081 trace "${ns_a}" ${type}_a "${ns_b}" ${type}_b \ 1082 "${ns_a}" veth_A-R1 "${ns_r1}" veth_R1-A \ 1083 "${ns_b}" veth_B-R1 "${ns_r1}" veth_R1-B \ 1084 "${ns_a}" br0 "${ns_a}" veth-A-C \ 1085 "${ns_c}" veth_C-A 1086 1087 if [ ${family} -eq 4 ]; then 1088 ping=ping 1089 dst=${tunnel4_b_addr} 1090 else 1091 ping=${ping6} 1092 dst=${tunnel6_b_addr} 1093 fi 1094 1095 # Create route exception by exceeding link layer MTU 1096 mtu "${ns_a}" veth_A-R1 $((${ll_mtu} + 1000)) 1097 mtu "${ns_a}" br0 $((${ll_mtu} + 1000)) 1098 mtu "${ns_a}" veth_A-C $((${ll_mtu} + 1000)) 1099 mtu "${ns_c}" veth_C-A $((${ll_mtu} + 1000)) 1100 mtu "${ns_r1}" veth_R1-A $((${ll_mtu} + 1000)) 1101 mtu "${ns_b}" veth_B-R1 ${ll_mtu} 1102 mtu "${ns_r1}" veth_R1-B ${ll_mtu} 1103 1104 mtu "${ns_a}" ${type}_a $((${ll_mtu} + 1000)) 1105 mtu "${ns_b}" ${type}_b $((${ll_mtu} + 1000)) 1106 1107 run_cmd ${ns_c} ${ping} -q -M want -i 0.1 -c 10 -s $((${ll_mtu} + 500)) ${dst} || return 1 1108 run_cmd ${ns_a} ${ping} -q -M want -i 0.1 -w 1 -s $((${ll_mtu} + 500)) ${dst} || return 1 1109 1110 # Check that exceptions were created 1111 pmtu="$(route_get_dst_pmtu_from_exception "${ns_c}" ${dst})" 1112 check_pmtu_value ${exp_mtu} "${pmtu}" "exceeding link layer MTU on bridged ${type} interface" 1113 pmtu="$(route_get_dst_pmtu_from_exception "${ns_a}" ${dst})" 1114 check_pmtu_value ${exp_mtu} "${pmtu}" "exceeding link layer MTU on locally bridged ${type} interface" 1115} 1116 1117test_pmtu_ipv4_br_vxlan4_exception() { 1118 test_pmtu_ipvX_over_bridged_vxlanY_or_geneveY_exception vxlan 4 4 1119} 1120 1121test_pmtu_ipv6_br_vxlan4_exception() { 1122 test_pmtu_ipvX_over_bridged_vxlanY_or_geneveY_exception vxlan 6 4 1123} 1124 1125test_pmtu_ipv4_br_geneve4_exception() { 1126 test_pmtu_ipvX_over_bridged_vxlanY_or_geneveY_exception geneve 4 4 1127} 1128 1129test_pmtu_ipv6_br_geneve4_exception() { 1130 test_pmtu_ipvX_over_bridged_vxlanY_or_geneveY_exception geneve 6 4 1131} 1132 1133test_pmtu_ipv4_br_vxlan6_exception() { 1134 test_pmtu_ipvX_over_bridged_vxlanY_or_geneveY_exception vxlan 4 6 1135} 1136 1137test_pmtu_ipv6_br_vxlan6_exception() { 1138 test_pmtu_ipvX_over_bridged_vxlanY_or_geneveY_exception vxlan 6 6 1139} 1140 1141test_pmtu_ipv4_br_geneve6_exception() { 1142 test_pmtu_ipvX_over_bridged_vxlanY_or_geneveY_exception geneve 4 6 1143} 1144 1145test_pmtu_ipv6_br_geneve6_exception() { 1146 test_pmtu_ipvX_over_bridged_vxlanY_or_geneveY_exception geneve 6 6 1147} 1148 1149test_pmtu_ipvX_over_ovs_vxlanY_or_geneveY_exception() { 1150 type=${1} 1151 family=${2} 1152 outer_family=${3} 1153 ll_mtu=4000 1154 1155 if [ ${outer_family} -eq 4 ]; then 1156 setup namespaces routing ovs_bridge ovs_${type}4 || return 2 1157 # IPv4 header UDP header VXLAN/GENEVE header Ethernet header 1158 exp_mtu=$((${ll_mtu} - 20 - 8 - 8 - 14)) 1159 else 1160 setup namespaces routing ovs_bridge ovs_${type}6 || return 2 1161 # IPv6 header UDP header VXLAN/GENEVE header Ethernet header 1162 exp_mtu=$((${ll_mtu} - 40 - 8 - 8 - 14)) 1163 fi 1164 1165 if [ "${type}" = "vxlan" ]; then 1166 tun_a="vxlan_sys_4789" 1167 elif [ "${type}" = "geneve" ]; then 1168 tun_a="genev_sys_6081" 1169 fi 1170 1171 trace "" "${tun_a}" "${ns_b}" ${type}_b \ 1172 "" veth_A-R1 "${ns_r1}" veth_R1-A \ 1173 "${ns_b}" veth_B-R1 "${ns_r1}" veth_R1-B \ 1174 "" ovs_br0 "" veth-A-C \ 1175 "${ns_c}" veth_C-A 1176 1177 if [ ${family} -eq 4 ]; then 1178 ping=ping 1179 dst=${tunnel4_b_addr} 1180 else 1181 ping=${ping6} 1182 dst=${tunnel6_b_addr} 1183 fi 1184 1185 # Create route exception by exceeding link layer MTU 1186 mtu "" veth_A-R1 $((${ll_mtu} + 1000)) 1187 mtu "" ovs_br0 $((${ll_mtu} + 1000)) 1188 mtu "" veth_A-C $((${ll_mtu} + 1000)) 1189 mtu "${ns_c}" veth_C-A $((${ll_mtu} + 1000)) 1190 mtu "${ns_r1}" veth_R1-A $((${ll_mtu} + 1000)) 1191 mtu "${ns_b}" veth_B-R1 ${ll_mtu} 1192 mtu "${ns_r1}" veth_R1-B ${ll_mtu} 1193 1194 mtu "" ${tun_a} $((${ll_mtu} + 1000)) 1195 mtu "${ns_b}" ${type}_b $((${ll_mtu} + 1000)) 1196 1197 run_cmd ${ns_c} ${ping} -q -M want -i 0.1 -c 20 -s $((${ll_mtu} + 500)) ${dst} || return 1 1198 1199 # Check that exceptions were created 1200 pmtu="$(route_get_dst_pmtu_from_exception "${ns_c}" ${dst})" 1201 check_pmtu_value ${exp_mtu} "${pmtu}" "exceeding link layer MTU on Open vSwitch ${type} interface" 1202} 1203 1204test_pmtu_ipv4_ovs_vxlan4_exception() { 1205 test_pmtu_ipvX_over_ovs_vxlanY_or_geneveY_exception vxlan 4 4 1206} 1207 1208test_pmtu_ipv6_ovs_vxlan4_exception() { 1209 test_pmtu_ipvX_over_ovs_vxlanY_or_geneveY_exception vxlan 6 4 1210} 1211 1212test_pmtu_ipv4_ovs_geneve4_exception() { 1213 test_pmtu_ipvX_over_ovs_vxlanY_or_geneveY_exception geneve 4 4 1214} 1215 1216test_pmtu_ipv6_ovs_geneve4_exception() { 1217 test_pmtu_ipvX_over_ovs_vxlanY_or_geneveY_exception geneve 6 4 1218} 1219 1220test_pmtu_ipv4_ovs_vxlan6_exception() { 1221 test_pmtu_ipvX_over_ovs_vxlanY_or_geneveY_exception vxlan 4 6 1222} 1223 1224test_pmtu_ipv6_ovs_vxlan6_exception() { 1225 test_pmtu_ipvX_over_ovs_vxlanY_or_geneveY_exception vxlan 6 6 1226} 1227 1228test_pmtu_ipv4_ovs_geneve6_exception() { 1229 test_pmtu_ipvX_over_ovs_vxlanY_or_geneveY_exception geneve 4 6 1230} 1231 1232test_pmtu_ipv6_ovs_geneve6_exception() { 1233 test_pmtu_ipvX_over_ovs_vxlanY_or_geneveY_exception geneve 6 6 1234} 1235 1236test_pmtu_ipvX_over_fouY_or_gueY() { 1237 inner_family=${1} 1238 outer_family=${2} 1239 encap=${3} 1240 ll_mtu=4000 1241 1242 setup namespaces routing ${encap}${outer_family}${inner_family} || return 2 1243 trace "${ns_a}" ${encap}_a "${ns_b}" ${encap}_b \ 1244 "${ns_a}" veth_A-R1 "${ns_r1}" veth_R1-A \ 1245 "${ns_b}" veth_B-R1 "${ns_r1}" veth_R1-B 1246 1247 if [ ${inner_family} -eq 4 ]; then 1248 ping=ping 1249 dst=${tunnel4_b_addr} 1250 else 1251 ping=${ping6} 1252 dst=${tunnel6_b_addr} 1253 fi 1254 1255 if [ "${encap}" = "gue" ]; then 1256 encap_overhead=4 1257 else 1258 encap_overhead=0 1259 fi 1260 1261 if [ ${outer_family} -eq 4 ]; then 1262 # IPv4 header UDP header 1263 exp_mtu=$((${ll_mtu} - 20 - 8 - ${encap_overhead})) 1264 else 1265 # IPv6 header Option 4 UDP header 1266 exp_mtu=$((${ll_mtu} - 40 - 8 - 8 - ${encap_overhead})) 1267 fi 1268 1269 # Create route exception by exceeding link layer MTU 1270 mtu "${ns_a}" veth_A-R1 $((${ll_mtu} + 1000)) 1271 mtu "${ns_r1}" veth_R1-A $((${ll_mtu} + 1000)) 1272 mtu "${ns_b}" veth_B-R1 ${ll_mtu} 1273 mtu "${ns_r1}" veth_R1-B ${ll_mtu} 1274 1275 mtu "${ns_a}" ${encap}_a $((${ll_mtu} + 1000)) 1276 mtu "${ns_b}" ${encap}_b $((${ll_mtu} + 1000)) 1277 run_cmd ${ns_a} ${ping} -q -M want -i 0.1 -w 1 -s $((${ll_mtu} + 500)) ${dst} 1278 1279 # Check that exception was created 1280 pmtu="$(route_get_dst_pmtu_from_exception "${ns_a}" ${dst})" 1281 check_pmtu_value ${exp_mtu} "${pmtu}" "exceeding link layer MTU on ${encap} interface" 1282} 1283 1284test_pmtu_ipv4_fou4_exception() { 1285 test_pmtu_ipvX_over_fouY_or_gueY 4 4 fou 1286} 1287 1288test_pmtu_ipv6_fou4_exception() { 1289 test_pmtu_ipvX_over_fouY_or_gueY 6 4 fou 1290} 1291 1292test_pmtu_ipv4_fou6_exception() { 1293 test_pmtu_ipvX_over_fouY_or_gueY 4 6 fou 1294} 1295 1296test_pmtu_ipv6_fou6_exception() { 1297 test_pmtu_ipvX_over_fouY_or_gueY 6 6 fou 1298} 1299 1300test_pmtu_ipv4_gue4_exception() { 1301 test_pmtu_ipvX_over_fouY_or_gueY 4 4 gue 1302} 1303 1304test_pmtu_ipv6_gue4_exception() { 1305 test_pmtu_ipvX_over_fouY_or_gueY 6 4 gue 1306} 1307 1308test_pmtu_ipv4_gue6_exception() { 1309 test_pmtu_ipvX_over_fouY_or_gueY 4 6 gue 1310} 1311 1312test_pmtu_ipv6_gue6_exception() { 1313 test_pmtu_ipvX_over_fouY_or_gueY 6 6 gue 1314} 1315 1316test_pmtu_ipvX_over_ipvY_exception() { 1317 inner=${1} 1318 outer=${2} 1319 ll_mtu=4000 1320 1321 setup namespaces routing ip${inner}ip${outer} || return 2 1322 1323 trace "${ns_a}" ip_a "${ns_b}" ip_b \ 1324 "${ns_a}" veth_A-R1 "${ns_r1}" veth_R1-A \ 1325 "${ns_b}" veth_B-R1 "${ns_r1}" veth_R1-B 1326 1327 if [ ${inner} -eq 4 ]; then 1328 ping=ping 1329 dst=${tunnel4_b_addr} 1330 else 1331 ping=${ping6} 1332 dst=${tunnel6_b_addr} 1333 fi 1334 1335 if [ ${outer} -eq 4 ]; then 1336 # IPv4 header 1337 exp_mtu=$((${ll_mtu} - 20)) 1338 else 1339 # IPv6 header Option 4 1340 exp_mtu=$((${ll_mtu} - 40 - 8)) 1341 fi 1342 1343 # Create route exception by exceeding link layer MTU 1344 mtu "${ns_a}" veth_A-R1 $((${ll_mtu} + 1000)) 1345 mtu "${ns_r1}" veth_R1-A $((${ll_mtu} + 1000)) 1346 mtu "${ns_b}" veth_B-R1 ${ll_mtu} 1347 mtu "${ns_r1}" veth_R1-B ${ll_mtu} 1348 1349 mtu "${ns_a}" ip_a $((${ll_mtu} + 1000)) || return 1350 mtu "${ns_b}" ip_b $((${ll_mtu} + 1000)) || return 1351 run_cmd ${ns_a} ${ping} -q -M want -i 0.1 -w 1 -s $((${ll_mtu} + 500)) ${dst} 1352 1353 # Check that exception was created 1354 pmtu="$(route_get_dst_pmtu_from_exception "${ns_a}" ${dst})" 1355 check_pmtu_value ${exp_mtu} "${pmtu}" "exceeding link layer MTU on ip${inner}ip${outer} interface" 1356} 1357 1358test_pmtu_ipv4_ipv4_exception() { 1359 test_pmtu_ipvX_over_ipvY_exception 4 4 1360} 1361 1362test_pmtu_ipv6_ipv4_exception() { 1363 test_pmtu_ipvX_over_ipvY_exception 6 4 1364} 1365 1366test_pmtu_ipv4_ipv6_exception() { 1367 test_pmtu_ipvX_over_ipvY_exception 4 6 1368} 1369 1370test_pmtu_ipv6_ipv6_exception() { 1371 test_pmtu_ipvX_over_ipvY_exception 6 6 1372} 1373 1374test_pmtu_vti4_exception() { 1375 setup namespaces veth vti4 xfrm4 || return 2 1376 trace "${ns_a}" veth_a "${ns_b}" veth_b \ 1377 "${ns_a}" vti4_a "${ns_b}" vti4_b 1378 1379 veth_mtu=1500 1380 vti_mtu=$((veth_mtu - 20)) 1381 1382 # SPI SN IV ICV pad length next header 1383 esp_payload_rfc4106=$((vti_mtu - 4 - 4 - 8 - 16 - 1 - 1)) 1384 ping_payload=$((esp_payload_rfc4106 - 28)) 1385 1386 mtu "${ns_a}" veth_a ${veth_mtu} 1387 mtu "${ns_b}" veth_b ${veth_mtu} 1388 mtu "${ns_a}" vti4_a ${vti_mtu} 1389 mtu "${ns_b}" vti4_b ${vti_mtu} 1390 1391 # Send DF packet without exceeding link layer MTU, check that no 1392 # exception is created 1393 run_cmd ${ns_a} ping -q -M want -i 0.1 -w 1 -s ${ping_payload} ${tunnel4_b_addr} 1394 pmtu="$(route_get_dst_pmtu_from_exception "${ns_a}" ${tunnel4_b_addr})" 1395 check_pmtu_value "" "${pmtu}" "sending packet smaller than PMTU (IP payload length ${esp_payload_rfc4106})" || return 1 1396 1397 # Now exceed link layer MTU by one byte, check that exception is created 1398 # with the right PMTU value 1399 run_cmd ${ns_a} ping -q -M want -i 0.1 -w 1 -s $((ping_payload + 1)) ${tunnel4_b_addr} 1400 pmtu="$(route_get_dst_pmtu_from_exception "${ns_a}" ${tunnel4_b_addr})" 1401 check_pmtu_value "${esp_payload_rfc4106}" "${pmtu}" "exceeding PMTU (IP payload length $((esp_payload_rfc4106 + 1)))" 1402} 1403 1404test_pmtu_vti6_exception() { 1405 setup namespaces veth vti6 xfrm6 || return 2 1406 trace "${ns_a}" veth_a "${ns_b}" veth_b \ 1407 "${ns_a}" vti6_a "${ns_b}" vti6_b 1408 fail=0 1409 1410 # Create route exception by exceeding link layer MTU 1411 mtu "${ns_a}" veth_a 4000 1412 mtu "${ns_b}" veth_b 4000 1413 mtu "${ns_a}" vti6_a 5000 1414 mtu "${ns_b}" vti6_b 5000 1415 run_cmd ${ns_a} ${ping6} -q -i 0.1 -w 1 -s 60000 ${tunnel6_b_addr} 1416 1417 # Check that exception was created 1418 pmtu="$(route_get_dst_pmtu_from_exception "${ns_a}" ${tunnel6_b_addr})" 1419 check_pmtu_value any "${pmtu}" "creating tunnel exceeding link layer MTU" || return 1 1420 1421 # Decrease tunnel MTU, check for PMTU decrease in route exception 1422 mtu "${ns_a}" vti6_a 3000 1423 pmtu="$(route_get_dst_pmtu_from_exception "${ns_a}" ${tunnel6_b_addr})" 1424 check_pmtu_value "3000" "${pmtu}" "decreasing tunnel MTU" || fail=1 1425 1426 # Increase tunnel MTU, check for PMTU increase in route exception 1427 mtu "${ns_a}" vti6_a 9000 1428 pmtu="$(route_get_dst_pmtu_from_exception "${ns_a}" ${tunnel6_b_addr})" 1429 check_pmtu_value "9000" "${pmtu}" "increasing tunnel MTU" || fail=1 1430 1431 return ${fail} 1432} 1433 1434test_pmtu_vti4_default_mtu() { 1435 setup namespaces veth vti4 || return 2 1436 1437 # Check that MTU of vti device is MTU of veth minus IPv4 header length 1438 veth_mtu="$(link_get_mtu "${ns_a}" veth_a)" 1439 vti4_mtu="$(link_get_mtu "${ns_a}" vti4_a)" 1440 if [ $((veth_mtu - vti4_mtu)) -ne 20 ]; then 1441 err " vti MTU ${vti4_mtu} is not veth MTU ${veth_mtu} minus IPv4 header length" 1442 return 1 1443 fi 1444} 1445 1446test_pmtu_vti6_default_mtu() { 1447 setup namespaces veth vti6 || return 2 1448 1449 # Check that MTU of vti device is MTU of veth minus IPv6 header length 1450 veth_mtu="$(link_get_mtu "${ns_a}" veth_a)" 1451 vti6_mtu="$(link_get_mtu "${ns_a}" vti6_a)" 1452 if [ $((veth_mtu - vti6_mtu)) -ne 40 ]; then 1453 err " vti MTU ${vti6_mtu} is not veth MTU ${veth_mtu} minus IPv6 header length" 1454 return 1 1455 fi 1456} 1457 1458test_pmtu_vti4_link_add_mtu() { 1459 setup namespaces || return 2 1460 1461 run_cmd ${ns_a} ip link add vti4_a type vti local ${veth4_a_addr} remote ${veth4_b_addr} key 10 1462 [ $? -ne 0 ] && err " vti not supported" && return 2 1463 run_cmd ${ns_a} ip link del vti4_a 1464 1465 fail=0 1466 1467 min=68 1468 max=$((65535 - 20)) 1469 # Check invalid values first 1470 for v in $((min - 1)) $((max + 1)); do 1471 run_cmd ${ns_a} ip link add vti4_a mtu ${v} type vti local ${veth4_a_addr} remote ${veth4_b_addr} key 10 1472 # This can fail, or MTU can be adjusted to a proper value 1473 [ $? -ne 0 ] && continue 1474 mtu="$(link_get_mtu "${ns_a}" vti4_a)" 1475 if [ ${mtu} -lt ${min} -o ${mtu} -gt ${max} ]; then 1476 err " vti tunnel created with invalid MTU ${mtu}" 1477 fail=1 1478 fi 1479 run_cmd ${ns_a} ip link del vti4_a 1480 done 1481 1482 # Now check valid values 1483 for v in ${min} 1300 ${max}; do 1484 run_cmd ${ns_a} ip link add vti4_a mtu ${v} type vti local ${veth4_a_addr} remote ${veth4_b_addr} key 10 1485 mtu="$(link_get_mtu "${ns_a}" vti4_a)" 1486 run_cmd ${ns_a} ip link del vti4_a 1487 if [ "${mtu}" != "${v}" ]; then 1488 err " vti MTU ${mtu} doesn't match configured value ${v}" 1489 fail=1 1490 fi 1491 done 1492 1493 return ${fail} 1494} 1495 1496test_pmtu_vti6_link_add_mtu() { 1497 setup namespaces || return 2 1498 1499 run_cmd ${ns_a} ip link add vti6_a type vti6 local ${veth6_a_addr} remote ${veth6_b_addr} key 10 1500 [ $? -ne 0 ] && err " vti6 not supported" && return 2 1501 run_cmd ${ns_a} ip link del vti6_a 1502 1503 fail=0 1504 1505 min=68 # vti6 can carry IPv4 packets too 1506 max=$((65535 - 40)) 1507 # Check invalid values first 1508 for v in $((min - 1)) $((max + 1)); do 1509 run_cmd ${ns_a} ip link add vti6_a mtu ${v} type vti6 local ${veth6_a_addr} remote ${veth6_b_addr} key 10 1510 # This can fail, or MTU can be adjusted to a proper value 1511 [ $? -ne 0 ] && continue 1512 mtu="$(link_get_mtu "${ns_a}" vti6_a)" 1513 if [ ${mtu} -lt ${min} -o ${mtu} -gt ${max} ]; then 1514 err " vti6 tunnel created with invalid MTU ${v}" 1515 fail=1 1516 fi 1517 run_cmd ${ns_a} ip link del vti6_a 1518 done 1519 1520 # Now check valid values 1521 for v in 68 1280 1300 $((65535 - 40)); do 1522 run_cmd ${ns_a} ip link add vti6_a mtu ${v} type vti6 local ${veth6_a_addr} remote ${veth6_b_addr} key 10 1523 mtu="$(link_get_mtu "${ns_a}" vti6_a)" 1524 run_cmd ${ns_a} ip link del vti6_a 1525 if [ "${mtu}" != "${v}" ]; then 1526 err " vti6 MTU ${mtu} doesn't match configured value ${v}" 1527 fail=1 1528 fi 1529 done 1530 1531 return ${fail} 1532} 1533 1534test_pmtu_vti6_link_change_mtu() { 1535 setup namespaces || return 2 1536 1537 run_cmd ${ns_a} ip link add dummy0 mtu 1500 type dummy 1538 [ $? -ne 0 ] && err " dummy not supported" && return 2 1539 run_cmd ${ns_a} ip link add dummy1 mtu 3000 type dummy 1540 run_cmd ${ns_a} ip link set dummy0 up 1541 run_cmd ${ns_a} ip link set dummy1 up 1542 1543 run_cmd ${ns_a} ip addr add ${dummy6_0_prefix}1/${dummy6_mask} dev dummy0 1544 run_cmd ${ns_a} ip addr add ${dummy6_1_prefix}1/${dummy6_mask} dev dummy1 1545 1546 fail=0 1547 1548 # Create vti6 interface bound to device, passing MTU, check it 1549 run_cmd ${ns_a} ip link add vti6_a mtu 1300 type vti6 remote ${dummy6_0_prefix}2 local ${dummy6_0_prefix}1 1550 mtu="$(link_get_mtu "${ns_a}" vti6_a)" 1551 if [ ${mtu} -ne 1300 ]; then 1552 err " vti6 MTU ${mtu} doesn't match configured value 1300" 1553 fail=1 1554 fi 1555 1556 # Move to another device with different MTU, without passing MTU, check 1557 # MTU is adjusted 1558 run_cmd ${ns_a} ip link set vti6_a type vti6 remote ${dummy6_1_prefix}2 local ${dummy6_1_prefix}1 1559 mtu="$(link_get_mtu "${ns_a}" vti6_a)" 1560 if [ ${mtu} -ne $((3000 - 40)) ]; then 1561 err " vti MTU ${mtu} is not dummy MTU 3000 minus IPv6 header length" 1562 fail=1 1563 fi 1564 1565 # Move it back, passing MTU, check MTU is not overridden 1566 run_cmd ${ns_a} ip link set vti6_a mtu 1280 type vti6 remote ${dummy6_0_prefix}2 local ${dummy6_0_prefix}1 1567 mtu="$(link_get_mtu "${ns_a}" vti6_a)" 1568 if [ ${mtu} -ne 1280 ]; then 1569 err " vti6 MTU ${mtu} doesn't match configured value 1280" 1570 fail=1 1571 fi 1572 1573 return ${fail} 1574} 1575 1576check_command() { 1577 cmd=${1} 1578 1579 if ! which ${cmd} > /dev/null 2>&1; then 1580 err " missing required command: '${cmd}'" 1581 return 1 1582 fi 1583 return 0 1584} 1585 1586check_running() { 1587 pid=${1} 1588 cmd=${2} 1589 1590 [ "$(cat /proc/${pid}/cmdline 2>/dev/null | tr -d '\0')" = "{cmd}" ] 1591} 1592 1593test_cleanup_vxlanX_exception() { 1594 outer="${1}" 1595 encap="vxlan" 1596 ll_mtu=4000 1597 1598 check_command taskset || return 2 1599 cpu_list=$(grep -m 2 processor /proc/cpuinfo | cut -d ' ' -f 2) 1600 1601 setup namespaces routing ${encap}${outer} || return 2 1602 trace "${ns_a}" ${encap}_a "${ns_b}" ${encap}_b \ 1603 "${ns_a}" veth_A-R1 "${ns_r1}" veth_R1-A \ 1604 "${ns_b}" veth_B-R1 "${ns_r1}" veth_R1-B 1605 1606 # Create route exception by exceeding link layer MTU 1607 mtu "${ns_a}" veth_A-R1 $((${ll_mtu} + 1000)) 1608 mtu "${ns_r1}" veth_R1-A $((${ll_mtu} + 1000)) 1609 mtu "${ns_b}" veth_B-R1 ${ll_mtu} 1610 mtu "${ns_r1}" veth_R1-B ${ll_mtu} 1611 1612 mtu "${ns_a}" ${encap}_a $((${ll_mtu} + 1000)) 1613 mtu "${ns_b}" ${encap}_b $((${ll_mtu} + 1000)) 1614 1615 # Fill exception cache for multiple CPUs (2) 1616 # we can always use inner IPv4 for that 1617 for cpu in ${cpu_list}; do 1618 run_cmd taskset --cpu-list ${cpu} ${ns_a} ping -q -M want -i 0.1 -w 1 -s $((${ll_mtu} + 500)) ${tunnel4_b_addr} 1619 done 1620 1621 ${ns_a} ip link del dev veth_A-R1 & 1622 iplink_pid=$! 1623 for i in $(seq 1 20); do 1624 check_running ${iplink_pid} "iplinkdeldevveth_A-R1" || return 0 1625 sleep 0.1 1626 done 1627 err " can't delete veth device in a timely manner, PMTU dst likely leaked" 1628 return 1 1629} 1630 1631test_cleanup_ipv6_exception() { 1632 test_cleanup_vxlanX_exception 6 1633} 1634 1635test_cleanup_ipv4_exception() { 1636 test_cleanup_vxlanX_exception 4 1637} 1638 1639run_test() { 1640 ( 1641 tname="$1" 1642 tdesc="$2" 1643 1644 unset IFS 1645 1646 # Since cleanup() relies on variables modified by this subshell, it 1647 # has to run in this context. 1648 trap cleanup EXIT 1649 1650 if [ "$VERBOSE" = "1" ]; then 1651 printf "\n##########################################################################\n\n" 1652 fi 1653 1654 eval test_${tname} 1655 ret=$? 1656 1657 if [ $ret -eq 0 ]; then 1658 printf "TEST: %-60s [ OK ]\n" "${tdesc}" 1659 elif [ $ret -eq 1 ]; then 1660 printf "TEST: %-60s [FAIL]\n" "${tdesc}" 1661 if [ "${PAUSE_ON_FAIL}" = "yes" ]; then 1662 echo 1663 echo "Pausing. Hit enter to continue" 1664 read a 1665 fi 1666 err_flush 1667 exit 1 1668 elif [ $ret -eq 2 ]; then 1669 printf "TEST: %-60s [SKIP]\n" "${tdesc}" 1670 err_flush 1671 fi 1672 1673 return $ret 1674 ) 1675 ret=$? 1676 [ $ret -ne 0 ] && exitcode=1 1677 1678 return $ret 1679} 1680 1681run_test_nh() { 1682 tname="$1" 1683 tdesc="$2" 1684 1685 USE_NH=yes 1686 run_test "${tname}" "${tdesc} - nexthop objects" 1687 USE_NH=no 1688} 1689 1690test_list_flush_ipv4_exception() { 1691 setup namespaces routing || return 2 1692 trace "${ns_a}" veth_A-R1 "${ns_r1}" veth_R1-A \ 1693 "${ns_r1}" veth_R1-B "${ns_b}" veth_B-R1 \ 1694 "${ns_a}" veth_A-R2 "${ns_r2}" veth_R2-A \ 1695 "${ns_r2}" veth_R2-B "${ns_b}" veth_B-R2 1696 1697 dst_prefix1="${prefix4}.${b_r1}." 1698 dst2="${prefix4}.${b_r2}.1" 1699 1700 # Set up initial MTU values 1701 mtu "${ns_a}" veth_A-R1 2000 1702 mtu "${ns_r1}" veth_R1-A 2000 1703 mtu "${ns_r1}" veth_R1-B 1500 1704 mtu "${ns_b}" veth_B-R1 1500 1705 1706 mtu "${ns_a}" veth_A-R2 2000 1707 mtu "${ns_r2}" veth_R2-A 2000 1708 mtu "${ns_r2}" veth_R2-B 1500 1709 mtu "${ns_b}" veth_B-R2 1500 1710 1711 fail=0 1712 1713 # Add 100 addresses for veth endpoint on B reached by default A route 1714 for i in $(seq 100 199); do 1715 run_cmd ${ns_b} ip addr add "${dst_prefix1}${i}" dev veth_B-R1 1716 done 1717 1718 # Create 100 cached route exceptions for path via R1, one via R2. Note 1719 # that with IPv4 we need to actually cause a route lookup that matches 1720 # the exception caused by ICMP, in order to actually have a cached 1721 # route, so we need to ping each destination twice 1722 for i in $(seq 100 199); do 1723 run_cmd ${ns_a} ping -q -M want -i 0.1 -c 2 -s 1800 "${dst_prefix1}${i}" 1724 done 1725 run_cmd ${ns_a} ping -q -M want -i 0.1 -c 2 -s 1800 "${dst2}" 1726 1727 if [ "$(${ns_a} ip -oneline route list cache | wc -l)" -ne 101 ]; then 1728 err " can't list cached exceptions" 1729 fail=1 1730 fi 1731 1732 run_cmd ${ns_a} ip route flush cache 1733 pmtu1="$(route_get_dst_pmtu_from_exception "${ns_a}" ${dst_prefix}1)" 1734 pmtu2="$(route_get_dst_pmtu_from_exception "${ns_a}" ${dst_prefix}2)" 1735 if [ -n "${pmtu1}" ] || [ -n "${pmtu2}" ] || \ 1736 [ -n "$(${ns_a} ip route list cache)" ]; then 1737 err " can't flush cached exceptions" 1738 fail=1 1739 fi 1740 1741 return ${fail} 1742} 1743 1744test_list_flush_ipv6_exception() { 1745 setup namespaces routing || return 2 1746 trace "${ns_a}" veth_A-R1 "${ns_r1}" veth_R1-A \ 1747 "${ns_r1}" veth_R1-B "${ns_b}" veth_B-R1 \ 1748 "${ns_a}" veth_A-R2 "${ns_r2}" veth_R2-A \ 1749 "${ns_r2}" veth_R2-B "${ns_b}" veth_B-R2 1750 1751 dst_prefix1="${prefix6}:${b_r1}::" 1752 dst2="${prefix6}:${b_r2}::1" 1753 1754 # Set up initial MTU values 1755 mtu "${ns_a}" veth_A-R1 2000 1756 mtu "${ns_r1}" veth_R1-A 2000 1757 mtu "${ns_r1}" veth_R1-B 1500 1758 mtu "${ns_b}" veth_B-R1 1500 1759 1760 mtu "${ns_a}" veth_A-R2 2000 1761 mtu "${ns_r2}" veth_R2-A 2000 1762 mtu "${ns_r2}" veth_R2-B 1500 1763 mtu "${ns_b}" veth_B-R2 1500 1764 1765 fail=0 1766 1767 # Add 100 addresses for veth endpoint on B reached by default A route 1768 for i in $(seq 100 199); do 1769 run_cmd ${ns_b} ip addr add "${dst_prefix1}${i}" dev veth_B-R1 1770 done 1771 1772 # Create 100 cached route exceptions for path via R1, one via R2 1773 for i in $(seq 100 199); do 1774 run_cmd ${ns_a} ping -q -M want -i 0.1 -w 1 -s 1800 "${dst_prefix1}${i}" 1775 done 1776 run_cmd ${ns_a} ping -q -M want -i 0.1 -w 1 -s 1800 "${dst2}" 1777 if [ "$(${ns_a} ip -oneline -6 route list cache | wc -l)" -ne 101 ]; then 1778 err " can't list cached exceptions" 1779 fail=1 1780 fi 1781 1782 run_cmd ${ns_a} ip -6 route flush cache 1783 pmtu1="$(route_get_dst_pmtu_from_exception "${ns_a}" "${dst_prefix1}100")" 1784 pmtu2="$(route_get_dst_pmtu_from_exception "${ns_a}" ${dst2})" 1785 if [ -n "${pmtu1}" ] || [ -n "${pmtu2}" ] || \ 1786 [ -n "$(${ns_a} ip -6 route list cache)" ]; then 1787 err " can't flush cached exceptions" 1788 fail=1 1789 fi 1790 1791 return ${fail} 1792} 1793 1794test_pmtu_ipvX_route_change() { 1795 family=${1} 1796 1797 setup namespaces routing || return 2 1798 trace "${ns_a}" veth_A-R1 "${ns_r1}" veth_R1-A \ 1799 "${ns_r1}" veth_R1-B "${ns_b}" veth_B-R1 \ 1800 "${ns_a}" veth_A-R2 "${ns_r2}" veth_R2-A \ 1801 "${ns_r2}" veth_R2-B "${ns_b}" veth_B-R2 1802 1803 if [ ${family} -eq 4 ]; then 1804 ping=ping 1805 dst1="${prefix4}.${b_r1}.1" 1806 dst2="${prefix4}.${b_r2}.1" 1807 gw="${prefix4}.${a_r1}.2" 1808 else 1809 ping=${ping6} 1810 dst1="${prefix6}:${b_r1}::1" 1811 dst2="${prefix6}:${b_r2}::1" 1812 gw="${prefix6}:${a_r1}::2" 1813 fi 1814 1815 # Set up initial MTU values 1816 mtu "${ns_a}" veth_A-R1 2000 1817 mtu "${ns_r1}" veth_R1-A 2000 1818 mtu "${ns_r1}" veth_R1-B 1400 1819 mtu "${ns_b}" veth_B-R1 1400 1820 1821 mtu "${ns_a}" veth_A-R2 2000 1822 mtu "${ns_r2}" veth_R2-A 2000 1823 mtu "${ns_r2}" veth_R2-B 1500 1824 mtu "${ns_b}" veth_B-R2 1500 1825 1826 # Create route exceptions 1827 run_cmd ${ns_a} ${ping} -q -M want -i 0.1 -w 1 -s 1800 ${dst1} 1828 run_cmd ${ns_a} ${ping} -q -M want -i 0.1 -w 1 -s 1800 ${dst2} 1829 1830 # Check that exceptions have been created with the correct PMTU 1831 pmtu_1="$(route_get_dst_pmtu_from_exception "${ns_a}" ${dst1})" 1832 check_pmtu_value "1400" "${pmtu_1}" "exceeding MTU" || return 1 1833 pmtu_2="$(route_get_dst_pmtu_from_exception "${ns_a}" ${dst2})" 1834 check_pmtu_value "1500" "${pmtu_2}" "exceeding MTU" || return 1 1835 1836 # Replace the route from A to R1 1837 run_cmd ${ns_a} ip route change default via ${gw} 1838 1839 # Delete the device in A 1840 run_cmd ${ns_a} ip link del "veth_A-R1" 1841} 1842 1843test_pmtu_ipv4_route_change() { 1844 test_pmtu_ipvX_route_change 4 1845} 1846 1847test_pmtu_ipv6_route_change() { 1848 test_pmtu_ipvX_route_change 6 1849} 1850 1851usage() { 1852 echo 1853 echo "$0 [OPTIONS] [TEST]..." 1854 echo "If no TEST argument is given, all tests will be run." 1855 echo 1856 echo "Options" 1857 echo " --trace: capture traffic to TEST_INTERFACE.pcap" 1858 echo 1859 echo "Available tests${tests}" 1860 exit 1 1861} 1862 1863################################################################################ 1864# 1865exitcode=0 1866desc=0 1867 1868while getopts :ptv o 1869do 1870 case $o in 1871 p) PAUSE_ON_FAIL=yes;; 1872 v) VERBOSE=1;; 1873 t) if which tcpdump > /dev/null 2>&1; then 1874 TRACING=1 1875 else 1876 echo "=== tcpdump not available, tracing disabled" 1877 fi 1878 ;; 1879 *) usage;; 1880 esac 1881done 1882shift $(($OPTIND-1)) 1883 1884IFS=" 1885" 1886 1887for arg do 1888 # Check first that all requested tests are available before running any 1889 command -v > /dev/null "test_${arg}" || { echo "=== Test ${arg} not found"; usage; } 1890done 1891 1892trap cleanup EXIT 1893 1894# start clean 1895cleanup 1896 1897HAVE_NH=no 1898ip nexthop ls >/dev/null 2>&1 1899[ $? -eq 0 ] && HAVE_NH=yes 1900 1901name="" 1902desc="" 1903rerun_nh=0 1904for t in ${tests}; do 1905 [ "${name}" = "" ] && name="${t}" && continue 1906 [ "${desc}" = "" ] && desc="${t}" && continue 1907 1908 if [ "${HAVE_NH}" = "yes" ]; then 1909 rerun_nh="${t}" 1910 fi 1911 1912 run_this=1 1913 for arg do 1914 [ "${arg}" != "${arg#--*}" ] && continue 1915 [ "${arg}" = "${name}" ] && run_this=1 && break 1916 run_this=0 1917 done 1918 if [ $run_this -eq 1 ]; then 1919 run_test "${name}" "${desc}" 1920 # if test was skipped no need to retry with nexthop objects 1921 [ $? -eq 2 ] && rerun_nh=0 1922 1923 if [ "${rerun_nh}" = "1" ]; then 1924 run_test_nh "${name}" "${desc}" 1925 fi 1926 fi 1927 name="" 1928 desc="" 1929 rerun_nh=0 1930done 1931 1932exit ${exitcode} 1933