fix(pep): resolve a named endpoint over a bound socket - #99
Merged
Conversation
`--local-address` exists so the outer path bypasses a host TUN route, and netbind.InterfaceControl asserts that with IP_BOUND_IF so a transparent proxy honouring NEAppProxyFlow.isBound leaves those sockets alone. That covers the sockets this client creates. It did not cover the ones the resolver creates on its behalf: net.Dialer applies LocalAddr and Control to the connection it dials, never to the lookup that turns the endpoint name into the address it dials to, and dialQUICConnection went through net.ResolveUDPAddr, which is the default resolver outright. So a client bound to a physical interface still asked that one question over an unbound socket. On a host whose transparent proxy redirects port 53 into this very client, the question cannot be answered: the name has to resolve before the datapath exists, and the datapath has to exist before the name resolves. Both transports then fail with `no such host` and the provider never comes up. netbind.ResolverFor builds a resolver whose own sockets carry the same binding, and both lane paths use it for the endpoint name. PreferGo is required or the cgo resolver answers inside libSystem and the binding is silently dropped; the scope is kept to the endpoint lookup for that reason, since the pure resolver reads /etc/resolv.conf rather than the platform's configuration. A literal endpoint needs no lookup and keeps the path it had. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01MHr1RSawjHAuUBJwK63vxE
…already did Both dial paths resolve the local-address spec to build the socket's own binding, and resolving an "auto" or "if:NAME" spec enumerates the host's interfaces. Calling netbind.ResolverFor afterwards repeated that on every connection, which is worst exactly where this matters: a client with --local-address set, opening and replacing lanes. netbind.ResolverForResult takes what the caller already has, and both paths pass it. Behaviour is unchanged, and an unset --local-address still never constructs a resolver at all. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01MHr1RSawjHAuUBJwK63vxE
Merged
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.
What was wrong
--local-addressexists so the outer path bypasses a host TUN route, andnetbind.InterfaceControlasserts that at the kernel level withIP_BOUND_IF— which is what makesNEAppProxyFlow.isBoundtrue, so a transparent proxy honouring it leaves those sockets alone.That covers the sockets this client creates. It did not cover the ones the resolver creates on its behalf.
net.DialerappliesLocalAddrandControlto the connection it dials, never to the lookup that turns the endpoint name into the address it dials to — anddialQUICConnectionusednet.ResolveUDPAddr, which is the default resolver outright.So a client bound to a physical interface still asked that one question over an unbound socket.
Why it is fatal rather than untidy
On a host whose transparent proxy redirects port 53, that unbound question is claimed and sent to the proxy — which, when this client is the proxy's upstream, is this client. The name has to resolve before the datapath exists, and the datapath has to exist before the name resolves.
Observed on a live host: a provider whose endpoint is
<name>:12540loggedlookup <name>: no such hoston both transports 25,365 times in 67 minutes and never came up. Its lane sockets were fine the whole time — 20,162 of them went out direct underbypass:bound-interface, exactly as designed. Only the lookup leaked.The fix
netbind.ResolverFor(spec, control)returns a resolver whose own sockets carry the same interface binding and source address as a data socket built forspec. Both lane paths use it for the endpoint name: the TCP dialer vianet.Dialer.Resolver, and the QUIC path via a newresolveUDPAddrBound.Two deliberate limits:
PreferGois required or the cgo resolver answers inside libSystem and never callsDial, silently dropping the binding. That has a cost — the pure resolver reads/etc/resolv.confrather than the platform's own configuration — which is why the scope is the endpoint lookup rather than a process-wide resolver. A gateway endpoint is a public name reached over a specific interface, the lookup least likely to want split-horizon rules.A literal endpoint address needs no lookup and takes the same path it always did.
Tests
New:
internal/netbind/resolver_test.go(default resolver when unbound, error propagation, the dial actually leaving from the bound address, and family matching);internal/pep/resolve_test.go(literal fast path for v4 and v6, malformed endpoint, and an unusable local address surfacing as itself rather than as a lookup failure).go vetandstaticcheck -checks=all,-U1000clean on both packages.Note:
go test -short -race ./...locally times out ininternal/feconTestTheWindowRateIsWhatTheWindowNeeds(~10m under the race detector). That is pre-existing and unreachable from these packages —go list -deps ./internal/feccontains neithernetbindnorpep— and is not the combination CI runs.🤖 Generated with Claude Code
https://claude.ai/code/session_01MHr1RSawjHAuUBJwK63vxE