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.
This commit is contained in:
Daniel Nephin 2021-06-18 17:57:20 -04:00
parent 48171c43f4
commit edd755b7ab
2 changed files with 9 additions and 15 deletions

View File

@ -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

View File

@ -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())
resp, _, err := c.Exchange(req, a.DNSAddr())
require.NoError(t, err)
require.True(t, r.Len() < 2048)
}
require.True(t, resp.Len() < 2048)
}
func TestDNS_trimUDPResponse_NoTrim(t *testing.T) {