From: Remi Gacogne Date: Fri, 28 Jul 2017 13:36:29 +0000 (+0200) Subject: dnsdist: Only call `toDNSString()` once when retrieving from the cache X-Git-Tag: rec-4.1.0-rc1~22^2~4 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=7acad2d53accca9f0d9de46b59d2d1a7b2295fba;p=thirdparty%2Fpdns.git dnsdist: Only call `toDNSString()` once when retrieving from the cache --- diff --git a/pdns/dnsdist-cache.cc b/pdns/dnsdist-cache.cc index da8d15052f..7ecb8c2ddc 100644 --- a/pdns/dnsdist-cache.cc +++ b/pdns/dnsdist-cache.cc @@ -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"); diff --git a/pdns/dnsdist-cache.hh b/pdns/dnsdist-cache.hh index 923f6e006f..7283f96ace 100644 --- a/pdns/dnsdist-cache.hh +++ b/pdns/dnsdist-cache.hh @@ -90,7 +90,7 @@ private: std::atomic 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);