Commit Graph

1908 Commits

Author SHA1 Message Date
DL6ER 1097d75cb5
Only match full lines in input file
Signed-off-by: DL6ER <dl6er@dl6er.de>
2023-03-25 19:02:04 +01:00
DL6ER 688e1d5112
Add gravity parseList funtion to FTL
Signed-off-by: DL6ER <dl6er@dl6er.de>
2023-03-25 18:07:02 +01:00
Samu Voutilainen 2f29edb8be
Correct declaration for blockingstatus variable.
Signed-off-by: Samu Voutilainen <smar@smar.fi>
2023-03-24 07:02:01 +02:00
Samu Voutilainen 094f33a8c2
Correct declaration for query_blocked().
Fixes build on OpenSUSE Tumbleweed.

Signed-off-by: Samu Voutilainen <smar@smar.fi>
2023-03-24 07:01:58 +02:00
Adam Warner e408bd9e2d
Merge pull request #1543 from pi-hole/update/dnsmasq
Update embedded dnsmasq
2023-03-22 21:08:24 +00:00
DL6ER d35edd4840
Merge pull request #1536 from MichaIng/development
Add RISC-V 64-bit support and builds
2023-03-20 20:46:54 +01:00
MichaIng 017e086c1c
Add RISC-V 64-bit support and builds
Signed-off-by: MichaIng <micha@dietpi.com>
2023-03-20 20:03:19 +01:00
DL6ER e08f118bba
Add .codespellignore file to fix spell-checker action
Signed-off-by: DL6ER <dl6er@dl6er.de>
2023-03-20 19:46:09 +01:00
Simon Kelley cf20043aab
Remove limitation on --dynamic-host.
Dynamic-host was implemented to ignore interface addresses with /32
(or /128 for IPv6) prefix lengths, since they are not useful for
synthesising addresses.

Due to a bug before 2.88, this didn't work for IPv4, and some have
used --dynamic-host=example.com,0.0.0.0,eth0 to do the equivalent of
--interface-name for such interfaces. When the bug was fixed in 2.88
these uses broke.

Since this behaviour seems to violate the principle of least surprise,
and since the 2.88 fix is breaking existing imstallations, this
commit removes the check on /32 and /128 prefix lengths to solve both
problems.

Signed-off-by: DL6ER <dl6er@dl6er.de>
2023-03-18 13:59:07 +01:00
Simon Kelley 8d130417f4
Fix DHCPv6 "use multicast" response which previously failed to set the message type correctly.
Thanks to Petr Menšík for spotting the problem.

Signed-off-by: DL6ER <dl6er@dl6er.de>
2023-03-18 13:59:03 +01:00
Clayton Craft e57b84be66
Allow configuring filter-A/AAAA via dbus.
Signed-off-by: DL6ER <dl6er@dl6er.de>
2023-03-18 13:58:46 +01:00
Simon Kelley 16b711dd1c
Generalise cached NXDOMAIN replies.
We can cache an NXDOMAIN reply to a query for any RRTYPE
and reply from a cached NXDOMAIN to any RRTYPE.

Signed-off-by: DL6ER <dl6er@dl6er.de>
2023-03-18 13:58:46 +01:00
Simon Kelley e5c5a34dd7
Set the default maximum DNS UDP packet size to 1232.
http://www.dnsflagday.net/2020/ refers.

Thanks to Xiang Li for the prompt.

Signed-off-by: DL6ER <dl6er@dl6er.de>
2023-03-18 13:58:46 +01:00
Simon Kelley 4f2fd40c7d
Fix possible SEGV when no servers defined.
If there exists a --address=/<domain>/  or --server=/<domain>/#
configuration but no upstream server config unqualified by
domain then when a query which doesnt match the domain is
recieved it will use the qualfied server config and in the process
possibly make an out-of-bounds memory access.

Thanks to Daniel Danzberger for spotting the bug.

Signed-off-by: DL6ER <dl6er@dl6er.de>
2023-03-18 13:58:46 +01:00
Dominik Derigs d7883c53dd
Fix --rev-server option. It was broken in 1db9943c6879c160a5fbef885d5ceadd3668b74d when resolving upstream servers by name was extended to --rev-server without accounting for the fact that re-using one and the same upstream server for each of the x.y.z.in-addr.arpa is actually a wanted feature
Signed-off-by: DL6ER <dl6er@dl6er.de>
2023-03-18 13:58:46 +01:00
Taylor R Campbell e343086ca5
Avoid undefined behaviour with the ctype(3) functions.
As defined in the C standard:

	In all cases the argument is an int, the value of which shall
	be representable as an unsigned char or shall equal the value
	of the macro EOF.  If the argument has any other value, the
	behavior is undefined.

This is because they're designed to work with the int values returned
by getc or fgetc; they need extra work to handle a char value.

If EOF is -1 (as it almost always is), with 8-bit bytes, the allowed
inputs to the ctype(3) functions are:

	{-1, 0, 1, 2, 3, ..., 255}.

However, on platforms where char is signed, such as x86 with the
usual ABI, code like

	char *arg = ...;
	... isspace(*arg) ...

