]> granicus.if.org Git - pdns/commitdiff
initial rough implementation of *reverse* DNS64. Inspired by Terry Froy & a pint...
authorbert hubert <bert.hubert@netherlabs.nl>
Thu, 16 May 2013 19:08:10 +0000 (21:08 +0200)
committerbert hubert <bert.hubert@netherlabs.nl>
Thu, 16 May 2013 19:08:10 +0000 (21:08 +0200)
This fakes up the proper PTR records too.

pdns/lua-recursor.cc
pdns/powerdns-example-script.lua
pdns/syncres.cc

index 9642cd72129f47fc6962d14e9aafc0dd9da4a7a2..8c9a16fdbd46677fe1accc5e9a8d29c8d0b6bad6 100644 (file)
@@ -1,5 +1,5 @@
 #include "lua-recursor.hh"
-
+#include "config.h"
 // to avoid including all of syncres.hh
 int directResolve(const std::string& qname, const QType& qtype, int qclass, vector<DNSResourceRecord>& ret);
 
@@ -79,6 +79,36 @@ int getFakeAAAARecords(const std::string& qname, const std::string& prefix, vect
   return rcode;
 }
 
+int getFakePTRRecords(const std::string& qname, const std::string& prefix, vector<DNSResourceRecord>& ret)
+{
+  /* qname has a reverse ordered IPv6 address, need to extract the underlying IPv4 address from it
+     and turn it into an IPv4 in-addr.arpa query */
+  ret.clear();
+  vector<string> parts;
+  stringtok(parts, qname, ".");
+  if(parts.size() < 8)
+    return -1;
+  
+  string newquery;
+  for(int n = 0; n < 4; ++n) {
+    newquery += 
+      lexical_cast<string>(strtol(parts[n*2].c_str(), 0, 16) + 16*strtol(parts[n*2+1].c_str(), 0, 16));
+    newquery.append(1,'.');
+  }
+  newquery += "in-addr.arpa.";
+
+  
+  int rcode = directResolve(newquery, QType(QType::PTR), 1, ret);
+  BOOST_FOREACH(DNSResourceRecord& rr, ret)
+  {    
+    if(rr.qtype.getCode() == QType::PTR && rr.d_place==DNSResourceRecord::ANSWER) {
+      rr.qname = qname;
+    }
+  }
+  return rcode;
+
+}
+
 bool RecursorLua::nxdomain(const ComboAddress& remote, const ComboAddress& local,const string& query, const QType& qtype, vector<DNSResourceRecord>& ret, int& res, bool* variable)
 {
   return passthrough("nxdomain", remote, local, query, qtype, ret, res, variable);
@@ -136,8 +166,7 @@ bool RecursorLua::passthrough(const string& func, const ComboAddress& remote, co
   }
   
   *variable |= d_variable;
-  
-  
+    
   if(!lua_isnumber(d_lua, 1)) {
     string tocall = lua_tostring(d_lua,1);
     string luaqname = lua_tostring(d_lua,2);
@@ -145,7 +174,10 @@ bool RecursorLua::passthrough(const string& func, const ComboAddress& remote, co
     lua_pop(d_lua, 3);
     // cerr<<"should call '"<<tocall<<"' to finish off"<<endl;
     ret.clear();
-    res=getFakeAAAARecords(luaqname, luaprefix, ret);
+    if(tocall == "getFakeAAAARecords")
+      res = getFakeAAAARecords(luaqname, luaprefix, ret);
+    else if(tocall == "getFakePTRRecords")
+      res = getFakePTRRecords(luaqname, luaprefix, ret);
     return true;
     // returned a followup 
   }
@@ -170,4 +202,4 @@ bool RecursorLua::passthrough(const string& func, const ComboAddress& remote, co
   return true;
 }
 
-#endif
\ No newline at end of file
+#endif
index 5cab16e941c520121135270ae7a8c02f1c9255e2..c05bd8374d786d7abf4317f7f733d9fcd10e8857 100644 (file)
@@ -1,7 +1,17 @@
+function endswith(s, send)
+        return #s >= #send and s:find(send, #s-#send+1, true) and true or false
+end
+
 function preresolve ( remoteip, domain, qtype )
        print ("prequery handler called for: ", remoteip, getlocaladdress(), domain, qtype)
        pdnslog("a test message.. received query from "..remoteip.." on "..getlocaladdress());
 
+       if endswith(domain, "f.f.7.7.b.1.2.0.0.0.0.0.0.0.0.0.0.0.0.0.0.8.e.f.ip6.arpa.")
+       then
+               print("This is our faked AAAA record in reverse")
+               return "getFakePTRRecords", domain, "fe80::21b::77ff:0:0"
+       end
+
        if domain == "www.donotcache.org."
        then
                print("making sure www.donotcache.org will never end up in the cache")
@@ -73,7 +83,7 @@ function nodata ( remoteip, domain, qtype, records )
        if qtype ~= pdns.AAAA then return -1, {} end  --  only AAAA records
 
        setvariable()
-    return "getFakeAAAARecords", domain, "fe80::21b:77ff:0:0"
+       return "getFakeAAAARecords", domain, "fe80::21b:77ff:0:0"
 end    
 
 -- records contains the entire packet, ready for your modifying pleasure
index 7c2ed96cd676d3d586353cec3b2162bfb31aa4fd..fceb3a03d2a1ec745fe9dc2fb17d1f0fb4c16569 100644 (file)
@@ -1209,7 +1209,7 @@ void SyncRes::addAuthorityRecords(const string& qname, vector<DNSResourceRecord>
   }
 }
 
-// used by PowerDNSLua
+// used by PowerDNSLua - note that this neglects to add the packet count & statistics back to pdns_ercursor.cc
 int directResolve(const std::string& qname, const QType& qtype, int qclass, vector<DNSResourceRecord>& ret)
 {
   struct timeval now;