Skip to content

PMTUD DF cleanup, PMTUD tick lock, and UDP header-only ICMP quotes - #176

Merged
lance0 merged 4 commits into
masterfrom
fix/pmtud-and-short-udp-quotes
Nov 14, 2026
Merged

lance0 merged 4 commits into
masterfrom
fix/pmtud-and-short-udp-quotes

Conversation

@lance0

@lance0 lance0 commented Nov 13, 2026 •

Copy link
Copy Markdown
Owner

Three items deferred from #171: PMTUD Don't Fragment handling, the PMTUD per-tick write lock, and UDP quotes that contain only the transport header.

UDP replies that quote only the 8-byte UDP header

Symptom. RFC 792 only requires a router to quote the IP header plus 8 bytes of the original datagram. For a UDP probe that is the UDP header alone. The probe id lives in the payload (sequence plus TTL magic), so every UDP parser required at least 14 bytes past the IP header and dropped these replies. The hop showed as a timeout. This affected IPv4 raw, IPv4 DGRAM and IPv6.

Fix. The quoted UDP checksum still covers the payload. Every other byte it covers is known: the pseudo-header from the quoted IP header, the ports and length from the quoted UDP header, and the fixed payload pattern for that length. The one's-complement sum is linear, so sequence = ~quoted_checksum +' checksum(sequence = 0). The result is checked by recomputing the checksum, and against any payload bytes the router did quote. Quotes with 14 bytes or more still go through the existing magic-byte path unchanged. A quoted checksum of 0 (IPv4 "no checksum") is rejected.

Known limit (marked with a ponytail: comment). A short quote has no magic bytes, so a header-only quote of another program's UDP also decodes to some sequence. It is credited only if it matches a pending probe. With one target and a source port outside ttl's flow range, the receiver's fallbacks leave the sequence as the only filter, so the chance is roughly the number of in-flight probes out of 65536 per stray quote. A stray quote whose destination is a target is also logged as a late reply in recordings. A per-run payload nonce, or checking the quoted destination port against the decoded TTL, would close that gap if it ever matters. RFC 4884 routers that pad a short quote to 128 bytes with zeros are still dropped, because the magic check sees zeros there.

PMTUD left IPV6_DONTFRAG on the shared send socket

Verified on master.

  • IPv4: not affected. The PMTUD probe sets DF in its hand-built IP_HDRINCL header and ordinary probes do not (see the live check below).
  • macOS, FreeBSD, NetBSD: not affected. Ordinary IPv6 probes use per-probe sockets.
  • Linux and Windows: affected. Ordinary IPv6 probes share the socket the PMTUD probe uses, and set_dont_fragment was never undone, so every ordinary probe after the first PMTUD probe went out with IPV6_DONTFRAG=1. In practice the impact was small: IPv6 has no on-wire DF bit, and --size conflicts with --pmtud, so ordinary probes stay small. It was still state leaking into probes that never asked for it.

Fix. set_dont_fragment now takes an on/off flag on every platform. send_pmtud_probe_icmp clears the flag right after the send, on both the success and error paths. The clear is limited to cfg(not(per_probe_send)), so the BSDs keep their current behavior and are not exposed to their asynchronous-send behavior.

PMTUD write-locked the session every tick

check_pmtud_ready took state.write() every tick, even when only reading the phase or with no destination yet. Each write guard bumps render_generation. The tick's own sent counters also write, so the visible cost was small, but the check now reads first and takes the write lock only for the WaitingForDestination to Searching transition. It rechecks dest_ttl and the phase under the write lock in case a stats reset ran in between.

Tests (each fails on the pre-fix code)

  • probe::correlate::tests::udp_quote_of_header_only_correlates: builds real probes with build_udp_payload_sized, using build_udp_datagram for IPv4 and a kernel-style checksum for IPv6. It covers payload lengths 8, 32, 33 (odd) and 1472, and ProbeIds including (1,0) and (255,255). It quotes only the 8-byte header and parses via IPv4 raw, IPv4 DGRAM and IPv6. On master it panics at the first case (dropped).
  • trace::engine::tests::check_pmtud_ready_writes_only_on_phase_change: render_generation must not move for no-destination, Searching or Complete, and the search must still start. On master it fails with "WaitingForDestination took a write lock".
  • trace::engine::tests::pmtud_probe_leaves_shared_socket_without_dontfrag (Linux): an unprivileged IPv6 UDP socket stands in for the shared socket, and getsockopt(IPV6_DONTFRAG) must be 0 after a PMTUD send. Without the clear it fails with "IPV6_DONTFRAG left set on the shared send socket".
  • The Windows Don't Fragment readback test now also checks that clearing reads back 0 (Windows CI only).

Live check (Docker, NET_RAW, master vs branch release builds, --pmtud -c 10 -i 0.3)

IPv4 to 1.1.1.1, tcpdump of outgoing echo requests (identical on master and branch, so IPv4 was not affected):

2 DF   len=1500   (PMTUD probes)
102 none len=84   (ordinary probes)

IPv6 to 2606:4700:4700::1111, strace -e setsockopt:

master: 9 x SOL_IPV6, IPV6_DONTFRAG, [1]   (never cleared)
branch: 9 x SOL_IPV6, IPV6_DONTFRAG, [1]
        9 x SOL_IPV6, IPV6_DONTFRAG, [0]

The IPv6 --pmtud --json results are the same on both builds (dest_ttl 8, same search bounds).

Gates

cargo fmt --check, cargo clippy --all-targets -- -D warnings, the same with --no-default-features, the same with RUSTFLAGS='--cfg per_probe_send', RUSTDOCFLAGS=-D warnings cargo doc, and cargo test (all passing).

Not verified here

  • The short-quote path against a real router that quotes only 8 bytes. It is covered by unit tests only.
  • The macOS, FreeBSD, NetBSD and Windows builds of the set_dont_fragment signature change. They cannot be cross-compiled locally (C dependencies), so CI is the check. NetBSD has no CI runner, and its change is a one-line on flag.

RFC 792 only requires routers to quote 8 bytes past the IP header, which
for a UDP probe is the header alone, without the payload carrying the
probe id. Those replies were dropped. Recover the sequence from the quoted
UDP checksum instead: every other byte it covers is known, and the
one's-complement sum is linear in the sequence word.
On Linux and Windows ordinary IPv6 probes share the PMTUD probe's send
socket, and the DONTFRAG option set for the size probe stayed on for
them. set_dont_fragment now takes an on/off flag and the PMTUD send
clears it again where the socket is shared.

The per-tick PMTUD readiness check took the session write lock (which
bumps the TUI render generation) just to read the phase; it now reads
first and writes only when the search starts.
@lance0
lance0 marked this pull request as ready for review November 14, 2026 20:25
@lance0
lance0 merged commit 11abf11 into master Nov 14, 2026
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant