-
Notifications
You must be signed in to change notification settings - Fork 12
/
types.go
632 lines (608 loc) · 12.7 KB
/
types.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
package fastdns
import (
"net/netip"
)
// Rcode denotes a 4bit field that specifies the response
// code for a query.
type Rcode byte
// Message Response Codes, see https://www.iana.org/assignments/dns-parameters/dns-parameters.xhtml
const (
RcodeNoError Rcode = 0 // No Error [DNS]
RcodeFormErr Rcode = 1 // Format Error [DNS]
RcodeServFail Rcode = 2 // Server Failure [DNS]
RcodeNXDomain Rcode = 3 // Non-Existent Domain [DNS]
RcodeNotImp Rcode = 4 // Not Implemented [DNS]
RcodeRefused Rcode = 5 // Query Refused [DNS]
RcodeYXDomain Rcode = 6 // Name Exists when it should not [DNS Update]
RcodeYXRRSet Rcode = 7 // RR Set Exists when it should not [DNS Update]
RcodeNXRRSet Rcode = 8 // RR Set that should exist does not [DNS Update]
RcodeNotAuth Rcode = 9 // Server Not Authoritative for zone [DNS Update]
RcodeNotZone Rcode = 10 // Name not contained in zone [DNS Update/TSIG]
RcodeBADSIG Rcode = 16 // TSIG Signature Failure [TSIG]
RcodeBADVERS Rcode = 16 // Bad OPT Version [EDNS0]
RcodeBADKEY Rcode = 17 // Key not recognized [TSIG]
RcodeBADTIME Rcode = 18 // Signature out of time window [TSIG]
RcodeBADMODE Rcode = 19 // Bad TKEY Mode [TKEY]
RcodeBADNAME Rcode = 20 // Duplicate key name [TKEY]
RcodeBADALG Rcode = 21 // Algorithm not supported [TKEY]
RcodeBADTRUNC Rcode = 22 // Bad Truncation [TSIG]
RcodeBADCOOKIE Rcode = 23 // Bad/missing Server Cookie [DNS Cookies]
)
func (c Rcode) String() string {
switch c {
case RcodeNoError:
return "NoError"
case RcodeFormErr:
return "FormErr"
case RcodeServFail:
return "ServFail"
case RcodeNXDomain:
return "NXDomain"
case RcodeNotImp:
return "NotImp"
case RcodeRefused:
return "Refused"
case RcodeYXDomain:
return "YXDomain"
case RcodeYXRRSet:
return "YXRRSet"
case RcodeNXRRSet:
return "NXRRSet"
case RcodeNotAuth:
return "NotAuth"
case RcodeNotZone:
return "NotZone"
case RcodeBADSIG: // RcodeBADVERS
return "BadSig/BadVers"
case RcodeBADKEY:
return "BadKey"
case RcodeBADTIME:
return "BadTime"
case RcodeBADMODE:
return "BadMode"
case RcodeBADNAME:
return "BadName"
case RcodeBADALG:
return "BadAlg"
case RcodeBADTRUNC:
return "BadTrunc"
case RcodeBADCOOKIE:
return "BadCookie"
}
return ""
}
// Opcode denotes a 4bit field that specified the query type.
type Opcode byte
// Wire constants and supported types.
const (
OpcodeQuery Opcode = 0
OpcodeIQuery Opcode = 1
OpcodeStatus Opcode = 2
OpcodeNotify Opcode = 4
OpcodeUpdate Opcode = 5
)
func (c Opcode) String() string {
switch c {
case OpcodeQuery:
return "Query"
case OpcodeIQuery:
return "IQuery"
case OpcodeStatus:
return "Status"
case OpcodeNotify:
return "Notify"
case OpcodeUpdate:
return "Update"
}
return ""
}
// Flags is an arbitrary 16bit represents QR, Opcode, AA, TC, RD, RA, Z and RCODE.
//
// 0 1 2 3 4 5 6 7 8 9 A B C D E F
//
// +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
// |QR| Opcode |AA|TC|RD|RA| Z | RCODE |
// +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
type Flags uint16
// QR is QR bit in Flags
func (f Flags) QR() byte {
return byte(f >> 15)
}
// Opcode is Opcode in Flags
func (f Flags) Opcode() Opcode {
return Opcode((f & 0b0111111111111111) >> 11)
}
// AA is AA bit in Flags
func (f Flags) AA() byte {
return byte((f & 0b0000010000000000) >> 10)
}
// TC is TC bit in Flags
func (f Flags) TC() byte {
return byte((f & 0b0000001000000000) >> 9)
}
// RD is RD bit in Flags
func (f Flags) RD() byte {
return byte((f & 0b0000000100000000) >> 8)
}
// RA is RA bit in Flags
func (f Flags) RA() byte {
return byte((f & 0b0000000010000000) >> 7)
}
// Z is Z bits in Flags
func (f Flags) Z() byte {
return byte((f & 0b0000000001110000) >> 4)
}
// Rcode is Rcode in Flags
func (f Flags) Rcode() Rcode {
return Rcode((f & 0b0000000000001111))
}
// Class is a DNS class.
type Class uint16
// Wire constants and supported types.
const (
ClassINET Class = 1
ClassCSNET Class = 2
ClassCHAOS Class = 3
ClassHESIOD Class = 4
ClassNONE Class = 254
ClassANY Class = 255
)
func (c Class) String() string {
switch c {
case ClassINET:
return "IN"
case ClassCSNET:
return "CS"
case ClassCHAOS:
return "CH"
case ClassHESIOD:
return "HS"
case ClassNONE:
return "NONE"
case ClassANY:
return "ANY"
}
return ""
}
// Type is a DNS type.
type Type uint16
// Wire constants and supported types.
const (
TypeNone Type = 0
TypeA Type = 1
TypeNS Type = 2
TypeMD Type = 3
TypeMF Type = 4
TypeCNAME Type = 5
TypeSOA Type = 6
TypeMB Type = 7
TypeMG Type = 8
TypeMR Type = 9
TypeNULL Type = 10
TypePTR Type = 12
TypeHINFO Type = 13
TypeMINFO Type = 14
TypeMX Type = 15
TypeTXT Type = 16
TypeRP Type = 17
TypeAFSDB Type = 18
TypeX25 Type = 19
TypeISDN Type = 20
TypeRT Type = 21
TypeNSAPPTR Type = 23
TypeSIG Type = 24
TypeKEY Type = 25
TypePX Type = 26
TypeGPOS Type = 27
TypeAAAA Type = 28
TypeLOC Type = 29
TypeNXT Type = 30
TypeEID Type = 31
TypeNIMLOC Type = 32
TypeSRV Type = 33
TypeATMA Type = 34
TypeNAPTR Type = 35
TypeKX Type = 36
TypeCERT Type = 37
TypeDNAME Type = 39
TypeOPT Type = 41 // EDNS
TypeAPL Type = 42
TypeDS Type = 43
TypeSSHFP Type = 44
TypeRRSIG Type = 46
TypeNSEC Type = 47
TypeDNSKEY Type = 48
TypeDHCID Type = 49
TypeNSEC3 Type = 50
TypeNSEC3PARAM Type = 51
TypeTLSA Type = 52
TypeSMIMEA Type = 53
TypeHIP Type = 55
TypeNINFO Type = 56
TypeRKEY Type = 57
TypeTALINK Type = 58
TypeCDS Type = 59
TypeCDNSKEY Type = 60
TypeOPENPGPKEY Type = 61
TypeCSYNC Type = 62
TypeZONEMD Type = 63
TypeSVCB Type = 64
TypeHTTPS Type = 65
TypeSPF Type = 99
TypeUINFO Type = 100
TypeUID Type = 101
TypeGID Type = 102
TypeUNSPEC Type = 103
TypeNID Type = 104
TypeL32 Type = 105
TypeL64 Type = 106
TypeLP Type = 107
TypeEUI48 Type = 108
TypeEUI64 Type = 109
TypeURI Type = 256
TypeCAA Type = 257
TypeAVC Type = 258
TypeTKEY Type = 249
TypeTSIG Type = 250
TypeIXFR Type = 251
TypeAXFR Type = 252
TypeMAILB Type = 253
TypeMAILA Type = 254
TypeANY Type = 255
TypeTA Type = 32768
TypeDLV Type = 32769
TypeReserved Type = 65535
)
func (t Type) String() string {
switch t {
case TypeNone:
return "None"
case TypeA:
return "A"
case TypeNS:
return "NS"
case TypeMD:
return "MD"
case TypeMF:
return "MF"
case TypeCNAME:
return "CNAME"
case TypeSOA:
return "SOA"
case TypeMB:
return "MB"
case TypeMG:
return "MG"
case TypeMR:
return "MR"
case TypeNULL:
return "NULL"
case TypePTR:
return "PTR"
case TypeHINFO:
return "HINFO"
case TypeMINFO:
return "MINFO"
case TypeMX:
return "MX"
case TypeTXT:
return "TXT"
case TypeRP:
return "RP"
case TypeAFSDB:
return "AFSDB"
case TypeX25:
return "X25"
case TypeISDN:
return "ISDN"
case TypeRT:
return "RT"
case TypeNSAPPTR:
return "NSAPPTR"
case TypeSIG:
return "SIG"
case TypeKEY:
return "KEY"
case TypePX:
return "PX"
case TypeGPOS:
return "GPOS"
case TypeAAAA:
return "AAAA"
case TypeLOC:
return "LOC"
case TypeNXT:
return "NXT"
case TypeEID:
return "EID"
case TypeNIMLOC:
return "NIMLOC"
case TypeSRV:
return "SRV"
case TypeATMA:
return "ATMA"
case TypeNAPTR:
return "NAPTR"
case TypeKX:
return "KX"
case TypeCERT:
return "CERT"
case TypeDNAME:
return "DNAME"
case TypeOPT:
return "OPT"
case TypeAPL:
return "APL"
case TypeDS:
return "DS"
case TypeSSHFP:
return "SSHFP"
case TypeRRSIG:
return "RRSIG"
case TypeNSEC:
return "NSEC"
case TypeDNSKEY:
return "DNSKEY"
case TypeDHCID:
return "DHCID"
case TypeNSEC3:
return "NSEC3"
case TypeNSEC3PARAM:
return "NSEC3PARAM"
case TypeTLSA:
return "TLSA"
case TypeSMIMEA:
return "SMIMEA"
case TypeHIP:
return "HIP"
case TypeNINFO:
return "NINFO"
case TypeRKEY:
return "RKEY"
case TypeTALINK:
return "TALINK"
case TypeCDS:
return "CDS"
case TypeCDNSKEY:
return "CDNSKEY"
case TypeOPENPGPKEY:
return "OPENPGPKEY"
case TypeCSYNC:
return "CSYNC"
case TypeZONEMD:
return "ZONEMD"
case TypeSVCB:
return "SVCB"
case TypeHTTPS:
return "HTTPS"
case TypeSPF:
return "SPF"
case TypeUINFO:
return "UINFO"
case TypeUID:
return "UID"
case TypeGID:
return "GID"
case TypeUNSPEC:
return "UNSPEC"
case TypeNID:
return "NID"
case TypeL32:
return "L32"
case TypeL64:
return "L64"
case TypeLP:
return "LP"
case TypeEUI48:
return "EUI48"
case TypeEUI64:
return "EUI64"
case TypeURI:
return "URI"
case TypeCAA:
return "CAA"
case TypeAVC:
return "AVC"
case TypeTKEY:
return "TKEY"
case TypeTSIG:
return "TSIG"
case TypeIXFR:
return "IXFR"
case TypeAXFR:
return "AXFR"
case TypeMAILB:
return "MAILB"
case TypeMAILA:
return "MAILA"
case TypeANY:
return "ANY"
case TypeTA:
return "TA"
case TypeDLV:
return "DLV"
case TypeReserved:
return "Reserved"
}
return ""
}
// ParseType converts a question type string into a question type value.
func ParseType(s string) (t Type) {
switch s {
case "A", "a":
t = TypeA
case "NS", "ns":
t = TypeNS
case "MD", "md":
t = TypeMD
case "MF", "mf":
t = TypeMF
case "CNAME", "cname":
t = TypeCNAME
case "SOA", "soa":
t = TypeSOA
case "MB", "mb":
t = TypeMB
case "MG", "mg":
t = TypeMG
case "MR", "mr":
t = TypeMR
case "NULL", "null":
t = TypeNULL
case "PTR", "ptr":
t = TypePTR
case "HINFO", "hinfo":
t = TypeHINFO
case "MINFO", "minfo":
t = TypeMINFO
case "MX", "mx":
t = TypeMX
case "TXT", "txt":
t = TypeTXT
case "RP", "rp":
t = TypeRP
case "AFSDB", "afsdb":
t = TypeAFSDB
case "X25", "x25":
t = TypeX25
case "ISDN", "isdn":
t = TypeISDN
case "RT", "rt":
t = TypeRT
case "NSAPPTR", "nsapptr":
t = TypeNSAPPTR
case "SIG", "sig":
t = TypeSIG
case "KEY", "key":
t = TypeKEY
case "PX", "px":
t = TypePX
case "GPOS", "gpos":
t = TypeGPOS
case "AAAA", "aaaa":
t = TypeAAAA
case "LOC", "loc":
t = TypeLOC
case "NXT", "nxt":
t = TypeNXT
case "EID", "eid":
t = TypeEID
case "NIMLOC", "nimloc":
t = TypeNIMLOC
case "SRV", "srv":
t = TypeSRV
case "ATMA", "atma":
t = TypeATMA
case "NAPTR", "naptr":
t = TypeNAPTR
case "KX", "kx":
t = TypeKX
case "CERT", "cert":
t = TypeCERT
case "DNAME", "dname":
t = TypeDNAME
case "OPT", "opt":
t = TypeOPT
case "APL", "apl":
t = TypeAPL
case "DS", "ds":
t = TypeDS
case "SSHFP", "sshfp":
t = TypeSSHFP
case "RRSIG", "rrsig":
t = TypeRRSIG
case "NSEC", "nsec":
t = TypeNSEC
case "DNSKEY", "dnskey":
t = TypeDNSKEY
case "DHCID", "dhcid":
t = TypeDHCID
case "NSEC3", "nsec3":
t = TypeNSEC3
case "NSEC3PARAM", "nsec3param":
t = TypeNSEC3PARAM
case "TLSA", "tlsa":
t = TypeTLSA
case "SMIMEA", "smimea":
t = TypeSMIMEA
case "HIP", "hip":
t = TypeHIP
case "NINFO", "ninfo":
t = TypeNINFO
case "RKEY", "rkey":
t = TypeRKEY
case "TALINK", "talink":
t = TypeTALINK
case "CDS", "cds":
t = TypeCDS
case "CDNSKEY", "cdnskey":
t = TypeCDNSKEY
case "OPENPGPKEY", "openpgpkey":
t = TypeOPENPGPKEY
case "CSYNC", "csync":
t = TypeCSYNC
case "ZONEMD", "zonemd":
t = TypeZONEMD
case "SVCB", "svcb":
t = TypeSVCB
case "HTTPS", "https":
t = TypeHTTPS
case "SPF", "spf":
t = TypeSPF
case "UINFO", "uinfo":
t = TypeUINFO
case "UID", "uid":
t = TypeUID
case "GID", "gid":
t = TypeGID
case "UNSPEC", "unspec":
t = TypeUNSPEC
case "NID", "nid":
t = TypeNID
case "L32", "l32":
t = TypeL32
case "L64", "l64":
t = TypeL64
case "LP", "lp":
t = TypeLP
case "EUI48", "eui48":
t = TypeEUI48
case "EUI64", "eui64":
t = TypeEUI64
case "URI", "uri":
t = TypeURI
case "CAA", "caa":
t = TypeCAA
case "AVC", "avc":
t = TypeAVC
case "TKEY", "tkey":
t = TypeTKEY
case "TSIG", "tsig":
t = TypeTSIG
case "IXFR", "ixfr":
t = TypeIXFR
case "AXFR", "axfr":
t = TypeAXFR
case "MAILB", "mailb":
t = TypeMAILB
case "MAILA", "maila":
t = TypeMAILA
case "ANY", "any":
t = TypeANY
case "TA", "ta":
t = TypeTA
case "DLV", "dlv":
t = TypeDLV
case "Reserved", "reserved":
t = TypeReserved
}
return
}
type NetHTTPS struct {
ALPN []string
NoDefaultALPN bool
Port uint32
IPv4Hint []netip.Addr
IPv6Hint []netip.Addr
ECH []byte
}