plugin/template : add support for extended DNS errors (#5659)

* plugin/template : add support for extended DNS errors

Signed-off-by: Ondřej Benkovský <ondrej.benkovsky@jamf.com>
This commit is contained in:
Ondřej Benkovský
2022-10-03 17:04:56 +02:00
committed by GitHub
parent b9a31f2c89
commit 2fa9821c7e
5 changed files with 94 additions and 0 deletions

View File

@@ -33,10 +33,16 @@ type template struct {
authority []*gotmpl.Template
qclass uint16
qtype uint16
ederror *ederror
fall fall.F
upstream Upstreamer
}
type ederror struct {
code uint16
reason string
}
// Upstreamer looks up targets of CNAME templates
type Upstreamer interface {
Lookup(ctx context.Context, state request.Request, name string, typ uint16) (*dns.Msg, error)
@@ -125,6 +131,12 @@ func (h Handler) ServeDNS(ctx context.Context, w dns.ResponseWriter, r *dns.Msg)
msg.Ns = append(msg.Ns, rr)
}
if template.ederror != nil {
msg = msg.SetEdns0(4096, true)
ede := dns.EDNS0_EDE{InfoCode: template.ederror.code, ExtraText: template.ederror.reason}
msg.IsEdns0().Option = append(msg.IsEdns0().Option, &ede)
}
w.WriteMsg(msg)
return template.rcode, nil
}