mirror of
				https://github.com/coredns/coredns.git
				synced 2025-10-31 10:13:14 -04:00 
			
		
		
		
	* Implement notifies for transfer plugin (#3972) * Fix notifies in transfer plugin Signed-off-by: Miek Gieben <miek@miek.nl> * Make it compile Signed-off-by: Miek Gieben <miek@miek.nl> * Port more plugins Signed-off-by: Miek Gieben <miek@miek.nl> * golint Signed-off-by: Miek Gieben <miek@miek.nl> * Fix tests Signed-off-by: Miek Gieben <miek@miek.nl> * Fix notifies in transfer plugin Signed-off-by: Miek Gieben <miek@miek.nl> * Make it compile Signed-off-by: Miek Gieben <miek@miek.nl> * Port more plugins Signed-off-by: Miek Gieben <miek@miek.nl> * golint Signed-off-by: Miek Gieben <miek@miek.nl> * Fix tests Signed-off-by: Miek Gieben <miek@miek.nl> * Fix tests Signed-off-by: Miek Gieben <miek@miek.nl> * really fix test Signed-off-by: Miek Gieben <miek@miek.nl> * Implement ixfr fallback and unify file and auto for transfering Signed-off-by: Miek Gieben <miek@miek.nl> * Add transfer tests copied and modified from #3452 Signed-off-by: Miek Gieben <miek@miek.nl> * Test correct selection of plugin Signed-off-by: Miek Gieben <miek@miek.nl> * add upstream back in Signed-off-by: Miek Gieben <miek@miek.nl> * Implement ixfr fallback and unify file and auto for transfering Signed-off-by: Miek Gieben <miek@miek.nl> * fix test Signed-off-by: Miek Gieben <miek@miek.nl> * properly merge Signed-off-by: Miek Gieben <miek@miek.nl> * Remove plugin/kubernetes/setup_transfer_test.go Signed-off-by: Yong Tang <yong.tang.github@outlook.com> Co-authored-by: Miek Gieben <miek@miek.nl>
		
			
				
	
	
		
			86 lines
		
	
	
		
			1.9 KiB
		
	
	
	
		
			Go
		
	
	
	
	
	
			
		
		
	
	
			86 lines
		
	
	
		
			1.9 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/plugin/transfer"
 | |
| 	"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
 | |
| 		transfer *transfer.Transfer
 | |
| 		loader
 | |
| 	}
 | |
| 
 | |
| 	loader struct {
 | |
| 		directory string
 | |
| 		template  string
 | |
| 		re        *regexp.Regexp
 | |
| 
 | |
| 		ReloadInterval time.Duration
 | |
| 		upstream       *upstream.Upstream // Upstream for looking up names during the resolution process.
 | |
| 	}
 | |
| )
 | |
| 
 | |
| // 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}
 | |
| 	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
 | |
| 	}
 | |
| 
 | |
| 	answer, ns, extra, result := z.Lookup(ctx, state, qname)
 | |
| 
 | |
| 	m := new(dns.Msg)
 | |
| 	m.SetReply(r)
 | |
| 	m.Authoritative = 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" }
 |