From a7d9ffb30e3b55d9b6347546391d3565bd3c7ff5 Mon Sep 17 00:00:00 2001 From: bert hubert Date: Wed, 28 Oct 2015 12:02:46 +0100 Subject: [PATCH] teach sdig about EDNS subnet, plus clean it up a bit --- pdns/Makefile.am | 2 ++ pdns/sdig.cc | 49 +++++++++++++++++++++++------------------------- 2 files changed, 25 insertions(+), 26 deletions(-) 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<