mirror of
https://github.com/SagerNet/sing-box.git
synced 2025-06-13 21:54:13 +08:00
Improve fake-ip dual stack behavior
This commit is contained in:
parent
8d629ef323
commit
ec0fa4781f
@ -69,6 +69,7 @@ type Router struct {
|
||||
transportDomainStrategy map[dns.Transport]dns.DomainStrategy
|
||||
dnsReverseMapping *DNSReverseMapping
|
||||
fakeIPStore adapter.FakeIPStore
|
||||
fakeIPDualStack bool
|
||||
interfaceFinder myInterfaceFinder
|
||||
autoDetectInterface bool
|
||||
defaultInterface string
|
||||
@ -253,6 +254,7 @@ func NewRouter(
|
||||
inet6Range = fakeIPOptions.Inet6Range.Build()
|
||||
}
|
||||
router.fakeIPStore = fakeip.NewStore(router, router.logger, inet4Range, inet6Range)
|
||||
router.fakeIPDualStack = inet4Range.IsValid() && inet6Range.IsValid()
|
||||
}
|
||||
|
||||
usePlatformDefaultInterfaceMonitor := platformInterface != nil && platformInterface.UsePlatformDefaultInterfaceMonitor()
|
||||
|
@ -63,14 +63,14 @@ func (r *Router) matchDNS(ctx context.Context) (context.Context, dns.Transport,
|
||||
if domainStrategy, dsLoaded := r.transportDomainStrategy[transport]; dsLoaded {
|
||||
return ctx, transport, domainStrategy
|
||||
} else {
|
||||
return ctx, transport, r.defaultDomainStrategy
|
||||
return ctx, transport, dns.DomainStrategyAsIS
|
||||
}
|
||||
}
|
||||
}
|
||||
if domainStrategy, dsLoaded := r.transportDomainStrategy[r.defaultTransport]; dsLoaded {
|
||||
return ctx, r.defaultTransport, domainStrategy
|
||||
} else {
|
||||
return ctx, r.defaultTransport, r.defaultDomainStrategy
|
||||
return ctx, r.defaultTransport, dns.DomainStrategyAsIS
|
||||
}
|
||||
}
|
||||
|
||||
@ -128,6 +128,22 @@ func (r *Router) Lookup(ctx context.Context, domain string, strategy dns.DomainS
|
||||
if strategy == dns.DomainStrategyAsIS {
|
||||
strategy = transportStrategy
|
||||
}
|
||||
if strategy == dns.DomainStrategyAsIS {
|
||||
switch r.defaultDomainStrategy {
|
||||
case dns.DomainStrategyUseIPv4, dns.DomainStrategyUseIPv6:
|
||||
strategy = r.defaultDomainStrategy
|
||||
}
|
||||
}
|
||||
if strategy == dns.DomainStrategyAsIS && metadata.FakeIP && r.fakeIPDualStack {
|
||||
if metadata.IPVersion == 4 {
|
||||
strategy = dns.DomainStrategyUseIPv4
|
||||
} else if metadata.IPVersion == 6 {
|
||||
strategy = dns.DomainStrategyPreferIPv6
|
||||
}
|
||||
}
|
||||
if strategy == dns.DomainStrategyAsIS {
|
||||
strategy = r.defaultDomainStrategy
|
||||
}
|
||||
ctx, cancel := context.WithTimeout(ctx, C.DNSTimeout)
|
||||
defer cancel()
|
||||
addrs, err := r.dnsClient.Lookup(ctx, transport, domain, strategy)
|
||||
|
Loading…
x
Reference in New Issue
Block a user