]> granicus.if.org Git - pdns/commitdiff
calidns: Add an option to read ECS values from the query file
authorRemi Gacogne <remi.gacogne@powerdns.com>
Mon, 23 Apr 2018 09:31:47 +0000 (11:31 +0200)
committerRemi Gacogne <remi.gacogne@powerdns.com>
Tue, 24 Apr 2018 09:21:11 +0000 (11:21 +0200)
docs/manpages/calidns.1.rst
pdns/calidns.cc

index c7b943de30a87ff23e3c43b71c6e05d483a4dfae..32cb08c4358caf0e6a1ea2b393cf0f1db18a5a9e 100644 (file)
@@ -34,6 +34,8 @@ Options
 
 --ecs <SUBNET>           Add EDNS Client Subnet option to outgoing queries using random
                          addresses from the specified *SUBNET* range (IPv4 only).
+--ecs-from-file          Read IP or subnet values from the query file and add them as EDNS
+                         Client Subnet option to outgoing queries.
 --increment <NUM>        On every subsequent run, multiply the number of queries per second
                          by *NUM*. By default, this is 1.1.
 --maximum-qps <NUM>      Stop incrementing once this rate has been reached, to provide a
index 9fb42fb975d86366cbf143c448fc3c236dd26751..cd0e1e630d14e54babcec10ae1242b29df03cdaa 100644 (file)
@@ -222,6 +222,7 @@ try
     ("help,h", "Show this helpful message")
     ("version", "Show the version number")
     ("ecs", po::value<string>(), "Add EDNS Client Subnet option to outgoing queries using random addresses from the specified range (IPv4 only)")
+    ("ecs-from-file", "Read IP or subnet values from the query file and add them as EDNS Client Subnet options to outgoing queries")
     ("increment", po::value<float>()->default_value(1.1),  "Set the factor to increase the QPS load per run")
     ("maximum-qps", po::value<uint32_t>(), "Stop incrementing once this rate has been reached, to provide a stable load")
     ("want-recursion", "Set the Recursion Desired flag on queries");
@@ -266,6 +267,7 @@ try
   }
 
   bool wantRecursion = g_vm.count("want-recursion");
+  bool useECSFromFile = g_vm.count("ecs-from-file");
 
   double hitrate = g_vm["hitrate"].as<double>();
   if (hitrate > 100 || hitrate < 0) {
@@ -316,14 +318,25 @@ try
     vector<uint8_t> packet;
     DNSPacketWriter::optvect_t ednsOptions;
     boost::trim(line);
-    const auto fields = splitField(line, ' ');
-    DNSPacketWriter pw(packet, DNSName(fields.first), DNSRecordContent::TypeToNumber(fields.second));
+
+    auto fields = splitField(line, ' ');
+    std::string qname = fields.first;
+    std::string qtype = fields.second;
+    std::string subnet;
+
+    if(useECSFromFile) {
+      fields = splitField(qtype, ' ');
+      qtype = fields.first;
+      subnet = fields.second;
+    }
+
+    DNSPacketWriter pw(packet, DNSName(qname), DNSRecordContent::TypeToNumber(qtype));
     pw.getHeader()->rd=wantRecursion;
     pw.getHeader()->id=random();
 
-    if(!ecsRange.empty()) {
+    if(!subnet.empty() || !ecsRange.empty()) {
       EDNSSubnetOpts opt;
-      opt.source = Netmask("0.0.0.0/32");
+      opt.source = Netmask(subnet.empty() ? "0.0.0.0/32" : subnet);
       ednsOptions.push_back(std::make_pair(EDNSOptionCode::ECS, makeEDNSSubnetOptsString(opt)));
     }