From 09f6cd2ec4afcac4ecbcbb93b16e0e63e86f8a7f Mon Sep 17 00:00:00 2001 From: gVisor bot Date: Mon, 11 Feb 2019 15:44:42 +0800 Subject: [PATCH] Fix: tun2socks not lookup IP --- constant/metadata.go | 4 ---- dns/client.go | 4 ++++ tunnel/tunnel.go | 6 +++++- 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/constant/metadata.go b/constant/metadata.go index 4a361dfb..4bb02885 100644 --- a/constant/metadata.go +++ b/constant/metadata.go @@ -50,7 +50,3 @@ func (m *Metadata) String() string { func (m *Metadata) Valid() bool { return m.Host != "" || m.IP != nil } - -func (m *Metadata) NeedLoopUpHost() bool { - return m.Source == REDIR -} diff --git a/dns/client.go b/dns/client.go index 29b4207c..cfae7b9f 100644 --- a/dns/client.go +++ b/dns/client.go @@ -219,6 +219,10 @@ func (r *Resolver) resolve(client []*nameserver, msg *D.Msg) <-chan *result { return ch } +func (r *Resolver) IsMapping() bool { + return r.mapping +} + type NameServer struct { Net string Addr string diff --git a/tunnel/tunnel.go b/tunnel/tunnel.go index 96920818..2663ca31 100644 --- a/tunnel/tunnel.go +++ b/tunnel/tunnel.go @@ -107,11 +107,15 @@ func (t *Tunnel) resolveIP(host string) (net.IP, error) { return t.resolver.ResolveIP(host) } +func (t *Tunnel) needLookupIP() bool { + return t.hasResolver() && t.resolver.IsMapping() +} + func (t *Tunnel) handleConn(localConn C.ServerAdapter) { defer localConn.Close() metadata := localConn.Metadata() - if metadata.NeedLoopUpHost() && t.hasResolver() { + if t.needLookupIP() { host, exist := t.resolver.IPToHost(*metadata.IP) if exist { metadata.Host = host