Skip to content

Commit

Permalink
Store blocked property in query flags.
Browse files Browse the repository at this point in the history
Signed-off-by: DL6ER <[email protected]>
  • Loading branch information
DL6ER committed Jan 18, 2021
1 parent 50d1829 commit c227fc1
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 11 deletions.
20 changes: 9 additions & 11 deletions src/database/query-table.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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++;
Expand All @@ -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;
Expand Down
2 changes: 2 additions & 0 deletions src/datastructure.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ typedef struct {
struct query_flags {
bool whitelisted :1;
bool complete :1;
bool blocked :1;
bool forwarded :1;
} flags;
} queriesData;

Expand Down
6 changes: 6 additions & 0 deletions src/dnsmasq_interface.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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++;
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit c227fc1

Please sign in to comment.