Commit Graph

58 Commits

Author SHA1 Message Date
DL6ER 536ef08ce5 Free allocated memory after ordinary termination of TCP workers (TCP connection closed)
Signed-off-by: DL6ER <dl6er@dl6er.de>
2020-04-06 15:11:32 +02:00
DL6ER 3aa6edcf07 Implement process-private prepared gravity database client statements. This fixes an incompatibility across forks when serving TCP traffic using dedicated workers.
Signed-off-by: DL6ER <dl6er@dl6er.de>
2020-04-06 12:17:04 +02:00
DL6ER 48dc5ea073 Memorize PID of this thread to avoid re-opening the gravity database connection multiple times for the same fork
Signed-off-by: DL6ER <dl6er@dl6er.de>
2020-04-06 10:17:12 +02:00
DL6ER f1f817ab31 Re-open gravity database (and re-prepare database statements) before accessing the database in case FTL forked.
Signed-off-by: DL6ER <dl6er@dl6er.de>
2020-04-06 09:56:14 +02:00
DL6ER 3a5154bbb8 Merge branch 'release/v5.0' into tweak/sqlite_debugging 2020-03-28 15:13:05 +01:00
DL6ER 8406e1b036 Explicitly log if we had to make assumptions because the gravity database was not available.
Signed-off-by: DL6ER <dl6er@dl6er.de>
2020-03-25 08:07:13 +01:00
DL6ER c0b1489434 Explicitly set prepared statements to NULL when they are finalized.
Signed-off-by: DL6ER <dl6er@dl6er.de>
2020-03-25 07:57:44 +01:00
DL6ER 80fbd889f9 Replace sqlite3_errmsg() by sqlite3_errstr() everywhere to ensure we always catch the right error.
Signed-off-by: DL6ER <dl6er@dl6er.de>
2020-03-24 10:52:01 +01:00
DL6ER 07c8de2340 Signal early that database is opened to prevent re-opening in sub-processes.
Signed-off-by: DL6ER <dl6er@dl6er.de>
2020-03-23 09:58:44 +01:00
DL6ER 2fbdf7b004 Do not open gravity database if already connected.
Signed-off-by: DL6ER <dl6er@dl6er.de>
2020-03-23 08:33:28 +01:00
DL6ER aa3cc95ae1 Add more debugging output to database opening.
Signed-off-by: DL6ER <dl6er@dl6er.de>
2020-03-23 08:28:09 +01:00
DL6ER 5c3661015f Fix preparation of client statements when gravity database had to be re-opened.
Signed-off-by: DL6ER <dl6er@dl6er.de>
2020-03-08 16:27:06 +01:00
DL6ER 0b8915a321 Improve debugging output, reduce code duplication.
Signed-off-by: DL6ER <dl6er@dl6er.de>
2020-03-04 17:37:43 +00:00
DL6ER 0ac6b5cb69 Implement new SQLite3 subroutine which can interpret IP addresses that may use Classless Inter-Domain Routing (CIDR) notation. This is also known as variable-length subnet masking (VLSM) technique.
Signed-off-by: DL6ER <dl6er@dl6er.de>
2020-03-03 23:35:27 +00:00
DL6ER 71d2c8dcd7 Add busy timeout to gravity per-client group configuration importing. This may help on slow devices where updating the database is not yet finished when FTL is already trying to re-read to database tables.
Signed-off-by: DL6ER <dl6er@dl6er.de>
2020-02-22 12:31:29 +01:00
DL6ER 3e7641abee Try to reopen gravity database when not available.
Signed-off-by: DL6ER <dl6er@dl6er.de>
2020-02-22 12:06:26 +01:00
DL6ER 06b5f3ca6f Merge branch 'release/v5.0' into new/CNAME_inspection_details
Signed-off-by: DL6ER <dl6er@dl6er.de>
2020-02-11 10:17:44 +01:00
DL6ER 0d9b301733 Ensure we group domains read from the views by their ID to avoid importing identical regex filters multiple times.
Signed-off-by: DL6ER <dl6er@dl6er.de>
2020-02-06 17:45:42 +01:00
DL6ER 66f061265b Special debug logging.
Signed-off-by: DL6ER <dl6er@dl6er.de>
2020-02-05 23:41:40 +01:00
DL6ER 3ecc42b69d Merge branch 'release/v5.0' into tweak/gravity_count 2020-02-04 20:52:28 +01:00
DL6ER 5c08c56d35 Store ID of matching blacklist regex if this is the blocking reason.
Signed-off-by: DL6ER <dl6er@dl6er.de>
2020-02-04 08:34:01 +01:00
DL6ER 1af474819c Update tests to use gravity domain count stored in test database.
Signed-off-by: DL6ER <dl6er@dl6er.de>
2020-02-03 08:43:06 +01:00
DL6ER 2e7e6231e7 Use number of distinct gravity domains as counted and stored by pihole -g itself. This drastically reduces the runtime of reload-lists.
Signed-off-by: DL6ER <dl6er@dl6er.de>
2020-02-02 23:45:12 +01:00
DL6ER 6a6608fd60 Clarify gravity database debug message
Signed-off-by: DL6ER <dl6er@dl6er.de>
2020-01-28 19:04:30 +01:00
DL6ER 4c74a29f87 Add shared per-client regex array. This ensures TCP and UDP workers know the same details about client/regex combinations. This commit also fixes an issue with regex group associations for configured clients that have no assigned group.
Signed-off-by: DL6ER <dl6er@dl6er.de>
2019-12-30 17:14:40 +00:00
DL6ER 33940f2cf2 Add group zero support.
Signed-off-by: DL6ER <dl6er@dl6er.de>
2019-12-12 17:24:12 +00:00
DL6ER 9d65dd566f Check if gravity database is available before trying to use it in get_client_groupids().
Signed-off-by: DL6ER <dl6er@dl6er.de>
2019-11-28 09:18:07 +01:00
DL6ER 0941db9f0d Merge branch 'development' into new/internal-blocking 2019-09-23 21:03:28 +02:00
DL6ER 12df978432 Do not try to bind to statements that might not be available when preparing the database failed.
Signed-off-by: DL6ER <dl6er@dl6er.de>
2019-09-20 22:53:49 +02:00
DL6ER fe416709db Count DISTINCT domains when showing the size of gravity, blacklist, etc. Otherwise, we would show the domains once for each group so they might show up multiple times.
Signed-off-by: DL6ER <dl6er@dl6er.de>
2019-09-19 16:14:07 +02:00
DL6ER 0b7d9c7a29 Do not import untagged domains for a tagged client.
Signed-off-by: DL6ER <dl6er@dl6er.de>
2019-09-18 20:15:24 +02:00
DL6ER 3dde49da4f Ensure that untagged domains and regular expressions are used by clients that use group-based SELECT statements.
Signed-off-by: DL6ER <dl6er@dl6er.de>
2019-09-11 09:15:32 +02:00
DL6ER 8e7b31713f Implement per-client regular expressions.
Signed-off-by: DL6ER <dl6er@dl6er.de>
2019-09-11 09:14:21 +02:00
DL6ER c2c43a84e7 Check for availablility of prepared statement before trying to use it. This prevents us from preparing statements for clients that have been there within the past 24 hours but might have left the network meanwhile.
Signed-off-by: DL6ER <dl6er@dl6er.de>
2019-09-09 13:10:04 +02:00
DL6ER 72bc239b8f Re-prepare per-client statements for the gravity database after gravityDB_close() has finalized them when FTL received SIGHUP.
Signed-off-by: DL6ER <dl6er@dl6er.de>
2019-09-09 08:47:45 +02:00
DL6ER d303f5f6e8 Log if we are in DEBUG mode and prepare gravity client statements.
Signed-off-by: DL6ER <dl6er@dl6er.de>
2019-09-09 08:38:40 +02:00
DL6ER 424c9be804 Changes due to most addition of the association table client_by_group.
Signed-off-by: DL6ER <dl6er@dl6er.de>
2019-09-09 00:04:40 +02:00
DL6ER 96f00e0b08 Finish implementation of per-client gravity, whitelist, and blacklist.
Signed-off-by: DL6ER <dl6er@dl6er.de>
2019-09-07 13:02:13 +02:00
DL6ER 8c3ff39510 Implement client-specific gravity, white- and blacklist database statements.
Signed-off-by: DL6ER <dl6er@dl6er.de>
2019-09-07 11:48:32 +02:00
DL6ER a8410867a2 Remove now obsolete Pi-hole modifications from dnsmasq's code.
Signed-off-by: DL6ER <dl6er@dl6er.de>
2019-09-05 19:58:05 +02:00
DL6ER bbfa582e2d Instead of populating the DNS cache with the domains from the blacklist and gravity on startup/reload, we move the evaluation of whether or not a certain query is to be blocked out of the (generic) cache into FTL's main code. As this gives us full control over what is blocked and what not, it is also the first step into an often requested feature (per-client blocking with Pi-hole). Note that this commit should work without any changes to the gravity database. The performance impact is entirely untested as are the various blocking modes (I tested our standard NULL blocking over UDP and TCP and both seem to work). Consider this code as highly experimental but hopefully stable (given what "stable" means on our development branches)
Signed-off-by: DL6ER <dl6er@dl6er.de>
2019-09-04 18:18:34 +02:00
DL6ER f3e8d23baf Merge branch 'development' into new/whitelist-regex-support
Signed-off-by: DL6ER <dl6er@dl6er.de>
2019-08-17 15:01:32 +02:00
DL6ER 2a731f08a3 Remove call to sqlite3_finalize(stmt) on error in gravityDB_getDomain(). We always finalize the statement afterwards - whether or not we encountered an error before.
Signed-off-by: DL6ER <dl6er@dl6er.de>
2019-08-07 21:21:06 +02:00
DL6ER b21b551a52 Add busy timeout for database connections.
Signed-off-by: DL6ER <dl6er@dl6er.de>
2019-07-21 21:43:03 +02:00
DL6ER 8c6736a55f Fix minor typo.
Signed-off-by: DL6ER <dl6er@dl6er.de>
2019-07-16 18:49:51 +02:00
DL6ER dd8af36613 Add debugging output for gravity table if requested via DEBUG_DATABASE option. We might want to separate this into DEBUG_GRAVITY_DATABASE in the future.
Signed-off-by: DL6ER <dl6er@dl6er.de>
2019-07-16 12:25:42 +02:00
DL6ER a3f25f92f2 Do not check regex whitelist filters when querying the domain_audit table. Added documentation to in_whitelist() that explains the idea of the chosen implementation method.
Signed-off-by: DL6ER <dl6er@dl6er.de>
2019-07-16 12:04:43 +02:00
DL6ER caf18e1370 Improve difference between between REGEX and TABLE constants by renaming the latter to always end in _TABLE. Also remove code duplication by using a lookup array for the table names instead of using multiple select labels.
Signed-off-by: DL6ER <dl6er@dl6er.de>
2019-07-16 11:55:34 +02:00
DL6ER d362a5eb27 Merge branch 'development' into new/whitelist-regex-support
Signed-off-by: DL6ER <dl6er@dl6er.de>
2019-07-14 22:50:53 +02:00
DL6ER f996753dec Rename in_whitelist() to whitelisted() as this routine does not only compare against the whitelist table but also evaluates possible whitelist regex filters.
Signed-off-by: DL6ER <dl6er@dl6er.de>
2019-07-09 17:48:27 +02:00