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) + } + } +}