Skip to content

Commit

Permalink
Unify query and cache status enums
Browse files Browse the repository at this point in the history
Signed-off-by: DL6ER <[email protected]>
  • Loading branch information
DL6ER committed Aug 21, 2024
1 parent 6760ca6 commit 376b584
Show file tree
Hide file tree
Showing 5 changed files with 182 additions and 183 deletions.
60 changes: 58 additions & 2 deletions src/datastructure.c
Original file line number Diff line number Diff line change
Expand Up @@ -435,7 +435,8 @@ int _findCacheID(const int domainID, const int clientID, const enum query_type q

// Initialize cache entry
dns_cache->magic = MAGICBYTE;
dns_cache->blocking_status = UNKNOWN_BLOCKED;
dns_cache->blocking_status = QUERY_UNKNOWN;
dns_cache->expires = 0;
dns_cache->domainID = domainID;
dns_cache->clientID = clientID;
dns_cache->query_type = query_type;
Expand Down Expand Up @@ -570,7 +571,9 @@ void FTL_reset_per_client_domain_data(void)
continue;

// Reset blocking status
dns_cache->blocking_status = UNKNOWN_BLOCKED;
dns_cache->blocking_status = QUERY_UNKNOWN;
// Reset expiry
dns_cache->expires = 0;
// Reset domainlist ID
dns_cache->list_id = -1;
}
Expand Down Expand Up @@ -1069,6 +1072,59 @@ void _query_set_status(queriesData *query, const enum query_status new_status, c
return;
}

// Memorize this in the DNS cache if blocked due to the response
// We do not cahe intermittent statuses as they are subject to change

Check failure on line 1076 in src/datastructure.c

View workflow job for this annotation

GitHub Actions / spell-check

cahe ==> cache, ache
if(!init &&
new_status != QUERY_UNKNOWN &&
new_status != QUERY_DBBUSY &&
new_status != QUERY_IN_PROGRESS &&
new_status != QUERY_RETRIED &&
new_status != QUERY_RETRIED_DNSSEC)
{
const int cacheID = findCacheID(query->domainID, query->clientID, query->type, true);
DNSCacheData *dns_cache = getDNSCache(cacheID, true);
if(dns_cache != NULL && dns_cache->blocking_status != new_status)
{
// Memorize blocking status DNS cache for the domain/client combination
dns_cache->blocking_status = new_status;

// Set expiration time for this cache entry (if applicable)
// We set this only if not already set to avoid extending the TTL of an
// existing entry
if(config.dns.cache.upstreamTTL.v.ui > 0 &&
dns_cache->expires == 0 &&
(new_status == QUERY_EXTERNAL_BLOCKED_NXRA ||
new_status == QUERY_EXTERNAL_BLOCKED_NULL ||
new_status == QUERY_EXTERNAL_BLOCKED_IP ||
new_status == QUERY_EXTERNAL_BLOCKED_EDE15))
{
// Set expiration time for this cache entry
dns_cache->expires = time(NULL) + config.dns.cache.upstreamTTL.v.ui;
}

if(config.debug.queries.v.b)
{
// Debug logging
const char *qtype = get_query_type_str(dns_cache->query_type, NULL, NULL);
const char *domain = getDomainString(query);
const char *clientstr = getClientIPString(query);
const char *statusstr = get_query_status_str(new_status);

if(dns_cache->expires > 0)
{
log_debug(DEBUG_QUERIES, "DNS cache: %s/%s/%s -> %s, expires in %lis",
qtype, clientstr, domain, statusstr,
(long)(dns_cache->expires - time(NULL)));
}
else
{
log_debug(DEBUG_QUERIES, "DNS cache: %s/%s/%s -> %s, no expiry",
qtype, clientstr, domain, statusstr);
}
}
}
}

// else: update global counters, ...
if(!init)
{
Expand Down
5 changes: 4 additions & 1 deletion src/datastructure.h
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,10 @@ typedef struct {

typedef struct {
unsigned char magic;
enum domain_client_status blocking_status;
struct {
bool allowed :1;
} flags;
enum query_status blocking_status;
enum reply_type force_reply;
enum query_type query_type;
int domainID;
Expand Down
Loading

0 comments on commit 376b584

Please sign in to comment.