diff options
Diffstat (limited to 'dns/types.go')
-rw-r--r-- | dns/types.go | 271 |
1 files changed, 6 insertions, 265 deletions
diff --git a/dns/types.go b/dns/types.go index 8f840be..aa5112b 100644 --- a/dns/types.go +++ b/dns/types.go | |||
@@ -2,12 +2,14 @@ package dns | |||
2 | 2 | ||
3 | import ( | 3 | import ( |
4 | "fmt" | 4 | "fmt" |
5 | "net" | 5 | _ "net" |
6 | 6 | ||
7 | "code.crute.me/mcrute/go_ddns_manager/bind" | 7 | "code.crute.me/mcrute/go_ddns_manager/bind" |
8 | "github.com/miekg/dns" | 8 | "github.com/miekg/dns" |
9 | ) | 9 | ) |
10 | 10 | ||
11 | //go:generate go run ../generate_dns_types.go | ||
12 | |||
11 | func makeHeader(name string, zone *bind.Zone, t uint16, ttl int) dns.RR_Header { | 13 | func makeHeader(name string, zone *bind.Zone, t uint16, ttl int) dns.RR_Header { |
12 | return dns.RR_Header{ | 14 | return dns.RR_Header{ |
13 | Name: fmt.Sprintf("%s.%s", name, zone.Name), | 15 | Name: fmt.Sprintf("%s.%s", name, zone.Name), |
@@ -27,268 +29,7 @@ func toRRSet(z *bind.Zone, rr ...RR) []dns.RR { | |||
27 | 29 | ||
28 | type RR interface { | 30 | type RR interface { |
29 | ToDNS(*bind.Zone) dns.RR | 31 | ToDNS(*bind.Zone) dns.RR |
30 | } | 32 | FromDNS(rr dns.RR) error |
31 | 33 | MarshalJSON() ([]byte, error) | |
32 | type A struct { | 34 | UnmarshalJSON(data []byte) error |
33 | Name string | ||
34 | Ttl int | ||
35 | A net.IP | ||
36 | } | ||
37 | |||
38 | func (r *A) ToDNS(zone *bind.Zone) dns.RR { | ||
39 | return &dns.A{ | ||
40 | Hdr: makeHeader(r.Name, zone, dns.TypeA, r.Ttl), | ||
41 | A: r.A, | ||
42 | } | ||
43 | } | ||
44 | |||
45 | type AAAA struct { | ||
46 | Name string | ||
47 | Ttl int | ||
48 | AAAA net.IP | ||
49 | } | ||
50 | |||
51 | func (r *AAAA) ToDNS(zone *bind.Zone) dns.RR { | ||
52 | return &dns.AAAA{ | ||
53 | Hdr: makeHeader(r.Name, zone, dns.TypeAAAA, r.Ttl), | ||
54 | AAAA: r.AAAA, | ||
55 | } | ||
56 | } | ||
57 | |||
58 | type CAA struct { | ||
59 | Name string | ||
60 | Ttl int | ||
61 | Flag uint8 | ||
62 | Tag string | ||
63 | Value string | ||
64 | } | ||
65 | |||
66 | func (r *CAA) ToDNS(zone *bind.Zone) dns.RR { | ||
67 | return &dns.CAA{ | ||
68 | Hdr: makeHeader(r.Name, zone, dns.TypeCAA, r.Ttl), | ||
69 | Flag: r.Flag, | ||
70 | Tag: r.Tag, | ||
71 | Value: r.Value, | ||
72 | } | ||
73 | } | ||
74 | |||
75 | type CERT struct { | ||
76 | Name string | ||
77 | Ttl int | ||
78 | Type uint16 | ||
79 | KeyTag uint16 | ||
80 | Algorithm uint8 | ||
81 | Certificate string | ||
82 | } | ||
83 | |||
84 | func (r *CERT) ToDNS(zone *bind.Zone) dns.RR { | ||
85 | return &dns.CERT{ | ||
86 | Hdr: makeHeader(r.Name, zone, dns.TypeCERT, r.Ttl), | ||
87 | Type: r.Type, | ||
88 | KeyTag: r.KeyTag, | ||
89 | Algorithm: r.Algorithm, | ||
90 | Certificate: r.Certificate, | ||
91 | } | ||
92 | } | ||
93 | |||
94 | type CNAME struct { | ||
95 | Name string | ||
96 | Ttl int | ||
97 | Target string | ||
98 | } | ||
99 | |||
100 | func (r *CNAME) ToDNS(zone *bind.Zone) dns.RR { | ||
101 | return &dns.CNAME{ | ||
102 | Hdr: makeHeader(r.Name, zone, dns.TypeCNAME, r.Ttl), | ||
103 | Target: r.Target, | ||
104 | } | ||
105 | } | ||
106 | |||
107 | type DNAME struct { | ||
108 | Name string | ||
109 | Ttl int | ||
110 | Target string | ||
111 | } | ||
112 | |||
113 | func (r *DNAME) ToDNS(zone *bind.Zone) dns.RR { | ||
114 | return &dns.DNAME{ | ||
115 | Hdr: makeHeader(r.Name, zone, dns.TypeDNAME, r.Ttl), | ||
116 | Target: r.Target, | ||
117 | } | ||
118 | } | ||
119 | |||
120 | type LOC struct { | ||
121 | Name string | ||
122 | Ttl int | ||
123 | Version uint8 | ||
124 | Size uint8 | ||
125 | HorizPre uint8 | ||
126 | VertPre uint8 | ||
127 | Latitude uint32 | ||
128 | Longitude uint32 | ||
129 | Altitude uint32 | ||
130 | } | ||
131 | |||
132 | func (r *LOC) ToDNS(zone *bind.Zone) dns.RR { | ||
133 | return &dns.LOC{ | ||
134 | Hdr: makeHeader(r.Name, zone, dns.TypeLOC, r.Ttl), | ||
135 | Version: r.Version, | ||
136 | Size: r.Size, | ||
137 | HorizPre: r.HorizPre, | ||
138 | VertPre: r.VertPre, | ||
139 | Latitude: r.Latitude, | ||
140 | Longitude: r.Longitude, | ||
141 | Altitude: r.Altitude, | ||
142 | } | ||
143 | } | ||
144 | |||
145 | type MX struct { | ||
146 | Name string | ||
147 | Ttl int | ||
148 | Preference uint16 | ||
149 | Mx string | ||
150 | } | ||
151 | |||
152 | func (r *MX) ToDNS(zone *bind.Zone) dns.RR { | ||
153 | return &dns.MX{ | ||
154 | Hdr: makeHeader(r.Name, zone, dns.TypeMX, r.Ttl), | ||
155 | Preference: r.Preference, | ||
156 | Mx: r.Mx, | ||
157 | } | ||
158 | } | ||
159 | |||
160 | type NAPTR struct { | ||
161 | Name string | ||
162 | Ttl int | ||
163 | Order uint16 | ||
164 | Preference uint16 | ||
165 | Flags string | ||
166 | Service string | ||
167 | Regexp string | ||
168 | Replacement string | ||
169 | } | ||
170 | |||
171 | func (r *NAPTR) ToDNS(zone *bind.Zone) dns.RR { | ||
172 | return &dns.NAPTR{ | ||
173 | Hdr: makeHeader(r.Name, zone, dns.TypeNAPTR, r.Ttl), | ||
174 | Order: r.Order, | ||
175 | Preference: r.Preference, | ||
176 | Flags: r.Flags, | ||
177 | Service: r.Service, | ||
178 | Regexp: r.Regexp, | ||
179 | Replacement: r.Replacement, | ||
180 | } | ||
181 | } | ||
182 | |||
183 | type NS struct { | ||
184 | Name string | ||
185 | Ttl int | ||
186 | Ns string | ||
187 | } | ||
188 | |||
189 | func (r *NS) ToDNS(zone *bind.Zone) dns.RR { | ||
190 | return &dns.NS{ | ||
191 | Hdr: makeHeader(r.Name, zone, dns.TypeNS, r.Ttl), | ||
192 | Ns: r.Ns, | ||
193 | } | ||
194 | } | ||
195 | |||
196 | type OPENPGPKEY struct { | ||
197 | Name string | ||
198 | Ttl int | ||
199 | PublicKey string | ||
200 | } | ||
201 | |||
202 | func (r *OPENPGPKEY) ToDNS(zone *bind.Zone) dns.RR { | ||
203 | return &dns.OPENPGPKEY{ | ||
204 | Hdr: makeHeader(r.Name, zone, dns.TypeOPENPGPKEY, r.Ttl), | ||
205 | PublicKey: r.PublicKey, | ||
206 | } | ||
207 | } | ||
208 | |||
209 | type PTR struct { | ||
210 | Name string | ||
211 | Ttl int | ||
212 | Ptr string | ||
213 | } | ||
214 | |||
215 | func (r *PTR) ToDNS(zone *bind.Zone) dns.RR { | ||
216 | return &dns.PTR{ | ||
217 | Hdr: makeHeader(r.Name, zone, dns.TypePTR, r.Ttl), | ||
218 | Ptr: r.Ptr, | ||
219 | } | ||
220 | } | ||
221 | |||
222 | type SOA struct { | ||
223 | Name string | ||
224 | Ttl int | ||
225 | Ns string | ||
226 | Mbox string | ||
227 | Serial uint32 | ||
228 | Refresh uint32 | ||
229 | Retry uint32 | ||
230 | Expire uint32 | ||
231 | Minttl uint32 | ||
232 | } | ||
233 | |||
234 | func (r *SOA) ToDNS(zone *bind.Zone) dns.RR { | ||
235 | return &dns.SOA{ | ||
236 | Hdr: makeHeader(r.Name, zone, dns.TypeSOA, r.Ttl), | ||
237 | Ns: r.Ns, | ||
238 | Mbox: r.Mbox, | ||
239 | Serial: r.Serial, | ||
240 | Refresh: r.Refresh, | ||
241 | Retry: r.Retry, | ||
242 | Expire: r.Expire, | ||
243 | Minttl: r.Minttl, | ||
244 | } | ||
245 | } | ||
246 | |||
247 | type SRV struct { | ||
248 | Name string | ||
249 | Ttl int | ||
250 | Priority uint16 | ||
251 | Weight uint16 | ||
252 | Port uint16 | ||
253 | Target string | ||
254 | } | ||
255 | |||
256 | func (r *SRV) ToDNS(zone *bind.Zone) dns.RR { | ||
257 | return &dns.SRV{ | ||
258 | Hdr: makeHeader(r.Name, zone, dns.TypeSRV, r.Ttl), | ||
259 | Priority: r.Priority, | ||
260 | Weight: r.Weight, | ||
261 | Port: r.Port, | ||
262 | Target: r.Target, | ||
263 | } | ||
264 | } | ||
265 | |||
266 | type SSHFP struct { | ||
267 | Name string | ||
268 | Ttl int | ||
269 | Algorithm uint8 | ||
270 | Type uint8 | ||
271 | FingerPrint string | ||
272 | } | ||
273 | |||
274 | func (r *SSHFP) ToDNS(zone *bind.Zone) dns.RR { | ||
275 | return &dns.SSHFP{ | ||
276 | Hdr: makeHeader(r.Name, zone, dns.TypeSSHFP, r.Ttl), | ||
277 | Algorithm: r.Algorithm, | ||
278 | Type: r.Type, | ||
279 | FingerPrint: r.FingerPrint, | ||
280 | } | ||
281 | } | ||
282 | |||
283 | type TXT struct { | ||
284 | Name string | ||
285 | Ttl int | ||
286 | Txt []string | ||
287 | } | ||
288 | |||
289 | func (r *TXT) ToDNS(zone *bind.Zone) dns.RR { | ||
290 | return &dns.TXT{ | ||
291 | Hdr: makeHeader(r.Name, zone, dns.TypeTXT, r.Ttl), | ||
292 | Txt: r.Txt, | ||
293 | } | ||
294 | } | 35 | } |