may pass in values in the range:

	{-128, -127, -126, ..., -2, -1, 0, 1, ..., 127}.

This has two problems:

1. Inputs in the set {-128, -127, -126, ..., -2} are forbidden.

2. The non-EOF byte 0xff is conflated with the value EOF = -1, so
   even though the input is not forbidden, it may give the wrong
   answer.

Casting char to int first before passing the result to ctype(3)
doesn't help: inputs like -128 are unchanged by this cast.  It is
necessary to cast char inputs to unsigned char first; you can then
cast to int if you like but there's no need because the functions
will always convert the argument to int by definition.  So the above
fragment needs to be:

	char *arg = ...;
	... isspace((unsigned char)*arg) ...

This patch inserts unsigned char casts where necessary, and changes
int casts to unsigned char casts where the input is char.

I left alone int casts where the input is unsigned char already --
they're not immediately harmful, although they would have the effect
of suppressing some compiler warnings if the input is ever changed to
be char instead of unsigned char, so it might be better to remove
those casts too.

I also left alone calls where the input is int to begin with because
it came from getc; casting to unsigned char here would be wrong, of
course.

Signed-off-by: DL6ER <dl6er@dl6er.de>
2023-03-18 13:58:43 +01:00
DL6ER f4cd2b4e98
Put version.ftl also behind new no-ident config option
Signed-off-by: DL6ER <dl6er@dl6er.de>
2023-03-15 21:31:12 +01:00
DL6ER b87ef114ef
Merge pull request #1532 from pi-hole/new/adb_style_blocking
Add support for Adblock Plus domain lists
2023-03-11 15:18:29 -05:00
DL6ER 62ebd05496
Apply Pi-hole SQLite3 patches
Signed-off-by: DL6ER <dl6er@dl6er.de>
2023-03-11 07:52:57 +01:00
DL6ER 1fe7bb6946
Update embedded SQLite3 engine to version 3.41.1
Signed-off-by: DL6ER <dl6er@dl6er.de>
2023-03-11 07:45:25 +01:00
DL6ER da118e87ce
Remove last traces of temporarily added benchmarking tools. Also remove the hint about ABP domains, this can easily be checked in gravity
Signed-off-by: DL6ER <dl6er@dl6er.de>
2023-03-05 13:56:55 +01:00
DL6ER 06f0e0340e
Remove debugging timing output
Signed-off-by: DL6ER <dl6er@dl6er.de>
2023-02-26 16:52:23 +01:00
DL6ER ae9b291082
Set abp_domains = 1 during the CI tests.
Signed-off-by: DL6ER <dl6er@dl6er.de>
2023-02-26 07:19:48 +01:00
DL6ER ab2f652e22
Use property "abp_domains" from info table to decide whether ABP blocking is to be used or not. Also log when FTL enabled ABP-style blocking
Signed-off-by: DL6ER <dl6er@dl6er.de>
2023-02-25 22:29:17 +01:00
DL6ER ec82cd3dd4
Add timing for ABP style detection
Signed-off-by: DL6ER <dl6er@dl6er.de>
2023-02-25 18:37:40 +01:00
Dan Schaper 6f8ba76077
Update src/database/gravity-db.c
Spespellingllling

