aboutsummaryrefslogtreecommitdiff
path: root/plugin/pkg/upstream/upstream.go
diff options
context:
space:
mode:
Diffstat (limited to 'plugin/pkg/upstream/upstream.go')
-rw-r--r--plugin/pkg/upstream/upstream.go57
1 files changed, 17 insertions, 40 deletions
diff --git a/plugin/pkg/upstream/upstream.go b/plugin/pkg/upstream/upstream.go
index 239d3dd96..c5eba8ead 100644
--- a/plugin/pkg/upstream/upstream.go
+++ b/plugin/pkg/upstream/upstream.go
@@ -1,58 +1,35 @@
-// Package upstream abstracts a upstream lookups so that plugins
-// can handle them in an unified way.
+// Package upstream abstracts a upstream lookups so that plugins can handle them in an unified way.
package upstream
import (
+ "fmt"
+
"github.com/miekg/dns"
"github.com/coredns/coredns/core/dnsserver"
"github.com/coredns/coredns/plugin/pkg/nonwriter"
- "github.com/coredns/coredns/plugin/pkg/parse"
- "github.com/coredns/coredns/plugin/proxy"
"github.com/coredns/coredns/request"
)
-// Upstream is used to resolve CNAME targets
-type Upstream struct {
- self bool
- Forward *proxy.Proxy
-}
+// Upstream is used to resolve CNAME or other external targets via CoreDNS itself.
+type Upstream struct{}
-// New creates a new Upstream for given destination(s). If dests is empty it default to upstreaming to
-// the coredns process.
-func New(dests []string) (Upstream, error) {
- u := Upstream{}
- if len(dests) == 0 {
- u.self = true
- return u, nil
- }
- u.self = false
- ups, err := parse.HostPortOrFile(dests...)
- if err != nil {
- return u, err
- }
- p := proxy.NewLookup(ups)
- u.Forward = &p
- return u, nil
-}
+// New creates a new Upstream to resolve names using the the coredns process.
+func New() *Upstream { return &Upstream{} }
// Lookup routes lookups to our selves or forward to a remote.
-func (u Upstream) Lookup(state request.Request, name string, typ uint16) (*dns.Msg, error) {
- if u.self {
- req := new(dns.Msg)
- req.SetQuestion(name, typ)
-
- nw := nonwriter.New(state.W)
- server := state.Context.Value(dnsserver.Key{}).(*dnsserver.Server)
+func (u *Upstream) Lookup(state request.Request, name string, typ uint16) (*dns.Msg, error) {
+ server, ok := state.Context.Value(dnsserver.Key{}).(*dnsserver.Server)
+ if !ok {
+ return nil, fmt.Errorf("no full server is running")
+ }
- server.ServeDNS(state.Context, nw, req)
+ req := new(dns.Msg)
+ req.SetQuestion(name, typ)
- return nw.Msg, nil
- }
+ nw := nonwriter.New(state.W)
- if u.Forward != nil {
- return u.Forward.Lookup(state, name, typ)
- }
+ server.ServeDNS(state.Context, nw, req)
- return nil, nil
+ return nw.Msg, nil
}