check / check (push) Successful in 1m27s
The resolver lists in FailedTypes each record type whose query to a nameserver got no usable reply (no reply, a code other than NOERROR or NXDOMAIN, a referral, or a truncated reply whose TCP retry failed) and logs it unless shutdown cut it short. A nameserver that answered no type has failed. The watcher saves such a type in failedTypes with the previous check's records, leaves it out of the comparison with other nameservers on that check, and compares it with the next answer. When the previous check did not know its records either, it is also in unknownTypes and not compared until it answers. A nameserver whose A, AAAA or CNAME query failed is no answer when following a CNAME or resolving addresses. Model: opus-5-5
110 lines
2.5 KiB
Go
110 lines
2.5 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)
|
|
}
|
|
|
|
// CollectAnswerRecords exports collectAnswerRecords for testing.
|
|
func CollectAnswerRecords(msg *dns.Msg, resp *NameserverResponse) {
|
|
var state queryState
|
|
|
|
collectAnswerRecords(msg, resp, &state)
|
|
}
|
|
|
|
// 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, looking each name up
|
|
// as a lookup that no other lookup started.
|
|
func (r *Resolver) ResolveNSIPs(
|
|
ctx context.Context,
|
|
nsNames []string,
|
|
) []string {
|
|
ips, _ := r.resolveNSIPs(ctx, nsNames, 1)
|
|
|
|
return ips
|
|
}
|
|
|
|
// MaxLookupDepth exports maxLookupDepth for testing.
|
|
const MaxLookupDepth = maxLookupDepth
|
|
|
|
// QueryZone exports queryZone for testing.
|
|
func (r *Resolver) QueryZone(
|
|
ctx context.Context,
|
|
given []string,
|
|
withoutAddresses []string,
|
|
zone string,
|
|
name string,
|
|
qtype uint16,
|
|
depth int,
|
|
) (*dns.Msg, error) {
|
|
return r.queryZone(
|
|
ctx, given, withoutAddresses, zone, name, qtype, depth,
|
|
)
|
|
}
|
|
|
|
// 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)
|
|
}
|