Signed-off-by: Dan Schaper <dan.schaper@pi-hole.net>
2023-02-15 14:01:37 -08:00
Christian König d9c753be27
Fix spellcheck to get things deployed
Signed-off-by: Christian König <ckoenig@posteo.de>
2023-02-15 21:55:47 +01:00
DL6ER 80b5fa008c
Fix handling of rare (but possible) gravity database issues such as "list not available"
Signed-off-by: DL6ER <dl6er@dl6er.de>
2023-02-15 21:27:12 +01:00
DL6ER 75cd6913ee
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>
2023-02-15 21:19:31 +01:00
DL6ER 8794b1684d
Add ABP format blocking support for gravity. Note that the option needs to be switched on by setting GRAVITY_ABP_STYLE=true in pihole-FTL.conf to avoid running this computationally expensive task on the vast majority of user databases only fed from properly formatted HOSTS lists. Gravity can enable the setting when it detects ABP format automatically.
Signed-off-by: DL6ER <dl6er@dl6er.de>
2023-02-15 19:48:19 +01:00
DL6ER a8a75d86e6
Merge pull request #1522 from pi-hole/update/dnsmasq
Update embedded dnsmasq to v2.89
2023-02-07 19:42:45 +01:00
DL6ER 49e1c74455
New syntax: querytype=A accepts now also a list (like querytype=A,AAAA,MX). You can use the exclamation mark as before for inversion (querytype=!A) matches everything BUT type A queries. This has now been extended to be able to invert a list, too (like (querytype=!A,AAAA matches everything BUT A and AAAA queries)
Signed-off-by: DL6ER <dl6er@dl6er.de>
2023-01-26 20:11:55 +01:00
Dominik Derigs 1b62122a8c
Add --no-ident option.
Signed-off-by: DL6ER <dl6er@dl6er.de>
2023-01-26 20:11:55 +01:00
DL6ER 8b9e6c6c7e
Print regex type hints only in debug mode
Signed-off-by: DL6ER <dl6er@dl6er.de>
2023-01-26 20:11:55 +01:00
DL6ER ffa4d338f1
Allow selection of multiple query types in regex extension, like "abcabc;querytype=HTTPS,SVCB"
Signed-off-by: DL6ER <dl6er@dl6er.de>
2023-01-15 13:20:21 +01:00
Simon Kelley 33c04059f4
Fix bug which can break the invariants on the order of a hash chain.
If there are multiple cache records with the same name but different
F_REVERSE and/or F_IMMORTAL flags, the code added in fe9a134b could
concievable break the REVERSE-FORWARD-IMMORTAL order invariant.

Reproducing this is damn near impossible, but it is responsible
for rare and otherwise inexplicable reversion between 2.87 and 2.88
which manifests itself as a cache internal error. All observed
cases have depended on DNSSEC being enabled, but the bug could in
theory manifest itself without DNSSEC

Thanks to Timo van Roermund for reporting the bug and huge
efforts to isolate it.

Signed-off-by: DL6ER <dl6er@dl6er.de>
2023-01-15 07:54:55 +01:00
Simon Kelley 45a760b3f8
Fix cosmetic big in dump_cache_entry()
Signed-off-by: DL6ER <dl6er@dl6er.de>
2023-01-15 07:54:51 +01:00
Simon Kelley 21cec0c01d
Log all cache internal errors.
Signed-off-by: DL6ER <dl6er@dl6er.de>
2023-01-15 07:54:47 +01:00
Simon Kelley 3b103ae8aa
If we hit a cache internal error, log the entry we failed to remove.
This is code which should never run, but if it does,
we now log information useful for debugging.

Signed-off-by: DL6ER <dl6er@dl6er.de>
2023-01-15 07:54:40 +01:00
Christian König 6bb3927e7a
Remove gray color in help output
Signed-off-by: Christian König <ckoenig@posteo.de>
2023-01-08 22:20:36 +01:00
DL6ER f0b133b285
Always store time we start to save to the database (not only in debug mode). This avoids errorneous timing reports in case of errors.
Signed-off-by: DL6ER <dl6er@dl6er.de>
2022-12-27 07:31:39 +01:00
DL6ER 529fbb8e52
Merge pull request #1510 from pi-hole/update/dnsmasq
Update embedded dnsmasq to v2.88
2022-12-21 20:52:10 +01:00
Simon Kelley db98d0b495
Add posix-timezone and tzdb-timezone DHCPv6 options.
They are already in place for DHCPv4.
2022-12-21 20:38:43 +01:00
DL6ER ffea21e6b7
Merge pull request #1501 from pi-hole/new/colorful_cli
Improve -vv and --help
2022-12-11 11:33:37 +01:00
DL6ER bf0bbd9092
Review comments
Signed-off-by: DL6ER <dl6er@dl6er.de>
2022-12-10 13:57:21 +01:00
DL6ER 66af13b283
Merge pull request #1502 from pi-hole/fix/dnsmasq-test-segfault
Exit immediately after running dnsmasq-test
2022-12-10 11:40:01 +01:00
DL6ER f6e8d7fff6
Exit immediately after running dnsmasq-test
Signed-off-by: DL6ER <dl6er@dl6er.de>
2022-12-09 16:45:50 +01:00
DL6ER 3f1be06814
Fix logic for status code parsing
Signed-off-by: DL6ER <dl6er@dl6er.de>
2022-12-09 16:43:43 +01:00
DL6ER 92d7d314f9
Modify text slightly to prevent codespell from misinterpreting a control sequence as spellchecking error
Signed-off-by: DL6ER <dl6er@dl6er.de>
2022-12-09 11:49:49 +01:00
DL6ER 4e392f0ad8
Minor improvements (show -h in the qlite3 usage and remove extra newline after dnsmasq-test)
Signed-off-by: DL6ER <dl6er@dl6er.de>
2022-12-09 11:37:36 +01:00
DL6ER 8cacd8f5ec
Adds colors (if available) to verbose version output and completely revamp the help function
Signed-off-by: DL6ER <dl6er@dl6er.de>
2022-12-09 10:42:20 +01:00
DL6ER 983544e6d3
Fix incorrect DNSSEC-related warning during history import
Signed-off-by: DL6ER <dl6er@dl6er.de>
2022-12-03 12:43:20 +01:00
DL6ER 0766a9e4fc
Update embedded dnsmasq to v2.88rc5
Signed-off-by: DL6ER <dl6er@dl6er.de>
2022-11-27 12:03:43 +01:00
DL6ER f72bbc9e0e
Re-install Pi-hole modifications to src/dnsmasq/forward.c and src/dnsmasq/rfc1035.c
Signed-off-by: DL6ER <dl6er@dl6er.de>
2022-11-27 11:03:28 +01:00
Simon Kelley 4650c3d9f5
Handle malformed DNS replies better.
If we detect that that reply from usptream is malformed,
transform it into a SERVFAIL reply before sending to the
original requestor.

Signed-off-by: DL6ER <dl6er@dl6er.de>
2022-11-27 10:50:30 +01:00
DL6ER 9bb96b5b93
Undo Pi-hole modification in src/dnsmasq/forward.c
Signed-off-by: DL6ER <dl6er@dl6er.de>
2022-11-27 10:49:23 +01:00
Brad Smith c81b15ee65
Fix warning in cache.c
Signed-off-by: DL6ER <dl6er@dl6er.de>
2022-11-27 10:44:13 +01:00
Dominik Derigs 1f2ef8c037
Make max staleness of stale cache entries configurable and default to one day.
Signed-off-by: DL6ER <dl6er@dl6er.de>
2022-11-27 10:44:09 +01:00
Petr Menšík 208a1824b1
Fix use-after-free in mark_servers()
Signed-off-by: DL6ER <dl6er@dl6er.de>
2022-11-27 10:44:03 +01:00
DL6ER 4fdf3d9ab4
Re-add /*** Pi-hole modification ***/ comments
Signed-off-by: DL6ER <dl6er@dl6er.de>
2022-11-26 18:13:33 +01:00
DL6ER 7023feaccc
Merge branch 'development' into update/lua
Signed-off-by: DL6ER <dl6er@dl6er.de>
2022-11-25 19:55:41 +01:00
DL6ER bc4a2b11e9
Merge pull request #1492 from pi-hole/new/embedded_lua_scripts
Embedded lua scripts into FTL
2022-11-25 19:51:32 +01:00
DL6ER d626c0d6c7
Add missing newline in front of LUA details in pihole-FTL -vv
Signed-off-by: DL6ER <dl6er@dl6er.de>
2022-11-25 19:18:47 +01:00
DL6ER 8957ee456b
Update embedded LUA to 5.4.4
Signed-off-by: DL6ER <dl6er@dl6er.de>
2022-11-25 19:13:51 +01:00
DL6ER 717181335b
Add LUA patches
Signed-off-by: DL6ER <dl6er@dl6er.de>
2022-11-25 19:07:49 +01:00
DL6ER d066946e3f
Print embedded libraries in pihole-FTL -vv
Signed-off-by: DL6ER <dl6er@dl6er.de>
2022-11-25 12:07:46 +01:00
DL6ER a1ba4bc97d
Update inspect.lua
Signed-off-by: DL6ER <dl6er@dl6er.de>
2022-11-25 12:07:46 +01:00
DL6ER 5252aeb077
Reference sqlite3ErrName instead of copying it. This requires SQLite3 patching
Signed-off-by: DL6ER <dl6er@dl6er.de>
2022-11-25 11:35:08 +01:00
DL6ER 51b2b71756
Print extended error code if anything in dbquery() fails. This will be helpful in a lot of cases where we'd only be logging 'disk I/O error' but a more specififc error is available
Signed-off-by: DL6ER <dl6er@dl6er.de>
2022-11-25 11:32:15 +01:00
Petr Menšík f74523d391
fixup! Handle DS records for unsupported crypto algorithms. 2022-11-23 04:16:32 +01:00
Simon Kelley 96e1c4407e
Optimise readng large number --server options at start up.
When re-reading upstream servers from /etc/resolv.conf or other
sources that can change dnsmasq tries to avoid memory fragmentation by
re-using existing records that are being re-read unchanged. This
involves seaching all the server records for each new one installed.
During startup this search is pointless, and can cause long start
times with thousands of --server options because the work needed is
O(n^2). Handle this case more intelligently.  Thanks to Ye Zhou for
spotting the problem and an initial patch.

Signed-off-by: DL6ER <dl6er@dl6er.de>
2022-11-23 04:15:54 +01:00
DL6ER 395e0792d8
Use luaL_loadbufferx to pass name directly to interpreter
Signed-off-by: DL6ER <dl6er@dl6er.de>
2022-11-20 13:56:42 +01:00
DL6ER 0fea2d586b
Add facility to embedd LUA scripts into FTL and run them during luainit
Signed-off-by: DL6ER <dl6er@dl6er.de>
2022-11-20 12:57:39 +01:00
DL6ER bfd2c988ce
Merge pull request #1491 from pi-hole/update/dnsmasq
Update embedded dnsmasq to v2.88rc3
2022-11-19 09:34:44 +01:00
Simon Kelley b7c858f6b5
Fix SEGV on --local= added by immediately previous commit.
Signed-off-by: DL6ER <dl6er@dl6er.de>
2022-11-19 08:17:35 +01:00
Simon Kelley 576e766b59
Fix struct hostinfo free code and BSD compile.
The code added in6 c596f1cc1d92b2b90ef5ce043ace314eefa868b
fails to free the returned datastructures from gethostinfo()
because sdetails.hostinfo is used to loop through the addresses
and ends up NULL. In some libc implementations this results
in a SEGV when freeaddrinfo() is called.

Also fix FTBFS under BSD. Thanks to Johnny S. Lee for the bug report.

Signed-off-by: DL6ER <dl6er@dl6er.de>
2022-11-19 08:17:28 +01:00
DL6ER fe4077ea9f
Increase default SQLite3 cache size from 2000 kiB to 16 MiB
Signed-off-by: DL6ER <dl6er@dl6er.de>
2022-11-18 10:51:43 +01:00
DL6ER f4c9460f21
Merge pull request #1485 from pi-hole/fix/forked_shmSettings
Fix shared memory crashes in TCP forks
2022-11-17 12:59:07 +01:00
DL6ER cafa2eff8f
Merge pull request #1482 from pi-hole/update/sqlite_3.40.0
Update embedded SQLite3 engine to version 3.40.0
2022-11-17 12:51:42 +01:00
DL6ER 9dd37ecafb
Merge pull request #1480 from pi-hole/tweak/unique_messages
Always ensure FTL messages are unique
2022-11-17 12:51:34 +01:00
DL6ER 78597ddf1c
Verify PID of shared memory without remapping global shmSettings object
Signed-off-by: DL6ER <dl6er@dl6er.de>
2022-11-16 21:57:13 +01:00
Simon Kelley bc1acb24e8
Handle DS records for unsupported crypto algorithms correctly.
Such a DS, as long as it is validated, should allow answers
in the domain is attests to be returned as unvalidated, and not
as a validation error.

Signed-off-by: DL6ER <dl6er@dl6er.de>
2022-11-16 21:44:27 +01:00
Simon Kelley b6e61c2da0
Fix GOST signature algorithms for DNSSEC validation.
Use CryptoPro version of the hash function.
Handle the little-endian wire format of key data.
Get the wire order of S and R correct.

Note that Nettle version 3.6 or later is required for GOST support.

Signed-off-by: DL6ER <dl6er@dl6er.de>
2022-11-16 21:44:23 +01:00
Simon Kelley c030b2d610
Handle known DNSSEC signature algorithms which are not supported.
This fixes a confusion if certain algorithms are not supported
because the version is the crypto library is too old.  The validation
should be treated the same as for a completely unknown algorithm,
(ie return unverified answer) and not as a validation failure
(ie return SERVFAIL).

The algorithems affected are GOST and ED448.

Signed-off-by: DL6ER <dl6er@dl6er.de>
2022-11-16 21:44:19 +01:00
DL6ER bb57105001
Update embedded SQLite3 engine to version 3.40.0
Signed-off-by: DL6ER <dl6er@dl6er.de>
2022-11-16 17:58:46 +01:00
DL6ER c689cf23ff
Add debugging output to verify_shmem_pid()
Signed-off-by: DL6ER <dl6er@dl6er.de>
2022-11-16 04:26:55 +01:00
DL6ER af495664f9
Adlist warning -> ADLIST WARNING
Signed-off-by: DL6ER <dl6er@dl6er.de>
2022-11-15 21:28:38 +01:00
DL6ER fc212c383a
Always ensure FTL messages are unique
Signed-off-by: DL6ER <dl6er@dl6er.de>
2022-11-15 19:33:47 +01:00
DL6ER b63a37281d
Force 8 digits to display git object names
Signed-off-by: DL6ER <dl6er@dl6er.de>
2022-11-14 22:52:53 +01:00
DL6ER 64d5b3af4e
Fix CMake ENV var comparison to restore compilation in environments where this variable is unset
Signed-off-by: DL6ER <dl6er@dl6er.de>
2022-11-14 22:41:31 +01:00
DL6ER a052113364
Add "pihole-FTL --hash" printing the current git hash of the binary's source code
Signed-off-by: DL6ER <dl6er@dl6er.de>
2022-11-14 22:21:10 +01:00
DL6ER 9fe7fb5686
Merge pull request #1472 from pi-hole/special/CI_development
Update CI to ftl-build:v1.23 containers
2022-11-14 08:19:50 +01:00
DL6ER eec622c687
Add shortcut to compile an all-options build of dnsmasq inside FTL. Note that this does not include ubus as it is an OpenWRT-native thing that cannot be setup easily on any other distro.
Signed-off-by: DL6ER <dl6er@dl6er.de>
2022-11-10 20:36:25 +01:00
DL6ER 4b798e8aec
Fix incorrect three-way merge happened when importing the stale-cache patch
Signed-off-by: DL6ER <dl6er@dl6er.de>
2022-11-09 20:09:49 +01:00
Simon Kelley 2a94aef407
Fix --server=/domain/#
Signed-off-by: DL6ER <dl6er@dl6er.de>
2022-11-09 20:09:49 +01:00
Simon Kelley 1449829f1d
Fix --server with multiple domains.
Signed-off-by: DL6ER <dl6er@dl6er.de>
2022-11-09 20:09:49 +01:00
Simon Kelley ed8d37bf0b
Make specifying nameservers by name work for DBus API.
Signed-off-by: DL6ER <dl6er@dl6er.de>
2022-11-09 20:09:49 +01:00
Simon Kelley 0ae86d2641
Call freeaddrinfo() in domain_rev[46]()
Signed-off-by: DL6ER <dl6er@dl6er.de>
2022-11-09 20:09:48 +01:00
DL6ER 7ecd358f96
Allow FTL to analyze stale cache replies. They are assigned to a new query type (17)
Signed-off-by: DL6ER <dl6er@dl6er.de>
2022-11-09 20:09:48 +01:00
DL6ER 42c71058a9
Add support for dnsmasq flags F_SRV and F_STALE
Signed-off-by: DL6ER <dl6er@dl6er.de>
2022-11-09 20:09:48 +01:00
Simon Kelley 891acaa301
Extend specifying DNS servers by domain-name to --rev-server
Also Dbus SetDomainServers method.

Revert getaddrinfo hints.ai_socktype to SOCK_DGRAM to eliminate
duplicating every address three times for DGRAM, STREAM and RAW
in the results.

Signed-off-by: DL6ER <dl6er@dl6er.de>
2022-11-09 20:09:48 +01:00
Simon Kelley 1b2612cff6
Fix breakage of --local=/domain.name/1.2.3.4 in immediately previous commit.
Signed-off-by: DL6ER <dl6er@dl6er.de>
2022-11-09 20:09:48 +01:00
Dominik Derigs 703ee7e2b0
Allow domain names as well is IP addresses in --server options.
Signed-off-by: DL6ER <dl6er@dl6er.de>
2022-11-09 20:09:48 +01:00
Simon Kelley 2bf2863224
Reconcile "names" and "address" counts when reading hostfiles.
Signed-off-by: DL6ER <dl6er@dl6er.de>
2022-11-09 20:09:48 +01:00
Simon Kelley 8aba33f751
Inotify: make "flushed" log message more understandable.
Saying we've "flushed x outdated entries" is confusing, since
the count is the total number of entries in the modified file,
most of which are going	to get added straight back when	the file
is re-read.

The log now looks like

dnsmasq: inotify: /tmp/dir/1 (new or modified)
dnsmasq: inotify: flushed 1 addresses read from /tmp/dir/1
dnsmasq: read /tmp/dir/1 - 2 addresses

which hopefully make it more obvious that /tmp/dir/1 contained one
address before, and now contains two.

Signed-off-by: Dominik Derigs <dl6er@dl6er.de>
2022-11-09 20:09:48 +01:00
Dominik Derigs 779ba107fa
Do not (try to) re-read deleted files inside a --hostsdir.
Signed-off-by: Dominik Derigs <dl6er@dl6er.de>
2022-11-09 20:09:48 +01:00
Simon Kelley 3a6dd32f91
Fix in dhcpv4 rapid-commit code.
1) Cosmetic: don't log the tags twice.

