plugin/file/auto: Write CNAME answer to client even if target lookup is SERVFAIL (#4863)

* write cname answer to client even if target lookup is servfail

Signed-off-by: Chris O'Haver <cohaver@infoblox.com>

* fix existing unit test expectations

Signed-off-by: Chris O'Haver <cohaver@infoblox.com>
This commit is contained in:
Chris O'Haver
2021-09-14 04:08:22 -04:00
committed by GitHub
parent 8f7162c42b
commit 158ad2d738
5 changed files with 35 additions and 4 deletions

View File

@@ -99,7 +99,14 @@ func (f File) ServeDNS(ctx context.Context, w dns.ResponseWriter, r *dns.Msg) (i
case Delegation:
m.Authoritative = false
case ServerFailure:
return dns.RcodeServerFailure, nil
// If the result is SERVFAIL and the answer is non-empty, then the SERVFAIL came from an
// external CNAME lookup and the answer contains the CNAME with no target record. We should
// write the CNAME record to the client instead of sending an empty SERVFAIL response.
if len(m.Answer) == 0 {
return dns.RcodeServerFailure, nil
}
// The rcode in the response should be the rcode received from the target lookup. RFC 6604 section 3
m.Rcode = dns.RcodeServerFailure
}
w.WriteMsg(m)