Repository navigation
Share one ICMP echo ID allocator between probers and tracers - #85
Merged
Merged
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
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). PrivateechoIDs/echoIDBase/nextEchoIDremoved.internal/trace/transport_icmp.go: the ICMP transport acquires its ID from the allocator and releases it onclose(once) or when no socket can be opened. PrivateidBase/idCounter/echoID(and the obsolete pid avoidance) removed. The Linux datagram-socket path still disablescheckID, 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.Stopreleases.go build/go vet(darwin, linux, windows),go test -race ./...,go test -tags integration ./internal/trace/... ./internal/prober/...(unprivileged),golangci-lint runall pass.