2) Functional. If a host has an old lease for a different address,
   the rapid-commit will appear to work, but the old lease will
   not be removed and the new lease will not be recorded, so
   the client and server will have conflicting state, leading to
   problems later.

Signed-off-by: Dominik Derigs <dl6er@dl6er.de>
2022-11-09 20:09:48 +01:00
Simon Kelley cdf9d9d5ab
Add --no-round-robin option.
Signed-off-by: DL6ER <dl6er@dl6er.de>
2022-11-09 20:09:48 +01:00
Simon Kelley 4cfb84ae99
Fix loss of DNS servers on config reload.
A bug, introduced in 2.87, which could result in DNS
servers being removed from the configuration when reloading
server configuration from DBus, or re-reading /etc/resolv.conf
Only servers from the same source should be replaced, but some
servers from other sources (ie hard coded or another dynamic source)
could mysteriously disappear.

Signed-off-by: DL6ER <dl6er@dl6er.de>
2022-11-09 20:09:48 +01:00
Dominik Derigs a1b66e89d2
Handle multiple addresses when removing duplicates in host files.
Signed-off-by: DL6ER <dl6er@dl6er.de>
2022-11-09 20:09:48 +01:00
Dominik Derigs e8d19f71cc
Enhance --hostdir so that records are automatically removed when re-reading.
Initial patch from Dominik Derigs, re-written by Simon Kelley.

