Skip to content

Commit

Permalink
Merge pull request #1034 from pi-hole/release/v5.5
Browse files Browse the repository at this point in the history
Pi-hole FTL v5.5
  • Loading branch information
DL6ER authored Jan 19, 2021
2 parents 6bd0988 + 1ecb3ff commit fb9b274
Show file tree
Hide file tree
Showing 36 changed files with 1,090 additions and 527 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@
cmake_minimum_required(VERSION 2.8.12)
project(PIHOLE_FTL C)

set(DNSMASQ_VERSION pi-hole-2.82)
set(DNSMASQ_VERSION pi-hole-2.83)

add_subdirectory(src)
1 change: 1 addition & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ set(sources
shmem.h
signals.c
signals.h
static_assert.h
timers.c
timers.h
vector.c
Expand Down
59 changes: 20 additions & 39 deletions src/api/api.c
Original file line number Diff line number Diff line change
Expand Up @@ -397,7 +397,7 @@ void getTopClients(const char *client_message, const int *sock)
// Get client pointer
const clientsData* client = getClient(clientID, true);
// Skip invalid clients and also those managed by alias clients
if(client == NULL || (!client->aliasclient && client->aliasclient_id >= 0))
if(client == NULL || (!client->flags.aliasclient && client->aliasclient_id >= 0))
{
temparray[clientID][0] = -1;
continue;
Expand Down Expand Up @@ -823,7 +823,7 @@ void getAllQueries(const char *client_message, const int *sock)
clientid = i;

// Is this a alias-client?
if(client->aliasclient)
if(client->flags.aliasclient)
clientid_list = get_aliasclient_list(i);

break;
Expand Down Expand Up @@ -891,19 +891,12 @@ void getAllQueries(const char *client_message, const int *sock)
if(query->status == QUERY_UNKNOWN && !(showpermitted && showblocked))
continue;

// 1 = gravity.list, 4 = wildcard, 5 = black.list
if((query->status == QUERY_GRAVITY ||
query->status == QUERY_REGEX ||
query->status == QUERY_BLACKLIST ||
query->status == QUERY_GRAVITY_CNAME ||
query->status == QUERY_REGEX_CNAME ||
query->status == QUERY_BLACKLIST_CNAME) && !showblocked)
// Skip blocked queries when asked to
if(query->flags.blocked && !showblocked)
continue;
// 2 = forwarded, 3 = cached
if((query->status == QUERY_FORWARDED ||
query->status == QUERY_CACHE ||
query->status == QUERY_RETRIED ||
query->status == QUERY_RETRIED_DNSSEC) && !showpermitted)

// Skip permitted queries when asked to
if(!query->flags.blocked && !showpermitted)
continue;

// Skip those entries which so not meet the requested timeframe
Expand All @@ -921,10 +914,7 @@ void getAllQueries(const char *client_message, const int *sock)
// If the domain of this query did not match, the CNAME
// domain may still match - we have to check it in
// addition if this query is of CNAME blocked type
else if((query->status == QUERY_GRAVITY_CNAME ||
query->status == QUERY_BLACKLIST_CNAME ||
query->status == QUERY_REGEX_CNAME) &&
query->CNAME_domainID == domainid)
else if(query->CNAME_domainID > -1)
{
// Get this query
}
Expand Down Expand Up @@ -959,13 +949,8 @@ void getAllQueries(const char *client_message, const int *sock)

if(filterforwarddest)
{
// Does the user want to see queries answered from blocking lists?
if(forwarddestid == -2 && query->status != QUERY_GRAVITY
&& query->status != QUERY_REGEX
&& query->status != QUERY_BLACKLIST
&& query->status != QUERY_GRAVITY_CNAME
&& query->status != QUERY_REGEX_CNAME
&& query->status != QUERY_BLACKLIST_CNAME)
// Skip if not from the virtual blocking "upstream" server
if(forwarddestid == -2 && !query->flags.blocked)
continue;
// Does the user want to see queries answered from local cache?
else if(forwarddestid == -1 && query->status != QUERY_CACHE)
Expand Down Expand Up @@ -1017,7 +1002,7 @@ void getAllQueries(const char *client_message, const int *sock)
// Get IP of upstream destination, if applicable
in_port_t upstream_port = 0;
const char *upstream_name = "N/A";
if(query->status == QUERY_FORWARDED)
if(query->upstreamID > -1)
{
const upstreamsData *upstream = getUpstream(query->upstreamID, true);
if(upstream != NULL)
Expand Down Expand Up @@ -1104,15 +1089,8 @@ void getRecentBlocked(const char *client_message, const int *sock)
if(query == NULL)
continue;

if(query->status == QUERY_GRAVITY ||
query->status == QUERY_REGEX ||
query->status == QUERY_BLACKLIST ||
query->status == QUERY_GRAVITY_CNAME ||
query->status == QUERY_REGEX_CNAME ||
query->status == QUERY_BLACKLIST_CNAME)
if(query->flags.blocked)
{
found++;

// Ask subroutine for domain. It may return "hidden" depending on
// the privacy settings at the time the query was made
const char *domain = getDomainString(query);
Expand All @@ -1123,6 +1101,9 @@ void getRecentBlocked(const char *client_message, const int *sock)
ssend(*sock,"%s\n", domain);
else if(!pack_str32(*sock, domain))
return;

// Only count when sent succesfully
found++;
}

if(found >= num)
Expand Down Expand Up @@ -1312,7 +1293,7 @@ void getClientsOverTime(const int *sock)
// Check if this client should be skipped
if(insetupVarsArray(getstr(client->ippos)) ||
insetupVarsArray(getstr(client->namepos)) ||
(!client->aliasclient && client->aliasclient_id > -1))
(!client->flags.aliasclient && client->aliasclient_id > -1))
skipclient[clientID] = true;
}
}
Expand Down Expand Up @@ -1387,7 +1368,7 @@ void getClientNames(const int *sock)
// Check if this client should be skipped
if(insetupVarsArray(getstr(client->ippos)) ||
insetupVarsArray(getstr(client->namepos)) ||
(!client->aliasclient && client->aliasclient_id > -1))
(!client->flags.aliasclient && client->aliasclient_id > -1))
skipclient[clientID] = true;
}
}
Expand Down Expand Up @@ -1434,7 +1415,7 @@ void getUnknownQueries(const int *sock)
const queriesData* query = getQuery(queryID, true);

