check / check (push) Canceled after 0s
The resolver lists in FailedTypes each record type whose query to a nameserver got no usable reply (none after two tries, an error reply, a referral, or a truncated reply whose TCP retry failed), and logs it with the reason. A nameserver that answered no type has failed, as before. The watcher saves such a type in failedTypes, keeping the previous check's records, leaves it out of the comparison with other nameservers on that check, and compares the kept records with the next answer. With nothing to keep, it is also in unknownTypes and not compared until it answers. Change messages leave out what was not compared. A nameserver whose A, AAAA or CNAME query failed is no answer when following a CNAME or resolving addresses. Model: opus-5-5
82 lines
1.9 KiB
Go
82 lines
1.9 KiB
Go
package resolver
|
|
|
|
import (
|
|
"context"
|
|
"log/slog"
|
|
"time"
|
|
|
|
"github.com/miekg/dns"
|
|
)
|
|
|
|
// NewWithFailingTCP returns a Resolver whose TCP client gives up before
|
|
// it can connect, so the retry over TCP of every truncated reply fails.
|
|
func NewWithFailingTCP(log *slog.Logger) *Resolver {
|
|
r := NewFromLogger(log)
|
|
r.tcp = &tcpClient{timeout: time.Nanosecond}
|
|
|
|
return r
|
|
}
|
|
|
|
// ExtractRecordValue exports extractRecordValue for testing.
|
|
func ExtractRecordValue(rr dns.RR) string {
|
|
return extractRecordValue(rr)
|
|
}
|
|
|
|
// UsableReply exports usableReply for testing.
|
|
func UsableReply(resp *dns.Msg, zone string, name string) bool {
|
|
return usableReply(resp, zone, name)
|
|
}
|
|
|
|
// NSSetFrom exports nsSetFrom for testing.
|
|
func NSSetFrom(resp *dns.Msg, domain string) []string {
|
|
return nsSetFrom(resp, domain)
|
|
}
|
|
|
|
// CollectIPs exports collectIPs for testing.
|
|
func CollectIPs(
|
|
results map[string]*NameserverResponse,
|
|
) ([]string, string, error) {
|
|
return collectIPs(results)
|
|
}
|
|
|
|
// QueryServers exports queryServers for testing.
|
|
func (r *Resolver) QueryServers(
|
|
ctx context.Context,
|
|
servers []string,
|
|
zone string,
|
|
name string,
|
|
qtype uint16,
|
|
) (*dns.Msg, error) {
|
|
return r.queryServers(ctx, servers, zone, name, qtype)
|
|
}
|
|
|
|
// QueryEachNS exports queryEachNS for testing.
|
|
func (r *Resolver) QueryEachNS(
|
|
ctx context.Context,
|
|
nameservers []string,
|
|
hostname string,
|
|
) (map[string]*NameserverResponse, error) {
|
|
return r.queryEachNS(ctx, nameservers, hostname, recordTypes())
|
|
}
|
|
|
|
// ResolveNSIPs exports resolveNSIPs for testing.
|
|
func (r *Resolver) ResolveNSIPs(
|
|
ctx context.Context,
|
|
nsNames []string,
|
|
) []string {
|
|
return r.resolveNSIPs(ctx, nsNames)
|
|
}
|
|
|
|
// RootServerList exports rootServerList for testing.
|
|
func RootServerList() []string {
|
|
return rootServerList()
|
|
}
|
|
|
|
// Shuffled exports shuffled for testing.
|
|
func Shuffled(
|
|
servers []string,
|
|
shuffle func(n int, swap func(i, j int)),
|
|
) []string {
|
|
return shuffled(servers, shuffle)
|
|
}
|