From: Otto Moerbeek Date: Mon, 11 Mar 2024 09:05:44 +0000 (+0100) Subject: Make a few fields (d_gettag and friends and handle) private X-Git-Tag: rec-5.1.0-alpha1~130^2~2 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=3bc38426b64ea9207d4da4f38a130eaa3f65343c;p=thirdparty%2Fpdns.git Make a few fields (d_gettag and friends and handle) private --- diff --git a/pdns/recursordist/lua-recursor4.cc b/pdns/recursordist/lua-recursor4.cc index d6dd545ac2..a9d6850b59 100644 --- a/pdns/recursordist/lua-recursor4.cc +++ b/pdns/recursordist/lua-recursor4.cc @@ -1092,9 +1092,12 @@ public: return iter; } - RecursorLua4::PostResolveFFIHandle& handle; - + [[nodiscard]] const RecursorLua4::PostResolveFFIHandle& getHandle() const + { + return handle; + } private: + RecursorLua4::PostResolveFFIHandle& handle; std::unordered_set pool; }; @@ -1111,49 +1114,49 @@ bool RecursorLua4::postresolve_ffi(RecursorLua4::PostResolveFFIHandle& arg) cons const char* pdns_postresolve_ffi_handle_get_qname(pdns_postresolve_ffi_handle_t* ref) { - auto str = ref->insert(ref->handle.d_dq.qname.toStringNoDot()); + auto str = ref->insert(ref->getHandle().d_dq.qname.toStringNoDot()); return str->c_str(); } void pdns_postresolve_ffi_handle_get_qname_raw(pdns_postresolve_ffi_handle_t* ref, const char** qname, size_t* qnameSize) { - const auto& storage = ref->handle.d_dq.qname.getStorage(); + const auto& storage = ref->getHandle().d_dq.qname.getStorage(); *qname = storage.data(); *qnameSize = storage.size(); } uint16_t pdns_postresolve_ffi_handle_get_qtype(const pdns_postresolve_ffi_handle_t* ref) { - return ref->handle.d_dq.qtype; + return ref->getHandle().d_dq.qtype; } uint16_t pdns_postresolve_ffi_handle_get_rcode(const pdns_postresolve_ffi_handle_t* ref) { - return ref->handle.d_dq.rcode; + return ref->getHandle().d_dq.rcode; } void pdns_postresolve_ffi_handle_set_rcode(const pdns_postresolve_ffi_handle_t* ref, uint16_t rcode) { - ref->handle.d_dq.rcode = rcode; + ref->getHandle().d_dq.rcode = rcode; } pdns_policy_kind_t pdns_postresolve_ffi_handle_get_appliedpolicy_kind(const pdns_postresolve_ffi_handle_t* ref) { - return static_cast(ref->handle.d_dq.appliedPolicy->d_kind); + return static_cast(ref->getHandle().d_dq.appliedPolicy->d_kind); } void pdns_postresolve_ffi_handle_set_appliedpolicy_kind(pdns_postresolve_ffi_handle_t* ref, pdns_policy_kind_t kind) { - ref->handle.d_dq.appliedPolicy->d_kind = static_cast(kind); + ref->getHandle().d_dq.appliedPolicy->d_kind = static_cast(kind); } bool pdns_postresolve_ffi_handle_get_record(pdns_postresolve_ffi_handle_t* ref, unsigned int index, pdns_ffi_record_t* record, bool raw) { - if (index >= ref->handle.d_dq.currentRecords->size()) { + if (index >= ref->getHandle().d_dq.currentRecords->size()) { return false; } try { - DNSRecord& dnsRecord = ref->handle.d_dq.currentRecords->at(index); + DNSRecord& dnsRecord = ref->getHandle().d_dq.currentRecords->at(index); if (raw) { const auto& storage = dnsRecord.d_name.getStorage(); record->name = storage.data(); @@ -1188,11 +1191,11 @@ bool pdns_postresolve_ffi_handle_get_record(pdns_postresolve_ffi_handle_t* ref, 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 (index >= ref->handle.d_dq.currentRecords->size()) { + if (index >= ref->getHandle().d_dq.currentRecords->size()) { return false; } try { - DNSRecord& dnsRecord = ref->handle.d_dq.currentRecords->at(index); + DNSRecord& dnsRecord = ref->getHandle().d_dq.currentRecords->at(index); if (raw) { dnsRecord.setContent(DNSRecordContent::deserialize(dnsRecord.d_name, dnsRecord.d_type, string(content, contentLen))); } @@ -1210,14 +1213,14 @@ bool pdns_postresolve_ffi_handle_set_record(pdns_postresolve_ffi_handle_t* ref, void pdns_postresolve_ffi_handle_clear_records(pdns_postresolve_ffi_handle_t* ref) { - ref->handle.d_dq.currentRecords->clear(); + ref->getHandle().d_dq.currentRecords->clear(); } 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 dnsRecord; - dnsRecord.d_name = name != nullptr ? DNSName(name) : ref->handle.d_dq.qname; + dnsRecord.d_name = name != nullptr ? DNSName(name) : ref->getHandle().d_dq.qname; dnsRecord.d_ttl = ttl; dnsRecord.d_type = type; dnsRecord.d_class = QClass::IN; @@ -1228,7 +1231,7 @@ bool pdns_postresolve_ffi_handle_add_record(pdns_postresolve_ffi_handle_t* ref, else { dnsRecord.setContent(DNSRecordContent::make(type, QClass::IN, string(content, contentLen))); } - ref->handle.d_dq.currentRecords->push_back(std::move(dnsRecord)); + ref->getHandle().d_dq.currentRecords->push_back(std::move(dnsRecord)); return true; } @@ -1240,10 +1243,10 @@ bool pdns_postresolve_ffi_handle_add_record(pdns_postresolve_ffi_handle_t* ref, const char* pdns_postresolve_ffi_handle_get_authip(pdns_postresolve_ffi_handle_t* ref) { - return ref->insert(ref->handle.d_dq.fromAuthIP->toString())->c_str(); + return ref->insert(ref->getHandle().d_dq.fromAuthIP->toString())->c_str(); } void pdns_postresolve_ffi_handle_get_authip_raw(pdns_postresolve_ffi_handle_t* ref, const void** addr, size_t* addrSize) { - return pdns_ffi_comboaddress_to_raw(*ref->handle.d_dq.fromAuthIP, addr, addrSize); + return pdns_ffi_comboaddress_to_raw(*ref->getHandle().d_dq.fromAuthIP, addr, addrSize); } diff --git a/pdns/recursordist/lua-recursor4.hh b/pdns/recursordist/lua-recursor4.hh index b59d0567b2..b90fe76866 100644 --- a/pdns/recursordist/lua-recursor4.hh +++ b/pdns/recursordist/lua-recursor4.hh @@ -221,11 +221,6 @@ public: return (d_prerpz || d_preresolve || d_nxdomain || d_nodata || d_postresolve); } - 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 - - using gettag_ffi_t = std::function (pdns_ffi_param_t *)>; - gettag_ffi_t d_gettag_ffi; struct PostResolveFFIHandle { @@ -237,8 +232,19 @@ public: bool d_ret{false}; }; bool postresolve_ffi(PostResolveFFIHandle&) const; - using postresolve_ffi_t = std::function; - postresolve_ffi_t d_postresolve_ffi; + + [[nodiscard]] bool hasGettagFunc() const + { + return static_cast(d_gettag); + } + [[nodiscard]] bool hasGettagFFIFunc() const + { + return static_cast(d_gettag_ffi); + } + [[nodiscard]] bool hasPostResolveFFIfunc() const + { + return static_cast(d_postresolve_ffi); + } protected: void postPrepareContext() override; @@ -246,13 +252,25 @@ protected: void getFeatures(Features& features) override; private: + 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 + + using gettag_ffi_t = std::function (pdns_ffi_param_t *)>; + gettag_ffi_t d_gettag_ffi; + + using postresolve_ffi_t = std::function; + postresolve_ffi_t d_postresolve_ffi; + using luamaintenance_t = std::function; luamaintenance_t d_maintenance; + 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& dnsQuestion, int& ret) const; + using ipfilter_t = std::function; ipfilter_t d_ipfilter; + using policyEventFilter_t = std::function; policyEventFilter_t d_policyHitEventFilter; }; diff --git a/pdns/recursordist/pdns_recursor.cc b/pdns/recursordist/pdns_recursor.cc index 419e341369..56c9954643 100644 --- a/pdns/recursordist/pdns_recursor.cc +++ b/pdns/recursordist/pdns_recursor.cc @@ -1348,7 +1348,7 @@ void startDoResolve(void* arg) // NOLINT(readability-function-cognitive-complexi if (comboWriter->d_luaContext) { PolicyResult policyResult = PolicyResult::NoAction; - if (comboWriter->d_luaContext->d_postresolve_ffi) { + if (comboWriter->d_luaContext->hasPostResolveFFIfunc()) { RecursorLua4::PostResolveFFIHandle handle(dnsQuestion); resolver.d_eventTrace.add(RecEventTrace::LuaPostResolveFFI); bool prResult = comboWriter->d_luaContext->postresolve_ffi(handle); @@ -2201,7 +2201,7 @@ static string* doProcessUDPQuestion(const std::string& question, const ComboAddr #endif // We do not have a SyncRes specific Lua context at this point yet, so ok to use t_pdl - if (needECS || (t_pdl && (t_pdl->d_gettag || t_pdl->d_gettag_ffi)) || dnsheader->opcode == static_cast(Opcode::Notify)) { + if (needECS || (t_pdl && (t_pdl->hasGettagFunc() || t_pdl->hasGettagFFIFunc())) || dnsheader->opcode == static_cast(Opcode::Notify)) { try { EDNSOptionViewMap ednsOptions; @@ -2215,14 +2215,14 @@ static string* doProcessUDPQuestion(const std::string& question, const ComboAddr if (t_pdl) { try { - if (t_pdl->d_gettag_ffi) { + if (t_pdl->hasGettagFFIFunc()) { RecursorLua4::FFIParams params(qname, qtype, destination, source, ednssubnet.source, data, policyTags, records, ednsOptions, proxyProtocolValues, requestorId, deviceId, deviceName, routingTag, rcode, ttlCap, variable, false, logQuery, logResponse, followCNAMEs, extendedErrorCode, extendedErrorExtra, responsePaddingDisabled, meta); eventTrace.add(RecEventTrace::LuaGetTagFFI); ctag = t_pdl->gettag_ffi(params); eventTrace.add(RecEventTrace::LuaGetTagFFI, ctag, false); } - else if (t_pdl->d_gettag) { + else if (t_pdl->hasGettagFunc()) { eventTrace.add(RecEventTrace::LuaGetTag); ctag = t_pdl->gettag(source, ednssubnet.source, destination, qname, qtype, &policyTags, data, ednsOptions, false, requestorId, deviceId, deviceName, routingTag, proxyProtocolValues); eventTrace.add(RecEventTrace::LuaGetTag, ctag, false); diff --git a/pdns/recursordist/rec-tcp.cc b/pdns/recursordist/rec-tcp.cc index 0eac47653b..196db6fe7b 100644 --- a/pdns/recursordist/rec-tcp.cc +++ b/pdns/recursordist/rec-tcp.cc @@ -314,7 +314,7 @@ static void doProcessTCPQuestion(std::unique_ptr& comboWriter, s logQuery = t_protobufServers.servers && luaconfsLocal->protobufExportConfig.logQueries; comboWriter->d_logResponse = t_protobufServers.servers && luaconfsLocal->protobufExportConfig.logResponses; - if (needECS || (t_pdl && (t_pdl->d_gettag_ffi || t_pdl->d_gettag)) || comboWriter->d_mdp.d_header.opcode == static_cast(Opcode::Notify)) { + if (needECS || (t_pdl && (t_pdl->hasGettagFFIFunc() || t_pdl->hasGettagFunc())) || comboWriter->d_mdp.d_header.opcode == static_cast(Opcode::Notify)) { try { EDNSOptionViewMap ednsOptions; @@ -326,13 +326,13 @@ static void doProcessTCPQuestion(std::unique_ptr& comboWriter, s if (t_pdl) { try { - if (t_pdl->d_gettag_ffi) { + if (t_pdl->hasGettagFFIFunc()) { RecursorLua4::FFIParams params(qname, qtype, comboWriter->d_destination, comboWriter->d_source, comboWriter->d_ednssubnet.source, comboWriter->d_data, comboWriter->d_policyTags, comboWriter->d_records, ednsOptions, comboWriter->d_proxyProtocolValues, requestorId, deviceId, deviceName, comboWriter->d_routingTag, comboWriter->d_rcode, comboWriter->d_ttlCap, comboWriter->d_variable, true, logQuery, comboWriter->d_logResponse, comboWriter->d_followCNAMERecords, comboWriter->d_extendedErrorCode, comboWriter->d_extendedErrorExtra, comboWriter->d_responsePaddingDisabled, comboWriter->d_meta); comboWriter->d_eventTrace.add(RecEventTrace::LuaGetTagFFI); comboWriter->d_tag = t_pdl->gettag_ffi(params); comboWriter->d_eventTrace.add(RecEventTrace::LuaGetTagFFI, comboWriter->d_tag, false); } - else if (t_pdl->d_gettag) { + else if (t_pdl->hasGettagFunc()) { comboWriter->d_eventTrace.add(RecEventTrace::LuaGetTag); comboWriter->d_tag = t_pdl->gettag(comboWriter->d_source, comboWriter->d_ednssubnet.source, comboWriter->d_destination, qname, qtype, &comboWriter->d_policyTags, comboWriter->d_data, ednsOptions, true, requestorId, deviceId, deviceName, comboWriter->d_routingTag, comboWriter->d_proxyProtocolValues); comboWriter->d_eventTrace.add(RecEventTrace::LuaGetTag, comboWriter->d_tag, false);