Every plugin needs to deal with EDNS0 and should call Scrub to make a message fit the client's buffer. Move this functionality into the server and wrapping the ResponseWriter into a ScrubWriter that handles these bits for us. Result: Less code and faster, because multiple chained plugins could all be calling scrub and SizeAndDo - now there is just one place. Most tests in file/* and dnssec/* needed adjusting because in those unit tests you don't see OPT RRs anymore. The DNSSEC signer was also looking at the returned OPT RR to see if it needed to sign - as those are now added by the server (and thus later), this needed to change slightly. Scrub itself still exist (for backward compat reasons), but has been made a noop. Scrub has been renamed to scrub as it should not be used by external plugins. Fixes: #2010 Signed-off-by: Miek Gieben <miek@miek.nl>
92 lines
2.1 KiB
Go
92 lines
2.1 KiB
Go
// Package auto implements an on-the-fly loading file backend.
|
|
package auto
|
|
|
|
import (
|
|
"context"
|
|
"regexp"
|
|
"time"
|
|
|
|
"github.com/coredns/coredns/plugin"
|
|
"github.com/coredns/coredns/plugin/file"
|
|
"github.com/coredns/coredns/plugin/metrics"
|
|
"github.com/coredns/coredns/plugin/pkg/upstream"
|
|
"github.com/coredns/coredns/request"
|
|
|
|
"github.com/miekg/dns"
|
|
)
|
|
|
|
type (
|
|
// Auto holds the zones and the loader configuration for automatically loading zones.
|
|
Auto struct {
|
|
Next plugin.Handler
|
|
*Zones
|
|
|
|
metrics *metrics.Metrics
|
|
loader
|
|
}
|
|
|
|
loader struct {
|
|
directory string
|
|
template string
|
|
re *regexp.Regexp
|
|
|
|
// In the future this should be something like ZoneMeta that contains all this stuff.
|
|
transferTo []string
|
|
noReload bool
|
|
upstream upstream.Upstream // Upstream for looking up names during the resolution process.
|
|
|
|
duration time.Duration
|
|
}
|
|
)
|
|
|
|
// ServeDNS implements the plugin.Handler interface.
|
|
func (a Auto) ServeDNS(ctx context.Context, w dns.ResponseWriter, r *dns.Msg) (int, error) {
|
|
state := request.Request{W: w, Req: r, Context: ctx}
|
|
qname := state.Name()
|
|
|
|
// Precheck with the origins, i.e. are we allowed to look here?
|
|
zone := plugin.Zones(a.Zones.Origins()).Matches(qname)
|
|
if zone == "" {
|
|
return plugin.NextOrFailure(a.Name(), a.Next, ctx, w, r)
|
|
}
|
|
|
|
// Now the real zone.
|
|
zone = plugin.Zones(a.Zones.Names()).Matches(qname)
|
|
|
|
a.Zones.RLock()
|
|
z, ok := a.Zones.Z[zone]
|
|
a.Zones.RUnlock()
|
|
|
|
if !ok || z == nil {
|
|
return dns.RcodeServerFailure, nil
|
|
}
|
|
|
|
if state.QType() == dns.TypeAXFR || state.QType() == dns.TypeIXFR {
|
|
xfr := file.Xfr{Zone: z}
|
|
return xfr.ServeDNS(ctx, w, r)
|
|
}
|
|
|
|
answer, ns, extra, result := z.Lookup(state, qname)
|
|
|
|
m := new(dns.Msg)
|
|
m.SetReply(r)
|
|
m.Authoritative, m.RecursionAvailable = true, true
|
|
m.Answer, m.Ns, m.Extra = answer, ns, extra
|
|
|
|
switch result {
|
|
case file.Success:
|
|
case file.NoData:
|
|
case file.NameError:
|
|
m.Rcode = dns.RcodeNameError
|
|
case file.Delegation:
|
|
m.Authoritative = false
|
|
case file.ServerFailure:
|
|
return dns.RcodeServerFailure, nil
|
|
}
|
|
|
|
w.WriteMsg(m)
|
|
return dns.RcodeSuccess, nil
|
|
}
|
|
|
|
// Name implements the Handler interface.
|
|
func (a Auto) Name() string { return "auto" }
|