Debian Codegraph @

edns_types.go

raw
1 package dns
2
3 import (
4 "encoding/binary"
5 "encoding/hex"
6 "fmt"
7 "net/netip"
8 "strconv"
9
10 "codeberg.org/miekg/dns/internal/reverse"
11 "golang.org/x/crypto/cryptobyte"
12 )
13
14 // ENDS0 option codes. See https://www.iana.org/assignments/dns-parameters#dns-parameters-11.
15 const (
16 CodeNone uint16 = 0x0
17 CodeLLQ uint16 = 0x1 // Long lived queries: http://tools.ietf.org/html/draft-sekar-dns-llq-01.
18 CodeUPDATELEASE uint16 = 0x2 // Update lease (see RFC 9664).
19 CodeNSID uint16 = 0x3 // Nsid (see RFC 5001).
20 CodeESU uint16 = 0x4 // ENUM Source-URI draft: https://datatracker.ietf.org/doc/html/draft-kaplan-enum-source-uri-00.
21 CodeDAU uint16 = 0x5 // DNSSEC Algorithm Understood.
22 CodeDHU uint16 = 0x6 // DS Hash Understood.
23 CodeN3U uint16 = 0x7 // NSEC3 Hash Understood.
24 CodeSUBNET uint16 = 0x8 // Client-subnet, see RFC 7871.
25 CodeEXPIRE uint16 = 0x9 // Expire, RFC 7314.
26 CodeCOOKIE uint16 = 0xA // Cookie, RFC 7873.
27 CodeTCPKEEPALIVE uint16 = 0xB // TCP keep alive (see RFC 7828).
28 CodePADDING uint16 = 0xC // Padding (see RFC 7830).
29 CodeKEYTAG uint16 = 0xE // Key Tag Signaling (see RFC 8145).
30 CodeEDE uint16 = 0xF // Extended DNS errors (see RFC 8914).
31 CodeREPORTING uint16 = 0x12 // EDNS0 reporting (see RFC 9567).
32 CodeZONEVERSION uint16 = 0x13 // Zone version (see RFC 9660).
33 CodeMQQUERY uint16 = 0x14 // MQTYPE-Query (see RFC 10029)
34 CodeMQRESPONSE uint16 = 0x15 // MQTYPE-Response (see RFC 10029)
35
36 CodeLOCALSTART uint16 = 0xFDE9 // Beginning of range reserved for local/experimental use (see RFC 6891).
37 CodeLOCALEND uint16 = 0xFFFE // End of range reserved for local/experimental use (see RFC 6891).
38 )
39
40 // LLQ stands for Long Lived Queries: http://tools.ietf.org/html/draft-sekar-dns-llq-01
41 // Implemented for completeness, as the EDNS0 type code is assigned.
42 //
43 // This record must be put in the pseudo section.
44 type LLQ struct {
45 Version uint16
46 Opcode uint16
47 Error uint16
48 ID uint64
49 LeaseLife uint32
50 }
51
52 func (o *LLQ) Len() int { return tlv + 18 }
53 func (o *LLQ) Data() RDATA { return o }
54 func (o *LLQ) String() string {
55 sb := sprintOptionHeader(o)
56 sprintData(sb, strconv.FormatUint(uint64(o.Version), 10), strconv.FormatUint(uint64(o.Opcode), 10),
57 strconv.FormatUint(uint64(o.Error), 10), strconv.FormatUint(o.ID, 10),
58 strconv.FormatUint(uint64(o.LeaseLife), 10))
59 s := sb.String()
60 builderPool.Put(*sb)
61 return s
62 }
63
64 // UPDATELEASE implements the EDNS0 Update Lease option (RFC 9664).
65 //
66 // The Update Lease option provides lease durations that should be associated
67 // with a given DNS Update request, and are included in responses for acknowledgement.
68 // A DNS server should automatically delete the included RRs after the lease time
69 // is over.
70 //
71 // The Update Lease option has two variants: a pre-RFC 4-byte variant and
72 // the 8-byte variant. This library only supports the post-standardization
73 // 8-byte variant.
74 //
75 // This record must be put in the pseudo section.
76 type UPDATELEASE struct {
77 Lease uint32
78 KeyLease uint32
79 }
80
81 func (o *UPDATELEASE) Len() int { return tlv + 8 }
82 func (o *UPDATELEASE) Data() RDATA { return o }
83 func (o *UPDATELEASE) String() string {
84 sb := sprintOptionHeader(o)
85 sprintData(sb, strconv.FormatUint(uint64(o.Lease), 10), strconv.FormatUint(uint64(o.KeyLease), 10))
86 s := sb.String()
87 builderPool.Put(*sb)
88 return s
89 }
90
91 // REPORTING implements the EDNS0 Reporting Channel option (RFC 9567).
92 //
93 // This record must be put in the pseudo section.
94 type REPORTING struct {
95 AgentDomain string `dns:"name"`
96 }
97
98 func (o *REPORTING) Len() int { return tlv + len(o.AgentDomain) }
99 func (o *REPORTING) Data() RDATA { return o }
100 func (o *REPORTING) String() string {
101 sb := sprintOptionHeader(o)
102 sprintData(sb, o.AgentDomain)
103 s := sb.String()
104 builderPool.Put(*sb)
105 return s
106 }
107
108 // The Cookie option is used to add a DNS Cookie to a message.
109 //
110 // The Cookie field consists out of a client cookie (RFC 7873 Section 4), that is
111 // always 8 bytes. It may then optionally be followed by the server cookie. The server
112 // cookie is of variable length, 8 to a maximum of 32 bytes. In other words:
113 //
114 // cCookie := o.Cookie[:16]
115 // sCookie := o.Cookie[16:]
116 //
117 // There is no guarantee that the Cookie string has a specific length.
118 //
119 // This record must be put in the pseudo section.
120 type COOKIE struct {
121 Cookie string `dns:"hex"`
122 }
123
124 func (o *COOKIE) Len() int { return tlv + len(o.Cookie)/2 }
125 func (o *COOKIE) Data() RDATA { return o }
126
127 // String outputs: "COOKIE 962d3a4c596914578386a9a1dbbebf9e" (depending on the cookie size). This is the presentation
128 // format.
129 func (o *COOKIE) String() string {
130 sb := sprintOptionHeader(o)
131 sb.WriteString(o.Cookie)
132 s := sb.String()
133 builderPool.Put(*sb)
134 return s
135 }
136
137 // NSID option is used to retrieve a nameserver identifier. When sending a request Nsid must be empty.
138 // The identifier is an opaque string encoded as hex.
139 //
140 // This record must be put in the pseudo section.
141 type NSID struct {
142 Nsid string `dns:"hex"`
143 }
144
145 func (o *NSID) Len() int { return tlv + len(o.Nsid)/2 }
146 func (o *NSID) Data() RDATA { return o }
147
148 // String outputs: "NSID 5573652074686520666f726365: "Use the force"
149 // This is the presentation format.
150 func (o *NSID) String() string {
151 sb := sprintOptionHeader(o)
152 sb.WriteString(o.Nsid)
153 if x, err := hex.DecodeString(o.Nsid); err == nil { // == nil
154 sb.WriteString(": \"")
155 sb.Write(x)
156 sb.WriteString("\"")
157 }
158 s := sb.String()
159 builderPool.Put(*sb)
160 return s
161 }
162
163 // PADDING option is used to add padding to a request/response. The default value of padding SHOULD be 0x0 but
164 // other values MAY be used.
165 //
166 // This record must be put in the pseudo section.
167 type PADDING struct {
168 Padding string `dns:"hex"`
169 }
170
171 func (o *PADDING) Len() int { return tlv + len(o.Padding)/2 }
172 func (o *PADDING) Data() RDATA { return o }
173 func (o *PADDING) String() string {
174 sb := sprintOptionHeader(o)
175 sb.WriteString(o.Padding)
176 s := sb.String()
177 builderPool.Put(*sb)
178 return s
179 }
180
181 // EXPIRE implements the EDNS0 option as described in RFC 7314.
182 //
183 // This record must be put in the pseudo section.
184 type EXPIRE struct {
185 // If Expire is zero this option will be empty.
186 Expire uint32
187 }
188
189 func (o *EXPIRE) Len() int { return tlv + 4 }
190 func (o *EXPIRE) Data() RDATA { return o }
191 func (o *EXPIRE) String() string {
192 sb := sprintOptionHeader(o)
193 if o.Expire == 0 {
194 s := sb.String()
195 builderPool.Put(*sb)
196 return s
197 }
198 sb.WriteString(strconv.FormatUint(uint64(o.Expire), 10))
199 s := sb.String()
200 builderPool.Put(*sb)
201 return s
202 }
203
204 // DAU implements the EDNS0 "DNSSEC Algorithm Understood" option. See RFC 6975.
205 //
206 // This record must be put in the pseudo section.
207 type DAU struct {
208 AlgCode []uint8
209 }
210
211 func (o *DAU) Len() int { return tlv + len(o.AlgCode) }
212 func (o *DAU) Data() RDATA { return o }
213 func (o *DAU) String() string {
214 sb := sprintOptionHeader(o)
215 for _, alg := range o.AlgCode {
216 sb.WriteByte(' ')
217 if a, ok := AlgorithmToString[alg]; ok {
218 sb.WriteString(a)
219 } else {
220 sb.WriteString(strconv.Itoa(int(alg)))
221 }
222 }
223 s := sb.String()
224 builderPool.Put(*sb)
225 return s
226 }
227
228 // DHU implements the EDNS0 "DS Hash Understood" option. See RFC 6975.
229 //
230 // This record must be put in the pseudo section.
231 type DHU struct {
232 AlgCode []uint8
233 }
234
235 func (o *DHU) Len() int { return tlv + len(o.AlgCode) }
236 func (o *DHU) Data() RDATA { return o }
237 func (o *DHU) String() string {
238 sb := sprintOptionHeader(o)
239 for _, alg := range o.AlgCode {
240 sb.WriteByte(' ')
241 if a, ok := AlgorithmToString[alg]; ok {
242 sb.WriteString(a)
243 } else {
244 sb.WriteString(strconv.Itoa(int(alg)))
245 }
246 }
247 s := sb.String()
248 builderPool.Put(*sb)
249 return s
250 }
251
252 // EDNS0_N3U implements the EDNS0 "NSEC3 Hash Understood" option. See RFC 6975.
253 //
254 // This record must be put in the pseudo section.
255 type N3U struct {
256 AlgCode []uint8
257 }
258
259 func (o *N3U) Len() int { return tlv + len(o.AlgCode) }
260 func (o *N3U) Data() RDATA { return o }
261 func (o *N3U) String() string {
262 sb := sprintOptionHeader(o)
263 for _, alg := range o.AlgCode {
264 sb.WriteByte(' ')
265 if a, ok := AlgorithmToString[alg]; ok {
266 sb.WriteString(a)
267 } else {
268 sb.WriteString(strconv.Itoa(int(alg)))
269 }
270 }
271 s := sb.String()
272 builderPool.Put(*sb)
273 return s
274 }
275
276 // TCPKEEPALIVE is an EDNS0 option that instructs the server to keep the TCP connection alivo. See RFC 7828.
277 //
278 // This record must be put in the pseudo section.
279 type TCPKEEPALIVE struct {
280 // Timeout is an idle timeout value for the TCP connection, specified in units of 100 milliseconds
281 Timeout uint16
282 }
283
284 func (o *TCPKEEPALIVE) Len() int {
285 if o.Timeout == 0 {
286 return tlv
287 }
288 return tlv + 2
289 }
290
291 func (o *TCPKEEPALIVE) Data() RDATA { return o }
292
293 func (o *TCPKEEPALIVE) String() string {
294 sb := sprintOptionHeader(o)
295 sb.WriteString("use tcp keep-alive")
296 if o.Timeout == 0 {
297 sb.WriteString(", timeout omitted")
298 } else {
299 fmt.Fprintf(sb, ", timeout %dms", o.Timeout*100)
300 }
301 s := sb.String()
302 builderPool.Put(*sb)
303 return s
304 }
305
306 // EDE option is used to return additional information about the cause of DNS errors. EDE stands for Extended
307 // DNS Errors. See RFC 8914.
308 //
309 // This record must be put in the pseudo section.
310 type EDE struct {
311 InfoCode uint16
312 ExtraText string
313 }
314
315 func (o *EDE) Len() int { return tlv + 2 + len(o.ExtraText) }
316 func (o *EDE) Data() RDATA { return o }
317
318 // String outputs: "EDE 15 "Blocked": "", where ExtraText is always printed, even if it's
319 // empty. This is the presentation format.
320 func (o *EDE) String() string {
321 sb := sprintOptionHeader(o)
322 sb.WriteString(strconv.FormatUint(uint64(o.InfoCode), 10))
323 if s, ok := ExtendedErrorToString[o.InfoCode]; ok {
324 sb.WriteString(" \"")
325 sb.WriteString(s)
326 sb.WriteByte('"')
327 }
328 sb.WriteString(": \"")
329 sb.WriteString(o.ExtraText)
330 sb.WriteByte('"')
331 s := sb.String()
332 builderPool.Put(*sb)
333 return s
334 }
335
336 // SUBNET is the subnet option that is used to give the remote nameserver
337 // an idea of where the client is, see RFC 7871. It can give back a different
338 // answer depending on the location or network topology.
339 //
340 // This record must be put in the pseudo section.
341 type SUBNET struct {
342 Family uint16 // 1 for IP, 2 for IP6.
343 Netmask uint8 // 32 for IPV4, 128 for IPv6.
344 Scope uint8
345 Address netip.Addr // Client IP address.
346 }
347
348 func (o *SUBNET) Len() int { return tlv + 2 + 2 + int((o.Netmask+7)/8) }
349 func (o *SUBNET) Data() RDATA { return o }
350 func (o *SUBNET) String() string {
351 sb := sprintOptionHeader(o)
352 switch {
353 case !o.Address.IsValid():
354 sb.WriteString("<nil>")
355 case o.Address.Unmap().Is4():
356 sb.WriteString(o.Address.Unmap().String())
357 default:
358 sb.WriteByte('[')
359 sb.WriteString(o.Address.String())
360 sb.WriteByte(']')
361 }
362 sb.WriteByte('/')
363 sb.WriteString(strconv.Itoa(int(o.Netmask)))
364 sb.WriteByte('/')
365 sb.WriteString(strconv.Itoa(int(o.Scope)))
366 s := sb.String()
367 builderPool.Put(*sb)
368 return s
369 }
370
371 // The ESU option for ENUM Source-URI Extension.
372 type ESU struct {
373 URI string
374 }
375
376 func (o *ESU) Len() int { return tlv + len(o.URI) }
377 func (o *ESU) Data() RDATA { return o }
378 func (o *ESU) String() string {
379 sb := sprintOptionHeader(o)
380 sb.WriteString(o.URI)
381 s := sb.String()
382 builderPool.Put(*sb)
383 return s
384 }
385
386 // The ZONEVERSION option, see RFC 9660. Only a single type (0) has been allocated, if used the [SOA] serial
387 // is put in Version. Example on how to create a ZONEVERSION:
388 //
389 // z := &ZONEVERSION{Labels: 8, Type: 0, Version: make([]byte, 4)}
390 // binary.BigEndian.PutUint32(z.Version, serial)
391 //
392 // Or if you know your binary: &ZONEVERSION{Labels: 8, Type: 0, Version: {1,2,3,4}}
393 //
394 // This record must be put in the pseudo section.
395 type ZONEVERSION struct {
396 Labels uint8
397 Type uint8
398 Version []byte
399 }
400
401 func (o *ZONEVERSION) Len() int { return tlv + 2 + len(o.Version) }
402 func (o *ZONEVERSION) Data() RDATA { return o }
403
404 // Strings outputs "ZONEVERSION 4 SOA-SERIAL 1002" as the presentation format.
405 func (o *ZONEVERSION) String() string {
406 sb := sprintOptionHeader(o)
407 sb.WriteString(strconv.Itoa(int(o.Labels)))
408 sb.WriteByte(' ')
409 switch o.Type {
410 case 0:
411 sb.WriteString("SOA-SERIAL")
412 sb.WriteByte(' ')
413 version := 0
414 if len(o.Version) == 4 {
415 version = int(binary.BigEndian.Uint32([]byte(o.Version)))
416 }
417 sb.WriteString(strconv.Itoa(version))
418 default:
419 sb.WriteString("TYPE")
420 sb.WriteString(strconv.Itoa(int(o.Type)))
421 sb.WriteByte(' ')
422 sb.Write(o.Version)
423 }
424 s := sb.String()
425 builderPool.Put(*sb)
426 return s
427 }
428
429 // MQQUERY implements the EDNS0 MQTYPE-Query option (RFC 10029).
430 //
431 // This record must be put in the pseudo section.
432 type MQQUERY struct {
433 Types []uint16
434 }
435
436 func (o *MQQUERY) Len() int { return tlv + len(o.Types)*2 }
437 func (o *MQQUERY) Data() RDATA { return o }
438 func (o *MQQUERY) String() string {
439 sb := sprintOptionHeader(o)
440 defer builderPool.Put(*sb)
441
442 switch len(o.Types) {
443 case 0:
444 return sb.String()
445 case 1:
446 sb.WriteString(typeToString(o.Types[0]))
447 return sb.String()
448 default:
449 typeToString(o.Types[0])
450 }
451 for _, t := range o.Types[1:] {
452 sb.WriteByte(' ')
453 sb.WriteString(typeToString(t))
454 }
455
456 return sb.String()
457 }
458
459 // MQRESPONSE implements the EDNS0 MQTYPE-Response option (RFC 10029).
460 //
461 // This record must be put in the pseudo section.
462 type MQRESPONSE struct {
463 Types []uint16
464 }
465
466 func (o *MQRESPONSE) Len() int { return tlv + len(o.Types)*2 }
467 func (o *MQRESPONSE) Data() RDATA { return o }
468 func (o *MQRESPONSE) String() string { x := MQQUERY(*o); return x.String() }
469
470 // KEYTAG implements the EDNS0 key tag signalling option (RFC 8145).
471 //
472 // This record must be put in the pseudo section.
473 type KEYTAG struct {
474 Types []uint16
475 }
476
477 func (o *KEYTAG) Len() int { return tlv + len(o.Types)*2 }
478 func (o *KEYTAG) Data() RDATA { return o }
479 func (o *KEYTAG) String() string {
480 sb := sprintOptionHeader(o)
481 defer builderPool.Put(*sb)
482
483 switch len(o.Types) {
484 case 0:
485 return sb.String()
486 case 1:
487 fmt.Fprintf(sb, "%d", o.Types[0])
488 return sb.String()
489 default:
490 fmt.Fprintf(sb, "%d", o.Types[0])
491 }
492 for _, t := range o.Types[1:] {
493 sb.WriteByte(' ')
494 fmt.Fprintf(sb, "%d", t)
495 }
496
497 return sb.String()
498 }
499
500 // ERFC3597 is used to represent unknown EDNS0 options.
501 type ERFC3597 struct {
502 EDNS0Code uint16 `dns:"-"`
503 Code string `dns:"hex"`
504 }
505
506 func (o *ERFC3597) Len() int { return tlv + len(o.Code)/2 }
507 func (o *ERFC3597) Data() RDATA { return o }
508 func (o *ERFC3597) String() string {
509 sb := builderPool.Get()
510 sb.WriteByte('.')
511 sb.WriteByte('\t')
512 sb.WriteByte('\t') // skip TTL
513 sb.WriteString(classToString(o.Header().Class))
514 sb.WriteByte('\t')
515 sb.WriteString(codeToString(o.EDNS0Code))
516 sb.WriteByte('\t')
517
518 sprintData(&sb, `\#`, strconv.Itoa(len(o.Code)/2), o.Code)
519 s := sb.String()
520 builderPool.Put(sb)
521 return s
522 }
523
524 // Extended DNS Error Codes (RFC 8914). These are used in the [EDE] pseudo RR.
525 const (
526 ExtendedErrorOther uint16 = iota
527 ExtendedErrorUnsupportedDNSKEYAlgorithm
528 ExtendedErrorUnsupportedDSDigestType
529 ExtendedErrorStaleAnswer
530 ExtendedErrorForgedAnswer
531 ExtendedErrorDNSSECIndeterminate
532 ExtendedErrorDNSBogus
533 ExtendedErrorSignatureExpired
534 ExtendedErrorSignatureNotYetValid
535 ExtendedErrorDNSKEYMissing
536 ExtendedErrorRRSIGsMissing
537 ExtendedErrorNoZoneKeyBitSet
538 ExtendedErrorNSECMissing
539 ExtendedErrorCachedError
540 ExtendedErrorNotReady
541 ExtendedErrorBlocked
542 ExtendedErrorCensored
543 ExtendedErrorFiltered
544 ExtendedErrorProhibited
545 ExtendedErrorStaleNXDOMAINAnswer
546 ExtendedErrorNotAuthoritative
547 ExtendedErrorNotSupported
548 ExtendedErrorNoReachableAuthority
549 ExtendedErrorNetworkError
550 ExtendedErrorInvalidData
551 ExtendedErrorSignatureExpiredBeforeValid
552 ExtendedErrorTooEarly // RFC 9250
553 ExtendedErrorUnsupportedNSEC3IterValue // RFC 9276
554 ExtendedErrorUnableToConformToPolicy
555 ExtendedErrorSynthesized
556 ExtendedErrorInvalidQueryType // RFC 9824
557 ExtendedErrorRateLimited
558 ExtendedErrorOverQuota
559 ExtendedErrorNegativeTrustAnchor
560 )
561
562 // ExtendedErrorToString maps extended error info codes to a human readable description. This is used inside
563 // the [EDE] pseudo RR.
564 var ExtendedErrorToString = map[uint16]string{
565 ExtendedErrorOther: "Other",
566 ExtendedErrorUnsupportedDNSKEYAlgorithm: "Unsupported DNSKEY Algorithm",
567 ExtendedErrorUnsupportedDSDigestType: "Unsupported DS Digest Type",
568 ExtendedErrorStaleAnswer: "Stale Answer",
569 ExtendedErrorForgedAnswer: "Forged Answer",
570 ExtendedErrorDNSSECIndeterminate: "DNSSEC Indeterminate",
571 ExtendedErrorDNSBogus: "DNSSEC Bogus",
572 ExtendedErrorSignatureExpired: "Signature Expired",
573 ExtendedErrorSignatureNotYetValid: "Signature Not Yet Valid",
574 ExtendedErrorDNSKEYMissing: "DNSKEY Missing",
575 ExtendedErrorRRSIGsMissing: "RRSIGs Missing",
576 ExtendedErrorNoZoneKeyBitSet: "No Zone Key Bit Set",
577 ExtendedErrorNSECMissing: "NSEC Missing",
578 ExtendedErrorCachedError: "Cached Error",
579 ExtendedErrorNotReady: "Not Ready",
580 ExtendedErrorBlocked: "Blocked",
581 ExtendedErrorCensored: "Censored",
582 ExtendedErrorFiltered: "Filtered",
583 ExtendedErrorProhibited: "Prohibited",
584 ExtendedErrorStaleNXDOMAINAnswer: "Stale NXDOMAIN Answer",
585 ExtendedErrorNotAuthoritative: "Not Authoritative",
586 ExtendedErrorNotSupported: "Not Supported",
587 ExtendedErrorNoReachableAuthority: "No Reachable Authority",
588 ExtendedErrorNetworkError: "Network Error",
589 ExtendedErrorInvalidData: "Invalid Data",
590 ExtendedErrorSignatureExpiredBeforeValid: "Signature Expired Before Valid",
591 ExtendedErrorTooEarly: "Too Early",
592 ExtendedErrorUnsupportedNSEC3IterValue: "Unsupported NSEC3 Iterations Value",
593 ExtendedErrorUnableToConformToPolicy: "Unable To Conform To Policy",
594 ExtendedErrorSynthesized: "Synthesized",
595 ExtendedErrorInvalidQueryType: "Invalid Query Type",
596 ExtendedErrorRateLimited: "Rate Limited",
597 ExtendedErrorOverQuota: "Over Quota",
598 ExtendedErrorNegativeTrustAnchor: "Negative Trust Anchor",
599 }
600
601 // StringToExtendedError is a map from human readable descriptions to extended error info codes.
602 var StringToExtendedError = reverse.Map(ExtendedErrorToString)
603
604 func unpackOptionCode(option EDNS0, s *cryptobyte.String) error {
605 switch x := option.(type) {
606 case *LLQ:
607 return x.unpack(s)
608 case *NSID:
609 return x.unpack(s)
610 case *PADDING:
611 return x.unpack(s)
612 case *EDE:
613 return x.unpack(s)
614 case *REPORTING:
615 return x.unpack(s)
616 case *COOKIE:
617 return x.unpack(s)
618 case *EXPIRE:
619 return x.unpack(s)
620 case *DAU:
621 return x.unpack(s)
622 case *DHU:
623 return x.unpack(s)
624 case *N3U:
625 return x.unpack(s)
626 case *TCPKEEPALIVE:
627 return x.unpack(s)
628 case *SUBNET:
629 return x.unpack(s)
630 case *ESU:
631 return x.unpack(s)
632 case *ZONEVERSION:
633 return x.unpack(s)
634 case *MQQUERY:
635 return x.unpack(s)
636 case *MQRESPONSE:
637 return x.unpack(s)
638 case *KEYTAG:
639 return x.unpack(s)
640 case *UPDATELEASE:
641 return x.unpack(s)
642 case *ERFC3597:
643 return x.unpack(s)
644 }
645 if x, ok := option.(Packer); ok {
646 msg := []byte(*s)
647 return x.Unpack(msg)
648 }
649 return fmt.Errorf("dns: no option unpack defined")
650 }
651
652 func packOptionCode(option EDNS0, msg []byte, off int) (int, error) {
653 switch x := option.(type) {
654 case *LLQ:
655 return x.pack(msg, off)
656 case *NSID:
657 return x.pack(msg, off)
658 case *PADDING:
659 return x.pack(msg, off)
660 case *EDE:
661 return x.pack(msg, off)
662 case *REPORTING:
663 return x.pack(msg, off)
664 case *COOKIE:
665 return x.pack(msg, off)
666 case *EXPIRE:
667 return x.pack(msg, off)
668 case *DAU:
669 return x.pack(msg, off)
670 case *DHU:
671 return x.pack(msg, off)
672 case *N3U:
673 return x.pack(msg, off)
674 case *TCPKEEPALIVE:
675 return x.pack(msg, off)
676 case *SUBNET:
677 return x.pack(msg, off)
678 case *ESU:
679 return x.pack(msg, off)
680 case *ZONEVERSION:
681 return x.pack(msg, off)
682 case *MQQUERY:
683 return x.pack(msg, off)
684 case *MQRESPONSE:
685 return x.pack(msg, off)
686 case *KEYTAG:
687 return x.pack(msg, off)
688 case *UPDATELEASE:
689 return x.pack(msg, off)
690 case *ERFC3597:
691 return x.pack(msg, off)
692 }
693 if x, ok := option.(Packer); ok {
694 return x.Pack(msg, off)
695 }
696 return 0, fmt.Errorf("dns: no option pack defined")
697 }
698
699 // type, length, value is the length the code (2 octets) and length (2 octets) of each EDNS0 option code.
700 const tlv = 4