Forráskód Böngészése

Add AA and CD protocol tweaks

Benjamin Sago 4 éve
szülő
commit
4cf7d6b56d
7 módosított fájl, 68 hozzáadás és 31 törlés
  1. 1 1
      README.md
  2. 1 1
      completions/dog.bash
  3. 4 2
      completions/dog.fish
  4. 1 1
      completions/dog.zsh
  5. 35 20
      src/options.rs
  6. 25 5
      src/requests.rs
  7. 1 1
      src/usage.txt

+ 1 - 1
README.md

@@ -45,7 +45,7 @@ It has colourful output, understands normal command-line argument syntax, suppor
 
     --edns=SETTING           Whether to OPT in to EDNS (disable, hide, show)
     --txid=NUMBER            Set the transaction ID to a specific value
-    -Z=TWEAKS                Uncommon protocol tweaks
+    -Z=TWEAKS                Set uncommon protocol-level tweaks
 
 ### Protocol options
 

+ 1 - 1
completions/dog.bash

@@ -19,7 +19,7 @@ _dog()
             ;;
 
         -Z)
-            COMPREPLY=( $( compgen -W 'authentic' -- "$cur" ) )
+            COMPREPLY=( $( compgen -W 'aa ad cd' -- "$cur" ) )
             return
             ;;
 

+ 4 - 2
completions/dog.fish

@@ -16,8 +16,10 @@ complete -c dog        -l 'edns'       -d "Whether to OPT in to EDNS" -x -a "
     show\t'Send an OPT query, and show the result'
 "
 complete -c dog        -l 'txid'       -d "Set the transaction ID to a specific value" -x
-complete -c dog -s 'Z'                 -d "Configure uncommon protocol tweaks" -x -a "
-    authentic\t'Set the AD (Authentic Data) query bit'
+complete -c dog -s 'Z'                 -d "Configure uncommon protocol-level tweaks" -x -a "
+    aa\t'Set the AA (Authoritative Answers) query bit'
+    ad\t'Set the AD (Authentic Data) query bit'
+    cd\t'Set the CD (Checking Disabled) query bit'
 "
 
 # Protocol options

+ 1 - 1
completions/dog.zsh

