From: bert hubert Date: Wed, 28 Oct 2015 11:02:46 +0000 (+0100) Subject: teach sdig about EDNS subnet, plus clean it up a bit X-Git-Tag: dnsdist-1.0.0-alpha1~230^2~19 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=a7d9ffb30e3b55d9b6347546391d3565bd3c7ff5;p=pdns teach sdig about EDNS subnet, plus clean it up a bit --- diff --git a/pdns/Makefile.am b/pdns/Makefile.am index 7cf651454..69ae6a732 100644 --- a/pdns/Makefile.am +++ b/pdns/Makefile.am @@ -481,11 +481,13 @@ endif sdig_SOURCES = \ base32.cc \ base64.cc base64.hh \ + dns.cc \ dnslabeltext.cc \ dnsname.cc dnsname.hh \ dnsparser.cc dnsparser.hh \ dnsrecords.cc \ dnswriter.cc dnswriter.hh \ + ednssubnet.cc \ logger.cc \ mbedtlscompat.hh \ misc.cc misc.hh \ diff --git a/pdns/sdig.cc b/pdns/sdig.cc index 4726899ed..330cf523f 100644 --- a/pdns/sdig.cc +++ b/pdns/sdig.cc @@ -8,6 +8,7 @@ #include "dnsrecords.hh" #include "statbag.hh" #include +#include "ednssubnet.hh" StatBag S; int main(int argc, char** argv) @@ -18,11 +19,12 @@ try bool tcp=false; bool showflags=false; bool hidesoadetails=false; + boost::optional ednsnm; reportAllTypes(); if(argc < 5) { - cerr<<"Syntax: sdig IP-address port question question-type [dnssec] [recurse] [showflags] [hidesoadetails] [tcp]\n"; + cerr<<"Syntax: sdig IP-address port question question-type [dnssec] [recurse] [showflags] [hidesoadetails] [tcp] [ednssubnet subnet]\n"; exit(EXIT_FAILURE); } @@ -36,8 +38,8 @@ try showflags=true; if (strcmp(argv[i], "hidesoadetails") == 0) hidesoadetails=true; - if (strcmp(argv[i], "tcp") == 0) { - tcp=true; + if (strcmp(argv[i], "ednssubnet") == 0) { + ednsnm=Netmask(argv[++i]); } } } @@ -46,7 +48,7 @@ try DNSPacketWriter pw(packet, DNSName(argv[3]), DNSRecordContent::TypeToNumber(argv[4])); - if(dnssec || getenv("SDIGBUFSIZE")) + if(dnssec || ednsnm || getenv("SDIGBUFSIZE")) { char *sbuf=getenv("SDIGBUFSIZE"); int bufsize; @@ -54,8 +56,16 @@ try bufsize=atoi(sbuf); else bufsize=2800; + DNSPacketWriter::optvect_t opts; + if(ednsnm) { - pw.addOpt(bufsize, 0, dnssec ? EDNSOpts::DNSSECOK : 0); + + EDNSSubnetOpts eo; + eo.source = *ednsnm; + opts.push_back(make_pair(8, makeEDNSSubnetOptsString(eo))); + } + + pw.addOpt(bufsize, 0, dnssec ? EDNSOpts::DNSSECOK : 0, opts); pw.commit(); } @@ -63,27 +73,7 @@ try { pw.getHeader()->rd=true; } - // pw.setRD(true); - - /* - pw.startRecord("powerdns.com", DNSRecordContent::TypeToNumber("NS")); - NSRecordContent nrc("ns1.powerdns.com"); - nrc.toPacket(pw); - - pw.startRecord("powerdns.com", DNSRecordContent::TypeToNumber("NS")); - NSRecordContent nrc2("ns2.powerdns.com"); - nrc2.toPacket(pw); - */ - -/* DNSPacketWriter::optvect_t opts; - opts.push_back(make_pair(5, ping)); - - pw.commit(); -*/ - // pw.addOpt(5200, 0, 0); - // pw.commit(); - string reply; ComboAddress dest(argv[1] + (*argv[1]=='@'), atoi(argv[2])); @@ -123,7 +113,7 @@ try } MOADNSParser mdp(reply); cout<<"Reply to question for qname='"<second == ping) // cerr<<"It is correct!"<first == 8) {// 'EDNS subnet' + EDNSSubnetOpts reso; + if(getEDNSSubnetOptsFromString(iter->second, &reso)) { + cerr<<"EDNS Subnet response: "<first<