-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathns.go
45 lines (38 loc) · 913 Bytes
/
ns.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
// sean at shanghai 2021
package main
import (
"log"
"github.com/miekg/dns"
)
type NSHandler struct{}
func (ns *NSHandler) FillRecords(req *dns.Msg, records []DNSRecord) *dns.Msg {
m := new(dns.Msg)
m.SetReply(req)
m.Authoritative = true
rr := make([]dns.NS, len(records))
for idx, record := range records {
rr[idx].Hdr.Name = req.Question[0].Name
rr[idx].Hdr.Rrtype = dns.TypeNS
rr[idx].Hdr.Class = dns.ClassINET
rr[idx].Hdr.Ttl = record.Ttl
rr[idx].Ns = record.Ns
m.Answer = append(m.Answer, &rr[idx])
}
return m
}
func (ns *NSHandler) CheckRecord(record *DNSRecord) error {
is := GoodName(record.Ns)
if !is {
log.Println("bad ns value:", record.Ns)
return ErrBadValue
}
record.Ns = AppendDot(record.Ns)
return nil
}
func (ns *NSHandler) RRToRecord(msg dns.RR) DNSRecord {
var record DNSRecord
v := msg.(*dns.NS)
record.Ns = v.Ns
record.Ttl = v.Hdr.Ttl
return record
}