@@ -10,7 +10,7 @@ __dog() {
         --class"[Network class of the DNS record being queried]:(network class):(IN CH HS)" \
         --edns"[Whether to OPT in to EDNS]:(edns setting):(disable hide show)" \
         --txid"[Set the transaction ID to a specific value]" \
-        -Z"[Configure uncommon protocol tweaks]" \
+        -Z"[Configure uncommon protocol-level tweaks]:(protocol tweak):(aa ad cd)" \
         {-U,--udp}"[Use the DNS protocol over UDP]" \
         {-T,--tcp}"[Use the DNS protocol over TCP]" \
         {-S,--tls}"[Use the DNS-over-TLS protocol]" \

+ 35 - 20
src/options.rs

@@ -52,27 +52,27 @@ impl Options {
         opts.optmulti("",  "class",       "Network class of the DNS record being queried (IN, CH, HS)", "CLASS");
 
         // Sending options
-        opts.optopt ("",  "edns",         "Whether to OPT in to EDNS (disable, hide, show)", "SETTING");
-        opts.optopt ("",  "txid",         "Set the transaction ID to a specific value", "NUMBER");
-        opts.optopt ("Z", "",             "Uncommon protocol tweaks", "TWEAKS");
+        opts.optopt  ("",  "edns",         "Whether to OPT in to EDNS (disable, hide, show)", "SETTING");
+        opts.optopt  ("",  "txid",         "Set the transaction ID to a specific value", "NUMBER");
+        opts.optmulti("Z", "",             "Set uncommon protocol tweaks", "TWEAKS");
 
         // Protocol options
-        opts.optflag("U", "udp",          "Use the DNS protocol over UDP");
-        opts.optflag("T", "tcp",          "Use the DNS protocol over TCP");
-        opts.optflag("S", "tls",          "Use the DNS-over-TLS protocol");
-        opts.optflag("H", "https",        "Use the DNS-over-HTTPS protocol");
+        opts.optflag ("U", "udp",          "Use the DNS protocol over UDP");
+        opts.optflag ("T", "tcp",          "Use the DNS protocol over TCP");
+        opts.optflag ("S", "tls",          "Use the DNS-over-TLS protocol");
+        opts.optflag ("H", "https",        "Use the DNS-over-HTTPS protocol");
 
         // Output options
-        opts.optopt ("",  "color",        "When to use terminal colors",  "WHEN");
-        opts.optopt ("",  "colour",       "When to use terminal colours", "WHEN");
-        opts.optflag("J", "json",         "Display the output as JSON");
-        opts.optflag("",  "seconds",      "Do not format durations, display them as seconds");
-        opts.optflag("1", "short",        "Short mode: display nothing but the first result");
-        opts.optflag("",  "time",         "Print how long the response took to arrive");
+        opts.optopt  ("",  "color",        "When to use terminal colors",  "WHEN");
+        opts.optopt  ("",  "colour",       "When to use terminal colours", "WHEN");
+        opts.optflag ("J", "json",         "Display the output as JSON");
+        opts.optflag ("",  "seconds",      "Do not format durations, display them as seconds");
+        opts.optflag ("1", "short",        "Short mode: display nothing but the first result");
+        opts.optflag ("",  "time",         "Print how long the response took to arrive");
 
         // Meta options
-        opts.optflag("v", "version",      "Print version information");
-        opts.optflag("?", "help",         "Print list of command-line options");
+        opts.optflag ("v", "version",      "Print version information");
+        opts.optflag ("?", "help",         "Print list of command-line options");
 
         let matches = match opts.parse(args) {
             Ok(m)  => m,
@@ -368,11 +368,19 @@ impl ProtocolTweaks {
     fn deduce(matches: &getopts::Matches) -> Result<Self, OptionsError> {
         let mut tweaks = Self::default();
 
-        if let Some(tweak_strs) = matches.opt_str("Z") {
-            for tweak_str in tweak_strs.split(',') {
-                match &*tweak_str {
-                    "authentic"  => { tweaks.set_authentic_flag = true; },
-                    otherwise    => return Err(OptionsError::InvalidTweak(otherwise.into())),
+        for tweak_str in matches.opt_strs("Z") {
+            match &*tweak_str {
+                "aa" | "authoritative" => {
+                    tweaks.set_authoritative_flag = true;
+                }
+                "ad" | "authentic" => {
+                    tweaks.set_authentic_flag = true;
+                }
+                "cd" | "checking-disabled" => {
+                    tweaks.set_checking_disabled_flag = true;
+                }
+                otherwise => {
+                    return Err(OptionsError::InvalidTweak(otherwise.into()));
                 }
             }
         }
@@ -662,6 +670,13 @@ mod test {
         assert_eq!(options.requests.protocol_tweaks.set_authentic_flag, true);
     }
 
+    #[test]
+    fn two_more_tweaks() {
+        let options = Options::getopts(&[ "dom.ain", "-Z", "aa", "-Z", "cd" ]).unwrap();
+        assert_eq!(options.requests.protocol_tweaks.set_authoritative_flag, true);
+        assert_eq!(options.requests.protocol_tweaks.set_checking_disabled_flag, true);
+    }
+
     #[test]
     fn short_mode() {
         let tf = TextFormat { format_durations: true };

+ 25 - 5
src/requests.rs

@@ -46,11 +46,17 @@ pub struct Inputs {
 }
 
 /// Weird protocol options that are allowed by the spec but are not common.
-#[derive(PartialEq, Debug, Default)]
+#[derive(PartialEq, Debug, Default, Copy, Clone)]
 pub struct ProtocolTweaks {
 
-    /// Set the `AD` flag (Authentic Data) in the header of each request.
+    /// Set the `AA` (Authoritative Answer) flag in the header of each request.
+    pub set_authoritative_flag: bool,
+
+    /// Set the `AD` (Authentic Data) flag in the header of each request.
     pub set_authentic_flag: bool,
+
+    /// Set the `CD` (Checking Disabled) flag in the header of each request.
+    pub set_checking_disabled_flag: bool,
 }
 
 /// Whether to send or display OPT packets.
@@ -88,9 +94,7 @@ impl RequestGenerator {
 
                             let transaction_id = self.txid_generator.generate();
                             let mut flags = dns::Flags::query();
-                            if self.protocol_tweaks.set_authentic_flag {
-                                flags.authentic_data = true;
-                            }
+                            self.protocol_tweaks.set_request_flags(&mut flags);
 
                             let mut additional = None;
                             if self.edns.should_send() {
@@ -124,3 +128,19 @@ impl UseEDNS {
         self == Self::SendAndShow
     }
 }
+
+impl ProtocolTweaks {
+    pub fn set_request_flags(self, flags: &mut dns::Flags) {
+        if self.set_authoritative_flag {
+            flags.authoritative = true;
+        }
+
+        if self.set_authentic_flag {
+            flags.authentic_data = true;
+        }
+
+        if self.set_checking_disabled_flag {
+            flags.checking_disabled = true;
+        }
+    }
+}

+ 1 - 1
src/usage.txt

@@ -18,7 +18,7 @@
 \4mSending options:\0m
   \1;33m--edns\0m=\33mSETTING\0m           Whether to OPT in to EDNS (disable, hide, show)
   \1;33m--txid\0m=\33mNUMBER\0m            Set the transaction ID to a specific value
-  \1;33m-Z\0m=\33mTWEAKS\0m                Uncommon protocol tweaks
+  \1;33m-Z\0m=\33mTWEAKS\0m                Set uncommon protocol-level tweaks
 
 \4mProtocol options:\0m
   \1;33m-U\0m, \1;33m--udp\0m                Use the DNS protocol over UDP