From edd755b7abeeb080c5683e7224de7edb44979601 Mon Sep 17 00:00:00 2001 From: Daniel Nephin Date: Fri, 18 Jun 2021 17:57:20 -0400 Subject: [PATCH] dns: correct rcode for qtype not supported A previous commit started using QueryRefuced, but that is not correct. QueryRefuced refers to the OpCode, not the query type. Instead use errNoAnswer because we have no records for that query type. --- agent/dns.go | 6 +----- agent/dns_test.go | 18 ++++++++---------- 2 files changed, 9 insertions(+), 15 deletions(-) diff --git a/agent/dns.go b/agent/dns.go index 18d709293..0114ac425 100644 --- a/agent/dns.go +++ b/agent/dns.go @@ -609,7 +609,6 @@ func (d *DNSServer) parseDatacenter(labels []string, datacenter *string) bool { var errECSNotGlobal = fmt.Errorf("ECS response is not global") var errNameNotFound = fmt.Errorf("DNS name not found") -var errQueryRefused = fmt.Errorf("query refused") // errNoAnswer is used to indicate that the response should set SOA, and the // success response code. @@ -876,12 +875,9 @@ func rCodeFromError(err error) int { case err == nil: return dns.RcodeSuccess case errors.Is(err, errNoAnswer): - // TODO: why do we return success if the answer is empty? return dns.RcodeSuccess case errors.Is(err, errECSNotGlobal): return rCodeFromError(errors.Unwrap(err)) - case errors.Is(err, errQueryRefused): - return dns.RcodeRefused case errors.Is(err, errNameNotFound): return dns.RcodeNameError case structs.IsErrNoDCPath(err) || structs.IsErrQueryNotFound(err): @@ -896,7 +892,7 @@ func (d *DNSServer) nodeLookup(cfg *dnsConfig, datacenter, node string, req, res // Only handle ANY, A, AAAA, and TXT type requests qType := req.Question[0].Qtype if qType != dns.TypeANY && qType != dns.TypeA && qType != dns.TypeAAAA && qType != dns.TypeTXT { - return errQueryRefused + return nil } // Make an RPC request diff --git a/agent/dns_test.go b/agent/dns_test.go index cd7ed4c18..e72b9ce7c 100644 --- a/agent/dns_test.go +++ b/agent/dns_test.go @@ -6779,17 +6779,15 @@ func TestDNS_EDNS_Truncate_AgentSource(t *testing.T) { t.Fatalf("err: %v", err) } - { - m := new(dns.Msg) - m.SetQuestion("foo.query.consul.", dns.TypeSRV) - m.SetEdns0(2048, true) - m.Compress = false + req := new(dns.Msg) + req.SetQuestion("foo.query.consul.", dns.TypeSRV) + req.SetEdns0(2048, true) + req.Compress = false - c := new(dns.Client) - r, _, err := c.Exchange(m, a.DNSAddr()) - require.NoError(t, err) - require.True(t, r.Len() < 2048) - } + c := new(dns.Client) + resp, _, err := c.Exchange(req, a.DNSAddr()) + require.NoError(t, err) + require.True(t, resp.Len() < 2048) } func TestDNS_trimUDPResponse_NoTrim(t *testing.T) {