if(query == NULL ||
(query->status != QUERY_UNKNOWN && query->complete))
(query->status != QUERY_UNKNOWN && query->flags.complete))
continue;

char type[5];
Expand All @@ -1459,7 +1440,7 @@ void getUnknownQueries(const int *sock)
const char *clientIP = getstr(client->ippos);

if(istelnet[*sock])
ssend(*sock, "%lli %i %i %s %s %s %i %s\n", (long long)query->timestamp, queryID, query->id, type, getstr(domain->domainpos), clientIP, query->status, query->complete ? "true" : "false");
ssend(*sock, "%lli %i %i %s %s %s %i %s\n", (long long)query->timestamp, queryID, query->id, type, getstr(domain->domainpos), clientIP, query->status, query->flags.complete ? "true" : "false");
else {
pack_int32(*sock, (int32_t)query->timestamp);
pack_int32(*sock, query->id);
Expand All @@ -1473,7 +1454,7 @@ void getUnknownQueries(const int *sock)
return;

pack_uint8(*sock, query->status);
pack_bool(*sock, query->complete);
pack_bool(*sock, query->flags.complete);
}
}
}
Expand Down
15 changes: 14 additions & 1 deletion src/config.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@
// saveport()
#include "api/socket.h"

// INT_MAX
#include <limits.h>

