Skip to content

Commit

Permalink
Merge pull request #1013 from pi-hole/new/OTHER_types
Browse files Browse the repository at this point in the history
Implement support for displaying exact type instead of just "OTHER"
  • Loading branch information
DL6ER authored Jan 15, 2021
2 parents 24914b8 + a33c9d3 commit 00492c1
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 6 deletions.
8 changes: 8 additions & 0 deletions src/api/api.c
Original file line number Diff line number Diff line change
Expand Up @@ -878,6 +878,14 @@ void getAllQueries(const char *client_message, const int *sock)
continue;
// Get query type
const char *qtype = querytypes[query->type];
char othertype[12] = { 0 }; // Maximum is "TYPE65535" = 10 bytes
if(query->type == TYPE_OTHER)
{
// Format custom type into buffer
sprintf(othertype, "TYPE%u", query->qtype);
// Replace qtype pointer
qtype = othertype;
}

// Hide UNKNOWN queries when not requesting both query status types
if(query->status == QUERY_UNKNOWN && !(showpermitted && showblocked))
Expand Down
28 changes: 25 additions & 3 deletions src/database/query-table.c
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,16 @@ void DB_save_queries(void)
sqlite3_bind_int(stmt, 1, query->timestamp);

// TYPE
sqlite3_bind_int(stmt, 2, query->type);
if(query->type != TYPE_OTHER)
{
// Store mapped type if query->type is not OTHER
sqlite3_bind_int(stmt, 2, query->type);
}
else
{
// Store query type + offset if query-> type is OTHER
sqlite3_bind_int(stmt, 2, query->qtype + 100);
}

// STATUS
sqlite3_bind_int(stmt, 3, query->status);
Expand Down Expand Up @@ -344,7 +353,9 @@ void DB_read_queries(void)
}

const int type = sqlite3_column_int(stmt, 2);
if(type < TYPE_A || type >= TYPE_MAX)
const bool mapped_type = type >= TYPE_A && type < TYPE_MAX;
const bool offset_type = type > 100 && type < (100 + UINT16_MAX);
if(!mapped_type && !offset_type)
{
logg("FTL_db warn: TYPE should not be %i", type);
continue;
Expand Down Expand Up @@ -423,7 +434,18 @@ void DB_read_queries(void)
queriesData* query = getQuery(queryIndex, false);
query->magic = MAGICBYTE;
query->timestamp = queryTimeStamp;
query->type = type;
if(type < 100)
{
// Mapped query type
query->type = type;
}
else
{
// Offset query type
query->type = TYPE_OTHER;
query->qtype = type - 100;
}

query->status = status;
query->domainID = domainID;
query->clientID = clientID;
Expand Down
5 changes: 3 additions & 2 deletions src/datastructure.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,16 @@ typedef struct {
enum privacy_level privacylevel;
enum reply_type reply;
enum dnssec_status dnssec;
time_t timestamp;
uint16_t qtype;
int domainID;
int clientID;
int upstreamID;
int id; // the ID is a (signed) int in dnsmasq, so no need for a long int here
int CNAME_domainID; // only valid if query has a CNAME blocking status
unsigned int timeidx;
unsigned long response; // saved in units of 1/10 milliseconds (1 = 0.1ms, 2 = 0.2ms, 2500 = 250.0ms, etc.)
time_t timestamp;
int64_t db;
unsigned int timeidx;
bool whitelisted;
bool complete;
} queriesData;
Expand Down
1 change: 1 addition & 0 deletions src/dnsmasq_interface.c
Original file line number Diff line number Diff line change
Expand Up @@ -626,6 +626,7 @@ bool _FTL_new_query(const unsigned int flags, const char *name,
query->magic = MAGICBYTE;
query->timestamp = querytimestamp;
query->type = querytype;
query->qtype = qtype;
query->status = QUERY_UNKNOWN;
query->domainID = domainID;
query->clientID = clientID;
Expand Down
2 changes: 1 addition & 1 deletion src/shmem.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
#include "regex_r.h"

/// The version of shared memory used
#define SHARED_MEMORY_VERSION 10
#define SHARED_MEMORY_VERSION 11

/// The name of the shared memory. Use this when connecting to the shared memory.
#define SHMEM_PATH "/dev/shm"
Expand Down

0 comments on commit 00492c1

Please sign in to comment.