selftest: net: Test IPv4 PMTU exceptions with DSCP and ECN
Add two tests to pmtu.sh, for verifying that PMTU exceptions get properly created for routes that don't belong to the main table. A fib-rule based on the packet's DSCP field is used to jump to the correct table. ECN shouldn't interfere with this process, so each test has two components: one that only sets DSCP and one that sets both DSCP and ECN. One of the test triggers PMTU exceptions using ICMP Echo Requests, the other using UDP packets (to test different handlers in the kernel). A few adjustments are necessary in the rest of the script to allow policy routing scenarios: * Add global variable rt_table that allows setup_routing_*() to add routes to a specific routing table. By default rt_table is set to "main", so existing tests don't need to be modified. * Another global variable, policy_mark, is used to define which dsfield value is used for policy routing. This variable has no effect on tests that don't use policy routing. * The UDP version of the test uses socat. So cleanup() now also need to kill socat PIDs. * route_get_dst_pmtu_from_exception() and route_get_dst_exception() now take an optional third argument specifying the dsfield. If not specified, 0 is used, so existing users don't need to be modified. Signed-off-by: Guillaume Nault <gnault@redhat.com> Reviewed-by: David Ahern <dsahern@kernel.org> Signed-off-by: Jakub Kicinski <kuba@kernel.org>
This commit is contained in:
Родитель
544b4dd568
Коммит
ec730c3e1f
|
@ -26,6 +26,15 @@
|
|||
# - pmtu_ipv6
|
||||
# Same as pmtu_ipv4, except for locked PMTU tests, using IPv6
|
||||
#
|
||||
# - pmtu_ipv4_dscp_icmp_exception
|
||||
# Set up the same network topology as pmtu_ipv4, but use non-default
|
||||
# routing table in A. A fib-rule is used to jump to this routing table
|
||||
# based on DSCP. Send ICMPv4 packets with the expected DSCP value and
|
||||
# verify that ECN doesn't interfere with the creation of PMTU exceptions.
|
||||
#
|
||||
# - pmtu_ipv4_dscp_udp_exception
|
||||
# Same as pmtu_ipv4_dscp_icmp_exception, but use UDP instead of ICMP.
|
||||
#
|
||||
# - pmtu_ipv4_vxlan4_exception
|
||||
# Set up the same network topology as pmtu_ipv4, create a VXLAN tunnel
|
||||
# over IPv4 between A and B, routed via R1. On the link between R1 and B,
|
||||
|
@ -203,6 +212,8 @@ which ping6 > /dev/null 2>&1 && ping6=$(which ping6) || ping6=$(which ping)
|
|||
tests="
|
||||
pmtu_ipv4_exception ipv4: PMTU exceptions 1
|
||||
pmtu_ipv6_exception ipv6: PMTU exceptions 1
|
||||
pmtu_ipv4_dscp_icmp_exception ICMPv4 with DSCP and ECN: PMTU exceptions 1
|
||||
pmtu_ipv4_dscp_udp_exception UDPv4 with DSCP and ECN: PMTU exceptions 1
|
||||
pmtu_ipv4_vxlan4_exception IPv4 over vxlan4: PMTU exceptions 1
|
||||
pmtu_ipv6_vxlan4_exception IPv6 over vxlan4: PMTU exceptions 1
|
||||
pmtu_ipv4_vxlan6_exception IPv4 over vxlan6: PMTU exceptions 1
|
||||
|
@ -323,6 +334,9 @@ routes_nh="
|
|||
B 6 default 61
|
||||
"
|
||||
|
||||
policy_mark=0x04
|
||||
rt_table=main
|
||||
|
||||
veth4_a_addr="192.168.1.1"
|
||||
veth4_b_addr="192.168.1.2"
|
||||
veth4_c_addr="192.168.2.10"
|
||||
|
@ -346,6 +360,7 @@ dummy6_mask="64"
|
|||
err_buf=
|
||||
tcpdump_pids=
|
||||
nettest_pids=
|
||||
socat_pids=
|
||||
|
||||
err() {
|
||||
err_buf="${err_buf}${1}
|
||||
|
@ -723,7 +738,7 @@ setup_routing_old() {
|
|||
|
||||
ns_name="$(nsname ${ns})"
|
||||
|
||||
ip -n ${ns_name} route add ${addr} via ${gw}
|
||||
ip -n "${ns_name}" route add "${addr}" table "${rt_table}" via "${gw}"
|
||||
|
||||
ns=""; addr=""; gw=""
|
||||
done
|
||||
|
@ -753,7 +768,7 @@ setup_routing_new() {
|
|||
|
||||
ns_name="$(nsname ${ns})"
|
||||
|
||||
ip -n ${ns_name} -${fam} route add ${addr} nhid ${nhid}
|
||||
ip -n "${ns_name}" -"${fam}" route add "${addr}" table "${rt_table}" nhid "${nhid}"
|
||||
|
||||
ns=""; fam=""; addr=""; nhid=""
|
||||
done
|
||||
|
@ -798,6 +813,24 @@ setup_routing() {
|
|||
return 0
|
||||
}
|
||||
|
||||
setup_policy_routing() {
|
||||
setup_routing
|
||||
|
||||
ip -netns "${NS_A}" -4 rule add dsfield "${policy_mark}" \
|
||||
table "${rt_table}"
|
||||
|
||||
# Set the IPv4 Don't Fragment bit with tc, since socat doesn't seem to
|
||||
# have an option do to it.
|
||||
tc -netns "${NS_A}" qdisc replace dev veth_A-R1 root prio
|
||||
tc -netns "${NS_A}" qdisc replace dev veth_A-R2 root prio
|
||||
tc -netns "${NS_A}" filter add dev veth_A-R1 \
|
||||
protocol ipv4 flower ip_proto udp \
|
||||
action pedit ex munge ip df set 0x40 pipe csum ip and udp
|
||||
tc -netns "${NS_A}" filter add dev veth_A-R2 \
|
||||
protocol ipv4 flower ip_proto udp \
|
||||
action pedit ex munge ip df set 0x40 pipe csum ip and udp
|
||||
}
|
||||
|
||||
setup_bridge() {
|
||||
run_cmd ${ns_a} ip link add br0 type bridge || return $ksft_skip
|
||||
run_cmd ${ns_a} ip link set br0 up
|
||||
|
@ -903,6 +936,11 @@ cleanup() {
|
|||
done
|
||||
nettest_pids=
|
||||
|
||||
for pid in ${socat_pids}; do
|
||||
kill "${pid}"
|
||||
done
|
||||
socat_pids=
|
||||
|
||||
for n in ${NS_A} ${NS_B} ${NS_C} ${NS_R1} ${NS_R2}; do
|
||||
ip netns del ${n} 2> /dev/null
|
||||
done
|
||||
|
@ -950,15 +988,21 @@ link_get_mtu() {
|
|||
route_get_dst_exception() {
|
||||
ns_cmd="${1}"
|
||||
dst="${2}"
|
||||
dsfield="${3}"
|
||||
|
||||
${ns_cmd} ip route get "${dst}"
|
||||
if [ -z "${dsfield}" ]; then
|
||||
dsfield=0
|
||||
fi
|
||||
|
||||
${ns_cmd} ip route get "${dst}" dsfield "${dsfield}"
|
||||
}
|
||||
|
||||
route_get_dst_pmtu_from_exception() {
|
||||
ns_cmd="${1}"
|
||||
dst="${2}"
|
||||
dsfield="${3}"
|
||||
|
||||
mtu_parse "$(route_get_dst_exception "${ns_cmd}" ${dst})"
|
||||
mtu_parse "$(route_get_dst_exception "${ns_cmd}" "${dst}" "${dsfield}")"
|
||||
}
|
||||
|
||||
check_pmtu_value() {
|
||||
|
@ -1068,6 +1112,95 @@ test_pmtu_ipv6_exception() {
|
|||
test_pmtu_ipvX 6
|
||||
}
|
||||
|
||||
test_pmtu_ipv4_dscp_icmp_exception() {
|
||||
rt_table=100
|
||||
|
||||
setup namespaces policy_routing || return $ksft_skip
|
||||
trace "${ns_a}" veth_A-R1 "${ns_r1}" veth_R1-A \
|
||||
"${ns_r1}" veth_R1-B "${ns_b}" veth_B-R1 \
|
||||
"${ns_a}" veth_A-R2 "${ns_r2}" veth_R2-A \
|
||||
"${ns_r2}" veth_R2-B "${ns_b}" veth_B-R2
|
||||
|
||||
# Set up initial MTU values
|
||||
mtu "${ns_a}" veth_A-R1 2000
|
||||
mtu "${ns_r1}" veth_R1-A 2000
|
||||
mtu "${ns_r1}" veth_R1-B 1400
|
||||
mtu "${ns_b}" veth_B-R1 1400
|
||||
|
||||
mtu "${ns_a}" veth_A-R2 2000
|
||||
mtu "${ns_r2}" veth_R2-A 2000
|
||||
mtu "${ns_r2}" veth_R2-B 1500
|
||||
mtu "${ns_b}" veth_B-R2 1500
|
||||
|
||||
len=$((2000 - 20 - 8)) # Fills MTU of veth_A-R1
|
||||
|
||||
dst1="${prefix4}.${b_r1}.1"
|
||||
dst2="${prefix4}.${b_r2}.1"
|
||||
|
||||
# Create route exceptions
|
||||
dsfield=${policy_mark} # No ECN bit set (Not-ECT)
|
||||
run_cmd "${ns_a}" ping -q -M want -Q "${dsfield}" -c 1 -w 1 -s "${len}" "${dst1}"
|
||||
|
||||
dsfield=$(printf "%#x" $((policy_mark + 0x02))) # ECN=2 (ECT(0))
|
||||
run_cmd "${ns_a}" ping -q -M want -Q "${dsfield}" -c 1 -w 1 -s "${len}" "${dst2}"
|
||||
|
||||
# Check that exceptions have been created with the correct PMTU
|
||||
pmtu_1="$(route_get_dst_pmtu_from_exception "${ns_a}" "${dst1}" "${policy_mark}")"
|
||||
check_pmtu_value "1400" "${pmtu_1}" "exceeding MTU" || return 1
|
||||
|
||||
pmtu_2="$(route_get_dst_pmtu_from_exception "${ns_a}" "${dst2}" "${policy_mark}")"
|
||||
check_pmtu_value "1500" "${pmtu_2}" "exceeding MTU" || return 1
|
||||
}
|
||||
|
||||
test_pmtu_ipv4_dscp_udp_exception() {
|
||||
rt_table=100
|
||||
|
||||
if ! which socat > /dev/null 2>&1; then
|
||||
echo "'socat' command not found; skipping tests"
|
||||
return $ksft_skip
|
||||
fi
|
||||
|
||||
setup namespaces policy_routing || return $ksft_skip
|
||||
trace "${ns_a}" veth_A-R1 "${ns_r1}" veth_R1-A \
|
||||
"${ns_r1}" veth_R1-B "${ns_b}" veth_B-R1 \
|
||||
"${ns_a}" veth_A-R2 "${ns_r2}" veth_R2-A \
|
||||
"${ns_r2}" veth_R2-B "${ns_b}" veth_B-R2
|
||||
|
||||
# Set up initial MTU values
|
||||
mtu "${ns_a}" veth_A-R1 2000
|
||||
mtu "${ns_r1}" veth_R1-A 2000
|
||||
mtu "${ns_r1}" veth_R1-B 1400
|
||||
mtu "${ns_b}" veth_B-R1 1400
|
||||
|
||||
mtu "${ns_a}" veth_A-R2 2000
|
||||
mtu "${ns_r2}" veth_R2-A 2000
|
||||
mtu "${ns_r2}" veth_R2-B 1500
|
||||
mtu "${ns_b}" veth_B-R2 1500
|
||||
|
||||
len=$((2000 - 20 - 8)) # Fills MTU of veth_A-R1
|
||||
|
||||
dst1="${prefix4}.${b_r1}.1"
|
||||
dst2="${prefix4}.${b_r2}.1"
|
||||
|
||||
# Create route exceptions
|
||||
run_cmd_bg "${ns_b}" socat UDP-LISTEN:50000 OPEN:/dev/null,wronly=1
|
||||
socat_pids="${socat_pids} $!"
|
||||
|
||||
dsfield=${policy_mark} # No ECN bit set (Not-ECT)
|
||||
run_cmd "${ns_a}" socat OPEN:/dev/zero,rdonly=1,readbytes="${len}" \
|
||||
UDP:"${dst1}":50000,tos="${dsfield}"
|
||||
|
||||
dsfield=$(printf "%#x" $((policy_mark + 0x02))) # ECN=2 (ECT(0))
|
||||
run_cmd "${ns_a}" socat OPEN:/dev/zero,rdonly=1,readbytes="${len}" \
|
||||
UDP:"${dst2}":50000,tos="${dsfield}"
|
||||
|
||||
# Check that exceptions have been created with the correct PMTU
|
||||
pmtu_1="$(route_get_dst_pmtu_from_exception "${ns_a}" "${dst1}" "${policy_mark}")"
|
||||
check_pmtu_value "1400" "${pmtu_1}" "exceeding MTU" || return 1
|
||||
pmtu_2="$(route_get_dst_pmtu_from_exception "${ns_a}" "${dst2}" "${policy_mark}")"
|
||||
check_pmtu_value "1500" "${pmtu_2}" "exceeding MTU" || return 1
|
||||
}
|
||||
|
||||
test_pmtu_ipvX_over_vxlanY_or_geneveY_exception() {
|
||||
type=${1}
|
||||
family=${2}
|
||||
|
|
Загрузка…
Ссылка в новой задаче