Debian Codegraph @

types.go

raw
1 package dns
2
3 import (
4 "strconv"
5 "time"
6
7 "codeberg.org/miekg/dns/internal/dnslex"
8 "codeberg.org/miekg/dns/rdata"
9 )
10
11 // Packet formats
12
13 // Wire constants and supported types.
14 const (
15
16 // If you add one here, also add internal/dnsstrings/types.go
17
18 TypeNone uint16 = 0
19 TypeA uint16 = 1
20 TypeNS uint16 = 2
21 TypeMD uint16 = 3
22 TypeMF uint16 = 4
23 TypeCNAME uint16 = 5
24 TypeSOA uint16 = 6
25 TypeMB uint16 = 7
26 TypeMG uint16 = 8
27 TypeMR uint16 = 9
28 TypeNULL uint16 = 10
29 TypePTR uint16 = 12
30 TypeHINFO uint16 = 13
31 TypeMINFO uint16 = 14
32 TypeMX uint16 = 15
33 TypeTXT uint16 = 16
34 TypeRP uint16 = 17
35 TypeAFSDB uint16 = 18
36 TypeX25 uint16 = 19
37 TypeISDN uint16 = 20
38 TypeRT uint16 = 21
39 TypeNSAPPTR uint16 = 23
40 TypeSIG uint16 = 24
41 TypeKEY uint16 = 25
42 TypePX uint16 = 26
43 TypeGPOS uint16 = 27
44 TypeAAAA uint16 = 28
45 TypeLOC uint16 = 29
46 TypeNXT uint16 = 30
47 TypeEID uint16 = 31
48 TypeNIMLOC uint16 = 32
49 TypeSRV uint16 = 33
50 TypeATMA uint16 = 34
51 TypeNAPTR uint16 = 35
52 TypeKX uint16 = 36
53 TypeCERT uint16 = 37
54 TypeDNAME uint16 = 39
55 TypeOPT uint16 = 41
56 TypeAPL uint16 = 42 // Not implemented.
57 TypeDS uint16 = 43
58 TypeSSHFP uint16 = 44
59 TypeIPSECKEY uint16 = 45 // Not implemented.
60 TypeRRSIG uint16 = 46
61 TypeNSEC uint16 = 47
62 TypeDNSKEY uint16 = 48
63 TypeDHCID uint16 = 49
64 TypeNSEC3 uint16 = 50
65 TypeNSEC3PARAM uint16 = 51
66 TypeTLSA uint16 = 52
67 TypeSMIMEA uint16 = 53
68 TypeHIP uint16 = 55
69 TypeNINFO uint16 = 56
70 TypeRKEY uint16 = 57
71 TypeTALINK uint16 = 58
72 TypeCDS uint16 = 59
73 TypeCDNSKEY uint16 = 60
74 TypeOPENPGPKEY uint16 = 61
75 TypeCSYNC uint16 = 62
76 TypeZONEMD uint16 = 63
77 TypeSVCB uint16 = 64
78 TypeHTTPS uint16 = 65
79 TypeDSYNC uint16 = 66
80 TypeUNECE uint16 = 69 // Not implemented, see https://www.ietf.org/archive/id/draft-woodcock-faltstrom-external-registry-rrtypes-01.html.
81 TypeISO uint16 = 70 // Not implemented, see https://www.ietf.org/archive/id/draft-woodcock-faltstrom-external-registry-rrtypes-01.html.
82 TypeSPF uint16 = 99
83 TypeUINFO uint16 = 100
84 TypeUID uint16 = 101
85 TypeGID uint16 = 102
86 TypeUNSPEC uint16 = 103
87 TypeNID uint16 = 104
88 TypeL32 uint16 = 105
89 TypeL64 uint16 = 106
90 TypeLP uint16 = 107
91 TypeEUI48 uint16 = 108
92 TypeEUI64 uint16 = 109
93 TypeNXNAME uint16 = 128
94 TypeURI uint16 = 256
95 TypeCAA uint16 = 257
96 TypeAVC uint16 = 258
97 TypeAMTRELAY uint16 = 260 // Not implemented.
98 TypeRESINFO uint16 = 261
99 TypeWALLET uint16 = 262
100 TypeCLA uint16 = 263
101 TypeIPN uint16 = 264
102
103 TypeTKEY uint16 = 249
104 TypeTSIG uint16 = 250
105
106 // Valid question types only.
107 TypeIXFR uint16 = 251
108 TypeAXFR uint16 = 252
109 TypeMAILB uint16 = 253
110 TypeMAILA uint16 = 254
111 TypeANY uint16 = 255
112
113 TypeTA uint16 = 32768
114 TypeDLV uint16 = 32769
115 TypeDELEG uint16 = 65432 // Provisional type.
116 TypeDELEGPARAM uint16 = 65433 // Provisional type.
117 TypeReserved uint16 = 65535
118
119 // valid question classes only.
120 ClassINET = 1
121 ClassCSNET = 2
122 ClassCHAOS = 3
123 ClassHESIOD = 4
124 ClassNONE = 254
125 ClassANY = 255
126
127 // Message Response Codes, see https://www.iana.org/assignments/dns-parameters/dns-parameters.xhtml.
128 RcodeSuccess = 0 // NoError - No Error [DNS]
129 RcodeFormatError = 1 // FormErr - Format Error [DNS]
130 RcodeServerFailure = 2 // ServFail - Server Failure [DNS]
131 RcodeNameError = 3 // NXDomain - Non-Existent Domain [DNS]
132 RcodeNotImplemented = 4 // NotImp - Not Implemented [DNS]
133 RcodeRefused = 5 // Refused - Query Refused [DNS]
134 RcodeYXDomain = 6 // YXDomain - Name Exists when it should not [DNS Update]
135 RcodeYXRrset = 7 // YXRRSet - RR Set Exists when it should not [DNS Update]
136 RcodeNXRrset = 8 // NXRRSet - RR Set that should exist does not [DNS Update]
137 RcodeNotAuth = 9 // NotAuth - Server Not Authoritative for zone [DNS Update]
138 RcodeNotZone = 10 // NotZone - Name not contained in zone [DNS Update/TSIG]
139 RcodeStatefulNotImplemented = 11 // DSOTYPENI - DSO-TYPE Not Implemented [DSO] [DSO]
140 RcodeBadSig = 16 // BADSIG - TSIG Signature Failure [TSIG]
141 RcodeBadVers = 16 // BADVERS - Bad OPT Version [EDNS0]
142 RcodeBadKey = 17 // BADKEY - Key not recognized [TSIG]
143 RcodeBadTime = 18 // BADTIME - Signature out of time window [TSIG]
144 RcodeBadMode = 19 // BADMODE - Bad TKEY Mode [TKEY]
145 RcodeBadName = 20 // BADNAME - Duplicate key name [TKEY]
146 RcodeBadAlg = 21 // BADALG - Algorithm not supported [TKEY]
147 RcodeBadTrunc = 22 // BADTRUNC - Bad Truncation [TSIG]
148 RcodeBadCookie = 23 // BADCOOKIE - Bad/missing Server Cookie [DNS Cookies]
149
150 // Message Opcodes. There is no 3.
151 OpcodeQuery = 0
152 OpcodeIQuery = 1
153 OpcodeStatus = 2
154 OpcodeNotify = 4
155 OpcodeUpdate = 5
156 OpcodeStateful = 6
157 )
158
159 // Names for things inside RRs should be RR-name (all capitals) and than snakecase the rest.
160
161 // Used in [ZONEMD], RFC 8976.
162 const (
163 ZONEMDSchemeSimple = 1
164
165 ZONEMDHashSHA384 = 1
166 ZONEMDHashSHA512 = 2
167 )
168
169 const (
170 // Header.Bits
171 _QR = 1 << 15 // query/response (response=1)
172 _AA = 1 << 10 // authoritative
173 _TC = 1 << 9 // truncated
174 _RD = 1 << 8 // recursion desired
175 _RA = 1 << 7 // recursion available
176 _Z = 1 << 6 // Z
177 _AD = 1 << 5 // authenticated data
178 _CD = 1 << 4 // checking disabled
179
180 // EDNS0 OPT "Header.Bits", these are placed directory in a *Msg in this impl.
181 _DO = 1 << 15 // DNSSEC OK
182 _CO = 1 << 14 // Compact Answers OK
183 _DE = 1 << 13 // DELEG OK
184 )
185
186 // Various constants used [LOC]. See RFC 1876.
187 const (
188 LOCEquator = 1 << 31 // RFC 1876, Section 2.
189 LOCPrimemeridian = 1 << 31 // RFC 1876, Section 2.
190 LOCHours = 60 * 1000
191 LOCDegrees = 60 * LOCHours
192 LOCAltitudebase = 100000
193 )
194
195 // Certificate Types, see RFC 4398, Section 2.1.
196 const (
197 CERTPkix = 1 + iota
198 CERTSpki
199 CERTPgp
200 CERTIpix
201 CERTIspki
202 CERTIpgp
203 CERTAcpkix
204 CERTIAcpkix
205 CERTUri = 253
206 CERTOid = 254
207 )
208
209 // CertTypeToString converts the Cert Type to its string representation.
210 // See RFC 4398 and RFC 6944.
211 var CertTypeToString = map[uint16]string{
212 CERTPkix: "PKIX",
213 CERTSpki: "SPKI",
214 CERTPgp: "PGP",
215 CERTIpix: "IPIX",
216 CERTIspki: "ISPKI",
217 CERTIpgp: "IPGP",
218 CERTAcpkix: "ACPKIX",
219 CERTIAcpkix: "IACPKIX",
220 CERTUri: "URI",
221 CERTOid: "OID",
222 }
223
224 // NULL RR. See RFC 1035.
225 type NULL struct {
226 Hdr Header
227 rdata.NULL
228 }
229
230 func (rr *NULL) String() string {
231 // There is no presentation format; prefix string with a comment.
232 return ";" + rr.Hdr.String() + rr.Null
233 }
234
235 func (*NULL) parse(_ *dnslex.Lexer, _ string) *ParseError {
236 return &ParseError{err: "NULL records do not have a presentation format"}
237 }
238
239 // NXNAME is a meta record. See https://www.iana.org/go/draft-ietf-dnsop-compact-denial-of-existence-04
240 // Reference: https://www.iana.org/assignments/dns-parameters/dns-parameters.xhtml
241 type NXNAME struct {
242 Hdr Header
243 // Does not have any rdata
244 }
245
246 func (rr *NXNAME) Len() int { return rr.Hdr.Len() }
247 func (rr *NXNAME) String() string { return rr.Hdr.String() }
248
249 func (*NXNAME) parse(_ *dnslex.Lexer, _ string) *ParseError {
250 return &ParseError{err: "NXNAME records do not have a presentation format"}
251 }
252
253 // CNAME RR. See RFC 1034.
254 type CNAME struct {
255 Hdr Header
256 rdata.CNAME
257 }
258
259 func (rr *CNAME) String() string {
260 sb := sprintHeader(rr)
261 sb.WriteString(rr.Target)
262 s := sb.String()
263 builderPool.Put(*sb)
264 return s
265 }
266
267 // HINFO RR. See RFC 1034.
268 type HINFO struct {
269 Hdr Header
270 rdata.HINFO
271 }
272
273 func (rr *HINFO) String() string {
274 sb := sprintHeader(rr)
275 sb.WriteString(rr.HINFO.String())
276 s := sb.String()
277 builderPool.Put(*sb)
278 return s
279 }
280
281 // MB RR. See RFC 1035.
282 type MB struct {
283 Hdr Header
284 rdata.MB
285 }
286
287 func (rr *MB) String() string {
288 sb := sprintHeader(rr)
289 sb.WriteString(rr.MB.String())
290 s := sb.String()
291 builderPool.Put(*sb)
292 return s
293 }
294
295 // MG RR. See RFC 1035.
296 type MG struct {
297 Hdr Header
298 rdata.MG
299 }
300
301 func (rr *MG) String() string {
302 sb := sprintHeader(rr)
303 sb.WriteString(rr.MG.String())
304 s := sb.String()
305 builderPool.Put(*sb)
306 return s
307 }
308
309 // MINFO RR. See RFC 1035.
310 type MINFO struct {
311 Hdr Header
312 rdata.MINFO
313 }
314
315 func (rr *MINFO) String() string {
316 sb := sprintHeader(rr)
317 sb.WriteString(rr.MINFO.String())
318 s := sb.String()
319 builderPool.Put(*sb)
320 return s
321 }
322
323 // MR RR. See RFC 1035.
324 type MR struct {
325 Hdr Header
326 rdata.MR
327 }
328
329 func (rr *MR) String() string {
330 sb := sprintHeader(rr)
331 sb.WriteString(rr.MR.String())
332 s := sb.String()
333 builderPool.Put(*sb)
334 return s
335 }
336
337 // MF RR. See RFC 1035.
338 type MF struct {
339 Hdr Header
340 rdata.MF
341 }
342
343 func (rr *MF) String() string {
344 sb := sprintHeader(rr)
345 sb.WriteString(rr.MF.String())
346 s := sb.String()
347 builderPool.Put(*sb)
348 return s
349 }
350
351 // MD RR. See RFC 1035.
352 type MD struct {
353 Hdr Header
354 rdata.MD
355 }
356
357 func (rr *MD) String() string {
358 sb := sprintHeader(rr)
359 sb.WriteString(rr.MD.String())
360 s := sb.String()
361 builderPool.Put(*sb)
362 return s
363 }
364
365 // MX RR. See RFC 1035.
366 type MX struct {
367 Hdr Header
368 rdata.MX
369 }
370
371 func (rr *MX) String() string {
372 sb := sprintHeader(rr)
373 sb.WriteString(rr.MX.String())
374 s := sb.String()
375 builderPool.Put(*sb)
376 return s
377 }
378
379 // AFSDB RR. See RFC 1183.
380 type AFSDB struct {
381 Hdr Header
382 rdata.AFSDB
383 }
384
385 func (rr *AFSDB) String() string {
386 sb := sprintHeader(rr)
387 sb.WriteString(rr.AFSDB.String())
388 s := sb.String()
389 builderPool.Put(*sb)
390 return s
391 }
392
393 // X25 RR. See RFC 1183, Section 3.1.
394 type X25 struct {
395 Hdr Header
396 rdata.X25
397 }
398
399 func (rr *X25) String() string {
400 sb := sprintHeader(rr)
401 sb.WriteString(rr.X25.String())
402 s := sb.String()
403 builderPool.Put(*sb)
404 return s
405 }
406
407 // ISDN RR. See RFC 1183, Section 3.2.
408 type ISDN struct {
409 Hdr Header
410 rdata.ISDN
411 }
412
413 func (rr *ISDN) String() string {
414 sb := sprintHeader(rr)
415 sb.WriteString(rr.ISDN.String())
416 s := sb.String()
417 builderPool.Put(*sb)
418 return s
419 }
420
421 // RT RR. See RFC 1183, Section 3.3.
422 type RT struct {
423 Hdr Header
424 rdata.RT
425 }
426
427 func (rr *RT) String() string {
428 sb := sprintHeader(rr)
429 sb.WriteString(rr.RT.String())
430 s := sb.String()
431 builderPool.Put(*sb)
432 return s
433 }
434
435 // NS RR. See RFC 1035.
436 type NS struct {
437 Hdr Header
438 rdata.NS
439 }
440
441 func (rr *NS) String() string {
442 sb := sprintHeader(rr)
443 sb.WriteString(rr.NS.String())
444 s := sb.String()
445 builderPool.Put(*sb)
446 return s
447 }
448
449 // PTR RR. See RFC 1035.
450 type PTR struct {
451 Hdr Header
452 rdata.PTR
453 }
454
455 func (rr *PTR) String() string {
456 sb := sprintHeader(rr)
457 sb.WriteString(rr.PTR.String())
458 s := sb.String()
459 builderPool.Put(*sb)
460 return s
461 }
462
463 // RP RR. See RFC 1138, Section 2.2.
464 type RP struct {
465 Hdr Header
466 rdata.RP
467 }
468
469 func (rr *RP) String() string {
470 sb := sprintHeader(rr)
471 sb.WriteString(rr.RP.String())
472 s := sb.String()
473 builderPool.Put(*sb)
474 return s
475 }
476
477 // SOA RR. See RFC 1035.
478 type SOA struct {
479 Hdr Header
480 rdata.SOA
481 }
482
483 func (rr *SOA) String() string {
484 sb := sprintHeader(rr)
485 sb.WriteString(rr.SOA.String())
486 s := sb.String()
487 builderPool.Put(*sb)
488 return s
489 }
490
491 // TXT RR. See RFC 1035.
492 type TXT struct {
493 Hdr Header
494 rdata.TXT
495 }
496
497 func (rr *TXT) String() string {
498 sb := sprintHeader(rr)
499 sb.WriteString(rr.TXT.String())
500 s := sb.String()
501 builderPool.Put(*sb)
502 return s
503 }
504
505 // SPF RR. See RFC 4408, Section 3.1.1.
506 type SPF struct{ TXT }
507
508 func (rr *SPF) String() string {
509 sb := sprintHeader(rr)
510 sb.WriteString(rr.TXT.TXT.String())
511 s := sb.String()
512 builderPool.Put(*sb)
513 return s
514 }
515
516 // AVC RR. See https://www.iana.org/assignments/dns-parameters/AVC/avc-completed-template.
517 type AVC struct{ TXT }
518
519 func (rr *AVC) String() string {
520 sb := sprintHeader(rr)
521 sb.WriteString(rr.TXT.TXT.String())
522 s := sb.String()
523 builderPool.Put(*sb)
524 return s
525 }
526
527 // WALLET RR. See https://www.iana.org/assignments/dns-parameters/WALLET/wallet-completed-template.
528 type WALLET struct{ TXT }
529
530 func (rr *WALLET) String() string {
531 sb := sprintHeader(rr)
532 sb.WriteString(rr.TXT.TXT.String())
533 s := sb.String()
534 builderPool.Put(*sb)
535 return s
536 }
537
538 // CLA RR. See https://www.iana.org/assignments/dns-parameters/CLA/cla-completed-template.
539 type CLA struct{ TXT }
540
541 func (rr *CLA) String() string {
542 sb := sprintHeader(rr)
543 sb.WriteString(rr.TXT.TXT.String())
544 s := sb.String()
545 builderPool.Put(*sb)
546 return s
547 }
548
549 // IPN RR. See https://www.iana.org/assignments/dns-parameters/IPN/ipn-completed-template.
550 type IPN struct {
551 Hdr Header
552 rdata.IPN
553 }
554
555 func (rr *IPN) String() string {
556 sb := sprintHeader(rr)
557 sb.WriteString(rr.IPN.String())
558 s := sb.String()
559 builderPool.Put(*sb)
560 return s
561 }
562
563 // SRV RR. See RFC 2782.
564 type SRV struct {
565 Hdr Header
566 rdata.SRV
567 }
568
569 func (rr *SRV) String() string {
570 sb := sprintHeader(rr)
571 sb.WriteString(rr.SRV.String())
572 s := sb.String()
573 builderPool.Put(*sb)
574 return s
575 }
576
577 // NAPTR RR. See RFC 2915.
578 type NAPTR struct {
579 Hdr Header
580 rdata.NAPTR
581 }
582
583 func (rr *NAPTR) String() string {
584 sb := sprintHeader(rr)
585 sb.WriteString(rr.NAPTR.String())
586 s := sb.String()
587 builderPool.Put(*sb)
588 return s
589 }
590
591 // CERT RR. See RFC 4398.
592 type CERT struct {
593 Hdr Header
594 rdata.CERT
595 }
596
597 func (rr *CERT) String() string {
598 sb := sprintHeader(rr)
599 defer builderPool.Put(*sb)
600 sb.WriteString(rr.CERT.String())
601 return sb.String()
602 }
603
604 // DNAME RR. See RFC 2672.
605 type DNAME struct {
606 Hdr Header
607 rdata.DNAME
608 }
609
610 func (rr *DNAME) String() string {
611 sb := sprintHeader(rr)
612 sb.WriteString(rr.DNAME.String())
613 s := sb.String()
614 builderPool.Put(*sb)
615 return s
616 }
617
618 // A RR. See RFC 1035.
619 type A struct {
620 Hdr Header
621 rdata.A
622 }
623
624 func (rr *A) String() string {
625 sb := sprintHeader(rr)
626 sb.WriteString(rr.A.String())
627 s := sb.String()
628 builderPool.Put(*sb)
629 return s
630 }
631
632 // AAAA RR. See RFC 3596.
633 type AAAA struct {
634 Hdr Header
635 rdata.AAAA
636 }
637
638 func (rr *AAAA) String() string {
639 sb := sprintHeader(rr)
640 sb.WriteString(rr.AAAA.String())
641 s := sb.String()
642 builderPool.Put(*sb)
643 return s
644 }
645
646 // PX RR. See RFC 2163.
647 type PX struct {
648 Hdr Header
649 rdata.PX
650 }
651
652 func (rr *PX) String() string {
653 sb := sprintHeader(rr)
654 sb.WriteString(rr.PX.String())
655 s := sb.String()
656 builderPool.Put(*sb)
657 return s
658 }
659
660 // GPOS RR. See RFC 1712.
661 type GPOS struct {
662 Hdr Header
663 rdata.GPOS
664 }
665
666 func (rr *GPOS) String() string {
667 sb := sprintHeader(rr)
668 sb.WriteString(rr.GPOS.String())
669 s := sb.String()
670 builderPool.Put(*sb)
671 return s
672 }
673
674 // LOC RR. See RFC 1876.
675 type LOC struct {
676 Hdr Header
677 rdata.LOC
678 }
679
680 func (rr *LOC) String() string {
681 sb := sprintHeader(rr)
682 defer builderPool.Put(*sb)
683 sb.WriteString(rr.LOC.String())
684 return sb.String()
685 }
686
687 // SIG RR. See RFC 2535. The SIG RR is identical to RRSIG and nowadays only used for SIG(0), See RFC 2931.
688 type SIG struct{ RRSIG }
689
690 func (rr *SIG) String() string {
691 sb := sprintHeader(rr)
692 defer builderPool.Put(*sb)
693 sb.WriteString(rr.RRSIG.RRSIG.String())
694 return sb.String()
695 }
696
697 // NewSIG0 return a new SIG with initial fields set. This can be used SIG0 transaction signing.
698 func NewSIG0() *SIG {
699 // TODO(miek)
700 return nil
701 }
702
703 // RRSIG RR. See RFC 4034 and RFC 3755.
704 type RRSIG struct {
705 Hdr Header
706 rdata.RRSIG
707 }
708
709 func (rr *RRSIG) String() string {
710 sb := sprintHeader(rr)
711 defer builderPool.Put(*sb)
712 sb.WriteString(rr.RRSIG.String())
713 return sb.String()
714 }
715
716 // NewRRSIG returns a new RRSIG with many fields set. That can be used as a "stub" RRSIG before generating the
717 // signature. If incepexp, the inception and expiration dates, are not the given, now-300s and now+2w is used.
718 // origin (which must be in canonical form) is set as the signers name. The name of the RRSIG is set while
719 // signing.
720 func NewRRSIG(origin string, algorithm uint8, keytag uint16, incepexp ...uint32) *RRSIG {
721 s := &RRSIG{Algorithm: algorithm, KeyTag: keytag, SignerName: origin}
722 if len(incepexp) == 0 {
723 now := time.Now().Unix()
724 s.Expiration = uint32(now + (14 * 86400))
725 s.Inception = uint32(now - 300)
726 } else {
727 s.Inception = incepexp[0]
728 s.Expiration = incepexp[1]
729 }
730 return s
731 }
732
733 // NXT RR. See RFC 2535.
734 type NXT struct{ NSEC }
735
736 func (rr *NXT) String() string {
737 sb := sprintHeader(rr)
738 sb.WriteString(rr.NSEC.NSEC.String())
739 s := sb.String()
740 builderPool.Put(*sb)
741 return s
742 }
743
744 // NSEC RR. See RFC 4034 and RFC 3755.
745 type NSEC struct {
746 Hdr Header
747 rdata.NSEC
748 }
749
750 func (rr *NSEC) String() string {
751 sb := sprintHeader(rr)
752 sb.WriteString(rr.NSEC.String())
753 s := sb.String()
754 builderPool.Put(*sb)
755 return s
756 }
757
758 func (rr *NSEC) Len() int { return rr.Hdr.Len() + rr.NSEC.Len() }
759
760 // DLV RR. See RFC 4431.
761 type DLV struct{ DS }
762
763 func (rr *DLV) String() string {
764 sb := sprintHeader(rr)
765 sb.WriteString(rr.DS.DS.String())
766 s := sb.String()
767 builderPool.Put(*sb)
768 return s
769 }
770
771 // CDS RR. See RFC 7344.
772 type CDS struct{ DS }
773
774 func (rr *CDS) String() string {
775 sb := sprintHeader(rr)
776 sb.WriteString(rr.DS.DS.String())
777 s := sb.String()
778 builderPool.Put(*sb)
779 return s
780 }
781
782 // DS RR. See RFC 4034 and RFC 3658.
783 type DS struct {
784 Hdr Header
785 rdata.DS
786 }
787
788 func (rr *DS) String() string {
789 sb := sprintHeader(rr)
790 sb.WriteString(rr.DS.String())
791 s := sb.String()
792 builderPool.Put(*sb)
793 return s
794 }
795
796 // KX RR. See RFC 2230.
797 type KX struct {
798 Hdr Header
799 rdata.KX
800 }
801
802 func (rr *KX) String() string {
803 sb := sprintHeader(rr)
804 sb.WriteString(rr.KX.String())
805 s := sb.String()
806 builderPool.Put(*sb)
807 return s
808 }
809
810 // TA RR. See http://www.watson.org/~weiler/INI1999-19.pdf.
811 type TA struct {
812 Hdr Header
813 rdata.TA
814 }
815
816 func (rr *TA) String() string {
817 sb := sprintHeader(rr)
818 sb.WriteString(rr.TA.String())
819 s := sb.String()
820 builderPool.Put(*sb)
821 return s
822 }
823
824 // TALINK RR. See https://www.iana.org/assignments/dns-parameters/TALINK/talink-completed-template.
825 type TALINK struct {
826 Hdr Header
827 rdata.TALINK
828 }
829
830 func (rr *TALINK) String() string {
831 sb := sprintHeader(rr)
832 sb.WriteString(rr.TALINK.String())
833 s := sb.String()
834 builderPool.Put(*sb)
835 return s
836 }
837
838 // SSHFP RR. See RFC 4255.
839 type SSHFP struct {
840 Hdr Header
841 rdata.SSHFP
842 }
843
844 func (rr *SSHFP) String() string {
845 sb := sprintHeader(rr)
846 sb.WriteString(rr.SSHFP.String())
847 s := sb.String()
848 builderPool.Put(*sb)
849 return s
850 }
851
852 // KEY RR. See RFC 2535.
853 type KEY struct{ DNSKEY }
854
855 func (rr *KEY) String() string {
856 sb := sprintHeader(rr)
857 sb.WriteString(rr.DNSKEY.DNSKEY.String())
858 s := sb.String()
859 builderPool.Put(*sb)
860 return s
861 }
862
863 // CDNSKEY RR. See RFC 7344.
864 type CDNSKEY struct{ DNSKEY }
865
866 func (rr *CDNSKEY) String() string {
867 sb := sprintHeader(rr)
868 sb.WriteString(rr.DNSKEY.DNSKEY.String())
869 s := sb.String()
870 builderPool.Put(*sb)
871 return s
872 }
873
874 // DNSKEY RR. See RFC 4034 and RFC 3755.
875 type DNSKEY struct {
876 Hdr Header
877 rdata.DNSKEY
878 }
879
880 func (rr *DNSKEY) String() string {
881 sb := sprintHeader(rr)
882 sb.WriteString(rr.DNSKEY.String())
883 s := sb.String()
884 builderPool.Put(*sb)
885 return s
886 }
887
888 // NewDNSKEY returns a DNSKEY with good defaults for some fields. The key's flag field is set to 256.
889 func NewDNSKEY(z string, algorithm uint8) *DNSKEY {
890 k := new(DNSKEY)
891 k.Hdr.Name = z
892 k.Hdr.Class = ClassINET
893 k.Algorithm = algorithm
894 k.Flags = 256
895 k.Protocol = 3
896 return k
897 }
898
899 // RKEY RR. See https://www.iana.org/assignments/dns-parameters/RKEY/rkey-completed-template.
900 type RKEY struct {
901 Hdr Header
902 rdata.RKEY
903 }
904
905 func (rr *RKEY) String() string {
906 sb := sprintHeader(rr)
907 sb.WriteString(rr.RKEY.String())
908 s := sb.String()
909 builderPool.Put(*sb)
910 return s
911 }
912
913 // NSAPPTR RR. See RFC 1348.
914 type NSAPPTR struct {
915 Hdr Header
916 rdata.NSAPPTR
917 }
918
919 func (rr *NSAPPTR) String() string {
920 sb := sprintHeader(rr)
921 sb.WriteString(rr.NSAPPTR.String())
922 s := sb.String()
923 builderPool.Put(*sb)
924 return s
925 }
926
927 // NSEC3 RR. See RFC 5155.
928 type NSEC3 struct {
929 Hdr Header
930 rdata.NSEC3
931 }
932
933 func (rr *NSEC3) String() string {
934 sb := sprintHeader(rr)
935 defer builderPool.Put(*sb)
936 sb.WriteString(rr.NSEC3.String())
937 return sb.String()
938 }
939
940 func (rr *NSEC3) Len() int { return rr.Hdr.Len() + rr.NSEC3.Len() }
941
942 // NSEC3PARAM RR. See RFC 5155.
943 type NSEC3PARAM struct {
944 Hdr Header
945 rdata.NSEC3PARAM
946 }
947
948 func (rr *NSEC3PARAM) String() string {
949 sb := sprintHeader(rr)
950 defer builderPool.Put(*sb)
951 sb.WriteString(rr.NSEC3PARAM.String())
952 return sb.String()
953 }
954
955 // TKEY RR. See RFC 2930.
956 type TKEY struct {
957 Hdr Header
958 rdata.TKEY
959 }
960
961 // TKEY has no official presentation format, but this will suffice.
962 func (rr *TKEY) String() string {
963 sb := sprintHeader(rr)
964 sb.WriteString(rr.TKEY.String())
965 s := sb.String()
966 builderPool.Put(*sb)
967 return s
968 }
969
970 // RFC3597 represents an unknown/generic RR. See RFC 3597.
971 type RFC3597 struct {
972 Hdr Header
973 rdata.RFC3597
974 }
975
976 func (rr *RFC3597) Data() RDATA { return rr.RFC3597 }
977
978 func (rr *RFC3597) String() string {
979 sb := builderPool.Get()
980
981 sb.WriteString(rr.Hdr.Name)
982 sb.WriteByte('\t')
983 sb.WriteString(strconv.FormatInt(int64(rr.Hdr.TTL), 10))
984 sb.WriteByte('\t')
985 sb.WriteString(classToString(rr.Header().Class))
986 sb.WriteByte('\t')
987 sb.WriteString(typeToString(rr.RRType))
988 sb.WriteByte('\t')
989
990 sb.WriteString(rr.RFC3597.String())
991 s := sb.String()
992 builderPool.Put(sb)
993 return s
994 }
995
996 // Type implements the Typer interface. This is mandatory for this type as its Go type isn't indicative of the
997 // actual type it is carrying.
998 func (rr *RFC3597) Type() uint16 { return rr.RRType }
999
1000 // URI RR. See RFC 7553.
1001 type URI struct {
1002 Hdr Header
1003 rdata.URI
1004 }
1005
1006 func (rr *URI) String() string {
1007 sb := sprintHeader(rr)
1008 sb.WriteString(rr.URI.String())
1009 s := sb.String()
1010 builderPool.Put(*sb)
1011 return s
1012 }
1013
1014 // DHCID RR. See RFC 4701.
1015 type DHCID struct {
1016 Hdr Header
1017 rdata.DHCID
1018 }
1019
1020 func (rr *DHCID) String() string {
1021 sb := sprintHeader(rr)
1022 sb.WriteString(rr.DHCID.String())
1023 s := sb.String()
1024 builderPool.Put(*sb)
1025 return s
1026 }
1027
1028 // TLSA RR. See RFC 6698.
1029 type TLSA struct {
1030 Hdr Header
1031 rdata.TLSA
1032 }
1033
1034 func (rr *TLSA) String() string {
1035 sb := sprintHeader(rr)
1036 sb.WriteString(rr.TLSA.String())
1037 s := sb.String()
1038 builderPool.Put(*sb)
1039 return s
1040 }
1041
1042 // SMIMEA RR. See RFC 8162.
1043 type SMIMEA struct {
1044 Hdr Header
1045 rdata.SMIMEA
1046 }
1047
1048 func (rr *SMIMEA) String() string {
1049 sb := sprintHeader(rr)
1050 sb.WriteString(rr.SMIMEA.String())
1051 s := sb.String()
1052 builderPool.Put(*sb)
1053 return s
1054 }
1055
1056 // HIP RR. See RFC 8005.
1057 type HIP struct {
1058 Hdr Header
1059 rdata.HIP
1060 }
1061
1062 func (rr *HIP) String() string {
1063 sb := sprintHeader(rr)
1064 sb.WriteString(rr.HIP.String())
1065 s := sb.String()
1066 builderPool.Put(*sb)
1067 return s
1068 }
1069
1070 // NINFO RR. See https://www.iana.org/assignments/dns-parameters/NINFO/ninfo-completed-template.
1071 type NINFO struct {
1072 Hdr Header
1073 rdata.NINFO
1074 }
1075
1076 func (rr *NINFO) String() string {
1077 sb := sprintHeader(rr)
1078 sb.WriteString(rr.NINFO.String())
1079 s := sb.String()
1080 builderPool.Put(*sb)
1081 return s
1082 }
1083
1084 // NID RR. See RFC 6742.
1085 type NID struct {
1086 Hdr Header
1087 rdata.NID
1088 }
1089
1090 func (rr *NID) String() string {
1091 sb := sprintHeader(rr)
1092 sb.WriteString(rr.NID.String())
1093 s := sb.String()
1094 builderPool.Put(*sb)
1095 return s
1096 }
1097
1098 // L32 RR, See RFC 6742.
1099 type L32 struct {
1100 Hdr Header
1101 rdata.L32
1102 }
1103
1104 func (rr *L32) String() string {
1105 sb := sprintHeader(rr)
1106 sb.WriteString(rr.L32.String())
1107 s := sb.String()
1108 builderPool.Put(*sb)
1109 return s
1110 }
1111
1112 // L64 RR, See RFC 6742.
1113 type L64 struct {
1114 Hdr Header
1115 rdata.L64
1116 }
1117
1118 func (rr *L64) String() string {
1119 sb := sprintHeader(rr)
1120 sb.WriteString(rr.L64.String())
1121 s := sb.String()
1122 builderPool.Put(*sb)
1123 return s
1124 }
1125
1126 // LP RR. See RFC 6742.
1127 type LP struct {
1128 Hdr Header
1129 rdata.LP
1130 }
1131
1132 func (rr *LP) String() string {
1133 sb := sprintHeader(rr)
1134 sb.WriteString(rr.LP.String())
1135 s := sb.String()
1136 builderPool.Put(*sb)
1137 return s
1138 }
1139
1140 // EUI48 RR. See RFC 7043.
1141 type EUI48 struct {
1142 Hdr Header
1143 rdata.EUI48
1144 }
1145
1146 func (rr *EUI48) String() string {
1147 sb := sprintHeader(rr)
1148 sb.WriteString(rr.EUI48.String())
1149 s := sb.String()
1150 builderPool.Put(*sb)
1151 return s
1152 }
1153
1154 // EUI64 RR. See RFC 7043.
1155 type EUI64 struct {
1156 Hdr Header
1157 rdata.EUI64
1158 }
1159
1160 func (rr *EUI64) String() string {
1161 sb := sprintHeader(rr)
1162 sb.WriteString(rr.EUI64.String())
1163 s := sb.String()
1164 builderPool.Put(*sb)
1165 return s
1166 }
1167
1168 // CAA RR. See RFC 6844.
1169 type CAA struct {
1170 Hdr Header
1171 rdata.CAA
1172 }
1173
1174 func (rr *CAA) String() string {
1175 sb := sprintHeader(rr)
1176 sb.WriteString(rr.CAA.String())
1177 s := sb.String()
1178 builderPool.Put(*sb)
1179 return s
1180 }
1181
1182 // UID RR. Deprecated, IANA-Reserved.
1183 type UID struct {
1184 Hdr Header
1185 rdata.UID
1186 }
1187
1188 func (rr *UID) String() string {
1189 sb := sprintHeader(rr)
1190 sb.WriteString(rr.UID.String())
1191 s := sb.String()
1192 builderPool.Put(*sb)
1193 return s
1194 }
1195
1196 // GID RR. Deprecated, IANA-Reserved.
1197 type GID struct {
1198 Hdr Header
1199 rdata.GID
1200 }
1201
1202 func (rr *GID) String() string {
1203 sb := sprintHeader(rr)
1204 sb.WriteString(rr.GID.String())
1205 s := sb.String()
1206 builderPool.Put(*sb)
1207 return s
1208 }
1209
1210 // UINFO RR. Deprecated, IANA-Reserved.
1211 type UINFO struct {
1212 Hdr Header
1213 rdata.UINFO
1214 }
1215
1216 func (rr *UINFO) String() string {
1217 sb := sprintHeader(rr)
1218 sb.WriteString(rr.UINFO.String())
1219 s := sb.String()
1220 builderPool.Put(*sb)
1221 return s
1222 }
1223
1224 // EID RR. See http://ana-3.lcs.mit.edu/~jnc/nimrod/dns.txt.
1225 type EID struct {
1226 Hdr Header
1227 rdata.EID
1228 }
1229
1230 func (rr *EID) String() string {
1231 sb := sprintHeader(rr)
1232 sb.WriteString(rr.EID.String())
1233 s := sb.String()
1234 builderPool.Put(*sb)
1235 return s
1236 }
1237
1238 // NIMLOC RR. See http://ana-3.lcs.mit.edu/~jnc/nimrod/dns.txt.
1239 type NIMLOC struct {
1240 Hdr Header
1241 rdata.NIMLOC
1242 }
1243
1244 func (rr *NIMLOC) String() string {
1245 sb := sprintHeader(rr)
1246 sb.WriteString(rr.NIMLOC.String())
1247 s := sb.String()
1248 builderPool.Put(*sb)
1249 return s
1250 }
1251
1252 // OPENPGPKEY RR. See RFC 7929.
1253 type OPENPGPKEY struct {
1254 Hdr Header
1255 rdata.OPENPGPKEY
1256 }
1257
1258 func (rr *OPENPGPKEY) String() string {
1259 sb := sprintHeader(rr)
1260 sb.WriteString(rr.OPENPGPKEY.String())
1261 s := sb.String()
1262 builderPool.Put(*sb)
1263 return s
1264 }
1265
1266 // CSYNC RR. See RFC 7477.
1267 type CSYNC struct {
1268 Hdr Header
1269 rdata.CSYNC
1270 }
1271
1272 func (rr *CSYNC) String() string {
1273 sb := sprintHeader(rr)
1274 sb.WriteString(rr.CSYNC.String())
1275 s := sb.String()
1276 builderPool.Put(*sb)
1277 return s
1278 }
1279
1280 func (rr *CSYNC) Len() int { return rr.Hdr.Len() + rr.CSYNC.Len() }
1281
1282 // ZONEMD RR, RFC 8976.
1283 type ZONEMD struct {
1284 Hdr Header
1285 rdata.ZONEMD
1286 }
1287
1288 func (rr *ZONEMD) String() string {
1289 sb := sprintHeader(rr)
1290 sb.WriteString(rr.ZONEMD.String())
1291 s := sb.String()
1292 builderPool.Put(*sb)
1293 return s
1294 }
1295
1296 // OPT is the EDNS0 RR appended to messages to convey extra (meta) information. See RFC 6891. This record is
1297 // not (directly) found in messages as the pack and unpack function take care of this. Any EDNS0 options are
1298 // found in the [Pseudo] section of the message. There should be rarely the need to access specifics of this
1299 // RR as you can just set things directly on [Msg].
1300 type OPT struct {
1301 Hdr Header
1302 Options []EDNS0 `dns:"opt"`
1303 }
1304
1305 // See opt.go for other methods.
1306
1307 func (rr *OPT) Data() RDATA { return nil }
1308 func (rr *OPT) String() string { return "" }
1309
1310 func (rr *OPT) Len() int {
1311 l := rr.Hdr.Len()
1312 for i := range rr.Options {
1313 l += rr.Options[i].Len()
1314 }
1315 return l
1316 }
1317
1318 var _ RR = &OPT{}
1319
1320 // RESINFO RR. See RFC 9606.
1321 type RESINFO struct{ TXT }
1322
1323 func (rr *RESINFO) String() string {
1324 sb := sprintHeader(rr)
1325 sb.WriteString(rr.TXT.TXT.String())
1326 s := sb.String()
1327 builderPool.Put(*sb)
1328 return s
1329 }
1330
1331 // SVCB RR. See RFC 9460.
1332 type SVCB struct {
1333 Hdr Header
1334 rdata.SVCB
1335 }
1336
1337 func (rr *SVCB) String() string {
1338 sb := sprintHeader(rr)
1339 sb.WriteString(rr.SVCB.String())
1340 s := sb.String()
1341 builderPool.Put(*sb)
1342 return s
1343 }
1344
1345 // HTTPS RR. See RFC 9460. Everything valid for SVCB applies to HTTPS as well.
1346 // Except that the HTTPS record is intended for use with the HTTP and HTTPS protocols.
1347 type HTTPS struct{ SVCB }
1348
1349 func (rr *HTTPS) String() string {
1350 sb := sprintHeader(rr)
1351 sb.WriteString(rr.SVCB.SVCB.String())
1352 s := sb.String()
1353 builderPool.Put(*sb)
1354 return s
1355 }
1356
1357 // DELEG RR. See draft https://datatracker.ietf.org/doc/draft-ietf-deleg/.
1358 type DELEG struct {
1359 Hdr Header
1360 rdata.DELEG
1361 }
1362
1363 func (rr *DELEG) String() string {
1364 sb := sprintHeader(rr)
1365 sb.WriteString(rr.DELEG.String())
1366 s := sb.String()
1367 builderPool.Put(*sb)
1368 return s
1369 }
1370
1371 type DELEGPARAM struct{ DELEG }
1372
1373 func (rr *DELEGPARAM) String() string {
1374 sb := sprintHeader(rr)
1375 sb.WriteString(rr.DELEG.DELEG.String())
1376 s := sb.String()
1377 builderPool.Put(*sb)
1378 return s
1379 }
1380
1381 // See RFC 9859
1382 type DSYNC struct {
1383 Hdr Header
1384 rdata.DSYNC
1385 }
1386
1387 func (rr *DSYNC) String() string {
1388 sb := sprintHeader(rr)
1389 sb.WriteString(rr.DSYNC.String())
1390 s := sb.String()
1391 builderPool.Put(*sb)
1392 return s
1393 }
1394
1395 // Meta RRs
1396
1397 // ANY is a wildcard record. See RFC 1035, Section 3.2.3. ANY is named "*" there.
1398 // ANY is also used for dynamic updates (RFC 2136).
1399 type ANY struct {
1400 Hdr Header
1401 }
1402
1403 func (rr *ANY) Len() int { return rr.Hdr.Len() }
1404 func (rr *ANY) String() string { return rr.Hdr.String() }
1405
1406 func (*ANY) parse(c *dnslex.Lexer, origin string) *ParseError {
1407 return &ParseError{err: "ANY records do not have a presentation format"}
1408 }
1409
1410 // AXFR is a meta record used (solely) in question sections to ask for a zone transfer.
1411 type AXFR struct {
1412 Hdr Header
1413 }
1414
1415 func (rr *AXFR) Len() int { return rr.Hdr.Len() }
1416 func (rr *AXFR) String() string { return rr.Hdr.String() }
1417
1418 func (*AXFR) parse(c *dnslex.Lexer, origin string) *ParseError {
1419 return &ParseError{err: "AXFR records do not have a presentation format"}
1420 }
1421
1422 // IXFR is a meta record used (solely) in question sections to ask for an incremental zone transfer.
1423 type IXFR struct {
1424 Hdr Header
1425 }
1426
1427 func (rr *IXFR) Len() int { return rr.Hdr.Len() }
1428 func (rr *IXFR) String() string { return rr.Hdr.String() }
1429
1430 func (*IXFR) parse(c *dnslex.Lexer, origin string) *ParseError {
1431 return &ParseError{err: "IXFR records do not have a presentation format"}
1432 }
1433
1434 // TSIG is the RR the holds the transaction signature of a message. See RFC 2845 and RFC 4635.
1435 // A TSIG RR when created must have the [ClassANY], algorithm, timesigned, and optianal fudge factor.
1436 // The owner name is the name of the key. I.e:
1437 //
1438 // tsig := &dns.TSIG{Hdr: dns.Header{Name: "keyname.", Class: dns.ClassANY}, Algorithm: dns.HmacSHA512,
1439 // TimeSigned: uint64(time.Now().Unix())}
1440 //
1441 // See [NewTSIG] for an easier way of doing this. The TSIG record MUST be the last record in the pseudo
1442 // section of a [Msg].
1443 type TSIG struct {
1444 Hdr Header
1445 rdata.TSIG
1446 }
1447
1448 func (rr *TSIG) String() string {
1449 sb := sprintHeader(rr)
1450 sb.WriteString(rr.TSIG.String())
1451 s := sb.String()
1452 builderPool.Put(*sb)
1453 return s
1454 }
1455
1456 // NewTSIG return a new TSIG with initial fields set. If fudge is zero, the default of 300 is used.
1457 // If timesigned isn't given the current time is used via time.Now().Unix().
1458 func NewTSIG(z, algorithm string, fudge uint16, timesigned ...int64) *TSIG {
1459 t := new(TSIG)
1460 t.Hdr.Name = z
1461 t.Hdr.Class = ClassANY
1462 t.Algorithm = algorithm
1463 if fudge == 0 {
1464 fudge = 300
1465 }
1466 t.Fudge = fudge
1467 if len(timesigned) == 0 {
1468 t.TimeSigned = uint64(time.Now().Unix())
1469 } else {
1470 t.TimeSigned = uint64(timesigned[0])
1471 }
1472 return t
1473 }
1474
1475 func (*TSIG) parse(c *dnslex.Lexer, origin string) *ParseError {
1476 return &ParseError{err: "TSIG records do not have a presentation format"}
1477 }