mirror of
https://github.com/coredns/coredns.git
synced 2025-12-06 02:15:11 -05:00
plugin/auto/file/secondary: Use new upstream resolver (#1534)
* move file, auto, secondary to new upstream * include context in request
This commit is contained in:
committed by
Miek Gieben
parent
fc1d73ffa9
commit
ba573c0f40
@@ -28,7 +28,7 @@ If you want to round robin A and AAAA responses look at the *loadbalance* plugin
|
||||
file DBFILE [ZONES... ] {
|
||||
transfer to ADDRESS...
|
||||
no_reload
|
||||
upstream ADDRESS...
|
||||
upstream [ADDRESS...]
|
||||
}
|
||||
~~~
|
||||
|
||||
@@ -42,6 +42,7 @@ file DBFILE [ZONES... ] {
|
||||
pointing to external names. This is only really useful when CoreDNS is configured as a proxy, for
|
||||
normal authoritative serving you don't need *or* want to use this. **ADDRESS** can be an IP
|
||||
address, and IP:port or a string pointing to a file that is structured as /etc/resolv.conf.
|
||||
If no **ADDRESS** is given, CoreDNS will resolve CNAMEs against itself.
|
||||
|
||||
## Examples
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@ import (
|
||||
"testing"
|
||||
|
||||
"github.com/coredns/coredns/plugin/pkg/dnstest"
|
||||
"github.com/coredns/coredns/plugin/proxy"
|
||||
"github.com/coredns/coredns/plugin/pkg/upstream"
|
||||
"github.com/coredns/coredns/plugin/test"
|
||||
|
||||
"github.com/miekg/dns"
|
||||
@@ -74,7 +74,7 @@ func TestLookupCNAMEExternal(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatalf("Expected no error when reading zone, got %q", err)
|
||||
}
|
||||
zone.Proxy = proxy.NewLookup([]string{"8.8.8.8:53"}) // TODO(miek): point to local instance
|
||||
zone.Upstream, _ = upstream.NewUpstream([]string{"8.8.8.8:53"}) // TODO(miek): point to local instance
|
||||
|
||||
fm := File{Next: test.ErrorHandler(), Zones: Zones{Z: map[string]*Zone{name: zone}, Names: []string{name}}}
|
||||
ctx := context.TODO()
|
||||
|
||||
@@ -29,7 +29,7 @@ type (
|
||||
|
||||
// ServeDNS implements the plugin.Handle interface.
|
||||
func (f File) ServeDNS(ctx context.Context, w dns.ResponseWriter, r *dns.Msg) (int, error) {
|
||||
state := request.Request{W: w, Req: r}
|
||||
state := request.Request{W: w, Req: r, Context: ctx}
|
||||
|
||||
qname := state.Name()
|
||||
// TODO(miek): match the qname better in the map
|
||||
|
||||
@@ -378,7 +378,7 @@ func cnameForType(targets []dns.RR, origQtype uint16) []dns.RR {
|
||||
}
|
||||
|
||||
func (z *Zone) externalLookup(state request.Request, target string, qtype uint16) []dns.RR {
|
||||
m, e := z.Proxy.Lookup(state, target, qtype)
|
||||
m, e := z.Upstream.Lookup(state, target, qtype)
|
||||
if e != nil {
|
||||
// TODO(miek): debugMsg for this as well? Log?
|
||||
return nil
|
||||
|
||||
@@ -6,9 +6,8 @@ import (
|
||||
|
||||
"github.com/coredns/coredns/core/dnsserver"
|
||||
"github.com/coredns/coredns/plugin"
|
||||
"github.com/coredns/coredns/plugin/pkg/dnsutil"
|
||||
"github.com/coredns/coredns/plugin/pkg/parse"
|
||||
"github.com/coredns/coredns/plugin/proxy"
|
||||
"github.com/coredns/coredns/plugin/pkg/upstream"
|
||||
|
||||
"github.com/mholt/caddy"
|
||||
)
|
||||
@@ -90,7 +89,7 @@ func fileParse(c *caddy.Controller) (Zones, error) {
|
||||
}
|
||||
|
||||
noReload := false
|
||||
prxy := proxy.Proxy{}
|
||||
upstr := upstream.Upstream{}
|
||||
t := []string{}
|
||||
var e error
|
||||
|
||||
@@ -107,14 +106,11 @@ func fileParse(c *caddy.Controller) (Zones, error) {
|
||||
|
||||
case "upstream":
|
||||
args := c.RemainingArgs()
|
||||
if len(args) == 0 {
|
||||
return Zones{}, c.ArgErr()
|
||||
}
|
||||
ups, err := dnsutil.ParseHostPortOrFile(args...)
|
||||
upstr, err = upstream.NewUpstream(args)
|
||||
if err != nil {
|
||||
return Zones{}, err
|
||||
}
|
||||
prxy = proxy.NewLookup(ups)
|
||||
|
||||
default:
|
||||
return Zones{}, c.Errf("unknown property '%s'", c.Val())
|
||||
}
|
||||
@@ -124,7 +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
|
||||
z[origin].Upstream = upstr
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@ import (
|
||||
"sync"
|
||||
|
||||
"github.com/coredns/coredns/plugin/file/tree"
|
||||
"github.com/coredns/coredns/plugin/proxy"
|
||||
"github.com/coredns/coredns/plugin/pkg/upstream"
|
||||
"github.com/coredns/coredns/request"
|
||||
|
||||
"github.com/miekg/dns"
|
||||
@@ -30,7 +30,7 @@ type Zone struct {
|
||||
NoReload bool
|
||||
reloadMu sync.RWMutex
|
||||
ReloadShutdown chan bool
|
||||
Proxy proxy.Proxy // Proxy for looking up names during the resolution process
|
||||
Upstream upstream.Upstream // Upstream for looking up names during the resolution process
|
||||
}
|
||||
|
||||
// Apex contains the apex records of a zone: SOA, NS and their potential signatures.
|
||||
|
||||
Reference in New Issue
Block a user