2 # SPDX-License-Identifier: GPL-2.0
4 # Check that route PMTU values match expectations, and that initial device MTU
5 # values are assigned correctly
7 # Tests currently implemented:
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:
13 # segment a_r1 segment b_r1 a_r1: 2000
14 # .--------------R1--------------. b_r1: 1400
16 # '--------------R2--------------' b_r2: 1500
17 # segment a_r2 segment b_r2
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
27 # Same as pmtu_ipv4, except for locked PMTU tests, using IPv6
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.
35 # - pmtu_ipv4_dscp_udp_exception
36 # Same as pmtu_ipv4_dscp_icmp_exception, but use UDP instead of ICMP.
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
46 # - pmtu_ipv6_vxlan4_exception
47 # Same as pmtu_ipv4_vxlan4_exception, but send IPv6 packets from A to B
49 # - pmtu_ipv4_vxlan6_exception
50 # Same as pmtu_ipv4_vxlan4_exception, but use IPv6 transport from A to B
52 # - pmtu_ipv6_vxlan6_exception
53 # Same as pmtu_ipv4_vxlan6_exception, but send IPv6 packets from A to B
55 # - pmtu_ipv4_geneve4_exception
56 # Same as pmtu_ipv4_vxlan4_exception, but using a GENEVE tunnel instead of
59 # - pmtu_ipv6_geneve4_exception
60 # Same as pmtu_ipv6_vxlan4_exception, but using a GENEVE tunnel instead of
63 # - pmtu_ipv4_geneve6_exception
64 # Same as pmtu_ipv4_vxlan6_exception, but using a GENEVE tunnel instead of
67 # - pmtu_ipv6_geneve6_exception
68 # Same as pmtu_ipv6_vxlan6_exception, but using a GENEVE tunnel instead of
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.
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.
80 # segment a_r1 segment b_r1 b_r1: 4000
81 # .--------------R1--------------. everything
82 # C---veth A B else: 5000
84 # '---- - - - - - VXLAN - - - - - - - '
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
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.
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.
100 # segment a_r1 segment b_r1 b_r1: 4000
101 # .--------------R1--------------. everything
102 # C---veth init B else: 5000
104 # '---- - - - - - VXLAN - - - - - - - '
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
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
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
118 # - pmtu_ipv{4,6}_ipv{4,6}_exception
119 # Same as pmtu_ipv4_vxlan4, but using a IPv4/IPv6 tunnel over IPv4/IPv6,
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
130 # - pmtu_vti4_udp_exception
131 # Same as pmtu_vti4_exception, but using ESP-in-UDP
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.
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
147 # - pmtu_vti6_udp_exception
148 # Same as pmtu_vti6_exception, but using ESP-in-UDP
150 # - pmtu_vti6_udp_routed_exception
151 # Same as pmtu_vti6_udp_routed_exception but with routing between vti
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
160 # - pmtu_vti6_default_mtu
161 # Same as above, for IPv6
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
167 # - pmtu_vti6_link_add_mtu
168 # Same as above, for IPv6
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
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
181 # - cleanup_ipv6_exception
182 # Same as above, but use IPv6 transport from A to B
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
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
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
198 # - pmtu_ipv6_route_change
199 # Same as above but with IPv6
207 # Some systems don't have a ping6 binary anymore
208 which ping6 > /dev/null 2>&1 && ping6=$(which ping6) || ping6=$(which ping)
210 # Name Description re-run with nh
212 pmtu_ipv4_exception ipv4: PMTU exceptions 1
213 pmtu_ipv6_exception ipv6: PMTU exceptions 1
214 pmtu_ipv4_dscp_icmp_exception ICMPv4 with DSCP and ECN: PMTU exceptions 1
215 pmtu_ipv4_dscp_udp_exception UDPv4 with DSCP and ECN: PMTU exceptions 1
216 pmtu_ipv4_vxlan4_exception IPv4 over vxlan4: PMTU exceptions 1
217 pmtu_ipv6_vxlan4_exception IPv6 over vxlan4: PMTU exceptions 1
218 pmtu_ipv4_vxlan6_exception IPv4 over vxlan6: PMTU exceptions 1
219 pmtu_ipv6_vxlan6_exception IPv6 over vxlan6: PMTU exceptions 1
220 pmtu_ipv4_geneve4_exception IPv4 over geneve4: PMTU exceptions 1
221 pmtu_ipv6_geneve4_exception IPv6 over geneve4: PMTU exceptions 1
222 pmtu_ipv4_geneve6_exception IPv4 over geneve6: PMTU exceptions 1
223 pmtu_ipv6_geneve6_exception IPv6 over geneve6: PMTU exceptions 1
224 pmtu_ipv4_br_vxlan4_exception IPv4, bridged vxlan4: PMTU exceptions 1
225 pmtu_ipv6_br_vxlan4_exception IPv6, bridged vxlan4: PMTU exceptions 1
226 pmtu_ipv4_br_vxlan6_exception IPv4, bridged vxlan6: PMTU exceptions 1
227 pmtu_ipv6_br_vxlan6_exception IPv6, bridged vxlan6: PMTU exceptions 1
228 pmtu_ipv4_br_geneve4_exception IPv4, bridged geneve4: PMTU exceptions 1
229 pmtu_ipv6_br_geneve4_exception IPv6, bridged geneve4: PMTU exceptions 1
230 pmtu_ipv4_br_geneve6_exception IPv4, bridged geneve6: PMTU exceptions 1
231 pmtu_ipv6_br_geneve6_exception IPv6, bridged geneve6: PMTU exceptions 1
232 pmtu_ipv4_ovs_vxlan4_exception IPv4, OVS vxlan4: PMTU exceptions 1
233 pmtu_ipv6_ovs_vxlan4_exception IPv6, OVS vxlan4: PMTU exceptions 1
234 pmtu_ipv4_ovs_vxlan6_exception IPv4, OVS vxlan6: PMTU exceptions 1
235 pmtu_ipv6_ovs_vxlan6_exception IPv6, OVS vxlan6: PMTU exceptions 1
236 pmtu_ipv4_ovs_geneve4_exception IPv4, OVS geneve4: PMTU exceptions 1
237 pmtu_ipv6_ovs_geneve4_exception IPv6, OVS geneve4: PMTU exceptions 1
238 pmtu_ipv4_ovs_geneve6_exception IPv4, OVS geneve6: PMTU exceptions 1
239 pmtu_ipv6_ovs_geneve6_exception IPv6, OVS geneve6: PMTU exceptions 1
240 pmtu_ipv4_fou4_exception IPv4 over fou4: PMTU exceptions 1
241 pmtu_ipv6_fou4_exception IPv6 over fou4: PMTU exceptions 1
242 pmtu_ipv4_fou6_exception IPv4 over fou6: PMTU exceptions 1
243 pmtu_ipv6_fou6_exception IPv6 over fou6: PMTU exceptions 1
244 pmtu_ipv4_gue4_exception IPv4 over gue4: PMTU exceptions 1
245 pmtu_ipv6_gue4_exception IPv6 over gue4: PMTU exceptions 1
246 pmtu_ipv4_gue6_exception IPv4 over gue6: PMTU exceptions 1
247 pmtu_ipv6_gue6_exception IPv6 over gue6: PMTU exceptions 1
248 pmtu_ipv4_ipv4_exception IPv4 over IPv4: PMTU exceptions 1
249 pmtu_ipv6_ipv4_exception IPv6 over IPv4: PMTU exceptions 1
250 pmtu_ipv4_ipv6_exception IPv4 over IPv6: PMTU exceptions 1
251 pmtu_ipv6_ipv6_exception IPv6 over IPv6: PMTU exceptions 1
252 pmtu_vti6_exception vti6: PMTU exceptions 0
253 pmtu_vti4_exception vti4: PMTU exceptions 0
254 pmtu_vti6_udp_exception vti6: PMTU exceptions (ESP-in-UDP) 0
255 pmtu_vti4_udp_exception vti4: PMTU exceptions (ESP-in-UDP) 0
256 pmtu_vti6_udp_routed_exception vti6: PMTU exceptions, routed (ESP-in-UDP) 0
257 pmtu_vti4_udp_routed_exception vti4: PMTU exceptions, routed (ESP-in-UDP) 0
258 pmtu_vti4_default_mtu vti4: default MTU assignment 0
259 pmtu_vti6_default_mtu vti6: default MTU assignment 0
260 pmtu_vti4_link_add_mtu vti4: MTU setting on link creation 0
261 pmtu_vti6_link_add_mtu vti6: MTU setting on link creation 0
262 pmtu_vti6_link_change_mtu vti6: MTU changes on link changes 0
263 cleanup_ipv4_exception ipv4: cleanup of cached exceptions 1
264 cleanup_ipv6_exception ipv6: cleanup of cached exceptions 1
265 list_flush_ipv4_exception ipv4: list and flush cached exceptions 1
266 list_flush_ipv6_exception ipv6: list and flush cached exceptions 1
267 pmtu_ipv4_route_change ipv4: PMTU exception w/route replace 1
268 pmtu_ipv6_route_change ipv6: PMTU exception w/route replace 1"
270 # Addressing and routing for tests with routers: four network segments, with
271 # index SEGMENT between 1 and 4, a common prefix (PREFIX4 or PREFIX6) and an
272 # identifier ID, which is 1 for hosts (A and B), 2 for routers (R1 and R2).
274 # - IPv4: PREFIX4.SEGMENT.ID (/24)
275 # - IPv6: PREFIX6:SEGMENT::ID (/64)
289 # Traffic from A to B goes through R1 by default, and through R2, if destined to
290 # B's address on the b_r2 segment.
291 # Traffic from B to A goes through R1.
292 # ns destination gateway
294 A default ${prefix4}.${a_r1}.2
295 A ${prefix4}.${b_r2}.1 ${prefix4}.${a_r2}.2
296 B default ${prefix4}.${b_r1}.2
298 A default ${prefix6}:${a_r1}::2
299 A ${prefix6}:${b_r2}::1 ${prefix6}:${a_r2}::2
300 B default ${prefix6}:${b_r1}::2
303 # ns family nh id destination gateway
305 A 4 41 ${prefix4}.${a_r1}.2 veth_A-R1
306 A 4 42 ${prefix4}.${a_r2}.2 veth_A-R2
307 B 4 41 ${prefix4}.${b_r1}.2 veth_B-R1
309 A 6 61 ${prefix6}:${a_r1}::2 veth_A-R1
310 A 6 62 ${prefix6}:${a_r2}::2 veth_A-R2
311 B 6 61 ${prefix6}:${b_r1}::2 veth_B-R1
314 # nexthop id correlates to id in nexthops config above
315 # ns family prefix nh id
318 A 4 ${prefix4}.${b_r2}.1 42
322 A 6 ${prefix6}:${b_r2}::1 62
329 veth4_a_addr="192.168.1.1"
330 veth4_b_addr="192.168.1.2"
331 veth4_c_addr="192.168.2.10"
333 veth6_a_addr="fd00:1::a"
334 veth6_b_addr="fd00:1::b"
335 veth6_c_addr="fd00:2::c"
338 tunnel4_a_addr="192.168.2.1"
339 tunnel4_b_addr="192.168.2.2"
341 tunnel6_a_addr="fd00:2::a"
342 tunnel6_b_addr="fd00:2::b"
345 dummy6_0_prefix="fc00:1000::"
346 dummy6_1_prefix="fc00:1001::"
356 err_buf="${err_buf}${1}
368 if [ "$VERBOSE" = "1" ]; then
369 printf " COMMAND: $cmd\n"
374 if [ "$VERBOSE" = "1" -a -n "$out" ]; then
385 if [ "$VERBOSE" = "1" ]; then
386 printf " COMMAND: %s &\n" "${cmd}"
392 # Find the auto-generated name for this namespace
402 if [ "${outer}" = "4" ]; then
403 modprobe fou || return $ksft_skip
404 a_addr="${prefix4}.${a_r1}.1"
405 b_addr="${prefix4}.${b_r1}.1"
406 if [ "${inner}" = "4" ]; then
414 modprobe fou6 || return $ksft_skip
415 a_addr="${prefix6}:${a_r1}::1"
416 b_addr="${prefix6}:${b_r1}::1"
417 if [ "${inner}" = "4" ]; then
428 run_cmd ${ns_a} ip fou add port 5555 ipproto ${ipproto} || return $ksft_skip
429 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
431 run_cmd ${ns_b} ip fou add port 5556 ipproto ${ipproto}
432 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
434 if [ "${inner}" = "4" ]; then
435 run_cmd ${ns_a} ip addr add ${tunnel4_a_addr}/${tunnel4_mask} dev ${encap}_a
436 run_cmd ${ns_b} ip addr add ${tunnel4_b_addr}/${tunnel4_mask} dev ${encap}_b
438 run_cmd ${ns_a} ip addr add ${tunnel6_a_addr}/${tunnel6_mask} dev ${encap}_a
439 run_cmd ${ns_b} ip addr add ${tunnel6_b_addr}/${tunnel6_mask} dev ${encap}_b
442 run_cmd ${ns_a} ip link set ${encap}_a up
443 run_cmd ${ns_b} ip link set ${encap}_b up
447 setup_fou_or_gue 4 4 fou
451 setup_fou_or_gue 4 6 fou
455 setup_fou_or_gue 6 4 fou
459 setup_fou_or_gue 6 6 fou
463 setup_fou_or_gue 4 4 gue
467 setup_fou_or_gue 4 6 gue
471 setup_fou_or_gue 6 4 gue
475 setup_fou_or_gue 6 6 gue
478 setup_ipvX_over_ipvY() {
482 if [ "${outer}" -eq 4 ]; then
483 a_addr="${prefix4}.${a_r1}.1"
484 b_addr="${prefix4}.${b_r1}.1"
485 if [ "${inner}" -eq 4 ]; then
493 a_addr="${prefix6}:${a_r1}::1"
494 b_addr="${prefix6}:${b_r1}::1"
496 if [ "${inner}" -eq 4 ]; then
503 run_cmd ${ns_a} ip link add ip_a type ${type} local ${a_addr} remote ${b_addr} mode ${mode} || return $ksft_skip
504 run_cmd ${ns_b} ip link add ip_b type ${type} local ${b_addr} remote ${a_addr} mode ${mode}
506 run_cmd ${ns_a} ip link set ip_a up
507 run_cmd ${ns_b} ip link set ip_b up
509 if [ "${inner}" = "4" ]; then
510 run_cmd ${ns_a} ip addr add ${tunnel4_a_addr}/${tunnel4_mask} dev ip_a
511 run_cmd ${ns_b} ip addr add ${tunnel4_b_addr}/${tunnel4_mask} dev ip_b
513 run_cmd ${ns_a} ip addr add ${tunnel6_a_addr}/${tunnel6_mask} dev ip_a
514 run_cmd ${ns_b} ip addr add ${tunnel6_b_addr}/${tunnel6_mask} dev ip_b
519 setup_ipvX_over_ipvY 4 4
523 setup_ipvX_over_ipvY 6 4
527 setup_ipvX_over_ipvY 4 6
531 setup_ipvX_over_ipvY 6 6
535 setup_ns NS_A NS_B NS_C NS_R1 NS_R2
536 for n in ${NS_A} ${NS_B} ${NS_C} ${NS_R1} ${NS_R2}; do
537 # Disable DAD, so that we don't have to wait to use the
538 # configured IPv6 addresses
539 ip netns exec ${n} sysctl -q net/ipv6/conf/default/accept_dad=0
541 ns_a="ip netns exec ${NS_A}"
542 ns_b="ip netns exec ${NS_B}"
543 ns_c="ip netns exec ${NS_C}"
544 ns_r1="ip netns exec ${NS_R1}"
545 ns_r2="ip netns exec ${NS_R2}"
549 run_cmd ${ns_a} ip link add veth_a type veth peer name veth_b || return 1
550 run_cmd ${ns_a} ip link set veth_b netns ${NS_B}
552 run_cmd ${ns_a} ip addr add ${veth4_a_addr}/${veth4_mask} dev veth_a
553 run_cmd ${ns_b} ip addr add ${veth4_b_addr}/${veth4_mask} dev veth_b
555 run_cmd ${ns_a} ip addr add ${veth6_a_addr}/${veth6_mask} dev veth_a
556 run_cmd ${ns_b} ip addr add ${veth6_b_addr}/${veth6_mask} dev veth_b
558 run_cmd ${ns_a} ip link set veth_a up
559 run_cmd ${ns_b} ip link set veth_b up
570 [ ${proto} -eq 6 ] && vti_type="vti6" || vti_type="vti"
572 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
573 run_cmd ${ns_b} ip link add vti${proto}_b type ${vti_type} local ${veth_b_addr} remote ${veth_a_addr} key 10
575 run_cmd ${ns_a} ip addr add ${vti_a_addr}/${vti_mask} dev vti${proto}_a
576 run_cmd ${ns_b} ip addr add ${vti_b_addr}/${vti_mask} dev vti${proto}_b
578 run_cmd ${ns_a} ip link set vti${proto}_a up
579 run_cmd ${ns_b} ip link set vti${proto}_b up
583 setup_vti 4 ${veth4_a_addr} ${veth4_b_addr} ${tunnel4_a_addr} ${tunnel4_b_addr} ${tunnel4_mask}
587 setup_vti 6 ${veth6_a_addr} ${veth6_b_addr} ${tunnel6_a_addr} ${tunnel6_b_addr} ${tunnel6_mask}
591 setup_vti 4 ${prefix4}.${a_r1}.1 ${prefix4}.${b_r1}.1 ${tunnel4_a_addr} ${tunnel4_b_addr} ${tunnel4_mask}
595 setup_vti 6 ${prefix6}:${a_r1}::1 ${prefix6}:${b_r1}::1 ${tunnel6_a_addr} ${tunnel6_b_addr} ${tunnel6_mask}
598 setup_vxlan_or_geneve() {
605 if [ "${type}" = "vxlan" ]; then
606 opts="${opts} ttl 64 dstport 4789"
607 opts_a="local ${a_addr}"
608 opts_b="local ${b_addr}"
614 run_cmd ${ns_a} ip link add ${type}_a type ${type} id 1 ${opts_a} remote ${b_addr} ${opts} || return 1
615 run_cmd ${ns_b} ip link add ${type}_b type ${type} id 1 ${opts_b} remote ${a_addr} ${opts}
617 if [ -n "${br_if_a}" ]; then
618 run_cmd ${ns_a} ip addr add ${tunnel4_a_addr}/${tunnel4_mask} dev ${br_if_a}
619 run_cmd ${ns_a} ip addr add ${tunnel6_a_addr}/${tunnel6_mask} dev ${br_if_a}
620 run_cmd ${ns_a} ip link set ${type}_a master ${br_if_a}
622 run_cmd ${ns_a} ip addr add ${tunnel4_a_addr}/${tunnel4_mask} dev ${type}_a
623 run_cmd ${ns_a} ip addr add ${tunnel6_a_addr}/${tunnel6_mask} dev ${type}_a
626 run_cmd ${ns_b} ip addr add ${tunnel4_b_addr}/${tunnel4_mask} dev ${type}_b
627 run_cmd ${ns_b} ip addr add ${tunnel6_b_addr}/${tunnel6_mask} dev ${type}_b
629 run_cmd ${ns_a} ip link set ${type}_a up
630 run_cmd ${ns_b} ip link set ${type}_b up
634 setup_vxlan_or_geneve geneve ${prefix4}.${a_r1}.1 ${prefix4}.${b_r1}.1 "df set"
638 setup_vxlan_or_geneve vxlan ${prefix4}.${a_r1}.1 ${prefix4}.${b_r1}.1 "df set"
642 setup_vxlan_or_geneve geneve ${prefix6}:${a_r1}::1 ${prefix6}:${b_r1}::1 ""
646 setup_vxlan_or_geneve vxlan ${prefix6}:${a_r1}::1 ${prefix6}:${b_r1}::1 ""
649 setup_bridged_geneve4() {
650 setup_vxlan_or_geneve geneve ${prefix4}.${a_r1}.1 ${prefix4}.${b_r1}.1 "df set" "br0"
653 setup_bridged_vxlan4() {
654 setup_vxlan_or_geneve vxlan ${prefix4}.${a_r1}.1 ${prefix4}.${b_r1}.1 "df set" "br0"
657 setup_bridged_geneve6() {
658 setup_vxlan_or_geneve geneve ${prefix6}:${a_r1}::1 ${prefix6}:${b_r1}::1 "" "br0"
661 setup_bridged_vxlan6() {
662 setup_vxlan_or_geneve vxlan ${prefix6}:${a_r1}::1 ${prefix6}:${b_r1}::1 "" "br0"
671 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
672 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}
673 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
674 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
676 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}
677 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}
678 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
679 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
682 setup_nettest_xfrm() {
683 if ! which nettest >/dev/null; then
685 if ! which nettest >/dev/null; then
686 echo "'nettest' command not found; skipping tests"
691 [ ${1} -eq 6 ] && proto="-6" || proto=""
694 run_cmd_bg "${ns_a}" nettest "${proto}" -q -D -s -x -p "${port}" -t 5
695 nettest_pids="${nettest_pids} $!"
697 run_cmd_bg "${ns_b}" nettest "${proto}" -q -D -s -x -p "${port}" -t 5
698 nettest_pids="${nettest_pids} $!"
702 setup_xfrm 4 ${veth4_a_addr} ${veth4_b_addr}
706 setup_xfrm 6 ${veth6_a_addr} ${veth6_b_addr}
710 setup_xfrm 4 ${veth4_a_addr} ${veth4_b_addr} "encap espinudp 4500 4500 0.0.0.0" && \
711 setup_nettest_xfrm 4 4500
715 setup_xfrm 6 ${veth6_a_addr} ${veth6_b_addr} "encap espinudp 4500 4500 0.0.0.0" && \
716 setup_nettest_xfrm 6 4500
719 setup_xfrm4udprouted() {
720 setup_xfrm 4 ${prefix4}.${a_r1}.1 ${prefix4}.${b_r1}.1 "encap espinudp 4500 4500 0.0.0.0" && \
721 setup_nettest_xfrm 4 4500
724 setup_xfrm6udprouted() {
725 setup_xfrm 6 ${prefix6}:${a_r1}::1 ${prefix6}:${b_r1}::1 "encap espinudp 4500 4500 0.0.0.0" && \
726 setup_nettest_xfrm 6 4500
729 setup_routing_old() {
730 for i in ${routes}; do
731 [ "${ns}" = "" ] && ns="${i}" && continue
732 [ "${addr}" = "" ] && addr="${i}" && continue
733 [ "${gw}" = "" ] && gw="${i}"
735 ns_name="$(nsname ${ns})"
737 ip -n "${ns_name}" route add "${addr}" table "${rt_table}" via "${gw}"
739 ns=""; addr=""; gw=""
743 setup_routing_new() {
744 for i in ${nexthops}; do
745 [ "${ns}" = "" ] && ns="${i}" && continue
746 [ "${fam}" = "" ] && fam="${i}" && continue
747 [ "${nhid}" = "" ] && nhid="${i}" && continue
748 [ "${gw}" = "" ] && gw="${i}" && continue
749 [ "${dev}" = "" ] && dev="${i}"
751 ns_name="$(nsname ${ns})"
753 ip -n ${ns_name} -${fam} nexthop add id ${nhid} via ${gw} dev ${dev}
755 ns=""; fam=""; nhid=""; gw=""; dev=""
759 for i in ${routes_nh}; do
760 [ "${ns}" = "" ] && ns="${i}" && continue
761 [ "${fam}" = "" ] && fam="${i}" && continue
762 [ "${addr}" = "" ] && addr="${i}" && continue
763 [ "${nhid}" = "" ] && nhid="${i}"
765 ns_name="$(nsname ${ns})"
767 ip -n "${ns_name}" -"${fam}" route add "${addr}" table "${rt_table}" nhid "${nhid}"
769 ns=""; fam=""; addr=""; nhid=""
774 for i in ${NS_R1} ${NS_R2}; do
775 ip netns exec ${i} sysctl -q net/ipv4/ip_forward=1
776 ip netns exec ${i} sysctl -q net/ipv6/conf/all/forwarding=1
779 for i in ${routing_addrs}; do
780 [ "${ns}" = "" ] && ns="${i}" && continue
781 [ "${peer}" = "" ] && peer="${i}" && continue
782 [ "${segment}" = "" ] && segment="${i}"
784 ns_name="$(nsname ${ns})"
785 peer_name="$(nsname ${peer})"
786 if="veth_${ns}-${peer}"
787 ifpeer="veth_${peer}-${ns}"
790 ip link add ${if} up netns ${ns_name} type veth peer name ${ifpeer} netns ${peer_name} || return 1
791 ip -n ${peer_name} link set dev ${ifpeer} up
794 ip -n ${ns_name} addr add ${prefix4}.${segment}.1/24 dev ${if}
795 ip -n ${ns_name} addr add ${prefix6}:${segment}::1/64 dev ${if}
797 ip -n ${peer_name} addr add ${prefix4}.${segment}.2/24 dev ${ifpeer}
798 ip -n ${peer_name} addr add ${prefix6}:${segment}::2/64 dev ${ifpeer}
800 ns=""; peer=""; segment=""
803 if [ "$USE_NH" = "yes" ]; then
812 setup_policy_routing() {
815 ip -netns "${NS_A}" -4 rule add dsfield "${policy_mark}" \
818 # Set the IPv4 Don't Fragment bit with tc, since socat doesn't seem to
819 # have an option do to it.
820 tc -netns "${NS_A}" qdisc replace dev veth_A-R1 root prio
821 tc -netns "${NS_A}" qdisc replace dev veth_A-R2 root prio
822 tc -netns "${NS_A}" filter add dev veth_A-R1 \
823 protocol ipv4 flower ip_proto udp \
824 action pedit ex munge ip df set 0x40 pipe csum ip and udp
825 tc -netns "${NS_A}" filter add dev veth_A-R2 \
826 protocol ipv4 flower ip_proto udp \
827 action pedit ex munge ip df set 0x40 pipe csum ip and udp
831 run_cmd ${ns_a} ip link add br0 type bridge || return $ksft_skip
832 run_cmd ${ns_a} ip link set br0 up
834 run_cmd ${ns_c} ip link add veth_C-A type veth peer name veth_A-C
835 run_cmd ${ns_c} ip link set veth_A-C netns ${NS_A}
837 run_cmd ${ns_a} ip link set veth_A-C up
838 run_cmd ${ns_c} ip link set veth_C-A up
839 run_cmd ${ns_c} ip addr add ${veth4_c_addr}/${veth4_mask} dev veth_C-A
840 run_cmd ${ns_c} ip addr add ${veth6_c_addr}/${veth6_mask} dev veth_C-A
841 run_cmd ${ns_a} ip link set veth_A-C master br0
844 setup_ovs_vxlan_or_geneve() {
849 if [ "${type}" = "vxlan" ]; then
850 opts="${opts} ttl 64 dstport 4789"
851 opts_b="local ${b_addr}"
854 run_cmd ovs-vsctl add-port ovs_br0 ${type}_a -- \
855 set interface ${type}_a type=${type} \
856 options:remote_ip=${b_addr} options:key=1 options:csum=true || return 1
858 run_cmd ${ns_b} ip link add ${type}_b type ${type} id 1 ${opts_b} remote ${a_addr} ${opts} || return 1
860 run_cmd ${ns_b} ip addr add ${tunnel4_b_addr}/${tunnel4_mask} dev ${type}_b
861 run_cmd ${ns_b} ip addr add ${tunnel6_b_addr}/${tunnel6_mask} dev ${type}_b
863 run_cmd ${ns_b} ip link set ${type}_b up
866 setup_ovs_geneve4() {
867 setup_ovs_vxlan_or_geneve geneve ${prefix4}.${a_r1}.1 ${prefix4}.${b_r1}.1
871 setup_ovs_vxlan_or_geneve vxlan ${prefix4}.${a_r1}.1 ${prefix4}.${b_r1}.1
874 setup_ovs_geneve6() {
875 setup_ovs_vxlan_or_geneve geneve ${prefix6}:${a_r1}::1 ${prefix6}:${b_r1}::1
879 setup_ovs_vxlan_or_geneve vxlan ${prefix6}:${a_r1}::1 ${prefix6}:${b_r1}::1
883 run_cmd ovs-vsctl add-br ovs_br0 || return $ksft_skip
884 run_cmd ip link set ovs_br0 up
886 run_cmd ${ns_c} ip link add veth_C-A type veth peer name veth_A-C
887 run_cmd ${ns_c} ip link set veth_A-C netns 1
889 run_cmd ip link set veth_A-C up
890 run_cmd ${ns_c} ip link set veth_C-A up
891 run_cmd ${ns_c} ip addr add ${veth4_c_addr}/${veth4_mask} dev veth_C-A
892 run_cmd ${ns_c} ip addr add ${veth6_c_addr}/${veth6_mask} dev veth_C-A
893 run_cmd ovs-vsctl add-port ovs_br0 veth_A-C
895 # Move veth_A-R1 to init
896 run_cmd ${ns_a} ip link set veth_A-R1 netns 1
897 run_cmd ip addr add ${prefix4}.${a_r1}.1/${veth4_mask} dev veth_A-R1
898 run_cmd ip addr add ${prefix6}:${a_r1}::1/${veth6_mask} dev veth_A-R1
899 run_cmd ip link set veth_A-R1 up
900 run_cmd ip route add ${prefix4}.${b_r1}.1 via ${prefix4}.${a_r1}.2
901 run_cmd ip route add ${prefix6}:${b_r1}::1 via ${prefix6}:${a_r1}::2
905 [ "$(id -u)" -ne 0 ] && echo " need to run as root" && return $ksft_skip
908 eval setup_${arg} || { echo " ${arg} not supported"; return 1; }
913 [ $TRACING -eq 0 ] && return
916 [ "${ns_cmd}" = "" ] && ns_cmd="${arg}" && continue
917 ${ns_cmd} tcpdump --immediate-mode -s 0 -i "${arg}" -w "${name}_${arg}.pcap" 2> /dev/null &
918 tcpdump_pids="${tcpdump_pids} $!"
925 for pid in ${tcpdump_pids}; do
930 for pid in ${nettest_pids}; do
935 for pid in ${socat_pids}; do
942 ip link del veth_A-C 2>/dev/null
943 ip link del veth_A-R1 2>/dev/null
944 ovs-vsctl --if-exists del-port vxlan_a 2>/dev/null
945 ovs-vsctl --if-exists del-br ovs_br0 2>/dev/null
954 ${ns_cmd} ip link set dev ${dev} mtu ${mtu}
961 for i in ${input}; do
962 [ ${next} -eq 1 -a "${i}" = "lock" ] && next=2 && continue
963 [ ${next} -eq 1 ] && echo "${i}" && return
964 [ ${next} -eq 2 ] && echo "lock ${i}" && return
965 [ "${i}" = "mtu" ] && next=1
973 ${ns_cmd} ip link show dev "${name}"
980 mtu_parse "$(link_get "${ns_cmd}" ${name})"
983 route_get_dst_exception() {
988 if [ -z "${dsfield}" ]; then
992 ${ns_cmd} ip route get "${dst}" dsfield "${dsfield}"
995 route_get_dst_pmtu_from_exception() {
1000 mtu_parse "$(route_get_dst_exception "${ns_cmd}" "${dst}" "${dsfield}")"
1003 check_pmtu_value() {
1008 [ "${expected}" = "any" ] && [ -n "${value}" ] && return 0
1009 [ "${value}" = "${expected}" ] && return 0
1010 [ -z "${value}" ] && err " PMTU exception wasn't created after ${event}" && return 1
1011 [ -z "${expected}" ] && err " PMTU exception shouldn't exist after ${event}" && return 1
1012 err " found PMTU exception with incorrect MTU ${value}, expected ${expected}, after ${event}"
1019 setup namespaces routing || return $ksft_skip
1020 trace "${ns_a}" veth_A-R1 "${ns_r1}" veth_R1-A \
1021 "${ns_r1}" veth_R1-B "${ns_b}" veth_B-R1 \
1022 "${ns_a}" veth_A-R2 "${ns_r2}" veth_R2-A \
1023 "${ns_r2}" veth_R2-B "${ns_b}" veth_B-R2
1025 if [ ${family} -eq 4 ]; then
1027 dst1="${prefix4}.${b_r1}.1"
1028 dst2="${prefix4}.${b_r2}.1"
1031 dst1="${prefix6}:${b_r1}::1"
1032 dst2="${prefix6}:${b_r2}::1"
1035 # Set up initial MTU values
1036 mtu "${ns_a}" veth_A-R1 2000
1037 mtu "${ns_r1}" veth_R1-A 2000
1038 mtu "${ns_r1}" veth_R1-B 1400
1039 mtu "${ns_b}" veth_B-R1 1400
1041 mtu "${ns_a}" veth_A-R2 2000
1042 mtu "${ns_r2}" veth_R2-A 2000
1043 mtu "${ns_r2}" veth_R2-B 1500
1044 mtu "${ns_b}" veth_B-R2 1500
1046 # Create route exceptions
1047 run_cmd ${ns_a} ${ping} -q -M want -i 0.1 -w 1 -s 1800 ${dst1}
1048 run_cmd ${ns_a} ${ping} -q -M want -i 0.1 -w 1 -s 1800 ${dst2}
1050 # Check that exceptions have been created with the correct PMTU
1051 pmtu_1="$(route_get_dst_pmtu_from_exception "${ns_a}" ${dst1})"
1052 check_pmtu_value "1400" "${pmtu_1}" "exceeding MTU" || return 1
1053 pmtu_2="$(route_get_dst_pmtu_from_exception "${ns_a}" ${dst2})"
1054 check_pmtu_value "1500" "${pmtu_2}" "exceeding MTU" || return 1
1056 # Decrease local MTU below PMTU, check for PMTU decrease in route exception
1057 mtu "${ns_a}" veth_A-R1 1300
1058 mtu "${ns_r1}" veth_R1-A 1300
1059 pmtu_1="$(route_get_dst_pmtu_from_exception "${ns_a}" ${dst1})"
1060 check_pmtu_value "1300" "${pmtu_1}" "decreasing local MTU" || return 1
1061 # Second exception shouldn't be modified
1062 pmtu_2="$(route_get_dst_pmtu_from_exception "${ns_a}" ${dst2})"
1063 check_pmtu_value "1500" "${pmtu_2}" "changing local MTU on a link not on this path" || return 1
1065 # Increase MTU, check for PMTU increase in route exception
1066 mtu "${ns_a}" veth_A-R1 1700
1067 mtu "${ns_r1}" veth_R1-A 1700
1068 pmtu_1="$(route_get_dst_pmtu_from_exception "${ns_a}" ${dst1})"
1069 check_pmtu_value "1700" "${pmtu_1}" "increasing local MTU" || return 1
1070 # Second exception shouldn't be modified
1071 pmtu_2="$(route_get_dst_pmtu_from_exception "${ns_a}" ${dst2})"
1072 check_pmtu_value "1500" "${pmtu_2}" "changing local MTU on a link not on this path" || return 1
1074 # Skip PMTU locking tests for IPv6
1075 [ $family -eq 6 ] && return 0
1077 # Decrease remote MTU on path via R2, get new exception
1078 mtu "${ns_r2}" veth_R2-B 400
1079 mtu "${ns_b}" veth_B-R2 400
1080 run_cmd ${ns_a} ${ping} -q -M want -i 0.1 -w 1 -s 1400 ${dst2}
1081 pmtu_2="$(route_get_dst_pmtu_from_exception "${ns_a}" ${dst2})"
1082 check_pmtu_value "lock 552" "${pmtu_2}" "exceeding MTU, with MTU < min_pmtu" || return 1
1084 # Decrease local MTU below PMTU
1085 mtu "${ns_a}" veth_A-R2 500
1086 mtu "${ns_r2}" veth_R2-A 500
1087 pmtu_2="$(route_get_dst_pmtu_from_exception "${ns_a}" ${dst2})"
1088 check_pmtu_value "500" "${pmtu_2}" "decreasing local MTU" || return 1
1090 # Increase local MTU
1091 mtu "${ns_a}" veth_A-R2 1500
1092 mtu "${ns_r2}" veth_R2-A 1500
1093 pmtu_2="$(route_get_dst_pmtu_from_exception "${ns_a}" ${dst2})"
1094 check_pmtu_value "1500" "${pmtu_2}" "increasing local MTU" || return 1
1097 run_cmd ${ns_a} ${ping} -q -M want -i 0.1 -w 1 -s 1400 ${dst2}
1098 pmtu_2="$(route_get_dst_pmtu_from_exception "${ns_a}" ${dst2})"
1099 check_pmtu_value "lock 552" "${pmtu_2}" "exceeding MTU, with MTU < min_pmtu" || return 1
1102 test_pmtu_ipv4_exception() {
1106 test_pmtu_ipv6_exception() {
1110 test_pmtu_ipv4_dscp_icmp_exception() {
1113 setup namespaces policy_routing || return $ksft_skip
1114 trace "${ns_a}" veth_A-R1 "${ns_r1}" veth_R1-A \
1115 "${ns_r1}" veth_R1-B "${ns_b}" veth_B-R1 \
1116 "${ns_a}" veth_A-R2 "${ns_r2}" veth_R2-A \
1117 "${ns_r2}" veth_R2-B "${ns_b}" veth_B-R2
1119 # Set up initial MTU values
1120 mtu "${ns_a}" veth_A-R1 2000
1121 mtu "${ns_r1}" veth_R1-A 2000
1122 mtu "${ns_r1}" veth_R1-B 1400
1123 mtu "${ns_b}" veth_B-R1 1400
1125 mtu "${ns_a}" veth_A-R2 2000
1126 mtu "${ns_r2}" veth_R2-A 2000
1127 mtu "${ns_r2}" veth_R2-B 1500
1128 mtu "${ns_b}" veth_B-R2 1500
1130 len=$((2000 - 20 - 8)) # Fills MTU of veth_A-R1
1132 dst1="${prefix4}.${b_r1}.1"
1133 dst2="${prefix4}.${b_r2}.1"
1135 # Create route exceptions
1136 dsfield=${policy_mark} # No ECN bit set (Not-ECT)
1137 run_cmd "${ns_a}" ping -q -M want -Q "${dsfield}" -c 1 -w 1 -s "${len}" "${dst1}"
1139 dsfield=$(printf "%#x" $((policy_mark + 0x02))) # ECN=2 (ECT(0))
1140 run_cmd "${ns_a}" ping -q -M want -Q "${dsfield}" -c 1 -w 1 -s "${len}" "${dst2}"
1142 # Check that exceptions have been created with the correct PMTU
1143 pmtu_1="$(route_get_dst_pmtu_from_exception "${ns_a}" "${dst1}" "${policy_mark}")"
1144 check_pmtu_value "1400" "${pmtu_1}" "exceeding MTU" || return 1
1146 pmtu_2="$(route_get_dst_pmtu_from_exception "${ns_a}" "${dst2}" "${policy_mark}")"
1147 check_pmtu_value "1500" "${pmtu_2}" "exceeding MTU" || return 1
1150 test_pmtu_ipv4_dscp_udp_exception() {
1153 if ! which socat > /dev/null 2>&1; then
1154 echo "'socat' command not found; skipping tests"
1158 setup namespaces policy_routing || return $ksft_skip
1159 trace "${ns_a}" veth_A-R1 "${ns_r1}" veth_R1-A \
1160 "${ns_r1}" veth_R1-B "${ns_b}" veth_B-R1 \
1161 "${ns_a}" veth_A-R2 "${ns_r2}" veth_R2-A \
1162 "${ns_r2}" veth_R2-B "${ns_b}" veth_B-R2
1164 # Set up initial MTU values
1165 mtu "${ns_a}" veth_A-R1 2000
1166 mtu "${ns_r1}" veth_R1-A 2000
1167 mtu "${ns_r1}" veth_R1-B 1400
1168 mtu "${ns_b}" veth_B-R1 1400
1170 mtu "${ns_a}" veth_A-R2 2000
1171 mtu "${ns_r2}" veth_R2-A 2000
1172 mtu "${ns_r2}" veth_R2-B 1500
1173 mtu "${ns_b}" veth_B-R2 1500
1175 len=$((2000 - 20 - 8)) # Fills MTU of veth_A-R1
1177 dst1="${prefix4}.${b_r1}.1"
1178 dst2="${prefix4}.${b_r2}.1"
1180 # Create route exceptions
1181 run_cmd_bg "${ns_b}" socat UDP-LISTEN:50000 OPEN:/dev/null,wronly=1
1182 socat_pids="${socat_pids} $!"
1184 dsfield=${policy_mark} # No ECN bit set (Not-ECT)
1185 run_cmd "${ns_a}" socat OPEN:/dev/zero,rdonly=1,readbytes="${len}" \
1186 UDP:"${dst1}":50000,tos="${dsfield}"
1188 dsfield=$(printf "%#x" $((policy_mark + 0x02))) # ECN=2 (ECT(0))
1189 run_cmd "${ns_a}" socat OPEN:/dev/zero,rdonly=1,readbytes="${len}" \
1190 UDP:"${dst2}":50000,tos="${dsfield}"
1192 # Check that exceptions have been created with the correct PMTU
1193 pmtu_1="$(route_get_dst_pmtu_from_exception "${ns_a}" "${dst1}" "${policy_mark}")"
1194 check_pmtu_value "1400" "${pmtu_1}" "exceeding MTU" || return 1
1195 pmtu_2="$(route_get_dst_pmtu_from_exception "${ns_a}" "${dst2}" "${policy_mark}")"
1196 check_pmtu_value "1500" "${pmtu_2}" "exceeding MTU" || return 1
1199 test_pmtu_ipvX_over_vxlanY_or_geneveY_exception() {
1205 if [ ${outer_family} -eq 4 ]; then
1206 setup namespaces routing ${type}4 || return $ksft_skip
1207 # IPv4 header UDP header VXLAN/GENEVE header Ethernet header
1208 exp_mtu=$((${ll_mtu} - 20 - 8 - 8 - 14))
1210 setup namespaces routing ${type}6 || return $ksft_skip
1211 # IPv6 header UDP header VXLAN/GENEVE header Ethernet header
1212 exp_mtu=$((${ll_mtu} - 40 - 8 - 8 - 14))
1215 trace "${ns_a}" ${type}_a "${ns_b}" ${type}_b \
1216 "${ns_a}" veth_A-R1 "${ns_r1}" veth_R1-A \
1217 "${ns_b}" veth_B-R1 "${ns_r1}" veth_R1-B
1219 if [ ${family} -eq 4 ]; then
1221 dst=${tunnel4_b_addr}
1224 dst=${tunnel6_b_addr}
1227 # Create route exception by exceeding link layer MTU
1228 mtu "${ns_a}" veth_A-R1 $((${ll_mtu} + 1000))
1229 mtu "${ns_r1}" veth_R1-A $((${ll_mtu} + 1000))
1230 mtu "${ns_b}" veth_B-R1 ${ll_mtu}
1231 mtu "${ns_r1}" veth_R1-B ${ll_mtu}
1233 mtu "${ns_a}" ${type}_a $((${ll_mtu} + 1000))
1234 mtu "${ns_b}" ${type}_b $((${ll_mtu} + 1000))
1235 run_cmd ${ns_a} ${ping} -q -M want -i 0.1 -w 1 -s $((${ll_mtu} + 500)) ${dst}
1237 # Check that exception was created
1238 pmtu="$(route_get_dst_pmtu_from_exception "${ns_a}" ${dst})"
1239 check_pmtu_value ${exp_mtu} "${pmtu}" "exceeding link layer MTU on ${type} interface"
1242 test_pmtu_ipv4_vxlan4_exception() {
1243 test_pmtu_ipvX_over_vxlanY_or_geneveY_exception vxlan 4 4
1246 test_pmtu_ipv6_vxlan4_exception() {
1247 test_pmtu_ipvX_over_vxlanY_or_geneveY_exception vxlan 6 4
1250 test_pmtu_ipv4_geneve4_exception() {
1251 test_pmtu_ipvX_over_vxlanY_or_geneveY_exception geneve 4 4
1254 test_pmtu_ipv6_geneve4_exception() {
1255 test_pmtu_ipvX_over_vxlanY_or_geneveY_exception geneve 6 4
1258 test_pmtu_ipv4_vxlan6_exception() {
1259 test_pmtu_ipvX_over_vxlanY_or_geneveY_exception vxlan 4 6
1262 test_pmtu_ipv6_vxlan6_exception() {
1263 test_pmtu_ipvX_over_vxlanY_or_geneveY_exception vxlan 6 6
1266 test_pmtu_ipv4_geneve6_exception() {
1267 test_pmtu_ipvX_over_vxlanY_or_geneveY_exception geneve 4 6
1270 test_pmtu_ipv6_geneve6_exception() {
1271 test_pmtu_ipvX_over_vxlanY_or_geneveY_exception geneve 6 6
1274 test_pmtu_ipvX_over_bridged_vxlanY_or_geneveY_exception() {
1280 if [ ${outer_family} -eq 4 ]; then
1281 setup namespaces routing bridge bridged_${type}4 || return $ksft_skip
1282 # IPv4 header UDP header VXLAN/GENEVE header Ethernet header
1283 exp_mtu=$((${ll_mtu} - 20 - 8 - 8 - 14))
1285 setup namespaces routing bridge bridged_${type}6 || return $ksft_skip
1286 # IPv6 header UDP header VXLAN/GENEVE header Ethernet header
1287 exp_mtu=$((${ll_mtu} - 40 - 8 - 8 - 14))
1290 trace "${ns_a}" ${type}_a "${ns_b}" ${type}_b \
1291 "${ns_a}" veth_A-R1 "${ns_r1}" veth_R1-A \
1292 "${ns_b}" veth_B-R1 "${ns_r1}" veth_R1-B \
1293 "${ns_a}" br0 "${ns_a}" veth-A-C \
1296 if [ ${family} -eq 4 ]; then
1298 dst=${tunnel4_b_addr}
1301 dst=${tunnel6_b_addr}
1304 # Create route exception by exceeding link layer MTU
1305 mtu "${ns_a}" veth_A-R1 $((${ll_mtu} + 1000))
1306 mtu "${ns_a}" br0 $((${ll_mtu} + 1000))
1307 mtu "${ns_a}" veth_A-C $((${ll_mtu} + 1000))
1308 mtu "${ns_c}" veth_C-A $((${ll_mtu} + 1000))
1309 mtu "${ns_r1}" veth_R1-A $((${ll_mtu} + 1000))
1310 mtu "${ns_b}" veth_B-R1 ${ll_mtu}
1311 mtu "${ns_r1}" veth_R1-B ${ll_mtu}
1313 mtu "${ns_a}" ${type}_a $((${ll_mtu} + 1000))
1314 mtu "${ns_b}" ${type}_b $((${ll_mtu} + 1000))
1316 run_cmd ${ns_c} ${ping} -q -M want -i 0.1 -c 10 -s $((${ll_mtu} + 500)) ${dst} || return 1
1317 run_cmd ${ns_a} ${ping} -q -M want -i 0.1 -w 1 -s $((${ll_mtu} + 500)) ${dst} || return 1
1319 # Check that exceptions were created
1320 pmtu="$(route_get_dst_pmtu_from_exception "${ns_c}" ${dst})"
1321 check_pmtu_value ${exp_mtu} "${pmtu}" "exceeding link layer MTU on bridged ${type} interface"
1322 pmtu="$(route_get_dst_pmtu_from_exception "${ns_a}" ${dst})"
1323 check_pmtu_value ${exp_mtu} "${pmtu}" "exceeding link layer MTU on locally bridged ${type} interface"
1325 tmpoutfile=$(mktemp)
1327 # Flush Exceptions, retry with TCP
1328 run_cmd ${ns_a} ip route flush cached ${dst}
1329 run_cmd ${ns_b} ip route flush cached ${dst}
1330 run_cmd ${ns_c} ip route flush cached ${dst}
1332 for target in "${ns_a}" "${ns_c}" ; do
1333 if [ ${family} -eq 4 ]; then
1334 TCPDST=TCP:${dst}:50000
1336 TCPDST="TCP:[${dst}]:50000"
1338 ${ns_b} socat -T 3 -u -6 TCP-LISTEN:50000 STDOUT > $tmpoutfile &
1342 dd if=/dev/zero status=none bs=1M count=1 | ${target} socat -T 3 -u STDIN $TCPDST,connect-timeout=3
1344 size=$(du -sb $tmpoutfile)
1345 size=${size%%/tmp/*}
1347 [ $size -ne 1048576 ] && err "File size $size mismatches exepcted value in locally bridged vxlan test" && return 1
1352 # Check that exceptions were created
1353 pmtu="$(route_get_dst_pmtu_from_exception "${ns_c}" ${dst})"
1354 check_pmtu_value ${exp_mtu} "${pmtu}" "tcp: exceeding link layer MTU on bridged ${type} interface"
1355 pmtu="$(route_get_dst_pmtu_from_exception "${ns_a}" ${dst})"
1356 check_pmtu_value ${exp_mtu} "${pmtu}" "tcp exceeding link layer MTU on locally bridged ${type} interface"
1359 test_pmtu_ipv4_br_vxlan4_exception() {
1360 test_pmtu_ipvX_over_bridged_vxlanY_or_geneveY_exception vxlan 4 4
1363 test_pmtu_ipv6_br_vxlan4_exception() {
1364 test_pmtu_ipvX_over_bridged_vxlanY_or_geneveY_exception vxlan 6 4
1367 test_pmtu_ipv4_br_geneve4_exception() {
1368 test_pmtu_ipvX_over_bridged_vxlanY_or_geneveY_exception geneve 4 4
1371 test_pmtu_ipv6_br_geneve4_exception() {
1372 test_pmtu_ipvX_over_bridged_vxlanY_or_geneveY_exception geneve 6 4
1375 test_pmtu_ipv4_br_vxlan6_exception() {
1376 test_pmtu_ipvX_over_bridged_vxlanY_or_geneveY_exception vxlan 4 6
1379 test_pmtu_ipv6_br_vxlan6_exception() {
1380 test_pmtu_ipvX_over_bridged_vxlanY_or_geneveY_exception vxlan 6 6
1383 test_pmtu_ipv4_br_geneve6_exception() {
1384 test_pmtu_ipvX_over_bridged_vxlanY_or_geneveY_exception geneve 4 6
1387 test_pmtu_ipv6_br_geneve6_exception() {
1388 test_pmtu_ipvX_over_bridged_vxlanY_or_geneveY_exception geneve 6 6
1391 test_pmtu_ipvX_over_ovs_vxlanY_or_geneveY_exception() {
1397 if [ ${outer_family} -eq 4 ]; then
1398 setup namespaces routing ovs_bridge ovs_${type}4 || return $ksft_skip
1399 # IPv4 header UDP header VXLAN/GENEVE header Ethernet header
1400 exp_mtu=$((${ll_mtu} - 20 - 8 - 8 - 14))
1402 setup namespaces routing ovs_bridge ovs_${type}6 || return $ksft_skip
1403 # IPv6 header UDP header VXLAN/GENEVE header Ethernet header
1404 exp_mtu=$((${ll_mtu} - 40 - 8 - 8 - 14))
1407 if [ "${type}" = "vxlan" ]; then
1408 tun_a="vxlan_sys_4789"
1409 elif [ "${type}" = "geneve" ]; then
1410 tun_a="genev_sys_6081"
1413 trace "" "${tun_a}" "${ns_b}" ${type}_b \
1414 "" veth_A-R1 "${ns_r1}" veth_R1-A \
1415 "${ns_b}" veth_B-R1 "${ns_r1}" veth_R1-B \
1416 "" ovs_br0 "" veth-A-C \
1419 if [ ${family} -eq 4 ]; then
1421 dst=${tunnel4_b_addr}
1424 dst=${tunnel6_b_addr}
1427 # Create route exception by exceeding link layer MTU
1428 mtu "" veth_A-R1 $((${ll_mtu} + 1000))
1429 mtu "" ovs_br0 $((${ll_mtu} + 1000))
1430 mtu "" veth_A-C $((${ll_mtu} + 1000))
1431 mtu "${ns_c}" veth_C-A $((${ll_mtu} + 1000))
1432 mtu "${ns_r1}" veth_R1-A $((${ll_mtu} + 1000))
1433 mtu "${ns_b}" veth_B-R1 ${ll_mtu}
1434 mtu "${ns_r1}" veth_R1-B ${ll_mtu}
1436 mtu "" ${tun_a} $((${ll_mtu} + 1000))
1437 mtu "${ns_b}" ${type}_b $((${ll_mtu} + 1000))
1439 run_cmd ${ns_c} ${ping} -q -M want -i 0.1 -c 20 -s $((${ll_mtu} + 500)) ${dst} || return 1
1441 # Check that exceptions were created
1442 pmtu="$(route_get_dst_pmtu_from_exception "${ns_c}" ${dst})"
1443 check_pmtu_value ${exp_mtu} "${pmtu}" "exceeding link layer MTU on Open vSwitch ${type} interface"
1446 test_pmtu_ipv4_ovs_vxlan4_exception() {
1447 test_pmtu_ipvX_over_ovs_vxlanY_or_geneveY_exception vxlan 4 4
1450 test_pmtu_ipv6_ovs_vxlan4_exception() {
1451 test_pmtu_ipvX_over_ovs_vxlanY_or_geneveY_exception vxlan 6 4
1454 test_pmtu_ipv4_ovs_geneve4_exception() {
1455 test_pmtu_ipvX_over_ovs_vxlanY_or_geneveY_exception geneve 4 4
1458 test_pmtu_ipv6_ovs_geneve4_exception() {
1459 test_pmtu_ipvX_over_ovs_vxlanY_or_geneveY_exception geneve 6 4
1462 test_pmtu_ipv4_ovs_vxlan6_exception() {
1463 test_pmtu_ipvX_over_ovs_vxlanY_or_geneveY_exception vxlan 4 6
1466 test_pmtu_ipv6_ovs_vxlan6_exception() {
1467 test_pmtu_ipvX_over_ovs_vxlanY_or_geneveY_exception vxlan 6 6
1470 test_pmtu_ipv4_ovs_geneve6_exception() {
1471 test_pmtu_ipvX_over_ovs_vxlanY_or_geneveY_exception geneve 4 6
1474 test_pmtu_ipv6_ovs_geneve6_exception() {
1475 test_pmtu_ipvX_over_ovs_vxlanY_or_geneveY_exception geneve 6 6
1478 test_pmtu_ipvX_over_fouY_or_gueY() {
1484 setup namespaces routing ${encap}${outer_family}${inner_family} || return $ksft_skip
1485 trace "${ns_a}" ${encap}_a "${ns_b}" ${encap}_b \
1486 "${ns_a}" veth_A-R1 "${ns_r1}" veth_R1-A \
1487 "${ns_b}" veth_B-R1 "${ns_r1}" veth_R1-B
1489 if [ ${inner_family} -eq 4 ]; then
1491 dst=${tunnel4_b_addr}
1494 dst=${tunnel6_b_addr}
1497 if [ "${encap}" = "gue" ]; then
1503 if [ ${outer_family} -eq 4 ]; then
1504 # IPv4 header UDP header
1505 exp_mtu=$((${ll_mtu} - 20 - 8 - ${encap_overhead}))
1507 # IPv6 header Option 4 UDP header
1508 exp_mtu=$((${ll_mtu} - 40 - 8 - 8 - ${encap_overhead}))
1511 # Create route exception by exceeding link layer MTU
1512 mtu "${ns_a}" veth_A-R1 $((${ll_mtu} + 1000))
1513 mtu "${ns_r1}" veth_R1-A $((${ll_mtu} + 1000))
1514 mtu "${ns_b}" veth_B-R1 ${ll_mtu}
1515 mtu "${ns_r1}" veth_R1-B ${ll_mtu}
1517 mtu "${ns_a}" ${encap}_a $((${ll_mtu} + 1000))
1518 mtu "${ns_b}" ${encap}_b $((${ll_mtu} + 1000))
1519 run_cmd ${ns_a} ${ping} -q -M want -i 0.1 -w 1 -s $((${ll_mtu} + 500)) ${dst}
1521 # Check that exception was created
1522 pmtu="$(route_get_dst_pmtu_from_exception "${ns_a}" ${dst})"
1523 check_pmtu_value ${exp_mtu} "${pmtu}" "exceeding link layer MTU on ${encap} interface"
1526 test_pmtu_ipv4_fou4_exception() {
1527 test_pmtu_ipvX_over_fouY_or_gueY 4 4 fou
1530 test_pmtu_ipv6_fou4_exception() {
1531 test_pmtu_ipvX_over_fouY_or_gueY 6 4 fou
1534 test_pmtu_ipv4_fou6_exception() {
1535 test_pmtu_ipvX_over_fouY_or_gueY 4 6 fou
1538 test_pmtu_ipv6_fou6_exception() {
1539 test_pmtu_ipvX_over_fouY_or_gueY 6 6 fou
1542 test_pmtu_ipv4_gue4_exception() {
1543 test_pmtu_ipvX_over_fouY_or_gueY 4 4 gue
1546 test_pmtu_ipv6_gue4_exception() {
1547 test_pmtu_ipvX_over_fouY_or_gueY 6 4 gue
1550 test_pmtu_ipv4_gue6_exception() {
1551 test_pmtu_ipvX_over_fouY_or_gueY 4 6 gue
1554 test_pmtu_ipv6_gue6_exception() {
1555 test_pmtu_ipvX_over_fouY_or_gueY 6 6 gue
1558 test_pmtu_ipvX_over_ipvY_exception() {
1563 setup namespaces routing ip${inner}ip${outer} || return $ksft_skip
1565 trace "${ns_a}" ip_a "${ns_b}" ip_b \
1566 "${ns_a}" veth_A-R1 "${ns_r1}" veth_R1-A \
1567 "${ns_b}" veth_B-R1 "${ns_r1}" veth_R1-B
1569 if [ ${inner} -eq 4 ]; then
1571 dst=${tunnel4_b_addr}
1574 dst=${tunnel6_b_addr}
1577 if [ ${outer} -eq 4 ]; then
1579 exp_mtu=$((${ll_mtu} - 20))
1581 # IPv6 header Option 4
1582 exp_mtu=$((${ll_mtu} - 40 - 8))
1585 # Create route exception by exceeding link layer MTU
1586 mtu "${ns_a}" veth_A-R1 $((${ll_mtu} + 1000))
1587 mtu "${ns_r1}" veth_R1-A $((${ll_mtu} + 1000))
1588 mtu "${ns_b}" veth_B-R1 ${ll_mtu}
1589 mtu "${ns_r1}" veth_R1-B ${ll_mtu}
1591 mtu "${ns_a}" ip_a $((${ll_mtu} + 1000)) || return
1592 mtu "${ns_b}" ip_b $((${ll_mtu} + 1000)) || return
1593 run_cmd ${ns_a} ${ping} -q -M want -i 0.1 -w 1 -s $((${ll_mtu} + 500)) ${dst}
1595 # Check that exception was created
1596 pmtu="$(route_get_dst_pmtu_from_exception "${ns_a}" ${dst})"
1597 check_pmtu_value ${exp_mtu} "${pmtu}" "exceeding link layer MTU on ip${inner}ip${outer} interface"
1600 test_pmtu_ipv4_ipv4_exception() {
1601 test_pmtu_ipvX_over_ipvY_exception 4 4
1604 test_pmtu_ipv6_ipv4_exception() {
1605 test_pmtu_ipvX_over_ipvY_exception 6 4
1608 test_pmtu_ipv4_ipv6_exception() {
1609 test_pmtu_ipvX_over_ipvY_exception 4 6
1612 test_pmtu_ipv6_ipv6_exception() {
1613 test_pmtu_ipvX_over_ipvY_exception 6 6
1616 test_pmtu_vti4_exception() {
1617 setup namespaces veth vti4 xfrm4 || return $ksft_skip
1618 trace "${ns_a}" veth_a "${ns_b}" veth_b \
1619 "${ns_a}" vti4_a "${ns_b}" vti4_b
1622 vti_mtu=$((veth_mtu - 20))
1624 # SPI SN IV ICV pad length next header
1625 esp_payload_rfc4106=$((vti_mtu - 4 - 4 - 8 - 16 - 1 - 1))
1626 ping_payload=$((esp_payload_rfc4106 - 28))
1628 mtu "${ns_a}" veth_a ${veth_mtu}
1629 mtu "${ns_b}" veth_b ${veth_mtu}
1630 mtu "${ns_a}" vti4_a ${vti_mtu}
1631 mtu "${ns_b}" vti4_b ${vti_mtu}
1633 # Send DF packet without exceeding link layer MTU, check that no
1634 # exception is created
1635 run_cmd ${ns_a} ping -q -M want -i 0.1 -w 1 -s ${ping_payload} ${tunnel4_b_addr}
1636 pmtu="$(route_get_dst_pmtu_from_exception "${ns_a}" ${tunnel4_b_addr})"
1637 check_pmtu_value "" "${pmtu}" "sending packet smaller than PMTU (IP payload length ${esp_payload_rfc4106})" || return 1
1639 # Now exceed link layer MTU by one byte, check that exception is created
1640 # with the right PMTU value
1641 run_cmd ${ns_a} ping -q -M want -i 0.1 -w 1 -s $((ping_payload + 1)) ${tunnel4_b_addr}
1642 pmtu="$(route_get_dst_pmtu_from_exception "${ns_a}" ${tunnel4_b_addr})"
1643 check_pmtu_value "${esp_payload_rfc4106}" "${pmtu}" "exceeding PMTU (IP payload length $((esp_payload_rfc4106 + 1)))"
1646 test_pmtu_vti6_exception() {
1647 setup namespaces veth vti6 xfrm6 || return $ksft_skip
1648 trace "${ns_a}" veth_a "${ns_b}" veth_b \
1649 "${ns_a}" vti6_a "${ns_b}" vti6_b
1652 # Create route exception by exceeding link layer MTU
1653 mtu "${ns_a}" veth_a 4000
1654 mtu "${ns_b}" veth_b 4000
1655 mtu "${ns_a}" vti6_a 5000
1656 mtu "${ns_b}" vti6_b 5000
1657 run_cmd ${ns_a} ${ping6} -q -i 0.1 -w 1 -s 60000 ${tunnel6_b_addr}
1659 # Check that exception was created
1660 pmtu="$(route_get_dst_pmtu_from_exception "${ns_a}" ${tunnel6_b_addr})"
1661 check_pmtu_value any "${pmtu}" "creating tunnel exceeding link layer MTU" || return 1
1663 # Decrease tunnel MTU, check for PMTU decrease in route exception
1664 mtu "${ns_a}" vti6_a 3000
1665 pmtu="$(route_get_dst_pmtu_from_exception "${ns_a}" ${tunnel6_b_addr})"
1666 check_pmtu_value "3000" "${pmtu}" "decreasing tunnel MTU" || fail=1
1668 # Increase tunnel MTU, check for PMTU increase in route exception
1669 mtu "${ns_a}" vti6_a 9000
1670 pmtu="$(route_get_dst_pmtu_from_exception "${ns_a}" ${tunnel6_b_addr})"
1671 check_pmtu_value "9000" "${pmtu}" "increasing tunnel MTU" || fail=1
1676 test_pmtu_vti4_udp_exception() {
1677 setup namespaces veth vti4 xfrm4udp || return $ksft_skip
1678 trace "${ns_a}" veth_a "${ns_b}" veth_b \
1679 "${ns_a}" vti4_a "${ns_b}" vti4_b
1682 vti_mtu=$((veth_mtu - 20))
1684 # UDP SPI SN IV ICV pad length next header
1685 esp_payload_rfc4106=$((vti_mtu - 8 - 4 - 4 - 8 - 16 - 1 - 1))
1686 ping_payload=$((esp_payload_rfc4106 - 28))
1688 mtu "${ns_a}" veth_a ${veth_mtu}
1689 mtu "${ns_b}" veth_b ${veth_mtu}
1690 mtu "${ns_a}" vti4_a ${vti_mtu}
1691 mtu "${ns_b}" vti4_b ${vti_mtu}
1693 # Send DF packet without exceeding link layer MTU, check that no
1694 # exception is created
1695 run_cmd ${ns_a} ping -q -M want -i 0.1 -w 1 -s ${ping_payload} ${tunnel4_b_addr}
1696 pmtu="$(route_get_dst_pmtu_from_exception "${ns_a}" ${tunnel4_b_addr})"
1697 check_pmtu_value "" "${pmtu}" "sending packet smaller than PMTU (IP payload length ${esp_payload_rfc4106})" || return 1
1699 # Now exceed link layer MTU by one byte, check that exception is created
1700 # with the right PMTU value
1701 run_cmd ${ns_a} ping -q -M want -i 0.1 -w 1 -s $((ping_payload + 1)) ${tunnel4_b_addr}
1702 pmtu="$(route_get_dst_pmtu_from_exception "${ns_a}" ${tunnel4_b_addr})"
1703 check_pmtu_value "${esp_payload_rfc4106}" "${pmtu}" "exceeding PMTU (IP payload length $((esp_payload_rfc4106 + 1)))"
1706 test_pmtu_vti6_udp_exception() {
1707 setup namespaces veth vti6 xfrm6udp || return $ksft_skip
1708 trace "${ns_a}" veth_a "${ns_b}" veth_b \
1709 "${ns_a}" vti6_a "${ns_b}" vti6_b
1712 # Create route exception by exceeding link layer MTU
1713 mtu "${ns_a}" veth_a 4000
1714 mtu "${ns_b}" veth_b 4000
1715 mtu "${ns_a}" vti6_a 5000
1716 mtu "${ns_b}" vti6_b 5000
1717 run_cmd ${ns_a} ${ping6} -q -i 0.1 -w 1 -s 60000 ${tunnel6_b_addr}
1719 # Check that exception was created
1720 pmtu="$(route_get_dst_pmtu_from_exception "${ns_a}" ${tunnel6_b_addr})"
1721 check_pmtu_value any "${pmtu}" "creating tunnel exceeding link layer MTU" || return 1
1723 # Decrease tunnel MTU, check for PMTU decrease in route exception
1724 mtu "${ns_a}" vti6_a 3000
1725 pmtu="$(route_get_dst_pmtu_from_exception "${ns_a}" ${tunnel6_b_addr})"
1726 check_pmtu_value "3000" "${pmtu}" "decreasing tunnel MTU" || fail=1
1728 # Increase tunnel MTU, check for PMTU increase in route exception
1729 mtu "${ns_a}" vti6_a 9000
1730 pmtu="$(route_get_dst_pmtu_from_exception "${ns_a}" ${tunnel6_b_addr})"
1731 check_pmtu_value "9000" "${pmtu}" "increasing tunnel MTU" || fail=1
1736 test_pmtu_vti4_udp_routed_exception() {
1737 setup namespaces routing vti4routed xfrm4udprouted || return $ksft_skip
1738 trace "${ns_a}" veth_A-R1 "${ns_b}" veth_B-R1 \
1739 "${ns_a}" vti4_a "${ns_b}" vti4_b
1742 vti_mtu=$((veth_mtu - 20))
1744 # UDP SPI SN IV ICV pad length next header
1745 esp_payload_rfc4106=$((vti_mtu - 8 - 4 - 4 - 8 - 16 - 1 - 1))
1746 ping_payload=$((esp_payload_rfc4106 - 28))
1748 mtu "${ns_a}" veth_A-R1 ${veth_mtu}
1749 mtu "${ns_r1}" veth_R1-A ${veth_mtu}
1750 mtu "${ns_b}" veth_B-R1 ${veth_mtu}
1751 mtu "${ns_r1}" veth_R1-B ${veth_mtu}
1753 mtu "${ns_a}" vti4_a ${vti_mtu}
1754 mtu "${ns_b}" vti4_b ${vti_mtu}
1756 # Send DF packet without exceeding link layer MTU, check that no
1757 # exception is created
1758 run_cmd ${ns_a} ping -q -M want -i 0.1 -w 1 -s ${ping_payload} ${tunnel4_b_addr}
1759 pmtu="$(route_get_dst_pmtu_from_exception "${ns_a}" ${tunnel4_b_addr})"
1760 check_pmtu_value "" "${pmtu}" "sending packet smaller than PMTU (IP payload length ${esp_payload_rfc4106})" || return 1
1762 # Now decrease link layer MTU by 8 bytes on R1, check that exception is created
1763 # with the right PMTU value
1764 mtu "${ns_r1}" veth_R1-B $((veth_mtu - 8))
1765 run_cmd ${ns_a} ping -q -M want -i 0.1 -w 1 -s $((ping_payload)) ${tunnel4_b_addr}
1766 pmtu="$(route_get_dst_pmtu_from_exception "${ns_a}" ${tunnel4_b_addr})"
1767 check_pmtu_value "$((esp_payload_rfc4106 - 8))" "${pmtu}" "exceeding PMTU (IP payload length $((esp_payload_rfc4106)))"
1770 test_pmtu_vti6_udp_routed_exception() {
1771 setup namespaces routing vti6routed xfrm6udprouted || return $ksft_skip
1772 trace "${ns_a}" veth_A-R1 "${ns_b}" veth_B-R1 \
1773 "${ns_a}" vti6_a "${ns_b}" vti6_b
1776 vti_mtu=$((veth_mtu - 40))
1778 # UDP SPI SN IV ICV pad length next header
1779 esp_payload_rfc4106=$((vti_mtu - 8 - 4 - 4 - 8 - 16 - 1 - 1))
1780 ping_payload=$((esp_payload_rfc4106 - 48))
1782 mtu "${ns_a}" veth_A-R1 ${veth_mtu}
1783 mtu "${ns_r1}" veth_R1-A ${veth_mtu}
1784 mtu "${ns_b}" veth_B-R1 ${veth_mtu}
1785 mtu "${ns_r1}" veth_R1-B ${veth_mtu}
1787 # mtu "${ns_a}" vti6_a ${vti_mtu}
1788 # mtu "${ns_b}" vti6_b ${vti_mtu}
1790 run_cmd ${ns_a} ${ping6} -q -M want -i 0.1 -w 1 -s ${ping_payload} ${tunnel6_b_addr}
1792 # Check that exception was not created
1793 pmtu="$(route_get_dst_pmtu_from_exception "${ns_a}" ${tunnel6_b_addr})"
1794 check_pmtu_value "" "${pmtu}" "sending packet smaller than PMTU (IP payload length ${esp_payload_rfc4106})" || return 1
1796 # Now decrease link layer MTU by 8 bytes on R1, check that exception is created
1797 # with the right PMTU value
1798 mtu "${ns_r1}" veth_R1-B $((veth_mtu - 8))
1799 run_cmd ${ns_a} ${ping6} -q -M want -i 0.1 -w 1 -s $((ping_payload)) ${tunnel6_b_addr}
1800 pmtu="$(route_get_dst_pmtu_from_exception "${ns_a}" ${tunnel6_b_addr})"
1801 check_pmtu_value "$((esp_payload_rfc4106 - 8))" "${pmtu}" "exceeding PMTU (IP payload length $((esp_payload_rfc4106)))"
1805 test_pmtu_vti4_default_mtu() {
1806 setup namespaces veth vti4 || return $ksft_skip
1808 # Check that MTU of vti device is MTU of veth minus IPv4 header length
1809 veth_mtu="$(link_get_mtu "${ns_a}" veth_a)"
1810 vti4_mtu="$(link_get_mtu "${ns_a}" vti4_a)"
1811 if [ $((veth_mtu - vti4_mtu)) -ne 20 ]; then
1812 err " vti MTU ${vti4_mtu} is not veth MTU ${veth_mtu} minus IPv4 header length"
1817 test_pmtu_vti6_default_mtu() {
1818 setup namespaces veth vti6 || return $ksft_skip
1820 # Check that MTU of vti device is MTU of veth minus IPv6 header length
1821 veth_mtu="$(link_get_mtu "${ns_a}" veth_a)"
1822 vti6_mtu="$(link_get_mtu "${ns_a}" vti6_a)"
1823 if [ $((veth_mtu - vti6_mtu)) -ne 40 ]; then
1824 err " vti MTU ${vti6_mtu} is not veth MTU ${veth_mtu} minus IPv6 header length"
1829 test_pmtu_vti4_link_add_mtu() {
1830 setup namespaces || return $ksft_skip
1832 run_cmd ${ns_a} ip link add vti4_a type vti local ${veth4_a_addr} remote ${veth4_b_addr} key 10
1833 [ $? -ne 0 ] && err " vti not supported" && return $ksft_skip
1834 run_cmd ${ns_a} ip link del vti4_a
1840 # Check invalid values first
1841 for v in $((min - 1)) $((max + 1)); do
1842 run_cmd ${ns_a} ip link add vti4_a mtu ${v} type vti local ${veth4_a_addr} remote ${veth4_b_addr} key 10
1843 # This can fail, or MTU can be adjusted to a proper value
1844 [ $? -ne 0 ] && continue
1845 mtu="$(link_get_mtu "${ns_a}" vti4_a)"
1846 if [ ${mtu} -lt ${min} -o ${mtu} -gt ${max} ]; then
1847 err " vti tunnel created with invalid MTU ${mtu}"
1850 run_cmd ${ns_a} ip link del vti4_a
1853 # Now check valid values
1854 for v in ${min} 1300 ${max}; do
1855 run_cmd ${ns_a} ip link add vti4_a mtu ${v} type vti local ${veth4_a_addr} remote ${veth4_b_addr} key 10
1856 mtu="$(link_get_mtu "${ns_a}" vti4_a)"
1857 run_cmd ${ns_a} ip link del vti4_a
1858 if [ "${mtu}" != "${v}" ]; then
1859 err " vti MTU ${mtu} doesn't match configured value ${v}"
1867 test_pmtu_vti6_link_add_mtu() {
1868 setup namespaces || return $ksft_skip
1870 run_cmd ${ns_a} ip link add vti6_a type vti6 local ${veth6_a_addr} remote ${veth6_b_addr} key 10
1871 [ $? -ne 0 ] && err " vti6 not supported" && return $ksft_skip
1872 run_cmd ${ns_a} ip link del vti6_a
1876 min=68 # vti6 can carry IPv4 packets too
1878 # Check invalid values first
1879 for v in $((min - 1)) $((max + 1)); do
1880 run_cmd ${ns_a} ip link add vti6_a mtu ${v} type vti6 local ${veth6_a_addr} remote ${veth6_b_addr} key 10
1881 # This can fail, or MTU can be adjusted to a proper value
1882 [ $? -ne 0 ] && continue
1883 mtu="$(link_get_mtu "${ns_a}" vti6_a)"
1884 if [ ${mtu} -lt ${min} -o ${mtu} -gt ${max} ]; then
1885 err " vti6 tunnel created with invalid MTU ${v}"
1888 run_cmd ${ns_a} ip link del vti6_a
1891 # Now check valid values
1892 for v in 68 1280 1300 $((65535 - 40)); do
1893 run_cmd ${ns_a} ip link add vti6_a mtu ${v} type vti6 local ${veth6_a_addr} remote ${veth6_b_addr} key 10
1894 mtu="$(link_get_mtu "${ns_a}" vti6_a)"
1895 run_cmd ${ns_a} ip link del vti6_a
1896 if [ "${mtu}" != "${v}" ]; then
1897 err " vti6 MTU ${mtu} doesn't match configured value ${v}"
1905 test_pmtu_vti6_link_change_mtu() {
1906 setup namespaces || return $ksft_skip
1908 run_cmd ${ns_a} ip link add dummy0 mtu 1500 type dummy
1909 [ $? -ne 0 ] && err " dummy not supported" && return $ksft_skip
1910 run_cmd ${ns_a} ip link add dummy1 mtu 3000 type dummy
1911 run_cmd ${ns_a} ip link set dummy0 up
1912 run_cmd ${ns_a} ip link set dummy1 up
1914 run_cmd ${ns_a} ip addr add ${dummy6_0_prefix}1/${dummy6_mask} dev dummy0
1915 run_cmd ${ns_a} ip addr add ${dummy6_1_prefix}1/${dummy6_mask} dev dummy1
1919 # Create vti6 interface bound to device, passing MTU, check it
1920 run_cmd ${ns_a} ip link add vti6_a mtu 1300 type vti6 remote ${dummy6_0_prefix}2 local ${dummy6_0_prefix}1
1921 mtu="$(link_get_mtu "${ns_a}" vti6_a)"
1922 if [ ${mtu} -ne 1300 ]; then
1923 err " vti6 MTU ${mtu} doesn't match configured value 1300"
1927 # Move to another device with different MTU, without passing MTU, check
1929 run_cmd ${ns_a} ip link set vti6_a type vti6 remote ${dummy6_1_prefix}2 local ${dummy6_1_prefix}1
1930 mtu="$(link_get_mtu "${ns_a}" vti6_a)"
1931 if [ ${mtu} -ne $((3000 - 40)) ]; then
1932 err " vti MTU ${mtu} is not dummy MTU 3000 minus IPv6 header length"
1936 # Move it back, passing MTU, check MTU is not overridden
1937 run_cmd ${ns_a} ip link set vti6_a mtu 1280 type vti6 remote ${dummy6_0_prefix}2 local ${dummy6_0_prefix}1
1938 mtu="$(link_get_mtu "${ns_a}" vti6_a)"
1939 if [ ${mtu} -ne 1280 ]; then
1940 err " vti6 MTU ${mtu} doesn't match configured value 1280"
1950 if ! which ${cmd} > /dev/null 2>&1; then
1951 err " missing required command: '${cmd}'"
1957 test_cleanup_vxlanX_exception() {
1962 check_command taskset || return $ksft_skip
1963 cpu_list=$(grep -m 2 processor /proc/cpuinfo | cut -d ' ' -f 2)
1965 setup namespaces routing ${encap}${outer} || return $ksft_skip
1966 trace "${ns_a}" ${encap}_a "${ns_b}" ${encap}_b \
1967 "${ns_a}" veth_A-R1 "${ns_r1}" veth_R1-A \
1968 "${ns_b}" veth_B-R1 "${ns_r1}" veth_R1-B
1970 # Create route exception by exceeding link layer MTU
1971 mtu "${ns_a}" veth_A-R1 $((${ll_mtu} + 1000))
1972 mtu "${ns_r1}" veth_R1-A $((${ll_mtu} + 1000))
1973 mtu "${ns_b}" veth_B-R1 ${ll_mtu}
1974 mtu "${ns_r1}" veth_R1-B ${ll_mtu}
1976 mtu "${ns_a}" ${encap}_a $((${ll_mtu} + 1000))
1977 mtu "${ns_b}" ${encap}_b $((${ll_mtu} + 1000))
1979 # Fill exception cache for multiple CPUs (2)
1980 # we can always use inner IPv4 for that
1981 for cpu in ${cpu_list}; do
1982 run_cmd taskset --cpu-list ${cpu} ${ns_a} ping -q -M want -i 0.1 -w 1 -s $((${ll_mtu} + 500)) ${tunnel4_b_addr}
1985 ${ns_a} ip link del dev veth_A-R1 &
1988 if [ "$(cat /proc/${iplink_pid}/cmdline 2>/dev/null | tr -d '\0')" = "iplinkdeldevveth_A-R1" ]; then
1989 err " can't delete veth device in a timely manner, PMTU dst likely leaked"
1994 test_cleanup_ipv6_exception() {
1995 test_cleanup_vxlanX_exception 6
1998 test_cleanup_ipv4_exception() {
1999 test_cleanup_vxlanX_exception 4
2009 # Since cleanup() relies on variables modified by this subshell, it
2010 # has to run in this context.
2013 if [ "$VERBOSE" = "1" ]; then
2014 printf "\n##########################################################################\n\n"
2020 if [ $ret -eq 0 ]; then
2021 printf "TEST: %-60s [ OK ]\n" "${tdesc}"
2022 elif [ $ret -eq 1 ]; then
2023 printf "TEST: %-60s [FAIL]\n" "${tdesc}"
2024 if [ "${PAUSE_ON_FAIL}" = "yes" ]; then
2026 echo "Pausing. Hit enter to continue"
2031 elif [ $ret -eq $ksft_skip ]; then
2032 printf "TEST: %-60s [SKIP]\n" "${tdesc}"
2042 [ $exitcode -eq $ksft_skip ] && exitcode=0
2045 [ $all_skipped = true ] && exitcode=$ksft_skip
2061 run_test "${tname}" "${tdesc} - nexthop objects"
2065 test_list_flush_ipv4_exception() {
2066 setup namespaces routing || return $ksft_skip
2067 trace "${ns_a}" veth_A-R1 "${ns_r1}" veth_R1-A \
2068 "${ns_r1}" veth_R1-B "${ns_b}" veth_B-R1 \
2069 "${ns_a}" veth_A-R2 "${ns_r2}" veth_R2-A \
2070 "${ns_r2}" veth_R2-B "${ns_b}" veth_B-R2
2072 dst_prefix1="${prefix4}.${b_r1}."
2073 dst2="${prefix4}.${b_r2}.1"
2075 # Set up initial MTU values
2076 mtu "${ns_a}" veth_A-R1 2000
2077 mtu "${ns_r1}" veth_R1-A 2000
2078 mtu "${ns_r1}" veth_R1-B 1500
2079 mtu "${ns_b}" veth_B-R1 1500
2081 mtu "${ns_a}" veth_A-R2 2000
2082 mtu "${ns_r2}" veth_R2-A 2000
2083 mtu "${ns_r2}" veth_R2-B 1500
2084 mtu "${ns_b}" veth_B-R2 1500
2088 # Add 100 addresses for veth endpoint on B reached by default A route
2089 for i in $(seq 100 199); do
2090 run_cmd ${ns_b} ip addr add "${dst_prefix1}${i}" dev veth_B-R1
2093 # Create 100 cached route exceptions for path via R1, one via R2. Note
2094 # that with IPv4 we need to actually cause a route lookup that matches
2095 # the exception caused by ICMP, in order to actually have a cached
2096 # route, so we need to ping each destination twice
2097 for i in $(seq 100 199); do
2098 run_cmd ${ns_a} ping -q -M want -i 0.1 -c 2 -s 1800 "${dst_prefix1}${i}"
2100 run_cmd ${ns_a} ping -q -M want -i 0.1 -c 2 -s 1800 "${dst2}"
2102 if [ "$(${ns_a} ip -oneline route list cache | wc -l)" -ne 101 ]; then
2103 err " can't list cached exceptions"
2107 run_cmd ${ns_a} ip route flush cache
2108 pmtu1="$(route_get_dst_pmtu_from_exception "${ns_a}" ${dst_prefix}1)"
2109 pmtu2="$(route_get_dst_pmtu_from_exception "${ns_a}" ${dst_prefix}2)"
2110 if [ -n "${pmtu1}" ] || [ -n "${pmtu2}" ] || \
2111 [ -n "$(${ns_a} ip route list cache)" ]; then
2112 err " can't flush cached exceptions"
2119 test_list_flush_ipv6_exception() {
2120 setup namespaces routing || return $ksft_skip
2121 trace "${ns_a}" veth_A-R1 "${ns_r1}" veth_R1-A \
2122 "${ns_r1}" veth_R1-B "${ns_b}" veth_B-R1 \
2123 "${ns_a}" veth_A-R2 "${ns_r2}" veth_R2-A \
2124 "${ns_r2}" veth_R2-B "${ns_b}" veth_B-R2
2126 dst_prefix1="${prefix6}:${b_r1}::"
2127 dst2="${prefix6}:${b_r2}::1"
2129 # Set up initial MTU values
2130 mtu "${ns_a}" veth_A-R1 2000
2131 mtu "${ns_r1}" veth_R1-A 2000
2132 mtu "${ns_r1}" veth_R1-B 1500
2133 mtu "${ns_b}" veth_B-R1 1500
2135 mtu "${ns_a}" veth_A-R2 2000
2136 mtu "${ns_r2}" veth_R2-A 2000
2137 mtu "${ns_r2}" veth_R2-B 1500
2138 mtu "${ns_b}" veth_B-R2 1500
2142 # Add 100 addresses for veth endpoint on B reached by default A route
2143 for i in $(seq 100 199); do
2144 run_cmd ${ns_b} ip addr add "${dst_prefix1}${i}" dev veth_B-R1
2147 # Create 100 cached route exceptions for path via R1, one via R2
2148 for i in $(seq 100 199); do
2149 run_cmd ${ns_a} ping -q -M want -i 0.1 -w 1 -s 1800 "${dst_prefix1}${i}"
2151 run_cmd ${ns_a} ping -q -M want -i 0.1 -w 1 -s 1800 "${dst2}"
2152 if [ "$(${ns_a} ip -oneline -6 route list cache | wc -l)" -ne 101 ]; then
2153 err " can't list cached exceptions"
2157 run_cmd ${ns_a} ip -6 route flush cache
2158 pmtu1="$(route_get_dst_pmtu_from_exception "${ns_a}" "${dst_prefix1}100")"
2159 pmtu2="$(route_get_dst_pmtu_from_exception "${ns_a}" ${dst2})"
2160 if [ -n "${pmtu1}" ] || [ -n "${pmtu2}" ] || \
2161 [ -n "$(${ns_a} ip -6 route list cache)" ]; then
2162 err " can't flush cached exceptions"
2169 test_pmtu_ipvX_route_change() {
2172 setup namespaces routing || return 2
2173 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-R2
2178 if [ ${family} -eq 4 ]; then
2180 dst1="${prefix4}.${b_r1}.1"
2181 dst2="${prefix4}.${b_r2}.1"
2182 gw="${prefix4}.${a_r1}.2"
2185 dst1="${prefix6}:${b_r1}::1"
2186 dst2="${prefix6}:${b_r2}::1"
2187 gw="${prefix6}:${a_r1}::2"
2190 # Set up initial MTU values
2191 mtu "${ns_a}" veth_A-R1 2000
2192 mtu "${ns_r1}" veth_R1-A 2000
2193 mtu "${ns_r1}" veth_R1-B 1400
2194 mtu "${ns_b}" veth_B-R1 1400
2196 mtu "${ns_a}" veth_A-R2 2000
2197 mtu "${ns_r2}" veth_R2-A 2000
2198 mtu "${ns_r2}" veth_R2-B 1500
2199 mtu "${ns_b}" veth_B-R2 1500
2201 # Create route exceptions
2202 run_cmd ${ns_a} ${ping} -q -M want -i 0.1 -w 1 -s 1800 ${dst1}
2203 run_cmd ${ns_a} ${ping} -q -M want -i 0.1 -w 1 -s 1800 ${dst2}
2205 # Check that exceptions have been created with the correct PMTU
2206 pmtu_1="$(route_get_dst_pmtu_from_exception "${ns_a}" ${dst1})"
2207 check_pmtu_value "1400" "${pmtu_1}" "exceeding MTU" || return 1
2208 pmtu_2="$(route_get_dst_pmtu_from_exception "${ns_a}" ${dst2})"
2209 check_pmtu_value "1500" "${pmtu_2}" "exceeding MTU" || return 1
2211 # Replace the route from A to R1
2212 run_cmd ${ns_a} ip route change default via ${gw}
2214 # Delete the device in A
2215 run_cmd ${ns_a} ip link del "veth_A-R1"
2218 test_pmtu_ipv4_route_change() {
2219 test_pmtu_ipvX_route_change 4
2222 test_pmtu_ipv6_route_change() {
2223 test_pmtu_ipvX_route_change 6
2228 echo "$0 [OPTIONS] [TEST]..."
2229 echo "If no TEST argument is given, all tests will be run."
2232 echo " --trace: capture traffic to TEST_INTERFACE.pcap"
2234 echo "Available tests${tests}"
2238 ################################################################################
2244 while getopts :ptv o
2247 p) PAUSE_ON_FAIL=yes;;
2249 t) if which tcpdump > /dev/null 2>&1; then
2252 echo "=== tcpdump not available, tracing disabled"
2258 shift $(($OPTIND-1))
2264 # Check first that all requested tests are available before running any
2265 command -v > /dev/null "test_${arg}" || { echo "=== Test ${arg} not found"; usage; }
2274 ip nexthop ls >/dev/null 2>&1
2275 [ $? -eq 0 ] && HAVE_NH=yes
2280 for t in ${tests}; do
2281 [ "${name}" = "" ] && name="${t}" && continue
2282 [ "${desc}" = "" ] && desc="${t}" && continue
2284 if [ "${HAVE_NH}" = "yes" ]; then
2290 [ "${arg}" != "${arg#--*}" ] && continue
2291 [ "${arg}" = "${name}" ] && run_this=1 && break
2294 if [ $run_this -eq 1 ]; then
2295 run_test "${name}" "${desc}"
2296 # if test was skipped no need to retry with nexthop objects
2297 [ $? -eq $ksft_skip ] && rerun_nh=0
2299 if [ "${rerun_nh}" = "1" ]; then
2300 run_test_nh "${name}" "${desc}"