resolver: a root server's reply marked recursion available means interception (closes #300)
check / check (push) Canceled after 0s

dnswatcher never asks for recursion and a root server never offers it,
so a reply marked recursion available from a root server's address
came from a resolver on the network answering in its place. Such a
reply is now passed over, and when every root server refused or gave
one, the lookup fails with the existing "this network intercepts DNS
queries", whether or not that resolver had the name cached. Before, a
cached name was checked against the resolver's second-hand answer.

On such a network dnswatcher and its tests fail with that error, by
design; nothing asks again another way or works around it. A live test
passes public resolvers as the root servers and expects the error.

Model: opus-5-5
This commit is contained in:
2026-10-16 08:19:27 +00:00
parent adc8131191
commit ca26499c88
5 changed files with 117 additions and 10 deletions
+41 -8
View File
@@ -284,10 +284,11 @@ func shuffled(
}
// queryServers asks servers, the servers of zone, about name in a random
// order until one gives a usable reply. A server that times out, refuses
// or gives a reply that is not usable is passed over for the next. When
// every server refused, the error says so, and when they are the root
// servers it is ErrIntercepted.
// order until one gives a reply it uses (see replyError). A server that
// times out, refuses or gives a reply it does not use is passed over for
// the next. When every server refused, the error says so. When they are
// the root servers and each one refused or gave a reply marked recursion
// available, the error is ErrIntercepted.
func (r *Resolver) queryServers(
ctx context.Context,
servers []string,
@@ -298,6 +299,7 @@ func (r *Resolver) queryServers(
var lastErr error
refused := 0
recursionAvailable := 0
for _, ip := range shuffled(servers, rand.Shuffle) {
if checkCtx(ctx) != nil {
@@ -305,10 +307,8 @@ func (r *Resolver) queryServers(
}
resp, err := r.queryDNS(ctx, ip, name, qtype)
if err == nil && !usableReply(resp, zone, name) {
err = fmt.Errorf(
"query %s @%s: %w", name, ip, ErrUnusableReply,
)
if err == nil {
err = replyError(resp, ip, zone, name)
}
if err == nil {
@@ -319,6 +319,10 @@ func (r *Resolver) queryServers(
refused++
}
if errors.Is(err, ErrRecursionAvailable) {
recursionAvailable++
}
lastErr = err
}
@@ -329,6 +333,14 @@ func (r *Resolver) queryServers(
)
}
if refused+recursionAvailable == len(servers) && zone == "." {
return nil, fmt.Errorf(
"every root server refused a query for %s or gave a reply "+
"marked recursion available: %w",
name, ErrIntercepted,
)
}
if refused == len(servers) {
return nil, fmt.Errorf(
"every server of %s refused a query for %s: %w",
@@ -339,6 +351,27 @@ func (r *Resolver) queryServers(
return nil, fmt.Errorf("all servers failed: %w", lastErr)
}
// replyError returns why resp, the reply of the server at ip, one of the
// servers of zone, to a query about name, is not used, or nil when it
// is. A reply that is not usable is not used. Nor is a reply from a root
// server marked recursion available: root servers offer no recursion,
// so it came from something on the network answering in their place.
func replyError(resp *dns.Msg, ip string, zone string, name string) error {
if zone == "." && resp.RecursionAvailable {
return fmt.Errorf(
"query %s @%s: %w", name, ip, ErrRecursionAvailable,
)
}
if !usableReply(resp, zone, name) {
return fmt.Errorf(
"query %s @%s: %w", name, ip, ErrUnusableReply,
)
}
return nil
}
// isErrorReply reports whether msg is an error reply: one with any code
// but NOERROR and NXDOMAIN, such as SERVFAIL, NOTIMP or FORMERR. An error
// reply says nothing about the name's records.