Skip to content

Add answer CIDR cache exclusions#2901

Open
rz467fzs7d wants to merge 1 commit into
pi-hole:masterfrom
rz467fzs7d:codex/cache-exclude-answer-cidrs
Open

Add answer CIDR cache exclusions#2901
rz467fzs7d wants to merge 1 commit into
pi-hole:masterfrom
rz467fzs7d:codex/cache-exclude-answer-cidrs

Conversation

@rz467fzs7d
Copy link
Copy Markdown

Summary

  • add dns.cache.excludeAnswerCIDRs, a restart-scoped JSON string array of CIDR ranges
  • skip committing an upstream DNS response to FTL's cache when any A/AAAA answer matches one of the configured ranges
  • add CIDR parsing/matching coverage for IPv4, IPv6, and invalid input

Motivation

This helps deployments where Pi-hole forwards to a fake-IP resolver. The client still receives the upstream answer, but FTL avoids caching fake-IP answers that may outlive the upstream resolver's own mapping state.

The default is 198.18.0.0/15, the RFC 2544 benchmarking range commonly used by fake-IP DNS implementations.

Test

  • cc -Wall -Wextra -I src -o /tmp/cache_exclude_cidr_test test/cache_exclude_cidr_test.c src/dnsmasq/cache_exclude.c src/webserver/cJSON/cJSON.c && /tmp/cache_exclude_cidr_test
  • git diff --check

@rz467fzs7d rz467fzs7d requested a review from a team as a code owner May 28, 2026 05:57
@rz467fzs7d rz467fzs7d force-pushed the codex/cache-exclude-answer-cidrs branch from 414b720 to 632f4a9 Compare May 28, 2026 06:48
Copy link
Copy Markdown
Contributor

@darkexplosiveqwx darkexplosiveqwx left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use the PR template from https://github.com/pi-hole/.github/blob/master/.github/PULL_REQUEST_TEMPLATE.md.
The PR template also mentions the following issues: DCO and targeting development branch.

This PR mainly touches dnsmasq code. We want to make as litte changes a possible to dnsmasq to avoid future merge conflicts. If it is possible, it should be submitted upstream at Dnsmasq-dicuss.

Some more issues are that test/cache_exclude_cidr_test.c is never used and that the config option is not added to test/pihole.toml and src/api/docs/content/specs/config.yaml

@rdwebdesign rdwebdesign requested a review from DL6ER May 29, 2026 19:59
@DL6ER
Copy link
Copy Markdown
Member

DL6ER commented May 30, 2026

I read your motivation but this is still somewhat obscure to me: we cache per domains per client per record so why is this bad? Note that this will introduce extra work as FTL will not be able to short-circuit queries for said combination (domain, client, type) but has to do all lengthy regex comparisons, etc. over and over again, always coming back to (very likely to guaranteed) the same outcome. Something is missing for me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants