mirror of
https://github.com/coredns/coredns.git
synced 2026-10-08 19:45:21 -04:00
plugin: use Zones.Contains when any match suffices (#8505)
This commit is contained in:
@@ -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() {
|
||||
|
||||
Reference in New Issue
Block a user