Skip to content

Commit

Permalink
Add global counters for types of replies (and properly GC them)
Browse files Browse the repository at this point in the history
Signed-off-by: DL6ER <dl6er@dl6er.de>
  • Loading branch information
DL6ER committed Dec 28, 2017
1 parent 7cbf68f commit 3346a84
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 0 deletions.
4 changes: 4 additions & 0 deletions FTL.h
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,10 @@ typedef struct {
int SRV;
int wildcarddomains;
int forwardedqueries;
int reply_NODATA;
int reply_NXDOMAIN;
int reply_CNAME;
int reply_IP;
} countersStruct;

typedef struct {
Expand Down
22 changes: 22 additions & 0 deletions gc.c
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,28 @@ void *GC_thread(void *val)
counters.forwardedqueries--;
validate_access("forwarded", queries[i].forwardID, true, __LINE__, __FUNCTION__, __FILE__);
forwarded[queries[i].forwardID].count--;
// Maybe we have to adjust total counters depending on the reply type
switch(queries[i].reply)
{
case 1: // NODATA(-IPv6)
counters.reply_NODATA--;
break;

case 2: // NXDOMAIN
counters.reply_NXDOMAIN--;
break;

case 3: // <CNAME>
counters.reply_CNAME--;
break;

case 4: // valid IP
counters.reply_IP--;
break;

default: // Incomplete query, do nothing
break;
}
break;
case 3:
// Answered from local cache _or_ local config
Expand Down
4 changes: 4 additions & 0 deletions parser.c
Original file line number Diff line number Diff line change
Expand Up @@ -916,21 +916,25 @@ void process_pihole_log(int file)
{
// NODATA(-IPv6)
queries[i].reply = 1;
counters.reply_NODATA++;
}
else if(strstr(readbuffer," is NXDOMAIN") != NULL)
{
// NXDOMAIN
queries[i].reply = 2;
counters.reply_NXDOMAIN++;
}
else if(strstr(readbuffer," is <CNAME>") != NULL)
{
// <CNAME>
queries[i].reply = 3;
counters.reply_CNAME++;
}
else
{
// Valid IP
queries[i].reply = 4;
counters.reply_IP++;
// const char * dest = strstr(readbuffer," is ");
// char * result;
// sscanf(dest, " is %ms", &result);
Expand Down

0 comments on commit 3346a84

Please sign in to comment.