summaryrefslogtreecommitdiffstats
path: root/dnsdist-cache.cc
diff options
context:
space:
mode:
Diffstat (limited to 'dnsdist-cache.cc')
-rw-r--r--dnsdist-cache.cc20
1 files changed, 13 insertions, 7 deletions
diff --git a/dnsdist-cache.cc b/dnsdist-cache.cc
index 7ca9be2..86c900b 100644
--- a/dnsdist-cache.cc
+++ b/dnsdist-cache.cc
@@ -119,9 +119,10 @@ void DNSDistPacketCache::insertLocked(CacheShard& shard, std::unordered_map<uint
void DNSDistPacketCache::insert(uint32_t key, const boost::optional<Netmask>& subnet, uint16_t queryFlags, bool dnssecOK, const DNSName& qname, uint16_t qtype, uint16_t qclass, const PacketBuffer& response, bool receivedOverUDP, uint8_t rcode, boost::optional<uint32_t> tempFailureTTL)
{
- if (response.size() < sizeof(dnsheader)) {
+ if (response.size() < sizeof(dnsheader) || response.size() > getMaximumEntrySize()) {
return;
}
+
if (qtype == QType::AXFR || qtype == QType::IXFR) {
return;
}
@@ -252,7 +253,7 @@ bool DNSDistPacketCache::get(DNSQuestion& dq, uint16_t queryId, uint32_t* keyOut
}
/* check for collision */
- if (!cachedValueMatches(value, *(getFlagsFromDNSHeader(dq.getHeader())), dq.ids.qname, dq.ids.qtype, dq.ids.qclass, receivedOverUDP, dnssecOK, subnet)) {
+ if (!cachedValueMatches(value, *(getFlagsFromDNSHeader(dq.getHeader().get())), dq.ids.qname, dq.ids.qtype, dq.ids.qclass, receivedOverUDP, dnssecOK, subnet)) {
++d_lookupCollisions;
return false;
}
@@ -472,12 +473,12 @@ uint64_t DNSDistPacketCache::getEntriesCount()
uint64_t DNSDistPacketCache::dump(int fd)
{
- auto fp = std::unique_ptr<FILE, int(*)(FILE*)>(fdopen(dup(fd), "w"), fclose);
- if (fp == nullptr) {
+ auto filePtr = pdns::UniqueFilePtr(fdopen(dup(fd), "w"));
+ if (filePtr == nullptr) {
return 0;
}
- fprintf(fp.get(), "; dnsdist's packet cache dump follows\n;\n");
+ fprintf(filePtr.get(), "; dnsdist's packet cache dump follows\n;\n");
uint64_t count = 0;
time_t now = time(nullptr);
@@ -496,10 +497,10 @@ uint64_t DNSDistPacketCache::dump(int fd)
rcode = dh.rcode;
}
- fprintf(fp.get(), "%s %" PRId64 " %s ; rcode %" PRIu8 ", key %" PRIu32 ", length %" PRIu16 ", received over UDP %d, added %" PRId64 "\n", value.qname.toString().c_str(), static_cast<int64_t>(value.validity - now), QType(value.qtype).toString().c_str(), rcode, entry.first, value.len, value.receivedOverUDP, static_cast<int64_t>(value.added));
+ fprintf(filePtr.get(), "%s %" PRId64 " %s ; rcode %" PRIu8 ", key %" PRIu32 ", length %" PRIu16 ", received over UDP %d, added %" PRId64 "\n", value.qname.toString().c_str(), static_cast<int64_t>(value.validity - now), QType(value.qtype).toString().c_str(), rcode, entry.first, value.len, static_cast<int>(value.receivedOverUDP), static_cast<int64_t>(value.added));
}
catch(...) {
- fprintf(fp.get(), "; error printing '%s'\n", value.qname.empty() ? "EMPTY" : value.qname.toString().c_str());
+ fprintf(filePtr.get(), "; error printing '%s'\n", value.qname.empty() ? "EMPTY" : value.qname.toString().c_str());
}
}
}
@@ -620,3 +621,8 @@ std::set<ComboAddress> DNSDistPacketCache::getRecordsForDomain(const DNSName& do
return addresses;
}
+
+void DNSDistPacketCache::setMaximumEntrySize(size_t maxSize)
+{
+ d_maximumEntrySize = maxSize;
+}