Skip to content

feat: automatic fake TTL and TTL-range candidates - #7

Merged
Nemu-x merged 3 commits into
mainfrom
feat/auto-ttl
Oct 29, 2026
Merged

Nemu-x merged 3 commits into
mainfrom
feat/auto-ttl

Conversation

@Nemu-x

@Nemu-x Nemu-x commented Oct 29, 2026

Copy link
Copy Markdown
Owner

Automatic TTL for the fake prefix, where an OS lets an unprivileged TCP socket see the server's hop limit, and TTL-range candidates for discovery everywhere else.

observes the server's hop limit how
Linux / Android, IPv6 ✓ IPV6_RECVHOPLIMIT before connect, then getsockopt(IPV6_2292PKTOPTIONS) returns the SYN-ACK's hop limit (net/ipv6/tcp_ipv6.c, ipv6_sockglue.c)
Linux, IPv4 ✗ IP_PKTOPTIONS is filled only on accepted sockets (tcp_v4_syn_recv_sock); IP_RECVTTL is datagram-only
macOS ✗ xnu TCP never saves received control data; IPV6_2292PKTOPTIONS returns nothing (source reading only)
Windows ✗ IP_RECVTTL / WSARecvMsg are datagram/raw only; TCP_INFO_v1 has no TTL
d := net.Dialer{Control: desync.ControlAutoTTL} // enables the observation where it exists
raw, _ := d.Dial("tcp", "[2001:db8::1]:443")
c := desync.WrapConn(raw, desync.Options{Fake: &desync.FakeOptions{AutoTTL: &desync.AutoTTL{}, TTL: 4}}) // TTL 4 is the fallback
cands, _ := desync.FakeTTLCandidates(desync.Options{Fake: &desync.FakeOptions{Prefix: -1}}, 2, 8)       // one option set per TTL
  • AutoTTL{Delta, Min, Max} (defaults 1, 3, 20): fake TTL = hops − Delta, clamped, never ≥ hops. Hops from the observed TTL against the initial values 64/128/255 (EstimateHops; ambiguous values are reported). This is zapret's --dpi-desync-autottl logic (MIT, credited in third_party/); ByeDPI has no auto TTL.
  • With TTL == 0 auto is mandatory (ErrAutoTTLUnsupported / ErrAutoTTLUnobserved); with TTL > 0 that value is the fallback.
  • ObserveHops(conn) reads without changing anything; (*Conn).FakeTTL() tells which TTL was used and whether it was derived. Capabilities.AutoTTL plus reasons in Unsupported.
  • FakeTTLCandidates / UDPTTLCandidates: stable, distinct keys (at most 64) for the controller to probe. UDPOptions.Key() is new. The UDP burst has no auto TTL: it is sent before the peer's first reply.
  • Key() adds ,auto:D:min-max only when set; the existing fixed-TTL key is pinned in a test.
  • Linux/386 goes through socketcall; a 32-bit process on a 64-bit kernel gets 64-bit control headers on this IPv6 path, the parser reads both.

Tests: EstimateHops table, validation, keys; on Linux (Docker, IPv6) server hop limits 120/61/250/64 read as 8/3/5/0 hops, 80 reported ambiguous, updates on later data, unobserved without ControlAutoTTL, unsupported on IPv4; end to end the fake goes out with the derived TTL 7, the low-hop BPF filter drops it and the stream arrives through retransmission. Checks: gofmt; vet windows/linux/darwin on Go 1.26.10 and 1.20.14 (also linux/386, s390x, arm); tests on Windows (both Go) and Linux in Docker as root (1.26.9 -race, 1.20, GOARCH=386). Not verified: real networks (asymmetric routes and CDNs can skew the estimate), macOS runtime, Android devices. No desync-socks flags yet.

FakeOptions.AutoTTL (delta/min/max, zapret's --dpi-desync-autottl) sets the
fake's TTL from the hop count estimated from the server's SYN-ACK, with
Fake.TTL as an optional fallback. Linux/Android IPv6 records the hop limit
with IPV6_RECVHOPLIMIT (enabled before connect by ControlAutoTTL) and
returns it through IPV6_2292PKTOPTIONS. Linux IPv4, Windows and macOS keep
no received TTL for TCP sockets and are reported in
PlatformCapabilities().AutoTTL and Unsupported with the reason.
FakeTTLCandidates and UDPTTLCandidates return one option set per TTL with a
stable Key, so discovery can probe the TTL where the path cannot be
observed. UDPOptions gains Key.
@Nemu-x
Nemu-x merged commit 941d5b7 into main Oct 29, 2026
19 checks passed
@Nemu-x
Nemu-x deleted the feat/auto-ttl branch October 29, 2026 17:40
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