]> granicus.if.org Git - pdns/commitdiff
teach sdig about EDNS subnet, plus clean it up a bit
authorbert hubert <bert.hubert@netherlabs.nl>
Wed, 28 Oct 2015 11:02:46 +0000 (12:02 +0100)
committerbert hubert <bert.hubert@netherlabs.nl>
Wed, 28 Oct 2015 11:03:04 +0000 (12:03 +0100)
pdns/Makefile.am
pdns/sdig.cc

index 7cf651454a09476c7c3135d298a11ba5803dec1e..69ae6a732a56ddbf218133d02b614d97031bd245 100644 (file)
@@ -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 \
index 4726899ed847e6aa54beecd71582c6846fa80fd8..330cf523f5cf1b044e16cec0d13a0f9bf31af2ef 100644 (file)
@@ -8,6 +8,7 @@
 #include "dnsrecords.hh"
 #include "statbag.hh"
 #include <boost/array.hpp>
+#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<Netmask> 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='"<<mdp.d_qname.toString()<<"', qtype="<<DNSRecordContent::NumberToType(mdp.d_qtype)<<endl;
-  cout<<"Rcode: "<<mdp.d_header.rcode<<", RD: "<<mdp.d_header.rd<<", QR: "<<mdp.d_header.qr;
+  cout<<"Rcode: "<<mdp.d_header.rcode<<" ("<<RCode::to_s(mdp.d_header.rcode)<<"), RD: "<<mdp.d_header.rd<<", QR: "<<mdp.d_header.qr;
   cout<<", TC: "<<mdp.d_header.tc<<", AA: "<<mdp.d_header.aa<<", opcode: "<<mdp.d_header.opcode<<endl;
 
   for(MOADNSParser::answers_t::const_iterator i=mdp.d_answers.begin(); i!=mdp.d_answers.end(); ++i) {          
@@ -177,6 +167,13 @@ try
         //if(iter->second == ping) 
          // cerr<<"It is correct!"<<endl;
       }
+      if(iter->first == 8) {// 'EDNS subnet'
+       EDNSSubnetOpts reso;
+        if(getEDNSSubnetOptsFromString(iter->second, &reso)) {
+          cerr<<"EDNS Subnet response: "<<reso.source.toString()<<", scope: "<<reso.scope.toString()<<", family = "<<reso.scope.getNetwork().sin4.sin_family<<endl;
+       }
+      }
+
       else {
         cerr<<"Have unknown option "<<(int)iter->first<<endl;
       }