Skip to content

IPv6: per-probe sockets on FreeBSD/NetBSD; remove the inter-probe delay (#12) - #98

Merged
lance0 merged 2 commits into
masterfrom
fix/ipv6-per-probe-bsd
Jun 27, 2026
Merged

lance0 merged 2 commits into
masterfrom
fix/ipv6-per-probe-bsd

Conversation

@lance0

@lance0 lance0 commented Jun 27, 2026

Copy link
Copy Markdown
Owner

Summary

Completes the #12 send-path work on the IPv6 side. IPv4 is already race-free via IP_HDRINCL (#97); this extends the per-probe send-socket strategy — previously macOS-only — to FreeBSD and NetBSD for IPv6, so a fast BSD host can no longer collapse an IPv6 trace to a single hop. There is no IPv4-style IP_HDRINCL for IPv6, so sending each probe from a fresh socket (one datagram, one hop limit) is the deterministic fix.

With this, every send path is deterministic by construction — IPv4 via IP_HDRINCL, IPv6 via per-probe sockets on all BSD-derived platforms — so the interim 500µs delay is removed.

What changed

  • build.rs defines a per_probe_send cfg (macOS/FreeBSD/NetBSD) as the single source of truth for "platforms whose async sendto needs a fresh socket per probe." It replaces the scattered cfg(target_os = "macos") gates in run_icmp/run_udp/run_tcp and the UDP SO_REUSEADDR gate. Linux is excluded — its sendto never exhibited the race — and keeps one shared socket.
  • IPv6 on FreeBSD/NetBSD now uses per-probe sockets (the same proven path macOS already used): ICMP/TCP via a fresh raw socket per probe, UDP via a fresh socket re-bound to the flow's source port (with SO_REUSEADDR for rapid re-bind).
  • Removed the 500µs apply_rate_limit floor. No path needs it anymore; only the explicit --rate delay remains. apply_rate_limit_explicit is folded back into apply_rate_limit.
  • Comments/CHANGELOG/ROADMAP updated; the --source-ip fail-fast bind and correlation behavior are unchanged.

Validation

  • ✅ Linux (per_probe_send off → shared path, unchanged): build, clippy --all-targets -D warnings, fmt, 227 tests.
  • ✅ BSD path type-checked locally by forcing RUSTFLAGS='--cfg per_probe_send' — the FreeBSD/NetBSD per-probe blocks compile and lint clean against the cross-platform socket APIs.
  • ✅ CI build/clippy on macOS + FreeBSD compiles and lints the per_probe_send path on those real toolchains; the FreeBSD job also runs the existing privileged raw-socket runtime test, confirming raw sends work in that environment.
  • ⏳ Recommended pre-merge check: a live IPv6 trace on a FreeBSD (and ideally NetBSD) host — the per-probe IPv6 path is a cfg extension of the proven macOS path, but a real IPv6 trace is the final confirmation. I couldn't runtime-test IPv6 loopback reliably in CI VMs without risking false failures.

Notes

This is the last of the three pre-release send-path follow-ups; the ROADMAP section is now fully checked off. Ready for review — not auto-merged.

…ay floor

Extend the per-probe send-socket strategy (previously macOS-only) to FreeBSD and
NetBSD for the IPv6 path, so a fast BSD host can no longer collapse an IPv6 trace
to a single hop the way macOS could (issue #12). There is no IPv4-style
IP_HDRINCL for IPv6, so a fresh socket per probe is the deterministic fix.

The platform set is now a single source of truth: a new build.rs defines the
`per_probe_send` cfg (macOS/FreeBSD/NetBSD), replacing the scattered
cfg(target_os = "macos") gates in run_icmp/run_udp/run_tcp and the UDP
SO_REUSEADDR gate. Linux keeps one shared socket (its sendto never raced).

With IPv4 on IP_HDRINCL and IPv6 per-probe across all BSD-derived platforms,
every send path is deterministic by construction, so the 500us apply_rate_limit
floor is removed entirely; only the explicit --rate delay remains, and
apply_rate_limit_explicit is folded back into apply_rate_limit.

Validation: builds + clippy -D warnings on Linux (per_probe_send off) and with
per_probe_send forced on (type-checks the BSD path locally); 227 unit tests
pass; FreeBSD/macOS CI build+clippy+the raw-socket runtime test cover the
per_probe_send platforms. A live IPv6 trace on FreeBSD/NetBSD is the recommended
pre-release check.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR completes the IPv6 send-path fix for issue #12 by extending the per-probe socket strategy (previously macOS-only) to FreeBSD/NetBSD, and removes the interim 500µs inter-probe delay now that all send paths are intended to be deterministic.

Changes:

  • Introduces a per_probe_send cfg (macOS/FreeBSD/NetBSD) to gate per-probe socket creation for IPv6 sends.
  • Updates the IPv6 ICMP/UDP/TCP loops to use per-probe sockets under per_probe_send, and removes the 500µs platform floor from apply_rate_limit.
  • Updates UDP socket binding behavior (SO_REUSEADDR) and documentation (ROADMAP/CHANGELOG) to reflect the new strategy.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
src/trace/engine.rs Switches IPv6 send loops to per_probe_send per-probe sockets and removes the old 500µs floor delay.
src/probe/udp.rs Gates SO_REUSEADDR on per_probe_send to support rapid per-probe port rebinds.
build.rs Adds build-script-defined per_probe_send cfg intended to be the single source of truth for per-probe send platforms.
ROADMAP.md Marks the IPv6 determinism work and delay removal as completed.
CHANGELOG.md Documents deterministic send behavior across IPv4 (HDRINCL) and IPv6 (per-probe sockets on BSD-derived platforms) and the removal of the 500µs delay.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread build.rs
Comment on lines +11 to +15
println!("cargo::rustc-check-cfg=cfg(per_probe_send)");
let target_os = std::env::var("CARGO_CFG_TARGET_OS").unwrap_or_default();
if matches!(target_os.as_str(), "macos" | "freebsd" | "netbsd") {
println!("cargo::rustc-cfg=per_probe_send");
}
The IPv6 PMTUD probe still sends on the shared ICMP socket (a single isolated
probe per round, so not subject to the back-to-back stale-TTL race). Reword the
CHANGELOG and ROADMAP so "deterministic / race-free" describes the rapid probe
sweeps rather than literally every send.
@lance0
lance0 merged commit 1aef07f into master Jun 27, 2026
5 checks passed
@lance0
lance0 deleted the fix/ipv6-per-probe-bsd branch June 27, 2026 14:23
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.

2 participants