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