Repository navigation
fix(xtcp): collect IPv6 sockets (AF_INET6 dump), test-first - #320
Merged
Merged
Conversation
…ze, diff - pkg/goldenrec: every ParquetRow column in exactly one class (strict, presence, ordinal, address, port, volatile, host); Normalize, Scrub (Normalize-invariant) and Diff with a column filter, for FP-9 and FP-12. - cmd/xtcp2-golden: scrub, normalize, diff and check. - s3parquet-golden microVM flavor and nix run .#capture-golden-records: the production binary, 3 Docker containers, a named netns; keeps the second poll; metrics over a unix listener so no host TCP is recorded. - Fixture pkg/xtcp/testdata/golden/7_3_1 (23 rows, scrubbed); two independent captures normalize byte-identical. - checks.golden-records: the JSONL matches the Parquet, the scrub is clean, the manifest row count and the schema match. - Golden rows seed FuzzRowFromProto; protoFromRow round-trip test. - Plan doc: F0.5 done; F2 TODOs for AF_INET6 collection and the ambiguous nsid 0. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
xtcp2 sends one SOCK_DIAG_BY_FAMILY request, AF_INET, so the kernel never reports AF_INET6 sockets: pure IPv6, and every dual-stack socket (a Go listener on 0.0.0.0 or [::], its accepted connections). These tests pin the fix and fail on today's code, only on their IPv6 rows: - TestCreateNetLinkRequests: an AF_INET and an AF_INET6 request. - TestPollRequestsBothFamilies / TestPollEndWaitsForBothDumps: each namespace gets AF_INET, then AF_INET6 after the first DONE (a send during a dump is EBUSY); the poll ends after the second DONE. - TestDumpTrackerSharedBudget: -maxRecordsPerNetns spans both dumps. - TestRealDumpFamilies: a real sock_diag dump of loopback sockets. - TestListenAddress / TestDialAddress: the stress tools and IPv6. - TestIndexV4Mapped, TestDiscoveryV4Mapped (clickhouse local), TestNormalizeV4Mapped: a v4-mapped peer is the IPv4 peer. Seams only, behavior unchanged: createNetLinkRequests over dumpFamilies (AF_INET), listenTarget / dialTarget, decodeCandidate. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Test infrastructure for the IPv6 collection work: the stress tools built "host:port" with "%s:%d", so ::1 could not be used, and always used network "tcp". Now net.JoinHostPort, a -network flag (default tcp, unchanged) checked against the address family of -bind, -connect and -srcaddr, and a port range check. The stress image takes TCP_NETWORK. TestListenAddress and TestDialAddress pass. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
nix run .#microvm-x86_64-tcp-families boots the production binary over IPv4-only (tcp4), IPv6-only (tcp6) and dual-stack containers and an IPv6 named netns, keeps xtcp2's second poll as the golden capture does, and compares each unit's rows per inet_diag_msg_family with ss -4 / ss -6. The metric waits and the object fetch move from golden-capture.sh to golden-common.sh, shared by both. Red on this tree, as expected (xtcp2 dumps AF_INET only): v4_counts PASS fam-v4 v4=12/12 v6=0/0 v6_counts FAIL fam-v6 v4=0/0 v6=0/12 dual_counts FAIL fam-dual v4=4/4 v6=0/8 accepted-v4-mapped=0/4 netns_v6 FAIL fam-ns v4=0/0 v6=0/3 host_ns FAIL host v4=8/8 v6=0/1 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Each poll now sends every namespace's socket an AF_INET dump and, once its NLMSG_DONE is in, an AF_INET6 dump: the kernel answers a SOCK_DIAG_BY_FAMILY request only with its family's sockets, and a second request during a running dump gets EBUSY with no DONE. - createNetLinkRequests builds both; the AF_INET6 one differs only in sdiag_family. The gate builds each level for both families. - handleNetlinkerDone sends a socket's queued AF_INET6 dump and keeps the namespace counted, so poll_end waits for each namespace's last dump; a failed send ends the namespace; a timeout clears the queue. - Both dumps carry the poll's sequence number, so -maxDumpBytes and -maxRecordsPerNetns stay the namespace's share of a poll: the receiver restarts its budget at a new sequence number, not at every NLMSG_DONE. The cap tests' "next dump" rows now use the next poll's. TestCreateNetLinkRequests, TestPollRequestsBothFamilies, TestPollEndWaitsForBothDumps, TestDumpTrackerSharedBudget and TestRealDumpFamilies pass. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The gate sized each namespace's dump from /proc/net/sockstat, which counts only AF_INET TCP sockets. A namespace holding only IPv6 sockets looked empty and was skipped once the dump requests covered AF_INET6. - open /proc/thread-self/net/sockstat6 alongside sockstat per namespace and add its "TCP6: inuse" to the namespace's demand (tw is shared across families in sockstat, so it is not added twice) - a sockstat6 fd that is open but unreadable makes the namespace unknown (polled in full); a missing one adds nothing - fdsPerNetns with the gate on goes from 4 to 5 TestGateCountsIPv6 (v6_heavy, no_sockstat6, sockstat6_read_fails, v6_zero, tcp6_line_not_first) is new; it reaches the sockstat6 handle, so it does not build without this change. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
DeserializeInetDiagSockIDXTCP sliced the source and destination out of the netlink receive buffer. That buffer goes back to the pool once its packet is decoded and is reused for the next packet, while the record waits in the envelope for the poll's flush, so a record could carry a later socket's address. The tcp-families microVM caught it once a poll ran two dumps per namespace: AF_INET rows carried AF_INET6 bytes. - copy both addresses into buffers the record owns; a new record gets one 32-byte array for the pair - recycleRecord (flushEnvelope, the post-flush drop) resets a record for the pool but keeps those buffers, so a recycled record decodes its addresses without allocating TestSockIDXTCPOwnsAddresses failed before the copy (buffer_reused, family_switch). Benchmarks, 102k-socket dump, 1 netlinker: - aliasing (before): 24.9k allocs/dump, 106 ms - copy + Reset: 229k allocs/dump - copy + recycleRecord + shared array: 44.3k allocs/dump, 105 ms - BenchmarkDeserialize unchanged at 1 alloc/op Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A dual-stack (AF_INET6) socket talking to an IPv4 peer reports the peer as ::ffff:a.b.c.d. Stamp looked that up as-is, so once xtcp2 dumped AF_INET6 those rows were never attributed. Unmap before the route lookup. TestIndexV4Mapped failed before this change on mapped_matches_v4 and mapped_zero. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A dual-stack (AF_INET6) socket reports an IPv4 peer as ::ffff:a.b.c.d. With AF_INET6 now collected, discovery grouped those sockets apart from the AF_INET ones and reported the peer as an IPv6 /128, and analysis (matching the candidate's IPv4 hex) never measured them. - both queries derive peer_hex: a v4-mapped AF_INET6 destination becomes the IPv4 address left-aligned, as AF_INET rows store it - discovery groups and reports on peer_hex (family 2); analysis matches the candidate on it - the clickhouse-local tests share the table DDL and runner Red before: TestDiscoveryV4Mapped one_peer_one_candidate, mapped_zero, all_mapped; TestAnalysisV4Mapped v4_and_mapped, mapped_only. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
With AF_INET6 collected, a dual-stack socket's IPv4 peer appears as ::ffff:a.b.c.d. Normalize/Scrub treated that as any IPv6 address and mapped it into 2001:db8::/32, so the same peer got two unrelated numbers. - new addrMapped kind: numbered in the IPv4 sequence (by its unmapped address) and written as ::ffff:192.0.2.N - ::ffff:0.0.0.0 is kept like 0.0.0.0 (netip's IsUnspecified does not unmap; IsLoopback already does) - CheckScrubbed accepts ::ffff:192.0.2.0/120 Red before: TestNormalizeV4Mapped v4_mapped_doc, v4_mapped_zero. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
xtcp2 now dumps AF_INET6, so the Go servers' dual-stack listeners and the connections they accept are recorded. Compare each container's rows with ss -Htan (both families) instead of ss -4. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- golden fixture 7_3_1: 48 rows (was 23), 12 per container (4 AF_INET client ends, 8 AF_INET6 dual-stack listeners and accepted sockets), 3 in golden-ns, 9 on the host; two captures normalize byte-identical - CHANGELOG: IPv6 collection, the receive-buffer aliasing fix - nix/README: tcp-families check; golden notes for both families - plan doc: close the AF_INET6 TODOs Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…test - pollWith logs a failed send at debug instead of discarding it - TestSendNetlinkDumpRequest_errorPath asserts the error is returned - parseSockstat's line search loops on the TCP prefix (QF1006) 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.
xtcp2 only asked the kernel for
AF_INETsockets, so everyAF_INET6socket went unrecorded, including Go's dual-stack0.0.0.0listeners and their accepted connections. Done test-first.Includes #319's commits (the golden harness this builds on); the diff shrinks once #319 merges.
Fix
AF_INET, thenAF_INET6, on each namespace's netlink socket. TheAF_INET6dump is sent on the first DONE (a send mid-dump gets EBUSY), andpoll_endstill means every namespace finished.AF_UNSPECisn't possible (sock_diag.cdispatches on family)-maxDumpBytes/-maxRecordsPerNetnsare one budget across both dumpssockstat6(TCP6: inuse); 5 fds per namespace with the gate onrecycleRecordkeeps; 102k-socket dump 44k allocs (229k with a plain copy, 24k aliasing), same time::ffff:a.b.c.d) read as IPv4 in treatment attribution, discovery, analysis and golden scrubbingtools/tcp_server,tcp_client:-network tcp|tcp4|tcp6, IPv6 literals viaJoinHostPortTests
TestCreateNetLinkRequests,TestPollRequestsBothFamilies,TestPollEndWaitsForBothDumps,TestDumpTrackerSharedBudget,TestRealDumpFamilies(realNETLINK_SOCK_DIAG),TestGateCountsIPv6,TestSockIDXTCPOwnsAddresses,TestRecycleRecord, tool listen/dial tables,TestIndexV4Mapped,TestDiscoveryV4Mapped,TestAnalysisV4Mapped(clickhouse local),TestNormalizeV4Mappednix run .#microvm-x86_64-tcp-families: v4-only, v6-only, dual-stack containers and a v6 named netns, rows per family vsss -4/ss -6Red (tests commit, before the fix)
Green
(the first green run failed
family_mismatchwith 6 rows: the aliasing bug)Verified
xtcp2-golden diffcleanOVERALL_PASS), socket-scale (OVERALL_PASS)go test ./...; gofmt, go-vet, nix-fmt, lint-baseline, golangci quick/default/comprehensive, redteam-lint, golden-records, test-fuzz-all🤖 Generated with Claude Code