#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);
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);
}
*variable |= d_variable;
-
-
+
if(!lua_isnumber(d_lua, 1)) {
string tocall = lua_tostring(d_lua,1);
string luaqname = lua_tostring(d_lua,2);
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
}
return true;
}
-#endif
\ No newline at end of file
+#endif
+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")
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