mirror of
https://github.com/DNSCrypt/dnscrypt-proxy.git
synced 2025-03-04 02:14:40 +01:00
Try dnscrypt-proxy to resolve configured hosts when ignore_system_dns (#2204)
This commit is contained in:
parent
ca0f353087
commit
b3318a94b7
4 changed files with 40 additions and 12 deletions
|
@ -258,7 +258,15 @@ cert_refresh_delay = 240
|
|||
bootstrap_resolvers = ['9.9.9.11:53', '8.8.8.8:53']
|
||||
|
||||
|
||||
## Always use the bootstrap resolver before the system DNS settings.
|
||||
## This is a switch for prior bootstrap resolvers.
|
||||
##
|
||||
## Most of the time, the system DNS leads to dnscrypt-proxy itself,
|
||||
## if you set up dnscrypt-proxy in the system DNS chain.
|
||||
##
|
||||
## If true, dnscrypt-proxy will directly try on its own service instead.
|
||||
## Together with bootstrap resolvers, upstream hosts will be resolved most
|
||||
## of the time.
|
||||
## The system DNS still will be a last resort, if it has been ignored.
|
||||
|
||||
ignore_system_dns = true
|
||||
|
||||
|
|
|
@ -242,6 +242,8 @@ func (proxy *Proxy) StartProxy() {
|
|||
dlog.Fatal(err)
|
||||
}
|
||||
}
|
||||
proxy.xTransport.internalResolverReady = false
|
||||
proxy.xTransport.internalResolvers = proxy.listenAddresses
|
||||
liveServers, err := proxy.serversInfo.refresh(proxy)
|
||||
if liveServers > 0 {
|
||||
proxy.certIgnoreTimestamp = false
|
||||
|
|
|
@ -232,6 +232,7 @@ func (serversInfo *ServersInfo) refresh(proxy *Proxy) (int, error) {
|
|||
for _, registeredServer := range registeredServers {
|
||||
if err = serversInfo.refreshServer(proxy, registeredServer.name, registeredServer.stamp); err == nil {
|
||||
liveServers++
|
||||
proxy.xTransport.internalResolverReady = true
|
||||
}
|
||||
}
|
||||
serversInfo.Lock()
|
||||
|
|
|
@ -61,6 +61,8 @@ type XTransport struct {
|
|||
timeout time.Duration
|
||||
cachedIPs CachedIPs
|
||||
altSupport AltSupport
|
||||
internalResolvers []string
|
||||
internalResolverReady bool
|
||||
bootstrapResolvers []string
|
||||
mainProto string
|
||||
ignoreSystemDNS bool
|
||||
|
@ -371,16 +373,17 @@ func (xTransport *XTransport) resolveUsingResolvers(
|
|||
proto, host string,
|
||||
resolvers []string,
|
||||
) (ip net.IP, ttl time.Duration, err error) {
|
||||
err = errors.New("Empty resolvers")
|
||||
for i, resolver := range resolvers {
|
||||
ip, ttl, err = xTransport.resolveUsingResolver(proto, host, resolver)
|
||||
if err == nil {
|
||||
if i > 0 {
|
||||
dlog.Infof("Resolution succeeded with bootstrap resolver %s[%s]", proto, resolver)
|
||||
dlog.Infof("Resolution succeeded with resolver %s[%s]", proto, resolver)
|
||||
resolvers[0], resolvers[i] = resolvers[i], resolvers[0]
|
||||
}
|
||||
break
|
||||
}
|
||||
dlog.Infof("Unable to resolve [%s] using bootstrap resolver %s[%s]: %v", host, proto, resolver, err)
|
||||
dlog.Infof("Unable to resolve [%s] using resolver %s[%s]: %v", host, proto, resolver, err)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
@ -400,23 +403,37 @@ func (xTransport *XTransport) resolveAndUpdateCache(host string) error {
|
|||
var foundIP net.IP
|
||||
var ttl time.Duration
|
||||
var err error
|
||||
if !xTransport.ignoreSystemDNS {
|
||||
foundIP, ttl, err = xTransport.resolveUsingSystem(host)
|
||||
protos := []string{"udp", "tcp"}
|
||||
if xTransport.mainProto == "tcp" {
|
||||
protos = []string{"tcp", "udp"}
|
||||
}
|
||||
if xTransport.ignoreSystemDNS || err != nil {
|
||||
protos := []string{"udp", "tcp"}
|
||||
if xTransport.mainProto == "tcp" {
|
||||
protos = []string{"tcp", "udp"}
|
||||
if xTransport.ignoreSystemDNS {
|
||||
if xTransport.internalResolverReady {
|
||||
for _, proto := range protos {
|
||||
foundIP, ttl, err = xTransport.resolveUsingResolvers(proto, host, xTransport.internalResolvers)
|
||||
if err == nil {
|
||||
break
|
||||
}
|
||||
}
|
||||
} else {
|
||||
err = errors.New("Service is not usable yet")
|
||||
dlog.Noticef("%s", err)
|
||||
}
|
||||
} else {
|
||||
foundIP, ttl, err = xTransport.resolveUsingSystem(host)
|
||||
if err != nil {
|
||||
err = errors.New("System DNS is not usable yet")
|
||||
dlog.Noticef("%s", err)
|
||||
}
|
||||
}
|
||||
if err != nil {
|
||||
for _, proto := range protos {
|
||||
if err != nil {
|
||||
dlog.Noticef(
|
||||
"System DNS configuration not usable yet, exceptionally resolving [%s] using bootstrap resolvers over %s",
|
||||
"Resolving server host [%s] using bootstrap resolvers over %s",
|
||||
host,
|
||||
proto,
|
||||
)
|
||||
} else {
|
||||
dlog.Debugf("Resolving [%s] using bootstrap resolvers over %s", host, proto)
|
||||
}
|
||||
foundIP, ttl, err = xTransport.resolveUsingResolvers(proto, host, xTransport.bootstrapResolvers)
|
||||
if err == nil {
|
||||
|
|
Loading…
Add table
Reference in a new issue