request: stop echoing unhandled EDNS options (#8514)

Signed-off-by: houyuwushang <liuluoqianqiu@outlook.com>
This commit is contained in:
houyuwushang
2026-09-05 09:14:53 +08:00
committed by GitHub
parent 895eab37e8
commit b6987aeb4a
6 changed files with 77 additions and 64 deletions

View File

@@ -58,6 +58,10 @@ func TestLookupCache(t *testing.T) {
t.Run("DNSSEC OPT", func(t *testing.T) {
testCaseDNSSEC(t, "example.org.", udp, 0)
})
t.Run("EDNS request options", func(t *testing.T) {
testCaseEDNSOptionsNotEchoed(t, "example.org.", udp)
})
}
func testCase(t *testing.T, name, addr string, expectAnsLen int, expectTTL uint32) {
@@ -118,6 +122,29 @@ func testCaseDNSSEC(t *testing.T, name, addr string, bufsize int) {
}
}
func testCaseEDNSOptionsNotEchoed(t *testing.T, name, addr string) {
t.Helper()
m := new(dns.Msg)
m.SetQuestion(name, dns.TypeA)
m.SetEdns0(4096, false)
m.IsEdns0().Option = []dns.EDNS0{
&dns.EDNS0_NSID{Code: dns.EDNS0NSID},
&dns.EDNS0_COOKIE{Code: dns.EDNS0COOKIE, Cookie: "abcdef0123456789"},
}
resp, err := dns.Exchange(m, addr)
if err != nil {
t.Fatalf("Expected to receive reply, but didn't: %s", err)
}
opt := resp.IsEdns0()
if opt == nil {
t.Fatal("Expected OPT RR in response")
}
if len(opt.Option) != 0 {
t.Fatalf("Expected request EDNS options not to be echoed, got %v", opt.Option)
}
}
func TestLookupCacheWithoutEdns(t *testing.T) {
name, rm, err := test.TempFile(".", exampleOrg)
if err != nil {