Skip to main content

sawp_dns/
enums.rs

1use num_enum::TryFromPrimitive;
2
3use std::convert::TryFrom;
4
5#[derive(Clone, Copy, Debug, PartialEq, Eq, TryFromPrimitive)]
6#[repr(u16)]
7pub enum RecordType {
8    /// Address record
9    A = 1,
10    /// Name server record
11    NS = 2,
12    /// Obsolete
13    MD = 3,
14    /// Obsolete
15    MF = 4,
16    /// Canonical name record
17    CNAME = 5,
18    /// Start of authority record
19    SOA = 6,
20    /// Unlikely to be adopted. See https://tools.ietf.org/html/rfc2505
21    MB = 7,
22    /// Unlikely to be adopted. See https://tools.ietf.org/html/rfc2505
23    MG = 8,
24    /// Unlikely to be adopted. See https://tools.ietf.org/html/rfc2505
25    MR = 9,
26    /// Obsolete
27    NUL = 10,
28    /// Not to be relied upon. See https://tools.ietf.org/html/rfc1123
29    WKS = 11,
30    /// PTR resource record (pointer to a canonical name)
31    PTR = 12,
32    /// Host information
33    HINFO = 13,
34    /// Unlikely to be adopted. See https://tools.ietf.org/html/rfc2505
35    MINFO = 14,
36    /// Mail exchange record
37    MX = 15,
38    /// Text record
39    TXT = 16,
40    /// Responsible person
41    RP = 17,
42    /// AFS database record
43    AFSDB = 18,
44    /// Maps a domain name to a PSDN address number
45    X25 = 19,
46    /// Maps a domain name to an ISDN telephone number
47    ISDN = 20,
48    /// Specifies intermediate host routing to host with the name of the RT-record
49    RT = 21,
50    /// Maps a domain name to an NSAP address
51    NSAP = 22,
52    /// Facilitates translation from NSAP address to DNS name
53    NSAPPTR = 23,
54    /// Signature - obsolete
55    SIG = 24,
56    /// Key record - obsolete
57    KEY = 25,
58    /// Pointer to X.400/RFC822 mapping information
59    PX = 26,
60    /// A more limited early version of LOC
61    GPOS = 27,
62    /// IPv6 address record
63    AAAA = 28,
64    /// Location record
65    LOC = 29,
66    /// Obsolete
67    NXT = 30,
68    /// Never made it to RFC status. See https://tools.ietf.org/html/draft-ietf-nimrod-dns-00
69    EID = 31,
70    /// Never made it to RFC status. See https://tools.ietf.org/html/draft-ietf-nimrod-dns-00
71    NIMLOC = 32,
72    /// Service locator
73    SRV = 33,
74    /// Defined by the ATM forum committee
75    ATMA = 34,
76    /// Naming authority pointer
77    NAPTR = 35,
78    /// Key exchanger record
79    KX = 36,
80    /// Certificate record
81    CERT = 37,
82    /// Obsolete
83    A6 = 38,
84    /// Delegation name record
85    DNAME = 39,
86    /// Never made it to RFC status. See https://tools.ietf.org/html/draft-eastlake-kitchen-sink
87    SINK = 40,
88    /// Option (needed to support EDNS)
89    OPT = 41,
90    /// Address prefix list
91    APL = 42,
92    /// Delegation signer
93    DS = 43,
94    /// SSH public key fingerprint
95    SSHFP = 44,
96    /// IPsec key
97    IPSECKEY = 45,
98    /// DNSSEC signature
99    RRSIG = 46,
100    /// Next Secure record
101    NSEC = 47,
102    /// DNS Key record
103    DNSKEY = 48,
104    /// DHCP identifier
105    DHCID = 49,
106    /// Next Secure record version 3
107    NSEC3 = 50,
108    /// NSEC3 parameters
109    NSEC3PARAM = 51,
110    /// TLSA certificate association
111    TLSA = 52,
112    /// S/MIME cert association
113    SMIMEA = 53,
114    /// Host Identity Protocol
115    HIP = 55,
116    /// Expired without adoption by IETF
117    NINFO = 56,
118    /// Expired without adoption by IETF
119    RKEY = 57,
120    /// Never made it to RFC status. See https://tools.ietf.org/html/draft-wijngaards-dnsop-trust-history-02
121    TALINK = 58,
122    /// Child DS
123    CDS = 59,
124    /// Child DNSKEY
125    CDNSKEY = 60,
126    /// OpenPGP public key record
127    OPENPGPKEY = 61,
128    /// Child-to-parent synchronization
129    CSYNC = 62,
130    /// Draft: see https://tools.ietf.org/html/draft-ietf-dnsop-dns-zone-digest-14
131    ZONEMD = 63,
132    /// Draft: see https://datatracker.ietf.org/doc/draft-ietf-dnsop-svcb-https/00
133    SVCB = 64,
134    /// Draft: see https://datatracker.ietf.org/doc/draft-ietf-dnsop-svcb-https/00
135    HTTPS = 65,
136    /// Obsolete
137    SPF = 99,
138    /// IANA reserved
139    UINFO = 100,
140    /// IANA reserved
141    UID = 101,
142    /// IANA reserved
143    GID = 102,
144    /// IANA reserved
145    UNSPEC = 103,
146    /// Experimental: see https://tools.ietf.org/html/rfc6742
147    NID = 104,
148    /// Experimental: see https://tools.ietf.org/html/rfc6742
149    L32 = 105,
150    /// Experimental: see https://tools.ietf.org/html/rfc6742
151    L64 = 106,
152    /// Experimental: see https://tools.ietf.org/html/rfc6742
153    LP = 107,
154    /// MAC address (EUI-48)
155    EUI48 = 108,
156    /// MAC address (EUI-64)
157    EUI64 = 109,
158    /// Transaction key record
159    TKEY = 249,
160    /// Transaction signature
161    TSIG = 250,
162    /// Incremental zone transfer
163    IXFR = 251,
164    /// Authoritative zone transfer
165    AXFR = 252,
166    /// Returns MB, MG, MR, or MINFO. Unlikely to be adopted.
167    MAILB = 253,
168    /// Obsolete
169    MAILA = 254,
170    /// All cached records
171    ANY = 255,
172    /// Uniform resource identifier
173    URI = 256,
174    /// Certification authority authorization
175    CAA = 257,
176    /// Application visibility and control
177    AVC = 258,
178    /// Digital object architecture
179    DOA = 259,
180    /// Automatic multicast tunneling relay
181    AMTRELAY = 260,
182    /// DNSSEC trust authorities
183    TA = 32768,
184    /// DNSSEC lookaside validation record
185    DLV = 32769,
186    UNKNOWN,
187}
188
189impl RecordType {
190    pub fn from_raw(val: u16) -> Self {
191        RecordType::try_from(val).unwrap_or(RecordType::UNKNOWN)
192    }
193}
194
195#[derive(Clone, Copy, Debug, PartialEq, Eq, TryFromPrimitive)]
196#[repr(u16)]
197pub enum RecordClass {
198    IN = 1,
199    CH = 3,
200    HS = 4,
201    NONE = 254,
202    ANY = 255,
203    UNKNOWN,
204}
205
206impl RecordClass {
207    pub fn from_raw(val: u16) -> Self {
208        RecordClass::try_from(val).unwrap_or(RecordClass::UNKNOWN)
209    }
210}
211
212#[derive(Clone, Copy, Debug, PartialEq, Eq, TryFromPrimitive)]
213#[repr(u16)]
214pub enum OpCode {
215    QUERY = 0,
216    IQUERY = 1,
217    STATUS = 2,
218    NOTIFY = 4,
219    UPDATE = 5,
220    DSO = 6,
221    UNKNOWN,
222}
223
224impl OpCode {
225    pub fn from_raw(val: u16) -> Self {
226        OpCode::try_from(val).unwrap_or(OpCode::UNKNOWN)
227    }
228}
229
230#[derive(Clone, Copy, Debug, PartialEq, Eq, TryFromPrimitive)]
231#[repr(u16)]
232pub enum ResponseCode {
233    /// No error condition.
234    NOERROR = 0,
235    /// The name server was unable to interpret the query.
236    FORMATERROR = 1,
237    /// There was a problem with the name server.
238    SERVERFAILURE = 2,
239    /// The domain name referenced in the query does not exist.
240    NAMEERROR = 3,
241    /// The name server does not support the requested kind of query.
242    NOTIMPLEMENTED = 4,
243    /// The name server's policy forbids providing this information.
244    REFUSED = 5,
245    /// Name exists when it should not.
246    YXDOMAIN = 6,
247    /// RR set exists when it should not.
248    YXRRSET = 7,
249    /// RR set that should exist does not.
250    NXRRSET = 8,
251    /// Server not authoritative for zone or client not authorized.
252    NOTAUTH = 9,
253    /// Name not in contained zone.
254    NOTZONE = 10,
255    UNKNOWN,
256}
257
258impl ResponseCode {
259    pub fn from_raw(val: u16) -> Self {
260        ResponseCode::try_from(val).unwrap_or(ResponseCode::UNKNOWN)
261    }
262}
263
264#[derive(Clone, Copy, Debug, PartialEq, Eq, TryFromPrimitive)]
265#[repr(u16)]
266pub enum OptResponseCode {
267    /// No error condition.
268    NOERROR = 0,
269    /// The name server was unable to interpret the query.
270    FORMATERROR = 1,
271    /// There was a problem with the name server.
272    SERVERFAILURE = 2,
273    /// The domain name referenced in the query does not exist.
274    NAMEERROR = 3,
275    /// The name server does not support the requested kind of query.
276    NOTIMPLEMENTED = 4,
277    /// The name server's policy forbids providing this information.
278    REFUSED = 5,
279    /// Name exists when it should not.
280    YXDOMAIN = 6,
281    /// RR set exists when it should not.
282    YXRRSET = 7,
283    /// RR set that should exist does not.
284    NXRRSET = 8,
285    /// Server not authoritative for zone or client not authorized.
286    NOTAUTH = 9,
287    /// Name not in contained zone.
288    NOTZONE = 10,
289    /// Bad OPT version
290    BADVERSION = 16,
291    /// Bad/missing server cookie
292    BADCOOKIE = 23,
293    UNKNOWN,
294}
295
296impl OptResponseCode {
297    pub fn from_raw(val: u16) -> Self {
298        OptResponseCode::try_from(val).unwrap_or(OptResponseCode::UNKNOWN)
299    }
300}
301
302#[derive(Clone, Copy, Debug, PartialEq, Eq, TryFromPrimitive)]
303#[repr(u16)]
304pub enum TSigResponseCode {
305    /// No error condition.
306    NOERROR = 0,
307    /// The name server was unable to interpret the query.
308    FORMATERROR = 1,
309    /// There was a problem with the name server.
310    SERVERFAILURE = 2,
311    /// The domain name referenced in the query does not exist.
312    NAMEERROR = 3,
313    /// The name server does not support the requested kind of query.
314    NOTIMPLEMENTED = 4,
315    /// The name server's policy forbids providing this information.
316    REFUSED = 5,
317    /// Name exists when it should not.
318    YXDOMAIN = 6,
319    /// RR set exists when it should not.
320    YXRRSET = 7,
321    /// RR set that should exist does not.
322    NXRRSET = 8,
323    /// Server not authoritative for zone or client not authorized.
324    NOTAUTH = 9,
325    /// Name not in contained zone.
326    NOTZONE = 10,
327    /// Bad OPT version
328    BADSIGNATURE = 16,
329    /// Key not recognized
330    BADKEY = 17,
331    /// Signature out of time window
332    BADTIME = 18,
333    /// Bad TKEY mode
334    BADMODE = 19,
335    /// Duplicate key name
336    BADNAME = 20,
337    /// Algorithm not supported
338    BADALG = 21,
339    /// Bad truncation
340    BADTRUNC = 22,
341    /// Bad/missing server cookie
342    BADCOOKIE = 23,
343    UNKNOWN,
344}
345
346impl TSigResponseCode {
347    pub fn from_raw(val: u16) -> Self {
348        TSigResponseCode::try_from(val).unwrap_or(TSigResponseCode::UNKNOWN)
349    }
350}
351
352/// Indicates whether the message is a query or response.
353#[derive(Clone, Copy, Debug, PartialEq, Eq)]
354#[repr(u8)]
355pub enum QueryResponse {
356    Query = 0,
357    Response = 1,
358}
359
360/// Helper enum for determining where to store parsed answers in the message
361#[derive(Clone, Copy, Debug, PartialEq, Eq, TryFromPrimitive)]
362#[repr(u8)]
363pub enum AnswerType {
364    Answer = 0,
365    Nameserver = 1,
366    Additional = 2,
367}
368
369#[derive(Clone, Copy, Debug, PartialEq, Eq, TryFromPrimitive)]
370#[repr(u8)]
371pub enum SshfpAlgorithm {
372    RESERVED = 0,
373    RSA = 1,
374    DSA = 2,
375    ECDSA = 3,
376    Ed25519 = 4,
377    UNKNOWN,
378}
379
380impl SshfpAlgorithm {
381    pub fn from_raw(val: u8) -> Self {
382        SshfpAlgorithm::try_from(val).unwrap_or(SshfpAlgorithm::UNKNOWN)
383    }
384}
385
386#[derive(Clone, Copy, Debug, PartialEq, Eq, TryFromPrimitive)]
387#[repr(u8)]
388pub enum SshfpFingerprint {
389    RESERVED = 0,
390    SHA1 = 1,
391    SHA256 = 2,
392    UNKNOWN,
393}
394
395impl SshfpFingerprint {
396    pub fn from_raw(val: u8) -> Self {
397        SshfpFingerprint::try_from(val).unwrap_or(SshfpFingerprint::UNKNOWN)
398    }
399}
400
401#[derive(Clone, Copy, Debug, PartialEq, Eq, TryFromPrimitive)]
402#[repr(u16)]
403pub enum TkeyMode {
404    RESERVED = 0,
405    ServerAssignment = 1,
406    DiffieHelmanExchange = 2,
407    GssApiNegotiation = 3,
408    ResolverAssignment = 4,
409    KeyDeletion = 5,
410    UNKNOWN,
411}
412
413impl TkeyMode {
414    pub fn from_raw(val: u16) -> Self {
415        TkeyMode::try_from(val).unwrap_or(TkeyMode::UNKNOWN)
416    }
417}