From 7acad2d53accca9f0d9de46b59d2d1a7b2295fba Mon Sep 17 00:00:00 2001 From: Remi Gacogne Date: Fri, 28 Jul 2017 15:36:29 +0200 Subject: [PATCH] dnsdist: Only call `toDNSString()` once when retrieving from the cache --- pdns/dnsdist-cache.cc | 8 ++++---- pdns/dnsdist-cache.hh | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/pdns/dnsdist-cache.cc b/pdns/dnsdist-cache.cc index da8d15052..7ecb8c2dd 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 923f6e006..7283f96ac 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); -- 2.40.0