forked from coredns/coredns
-
Notifications
You must be signed in to change notification settings - Fork 0
/
xfr.go
52 lines (41 loc) · 1.15 KB
/
xfr.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
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
}