#include "ednssubnet.hh"
#include "query-local-address.hh"
#include "tcpiohandler.hh"
+#include "ednsoptions.hh"
#include "rec-protozero.hh"
#include "uuid-utils.hh"
#endif
}
- if (!SyncRes::s_nopacketcache && !variableAnswer && !sr.wasVariable()) {
+ if (t_packetCache && !variableAnswer && !sr.wasVariable()) {
const auto& hdr = pw.getHeader();
if ((hdr->rcode != RCode::NoError && hdr->rcode != RCode::NXDomain) || (hdr->ancount == 0 && hdr->nscount == 0)) {
minTTL = min(minTTL, SyncRes::s_packetcacheservfailttl);
string& response, uint32_t& qhash,
RecursorPacketCache::OptPBData& pbData, bool tcp, const ComboAddress& source)
{
+ if (!t_packetCache) {
+ return false;
+ }
bool cacheHit = false;
uint32_t age;
vState valState;
if (qnameParsed) {
- cacheHit = !SyncRes::s_nopacketcache && t_packetCache->getResponsePacket(tag, data, qname, qtype, qclass, now.tv_sec, &response, &age, &valState, &qhash, &pbData, tcp);
+ cacheHit = t_packetCache->getResponsePacket(tag, data, qname, qtype, qclass, now.tv_sec, &response, &age, &valState, &qhash, &pbData, tcp);
}
else {
- cacheHit = !SyncRes::s_nopacketcache && t_packetCache->getResponsePacket(tag, data, qname, &qtype, &qclass, now.tv_sec, &response, &age, &valState, &qhash, &pbData, tcp);
+ cacheHit = t_packetCache->getResponsePacket(tag, data, qname, &qtype, &qclass, now.tv_sec, &response, &age, &valState, &qhash, &pbData, tcp);
}
if (cacheHit) {
static uint64_t* pleaseDump(int fd)
{
- return new uint64_t(t_packetCache->doDump(fd));
+ return new uint64_t(t_packetCache ? t_packetCache->doDump(fd) : 0);
}
static uint64_t* pleaseDumpEDNSMap(int fd)
{
if (end - begin != 1)
return "Need to supply new packet cache size\n";
+ if (::arg().mustDo("disable-packetcache")) {
+ return "Packet cache is disabled\n";
+ }
try {
g_maxPacketCacheEntries = pdns::checked_stoi<uint32_t>(*begin);
return "New max packetcache entries: " + std::to_string(g_maxPacketCacheEntries) + "\n";
SyncRes::s_minimumTTL = ::arg().asNum("minimum-ttl-override");
SyncRes::s_minimumECSTTL = ::arg().asNum("ecs-minimum-ttl-override");
-
- SyncRes::s_nopacketcache = ::arg().mustDo("disable-packetcache");
-
SyncRes::s_maxnegttl = ::arg().asNum("max-negative-ttl");
SyncRes::s_maxbogusttl = ::arg().asNum("max-cache-bogus-ttl");
SyncRes::s_maxcachettl = max(::arg().asNum("max-cache-ttl"), 15);
struct timeval now;
Utility::gettimeofday(&now);
- // Below are the tasks that run for every recursorThread, including handler and taskThread
- static thread_local PeriodicTask packetCacheTask{"packetCacheTask", 5};
- packetCacheTask.runIfDue(now, []() {
- t_packetCache->doPruneTo(g_maxPacketCacheEntries / (RecThreadInfo::numDistributors() + RecThreadInfo::numWorkers()));
- });
+ if (t_packetCache) {
+ // Below are the tasks that run for every recursorThread, including handler and taskThread
+ static thread_local PeriodicTask packetCacheTask{"packetCacheTask", 5};
+ packetCacheTask.runIfDue(now, []() {
+ t_packetCache->doPruneTo(g_maxPacketCacheEntries / (RecThreadInfo::numDistributors() + RecThreadInfo::numWorkers()));
+ });
+ }
// This is a full scan
static thread_local PeriodicTask pruneNSpeedTask{"pruneNSSpeedTask", 100};
}
}
- t_packetCache = std::make_unique<RecursorPacketCache>();
+ if (!::arg().mustDo("disable-packetcache") && (threadInfo.isDistributor() || threadInfo.isWorker())) {
+ t_packetCache = std::make_unique<RecursorPacketCache>();
+ }
#ifdef NOD_ENABLED
if (threadInfo.isWorker())
static uint64_t* pleaseWipePacketCache(const DNSName& canon, bool subtree, uint16_t qtype)
{
- return new uint64_t(t_packetCache->doWipePacketCache(canon, qtype, subtree));
+ return new uint64_t(t_packetCache ? 0 : t_packetCache->doWipePacketCache(canon, qtype, subtree));
}
struct WipeCacheResult wipeCaches(const DNSName& canon, bool subtree, uint16_t qtype)
#include "rec-snmp.hh"
#include "rec_channel.hh"
#include "threadname.hh"
+#include "recpacketcache.hh"
#ifdef NOD_ENABLED
#include "nod.hh"
typedef MTasker<std::shared_ptr<PacketID>, PacketBuffer, PacketIDCompare> MT_t;
extern thread_local std::unique_ptr<MT_t> MT; // the big MTasker
+extern thread_local std::unique_ptr<RecursorPacketCache> t_packetCache;
extern bool g_logCommonErrors;
extern size_t g_proxyProtocolMaximumSize;
bool SyncRes::s_doIPv4;
bool SyncRes::s_doIPv6;
-bool SyncRes::s_nopacketcache;
bool SyncRes::s_rootNXTrust;
bool SyncRes::s_noEDNS;
bool SyncRes::s_qnameminimization;
#include "circular_buffer.hh"
#include "sstuff.hh"
#include "recursor_cache.hh"
-#include "recpacketcache.hh"
#include <boost/optional.hpp>
#include "mtasker.hh"
#include "iputils.hh"
static bool s_noEDNSPing;
static bool s_noEDNS;
static bool s_rootNXTrust;
- static bool s_nopacketcache;
static bool s_qnameminimization;
static HardenNXD s_hardenNXD;
static unsigned int s_refresh_ttlperc;
}
};
extern std::unique_ptr<MemRecursorCache> g_recCache;
-extern thread_local std::unique_ptr<RecursorPacketCache> t_packetCache;
struct RecursorStats
{