ConfigStruct config;
FTLFileNamesStruct FTLfiles = {
// Default path for config file (regular installations)
Expand Down Expand Up @@ -132,12 +135,22 @@ void read_FTLconf(void)
buffer = parse_FTLconf(fp, "MAXDBDAYS");

int value = 0;
const int maxdbdays_max = INT_MAX / 24 / 60 / 60;
if(buffer != NULL && sscanf(buffer, "%i", &value))
if(value >= 0)
{
// Prevent possible overflow
if(value > maxdbdays_max)
value = maxdbdays_max;

// Only use valid values
if(value == -1 || value >= 0)
config.maxDBdays = value;
}

if(config.maxDBdays == 0)
logg(" MAXDBDAYS: --- (DB disabled)");
else if(config.maxDBdays == -1)
logg(" MAXDBDAYS: --- (cleaning disabled)");
else
logg(" MAXDBDAYS: max age for stored queries is %i days", config.maxDBdays);

Expand Down
27 changes: 17 additions & 10 deletions src/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,24 +17,20 @@
#include <sys/types.h>
// typedef uni32_t
#include <idn-int.h>
// assert_sizeof
#include "static_assert.h"

void getLogFilePath(void);
void read_FTLconf(void);
void get_privacy_level(FILE *fp);
void get_blocking_mode(FILE *fp);
void read_debuging_settings(FILE *fp);

// We do not use bitfields in here as this struct exists only once in memory.
// Accessing bitfields may produce slightly more inefficient code on some
// architectures (such as ARM) and savng a few bit of RAM but bloating up the
// rest of the application each time these fields are accessed is bad.
typedef struct {
int maxDBdays;
int port;
int maxlogage;
int dns_port;
unsigned int delay_startup;
enum debug_flags debug;
unsigned int network_expire;
enum privacy_level privacylevel;
enum blocking_mode blockingmode;
enum refresh_hostnames refresh_hostnames;
bool socket_listenlocal;
bool analyze_AAAA;
bool resolveIPv6;
Expand All @@ -48,8 +44,19 @@ typedef struct {
bool block_esni;
bool names_from_netdb;
bool edns0_ecs;
enum privacy_level privacylevel;
enum blocking_mode blockingmode;
enum refresh_hostnames refresh_hostnames;
int maxDBdays;
int port;
int maxlogage;
int dns_port;
unsigned int delay_startup;
unsigned int network_expire;
enum debug_flags debug;
time_t DBinterval;
} ConfigStruct;
ASSERT_SIZEOF(ConfigStruct, 56, 48, 48);

typedef struct {
const char* conf;
Expand Down
16 changes: 8 additions & 8 deletions src/database/aliasclients.c
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ static void recompute_aliasclient(const int aliasclientID)
// Get pointer to client candidate
const clientsData *client = getClient(clientID, true);
// Skip invalid clients and alias-clients
if(client == NULL || client->aliasclient)
if(client == NULL || client->flags.aliasclient)
continue;

// Skip clients that are not managed by this aliasclient
Expand Down Expand Up @@ -131,7 +131,7 @@ bool import_aliasclients(void)
const int clientID = findClientID(aliasclient_str, false, true);

clientsData *client = getClient(clientID, true);
client->new = false;
client->flags.new = false;

// Reset counter
client->count = 0;
Expand All @@ -141,7 +141,7 @@ bool import_aliasclients(void)
client->namepos = addstr(name);

// This is a aliasclient
client->aliasclient = true;
client->flags.aliasclient = true;
client->aliasclient_id = aliasclient_id;

// Debug logging
Expand Down Expand Up @@ -169,7 +169,7 @@ bool import_aliasclients(void)
static int get_aliasclient_ID(const clientsData *client)
{
// Skip alias-clients themselves
if(client->aliasclient)
if(client->flags.aliasclient)
return -1;

const char *clientIP = getstr(client->ippos);
Expand All @@ -190,7 +190,7 @@ static int get_aliasclient_ID(const clientsData *client)
const clientsData *alias_client = getClient(aliasclientID, true);

// Skip clients that are not alias-clients
if(!alias_client->aliasclient)
if(!alias_client->flags.aliasclient)
continue;

// Compare MAC address of the current client to the
Expand Down Expand Up @@ -220,7 +220,7 @@ static int get_aliasclient_ID(const clientsData *client)
void reset_aliasclient(clientsData *client)
{
// Skip alias-clients themselves
if(client->aliasclient)
if(client->flags.aliasclient)
return;

// Find corresponding alias-client (if any)
Expand Down Expand Up @@ -288,7 +288,7 @@ void reimport_aliasclients(void)
// Get pointer to client candidate
clientsData *client = getClient(clientID, true);
// Skip invalid and non-alias-clients
if(client == NULL || !client->aliasclient)
if(client == NULL || !client->flags.aliasclient)
continue;

// Reset this alias-client
Expand All @@ -309,7 +309,7 @@ void reimport_aliasclients(void)
// Get pointer to client candidate
clientsData *client = getClient(clientID, true);
// Skip invalid and alias-clients
if(client == NULL || client->aliasclient)
if(client == NULL || client->flags.aliasclient)
continue;

reset_aliasclient(client);
Expand Down
2 changes: 1 addition & 1 deletion src/database/database-thread.c
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ void *DB_thread(void *val)
unlock_shm();

// Check if GC should be done on the database
if(DBdeleteoldqueries)
if(DBdeleteoldqueries && config.maxDBdays != -1)
{
// No thread locks needed
delete_old_queries_in_DB();
Expand Down
Loading

0 comments on commit fb9b274

Please sign in to comment.