logger.cc \
lua-pdns.cc lua-pdns.hh lua-iputils.cc \
lua-recursor.cc lua-recursor.hh \
+ lua-recursor4.cc lua-recursor4.hh \
lwres.cc lwres.hh \
mbedtlscompat.hh \
mbedtlssigners.cc \
return std::shared_ptr<DNSAction>(new DisableValidationAction);
});
+ g_lua.writeFunction("LogAction", [](const std::string& fname) {
+ return std::shared_ptr<DNSAction>(new LogAction(fname));
+ });
+
g_lua.writeFunction("MaxQPSIPRule", [](unsigned int qps, boost::optional<int> ipv4trunc, boost::optional<int> ipv6trunc) {
return std::shared_ptr<DNSRule>(new MaxQPSIPRule(qps, ipv4trunc.get_value_or(32), ipv6trunc.get_value_or(64)));
#include "dnsdist.hh"
#include "dnsname.hh"
+#include "dolog.hh"
class MaxQPSIPRule : public DNSRule
{
}
};
+class LogAction : public DNSAction, public boost::noncopyable
+{
+public:
+ LogAction() : d_fp(0)
+ {
+ }
+ LogAction(const std::string& str) : d_fname(str)
+ {
+ if(str.empty())
+ return;
+ d_fp = fopen(str.c_str(), "w");
+ if(!d_fp)
+ throw std::runtime_error("Unable to open file '"+str+"' for logging: "+string(strerror(errno)));
+ }
+ ~LogAction()
+ {
+ if(d_fp)
+ fclose(d_fp);
+ }
+ DNSAction::Action operator()(const ComboAddress& remote, const DNSName& qname, uint16_t qtype, dnsheader* dh, uint16_t& len, string* ruleresult) const override
+ {
+ if(!d_fp)
+ infolog("Packet from %s for %s %s with id %d", remote.toStringWithPort(), qname.toString(), QType(qtype).getName(), dh->id);
+ else {
+ string out = qname.toDNSString();
+ fwrite(out.c_str(), 1, out.size(), d_fp);
+ fwrite((void*)&qtype, 1, 2, d_fp);
+ }
+ return Action::None;
+ }
+ string toString() const override
+ {
+ return "log";
+ }
+private:
+ string d_fname;
+ FILE* d_fp;
+};
+
+
class DisableValidationAction : public DNSAction
{
public:
--- /dev/null
+#include "lua-recursor4.hh"
+#include <fstream>
+#undef L
+#include "ext/luawrapper/include/LuaContext.hpp"
+#include "logger.hh"
+
+RecursorLua4::RecursorLua4(const std::string& fname)
+{
+ d_lw = new LuaContext;
+ d_lw->writeFunction("newDN", [](const std::string& dom){ return DNSName(dom); });
+ d_lw->registerFunction("isPartOf", &DNSName::isPartOf);
+ d_lw->registerFunction("toString", &ComboAddress::toString);
+ d_lw->registerFunction("toString", &DNSName::toString);
+
+ vector<pair<string,int>> pd{{"PASS", PolicyDecision::PASS}, {"DROP", PolicyDecision::DROP}, {"TRUNCATE", PolicyDecision::TRUNCATE}};
+ d_lw->writeVariable("pdns", pd);
+
+ ifstream ifs(fname);
+ if(!ifs) {
+ theL()<<"Unable to read configuration file from '"<<fname<<"': "<<strerror(errno)<<endl;
+ return;
+ }
+ d_lw->executeCode(ifs);
+}
+
+bool RecursorLua4::preresolve(const ComboAddress& remote,const ComboAddress& local, const DNSName& query, const QType& qtype, vector<DNSRecord>& res, int& ret, bool* variable)
+{
+ const auto function = d_lw->readVariable<std::function<bool(const ComboAddress& remote, const ComboAddress& local, const DNSName& query, uint16_t)>>("preresolve");
+ if(!function)
+ return false;
+ ret = function(remote, local, query, qtype.getCode());
+ return true;
+}
\ No newline at end of file
--- /dev/null
+#pragma once
+#include "iputils.hh"
+#include "dnsname.hh"
+#include "namespaces.hh"
+
+class LuaContext;
+class RecursorLua4
+{
+public:
+ explicit RecursorLua4(const std::string& fname);
+ // ~RecursorLua();
+ bool preresolve(const ComboAddress& remote,const ComboAddress& local, const DNSName& query, const QType& qtype, vector<DNSRecord>& res, int& ret, bool* variable);
+private:
+ LuaContext* d_lw;
+};
+
#include "mplexer.hh"
#include "config.h"
#include "lua-recursor.hh"
+#include "lua-recursor4.hh"
#include "version.hh"
#include "responsestats.hh"
#include "secpoll-recursor.hh"
void startDoResolve(void *p)
{
+ RecursorLua4 rl4("./recursor4.lua");
DNSComboWriter* dc=(DNSComboWriter *)p;
try {
t_queryring->push_back(make_pair(dc->d_mdp.d_qname, dc->d_mdp.d_qtype));
break;
}
- if(!t_pdl->get() || !(*t_pdl)->preresolve(dc->d_remote, local, dc->d_mdp.d_qname, QType(dc->d_mdp.d_qtype), ret, res, &variableAnswer)) {
+
+ if(/* !t_pdl->get() ||*/ !rl4.preresolve(dc->d_remote, local, dc->d_mdp.d_qname, QType(dc->d_mdp.d_qtype), ret, res, &variableAnswer)) {
try {
res = sr.beginResolve(dc->d_mdp.d_qname, QType(dc->d_mdp.d_qtype), dc->d_mdp.d_qclass, ret);
}