Signed-off-by: DL6ER <dl6er@dl6er.de>
2022-11-09 20:09:48 +01:00
Dominik Derigs 652c1e8a90
Improve logging of DNS record source from --hostsdir files.
Patch author Dominik Derigs <dl6er@dl6er.de> with subsequent bugfixes
and tweaks from Simon Kelley.

Signed-off-by: DL6ER <dl6er@dl6er.de>
2022-11-09 20:09:48 +01:00
DL6ER 0dc053364b
Locally blocked queries are not stale
Signed-off-by: DL6ER <dl6er@dl6er.de>
2022-11-09 20:09:48 +01:00
Simon Kelley 5929989ff9
Fix bug in --dynamic-host when interface has /16 IPv4 address.
Signed-off-by: DL6ER <dl6er@dl6er.de>
2022-11-09 20:09:48 +01:00
Simon Kelley 976e9321ed
Add ClearMetrics Dbus method.
Signed-off-by: DL6ER <dl6er@dl6er.de>
2022-11-09 20:09:48 +01:00
Simon Kelley f4e359296d
Optimise cache code when stale caching in use.
Exclude DNSSEC entries from stale caching.

Signed-off-by: DL6ER <dl6er@dl6er.de>
2022-11-09 20:09:48 +01:00
Simon Kelley 0fd2a136c6
Don't exclude stale-cache answers from "local answered" metric.
Signed-off-by: DL6ER <dl6er@dl6er.de>
2022-11-09 20:09:48 +01:00
Simon Kelley 5935160b7b
Initialise modified-moving-average latency calc better.
Use the first value, rather than initialising at zero,
which takes many queries to converge.

