From faeb8ba699ce2e8b999da31991ee62e7ac2c9a9e Mon Sep 17 00:00:00 2001 From: houyuwushang Date: Wed, 24 Jun 2026 17:28:20 +0800 Subject: [PATCH] plugin/hosts: fall through unsupported query types (#8193) --- plugin/hosts/hosts.go | 4 ++++ plugin/hosts/hosts_test.go | 29 +++++++++++++++++++++++++++++ 2 files changed, 33 insertions(+) diff --git a/plugin/hosts/hosts.go b/plugin/hosts/hosts.go index 5c644e752..816a5bb1d 100644 --- a/plugin/hosts/hosts.go +++ b/plugin/hosts/hosts.go @@ -50,6 +50,10 @@ func (h Hosts) ServeDNS(ctx context.Context, w dns.ResponseWriter, r *dns.Msg) ( case dns.TypeAAAA: ips := h.LookupStaticHostV6(qname) 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. diff --git a/plugin/hosts/hosts_test.go b/plugin/hosts/hosts_test.go index 320655adb..ccde52583 100644 --- a/plugin/hosts/hosts_test.go +++ b/plugin/hosts/hosts_test.go @@ -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{ { Qname: "example.org.", Qtype: dns.TypeA,