summaryrefslogtreecommitdiff
path: root/dns/types.go
blob: 8f840be1cf1af8db2b63fdae9dd6621bec12077b (plain)
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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
package dns

import (
	"fmt"
	"net"

	"code.crute.me/mcrute/go_ddns_manager/bind"
	"github.com/miekg/dns"
)

func makeHeader(name string, zone *bind.Zone, t uint16, ttl int) dns.RR_Header {
	return dns.RR_Header{
		Name:   fmt.Sprintf("%s.%s", name, zone.Name),
		Rrtype: t,
		Class:  dns.ClassINET,
		Ttl:    uint32(ttl),
	}
}

func toRRSet(z *bind.Zone, rr ...RR) []dns.RR {
	o := []dns.RR{}
	for _, v := range rr {
		o = append(o, v.ToDNS(z))
	}
	return o
}

type RR interface {
	ToDNS(*bind.Zone) dns.RR
}

type A struct {
	Name string
	Ttl  int
	A    net.IP
}

func (r *A) ToDNS(zone *bind.Zone) dns.RR {
	return &dns.A{
		Hdr: makeHeader(r.Name, zone, dns.TypeA, r.Ttl),
		A:   r.A,
	}
}

type AAAA struct {
	Name string
	Ttl  int
	AAAA net.IP
}

func (r *AAAA) ToDNS(zone *bind.Zone) dns.RR {
	return &dns.AAAA{
		Hdr:  makeHeader(r.Name, zone, dns.TypeAAAA, r.Ttl),
		AAAA: r.AAAA,
	}
}

type CAA struct {
	Name  string
	Ttl   int
	Flag  uint8
	Tag   string
	Value string
}

func (r *CAA) ToDNS(zone *bind.Zone) dns.RR {
	return &dns.CAA{
		Hdr:   makeHeader(r.Name, zone, dns.TypeCAA, r.Ttl),
		Flag:  r.Flag,
		Tag:   r.Tag,
		Value: r.Value,
	}
}

type CERT struct {
	Name        string
	Ttl         int
	Type        uint16
	KeyTag      uint16
	Algorithm   uint8
	Certificate string
}

func (r *CERT) ToDNS(zone *bind.Zone) dns.RR {
	return &dns.CERT{
		Hdr:         makeHeader(r.Name, zone, dns.TypeCERT, r.Ttl),
		Type:        r.Type,
		KeyTag:      r.KeyTag,
		Algorithm:   r.Algorithm,
		Certificate: r.Certificate,
	}
}

type CNAME struct {
	Name   string
	Ttl    int
	Target string
}

func (r *CNAME) ToDNS(zone *bind.Zone) dns.RR {
	return &dns.CNAME{
		Hdr:    makeHeader(r.Name, zone, dns.TypeCNAME, r.Ttl),
		Target: r.Target,
	}
}

type DNAME struct {
	Name   string
	Ttl    int
	Target string
}

func (r *DNAME) ToDNS(zone *bind.Zone) dns.RR {
	return &dns.DNAME{
		Hdr:    makeHeader(r.Name, zone, dns.TypeDNAME, r.Ttl),
		Target: r.Target,
	}
}

type LOC struct {
	Name      string
	Ttl       int
	Version   uint8
	Size      uint8
	HorizPre  uint8
	VertPre   uint8
	Latitude  uint32
	Longitude uint32
	Altitude  uint32
}

func (r *LOC) ToDNS(zone *bind.Zone) dns.RR {
	return &dns.LOC{
		Hdr:       makeHeader(r.Name, zone, dns.TypeLOC, r.Ttl),
		Version:   r.Version,
		Size:      r.Size,
		HorizPre:  r.HorizPre,
		VertPre:   r.VertPre,
		Latitude:  r.Latitude,
		Longitude: r.Longitude,
		Altitude:  r.Altitude,
	}
}

type MX struct {
	Name       string
	Ttl        int
	Preference uint16
	Mx         string
}

