middleware/{file, auto}: resolve external CNAMEs

Do the same thing as in etcd and give the option of externally resolving
CNAME. This is needed when CoreDNS is a proxy as well is serving zones.
This commit is contained in:
Miek Gieben 2016-11-09 21:26:49 +00:00
parent a8287bb04d
commit 0919216d3c
10 changed files with 125 additions and 7 deletions

View file

@ -8,6 +8,7 @@ import (
"github.com/miekg/coredns/core/dnsserver"
"github.com/miekg/coredns/middleware"
"github.com/miekg/coredns/middleware/proxy"
"github.com/mholt/caddy"
)
@ -90,6 +91,7 @@ func fileParse(c *caddy.Controller) (Zones, error) {
}
noReload := false
prxy := proxy.Proxy{}
for c.NextBlock() {
t, _, e := TransferParse(c, false)
if e != nil {
@ -98,6 +100,19 @@ func fileParse(c *caddy.Controller) (Zones, error) {
switch c.Val() {
case "no_reload":
noReload = true
case "upstream":
args := c.RemainingArgs()
if len(args) == 0 {
return Zones{}, c.ArgErr()
}
for i := 0; i < len(args); i++ {
h, p, e := net.SplitHostPort(args[i])
if e != nil && p == "" {
args[i] = h + ":53"
}
}
prxy = proxy.New(args)
}
for _, origin := range origins {
@ -105,6 +120,7 @@ func fileParse(c *caddy.Controller) (Zones, error) {
z[origin].TransferTo = append(z[origin].TransferTo, t...)
}
z[origin].NoReload = noReload
z[origin].Proxy = prxy
}
}
}