From: bert hubert Date: Thu, 16 May 2013 19:08:10 +0000 (+0200) Subject: initial rough implementation of *reverse* DNS64. Inspired by Terry Froy & a pint... X-Git-Tag: auth-3.3-rc1~29^2~7^2~2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=8ce79a2266e267cffade2e5a27f9b8725a999798;p=thirdparty%2Fpdns.git initial rough implementation of *reverse* DNS64. Inspired by Terry Froy & a pint of #ripe66 guinness This fakes up the proper PTR records too. --- diff --git a/pdns/lua-recursor.cc b/pdns/lua-recursor.cc index 9642cd7212..8c9a16fdbd 100644 --- a/pdns/lua-recursor.cc +++ b/pdns/lua-recursor.cc @@ -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& 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& 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 parts; + stringtok(parts, qname, "."); + if(parts.size() < 8) + return -1; + + string newquery; + for(int n = 0; n < 4; ++n) { + newquery += + lexical_cast(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& 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 '"<= #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 diff --git a/pdns/syncres.cc b/pdns/syncres.cc index 7c2ed96cd6..fceb3a03d2 100644 --- a/pdns/syncres.cc +++ b/pdns/syncres.cc @@ -1209,7 +1209,7 @@ void SyncRes::addAuthorityRecords(const string& qname, vector } } -// 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& ret) { struct timeval now;