//! used to send information to a newborn mthread
struct DNSComboWriter {
- DNSComboWriter(const std::string& query, const struct timeval& now): d_mdp(true, query), d_now(now), d_query(query)
+ DNSComboWriter(const std::string& query, const struct timeval& now, shared_ptr<RecursorLua4> luaContext): d_mdp(true, query), d_now(now), d_query(query), d_luaContext(luaContext)
{
}
- DNSComboWriter(const std::string& query, const struct timeval& now, std::unordered_set<std::string>&& policyTags, LuaContext::LuaObject&& data, std::vector<DNSRecord>&& records): d_mdp(true, query), d_now(now), d_query(query), d_policyTags(std::move(policyTags)), d_records(std::move(records)), d_data(std::move(data))
+ DNSComboWriter(const std::string& query, const struct timeval& now, std::unordered_set<std::string>&& policyTags, shared_ptr<RecursorLua4> luaContext, LuaContext::LuaObject&& data, std::vector<DNSRecord>&& records): d_mdp(true, query), d_now(now), d_query(query), d_policyTags(std::move(policyTags)), d_records(std::move(records)), d_luaContext(luaContext), d_data(std::move(data))
{
}
std::unordered_set<std::string> d_policyTags;
std::string d_routingTag;
std::vector<DNSRecord> d_records;
+
+ // d_data is tied to this LuaContext so we need to keep it alive and use it, not a newer one, as long as d_data exists
+ shared_ptr<RecursorLua4> d_luaContext;
LuaContext::LuaObject d_data;
+
EDNSSubnetOpts d_ednssubnet;
shared_ptr<TCPConnection> d_tcpConnection;
boost::optional<uint16_t> d_extendedErrorCode{boost::none};
sr.setId(MT->getTid());
bool DNSSECOK=false;
- if(t_pdl) {
- sr.setLuaEngine(t_pdl);
+ if(dc->d_luaContext) {
+ sr.setLuaEngine(dc->d_luaContext);
}
if(g_dnssecmode != DNSSECMode::Off) {
sr.setDoDNSSEC(true);
sr.setCacheOnly();
}
- if (t_pdl) {
- t_pdl->prerpz(dq, res, sr.d_eventTrace);
+ if (dc->d_luaContext) {
+ dc->d_luaContext->prerpz(dq, res, sr.d_eventTrace);
}
// Check if the client has a policy attached to it
}
// if there is a RecursorLua active, and it 'took' the query in preResolve, we don't launch beginResolve
- if (!t_pdl || !t_pdl->preresolve(dq, res, sr.d_eventTrace)) {
+ if (!dc->d_luaContext || !dc->d_luaContext->preresolve(dq, res, sr.d_eventTrace)) {
if (!g_dns64PrefixReverse.empty() && dq.qtype == QType::PTR && dq.qname.isPartOf(g_dns64PrefixReverse)) {
res = getFakePTRRecords(dq.qname, ret);
if (wantsRPZ && appliedPolicy.d_kind != DNSFilterEngine::PolicyKind::NoAction) {
- if (t_pdl && t_pdl->policyHitEventFilter(dc->d_source, dc->d_mdp.d_qname, QType(dc->d_mdp.d_qtype), dc->d_tcp, appliedPolicy, dc->d_policyTags, sr.d_discardedPolicies)) {
+ if (dc->d_luaContext && dc->d_luaContext->policyHitEventFilter(dc->d_source, dc->d_mdp.d_qname, QType(dc->d_mdp.d_qtype), dc->d_tcp, appliedPolicy, dc->d_policyTags, sr.d_discardedPolicies)) {
/* reset to no match */
appliedPolicy = DNSFilterEngine::Policy();
}
}
}
- if (t_pdl || (g_dns64Prefix && dq.qtype == QType::AAAA && !vStateIsBogus(dq.validationState))) {
+ if (dc->d_luaContext || (g_dns64Prefix && dq.qtype == QType::AAAA && !vStateIsBogus(dq.validationState))) {
if (res == RCode::NoError) {
if (answerIsNOData(dc->d_mdp.d_qtype, res, ret)) {
- if (t_pdl && t_pdl->nodata(dq, res, sr.d_eventTrace)) {
+ if (dc->d_luaContext && dc->d_luaContext->nodata(dq, res, sr.d_eventTrace)) {
shouldNotValidate = true;
auto policyResult = handlePolicyHit(appliedPolicy, dc, sr, res, ret, pw);
if (policyResult == PolicyResult::HaveAnswer) {
}
}
}
- else if (res == RCode::NXDomain && t_pdl && t_pdl->nxdomain(dq, res, sr.d_eventTrace)) {
+ else if (res == RCode::NXDomain && dc->d_luaContext && dc->d_luaContext->nxdomain(dq, res, sr.d_eventTrace)) {
shouldNotValidate = true;
auto policyResult = handlePolicyHit(appliedPolicy, dc, sr, res, ret, pw);
if (policyResult == PolicyResult::HaveAnswer) {
}
}
- if (t_pdl && t_pdl->postresolve(dq, res, sr.d_eventTrace)) {
+ if (dc->d_luaContext && dc->d_luaContext->postresolve(dq, res, sr.d_eventTrace)) {
shouldNotValidate = true;
auto policyResult = handlePolicyHit(appliedPolicy, dc, sr, res, ret, pw);
// haveAnswer case redundant
}
}
}
- else if (t_pdl) {
+ else if (dc->d_luaContext) {
// preresolve returned true
shouldNotValidate = true;
auto policyResult = handlePolicyHit(appliedPolicy, dc, sr, res, ret, pw);
conn->state = TCPConnection::BYTE0;
std::unique_ptr<DNSComboWriter> dc;
try {
- dc = std::make_unique<DNSComboWriter>(conn->data, g_now);
+ dc = std::make_unique<DNSComboWriter>(conn->data, g_now, t_pdl);
}
catch(const MOADNSException &mde) {
g_stats.clientParseError++;
return 0;
}
- auto dc = std::make_unique<DNSComboWriter>(question, g_now, std::move(policyTags), std::move(data), std::move(records));
+ auto dc = std::make_unique<DNSComboWriter>(question, g_now, std::move(policyTags), t_pdl, std::move(data), std::move(records));
dc->setSocket(fd);
dc->d_tag=ctag;
dc->d_qhash=qhash;