Skip to content

Mark the destination reached on a Port Unreachable from the target - #180

Merged
lance0 merged 4 commits into
masterfrom
fix/udp-port-unreachable-destination
Nov 14, 2026
Merged

lance0 merged 4 commits into
masterfrom
fix/udp-port-unreachable-destination

Conversation

@lance0

@lance0 lance0 commented Nov 13, 2026 •

Copy link
Copy Markdown
Owner

Symptom

A live UDP trace never marks the destination reached. dest_ttl stays null, complete stays false, every TTL up to the max keeps being probed every round, and the TUI lists the target again at each hop past it (with the max_ttl=30 badge). On master this shows with -p udp against the LAN gateway: it is listed at hops 1, 2, 3 and further. Replay of the same session already ends the path at the first reply from the target, so live and replay disagree.

Root cause

The receiver's batch update (src/trace/receiver.rs) only set dest_ttl/complete on an ICMP Echo Reply from the target. A UDP probe that reaches the target draws a Port Unreachable (IPv4 type 3 code 3, IPv6 type 1 code 4), so the check never fired. Every protocol's ICMP replies go through that one check. The other places that set dest_ttl are replay (any reply from the target) and the engine's IPv6 Echo Reply poll, which handles only ICMP-mode Echo Replies from the target and is already correct.

Fix

is_destination_reply() counts an Echo Reply or a Destination Unreachable sent by the target itself as reaching the destination. The receiver uses it in place of the Echo-only check. These still do not count:

  • a Port Unreachable (or any reply) from an intermediate router: the responder must be the target;
  • Time Exceeded from the target;
  • Parameter Problem from the target. This keeps the earlier decision that it never marks the destination.

The engine already stops probing at dest_ttl, so once it is set, UDP stops probing past the destination the same way ICMP does. PMTUD runs only in ICMP mode and still confirms sizes only on Echo Replies from the target, so it is unchanged. The single-target DNAT tolerance in take_pending is untouched.

Replay is unchanged. Recorded events carry no ICMP type, so replay still ends the path at any reply from the target, including Time Exceeded or Parameter Problem; live is now the same for Echo Reply and Destination Unreachable and stricter for those two. For an ordinary UDP trace the target only sends Port Unreachable, so live and replay agree.

TCP is a separate gap and is not fixed here. The destination answers a SYN with SYN-ACK or RST over TCP, and ttl only reads ICMP, so a TCP trace still never marks the destination unless the target sends ICMP. Live results below confirm this. I added a note to KNOWN_ISSUES.md. Reading TCP replies would need a new receive path.

Tests

  • destination_reply_includes_port_unreachable_from_target, for IPv4 and IPv6. With the master predicate (Echo Reply only) swapped back in, it fails on the Port Unreachable assertion. It passes with the fix.
  • cargo fmt --check, cargo clippy --all-targets -- -D warnings, cargo clippy --all-targets --no-default-features -- -D warnings, cargo test: all pass.

Live before/after (Linux, Docker NET_RAW, -c 3 --json)

On this network, hops past the home gateway answer UDP probes only with the unmerged short-quote fix (#176). So the internet targets compare master+#176 against this branch+#176. The gateway rows use plain master and this branch.

Run master this branch
-p udp --flows 4 8.8.8.8 dest_ttl null, complete false, 360 probes sent dest_ttl 7, complete true, 176 sent
-p udp --flows 4 1.1.1.1 dest_ttl null, 360 sent dest_ttl 8, 184 sent
-p udp 2001:4860:4860::8888 dest_ttl null, 90 sent dest_ttl 7, 44 sent
-p udp LAN gateway (no #176) dest_ttl null, 90 sent dest_ttl 1, 32 sent
-p icmp 8.8.8.8 (control) dest_ttl 8, 46 sent dest_ttl 8, 46 sent
-p tcp 1.1.1.1 dest_ttl null, target never answers same (see TCP note above)

The sent counts match what a fixed path gives: all TTLs in round 1, then TTLs up to dest_ttl only. For example, 30×4 + 7×4×2 = 176. The JSON export still contains the round-1 rows past dest_ttl, as it already does for ICMP. The TUI, CSV and report cap at dest_ttl.

Not verified

  • macOS, FreeBSD and Windows live runs (the change is platform-independent receiver logic).
  • A UDP trace through a real destination NAT (VIP to backend) live.

A live trace only counted an ICMP Echo Reply as reaching the target, so
UDP probes, which the target answers with Port Unreachable, never set
dest_ttl or complete. Every TTL up to the maximum kept being probed and
the target was listed at each of them. Count a Destination Unreachable
sent by the target itself as the destination, matching replay.
@lance0
lance0 marked this pull request as ready for review November 14, 2026 20:49
@lance0
lance0 merged commit ce1a0cc 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