]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
Make a few fields (d_gettag and friends and handle) private
authorOtto Moerbeek <otto.moerbeek@open-xchange.com>
Mon, 11 Mar 2024 09:05:44 +0000 (10:05 +0100)
committerOtto Moerbeek <otto.moerbeek@open-xchange.com>
Wed, 13 Mar 2024 09:23:23 +0000 (10:23 +0100)
pdns/recursordist/lua-recursor4.cc
pdns/recursordist/lua-recursor4.hh
pdns/recursordist/pdns_recursor.cc
pdns/recursordist/rec-tcp.cc

index d6dd545ac27790306eb02ece35be9fbf8d70d1f9..a9d6850b592bb042d482ad2d2e4a1249303c091b 100644 (file)
@@ -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<std::string> 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<pdns_policy_kind_t>(ref->handle.d_dq.appliedPolicy->d_kind);
+  return static_cast<pdns_policy_kind_t>(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<DNSFilterEngine::PolicyKind>(kind);
+  ref->getHandle().d_dq.appliedPolicy->d_kind = static_cast<DNSFilterEngine::PolicyKind>(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);
 }
index b59d0567b29265b9dd0926f2f2c28e9fc8ac46ca..b90fe7686693343eab0981889352883b3f93ac59 100644 (file)
@@ -221,11 +221,6 @@ public:
     return (d_prerpz || d_preresolve || d_nxdomain || d_nodata || d_postresolve);
   }
 
-  using gettag_t = std::function<std::tuple<unsigned int, boost::optional<std::unordered_map<int, string>>, boost::optional<LuaContext::LuaObject>, boost::optional<std::string>, boost::optional<std::string>, boost::optional<std::string>, boost::optional<string>> (ComboAddress, Netmask, ComboAddress, DNSName, uint16_t, const EDNSOptionViewMap &, bool, const std::vector<std::pair<int, const ProxyProtocolValue *>> &)>;
-  gettag_t d_gettag; // public so you can query if we have this hooked
-
-  using gettag_ffi_t = std::function<boost::optional<LuaContext::LuaObject> (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<bool (pdns_postresolve_ffi_handle_t *)>;
-  postresolve_ffi_t d_postresolve_ffi;
+
+  [[nodiscard]] bool hasGettagFunc() const
+  {
+    return static_cast<bool>(d_gettag);
+  }
+  [[nodiscard]] bool hasGettagFFIFunc() const
+  {
+    return static_cast<bool>(d_gettag_ffi);
+  }
+  [[nodiscard]] bool hasPostResolveFFIfunc() const
+  {
+    return static_cast<bool>(d_postresolve_ffi);
+  }
 
 protected:
   void postPrepareContext() override;
@@ -246,13 +252,25 @@ protected:
   void getFeatures(Features& features) override;
 
 private:
+  using gettag_t = std::function<std::tuple<unsigned int, boost::optional<std::unordered_map<int, string>>, boost::optional<LuaContext::LuaObject>, boost::optional<std::string>, boost::optional<std::string>, boost::optional<std::string>, boost::optional<string>> (ComboAddress, Netmask, ComboAddress, DNSName, uint16_t, const EDNSOptionViewMap &, bool, const std::vector<std::pair<int, const ProxyProtocolValue *>> &)>;
+  gettag_t d_gettag; // public so you can query if we have this hooked
+
+  using gettag_ffi_t = std::function<boost::optional<LuaContext::LuaObject> (pdns_ffi_param_t *)>;
+  gettag_ffi_t d_gettag_ffi;
+
+  using postresolve_ffi_t = std::function<bool (pdns_postresolve_ffi_handle_t *)>;
+  postresolve_ffi_t d_postresolve_ffi;
+
   using luamaintenance_t = std::function<void ()>;
   luamaintenance_t d_maintenance;
+
   using luacall_t = std::function<bool (DNSQuestion *)>;
   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<bool (ComboAddress, ComboAddress, struct dnsheader)>;
   ipfilter_t d_ipfilter;
+
   using policyEventFilter_t = std::function<bool (PolicyEvent &)>;
   policyEventFilter_t d_policyHitEventFilter;
 };
index 419e341369d0ce9e1f561dc85a86bf2e31f49b42..56c9954643640ec42bd918a62fd0dfcd440e0cf9 100644 (file)
@@ -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<unsigned>(Opcode::Notify)) {
+    if (needECS || (t_pdl && (t_pdl->hasGettagFunc() || t_pdl->hasGettagFFIFunc())) || dnsheader->opcode == static_cast<unsigned>(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);
index 0eac47653b534f8eeefd95278f7df86a0a6e6cc9..196db6fe7b66a1da64a4eae94c1cf3c02e3af4a2 100644 (file)
@@ -314,7 +314,7 @@ static void doProcessTCPQuestion(std::unique_ptr<DNSComboWriter>& 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<unsigned>(Opcode::Notify)) {
+  if (needECS || (t_pdl && (t_pdl->hasGettagFFIFunc() || t_pdl->hasGettagFunc())) || comboWriter->d_mdp.d_header.opcode == static_cast<unsigned>(Opcode::Notify)) {
 
     try {
       EDNSOptionViewMap ednsOptions;
@@ -326,13 +326,13 @@ static void doProcessTCPQuestion(std::unique_ptr<DNSComboWriter>& 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);