-
Notifications
You must be signed in to change notification settings - Fork 2
/
helpers.go
68 lines (58 loc) · 1.66 KB
/
helpers.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
package nomad
import (
"net"
"github.com/hashicorp/nomad/api"
"github.com/miekg/dns"
)
func addSRVRecord(m *dns.Msg, s *api.ServiceRegistration, header dns.RR_Header, originalQName string, addr net.IP, ttl uint32) error {
srvRecord := &dns.SRV{
Hdr: header,
Target: originalQName,
Port: uint16(s.Port),
Priority: 10,
Weight: 10,
}
m.Answer = append(m.Answer, srvRecord)
if addr.To4() == nil {
addExtrasToAAAARecord(m, originalQName, ttl, addr)
} else {
addExtrasToARecord(m, originalQName, ttl, addr)
}
return nil
}
func addExtrasToARecord(m *dns.Msg, originalQName string, ttl uint32, addr net.IP) {
header := dns.RR_Header{
Name: originalQName,
Rrtype: dns.TypeA,
Class: dns.ClassINET,
Ttl: ttl,
}
m.Extra = append(m.Extra, &dns.A{Hdr: header, A: addr})
}
func addExtrasToAAAARecord(m *dns.Msg, originalQName string, ttl uint32, addr net.IP) {
header := dns.RR_Header{
Name: originalQName,
Rrtype: dns.TypeAAAA,
Class: dns.ClassINET,
Ttl: ttl,
}
m.Extra = append(m.Extra, &dns.AAAA{Hdr: header, AAAA: addr})
}
func addARecord(m *dns.Msg, header dns.RR_Header, addr net.IP) {
m.Answer = append(m.Answer, &dns.A{Hdr: header, A: addr})
}
func addAAAARecord(m *dns.Msg, header dns.RR_Header, addr net.IP) {
m.Answer = append(m.Answer, &dns.AAAA{Hdr: header, AAAA: addr})
}
func createSOARecord(originalQName string, ttl uint32) *dns.SOA {
return &dns.SOA{
Hdr: dns.RR_Header{Name: dns.Fqdn(originalQName), Rrtype: dns.TypeSOA, Class: dns.ClassINET, Ttl: ttl},
Ns: "ns1." + originalQName,
Mbox: "hostmaster." + zone,
Serial: 0,
Refresh: 3600,
Retry: 600,
Expire: 86400,
Minttl: 30,
}
}