Skip to content

Commit ec93518

Browse files
committed
Merge branch 'tunnels-fix-ipv4-pmtu-icmp-checksum'
Florian Westphal says: ==================== tunnels: fix ipv4 pmtu icmp checksum The checksum of the generated ipv4 icmp pmtud message is only correct if the skb that causes the icmp error generation is linear. Fix this and add a selftest for this. ==================== Link: https://lore.kernel.org/r/20230803152653.29535-1-fw@strlen.de Signed-off-by: Jakub Kicinski <kuba@kernel.org>
2 parents 8a98961 + 136a1b4 commit ec93518

File tree

2 files changed

+36
-1
lines changed

2 files changed

+36
-1
lines changed

net/ipv4/ip_tunnel_core.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ static int iptunnel_pmtud_build_icmp(struct sk_buff *skb, int mtu)
224224
.un.frag.__unused = 0,
225225
.un.frag.mtu = htons(mtu),
226226
};
227-
icmph->checksum = ip_compute_csum(icmph, len);
227+
icmph->checksum = csum_fold(skb_checksum(skb, 0, len, 0));
228228
skb_reset_transport_header(skb);
229229

230230
niph = skb_push(skb, sizeof(*niph));

tools/testing/selftests/net/pmtu.sh

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -361,6 +361,7 @@ err_buf=
361361
tcpdump_pids=
362362
nettest_pids=
363363
socat_pids=
364+
tmpoutfile=
364365

365366
err() {
366367
err_buf="${err_buf}${1}
@@ -951,6 +952,7 @@ cleanup() {
951952
ip link del veth_A-R1 2>/dev/null
952953
ovs-vsctl --if-exists del-port vxlan_a 2>/dev/null
953954
ovs-vsctl --if-exists del-br ovs_br0 2>/dev/null
955+
rm -f "$tmpoutfile"
954956
}
955957

956958
mtu() {
@@ -1328,6 +1330,39 @@ test_pmtu_ipvX_over_bridged_vxlanY_or_geneveY_exception() {
13281330
check_pmtu_value ${exp_mtu} "${pmtu}" "exceeding link layer MTU on bridged ${type} interface"
13291331
pmtu="$(route_get_dst_pmtu_from_exception "${ns_a}" ${dst})"
13301332
check_pmtu_value ${exp_mtu} "${pmtu}" "exceeding link layer MTU on locally bridged ${type} interface"
1333+
1334+
tmpoutfile=$(mktemp)
1335+
1336+
# Flush Exceptions, retry with TCP
1337+
run_cmd ${ns_a} ip route flush cached ${dst}
1338+
run_cmd ${ns_b} ip route flush cached ${dst}
1339+
run_cmd ${ns_c} ip route flush cached ${dst}
1340+
1341+
for target in "${ns_a}" "${ns_c}" ; do
1342+
if [ ${family} -eq 4 ]; then
1343+
TCPDST=TCP:${dst}:50000
1344+
else
1345+
TCPDST="TCP:[${dst}]:50000"
1346+
fi
1347+
${ns_b} socat -T 3 -u -6 TCP-LISTEN:50000 STDOUT > $tmpoutfile &
1348+
1349+
sleep 1
1350+
1351+
dd if=/dev/zero of=/dev/stdout status=none bs=1M count=1 | ${target} socat -T 3 -u STDIN $TCPDST,connect-timeout=3
1352+
1353+
size=$(du -sb $tmpoutfile)
1354+
size=${size%%/tmp/*}
1355+
1356+
[ $size -ne 1048576 ] && err "File size $size mismatches exepcted value in locally bridged vxlan test" && return 1
1357+
done
1358+
1359+
rm -f "$tmpoutfile"
1360+
1361+
# Check that exceptions were created
1362+
pmtu="$(route_get_dst_pmtu_from_exception "${ns_c}" ${dst})"
1363+
check_pmtu_value ${exp_mtu} "${pmtu}" "tcp: exceeding link layer MTU on bridged ${type} interface"
1364+
pmtu="$(route_get_dst_pmtu_from_exception "${ns_a}" ${dst})"
1365+
check_pmtu_value ${exp_mtu} "${pmtu}" "tcp exceeding link layer MTU on locally bridged ${type} interface"
13311366
}
13321367

13331368
test_pmtu_ipv4_br_vxlan4_exception() {

0 commit comments

Comments
 (0)