-
Notifications
You must be signed in to change notification settings - Fork 12
/
handler.go
80 lines (68 loc) · 2.84 KB
/
handler.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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
package fastdns
import (
"net"
"net/netip"
)
// Handler is implemented by any value that implements ServeDNS.
type Handler interface {
ServeDNS(rw ResponseWriter, req *Message)
}
// Error replies to the request with the specified Rcode.
func Error(rw ResponseWriter, req *Message, rcode Rcode) {
req.SetResponseHeader(rcode, 0)
_, _ = rw.Write(req.Raw)
}
// HOST1 replies to the request with the specified Host record.
func HOST1(rw ResponseWriter, req *Message, ttl uint32, ip netip.Addr) {
req.SetResponseHeader(RcodeNoError, 1)
req.Raw = AppendHOST1Record(req.Raw, req, ttl, ip)
_, _ = rw.Write(req.Raw)
}
// HOST replies to the request with the specified Host records.
func HOST(rw ResponseWriter, req *Message, ttl uint32, ips []netip.Addr) {
req.SetResponseHeader(RcodeNoError, uint16(len(ips)))
req.Raw = AppendHOSTRecord(req.Raw, req, ttl, ips)
_, _ = rw.Write(req.Raw)
}
// CNAME replies to the request with the specified CName and Host records.
func CNAME(rw ResponseWriter, req *Message, ttl uint32, cnames []string, ips []netip.Addr) {
req.SetResponseHeader(RcodeNoError, uint16(len(cnames)+len(ips)))
req.Raw = AppendCNAMERecord(req.Raw, req, ttl, cnames, ips)
_, _ = rw.Write(req.Raw)
}
// SRV replies to the request with the specified SRV records.
func SRV(rw ResponseWriter, req *Message, ttl uint32, srvs []net.SRV) {
req.SetResponseHeader(RcodeNoError, uint16(len(srvs)))
req.Raw = AppendSRVRecord(req.Raw, req, ttl, srvs)
_, _ = rw.Write(req.Raw)
}
// NS replies to the request with the specified CName and Host records.
func NS(rw ResponseWriter, req *Message, ttl uint32, nameservers []net.NS) {
req.SetResponseHeader(RcodeNoError, uint16(len(nameservers)))
req.Raw = AppendNSRecord(req.Raw, req, ttl, nameservers)
_, _ = rw.Write(req.Raw)
}
// SOA replies to the request with the specified SOA records.
func SOA(rw ResponseWriter, req *Message, ttl uint32, mname, rname net.NS, serial, refresh, retry, expire, minimum uint32) {
req.SetResponseHeader(RcodeNoError, 1)
req.Raw = AppendSOARecord(req.Raw, req, ttl, mname, rname, serial, refresh, retry, expire, minimum)
_, _ = rw.Write(req.Raw)
}
// MX replies to the request with the specified MX records.
func MX(rw ResponseWriter, req *Message, ttl uint32, mxs []net.MX) {
req.SetResponseHeader(RcodeNoError, uint16(len(mxs)))
req.Raw = AppendMXRecord(req.Raw, req, ttl, mxs)
_, _ = rw.Write(req.Raw)
}
// PTR replies to the request with the specified PTR records.
func PTR(rw ResponseWriter, req *Message, ttl uint32, ptr string) {
req.SetResponseHeader(RcodeNoError, 1)
req.Raw = AppendPTRRecord(req.Raw, req, ttl, ptr)
_, _ = rw.Write(req.Raw)
}
// TXT replies to the request with the specified TXT records.
func TXT(rw ResponseWriter, req *Message, ttl uint32, txt string) {
req.SetResponseHeader(RcodeNoError, 1)
req.Raw = AppendTXTRecord(req.Raw, req, ttl, txt)
_, _ = rw.Write(req.Raw)
}