Repository navigation
Conversation
Every proxied connection to a hostname currently does a fresh LookupAddr, over the tunnel or via the system resolver. Add `CacheTTL` (seconds) to the [Resolve] section to cache successful lookups by hostname. - Unset or 0 keeps today's behaviour (no cache); negative or non-numeric values are rejected at config parse. - The raw answer is cached before shuffling and strategy selection, so per-request shuffling still spreads load across records. - Applies to both the tunnel and SystemDNS paths. Errors and empty answers are not cached. - Entries expire lazily on read; the map is capped at 1024 names and swept for expired entries when it reaches the cap. - The cache is a pointer on VirtualTun, so all copies share it. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
The HTTP proxy, SNI proxy and split-routing SOCKS5 dial tunnelled hosts with Tnet.Dial/DialContext, whose netstack-internal lookup bypasses VirtualTun.LookupAddr, so CacheTTL had no effect there. Add VirtualTun.tunnelDial, used by RoutedDial and routedSocks5Dial. With a cache and a non-literal host it resolves through the cache and dials each address in order (filtered by network family), mirroring netstack's loop. A nil cache, SystemDNS, IP literals and unparsable addresses use Tnet.DialContext unchanged. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Check the context before each address, share the remaining deadline across the addresses still to try (2s floor, capped at what remains), and return the first dial error rather than the last. Tidy the cache tests (close both net.Pipe ends, drop a pointer-copy test) and make the README coverage sentence precise. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
netstack's DialContext wraps these errors in &net.OpError{Op: "dial"}, so
callers that inspect the error type (or print it) see the same shape
whether or not the dial went through dialCached. Return the bare
ctx.Err() / context.DeadlineExceeded wrapped the same way.
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Without a DNS setting netstack has no DNS servers, so Tnet.DialContext on a hostname failed with "cannot marshal DNS message", and tunnelDial worked around it by skipping the cache. LookupAddr already uses the system resolver in that mode. Always go through dialCached with d.lookupAddr: the system resolver without DNS =, the tunnel's DNS otherwise. This makes HTTP/SNI hostname dials work without DNS =, applies CacheTTL in both modes, and keeps the cache consistent with LookupAddr, which uses the same function. dialCached no longer short-circuits on a nil cache: the nil cache looks the name up on every call, so IP literals and unparsable addresses are still the only addresses passed to dial unchanged. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Without a DNS setting, hostnames for tunnelled connections are resolved by the host's resolver outside the tunnel; say so next to the DNS option. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
parseResolveConfig built an empty ResolveConfig and copied ResolveStrategy from the key even when it was absent, so a [Resolve] section with only CacheTTL left the strategy empty. ResolveAddrWithContext then returned "no address found" for every name, breaking SOCKS5 and TCP tunnels. Default to "auto" when the key is missing, normalise the value to lower case, and return a parse error for anything other than auto, ipv4 or ipv6. Co-Authored-By: Claude Sonnet 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.
Summary
An opt-in DNS cache:
[Resolve] CacheTTL = <seconds>(unset or0keeps today's behaviour).Every proxied connection to a hostname currently does a fresh lookup, through the tunnel's
DNSservers (or the system resolver), which adds a tunnel round trip to each new connection. WithCacheTTL = 60, fresh-connection latency through the HTTP proxy dropped by about 150 ms in our testing against a remote WireGuard peer, matching a kernel-WireGuard client on the same link.ResolveStrategy, so per-request ordering still spreads load. The map is bounded (1024 names, expired entries swept).Tnet.Dial, which resolves inside netstack and never reachedLookupAddr. They now resolve through the cache and dial each address in order, matching netstack's own loop (family filter, per-address deadline split, first error returned, cancellation reported as*net.OpError).DNSset, tunnelled hostname dials on those paths failed withcannot marshal DNS message; they now resolve through the system resolver, as the SOCKS5 legacy path already did. The README notes that this resolves outside the tunnel.[Resolve]section withoutResolveStrategy(e.g. onlyCacheTTL) left the strategy empty instead ofauto, so the SOCKS5 legacy and TCP-tunnel resolvers found no address. It now defaults toauto, and unknown values are rejected at parse.Test plan
go test -race ./...,go vet ./...,gofmt -l ., golangci-lint (fork CI green).RoutedDialgoing through the cache, a real-netstack test with system DNS, andResolveStrategyparsing.🤖 Generated with Claude Code