]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
Minor code cleanups:
authorMiod Vallat <miod.vallat@powerdns.com>
Mon, 15 Dec 2025 09:48:27 +0000 (10:48 +0100)
committerMiod Vallat <miod.vallat@powerdns.com>
Mon, 15 Dec 2025 09:48:27 +0000 (10:48 +0100)
- remove unused bits from getUnfreshSecondaryInfo().
- use similar logic for the two code paths which need to fetch SOA numbers.

Signed-off-by: Miod Vallat <miod.vallat@powerdns.com>
modules/lmdbbackend/lmdbbackend.cc

index 68de6e8bb2174ee062b2388dbedee59829296c86..3c36327bb85eabad4e3fab55212e9d5a4f4d5dc6 100644 (file)
@@ -2121,12 +2121,12 @@ bool LMDBBackend::getSerial(DomainInfo& di)
   if (!txn->txn->get(txn->db->dbi, co(di.id, g_rootdnsname, QType::SOA), val)) {
     LMDBResourceRecord lrr;
     deserializeFromBuffer(val.get<string_view>(), lrr);
-    if (lrr.content.size() >= 5 * sizeof(uint32_t)) {
-      uint32_t serial;
-      // a SOA has five 32 bit fields, the first of which is the serial
-      // there are two variable length names before the serial, so we calculate from the back
-      memcpy(&serial, &lrr.content[lrr.content.size() - (5 * sizeof(uint32_t))], sizeof(serial));
-      di.serial = ntohl(serial);
+    if (lrr.content.size() >= sizeof(soatimes)) {
+      soatimes st;
+      // A SOA has five 32 bit fields, the first of which is the serial;
+      // there are two variable length names before the serial, so we calculate from the back.
+      memcpy(&st.serial, &lrr.content[lrr.content.size() - sizeof(soatimes)], sizeof(st.serial));
+      di.serial = ntohl(st.serial);
     }
     return !lrr.disabled;
   }
@@ -2288,12 +2288,9 @@ void LMDBBackend::getAllDomains(vector<DomainInfo>* domains, bool /* doSerial */
 
 void LMDBBackend::getUnfreshSecondaryInfos(vector<DomainInfo>* domains)
 {
-  uint32_t serial;
-  time_t now = time(0);
-  LMDBResourceRecord lrr;
-  soatimes st;
+  time_t now = time(nullptr);
 
-  getAllDomainsFiltered(domains, [this, &lrr, &st, &now, &serial](DomainInfo& di) {
+  getAllDomainsFiltered(domains, [this, now](DomainInfo& di) {
     if (!di.isSecondaryType()) {
       return false;
     }
@@ -2302,15 +2299,14 @@ void LMDBBackend::getUnfreshSecondaryInfos(vector<DomainInfo>* domains)
     compoundOrdername co;
     MDBOutVal val;
     if (!txn2->txn->get(txn2->db->dbi, co(di.id, g_rootdnsname, QType::SOA), val)) {
+      LMDBResourceRecord lrr;
       deserializeFromBuffer(val.get<string_view>(), lrr);
+      soatimes st;
+      // There are two variable length names before the SOA numbers, so we calculate from the back.
       memcpy(&st, &lrr.content[lrr.content.size() - sizeof(soatimes)], sizeof(soatimes));
       if ((time_t)(di.last_check + ntohl(st.refresh)) > now) { // still fresh
         return false;
       }
-      serial = ntohl(st.serial);
-    }
-    else {
-      serial = 0;
     }
 
     return true;