plugin: use Zones.Contains when any match suffices (#8505)

This commit is contained in:
Ilya Kulakov
2026-09-02 23:59:58 -07:00
committed by GitHub
parent f1d835aa51
commit c942ca7c36
16 changed files with 25 additions and 30 deletions

View File

@@ -4,6 +4,7 @@ import (
"fmt"
"net"
"runtime"
"slices"
"strconv"
"strings"
@@ -22,8 +23,7 @@ type Zones []string
// Matches checks if qname is a subdomain of any of the zones in z. The match
// will return the most specific zones that matches. The empty string
// signals a not found condition.
func (z Zones) Matches(qname string) string {
zone := ""
func (z Zones) Matches(qname string) (zone string) {
for _, zname := range z {
if dns.IsSubDomain(zname, qname) {
// We want the *longest* matching zone, otherwise we may end up in a parent
@@ -35,6 +35,12 @@ func (z Zones) Matches(qname string) string {
return zone
}
func (z Zones) Contains(qname string) bool {
return slices.ContainsFunc(z, func(zname string) bool {
return dns.IsSubDomain(zname, qname)
})
}
// Normalize fully qualifies all zones in z. The zones in Z must be domain names, without
// a port or protocol prefix.
func (z Zones) Normalize() {