-
Notifications
You must be signed in to change notification settings - Fork 22
/
provider.go
56 lines (48 loc) · 1.45 KB
/
provider.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
package secureoperator
import (
"github.com/miekg/dns"
)
// DNSQuestion represents a DNS question to be resolved by a DNS server
type DNSQuestion struct {
Name string `json:"name,omitempty"`
Type uint16 `json:"type,omitempty"`
}
// DNSRR represents a DNS record, part of a response to a DNSQuestion
type DNSRR struct {
Name string `json:"name,omitempty"`
Type uint16 `json:"type,omitempty"`
TTL uint32 `json:"TTL,omitempty"`
Data string `json:"data,omitempty"`
}
// RR transforms a DNSRR to a dns.RR
func (r DNSRR) RR() (dns.RR, error) {
hdr := dns.RR_Header{Name: r.Name, Rrtype: r.Type, Class: dns.ClassINET, Ttl: r.TTL}
str := hdr.String() + r.Data
return dns.NewRR(str)
}
// DNSRR is deprecated as of 3.0.0; use RR instead.
func (r DNSRR) DNSRR() (dns.RR, error) {
return r.RR()
}
func (r DNSRR) String() string {
hdr := dns.RR_Header{Name: r.Name, Rrtype: r.Type, Class: dns.ClassINET, Ttl: r.TTL}
return hdr.String()
}
// DNSResponse represents a complete DNS server response, to be served by the
// DNS server handler.
type DNSResponse struct {
Question []DNSQuestion
Answer []DNSRR
Authority []DNSRR
Extra []DNSRR
Truncated bool
RecursionDesired bool
RecursionAvailable bool
AuthenticatedData bool
CheckingDisabled bool
ResponseCode int
}
// Provider is an interface representing a servicer of DNS queries.
type Provider interface {
Query(DNSQuestion) (*DNSResponse, error)
}