feat(web): clamp IPv4 TTL / IPv6 hop limit on xtcp2's TCP listeners#61
Merged
Conversation
Adds an opt-in per-listener TTL / hop-limit clamp so xtcp2's replies can't travel far if the host is unexpectedly internet-exposed — the per-listener analogue of a host-level nftables TTL clamp, mirroring prometheus/exporter-toolkit#396. - New pkg/ipsockopt: a net.ListenConfig.Control that setsockopt IP_TTL / IPV6_UNICAST_HOPS on the listening socket (inherited by accepted conns). Returns nil when both are 0 (kernel default); swallows ENOPROTOOPT for the non-matching address family. - Config: ipv4_ttl (184) + ipv6_hop_limit (185) on XtcpConfig (0 = default, validated <= 255). Flags -ipv4Ttl / -ipv6HopLimit, env IPV4_TTL / IPV6_HOP_LIMIT. - Applied to BOTH host-exposed listeners: the Prometheus /metrics server (cmd/xtcp2 now net.Listen + srv.Serve instead of ListenAndServe) and the gRPC server (grpc_server.go). - Tests: pkg/ipsockopt binds real v4/v6 listeners and getsockopt-verifies the value; cmd/xtcp2 env + buildConfig cover the new knobs. Default 0 → no behavior change for existing deployments. Co-Authored-By: Claude Opus 4.8 <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.
Summary
Adds an opt-in per-listener IPv4 TTL / IPv6 hop-limit clamp on xtcp2's own TCP listeners, so their replies can't travel far if the host is unexpectedly internet-exposed. It's the per-listener analogue of a host-level nftables TTL clamp, and mirrors prometheus/exporter-toolkit#396.
What
pkg/ipsockopt— anet.ListenConfig.Controlcallback thatsetsockoptsIP_TTL/IPV6_UNICAST_HOPSon the listening socket (the kernel inherits it onto accepted connections). Returnsnilwhen both are 0 so the kernel default is kept; swallowsENOPROTOOPTfor the address family the option doesn't apply to.ipv4_ttl(184) +ipv6_hop_limit(185) onXtcpConfig—0= kernel default, validated<= 255. Flags-ipv4Ttl/-ipv6HopLimit, envIPV4_TTL/IPV6_HOP_LIMIT./metricsserver —cmd/xtcp2now doesnet.Listen+srv.Serve(instead ofsrv.ListenAndServe) so the option can be set on the socket before bind;grpc_server.go).Verification
Default
0→ no behavior change for existing deployments; the clamp only applies when a value is set. (Only TTL + hop-limit here; exporter-toolkit#396 also does DSCP, which I skipped as it's per-connection and not needed for this use case.)🤖 Generated with Claude Code