Signed-off-by: DL6ER <dl6er@dl6er.de>
2022-11-09 20:09:48 +01:00
Simon Kelley a59927835f
Split failed queries in retries in stat counting.
Signed-off-by: DL6ER <dl6er@dl6er.de>
2022-11-09 20:09:48 +01:00
Simon Kelley 861f529980
Tweak server-selection logic in the fast-retry case.
Signed-off-by: DL6ER <dl6er@dl6er.de>
2022-11-09 20:09:48 +01:00
Simon Kelley b9957e4ca1
Keep a per-DNS-server moving average of query latency.
Signed-off-by: DL6ER <dl6er@dl6er.de>
2022-11-09 20:09:48 +01:00
Simon Kelley 7cae4bd3c3
Combine server stats from all records for the same server in DBUS method.
The DBUS per-server stats method should combine the stats from
different records (for different domains) in the same way at the
logging code.

Signed-off-by: DL6ER <dl6er@dl6er.de>
2022-11-09 20:09:48 +01:00
Simon Kelley 3d5b4e20ec
Count NXDOMAIN replies from each server.
Signed-off-by: DL6ER <dl6er@dl6er.de>
2022-11-09 20:09:48 +01:00
Simon Kelley 85fdfb0d79
Add metric for queries which never see an answer.
Signed-off-by: DL6ER <dl6er@dl6er.de>
2022-11-09 20:09:48 +01:00
Simon Kelley 039e2b3711
Make fast-retry more configurable and do exponential backoff.
Signed-off-by: DL6ER <dl6er@dl6er.de>
2022-11-09 20:09:48 +01:00
Simon Kelley ee8072555a
Remove unused vars.
Signed-off-by: DL6ER <dl6er@dl6er.de>
2022-11-09 20:09:48 +01:00
Simon Kelley 11119f7ed9
Return EDE_STALE extended error when returning stale data from cache.
Signed-off-by: DL6ER <dl6er@dl6er.de>
2022-11-09 20:09:48 +01:00
Simon Kelley 8f2d7b5302
Add stale cache replies to metrics.
Signed-off-by: DL6ER <dl6er@dl6er.de>
2022-11-09 20:09:48 +01:00
Simon Kelley 7fe84aeba4
Add GetServerMetrics method to DBus interface.
Signed-off-by: DL6ER <dl6er@dl6er.de>
2022-11-09 20:09:48 +01:00
Simon Kelley 10dcef3ea9
Further optimisation of --port-limit.
No longer try and fail to open every port when the port range
is in complete use; go straight to re-using an existing socket.

