Skip to content

Commit

Permalink
Merge pull request PowerDNS#13504 from omoerbeek/rec-set-aggr-nsec-size
Browse files Browse the repository at this point in the history
rec: introduce command to set aggressive NSEC cache size
  • Loading branch information
omoerbeek authored Jan 24, 2024
2 parents f21123c + e2f1fd5 commit cd64db1
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 2 deletions.
8 changes: 7 additions & 1 deletion pdns/recursordist/aggressive_nsec.hh
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
*/
#pragma once

#include <atomic>
#include <boost/utility.hpp>
#include <boost/multi_index_container.hpp>
#include <boost/multi_index/ordered_index.hpp>
Expand Down Expand Up @@ -48,6 +49,11 @@ public:
{
}

void setMaxEntries(uint64_t number)
{
d_maxEntries = number;
}

static bool nsec3Disabled()
{
return s_maxNSEC3CommonPrefix == 0;
Expand Down Expand Up @@ -157,7 +163,7 @@ private:
pdns::stat_t d_nsecWildcardHits{0};
pdns::stat_t d_nsec3WildcardHits{0};
pdns::stat_t d_entriesCount{0};
uint64_t d_maxEntries{0};
std::atomic<uint64_t> d_maxEntries{0};
};

extern std::unique_ptr<AggressiveNSECCache> g_aggressiveNSECCache;
6 changes: 6 additions & 0 deletions pdns/recursordist/docs/manpages/rec_control.1.rst
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,12 @@ set-dnssec-log-bogus *SETTING*
set-ecs-minimum-ttl *NUM*
Set ecs-minimum-ttl-override to *NUM*.

set-max-aggr-nsec-cache-size *NUM*
Change the maximum number of entries in the NSEC aggressive cache. If the
cache is disabled by setting its size to 0 in the config, the cache size
cannot be set by this command. Setting the size to 0 by this command still
keeps the cache, but makes it mostly ineffective as it is emptied periodically.

set-max-cache-entries *NUM*
Change the maximum number of entries in the DNS cache. If reduced, the
cache size will start shrinking to this number as part of the normal
Expand Down
25 changes: 24 additions & 1 deletion pdns/recursordist/rec_channel_rec.cc
Original file line number Diff line number Diff line change
Expand Up @@ -888,6 +888,25 @@ static string setMaxPacketCacheEntries(T begin, T end)
}
}

template <typename T>
static RecursorControlChannel::Answer setAggrNSECCacheSize(T begin, T end)
{
if (end - begin != 1) {
return {1, "Need to supply new aggressive NSEC cache size\n"};
}
if (!g_aggressiveNSECCache) {
return {1, "Aggressive NSEC cache is disabled by startup config\n"};
}
try {
auto newmax = pdns::checked_stoi<uint64_t>(*begin);
g_aggressiveNSECCache->setMaxEntries(newmax);
return {0, "New aggressive NSEC cache size: " + std::to_string(newmax) + "\n"};
}
catch (const std::exception& e) {
return {1, "Error parsing the new aggressive NSEC cache size: " + std::string(e.what()) + "\n"};
}
}

static uint64_t getSysTimeMsec()
{
struct rusage ru;
Expand Down Expand Up @@ -2085,7 +2104,8 @@ static RecursorControlChannel::Answer help()
"reload-lua-config [filename] (re)load Lua configuration file\n"
"reload-zones reload all auth and forward zones\n"
"set-ecs-minimum-ttl value set ecs-minimum-ttl-override\n"
"set-max-cache-entries value set new maximum cache size\n"
"set-max-aggr-nsec-cache-size value set new maximum aggressive NSEC cache size\n"
"set-max-cache-entries value set new maximum record cache size\n"
"set-max-packetcache-entries val set new maximum packet cache size\n"
"set-minimum-ttl value set minimum-ttl-override\n"
"set-carbon-server set a carbon server for telemetry\n"
Expand Down Expand Up @@ -2365,6 +2385,9 @@ RecursorControlChannel::Answer RecursorControlParser::getAnswer(int socket, cons
if (cmd == "list-dnssec-algos") {
return {0, DNSCryptoKeyEngine::listSupportedAlgoNames()};
}
if (cmd == "set-aggr-nsec-cache-size") {
return setAggrNSECCacheSize(begin, end);
}

return {1, "Unknown command '" + cmd + "', try 'help'\n"};
}

0 comments on commit cd64db1

Please sign in to comment.