plugin/template: Persist truncated state to client if CNAME lookup response is truncated (#4713)

* persist truncated state to client if cname lookup response is truncated

Signed-off-by: Chris O'Haver <cohaver@infoblox.com>
This commit is contained in:
Chris O'Haver
2022-01-26 15:49:44 -05:00
committed by GitHub
parent f713a51319
commit 49f0562f6c
2 changed files with 106 additions and 4 deletions

View File

@@ -11,7 +11,6 @@ import (
"github.com/coredns/coredns/plugin/metadata"
"github.com/coredns/coredns/plugin/metrics"
"github.com/coredns/coredns/plugin/pkg/fall"
"github.com/coredns/coredns/plugin/pkg/upstream"
"github.com/coredns/coredns/request"
"github.com/miekg/dns"
@@ -35,7 +34,12 @@ type template struct {
qclass uint16
qtype uint16
fall fall.F
upstream *upstream.Upstream
upstream Upstreamer
}
// Upstreamer looks up targets of CNAME templates
type Upstreamer interface {
Lookup(ctx context.Context, state request.Request, name string, typ uint16) (*dns.Msg, error)
}
type templateData struct {
@@ -100,8 +104,10 @@ func (h Handler) ServeDNS(ctx context.Context, w dns.ResponseWriter, r *dns.Msg)
}
msg.Answer = append(msg.Answer, rr)
if template.upstream != nil && (state.QType() == dns.TypeA || state.QType() == dns.TypeAAAA) && rr.Header().Rrtype == dns.TypeCNAME {
up, _ := template.upstream.Lookup(ctx, state, rr.(*dns.CNAME).Target, state.QType())
msg.Answer = append(msg.Answer, up.Answer...)
if up, err := template.upstream.Lookup(ctx, state, rr.(*dns.CNAME).Target, state.QType()); err == nil && up != nil {
msg.Truncated = up.Truncated
msg.Answer = append(msg.Answer, up.Answer...)
}
}
}
for _, additional := range template.additional {