(chore) Change DNS OpCode and DNS RCode enum names to CamelCase (#13)

and use the same names as the RFC.
Also added some RFC documentation as doc comments in the code.

Co-authored-by: ddidderr <ddidderr@paul.network>
Reviewed-on: #13
This commit is contained in:
ddidderr 2022-04-03 18:22:47 +02:00
parent 812264e2ab
commit a07fb80b45
Signed by: ddidderr
GPG Key ID: 3841F1C27E6F0E14

View File

@ -1,57 +1,106 @@
use std::convert::TryInto;
/// Taken from RFC 6895, 2.2. OpCode Assignment
/// Currently, DNS OpCodes are assigned as follows:
/// OpCode Name Reference
///
/// 0 Query [RFC1035]
/// 1 IQuery (Inverse Query, OBSOLETE) [RFC3425]
/// 2 Status [RFC1035]
/// 3 Unassigned
/// 4 Notify [RFC1996]
/// 5 Update [RFC2136]
/// 6-15 Unassigned
#[derive(Debug)]
pub enum DNSOpCode {
QUERY = 0,
IQUERY = 1, // obsolete
STATUS = 2,
NOTIFY = 4,
UPDATE = 5,
Query = 0,
IQuery = 1, // obsolete
Status = 2,
Notify = 4,
Update = 5,
}
impl From<u16> for DNSOpCode {
fn from(val: u16) -> Self {
match val {
0 => DNSOpCode::QUERY,
1 => DNSOpCode::IQUERY,
2 => DNSOpCode::STATUS,
4 => DNSOpCode::NOTIFY,
5 => DNSOpCode::UPDATE,
0 => DNSOpCode::Query,
1 => DNSOpCode::IQuery,
2 => DNSOpCode::Status,
4 => DNSOpCode::Notify,
5 => DNSOpCode::Update,
_ => panic!("KACKE"),
}
}
}
// TODO: FIXME: TECHNISCHE SCHULD (alle pubs weg und gucken wie es richtig geht)
/// Taken from RFC 6895, 2.3. RCODE Assignment
///
/// RCODE Name Description Reference
///
/// 0 NoError No Error [RFC1035]
/// 1 FormErr Format Error [RFC1035]
/// 2 ServFail Server Failure [RFC1035]
/// 3 NXDomain Non-Existent Domain [RFC1035]
/// 4 NotImp Not Implemented [RFC1035]
/// 5 Refused Query Refused [RFC1035]
/// 6 YXDomain Name Exists when it should not [RFC2136]
/// 7 YXRRSet RR Set Exists when it should not [RFC2136]
/// 8 NXRRSet RR Set that should exist does not [RFC2136]
/// 9 NotAuth Server Not Authoritative for zone [RFC2136]
/// 9 NotAuth Not Authorized [RFC2845]
/// 10 NotZone Name not contained in zone [RFC2136]
///
/// 11 - 15 Unassigned
///
/// 16 BADVERS Bad OPT Version [RFC6891]
/// 16 BADSIG TSIG Signature Failure [RFC2845]
/// 17 BADKEY Key not recognized [RFC2845]
/// 18 BADTIME Signature out of time window [RFC2845]
/// 19 BADMODE Bad TKEY Mode [RFC2930]
/// 20 BADNAME Duplicate key name [RFC2930]
/// 21 BADALG Algorithm not supported [RFC2930]
/// 22 BADTRUNC Bad Truncation [RFC4635]
///
/// 23 - 3,840
/// 0x0017 - 0x0F00 Unassigned
///
/// 3,841 - 4,095
/// 0x0F01 - 0x0FFF Reserved for Private Use
///
/// 4,096 - 65,534
/// 0x1000 - 0xFFFE Unassigned
///
/// 65,535
/// 0xFFFF Reserved; can only be allocated by Standards Action.
#[derive(Debug)]
pub enum DNSRCode {
NOERROR = 0,
FORMERR = 1,
SERVFAIL = 2,
NXDOMAIN = 3,
NOTIMP = 4,
REFUSED = 5,
XYDOMAIN = 6,
XYRRSET = 7,
NXRRSET = 8,
NOTAUTH = 9,
NOTINZONE = 10,
NoError = 0,
FormErr = 1,
ServFail = 2,
NXDomain = 3,
NotImp = 4,
Refused = 5,
YXDomain = 6,
YXRRSet = 7,
NXRRSet = 8,
NotAuth = 9,
NotZone = 10,
}
impl From<u16> for DNSRCode {
fn from(val: u16) -> Self {
match val {
0 => DNSRCode::NOERROR,
1 => DNSRCode::FORMERR,
2 => DNSRCode::SERVFAIL,
3 => DNSRCode::NXDOMAIN,
4 => DNSRCode::NOTIMP,
5 => DNSRCode::REFUSED,
6 => DNSRCode::XYDOMAIN,
7 => DNSRCode::XYRRSET,
8 => DNSRCode::NXRRSET,
9 => DNSRCode::NOTAUTH,
10 => DNSRCode::NOTINZONE,
0 => DNSRCode::NoError,
1 => DNSRCode::FormErr,
2 => DNSRCode::ServFail,
3 => DNSRCode::NXDomain,
4 => DNSRCode::NotImp,
5 => DNSRCode::Refused,
6 => DNSRCode::YXDomain,
7 => DNSRCode::YXRRSet,
8 => DNSRCode::NXRRSet,
9 => DNSRCode::NotAuth,
10 => DNSRCode::NotZone,
_ => panic!("KACKE"),
}
}