Skip to content

Commit

Permalink
Merge pull request #901 from pi-hole/fix/query_retries
Browse files Browse the repository at this point in the history
Add new query retried status
  • Loading branch information
DL6ER authored Oct 22, 2020
2 parents 36e7ff2 + 80c04ea commit baf7b2a
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 6 deletions.
3 changes: 2 additions & 1 deletion src/dnsmasq/forward.c
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,7 @@ static int forward_query(int udpfd, union mysockaddr *udpaddr,
else
log_query(F_NOEXTRA | F_DNSSEC | F_IPV6, "retry", (union all_addr *)&forward->sentto->addr.in6.sin6_addr, "dnssec");

FTL_forwarding_retried(forward->sentto, forward->log_id, daemon->log_id, true);

if (forward->sentto->sfd)
fd = forward->sentto->sfd->fd;
Expand Down Expand Up @@ -347,7 +348,7 @@ static int forward_query(int udpfd, union mysockaddr *udpaddr,
start = daemon->servers; /* at end of list, recycle */
header->id = htons(forward->new_id);

FTL_forwarding_failed(forward->sentto);
FTL_forwarding_retried(forward->sentto, forward->log_id, daemon->log_id, false);
}
else
{
Expand Down
38 changes: 36 additions & 2 deletions src/dnsmasq_interface.c
Original file line number Diff line number Diff line change
Expand Up @@ -1776,7 +1776,7 @@ void getCacheInformation(const int *sock)
// looked up for the longest time is evicted.
}

void _FTL_forwarding_failed(const struct server *server, const char* file, const int line)
void FTL_forwarding_retried(const struct server *server, const int oldID, const int newID, const bool dnssec)
{
// Forwarding to upstream server failed

Expand All @@ -1798,7 +1798,11 @@ void _FTL_forwarding_failed(const struct server *server, const char* file, const
const int upstreamID = findUpstreamID(upstreamIP, false);

// Possible debugging information
if(config.debug & DEBUG_QUERIES) logg("**** forwarding to %s (ID %i, %s:%i) FAILED", dest, upstreamID, file, line);
if(config.debug & DEBUG_QUERIES)
{
logg("**** RETRIED query %i as %i to %s (ID %i)",
oldID, newID, dest, upstreamID);
}

// Get upstream pointer
upstreamsData* upstream = getUpstream(upstreamID, true);
Expand All @@ -1807,6 +1811,36 @@ void _FTL_forwarding_failed(const struct server *server, const char* file, const
if(upstream != NULL)
upstream->failed++;

// Search for corresponding query identified by ID
// Retried DNSSEC queries are ignored, we have to flag themselves (newID)
// Retried normal queries take over, we have to flat the original query (oldID)
const int queryID = findQueryID(dnssec ? newID : oldID);
if(queryID >= 0)
{
// Get query pointer
queriesData* query = getQuery(queryID, true);

// Set retried status
if(query != NULL)
{
if(dnssec)
{
// There is point in retrying the query when
// we've already got an answer to this query,
// but we're awaiting keys for DNSSEC
// validation. We're retrying the DNSSEC query
// instead
query->status = QUERY_RETRIED_DNSSEC;
}
else
{
// Normal query retry due to answer not arriving
// soon enough at the requestor
query->status = QUERY_RETRIED;
}
}
}

// Clean up and unlock shared memory
free(upstreamIP);
unlock_shm();
Expand Down
3 changes: 1 addition & 2 deletions src/dnsmasq_interface.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,7 @@ void _FTL_dnssec(const int status, const int id, const char* file, const int lin
#define FTL_header_analysis(header4, rcode, id) _FTL_header_analysis(header4, rcode, id, __FILE__, __LINE__)
void _FTL_header_analysis(const unsigned char header4, const unsigned int rcode, const int id, const char* file, const int line);

#define FTL_forwarding_failed(server) _FTL_forwarding_failed(server, __FILE__, __LINE__)
void _FTL_forwarding_failed(const struct server *server, const char* file, const int line);
void FTL_forwarding_retried(const struct server *server, const int oldID, const int newID, const bool dnssec);

#define FTL_upstream_error(rcode, id) _FTL_upstream_error(rcode, id, __FILE__, __LINE__)
void _FTL_upstream_error(const unsigned int rcode, const int id, const char* file, const int line);
Expand Down
2 changes: 2 additions & 0 deletions src/enums.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ enum query_status {
QUERY_GRAVITY_CNAME,
QUERY_REGEX_CNAME,
QUERY_BLACKLIST_CNAME,
QUERY_RETRIED,
QUERY_RETRIED_DNSSEC,
QUERY_STATUS_MAX
} __attribute__ ((packed));

Expand Down
4 changes: 3 additions & 1 deletion src/gc.c
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,9 @@ void *GC_thread(void *val)
// Unknown (?)
counters->unknown--;
break;
case QUERY_FORWARDED:
case QUERY_FORWARDED: // (fall through)
case QUERY_RETRIED: // (fall through)
case QUERY_RETRIED_DNSSEC:
// Forwarded to an upstream DNS server
// Adjust counters
counters->forwarded--;
Expand Down

0 comments on commit baf7b2a

Please sign in to comment.