Skip to content

feat(web): clamp IPv4 TTL / IPv6 hop limit on xtcp2's TCP listeners#61

Merged
randomizedcoder merged 1 commit into
mainfrom
feat/listener-ip-ttl
Jul 9, 2026
Merged

feat(web): clamp IPv4 TTL / IPv6 hop limit on xtcp2's TCP listeners#61
randomizedcoder merged 1 commit into
mainfrom
feat/listener-ip-ttl

Conversation

@randomizedcoder

Copy link
Copy Markdown
Owner

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 — a net.ListenConfig.Control callback that setsockopts IP_TTL / IPV6_UNICAST_HOPS on the listening socket (the kernel inherits it onto accepted connections). Returns nil when both are 0 so the kernel default is kept; swallows ENOPROTOOPT for the address family the option doesn't apply to.
  • Config: ipv4_ttl (184) + ipv6_hop_limit (185) on XtcpConfig0 = kernel 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 does net.Listen + srv.Serve (instead of srv.ListenAndServe) so the option can be set on the socket before bind;
    • the gRPC server (grpc_server.go).

Verification

go test ./pkg/ipsockopt/         # binds real v4/v6 listeners, getsockopt-verifies TTL/hops
nix build .#xtcp2-s3parquet      # -help shows -ipv4Ttl / -ipv6HopLimit
nix build .#test-cmd-xtcp2       # env + buildConfig cover the new knobs
nix build .#test-go-flavor-s3parquet

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

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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant