}
-bool RecursorLua4::preresolve(const ComboAddress& remote, const ComboAddress& local, const DNSName& query, const QType& qtype, vector<DNSRecord>& ret, const vector<pair<uint8_t,string> >* ednsOpts, int& res, bool* variable)
+bool RecursorLua4::preresolve(const ComboAddress& remote, const ComboAddress& local, const DNSName& query, const QType& qtype, vector<DNSRecord>& ret, const vector<pair<uint16_t,string> >* ednsOpts, int& res, bool* variable)
{
return false;
}
}
+vector<pair<uint16_t, string> > RecursorLua4::DNSQuestion::getEDNSOptions()
+{
+ if(ednsOptions)
+ return *ednsOptions;
+ else
+ return vector<pair<uint16_t,string>>();
+}
+
+boost::optional<string> RecursorLua4::DNSQuestion::getEDNSOption(uint16_t code)
+{
+ if(ednsOptions)
+ for(const auto& o : *ednsOptions)
+ if(o.first==code)
+ return o.second;
+
+ return boost::optional<string>();
+}
+
+
vector<pair<int, DNSRecord> > RecursorLua4::DNSQuestion::getRecords()
{
vector<pair<int, DNSRecord> > ret;
d_lw->registerMember("udpAnswer", &DNSQuestion::udpAnswer);
d_lw->registerMember("udpQueryDest", &DNSQuestion::udpQueryDest);
d_lw->registerMember("udpCallback", &DNSQuestion::udpCallback);
+ d_lw->registerFunction("getEDNSOptions", &DNSQuestion::getEDNSOptions);
+ d_lw->registerFunction("getEDNSOption", &DNSQuestion::getEDNSOption);
d_lw->registerMember("name", &DNSRecord::d_name);
d_lw->registerMember("type", &DNSRecord::d_type);
d_lw->registerMember("ttl", &DNSRecord::d_ttl);
- d_lw->registerMember("ednsOptions", &DNSQuestion::ednsOptions);
+
d_lw->registerFunction<string(DNSRecord::*)()>("getContent", [](const DNSRecord& dr) { return dr.d_content->getZoneRepresentation(); });
d_gettag = d_lw->readVariable<boost::optional<gettag_t>>("gettag").get_value_or(0);
}
-bool RecursorLua4::preresolve(const ComboAddress& remote,const ComboAddress& local, const DNSName& query, const QType& qtype, vector<DNSRecord>& res, const vector<pair<uint8_t,string> >* ednsOpts, int& ret, bool* variable)
+bool RecursorLua4::preresolve(const ComboAddress& remote,const ComboAddress& local, const DNSName& query, const QType& qtype, vector<DNSRecord>& res, const vector<pair<uint16_t,string> >* ednsOpts, int& ret, bool* variable)
{
- return genhook(d_preresolve, remote, local, query, qtype, res, 0, ret, variable);
+ return genhook(d_preresolve, remote, local, query, qtype, res, ednsOpts, ret, variable);
}
bool RecursorLua4::nxdomain(const ComboAddress& remote,const ComboAddress& local, const DNSName& query, const QType& qtype, vector<DNSRecord>& res, int& ret, bool* variable)
return 0;
}
-bool RecursorLua4::genhook(luacall_t& func, const ComboAddress& remote,const ComboAddress& local, const DNSName& query, const QType& qtype, vector<DNSRecord>& res, const vector<pair<uint8_t,string> >* ednsOpts, int& ret, bool* variable)
+bool RecursorLua4::genhook(luacall_t& func, const ComboAddress& remote,const ComboAddress& local, const DNSName& query, const QType& qtype, vector<DNSRecord>& res, const vector<pair<uint16_t,string> >* ednsOpts, int& ret, bool* variable)
{
if(!func)
return false;
dq->local=local;
dq->remote=remote;
dq->records = res;
-
+ dq->ednsOptions = ednsOpts;
bool handled=func(dq);
if(variable) *variable |= dq->variable; // could still be set to indicate this *name* is variable
public:
explicit RecursorLua4(const std::string& fname);
- bool preresolve(const ComboAddress& remote,const ComboAddress& local, const DNSName& query, const QType& qtype, vector<DNSRecord>& res, const vector<pair<uint8_t,string> >* ednsOpts, int& ret, bool* variable);
+ bool preresolve(const ComboAddress& remote,const ComboAddress& local, const DNSName& query, const QType& qtype, vector<DNSRecord>& res, const vector<pair<uint16_t,string> >* ednsOpts, int& ret, bool* variable);
bool nxdomain(const ComboAddress& remote, const ComboAddress& local, const DNSName& query, const QType& qtype, vector<DNSRecord>& res, int& ret, bool* variable);
bool nodata(const ComboAddress& remote, const ComboAddress& local, const DNSName& query, const QType& qtype, vector<DNSRecord>& res, int& ret, bool* variable);
bool postresolve(const ComboAddress& remote, const ComboAddress& local, const DNSName& query, const QType& qtype, vector<DNSRecord>& res, int& ret, bool* variable);
void addAnswer(uint16_t type, const std::string& content, boost::optional<int> ttl, boost::optional<string> name);
void addRecord(uint16_t type, const std::string& content, DNSResourceRecord::Place place, boost::optional<int> ttl, boost::optional<string> name);
vector<pair<int,DNSRecord> > getRecords();
+ vector<pair<uint16_t, string> > getEDNSOptions();
+ boost::optional<string> getEDNSOption(uint16_t code);
void setRecords(const vector<pair<int,DNSRecord> >& records);
bool variable{false};
string udpCallback;
std::unordered_map<string,string> data;
- std::vector<pair<uint16_t, string>>* ednsOptions;
+ const std::vector<pair<uint16_t, string>>* ednsOptions;
DNSName followupName;
};
LuaContext* d_lw;
typedef std::function<bool(std::shared_ptr<DNSQuestion>)> luacall_t;
luacall_t d_preresolve, d_nxdomain, d_nodata, d_postresolve, d_preoutquery, d_postoutquery;
- bool genhook(luacall_t& func, const ComboAddress& remote,const ComboAddress& local, const DNSName& query, const QType& qtype, vector<DNSRecord>& res, const vector<pair<uint8_t,string> >* ednsOpts, int& ret, bool* variable);
+ bool genhook(luacall_t& func, const ComboAddress& remote,const ComboAddress& local, const DNSName& query, const QType& qtype, vector<DNSRecord>& res, const vector<pair<uint16_t,string> >* ednsOpts, int& ret, bool* variable);
typedef std::function<bool(ComboAddress,ComboAddress, struct dnsheader)> ipfilter_t;
ipfilter_t d_ipfilter;
};
int d_tag;
string d_query;
shared_ptr<TCPConnection> d_tcpConnection;
+ vector<pair<uint16_t, string> > d_ednsOpts;
};
if(getEDNSOpts(dc->d_mdp, &edo)) {
if(!dc->d_tcp)
maxanswersize = min(edo.d_packetsize, g_udpTruncationThreshold);
+ dc->d_ednsOpts = edo.d_options;
haveEDNS=true;
}
vector<DNSRecord> ret;
}
- if(!t_pdl->get() || !(*t_pdl)->preresolve(dc->d_remote, dc->d_local, dc->d_mdp.d_qname, QType(dc->d_mdp.d_qtype), ret, res, &variableAnswer)) {
+ if(!t_pdl->get() || !(*t_pdl)->preresolve(dc->d_remote, dc->d_local, dc->d_mdp.d_qname, QType(dc->d_mdp.d_qtype), ret, dc->d_ednsOpts.empty() ? 0 : &dc->d_ednsOpts, res, &variableAnswer)) {
try {
res = sr.beginResolve(dc->d_mdp.d_qname, QType(dc->d_mdp.d_qtype), dc->d_mdp.d_qclass, ret);
}