Skip to content

Commit

Permalink
rec: a few RPZ tweaks
Browse files Browse the repository at this point in the history
- Log policyname on policyHit when updating root
- Do not register invalid file-based RPZs
- Do not return null SOA
  • Loading branch information
omoerbeek committed Sep 20, 2024
1 parent 72ae147 commit 439913b
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 6 deletions.
2 changes: 1 addition & 1 deletion pdns/recursordist/filterpo.hh
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ public:

[[nodiscard]] bool getSOA(DNSRecord& rec) const
{
if (d_zoneData) {
if (d_zoneData && d_zoneData->d_soa.getContent()) {
rec = d_zoneData->d_soa;
return true;
}
Expand Down
10 changes: 7 additions & 3 deletions pdns/recursordist/rec-main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3426,7 +3426,7 @@ static void* pleaseInitPolCounts(const string& name)
return nullptr;
}

static void activateRPZFile(const RPZTrackerParams& params, LuaConfigItems& lci, shared_ptr<DNSFilterEngine::Zone>& zone)
static bool activateRPZFile(const RPZTrackerParams& params, LuaConfigItems& lci, shared_ptr<DNSFilterEngine::Zone>& zone)
{
auto log = lci.d_slog->withValues("file", Logging::Loggable(params.name));

Expand All @@ -3441,7 +3441,10 @@ static void activateRPZFile(const RPZTrackerParams& params, LuaConfigItems& lci,
catch (const std::exception& e) {
SLOG(g_log << Logger::Error << "Unable to load RPZ zone from '" << params.name << "': " << e.what() << endl,
log->error(Logr::Error, e.what(), "Exception while loading RPZ zone from file"));
zone->clear();
return false;
}
return true;
}

static void activateRPZPrimary(RPZTrackerParams& params, LuaConfigItems& lci, shared_ptr<DNSFilterEngine::Zone>& zone, const DNSName& domain)
Expand Down Expand Up @@ -3500,8 +3503,9 @@ static void activateRPZs(LuaConfigItems& lci)
zone->setIgnoreDuplicates(params.ignoreDuplicates);

if (params.primaries.empty()) {
activateRPZFile(params, lci, zone);
lci.dfe.addZone(zone);
if (activateRPZFile(params, lci, zone)) {
lci.dfe.addZone(zone);
}
}
else {
DNSName domain(params.name);
Expand Down
5 changes: 3 additions & 2 deletions pdns/recursordist/syncres.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6223,9 +6223,10 @@ int SyncRes::getRootNS(struct timeval now, asyncresolve_t asyncCallback, unsigne
SLOG(g_log << Logger::Error << "Failed to update . records, got an exception: " << e.reason << endl,
log->error(Logr::Error, e.reason, msg, "exception", Logging::Loggable("ImmediateServFailException")));
}
catch (const PolicyHitException& e) {
catch (const PolicyHitException& policyHit) {
SLOG(g_log << Logger::Error << "Failed to update . records, got a policy hit" << endl,
log->info(Logr::Error, msg, "exception", Logging::Loggable("PolicyHitException")));
log->info(Logr::Error, msg, "exception", Logging::Loggable("PolicyHitException"),
"policyName", Logging::Loggable(resolver.d_appliedPolicy.getName())));
ret.clear();
}
catch (const std::exception& e) {
Expand Down

0 comments on commit 439913b

Please sign in to comment.