Fix: tun2socks not lookup IP
This commit is contained in:
parent
2500169447
commit
09f6cd2ec4
3 changed files with 9 additions and 5 deletions
|
@ -50,7 +50,3 @@ func (m *Metadata) String() string {
|
||||||
func (m *Metadata) Valid() bool {
|
func (m *Metadata) Valid() bool {
|
||||||
return m.Host != "" || m.IP != nil
|
return m.Host != "" || m.IP != nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *Metadata) NeedLoopUpHost() bool {
|
|
||||||
return m.Source == REDIR
|
|
||||||
}
|
|
||||||
|
|
|
@ -219,6 +219,10 @@ func (r *Resolver) resolve(client []*nameserver, msg *D.Msg) <-chan *result {
|
||||||
return ch
|
return ch
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (r *Resolver) IsMapping() bool {
|
||||||
|
return r.mapping
|
||||||
|
}
|
||||||
|
|
||||||
type NameServer struct {
|
type NameServer struct {
|
||||||
Net string
|
Net string
|
||||||
Addr string
|
Addr string
|
||||||
|
|
|
@ -107,11 +107,15 @@ func (t *Tunnel) resolveIP(host string) (net.IP, error) {
|
||||||
return t.resolver.ResolveIP(host)
|
return t.resolver.ResolveIP(host)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (t *Tunnel) needLookupIP() bool {
|
||||||
|
return t.hasResolver() && t.resolver.IsMapping()
|
||||||
|
}
|
||||||
|
|
||||||
func (t *Tunnel) handleConn(localConn C.ServerAdapter) {
|
func (t *Tunnel) handleConn(localConn C.ServerAdapter) {
|
||||||
defer localConn.Close()
|
defer localConn.Close()
|
||||||
metadata := localConn.Metadata()
|
metadata := localConn.Metadata()
|
||||||
|
|
||||||
if metadata.NeedLoopUpHost() && t.hasResolver() {
|
if t.needLookupIP() {
|
||||||
host, exist := t.resolver.IPToHost(*metadata.IP)
|
host, exist := t.resolver.IPToHost(*metadata.IP)
|
||||||
if exist {
|
if exist {
|
||||||
metadata.Host = host
|
metadata.Host = host
|
||||||
|
|
Loading…
Reference in a new issue