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:
parent
48171c43f4
commit
edd755b7ab
|
@ -609,7 +609,6 @@ func (d *DNSServer) parseDatacenter(labels []string, datacenter *string) bool {
|
||||||
|
|
||||||
var errECSNotGlobal = fmt.Errorf("ECS response is not global")
|
var errECSNotGlobal = fmt.Errorf("ECS response is not global")
|
||||||
var errNameNotFound = fmt.Errorf("DNS name not found")
|
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
|
// errNoAnswer is used to indicate that the response should set SOA, and the
|
||||||
// success response code.
|
// success response code.
|
||||||
|
@ -876,12 +875,9 @@ func rCodeFromError(err error) int {
|
||||||
case err == nil:
|
case err == nil:
|
||||||
return dns.RcodeSuccess
|
return dns.RcodeSuccess
|
||||||
case errors.Is(err, errNoAnswer):
|
case errors.Is(err, errNoAnswer):
|
||||||
// TODO: why do we return success if the answer is empty?
|
|
||||||
return dns.RcodeSuccess
|
return dns.RcodeSuccess
|
||||||
case errors.Is(err, errECSNotGlobal):
|
case errors.Is(err, errECSNotGlobal):
|
||||||
return rCodeFromError(errors.Unwrap(err))
|
return rCodeFromError(errors.Unwrap(err))
|
||||||
case errors.Is(err, errQueryRefused):
|
|
||||||
return dns.RcodeRefused
|
|
||||||
case errors.Is(err, errNameNotFound):
|
case errors.Is(err, errNameNotFound):
|
||||||
return dns.RcodeNameError
|
return dns.RcodeNameError
|
||||||
case structs.IsErrNoDCPath(err) || structs.IsErrQueryNotFound(err):
|
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
|
// Only handle ANY, A, AAAA, and TXT type requests
|
||||||
qType := req.Question[0].Qtype
|
qType := req.Question[0].Qtype
|
||||||
if qType != dns.TypeANY && qType != dns.TypeA && qType != dns.TypeAAAA && qType != dns.TypeTXT {
|
if qType != dns.TypeANY && qType != dns.TypeA && qType != dns.TypeAAAA && qType != dns.TypeTXT {
|
||||||
return errQueryRefused
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Make an RPC request
|
// Make an RPC request
|
||||||
|
|
|
@ -6779,17 +6779,15 @@ func TestDNS_EDNS_Truncate_AgentSource(t *testing.T) {
|
||||||
t.Fatalf("err: %v", err)
|
t.Fatalf("err: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
req := new(dns.Msg)
|
||||||
m := new(dns.Msg)
|
req.SetQuestion("foo.query.consul.", dns.TypeSRV)
|
||||||
m.SetQuestion("foo.query.consul.", dns.TypeSRV)
|
req.SetEdns0(2048, true)
|
||||||
m.SetEdns0(2048, true)
|
req.Compress = false
|
||||||
m.Compress = false
|
|
||||||
|
|
||||||
c := new(dns.Client)
|
c := new(dns.Client)
|
||||||
r, _, err := c.Exchange(m, a.DNSAddr())
|
resp, _, err := c.Exchange(req, a.DNSAddr())
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
require.True(t, r.Len() < 2048)
|
require.True(t, resp.Len() < 2048)
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestDNS_trimUDPResponse_NoTrim(t *testing.T) {
|
func TestDNS_trimUDPResponse_NoTrim(t *testing.T) {
|
||||||
|
|
Loading…
Reference in New Issue