From a381107de16f86c760b8430c6927947fa6798c2f Mon Sep 17 00:00:00 2001 From: Otto Moerbeek Date: Thu, 7 Mar 2024 16:56:05 +0100 Subject: [PATCH] rec: Tidy lua-recursor4.cc and lua-recursor4.hh --- pdns/recursordist/lua-recursor4.cc | 505 +++++++++++++++-------------- pdns/recursordist/lua-recursor4.hh | 66 ++-- 2 files changed, 293 insertions(+), 278 deletions(-) diff --git a/pdns/recursordist/lua-recursor4.cc b/pdns/recursordist/lua-recursor4.cc index 1177cf05cb..d6dd545ac2 100644 --- a/pdns/recursordist/lua-recursor4.cc +++ b/pdns/recursordist/lua-recursor4.cc @@ -38,76 +38,79 @@ RecursorLua4::RecursorLua4() { prepareContext(); } boost::optional RecursorLua4::DNSQuestion::getDH() const { - if (dh) + if (dh != nullptr) { return *dh; - return boost::optional(); + } + return {}; } vector RecursorLua4::DNSQuestion::getEDNSFlags() const { vector ret; - if (ednsFlags) { - if (*ednsFlags & EDNSOpts::DNSSECOK) - ret.push_back("DO"); + if (ednsFlags != nullptr) { + if ((*ednsFlags & EDNSOpts::DNSSECOK) != 0) { + ret.emplace_back("DO"); + } } return ret; } -bool RecursorLua4::DNSQuestion::getEDNSFlag(string flag) const +bool RecursorLua4::DNSQuestion::getEDNSFlag(const string& flag) const { - if (ednsFlags) { - if (flag == "DO" && (*ednsFlags & EDNSOpts::DNSSECOK)) + if (ednsFlags != nullptr) { + if (flag == "DO" && (*ednsFlags & EDNSOpts::DNSSECOK) != 0) { return true; + } } return false; } vector> RecursorLua4::DNSQuestion::getEDNSOptions() const { - if (ednsOptions) + if (ednsOptions != nullptr) { return *ednsOptions; - else - return vector>(); + } + return {}; } boost::optional RecursorLua4::DNSQuestion::getEDNSOption(uint16_t code) const { - if (ednsOptions) - for (const auto& o : *ednsOptions) - if (o.first == code) - return o.second; - - return boost::optional(); + if (ednsOptions != nullptr) { + for (const auto& option : *ednsOptions) { + if (option.first == code) { + return option.second; + } + } + } + return {}; } boost::optional RecursorLua4::DNSQuestion::getEDNSSubnet() const { - if (ednsOptions) { - for (const auto& o : *ednsOptions) { - if (o.first == EDNSOptionCode::ECS) { + if (ednsOptions != nullptr) { + for (const auto& option : *ednsOptions) { + if (option.first == EDNSOptionCode::ECS) { EDNSSubnetOpts eso; - if (getEDNSSubnetOptsFromString(o.second, &eso)) + if (getEDNSSubnetOptsFromString(option.second, &eso)) { return eso.source; - else - break; + } + break; } } } - return boost::optional(); + return {}; } std::vector> RecursorLua4::DNSQuestion::getProxyProtocolValues() const { std::vector> result; - if (proxyProtocolValues) { - result.reserve(proxyProtocolValues->size()); - + if (proxyProtocolValues != nullptr) { int idx = 1; + result.reserve(proxyProtocolValues->size()); for (const auto& value : *proxyProtocolValues) { - result.push_back({idx++, value}); + result.emplace_back(idx++, value); } } - return result; } @@ -115,28 +118,30 @@ vector> RecursorLua4::DNSQuestion::getRecords() const { vector> ret; int num = 1; - for (const auto& r : records) { - ret.push_back({num++, r}); + ret.reserve(records.size()); + for (const auto& record : records) { + ret.emplace_back(num++, record); } return ret; } -void RecursorLua4::DNSQuestion::setRecords(const vector>& recs) + +void RecursorLua4::DNSQuestion::setRecords(const vector>& arg) { records.clear(); - for (const auto& p : recs) { - records.push_back(p.second); + for (const auto& pair : arg) { + records.push_back(pair.second); } } void RecursorLua4::DNSQuestion::addRecord(uint16_t type, const std::string& content, DNSResourceRecord::Place place, boost::optional ttl, boost::optional name) { - DNSRecord dr; - dr.d_name = name ? DNSName(*name) : qname; - dr.d_ttl = ttl.get_value_or(3600); - dr.d_type = type; - dr.d_place = place; - dr.setContent(DNSRecordContent::make(type, QClass::IN, content)); - records.push_back(dr); + DNSRecord dnsRecord; + dnsRecord.d_name = name ? DNSName(*name) : qname; + dnsRecord.d_ttl = ttl.get_value_or(3600); + dnsRecord.d_type = type; + dnsRecord.d_place = place; + dnsRecord.setContent(DNSRecordContent::make(type, QClass::IN, content)); + records.push_back(dnsRecord); } void RecursorLua4::DNSQuestion::addAnswer(uint16_t type, const std::string& content, boost::optional ttl, boost::optional name) @@ -147,28 +152,28 @@ void RecursorLua4::DNSQuestion::addAnswer(uint16_t type, const std::string& cont struct DynMetric { std::atomic* ptr; - void inc() { (*ptr)++; } - void incBy(unsigned int by) { (*ptr) += by; } - unsigned long get() { return *ptr; } - void set(unsigned long val) { *ptr = val; } + void inc() const { (*ptr)++; } + void incBy(unsigned int incr) const { (*ptr) += incr; } + [[nodiscard]] unsigned long get() const { return *ptr; } + void set(unsigned long val) const { *ptr = val; } }; // clang-format off void RecursorLua4::postPrepareContext() { - d_lw->registerMember("qname", [](const DNSQuestion& dq) -> const DNSName& { return dq.qname; }, [](DNSQuestion& /* dq */, const DNSName& newName) { (void) newName; }); - d_lw->registerMember("qtype", [](const DNSQuestion& dq) -> uint16_t { return dq.qtype; }, [](DNSQuestion& /* dq */, uint16_t newType) { (void) newType; }); - d_lw->registerMember("isTcp", [](const DNSQuestion& dq) -> bool { return dq.isTcp; }, [](DNSQuestion& /* dq */, bool newTcp) { (void) newTcp; }); - d_lw->registerMember("localaddr", [](const DNSQuestion& dq) -> const ComboAddress& { return dq.local; }, [](DNSQuestion& /* dq */, const ComboAddress& newLocal) { (void) newLocal; }); - d_lw->registerMember("remoteaddr", [](const DNSQuestion& dq) -> const ComboAddress& { return dq.remote; }, [](DNSQuestion& /* dq */, const ComboAddress& newRemote) { (void) newRemote; }); - d_lw->registerMember("validationState", [](const DNSQuestion& dq) -> uint8_t { return (vStateIsBogus(dq.validationState) ? /* in order not to break older scripts */ static_cast(255) : static_cast(dq.validationState)); }, [](DNSQuestion& /* dq */, uint8_t newState) { (void) newState; }); - d_lw->registerMember("detailedValidationState", [](const DNSQuestion& dq) -> vState { return dq.validationState; }, [](DNSQuestion& /* dq */, vState newState) { (void) newState; }); + d_lw->registerMember("qname", [](const DNSQuestion& dnsQuestion) -> const DNSName& { return dnsQuestion.qname; }, [](DNSQuestion& /* dnsQuestion */, const DNSName& newName) { (void) newName; }); + d_lw->registerMember("qtype", [](const DNSQuestion& dnsQuestion) -> uint16_t { return dnsQuestion.qtype; }, [](DNSQuestion& /* dnsQuestion */, uint16_t newType) { (void) newType; }); + d_lw->registerMember("isTcp", [](const DNSQuestion& dnsQuestion) -> bool { return dnsQuestion.isTcp; }, [](DNSQuestion& /* dnsQuestion */, bool newTcp) { (void) newTcp; }); + d_lw->registerMember("localaddr", [](const DNSQuestion& dnsQuestion) -> const ComboAddress& { return dnsQuestion.local; }, [](DNSQuestion& /* dnsQuestion */, const ComboAddress& newLocal) { (void) newLocal; }); + d_lw->registerMember("remoteaddr", [](const DNSQuestion& dnsQuestion) -> const ComboAddress& { return dnsQuestion.remote; }, [](DNSQuestion& /* dnsQuestion */, const ComboAddress& newRemote) { (void) newRemote; }); + d_lw->registerMember("validationState", [](const DNSQuestion& dnsQuestion) -> uint8_t { return (vStateIsBogus(dnsQuestion.validationState) ? /* in order not to break older scripts */ static_cast(255) : static_cast(dnsQuestion.validationState)); }, [](DNSQuestion& /* dnsQuestion */, uint8_t newState) { (void) newState; }); + d_lw->registerMember("detailedValidationState", [](const DNSQuestion& dnsQuestion) -> vState { return dnsQuestion.validationState; }, [](DNSQuestion& /* dnsQuestion */, vState newState) { (void) newState; }); - d_lw->registerMember("variable", [](const DNSQuestion& dq) -> bool { return dq.variable; }, [](DNSQuestion& dq, bool newVariable) { dq.variable = newVariable; }); - d_lw->registerMember("wantsRPZ", [](const DNSQuestion& dq) -> bool { return dq.wantsRPZ; }, [](DNSQuestion& dq, bool newWantsRPZ) { dq.wantsRPZ = newWantsRPZ; }); - d_lw->registerMember("logResponse", [](const DNSQuestion& dq) -> bool { return dq.logResponse; }, [](DNSQuestion& dq, bool newLogResponse) { dq.logResponse = newLogResponse; }); - d_lw->registerMember("addPaddingToResponse", [](const DNSQuestion& dq) -> bool { return dq.addPaddingToResponse; }, [](DNSQuestion& dq, bool add) { dq.addPaddingToResponse = add; }); + d_lw->registerMember("variable", [](const DNSQuestion& dnsQuestion) -> bool { return dnsQuestion.variable; }, [](DNSQuestion& dnsQuestion, bool newVariable) { dnsQuestion.variable = newVariable; }); + d_lw->registerMember("wantsRPZ", [](const DNSQuestion& dnsQuestion) -> bool { return dnsQuestion.wantsRPZ; }, [](DNSQuestion& dnsQuestion, bool newWantsRPZ) { dnsQuestion.wantsRPZ = newWantsRPZ; }); + d_lw->registerMember("logResponse", [](const DNSQuestion& dnsQuestion) -> bool { return dnsQuestion.logResponse; }, [](DNSQuestion& dnsQuestion, bool newLogResponse) { dnsQuestion.logResponse = newLogResponse; }); + d_lw->registerMember("addPaddingToResponse", [](const DNSQuestion& dnsQuestion) -> bool { return dnsQuestion.addPaddingToResponse; }, [](DNSQuestion& dnsQuestion, bool add) { dnsQuestion.addPaddingToResponse = add; }); d_lw->registerMember("rcode", &DNSQuestion::rcode); d_lw->registerMember("tag", &DNSQuestion::tag); @@ -179,26 +184,26 @@ void RecursorLua4::postPrepareContext() d_lw->registerMember("followupPrefix", &DNSQuestion::followupPrefix); d_lw->registerMember("followupName", &DNSQuestion::followupName); d_lw->registerMember("data", &DNSQuestion::data); - d_lw->registerMember("extendedErrorCode", [](const DNSQuestion& dq) -> uint16_t { - if (dq.extendedErrorCode && *dq.extendedErrorCode) { - return *(*dq.extendedErrorCode); + d_lw->registerMember("extendedErrorCode", [](const DNSQuestion& dnsQuestion) -> uint16_t { + if (dnsQuestion.extendedErrorCode != nullptr && *dnsQuestion.extendedErrorCode) { + return *(*dnsQuestion.extendedErrorCode); } return 0; }, - [](DNSQuestion& dq, uint16_t newCode) { - if (dq.extendedErrorCode) { - *dq.extendedErrorCode = newCode; + [](DNSQuestion& dnsQuestion, uint16_t newCode) { + if (dnsQuestion.extendedErrorCode != nullptr) { + *dnsQuestion.extendedErrorCode = newCode; } }); - d_lw->registerMember("extendedErrorExtra", [](const DNSQuestion& dq) -> std::string { - if (dq.extendedErrorExtra) { - return *dq.extendedErrorExtra; + d_lw->registerMember("extendedErrorExtra", [](const DNSQuestion& dnsQuestion) -> std::string { + if (dnsQuestion.extendedErrorExtra != nullptr) { + return *dnsQuestion.extendedErrorExtra; } return ""; }, - [](DNSQuestion& dq, const std::string& newExtra) { - if (dq.extendedErrorExtra) { - *dq.extendedErrorExtra = newExtra; + [](DNSQuestion& dnsQuestion, const std::string& newExtra) { + if (dnsQuestion.extendedErrorExtra != nullptr) { + *dnsQuestion.extendedErrorExtra = newExtra; } }); d_lw->registerMember("udpQuery", &DNSQuestion::udpQuery); @@ -274,8 +279,9 @@ void RecursorLua4::postPrepareContext() d_lw->registerFunction("count", [](const EDNSOptionView& option) { return option.values.size(); }); d_lw->registerFunction(EDNSOptionView::*)()>("getValues", [] (const EDNSOptionView& option) { std::vector values; + values.reserve(option.values.size()); for (const auto& value : option.values) { - values.push_back(std::string(value.content, value.size)); + values.emplace_back(value.content, value.size); } return values; }); @@ -296,68 +302,71 @@ void RecursorLua4::postPrepareContext() } return std::string(option.values.at(0).content, option.values.at(0).size); }); - d_lw->registerFunction("getContent", [](const DNSRecord& dr) { return dr.getContent()->getZoneRepresentation(); }); - d_lw->registerFunction(DNSRecord::*)()>("getCA", [](const DNSRecord& dr) { + d_lw->registerFunction("getContent", [](const DNSRecord& dnsRecord) { return dnsRecord.getContent()->getZoneRepresentation(); }); + d_lw->registerFunction(DNSRecord::*)()>("getCA", [](const DNSRecord& dnsRecord) { boost::optional ret; - if(auto rec = getRR(dr)) - ret=rec->getCA(53); - else if(auto aaaarec = getRR(dr)) - ret=aaaarec->getCA(53); + if (auto rec = getRR(dnsRecord)) { + ret = rec->getCA(53); + } + else if (auto aaaarec = getRR(dnsRecord)) { + ret = aaaarec->getCA(53); + } return ret; }); d_lw->registerFunction("getContent", [](const ProxyProtocolValue& value) -> std::string { return value.content; }); d_lw->registerFunction("getType", [](const ProxyProtocolValue& value) { return value.type; }); - d_lw->registerFunction("changeContent", [](DNSRecord& dr, const std::string& newContent) { dr.setContent(DNSRecordContent::make(dr.d_type, QClass::IN, newContent)); }); + d_lw->registerFunction("changeContent", [](DNSRecord& dnsRecord, const std::string& newContent) { dnsRecord.setContent(DNSRecordContent::make(dnsRecord.d_type, QClass::IN, newContent)); }); d_lw->registerFunction("addAnswer", &DNSQuestion::addAnswer); d_lw->registerFunction("addRecord", &DNSQuestion::addRecord); d_lw->registerFunction("getRecords", &DNSQuestion::getRecords); d_lw->registerFunction("setRecords", &DNSQuestion::setRecords); - d_lw->registerFunction("addPolicyTag", [](DNSQuestion& dq, const std::string& tag) { if (dq.policyTags) { dq.policyTags->insert(tag); } }); - d_lw->registerFunction >&)>("setPolicyTags", [](DNSQuestion& dq, const std::vector >& tags) { - if (dq.policyTags) { - dq.policyTags->clear(); - dq.policyTags->reserve(tags.size()); + d_lw->registerFunction("addPolicyTag", [](DNSQuestion& dnsQuestion, const std::string& tag) { if (dnsQuestion.policyTags != nullptr) { dnsQuestion.policyTags->insert(tag); } }); + d_lw->registerFunction >&)>("setPolicyTags", [](DNSQuestion& dnsQuestion, const std::vector >& tags) { + if (dnsQuestion.policyTags != nullptr) { + dnsQuestion.policyTags->clear(); + dnsQuestion.policyTags->reserve(tags.size()); for (const auto& tag : tags) { - dq.policyTags->insert(tag.second); + dnsQuestion.policyTags->insert(tag.second); } } }); - d_lw->registerFunction >(DNSQuestion::*)()>("getPolicyTags", [](const DNSQuestion& dq) { + d_lw->registerFunction >(DNSQuestion::*)()>("getPolicyTags", [](const DNSQuestion& dnsQuestion) { std::vector > ret; - if (dq.policyTags) { + if (dnsQuestion.policyTags != nullptr) { int count = 1; - ret.reserve(dq.policyTags->size()); - for (const auto& tag : *dq.policyTags) { - ret.push_back({count++, tag}); + ret.reserve(dnsQuestion.policyTags->size()); + for (const auto& tag : *dnsQuestion.policyTags) { + ret.emplace_back(count++, tag); } } return ret; }); - d_lw->registerFunction("discardPolicy", [](DNSQuestion& dq, const std::string& policy) { - if (dq.discardedPolicies) { - (*dq.discardedPolicies)[policy] = true; + d_lw->registerFunction("discardPolicy", [](DNSQuestion& dnsQuestion, const std::string& policy) { + if (dnsQuestion.discardedPolicies != nullptr) { + (*dnsQuestion.discardedPolicies)[policy] = true; } }); d_lw->writeFunction("newDS", []() { return SuffixMatchNode(); }); d_lw->registerFunction > >)>( "add", - [](SuffixMatchNode&smn, const boost::variant > >& in){ + [](SuffixMatchNode&smn, const boost::variant > >& arg){ try { - if(auto s = boost::get(&in)) { - smn.add(DNSName(*s)); + if (const auto *name = boost::get(&arg)) { + smn.add(DNSName(*name)); } - else if(auto v = boost::get > >(&in)) { - for(const auto& entry : *v) + else if (const auto *vec = boost::get > >(&arg)) { + for (const auto& entry : *vec) { smn.add(DNSName(entry.second)); + } } else { - smn.add(boost::get(in)); + smn.add(boost::get(arg)); } } catch(std::exception& e) { @@ -388,8 +397,9 @@ void RecursorLua4::postPrepareContext() {"NSIP", (int)DNSFilterEngine::PolicyType::NSIP } }}); - for(const auto& n : QType::names) - d_pd.push_back({n.first, n.second}); + for(const auto& name : QType::names) { + d_pd.emplace_back(name.first, name.second); + } d_pd.push_back({"validationstates", in_t{ {"Indeterminate", static_cast(vState::Indeterminate) }, @@ -418,7 +428,7 @@ void RecursorLua4::postPrepareContext() return vStateIsBogus(state); }); - d_pd.push_back({"now", &g_now}); + d_pd.emplace_back("now", &g_now); d_lw->writeFunction("getMetric", [](const std::string& str, boost::optional prometheusName) { return DynMetric{getDynMetric(str, prometheusName ? *prometheusName : "")}; @@ -457,9 +467,9 @@ void RecursorLua4::postPrepareContext() d_lw->registerMember("isTcp", [](const PolicyEvent& event) -> bool { return event.isTcp; }, [](PolicyEvent& /* event */, bool newTcp) { (void) newTcp; }); d_lw->registerMember("remote", [](const PolicyEvent& event) -> const ComboAddress& { return event.remote; }, [](PolicyEvent& /* event */, const ComboAddress& newRemote) { (void) newRemote; }); d_lw->registerMember("appliedPolicy", &PolicyEvent::appliedPolicy); - d_lw->registerFunction("addPolicyTag", [](PolicyEvent& event, const std::string& tag) { if (event.policyTags) { event.policyTags->insert(tag); } }); + d_lw->registerFunction("addPolicyTag", [](PolicyEvent& event, const std::string& tag) { if (event.policyTags != nullptr) { event.policyTags->insert(tag); } }); d_lw->registerFunction >&)>("setPolicyTags", [](PolicyEvent& event, const std::vector >& tags) { - if (event.policyTags) { + if (event.policyTags != nullptr) { event.policyTags->clear(); event.policyTags->reserve(tags.size()); for (const auto& tag : tags) { @@ -469,17 +479,17 @@ void RecursorLua4::postPrepareContext() }); d_lw->registerFunction >(PolicyEvent::*)()>("getPolicyTags", [](const PolicyEvent& event) { std::vector > ret; - if (event.policyTags) { + if (event.policyTags != nullptr) { int count = 1; ret.reserve(event.policyTags->size()); for (const auto& tag : *event.policyTags) { - ret.push_back({count++, tag}); + ret.emplace_back(count++, tag); } } return ret; }); d_lw->registerFunction("discardPolicy", [](PolicyEvent& event, const std::string& policy) { - if (event.discardedPolicies) { + if (event.discardedPolicies != nullptr) { (*event.discardedPolicies)[policy] = true; } }); @@ -489,20 +499,20 @@ void RecursorLua4::postPrepareContext() void RecursorLua4::postLoad() { - d_prerpz = d_lw->readVariable>("prerpz").get_value_or(0); - d_preresolve = d_lw->readVariable>("preresolve").get_value_or(0); - d_nodata = d_lw->readVariable>("nodata").get_value_or(0); - d_nxdomain = d_lw->readVariable>("nxdomain").get_value_or(0); - d_postresolve = d_lw->readVariable>("postresolve").get_value_or(0); - d_preoutquery = d_lw->readVariable>("preoutquery").get_value_or(0); - d_maintenance = d_lw->readVariable>("maintenance").get_value_or(0); + d_prerpz = d_lw->readVariable>("prerpz").get_value_or(nullptr); + d_preresolve = d_lw->readVariable>("preresolve").get_value_or(nullptr); + d_nodata = d_lw->readVariable>("nodata").get_value_or(nullptr); + d_nxdomain = d_lw->readVariable>("nxdomain").get_value_or(nullptr); + d_postresolve = d_lw->readVariable>("postresolve").get_value_or(nullptr); + d_preoutquery = d_lw->readVariable>("preoutquery").get_value_or(nullptr); + d_maintenance = d_lw->readVariable>("maintenance").get_value_or(nullptr); - d_ipfilter = d_lw->readVariable>("ipfilter").get_value_or(0); - d_gettag = d_lw->readVariable>("gettag").get_value_or(0); - d_gettag_ffi = d_lw->readVariable>("gettag_ffi").get_value_or(0); - d_postresolve_ffi = d_lw->readVariable>("postresolve_ffi").get_value_or(0); + d_ipfilter = d_lw->readVariable>("ipfilter").get_value_or(nullptr); + d_gettag = d_lw->readVariable>("gettag").get_value_or(nullptr); + d_gettag_ffi = d_lw->readVariable>("gettag_ffi").get_value_or(nullptr); + d_postresolve_ffi = d_lw->readVariable>("postresolve_ffi").get_value_or(nullptr); - d_policyHitEventFilter = d_lw->readVariable>("policyEventFilter").get_value_or(0); + d_policyHitEventFilter = d_lw->readVariable>("policyEventFilter").get_value_or(nullptr); } void RecursorLua4::getFeatures(Features& features) @@ -514,9 +524,9 @@ void RecursorLua4::getFeatures(Features& features) features.emplace_back("PR8001_devicename", true); } -static void warnDrop(const RecursorLua4::DNSQuestion& dq) +static void warnDrop(const RecursorLua4::DNSQuestion& dnsQuestion) { - if (dq.rcode == -2) { + if (dnsQuestion.rcode == -2) { SLOG(g_log << Logger::Error << "Returning -2 (pdns.DROP) is not supported anymore, see https://docs.powerdns.com/recursor/lua-scripting/hooks.html#hooksemantics" << endl, g_slog->withName("lua")->info(Logr::Error, "Returning -2 (pdns.DROP) is not supported anymore, see https://docs.powerdns.com/recursor/lua-scripting/hooks.html#hooksemantics")); // We *could* set policy here, but that would also mean interfering with rcode and the return code of the hook. @@ -531,67 +541,67 @@ void RecursorLua4::maintenance() const } } -bool RecursorLua4::prerpz(DNSQuestion& dq, int& ret, RecEventTrace& et) const +bool RecursorLua4::prerpz(DNSQuestion& dnsQuestion, int& ret, RecEventTrace& eventTrace) const { if (!d_prerpz) { return false; } - et.add(RecEventTrace::LuaPreRPZ); - bool ok = genhook(d_prerpz, dq, ret); - et.add(RecEventTrace::LuaPreRPZ, ok, false); - warnDrop(dq); - return ok; + eventTrace.add(RecEventTrace::LuaPreRPZ); + bool isOK = genhook(d_prerpz, dnsQuestion, ret); + eventTrace.add(RecEventTrace::LuaPreRPZ, isOK, false); + warnDrop(dnsQuestion); + return isOK; } -bool RecursorLua4::preresolve(DNSQuestion& dq, int& ret, RecEventTrace& et) const +bool RecursorLua4::preresolve(DNSQuestion& dnsQuestion, int& ret, RecEventTrace& eventTrace) const { if (!d_preresolve) { return false; } - et.add(RecEventTrace::LuaPreResolve); - bool ok = genhook(d_preresolve, dq, ret); - et.add(RecEventTrace::LuaPreResolve, ok, false); - warnDrop(dq); - return ok; + eventTrace.add(RecEventTrace::LuaPreResolve); + bool isOK = genhook(d_preresolve, dnsQuestion, ret); + eventTrace.add(RecEventTrace::LuaPreResolve, isOK, false); + warnDrop(dnsQuestion); + return isOK; } -bool RecursorLua4::nxdomain(DNSQuestion& dq, int& ret, RecEventTrace& et) const +bool RecursorLua4::nxdomain(DNSQuestion& dnsQuestion, int& ret, RecEventTrace& eventTrace) const { if (!d_nxdomain) { return false; } - et.add(RecEventTrace::LuaNXDomain); - bool ok = genhook(d_nxdomain, dq, ret); - et.add(RecEventTrace::LuaNXDomain, ok, false); - warnDrop(dq); - return ok; + eventTrace.add(RecEventTrace::LuaNXDomain); + bool isOK = genhook(d_nxdomain, dnsQuestion, ret); + eventTrace.add(RecEventTrace::LuaNXDomain, isOK, false); + warnDrop(dnsQuestion); + return isOK; } -bool RecursorLua4::nodata(DNSQuestion& dq, int& ret, RecEventTrace& et) const +bool RecursorLua4::nodata(DNSQuestion& dnsQuestion, int& ret, RecEventTrace& eventTrace) const { if (!d_nodata) { return false; } - et.add(RecEventTrace::LuaNoData); - bool ok = genhook(d_nodata, dq, ret); - et.add(RecEventTrace::LuaNoData, ok, false); - warnDrop(dq); - return ok; + eventTrace.add(RecEventTrace::LuaNoData); + bool isOK = genhook(d_nodata, dnsQuestion, ret); + eventTrace.add(RecEventTrace::LuaNoData, isOK, false); + warnDrop(dnsQuestion); + return isOK; } -bool RecursorLua4::postresolve(DNSQuestion& dq, int& ret, RecEventTrace& et) const +bool RecursorLua4::postresolve(DNSQuestion& dnsQuestion, int& ret, RecEventTrace& eventTrace) const { if (!d_postresolve) { return false; } - et.add(RecEventTrace::LuaPostResolve); - bool ok = genhook(d_postresolve, dq, ret); - et.add(RecEventTrace::LuaPostResolve, ok, false); - warnDrop(dq); - return ok; + eventTrace.add(RecEventTrace::LuaPostResolve); + bool isOK = genhook(d_postresolve, dnsQuestion, ret); + eventTrace.add(RecEventTrace::LuaPostResolve, isOK, false); + warnDrop(dnsQuestion); + return isOK; } -bool RecursorLua4::preoutquery(const ComboAddress& ns, const ComboAddress& requestor, const DNSName& query, const QType& qtype, bool isTcp, vector& res, int& ret, RecEventTrace& et, const struct timeval& tv) const +bool RecursorLua4::preoutquery(const ComboAddress& nameserver, const ComboAddress& requestor, const DNSName& query, const QType& qtype, bool isTcp, vector& res, int& ret, RecEventTrace& eventTrace, const struct timeval& theTime) const { if (!d_preoutquery) { return false; @@ -600,24 +610,24 @@ bool RecursorLua4::preoutquery(const ComboAddress& ns, const ComboAddress& reque bool wantsRPZ = false; bool logQuery = false; bool addPaddingToResponse = false; - RecursorLua4::DNSQuestion dq(ns, requestor, query, qtype.getCode(), isTcp, variableAnswer, wantsRPZ, logQuery, addPaddingToResponse, tv); - dq.currentRecords = &res; - et.add(RecEventTrace::LuaPreOutQuery); - bool ok = genhook(d_preoutquery, dq, ret); - et.add(RecEventTrace::LuaPreOutQuery, ok, false); - warnDrop(dq); - return ok; + RecursorLua4::DNSQuestion dnsQuestion(nameserver, requestor, query, qtype.getCode(), isTcp, variableAnswer, wantsRPZ, logQuery, addPaddingToResponse, theTime); + dnsQuestion.currentRecords = &res; + eventTrace.add(RecEventTrace::LuaPreOutQuery); + bool isOK = genhook(d_preoutquery, dnsQuestion, ret); + eventTrace.add(RecEventTrace::LuaPreOutQuery, isOK, false); + warnDrop(dnsQuestion); + return isOK; } -bool RecursorLua4::ipfilter(const ComboAddress& remote, const ComboAddress& local, const struct dnsheader& dh, RecEventTrace& et) const +bool RecursorLua4::ipfilter(const ComboAddress& remote, const ComboAddress& local, const struct dnsheader& header, RecEventTrace& eventTrace) const { if (!d_ipfilter) { return false; // Do not block } - et.add(RecEventTrace::LuaIPFilter); - bool ok = d_ipfilter(remote, local, dh); - et.add(RecEventTrace::LuaIPFilter, ok, false); - return ok; + eventTrace.add(RecEventTrace::LuaIPFilter); + bool isOK = d_ipfilter(remote, local, header); + eventTrace.add(RecEventTrace::LuaIPFilter, isOK, false); + return isOK; } bool RecursorLua4::policyHitEventFilter(const ComboAddress& remote, const DNSName& qname, const QType& qtype, bool tcp, DNSFilterEngine::Policy& policy, std::unordered_set& tags, std::unordered_map& discardedPolicies) const @@ -631,14 +641,10 @@ bool RecursorLua4::policyHitEventFilter(const ComboAddress& remote, const DNSNam event.policyTags = &tags; event.discardedPolicies = &discardedPolicies; - if (d_policyHitEventFilter(event)) { - return true; - } - else { - return false; - } + return d_policyHitEventFilter(event); } +// NOLINTNEXTLINE(bugprone-easily-swappable-parameters) unsigned int RecursorLua4::gettag(const ComboAddress& remote, const Netmask& ednssubnet, const ComboAddress& local, const DNSName& qname, uint16_t qtype, std::unordered_set* policyTags, LuaContext::LuaObject& data, const EDNSOptionViewMap& ednsOptions, bool tcp, std::string& requestorId, std::string& deviceId, std::string& deviceName, std::string& routingTag, const std::vector& proxyProtocolValues) const { if (d_gettag) { @@ -720,61 +726,62 @@ unsigned int RecursorLua4::gettag_ffi(RecursorLua4::FFIParams& params) const return 0; } -bool RecursorLua4::genhook(const luacall_t& func, DNSQuestion& dq, int& ret) const +bool RecursorLua4::genhook(const luacall_t& func, DNSQuestion& dnsQuestion, int& ret) const { - if (!func) + if (!func) { return false; + } - if (dq.currentRecords) { - dq.records = *dq.currentRecords; + if (dnsQuestion.currentRecords != nullptr) { + dnsQuestion.records = *dnsQuestion.currentRecords; } else { - dq.records.clear(); + dnsQuestion.records.clear(); } - dq.followupFunction.clear(); - dq.followupPrefix.clear(); - dq.followupName.clear(); - dq.udpQuery.clear(); - dq.udpAnswer.clear(); - dq.udpCallback.clear(); + dnsQuestion.followupFunction.clear(); + dnsQuestion.followupPrefix.clear(); + dnsQuestion.followupName.clear(); + dnsQuestion.udpQuery.clear(); + dnsQuestion.udpAnswer.clear(); + dnsQuestion.udpCallback.clear(); - dq.rcode = ret; - bool handled = func(&dq); + dnsQuestion.rcode = ret; + bool handled = func(&dnsQuestion); if (handled) { loop:; - ret = dq.rcode; + ret = dnsQuestion.rcode; - if (!dq.followupFunction.empty()) { - if (dq.followupFunction == "followCNAMERecords") { - ret = followCNAMERecords(dq.records, QType(dq.qtype), ret); + if (!dnsQuestion.followupFunction.empty()) { + if (dnsQuestion.followupFunction == "followCNAMERecords") { + ret = followCNAMERecords(dnsQuestion.records, QType(dnsQuestion.qtype), ret); } - else if (dq.followupFunction == "getFakeAAAARecords") { - ret = getFakeAAAARecords(dq.followupName, ComboAddress(dq.followupPrefix), dq.records); + else if (dnsQuestion.followupFunction == "getFakeAAAARecords") { + ret = getFakeAAAARecords(dnsQuestion.followupName, ComboAddress(dnsQuestion.followupPrefix), dnsQuestion.records); } - else if (dq.followupFunction == "getFakePTRRecords") { - ret = getFakePTRRecords(dq.followupName, dq.records); + else if (dnsQuestion.followupFunction == "getFakePTRRecords") { + ret = getFakePTRRecords(dnsQuestion.followupName, dnsQuestion.records); } - else if (dq.followupFunction == "udpQueryResponse") { - PacketBuffer p = GenUDPQueryResponse(dq.udpQueryDest, dq.udpQuery); - dq.udpAnswer = std::string(reinterpret_cast(p.data()), p.size()); + else if (dnsQuestion.followupFunction == "udpQueryResponse") { + PacketBuffer packetBuffer = GenUDPQueryResponse(dnsQuestion.udpQueryDest, dnsQuestion.udpQuery); + dnsQuestion.udpAnswer = std::string(reinterpret_cast(packetBuffer.data()), packetBuffer.size()); // coverity[auto_causes_copy] not copying produces a dangling ref - const auto cbFunc = d_lw->readVariable>(dq.udpCallback).get_value_or(nullptr); + const auto cbFunc = d_lw->readVariable>(dnsQuestion.udpCallback).get_value_or(nullptr); if (!cbFunc) { SLOG(g_log << Logger::Error << "Attempted callback for Lua UDP Query/Response which could not be found" << endl, g_slog->withName("lua")->info(Logr::Error, "Attempted callback for Lua UDP Query/Response which could not be found")); return false; } - bool result = cbFunc(&dq); + bool result = cbFunc(&dnsQuestion); if (!result) { return false; } goto loop; } } - if (dq.currentRecords) { - *dq.currentRecords = dq.records; + if (dnsQuestion.currentRecords != nullptr) { + *dnsQuestion.currentRecords = dnsQuestion.records; } } @@ -782,7 +789,7 @@ bool RecursorLua4::genhook(const luacall_t& func, DNSQuestion& dq, int& ret) con return handled; } -RecursorLua4::~RecursorLua4() {} +RecursorLua4::~RecursorLua4() = default; const char* pdns_ffi_param_get_qname(pdns_ffi_param_t* ref) { @@ -814,15 +821,15 @@ const char* pdns_ffi_param_get_remote(pdns_ffi_param_t* ref) return ref->remoteStr->c_str(); } -static void pdns_ffi_comboaddress_to_raw(const ComboAddress& ca, const void** addr, size_t* addrSize) +static void pdns_ffi_comboaddress_to_raw(const ComboAddress& address, const void** addr, size_t* addrSize) { - if (ca.isIPv4()) { - *addr = &ca.sin4.sin_addr.s_addr; - *addrSize = sizeof(ca.sin4.sin_addr.s_addr); + if (address.isIPv4()) { + *addr = &address.sin4.sin_addr.s_addr; + *addrSize = sizeof(address.sin4.sin_addr.s_addr); } else { - *addr = &ca.sin6.sin6_addr.s6_addr; - *addrSize = sizeof(ca.sin6.sin6_addr.s6_addr); + *addr = &address.sin6.sin6_addr.s6_addr; + *addrSize = sizeof(address.sin6.sin6_addr.s6_addr); } } @@ -923,15 +930,15 @@ size_t pdns_ffi_param_get_edns_options(pdns_ffi_param_t* ref, const pdns_ednsopt size_t pdns_ffi_param_get_edns_options_by_code(pdns_ffi_param_t* ref, uint16_t optionCode, const pdns_ednsoption_t** out) { - const auto& it = ref->params.ednsOptions.find(optionCode); - if (it == ref->params.ednsOptions.cend() || it->second.values.empty()) { + const auto iter = ref->params.ednsOptions.find(optionCode); + if (iter == ref->params.ednsOptions.cend() || iter->second.values.empty()) { return 0; } - ref->ednsOptionsVect.resize(it->second.values.size()); + ref->ednsOptionsVect.resize(iter->second.values.size()); size_t pos = 0; - for (const auto& entry : it->second.values) { + for (const auto& entry : iter->second.values) { fill_edns_option(entry, ref->ednsOptionsVect.at(pos)); ref->ednsOptionsVect.at(pos).optionCode = optionCode; pos++; @@ -988,12 +995,12 @@ void pdns_ffi_param_set_devicename(pdns_ffi_param_t* ref, const char* name) void pdns_ffi_param_set_deviceid(pdns_ffi_param_t* ref, size_t len, const void* name) { - ref->params.deviceId = std::string(reinterpret_cast(name), len); + ref->params.deviceId = std::string(reinterpret_cast(name), len); // NOLINT: It's the API } -void pdns_ffi_param_set_routingtag(pdns_ffi_param_t* ref, const char* rtag) +void pdns_ffi_param_set_routingtag(pdns_ffi_param_t* ref, const char* name) { - ref->params.routingTag = std::string(rtag); + ref->params.routingTag = std::string(name); } void pdns_ffi_param_set_variable(pdns_ffi_param_t* ref, bool variable) @@ -1039,14 +1046,14 @@ void pdns_ffi_param_set_extended_error_extra(pdns_ffi_param_t* ref, size_t len, bool pdns_ffi_param_add_record(pdns_ffi_param_t* ref, const char* name, uint16_t type, uint32_t ttl, const char* content, size_t contentSize, pdns_record_place_t place) { try { - DNSRecord dr; - dr.d_name = name != nullptr ? DNSName(name) : ref->params.qname; - dr.d_ttl = ttl; - dr.d_type = type; - dr.d_class = QClass::IN; - dr.d_place = DNSResourceRecord::Place(place); - dr.setContent(DNSRecordContent::make(type, QClass::IN, std::string(content, contentSize))); - ref->params.records.push_back(std::move(dr)); + DNSRecord dnsRecord; + dnsRecord.d_name = name != nullptr ? DNSName(name) : ref->params.qname; + dnsRecord.d_ttl = ttl; + dnsRecord.d_type = type; + dnsRecord.d_class = QClass::IN; + dnsRecord.d_place = DNSResourceRecord::Place(place); + dnsRecord.setContent(DNSRecordContent::make(type, QClass::IN, std::string(content, contentSize))); + ref->params.records.push_back(std::move(dnsRecord)); return true; } @@ -1074,25 +1081,27 @@ void pdns_ffi_param_add_meta_single_int64_kv(pdns_ffi_param_t* ref, const char* struct pdns_postresolve_ffi_handle { public: - pdns_postresolve_ffi_handle(RecursorLua4::PostResolveFFIHandle& h) : - handle(h) + pdns_postresolve_ffi_handle(RecursorLua4::PostResolveFFIHandle& arg) : + handle(arg) { } - RecursorLua4::PostResolveFFIHandle& handle; + auto insert(std::string&& str) { - const auto it = pool.insert(std::move(str)).first; - return it; + const auto iter = pool.insert(std::move(str)).first; + return iter; } + RecursorLua4::PostResolveFFIHandle& handle; + private: std::unordered_set pool; }; -bool RecursorLua4::postresolve_ffi(RecursorLua4::PostResolveFFIHandle& h) const +bool RecursorLua4::postresolve_ffi(RecursorLua4::PostResolveFFIHandle& arg) const { if (d_postresolve_ffi) { - pdns_postresolve_ffi_handle_t handle(h); + pdns_postresolve_ffi_handle_t handle(arg); auto ret = d_postresolve_ffi(&handle); return ret; @@ -1138,36 +1147,36 @@ void pdns_postresolve_ffi_handle_set_appliedpolicy_kind(pdns_postresolve_ffi_han ref->handle.d_dq.appliedPolicy->d_kind = static_cast(kind); } -bool pdns_postresolve_ffi_handle_get_record(pdns_postresolve_ffi_handle_t* ref, unsigned int i, pdns_ffi_record_t* record, bool raw) +bool pdns_postresolve_ffi_handle_get_record(pdns_postresolve_ffi_handle_t* ref, unsigned int index, pdns_ffi_record_t* record, bool raw) { - if (i >= ref->handle.d_dq.currentRecords->size()) { + if (index >= ref->handle.d_dq.currentRecords->size()) { return false; } try { - DNSRecord& r = ref->handle.d_dq.currentRecords->at(i); + DNSRecord& dnsRecord = ref->handle.d_dq.currentRecords->at(index); if (raw) { - const auto& storage = r.d_name.getStorage(); + const auto& storage = dnsRecord.d_name.getStorage(); record->name = storage.data(); record->name_len = storage.size(); } else { - std::string name = r.d_name.toStringNoDot(); + std::string name = dnsRecord.d_name.toStringNoDot(); record->name_len = name.size(); record->name = ref->insert(std::move(name))->c_str(); } if (raw) { - auto content = ref->insert(r.getContent()->serialize(r.d_name, true)); + auto content = ref->insert(dnsRecord.getContent()->serialize(dnsRecord.d_name, true)); record->content = content->data(); record->content_len = content->size(); } else { - auto content = ref->insert(r.getContent()->getZoneRepresentation()); + auto content = ref->insert(dnsRecord.getContent()->getZoneRepresentation()); record->content = content->data(); record->content_len = content->size(); } - record->ttl = r.d_ttl; - record->place = static_cast(r.d_place); - record->type = r.d_type; + record->ttl = dnsRecord.d_ttl; + record->place = static_cast(dnsRecord.d_place); + record->type = dnsRecord.d_type; } catch (const std::exception& e) { g_log << Logger::Error << "Error attempting to get a record from Lua via pdns_postresolve_ffi_handle_get_record: " << e.what() << endl; @@ -1177,18 +1186,18 @@ bool pdns_postresolve_ffi_handle_get_record(pdns_postresolve_ffi_handle_t* ref, return true; } -bool pdns_postresolve_ffi_handle_set_record(pdns_postresolve_ffi_handle_t* ref, unsigned int i, const char* content, size_t contentLen, bool raw) +bool pdns_postresolve_ffi_handle_set_record(pdns_postresolve_ffi_handle_t* ref, unsigned int index, const char* content, size_t contentLen, bool raw) { - if (i >= ref->handle.d_dq.currentRecords->size()) { + if (index >= ref->handle.d_dq.currentRecords->size()) { return false; } try { - DNSRecord& r = ref->handle.d_dq.currentRecords->at(i); + DNSRecord& dnsRecord = ref->handle.d_dq.currentRecords->at(index); if (raw) { - r.setContent(DNSRecordContent::deserialize(r.d_name, r.d_type, string(content, contentLen))); + dnsRecord.setContent(DNSRecordContent::deserialize(dnsRecord.d_name, dnsRecord.d_type, string(content, contentLen))); } else { - r.setContent(DNSRecordContent::make(r.d_type, QClass::IN, string(content, contentLen))); + dnsRecord.setContent(DNSRecordContent::make(dnsRecord.d_type, QClass::IN, string(content, contentLen))); } return true; @@ -1207,19 +1216,19 @@ void pdns_postresolve_ffi_handle_clear_records(pdns_postresolve_ffi_handle_t* re bool pdns_postresolve_ffi_handle_add_record(pdns_postresolve_ffi_handle_t* ref, const char* name, uint16_t type, uint32_t ttl, const char* content, size_t contentLen, pdns_record_place_t place, bool raw) { try { - DNSRecord dr; - dr.d_name = name != nullptr ? DNSName(name) : ref->handle.d_dq.qname; - dr.d_ttl = ttl; - dr.d_type = type; - dr.d_class = QClass::IN; - dr.d_place = DNSResourceRecord::Place(place); + DNSRecord dnsRecord; + dnsRecord.d_name = name != nullptr ? DNSName(name) : ref->handle.d_dq.qname; + dnsRecord.d_ttl = ttl; + dnsRecord.d_type = type; + dnsRecord.d_class = QClass::IN; + dnsRecord.d_place = DNSResourceRecord::Place(place); if (raw) { - dr.setContent(DNSRecordContent::deserialize(dr.d_name, dr.d_type, string(content, contentLen))); + dnsRecord.setContent(DNSRecordContent::deserialize(dnsRecord.d_name, dnsRecord.d_type, string(content, contentLen))); } else { - dr.setContent(DNSRecordContent::make(type, QClass::IN, string(content, contentLen))); + dnsRecord.setContent(DNSRecordContent::make(type, QClass::IN, string(content, contentLen))); } - ref->handle.d_dq.currentRecords->push_back(std::move(dr)); + ref->handle.d_dq.currentRecords->push_back(std::move(dnsRecord)); return true; } diff --git a/pdns/recursordist/lua-recursor4.hh b/pdns/recursordist/lua-recursor4.hh index dd1c117559..b59d0567b2 100644 --- a/pdns/recursordist/lua-recursor4.hh +++ b/pdns/recursordist/lua-recursor4.hh @@ -73,7 +73,11 @@ class RecursorLua4 : public BaseLua4 { public: RecursorLua4(); - ~RecursorLua4(); // this is so unique_ptr works with an incomplete type + RecursorLua4(const RecursorLua4&) = delete; + RecursorLua4(RecursorLua4&&) = delete; + RecursorLua4& operator=(const RecursorLua4&) = delete; + RecursorLua4& operator=(RecursorLua4&&) = delete; + ~RecursorLua4() override; // this is so unique_ptr works with an incomplete type struct MetaValue { @@ -82,6 +86,7 @@ public: }; struct DNSQuestion { + // NOLINTNEXTLINE(bugprone-easily-swappable-parameters) DNSQuestion(const ComboAddress& rem, const ComboAddress& loc, const DNSName& query, uint16_t type, bool tcp, bool& variable_, bool& wantsRPZ_, bool& logResponse_, bool& addPaddingToResponse_, const struct timeval& queryTime_) : qname(query), qtype(type), local(loc), remote(rem), isTcp(tcp), variable(variable_), wantsRPZ(wantsRPZ_), logResponse(logResponse_), addPaddingToResponse(addPaddingToResponse_), queryTime(queryTime_) { @@ -116,15 +121,15 @@ public: void addAnswer(uint16_t type, const std::string& content, boost::optional ttl, boost::optional name); void addRecord(uint16_t type, const std::string& content, DNSResourceRecord::Place place, boost::optional ttl, boost::optional name); - vector> getRecords() const; - boost::optional getDH() const; - vector> getEDNSOptions() const; - boost::optional getEDNSOption(uint16_t code) const; - boost::optional getEDNSSubnet() const; - std::vector> getProxyProtocolValues() const; - vector getEDNSFlags() const; - bool getEDNSFlag(string flag) const; - void setRecords(const vector>& records); + [[nodiscard]] vector> getRecords() const; + [[nodiscard]] boost::optional getDH() const; + [[nodiscard]] vector> getEDNSOptions() const; + [[nodiscard]] boost::optional getEDNSOption(uint16_t code) const; + [[nodiscard]] boost::optional getEDNSSubnet() const; + [[nodiscard]] std::vector> getProxyProtocolValues() const; + [[nodiscard]] vector getEDNSFlags() const; + [[nodiscard]] bool getEDNSFlag(const string& flag) const; + void setRecords(const vector>& arg); int rcode{0}; // struct dnsheader, packet length would be great @@ -160,6 +165,7 @@ public: struct FFIParams { public: + // NOLINTNEXTLINE(bugprone-easily-swappable-parameters) FFIParams(const DNSName& qname_, uint16_t qtype_, const ComboAddress& local_, const ComboAddress& remote_, const Netmask& ednssubnet_, LuaContext::LuaObject& data_, std::unordered_set& policyTags_, std::vector& records_, const EDNSOptionViewMap& ednsOptions_, const std::vector& proxyProtocolValues_, std::string& requestorId_, std::string& deviceId_, std::string& deviceName_, std::string& routingTag_, boost::optional& rcode_, uint32_t& ttlCap_, bool& variable_, bool tcp_, bool& logQuery_, bool& logResponse_, bool& followCNAMERecords_, boost::optional& extendedErrorCode_, std::string& extendedErrorExtra_, bool& disablePadding_, std::map& meta_) : data(data_), qname(qname_), local(local_), remote(remote_), ednssubnet(ednssubnet_), policyTags(policyTags_), records(records_), ednsOptions(ednsOptions_), proxyProtocolValues(proxyProtocolValues_), requestorId(requestorId_), deviceId(deviceId_), deviceName(deviceName_), routingTag(routingTag_), extendedErrorExtra(extendedErrorExtra_), rcode(rcode_), extendedErrorCode(extendedErrorCode_), ttlCap(ttlCap_), variable(variable_), logQuery(logQuery_), logResponse(logResponse_), followCNAMERecords(followCNAMERecords_), disablePadding(disablePadding_), qtype(qtype_), tcp(tcp_), meta(meta_) { @@ -199,54 +205,54 @@ public: unsigned int gettag_ffi(FFIParams&) const; void maintenance() const; - bool prerpz(DNSQuestion& dq, int& ret, RecEventTrace&) const; - bool preresolve(DNSQuestion& dq, int& ret, RecEventTrace&) const; - bool nxdomain(DNSQuestion& dq, int& ret, RecEventTrace&) const; - bool nodata(DNSQuestion& dq, int& ret, RecEventTrace&) const; - bool postresolve(DNSQuestion& dq, int& ret, RecEventTrace&) const; + bool prerpz(DNSQuestion& dnsQuestion, int& ret, RecEventTrace&) const; + bool preresolve(DNSQuestion& dnsQuestion, int& ret, RecEventTrace&) const; + bool nxdomain(DNSQuestion& dnsQuestion, int& ret, RecEventTrace&) const; + bool nodata(DNSQuestion& dnsQuestion, int& ret, RecEventTrace&) const; + bool postresolve(DNSQuestion& dnsQuestion, int& ret, RecEventTrace&) const; - bool preoutquery(const ComboAddress& ns, const ComboAddress& requestor, const DNSName& query, const QType& qtype, bool isTcp, vector& res, int& ret, RecEventTrace& et, const struct timeval& tv) const; + bool preoutquery(const ComboAddress& nameserver, const ComboAddress& requestor, const DNSName& query, const QType& qtype, bool isTcp, vector& res, int& ret, RecEventTrace& eventTrace, const struct timeval& theTime) const; bool ipfilter(const ComboAddress& remote, const ComboAddress& local, const struct dnsheader&, RecEventTrace&) const; bool policyHitEventFilter(const ComboAddress& remote, const DNSName& qname, const QType& qtype, bool tcp, DNSFilterEngine::Policy& policy, std::unordered_set& tags, std::unordered_map& discardedPolicies) const; - bool needDQ() const + [[nodiscard]] bool needDQ() const { return (d_prerpz || d_preresolve || d_nxdomain || d_nodata || d_postresolve); } - typedef std::function>, boost::optional, boost::optional, boost::optional, boost::optional, boost::optional>(ComboAddress, Netmask, ComboAddress, DNSName, uint16_t, const EDNSOptionViewMap&, bool, const std::vector>&)> gettag_t; + using gettag_t = std::function>, boost::optional, boost::optional, boost::optional, boost::optional, boost::optional> (ComboAddress, Netmask, ComboAddress, DNSName, uint16_t, const EDNSOptionViewMap &, bool, const std::vector> &)>; gettag_t d_gettag; // public so you can query if we have this hooked - typedef std::function(pdns_ffi_param_t*)> gettag_ffi_t; + using gettag_ffi_t = std::function (pdns_ffi_param_t *)>; gettag_ffi_t d_gettag_ffi; struct PostResolveFFIHandle { - PostResolveFFIHandle(DNSQuestion& dq) : - d_dq(dq) + PostResolveFFIHandle(DNSQuestion& dnsQuestion) : + d_dq(dnsQuestion) { } DNSQuestion& d_dq; bool d_ret{false}; }; bool postresolve_ffi(PostResolveFFIHandle&) const; - typedef std::function postresolve_ffi_t; + using postresolve_ffi_t = std::function; postresolve_ffi_t d_postresolve_ffi; protected: - virtual void postPrepareContext() override; - virtual void postLoad() override; - virtual void getFeatures(Features& features) override; + void postPrepareContext() override; + void postLoad() override; + void getFeatures(Features& features) override; private: - typedef std::function luamaintenance_t; + using luamaintenance_t = std::function; luamaintenance_t d_maintenance; - typedef std::function luacall_t; + using luacall_t = std::function; luacall_t d_prerpz, d_preresolve, d_nxdomain, d_nodata, d_postresolve, d_preoutquery, d_postoutquery; - bool genhook(const luacall_t& func, DNSQuestion& dq, int& ret) const; - typedef std::function ipfilter_t; + bool genhook(const luacall_t& func, DNSQuestion& dnsQuestion, int& ret) const; + using ipfilter_t = std::function; ipfilter_t d_ipfilter; - typedef std::function policyEventFilter_t; + using policyEventFilter_t = std::function; policyEventFilter_t d_policyHitEventFilter; }; -- 2.47.2