Stefano Brivio | d1f1b9c | 2018-03-06 22:16:27 +0100 | [diff] [blame] | 1 | #!/bin/sh |
| 2 | # SPDX-License-Identifier: GPL-2.0 |
| 3 | # |
Stefano Brivio | a41c789 | 2018-03-17 02:31:42 +0100 | [diff] [blame] | 4 | # Check that route PMTU values match expectations, and that initial device MTU |
| 5 | # values are assigned correctly |
Stefano Brivio | d1f1b9c | 2018-03-06 22:16:27 +0100 | [diff] [blame] | 6 | # |
| 7 | # Tests currently implemented: |
| 8 | # |
Stefano Brivio | 5e84430 | 2018-03-17 02:31:44 +0100 | [diff] [blame] | 9 | # - pmtu_vti4_exception |
| 10 | # Set up vti tunnel on top of veth, with xfrm states and policies, in two |
| 11 | # namespaces with matching endpoints. Check that route exception is not |
| 12 | # created if link layer MTU is not exceeded, then exceed it and check that |
| 13 | # exception is created with the expected PMTU. The approach described |
| 14 | # below for IPv6 doesn't apply here, because, on IPv4, administrative MTU |
| 15 | # changes alone won't affect PMTU |
| 16 | # |
Stefano Brivio | 36455bd | 2018-03-17 02:31:41 +0100 | [diff] [blame] | 17 | # - pmtu_vti6_exception |
Stefano Brivio | d1f1b9c | 2018-03-06 22:16:27 +0100 | [diff] [blame] | 18 | # Set up vti6 tunnel on top of veth, with xfrm states and policies, in two |
| 19 | # namespaces with matching endpoints. Check that route exception is |
| 20 | # created by exceeding link layer MTU with ping to other endpoint. Then |
| 21 | # decrease and increase MTU of tunnel, checking that route exception PMTU |
| 22 | # changes accordingly |
Stefano Brivio | a41c789 | 2018-03-17 02:31:42 +0100 | [diff] [blame] | 23 | # |
| 24 | # - pmtu_vti4_default_mtu |
| 25 | # Set up vti4 tunnel on top of veth, in two namespaces with matching |
| 26 | # endpoints. Check that MTU assigned to vti interface is the MTU of the |
| 27 | # lower layer (veth) minus additional lower layer headers (zero, for veth) |
| 28 | # minus IPv4 header length |
Stefano Brivio | 35b4942 | 2018-03-17 02:31:43 +0100 | [diff] [blame] | 29 | # |
| 30 | # - pmtu_vti6_default_mtu |
| 31 | # Same as above, for IPv6 |
Stefano Brivio | 719e121 | 2018-03-17 02:31:45 +0100 | [diff] [blame] | 32 | # |
| 33 | # - pmtu_vti4_link_add_mtu |
| 34 | # Set up vti4 interface passing MTU value at link creation, check MTU is |
| 35 | # configured, and that link is not created with invalid MTU values |
Stefano Brivio | 8b6022f | 2018-03-17 02:31:46 +0100 | [diff] [blame] | 36 | # |
| 37 | # - pmtu_vti6_link_add_mtu |
| 38 | # Same as above, for IPv6 |
Stefano Brivio | 1fad59e | 2018-03-17 02:31:47 +0100 | [diff] [blame] | 39 | # |
| 40 | # - pmtu_vti6_link_change_mtu |
| 41 | # Set up two dummy interfaces with different MTUs, create a vti6 tunnel |
| 42 | # and check that configured MTU is used on link creation and changes, and |
| 43 | # that MTU is properly calculated instead when MTU is not configured from |
| 44 | # userspace |
Stefano Brivio | d1f1b9c | 2018-03-06 22:16:27 +0100 | [diff] [blame] | 45 | |
Shuah Khan (Samsung OSG) | 57aefc7 | 2018-05-04 16:34:09 -0600 | [diff] [blame] | 46 | # Kselftest framework requirement - SKIP code is 4. |
| 47 | ksft_skip=4 |
| 48 | |
Sabrina Dubroca | c81c701 | 2018-08-30 16:01:18 +0200 | [diff] [blame] | 49 | # Some systems don't have a ping6 binary anymore |
| 50 | which ping6 > /dev/null 2>&1 && ping6=$(which ping6) || ping6=$(which ping) |
| 51 | |
Stefano Brivio | 36455bd | 2018-03-17 02:31:41 +0100 | [diff] [blame] | 52 | tests=" |
Stefano Brivio | 1fad59e | 2018-03-17 02:31:47 +0100 | [diff] [blame] | 53 | pmtu_vti6_exception vti6: PMTU exceptions |
| 54 | pmtu_vti4_exception vti4: PMTU exceptions |
| 55 | pmtu_vti4_default_mtu vti4: default MTU assignment |
| 56 | pmtu_vti6_default_mtu vti6: default MTU assignment |
| 57 | pmtu_vti4_link_add_mtu vti4: MTU setting on link creation |
| 58 | pmtu_vti6_link_add_mtu vti6: MTU setting on link creation |
| 59 | pmtu_vti6_link_change_mtu vti6: MTU changes on link changes" |
Stefano Brivio | 36455bd | 2018-03-17 02:31:41 +0100 | [diff] [blame] | 60 | |
Stefano Brivio | d1f1b9c | 2018-03-06 22:16:27 +0100 | [diff] [blame] | 61 | NS_A="ns-$(mktemp -u XXXXXX)" |
| 62 | NS_B="ns-$(mktemp -u XXXXXX)" |
| 63 | ns_a="ip netns exec ${NS_A}" |
| 64 | ns_b="ip netns exec ${NS_B}" |
| 65 | |
Stefano Brivio | a41c789 | 2018-03-17 02:31:42 +0100 | [diff] [blame] | 66 | veth4_a_addr="192.168.1.1" |
| 67 | veth4_b_addr="192.168.1.2" |
| 68 | veth4_mask="24" |
Stefano Brivio | d1f1b9c | 2018-03-06 22:16:27 +0100 | [diff] [blame] | 69 | veth6_a_addr="fd00:1::a" |
| 70 | veth6_b_addr="fd00:1::b" |
| 71 | veth6_mask="64" |
| 72 | |
Stefano Brivio | a41c789 | 2018-03-17 02:31:42 +0100 | [diff] [blame] | 73 | vti4_a_addr="192.168.2.1" |
| 74 | vti4_b_addr="192.168.2.2" |
| 75 | vti4_mask="24" |
Stefano Brivio | d1f1b9c | 2018-03-06 22:16:27 +0100 | [diff] [blame] | 76 | vti6_a_addr="fd00:2::a" |
| 77 | vti6_b_addr="fd00:2::b" |
| 78 | vti6_mask="64" |
| 79 | |
Stefano Brivio | 1fad59e | 2018-03-17 02:31:47 +0100 | [diff] [blame] | 80 | dummy6_0_addr="fc00:1000::0" |
| 81 | dummy6_1_addr="fc00:1001::0" |
| 82 | dummy6_mask="64" |
| 83 | |
Stefano Brivio | 36455bd | 2018-03-17 02:31:41 +0100 | [diff] [blame] | 84 | cleanup_done=1 |
| 85 | err_buf= |
| 86 | |
| 87 | err() { |
| 88 | err_buf="${err_buf}${1} |
| 89 | " |
| 90 | } |
| 91 | |
| 92 | err_flush() { |
| 93 | echo -n "${err_buf}" |
| 94 | err_buf= |
| 95 | } |
| 96 | |
Stefano Brivio | d1f1b9c | 2018-03-06 22:16:27 +0100 | [diff] [blame] | 97 | setup_namespaces() { |
Stefano Brivio | 380e29a | 2018-03-17 02:31:38 +0100 | [diff] [blame] | 98 | ip netns add ${NS_A} || return 1 |
Stefano Brivio | d1f1b9c | 2018-03-06 22:16:27 +0100 | [diff] [blame] | 99 | ip netns add ${NS_B} |
Stefano Brivio | d1f1b9c | 2018-03-06 22:16:27 +0100 | [diff] [blame] | 100 | } |
| 101 | |
| 102 | setup_veth() { |
Stefano Brivio | 380e29a | 2018-03-17 02:31:38 +0100 | [diff] [blame] | 103 | ${ns_a} ip link add veth_a type veth peer name veth_b || return 1 |
Stefano Brivio | d1f1b9c | 2018-03-06 22:16:27 +0100 | [diff] [blame] | 104 | ${ns_a} ip link set veth_b netns ${NS_B} |
| 105 | |
Stefano Brivio | a41c789 | 2018-03-17 02:31:42 +0100 | [diff] [blame] | 106 | ${ns_a} ip addr add ${veth4_a_addr}/${veth4_mask} dev veth_a |
| 107 | ${ns_b} ip addr add ${veth4_b_addr}/${veth4_mask} dev veth_b |
| 108 | |
Stefano Brivio | d1f1b9c | 2018-03-06 22:16:27 +0100 | [diff] [blame] | 109 | ${ns_a} ip addr add ${veth6_a_addr}/${veth6_mask} dev veth_a |
| 110 | ${ns_b} ip addr add ${veth6_b_addr}/${veth6_mask} dev veth_b |
| 111 | |
| 112 | ${ns_a} ip link set veth_a up |
| 113 | ${ns_b} ip link set veth_b up |
Stefano Brivio | d1f1b9c | 2018-03-06 22:16:27 +0100 | [diff] [blame] | 114 | } |
| 115 | |
Stefano Brivio | a41c789 | 2018-03-17 02:31:42 +0100 | [diff] [blame] | 116 | setup_vti() { |
| 117 | proto=${1} |
| 118 | veth_a_addr="${2}" |
| 119 | veth_b_addr="${3}" |
| 120 | vti_a_addr="${4}" |
| 121 | vti_b_addr="${5}" |
| 122 | vti_mask=${6} |
Stefano Brivio | d1f1b9c | 2018-03-06 22:16:27 +0100 | [diff] [blame] | 123 | |
Stefano Brivio | a41c789 | 2018-03-17 02:31:42 +0100 | [diff] [blame] | 124 | [ ${proto} -eq 6 ] && vti_type="vti6" || vti_type="vti" |
Stefano Brivio | d1f1b9c | 2018-03-06 22:16:27 +0100 | [diff] [blame] | 125 | |
Stefano Brivio | a41c789 | 2018-03-17 02:31:42 +0100 | [diff] [blame] | 126 | ${ns_a} ip link add vti${proto}_a type ${vti_type} local ${veth_a_addr} remote ${veth_b_addr} key 10 || return 1 |
| 127 | ${ns_b} ip link add vti${proto}_b type ${vti_type} local ${veth_b_addr} remote ${veth_a_addr} key 10 |
| 128 | |
| 129 | ${ns_a} ip addr add ${vti_a_addr}/${vti_mask} dev vti${proto}_a |
| 130 | ${ns_b} ip addr add ${vti_b_addr}/${vti_mask} dev vti${proto}_b |
| 131 | |
| 132 | ${ns_a} ip link set vti${proto}_a up |
| 133 | ${ns_b} ip link set vti${proto}_b up |
Stefano Brivio | d1f1b9c | 2018-03-06 22:16:27 +0100 | [diff] [blame] | 134 | |
| 135 | sleep 1 |
Stefano Brivio | d1f1b9c | 2018-03-06 22:16:27 +0100 | [diff] [blame] | 136 | } |
| 137 | |
Stefano Brivio | a41c789 | 2018-03-17 02:31:42 +0100 | [diff] [blame] | 138 | setup_vti4() { |
| 139 | setup_vti 4 ${veth4_a_addr} ${veth4_b_addr} ${vti4_a_addr} ${vti4_b_addr} ${vti4_mask} |
| 140 | } |
| 141 | |
| 142 | setup_vti6() { |
| 143 | setup_vti 6 ${veth6_a_addr} ${veth6_b_addr} ${vti6_a_addr} ${vti6_b_addr} ${vti6_mask} |
| 144 | } |
| 145 | |
Stefano Brivio | d1f1b9c | 2018-03-06 22:16:27 +0100 | [diff] [blame] | 146 | setup_xfrm() { |
Stefano Brivio | 5e84430 | 2018-03-17 02:31:44 +0100 | [diff] [blame] | 147 | proto=${1} |
| 148 | veth_a_addr="${2}" |
| 149 | veth_b_addr="${3}" |
Stefano Brivio | d1f1b9c | 2018-03-06 22:16:27 +0100 | [diff] [blame] | 150 | |
Stefano Brivio | 5e84430 | 2018-03-17 02:31:44 +0100 | [diff] [blame] | 151 | ${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 || return 1 |
| 152 | ${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 |
| 153 | ${ns_a} ip -${proto} xfrm policy add dir out mark 10 tmpl src ${veth_a_addr} dst ${veth_b_addr} proto esp mode tunnel |
| 154 | ${ns_a} ip -${proto} xfrm policy add dir in mark 10 tmpl src ${veth_b_addr} dst ${veth_a_addr} proto esp mode tunnel |
| 155 | |
| 156 | ${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 |
| 157 | ${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 |
| 158 | ${ns_b} ip -${proto} xfrm policy add dir out mark 10 tmpl src ${veth_b_addr} dst ${veth_a_addr} proto esp mode tunnel |
| 159 | ${ns_b} ip -${proto} xfrm policy add dir in mark 10 tmpl src ${veth_a_addr} dst ${veth_b_addr} proto esp mode tunnel |
| 160 | } |
| 161 | |
| 162 | setup_xfrm4() { |
| 163 | setup_xfrm 4 ${veth4_a_addr} ${veth4_b_addr} |
| 164 | } |
| 165 | |
| 166 | setup_xfrm6() { |
| 167 | setup_xfrm 6 ${veth6_a_addr} ${veth6_b_addr} |
Stefano Brivio | d1f1b9c | 2018-03-06 22:16:27 +0100 | [diff] [blame] | 168 | } |
| 169 | |
| 170 | setup() { |
Shuah Khan (Samsung OSG) | 57aefc7 | 2018-05-04 16:34:09 -0600 | [diff] [blame] | 171 | [ "$(id -u)" -ne 0 ] && echo " need to run as root" && return $ksft_skip |
Stefano Brivio | d1f1b9c | 2018-03-06 22:16:27 +0100 | [diff] [blame] | 172 | |
Stefano Brivio | 36455bd | 2018-03-17 02:31:41 +0100 | [diff] [blame] | 173 | cleanup_done=0 |
| 174 | for arg do |
| 175 | eval setup_${arg} || { echo " ${arg} not supported"; return 1; } |
| 176 | done |
Stefano Brivio | d1f1b9c | 2018-03-06 22:16:27 +0100 | [diff] [blame] | 177 | } |
| 178 | |
| 179 | cleanup() { |
Stefano Brivio | 36455bd | 2018-03-17 02:31:41 +0100 | [diff] [blame] | 180 | [ ${cleanup_done} -eq 1 ] && return |
Sabrina Dubroca | 0a286af | 2018-09-17 15:30:06 +0200 | [diff] [blame] | 181 | ip netns del ${NS_A} 2> /dev/null |
| 182 | ip netns del ${NS_B} 2> /dev/null |
Stefano Brivio | 36455bd | 2018-03-17 02:31:41 +0100 | [diff] [blame] | 183 | cleanup_done=1 |
Stefano Brivio | d1f1b9c | 2018-03-06 22:16:27 +0100 | [diff] [blame] | 184 | } |
| 185 | |
| 186 | mtu() { |
| 187 | ns_cmd="${1}" |
| 188 | dev="${2}" |
| 189 | mtu="${3}" |
| 190 | |
| 191 | ${ns_cmd} ip link set dev ${dev} mtu ${mtu} |
| 192 | } |
| 193 | |
Stefano Brivio | f2c929f | 2018-03-17 02:31:40 +0100 | [diff] [blame] | 194 | mtu_parse() { |
| 195 | input="${1}" |
| 196 | |
| 197 | next=0 |
| 198 | for i in ${input}; do |
| 199 | [ ${next} -eq 1 ] && echo "${i}" && return |
| 200 | [ "${i}" = "mtu" ] && next=1 |
| 201 | done |
| 202 | } |
| 203 | |
Stefano Brivio | a41c789 | 2018-03-17 02:31:42 +0100 | [diff] [blame] | 204 | link_get() { |
| 205 | ns_cmd="${1}" |
| 206 | name="${2}" |
| 207 | |
| 208 | ${ns_cmd} ip link show dev "${name}" |
| 209 | } |
| 210 | |
| 211 | link_get_mtu() { |
| 212 | ns_cmd="${1}" |
| 213 | name="${2}" |
| 214 | |
| 215 | mtu_parse "$(link_get "${ns_cmd}" ${name})" |
| 216 | } |
| 217 | |
Stefano Brivio | d1f1b9c | 2018-03-06 22:16:27 +0100 | [diff] [blame] | 218 | route_get_dst_exception() { |
Stefano Brivio | 822d2f8 | 2018-03-17 02:31:39 +0100 | [diff] [blame] | 219 | ns_cmd="${1}" |
| 220 | dst="${2}" |
Stefano Brivio | d1f1b9c | 2018-03-06 22:16:27 +0100 | [diff] [blame] | 221 | |
Stefano Brivio | 822d2f8 | 2018-03-17 02:31:39 +0100 | [diff] [blame] | 222 | ${ns_cmd} ip route get "${dst}" |
Stefano Brivio | d1f1b9c | 2018-03-06 22:16:27 +0100 | [diff] [blame] | 223 | } |
| 224 | |
| 225 | route_get_dst_pmtu_from_exception() { |
Stefano Brivio | 822d2f8 | 2018-03-17 02:31:39 +0100 | [diff] [blame] | 226 | ns_cmd="${1}" |
| 227 | dst="${2}" |
Stefano Brivio | d1f1b9c | 2018-03-06 22:16:27 +0100 | [diff] [blame] | 228 | |
Stefano Brivio | f2c929f | 2018-03-17 02:31:40 +0100 | [diff] [blame] | 229 | mtu_parse "$(route_get_dst_exception "${ns_cmd}" ${dst})" |
Stefano Brivio | d1f1b9c | 2018-03-06 22:16:27 +0100 | [diff] [blame] | 230 | } |
| 231 | |
Stefano Brivio | 1e0a7207 | 2018-10-08 14:37:03 +0200 | [diff] [blame^] | 232 | check_pmtu_value() { |
| 233 | expected="${1}" |
| 234 | value="${2}" |
| 235 | event="${3}" |
| 236 | |
| 237 | [ "${expected}" = "any" ] && [ -n "${value}" ] && return 0 |
| 238 | [ "${value}" = "${expected}" ] && return 0 |
| 239 | [ -z "${value}" ] && err " PMTU exception wasn't created after ${event}" && return 1 |
| 240 | [ -z "${expected}" ] && err " PMTU exception shouldn't exist after ${event}" && return 1 |
| 241 | err " found PMTU exception with incorrect MTU ${value}, expected ${expected}, after ${event}" |
| 242 | return 1 |
| 243 | } |
| 244 | |
Stefano Brivio | 5e84430 | 2018-03-17 02:31:44 +0100 | [diff] [blame] | 245 | test_pmtu_vti4_exception() { |
| 246 | setup namespaces veth vti4 xfrm4 || return 2 |
| 247 | |
| 248 | veth_mtu=1500 |
| 249 | vti_mtu=$((veth_mtu - 20)) |
| 250 | |
| 251 | # SPI SN IV ICV pad length next header |
| 252 | esp_payload_rfc4106=$((vti_mtu - 4 - 4 - 8 - 16 - 1 - 1)) |
| 253 | ping_payload=$((esp_payload_rfc4106 - 28)) |
| 254 | |
| 255 | mtu "${ns_a}" veth_a ${veth_mtu} |
| 256 | mtu "${ns_b}" veth_b ${veth_mtu} |
| 257 | mtu "${ns_a}" vti4_a ${vti_mtu} |
| 258 | mtu "${ns_b}" vti4_b ${vti_mtu} |
| 259 | |
| 260 | # Send DF packet without exceeding link layer MTU, check that no |
| 261 | # exception is created |
| 262 | ${ns_a} ping -q -M want -i 0.1 -w 2 -s ${ping_payload} ${vti4_b_addr} > /dev/null |
| 263 | pmtu="$(route_get_dst_pmtu_from_exception "${ns_a}" ${vti4_b_addr})" |
Stefano Brivio | 1e0a7207 | 2018-10-08 14:37:03 +0200 | [diff] [blame^] | 264 | check_pmtu_value "" "${pmtu}" "sending packet smaller than PMTU (IP payload length ${esp_payload_rfc4106})" || return 1 |
Stefano Brivio | 5e84430 | 2018-03-17 02:31:44 +0100 | [diff] [blame] | 265 | |
| 266 | # Now exceed link layer MTU by one byte, check that exception is created |
Stefano Brivio | 1e0a7207 | 2018-10-08 14:37:03 +0200 | [diff] [blame^] | 267 | # with the right PMTU value |
Stefano Brivio | 5e84430 | 2018-03-17 02:31:44 +0100 | [diff] [blame] | 268 | ${ns_a} ping -q -M want -i 0.1 -w 2 -s $((ping_payload + 1)) ${vti4_b_addr} > /dev/null |
| 269 | pmtu="$(route_get_dst_pmtu_from_exception "${ns_a}" ${vti4_b_addr})" |
Stefano Brivio | 1e0a7207 | 2018-10-08 14:37:03 +0200 | [diff] [blame^] | 270 | check_pmtu_value "${esp_payload_rfc4106}" "${pmtu}" "exceeding PMTU (IP payload length $((esp_payload_rfc4106 + 1)))" |
Stefano Brivio | 5e84430 | 2018-03-17 02:31:44 +0100 | [diff] [blame] | 271 | } |
| 272 | |
Stefano Brivio | d1f1b9c | 2018-03-06 22:16:27 +0100 | [diff] [blame] | 273 | test_pmtu_vti6_exception() { |
Stefano Brivio | 5e84430 | 2018-03-17 02:31:44 +0100 | [diff] [blame] | 274 | setup namespaces veth vti6 xfrm6 || return 2 |
Stefano Brivio | 36455bd | 2018-03-17 02:31:41 +0100 | [diff] [blame] | 275 | fail=0 |
Stefano Brivio | d1f1b9c | 2018-03-06 22:16:27 +0100 | [diff] [blame] | 276 | |
| 277 | # Create route exception by exceeding link layer MTU |
| 278 | mtu "${ns_a}" veth_a 4000 |
| 279 | mtu "${ns_b}" veth_b 4000 |
Stefano Brivio | a41c789 | 2018-03-17 02:31:42 +0100 | [diff] [blame] | 280 | mtu "${ns_a}" vti6_a 5000 |
| 281 | mtu "${ns_b}" vti6_b 5000 |
Sabrina Dubroca | c81c701 | 2018-08-30 16:01:18 +0200 | [diff] [blame] | 282 | ${ns_a} ${ping6} -q -i 0.1 -w 2 -s 60000 ${vti6_b_addr} > /dev/null |
Stefano Brivio | d1f1b9c | 2018-03-06 22:16:27 +0100 | [diff] [blame] | 283 | |
| 284 | # Check that exception was created |
Stefano Brivio | 1e0a7207 | 2018-10-08 14:37:03 +0200 | [diff] [blame^] | 285 | pmtu="$(route_get_dst_pmtu_from_exception "${ns_a}" ${vti6_b_addr})" |
| 286 | check_pmtu_value any "${pmtu}" "creating tunnel exceeding link layer MTU" || return 1 |
Stefano Brivio | d1f1b9c | 2018-03-06 22:16:27 +0100 | [diff] [blame] | 287 | |
| 288 | # Decrease tunnel MTU, check for PMTU decrease in route exception |
Stefano Brivio | a41c789 | 2018-03-17 02:31:42 +0100 | [diff] [blame] | 289 | mtu "${ns_a}" vti6_a 3000 |
Stefano Brivio | 1e0a7207 | 2018-10-08 14:37:03 +0200 | [diff] [blame^] | 290 | pmtu="$(route_get_dst_pmtu_from_exception "${ns_a}" ${vti6_b_addr})" |
| 291 | check_pmtu_value "3000" "${pmtu}" "decreasing tunnel MTU" || fail=1 |
Stefano Brivio | d1f1b9c | 2018-03-06 22:16:27 +0100 | [diff] [blame] | 292 | |
| 293 | # Increase tunnel MTU, check for PMTU increase in route exception |
Stefano Brivio | a41c789 | 2018-03-17 02:31:42 +0100 | [diff] [blame] | 294 | mtu "${ns_a}" vti6_a 9000 |
Stefano Brivio | 1e0a7207 | 2018-10-08 14:37:03 +0200 | [diff] [blame^] | 295 | pmtu="$(route_get_dst_pmtu_from_exception "${ns_a}" ${vti6_b_addr})" |
| 296 | check_pmtu_value "9000" "${pmtu}" "increasing tunnel MTU" || fail=1 |
Stefano Brivio | d1f1b9c | 2018-03-06 22:16:27 +0100 | [diff] [blame] | 297 | |
Stefano Brivio | 36455bd | 2018-03-17 02:31:41 +0100 | [diff] [blame] | 298 | return ${fail} |
Stefano Brivio | d1f1b9c | 2018-03-06 22:16:27 +0100 | [diff] [blame] | 299 | } |
| 300 | |
Stefano Brivio | a41c789 | 2018-03-17 02:31:42 +0100 | [diff] [blame] | 301 | test_pmtu_vti4_default_mtu() { |
| 302 | setup namespaces veth vti4 || return 2 |
| 303 | |
| 304 | # Check that MTU of vti device is MTU of veth minus IPv4 header length |
| 305 | veth_mtu="$(link_get_mtu "${ns_a}" veth_a)" |
| 306 | vti4_mtu="$(link_get_mtu "${ns_a}" vti4_a)" |
| 307 | if [ $((veth_mtu - vti4_mtu)) -ne 20 ]; then |
| 308 | err " vti MTU ${vti4_mtu} is not veth MTU ${veth_mtu} minus IPv4 header length" |
| 309 | return 1 |
| 310 | fi |
| 311 | } |
| 312 | |
Stefano Brivio | 35b4942 | 2018-03-17 02:31:43 +0100 | [diff] [blame] | 313 | test_pmtu_vti6_default_mtu() { |
| 314 | setup namespaces veth vti6 || return 2 |
| 315 | |
| 316 | # Check that MTU of vti device is MTU of veth minus IPv6 header length |
| 317 | veth_mtu="$(link_get_mtu "${ns_a}" veth_a)" |
| 318 | vti6_mtu="$(link_get_mtu "${ns_a}" vti6_a)" |
| 319 | if [ $((veth_mtu - vti6_mtu)) -ne 40 ]; then |
| 320 | err " vti MTU ${vti6_mtu} is not veth MTU ${veth_mtu} minus IPv6 header length" |
| 321 | return 1 |
| 322 | fi |
| 323 | } |
| 324 | |
Stefano Brivio | 719e121 | 2018-03-17 02:31:45 +0100 | [diff] [blame] | 325 | test_pmtu_vti4_link_add_mtu() { |
| 326 | setup namespaces || return 2 |
| 327 | |
| 328 | ${ns_a} ip link add vti4_a type vti local ${veth4_a_addr} remote ${veth4_b_addr} key 10 |
| 329 | [ $? -ne 0 ] && err " vti not supported" && return 2 |
| 330 | ${ns_a} ip link del vti4_a |
| 331 | |
| 332 | fail=0 |
| 333 | |
| 334 | min=68 |
Sabrina Dubroca | 902b541 | 2018-08-30 16:01:17 +0200 | [diff] [blame] | 335 | max=$((65535 - 20)) |
Stefano Brivio | 719e121 | 2018-03-17 02:31:45 +0100 | [diff] [blame] | 336 | # Check invalid values first |
| 337 | for v in $((min - 1)) $((max + 1)); do |
| 338 | ${ns_a} ip link add vti4_a mtu ${v} type vti local ${veth4_a_addr} remote ${veth4_b_addr} key 10 2>/dev/null |
| 339 | # This can fail, or MTU can be adjusted to a proper value |
| 340 | [ $? -ne 0 ] && continue |
| 341 | mtu="$(link_get_mtu "${ns_a}" vti4_a)" |
| 342 | if [ ${mtu} -lt ${min} -o ${mtu} -gt ${max} ]; then |
| 343 | err " vti tunnel created with invalid MTU ${mtu}" |
| 344 | fail=1 |
| 345 | fi |
| 346 | ${ns_a} ip link del vti4_a |
| 347 | done |
| 348 | |
| 349 | # Now check valid values |
| 350 | for v in ${min} 1300 ${max}; do |
| 351 | ${ns_a} ip link add vti4_a mtu ${v} type vti local ${veth4_a_addr} remote ${veth4_b_addr} key 10 |
| 352 | mtu="$(link_get_mtu "${ns_a}" vti4_a)" |
| 353 | ${ns_a} ip link del vti4_a |
| 354 | if [ "${mtu}" != "${v}" ]; then |
| 355 | err " vti MTU ${mtu} doesn't match configured value ${v}" |
| 356 | fail=1 |
| 357 | fi |
| 358 | done |
| 359 | |
| 360 | return ${fail} |
| 361 | } |
| 362 | |
Stefano Brivio | 8b6022f | 2018-03-17 02:31:46 +0100 | [diff] [blame] | 363 | test_pmtu_vti6_link_add_mtu() { |
| 364 | setup namespaces || return 2 |
| 365 | |
| 366 | ${ns_a} ip link add vti6_a type vti6 local ${veth6_a_addr} remote ${veth6_b_addr} key 10 |
| 367 | [ $? -ne 0 ] && err " vti6 not supported" && return 2 |
| 368 | ${ns_a} ip link del vti6_a |
| 369 | |
| 370 | fail=0 |
| 371 | |
Stefano Brivio | 5a643c8 | 2018-04-26 19:41:02 +0200 | [diff] [blame] | 372 | min=68 # vti6 can carry IPv4 packets too |
Stefano Brivio | 8b6022f | 2018-03-17 02:31:46 +0100 | [diff] [blame] | 373 | max=$((65535 - 40)) |
| 374 | # Check invalid values first |
| 375 | for v in $((min - 1)) $((max + 1)); do |
| 376 | ${ns_a} ip link add vti6_a mtu ${v} type vti6 local ${veth6_a_addr} remote ${veth6_b_addr} key 10 2>/dev/null |
| 377 | # This can fail, or MTU can be adjusted to a proper value |
| 378 | [ $? -ne 0 ] && continue |
| 379 | mtu="$(link_get_mtu "${ns_a}" vti6_a)" |
| 380 | if [ ${mtu} -lt ${min} -o ${mtu} -gt ${max} ]; then |
| 381 | err " vti6 tunnel created with invalid MTU ${v}" |
| 382 | fail=1 |
| 383 | fi |
| 384 | ${ns_a} ip link del vti6_a |
| 385 | done |
| 386 | |
| 387 | # Now check valid values |
Stefano Brivio | 5a643c8 | 2018-04-26 19:41:02 +0200 | [diff] [blame] | 388 | for v in 68 1280 1300 $((65535 - 40)); do |
Stefano Brivio | 8b6022f | 2018-03-17 02:31:46 +0100 | [diff] [blame] | 389 | ${ns_a} ip link add vti6_a mtu ${v} type vti6 local ${veth6_a_addr} remote ${veth6_b_addr} key 10 |
| 390 | mtu="$(link_get_mtu "${ns_a}" vti6_a)" |
| 391 | ${ns_a} ip link del vti6_a |
| 392 | if [ "${mtu}" != "${v}" ]; then |
| 393 | err " vti6 MTU ${mtu} doesn't match configured value ${v}" |
| 394 | fail=1 |
| 395 | fi |
| 396 | done |
| 397 | |
| 398 | return ${fail} |
| 399 | } |
| 400 | |
Stefano Brivio | 1fad59e | 2018-03-17 02:31:47 +0100 | [diff] [blame] | 401 | test_pmtu_vti6_link_change_mtu() { |
| 402 | setup namespaces || return 2 |
| 403 | |
| 404 | ${ns_a} ip link add dummy0 mtu 1500 type dummy |
| 405 | [ $? -ne 0 ] && err " dummy not supported" && return 2 |
| 406 | ${ns_a} ip link add dummy1 mtu 3000 type dummy |
| 407 | ${ns_a} ip link set dummy0 up |
| 408 | ${ns_a} ip link set dummy1 up |
| 409 | |
| 410 | ${ns_a} ip addr add ${dummy6_0_addr}/${dummy6_mask} dev dummy0 |
| 411 | ${ns_a} ip addr add ${dummy6_1_addr}/${dummy6_mask} dev dummy1 |
| 412 | |
| 413 | fail=0 |
| 414 | |
| 415 | # Create vti6 interface bound to device, passing MTU, check it |
| 416 | ${ns_a} ip link add vti6_a mtu 1300 type vti6 remote ${dummy6_0_addr} local ${dummy6_0_addr} |
| 417 | mtu="$(link_get_mtu "${ns_a}" vti6_a)" |
| 418 | if [ ${mtu} -ne 1300 ]; then |
| 419 | err " vti6 MTU ${mtu} doesn't match configured value 1300" |
| 420 | fail=1 |
| 421 | fi |
| 422 | |
| 423 | # Move to another device with different MTU, without passing MTU, check |
| 424 | # MTU is adjusted |
Stefano Brivio | 1fad59e | 2018-03-17 02:31:47 +0100 | [diff] [blame] | 425 | ${ns_a} ip link set vti6_a type vti6 remote ${dummy6_1_addr} local ${dummy6_1_addr} |
| 426 | mtu="$(link_get_mtu "${ns_a}" vti6_a)" |
| 427 | if [ ${mtu} -ne $((3000 - 40)) ]; then |
| 428 | err " vti MTU ${mtu} is not dummy MTU 3000 minus IPv6 header length" |
| 429 | fail=1 |
| 430 | fi |
| 431 | |
| 432 | # Move it back, passing MTU, check MTU is not overridden |
Stefano Brivio | 1fad59e | 2018-03-17 02:31:47 +0100 | [diff] [blame] | 433 | ${ns_a} ip link set vti6_a mtu 1280 type vti6 remote ${dummy6_0_addr} local ${dummy6_0_addr} |
| 434 | mtu="$(link_get_mtu "${ns_a}" vti6_a)" |
| 435 | if [ ${mtu} -ne 1280 ]; then |
| 436 | err " vti6 MTU ${mtu} doesn't match configured value 1280" |
| 437 | fail=1 |
| 438 | fi |
| 439 | |
| 440 | return ${fail} |
| 441 | } |
| 442 | |
Stefano Brivio | d1f1b9c | 2018-03-06 22:16:27 +0100 | [diff] [blame] | 443 | trap cleanup EXIT |
| 444 | |
Stefano Brivio | 36455bd | 2018-03-17 02:31:41 +0100 | [diff] [blame] | 445 | exitcode=0 |
| 446 | desc=0 |
| 447 | IFS=" |
| 448 | " |
| 449 | for t in ${tests}; do |
| 450 | [ $desc -eq 0 ] && name="${t}" && desc=1 && continue || desc=0 |
Stefano Brivio | d1f1b9c | 2018-03-06 22:16:27 +0100 | [diff] [blame] | 451 | |
Stefano Brivio | 36455bd | 2018-03-17 02:31:41 +0100 | [diff] [blame] | 452 | ( |
| 453 | unset IFS |
| 454 | eval test_${name} |
| 455 | ret=$? |
| 456 | cleanup |
| 457 | |
| 458 | if [ $ret -eq 0 ]; then |
| 459 | printf "TEST: %-60s [ OK ]\n" "${t}" |
| 460 | elif [ $ret -eq 1 ]; then |
| 461 | printf "TEST: %-60s [FAIL]\n" "${t}" |
| 462 | err_flush |
| 463 | exit 1 |
| 464 | elif [ $ret -eq 2 ]; then |
| 465 | printf "TEST: %-60s [SKIP]\n" "${t}" |
| 466 | err_flush |
| 467 | fi |
| 468 | ) |
| 469 | [ $? -ne 0 ] && exitcode=1 |
| 470 | done |
| 471 | |
| 472 | exit ${exitcode} |