fix(net): defer DNS resolution to final dialer to preserve domain in proxy chain

Commit 0522ae8 added inline DNS resolution (PreferGo: true) in Resolve(),
resolving domain names to IPs before routing. This caused the SOCKS5
connector to send CONNECT with ATYP=IPv4 instead of ATYP=domain, breaking
chains where the backend (e.g., ssh -D) cannot reach the gost-resolved IP.

Revert the DNS fallback in Resolve() — return the address unchanged so
the original hostname flows through the proxy chain. Instead, add
net.Resolver{PreferGo: true} to the TCP dialer in internal/net/dialer,
which resolves DNS at the point of actual TCP connection — still pure
Go (no cgo thread exhaustion) but after the proxy chain routing is done.

Also rename resovle.go → resolve.go (fix typo).

Fixes go-gost/gost#877
This commit is contained in:
ginuerzh
2026-06-25 11:02:36 +08:00
parent ec4791485c
commit 8fd5200bf1
3 changed files with 21 additions and 25 deletions
+1
View File
@@ -146,6 +146,7 @@ func (d *Dialer) dialOnce(ctx context.Context, network, addr, ifceName string, i
return nil, fmt.Errorf("dial: unsupported network %s", network)
}
netd := net.Dialer{
Resolver: &net.Resolver{PreferGo: true},
LocalAddr: ifAddr,
Control: func(network, address string, c syscall.RawConn) error {
return c.Control(func(fd uintptr) {