mirror of
https://github.com/Control-D-Inc/ctrld.git
synced 2026-07-04 01:07:49 +02:00
Only used saved LAN servers if available
This commit is contained in:
committed by
Cuong Manh Le
parent
a5c776c846
commit
db6e977e3a
+14
-2
@@ -78,7 +78,7 @@ func availableNameservers() []string {
|
||||
if _, ok := machineIPsMap[ns]; ok {
|
||||
continue
|
||||
}
|
||||
if testNameserver(ns) {
|
||||
if testNameServerFn(ns) {
|
||||
nss = append(nss, ns)
|
||||
}
|
||||
}
|
||||
@@ -122,7 +122,16 @@ func initializeOsResolver(servers []string) []string {
|
||||
or.initializedLanServers.CompareAndSwap(nil, &lanNss)
|
||||
}
|
||||
if len(lanNss) == 0 {
|
||||
or.lanServers.Store(or.initializedLanServers.Load())
|
||||
var nss []string
|
||||
p := or.initializedLanServers.Load()
|
||||
if p != nil {
|
||||
for _, ns := range *p {
|
||||
if testNameServerFn(ns) {
|
||||
nss = append(nss, ns)
|
||||
}
|
||||
}
|
||||
}
|
||||
or.lanServers.Store(&nss)
|
||||
} else {
|
||||
or.lanServers.Store(&lanNss)
|
||||
}
|
||||
@@ -133,6 +142,9 @@ func initializeOsResolver(servers []string) []string {
|
||||
return slices.Concat(lanNss, publicNss)
|
||||
}
|
||||
|
||||
// testNameserverFn sends a test query to DNS nameserver to check if the server is available.
|
||||
var testNameServerFn = testNameserver
|
||||
|
||||
// testPlainDnsNameserver sends a test query to DNS nameserver to check if the server is available.
|
||||
func testNameserver(addr string) bool {
|
||||
msg := new(dns.Msg)
|
||||
|
||||
Reference in New Issue
Block a user