mirror of
https://github.com/Control-D-Inc/ctrld.git
synced 2026-07-04 01:07:49 +02:00
Using ControlD bootstrap DNS again
So on system where there's no available DNS, non-ControlD upstreams could be bootstrapped like before. While at it, also improving lookupIP to not initializing OS resolver anymore, removing the un-necessary contention for accquiring/releasing OS resolver mutex.
This commit is contained in:
committed by
Cuong Manh Le
parent
8d6ea91f35
commit
0c2cc00c4f
+11
-12
@@ -466,27 +466,26 @@ func (d dummyResolver) Resolve(ctx context.Context, msg *dns.Msg) (*dns.Msg, err
|
||||
return ans, nil
|
||||
}
|
||||
|
||||
// LookupIP looks up host using OS resolver.
|
||||
// LookupIP looks up domain using current system nameservers settings.
|
||||
// It returns a slice of that host's IPv4 and IPv6 addresses.
|
||||
func LookupIP(domain string) []string {
|
||||
return lookupIP(domain, -1)
|
||||
return lookupIP(domain, -1, defaultNameservers())
|
||||
}
|
||||
|
||||
func lookupIP(domain string, timeout int) (ips []string) {
|
||||
// lookupIP looks up domain with given timeout and bootstrapDNS.
|
||||
// If timeout is negative, default timeout 2000 ms will be used.
|
||||
// It returns nil if bootstrapDNS is nil or empty.
|
||||
func lookupIP(domain string, timeout int, bootstrapDNS []string) (ips []string) {
|
||||
if net.ParseIP(domain) != nil {
|
||||
return []string{domain}
|
||||
}
|
||||
resolverMutex.Lock()
|
||||
if or == nil {
|
||||
ProxyLogger.Load().Debug().Msgf("Initialize OS resolver in lookupIP")
|
||||
or = newResolverWithNameserver(defaultNameservers())
|
||||
if bootstrapDNS == nil {
|
||||
ProxyLogger.Load().Debug().Msgf("empty bootstrap DNS")
|
||||
return nil
|
||||
}
|
||||
nss := *or.lanServers.Load()
|
||||
nss = append(nss, *or.publicServers.Load()...)
|
||||
resolverMutex.Unlock()
|
||||
|
||||
resolver := newResolverWithNameserver(nss)
|
||||
ProxyLogger.Load().Debug().Msgf("resolving %q using bootstrap DNS %q", domain, nss)
|
||||
resolver := newResolverWithNameserver(bootstrapDNS)
|
||||
ProxyLogger.Load().Debug().Msgf("resolving %q using bootstrap DNS %q", domain, bootstrapDNS)
|
||||
timeoutMs := 2000
|
||||
if timeout > 0 && timeout < timeoutMs {
|
||||
timeoutMs = timeout
|
||||
|
||||
Reference in New Issue
Block a user