From 2443b231e194acbb2e34c8e3fa912dad5ef798bb Mon Sep 17 00:00:00 2001 From: DL6ER Date: Sat, 20 Jan 2018 14:38:45 +0100 Subject: [PATCH] Detect if we cached the but still need to ask the upstream servers for the actual IPs. In think case we have to decrease the "cached" counter Signed-off-by: DL6ER --- parser.c | 45 ++++++++++++++++----------------------------- 1 file changed, 16 insertions(+), 29 deletions(-) diff --git a/parser.c b/parser.c index 257ea36e..b8c56e44 100644 --- a/parser.c +++ b/parser.c @@ -274,6 +274,13 @@ void process_pihole_log(int file) break; } + // Get timestamp + int querytimestamp, overTimetimestamp; + extracttimestamp(readbuffer, &querytimestamp, &overTimetimestamp); + + // Check if this query has already been imported from the database + if(querytimestamp < lastDBimportedtimestamp) continue; + // Test if the read line is a query line if(strstr(readbuffer," query[A") != NULL) { @@ -286,10 +293,6 @@ void process_pihole_log(int file) continue; } - // Get timestamp - int querytimestamp, overTimetimestamp; - extracttimestamp(readbuffer, &querytimestamp, &overTimetimestamp); - // Get minimum time stamp to analyze int differencetofullhour = time(NULL) % GCinterval; int mintime = (time(NULL) - GCdelay - differencetofullhour) - MAXLOGAGE; @@ -459,11 +462,6 @@ void process_pihole_log(int file) if(!checkQuery(readbuffer, "gravity.list")) continue; - // Check if this query has already been imported from the database - int querytimestamp, overTimetimestamp; - extracttimestamp(readbuffer, &querytimestamp, &overTimetimestamp); - if(querytimestamp < lastDBimportedtimestamp) continue; - // Get dnsmasq's ID for this transaction int dnsmasqID = getdnsmasqID(readbuffer); // Skip invalid lines @@ -513,11 +511,6 @@ void process_pihole_log(int file) if(!checkQuery(readbuffer, "forwarded")) continue; - // Check if this query has already been imported from the database - int querytimestamp, overTimetimestamp; - extracttimestamp(readbuffer, &querytimestamp, &overTimetimestamp); - if(querytimestamp < lastDBimportedtimestamp) continue; - // Get dnsmasq's ID for this transaction int dnsmasqID = getdnsmasqID(readbuffer); // Skip invalid lines @@ -569,6 +562,15 @@ void process_pihole_log(int file) // Check both UUID and generation of this query if(queries[i].id == dnsmasqID && queries[i].generation == loggeneration) { + // Detect if we cached the but need to ask the upstream + // servers for the actual IPs now + if(queries[i].status == 2) + { + // Fix counters + counters.cached--; + validate_access("overTime", queries[i].timeidx, true, __LINE__, __FUNCTION__, __FILE__); + overTime[queries[i].timeidx].cached--; + } queries[i].status = 2; queries[i].forwardID = forwardID; found = true; @@ -611,11 +613,6 @@ void process_pihole_log(int file) if(!checkQuery(readbuffer, "cached")) continue; - // Check if this query has already been imported from the database - int querytimestamp, overTimetimestamp; - extracttimestamp(readbuffer, &querytimestamp, &overTimetimestamp); - if(querytimestamp < lastDBimportedtimestamp) continue; - // Get dnsmasq's ID for this transaction int dnsmasqID = getdnsmasqID(readbuffer); // Skip invalid lines @@ -663,11 +660,6 @@ void process_pihole_log(int file) if(!checkQuery(readbuffer, "config")) continue; - // Check if this query has already been imported from the database - int querytimestamp, overTimetimestamp; - extracttimestamp(readbuffer, &querytimestamp, &overTimetimestamp); - if(querytimestamp < lastDBimportedtimestamp) continue; - // Get dnsmasq's ID for this transaction int dnsmasqID = getdnsmasqID(readbuffer); // Skip invalid lines @@ -733,11 +725,6 @@ void process_pihole_log(int file) if(!checkQuery(readbuffer, "black.list")) continue; - // Check if this query has already been imported from the database - int querytimestamp, overTimetimestamp; - extracttimestamp(readbuffer, &querytimestamp, &overTimetimestamp); - if(querytimestamp < lastDBimportedtimestamp) continue; - // Get dnsmasq's ID for this transaction int dnsmasqID = getdnsmasqID(readbuffer); // Skip invalid lines