Repository navigation
tcp: random ephemeral ports with TIME_WAIT quarantine - #196
Merged
Merged
Conversation
Fixes the five issues in doc/EPHEMERAL_PORT_ISSUES.md: 1. tcp_allocate_port() draws each port from global_csprng over 49152-65535 (up to 64 tries) instead of counting up from 49152 on every boot. No fallback: the CSPRNG fails closed and is up before any network bring-up. 2. The unreachable exhaustion check and its counter are gone. 3. Local-port-only collision check kept, now documented. 4. tcp_evict_oldest_time_wait() quarantines the evicted port for the rest of its 30 s; tcp_port_is_free() refuses quarantined ports. Random allocation would otherwise reuse it early. 5. tcp_connect() holds TCP_LOCK across state check, half-open count and allocation; an in_use CLOSED slot now holds its port. verify-tcp-ephemeral-port.sh (FAULT_INJECT `tcpport`) drives ten real connect cycles and a synthetic eviction. Mutation-checked: main's allocator, no quarantine check, and the CLOSED exception each FAIL. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.
Fixes the five issues recorded in
doc/EPHEMERAL_PORT_ISSUES.md(PR #195).tcp_allocate_port()uses RFC 6056 Algorithm 1: a per-connectionglobal_csprngdraw over 49152-65535, with up to 64 tries on collision. There is no sequential fallback.tcp_connect()holdsTCP_LOCKacross the state check, half-open count and allocation. An in_use CLOSED slot now holds its port.Test
New harness
verify/verify-tcp-ephemeral-port.sh(FAULT_INJECTtcpportcommand):main's allocator, verbatim (fail-first)evictedclosedThe
TCP_LOCKpart of #5 has no witness; the race it closes is a 1-in-16384 event.Regression (TCP harnesses)
main(0f03f03). Injected mcast frames never reach the guest (RX ring 0) on this host.🤖 Generated with Claude Code