Commit Graph

108 Commits

Author SHA1 Message Date
DL6ER
6fcbce6c34 Improve code based on a full static analysis of our code. There are no real bugs, nowever, we use the obtained knowledge to improve the code such as unify declarations and function definitions, reduce the scope of local variables, mark many function arguments and local variables const when they are, fix the type expected by %x and fix one if-condition
Signed-off-by: DL6ER <dl6er@dl6er.de>
2019-04-15 22:35:14 +02:00
Mark Drobnak
adecb56f1c Merge branch 'development' into fix/externally_blocked_use_RA 2019-03-11 22:47:20 -04:00
DL6ER
f2ac2362fa Merge branch 'development' into fix/externally_blocked_use_RA
Signed-off-by: DL6ER <dl6er@dl6er.de>
2019-03-11 17:16:22 +01:00
DL6ER
0d6f424f1f Enforce prototyping. This ensures that function that are not explicitly made globally available across files (through an explicit prototype in a header file) need to be marked static such that their scope is limited to where they are actually used. This also enforces strict prototyping, i.e., a function with zero arguments needs to be written explicitly as function(void) as a non-strict prototype such as function() would in fact allow an arbitrary amount of parameters.
Signed-off-by: DL6ER <dl6er@dl6er.de>
2019-03-10 15:31:14 +01:00
DL6ER
a3924c06cf Declare return value of getstr() as const char* because the returned strings should not be modifiable. Similarly, neither pack_fixstr() nor pack_str32() should be able to modify strings they are given. Furthermore, getDomainString(), getClientIPString(), getClientNameString(), getSetupVarsArray(), insetupVarsArray(), and getSetupVarsBool() should never modify the strings they receive as arguments.
Signed-off-by: DL6ER <dl6er@dl6er.de>
2019-03-10 11:24:51 +01:00
DL6ER
32be41ed5d Declare attributes for functions in FTL. These attributes help the compiler to optimize functions calls and to check our code more carefully during compilation. See pull reqeust text for details.
Signed-off-by: DL6ER <dl6er@dl6er.de>
2019-03-08 11:36:11 +01:00
DL6ER
2f74929d2a Merge branch 'development' into tweak/overhaul_overTime
Signed-off-by: DL6ER <dl6er@dl6er.de>
2019-02-18 19:00:09 +01:00
Mark Drobnak
341dd8f90b Merge pull request #511 from pi-hole/sqlite/3.27.1
Update SQLite3 to v3.27.1
2019-02-17 14:18:33 -05:00
Mcat12
ab082a4857 Fix spelling error
Signed-off-by: Mcat12 <newtoncat12@yahoo.com>
2019-02-17 11:16:12 -08:00
Mcat12
d04c0aa3a4 Fix last timestamp getting set to zero if no queries were saved
If no queries were saved to the database, the last timestamp field would
be set to zero instead of left as it was. In addition, this commit skips
adding zero to the other counters in the database if there were no saved
queries.