Die at startup if port range is smaller than --port-limit, since
the code behaves badly in this case.

Signed-off-by: DL6ER <dl6er@dl6er.de>
2022-11-09 20:09:48 +01:00
Simon Kelley 281063af0c
Second try at port-limit option.
1) It's expected to fail to bind a new source port when they
   are scarce, suppress warning in log in this case.

2) Optimse bind_local when max_port - min_port is small. There's no
   randomness in this case, so we try all possible source ports
   rather than poking at random ones for an arbitrary number of tries.

3) In allocate_rfd() handle the case that all available source ports
   are already open. In this case we need to pick an existing
   socket/port to use, such that it has a different port from any we
   already hold. This gives the required property that the set of ports
   utilised by any given query is set by --port-limit and we don't
   re-use any until we have port-limit different ones.

Signed-off-by: DL6ER <dl6er@dl6er.de>
2022-11-09 20:09:48 +01:00
Simon Kelley d4065af553
Fix namebuff overwrite leading to wrong log after socket bind warning.
Signed-off-by: DL6ER <dl6er@dl6er.de>
2022-11-09 20:09:47 +01:00
Simon Kelley 00f7c4e95c
Remove fast-retry development logging.
Signed-off-by: DL6ER <dl6er@dl6er.de>
2022-11-09 20:09:47 +01:00
Simon Kelley cf06741178
Add --use-stale-cache option.
Signed-off-by: DL6ER <dl6er@dl6er.de>
2022-11-09 20:09:47 +01:00
Simon Kelley c7a4c2dac4
Add --fast-dns-retry option.
This gives dnsmasq the ability to originate retries for upstream DNS
queries itself, rather than relying on the downstream client. This is
most useful when doing DNSSEC over unreliable upstream network. It
comes with some cost in memory usage and network bandwidth.

