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 if ! which nettest >/dev/null; then 675 PATH=$PWD:$PATH 676 if ! which nettest >/dev/null; then 677 echo "'nettest' command not found; skipping tests" 678 return 1 679 fi 680 fi 681 682 [ ${1} -eq 6 ] && proto="-6" || proto="" 683 port=${2} 684 685 run_cmd_bg "${ns_a}" nettest "${proto}" -q -D -s -x -p "${port}" -t 5 686 nettest_pids="${nettest_pids} $!" 687 688 run_cmd_bg "${ns_b}" nettest "${proto}" -q -D -s -x -p "${port}" -t 5 689 nettest_pids="${nettest_pids} $!" 690} 691 692setup_xfrm4() { 693 setup_xfrm 4 ${veth4_a_addr} ${veth4_b_addr} 694} 695 696setup_xfrm6() { 697 setup_xfrm 6 ${veth6_a_addr} ${veth6_b_addr} 698} 699 700setup_xfrm4udp() { 701 setup_xfrm 4 ${veth4_a_addr} ${veth4_b_addr} "encap espinudp 4500 4500 0.0.0.0" && \ 702 setup_nettest_xfrm 4 4500 703} 704 705setup_xfrm6udp() { 706 setup_xfrm 6 ${veth6_a_addr} ${veth6_b_addr} "encap espinudp 4500 4500 0.0.0.0" && \ 707 setup_nettest_xfrm 6 4500 708} 709 710setup_xfrm4udprouted() { 711 setup_xfrm 4 ${prefix4}.${a_r1}.1 ${prefix4}.${b_r1}.1 "encap espinudp 4500 4500 0.0.0.0" && \ 712 setup_nettest_xfrm 4 4500 713} 714 715setup_xfrm6udprouted() { 716 setup_xfrm 6 ${prefix6}:${a_r1}::1 ${prefix6}:${b_r1}::1 "encap espinudp 4500 4500 0.0.0.0" && \ 717 setup_nettest_xfrm 6 4500 718} 719 720setup_routing_old() { 721 for i in ${routes}; do 722 [ "${ns}" = "" ] && ns="${i}" && continue 723 [ "${addr}" = "" ] && addr="${i}" && continue 724 [ "${gw}" = "" ] && gw="${i}" 725 726 ns_name="$(nsname ${ns})" 727 728 ip -n ${ns_name} route add ${addr} via ${gw} 729 730 ns=""; addr=""; gw="" 731 done 732} 733 734setup_routing_new() { 735 for i in ${nexthops}; do 736 [ "${ns}" = "" ] && ns="${i}" && continue 737 [ "${fam}" = "" ] && fam="${i}" && continue 738 [ "${nhid}" = "" ] && nhid="${i}" && continue 739 [ "${gw}" = "" ] && gw="${i}" && continue 740 [ "${dev}" = "" ] && dev="${i}" 741 742 ns_name="$(nsname ${ns})" 743 744 ip -n ${ns_name} -${fam} nexthop add id ${nhid} via ${gw} dev ${dev} 745 746 ns=""; fam=""; nhid=""; gw=""; dev="" 747 748 done 749 750 for i in ${routes_nh}; do 751 [ "${ns}" = "" ] && ns="${i}" && continue 752 [ "${fam}" = "" ] && fam="${i}" && continue 753 [ "${addr}" = "" ] && addr="${i}" && continue 754 [ "${nhid}" = "" ] && nhid="${i}" 755 756 ns_name="$(nsname ${ns})" 757 758 ip -n ${ns_name} -${fam} route add ${addr} nhid ${nhid} 759 760 ns=""; fam=""; addr=""; nhid="" 761 done 762} 763 764setup_routing() { 765 for i in ${NS_R1} ${NS_R2}; do 766 ip netns exec ${i} sysctl -q net/ipv4/ip_forward=1 767 ip netns exec ${i} sysctl -q net/ipv6/conf/all/forwarding=1 768 done 769 770 for i in ${routing_addrs}; do 771 [ "${ns}" = "" ] && ns="${i}" && continue 772 [ "${peer}" = "" ] && peer="${i}" && continue 773 [ "${segment}" = "" ] && segment="${i}" 774 775 ns_name="$(nsname ${ns})" 776 peer_name="$(nsname ${peer})" 777 if="veth_${ns}-${peer}" 778 ifpeer="veth_${peer}-${ns}" 779 780 # Create veth links 781 ip link add ${if} up netns ${ns_name} type veth peer name ${ifpeer} netns ${peer_name} || return 1 782 ip -n ${peer_name} link set dev ${ifpeer} up 783 784 # Add addresses 785 ip -n ${ns_name} addr add ${prefix4}.${segment}.1/24 dev ${if} 786 ip -n ${ns_name} addr add ${prefix6}:${segment}::1/64 dev ${if} 787 788 ip -n ${peer_name} addr add ${prefix4}.${segment}.2/24 dev ${ifpeer} 789 ip -n ${peer_name} addr add ${prefix6}:${segment}::2/64 dev ${ifpeer} 790 791 ns=""; peer=""; segment="" 792 done 793 794 if [ "$USE_NH" = "yes" ]; then 795 setup_routing_new 796 else 797 setup_routing_old 798 fi 799 800 return 0 801} 802 803setup_bridge() { 804 run_cmd ${ns_a} ip link add br0 type bridge || return $ksft_skip 805 run_cmd ${ns_a} ip link set br0 up 806 807 run_cmd ${ns_c} ip link add veth_C-A type veth peer name veth_A-C 808 run_cmd ${ns_c} ip link set veth_A-C netns ns-A 809 810 run_cmd ${ns_a} ip link set veth_A-C up 811 run_cmd ${ns_c} ip link set veth_C-A up 812 run_cmd ${ns_c} ip addr add ${veth4_c_addr}/${veth4_mask} dev veth_C-A 813 run_cmd ${ns_c} ip addr add ${veth6_c_addr}/${veth6_mask} dev veth_C-A 814 run_cmd ${ns_a} ip link set veth_A-C master br0 815} 816 817setup_ovs_vxlan_or_geneve() { 818 type="${1}" 819 a_addr="${2}" 820 b_addr="${3}" 821 822 if [ "${type}" = "vxlan" ]; then 823 opts="${opts} ttl 64 dstport 4789" 824 opts_b="local ${b_addr}" 825 fi 826 827 run_cmd ovs-vsctl add-port ovs_br0 ${type}_a -- \ 828 set interface ${type}_a type=${type} \ 829 options:remote_ip=${b_addr} options:key=1 options:csum=true || return 1 830 831 run_cmd ${ns_b} ip link add ${type}_b type ${type} id 1 ${opts_b} remote ${a_addr} ${opts} || return 1 832 833 run_cmd ${ns_b} ip addr add ${tunnel4_b_addr}/${tunnel4_mask} dev ${type}_b 834 run_cmd ${ns_b} ip addr add ${tunnel6_b_addr}/${tunnel6_mask} dev ${type}_b 835 836 run_cmd ${ns_b} ip link set ${type}_b up 837} 838 839setup_ovs_geneve4() { 840 setup_ovs_vxlan_or_geneve geneve ${prefix4}.${a_r1}.1 ${prefix4}.${b_r1}.1 841} 842 843setup_ovs_vxlan4() { 844 setup_ovs_vxlan_or_geneve vxlan ${prefix4}.${a_r1}.1 ${prefix4}.${b_r1}.1 845} 846 847setup_ovs_geneve6() { 848 setup_ovs_vxlan_or_geneve geneve ${prefix6}:${a_r1}::1 ${prefix6}:${b_r1}::1 849} 850 851setup_ovs_vxlan6() { 852 setup_ovs_vxlan_or_geneve vxlan ${prefix6}:${a_r1}::1 ${prefix6}:${b_r1}::1 853} 854 855setup_ovs_bridge() { 856 run_cmd ovs-vsctl add-br ovs_br0 || return $ksft_skip 857 run_cmd ip link set ovs_br0 up 858 859 run_cmd ${ns_c} ip link add veth_C-A type veth peer name veth_A-C 860 run_cmd ${ns_c} ip link set veth_A-C netns 1 861 862 run_cmd ip link set veth_A-C up 863 run_cmd ${ns_c} ip link set veth_C-A up 864 run_cmd ${ns_c} ip addr add ${veth4_c_addr}/${veth4_mask} dev veth_C-A 865 run_cmd ${ns_c} ip addr add ${veth6_c_addr}/${veth6_mask} dev veth_C-A 866 run_cmd ovs-vsctl add-port ovs_br0 veth_A-C 867 868 # Move veth_A-R1 to init 869 run_cmd ${ns_a} ip link set veth_A-R1 netns 1 870 run_cmd ip addr add ${prefix4}.${a_r1}.1/${veth4_mask} dev veth_A-R1 871 run_cmd ip addr add ${prefix6}:${a_r1}::1/${veth6_mask} dev veth_A-R1 872 run_cmd ip link set veth_A-R1 up 873 run_cmd ip route add ${prefix4}.${b_r1}.1 via ${prefix4}.${a_r1}.2 874 run_cmd ip route add ${prefix6}:${b_r1}::1 via ${prefix6}:${a_r1}::2 875} 876 877setup() { 878 [ "$(id -u)" -ne 0 ] && echo " need to run as root" && return $ksft_skip 879 880 for arg do 881 eval setup_${arg} || { echo " ${arg} not supported"; return 1; } 882 done 883} 884 885trace() { 886 [ $TRACING -eq 0 ] && return 887 888 for arg do 889 [ "${ns_cmd}" = "" ] && ns_cmd="${arg}" && continue 890 ${ns_cmd} tcpdump --immediate-mode -s 0 -i "${arg}" -w "${name}_${arg}.pcap" 2> /dev/null & 891 tcpdump_pids="${tcpdump_pids} $!" 892 ns_cmd= 893 done 894 sleep 1 895} 896 897cleanup() { 898 for pid in ${tcpdump_pids}; do 899 kill ${pid} 900 done 901 tcpdump_pids= 902 903 for pid in ${nettest_pids}; do 904 kill ${pid} 905 done 906 nettest_pids= 907 908 for n in ${NS_A} ${NS_B} ${NS_C} ${NS_R1} ${NS_R2}; do 909 ip netns del ${n} 2> /dev/null 910 done 911 912 ip link del veth_A-C 2>/dev/null 913 ip link del veth_A-R1 2>/dev/null 914 ovs-vsctl --if-exists del-port vxlan_a 2>/dev/null 915 ovs-vsctl --if-exists del-br ovs_br0 2>/dev/null 916} 917 918mtu() { 919 ns_cmd="${1}" 920 dev="${2}" 921 mtu="${3}" 922 923 ${ns_cmd} ip link set dev ${dev} mtu ${mtu} 924} 925 926mtu_parse() { 927 input="${1}" 928 929 next=0 930 for i in ${input}; do 931 [ ${next} -eq 1 -a "${i}" = "lock" ] && next=2 && continue 932 [ ${next} -eq 1 ] && echo "${i}" && return 933 [ ${next} -eq 2 ] && echo "lock ${i}" && return 934 [ "${i}" = "mtu" ] && next=1 935 done 936} 937 938link_get() { 939 ns_cmd="${1}" 940 name="${2}" 941 942 ${ns_cmd} ip link show dev "${name}" 943} 944 945link_get_mtu() { 946 ns_cmd="${1}" 947 name="${2}" 948 949 mtu_parse "$(link_get "${ns_cmd}" ${name})" 950} 951 952route_get_dst_exception() { 953 ns_cmd="${1}" 954 dst="${2}" 955 956 ${ns_cmd} ip route get "${dst}" 957} 958 959route_get_dst_pmtu_from_exception() { 960 ns_cmd="${1}" 961 dst="${2}" 962 963 mtu_parse "$(route_get_dst_exception "${ns_cmd}" ${dst})" 964} 965 966check_pmtu_value() { 967 expected="${1}" 968 value="${2}" 969 event="${3}" 970 971 [ "${expected}" = "any" ] && [ -n "${value}" ] && return 0 972 [ "${value}" = "${expected}" ] && return 0 973 [ -z "${value}" ] && err " PMTU exception wasn't created after ${event}" && return 1 974 [ -z "${expected}" ] && err " PMTU exception shouldn't exist after ${event}" && return 1 975 err " found PMTU exception with incorrect MTU ${value}, expected ${expected}, after ${event}" 976 return 1 977} 978 979test_pmtu_ipvX() { 980 family=${1} 981 982 setup namespaces routing || return $ksft_skip 983 trace "${ns_a}" veth_A-R1 "${ns_r1}" veth_R1-A \ 984 "${ns_r1}" veth_R1-B "${ns_b}" veth_B-R1 \ 985 "${ns_a}" veth_A-R2 "${ns_r2}" veth_R2-A \ 986 "${ns_r2}" veth_R2-B "${ns_b}" veth_B-R2 987 988 if [ ${family} -eq 4 ]; then 989 ping=ping 990 dst1="${prefix4}.${b_r1}.1" 991 dst2="${prefix4}.${b_r2}.1" 992 else 993 ping=${ping6} 994 dst1="${prefix6}:${b_r1}::1" 995 dst2="${prefix6}:${b_r2}::1" 996 fi 997 998 # Set up initial MTU values 999 mtu "${ns_a}" veth_A-R1 2000 1000 mtu "${ns_r1}" veth_R1-A 2000 1001 mtu "${ns_r1}" veth_R1-B 1400 1002 mtu "${ns_b}" veth_B-R1 1400 1003 1004 mtu "${ns_a}" veth_A-R2 2000 1005 mtu "${ns_r2}" veth_R2-A 2000 1006 mtu "${ns_r2}" veth_R2-B 1500 1007 mtu "${ns_b}" veth_B-R2 1500 1008 1009 # Create route exceptions 1010 run_cmd ${ns_a} ${ping} -q -M want -i 0.1 -w 1 -s 1800 ${dst1} 1011 run_cmd ${ns_a} ${ping} -q -M want -i 0.1 -w 1 -s 1800 ${dst2} 1012 1013 # Check that exceptions have been created with the correct PMTU 1014 pmtu_1="$(route_get_dst_pmtu_from_exception "${ns_a}" ${dst1})" 1015 check_pmtu_value "1400" "${pmtu_1}" "exceeding MTU" || return 1 1016 pmtu_2="$(route_get_dst_pmtu_from_exception "${ns_a}" ${dst2})" 1017 check_pmtu_value "1500" "${pmtu_2}" "exceeding MTU" || return 1 1018 1019 # Decrease local MTU below PMTU, check for PMTU decrease in route exception 1020 mtu "${ns_a}" veth_A-R1 1300 1021 mtu "${ns_r1}" veth_R1-A 1300 1022 pmtu_1="$(route_get_dst_pmtu_from_exception "${ns_a}" ${dst1})" 1023 check_pmtu_value "1300" "${pmtu_1}" "decreasing local MTU" || return 1 1024 # Second exception shouldn't be modified 1025 pmtu_2="$(route_get_dst_pmtu_from_exception "${ns_a}" ${dst2})" 1026 check_pmtu_value "1500" "${pmtu_2}" "changing local MTU on a link not on this path" || return 1 1027 1028 # Increase MTU, check for PMTU increase in route exception 1029 mtu "${ns_a}" veth_A-R1 1700 1030 mtu "${ns_r1}" veth_R1-A 1700 1031 pmtu_1="$(route_get_dst_pmtu_from_exception "${ns_a}" ${dst1})" 1032 check_pmtu_value "1700" "${pmtu_1}" "increasing local MTU" || return 1 1033 # Second exception shouldn't be modified 1034 pmtu_2="$(route_get_dst_pmtu_from_exception "${ns_a}" ${dst2})" 1035 check_pmtu_value "1500" "${pmtu_2}" "changing local MTU on a link not on this path" || return 1 1036 1037 # Skip PMTU locking tests for IPv6 1038 [ $family -eq 6 ] && return 0 1039 1040 # Decrease remote MTU on path via R2, get new exception 1041 mtu "${ns_r2}" veth_R2-B 400 1042 mtu "${ns_b}" veth_B-R2 400 1043 run_cmd ${ns_a} ${ping} -q -M want -i 0.1 -w 1 -s 1400 ${dst2} 1044 pmtu_2="$(route_get_dst_pmtu_from_exception "${ns_a}" ${dst2})" 1045 check_pmtu_value "lock 552" "${pmtu_2}" "exceeding MTU, with MTU < min_pmtu" || return 1 1046 1047 # Decrease local MTU below PMTU 1048 mtu "${ns_a}" veth_A-R2 500 1049 mtu "${ns_r2}" veth_R2-A 500 1050 pmtu_2="$(route_get_dst_pmtu_from_exception "${ns_a}" ${dst2})" 1051 check_pmtu_value "500" "${pmtu_2}" "decreasing local MTU" || return 1 1052 1053 # Increase local MTU 1054 mtu "${ns_a}" veth_A-R2 1500 1055 mtu "${ns_r2}" veth_R2-A 1500 1056 pmtu_2="$(route_get_dst_pmtu_from_exception "${ns_a}" ${dst2})" 1057 check_pmtu_value "1500" "${pmtu_2}" "increasing local MTU" || return 1 1058 1059 # Get new exception 1060 run_cmd ${ns_a} ${ping} -q -M want -i 0.1 -w 1 -s 1400 ${dst2} 1061 pmtu_2="$(route_get_dst_pmtu_from_exception "${ns_a}" ${dst2})" 1062 check_pmtu_value "lock 552" "${pmtu_2}" "exceeding MTU, with MTU < min_pmtu" || return 1 1063} 1064 1065test_pmtu_ipv4_exception() { 1066 test_pmtu_ipvX 4 1067} 1068 1069test_pmtu_ipv6_exception() { 1070 test_pmtu_ipvX 6 1071} 1072 1073test_pmtu_ipvX_over_vxlanY_or_geneveY_exception() { 1074 type=${1} 1075 family=${2} 1076 outer_family=${3} 1077 ll_mtu=4000 1078 1079 if [ ${outer_family} -eq 4 ]; then 1080 setup namespaces routing ${type}4 || return $ksft_skip 1081 # IPv4 header UDP header VXLAN/GENEVE header Ethernet header 1082 exp_mtu=$((${ll_mtu} - 20 - 8 - 8 - 14)) 1083 else 1084 setup namespaces routing ${type}6 || return $ksft_skip 1085 # IPv6 header UDP header VXLAN/GENEVE header Ethernet header 1086 exp_mtu=$((${ll_mtu} - 40 - 8 - 8 - 14)) 1087 fi 1088 1089 trace "${ns_a}" ${type}_a "${ns_b}" ${type}_b \ 1090 "${ns_a}" veth_A-R1 "${ns_r1}" veth_R1-A \ 1091 "${ns_b}" veth_B-R1 "${ns_r1}" veth_R1-B 1092 1093 if [ ${family} -eq 4 ]; then 1094 ping=ping 1095 dst=${tunnel4_b_addr} 1096 else 1097 ping=${ping6} 1098 dst=${tunnel6_b_addr} 1099 fi 1100 1101 # Create route exception by exceeding link layer MTU 1102 mtu "${ns_a}" veth_A-R1 $((${ll_mtu} + 1000)) 1103 mtu "${ns_r1}" veth_R1-A $((${ll_mtu} + 1000)) 1104 mtu "${ns_b}" veth_B-R1 ${ll_mtu} 1105 mtu "${ns_r1}" veth_R1-B ${ll_mtu} 1106 1107 mtu "${ns_a}" ${type}_a $((${ll_mtu} + 1000)) 1108 mtu "${ns_b}" ${type}_b $((${ll_mtu} + 1000)) 1109 run_cmd ${ns_a} ${ping} -q -M want -i 0.1 -w 1 -s $((${ll_mtu} + 500)) ${dst} 1110 1111 # Check that exception was created 1112 pmtu="$(route_get_dst_pmtu_from_exception "${ns_a}" ${dst})" 1113 check_pmtu_value ${exp_mtu} "${pmtu}" "exceeding link layer MTU on ${type} interface" 1114} 1115 1116test_pmtu_ipv4_vxlan4_exception() { 1117 test_pmtu_ipvX_over_vxlanY_or_geneveY_exception vxlan 4 4 1118} 1119 1120test_pmtu_ipv6_vxlan4_exception() { 1121 test_pmtu_ipvX_over_vxlanY_or_geneveY_exception vxlan 6 4 1122} 1123 1124test_pmtu_ipv4_geneve4_exception() { 1125 test_pmtu_ipvX_over_vxlanY_or_geneveY_exception geneve 4 4 1126} 1127 1128test_pmtu_ipv6_geneve4_exception() { 1129 test_pmtu_ipvX_over_vxlanY_or_geneveY_exception geneve 6 4 1130} 1131 1132test_pmtu_ipv4_vxlan6_exception() { 1133 test_pmtu_ipvX_over_vxlanY_or_geneveY_exception vxlan 4 6 1134} 1135 1136test_pmtu_ipv6_vxlan6_exception() { 1137 test_pmtu_ipvX_over_vxlanY_or_geneveY_exception vxlan 6 6 1138} 1139 1140test_pmtu_ipv4_geneve6_exception() { 1141 test_pmtu_ipvX_over_vxlanY_or_geneveY_exception geneve 4 6 1142} 1143 1144test_pmtu_ipv6_geneve6_exception() { 1145 test_pmtu_ipvX_over_vxlanY_or_geneveY_exception geneve 6 6 1146} 1147 1148test_pmtu_ipvX_over_bridged_vxlanY_or_geneveY_exception() { 1149 type=${1} 1150 family=${2} 1151 outer_family=${3} 1152 ll_mtu=4000 1153 1154 if [ ${outer_family} -eq 4 ]; then 1155 setup namespaces routing bridge bridged_${type}4 || return $ksft_skip 1156 # IPv4 header UDP header VXLAN/GENEVE header Ethernet header 1157 exp_mtu=$((${ll_mtu} - 20 - 8 - 8 - 14)) 1158 else 1159 setup namespaces routing bridge bridged_${type}6 || return $ksft_skip 1160 # IPv6 header UDP header VXLAN/GENEVE header Ethernet header 1161 exp_mtu=$((${ll_mtu} - 40 - 8 - 8 - 14)) 1162 fi 1163 1164 trace "${ns_a}" ${type}_a "${ns_b}" ${type}_b \ 1165 "${ns_a}" veth_A-R1 "${ns_r1}" veth_R1-A \ 1166 "${ns_b}" veth_B-R1 "${ns_r1}" veth_R1-B \ 1167 "${ns_a}" br0 "${ns_a}" veth-A-C \ 1168 "${ns_c}" veth_C-A 1169 1170 if [ ${family} -eq 4 ]; then 1171 ping=ping 1172 dst=${tunnel4_b_addr} 1173 else 1174 ping=${ping6} 1175 dst=${tunnel6_b_addr} 1176 fi 1177 1178 # Create route exception by exceeding link layer MTU 1179 mtu "${ns_a}" veth_A-R1 $((${ll_mtu} + 1000)) 1180 mtu "${ns_a}" br0 $((${ll_mtu} + 1000)) 1181 mtu "${ns_a}" veth_A-C $((${ll_mtu} + 1000)) 1182 mtu "${ns_c}" veth_C-A $((${ll_mtu} + 1000)) 1183 mtu "${ns_r1}" veth_R1-A $((${ll_mtu} + 1000)) 1184 mtu "${ns_b}" veth_B-R1 ${ll_mtu} 1185 mtu "${ns_r1}" veth_R1-B ${ll_mtu} 1186 1187 mtu "${ns_a}" ${type}_a $((${ll_mtu} + 1000)) 1188 mtu "${ns_b}" ${type}_b $((${ll_mtu} + 1000)) 1189 1190 run_cmd ${ns_c} ${ping} -q -M want -i 0.1 -c 10 -s $((${ll_mtu} + 500)) ${dst} || return 1 1191 run_cmd ${ns_a} ${ping} -q -M want -i 0.1 -w 1 -s $((${ll_mtu} + 500)) ${dst} || return 1 1192 1193 # Check that exceptions were created 1194 pmtu="$(route_get_dst_pmtu_from_exception "${ns_c}" ${dst})" 1195 check_pmtu_value ${exp_mtu} "${pmtu}" "exceeding link layer MTU on bridged ${type} interface" 1196 pmtu="$(route_get_dst_pmtu_from_exception "${ns_a}" ${dst})" 1197 check_pmtu_value ${exp_mtu} "${pmtu}" "exceeding link layer MTU on locally bridged ${type} interface" 1198} 1199 1200test_pmtu_ipv4_br_vxlan4_exception() { 1201 test_pmtu_ipvX_over_bridged_vxlanY_or_geneveY_exception vxlan 4 4 1202} 1203 1204test_pmtu_ipv6_br_vxlan4_exception() { 1205 test_pmtu_ipvX_over_bridged_vxlanY_or_geneveY_exception vxlan 6 4 1206} 1207 1208test_pmtu_ipv4_br_geneve4_exception() { 1209 test_pmtu_ipvX_over_bridged_vxlanY_or_geneveY_exception geneve 4 4 1210} 1211 1212test_pmtu_ipv6_br_geneve4_exception() { 1213 test_pmtu_ipvX_over_bridged_vxlanY_or_geneveY_exception geneve 6 4 1214} 1215 1216test_pmtu_ipv4_br_vxlan6_exception() { 1217 test_pmtu_ipvX_over_bridged_vxlanY_or_geneveY_exception vxlan 4 6 1218} 1219 1220test_pmtu_ipv6_br_vxlan6_exception() { 1221 test_pmtu_ipvX_over_bridged_vxlanY_or_geneveY_exception vxlan 6 6 1222} 1223 1224test_pmtu_ipv4_br_geneve6_exception() { 1225 test_pmtu_ipvX_over_bridged_vxlanY_or_geneveY_exception geneve 4 6 1226} 1227 1228test_pmtu_ipv6_br_geneve6_exception() { 1229 test_pmtu_ipvX_over_bridged_vxlanY_or_geneveY_exception geneve 6 6 1230} 1231 1232test_pmtu_ipvX_over_ovs_vxlanY_or_geneveY_exception() { 1233 type=${1} 1234 family=${2} 1235 outer_family=${3} 1236 ll_mtu=4000 1237 1238 if [ ${outer_family} -eq 4 ]; then 1239 setup namespaces routing ovs_bridge ovs_${type}4 || return $ksft_skip 1240 # IPv4 header UDP header VXLAN/GENEVE header Ethernet header 1241 exp_mtu=$((${ll_mtu} - 20 - 8 - 8 - 14)) 1242 else 1243 setup namespaces routing ovs_bridge ovs_${type}6 || return $ksft_skip 1244 # IPv6 header UDP header VXLAN/GENEVE header Ethernet header 1245 exp_mtu=$((${ll_mtu} - 40 - 8 - 8 - 14)) 1246 fi 1247 1248 if [ "${type}" = "vxlan" ]; then 1249 tun_a="vxlan_sys_4789" 1250 elif [ "${type}" = "geneve" ]; then 1251 tun_a="genev_sys_6081" 1252 fi 1253 1254 trace "" "${tun_a}" "${ns_b}" ${type}_b \ 1255 "" veth_A-R1 "${ns_r1}" veth_R1-A \ 1256 "${ns_b}" veth_B-R1 "${ns_r1}" veth_R1-B \ 1257 "" ovs_br0 "" veth-A-C \ 1258 "${ns_c}" veth_C-A 1259 1260 if [ ${family} -eq 4 ]; then 1261 ping=ping 1262 dst=${tunnel4_b_addr} 1263 else 1264 ping=${ping6} 1265 dst=${tunnel6_b_addr} 1266 fi 1267 1268 # Create route exception by exceeding link layer MTU 1269 mtu "" veth_A-R1 $((${ll_mtu} + 1000)) 1270 mtu "" ovs_br0 $((${ll_mtu} + 1000)) 1271 mtu "" veth_A-C $((${ll_mtu} + 1000)) 1272 mtu "${ns_c}" veth_C-A $((${ll_mtu} + 1000)) 1273 mtu "${ns_r1}" veth_R1-A $((${ll_mtu} + 1000)) 1274 mtu "${ns_b}" veth_B-R1 ${ll_mtu} 1275 mtu "${ns_r1}" veth_R1-B ${ll_mtu} 1276 1277 mtu "" ${tun_a} $((${ll_mtu} + 1000)) 1278 mtu "${ns_b}" ${type}_b $((${ll_mtu} + 1000)) 1279 1280 run_cmd ${ns_c} ${ping} -q -M want -i 0.1 -c 20 -s $((${ll_mtu} + 500)) ${dst} || return 1 1281 1282 # Check that exceptions were created 1283 pmtu="$(route_get_dst_pmtu_from_exception "${ns_c}" ${dst})" 1284 check_pmtu_value ${exp_mtu} "${pmtu}" "exceeding link layer MTU on Open vSwitch ${type} interface" 1285} 1286 1287test_pmtu_ipv4_ovs_vxlan4_exception() { 1288 test_pmtu_ipvX_over_ovs_vxlanY_or_geneveY_exception vxlan 4 4 1289} 1290 1291test_pmtu_ipv6_ovs_vxlan4_exception() { 1292 test_pmtu_ipvX_over_ovs_vxlanY_or_geneveY_exception vxlan 6 4 1293} 1294 1295test_pmtu_ipv4_ovs_geneve4_exception() { 1296 test_pmtu_ipvX_over_ovs_vxlanY_or_geneveY_exception geneve 4 4 1297} 1298 1299test_pmtu_ipv6_ovs_geneve4_exception() { 1300 test_pmtu_ipvX_over_ovs_vxlanY_or_geneveY_exception geneve 6 4 1301} 1302 1303test_pmtu_ipv4_ovs_vxlan6_exception() { 1304 test_pmtu_ipvX_over_ovs_vxlanY_or_geneveY_exception vxlan 4 6 1305} 1306 1307test_pmtu_ipv6_ovs_vxlan6_exception() { 1308 test_pmtu_ipvX_over_ovs_vxlanY_or_geneveY_exception vxlan 6 6 1309} 1310 1311test_pmtu_ipv4_ovs_geneve6_exception() { 1312 test_pmtu_ipvX_over_ovs_vxlanY_or_geneveY_exception geneve 4 6 1313} 1314 1315test_pmtu_ipv6_ovs_geneve6_exception() { 1316 test_pmtu_ipvX_over_ovs_vxlanY_or_geneveY_exception geneve 6 6 1317} 1318 1319test_pmtu_ipvX_over_fouY_or_gueY() { 1320 inner_family=${1} 1321 outer_family=${2} 1322 encap=${3} 1323 ll_mtu=4000 1324 1325 setup namespaces routing ${encap}${outer_family}${inner_family} || return $ksft_skip 1326 trace "${ns_a}" ${encap}_a "${ns_b}" ${encap}_b \ 1327 "${ns_a}" veth_A-R1 "${ns_r1}" veth_R1-A \ 1328 "${ns_b}" veth_B-R1 "${ns_r1}" veth_R1-B 1329 1330 if [ ${inner_family} -eq 4 ]; then 1331 ping=ping 1332 dst=${tunnel4_b_addr} 1333 else 1334 ping=${ping6} 1335 dst=${tunnel6_b_addr} 1336 fi 1337 1338 if [ "${encap}" = "gue" ]; then 1339 encap_overhead=4 1340 else 1341 encap_overhead=0 1342 fi 1343 1344 if [ ${outer_family} -eq 4 ]; then 1345 # IPv4 header UDP header 1346 exp_mtu=$((${ll_mtu} - 20 - 8 - ${encap_overhead})) 1347 else 1348 # IPv6 header Option 4 UDP header 1349 exp_mtu=$((${ll_mtu} - 40 - 8 - 8 - ${encap_overhead})) 1350 fi 1351 1352 # Create route exception by exceeding link layer MTU 1353 mtu "${ns_a}" veth_A-R1 $((${ll_mtu} + 1000)) 1354 mtu "${ns_r1}" veth_R1-A $((${ll_mtu} + 1000)) 1355 mtu "${ns_b}" veth_B-R1 ${ll_mtu} 1356 mtu "${ns_r1}" veth_R1-B ${ll_mtu} 1357 1358 mtu "${ns_a}" ${encap}_a $((${ll_mtu} + 1000)) 1359 mtu "${ns_b}" ${encap}_b $((${ll_mtu} + 1000)) 1360 run_cmd ${ns_a} ${ping} -q -M want -i 0.1 -w 1 -s $((${ll_mtu} + 500)) ${dst} 1361 1362 # Check that exception was created 1363 pmtu="$(route_get_dst_pmtu_from_exception "${ns_a}" ${dst})" 1364 check_pmtu_value ${exp_mtu} "${pmtu}" "exceeding link layer MTU on ${encap} interface" 1365} 1366 1367test_pmtu_ipv4_fou4_exception() { 1368 test_pmtu_ipvX_over_fouY_or_gueY 4 4 fou 1369} 1370 1371test_pmtu_ipv6_fou4_exception() { 1372 test_pmtu_ipvX_over_fouY_or_gueY 6 4 fou 1373} 1374 1375test_pmtu_ipv4_fou6_exception() { 1376 test_pmtu_ipvX_over_fouY_or_gueY 4 6 fou 1377} 1378 1379test_pmtu_ipv6_fou6_exception() { 1380 test_pmtu_ipvX_over_fouY_or_gueY 6 6 fou 1381} 1382 1383test_pmtu_ipv4_gue4_exception() { 1384 test_pmtu_ipvX_over_fouY_or_gueY 4 4 gue 1385} 1386 1387test_pmtu_ipv6_gue4_exception() { 1388 test_pmtu_ipvX_over_fouY_or_gueY 6 4 gue 1389} 1390 1391test_pmtu_ipv4_gue6_exception() { 1392 test_pmtu_ipvX_over_fouY_or_gueY 4 6 gue 1393} 1394 1395test_pmtu_ipv6_gue6_exception() { 1396 test_pmtu_ipvX_over_fouY_or_gueY 6 6 gue 1397} 1398 1399test_pmtu_ipvX_over_ipvY_exception() { 1400 inner=${1} 1401 outer=${2} 1402 ll_mtu=4000 1403 1404 setup namespaces routing ip${inner}ip${outer} || return $ksft_skip 1405 1406 trace "${ns_a}" ip_a "${ns_b}" ip_b \ 1407 "${ns_a}" veth_A-R1 "${ns_r1}" veth_R1-A \ 1408 "${ns_b}" veth_B-R1 "${ns_r1}" veth_R1-B 1409 1410 if [ ${inner} -eq 4 ]; then 1411 ping=ping 1412 dst=${tunnel4_b_addr} 1413 else 1414 ping=${ping6} 1415 dst=${tunnel6_b_addr} 1416 fi 1417 1418 if [ ${outer} -eq 4 ]; then 1419 # IPv4 header 1420 exp_mtu=$((${ll_mtu} - 20)) 1421 else 1422 # IPv6 header Option 4 1423 exp_mtu=$((${ll_mtu} - 40 - 8)) 1424 fi 1425 1426 # Create route exception by exceeding link layer MTU 1427 mtu "${ns_a}" veth_A-R1 $((${ll_mtu} + 1000)) 1428 mtu "${ns_r1}" veth_R1-A $((${ll_mtu} + 1000)) 1429 mtu "${ns_b}" veth_B-R1 ${ll_mtu} 1430 mtu "${ns_r1}" veth_R1-B ${ll_mtu} 1431 1432 mtu "${ns_a}" ip_a $((${ll_mtu} + 1000)) || return 1433 mtu "${ns_b}" ip_b $((${ll_mtu} + 1000)) || return 1434 run_cmd ${ns_a} ${ping} -q -M want -i 0.1 -w 1 -s $((${ll_mtu} + 500)) ${dst} 1435 1436 # Check that exception was created 1437 pmtu="$(route_get_dst_pmtu_from_exception "${ns_a}" ${dst})" 1438 check_pmtu_value ${exp_mtu} "${pmtu}" "exceeding link layer MTU on ip${inner}ip${outer} interface" 1439} 1440 1441test_pmtu_ipv4_ipv4_exception() { 1442 test_pmtu_ipvX_over_ipvY_exception 4 4 1443} 1444 1445test_pmtu_ipv6_ipv4_exception() { 1446 test_pmtu_ipvX_over_ipvY_exception 6 4 1447} 1448 1449test_pmtu_ipv4_ipv6_exception() { 1450 test_pmtu_ipvX_over_ipvY_exception 4 6 1451} 1452 1453test_pmtu_ipv6_ipv6_exception() { 1454 test_pmtu_ipvX_over_ipvY_exception 6 6 1455} 1456 1457test_pmtu_vti4_exception() { 1458 setup namespaces veth vti4 xfrm4 || return $ksft_skip 1459 trace "${ns_a}" veth_a "${ns_b}" veth_b \ 1460 "${ns_a}" vti4_a "${ns_b}" vti4_b 1461 1462 veth_mtu=1500 1463 vti_mtu=$((veth_mtu - 20)) 1464 1465 # SPI SN IV ICV pad length next header 1466 esp_payload_rfc4106=$((vti_mtu - 4 - 4 - 8 - 16 - 1 - 1)) 1467 ping_payload=$((esp_payload_rfc4106 - 28)) 1468 1469 mtu "${ns_a}" veth_a ${veth_mtu} 1470 mtu "${ns_b}" veth_b ${veth_mtu} 1471 mtu "${ns_a}" vti4_a ${vti_mtu} 1472 mtu "${ns_b}" vti4_b ${vti_mtu} 1473 1474 # Send DF packet without exceeding link layer MTU, check that no 1475 # exception is created 1476 run_cmd ${ns_a} ping -q -M want -i 0.1 -w 1 -s ${ping_payload} ${tunnel4_b_addr} 1477 pmtu="$(route_get_dst_pmtu_from_exception "${ns_a}" ${tunnel4_b_addr})" 1478 check_pmtu_value "" "${pmtu}" "sending packet smaller than PMTU (IP payload length ${esp_payload_rfc4106})" || return 1 1479 1480 # Now exceed link layer MTU by one byte, check that exception is created 1481 # with the right PMTU value 1482 run_cmd ${ns_a} ping -q -M want -i 0.1 -w 1 -s $((ping_payload + 1)) ${tunnel4_b_addr} 1483 pmtu="$(route_get_dst_pmtu_from_exception "${ns_a}" ${tunnel4_b_addr})" 1484 check_pmtu_value "${esp_payload_rfc4106}" "${pmtu}" "exceeding PMTU (IP payload length $((esp_payload_rfc4106 + 1)))" 1485} 1486 1487test_pmtu_vti6_exception() { 1488 setup namespaces veth vti6 xfrm6 || return $ksft_skip 1489 trace "${ns_a}" veth_a "${ns_b}" veth_b \ 1490 "${ns_a}" vti6_a "${ns_b}" vti6_b 1491 fail=0 1492 1493 # Create route exception by exceeding link layer MTU 1494 mtu "${ns_a}" veth_a 4000 1495 mtu "${ns_b}" veth_b 4000 1496 mtu "${ns_a}" vti6_a 5000 1497 mtu "${ns_b}" vti6_b 5000 1498 run_cmd ${ns_a} ${ping6} -q -i 0.1 -w 1 -s 60000 ${tunnel6_b_addr} 1499 1500 # Check that exception was created 1501 pmtu="$(route_get_dst_pmtu_from_exception "${ns_a}" ${tunnel6_b_addr})" 1502 check_pmtu_value any "${pmtu}" "creating tunnel exceeding link layer MTU" || return 1 1503 1504 # Decrease tunnel MTU, check for PMTU decrease in route exception 1505 mtu "${ns_a}" vti6_a 3000 1506 pmtu="$(route_get_dst_pmtu_from_exception "${ns_a}" ${tunnel6_b_addr})" 1507 check_pmtu_value "3000" "${pmtu}" "decreasing tunnel MTU" || fail=1 1508 1509 # Increase tunnel MTU, check for PMTU increase in route exception 1510 mtu "${ns_a}" vti6_a 9000 1511 pmtu="$(route_get_dst_pmtu_from_exception "${ns_a}" ${tunnel6_b_addr})" 1512 check_pmtu_value "9000" "${pmtu}" "increasing tunnel MTU" || fail=1 1513 1514 return ${fail} 1515} 1516 1517test_pmtu_vti4_udp_exception() { 1518 setup namespaces veth vti4 xfrm4udp || return $ksft_skip 1519 trace "${ns_a}" veth_a "${ns_b}" veth_b \ 1520 "${ns_a}" vti4_a "${ns_b}" vti4_b 1521 1522 veth_mtu=1500 1523 vti_mtu=$((veth_mtu - 20)) 1524 1525 # UDP SPI SN IV ICV pad length next header 1526 esp_payload_rfc4106=$((vti_mtu - 8 - 4 - 4 - 8 - 16 - 1 - 1)) 1527 ping_payload=$((esp_payload_rfc4106 - 28)) 1528 1529 mtu "${ns_a}" veth_a ${veth_mtu} 1530 mtu "${ns_b}" veth_b ${veth_mtu} 1531 mtu "${ns_a}" vti4_a ${vti_mtu} 1532 mtu "${ns_b}" vti4_b ${vti_mtu} 1533 1534 # Send DF packet without exceeding link layer MTU, check that no 1535 # exception is created 1536 run_cmd ${ns_a} ping -q -M want -i 0.1 -w 1 -s ${ping_payload} ${tunnel4_b_addr} 1537 pmtu="$(route_get_dst_pmtu_from_exception "${ns_a}" ${tunnel4_b_addr})" 1538 check_pmtu_value "" "${pmtu}" "sending packet smaller than PMTU (IP payload length ${esp_payload_rfc4106})" || return 1 1539 1540 # Now exceed link layer MTU by one byte, check that exception is created 1541 # with the right PMTU value 1542 run_cmd ${ns_a} ping -q -M want -i 0.1 -w 1 -s $((ping_payload + 1)) ${tunnel4_b_addr} 1543 pmtu="$(route_get_dst_pmtu_from_exception "${ns_a}" ${tunnel4_b_addr})" 1544 check_pmtu_value "${esp_payload_rfc4106}" "${pmtu}" "exceeding PMTU (IP payload length $((esp_payload_rfc4106 + 1)))" 1545} 1546 1547test_pmtu_vti6_udp_exception() { 1548 setup namespaces veth vti6 xfrm6udp || return $ksft_skip 1549 trace "${ns_a}" veth_a "${ns_b}" veth_b \ 1550 "${ns_a}" vti6_a "${ns_b}" vti6_b 1551 fail=0 1552 1553 # Create route exception by exceeding link layer MTU 1554 mtu "${ns_a}" veth_a 4000 1555 mtu "${ns_b}" veth_b 4000 1556 mtu "${ns_a}" vti6_a 5000 1557 mtu "${ns_b}" vti6_b 5000 1558 run_cmd ${ns_a} ${ping6} -q -i 0.1 -w 1 -s 60000 ${tunnel6_b_addr} 1559 1560 # Check that exception was created 1561 pmtu="$(route_get_dst_pmtu_from_exception "${ns_a}" ${tunnel6_b_addr})" 1562 check_pmtu_value any "${pmtu}" "creating tunnel exceeding link layer MTU" || return 1 1563 1564 # Decrease tunnel MTU, check for PMTU decrease in route exception 1565 mtu "${ns_a}" vti6_a 3000 1566 pmtu="$(route_get_dst_pmtu_from_exception "${ns_a}" ${tunnel6_b_addr})" 1567 check_pmtu_value "3000" "${pmtu}" "decreasing tunnel MTU" || fail=1 1568 1569 # Increase tunnel MTU, check for PMTU increase in route exception 1570 mtu "${ns_a}" vti6_a 9000 1571 pmtu="$(route_get_dst_pmtu_from_exception "${ns_a}" ${tunnel6_b_addr})" 1572 check_pmtu_value "9000" "${pmtu}" "increasing tunnel MTU" || fail=1 1573 1574 return ${fail} 1575} 1576 1577test_pmtu_vti4_udp_routed_exception() { 1578 setup namespaces routing vti4routed xfrm4udprouted || return $ksft_skip 1579 trace "${ns_a}" veth_A-R1 "${ns_b}" veth_B-R1 \ 1580 "${ns_a}" vti4_a "${ns_b}" vti4_b 1581 1582 veth_mtu=1500 1583 vti_mtu=$((veth_mtu - 20)) 1584 1585 # UDP SPI SN IV ICV pad length next header 1586 esp_payload_rfc4106=$((vti_mtu - 8 - 4 - 4 - 8 - 16 - 1 - 1)) 1587 ping_payload=$((esp_payload_rfc4106 - 28)) 1588 1589 mtu "${ns_a}" veth_A-R1 ${veth_mtu} 1590 mtu "${ns_r1}" veth_R1-A ${veth_mtu} 1591 mtu "${ns_b}" veth_B-R1 ${veth_mtu} 1592 mtu "${ns_r1}" veth_R1-B ${veth_mtu} 1593 1594 mtu "${ns_a}" vti4_a ${vti_mtu} 1595 mtu "${ns_b}" vti4_b ${vti_mtu} 1596 1597 # Send DF packet without exceeding link layer MTU, check that no 1598 # exception is created 1599 run_cmd ${ns_a} ping -q -M want -i 0.1 -w 1 -s ${ping_payload} ${tunnel4_b_addr} 1600 pmtu="$(route_get_dst_pmtu_from_exception "${ns_a}" ${tunnel4_b_addr})" 1601 check_pmtu_value "" "${pmtu}" "sending packet smaller than PMTU (IP payload length ${esp_payload_rfc4106})" || return 1 1602 1603 # Now decrease link layer MTU by 8 bytes on R1, check that exception is created 1604 # with the right PMTU value 1605 mtu "${ns_r1}" veth_R1-B $((veth_mtu - 8)) 1606 run_cmd ${ns_a} ping -q -M want -i 0.1 -w 1 -s $((ping_payload)) ${tunnel4_b_addr} 1607 pmtu="$(route_get_dst_pmtu_from_exception "${ns_a}" ${tunnel4_b_addr})" 1608 check_pmtu_value "$((esp_payload_rfc4106 - 8))" "${pmtu}" "exceeding PMTU (IP payload length $((esp_payload_rfc4106)))" 1609} 1610 1611test_pmtu_vti6_udp_routed_exception() { 1612 setup namespaces routing vti6routed xfrm6udprouted || return $ksft_skip 1613 trace "${ns_a}" veth_A-R1 "${ns_b}" veth_B-R1 \ 1614 "${ns_a}" vti6_a "${ns_b}" vti6_b 1615 1616 veth_mtu=1500 1617 vti_mtu=$((veth_mtu - 40)) 1618 1619 # UDP SPI SN IV ICV pad length next header 1620 esp_payload_rfc4106=$((vti_mtu - 8 - 4 - 4 - 8 - 16 - 1 - 1)) 1621 ping_payload=$((esp_payload_rfc4106 - 48)) 1622 1623 mtu "${ns_a}" veth_A-R1 ${veth_mtu} 1624 mtu "${ns_r1}" veth_R1-A ${veth_mtu} 1625 mtu "${ns_b}" veth_B-R1 ${veth_mtu} 1626 mtu "${ns_r1}" veth_R1-B ${veth_mtu} 1627 1628 # mtu "${ns_a}" vti6_a ${vti_mtu} 1629 # mtu "${ns_b}" vti6_b ${vti_mtu} 1630 1631 run_cmd ${ns_a} ${ping6} -q -M want -i 0.1 -w 1 -s ${ping_payload} ${tunnel6_b_addr} 1632 1633 # Check that exception was not created 1634 pmtu="$(route_get_dst_pmtu_from_exception "${ns_a}" ${tunnel6_b_addr})" 1635 check_pmtu_value "" "${pmtu}" "sending packet smaller than PMTU (IP payload length ${esp_payload_rfc4106})" || return 1 1636 1637 # Now decrease link layer MTU by 8 bytes on R1, check that exception is created 1638 # with the right PMTU value 1639 mtu "${ns_r1}" veth_R1-B $((veth_mtu - 8)) 1640 run_cmd ${ns_a} ${ping6} -q -M want -i 0.1 -w 1 -s $((ping_payload)) ${tunnel6_b_addr} 1641 pmtu="$(route_get_dst_pmtu_from_exception "${ns_a}" ${tunnel6_b_addr})" 1642 check_pmtu_value "$((esp_payload_rfc4106 - 8))" "${pmtu}" "exceeding PMTU (IP payload length $((esp_payload_rfc4106)))" 1643 1644} 1645 1646test_pmtu_vti4_default_mtu() { 1647 setup namespaces veth vti4 || return $ksft_skip 1648 1649 # Check that MTU of vti device is MTU of veth minus IPv4 header length 1650 veth_mtu="$(link_get_mtu "${ns_a}" veth_a)" 1651 vti4_mtu="$(link_get_mtu "${ns_a}" vti4_a)" 1652 if [ $((veth_mtu - vti4_mtu)) -ne 20 ]; then 1653 err " vti MTU ${vti4_mtu} is not veth MTU ${veth_mtu} minus IPv4 header length" 1654 return 1 1655 fi 1656} 1657 1658test_pmtu_vti6_default_mtu() { 1659 setup namespaces veth vti6 || return $ksft_skip 1660 1661 # Check that MTU of vti device is MTU of veth minus IPv6 header length 1662 veth_mtu="$(link_get_mtu "${ns_a}" veth_a)" 1663 vti6_mtu="$(link_get_mtu "${ns_a}" vti6_a)" 1664 if [ $((veth_mtu - vti6_mtu)) -ne 40 ]; then 1665 err " vti MTU ${vti6_mtu} is not veth MTU ${veth_mtu} minus IPv6 header length" 1666 return 1 1667 fi 1668} 1669 1670test_pmtu_vti4_link_add_mtu() { 1671 setup namespaces || return $ksft_skip 1672 1673 run_cmd ${ns_a} ip link add vti4_a type vti local ${veth4_a_addr} remote ${veth4_b_addr} key 10 1674 [ $? -ne 0 ] && err " vti not supported" && return $ksft_skip 1675 run_cmd ${ns_a} ip link del vti4_a 1676 1677 fail=0 1678 1679 min=68 1680 max=$((65535 - 20)) 1681 # Check invalid values first 1682 for v in $((min - 1)) $((max + 1)); do 1683 run_cmd ${ns_a} ip link add vti4_a mtu ${v} type vti local ${veth4_a_addr} remote ${veth4_b_addr} key 10 1684 # This can fail, or MTU can be adjusted to a proper value 1685 [ $? -ne 0 ] && continue 1686 mtu="$(link_get_mtu "${ns_a}" vti4_a)" 1687 if [ ${mtu} -lt ${min} -o ${mtu} -gt ${max} ]; then 1688 err " vti tunnel created with invalid MTU ${mtu}" 1689 fail=1 1690 fi 1691 run_cmd ${ns_a} ip link del vti4_a 1692 done 1693 1694 # Now check valid values 1695 for v in ${min} 1300 ${max}; do 1696 run_cmd ${ns_a} ip link add vti4_a mtu ${v} type vti local ${veth4_a_addr} remote ${veth4_b_addr} key 10 1697 mtu="$(link_get_mtu "${ns_a}" vti4_a)" 1698 run_cmd ${ns_a} ip link del vti4_a 1699 if [ "${mtu}" != "${v}" ]; then 1700 err " vti MTU ${mtu} doesn't match configured value ${v}" 1701 fail=1 1702 fi 1703 done 1704 1705 return ${fail} 1706} 1707 1708test_pmtu_vti6_link_add_mtu() { 1709 setup namespaces || return $ksft_skip 1710 1711 run_cmd ${ns_a} ip link add vti6_a type vti6 local ${veth6_a_addr} remote ${veth6_b_addr} key 10 1712 [ $? -ne 0 ] && err " vti6 not supported" && return $ksft_skip 1713 run_cmd ${ns_a} ip link del vti6_a 1714 1715 fail=0 1716 1717 min=68 # vti6 can carry IPv4 packets too 1718 max=$((65535 - 40)) 1719 # Check invalid values first 1720 for v in $((min - 1)) $((max + 1)); do 1721 run_cmd ${ns_a} ip link add vti6_a mtu ${v} type vti6 local ${veth6_a_addr} remote ${veth6_b_addr} key 10 1722 # This can fail, or MTU can be adjusted to a proper value 1723 [ $? -ne 0 ] && continue 1724 mtu="$(link_get_mtu "${ns_a}" vti6_a)" 1725 if [ ${mtu} -lt ${min} -o ${mtu} -gt ${max} ]; then 1726 err " vti6 tunnel created with invalid MTU ${v}" 1727 fail=1 1728 fi 1729 run_cmd ${ns_a} ip link del vti6_a 1730 done 1731 1732 # Now check valid values 1733 for v in 68 1280 1300 $((65535 - 40)); do 1734 run_cmd ${ns_a} ip link add vti6_a mtu ${v} type vti6 local ${veth6_a_addr} remote ${veth6_b_addr} key 10 1735 mtu="$(link_get_mtu "${ns_a}" vti6_a)" 1736 run_cmd ${ns_a} ip link del vti6_a 1737 if [ "${mtu}" != "${v}" ]; then 1738 err " vti6 MTU ${mtu} doesn't match configured value ${v}" 1739 fail=1 1740 fi 1741 done 1742 1743 return ${fail} 1744} 1745 1746test_pmtu_vti6_link_change_mtu() { 1747 setup namespaces || return $ksft_skip 1748 1749 run_cmd ${ns_a} ip link add dummy0 mtu 1500 type dummy 1750 [ $? -ne 0 ] && err " dummy not supported" && return $ksft_skip 1751 run_cmd ${ns_a} ip link add dummy1 mtu 3000 type dummy 1752 run_cmd ${ns_a} ip link set dummy0 up 1753 run_cmd ${ns_a} ip link set dummy1 up 1754 1755 run_cmd ${ns_a} ip addr add ${dummy6_0_prefix}1/${dummy6_mask} dev dummy0 1756 run_cmd ${ns_a} ip addr add ${dummy6_1_prefix}1/${dummy6_mask} dev dummy1 1757 1758 fail=0 1759 1760 # Create vti6 interface bound to device, passing MTU, check it 1761 run_cmd ${ns_a} ip link add vti6_a mtu 1300 type vti6 remote ${dummy6_0_prefix}2 local ${dummy6_0_prefix}1 1762 mtu="$(link_get_mtu "${ns_a}" vti6_a)" 1763 if [ ${mtu} -ne 1300 ]; then 1764 err " vti6 MTU ${mtu} doesn't match configured value 1300" 1765 fail=1 1766 fi 1767 1768 # Move to another device with different MTU, without passing MTU, check 1769 # MTU is adjusted 1770 run_cmd ${ns_a} ip link set vti6_a type vti6 remote ${dummy6_1_prefix}2 local ${dummy6_1_prefix}1 1771 mtu="$(link_get_mtu "${ns_a}" vti6_a)" 1772 if [ ${mtu} -ne $((3000 - 40)) ]; then 1773 err " vti MTU ${mtu} is not dummy MTU 3000 minus IPv6 header length" 1774 fail=1 1775 fi 1776 1777 # Move it back, passing MTU, check MTU is not overridden 1778 run_cmd ${ns_a} ip link set vti6_a mtu 1280 type vti6 remote ${dummy6_0_prefix}2 local ${dummy6_0_prefix}1 1779 mtu="$(link_get_mtu "${ns_a}" vti6_a)" 1780 if [ ${mtu} -ne 1280 ]; then 1781 err " vti6 MTU ${mtu} doesn't match configured value 1280" 1782 fail=1 1783 fi 1784 1785 return ${fail} 1786} 1787 1788check_command() { 1789 cmd=${1} 1790 1791 if ! which ${cmd} > /dev/null 2>&1; then 1792 err " missing required command: '${cmd}'" 1793 return 1 1794 fi 1795 return 0 1796} 1797 1798check_running() { 1799 pid=${1} 1800 cmd=${2} 1801 1802 [ "$(cat /proc/${pid}/cmdline 2>/dev/null | tr -d '\0')" = "{cmd}" ] 1803} 1804 1805test_cleanup_vxlanX_exception() { 1806 outer="${1}" 1807 encap="vxlan" 1808 ll_mtu=4000 1809 1810 check_command taskset || return $ksft_skip 1811 cpu_list=$(grep -m 2 processor /proc/cpuinfo | cut -d ' ' -f 2) 1812 1813 setup namespaces routing ${encap}${outer} || return $ksft_skip 1814 trace "${ns_a}" ${encap}_a "${ns_b}" ${encap}_b \ 1815 "${ns_a}" veth_A-R1 "${ns_r1}" veth_R1-A \ 1816 "${ns_b}" veth_B-R1 "${ns_r1}" veth_R1-B 1817 1818 # Create route exception by exceeding link layer MTU 1819 mtu "${ns_a}" veth_A-R1 $((${ll_mtu} + 1000)) 1820 mtu "${ns_r1}" veth_R1-A $((${ll_mtu} + 1000)) 1821 mtu "${ns_b}" veth_B-R1 ${ll_mtu} 1822 mtu "${ns_r1}" veth_R1-B ${ll_mtu} 1823 1824 mtu "${ns_a}" ${encap}_a $((${ll_mtu} + 1000)) 1825 mtu "${ns_b}" ${encap}_b $((${ll_mtu} + 1000)) 1826 1827 # Fill exception cache for multiple CPUs (2) 1828 # we can always use inner IPv4 for that 1829 for cpu in ${cpu_list}; do 1830 run_cmd taskset --cpu-list ${cpu} ${ns_a} ping -q -M want -i 0.1 -w 1 -s $((${ll_mtu} + 500)) ${tunnel4_b_addr} 1831 done 1832 1833 ${ns_a} ip link del dev veth_A-R1 & 1834 iplink_pid=$! 1835 for i in $(seq 1 20); do 1836 check_running ${iplink_pid} "iplinkdeldevveth_A-R1" || return 0 1837 sleep 0.1 1838 done 1839 err " can't delete veth device in a timely manner, PMTU dst likely leaked" 1840 return 1 1841} 1842 1843test_cleanup_ipv6_exception() { 1844 test_cleanup_vxlanX_exception 6 1845} 1846 1847test_cleanup_ipv4_exception() { 1848 test_cleanup_vxlanX_exception 4 1849} 1850 1851run_test() { 1852 ( 1853 tname="$1" 1854 tdesc="$2" 1855 1856 unset IFS 1857 1858 # Since cleanup() relies on variables modified by this subshell, it 1859 # has to run in this context. 1860 trap cleanup EXIT 1861 1862 if [ "$VERBOSE" = "1" ]; then 1863 printf "\n##########################################################################\n\n" 1864 fi 1865 1866 eval test_${tname} 1867 ret=$? 1868 1869 if [ $ret -eq 0 ]; then 1870 printf "TEST: %-60s [ OK ]\n" "${tdesc}" 1871 elif [ $ret -eq 1 ]; then 1872 printf "TEST: %-60s [FAIL]\n" "${tdesc}" 1873 if [ "${PAUSE_ON_FAIL}" = "yes" ]; then 1874 echo 1875 echo "Pausing. Hit enter to continue" 1876 read a 1877 fi 1878 err_flush 1879 exit 1 1880 elif [ $ret -eq $ksft_skip ]; then 1881 printf "TEST: %-60s [SKIP]\n" "${tdesc}" 1882 err_flush 1883 fi 1884 1885 return $ret 1886 ) 1887 ret=$? 1888 case $ret in 1889 0) 1890 all_skipped=false 1891 [ $exitcode -eq $ksft_skip ] && exitcode=0 1892 ;; 1893 $ksft_skip) 1894 [ $all_skipped = true ] && exitcode=$ksft_skip 1895 ;; 1896 *) 1897 all_skipped=false 1898 exitcode=1 1899 ;; 1900 esac 1901 1902 return $ret 1903} 1904 1905run_test_nh() { 1906 tname="$1" 1907 tdesc="$2" 1908 1909 USE_NH=yes 1910 run_test "${tname}" "${tdesc} - nexthop objects" 1911 USE_NH=no 1912} 1913 1914test_list_flush_ipv4_exception() { 1915 setup namespaces routing || return $ksft_skip 1916 trace "${ns_a}" veth_A-R1 "${ns_r1}" veth_R1-A \ 1917 "${ns_r1}" veth_R1-B "${ns_b}" veth_B-R1 \ 1918 "${ns_a}" veth_A-R2 "${ns_r2}" veth_R2-A \ 1919 "${ns_r2}" veth_R2-B "${ns_b}" veth_B-R2 1920 1921 dst_prefix1="${prefix4}.${b_r1}." 1922 dst2="${prefix4}.${b_r2}.1" 1923 1924 # Set up initial MTU values 1925 mtu "${ns_a}" veth_A-R1 2000 1926 mtu "${ns_r1}" veth_R1-A 2000 1927 mtu "${ns_r1}" veth_R1-B 1500 1928 mtu "${ns_b}" veth_B-R1 1500 1929 1930 mtu "${ns_a}" veth_A-R2 2000 1931 mtu "${ns_r2}" veth_R2-A 2000 1932 mtu "${ns_r2}" veth_R2-B 1500 1933 mtu "${ns_b}" veth_B-R2 1500 1934 1935 fail=0 1936 1937 # Add 100 addresses for veth endpoint on B reached by default A route 1938 for i in $(seq 100 199); do 1939 run_cmd ${ns_b} ip addr add "${dst_prefix1}${i}" dev veth_B-R1 1940 done 1941 1942 # Create 100 cached route exceptions for path via R1, one via R2. Note 1943 # that with IPv4 we need to actually cause a route lookup that matches 1944 # the exception caused by ICMP, in order to actually have a cached 1945 # route, so we need to ping each destination twice 1946 for i in $(seq 100 199); do 1947 run_cmd ${ns_a} ping -q -M want -i 0.1 -c 2 -s 1800 "${dst_prefix1}${i}" 1948 done 1949 run_cmd ${ns_a} ping -q -M want -i 0.1 -c 2 -s 1800 "${dst2}" 1950 1951 if [ "$(${ns_a} ip -oneline route list cache | wc -l)" -ne 101 ]; then 1952 err " can't list cached exceptions" 1953 fail=1 1954 fi 1955 1956 run_cmd ${ns_a} ip route flush cache 1957 pmtu1="$(route_get_dst_pmtu_from_exception "${ns_a}" ${dst_prefix}1)" 1958 pmtu2="$(route_get_dst_pmtu_from_exception "${ns_a}" ${dst_prefix}2)" 1959 if [ -n "${pmtu1}" ] || [ -n "${pmtu2}" ] || \ 1960 [ -n "$(${ns_a} ip route list cache)" ]; then 1961 err " can't flush cached exceptions" 1962 fail=1 1963 fi 1964 1965 return ${fail} 1966} 1967 1968test_list_flush_ipv6_exception() { 1969 setup namespaces routing || return $ksft_skip 1970 trace "${ns_a}" veth_A-R1 "${ns_r1}" veth_R1-A \ 1971 "${ns_r1}" veth_R1-B "${ns_b}" veth_B-R1 \ 1972 "${ns_a}" veth_A-R2 "${ns_r2}" veth_R2-A \ 1973 "${ns_r2}" veth_R2-B "${ns_b}" veth_B-R2 1974 1975 dst_prefix1="${prefix6}:${b_r1}::" 1976 dst2="${prefix6}:${b_r2}::1" 1977 1978 # Set up initial MTU values 1979 mtu "${ns_a}" veth_A-R1 2000 1980 mtu "${ns_r1}" veth_R1-A 2000 1981 mtu "${ns_r1}" veth_R1-B 1500 1982 mtu "${ns_b}" veth_B-R1 1500 1983 1984 mtu "${ns_a}" veth_A-R2 2000 1985 mtu "${ns_r2}" veth_R2-A 2000 1986 mtu "${ns_r2}" veth_R2-B 1500 1987 mtu "${ns_b}" veth_B-R2 1500 1988 1989 fail=0 1990 1991 # Add 100 addresses for veth endpoint on B reached by default A route 1992 for i in $(seq 100 199); do 1993 run_cmd ${ns_b} ip addr add "${dst_prefix1}${i}" dev veth_B-R1 1994 done 1995 1996 # Create 100 cached route exceptions for path via R1, one via R2 1997 for i in $(seq 100 199); do 1998 run_cmd ${ns_a} ping -q -M want -i 0.1 -w 1 -s 1800 "${dst_prefix1}${i}" 1999 done 2000 run_cmd ${ns_a} ping -q -M want -i 0.1 -w 1 -s 1800 "${dst2}" 2001 if [ "$(${ns_a} ip -oneline -6 route list cache | wc -l)" -ne 101 ]; then 2002 err " can't list cached exceptions" 2003 fail=1 2004 fi 2005 2006 run_cmd ${ns_a} ip -6 route flush cache 2007 pmtu1="$(route_get_dst_pmtu_from_exception "${ns_a}" "${dst_prefix1}100")" 2008 pmtu2="$(route_get_dst_pmtu_from_exception "${ns_a}" ${dst2})" 2009 if [ -n "${pmtu1}" ] || [ -n "${pmtu2}" ] || \ 2010 [ -n "$(${ns_a} ip -6 route list cache)" ]; then 2011 err " can't flush cached exceptions" 2012 fail=1 2013 fi 2014 2015 return ${fail} 2016} 2017 2018test_pmtu_ipvX_route_change() { 2019 family=${1} 2020 2021 setup namespaces routing || return 2 2022 trace "${ns_a}" veth_A-R1 "${ns_r1}" veth_R1-A \ 2023 "${ns_r1}" veth_R1-B "${ns_b}" veth_B-R1 \ 2024 "${ns_a}" veth_A-R2 "${ns_r2}" veth_R2-A \ 2025 "${ns_r2}" veth_R2-B "${ns_b}" veth_B-R2 2026 2027 if [ ${family} -eq 4 ]; then 2028 ping=ping 2029 dst1="${prefix4}.${b_r1}.1" 2030 dst2="${prefix4}.${b_r2}.1" 2031 gw="${prefix4}.${a_r1}.2" 2032 else 2033 ping=${ping6} 2034 dst1="${prefix6}:${b_r1}::1" 2035 dst2="${prefix6}:${b_r2}::1" 2036 gw="${prefix6}:${a_r1}::2" 2037 fi 2038 2039 # Set up initial MTU values 2040 mtu "${ns_a}" veth_A-R1 2000 2041 mtu "${ns_r1}" veth_R1-A 2000 2042 mtu "${ns_r1}" veth_R1-B 1400 2043 mtu "${ns_b}" veth_B-R1 1400 2044 2045 mtu "${ns_a}" veth_A-R2 2000 2046 mtu "${ns_r2}" veth_R2-A 2000 2047 mtu "${ns_r2}" veth_R2-B 1500 2048 mtu "${ns_b}" veth_B-R2 1500 2049 2050 # Create route exceptions 2051 run_cmd ${ns_a} ${ping} -q -M want -i 0.1 -w 1 -s 1800 ${dst1} 2052 run_cmd ${ns_a} ${ping} -q -M want -i 0.1 -w 1 -s 1800 ${dst2} 2053 2054 # Check that exceptions have been created with the correct PMTU 2055 pmtu_1="$(route_get_dst_pmtu_from_exception "${ns_a}" ${dst1})" 2056 check_pmtu_value "1400" "${pmtu_1}" "exceeding MTU" || return 1 2057 pmtu_2="$(route_get_dst_pmtu_from_exception "${ns_a}" ${dst2})" 2058 check_pmtu_value "1500" "${pmtu_2}" "exceeding MTU" || return 1 2059 2060 # Replace the route from A to R1 2061 run_cmd ${ns_a} ip route change default via ${gw} 2062 2063 # Delete the device in A 2064 run_cmd ${ns_a} ip link del "veth_A-R1" 2065} 2066 2067test_pmtu_ipv4_route_change() { 2068 test_pmtu_ipvX_route_change 4 2069} 2070 2071test_pmtu_ipv6_route_change() { 2072 test_pmtu_ipvX_route_change 6 2073} 2074 2075usage() { 2076 echo 2077 echo "$0 [OPTIONS] [TEST]..." 2078 echo "If no TEST argument is given, all tests will be run." 2079 echo 2080 echo "Options" 2081 echo " --trace: capture traffic to TEST_INTERFACE.pcap" 2082 echo 2083 echo "Available tests${tests}" 2084 exit 1 2085} 2086 2087################################################################################ 2088# 2089exitcode=0 2090desc=0 2091all_skipped=true 2092 2093while getopts :ptv o 2094do 2095 case $o in 2096 p) PAUSE_ON_FAIL=yes;; 2097 v) VERBOSE=1;; 2098 t) if which tcpdump > /dev/null 2>&1; then 2099 TRACING=1 2100 else 2101 echo "=== tcpdump not available, tracing disabled" 2102 fi 2103 ;; 2104 *) usage;; 2105 esac 2106done 2107shift $(($OPTIND-1)) 2108 2109IFS=" 2110" 2111 2112for arg do 2113 # Check first that all requested tests are available before running any 2114 command -v > /dev/null "test_${arg}" || { echo "=== Test ${arg} not found"; usage; } 2115done 2116 2117trap cleanup EXIT 2118 2119# start clean 2120cleanup 2121 2122HAVE_NH=no 2123ip nexthop ls >/dev/null 2>&1 2124[ $? -eq 0 ] && HAVE_NH=yes 2125 2126name="" 2127desc="" 2128rerun_nh=0 2129for t in ${tests}; do 2130 [ "${name}" = "" ] && name="${t}" && continue 2131 [ "${desc}" = "" ] && desc="${t}" && continue 2132 2133 if [ "${HAVE_NH}" = "yes" ]; then 2134 rerun_nh="${t}" 2135 fi 2136 2137 run_this=1 2138 for arg do 2139 [ "${arg}" != "${arg#--*}" ] && continue 2140 [ "${arg}" = "${name}" ] && run_this=1 && break 2141 run_this=0 2142 done 2143 if [ $run_this -eq 1 ]; then 2144 run_test "${name}" "${desc}" 2145 # if test was skipped no need to retry with nexthop objects 2146 [ $? -eq $ksft_skip ] && rerun_nh=0 2147 2148 if [ "${rerun_nh}" = "1" ]; then 2149 run_test_nh "${name}" "${desc}" 2150 fi 2151 fi 2152 name="" 2153 desc="" 2154 rerun_nh=0 2155done 2156 2157exit ${exitcode} 2158