]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
Set the domain ID
authorFred Morcos <fred.morcos@open-xchange.com>
Mon, 9 Oct 2023 13:02:51 +0000 (15:02 +0200)
committerFred Morcos <fred.morcos@open-xchange.com>
Thu, 12 Oct 2023 14:45:31 +0000 (16:45 +0200)
modules/geoipbackend/geoipbackend.cc
modules/geoipbackend/geoipbackend.hh

index 497d80c860cf0c9f6afe8a6b1f19ca730e15039f..5341e1d8549a478d922a00a24e7893f95271b37e 100644 (file)
@@ -19,6 +19,7 @@
  * along with this program; if not, write to the Free Software
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  */
+#include <cstdint>
 #ifdef HAVE_CONFIG_H
 #include "config.h"
 #endif
@@ -51,7 +52,7 @@ struct GeoIPService
 
 struct GeoIPDomain
 {
-  int id;
+  std::uint32_t id{};
   DNSName domain;
   int ttl{};
   map<DNSName, GeoIPService> services;
@@ -123,9 +124,10 @@ static bool validateMappingLookupFormats(const vector<string>& formats)
   return true;
 }
 
-bool GeoIPBackend::loadDomain(const YAML::Node& domain, unsigned int id, GeoIPDomain& dom)
+bool GeoIPBackend::loadDomain(const YAML::Node& domain, std::uint32_t domainID, GeoIPDomain& dom)
 {
   try {
+    dom.id = domainID;
     dom.domain = DNSName(domain["domain"].as<string>());
     dom.ttl = domain["ttl"].as<int>();
 
@@ -136,7 +138,7 @@ bool GeoIPBackend::loadDomain(const YAML::Node& domain, unsigned int id, GeoIPDo
       for (auto item = recs->second.begin(); item != recs->second.end(); item++) {
         auto rec = item->begin();
         GeoIPDNSResourceRecord rr;
-        rr.domain_id = dom.id;
+        rr.domain_id = static_cast<int>(dom.id);
         rr.ttl = dom.ttl;
         rr.qname = qname;
         if (rec->first.IsNull()) {
@@ -260,18 +262,18 @@ bool GeoIPBackend::loadDomain(const YAML::Node& domain, unsigned int id, GeoIPDo
       // ensure we have parent in records
       DNSName name = item.first;
       while (name.chopOff() && name.isPartOf(dom.domain)) {
-          GeoIPDNSResourceRecord rr;
         if (dom.records.find(name) == dom.records.end() && (dom.services.count(name) == 0U)) { // don't ENT out a service!
+          GeoIPDNSResourceRecord resourceRecord;
           vector<GeoIPDNSResourceRecord> rrs;
-          rr.domain_id = dom.id;
-          rr.ttl = dom.ttl;
-          rr.qname = name;
-          rr.qtype = QType(0); // empty non terminal
-          rr.content = "";
-          rr.auth = 1;
-          rr.weight = 100;
-          rr.has_weight = false;
-          rrs.push_back(rr);
+          resourceRecord.domain_id = static_cast<int>(dom.id);
+          resourceRecord.ttl = dom.ttl;
+          resourceRecord.qname = name;
+          resourceRecord.qtype = QType(0); // empty non terminal
+          resourceRecord.content = "";
+          resourceRecord.auth = true;
+          resourceRecord.weight = 100;
+          resourceRecord.has_weight = false;
+          rrs.push_back(resourceRecord);
           std::swap(dom.records[name], rrs);
         }
       }
@@ -283,17 +285,17 @@ bool GeoIPBackend::loadDomain(const YAML::Node& domain, unsigned int id, GeoIPDo
       DNSName name = item.first;
       while (name.chopOff() && name.isPartOf(dom.domain)) {
         if (dom.records.find(name) == dom.records.end()) {
-          GeoIPDNSResourceRecord rr;
+          GeoIPDNSResourceRecord resourceRecord;
           vector<GeoIPDNSResourceRecord> rrs;
-          rr.domain_id = dom.id;
-          rr.ttl = dom.ttl;
-          rr.qname = name;
-          rr.qtype = QType(0);
-          rr.content = "";
-          rr.auth = 1;
-          rr.weight = 100;
-          rr.has_weight = false;
-          rrs.push_back(rr);
+          resourceRecord.domain_id = static_cast<int>(dom.id);
+          resourceRecord.ttl = dom.ttl;
+          resourceRecord.qname = name;
+          resourceRecord.qtype = QType(0);
+          resourceRecord.content = "";
+          resourceRecord.auth = true;
+          resourceRecord.weight = 100;
+          resourceRecord.has_weight = false;
+          rrs.push_back(resourceRecord);
           std::swap(dom.records[name], rrs);
         }
       }
@@ -409,8 +411,7 @@ void GeoIPBackend::initialize()
 
   for (YAML::const_iterator _domain = config["domains"].begin(); _domain != config["domains"].end(); _domain++) {
     GeoIPDomain dom;
-    auto id = tmp_domains.size();
-    if (loadDomain(*_domain, id, dom)) {
+    if (loadDomain(*_domain, tmp_domains.size(), dom)) {
       tmp_domains.push_back(std::move(dom));
     }
   }
index 851927628d1f34f4f9c62984f07741a2b53e1782..a2d3c7b994ad6de64ff2d084d07e5fd230bd2b53 100644 (file)
@@ -22,6 +22,7 @@
 #pragma once
 #include "pdns/namespaces.hh"
 
+#include <cstdint>
 #include <vector>
 #include <map>
 #include <string>
@@ -82,7 +83,7 @@ private:
   bool d_dnssec{};
   bool hasDNSSECkey(const DNSName& name);
   bool lookup_static(const GeoIPDomain& dom, const DNSName& search, const QType& qtype, const DNSName& qdomain, const Netmask& addr, GeoIPNetmask& gl);
-  bool loadDomain(const YAML::Node& domain, unsigned int /* id */, GeoIPDomain& dom);
+  bool loadDomain(const YAML::Node& domain, std::uint32_t domainID, GeoIPDomain& dom);
   void loadDomainsFromDirectory(const std::string& dir, vector<GeoIPDomain>& domains);
   vector<DNSResourceRecord> d_result;
   vector<GeoIPInterface> d_files;