mirror of
https://github.com/coredns/coredns.git
synced 2026-07-10 17:50:12 -04:00
plugin/hosts: fall through unsupported query types (#8193)
This commit is contained in:
@@ -50,6 +50,10 @@ func (h Hosts) ServeDNS(ctx context.Context, w dns.ResponseWriter, r *dns.Msg) (
|
|||||||
case dns.TypeAAAA:
|
case dns.TypeAAAA:
|
||||||
ips := h.LookupStaticHostV6(qname)
|
ips := h.LookupStaticHostV6(qname)
|
||||||
answers = aaaa(qname, h.options.ttl, ips)
|
answers = aaaa(qname, h.options.ttl, ips)
|
||||||
|
default:
|
||||||
|
if h.Fall.Through(qname) {
|
||||||
|
return plugin.NextOrFailure(h.Name(), h.Next, ctx, w, r)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Only on NXDOMAIN we will fallthrough.
|
// Only on NXDOMAIN we will fallthrough.
|
||||||
|
|||||||
@@ -57,6 +57,35 @@ func TestLookupA(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestFallthroughUnsupportedType(t *testing.T) {
|
||||||
|
h := Hosts{
|
||||||
|
Next: test.NextHandler(dns.RcodeRefused, nil),
|
||||||
|
Hostsfile: &Hostsfile{
|
||||||
|
Origins: []string{"."},
|
||||||
|
hmap: newMap(),
|
||||||
|
inline: newMap(),
|
||||||
|
options: newOptions(),
|
||||||
|
},
|
||||||
|
Fall: fall.Root,
|
||||||
|
}
|
||||||
|
h.hmap = h.parse(strings.NewReader(hostsExample))
|
||||||
|
|
||||||
|
m := new(dns.Msg)
|
||||||
|
m.SetQuestion("example.org.", dns.TypeTXT)
|
||||||
|
rec := dnstest.NewRecorder(&test.ResponseWriter{})
|
||||||
|
|
||||||
|
rcode, err := h.ServeDNS(context.Background(), rec, m)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("Expected no error, got %v", err)
|
||||||
|
}
|
||||||
|
if rcode != dns.RcodeRefused {
|
||||||
|
t.Fatalf("Expected fallthrough rcode %d, got %d", dns.RcodeRefused, rcode)
|
||||||
|
}
|
||||||
|
if rec.Msg != nil {
|
||||||
|
t.Fatalf("Expected no response from hosts after fallthrough, got %#v", rec.Msg)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
var hostsTestCases = []test.Case{
|
var hostsTestCases = []test.Case{
|
||||||
{
|
{
|
||||||
Qname: "example.org.", Qtype: dns.TypeA,
|
Qname: "example.org.", Qtype: dns.TypeA,
|
||||||
|
|||||||
Reference in New Issue
Block a user