Signed-off-by: Mcat12 <newtoncat12@yahoo.com>
2019-02-16 14:57:36 -08:00
DL6ER
f54f5d413c As of SQLite3 v3.27.0, string literals need to be single-quotes. Double-quoted string literals are still accepted but issue a warning (see https://sqlite.org/quirks.html#dblquote)
Signed-off-by: DL6ER <dl6er@dl6er.de>
2019-02-16 09:41:14 +01:00
DL6ER
756fd0055d Add SQLite3 logging callback. SQLite can be configured to invoke a callback function containing an error code and a terse error message whenever anomalies occur. This mechanism is very helpful in tracking obscure problems that occur rarely and in the field. Application developers are encouraged to take advantage of the error logging facility of SQLite in their products, as it is very low CPU and memory cost but can be a huge aid for debugging.
Signed-off-by: DL6ER <dl6er@dl6er.de>
2019-02-16 09:17:35 +01:00
Mcat12
3cc4cca280 Remove OVERTIME_NOT_AVAILABLE
There is now no case where the overTime ID is invalid. GC will run
before the overTime slots run out.

Signed-off-by: Mcat12 <newtoncat12@yahoo.com>
2019-02-10 13:55:10 -08:00
DL6ER
cde008177f Redesign overTime data structure to use a known size, avoiding the need for on-the-fly resizing of the nested structs
Signed-off-by: DL6ER <dl6er@dl6er.de>
2019-02-10 09:30:41 +01:00
DL6ER
5bee17bd24 Implement finer-grained externally blocked displaying. This updates the shared memory version to 3
Signed-off-by: DL6ER <dl6er@dl6er.de>
2019-02-04 17:42:11 +01:00
DL6ER
f3235f107c Merge branch 'development' into fix/externally_blocked_use_RA
Signed-off-by: DL6ER <dl6er@dl6er.de>
2019-02-03 08:35:02 +01:00
DL6ER
be18b0745e Several microoptimizations around the code that checks the AD bit. Remove the now obsolete AD boolean in the queries struct
Signed-off-by: DL6ER <dl6er@dl6er.de>
2019-02-01 20:38:11 +01:00
DL6ER
72d91e8288 Merge branch 'release/v4.2' into update/devel_v4.2
Signed-off-by: DL6ER <dl6er@dl6er.de>

Conflicts:
	database.c
	docker/arm/Dockerfile
2019-01-24 10:18:27 +01:00
DL6ER
608458edfd Only include sqlite3.h in those files that need it. This should improve the compiling time slightly
Signed-off-by: DL6ER <dl6er@dl6er.de>
2019-01-22 17:26:25 +01:00
DL6ER
9d0346a424 Ensure lastdbindex in properly set after reading in queries from the database
Signed-off-by: DL6ER <dl6er@dl6er.de>
2019-01-22 17:23:34 +01:00
DL6ER
2c41ae7b73 Offer fine grained debugging options through independentally configurable debug flags. The debugging output of FTL gre considerable over the last year and became overwhelming for users that are not used to it. With this addition, users will be able to switch on only what they want to see.
Signed-off-by: DL6ER <dl6er@dl6er.de>
2019-01-16 09:14:35 +01:00
Mcat12
2b1a58bf9b Mark queries imported from the database as having an unknown DNSSEC type
Also explicity marks the queries with an unknown reply type. However,
this was already happening before, because `REPLY_UNKNOWN` equals 0,
and the struct is zero-initialized.

Signed-off-by: Mcat12 <newtoncat12@yahoo.com>
2019-01-11 21:51:15 -08:00
DL6ER
486e497d8a Review comments
Signed-off-by: DL6ER <dl6er@dl6er.de>
2019-01-07 02:17:22 +01:00
DL6ER
d8fdf76ceb Store number of queries per client in the database
Signed-off-by: DL6ER <dl6er@dl6er.de>
2018-12-28 12:18:35 +01:00
DL6ER
ac6ee9e1ef Add config option to disable ARP cache parsing
Signed-off-by: DL6ER <dl6er@dl6er.de>
2018-12-26 11:29:28 +01:00
DL6ER
3a8c87907a Initialize new devices with lastQuery property if available
Signed-off-by: DL6ER <dl6er@dl6er.de>
2018-12-26 11:14:25 +01:00
DL6ER
68a584ad8b Reduce code duplication
Signed-off-by: DL6ER <dl6er@dl6er.de>
2018-12-26 01:21:00 +01:00
DL6ER
95d3c02c5f Store lastQuery property for known clients
Signed-off-by: DL6ER <dl6er@dl6er.de>
2018-12-25 22:35:16 +01:00
DL6ER
82b43c332b Parse ARP cache after storing queries into long-term database(usen the dedicated database thread)
Signed-off-by: DL6ER <dl6er@dl6er.de>
2018-12-25 17:56:44 +01:00
DL6ER
c7bdf9bd60 Update if device uses Pi-hole and store host name if available
Print executed SQL statements when in debug mode

Signed-off-by: DL6ER <dl6er@dl6er.de>
2018-12-25 13:45:34 +01:00
DL6ER
40fd4d317e Add / update rows in table network depending on what we see in the ARP cache
Signed-off-by: DL6ER <dl6er@dl6er.de>
2018-12-24 13:19:18 +01:00
DL6ER
36d1499804 Add network table. This will update the database to version 3. Furthermore, we make some database routines globally (add prototypes to routines.h) and mark some internal database variables as static. This commit also improves on the speed of the database routines as the main loop is changed to run from the last saved query to the most recent one instead of looping over all queries in memory. This ID is corrected when queries are removed in gc.c
Signed-off-by: DL6ER <dl6er@dl6er.de>
2018-12-23 12:51:03 +01:00
Mcat12
ff4d985f9d Merge branch 'new/shmem' into feature/shm-lock
# Conflicts:
#	database.c
#	request.c
2018-11-21 14:56:15 -05:00
DL6ER
85290bb73e Merge branch 'development' into new/shmem
Signed-off-by: DL6ER <dl6er@dl6er.de>
2018-11-21 20:44:37 +01:00
DL6ER
8de30790f8 Review comments
Signed-off-by: DL6ER <dl6er@dl6er.de>
2018-11-10 08:16:36 +01:00
DL6ER
eeae592c58 Ensure regex validation is working as expected if privacylevel > 0. This required a certain rearrangement of how we handle domains and clients internally.
Signed-off-by: DL6ER <dl6er@dl6er.de>
2018-11-09 19:02:06 +01:00
DL6ER
f8ba1739b3 Remove unused variable queryID
Signed-off-by: DL6ER <dl6er@dl6er.de>
2018-10-25 21:33:55 +02:00
DL6ER
100d92bbd9 Set queryID to zero for queries imported from the database on startup
Signed-off-by: DL6ER <dl6er@dl6er.de>
2018-10-25 21:29:16 +02:00
DL6ER
f2f3566980 Move resolution of client and upstream host names to a dedicated thread. Fixes #404
Signed-off-by: DL6ER <dl6er@dl6er.de>
2018-10-25 19:53:29 +02:00
Mcat12
d7b4ce8a5f Remove read lock and simplify lock names
Signed-off-by: Mcat12 <newtoncat12@yahoo.com>
2018-10-11 15:59:52 -04:00
DL6ER
601722d441 Obtain ID before insertion transaction and store IDs only when a query has actually been saved instead of trying to do this in a post-processing step
Signed-off-by: DL6ER <dl6er@dl6er.de>
2018-10-11 06:10:18 +02:00
DL6ER
1279b93294 Store database ID in queries struct. This information will be availabe through shmem to the API to support transparent overlap with the SQlite3 database
Signed-off-by: DL6ER <dl6er@dl6er.de>
2018-10-07 20:50:21 +02:00
Mcat12
8c68aac456 Add shared memory lock
This replaces the previous mutex managed by threads.c. The lock is
stored in shared memory with the name "/FTL-lock", and any clients
connecting to the shared memory are expected to use the lock when
accessing memory.

Signed-off-by: Mcat12 <newtoncat12@yahoo.com>
2018-10-05 01:18:40 -04:00
Mcat12
cd41aaeab4 Put overTime data into shared memory
The array of overTime structs is separate from the client data, because
the client data is dynamically sized. Each client has a separate shared
memory block named `/FTL-client-ID` where `ID` is the numerical ID of
the client. The client data is an array of ints, which is indexed using
the overTime time indexes.

Before, the code referenced the client data via
`overTime[timeIndex].clientdata[clientID]`
Now, the code references the data via
`overTimeClientData[clientID][timeIndex]`

The client data is updated whenever a new client or overTime slot is
added, so referencing the client data should always be valid.

Signed-off-by: Mcat12 <newtoncat12@yahoo.com>
2018-09-19 13:00:50 -04:00
Mcat12
e1c8ccc975 Use negative query IDs for queries loaded from the database
This is necessary for all queries to have unique IDs. Previously,
all queries loaded from the database had an ID of zero.

Signed-off-by: Mcat12 <newtoncat12@yahoo.com>
2018-09-18 11:40:44 -04:00
Mcat12
ae1bb5b71a Move counters to shared memory
This requires that it be accessed through a pointer, so most of the
changes are just changing `counters.` to `counters->`

Signed-off-by: Mcat12 <newtoncat12@yahoo.com>
2018-09-03 14:25:16 -04:00
Mcat12
bbfe186dd8 Merge branch 'development' into new/shmem
# Conflicts:
#	api.c
#	dnsmasq_interface.c
2018-09-01 22:34:39 -04:00
DL6ER
dfe27e7c3b Add PRIVACY_NOSTATS mode that skips all (!) analysis. We furthermore don't even try to import or save anything to the database.
Signed-off-by: DL6ER <dl6er@dl6er.de>
2018-08-19 14:14:06 +02:00
DL6ER
79b2865bab Add new query type QUERY_EXTERNAL_BLOCKED triggered by an NXDOMAIN response with set AD bit (this is how Quad9 signals a blocked domain)
Signed-off-by: DL6ER <dl6er@dl6er.de>
2018-08-15 23:45:27 +02:00
DL6ER
64a895d720 Allow all query types (not only A and AAAA) during database import
Signed-off-by: DL6ER <dl6er@dl6er.de>
2018-08-09 11:57:41 +02:00