Skip to content

Commit

Permalink
Merge pull request #174 from pi-hole/new/extra-logging
Browse files Browse the repository at this point in the history
Handle dnsmasq "extra" logging
  • Loading branch information
DL6ER authored Dec 28, 2017
2 parents d087434 + d669a65 commit 21e60e3
Show file tree
Hide file tree
Showing 8 changed files with 540 additions and 238 deletions.
9 changes: 9 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 Expand Up @@ -137,6 +141,11 @@ typedef struct {
int forwardID;
bool valid;
bool db;
// the ID is a (signed) int in dnsmasq, so no need for a long int here
int id;
bool complete;
unsigned char reply;
int generation;
} queriesDataStruct;

typedef struct {
Expand Down
13 changes: 9 additions & 4 deletions database.c
Original file line number Diff line number Diff line change
Expand Up @@ -309,14 +309,19 @@ void save_to_DB(void)
return;
}

int currenttimestamp = time(NULL);
for(i = lastdbindex; i < counters.queries; i++)
{
validate_access("queries", i, true, __LINE__, __FUNCTION__, __FILE__);
if(queries[i].timestamp <= lasttimestamp || queries[i].db == true)
{
// Already in database
// logg("Skipping %i",i);
if(queries[i].timestamp <= lasttimestamp || queries[i].db)
// Already in database or not yet complete
continue;

if(!queries[i].complete && queries[i].timestamp > currenttimestamp-2)
{
// Break if a brand new query (age < 2 seconds) is not yet completed
// giving it a chance to be stored next time
break;
}

// Memory checks
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
5 changes: 4 additions & 1 deletion log.c
Original file line number Diff line number Diff line change
Expand Up @@ -135,10 +135,13 @@ void log_counter_info(void)
{
logg(" -> Total DNS queries: %i", counters.queries);
logg(" -> Cached DNS queries: %i", counters.cached);
logg(" -> Blocked DNS queries: %i", counters.blocked);
logg(" -> Forwarded DNS queries: %i", counters.forwardedqueries);
logg(" -> Exactly blocked DNS queries: %i", counters.blocked);
logg(" -> Wildcard blocked DNS queries: %i", counters.wildcardblocked);
logg(" -> Unknown DNS queries: %i", counters.unknown);
logg(" -> Unique domains: %i", counters.domains);
logg(" -> Unique clients: %i", counters.clients);
logg(" -> Known forward destinations: %i", counters.forwarded);
}

void log_FTL_version(void)
Expand Down
2 changes: 1 addition & 1 deletion main.c
Original file line number Diff line number Diff line change
Expand Up @@ -145,11 +145,11 @@ int main (int argc, char* argv[]) {
// Have to re-read gravity files
rereadgravity = false;
read_gravity_files();
log_counter_info();
disable_thread_lock("pihole_main_thread");
}
}


logg("Shutting down...");
pthread_cancel(piholelogthread);
pthread_cancel(socket_listenthread);
Expand Down
Loading

0 comments on commit 21e60e3

Please sign in to comment.