func (r *MX) ToDNS(zone *bind.Zone) dns.RR {
	return &dns.MX{
		Hdr:        makeHeader(r.Name, zone, dns.TypeMX, r.Ttl),
		Preference: r.Preference,
		Mx:         r.Mx,
	}
}

type NAPTR struct {
	Name        string
	Ttl         int
	Order       uint16
	Preference  uint16
	Flags       string
	Service     string
	Regexp      string
	Replacement string
}

func (r *NAPTR) ToDNS(zone *bind.Zone) dns.RR {
	return &dns.NAPTR{
		Hdr:         makeHeader(r.Name, zone, dns.TypeNAPTR, r.Ttl),
		Order:       r.Order,
		Preference:  r.Preference,
		Flags:       r.Flags,
		Service:     r.Service,
		Regexp:      r.Regexp,
		Replacement: r.Replacement,
	}
}

type NS struct {
	Name string
	Ttl  int
	Ns   string
}

func (r *NS) ToDNS(zone *bind.Zone) dns.RR {
	return &dns.NS{
		Hdr: makeHeader(r.Name, zone, dns.TypeNS, r.Ttl),
		Ns:  r.Ns,
	}
}

type OPENPGPKEY struct {
	Name      string
	Ttl       int
	PublicKey string
}

func (r *OPENPGPKEY) ToDNS(zone *bind.Zone) dns.RR {
	return &dns.OPENPGPKEY{
		Hdr:       makeHeader(r.Name, zone, dns.TypeOPENPGPKEY, r.Ttl),
		PublicKey: r.PublicKey,
	}
}

type PTR struct {
	Name string
	Ttl  int
	Ptr  string
}

func (r *PTR) ToDNS(zone *bind.Zone) dns.RR {
	return &dns.PTR{
		Hdr: makeHeader(r.Name, zone, dns.TypePTR, r.Ttl),
		Ptr: r.Ptr,
	}
}

type SOA struct {
	Name    string
	Ttl     int
	Ns      string
	Mbox    string
	Serial  uint32
	Refresh uint32
	Retry   uint32
	Expire  uint32
	Minttl  uint32
}

func (r *SOA) ToDNS(zone *bind.Zone) dns.RR {
	return &dns.SOA{
		Hdr:     makeHeader(r.Name, zone, dns.TypeSOA, r.Ttl),
		Ns:      r.Ns,
		Mbox:    r.Mbox,
		Serial:  r.Serial,
		Refresh: r.Refresh,
		Retry:   r.Retry,
		Expire:  r.Expire,
		Minttl:  r.Minttl,
	}
}

type SRV struct {
	Name     string
	Ttl      int
	Priority uint16
	Weight   uint16
	Port     uint16
	Target   string
}

func (r *SRV) ToDNS(zone *bind.Zone) dns.RR {
	return &dns.SRV{
		Hdr:      makeHeader(r.Name, zone, dns.TypeSRV, r.Ttl),
		Priority: r.Priority,
		Weight:   r.Weight,
		Port:     r.Port,
		Target:   r.Target,
	}
}

type SSHFP struct {
	Name        string
	Ttl         int
	Algorithm   uint8
	Type        uint8
	FingerPrint string
}

func (r *SSHFP) ToDNS(zone *bind.Zone) dns.RR {
	return &dns.SSHFP{
		Hdr:         makeHeader(r.Name, zone, dns.TypeSSHFP, r.Ttl),
		Algorithm:   r.Algorithm,
		Type:        r.Type,
		FingerPrint: r.FingerPrint,
	}
}

type TXT struct {
	Name string
	Ttl  int
	Txt  []string
}

func (r *TXT) ToDNS(zone *bind.Zone) dns.RR {
	return &dns.TXT{
		Hdr: makeHeader(r.Name, zone, dns.TypeTXT, r.Ttl),
		Txt: r.Txt,
	}
}