From a0149eccff0c377060196077ce65d1a33c48188c Mon Sep 17 00:00:00 2001 From: Remi Gacogne Date: Mon, 23 Apr 2018 11:31:47 +0200 Subject: [PATCH] calidns: Add an option to read ECS values from the query file --- docs/manpages/calidns.1.rst | 2 ++ pdns/calidns.cc | 21 +++++++++++++++++---- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/docs/manpages/calidns.1.rst b/docs/manpages/calidns.1.rst index c7b943de3..32cb08c43 100644 --- a/docs/manpages/calidns.1.rst +++ b/docs/manpages/calidns.1.rst @@ -34,6 +34,8 @@ Options --ecs 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 On every subsequent run, multiply the number of queries per second by *NUM*. By default, this is 1.1. --maximum-qps Stop incrementing once this rate has been reached, to provide a diff --git a/pdns/calidns.cc b/pdns/calidns.cc index 9fb42fb97..cd0e1e630 100644 --- a/pdns/calidns.cc +++ b/pdns/calidns.cc @@ -222,6 +222,7 @@ try ("help,h", "Show this helpful message") ("version", "Show the version number") ("ecs", po::value(), "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()->default_value(1.1), "Set the factor to increase the QPS load per run") ("maximum-qps", po::value(), "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(); if (hitrate > 100 || hitrate < 0) { @@ -316,14 +318,25 @@ try vector 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))); } -- 2.49.0