diff --git a/src/api/api.c b/src/api/api.c index 9edba5005..3874f4421 100644 --- a/src/api/api.c +++ b/src/api/api.c @@ -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)) diff --git a/src/database/query-table.c b/src/database/query-table.c index 6b04f9edf..169ccdad2 100644 --- a/src/database/query-table.c +++ b/src/database/query-table.c @@ -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); @@ -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; @@ -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; diff --git a/src/datastructure.h b/src/datastructure.h index 6eda319e2..c48a4a2f8 100644 --- a/src/datastructure.h +++ b/src/datastructure.h @@ -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; diff --git a/src/dnsmasq_interface.c b/src/dnsmasq_interface.c index 2c44b95a2..d8a62d94e 100644 --- a/src/dnsmasq_interface.c +++ b/src/dnsmasq_interface.c @@ -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; diff --git a/src/shmem.c b/src/shmem.c index 5d1b83e7c..0581f46eb 100644 --- a/src/shmem.c +++ b/src/shmem.c @@ -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"