Ensure the API does not try to create DNS cache records for queries that don't have one

Signed-off-by: DL6ER <dl6er@dl6er.de>
This commit is contained in:
DL6ER
2022-08-20 15:27:38 +02:00
parent ff30d4a973
commit 1ccfd9a081
5 changed files with 12 additions and 9 deletions
+1 -1
View File
@@ -1012,7 +1012,7 @@ void getAllQueries(const char *client_message, const int sock, const bool isteln
int domainlist_id = -1;
if (config.privacylevel < PRIVACY_HIDE_DOMAINS)
{
unsigned int cacheID = findCacheID(query->domainID, query->clientID, query->type);
unsigned int cacheID = findCacheID(query->domainID, query->clientID, query->type, false);
DNSCacheData *dns_cache = getDNSCache(cacheID, true);
if(dns_cache != NULL)
domainlist_id = dns_cache->domainlist_id;
+2 -2
View File
@@ -373,7 +373,7 @@ int DB_save_queries(sqlite3 *db)
sqlite3_bind_null(query_stmt, 7);
}
const int cacheID = findCacheID(query->domainID, query->clientID, query->type);
const int cacheID = findCacheID(query->domainID, query->clientID, query->type, false);
DNSCacheData *cache = getDNSCache(cacheID, true);
// ADDITIONAL_INFO
@@ -933,7 +933,7 @@ void DB_read_queries(void)
// Set ID of the domainlist entry that was the reason for permitting/blocking this query
// We assume the value in this field is said ID when it is not a CNAME-related domain
// (checked above) and the value of additional_info is not NULL (0 bytes storage size)
const int cacheID = findCacheID(query->domainID, query->clientID, query->type);
const int cacheID = findCacheID(query->domainID, query->clientID, query->type, true);
DNSCacheData *cache = getDNSCache(cacheID, true);
// Only load if
// a) we have a cache entry
+4 -1
View File
@@ -319,7 +319,7 @@ void change_clientcount(clientsData *client, int total, int blocked, int overTim
}
}
int _findCacheID(int domainID, int clientID, enum query_types query_type, const char *func, int line, const char *file)
int _findCacheID(const int domainID, const int clientID, const enum query_types query_type, const bool create_new, const char *func, int line, const char *file)
{
// Compare content of client against known client IP addresses
for(int cacheID = 0; cacheID < counters->dns_cache_size; cacheID++)
@@ -339,6 +339,9 @@ int _findCacheID(int domainID, int clientID, enum query_types query_type, const
}
}
if(!create_new)
return -1;
// Get ID of new cache entry
const int cacheID = counters->dns_cache_size;
+2 -2
View File
@@ -113,8 +113,8 @@ int findQueryID(const int id);
int findUpstreamID(const char * upstream, const in_port_t port);
int findDomainID(const char *domain, const bool count);
int findClientID(const char *client, const bool count, const bool aliasclient);
#define findCacheID(domainID, clientID, query_type) _findCacheID(domainID, clientID, query_type, __FUNCTION__, __LINE__, __FILE__)
int _findCacheID(int domainID, int clientID, enum query_types query_type, const char *func, const int line, const char *file);
#define findCacheID(domainID, clientID, query_type, create_new) _findCacheID(domainID, clientID, query_type, create_new, __FUNCTION__, __LINE__, __FILE__)
int _findCacheID(const int domainID, const int clientID, const enum query_types query_type, const bool create_new, const char *func, const int line, const char *file);
bool isValidIPv4(const char *addr);
bool isValidIPv6(const char *addr);
+3 -3
View File
@@ -1249,7 +1249,7 @@ static bool _FTL_check_blocking(int queryID, int domainID, int clientID, const c
}
// Get cache pointer
unsigned int cacheID = findCacheID(domainID, clientID, query->type);
unsigned int cacheID = findCacheID(domainID, clientID, query->type, true);
DNSCacheData *dns_cache = getDNSCache(cacheID, true);
if(dns_cache == NULL)
{
@@ -1581,8 +1581,8 @@ bool _FTL_CNAME(const char *domain, const struct crec *cpp, const int id, const
else if(query->status == QUERY_REGEX)
{
// Get parent and child DNS cache entries
const int parent_cacheID = findCacheID(parent_domainID, clientID, query->type);
const int child_cacheID = findCacheID(child_domainID, clientID, query->type);
const int parent_cacheID = findCacheID(parent_domainID, clientID, query->type, false);
const int child_cacheID = findCacheID(child_domainID, clientID, query->type, false);
// Get cache pointers
DNSCacheData *parent_cache = getDNSCache(parent_cacheID, true);