Browse Source

Mark RCODEs in the private use range

Benjamin Sago 4 years ago
parent
commit
a5dd008d2c
3 changed files with 14 additions and 6 deletions
  1. 9 6
      dns/src/types.rs
  2. 4 0
      dns/src/wire.rs
  3. 1 0
      src/output.rs

+ 9 - 6
dns/src/types.rs

@@ -182,13 +182,13 @@ pub enum Opcode {
 #[derive(PartialEq, Debug, Copy, Clone)]
 pub enum ErrorCode {
 
-    /// `FORMERR` — The server was unable to interpret the query.
+    /// `FormErr` — The server was unable to interpret the query.
     FormatError,
 
-    /// `SERVFAIL` — There was a problem with the server.
+    /// `ServFail` — There was a problem with the server.
     ServerFailure,
 
-    /// `NXDOMAIN` — The domain name referenced in the query does not exist.
+    /// `NXDomain` — The domain name referenced in the query does not exist.
     NXDomain,
 
     /// `NotImp` — The server does not support one of the requested features.
@@ -198,12 +198,15 @@ pub enum ErrorCode {
     /// fulfil it.
     QueryRefused,
 
-    /// `NotAuth` — The server did not accept the EDNS version, or failed to
-    /// verify a signature.
+    /// `BADVERS` and `BADSIG` — The server did not accept the EDNS version,
+    /// or failed to verify a signature. The same code is used for both.
     BadVersion,
 
-    /// An error code we don’t know what it is.
+    /// An error code with no currently-defined meaning.
     Other(u16),
+
+    /// An error code within the ‘Reserved for Private Use’ range.
+    Private(u16)
 }
 
 

+ 4 - 0
dns/src/wire.rs

@@ -325,6 +325,10 @@ impl ErrorCode {
 
     /// Extracts the rcode from the last four bits of the flags field.
     fn from_bits(bits: u16) -> Option<Self> {
+        if (0x0F01 .. 0x0FFF).contains(&bits) {
+            return Some(Self::Private(bits));
+        }
+
         match bits {
             0 => None,
             1 => Some(Self::FormatError),

+ 1 - 0
src/output.rs

@@ -498,6 +498,7 @@ pub fn print_error_code(rcode: ErrorCode) {
         ErrorCode::NotImplemented  => println!("Status: Not Implemented"),
         ErrorCode::QueryRefused    => println!("Status: Query Refused"),
         ErrorCode::BadVersion      => println!("Status: Bad Version"),
+        ErrorCode::Private(num)    => println!("Status: Private Reason ({})", num),
         ErrorCode::Other(num)      => println!("Status: Other Failure ({})", num),
     }
 }