From c227fc1598fcf211b0d0c223b7668cdc69210e9e Mon Sep 17 00:00:00 2001 From: DL6ER Date: Mon, 18 Jan 2021 14:57:20 +0100 Subject: [PATCH] Store blocked property in query flags. Signed-off-by: DL6ER --- src/database/query-table.c | 20 +++++++++----------- src/datastructure.h | 2 ++ src/dnsmasq_interface.c | 6 ++++++ 3 files changed, 17 insertions(+), 11 deletions(-) diff --git a/src/database/query-table.c b/src/database/query-table.c index 4034703ca..4f450998e 100644 --- a/src/database/query-table.c +++ b/src/database/query-table.c @@ -148,7 +148,7 @@ void DB_save_queries(void) sqlite3_bind_text(stmt, 5, client, -1, SQLITE_STATIC); // FORWARD - if(query->status == QUERY_FORWARDED && query->upstreamID > -1) + if(query->flags.forwarded && query->upstreamID > -1) { // Get forward pointer const upstreamsData* upstream = getUpstream(query->upstreamID, true); @@ -209,15 +209,7 @@ void DB_save_queries(void) // Total counter information (delta computation) total++; - if(query->status == QUERY_GRAVITY || - query->status == QUERY_BLACKLIST || - query->status == QUERY_REGEX || - query->status == QUERY_EXTERNAL_BLOCKED_IP || - query->status == QUERY_EXTERNAL_BLOCKED_NULL || - query->status == QUERY_EXTERNAL_BLOCKED_NXRA || - query->status == QUERY_GRAVITY_CNAME || - query->status == QUERY_REGEX_CNAME || - query->status == QUERY_BLACKLIST_CNAME) + if(query->flags.blocked) blocked++; // Update lasttimestamp variable with timestamp of the latest stored query @@ -453,11 +445,15 @@ void DB_read_queries(void) query->timeidx = timeidx; query->db = dbid; query->id = 0; - query->flags.complete = true; // Mark as all information is available query->response = 0; query->dnssec = DNSSEC_UNSPECIFIED; query->reply = REPLY_UNKNOWN; query->CNAME_domainID = -1; + // Initialize flags + query->flags.complete = true; // Mark as all information is available + query->flags.blocked = false; + query->flags.forwarded = false; + query->flags.whitelisted = false; // Set lastQuery timer for network table clientsData* client = getClient(clientID, true); @@ -523,6 +519,7 @@ void DB_read_queries(void) case QUERY_REGEX_CNAME: // Blocked by regex blacklist (inside CNAME path) case QUERY_BLACKLIST_CNAME: // Blocked by exact blacklist (inside CNAME path) counters->blocked++; + query->flags.blocked = true; // Get domain pointer domainsData* domain = getDomain(domainID, true); domain->blockedcount++; @@ -533,6 +530,7 @@ void DB_read_queries(void) case QUERY_FORWARDED: // Forwarded counters->forwarded++; + query->flags.forwarded = true; // Update overTime data structure overTime[timeidx].forwarded++; break; diff --git a/src/datastructure.h b/src/datastructure.h index 6a2454e98..295267a7f 100644 --- a/src/datastructure.h +++ b/src/datastructure.h @@ -46,6 +46,8 @@ typedef struct { struct query_flags { bool whitelisted :1; bool complete :1; + bool blocked :1; + bool forwarded :1; } flags; } queriesData; diff --git a/src/dnsmasq_interface.c b/src/dnsmasq_interface.c index 228dc98d0..8c99e2d72 100644 --- a/src/dnsmasq_interface.c +++ b/src/dnsmasq_interface.c @@ -641,6 +641,10 @@ bool _FTL_new_query(const unsigned int flags, const char *name, // Store DNSSEC result for this domain query->dnssec = DNSSEC_UNSPECIFIED; query->CNAME_domainID = -1; + // This query is not yet known ad forwarded or blocked + query->flags.blocked = false; + query->flags.forwarded = false; + query->flags.whitelisted = false; // Check and apply possible privacy level rules // The currently set privacy level (at the time the query is @@ -910,6 +914,7 @@ void _FTL_forwarded(const unsigned int flags, const char *name, const struct ser // from above as otherwise this check will always // be negative query->status = QUERY_FORWARDED; + query->flags.forwarded = true; // Update overTime data overTime[timeidx].forwarded++; @@ -1442,6 +1447,7 @@ static void query_blocked(queriesData* query, domainsData* domain, clientsData* // Update status query->status = new_status; + query->flags.blocked = true; } void _FTL_dnssec(const int status, const int id, const char* file, const int line)