coredns/middleware/zone.go
Miek Gieben 8f9f2cd1ab Add etcd middleware
This middleware acts in the same way as SkyDNS. We might add options
to allow it to be behave different, but for now it will suffice.

A Corefile like:
.:1053 {
    etcd miek.nl
    proxy . 8.8.8.8:53
}
will perform lookup in etcd and proxy everything not miek.nl to Google
for further resolution.

The internal etcd forwarding *also* uses the proxy infrastructure,
meaning you get health check and such for (almost) free
2016-03-23 10:41:40 +00:00

33 lines
610 B
Go

package middleware
import (
"strings"
"github.com/miekg/dns"
)
type Zones []string
// Matches checks to see if other matches p. The match will return the most
// specific zones that matches other. The empty string signals a not found
// condition.
func (z Zones) Matches(qname string) string {
zone := ""
// TODO(miek): use IsSubDomain here?
for _, zname := range z {
if strings.HasSuffix(qname, zname) {
if len(zname) > len(zone) {
zone = zname
}
}
}
return zone
}
// Fully qualify all zones in z
func (z Zones) FullyQualify() {
for i, _ := range z {
z[i] = dns.Fqdn(z[i])
}
}