Support SkyDNS' stubzones

This implements stubzones in the same way as SkyDNS. This
also works with multiple configured domains and has tests.
Also add more configuration parameters for TLS and path prefix and
enabling stubzones.  Run StubUpdates as a startup command to keep up to
date with the list in etcd.
This commit is contained in:
Miek Gieben 2016-03-25 20:26:42 +00:00
parent a832ab696a
commit ebef64280a
8 changed files with 403 additions and 98 deletions

View file

@ -1,6 +1,8 @@
package etcd
import (
"strings"
"github.com/miekg/coredns/middleware"
"github.com/miekg/dns"
@ -9,6 +11,20 @@ import (
func (e Etcd) ServeDNS(ctx context.Context, w dns.ResponseWriter, r *dns.Msg) (int, error) {
state := middleware.State{W: w, Req: r}
// We need to check stubzones first, because we may get a request for a zone we
// are not auth. for *but* do have a stubzone forward for. If we do the stubzone
// handler will handle the request.
name := state.Name()
if len(*e.Stubmap) > 0 {
for zone, _ := range *e.Stubmap {
if strings.HasSuffix(name, zone) {
stub := Stub{Etcd: e, Zone: zone}
return stub.ServeDNS(ctx, w, r)
}
}
}
zone := middleware.Zones(e.Zones).Matches(state.Name())
if zone == "" {
return e.Next.ServeDNS(ctx, w, r)