Create PTR records for every IPv6 address of a cloaked name (#3419)

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.
This commit is contained in:
Aleksey Fedorov 2026-11-13 00:57:53 +10:00 committed by GitHub
parent a286175551
commit 7b9e495e71
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 31 additions and 1 deletions

View file

@ -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

View file

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