Repository navigation
feat(tools): socket options, bulk and close modes for tcp_client/tcp_server - #329
Merged
Merged
Conversation
…server (red) Table-driven, all four categories: sockopt ParseSize/Validate/Control on real loopback sockets, procnet state parsing, client and server flag parsing, bulk echo, close modes (TIME_WAIT, FIN_WAIT2, CLOSE_WAIT read back from /proc/net/tcp). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…server
- tools/internal/sockopt: -cong, -tos (IPV6_TCLASS too on v6), -priority,
-rcvbuf, -freebind, -transparent, -bindNoPort, set via Control before
connect/listen. ApplyConn sets them again on accepted sockets: sk_clone
zeroes sk_priority, and tcp_reflect_tos replaces the listener's TOS.
- tcp_client: -bulk SIZE, -close (TIME_WAIT), -halfclose (FIN_WAIT2);
flag parsing moves to parseFlags.
- tcp_server: -holdEOF keeps a connection after EOF (CLOSE_WAIT).
- tools/internal/procnet reads states from /proc/net/tcp{,6} for the tests.
- OCI entrypoint: TCP_CLIENT_ARGS / TCP_SERVER_ARGS.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
main fails checks.nix-fmt on the binaries inherit added in #324. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The first dial attempt's timeout was fixed at 1s. Longer than the kernel's SYN retries, it holds a SYN_SENT socket to a peer that never answers. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This was referenced Nov 25, 2026
Review: an 8 KiB echo is read once, the close finds data unread and resets, and no TIME_WAIT socket is left. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
clientOnce read once into a 3000-byte buffer, so an 8 KiB echo left data queued; -close then reset the socket instead of leaving it in TIME_WAIT. readEcho reads the full echo, discarding past the buffer. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A reused ephemeral port can carry an earlier test's TIME_WAIT socket, so TestCloseModes -count=5 saw two states on the client port. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… socket is not counted Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
# Conflicts: # nix/default.nix
# Conflicts: # CHANGELOG.md
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.
The golden microVM workload only makes idle ESTABLISHED loopback sockets with the default congestion algorithm, so many columns never get a value (congestion info, tos/tclass, class_id, sockopt, window scales, non-ESTABLISHED states). This gives
tcp_client/tcp_serverthe knobs a wider workload needs. No workload change here. Done test-first.Feature
tools/internal/sockopt, shared by both tools, set viaControlbefore connect/listen:-cong NAME(TCP_CONGESTION)-tos N(IP_TOS, plus IPV6_TCLASS on IPv6)-priority N(SO_PRIORITY;inet_diag_class_idfalls back to it)-rcvbuf SIZE(SO_RCVBUF; sets the window scale)-freebind,-transparent,-bindNoPort(theinet_diag_sockoptbits)ApplyConn):sk_clonezeroessk_priority(net/core/sock.c), and withnet.ipv4.tcp_reflect_tosthe child takes the SYN's TOS (net/ipv4/tcp_ipv4.c). The congestion algorithm is inheritedipv6_setsockopthands them toip_setsockopt), so only the traffic class differs by familytcp_client:-bulk SIZEsends that much and reads the echo back before the first message-closecloses after one exchange (TIME_WAIT)-halfcloseshuts down writing and holds the socket (FIN_WAIT2)-dialTimeout(was a fixed 1s): longer than the kernel's SYN retries, it holds a SYN_SENT socket to a peer that never answerstcp_server -holdEOFkeeps a connection after the client's EOF (CLOSE_WAIT)parseFlagsin both toolsTCP_CLIENT_ARGS/TCP_SERVER_ARGSto each half; one shared variable would hand client-only flags to the server inbothmodetools/internal/procnetreads TCP states from/proc/net/tcp{,6}for the testsTests
TestParseSize,TestValidate,TestControlApplied(real loopback sockets, getsockopt read-back),TestParseStates,TestStateString,TestParseClientFlags,TestParseServerFlags,TestBulk,TestCloseModes,TestHoldEOF(states read from/proc/net/tcp)-raceclean;-count=10three times cleantransparentrow checks the error when it lacks CAP_NET_ADMINaccepted_inheritsassumed a listener's TOS and priority reach accepted sockets; the kernel says otherwise (above), so it now pins that andaccepted_reappliedchecksApplyConn-rcvbuf 64KiBRed (tests commit, before the feature)
-dialTimeout, a second red/green pair:Review fixes (each red first)
-closeread the echo once into a 3000-byte buffer, so a longer echo stayed queued and the close reset the socket (no TIME_WAIT).clientOncenow reads the whole echo (readEcho), discarding past the buffer. Red,TestCloseModes/close_large_echo(8 KiB echo):procnet.Lookupmatched only the local port; at-count=5a reused ephemeral port still held an earlier row's TIME_WAIT socket (states [TIME_WAIT TIME_WAIT]). It now takes the remote port too (0 = any);TestParseStatesgainsremote_match,remote_no_match,remote_any,remote_badGreen
go test ./...and the nix checks (gofmt, go-vet, nix-fmt, lint-baseline, golangci ×3, redteam-lint, golden-records, test-fuzz-all) pass. Includes thenix/default.nixnixfmt commit from #326, since main failschecks.nix-fmt.🤖 Generated with Claude Code