Signed-off-by: DL6ER <dl6er@dl6er.de>
2022-11-09 20:09:47 +01:00
Simon Kelley f3bf5480c0
Add --port-limit option.
By default, when sending a query via random ports to multiple upstream servers or
retrying a query dnsmasq will use a single random port for all the tries/retries.
This option allows a larger number of ports to be used, which can increase robustness
in certain network configurations. Note that increasing this to more than
two or three can have security and resource implications and should only
be done with understanding of those.

Signed-off-by: DL6ER <dl6er@dl6er.de>
2022-11-09 20:09:46 +01:00
DL6ER 94be8de5b6
Merge pull request #1467 from pi-hole/update/ftl-build
Update included crypto library (nettle)
2022-11-06 15:04:01 +01:00
DL6ER 9f156f5ade
Merge pull request #1464 from pi-hole/tweak/shmem
Improve shared memory protection
2022-11-06 13:23:27 +01:00
DL6ER cd83c1108b
Include libnettle version in pihole-FTL -vv output
Signed-off-by: DL6ER <dl6er@dl6er.de>
2022-11-06 08:45:37 +01:00
DL6ER a0909894c4
Adjust tests
Signed-off-by: DL6ER <dl6er@dl6er.de>
2022-11-03 20:51:54 +01:00
DL6ER 612b31b735
Write PID early on so systemd cannot be fooled during DELAY_STARTUP times. The PID in this file will later be overwritten after forking
Signed-off-by: DL6ER <dl6er@dl6er.de>
2022-11-03 20:51:48 +01:00
DL6ER 1e39eddbf8
Ensure DELAY_STARTUP can be interrupted by external signals (e.g. SIGTERM) when trying to restart FTL really early
Signed-off-by: DL6ER <dl6er@dl6er.de>
2022-11-03 20:45:31 +01:00
DL6ER 1d447acb5a
Store and check shared memory ownership before resizing shared memory objects. The scenario we are resolving here is the following: FTL is already running and someone(/-thing) deletes all the shared memory objects. If another instance of FTL is then started, it doesn't know a previous process is running and creates new SHM objects for itself. Both processes can - in theory - run just fine without touching each other as they are both actually using *different* shared memory objects. You are right when you think this is bizarre. The reason is that the first one has the shared memory objects still mapped into memory, i.e., "deleting" them from disk only removes the visible file handles. The next FTL instance creates files with the very same name, however, they are also new and distict files, i.e., their memory will point elsewhere. Both instances can now run in parallel just fine *until* one of them needs to resize a shared memory objects. If one of the shared memory events now gets resized to a size larger than it was before BUT smaller than what the other FTL instance is expecting, the other instance will instantaneously crash with a SIGSEGV (Bus error).
This commit resolves this by storing the PID of the SHM object creator in the settings object.
Each FTL instance reloads this shared memory instance now before performing any potentially dangerous operation and checks if the shared memory files on disk are still owned by this process. If this is not the case, we are in serious trouble and exit immediately.
This should allow the second instance (you could call it the "rightful owner" of the current existing SHM objects) a fairly good chance to never even notice this and continue to operate just fine.

Signed-off-by: DL6ER <dl6er@dl6er.de>
2022-11-03 20:45:31 +01:00
DL6ER fc303aeba5
Read FTL config *before* initializing shared memory to ensure we are aware of a possible DEBUG_SHMEM flag when creating the shared memory segments
Signed-off-by: DL6ER <dl6er@dl6er.de>
2022-11-03 20:45:31 +01:00
DL6ER ca9f7c027f
Remove create_new option in init_shmem() as it was always true
Signed-off-by: DL6ER <dl6er@dl6er.de>
2022-11-03 20:45:31 +01:00
DL6ER 615b8b6279
Work around long-standing bug in gcc 12.x reported in #1424
Signed-off-by: DL6ER <dl6er@dl6er.de>
2022-11-03 20:44:53 +01:00
RD WebDesign e24e162da4
Fix comment
Signed-off-by: RD WebDesign <github@rdwebdesign.com.br>
2022-10-11 00:54:01 -03:00
DL6ER bcdf65397d
Fix printed error message when binding fails
Signed-off-by: DL6ER <dl6er@dl6er.de>
2022-10-03 18:24:02 +02:00
DL6ER b2c3d4725c
Fix audit log SQL query
Signed-off-by: DL6ER <dl6er@dl6er.de>
2022-10-01 13:27:00 +02:00
Simon Kelley d74f5e1b0e
Fix a problem in overload handling.
Sending the same query repeatedly to a dnsmasq instance which
doesn't get replies from upstream will eventually hit the
hard limit on frec_src structures and start gettin REFUSED
replies. This is OK, except that since the queries are no longer
being forwarded, an upstream server coming back doesn't reset the
situation. If there is any other traffic, frec allocation will
eventually delete the timed-out frec and get things moving again,
but that's not guaranteed.

To fix this we explicitly delete the frec once timed out in this case.

Thanks to Filip Jenicek for noticing and characterising this problem.

Signed-off-by: DL6ER <dl6er@dl6er.de>
2022-09-26 19:14:58 +02:00