Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle dnsmasq "extra" logging #174

Merged
merged 26 commits into from
Dec 28, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
c86e8d9
Extract dnsmasq's ID from the logged queries
DL6ER Dec 21, 2017
90494ec
Modify parser to understand "query" lines with IDs
DL6ER Dec 21, 2017
468da59
Added proper analysis for "cached" lines + outsourced the timestamp d…
DL6ER Dec 21, 2017
a20eb2d
Initialize query status with 0 (unknown)
DL6ER Dec 21, 2017
9c49155
Change the logic FTL uses to treat the counters
DL6ER Dec 21, 2017
678e755
Properly update time index
DL6ER Dec 21, 2017
413dd41
List files like gravity.list, local.list, and hostname.list have to h…
DL6ER Dec 21, 2017
538e5a3
Handle wildcard blocked domains correctly
DL6ER Dec 21, 2017
d276e3b
Handle exactly blocked queries (blocked by black.list)
DL6ER Dec 21, 2017
99506f0
Have to actually break out of the loops for i to be the queryID
DL6ER Dec 21, 2017
541d86b
Add (undocumented) debugging command over telnet (display unknown que…
DL6ER Dec 21, 2017
24e4f6f
Display counter information after re-reading the log file (received S…
DL6ER Dec 21, 2017
478568e
Extend the new debug command a little bit
DL6ER Dec 21, 2017
f935312
Don't reuse i as counting index where we need it as query ID
DL6ER Dec 21, 2017
b61d035
Update tests with new log format
DL6ER Dec 21, 2017
86393d5
Skip lines without UUID
DL6ER Dec 21, 2017
f416fa5
Add the concept of log generations to account for UUIDs that are not …
DL6ER Dec 21, 2017
3d0fc44
Further reduction of code duplication in the parser routine
DL6ER Dec 22, 2017
8035d9f
Save only complete queries into the database
DL6ER Dec 22, 2017
dc0788c
Merge branch 'development' into new/extra-logging
DL6ER Dec 22, 2017
dac50b1
Add parsing for "reply ... is ..." lines
DL6ER Dec 26, 2017
13b89c7
Save reply type in query struct (can be used somewhere later on)
DL6ER Dec 26, 2017
7cbf68f
Output correct counters in log_counter_info() (this has always been w…
DL6ER Dec 27, 2017
3346a84
Add global counters for types of replies (and properly GC them)
DL6ER Dec 28, 2017
dbc9457
Worked on review comments
DL6ER Dec 28, 2017
d669a65
Compare age of query against current time to decide if we should give…
DL6ER Dec 28, 2017
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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