Debian Codegraph @

rdata/rdata.go

raw
1 // Package rdata contains the rdata elements of all the resource records, i.e., each type that implements
2 // [codeberg.org/miekg/dns.RR].
3 //
4 // Each rdata element implements [codeberg.org/miek/dns.RDATA]. And thus the [fmt.Stringer] interface. To
5 // full print the text reprentation of an RR use the following:
6 //
7 // mx := &dns.MX{Hdr: dns.Header{Name: "miek.nl.", Class: dns.ClassINET, TTL: 3600},
8 // MX: rdata.MX{Preference: 10, Mx: "mx.miek.nl."}}
9 // fmt.Printf("%s %s\t%s", mx.Header(), dnsutil.TypeToString(dns.RRToType(mx)), mx.Data())
10 //
11 // Creating new rdata from a string can be done via [codeberg.org/miekg/dns.NewData]. See
12 // [codeberg.org/miekg/dns.TypeToRDATA] for construction functions to set the rdata in an
13 // [codeberg.org/miekg/dns.RR].
14 package rdata
15
16 import (
17 "net/netip"
18
19 "codeberg.org/miekg/dns/deleg"
20 "codeberg.org/miekg/dns/svcb"
21 )
22
23 //go:generate go run len_generate.go
24
25 // NULL data. See RFC 1035.
26 type NULL struct {
27 Null string `dns:"any"`
28 }
29
30 // CNAME data. See RFC 1034.
31 type CNAME struct {
32 Target string `dns:"cname"`
33 }
34
35 // HINFO data. See RFC 1034.
36 type HINFO struct {
37 Cpu string
38 Os string
39 }
40
41 // MB data. See RFC 1035.
42 type MB struct {
43 Mb string `dns:"cname"`
44 }
45
46 // MG data. See RFC 1035.
47 type MG struct {
48 Mg string `dns:"mname"`
49 }
50
51 // MINFO data. See RFC 1035.
52 type MINFO struct {
53 Rmail string `dns:"mname"`
54 Email string `dns:"mname"`
55 }
56
57 // MR data. See RFC 1035.
58 type MR struct {
59 Mr string `dns:"mname"`
60 }
61
62 // MF data. See RFC 1035.
63 type MF struct {
64 Mf string `dns:"cname"`
65 }
66
67 // MD data. See RFC 1035.
68 type MD struct {
69 Md string `dns:"cname"`
70 }
71
72 // MX data. See RFC 1035.
73 type MX struct {
74 Preference uint16
75 Mx string `dns:"cname"`
76 }
77
78 // AFSDB data. See RFC 1183.
79 type AFSDB struct {
80 Subtype uint16
81 Hostname string `dns:"name"`
82 }
83
84 // X25 data. See RFC 1183, Section 3.1.
85 type X25 struct {
86 PSDNAddress string
87 }
88
89 // ISDN data. See RFC 1183, Section 3.2.
90 type ISDN struct {
91 Address string
92 SubAddress string
93 }
94
95 // RT data. See RFC 1183, Section 3.3.
96 type RT struct {
97 Preference uint16
98 Host string `dns:"name"` // RFC 3597 prohibits compressing records not defined in RFC 1035.
99 }
100
101 // NS data. See RFC 1035.
102 type NS struct {
103 Ns string `dns:"cname"`
104 }
105
106 // PTR data. See RFC 1035.
107 type PTR struct {
108 Ptr string `dns:"cname"`
109 }
110
111 // RP data. See RFC 1138, Section 2.2.
112 type RP struct {
113 Mbox string `dns:"mname"`
114 Txt string `dns:"name"`
115 }
116
117 // SOA data. See RFC 1035.
118 type SOA struct {
119 Ns string `dns:"cname"`
120 // MBox is the only name that contain escapes like \. as that is the norm in how to specific email
121 // addresses in a DNS zone. No other (looks-like-a-name) in this package has this feauture, so note
122 // that functions like [codeberg.org/miekg/dnsutil.Next] and [codeberg.org/miekg/dnsutil.Prev] will hit
123 // the \. instead of jumping over it.
124 Mbox string `dns:"mname"`
125 Serial uint32
126 Refresh uint32 `dns:"ttl"`
127 Retry uint32 `dns:"ttl"`
128 Expire uint32 `dns:"ttl"`
129 Minttl uint32 `dns:"ttl"`
130 }
131
132 // TXT data. See RFC 1035.
133 type TXT struct {
134 Txt []string `dns:"txt"`
135 }
136
137 // IPN data. See https://www.iana.org/assignments/dns-parameters/IPN/ipn-completed-template.
138 type IPN struct {
139 Node uint64
140 }
141
142 // SRV data. See RFC 2782.
143 type SRV struct {
144 Priority uint16
145 Weight uint16
146 Port uint16
147 Target string `dns:"name"`
148 }
149
150 // NAPTR data. See RFC 2915.
151 type NAPTR struct {
152 Order uint16
153 Preference uint16
154 Flags string
155 Service string
156 Regexp string
157 Replacement string `dns:"name"`
158 }
159
160 // CERT data. See RFC 4398.
161 type CERT struct {
162 Type uint16
163 KeyTag uint16
164 Algorithm uint8
165 Certificate string `dns:"base64"`
166 }
167
168 // DNAME data. See RFC 2672.
169 type DNAME struct {
170 Target string `dns:"name"`
171 }
172
173 // A data. See RFC 1035.
174 type A struct {
175 Addr netip.Addr `dns:"a"`
176 }
177
178 // AAAA data. See RFC 3596.
179 type AAAA struct {
180 Addr netip.Addr `dns:"aaaa"`
181 }
182
183 // PX data. See RFC 2163.
184 type PX struct {
185 Preference uint16
186 Map822 string `dns:"name"`
187 Mapx400 string `dns:"name"`
188 }
189
190 // GPOS data. See RFC 1712.
191 type GPOS struct {
192 Longitude string
193 Latitude string
194 Altitude string
195 }
196
197 // LOC data. See RFC 1876.
198 type LOC struct {
199 Version uint8
200 Size uint8
201 HorizPre uint8
202 VertPre uint8
203 Latitude uint32
204 Longitude uint32
205 Altitude uint32
206 }
207
208 // RRSIG data. See RFC 4034 and RFC 3755.
209 type RRSIG struct {
210 TypeCovered uint16
211 Algorithm uint8
212 Labels uint8
213 OrigTTL uint32
214 Expiration uint32
215 Inception uint32
216 KeyTag uint16
217 SignerName string `dns:"name"`
218 Signature string `dns:"base64"`
219 }
220
221 // NSEC data. See RFC 4034 and RFC 3755.
222 type NSEC struct {
223 NextDomain string `dns:"name"`
224 TypeBitMap []uint16 `dns:"nsec"`
225 }
226
227 func (rd NSEC) Len() int {
228 l := len(rd.NextDomain) + 1
229 l += typeBitMapLen(rd.TypeBitMap)
230 return l
231 }
232
233 // DS data. See RFC 4034 and RFC 3658.
234 type DS struct {
235 KeyTag uint16
236 Algorithm uint8
237 DigestType uint8
238 Digest string `dns:"hex"`
239 }
240
241 // KX data. See RFC 2230.
242 type KX struct {
243 Preference uint16
244 Exchanger string `dns:"name"`
245 }
246
247 // TA data. See http://www.watson.org/~weiler/INI1999-19.pdf.
248 type TA struct {
249 KeyTag uint16
250 Algorithm uint8
251 DigestType uint8
252 Digest string `dns:"hex"`
253 }
254
255 // TALINK data. See https://www.iana.org/assignments/dns-parameters/TALINK/talink-completed-template.
256 type TALINK struct {
257 PreviousName string `dns:"name"`
258 NextName string `dns:"name"`
259 }
260
261 // SSHFP data. See RFC 4255.
262 type SSHFP struct {
263 Algorithm uint8
264 Type uint8
265 FingerPrint string `dns:"hex"`
266 }
267
268 // DNSKEY data. See RFC 4034 and RFC 3755.
269 type DNSKEY struct {
270 Flags uint16
271 Protocol uint8
272 Algorithm uint8
273 PublicKey string `dns:"base64"`
274 // Tag is 0, once KeyTag is called for this key this is filed with the actual key tag.
275 Tag uint16 `dns:"-"`
276 }
277
278 // RKEY data. See https://www.iana.org/assignments/dns-parameters/RKEY/rkey-completed-template.
279 type RKEY struct {
280 Flags uint16
281 Protocol uint8
282 Algorithm uint8
283 PublicKey string `dns:"base64"`
284 }
285
286 // NSAPPTR data. See RFC 1348.
287 type NSAPPTR struct {
288 Ptr string `dns:"name"`
289 }
290
291 // NSEC3 data. See RFC 5155.
292 type NSEC3 struct {
293 Hash uint8
294 Flags uint8
295 Iterations uint16
296 SaltLength uint8
297 Salt string `dns:"size-hex:SaltLength"`
298 HashLength uint8
299 NextDomain string `dns:"size-base32:HashLength"`
300 TypeBitMap []uint16 `dns:"nsec"`
301 }
302
303 func (rd NSEC3) Len() int {
304 l := 6 + len(rd.Salt)/2 + 1 + len(rd.NextDomain) + 1
305 l += typeBitMapLen(rd.TypeBitMap)
306 return l
307 }
308
309 // NSEC3PARAM data. See RFC 5155.
310 type NSEC3PARAM struct {
311 Hash uint8
312 Flags uint8
313 Iterations uint16
314 SaltLength uint8
315 Salt string `dns:"size-hex:SaltLength"`
316 }
317
318 // TKEY data. See RFC 2930.
319 type TKEY struct {
320 Algorithm string `dns:"name"`
321 Inception uint32
322 Expiration uint32
323 Mode uint16
324 Error uint16
325 KeySize uint16
326 Key string `dns:"size-hex:KeySize"`
327 OtherLen uint16
328 OtherData string `dns:"size-hex:OtherLen"`
329 }
330
331 // RFC3597 represents an unknown/generic data. See RFC 3597.
332 type RFC3597 struct {
333 RRType uint16 `dns:"-"` // actual type
334 Data string `dns:"hex"`
335 }
336
337 // URI data. See RFC 7553.
338 type URI struct {
339 Priority uint16
340 Weight uint16
341 Target string `dns:"any"` // Target is to be parsed as a sequence of character encoded octets according to RFC 3986.
342 }
343
344 // DHCID data. See RFC 4701.
345 type DHCID struct {
346 Digest string `dns:"base64"`
347 }
348
349 // TLSA data. See RFC 6698.
350 type TLSA struct {
351 Usage uint8
352 Selector uint8
353 MatchingType uint8
354 Certificate string `dns:"hex"`
355 }
356
357 // SMIMEA data. See RFC 8162.
358 type SMIMEA struct {
359 Usage uint8
360 Selector uint8
361 MatchingType uint8
362 Certificate string `dns:"hex"`
363 }
364
365 // HIP data. See RFC 8005.
366 type HIP struct {
367 HitLength uint8
368 PublicKeyAlgorithm uint8
369 PublicKeyLength uint16
370 Hit string `dns:"size-hex:HitLength"`
371 PublicKey string `dns:"size-base64:PublicKeyLength"`
372 RendezvousServers []string `dns:"name"`
373 }
374
375 // NINFO data. See https://www.iana.org/assignments/dns-parameters/NINFO/ninfo-completed-template.
376 type NINFO struct {
377 ZSData []string `dns:"txt"`
378 }
379
380 // NID data. See RFC 6742.
381 type NID struct {
382 Preference uint16
383 NodeID uint64 `dns:"node"`
384 }
385
386 // L32 data, See RFC 6742.
387 type L32 struct {
388 Preference uint16
389 Locator32 netip.Addr `dns:"a"`
390 }
391
392 // L64 data, See RFC 6742.
393 type L64 struct {
394 Preference uint16
395 Locator64 uint64 `dns:"node"`
396 }
397
398 // LP data. See RFC 6742.
399 type LP struct {
400 Preference uint16
401 Fqdn string `dns:"name"`
402 }
403
404 type EUI48 struct {
405 Address uint64 `dns:"uint48"`
406 }
407
408 // EUI64 data. See RFC 7043.
409 type EUI64 struct {
410 Address uint64
411 }
412
413 // CAA data. See RFC 6844.
414 type CAA struct {
415 Flag uint8
416 Tag string
417 Value string `dns:"any"` // Value is the character-string encoding of the value field as specified in RFC 1035, Section 5.1.
418 }
419
420 // UID data. Deprecated, IANA-Reserved.
421 type UID struct {
422 Uid uint32
423 }
424
425 // GID data. Deprecated, IANA-Reserved.
426 type GID struct {
427 Gid uint32
428 }
429
430 // UINFO data. Deprecated, IANA-Reserved.
431 type UINFO struct {
432 Uinfo string
433 }
434
435 // EID data. See http://ana-3.lcs.mit.edu/~jnc/nimrod/dns.txt.
436 type EID struct {
437 Endpoint string `dns:"hex"`
438 }
439
440 // NIMLOC data. See http://ana-3.lcs.mit.edu/~jnc/nimrod/dns.txt.
441 type NIMLOC struct {
442 Locator string `dns:"hex"`
443 }
444
445 // OPENPGPKEY data. See RFC 7929.
446 type OPENPGPKEY struct {
447 PublicKey string `dns:"base64"`
448 }
449
450 // CSYNC data. See RFC 7477.
451 type CSYNC struct {
452 Serial uint32
453 Flags uint16
454 TypeBitMap []uint16 `dns:"nsec"`
455 }
456
457 func (rd CSYNC) Len() int {
458 l := 4 + 2
459 l += typeBitMapLen(rd.TypeBitMap)
460 return l
461 }
462
463 // ZONEMD data, RFC 8976.
464 type ZONEMD struct {
465 Serial uint32
466 Scheme uint8
467 Hash uint8
468 Digest string `dns:"hex"`
469 }
470
471 // SVCB data. See RFC 9460.
472 type SVCB struct {
473 Priority uint16 // If zero, Value must be empty or discarded by the user of this library.
474 Target string `dns:"name"`
475 Value []svcb.Pair `dns:"pairs"`
476 }
477
478 // DELEG data. See draft https://datatracker.ietf.org/doc/draft-ietf-deleg/.
479 type DELEG struct {
480 Value []deleg.Info `dns:"infos"`
481 }
482
483 // DYNC data. See RFC 9859.
484 type DSYNC struct {
485 Type uint16
486 Scheme uint8
487 Port uint16
488 Target string `dns:"name"`
489 }
490
491 // TSIG data.
492 type TSIG struct {
493 Algorithm string `dns:"name"` // Algorithm is encoded as a name, see HmacSHAXXX contstants.
494 TimeSigned uint64 `dns:"uint48"`
495 Fudge uint16
496 MACSize uint16
497 MAC string `dns:"size-hex:MACSize"`
498 OrigID uint16 // OrigID is the original message ID, when creating a TSIG this should be set to the message ID.
499 Error uint16
500 OtherLen uint16
501 OtherData string `dns:"size-hex:OtherLen"`
502 }
503
504 // typeBitMapLen is a helper function which computes the "maximum" length of
505 // a the NSEC Type BitMap field.
506 func typeBitMapLen(bitmap []uint16) int {
507 var l int
508 var lastwindow, lastlength uint16
509 for _, t := range bitmap {
510 window := t / 256
511 length := (t-window*256)/8 + 1
512 if window > lastwindow && lastlength != 0 { // New window, jump to the new off
513 l += int(lastlength) + 2
514 lastlength = 0
515 }
516 if window < lastwindow || length < lastlength {
517 // packNsec would return Error{err: "nsec bits out of order"} here, but
518 // when computing the length, we want do be liberal.
519 continue
520 }
521 lastwindow, lastlength = window, length
522 }
523 l += int(lastlength) + 2
524 return l
525 }