(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:
parent
812264e2ab
commit
a07fb80b45
115
src/proto.rs
115
src/proto.rs
@ -1,57 +1,106 @@
|
|||||||
use std::convert::TryInto;
|
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)]
|
#[derive(Debug)]
|
||||||
pub enum DNSOpCode {
|
pub enum DNSOpCode {
|
||||||
QUERY = 0,
|
Query = 0,
|
||||||
IQUERY = 1, // obsolete
|
IQuery = 1, // obsolete
|
||||||
STATUS = 2,
|
Status = 2,
|
||||||
NOTIFY = 4,
|
Notify = 4,
|
||||||
UPDATE = 5,
|
Update = 5,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<u16> for DNSOpCode {
|
impl From<u16> for DNSOpCode {
|
||||||
fn from(val: u16) -> Self {
|
fn from(val: u16) -> Self {
|
||||||
match val {
|
match val {
|
||||||
0 => DNSOpCode::QUERY,
|
0 => DNSOpCode::Query,
|
||||||
1 => DNSOpCode::IQUERY,
|
1 => DNSOpCode::IQuery,
|
||||||
2 => DNSOpCode::STATUS,
|
2 => DNSOpCode::Status,
|
||||||
4 => DNSOpCode::NOTIFY,
|
4 => DNSOpCode::Notify,
|
||||||
5 => DNSOpCode::UPDATE,
|
5 => DNSOpCode::Update,
|
||||||
_ => panic!("KACKE"),
|
_ => 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)]
|
#[derive(Debug)]
|
||||||
pub enum DNSRCode {
|
pub enum DNSRCode {
|
||||||
NOERROR = 0,
|
NoError = 0,
|
||||||
FORMERR = 1,
|
FormErr = 1,
|
||||||
SERVFAIL = 2,
|
ServFail = 2,
|
||||||
NXDOMAIN = 3,
|
NXDomain = 3,
|
||||||
NOTIMP = 4,
|
NotImp = 4,
|
||||||
REFUSED = 5,
|
Refused = 5,
|
||||||
XYDOMAIN = 6,
|
YXDomain = 6,
|
||||||
XYRRSET = 7,
|
YXRRSet = 7,
|
||||||
NXRRSET = 8,
|
NXRRSet = 8,
|
||||||
NOTAUTH = 9,
|
NotAuth = 9,
|
||||||
NOTINZONE = 10,
|
NotZone = 10,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<u16> for DNSRCode {
|
impl From<u16> for DNSRCode {
|
||||||
fn from(val: u16) -> Self {
|
fn from(val: u16) -> Self {
|
||||||
match val {
|
match val {
|
||||||
0 => DNSRCode::NOERROR,
|
0 => DNSRCode::NoError,
|
||||||
1 => DNSRCode::FORMERR,
|
1 => DNSRCode::FormErr,
|
||||||
2 => DNSRCode::SERVFAIL,
|
2 => DNSRCode::ServFail,
|
||||||
3 => DNSRCode::NXDOMAIN,
|
3 => DNSRCode::NXDomain,
|
||||||
4 => DNSRCode::NOTIMP,
|
4 => DNSRCode::NotImp,
|
||||||
5 => DNSRCode::REFUSED,
|
5 => DNSRCode::Refused,
|
||||||
6 => DNSRCode::XYDOMAIN,
|
6 => DNSRCode::YXDomain,
|
||||||
7 => DNSRCode::XYRRSET,
|
7 => DNSRCode::YXRRSet,
|
||||||
8 => DNSRCode::NXRRSET,
|
8 => DNSRCode::NXRRSet,
|
||||||
9 => DNSRCode::NOTAUTH,
|
9 => DNSRCode::NotAuth,
|
||||||
10 => DNSRCode::NOTINZONE,
|
10 => DNSRCode::NotZone,
|
||||||
_ => panic!("KACKE"),
|
_ => panic!("KACKE"),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user