Do not use a new option but instead automatically detect if ABP-style domains are present in the database. This ensures that this addition comes at no extra costs to any installs using pure HOSTS-style adlists.

Signed-off-by: DL6ER <dl6er@dl6er.de>
This commit is contained in:
DL6ER 2023-02-15 21:09:46 +01:00
parent 8794b1684d
commit 75cd6913ee
No known key found for this signature in database
GPG Key ID: 00135ACBD90B28DD
5 changed files with 40 additions and 18 deletions

View File

@ -1,6 +1,6 @@
{
"name": "FTL x86_64 Build Env",
"image": "ghcr.io/pi-hole/ftl-build:x86_64-musl",
"image": "ghcr.io/pi-hole/ftl-build:x86_64",
"extensions": [
"jetmartin.bats",
"ms-vscode.cpptools",

View File

@ -770,20 +770,6 @@ void read_FTLconf(void)
logg(" CHECK_DISK: Warning if certain disk usage exceeds %d%%", config.check.disk);
// GRAVITY_ABP_STYLE
// Should FTL check for ABP-style domain entries in the gravity database?
// This option should only be enabled if you are using ABP-style entries
// in your gravity database as it adds a significant overhead to the
// database query.
// defaults to: false
buffer = parse_FTLconf(fp, "GRAVITY_ABP_STYLE");
config.gravityABP = read_bool(buffer, false);
if(config.gravityABP)
logg(" GRAVITY_ABP_STYLE: Enabled");
else
logg(" GRAVITY_ABP_STYLE: Disabled");
// Read DEBUG_... setting from pihole-FTL.conf
read_debuging_settings(fp);

View File

@ -51,7 +51,6 @@ typedef struct {
bool edns0_ecs :1;
bool show_dnssec :1;
bool addr2line :1;
bool gravityABP:1;
struct {
bool mozilla_canary :1;
bool icloud_private_relay :1;

View File

@ -47,6 +47,7 @@ static sqlite3 *gravity_db = NULL;
static sqlite3_stmt* table_stmt = NULL;
static sqlite3_stmt* auditlist_stmt = NULL;
bool gravityDB_opened = false;
static bool gravity_abp_format = false;
// Table names corresponding to the enum defined in gravity-db.h
static const char* tablename[] = { "vw_gravity", "vw_blacklist", "vw_whitelist", "vw_regex_blacklist", "vw_regex_whitelist" , "" };
@ -95,6 +96,40 @@ void gravityDB_forked(void)
gravityDB_open();
}
static void gravity_check_ABP_format(void)
{
// Check if we have a valid ABP format
// We do this by checking if there are any domains in the gravity table that match the
// ABP format. If there are, we remember that we have seen this format.
// Prepare statement
sqlite3_stmt *stmt = NULL;
int rc = sqlite3_prepare_v2(gravity_db,
"SELECT EXISTS(SELECT 1 FROM gravity WHERE domain LIKE '||%^');",
-1, &stmt, NULL);
if( rc != SQLITE_OK )
{
logg("gravity_check_ABP_format() - SQL error prepare: %s", sqlite3_errstr(rc));
return;
}
// Execute statement
rc = sqlite3_step(stmt);
if( rc != SQLITE_ROW )
{
logg("gravity_check_ABP_format() - SQL error step: %s", sqlite3_errstr(rc));
sqlite3_finalize(stmt);
return;
}
// Get result
gravity_abp_format = sqlite3_column_int(stmt, 0) > 0;
// Finalize statement
sqlite3_finalize(stmt);
}
// Open gravity database
bool gravityDB_open(void)
{
@ -194,6 +229,9 @@ bool gravityDB_open(void)
logg("gravityDB_open() - Cannot set busy handler: %s", sqlite3_errstr(rc));
}
// Check if there are any ABP-style entries in the database
gravity_check_ABP_format();
if(config.debug & DEBUG_DATABASE)
logg("gravityDB_open(): Successfully opened gravity.db");
return true;
@ -1300,7 +1338,7 @@ enum db_result in_gravity(const char *domain, clientsData *client)
// Return early if we are not supposed to check for ABP-style regex
// matches. This needs to be enabled in the config file as it is
// computationally expensive and not needed in most cases (HOSTS lists).
if(!config.gravityABP)
if(!gravity_abp_format)
return NOT_FOUND;
// Make a copy of the domain we will slowly truncate

View File

@ -7,4 +7,3 @@ LOCAL_IPV4=10.100.0.10
LOCAL_IPV6=fe80::10
BLOCK_IPV4=10.100.0.11
BLOCK_IPV6=fe80::11
GRAVITY_ABP_STYLE=true