Skip to content

Share one ICMP echo ID allocator between probers and tracers - #85

Merged
servak merged 3 commits into
mainfrom
feature/icmp-id-allocator
Nov 8, 2026
Merged

servak merged 3 commits into
mainfrom
feature/icmp-id-allocator

Conversation

@servak

@servak servak commented Nov 8, 2026

Copy link
Copy Markdown
Owner

Summary

  • Add internal/icmpid: a process-wide echo ID allocator (one random 16-bit base chosen once, a counter, used-set + Release). It never returns 0 and guarantees distinct IDs for up to 65535 concurrently held allocations; when walking past the end it wraps around, skipping held IDs. A released ID is only reused after the counter wraps, so late replies to a stopped tracer do not hit a new holder. If all 65535 are held, a duplicate is returned (documented, unreachable in practice).
  • internal/prober/icmp.go: probers acquire their echo ID from the allocator and release it when the socket is closed (closeConn, once). Private echoIDs/echoIDBase/nextEchoID removed.
  • internal/trace/transport_icmp.go: the ICMP transport acquires its ID from the allocator and releases it on close (once) or when no socket can be opened. Private idBase/idCounter/echoID (and the obsolete pid avoidance) removed. The Linux datagram-socket path still disables checkID, since the kernel rewrites the ID.

Previously the prober and tracer each had their own random base + counter, so they could collide within one process, and tracer churn (restart on every target change) could wrap into IDs of live probers.

Tests

  • internal/icmpid: never 0 (including across the 0 boundary), all 65535 IDs distinct, exhaustion, wraparound skips held IDs under heavy churn, released IDs not reused before wrap, concurrent acquire/release (-race), global functions.
  • prober: prober IDs and interleaved tracer allocations are disjoint; Stop releases.
  • trace: transport ID is held in the shared allocator, never handed out again while open, released on close (skips without an ICMP socket).

go build/go vet (darwin, linux, windows), go test -race ./..., go test -tags integration ./internal/trace/... ./internal/prober/... (unprivileged), golangci-lint run all pass.

Add internal/icmpid, a process-wide allocator with one random 16-bit
base, a counter that skips 0 and IDs still held, and Release. The ICMP
prober and the path tracer's ICMP transport now draw their echo IDs from
it instead of private counters, so live probers and tracers in one
process never share an ID, and tracer restarts cannot wrap into IDs of
running probers. IDs are released when the socket is closed.
@servak
servak merged commit 5ecbc04 into main Nov 8, 2026
5 checks passed
@servak
servak deleted the feature/icmp-id-allocator branch November 8, 2026 07:43
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