mirror of
				https://github.com/coredns/coredns.git
				synced 2025-10-31 18:23:13 -04:00 
			
		
		
		
	* plugin/erratic: add axfr support Add support for axfr. This to fix and test long standing axfr issues that are hard to test if we don't support it directly in coredns. The most intriguing feature is withholding the last SOA from a response so the client needs to wait; drop (no reply) and delay is also supported. All TTLs are set to zero. Add simple tests that checks if first record is a SOA. Signed-off-by: Miek Gieben <miek@miek.nl> * more test coverage Signed-off-by: Miek Gieben <miek@miek.nl>
		
			
				
	
	
		
			53 lines
		
	
	
		
			1.1 KiB
		
	
	
	
		
			Go
		
	
	
	
	
	
			
		
		
	
	
			53 lines
		
	
	
		
			1.1 KiB
		
	
	
	
		
			Go
		
	
	
	
	
	
| package erratic
 | |
| 
 | |
| import (
 | |
| 	"strings"
 | |
| 
 | |
| 	"github.com/coredns/coredns/plugin/test"
 | |
| 	"github.com/coredns/coredns/request"
 | |
| 
 | |
| 	"github.com/miekg/dns"
 | |
| )
 | |
| 
 | |
| // allRecords returns a small zone file. The first RR must be a SOA.
 | |
| func allRecords(name string) []dns.RR {
 | |
| 	var rrs = []dns.RR{
 | |
| 		test.SOA("xx.		0	IN	SOA	sns.dns.icann.org. noc.dns.icann.org. 2018050825 7200 3600 1209600 3600"),
 | |
| 		test.NS("xx.		0	IN	NS	b.xx."),
 | |
| 		test.NS("xx.		0	IN	NS	a.xx."),
 | |
| 		test.AAAA("a.xx.	0	IN	AAAA	2001:bd8::53"),
 | |
| 		test.AAAA("b.xx.	0	IN	AAAA	2001:500::54"),
 | |
| 	}
 | |
| 
 | |
| 	for _, r := range rrs {
 | |
| 		r.Header().Name = strings.Replace(r.Header().Name, "xx.", name, 1)
 | |
| 
 | |
| 		if n, ok := r.(*dns.NS); ok {
 | |
| 			n.Ns = strings.Replace(n.Ns, "xx.", name, 1)
 | |
| 		}
 | |
| 	}
 | |
| 	return rrs
 | |
| }
 | |
| 
 | |
| func xfr(state request.Request, truncate bool) {
 | |
| 	rrs := allRecords(state.QName())
 | |
| 
 | |
| 	ch := make(chan *dns.Envelope)
 | |
| 	tr := new(dns.Transfer)
 | |
| 
 | |
| 	go func() {
 | |
| 		// So the rrs we have don't have a closing SOA, only add that when truncate is false,
 | |
| 		// so we send an incomplete AXFR.
 | |
| 		if !truncate {
 | |
| 			rrs = append(rrs, rrs[0])
 | |
| 		}
 | |
| 
 | |
| 		ch <- &dns.Envelope{RR: rrs}
 | |
| 		close(ch)
 | |
| 	}()
 | |
| 
 | |
| 	tr.Out(state.W, state.Req, ch)
 | |
| 	state.W.Hijack()
 | |
| 	return
 | |
| }
 |