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