2415 lines · bash
1#!/bin/bash2# SPDX-License-Identifier: GPL-2.03#4# Check that route PMTU values match expectations, and that initial device MTU5# values are assigned correctly6#7# Tests currently implemented:8#9# - pmtu_ipv410# Set up two namespaces, A and B, with two paths between them over routers11# R1 and R2 (also implemented with namespaces), with different MTUs:12#13# segment a_r1 segment b_r1 a_r1: 200014# .--------------R1--------------. b_r1: 140015# A B a_r2: 200016# '--------------R2--------------' b_r2: 150017# segment a_r2 segment b_r218#19# Check that PMTU exceptions with the correct PMTU are created. Then20# 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 over22# this path. Also check that locked exceptions are created when an ICMP23# message advertising a PMTU smaller than net.ipv4.route.min_pmtu is24# received25#26# - pmtu_ipv627# Same as pmtu_ipv4, except for locked PMTU tests, using IPv628#29# - pmtu_ipv4_dscp_icmp_exception30# Set up the same network topology as pmtu_ipv4, but use non-default31# routing table in A. A fib-rule is used to jump to this routing table32# based on DSCP. Send ICMPv4 packets with the expected DSCP value and33# verify that ECN doesn't interfere with the creation of PMTU exceptions.34#35# - pmtu_ipv4_dscp_udp_exception36# Same as pmtu_ipv4_dscp_icmp_exception, but use UDP instead of ICMP.37#38# - pmtu_ipv4_vxlan4_exception39# Set up the same network topology as pmtu_ipv4, create a VXLAN tunnel40# 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 and42# R1. Send IPv4 packets, exceeding the MTU between R1 and B, over VXLAN43# from A to B and check that the PMTU exception is created with the right44# value on A45#46# - pmtu_ipv6_vxlan4_exception47# Same as pmtu_ipv4_vxlan4_exception, but send IPv6 packets from A to B48#49# - pmtu_ipv4_vxlan6_exception50# Same as pmtu_ipv4_vxlan4_exception, but use IPv6 transport from A to B51#52# - pmtu_ipv6_vxlan6_exception53# Same as pmtu_ipv4_vxlan6_exception, but send IPv6 packets from A to B54#55# - pmtu_ipv4_geneve4_exception56# Same as pmtu_ipv4_vxlan4_exception, but using a GENEVE tunnel instead of57# VXLAN58#59# - pmtu_ipv6_geneve4_exception60# Same as pmtu_ipv6_vxlan4_exception, but using a GENEVE tunnel instead of61# VXLAN62#63# - pmtu_ipv4_geneve6_exception64# Same as pmtu_ipv4_vxlan6_exception, but using a GENEVE tunnel instead of65# VXLAN66#67# - pmtu_ipv6_geneve6_exception68# Same as pmtu_ipv6_vxlan6_exception, but using a GENEVE tunnel instead of69# VXLAN70#71# - pmtu_ipv{4,6}_br_vxlan{4,6}_exception72# Set up three namespaces, A, B, and C, with routing between A and B over73# R1. R2 is unused in these tests. A has a veth connection to C, and is74# 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 VXLAN78# tunnel, and that PMTU exceptions with the correct values are created.79#80# segment a_r1 segment b_r1 b_r1: 400081# .--------------R1--------------. everything82# C---veth A B else: 500083# ' bridge |84# '---- - - - - - VXLAN - - - - - - - '85#86# - pmtu_ipv{4,6}_br_geneve{4,6}_exception87# Same as pmtu_ipv{4,6}_br_vxlan{4,6}_exception, with a GENEVE tunnel88# instead.89#90# - pmtu_ipv{4,6}_ovs_vxlan{4,6}_exception91# Set up two namespaces, B, and C, with routing between the init namespace92# and B over R1. A and R2 are unused in these tests. The init namespace93# 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 link95# is lower than other MTUs.96#97# Check that C is able to communicate with B over the VXLAN tunnel, and98# that PMTU exceptions with the correct values are created.99#100# segment a_r1 segment b_r1 b_r1: 4000101# .--------------R1--------------. everything102# C---veth init B else: 5000103# '- ovs |104# '---- - - - - - VXLAN - - - - - - - '105#106# - pmtu_ipv{4,6}_ovs_geneve{4,6}_exception107# Same as pmtu_ipv{4,6}_ovs_vxlan{4,6}_exception, with a GENEVE tunnel108# instead.109#110# - pmtu_ipv{4,6}_fou{4,6}_exception111# Same as pmtu_ipv4_vxlan4, but using a direct IPv4/IPv6 encapsulation112# (FoU) over IPv4/IPv6, instead of VXLAN113#114# - pmtu_ipv{4,6}_fou{4,6}_exception115# Same as pmtu_ipv4_vxlan4, but using a generic UDP IPv4/IPv6116# encapsulation (GUE) over IPv4/IPv6, instead of VXLAN117#118# - pmtu_ipv{4,6}_ipv{4,6}_exception119# Same as pmtu_ipv4_vxlan4, but using a IPv4/IPv6 tunnel over IPv4/IPv6,120# instead of VXLAN121#122# - pmtu_vti4_exception123# Set up vti tunnel on top of veth, with xfrm states and policies, in two124# namespaces with matching endpoints. Check that route exception is not125# created if link layer MTU is not exceeded, then exceed it and check that126# exception is created with the expected PMTU. The approach described127# below for IPv6 doesn't apply here, because, on IPv4, administrative MTU128# changes alone won't affect PMTU129#130# - pmtu_vti4_udp_exception131# Same as pmtu_vti4_exception, but using ESP-in-UDP132#133# - pmtu_vti4_udp_routed_exception134# Set up vti tunnel on top of veth connected through routing namespace and135# add xfrm states and policies with ESP-in-UDP encapsulation. Check that136# route exception is not created if link layer MTU is not exceeded, then137# lower MTU on second part of routed environment and check that exception138# is created with the expected PMTU.139#140# - pmtu_vti6_exception141# Set up vti6 tunnel on top of veth, with xfrm states and policies, in two142# namespaces with matching endpoints. Check that route exception is143# created by exceeding link layer MTU with ping to other endpoint. Then144# decrease and increase MTU of tunnel, checking that route exception PMTU145# changes accordingly146#147# - pmtu_vti6_udp_exception148# Same as pmtu_vti6_exception, but using ESP-in-UDP149#150# - pmtu_vti6_udp_routed_exception151# Same as pmtu_vti6_udp_routed_exception but with routing between vti152# endpoints153#154# - pmtu_vti4_default_mtu155# Set up vti4 tunnel on top of veth, in two namespaces with matching156# endpoints. Check that MTU assigned to vti interface is the MTU of the157# lower layer (veth) minus additional lower layer headers (zero, for veth)158# minus IPv4 header length159#160# - pmtu_vti6_default_mtu161# Same as above, for IPv6162#163# - pmtu_vti4_link_add_mtu164# Set up vti4 interface passing MTU value at link creation, check MTU is165# configured, and that link is not created with invalid MTU values166#167# - pmtu_vti6_link_add_mtu168# Same as above, for IPv6169#170# - pmtu_vti6_link_change_mtu171# Set up two dummy interfaces with different MTUs, create a vti6 tunnel172# and check that configured MTU is used on link creation and changes, and173# that MTU is properly calculated instead when MTU is not configured from174# userspace175#176# - cleanup_ipv4_exception177# Similar to pmtu_ipv4_vxlan4_exception, but explicitly generate PMTU178# exceptions on multiple CPUs and check that the veth device tear-down179# happens in a timely manner180#181# - cleanup_ipv6_exception182# Same as above, but use IPv6 transport from A to B183#184# - list_flush_ipv4_exception185# Using the same topology as in pmtu_ipv4, create exceptions, and check186# they are shown when listing exception caches, gone after flushing them187#188# - list_flush_ipv6_exception189# Using the same topology as in pmtu_ipv6, create exceptions, and check190# they are shown when listing exception caches, gone after flushing them191#192# - pmtu_ipv4_route_change193# Use the same topology as in pmtu_ipv4, but issue a route replacement194# command and delete the corresponding device afterward. This tests for195# proper cleanup of the PMTU exceptions by the route replacement path.196# Device unregistration should complete successfully197#198# - pmtu_ipv6_route_change199# Same as above but with IPv6200 201source lib.sh202source net_helper.sh203 204PAUSE_ON_FAIL=no205VERBOSE=0206TRACING=0207 208# Some systems don't have a ping6 binary anymore209which ping6 > /dev/null 2>&1 && ping6=$(which ping6) || ping6=$(which ping)210 211# Name Description re-run with nh212tests="213 pmtu_ipv4_exception ipv4: PMTU exceptions 1214 pmtu_ipv6_exception ipv6: PMTU exceptions 1215 pmtu_ipv4_dscp_icmp_exception ICMPv4 with DSCP and ECN: PMTU exceptions 1216 pmtu_ipv4_dscp_udp_exception UDPv4 with DSCP and ECN: PMTU exceptions 1217 pmtu_ipv4_vxlan4_exception IPv4 over vxlan4: PMTU exceptions 1218 pmtu_ipv6_vxlan4_exception IPv6 over vxlan4: PMTU exceptions 1219 pmtu_ipv4_vxlan6_exception IPv4 over vxlan6: PMTU exceptions 1220 pmtu_ipv6_vxlan6_exception IPv6 over vxlan6: PMTU exceptions 1221 pmtu_ipv4_geneve4_exception IPv4 over geneve4: PMTU exceptions 1222 pmtu_ipv6_geneve4_exception IPv6 over geneve4: PMTU exceptions 1223 pmtu_ipv4_geneve6_exception IPv4 over geneve6: PMTU exceptions 1224 pmtu_ipv6_geneve6_exception IPv6 over geneve6: PMTU exceptions 1225 pmtu_ipv4_br_vxlan4_exception IPv4, bridged vxlan4: PMTU exceptions 1226 pmtu_ipv6_br_vxlan4_exception IPv6, bridged vxlan4: PMTU exceptions 1227 pmtu_ipv4_br_vxlan6_exception IPv4, bridged vxlan6: PMTU exceptions 1228 pmtu_ipv6_br_vxlan6_exception IPv6, bridged vxlan6: PMTU exceptions 1229 pmtu_ipv4_br_geneve4_exception IPv4, bridged geneve4: PMTU exceptions 1230 pmtu_ipv6_br_geneve4_exception IPv6, bridged geneve4: PMTU exceptions 1231 pmtu_ipv4_br_geneve6_exception IPv4, bridged geneve6: PMTU exceptions 1232 pmtu_ipv6_br_geneve6_exception IPv6, bridged geneve6: PMTU exceptions 1233 pmtu_ipv4_ovs_vxlan4_exception IPv4, OVS vxlan4: PMTU exceptions 1234 pmtu_ipv6_ovs_vxlan4_exception IPv6, OVS vxlan4: PMTU exceptions 1235 pmtu_ipv4_ovs_vxlan6_exception IPv4, OVS vxlan6: PMTU exceptions 1236 pmtu_ipv6_ovs_vxlan6_exception IPv6, OVS vxlan6: PMTU exceptions 1237 pmtu_ipv4_ovs_geneve4_exception IPv4, OVS geneve4: PMTU exceptions 1238 pmtu_ipv6_ovs_geneve4_exception IPv6, OVS geneve4: PMTU exceptions 1239 pmtu_ipv4_ovs_geneve6_exception IPv4, OVS geneve6: PMTU exceptions 1240 pmtu_ipv6_ovs_geneve6_exception IPv6, OVS geneve6: PMTU exceptions 1241 pmtu_ipv4_fou4_exception IPv4 over fou4: PMTU exceptions 1242 pmtu_ipv6_fou4_exception IPv6 over fou4: PMTU exceptions 1243 pmtu_ipv4_fou6_exception IPv4 over fou6: PMTU exceptions 1244 pmtu_ipv6_fou6_exception IPv6 over fou6: PMTU exceptions 1245 pmtu_ipv4_gue4_exception IPv4 over gue4: PMTU exceptions 1246 pmtu_ipv6_gue4_exception IPv6 over gue4: PMTU exceptions 1247 pmtu_ipv4_gue6_exception IPv4 over gue6: PMTU exceptions 1248 pmtu_ipv6_gue6_exception IPv6 over gue6: PMTU exceptions 1249 pmtu_ipv4_ipv4_exception IPv4 over IPv4: PMTU exceptions 1250 pmtu_ipv6_ipv4_exception IPv6 over IPv4: PMTU exceptions 1251 pmtu_ipv4_ipv6_exception IPv4 over IPv6: PMTU exceptions 1252 pmtu_ipv6_ipv6_exception IPv6 over IPv6: PMTU exceptions 1253 pmtu_vti6_exception vti6: PMTU exceptions 0254 pmtu_vti4_exception vti4: PMTU exceptions 0255 pmtu_vti6_udp_exception vti6: PMTU exceptions (ESP-in-UDP) 0256 pmtu_vti4_udp_exception vti4: PMTU exceptions (ESP-in-UDP) 0257 pmtu_vti6_udp_routed_exception vti6: PMTU exceptions, routed (ESP-in-UDP) 0258 pmtu_vti4_udp_routed_exception vti4: PMTU exceptions, routed (ESP-in-UDP) 0259 pmtu_vti4_default_mtu vti4: default MTU assignment 0260 pmtu_vti6_default_mtu vti6: default MTU assignment 0261 pmtu_vti4_link_add_mtu vti4: MTU setting on link creation 0262 pmtu_vti6_link_add_mtu vti6: MTU setting on link creation 0263 pmtu_vti6_link_change_mtu vti6: MTU changes on link changes 0264 cleanup_ipv4_exception ipv4: cleanup of cached exceptions 1265 cleanup_ipv6_exception ipv6: cleanup of cached exceptions 1266 list_flush_ipv4_exception ipv4: list and flush cached exceptions 1267 list_flush_ipv6_exception ipv6: list and flush cached exceptions 1268 pmtu_ipv4_route_change ipv4: PMTU exception w/route replace 1269 pmtu_ipv6_route_change ipv6: PMTU exception w/route replace 1"270 271# Addressing and routing for tests with routers: four network segments, with272# index SEGMENT between 1 and 4, a common prefix (PREFIX4 or PREFIX6) and an273# identifier ID, which is 1 for hosts (A and B), 2 for routers (R1 and R2).274# Addresses are:275# - IPv4: PREFIX4.SEGMENT.ID (/24)276# - IPv6: PREFIX6:SEGMENT::ID (/64)277prefix4="10.0"278prefix6="fc00"279a_r1=1280a_r2=2281b_r1=3282b_r2=4283# ns peer segment284routing_addrs="285 A R1 ${a_r1}286 A R2 ${a_r2}287 B R1 ${b_r1}288 B R2 ${b_r2}289"290# Traffic from A to B goes through R1 by default, and through R2, if destined to291# B's address on the b_r2 segment.292# Traffic from B to A goes through R1.293# ns destination gateway294routes="295 A default ${prefix4}.${a_r1}.2296 A ${prefix4}.${b_r2}.1 ${prefix4}.${a_r2}.2297 B default ${prefix4}.${b_r1}.2298 299 A default ${prefix6}:${a_r1}::2300 A ${prefix6}:${b_r2}::1 ${prefix6}:${a_r2}::2301 B default ${prefix6}:${b_r1}::2302"303USE_NH="no"304# ns family nh id destination gateway305nexthops="306 A 4 41 ${prefix4}.${a_r1}.2 veth_A-R1307 A 4 42 ${prefix4}.${a_r2}.2 veth_A-R2308 B 4 41 ${prefix4}.${b_r1}.2 veth_B-R1309 310 A 6 61 ${prefix6}:${a_r1}::2 veth_A-R1311 A 6 62 ${prefix6}:${a_r2}::2 veth_A-R2312 B 6 61 ${prefix6}:${b_r1}::2 veth_B-R1313"314 315# nexthop id correlates to id in nexthops config above316# ns family prefix nh id317routes_nh="318 A 4 default 41319 A 4 ${prefix4}.${b_r2}.1 42320 B 4 default 41321 322 A 6 default 61323 A 6 ${prefix6}:${b_r2}::1 62324 B 6 default 61325"326 327policy_mark=0x04328rt_table=main329 330veth4_a_addr="192.168.1.1"331veth4_b_addr="192.168.1.2"332veth4_c_addr="192.168.2.10"333veth4_mask="24"334veth6_a_addr="fd00:1::a"335veth6_b_addr="fd00:1::b"336veth6_c_addr="fd00:2::c"337veth6_mask="64"338 339tunnel4_a_addr="192.168.2.1"340tunnel4_b_addr="192.168.2.2"341tunnel4_mask="24"342tunnel6_a_addr="fd00:2::a"343tunnel6_b_addr="fd00:2::b"344tunnel6_mask="64"345 346dummy6_0_prefix="fc00:1000::"347dummy6_1_prefix="fc00:1001::"348dummy6_mask="64"349 350err_buf=351tcpdump_pids=352nettest_pids=353socat_pids=354tmpoutfile=355 356err() {357 err_buf="${err_buf}${1}358"359}360 361err_flush() {362 echo -n "${err_buf}"363 err_buf=364}365 366run_cmd() {367 cmd="$*"368 369 if [ "$VERBOSE" = "1" ]; then370 printf " COMMAND: $cmd\n"371 fi372 373 out="$($cmd 2>&1)"374 rc=$?375 if [ "$VERBOSE" = "1" -a -n "$out" ]; then376 echo " $out"377 echo378 fi379 380 return $rc381}382 383run_cmd_bg() {384 cmd="$*"385 386 if [ "$VERBOSE" = "1" ]; then387 printf " COMMAND: %s &\n" "${cmd}"388 fi389 390 $cmd 2>&1 &391}392 393# Find the auto-generated name for this namespace394nsname() {395 eval echo \$NS_$1396}397 398setup_fou_or_gue() {399 outer="${1}"400 inner="${2}"401 encap="${3}"402 403 if [ "${outer}" = "4" ]; then404 modprobe fou || return $ksft_skip405 a_addr="${prefix4}.${a_r1}.1"406 b_addr="${prefix4}.${b_r1}.1"407 if [ "${inner}" = "4" ]; then408 type="ipip"409 ipproto="4"410 else411 type="sit"412 ipproto="41"413 fi414 else415 modprobe fou6 || return $ksft_skip416 a_addr="${prefix6}:${a_r1}::1"417 b_addr="${prefix6}:${b_r1}::1"418 if [ "${inner}" = "4" ]; then419 type="ip6tnl"420 mode="mode ipip6"421 ipproto="4 -6"422 else423 type="ip6tnl"424 mode="mode ip6ip6"425 ipproto="41 -6"426 fi427 fi428 429 run_cmd ${ns_a} ip fou add port 5555 ipproto ${ipproto} || return $ksft_skip430 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_skip431 432 run_cmd ${ns_b} ip fou add port 5556 ipproto ${ipproto}433 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 5555434 435 if [ "${inner}" = "4" ]; then436 run_cmd ${ns_a} ip addr add ${tunnel4_a_addr}/${tunnel4_mask} dev ${encap}_a437 run_cmd ${ns_b} ip addr add ${tunnel4_b_addr}/${tunnel4_mask} dev ${encap}_b438 else439 run_cmd ${ns_a} ip addr add ${tunnel6_a_addr}/${tunnel6_mask} dev ${encap}_a440 run_cmd ${ns_b} ip addr add ${tunnel6_b_addr}/${tunnel6_mask} dev ${encap}_b441 fi442 443 run_cmd ${ns_a} ip link set ${encap}_a up444 run_cmd ${ns_b} ip link set ${encap}_b up445}446 447setup_fou44() {448 setup_fou_or_gue 4 4 fou449}450 451setup_fou46() {452 setup_fou_or_gue 4 6 fou453}454 455setup_fou64() {456 setup_fou_or_gue 6 4 fou457}458 459setup_fou66() {460 setup_fou_or_gue 6 6 fou461}462 463setup_gue44() {464 setup_fou_or_gue 4 4 gue465}466 467setup_gue46() {468 setup_fou_or_gue 4 6 gue469}470 471setup_gue64() {472 setup_fou_or_gue 6 4 gue473}474 475setup_gue66() {476 setup_fou_or_gue 6 6 gue477}478 479setup_ipvX_over_ipvY() {480 inner=${1}481 outer=${2}482 483 if [ "${outer}" -eq 4 ]; then484 a_addr="${prefix4}.${a_r1}.1"485 b_addr="${prefix4}.${b_r1}.1"486 if [ "${inner}" -eq 4 ]; then487 type="ipip"488 mode="ipip"489 else490 type="sit"491 mode="ip6ip"492 fi493 else494 a_addr="${prefix6}:${a_r1}::1"495 b_addr="${prefix6}:${b_r1}::1"496 type="ip6tnl"497 if [ "${inner}" -eq 4 ]; then498 mode="ipip6"499 else500 mode="ip6ip6"501 fi502 fi503 504 run_cmd ${ns_a} ip link add ip_a type ${type} local ${a_addr} remote ${b_addr} mode ${mode} || return $ksft_skip505 run_cmd ${ns_b} ip link add ip_b type ${type} local ${b_addr} remote ${a_addr} mode ${mode}506 507 run_cmd ${ns_a} ip link set ip_a up508 run_cmd ${ns_b} ip link set ip_b up509 510 if [ "${inner}" = "4" ]; then511 run_cmd ${ns_a} ip addr add ${tunnel4_a_addr}/${tunnel4_mask} dev ip_a512 run_cmd ${ns_b} ip addr add ${tunnel4_b_addr}/${tunnel4_mask} dev ip_b513 else514 run_cmd ${ns_a} ip addr add ${tunnel6_a_addr}/${tunnel6_mask} dev ip_a515 run_cmd ${ns_b} ip addr add ${tunnel6_b_addr}/${tunnel6_mask} dev ip_b516 fi517}518 519setup_ip4ip4() {520 setup_ipvX_over_ipvY 4 4521}522 523setup_ip6ip4() {524 setup_ipvX_over_ipvY 6 4525}526 527setup_ip4ip6() {528 setup_ipvX_over_ipvY 4 6529}530 531setup_ip6ip6() {532 setup_ipvX_over_ipvY 6 6533}534 535setup_namespaces() {536 setup_ns NS_A NS_B NS_C NS_R1 NS_R2537 for n in ${NS_A} ${NS_B} ${NS_C} ${NS_R1} ${NS_R2}; do538 # Disable DAD, so that we don't have to wait to use the539 # configured IPv6 addresses540 ip netns exec ${n} sysctl -q net/ipv6/conf/default/accept_dad=0541 done542 ns_a="ip netns exec ${NS_A}"543 ns_b="ip netns exec ${NS_B}"544 ns_c="ip netns exec ${NS_C}"545 ns_r1="ip netns exec ${NS_R1}"546 ns_r2="ip netns exec ${NS_R2}"547}548 549setup_veth() {550 run_cmd ${ns_a} ip link add veth_a type veth peer name veth_b || return 1551 run_cmd ${ns_a} ip link set veth_b netns ${NS_B}552 553 run_cmd ${ns_a} ip addr add ${veth4_a_addr}/${veth4_mask} dev veth_a554 run_cmd ${ns_b} ip addr add ${veth4_b_addr}/${veth4_mask} dev veth_b555 556 run_cmd ${ns_a} ip addr add ${veth6_a_addr}/${veth6_mask} dev veth_a557 run_cmd ${ns_b} ip addr add ${veth6_b_addr}/${veth6_mask} dev veth_b558 559 run_cmd ${ns_a} ip link set veth_a up560 run_cmd ${ns_b} ip link set veth_b up561}562 563setup_vti() {564 proto=${1}565 veth_a_addr="${2}"566 veth_b_addr="${3}"567 vti_a_addr="${4}"568 vti_b_addr="${5}"569 vti_mask=${6}570 571 [ ${proto} -eq 6 ] && vti_type="vti6" || vti_type="vti"572 573 run_cmd ${ns_a} ip link add vti${proto}_a type ${vti_type} local ${veth_a_addr} remote ${veth_b_addr} key 10 || return 1574 run_cmd ${ns_b} ip link add vti${proto}_b type ${vti_type} local ${veth_b_addr} remote ${veth_a_addr} key 10575 576 run_cmd ${ns_a} ip addr add ${vti_a_addr}/${vti_mask} dev vti${proto}_a577 run_cmd ${ns_b} ip addr add ${vti_b_addr}/${vti_mask} dev vti${proto}_b578 579 run_cmd ${ns_a} ip link set vti${proto}_a up580 run_cmd ${ns_b} ip link set vti${proto}_b up581}582 583setup_vti4() {584 setup_vti 4 ${veth4_a_addr} ${veth4_b_addr} ${tunnel4_a_addr} ${tunnel4_b_addr} ${tunnel4_mask}585}586 587setup_vti6() {588 setup_vti 6 ${veth6_a_addr} ${veth6_b_addr} ${tunnel6_a_addr} ${tunnel6_b_addr} ${tunnel6_mask}589}590 591setup_vti4routed() {592 setup_vti 4 ${prefix4}.${a_r1}.1 ${prefix4}.${b_r1}.1 ${tunnel4_a_addr} ${tunnel4_b_addr} ${tunnel4_mask}593}594 595setup_vti6routed() {596 setup_vti 6 ${prefix6}:${a_r1}::1 ${prefix6}:${b_r1}::1 ${tunnel6_a_addr} ${tunnel6_b_addr} ${tunnel6_mask}597}598 599setup_vxlan_or_geneve() {600 type="${1}"601 a_addr="${2}"602 b_addr="${3}"603 opts="${4}"604 br_if_a="${5}"605 606 if [ "${type}" = "vxlan" ]; then607 opts="${opts} ttl 64 dstport 4789"608 opts_a="local ${a_addr}"609 opts_b="local ${b_addr}"610 else611 opts_a=""612 opts_b=""613 fi614 615 run_cmd ${ns_a} ip link add ${type}_a type ${type} id 1 ${opts_a} remote ${b_addr} ${opts} || return 1616 run_cmd ${ns_b} ip link add ${type}_b type ${type} id 1 ${opts_b} remote ${a_addr} ${opts}617 618 if [ -n "${br_if_a}" ]; then619 run_cmd ${ns_a} ip addr add ${tunnel4_a_addr}/${tunnel4_mask} dev ${br_if_a}620 run_cmd ${ns_a} ip addr add ${tunnel6_a_addr}/${tunnel6_mask} dev ${br_if_a}621 run_cmd ${ns_a} ip link set ${type}_a master ${br_if_a}622 else623 run_cmd ${ns_a} ip addr add ${tunnel4_a_addr}/${tunnel4_mask} dev ${type}_a624 run_cmd ${ns_a} ip addr add ${tunnel6_a_addr}/${tunnel6_mask} dev ${type}_a625 fi626 627 run_cmd ${ns_b} ip addr add ${tunnel4_b_addr}/${tunnel4_mask} dev ${type}_b628 run_cmd ${ns_b} ip addr add ${tunnel6_b_addr}/${tunnel6_mask} dev ${type}_b629 630 run_cmd ${ns_a} ip link set ${type}_a up631 run_cmd ${ns_b} ip link set ${type}_b up632}633 634setup_geneve4() {635 setup_vxlan_or_geneve geneve ${prefix4}.${a_r1}.1 ${prefix4}.${b_r1}.1 "df set"636}637 638setup_vxlan4() {639 setup_vxlan_or_geneve vxlan ${prefix4}.${a_r1}.1 ${prefix4}.${b_r1}.1 "df set"640}641 642setup_geneve6() {643 setup_vxlan_or_geneve geneve ${prefix6}:${a_r1}::1 ${prefix6}:${b_r1}::1 ""644}645 646setup_vxlan6() {647 setup_vxlan_or_geneve vxlan ${prefix6}:${a_r1}::1 ${prefix6}:${b_r1}::1 ""648}649 650setup_bridged_geneve4() {651 setup_vxlan_or_geneve geneve ${prefix4}.${a_r1}.1 ${prefix4}.${b_r1}.1 "df set" "br0"652}653 654setup_bridged_vxlan4() {655 setup_vxlan_or_geneve vxlan ${prefix4}.${a_r1}.1 ${prefix4}.${b_r1}.1 "df set" "br0"656}657 658setup_bridged_geneve6() {659 setup_vxlan_or_geneve geneve ${prefix6}:${a_r1}::1 ${prefix6}:${b_r1}::1 "" "br0"660}661 662setup_bridged_vxlan6() {663 setup_vxlan_or_geneve vxlan ${prefix6}:${a_r1}::1 ${prefix6}:${b_r1}::1 "" "br0"664}665 666setup_xfrm() {667 proto=${1}668 veth_a_addr="${2}"669 veth_b_addr="${3}"670 encap=${4}671 672 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 1673 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}674 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 tunnel675 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 tunnel676 677 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}678 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}679 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 tunnel680 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 tunnel681}682 683setup_nettest_xfrm() {684 check_gen_prog "nettest"685 686 [ ${1} -eq 6 ] && proto="-6" || proto=""687 port=${2}688 689 run_cmd_bg "${ns_a}" nettest "${proto}" -q -D -s -x -p "${port}" -t 5690 nettest_pids="${nettest_pids} $!"691 692 run_cmd_bg "${ns_b}" nettest "${proto}" -q -D -s -x -p "${port}" -t 5693 nettest_pids="${nettest_pids} $!"694}695 696setup_xfrm4() {697 setup_xfrm 4 ${veth4_a_addr} ${veth4_b_addr}698}699 700setup_xfrm6() {701 setup_xfrm 6 ${veth6_a_addr} ${veth6_b_addr}702}703 704setup_xfrm4udp() {705 setup_xfrm 4 ${veth4_a_addr} ${veth4_b_addr} "encap espinudp 4500 4500 0.0.0.0" && \706 setup_nettest_xfrm 4 4500707}708 709setup_xfrm6udp() {710 setup_xfrm 6 ${veth6_a_addr} ${veth6_b_addr} "encap espinudp 4500 4500 0.0.0.0" && \711 setup_nettest_xfrm 6 4500712}713 714setup_xfrm4udprouted() {715 setup_xfrm 4 ${prefix4}.${a_r1}.1 ${prefix4}.${b_r1}.1 "encap espinudp 4500 4500 0.0.0.0" && \716 setup_nettest_xfrm 4 4500717}718 719setup_xfrm6udprouted() {720 setup_xfrm 6 ${prefix6}:${a_r1}::1 ${prefix6}:${b_r1}::1 "encap espinudp 4500 4500 0.0.0.0" && \721 setup_nettest_xfrm 6 4500722}723 724setup_routing_old() {725 for i in ${routes}; do726 [ "${ns}" = "" ] && ns="${i}" && continue727 [ "${addr}" = "" ] && addr="${i}" && continue728 [ "${gw}" = "" ] && gw="${i}"729 730 ns_name="$(nsname ${ns})"731 732 ip -n "${ns_name}" route add "${addr}" table "${rt_table}" via "${gw}"733 734 ns=""; addr=""; gw=""735 done736}737 738setup_routing_new() {739 for i in ${nexthops}; do740 [ "${ns}" = "" ] && ns="${i}" && continue741 [ "${fam}" = "" ] && fam="${i}" && continue742 [ "${nhid}" = "" ] && nhid="${i}" && continue743 [ "${gw}" = "" ] && gw="${i}" && continue744 [ "${dev}" = "" ] && dev="${i}"745 746 ns_name="$(nsname ${ns})"747 748 ip -n ${ns_name} -${fam} nexthop add id ${nhid} via ${gw} dev ${dev}749 750 ns=""; fam=""; nhid=""; gw=""; dev=""751 752 done753 754 for i in ${routes_nh}; do755 [ "${ns}" = "" ] && ns="${i}" && continue756 [ "${fam}" = "" ] && fam="${i}" && continue757 [ "${addr}" = "" ] && addr="${i}" && continue758 [ "${nhid}" = "" ] && nhid="${i}"759 760 ns_name="$(nsname ${ns})"761 762 ip -n "${ns_name}" -"${fam}" route add "${addr}" table "${rt_table}" nhid "${nhid}"763 764 ns=""; fam=""; addr=""; nhid=""765 done766}767 768setup_routing() {769 for i in ${NS_R1} ${NS_R2}; do770 ip netns exec ${i} sysctl -q net/ipv4/ip_forward=1771 ip netns exec ${i} sysctl -q net/ipv6/conf/all/forwarding=1772 done773 774 for i in ${routing_addrs}; do775 [ "${ns}" = "" ] && ns="${i}" && continue776 [ "${peer}" = "" ] && peer="${i}" && continue777 [ "${segment}" = "" ] && segment="${i}"778 779 ns_name="$(nsname ${ns})"780 peer_name="$(nsname ${peer})"781 if="veth_${ns}-${peer}"782 ifpeer="veth_${peer}-${ns}"783 784 # Create veth links785 ip link add ${if} up netns ${ns_name} type veth peer name ${ifpeer} netns ${peer_name} || return 1786 ip -n ${peer_name} link set dev ${ifpeer} up787 788 # Add addresses789 ip -n ${ns_name} addr add ${prefix4}.${segment}.1/24 dev ${if}790 ip -n ${ns_name} addr add ${prefix6}:${segment}::1/64 dev ${if}791 792 ip -n ${peer_name} addr add ${prefix4}.${segment}.2/24 dev ${ifpeer}793 ip -n ${peer_name} addr add ${prefix6}:${segment}::2/64 dev ${ifpeer}794 795 ns=""; peer=""; segment=""796 done797 798 if [ "$USE_NH" = "yes" ]; then799 setup_routing_new800 else801 setup_routing_old802 fi803 804 return 0805}806 807setup_policy_routing() {808 setup_routing809 810 ip -netns "${NS_A}" -4 rule add dsfield "${policy_mark}" \811 table "${rt_table}"812 813 # Set the IPv4 Don't Fragment bit with tc, since socat doesn't seem to814 # have an option do to it.815 tc -netns "${NS_A}" qdisc replace dev veth_A-R1 root prio816 tc -netns "${NS_A}" qdisc replace dev veth_A-R2 root prio817 tc -netns "${NS_A}" filter add dev veth_A-R1 \818 protocol ipv4 flower ip_proto udp \819 action pedit ex munge ip df set 0x40 pipe csum ip and udp820 tc -netns "${NS_A}" filter add dev veth_A-R2 \821 protocol ipv4 flower ip_proto udp \822 action pedit ex munge ip df set 0x40 pipe csum ip and udp823}824 825setup_bridge() {826 run_cmd ${ns_a} ip link add br0 type bridge || return $ksft_skip827 run_cmd ${ns_a} ip link set br0 up828 829 run_cmd ${ns_c} ip link add veth_C-A type veth peer name veth_A-C830 run_cmd ${ns_c} ip link set veth_A-C netns ${NS_A}831 832 run_cmd ${ns_a} ip link set veth_A-C up833 run_cmd ${ns_c} ip link set veth_C-A up834 run_cmd ${ns_c} ip addr add ${veth4_c_addr}/${veth4_mask} dev veth_C-A835 run_cmd ${ns_c} ip addr add ${veth6_c_addr}/${veth6_mask} dev veth_C-A836 run_cmd ${ns_a} ip link set veth_A-C master br0837}838 839setup_ovs_via_internal_utility() {840 type="${1}"841 a_addr="${2}"842 b_addr="${3}"843 dport="${4}"844 845 run_cmd python3 ./openvswitch/ovs-dpctl.py add-if ovs_br0 ${type}_a -t ${type} || return 1846 847 ports=$(python3 ./openvswitch/ovs-dpctl.py show)848 br0_port=$(echo "$ports" | grep -E "\sovs_br0" | sed -e 's@port @@' | cut -d: -f1 | xargs)849 type_a_port=$(echo "$ports" | grep ${type}_a | sed -e 's@port @@' | cut -d: -f1 | xargs)850 veth_a_port=$(echo "$ports" | grep veth_A | sed -e 's@port @@' | cut -d: -f1 | xargs)851 852 v4_a_tun="${prefix4}.${a_r1}.1"853 v4_b_tun="${prefix4}.${b_r1}.1"854 855 v6_a_tun="${prefix6}:${a_r1}::1"856 v6_b_tun="${prefix6}:${b_r1}::1"857 858 if [ "${v4_a_tun}" = "${a_addr}" ]; then859 run_cmd python3 ./openvswitch/ovs-dpctl.py add-flow ovs_br0 \860 "recirc_id(0),in_port(${veth_a_port}),eth(),eth_type(0x0800),ipv4()" \861 "set(tunnel(tun_id=1,dst=${v4_b_tun},ttl=64,tp_dst=${dport},flags(df|csum))),${type_a_port}"862 run_cmd python3 ./openvswitch/ovs-dpctl.py add-flow ovs_br0 \863 "recirc_id(0),in_port(${veth_a_port}),eth(),eth_type(0x86dd),ipv6()" \864 "set(tunnel(tun_id=1,dst=${v4_b_tun},ttl=64,tp_dst=${dport},flags(df|csum))),${type_a_port}"865 run_cmd python3 ./openvswitch/ovs-dpctl.py add-flow ovs_br0 \866 "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()" \867 "${veth_a_port}"868 run_cmd python3 ./openvswitch/ovs-dpctl.py add-flow ovs_br0 \869 "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()" \870 "${veth_a_port}"871 run_cmd python3 ./openvswitch/ovs-dpctl.py add-flow ovs_br0 \872 "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()" \873 "${veth_a_port}"874 run_cmd python3 ./openvswitch/ovs-dpctl.py add-flow ovs_br0 \875 "recirc_id(0),in_port(${veth_a_port}),eth(),eth_type(0x0806),arp(sip=${veth4_c_addr},tip=${tunnel4_b_addr})" \876 "set(tunnel(tun_id=1,dst=${v4_b_tun},ttl=64,tp_dst=${dport},flags(df|csum))),${type_a_port}"877 else878 run_cmd python3 ./openvswitch/ovs-dpctl.py add-flow ovs_br0 \879 "recirc_id(0),in_port(${veth_a_port}),eth(),eth_type(0x0800),ipv4()" \880 "set(tunnel(tun_id=1,ipv6_dst=${v6_b_tun},ttl=64,tp_dst=${dport},flags(df|csum))),${type_a_port}"881 run_cmd python3 ./openvswitch/ovs-dpctl.py add-flow ovs_br0 \882 "recirc_id(0),in_port(${veth_a_port}),eth(),eth_type(0x86dd),ipv6()" \883 "set(tunnel(tun_id=1,ipv6_dst=${v6_b_tun},ttl=64,tp_dst=${dport},flags(df|csum))),${type_a_port}"884 run_cmd python3 ./openvswitch/ovs-dpctl.py add-flow ovs_br0 \885 "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()" \886 "${veth_a_port}"887 run_cmd python3 ./openvswitch/ovs-dpctl.py add-flow ovs_br0 \888 "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()" \889 "${veth_a_port}"890 run_cmd python3 ./openvswitch/ovs-dpctl.py add-flow ovs_br0 \891 "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()" \892 "${veth_a_port}"893 run_cmd python3 ./openvswitch/ovs-dpctl.py add-flow ovs_br0 \894 "recirc_id(0),in_port(${veth_a_port}),eth(),eth_type(0x0806),arp(sip=${veth4_c_addr},tip=${tunnel4_b_addr})" \895 "set(tunnel(tun_id=1,ipv6_dst=${v6_b_tun},ttl=64,tp_dst=${dport},flags(df|csum))),${type_a_port}"896 fi897}898 899setup_ovs_via_vswitchd() {900 type="${1}"901 b_addr="${2}"902 903 run_cmd ovs-vsctl add-port ovs_br0 ${type}_a -- \904 set interface ${type}_a type=${type} \905 options:remote_ip=${b_addr} options:key=1 options:csum=true || return 1906}907 908setup_ovs_vxlan_or_geneve() {909 type="${1}"910 a_addr="${2}"911 b_addr="${3}"912 dport="6081"913 914 if [ "${type}" = "vxlan" ]; then915 dport="4789"916 opts="${opts} ttl 64 dstport 4789"917 opts_b="local ${b_addr}"918 fi919 920 setup_ovs_via_internal_utility "${type}" "${a_addr}" "${b_addr}" \921 "${dport}" || \922 setup_ovs_via_vswitchd "${type}" "${b_addr}" || return 1923 924 run_cmd ${ns_b} ip link add ${type}_b type ${type} id 1 ${opts_b} remote ${a_addr} ${opts} || return 1925 926 run_cmd ${ns_b} ip addr add ${tunnel4_b_addr}/${tunnel4_mask} dev ${type}_b927 run_cmd ${ns_b} ip addr add ${tunnel6_b_addr}/${tunnel6_mask} dev ${type}_b928 929 run_cmd ip link set ${type}_a up930 run_cmd ${ns_b} ip link set ${type}_b up931}932 933setup_ovs_geneve4() {934 setup_ovs_vxlan_or_geneve geneve ${prefix4}.${a_r1}.1 ${prefix4}.${b_r1}.1935}936 937setup_ovs_vxlan4() {938 setup_ovs_vxlan_or_geneve vxlan ${prefix4}.${a_r1}.1 ${prefix4}.${b_r1}.1939}940 941setup_ovs_geneve6() {942 setup_ovs_vxlan_or_geneve geneve ${prefix6}:${a_r1}::1 ${prefix6}:${b_r1}::1943}944 945setup_ovs_vxlan6() {946 setup_ovs_vxlan_or_geneve vxlan ${prefix6}:${a_r1}::1 ${prefix6}:${b_r1}::1947}948 949setup_ovs_br_internal() {950 run_cmd python3 ./openvswitch/ovs-dpctl.py add-dp ovs_br0 || \951 return 1952}953 954setup_ovs_br_vswitchd() {955 run_cmd ovs-vsctl add-br ovs_br0 || return 1956}957 958setup_ovs_add_if() {959 ifname="${1}"960 run_cmd python3 ./openvswitch/ovs-dpctl.py add-if ovs_br0 \961 "${ifname}" || \962 run_cmd ovs-vsctl add-port ovs_br0 "${ifname}"963}964 965setup_ovs_bridge() {966 setup_ovs_br_internal || setup_ovs_br_vswitchd || return $ksft_skip967 run_cmd ip link set ovs_br0 up968 969 run_cmd ${ns_c} ip link add veth_C-A type veth peer name veth_A-C970 run_cmd ${ns_c} ip link set veth_A-C netns 1971 972 run_cmd ip link set veth_A-C up973 run_cmd ${ns_c} ip link set veth_C-A up974 run_cmd ${ns_c} ip addr add ${veth4_c_addr}/${veth4_mask} dev veth_C-A975 run_cmd ${ns_c} ip addr add ${veth6_c_addr}/${veth6_mask} dev veth_C-A976 setup_ovs_add_if veth_A-C977 978 # Move veth_A-R1 to init979 run_cmd ${ns_a} ip link set veth_A-R1 netns 1980 run_cmd ip addr add ${prefix4}.${a_r1}.1/${veth4_mask} dev veth_A-R1981 run_cmd ip addr add ${prefix6}:${a_r1}::1/${veth6_mask} dev veth_A-R1982 run_cmd ip link set veth_A-R1 up983 run_cmd ip route add ${prefix4}.${b_r1}.1 via ${prefix4}.${a_r1}.2984 run_cmd ip route add ${prefix6}:${b_r1}::1 via ${prefix6}:${a_r1}::2985}986 987setup() {988 [ "$(id -u)" -ne 0 ] && echo " need to run as root" && return $ksft_skip989 990 for arg do991 eval setup_${arg} || { echo " ${arg} not supported"; return 1; }992 done993}994 995trace() {996 [ $TRACING -eq 0 ] && return997 998 for arg do999 [ "${ns_cmd}" = "" ] && ns_cmd="${arg}" && continue1000 ${ns_cmd} tcpdump --immediate-mode -s 0 -i "${arg}" -w "${name}_${arg}.pcap" 2> /dev/null &1001 tcpdump_pids="${tcpdump_pids} $!"1002 ns_cmd=1003 done1004 sleep 11005}1006 1007cleanup_del_ovs_internal() {1008 # squelch the output of the del-if commands since it can be wordy1009 python3 ./openvswitch/ovs-dpctl.py del-if ovs_br0 -d true vxlan_a >/dev/null 2>&11010 python3 ./openvswitch/ovs-dpctl.py del-if ovs_br0 -d true geneve_a >/dev/null 2>&11011 python3 ./openvswitch/ovs-dpctl.py del-dp ovs_br0 >/dev/null 2>&11012}1013 1014cleanup_del_ovs_vswitchd() {1015 ovs-vsctl --if-exists del-port vxlan_a 2>/dev/null1016 ovs-vsctl --if-exists del-br ovs_br0 2>/dev/null1017}1018 1019cleanup() {1020 for pid in ${tcpdump_pids}; do1021 kill ${pid}1022 done1023 tcpdump_pids=1024 1025 for pid in ${nettest_pids}; do1026 kill ${pid}1027 done1028 nettest_pids=1029 1030 for pid in ${socat_pids}; do1031 kill "${pid}"1032 done1033 socat_pids=1034 1035 cleanup_all_ns1036 1037 ip link del veth_A-C 2>/dev/null1038 ip link del veth_A-R1 2>/dev/null1039 cleanup_del_ovs_internal1040 cleanup_del_ovs_vswitchd1041 rm -f "$tmpoutfile"1042}1043 1044mtu() {1045 ns_cmd="${1}"1046 dev="${2}"1047 mtu="${3}"1048 1049 ${ns_cmd} ip link set dev ${dev} mtu ${mtu}1050}1051 1052mtu_parse() {1053 input="${1}"1054 1055 next=01056 for i in ${input}; do1057 [ ${next} -eq 1 -a "${i}" = "lock" ] && next=2 && continue1058 [ ${next} -eq 1 ] && echo "${i}" && return1059 [ ${next} -eq 2 ] && echo "lock ${i}" && return1060 [ "${i}" = "mtu" ] && next=11061 done1062}1063 1064link_get() {1065 ns_cmd="${1}"1066 name="${2}"1067 1068 ${ns_cmd} ip link show dev "${name}"1069}1070 1071link_get_mtu() {1072 ns_cmd="${1}"1073 name="${2}"1074 1075 mtu_parse "$(link_get "${ns_cmd}" ${name})"1076}1077 1078route_get_dst_exception() {1079 ns_cmd="${1}"1080 dst="${2}"1081 dsfield="${3}"1082 1083 if [ -z "${dsfield}" ]; then1084 dsfield=01085 fi1086 1087 ${ns_cmd} ip route get "${dst}" dsfield "${dsfield}"1088}1089 1090route_get_dst_pmtu_from_exception() {1091 ns_cmd="${1}"1092 dst="${2}"1093 dsfield="${3}"1094 1095 mtu_parse "$(route_get_dst_exception "${ns_cmd}" "${dst}" "${dsfield}")"1096}1097 1098check_pmtu_value() {1099 expected="${1}"1100 value="${2}"1101 event="${3}"1102 1103 [ "${expected}" = "any" ] && [ -n "${value}" ] && return 01104 [ "${value}" = "${expected}" ] && return 01105 [ -z "${value}" ] && err " PMTU exception wasn't created after ${event}" && return 11106 [ -z "${expected}" ] && err " PMTU exception shouldn't exist after ${event}" && return 11107 err " found PMTU exception with incorrect MTU ${value}, expected ${expected}, after ${event}"1108 return 11109}1110 1111test_pmtu_ipvX() {1112 family=${1}1113 1114 setup namespaces routing || return $ksft_skip1115 trace "${ns_a}" veth_A-R1 "${ns_r1}" veth_R1-A \1116 "${ns_r1}" veth_R1-B "${ns_b}" veth_B-R1 \1117 "${ns_a}" veth_A-R2 "${ns_r2}" veth_R2-A \1118 "${ns_r2}" veth_R2-B "${ns_b}" veth_B-R21119 1120 if [ ${family} -eq 4 ]; then1121 ping=ping1122 dst1="${prefix4}.${b_r1}.1"1123 dst2="${prefix4}.${b_r2}.1"1124 else1125 ping=${ping6}1126 dst1="${prefix6}:${b_r1}::1"1127 dst2="${prefix6}:${b_r2}::1"1128 fi1129 1130 # Set up initial MTU values1131 mtu "${ns_a}" veth_A-R1 20001132 mtu "${ns_r1}" veth_R1-A 20001133 mtu "${ns_r1}" veth_R1-B 14001134 mtu "${ns_b}" veth_B-R1 14001135 1136 mtu "${ns_a}" veth_A-R2 20001137 mtu "${ns_r2}" veth_R2-A 20001138 mtu "${ns_r2}" veth_R2-B 15001139 mtu "${ns_b}" veth_B-R2 15001140 1141 # Create route exceptions1142 run_cmd ${ns_a} ${ping} -q -M want -i 0.1 -w 1 -s 1800 ${dst1}1143 run_cmd ${ns_a} ${ping} -q -M want -i 0.1 -w 1 -s 1800 ${dst2}1144 1145 # Check that exceptions have been created with the correct PMTU1146 pmtu_1="$(route_get_dst_pmtu_from_exception "${ns_a}" ${dst1})"1147 check_pmtu_value "1400" "${pmtu_1}" "exceeding MTU" || return 11148 pmtu_2="$(route_get_dst_pmtu_from_exception "${ns_a}" ${dst2})"1149 check_pmtu_value "1500" "${pmtu_2}" "exceeding MTU" || return 11150 1151 # Decrease local MTU below PMTU, check for PMTU decrease in route exception1152 mtu "${ns_a}" veth_A-R1 13001153 mtu "${ns_r1}" veth_R1-A 13001154 pmtu_1="$(route_get_dst_pmtu_from_exception "${ns_a}" ${dst1})"1155 check_pmtu_value "1300" "${pmtu_1}" "decreasing local MTU" || return 11156 # Second exception shouldn't be modified1157 pmtu_2="$(route_get_dst_pmtu_from_exception "${ns_a}" ${dst2})"1158 check_pmtu_value "1500" "${pmtu_2}" "changing local MTU on a link not on this path" || return 11159 1160 # Increase MTU, check for PMTU increase in route exception1161 mtu "${ns_a}" veth_A-R1 17001162 mtu "${ns_r1}" veth_R1-A 17001163 pmtu_1="$(route_get_dst_pmtu_from_exception "${ns_a}" ${dst1})"1164 check_pmtu_value "1700" "${pmtu_1}" "increasing local MTU" || return 11165 # Second exception shouldn't be modified1166 pmtu_2="$(route_get_dst_pmtu_from_exception "${ns_a}" ${dst2})"1167 check_pmtu_value "1500" "${pmtu_2}" "changing local MTU on a link not on this path" || return 11168 1169 # Skip PMTU locking tests for IPv61170 [ $family -eq 6 ] && return 01171 1172 # Decrease remote MTU on path via R2, get new exception1173 mtu "${ns_r2}" veth_R2-B 4001174 mtu "${ns_b}" veth_B-R2 4001175 run_cmd ${ns_a} ${ping} -q -M want -i 0.1 -w 1 -s 1400 ${dst2}1176 pmtu_2="$(route_get_dst_pmtu_from_exception "${ns_a}" ${dst2})"1177 check_pmtu_value "lock 552" "${pmtu_2}" "exceeding MTU, with MTU < min_pmtu" || return 11178 1179 # Decrease local MTU below PMTU1180 mtu "${ns_a}" veth_A-R2 5001181 mtu "${ns_r2}" veth_R2-A 5001182 pmtu_2="$(route_get_dst_pmtu_from_exception "${ns_a}" ${dst2})"1183 check_pmtu_value "500" "${pmtu_2}" "decreasing local MTU" || return 11184 1185 # Increase local MTU1186 mtu "${ns_a}" veth_A-R2 15001187 mtu "${ns_r2}" veth_R2-A 15001188 pmtu_2="$(route_get_dst_pmtu_from_exception "${ns_a}" ${dst2})"1189 check_pmtu_value "1500" "${pmtu_2}" "increasing local MTU" || return 11190 1191 # Get new exception1192 run_cmd ${ns_a} ${ping} -q -M want -i 0.1 -w 1 -s 1400 ${dst2}1193 pmtu_2="$(route_get_dst_pmtu_from_exception "${ns_a}" ${dst2})"1194 check_pmtu_value "lock 552" "${pmtu_2}" "exceeding MTU, with MTU < min_pmtu" || return 11195}1196 1197test_pmtu_ipv4_exception() {1198 test_pmtu_ipvX 41199}1200 1201test_pmtu_ipv6_exception() {1202 test_pmtu_ipvX 61203}1204 1205test_pmtu_ipv4_dscp_icmp_exception() {1206 rt_table=1001207 1208 setup namespaces policy_routing || return $ksft_skip1209 trace "${ns_a}" veth_A-R1 "${ns_r1}" veth_R1-A \1210 "${ns_r1}" veth_R1-B "${ns_b}" veth_B-R1 \1211 "${ns_a}" veth_A-R2 "${ns_r2}" veth_R2-A \1212 "${ns_r2}" veth_R2-B "${ns_b}" veth_B-R21213 1214 # Set up initial MTU values1215 mtu "${ns_a}" veth_A-R1 20001216 mtu "${ns_r1}" veth_R1-A 20001217 mtu "${ns_r1}" veth_R1-B 14001218 mtu "${ns_b}" veth_B-R1 14001219 1220 mtu "${ns_a}" veth_A-R2 20001221 mtu "${ns_r2}" veth_R2-A 20001222 mtu "${ns_r2}" veth_R2-B 15001223 mtu "${ns_b}" veth_B-R2 15001224 1225 len=$((2000 - 20 - 8)) # Fills MTU of veth_A-R11226 1227 dst1="${prefix4}.${b_r1}.1"1228 dst2="${prefix4}.${b_r2}.1"1229 1230 # Create route exceptions1231 dsfield=${policy_mark} # No ECN bit set (Not-ECT)1232 run_cmd "${ns_a}" ping -q -M want -Q "${dsfield}" -c 1 -w 1 -s "${len}" "${dst1}"1233 1234 dsfield=$(printf "%#x" $((policy_mark + 0x02))) # ECN=2 (ECT(0))1235 run_cmd "${ns_a}" ping -q -M want -Q "${dsfield}" -c 1 -w 1 -s "${len}" "${dst2}"1236 1237 # Check that exceptions have been created with the correct PMTU1238 pmtu_1="$(route_get_dst_pmtu_from_exception "${ns_a}" "${dst1}" "${policy_mark}")"1239 check_pmtu_value "1400" "${pmtu_1}" "exceeding MTU" || return 11240 1241 pmtu_2="$(route_get_dst_pmtu_from_exception "${ns_a}" "${dst2}" "${policy_mark}")"1242 check_pmtu_value "1500" "${pmtu_2}" "exceeding MTU" || return 11243}1244 1245test_pmtu_ipv4_dscp_udp_exception() {1246 rt_table=1001247 1248 if ! which socat > /dev/null 2>&1; then1249 echo "'socat' command not found; skipping tests"1250 return $ksft_skip1251 fi1252 1253 setup namespaces policy_routing || return $ksft_skip1254 trace "${ns_a}" veth_A-R1 "${ns_r1}" veth_R1-A \1255 "${ns_r1}" veth_R1-B "${ns_b}" veth_B-R1 \1256 "${ns_a}" veth_A-R2 "${ns_r2}" veth_R2-A \1257 "${ns_r2}" veth_R2-B "${ns_b}" veth_B-R21258 1259 # Set up initial MTU values1260 mtu "${ns_a}" veth_A-R1 20001261 mtu "${ns_r1}" veth_R1-A 20001262 mtu "${ns_r1}" veth_R1-B 14001263 mtu "${ns_b}" veth_B-R1 14001264 1265 mtu "${ns_a}" veth_A-R2 20001266 mtu "${ns_r2}" veth_R2-A 20001267 mtu "${ns_r2}" veth_R2-B 15001268 mtu "${ns_b}" veth_B-R2 15001269 1270 len=$((2000 - 20 - 8)) # Fills MTU of veth_A-R11271 1272 dst1="${prefix4}.${b_r1}.1"1273 dst2="${prefix4}.${b_r2}.1"1274 1275 # Create route exceptions1276 run_cmd_bg "${ns_b}" socat UDP-LISTEN:50000 OPEN:/dev/null,wronly=11277 socat_pids="${socat_pids} $!"1278 1279 dsfield=${policy_mark} # No ECN bit set (Not-ECT)1280 run_cmd "${ns_a}" socat OPEN:/dev/zero,rdonly=1,readbytes="${len}" \1281 UDP:"${dst1}":50000,tos="${dsfield}"1282 1283 dsfield=$(printf "%#x" $((policy_mark + 0x02))) # ECN=2 (ECT(0))1284 run_cmd "${ns_a}" socat OPEN:/dev/zero,rdonly=1,readbytes="${len}" \1285 UDP:"${dst2}":50000,tos="${dsfield}"1286 1287 # Check that exceptions have been created with the correct PMTU1288 pmtu_1="$(route_get_dst_pmtu_from_exception "${ns_a}" "${dst1}" "${policy_mark}")"1289 check_pmtu_value "1400" "${pmtu_1}" "exceeding MTU" || return 11290 pmtu_2="$(route_get_dst_pmtu_from_exception "${ns_a}" "${dst2}" "${policy_mark}")"1291 check_pmtu_value "1500" "${pmtu_2}" "exceeding MTU" || return 11292}1293 1294test_pmtu_ipvX_over_vxlanY_or_geneveY_exception() {1295 type=${1}1296 family=${2}1297 outer_family=${3}1298 ll_mtu=40001299 1300 if [ ${outer_family} -eq 4 ]; then1301 setup namespaces routing ${type}4 || return $ksft_skip1302 # IPv4 header UDP header VXLAN/GENEVE header Ethernet header1303 exp_mtu=$((${ll_mtu} - 20 - 8 - 8 - 14))1304 else1305 setup namespaces routing ${type}6 || return $ksft_skip1306 # IPv6 header UDP header VXLAN/GENEVE header Ethernet header1307 exp_mtu=$((${ll_mtu} - 40 - 8 - 8 - 14))1308 fi1309 1310 trace "${ns_a}" ${type}_a "${ns_b}" ${type}_b \1311 "${ns_a}" veth_A-R1 "${ns_r1}" veth_R1-A \1312 "${ns_b}" veth_B-R1 "${ns_r1}" veth_R1-B1313 1314 if [ ${family} -eq 4 ]; then1315 ping=ping1316 dst=${tunnel4_b_addr}1317 else1318 ping=${ping6}1319 dst=${tunnel6_b_addr}1320 fi1321 1322 # Create route exception by exceeding link layer MTU1323 mtu "${ns_a}" veth_A-R1 $((${ll_mtu} + 1000))1324 mtu "${ns_r1}" veth_R1-A $((${ll_mtu} + 1000))1325 mtu "${ns_b}" veth_B-R1 ${ll_mtu}1326 mtu "${ns_r1}" veth_R1-B ${ll_mtu}1327 1328 mtu "${ns_a}" ${type}_a $((${ll_mtu} + 1000))1329 mtu "${ns_b}" ${type}_b $((${ll_mtu} + 1000))1330 run_cmd ${ns_a} ${ping} -q -M want -i 0.1 -w 1 -s $((${ll_mtu} + 500)) ${dst}1331 1332 # Check that exception was created1333 pmtu="$(route_get_dst_pmtu_from_exception "${ns_a}" ${dst})"1334 check_pmtu_value ${exp_mtu} "${pmtu}" "exceeding link layer MTU on ${type} interface"1335}1336 1337test_pmtu_ipv4_vxlan4_exception() {1338 test_pmtu_ipvX_over_vxlanY_or_geneveY_exception vxlan 4 41339}1340 1341test_pmtu_ipv6_vxlan4_exception() {1342 test_pmtu_ipvX_over_vxlanY_or_geneveY_exception vxlan 6 41343}1344 1345test_pmtu_ipv4_geneve4_exception() {1346 test_pmtu_ipvX_over_vxlanY_or_geneveY_exception geneve 4 41347}1348 1349test_pmtu_ipv6_geneve4_exception() {1350 test_pmtu_ipvX_over_vxlanY_or_geneveY_exception geneve 6 41351}1352 1353test_pmtu_ipv4_vxlan6_exception() {1354 test_pmtu_ipvX_over_vxlanY_or_geneveY_exception vxlan 4 61355}1356 1357test_pmtu_ipv6_vxlan6_exception() {1358 test_pmtu_ipvX_over_vxlanY_or_geneveY_exception vxlan 6 61359}1360 1361test_pmtu_ipv4_geneve6_exception() {1362 test_pmtu_ipvX_over_vxlanY_or_geneveY_exception geneve 4 61363}1364 1365test_pmtu_ipv6_geneve6_exception() {1366 test_pmtu_ipvX_over_vxlanY_or_geneveY_exception geneve 6 61367}1368 1369test_pmtu_ipvX_over_bridged_vxlanY_or_geneveY_exception() {1370 type=${1}1371 family=${2}1372 outer_family=${3}1373 ll_mtu=40001374 1375 if [ ${outer_family} -eq 4 ]; then1376 setup namespaces routing bridge bridged_${type}4 || return $ksft_skip1377 # IPv4 header UDP header VXLAN/GENEVE header Ethernet header1378 exp_mtu=$((${ll_mtu} - 20 - 8 - 8 - 14))1379 else1380 setup namespaces routing bridge bridged_${type}6 || return $ksft_skip1381 # IPv6 header UDP header VXLAN/GENEVE header Ethernet header1382 exp_mtu=$((${ll_mtu} - 40 - 8 - 8 - 14))1383 fi1384 1385 trace "${ns_a}" ${type}_a "${ns_b}" ${type}_b \1386 "${ns_a}" veth_A-R1 "${ns_r1}" veth_R1-A \1387 "${ns_b}" veth_B-R1 "${ns_r1}" veth_R1-B \1388 "${ns_a}" br0 "${ns_a}" veth-A-C \1389 "${ns_c}" veth_C-A1390 1391 if [ ${family} -eq 4 ]; then1392 ping=ping1393 dst=${tunnel4_b_addr}1394 else1395 ping=${ping6}1396 dst=${tunnel6_b_addr}1397 fi1398 1399 # Create route exception by exceeding link layer MTU1400 mtu "${ns_a}" veth_A-R1 $((${ll_mtu} + 1000))1401 mtu "${ns_a}" br0 $((${ll_mtu} + 1000))1402 mtu "${ns_a}" veth_A-C $((${ll_mtu} + 1000))1403 mtu "${ns_c}" veth_C-A $((${ll_mtu} + 1000))1404 mtu "${ns_r1}" veth_R1-A $((${ll_mtu} + 1000))1405 mtu "${ns_b}" veth_B-R1 ${ll_mtu}1406 mtu "${ns_r1}" veth_R1-B ${ll_mtu}1407 1408 mtu "${ns_a}" ${type}_a $((${ll_mtu} + 1000))1409 mtu "${ns_b}" ${type}_b $((${ll_mtu} + 1000))1410 1411 run_cmd ${ns_c} ${ping} -q -M want -i 0.1 -c 10 -s $((${ll_mtu} + 500)) ${dst} || return 11412 run_cmd ${ns_a} ${ping} -q -M want -i 0.1 -w 1 -s $((${ll_mtu} + 500)) ${dst} || return 11413 1414 # Check that exceptions were created1415 pmtu="$(route_get_dst_pmtu_from_exception "${ns_c}" ${dst})"1416 check_pmtu_value ${exp_mtu} "${pmtu}" "exceeding link layer MTU on bridged ${type} interface"1417 pmtu="$(route_get_dst_pmtu_from_exception "${ns_a}" ${dst})"1418 check_pmtu_value ${exp_mtu} "${pmtu}" "exceeding link layer MTU on locally bridged ${type} interface"1419 1420 tmpoutfile=$(mktemp)1421 1422 # Flush Exceptions, retry with TCP1423 run_cmd ${ns_a} ip route flush cached ${dst}1424 run_cmd ${ns_b} ip route flush cached ${dst}1425 run_cmd ${ns_c} ip route flush cached ${dst}1426 1427 for target in "${ns_a}" "${ns_c}" ; do1428 if [ ${family} -eq 4 ]; then1429 TCPDST=TCP:${dst}:500001430 else1431 TCPDST="TCP:[${dst}]:50000"1432 fi1433 ${ns_b} socat -T 3 -u -6 TCP-LISTEN:50000,reuseaddr STDOUT > $tmpoutfile &1434 local socat_pid=$!1435 1436 wait_local_port_listen ${NS_B} 50000 tcp1437 1438 dd if=/dev/zero status=none bs=1M count=1 | ${target} socat -T 3 -u STDIN $TCPDST,connect-timeout=31439 1440 wait ${socat_pid}1441 size=$(du -sb $tmpoutfile)1442 size=${size%%/tmp/*}1443 1444 [ $size -ne 1048576 ] && err "File size $size mismatches expected value in locally bridged vxlan test" && return 11445 done1446 1447 rm -f "$tmpoutfile"1448 1449 # Check that exceptions were created1450 pmtu="$(route_get_dst_pmtu_from_exception "${ns_c}" ${dst})"1451 check_pmtu_value ${exp_mtu} "${pmtu}" "tcp: exceeding link layer MTU on bridged ${type} interface"1452 pmtu="$(route_get_dst_pmtu_from_exception "${ns_a}" ${dst})"1453 check_pmtu_value ${exp_mtu} "${pmtu}" "tcp exceeding link layer MTU on locally bridged ${type} interface"1454}1455 1456test_pmtu_ipv4_br_vxlan4_exception() {1457 test_pmtu_ipvX_over_bridged_vxlanY_or_geneveY_exception vxlan 4 41458}1459 1460test_pmtu_ipv6_br_vxlan4_exception() {1461 test_pmtu_ipvX_over_bridged_vxlanY_or_geneveY_exception vxlan 6 41462}1463 1464test_pmtu_ipv4_br_geneve4_exception() {1465 test_pmtu_ipvX_over_bridged_vxlanY_or_geneveY_exception geneve 4 41466}1467 1468test_pmtu_ipv6_br_geneve4_exception() {1469 test_pmtu_ipvX_over_bridged_vxlanY_or_geneveY_exception geneve 6 41470}1471 1472test_pmtu_ipv4_br_vxlan6_exception() {1473 test_pmtu_ipvX_over_bridged_vxlanY_or_geneveY_exception vxlan 4 61474}1475 1476test_pmtu_ipv6_br_vxlan6_exception() {1477 test_pmtu_ipvX_over_bridged_vxlanY_or_geneveY_exception vxlan 6 61478}1479 1480test_pmtu_ipv4_br_geneve6_exception() {1481 test_pmtu_ipvX_over_bridged_vxlanY_or_geneveY_exception geneve 4 61482}1483 1484test_pmtu_ipv6_br_geneve6_exception() {1485 test_pmtu_ipvX_over_bridged_vxlanY_or_geneveY_exception geneve 6 61486}1487 1488test_pmtu_ipvX_over_ovs_vxlanY_or_geneveY_exception() {1489 type=${1}1490 family=${2}1491 outer_family=${3}1492 ll_mtu=40001493 1494 if [ "${type}" = "vxlan" ]; then1495 tun_a="vxlan_sys_4789"1496 elif [ "${type}" = "geneve" ]; then1497 tun_a="genev_sys_6081"1498 fi1499 1500 if [ ${outer_family} -eq 4 ]; then1501 setup namespaces routing ovs_bridge ovs_${type}4 || return $ksft_skip1502 # IPv4 header UDP header VXLAN/GENEVE header Ethernet header1503 exp_mtu=$((${ll_mtu} - 20 - 8 - 8 - 14))1504 else1505 setup namespaces routing ovs_bridge ovs_${type}6 || return $ksft_skip1506 # IPv6 header UDP header VXLAN/GENEVE header Ethernet header1507 exp_mtu=$((${ll_mtu} - 40 - 8 - 8 - 14))1508 fi1509 1510 trace "" ${type}_a "${ns_b}" ${type}_b \1511 "" veth_A-R1 "${ns_r1}" veth_R1-A \1512 "${ns_b}" veth_B-R1 "${ns_r1}" veth_R1-B \1513 "" ovs_br0 "" veth-A_C \1514 "${ns_c}" veth_C-A "" "${tun_a}"1515 1516 if [ ${family} -eq 4 ]; then1517 ping=ping1518 dst=${tunnel4_b_addr}1519 else1520 ping=${ping6}1521 dst=${tunnel6_b_addr}1522 fi1523 1524 # Create route exception by exceeding link layer MTU1525 mtu "" veth_A-R1 $((${ll_mtu} + 1000))1526 mtu "" ovs_br0 $((${ll_mtu} + 1000))1527 mtu "" veth_A-C $((${ll_mtu} + 1000))1528 mtu "${ns_c}" veth_C-A $((${ll_mtu} + 1000))1529 mtu "${ns_r1}" veth_R1-A $((${ll_mtu} + 1000))1530 mtu "${ns_b}" veth_B-R1 ${ll_mtu}1531 mtu "${ns_r1}" veth_R1-B ${ll_mtu}1532 1533 mtu "" ${tun_a} $((${ll_mtu} + 1000)) 2>/dev/null || \1534 mtu "" ${type}_a $((${ll_mtu} + 1000)) 2>/dev/null1535 mtu "${ns_b}" ${type}_b $((${ll_mtu} + 1000))1536 1537 run_cmd ${ns_c} ${ping} -q -M want -i 0.1 -c 20 -s $((${ll_mtu} + 500)) ${dst} || return 11538 1539 # Check that exceptions were created1540 pmtu="$(route_get_dst_pmtu_from_exception "${ns_c}" ${dst})"1541 check_pmtu_value ${exp_mtu} "${pmtu}" "exceeding link layer MTU on Open vSwitch ${type} interface"1542}1543 1544test_pmtu_ipv4_ovs_vxlan4_exception() {1545 test_pmtu_ipvX_over_ovs_vxlanY_or_geneveY_exception vxlan 4 41546}1547 1548test_pmtu_ipv6_ovs_vxlan4_exception() {1549 test_pmtu_ipvX_over_ovs_vxlanY_or_geneveY_exception vxlan 6 41550}1551 1552test_pmtu_ipv4_ovs_geneve4_exception() {1553 test_pmtu_ipvX_over_ovs_vxlanY_or_geneveY_exception geneve 4 41554}1555 1556test_pmtu_ipv6_ovs_geneve4_exception() {1557 test_pmtu_ipvX_over_ovs_vxlanY_or_geneveY_exception geneve 6 41558}1559 1560test_pmtu_ipv4_ovs_vxlan6_exception() {1561 test_pmtu_ipvX_over_ovs_vxlanY_or_geneveY_exception vxlan 4 61562}1563 1564test_pmtu_ipv6_ovs_vxlan6_exception() {1565 test_pmtu_ipvX_over_ovs_vxlanY_or_geneveY_exception vxlan 6 61566}1567 1568test_pmtu_ipv4_ovs_geneve6_exception() {1569 test_pmtu_ipvX_over_ovs_vxlanY_or_geneveY_exception geneve 4 61570}1571 1572test_pmtu_ipv6_ovs_geneve6_exception() {1573 test_pmtu_ipvX_over_ovs_vxlanY_or_geneveY_exception geneve 6 61574}1575 1576test_pmtu_ipvX_over_fouY_or_gueY() {1577 inner_family=${1}1578 outer_family=${2}1579 encap=${3}1580 ll_mtu=40001581 1582 setup namespaces routing ${encap}${outer_family}${inner_family} || return $ksft_skip1583 trace "${ns_a}" ${encap}_a "${ns_b}" ${encap}_b \1584 "${ns_a}" veth_A-R1 "${ns_r1}" veth_R1-A \1585 "${ns_b}" veth_B-R1 "${ns_r1}" veth_R1-B1586 1587 if [ ${inner_family} -eq 4 ]; then1588 ping=ping1589 dst=${tunnel4_b_addr}1590 else1591 ping=${ping6}1592 dst=${tunnel6_b_addr}1593 fi1594 1595 if [ "${encap}" = "gue" ]; then1596 encap_overhead=41597 else1598 encap_overhead=01599 fi1600 1601 if [ ${outer_family} -eq 4 ]; then1602 # IPv4 header UDP header1603 exp_mtu=$((${ll_mtu} - 20 - 8 - ${encap_overhead}))1604 else1605 # IPv6 header Option 4 UDP header1606 exp_mtu=$((${ll_mtu} - 40 - 8 - 8 - ${encap_overhead}))1607 fi1608 1609 # Create route exception by exceeding link layer MTU1610 mtu "${ns_a}" veth_A-R1 $((${ll_mtu} + 1000))1611 mtu "${ns_r1}" veth_R1-A $((${ll_mtu} + 1000))1612 mtu "${ns_b}" veth_B-R1 ${ll_mtu}1613 mtu "${ns_r1}" veth_R1-B ${ll_mtu}1614 1615 mtu "${ns_a}" ${encap}_a $((${ll_mtu} + 1000))1616 mtu "${ns_b}" ${encap}_b $((${ll_mtu} + 1000))1617 run_cmd ${ns_a} ${ping} -q -M want -i 0.1 -w 1 -s $((${ll_mtu} + 500)) ${dst}1618 1619 # Check that exception was created1620 pmtu="$(route_get_dst_pmtu_from_exception "${ns_a}" ${dst})"1621 check_pmtu_value ${exp_mtu} "${pmtu}" "exceeding link layer MTU on ${encap} interface"1622}1623 1624test_pmtu_ipv4_fou4_exception() {1625 test_pmtu_ipvX_over_fouY_or_gueY 4 4 fou1626}1627 1628test_pmtu_ipv6_fou4_exception() {1629 test_pmtu_ipvX_over_fouY_or_gueY 6 4 fou1630}1631 1632test_pmtu_ipv4_fou6_exception() {1633 test_pmtu_ipvX_over_fouY_or_gueY 4 6 fou1634}1635 1636test_pmtu_ipv6_fou6_exception() {1637 test_pmtu_ipvX_over_fouY_or_gueY 6 6 fou1638}1639 1640test_pmtu_ipv4_gue4_exception() {1641 test_pmtu_ipvX_over_fouY_or_gueY 4 4 gue1642}1643 1644test_pmtu_ipv6_gue4_exception() {1645 test_pmtu_ipvX_over_fouY_or_gueY 6 4 gue1646}1647 1648test_pmtu_ipv4_gue6_exception() {1649 test_pmtu_ipvX_over_fouY_or_gueY 4 6 gue1650}1651 1652test_pmtu_ipv6_gue6_exception() {1653 test_pmtu_ipvX_over_fouY_or_gueY 6 6 gue1654}1655 1656test_pmtu_ipvX_over_ipvY_exception() {1657 inner=${1}1658 outer=${2}1659 ll_mtu=40001660 1661 setup namespaces routing ip${inner}ip${outer} || return $ksft_skip1662 1663 trace "${ns_a}" ip_a "${ns_b}" ip_b \1664 "${ns_a}" veth_A-R1 "${ns_r1}" veth_R1-A \1665 "${ns_b}" veth_B-R1 "${ns_r1}" veth_R1-B1666 1667 if [ ${inner} -eq 4 ]; then1668 ping=ping1669 dst=${tunnel4_b_addr}1670 else1671 ping=${ping6}1672 dst=${tunnel6_b_addr}1673 fi1674 1675 if [ ${outer} -eq 4 ]; then1676 # IPv4 header1677 exp_mtu=$((${ll_mtu} - 20))1678 else1679 # IPv6 header Option 41680 exp_mtu=$((${ll_mtu} - 40 - 8))1681 fi1682 1683 # Create route exception by exceeding link layer MTU1684 mtu "${ns_a}" veth_A-R1 $((${ll_mtu} + 1000))1685 mtu "${ns_r1}" veth_R1-A $((${ll_mtu} + 1000))1686 mtu "${ns_b}" veth_B-R1 ${ll_mtu}1687 mtu "${ns_r1}" veth_R1-B ${ll_mtu}1688 1689 mtu "${ns_a}" ip_a $((${ll_mtu} + 1000)) || return1690 mtu "${ns_b}" ip_b $((${ll_mtu} + 1000)) || return1691 run_cmd ${ns_a} ${ping} -q -M want -i 0.1 -w 1 -s $((${ll_mtu} + 500)) ${dst}1692 1693 # Check that exception was created1694 pmtu="$(route_get_dst_pmtu_from_exception "${ns_a}" ${dst})"1695 check_pmtu_value ${exp_mtu} "${pmtu}" "exceeding link layer MTU on ip${inner}ip${outer} interface"1696}1697 1698test_pmtu_ipv4_ipv4_exception() {1699 test_pmtu_ipvX_over_ipvY_exception 4 41700}1701 1702test_pmtu_ipv6_ipv4_exception() {1703 test_pmtu_ipvX_over_ipvY_exception 6 41704}1705 1706test_pmtu_ipv4_ipv6_exception() {1707 test_pmtu_ipvX_over_ipvY_exception 4 61708}1709 1710test_pmtu_ipv6_ipv6_exception() {1711 test_pmtu_ipvX_over_ipvY_exception 6 61712}1713 1714test_pmtu_vti4_exception() {1715 setup namespaces veth vti4 xfrm4 || return $ksft_skip1716 trace "${ns_a}" veth_a "${ns_b}" veth_b \1717 "${ns_a}" vti4_a "${ns_b}" vti4_b1718 1719 veth_mtu=15001720 vti_mtu=$((veth_mtu - 20))1721 1722 # SPI SN IV ICV pad length next header1723 esp_payload_rfc4106=$((vti_mtu - 4 - 4 - 8 - 16 - 1 - 1))1724 ping_payload=$((esp_payload_rfc4106 - 28))1725 1726 mtu "${ns_a}" veth_a ${veth_mtu}1727 mtu "${ns_b}" veth_b ${veth_mtu}1728 mtu "${ns_a}" vti4_a ${vti_mtu}1729 mtu "${ns_b}" vti4_b ${vti_mtu}1730 1731 # Send DF packet without exceeding link layer MTU, check that no1732 # exception is created1733 run_cmd ${ns_a} ping -q -M want -i 0.1 -w 1 -s ${ping_payload} ${tunnel4_b_addr}1734 pmtu="$(route_get_dst_pmtu_from_exception "${ns_a}" ${tunnel4_b_addr})"1735 check_pmtu_value "" "${pmtu}" "sending packet smaller than PMTU (IP payload length ${esp_payload_rfc4106})" || return 11736 1737 # Now exceed link layer MTU by one byte, check that exception is created1738 # with the right PMTU value1739 run_cmd ${ns_a} ping -q -M want -i 0.1 -w 1 -s $((ping_payload + 1)) ${tunnel4_b_addr}1740 pmtu="$(route_get_dst_pmtu_from_exception "${ns_a}" ${tunnel4_b_addr})"1741 check_pmtu_value "${esp_payload_rfc4106}" "${pmtu}" "exceeding PMTU (IP payload length $((esp_payload_rfc4106 + 1)))"1742}1743 1744test_pmtu_vti6_exception() {1745 setup namespaces veth vti6 xfrm6 || return $ksft_skip1746 trace "${ns_a}" veth_a "${ns_b}" veth_b \1747 "${ns_a}" vti6_a "${ns_b}" vti6_b1748 fail=01749 1750 # Create route exception by exceeding link layer MTU1751 mtu "${ns_a}" veth_a 40001752 mtu "${ns_b}" veth_b 40001753 mtu "${ns_a}" vti6_a 50001754 mtu "${ns_b}" vti6_b 50001755 run_cmd ${ns_a} ${ping6} -q -i 0.1 -w 1 -s 60000 ${tunnel6_b_addr}1756 1757 # Check that exception was created1758 pmtu="$(route_get_dst_pmtu_from_exception "${ns_a}" ${tunnel6_b_addr})"1759 check_pmtu_value any "${pmtu}" "creating tunnel exceeding link layer MTU" || return 11760 1761 # Decrease tunnel MTU, check for PMTU decrease in route exception1762 mtu "${ns_a}" vti6_a 30001763 pmtu="$(route_get_dst_pmtu_from_exception "${ns_a}" ${tunnel6_b_addr})"1764 check_pmtu_value "3000" "${pmtu}" "decreasing tunnel MTU" || fail=11765 1766 # Increase tunnel MTU, check for PMTU increase in route exception1767 mtu "${ns_a}" vti6_a 90001768 pmtu="$(route_get_dst_pmtu_from_exception "${ns_a}" ${tunnel6_b_addr})"1769 check_pmtu_value "9000" "${pmtu}" "increasing tunnel MTU" || fail=11770 1771 return ${fail}1772}1773 1774test_pmtu_vti4_udp_exception() {1775 setup namespaces veth vti4 xfrm4udp || return $ksft_skip1776 trace "${ns_a}" veth_a "${ns_b}" veth_b \1777 "${ns_a}" vti4_a "${ns_b}" vti4_b1778 1779 veth_mtu=15001780 vti_mtu=$((veth_mtu - 20))1781 1782 # UDP SPI SN IV ICV pad length next header1783 esp_payload_rfc4106=$((vti_mtu - 8 - 4 - 4 - 8 - 16 - 1 - 1))1784 ping_payload=$((esp_payload_rfc4106 - 28))1785 1786 mtu "${ns_a}" veth_a ${veth_mtu}1787 mtu "${ns_b}" veth_b ${veth_mtu}1788 mtu "${ns_a}" vti4_a ${vti_mtu}1789 mtu "${ns_b}" vti4_b ${vti_mtu}1790 1791 # Send DF packet without exceeding link layer MTU, check that no1792 # exception is created1793 run_cmd ${ns_a} ping -q -M want -i 0.1 -w 1 -s ${ping_payload} ${tunnel4_b_addr}1794 pmtu="$(route_get_dst_pmtu_from_exception "${ns_a}" ${tunnel4_b_addr})"1795 check_pmtu_value "" "${pmtu}" "sending packet smaller than PMTU (IP payload length ${esp_payload_rfc4106})" || return 11796 1797 # Now exceed link layer MTU by one byte, check that exception is created1798 # with the right PMTU value1799 run_cmd ${ns_a} ping -q -M want -i 0.1 -w 1 -s $((ping_payload + 1)) ${tunnel4_b_addr}1800 pmtu="$(route_get_dst_pmtu_from_exception "${ns_a}" ${tunnel4_b_addr})"1801 check_pmtu_value "${esp_payload_rfc4106}" "${pmtu}" "exceeding PMTU (IP payload length $((esp_payload_rfc4106 + 1)))"1802}1803 1804test_pmtu_vti6_udp_exception() {1805 setup namespaces veth vti6 xfrm6udp || return $ksft_skip1806 trace "${ns_a}" veth_a "${ns_b}" veth_b \1807 "${ns_a}" vti6_a "${ns_b}" vti6_b1808 fail=01809 1810 # Create route exception by exceeding link layer MTU1811 mtu "${ns_a}" veth_a 40001812 mtu "${ns_b}" veth_b 40001813 mtu "${ns_a}" vti6_a 50001814 mtu "${ns_b}" vti6_b 50001815 run_cmd ${ns_a} ${ping6} -q -i 0.1 -w 1 -s 60000 ${tunnel6_b_addr}1816 1817 # Check that exception was created1818 pmtu="$(route_get_dst_pmtu_from_exception "${ns_a}" ${tunnel6_b_addr})"1819 check_pmtu_value any "${pmtu}" "creating tunnel exceeding link layer MTU" || return 11820 1821 # Decrease tunnel MTU, check for PMTU decrease in route exception1822 mtu "${ns_a}" vti6_a 30001823 pmtu="$(route_get_dst_pmtu_from_exception "${ns_a}" ${tunnel6_b_addr})"1824 check_pmtu_value "3000" "${pmtu}" "decreasing tunnel MTU" || fail=11825 1826 # Increase tunnel MTU, check for PMTU increase in route exception1827 mtu "${ns_a}" vti6_a 90001828 pmtu="$(route_get_dst_pmtu_from_exception "${ns_a}" ${tunnel6_b_addr})"1829 check_pmtu_value "9000" "${pmtu}" "increasing tunnel MTU" || fail=11830 1831 return ${fail}1832}1833 1834test_pmtu_vti4_udp_routed_exception() {1835 setup namespaces routing vti4routed xfrm4udprouted || return $ksft_skip1836 trace "${ns_a}" veth_A-R1 "${ns_b}" veth_B-R1 \1837 "${ns_a}" vti4_a "${ns_b}" vti4_b1838 1839 veth_mtu=15001840 vti_mtu=$((veth_mtu - 20))1841 1842 # UDP SPI SN IV ICV pad length next header1843 esp_payload_rfc4106=$((vti_mtu - 8 - 4 - 4 - 8 - 16 - 1 - 1))1844 ping_payload=$((esp_payload_rfc4106 - 28))1845 1846 mtu "${ns_a}" veth_A-R1 ${veth_mtu}1847 mtu "${ns_r1}" veth_R1-A ${veth_mtu}1848 mtu "${ns_b}" veth_B-R1 ${veth_mtu}1849 mtu "${ns_r1}" veth_R1-B ${veth_mtu}1850 1851 mtu "${ns_a}" vti4_a ${vti_mtu}1852 mtu "${ns_b}" vti4_b ${vti_mtu}1853 1854 # Send DF packet without exceeding link layer MTU, check that no1855 # exception is created1856 run_cmd ${ns_a} ping -q -M want -i 0.1 -w 1 -s ${ping_payload} ${tunnel4_b_addr}1857 pmtu="$(route_get_dst_pmtu_from_exception "${ns_a}" ${tunnel4_b_addr})"1858 check_pmtu_value "" "${pmtu}" "sending packet smaller than PMTU (IP payload length ${esp_payload_rfc4106})" || return 11859 1860 # Now decrease link layer MTU by 8 bytes on R1, check that exception is created1861 # with the right PMTU value1862 mtu "${ns_r1}" veth_R1-B $((veth_mtu - 8))1863 run_cmd ${ns_a} ping -q -M want -i 0.1 -w 1 -s $((ping_payload)) ${tunnel4_b_addr}1864 pmtu="$(route_get_dst_pmtu_from_exception "${ns_a}" ${tunnel4_b_addr})"1865 check_pmtu_value "$((esp_payload_rfc4106 - 8))" "${pmtu}" "exceeding PMTU (IP payload length $((esp_payload_rfc4106)))"1866}1867 1868test_pmtu_vti6_udp_routed_exception() {1869 setup namespaces routing vti6routed xfrm6udprouted || return $ksft_skip1870 trace "${ns_a}" veth_A-R1 "${ns_b}" veth_B-R1 \1871 "${ns_a}" vti6_a "${ns_b}" vti6_b1872 1873 veth_mtu=15001874 vti_mtu=$((veth_mtu - 40))1875 1876 # UDP SPI SN IV ICV pad length next header1877 esp_payload_rfc4106=$((vti_mtu - 8 - 4 - 4 - 8 - 16 - 1 - 1))1878 ping_payload=$((esp_payload_rfc4106 - 48))1879 1880 mtu "${ns_a}" veth_A-R1 ${veth_mtu}1881 mtu "${ns_r1}" veth_R1-A ${veth_mtu}1882 mtu "${ns_b}" veth_B-R1 ${veth_mtu}1883 mtu "${ns_r1}" veth_R1-B ${veth_mtu}1884 1885 # mtu "${ns_a}" vti6_a ${vti_mtu}1886 # mtu "${ns_b}" vti6_b ${vti_mtu}1887 1888 run_cmd ${ns_a} ${ping6} -q -M want -i 0.1 -w 1 -s ${ping_payload} ${tunnel6_b_addr}1889 1890 # Check that exception was not created1891 pmtu="$(route_get_dst_pmtu_from_exception "${ns_a}" ${tunnel6_b_addr})"1892 check_pmtu_value "" "${pmtu}" "sending packet smaller than PMTU (IP payload length ${esp_payload_rfc4106})" || return 11893 1894 # Now decrease link layer MTU by 8 bytes on R1, check that exception is created1895 # with the right PMTU value1896 mtu "${ns_r1}" veth_R1-B $((veth_mtu - 8))1897 run_cmd ${ns_a} ${ping6} -q -M want -i 0.1 -w 1 -s $((ping_payload)) ${tunnel6_b_addr}1898 pmtu="$(route_get_dst_pmtu_from_exception "${ns_a}" ${tunnel6_b_addr})"1899 check_pmtu_value "$((esp_payload_rfc4106 - 8))" "${pmtu}" "exceeding PMTU (IP payload length $((esp_payload_rfc4106)))"1900 1901}1902 1903test_pmtu_vti4_default_mtu() {1904 setup namespaces veth vti4 || return $ksft_skip1905 1906 # Check that MTU of vti device is MTU of veth minus IPv4 header length1907 veth_mtu="$(link_get_mtu "${ns_a}" veth_a)"1908 vti4_mtu="$(link_get_mtu "${ns_a}" vti4_a)"1909 if [ $((veth_mtu - vti4_mtu)) -ne 20 ]; then1910 err " vti MTU ${vti4_mtu} is not veth MTU ${veth_mtu} minus IPv4 header length"1911 return 11912 fi1913}1914 1915test_pmtu_vti6_default_mtu() {1916 setup namespaces veth vti6 || return $ksft_skip1917 1918 # Check that MTU of vti device is MTU of veth minus IPv6 header length1919 veth_mtu="$(link_get_mtu "${ns_a}" veth_a)"1920 vti6_mtu="$(link_get_mtu "${ns_a}" vti6_a)"1921 if [ $((veth_mtu - vti6_mtu)) -ne 40 ]; then1922 err " vti MTU ${vti6_mtu} is not veth MTU ${veth_mtu} minus IPv6 header length"1923 return 11924 fi1925}1926 1927test_pmtu_vti4_link_add_mtu() {1928 setup namespaces || return $ksft_skip1929 1930 run_cmd ${ns_a} ip link add vti4_a type vti local ${veth4_a_addr} remote ${veth4_b_addr} key 101931 [ $? -ne 0 ] && err " vti not supported" && return $ksft_skip1932 run_cmd ${ns_a} ip link del vti4_a1933 1934 fail=01935 1936 min=681937 max=$((65535 - 20))1938 # Check invalid values first1939 for v in $((min - 1)) $((max + 1)); do1940 run_cmd ${ns_a} ip link add vti4_a mtu ${v} type vti local ${veth4_a_addr} remote ${veth4_b_addr} key 101941 # This can fail, or MTU can be adjusted to a proper value1942 [ $? -ne 0 ] && continue1943 mtu="$(link_get_mtu "${ns_a}" vti4_a)"1944 if [ ${mtu} -lt ${min} -o ${mtu} -gt ${max} ]; then1945 err " vti tunnel created with invalid MTU ${mtu}"1946 fail=11947 fi1948 run_cmd ${ns_a} ip link del vti4_a1949 done1950 1951 # Now check valid values1952 for v in ${min} 1300 ${max}; do1953 run_cmd ${ns_a} ip link add vti4_a mtu ${v} type vti local ${veth4_a_addr} remote ${veth4_b_addr} key 101954 mtu="$(link_get_mtu "${ns_a}" vti4_a)"1955 run_cmd ${ns_a} ip link del vti4_a1956 if [ "${mtu}" != "${v}" ]; then1957 err " vti MTU ${mtu} doesn't match configured value ${v}"1958 fail=11959 fi1960 done1961 1962 return ${fail}1963}1964 1965test_pmtu_vti6_link_add_mtu() {1966 setup namespaces || return $ksft_skip1967 1968 run_cmd ${ns_a} ip link add vti6_a type vti6 local ${veth6_a_addr} remote ${veth6_b_addr} key 101969 [ $? -ne 0 ] && err " vti6 not supported" && return $ksft_skip1970 run_cmd ${ns_a} ip link del vti6_a1971 1972 fail=01973 1974 min=68 # vti6 can carry IPv4 packets too1975 max=$((65535 - 40))1976 # Check invalid values first1977 for v in $((min - 1)) $((max + 1)); do1978 run_cmd ${ns_a} ip link add vti6_a mtu ${v} type vti6 local ${veth6_a_addr} remote ${veth6_b_addr} key 101979 # This can fail, or MTU can be adjusted to a proper value1980 [ $? -ne 0 ] && continue1981 mtu="$(link_get_mtu "${ns_a}" vti6_a)"1982 if [ ${mtu} -lt ${min} -o ${mtu} -gt ${max} ]; then1983 err " vti6 tunnel created with invalid MTU ${v}"1984 fail=11985 fi1986 run_cmd ${ns_a} ip link del vti6_a1987 done1988 1989 # Now check valid values1990 for v in 68 1280 1300 $((65535 - 40)); do1991 run_cmd ${ns_a} ip link add vti6_a mtu ${v} type vti6 local ${veth6_a_addr} remote ${veth6_b_addr} key 101992 mtu="$(link_get_mtu "${ns_a}" vti6_a)"1993 run_cmd ${ns_a} ip link del vti6_a1994 if [ "${mtu}" != "${v}" ]; then1995 err " vti6 MTU ${mtu} doesn't match configured value ${v}"1996 fail=11997 fi1998 done1999 2000 return ${fail}2001}2002 2003test_pmtu_vti6_link_change_mtu() {2004 setup namespaces || return $ksft_skip2005 2006 run_cmd ${ns_a} ip link add dummy0 mtu 1500 type dummy2007 [ $? -ne 0 ] && err " dummy not supported" && return $ksft_skip2008 run_cmd ${ns_a} ip link add dummy1 mtu 3000 type dummy2009 run_cmd ${ns_a} ip link set dummy0 up2010 run_cmd ${ns_a} ip link set dummy1 up2011 2012 run_cmd ${ns_a} ip addr add ${dummy6_0_prefix}1/${dummy6_mask} dev dummy02013 run_cmd ${ns_a} ip addr add ${dummy6_1_prefix}1/${dummy6_mask} dev dummy12014 2015 fail=02016 2017 # Create vti6 interface bound to device, passing MTU, check it2018 run_cmd ${ns_a} ip link add vti6_a mtu 1300 type vti6 remote ${dummy6_0_prefix}2 local ${dummy6_0_prefix}12019 mtu="$(link_get_mtu "${ns_a}" vti6_a)"2020 if [ ${mtu} -ne 1300 ]; then2021 err " vti6 MTU ${mtu} doesn't match configured value 1300"2022 fail=12023 fi2024 2025 # Move to another device with different MTU, without passing MTU, check2026 # MTU is adjusted2027 run_cmd ${ns_a} ip link set vti6_a type vti6 remote ${dummy6_1_prefix}2 local ${dummy6_1_prefix}12028 mtu="$(link_get_mtu "${ns_a}" vti6_a)"2029 if [ ${mtu} -ne $((3000 - 40)) ]; then2030 err " vti MTU ${mtu} is not dummy MTU 3000 minus IPv6 header length"2031 fail=12032 fi2033 2034 # Move it back, passing MTU, check MTU is not overridden2035 run_cmd ${ns_a} ip link set vti6_a mtu 1280 type vti6 remote ${dummy6_0_prefix}2 local ${dummy6_0_prefix}12036 mtu="$(link_get_mtu "${ns_a}" vti6_a)"2037 if [ ${mtu} -ne 1280 ]; then2038 err " vti6 MTU ${mtu} doesn't match configured value 1280"2039 fail=12040 fi2041 2042 return ${fail}2043}2044 2045check_command() {2046 cmd=${1}2047 2048 if ! which ${cmd} > /dev/null 2>&1; then2049 err " missing required command: '${cmd}'"2050 return 12051 fi2052 return 02053}2054 2055check_running() {2056 pid=${1}2057 cmd=${2}2058 2059 [ "$(cat /proc/${pid}/cmdline 2>/dev/null | tr -d '\0')" = "{cmd}" ]2060}2061 2062test_cleanup_vxlanX_exception() {2063 outer="${1}"2064 encap="vxlan"2065 ll_mtu=40002066 2067 check_command taskset || return $ksft_skip2068 cpu_list=$(grep -m 2 processor /proc/cpuinfo | cut -d ' ' -f 2)2069 2070 setup namespaces routing ${encap}${outer} || return $ksft_skip2071 trace "${ns_a}" ${encap}_a "${ns_b}" ${encap}_b \2072 "${ns_a}" veth_A-R1 "${ns_r1}" veth_R1-A \2073 "${ns_b}" veth_B-R1 "${ns_r1}" veth_R1-B2074 2075 # Create route exception by exceeding link layer MTU2076 mtu "${ns_a}" veth_A-R1 $((${ll_mtu} + 1000))2077 mtu "${ns_r1}" veth_R1-A $((${ll_mtu} + 1000))2078 mtu "${ns_b}" veth_B-R1 ${ll_mtu}2079 mtu "${ns_r1}" veth_R1-B ${ll_mtu}2080 2081 mtu "${ns_a}" ${encap}_a $((${ll_mtu} + 1000))2082 mtu "${ns_b}" ${encap}_b $((${ll_mtu} + 1000))2083 2084 # Fill exception cache for multiple CPUs (2)2085 # we can always use inner IPv4 for that2086 for cpu in ${cpu_list}; do2087 run_cmd taskset --cpu-list ${cpu} ${ns_a} ping -q -M want -i 0.1 -w 1 -s $((${ll_mtu} + 500)) ${tunnel4_b_addr}2088 done2089 2090 ${ns_a} ip link del dev veth_A-R1 &2091 iplink_pid=$!2092 for i in $(seq 1 20); do2093 check_running ${iplink_pid} "iplinkdeldevveth_A-R1" || return 02094 sleep 0.12095 done2096 err " can't delete veth device in a timely manner, PMTU dst likely leaked"2097 return 12098}2099 2100test_cleanup_ipv6_exception() {2101 test_cleanup_vxlanX_exception 62102}2103 2104test_cleanup_ipv4_exception() {2105 test_cleanup_vxlanX_exception 42106}2107 2108run_test() {2109 (2110 tname="$1"2111 tdesc="$2"2112 2113 unset IFS2114 2115 # Since cleanup() relies on variables modified by this subshell, it2116 # has to run in this context.2117 trap cleanup EXIT2118 2119 if [ "$VERBOSE" = "1" ]; then2120 printf "\n##########################################################################\n\n"2121 fi2122 2123 eval test_${tname}2124 ret=$?2125 2126 if [ $ret -eq 0 ]; then2127 printf "TEST: %-60s [ OK ]\n" "${tdesc}"2128 elif [ $ret -eq 1 ]; then2129 printf "TEST: %-60s [FAIL]\n" "${tdesc}"2130 if [ "${PAUSE_ON_FAIL}" = "yes" ]; then2131 echo2132 echo "Pausing. Hit enter to continue"2133 read a2134 fi2135 err_flush2136 exit 12137 elif [ $ret -eq $ksft_skip ]; then2138 printf "TEST: %-60s [SKIP]\n" "${tdesc}"2139 err_flush2140 fi2141 2142 return $ret2143 )2144 ret=$?2145 case $ret in2146 0)2147 all_skipped=false2148 [ $exitcode -eq $ksft_skip ] && exitcode=02149 ;;2150 $ksft_skip)2151 [ $all_skipped = true ] && exitcode=$ksft_skip2152 ;;2153 *)2154 all_skipped=false2155 exitcode=12156 ;;2157 esac2158 2159 return $ret2160}2161 2162run_test_nh() {2163 tname="$1"2164 tdesc="$2"2165 2166 USE_NH=yes2167 run_test "${tname}" "${tdesc} - nexthop objects"2168 USE_NH=no2169}2170 2171test_list_flush_ipv4_exception() {2172 setup namespaces routing || return $ksft_skip2173 trace "${ns_a}" veth_A-R1 "${ns_r1}" veth_R1-A \2174 "${ns_r1}" veth_R1-B "${ns_b}" veth_B-R1 \2175 "${ns_a}" veth_A-R2 "${ns_r2}" veth_R2-A \2176 "${ns_r2}" veth_R2-B "${ns_b}" veth_B-R22177 2178 dst_prefix1="${prefix4}.${b_r1}."2179 dst2="${prefix4}.${b_r2}.1"2180 2181 # Set up initial MTU values2182 mtu "${ns_a}" veth_A-R1 20002183 mtu "${ns_r1}" veth_R1-A 20002184 mtu "${ns_r1}" veth_R1-B 15002185 mtu "${ns_b}" veth_B-R1 15002186 2187 mtu "${ns_a}" veth_A-R2 20002188 mtu "${ns_r2}" veth_R2-A 20002189 mtu "${ns_r2}" veth_R2-B 15002190 mtu "${ns_b}" veth_B-R2 15002191 2192 fail=02193 2194 # Add 100 addresses for veth endpoint on B reached by default A route2195 for i in $(seq 100 199); do2196 run_cmd ${ns_b} ip addr add "${dst_prefix1}${i}" dev veth_B-R12197 done2198 2199 # Create 100 cached route exceptions for path via R1, one via R2. Note2200 # that with IPv4 we need to actually cause a route lookup that matches2201 # the exception caused by ICMP, in order to actually have a cached2202 # route, so we need to ping each destination twice2203 for i in $(seq 100 199); do2204 run_cmd ${ns_a} ping -q -M want -i 0.1 -c 2 -s 1800 "${dst_prefix1}${i}"2205 done2206 run_cmd ${ns_a} ping -q -M want -i 0.1 -c 2 -s 1800 "${dst2}"2207 2208 if [ "$(${ns_a} ip -oneline route list cache | wc -l)" -ne 101 ]; then2209 err " can't list cached exceptions"2210 fail=12211 fi2212 2213 run_cmd ${ns_a} ip route flush cache2214 pmtu1="$(route_get_dst_pmtu_from_exception "${ns_a}" ${dst_prefix}1)"2215 pmtu2="$(route_get_dst_pmtu_from_exception "${ns_a}" ${dst_prefix}2)"2216 if [ -n "${pmtu1}" ] || [ -n "${pmtu2}" ] || \2217 [ -n "$(${ns_a} ip route list cache)" ]; then2218 err " can't flush cached exceptions"2219 fail=12220 fi2221 2222 return ${fail}2223}2224 2225test_list_flush_ipv6_exception() {2226 setup namespaces routing || return $ksft_skip2227 trace "${ns_a}" veth_A-R1 "${ns_r1}" veth_R1-A \2228 "${ns_r1}" veth_R1-B "${ns_b}" veth_B-R1 \2229 "${ns_a}" veth_A-R2 "${ns_r2}" veth_R2-A \2230 "${ns_r2}" veth_R2-B "${ns_b}" veth_B-R22231 2232 dst_prefix1="${prefix6}:${b_r1}::"2233 dst2="${prefix6}:${b_r2}::1"2234 2235 # Set up initial MTU values2236 mtu "${ns_a}" veth_A-R1 20002237 mtu "${ns_r1}" veth_R1-A 20002238 mtu "${ns_r1}" veth_R1-B 15002239 mtu "${ns_b}" veth_B-R1 15002240 2241 mtu "${ns_a}" veth_A-R2 20002242 mtu "${ns_r2}" veth_R2-A 20002243 mtu "${ns_r2}" veth_R2-B 15002244 mtu "${ns_b}" veth_B-R2 15002245 2246 fail=02247 2248 # Add 100 addresses for veth endpoint on B reached by default A route2249 for i in $(seq 100 199); do2250 run_cmd ${ns_b} ip addr add "${dst_prefix1}${i}" dev veth_B-R12251 done2252 2253 # Create 100 cached route exceptions for path via R1, one via R22254 for i in $(seq 100 199); do2255 run_cmd ${ns_a} ping -q -M want -i 0.1 -w 1 -s 1800 "${dst_prefix1}${i}"2256 done2257 run_cmd ${ns_a} ping -q -M want -i 0.1 -w 1 -s 1800 "${dst2}"2258 if [ "$(${ns_a} ip -oneline -6 route list cache | wc -l)" -ne 101 ]; then2259 err " can't list cached exceptions"2260 fail=12261 fi2262 2263 run_cmd ${ns_a} ip -6 route flush cache2264 pmtu1="$(route_get_dst_pmtu_from_exception "${ns_a}" "${dst_prefix1}100")"2265 pmtu2="$(route_get_dst_pmtu_from_exception "${ns_a}" ${dst2})"2266 if [ -n "${pmtu1}" ] || [ -n "${pmtu2}" ] || \2267 [ -n "$(${ns_a} ip -6 route list cache)" ]; then2268 err " can't flush cached exceptions"2269 fail=12270 fi2271 2272 return ${fail}2273}2274 2275test_pmtu_ipvX_route_change() {2276 family=${1}2277 2278 setup namespaces routing || return 22279 trace "${ns_a}" veth_A-R1 "${ns_r1}" veth_R1-A \2280 "${ns_r1}" veth_R1-B "${ns_b}" veth_B-R1 \2281 "${ns_a}" veth_A-R2 "${ns_r2}" veth_R2-A \2282 "${ns_r2}" veth_R2-B "${ns_b}" veth_B-R22283 2284 if [ ${family} -eq 4 ]; then2285 ping=ping2286 dst1="${prefix4}.${b_r1}.1"2287 dst2="${prefix4}.${b_r2}.1"2288 gw="${prefix4}.${a_r1}.2"2289 else2290 ping=${ping6}2291 dst1="${prefix6}:${b_r1}::1"2292 dst2="${prefix6}:${b_r2}::1"2293 gw="${prefix6}:${a_r1}::2"2294 fi2295 2296 # Set up initial MTU values2297 mtu "${ns_a}" veth_A-R1 20002298 mtu "${ns_r1}" veth_R1-A 20002299 mtu "${ns_r1}" veth_R1-B 14002300 mtu "${ns_b}" veth_B-R1 14002301 2302 mtu "${ns_a}" veth_A-R2 20002303 mtu "${ns_r2}" veth_R2-A 20002304 mtu "${ns_r2}" veth_R2-B 15002305 mtu "${ns_b}" veth_B-R2 15002306 2307 # Create route exceptions2308 run_cmd ${ns_a} ${ping} -q -M want -i 0.1 -w 1 -s 1800 ${dst1}2309 run_cmd ${ns_a} ${ping} -q -M want -i 0.1 -w 1 -s 1800 ${dst2}2310 2311 # Check that exceptions have been created with the correct PMTU2312 pmtu_1="$(route_get_dst_pmtu_from_exception "${ns_a}" ${dst1})"2313 check_pmtu_value "1400" "${pmtu_1}" "exceeding MTU" || return 12314 pmtu_2="$(route_get_dst_pmtu_from_exception "${ns_a}" ${dst2})"2315 check_pmtu_value "1500" "${pmtu_2}" "exceeding MTU" || return 12316 2317 # Replace the route from A to R12318 run_cmd ${ns_a} ip route change default via ${gw}2319 2320 # Delete the device in A2321 run_cmd ${ns_a} ip link del "veth_A-R1"2322}2323 2324test_pmtu_ipv4_route_change() {2325 test_pmtu_ipvX_route_change 42326}2327 2328test_pmtu_ipv6_route_change() {2329 test_pmtu_ipvX_route_change 62330}2331 2332usage() {2333 echo2334 echo "$0 [OPTIONS] [TEST]..."2335 echo "If no TEST argument is given, all tests will be run."2336 echo2337 echo "Options"2338 echo " --trace: capture traffic to TEST_INTERFACE.pcap"2339 echo2340 echo "Available tests${tests}"2341 exit 12342}2343 2344################################################################################2345#2346exitcode=02347desc=02348all_skipped=true2349 2350while getopts :ptv o2351do2352 case $o in2353 p) PAUSE_ON_FAIL=yes;;2354 v) VERBOSE=1;;2355 t) if which tcpdump > /dev/null 2>&1; then2356 TRACING=12357 else2358 echo "=== tcpdump not available, tracing disabled"2359 fi2360 ;;2361 *) usage;;2362 esac2363done2364shift $(($OPTIND-1))2365 2366IFS=" 2367"2368 2369for arg do2370 # Check first that all requested tests are available before running any2371 command -v > /dev/null "test_${arg}" || { echo "=== Test ${arg} not found"; usage; }2372done2373 2374trap cleanup EXIT2375 2376# start clean2377cleanup2378 2379HAVE_NH=no2380ip nexthop ls >/dev/null 2>&12381[ $? -eq 0 ] && HAVE_NH=yes2382 2383name=""2384desc=""2385rerun_nh=02386for t in ${tests}; do2387 [ "${name}" = "" ] && name="${t}" && continue2388 [ "${desc}" = "" ] && desc="${t}" && continue2389 2390 if [ "${HAVE_NH}" = "yes" ]; then2391 rerun_nh="${t}"2392 fi2393 2394 run_this=12395 for arg do2396 [ "${arg}" != "${arg#--*}" ] && continue2397 [ "${arg}" = "${name}" ] && run_this=1 && break2398 run_this=02399 done2400 if [ $run_this -eq 1 ]; then2401 run_test "${name}" "${desc}"2402 # if test was skipped no need to retry with nexthop objects2403 [ $? -eq $ksft_skip ] && rerun_nh=02404 2405 if [ "${rerun_nh}" = "1" ]; then2406 run_test_nh "${name}" "${desc}"2407 fi2408 fi2409 name=""2410 desc=""2411 rerun_nh=02412done2413 2414exit ${exitcode}2415