mirror of
https://github.com/coredns/coredns.git
synced 2026-10-16 15:25:47 -04:00
plugin/dns64: preserve A fallback response codes (#8619)
* plugin/dns64: preserve fallback response codes Signed-off-by: xinjun.jiang <xinjun.jiang@daocloud.io> * plugin/dns64: mark written fallback replies as handled Signed-off-by: xinjun.jiang <xinjun.jiang@daocloud.io> --------- Signed-off-by: xinjun.jiang <xinjun.jiang@daocloud.io>
This commit is contained in:
@@ -63,7 +63,7 @@ func (d *DNS64) ServeDNS(ctx context.Context, w dns.ResponseWriter, r *dns.Msg)
|
||||
|
||||
RequestsTranslatedCount.WithLabelValues(metrics.WithServer(ctx)).Inc()
|
||||
w.WriteMsg(msg)
|
||||
return msg.Rcode, nil
|
||||
return dns.RcodeSuccess, nil
|
||||
}
|
||||
|
||||
// Name implements the Handler interface.
|
||||
@@ -134,6 +134,7 @@ func (d *DNS64) DoDNS64(ctx context.Context, w dns.ResponseWriter, r *dns.Msg, o
|
||||
func (d *DNS64) Synthesize(origReq, origResponse, resp *dns.Msg) *dns.Msg {
|
||||
ret := dns.Msg{}
|
||||
ret.SetReply(origReq)
|
||||
ret.Rcode = resp.Rcode
|
||||
|
||||
// persist truncated state of AAAA response
|
||||
ret.Truncated = resp.Truncated
|
||||
|
||||
@@ -581,3 +581,42 @@ func TestDNS64NilUpstreamResponse(t *testing.T) {
|
||||
t.Error("Expected error when upstream returns nil response, got nil")
|
||||
}
|
||||
}
|
||||
|
||||
func TestDNS64FallbackError(t *testing.T) {
|
||||
_, prefix, _ := net.ParseCIDR("64:ff9b::/96")
|
||||
for _, rcode := range []int{dns.RcodeSuccess, dns.RcodeServerFailure, dns.RcodeRefused, dns.RcodeFormatError, dns.RcodeNameError, dns.RcodeNotImplemented} {
|
||||
t.Run(dns.RcodeToString[rcode], func(t *testing.T) {
|
||||
req := new(dns.Msg)
|
||||
req.SetQuestion("example.com.", dns.TypeAAAA)
|
||||
initial := new(dns.Msg)
|
||||
initial.SetReply(req)
|
||||
fallback := new(dns.Msg)
|
||||
fallback.SetRcode(req, rcode)
|
||||
fallback.Id++
|
||||
fallback.Question[0].Qtype = dns.TypeA
|
||||
fallback.Ns = []dns.RR{test.SOA("example.com. 60 IN SOA ns.example.com. hostmaster.example.com. 1 1 1 1 1")}
|
||||
d := DNS64{
|
||||
Next: &fakeHandler{t, initial},
|
||||
Prefix: prefix,
|
||||
Upstream: &fakeUpstream{t, req.Question[0].Name, fallback},
|
||||
}
|
||||
rec := dnstest.NewRecorder(&test.ResponseWriter{RemoteIP: "::1"})
|
||||
got, err := d.ServeDNS(t.Context(), rec, req)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if got != dns.RcodeSuccess {
|
||||
t.Errorf("written fallback %s returned handler code %s, want NOERROR", dns.RcodeToString[rcode], dns.RcodeToString[got])
|
||||
}
|
||||
if rec.Msg.Rcode != rcode {
|
||||
t.Errorf("fallback %s returned response code %s", dns.RcodeToString[rcode], dns.RcodeToString[rec.Msg.Rcode])
|
||||
}
|
||||
if rec.Msg.Id != req.Id || !reflect.DeepEqual(rec.Msg.Question, req.Question) {
|
||||
t.Errorf("response did not preserve the original AAAA query: %s", rec.Msg)
|
||||
}
|
||||
if !reflect.DeepEqual(rec.Msg.Ns, fallback.Ns) {
|
||||
t.Errorf("response did not preserve fallback authority records: %s", rec.Msg)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user