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