mirror of
https://github.com/pi-hole/FTL.git
synced 2025-12-20 06:58:25 +00:00
Store intermediate CNAME domain pointers in DNS cache for later retrieval from cache without another CNAME inspection
Signed-off-by: DL6ER <dl6er@dl6er.de>
This commit is contained in:
@@ -117,6 +117,7 @@ typedef struct {
|
|||||||
enum query_type query_type;
|
enum query_type query_type;
|
||||||
unsigned int domainID;
|
unsigned int domainID;
|
||||||
unsigned int clientID;
|
unsigned int clientID;
|
||||||
|
unsigned int CNAME_domainID; // only valid if query has a CNAME blocking status
|
||||||
int list_id;
|
int list_id;
|
||||||
uint32_t hash;
|
uint32_t hash;
|
||||||
time_t expires;
|
time_t expires;
|
||||||
|
|||||||
@@ -1537,7 +1537,9 @@ static bool FTL_check_blocking(const unsigned int queryID, const unsigned int do
|
|||||||
if(!query->flags.allowed)
|
if(!query->flags.allowed)
|
||||||
{
|
{
|
||||||
force_next_DNS_reply = dns_cache->force_reply;
|
force_next_DNS_reply = dns_cache->force_reply;
|
||||||
query_blocked(query, domain, client, QUERY_DENYLIST);
|
query_blocked(query, domain, client, blocking_status);
|
||||||
|
if(blocking_status == QUERY_DENYLIST_CNAME)
|
||||||
|
query->CNAME_domainID = dns_cache->CNAME_domainID;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@@ -1554,7 +1556,9 @@ static bool FTL_check_blocking(const unsigned int queryID, const unsigned int do
|
|||||||
if(!query->flags.allowed)
|
if(!query->flags.allowed)
|
||||||
{
|
{
|
||||||
force_next_DNS_reply = dns_cache->force_reply;
|
force_next_DNS_reply = dns_cache->force_reply;
|
||||||
query_blocked(query, domain, client, QUERY_GRAVITY);
|
query_blocked(query, domain, client, blocking_status);
|
||||||
|
if(blocking_status == QUERY_GRAVITY_CNAME)
|
||||||
|
query->CNAME_domainID = dns_cache->CNAME_domainID;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@@ -1573,7 +1577,9 @@ static bool FTL_check_blocking(const unsigned int queryID, const unsigned int do
|
|||||||
{
|
{
|
||||||
force_next_DNS_reply = dns_cache->force_reply;
|
force_next_DNS_reply = dns_cache->force_reply;
|
||||||
last_regex_idx = dns_cache->list_id;
|
last_regex_idx = dns_cache->list_id;
|
||||||
query_blocked(query, domain, client, QUERY_REGEX);
|
query_blocked(query, domain, client, blocking_status);
|
||||||
|
if(blocking_status == QUERY_REGEX_CNAME)
|
||||||
|
query->CNAME_domainID = dns_cache->CNAME_domainID;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@@ -1863,6 +1869,12 @@ bool FTL_CNAME(const char *dst, const char *src, const int id)
|
|||||||
// Store domain that was the reason for blocking the entire chain
|
// Store domain that was the reason for blocking the entire chain
|
||||||
query->CNAME_domainID = child_domainID;
|
query->CNAME_domainID = child_domainID;
|
||||||
|
|
||||||
|
// Store CNAME domain ID in DNS cache
|
||||||
|
const int parent_cacheID = query->cacheID > -1 ? query->cacheID : findCacheID(parent_domainID, clientID, query->type, false);
|
||||||
|
DNSCacheData *parent_cache = parent_cacheID < 0 ? NULL : getDNSCache(parent_cacheID, true);
|
||||||
|
if(parent_cache != NULL)
|
||||||
|
parent_cache->CNAME_domainID = child_domainID;
|
||||||
|
|
||||||
// Change blocking reason into CNAME-caused blocking
|
// Change blocking reason into CNAME-caused blocking
|
||||||
if(query->status == QUERY_GRAVITY)
|
if(query->status == QUERY_GRAVITY)
|
||||||
{
|
{
|
||||||
@@ -1870,12 +1882,10 @@ bool FTL_CNAME(const char *dst, const char *src, const int id)
|
|||||||
}
|
}
|
||||||
else if(query->status == QUERY_REGEX)
|
else if(query->status == QUERY_REGEX)
|
||||||
{
|
{
|
||||||
// Get parent and child DNS cache entries
|
// Get child DNS cache entries
|
||||||
const int parent_cacheID = query->cacheID > -1 ? query->cacheID : findCacheID(parent_domainID, clientID, query->type, false);
|
|
||||||
const int child_cacheID = findCacheID(child_domainID, clientID, query->type, false);
|
const int child_cacheID = findCacheID(child_domainID, clientID, query->type, false);
|
||||||
|
|
||||||
// Get cache pointers
|
// Get child's cache pointer
|
||||||
DNSCacheData *parent_cache = parent_cacheID < 0 ? NULL : getDNSCache(parent_cacheID, true);
|
|
||||||
const DNSCacheData *child_cache = child_cacheID < 0 ? NULL : getDNSCache(child_cacheID, true);
|
const DNSCacheData *child_cache = child_cacheID < 0 ? NULL : getDNSCache(child_cacheID, true);
|
||||||
|
|
||||||
// Propagate ID of responsible regex up from the child to the parent
|
// Propagate ID of responsible regex up from the child to the parent
|
||||||
|
|||||||
16
src/gc.c
16
src/gc.c
@@ -102,6 +102,22 @@ static void recycle(void)
|
|||||||
cache_used[query->cacheID] = true;
|
cache_used[query->cacheID] = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Scan cache records for CNAME domain pointers that prevent domains
|
||||||
|
// from being recyclable
|
||||||
|
for(unsigned int cacheID = 0; cacheID < counters->dns_cache_size; cacheID++)
|
||||||
|
{
|
||||||
|
const DNSCacheData *cache = getDNSCache(cacheID, true);
|
||||||
|
if(cache == NULL)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
// Mark domains as used when this is a CNAME-related cache
|
||||||
|
// record
|
||||||
|
if(cache->blocking_status == QUERY_GRAVITY_CNAME ||
|
||||||
|
cache->blocking_status == QUERY_REGEX_CNAME ||
|
||||||
|
cache->blocking_status == QUERY_DENYLIST_CNAME)
|
||||||
|
domain_used[cache->CNAME_domainID] = true;
|
||||||
|
}
|
||||||
|
|
||||||
// Recycle clients
|
// Recycle clients
|
||||||
unsigned int clients_recycled = 0;
|
unsigned int clients_recycled = 0;
|
||||||
for(unsigned int clientID = 0; clientID < counters->clients; clientID++)
|
for(unsigned int clientID = 0; clientID < counters->clients; clientID++)
|
||||||
|
|||||||
Reference in New Issue
Block a user