Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rec: rpz tweaks and do not apply rpz-nsdname and rpz-nsip to forwarders #14694

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
10 changes: 7 additions & 3 deletions pdns/recursordist/syncres.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3407,6 +3407,9 @@ bool SyncRes::nameserversBlockedByRPZ(const DNSFilterEngine& dfe, const NsSet& n
*/
if (d_wantsRPZ && !d_appliedPolicy.wasHit()) {
for (auto const& nameserver : nameservers) {
if (nameserver.first.empty()) {
continue;
}
bool match = dfe.getProcessingPolicy(nameserver.first, d_discardedPolicies, d_appliedPolicy);
if (match) {
mergePolicyTags(d_policyTags, d_appliedPolicy.getTags());
Expand Down Expand Up @@ -5944,7 +5947,7 @@ int SyncRes::doResolveAt(NsSet& nameservers, DNSName auth, bool flawedNSSet, con
LOG(", ");
}
LOG(remoteIP->toString());
if (nameserverIPBlockedByRPZ(luaconfsLocal->dfe, *remoteIP)) {
if (!tns->first.empty() && nameserverIPBlockedByRPZ(luaconfsLocal->dfe, *remoteIP)) {
hitPolicy = true;
}
}
Expand Down Expand Up @@ -6223,9 +6226,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
Loading