]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
dnsdist: Only call `toDNSString()` once when retrieving from the cache
authorRemi Gacogne <remi.gacogne@powerdns.com>
Fri, 28 Jul 2017 13:36:29 +0000 (15:36 +0200)
committerRemi Gacogne <remi.gacogne@powerdns.com>
Tue, 5 Sep 2017 14:52:23 +0000 (16:52 +0200)
pdns/dnsdist-cache.cc
pdns/dnsdist-cache.hh

index da8d15052fc6072d7fb12eddf18105a4314e318d..7ecb8c2ddc858302ff9dcbeff893fdce3086c66b 100644 (file)
@@ -158,7 +158,8 @@ void DNSDistPacketCache::insert(uint32_t key, const DNSName& qname, uint16_t qty
 
 bool DNSDistPacketCache::get(const DNSQuestion& dq, uint16_t consumed, uint16_t queryId, char* response, uint16_t* responseLen, uint32_t* keyOut, uint32_t allowExpired, bool skipAging)
 {
-  uint32_t key = getKey(*dq.qname, consumed, (const unsigned char*)dq.dh, dq.len, dq.tcp);
+  std::string dnsQName(dq.qname->toDNSString());
+  uint32_t key = getKey(dnsQName, consumed, (const unsigned char*)dq.dh, dq.len, dq.tcp);
   if (keyOut)
     *keyOut = key;
 
@@ -212,7 +213,6 @@ bool DNSDistPacketCache::get(const DNSQuestion& dq, uint16_t consumed, uint16_t
       return true;
     }
 
-    string dnsQName(dq.qname->toDNSString());
     const size_t dnsQNameLen = dnsQName.length();
     if (value.len < (sizeof(dnsheader) + dnsQNameLen)) {
       return false;
@@ -350,14 +350,14 @@ uint32_t DNSDistPacketCache::getMinTTL(const char* packet, uint16_t length)
   return getDNSPacketMinTTL(packet, length);
 }
 
-uint32_t DNSDistPacketCache::getKey(const DNSName& qname, uint16_t consumed, const unsigned char* packet, uint16_t packetLen, bool tcp)
+uint32_t DNSDistPacketCache::getKey(const std::string& qname, uint16_t consumed, const unsigned char* packet, uint16_t packetLen, bool tcp)
 {
   uint32_t result = 0;
   /* skip the query ID */
   if (packetLen < sizeof(dnsheader))
     throw std::range_error("Computing packet cache key for an invalid packet size");
   result = burtle(packet + 2, sizeof(dnsheader) - 2, result);
-  string lc(qname.toDNSStringLC());
+  string lc(toLower(qname));
   result = burtle((const unsigned char*) lc.c_str(), lc.length(), result);
   if (packetLen < sizeof(dnsheader) + consumed) {
     throw std::range_error("Computing packet cache key for an invalid packet");
index 923f6e006f2514e7332bc20e61655118ae15eebc..7283f96ace150c4c50f85d4bdedc5b72707fa97f 100644 (file)
@@ -90,7 +90,7 @@ private:
     std::atomic<uint64_t> d_entriesCount;
   };
 
-  static uint32_t getKey(const DNSName& qname, uint16_t consumed, const unsigned char* packet, uint16_t packetLen, bool tcp);
+  static uint32_t getKey(const std::string& qname, uint16_t consumed, const unsigned char* packet, uint16_t packetLen, bool tcp);
   static bool cachedValueMatches(const CacheValue& cachedValue, const DNSName& qname, uint16_t qtype, uint16_t qclass, bool tcp);
   uint32_t getShardIndex(uint32_t key) const;
   void insertLocked(CacheShard& shard, uint32_t key, const DNSName& qname, uint16_t qtype, uint16_t qclass, bool tcp, CacheValue& newValue, time_t now, time_t newValidity);