From d3e9d4832faf8aaa67cf5d806d29fddd8e6647e9 Mon Sep 17 00:00:00 2001 From: Dv2Corn <320380254+Dv2Corn@users.noreply.github.com> Date: Thu, 12 Nov 2026 13:46:15 +0000 Subject: [PATCH] Create PTR records for every IPv6 address of a cloaked name With cloak_ptr, the PTR record of an IPv6 rule was always built from the first IPv6 address of the name. A second address got no PTR record, and the first one got the name twice. --- dnscrypt-proxy/plugin_cloak.go | 2 +- dnscrypt-proxy/plugin_cloak_test.go | 30 +++++++++++++++++++++++++++++ 2 files changed, 31 insertions(+), 1 deletion(-) create mode 100644 dnscrypt-proxy/plugin_cloak_test.go diff --git a/dnscrypt-proxy/plugin_cloak.go b/dnscrypt-proxy/plugin_cloak.go index 0fc40b27ee..9e4ec310d5 100644 --- a/dnscrypt-proxy/plugin_cloak.go +++ b/dnscrypt-proxy/plugin_cloak.go @@ -130,7 +130,7 @@ func (plugin *PluginCloak) loadRules(lines string, patternMatcher *PatternMatche } ptrLine = strings.TrimSuffix(reversed, ".") } else { - reversed, err := reverseAddr(cloakedName.ipv6[0].String()) + reversed, err := reverseAddr(ip.String()) if err != nil { dlog.Errorf("Failed to reverse IPv6 address at line %d: %v", lineNo+1, err) continue diff --git a/dnscrypt-proxy/plugin_cloak_test.go b/dnscrypt-proxy/plugin_cloak_test.go new file mode 100644 index 0000000000..8d4f39ba96 --- /dev/null +++ b/dnscrypt-proxy/plugin_cloak_test.go @@ -0,0 +1,30 @@ +package main + +import ( + "strings" + "testing" +) + +// TestCloakPTRMultipleAddresses checks that cloak_ptr creates a PTR record +// for every address of a name, not only for the first one. +func TestCloakPTRMultipleAddresses(t *testing.T) { + plugin := &PluginCloak{createPTR: true} + matcher := NewPatternMatcher() + rules := "host.test 192.0.2.1\nhost.test 192.0.2.2\nhost.test 2001:db8::1\nhost.test 2001:db8::2\n" + if err := plugin.loadRules(rules, matcher); err != nil { + t.Fatal(err) + } + for _, ip := range []string{"192.0.2.1", "192.0.2.2", "2001:db8::1", "2001:db8::2"} { + arpa, err := reverseAddr(ip) + if err != nil { + t.Fatal(err) + } + _, _, val := matcher.Eval(strings.TrimSuffix(arpa, ".")) + cloakedName, _ := val.(*CloakedName) + if cloakedName == nil { + t.Errorf("no PTR record for %s", ip) + } else if len(cloakedName.PTR) != 1 || cloakedName.PTR[0] != "host.test." { + t.Errorf("PTR records for %s: %v, want [host.test.]", ip, cloakedName.PTR) + } + } +}