dnsmasq.git
12 months agoTweak packet-reduction code going from TCP->UDP. tcp-trunc holly/tcp-trunc origin/tcp-trunc
Simon Kelley [Sun, 13 Oct 2024 22:09:48 +0000 (23:09 +0100)]
Tweak packet-reduction code going from TCP->UDP.

12 months agoDon't log bogus source address when doing fast retry.
Simon Kelley [Sat, 12 Oct 2024 22:21:58 +0000 (23:21 +0100)]
Don't log bogus source address when doing fast retry.

12 months agoHandle truncated response UDP-to-TCP to downstream queries when validating.
Simon Kelley [Sat, 12 Oct 2024 21:25:06 +0000 (22:25 +0100)]
Handle truncated response UDP-to-TCP to downstream queries when validating.

A relatively common situation is that the reply to a downstream query
will fit in a UDP packet when no DNSSEC RRs are present, but overflows
when the RRSIGS, NSEC ect are added. This extends the automatic
move from UDP to TCP to downstream queries which get truncated replies,
in the hope that once stripped of the DNSSEC RRs, the reply can be returned
via UDP, nwithout making the downstream retry with TCP.

If the downstream sets the DO bit, (ie it wants the DNSSEC RRs, then
this path is not taken, since the downstream will have to get a truncated
repsonse and retry to get a correct answer.

12 months agoUDP-to-TCP bugfix: wrong calls to extract_name and
Simon Kelley [Wed, 2 Oct 2024 20:47:48 +0000 (21:47 +0100)]
UDP-to-TCP bugfix: wrong calls to extract_name and
suppress rapid (UDP) retry once we've switched to TCP.

12 months agoFix DNSSEC work counting when swapping from UDP to TCP
Simon Kelley [Mon, 23 Sep 2024 15:45:12 +0000 (16:45 +0100)]
Fix DNSSEC work counting when swapping from UDP to TCP

12 months agoImprove handling of truncated replies to DNSSEC queries.
Simon Kelley [Sun, 22 Sep 2024 21:32:13 +0000 (22:32 +0100)]
Improve handling of truncated replies to DNSSEC queries.

Heretofore, when a validating the result of an external query triggers
a DNSKEY or DS query and the result of that query is truncated, dnsmasq
has forced the whole validation process to move to TCP by returning a
truncated reply to the original requestor. This forces the original
requestor to retry the query in TCP mode, and the DNSSEC subqueries
also get made via TCP and everything works.

Note that in general the actual answer being validated is not large
enough to trigger truncation, and there's no reason not to return that
answer via UDP if we can validate it successfully. It follows that
a substandard client which can't do TCP queries will still work if the
answer could be returned via UDP, but fails if it gets an artifically
truncated answer and cannot move to TCP.

This patch teaches dnsmasq to move to TCP for DNSSEC queries when
validating UDP answers. That makes the substandard clients mentioned
above work, and saves a round trip even for clients that can do TCP.

12 months agoTidy up parameters to sendmsg() syscall.
Simon Kelley [Mon, 19 Aug 2024 20:38:37 +0000 (21:38 +0100)]
Tidy up parameters to sendmsg() syscall.

The msg_controllen field passed to sendmsg is computed using the
CMSG_SPACE(), which is correct, but CMSG_SPACE() can include
padding bytes at the end of the passed structure if they are required
to align subsequent structures in the buffer. Make sure these
bytes are zeroed to avoid passing uninitiased memory to the kernel,
even though it will never touch these bytes.

Also tidy up the mashalling code in send_from to use pointers to
the structure being filled out, rather than a temporary copy which
then gets memcpy()'d into place. The DHCP sendmsg code has always
worked like this.

Thanks to  Dominik Derigs for running Memcheck as submitting the
initial patch.

12 months agoMerge branch 'master' of ssh://thekelleys.org.uk/var/local/git/dnsmasq
Simon Kelley [Fri, 4 Oct 2024 16:03:55 +0000 (17:03 +0100)]
Merge branch 'master' of ssh://thekelleys.org.uk/var/local/git/dnsmasq

12 months agoFix crash when reloading DHCP config on SIGHUP.
Simon Kelley [Fri, 4 Oct 2024 15:59:14 +0000 (16:59 +0100)]
Fix crash when reloading DHCP config on SIGHUP.

Confusion in the code to free old DHCP configuration when it's
being reloaded causes invalid pointers to be followed and a crash.

https://lists.thekelleys.org.uk/pipermail/dnsmasq-discuss/2024q4/017764.html

has a more complete explanation of the problem.

18 months agoTreat cache insertion failure of DNSKEY and DS records as
Simon Kelley [Wed, 27 Mar 2024 16:00:06 +0000 (16:00 +0000)]
Treat cache insertion failure of DNSKEY and DS records as
another resource problem and fail validation with suitable logging.

19 months agoRemove debian directory and replace with a git submodule.
Simon Kelley [Thu, 22 Feb 2024 22:45:37 +0000 (22:45 +0000)]
Remove debian directory and replace with a git submodule.

20 months agoThe DHCPv4 server doesn't need CAP_NET_ADMIN if always broadcasting.
Simon Kelley [Wed, 21 Feb 2024 00:46:25 +0000 (00:46 +0000)]
The DHCPv4 server doesn't need CAP_NET_ADMIN if always broadcasting.

CAP_NET_ADMIN is needed in the DHCPv4 code to place entries into
the ARP cache. If it's configured to unconditionally broadcast
to unconfigured clients, it never touches the ARP cache and
doesn't need CAP_NET_ADMIN.

Thanks to Martin Ivičič <max.enhanced@gmail.com> for prompting this.

20 months ago[PATCH] Fix error introduced in 51471cafa5a4fa44d6fe490885d9910bd72a5907
renmingshuai [Wed, 21 Feb 2024 00:24:25 +0000 (00:24 +0000)]
[PATCH] Fix error introduced in 51471cafa5a4fa44d6fe490885d9910bd72a5907

Signed-off-by: renmingshuai <renmingshuai@huawei.com>
20 months agoFix breakage in DBus FilterA and FilterAAAA methods.
Simon Kelley [Tue, 20 Feb 2024 23:38:26 +0000 (23:38 +0000)]
Fix breakage in DBus FilterA and FilterAAAA methods.

In generalising the RR filter code, the Dbus methods
controlling filtering A and AAAA records
got severely broken. This, and the previous commit,
fixes things.

20 months agoFix infinite loop when invoking SetFilterA dbus method more than once.
Simon Kelley [Mon, 19 Feb 2024 23:21:58 +0000 (23:21 +0000)]
Fix infinite loop when invoking SetFilterA dbus method more than once.

Also applies to SetFilterAAAA.

Thanks to Clayton Craft for spotting the issue.

20 months agoAdd missing CHANGELOG entries for 2.90
Simon Kelley [Mon, 19 Feb 2024 13:22:09 +0000 (13:22 +0000)]
Add missing CHANGELOG entries for 2.90

20 months agoFix spurious "resource limit exceeded" messages.
Simon Kelley [Mon, 19 Feb 2024 12:22:43 +0000 (12:22 +0000)]
Fix spurious "resource limit exceeded" messages.

Replies from upstream with a REFUSED rcode can result in
log messages stating that a resource limit has been exceeded,
which is not the case.

Thanks to Dominik Derigs and the Pi-hole project for
spotting this.

20 months agoRelax limits imposed by d/t/functions.d/ip-addr.patterns in Debian autotest. v2.90deb2
Simon Kelley [Thu, 15 Feb 2024 09:55:57 +0000 (09:55 +0000)]
Relax limits imposed by d/t/functions.d/ip-addr.patterns in Debian autotest.

20 months agoBump Debian version. v2.90
Simon Kelley [Tue, 13 Feb 2024 13:49:15 +0000 (13:49 +0000)]
Bump Debian version.

20 months agoMerge branch 'dnssec-limit'
Simon Kelley [Tue, 13 Feb 2024 13:27:25 +0000 (13:27 +0000)]
Merge branch 'dnssec-limit'

This merges security fixes for CVE-2023-50387 and CVE-2023-50868

Keytrap - extreme CPU consumption in the DNSSEC validator.

20 months agoReverse suppression of ANY query answer logging.
Simon Kelley [Tue, 13 Feb 2024 13:26:24 +0000 (13:26 +0000)]
Reverse suppression of ANY query answer logging.

20 months agoAdd CHANGELOG entry for DNSSEC security fixes.
Simon Kelley [Mon, 12 Feb 2024 22:07:33 +0000 (22:07 +0000)]
Add CHANGELOG entry for DNSSEC security fixes.

20 months agoAdd --dnssec-limits option.
Simon Kelley [Sun, 7 Jan 2024 22:47:30 +0000 (22:47 +0000)]
Add --dnssec-limits option.

20 months agoBetter allocation code for DS digest cache.
Simon Kelley [Sat, 6 Jan 2024 20:51:13 +0000 (20:51 +0000)]
Better allocation code for DS digest cache.

20 months agoBetter stats and logging from DNSSEC resource limiting.
Simon Kelley [Sat, 6 Jan 2024 16:13:44 +0000 (16:13 +0000)]
Better stats and logging from DNSSEC resource limiting.

20 months agoOverhaul data checking in NSEC code.
Simon Kelley [Fri, 5 Jan 2024 22:56:47 +0000 (22:56 +0000)]
Overhaul data checking in NSEC code.

20 months agoRework validate-by-DS to avoid DoS vuln without arbitrary limits.
Simon Kelley [Thu, 4 Jan 2024 15:57:43 +0000 (15:57 +0000)]
Rework validate-by-DS to avoid DoS vuln without arbitrary limits.

By calculating the hash of a DNSKEY once for each digest algo,
we reduce the hashing work from (no. DS) x (no. DNSKEY) to
(no. DNSKEY) x (no. distinct digests)

The number of distinct digests can never be more than 255 and
it's limited by which hashes we implement, so currently only 4.

20 months agoUpdate EDE code -> text conversion.
Simon Kelley [Thu, 4 Jan 2024 00:45:31 +0000 (00:45 +0000)]
Update EDE code -> text conversion.

20 months agoParameterise work limits for DNSSEC validation.
Simon Kelley [Tue, 2 Jan 2024 21:43:04 +0000 (21:43 +0000)]
Parameterise work limits for DNSSEC validation.

20 months agoFix error introduced in 635bc51cac3d5d7dd49ce9e27149cf7e402b7e79
Simon Kelley [Tue, 2 Jan 2024 12:25:44 +0000 (12:25 +0000)]
Fix error introduced in 635bc51cac3d5d7dd49ce9e27149cf7e402b7e79

20 months agoMeasure cryptographic work done by DNSSEC.
Simon Kelley [Mon, 1 Jan 2024 17:17:25 +0000 (17:17 +0000)]
Measure cryptographic work done by DNSSEC.

20 months agoUpdate NSEC3 iterations handling to conform with RFC 9276.
Simon Kelley [Sun, 31 Dec 2023 23:28:11 +0000 (23:28 +0000)]
Update NSEC3 iterations handling to conform with RFC 9276.

20 months agoUpdate header with new EDE values.
Simon Kelley [Sun, 31 Dec 2023 15:11:54 +0000 (15:11 +0000)]
Update header with new EDE values.

20 months agoProtection against pathalogical DNSSEC domains.
Simon Kelley [Sat, 30 Dec 2023 21:01:05 +0000 (21:01 +0000)]
Protection against pathalogical DNSSEC domains.

An attacker can create DNSSEC signed domains which need a lot of
work to verfify. We limit the number of crypto operations to
avoid DoS attacks by CPU exhaustion.

20 months agoClose debian bug. v2.90test4
Simon Kelley [Mon, 12 Feb 2024 21:33:35 +0000 (21:33 +0000)]
Close debian bug.

20 months agoMake --filter-rr=ANY filter the answer to ANY queries.
Simon Kelley [Mon, 12 Feb 2024 16:14:06 +0000 (16:14 +0000)]
Make --filter-rr=ANY filter the answer to ANY queries.

Thanks to Dominik Derigs for an earlier patch which inspired this.

20 months agoTweak logging and special handling of T_ANY in rr-filter code.
Simon Kelley [Mon, 12 Feb 2024 13:42:07 +0000 (13:42 +0000)]
Tweak logging and special handling of T_ANY in rr-filter code.

20 months agoDon't create a useless inotify file desrcriptor when --port=0
Heikki Linnakangas [Wed, 7 Feb 2024 14:44:49 +0000 (14:44 +0000)]
Don't create a useless inotify file desrcriptor when --port=0

If there are no dynamic configuration directories configured with
dhcp-hostsdir, dhcp-optsdir and hostsdir then we need to use inotify
only to track changes to resolv-files, but we don't need to do
that when DNS is disabled (port=0) or no resolv-files are configured.

It turns out that inotify slots can be a scarce resource, so not
using one when it's not needed is a Goood Thing.

Patch by HL, description above from SRK.

20 months agoRefactor the accumulated crud of years in process_reply().
Simon Kelley [Sat, 3 Feb 2024 22:44:54 +0000 (22:44 +0000)]
Refactor the accumulated crud of years in process_reply().

20 months agoHandle caching SOA for negative PTR queries.
Simon Kelley [Fri, 2 Feb 2024 23:07:57 +0000 (23:07 +0000)]
Handle caching SOA for negative PTR queries.

Also deal with the fact that a root SOA is a thing.

20 months agoFix logic error in signed RR handling.
Simon Kelley [Fri, 2 Feb 2024 21:36:56 +0000 (21:36 +0000)]
Fix logic error in signed RR handling.

In extract_addresses() the "secure" argument is only set if the
whole reply is validated (ie the AD bit can be set). Even without
that, some records may be validated, and should be marked
as such in the cache.

Related, the DNS doctor code has to update the flags for individual
RRs as it works, not the global "secure" flag.

20 months agoFix compiler warning.
Simon Kelley [Fri, 2 Feb 2024 00:26:44 +0000 (00:26 +0000)]
Fix compiler warning.

20 months agoCache SOAs and return them with cached NXDOMAIN/NODATA replies.
Simon Kelley [Thu, 1 Feb 2024 23:37:11 +0000 (23:37 +0000)]
Cache SOAs and return them with cached NXDOMAIN/NODATA replies.

Now we can cache arbirary RRs, give more correct answers when
replying negative answers from cache.

To implement this needed the DNS-doctor code to be untangled from
find_soa(), so it should be under suspicion for any regresssions
in that department.

20 months agoHardcode Lua library version in debian/rules, rather than the Makefile. v2.90test3
Simon Kelley [Fri, 26 Jan 2024 22:58:58 +0000 (22:58 +0000)]
Hardcode Lua library version in debian/rules, rather than the Makefile.

20 months agoLet pkg-config select the newest installed Lua version, don't hardcode it.
Simon Kelley [Fri, 26 Jan 2024 22:44:06 +0000 (22:44 +0000)]
Let pkg-config select the newest installed Lua version, don't hardcode it.

The version can be overridden with the LUA envvar

Make LUA=lua5.4

Thanks to Petr Menšík for the patch which inspired this one.

20 months agoDebian changelog tweaking: LUA -> Lua and use upstream test version
Simon Kelley [Fri, 26 Jan 2024 22:23:12 +0000 (22:23 +0000)]
Debian changelog tweaking: LUA -> Lua and use upstream test version
for experimental release.

20 months agodebian/changelog cosmetic tweak. v2.90test2
Simon Kelley [Tue, 23 Jan 2024 23:30:57 +0000 (23:30 +0000)]
debian/changelog cosmetic tweak.

20 months agoAdjust .gitignore to reflect new Debian packaging.
Simon Kelley [Tue, 23 Jan 2024 23:19:01 +0000 (23:19 +0000)]
Adjust .gitignore to reflect new Debian packaging.

20 months agoUse debhelper to simplify tmpfiles installation in debian package.
Gioele Barabucci [Tue, 23 Jan 2024 23:09:11 +0000 (23:09 +0000)]
Use debhelper to simplify tmpfiles installation in debian package.

20 months ago2023->2024 in debian/copyright
Simon Kelley [Tue, 23 Jan 2024 23:04:29 +0000 (23:04 +0000)]
2023->2024 in debian/copyright

20 months agoTie up loose ends in debian/changelog for upload to experimental.
Simon Kelley [Tue, 23 Jan 2024 23:02:49 +0000 (23:02 +0000)]
Tie up loose ends in debian/changelog for upload to experimental.

21 months agoMan page typo fix.
Justin [Sun, 21 Jan 2024 22:24:43 +0000 (22:24 +0000)]
Man page typo fix.

21 months agoRemove Debian patch to bump Lua version. It's upstream now. v2.90test1
Simon Kelley [Sun, 21 Jan 2024 12:51:14 +0000 (12:51 +0000)]
Remove Debian patch to bump Lua version. It's upstream now.

21 months agoBump version in Debian changelog to 2.90
Simon Kelley [Fri, 19 Jan 2024 22:27:41 +0000 (22:27 +0000)]
Bump version in Debian changelog to 2.90

21 months agoBump copright year in debian/copyright and add a copyright holder.
Simon Kelley [Fri, 19 Jan 2024 14:47:03 +0000 (14:47 +0000)]
Bump copright year in debian/copyright and add a copyright holder.

21 months agoBump LUA library to 5.4
Simon Kelley [Fri, 19 Jan 2024 14:11:47 +0000 (14:11 +0000)]
Bump LUA library to 5.4

21 months agoLargely replace the Debian packaging with a new and much more up-to-date
Sven Geuer [Thu, 18 Jan 2024 16:28:49 +0000 (16:28 +0000)]
Largely replace the Debian packaging with a new and much more up-to-date
Debhelper based version.

21 months agoFix FTBFS introduced in 2748d4e901193c919614276e42d6d54b11f3232d
Simon Kelley [Fri, 19 Jan 2024 14:32:02 +0000 (14:32 +0000)]
Fix FTBFS introduced in 2748d4e901193c919614276e42d6d54b11f3232d

21 months agoBump copyright to 2024.
Simon Kelley [Sat, 13 Jan 2024 22:20:04 +0000 (22:20 +0000)]
Bump copyright to 2024.

21 months agoIntroduce new --local-service=host parameter
Petr Menšík [Tue, 5 Oct 2021 11:46:51 +0000 (13:46 +0200)]
Introduce new --local-service=host parameter

Similar to local-service, but more strict. Listen only on localhost
unless other interface is specified. Has no effect when interface is
provided explicitly. I had multiple bugs fillen on Fedora, because I have
changed default configuration to:

interface=lo
bind-interfaces

People just adding configuration parts to /etc/dnsmasq.d or appending to
existing configuration often fail to see some defaults are already there.
Give them auto-ignored configuration as smart default.

Signed-off-by: Petr Menšík <pemensik@redhat.com>
Do not add a new parameter on command line. Instead add just parameter
for behaviour modification of existing local-service option. Now it
accepts two optional values:
- net: exactly the same as before
- host: bind only to lo interface, do not listen on any other addresses
  than loopback.

22 months agoFix --synth-domain NXDOMAIN responses.
Simon Kelley [Sun, 3 Dec 2023 17:48:56 +0000 (17:48 +0000)]
Fix --synth-domain NXDOMAIN responses.

By design, dnsmasq forwards queries for RR-types it has no data
on, even if it has data for the same domain and other RR-types.

This can lead to an inconsitent view of the DNS when an upstream
server returns NXDOMAIN for an RR-type and domain but the same domain
but a different RR-type gets an answer from dnsmasq. To avoid this,
dnsmasq converts NXDOMAIN answer from upstream to NODATA answers if
it would answer a query for the domain and a different RR-type.

An oversight missed out --synth-domain from the code to do this, so
--synth-domain=thekelleys.org.uk,192.168.0.0/24
would result in the correct answer to an A query for
192-168.0.1.thekelleys.org.uk and an AAAA query for the same domain
would be forwarded upstream and the resulting NXDOMAIN reply
returned.

After the fix, the reply gets converted to NODATA.

Thanks to Matt Wong for spotting the bug.

22 months agoFix problem with domains associated with DHCP hosts at startup.
Simon Kelley [Sun, 3 Dec 2023 16:09:08 +0000 (16:09 +0000)]
Fix problem with domains associated with DHCP hosts at startup.

At startup, the leases file is read by lease_init(), and
in lease_init() undecorated hostnames are expanded into
FQDNs by adding the domain associated with the address
of the lease.

lease_init() happens relavtively early in the startup, party because
if it calls  the dhcp-lease helper script, we don't want that to inherit
a load of sensitive file descriptors. This has implications if domains
are defined using the --domain=example.com,eth0 format since it's long
before we call enumerate_interfaces(), so get_domain fails for such domains.

The patch just moves the hostname expansion function to a seperate
subroutine that gets called later, after enumerate_interfaces().

22 months agoFix typo in dnsmasq.conf.example
Simon Kelley [Thu, 30 Nov 2023 12:46:47 +0000 (12:46 +0000)]
Fix typo in dnsmasq.conf.example

Thanks to Brenton Bostick for the report.

22 months agoAdd information on process-forking for TCP connections to metrics.
Damian Sawicki [Thu, 30 Nov 2023 15:55:51 +0000 (15:55 +0000)]
Add information on process-forking for TCP connections to metrics.

Add the relevant information to the metrics and to the output of
dump_cache() (which is called when dnsmasq receives SIGUSR1).
Hence, users not collecting metrics will still be able to
troubleshoot with SIGUSR1. In addition to the current usage,
dump_cache() contains the information on the highest usage
since it was last called.

22 months agoTighten up error checking in --bind-dynamic mode.
Simon Kelley [Mon, 27 Nov 2023 23:08:31 +0000 (23:08 +0000)]
Tighten up error checking in --bind-dynamic mode.

In bind-dynamic mode, its OK to fail to bind a socket to an address
given by --listen-address if no interface with that address exists
for the time being. Dnsmasq will attempt to create the socket again
when the host's network configuration changes.

The code used to ignore pretty much any error from bind(), which is
incorrect and can lead to confusing behaviour. This change make ONLY
a return of EADDRNOTAVAIL from bind() a non-error: anything else will be
fatal during startup phase, or logged after startup phase.

Thanks to Petr Menšík for the problem report and first-pass patch.

22 months agoFix standalone SHA256 implementation.
Simon Kelley [Wed, 22 Nov 2023 22:02:05 +0000 (22:02 +0000)]
Fix standalone SHA256 implementation.

Bug report here:
https://lists.thekelleys.org.uk/pipermail/dnsmasq-discuss/2023q4/017332.html

This error probably has no practical effect since even if the hash
is wrong, it's only compared internally to other hashes computed using
the same code.

Understanding the error:

hash-questions.c:168:21: runtime error: left shift of 128 by 24 places
cannot be represented in type 'int'

requires a certain amount of c-lawyerliness. I think the problem is that

m[i] = data[j] << 24

promotes the unsigned char data array value to int before doing the shift and
then promotes the result to unsigned char to match the type of m[i].
What needs to happen is to cast the unsigned char to unsigned int
BEFORE the shift.

This patch does that with explicit casts.

22 months agoMerge branch 'master' of ssh://thekelleys.org.uk/var/local/git/dnsmasq
Simon Kelley [Wed, 22 Nov 2023 15:29:10 +0000 (15:29 +0000)]
Merge branch 'master' of ssh://thekelleys.org.uk/var/local/git/dnsmasq

22 months agoFix misuse of const pointer in src/nftset.c.
Simon Kelley [Wed, 22 Nov 2023 15:20:53 +0000 (15:20 +0000)]
Fix misuse of const pointer in src/nftset.c.

Thanks to  Kevin Darbyshire-Bryant for the initial patch, which was
modified by srk - any remaining bugs are his.

23 months agoFix use-after-free in cache_remove_uid().
Simon Kelley [Mon, 13 Nov 2023 22:08:08 +0000 (22:08 +0000)]
Fix use-after-free in cache_remove_uid().

Thanks to Kevin Darbyshire-Bryant for the bug report.

23 months agoFix crash when DNS disabled, introduced in 416390f9962e455769aa8ab6df0e105cae07ae55
Simon Kelley [Fri, 10 Nov 2023 23:13:46 +0000 (23:13 +0000)]
Fix crash when DNS disabled, introduced in 416390f9962e455769aa8ab6df0e105cae07ae55

23 months agoAdd --max-tcp-connections option to make this dynamically configurable.
Damian Sawicki [Sat, 4 Nov 2023 23:33:28 +0000 (23:33 +0000)]
Add --max-tcp-connections option to make this dynamically configurable.

23 months agoFix compile warning introduced by a889c554a7df71ff93a8299ef96037fbe05f2f55
Simon Kelley [Sat, 4 Nov 2023 16:58:30 +0000 (16:58 +0000)]
Fix compile warning introduced by a889c554a7df71ff93a8299ef96037fbe05f2f55

23 months agoAdd RESINFO RR-type to the table of RR-type names.
Dominik Derigs [Sat, 4 Nov 2023 16:52:09 +0000 (16:52 +0000)]
Add RESINFO RR-type to the table of RR-type names.

2 years agoFix bad reply to DHCPCONFIRM messages (wrong message type).
Simon Kelley [Wed, 11 Oct 2023 21:33:17 +0000 (22:33 +0100)]
Fix bad reply to DHCPCONFIRM messages (wrong message type).

Thanks to renmingshuai <renmingshuai@huawei.com> for
spotting the error, and making the initial patch.

2 years agoWork around possible Linux bug with VRF interfaces and DHCPv6. holly/vrf
Simon Kelley [Mon, 9 Oct 2023 20:50:15 +0000 (21:50 +0100)]
Work around possible Linux bug with VRF interfaces and DHCPv6.

The scope_id in the source address of recieved packets gets set
to the index of the VRF interface, not the slave. Fortunately,
the interface index returned by packetinfo is correct so we use
instead.

Thanks to Luci Stanescu <luci@safebits.tech> for characterising this.

Ref: https://lists.thekelleys.org.uk/pipermail/dnsmasq-discuss/2023q4/017276.html

2 years agoCache zero-TTL DNS replies when stale-caching is enabled.
Simon Kelley [Mon, 9 Oct 2023 20:15:13 +0000 (21:15 +0100)]
Cache zero-TTL DNS replies when stale-caching is enabled.

2 years agoFix memory leak in arbitrary-RR caching.
Simon Kelley [Mon, 9 Oct 2023 20:00:11 +0000 (21:00 +0100)]
Fix memory leak in arbitrary-RR caching.

If the cache insertion process fails for any reason, any
blockdata storage allocated needs to be freed.

Thanks to Damian Sawicki for spotting the problem and
supplying patches against earlier releases. This patch by SRK,
and any bugs are his.

2 years agoFix memory leak when using --dhcp-optsfile with DHCPv6 options.
renmingshuai [Sat, 30 Sep 2023 22:31:08 +0000 (23:31 +0100)]
Fix memory leak when using --dhcp-optsfile with DHCPv6 options.

2 years agoRemove two-decade old hack.
Simon Kelley [Mon, 11 Sep 2023 21:11:50 +0000 (22:11 +0100)]
Remove two-decade old hack.

answer_request() builds answers in the same packet buffer
as the request.  This means that any EDNS0 header from the
original request is overwritten. If the answer is in cache, that's
fine: dnsmasq adds its own EDNS0 header, but if the cache lookup fails
partially and the request needs to be sent upstream, it's a problem.

This was fixed a long, long time ago by running the cache
lookup twice if the request included an EDNS0 header. The first time,
nothing would be written to the answer packet, nad if the cache
lookup failed, the untouched question packet was still available
to forward upstream. If cache lookup succeeded, the whole thing
was done again, this time writing the data into the reply packet.
In a world where EDNS0 was rare and so was memory, this was a
reasonable solution. Today EDNS0 is ubiquitous so basically
every query is being looked up twice in the cache. There's also
the problem that any code change which makes successive cache lookups
for a query possibly return different answers adds a subtle hidden
bug, because this hack depends on absence of that behaviour.

This commit removes the lookup-twice hack entirely. answer_request()
can now return zero and overwrite the question packet. The code which
was previously added to support stale caching by saving a copy of the
query in the block-storage system is extended to always be active.
This handles the case where answer_request() returns no answer OR
a stale answer and a copy of the original query is needed to forward
upstream.

2 years agoFix problem with arbitrary RR caching.
Simon Kelley [Sat, 2 Sep 2023 20:34:54 +0000 (21:34 +0100)]
Fix problem with arbitrary RR caching.

Caching an answer which has more that one RR, with at least
one answer being <=13 bytes and at least one being >13 bytes
can screw up the F_KEYTAG flag bit, resulting in the wrong
type of the address union being used and either a bad value
return or a crash in the block code.

Thanks to Dominik Derigs and the Pi-hole project for finding
and characterising this.

2 years ago=/== typo in last commit.
Simon Kelley [Fri, 26 May 2023 17:19:15 +0000 (18:19 +0100)]
=/== typo in last commit.

2 years agoMerge branch 'master' of ssh://thekelleys.org.uk/var/local/git/dnsmasq
Simon Kelley [Fri, 26 May 2023 17:01:58 +0000 (18:01 +0100)]
Merge branch 'master' of ssh://thekelleys.org.uk/var/local/git/dnsmasq

2 years agoBehave better when attempting to contact unresponsive TCP servers.
Simon Kelley [Fri, 26 May 2023 16:55:35 +0000 (17:55 +0100)]
Behave better when attempting to contact unresponsive TCP servers.

By default TCP connect takes minutes to fail when trying to
connect a server which is not responding and for which the
network layer doesn't generate HOSTUNREACH errors.

This is doubled because having failed to connect in FASTOPEN
mode, the code then tries again with a call to connect().

We set TCP_SYNCNT to 2, which make the timeout about 10 seconds.
This in an unportable Linux feature, so it doesn't work on other
platforms.

No longer try connect() if sendmsg in fastopen mode fails with
ETIMEDOUT or EHOSTUNREACH since the story will just be the same.

2 years agoLog truncated DNS replies.
Simon Kelley [Wed, 17 May 2023 22:19:30 +0000 (23:19 +0100)]
Log truncated DNS replies.

2 years agoHandle SERVFAIL responses to DS queries better.
Simon Kelley [Mon, 15 May 2023 17:11:06 +0000 (18:11 +0100)]
Handle SERVFAIL responses to DS queries better.

On 15/5/2023 8.8.8.8 was returning SERVFAIL for a query on ec.europa.eu

ec.europa.eu is not a domain cut, that happens at jrc.ec.europa.eu. which
does return a signed proof of non-existance for a DS record.
Abandoning the search for a DS or proof of non existence at ec.europa.eu
renders everything within that domain BOGUS, since nothing is signed.

This code changes behaviour on a SERVFAIL to continue looking
deeper for a DS or proof of its nonexistence.

2 years agoCode tidying.
Simon Kelley [Mon, 1 May 2023 22:06:29 +0000 (23:06 +0100)]
Code tidying.

2 years agoFix issue with stale caching.
Simon Kelley [Mon, 1 May 2023 19:42:30 +0000 (20:42 +0100)]
Fix issue with stale caching.

After replying with stale data, dnsmasq sends the query upstream to
refresh the cache asynchronously and sometimes sends the wrong packet:
packet length can be wrong, and if an EDE marking stale data is added
to the answer that can end up in the query also. This bug only seems
to cause problems when the usptream server is a DOH/DOT proxy. Thanks
to Justin He for the bug report.

2 years agoImprove RFC3315 para 15 packet validation.
Simon Kelley [Mon, 24 Apr 2023 14:07:55 +0000 (15:07 +0100)]
Improve RFC3315 para 15 packet validation.

Thanks to Shashikumar Shashil for spotting the ommision.

2 years agoLog failure to determine MAC address in DHCPv6.
Simon Kelley [Mon, 17 Apr 2023 20:25:30 +0000 (21:25 +0100)]
Log failure to determine MAC address in DHCPv6.

2 years agoOptimization of socket events handling of dbus.
Petr Menšík [Mon, 17 Apr 2023 20:05:00 +0000 (21:05 +0100)]
Optimization of socket events handling of dbus.

Reduces calls to locate the file descriptor structure. Should lower CPU usage when monitoring
dbus watches.

2 years agoFix crash in dbus code.
Petr Menšík [Mon, 17 Apr 2023 19:55:31 +0000 (20:55 +0100)]
Fix crash in dbus code.

If I configure dnsmasq to use dbus and then restart dbus.service with watchers present,
it crashes dnsmasq. The reason is simple, it uses loop to walk over watchers to call
dbus handling code. But from that code the same list can be modified and watchers removed.
But the list iteration continues anyway.

Restart the loop if list were modified.

2 years agoFix paren blunder in aaba66efbd3b4e7283993ca3718df47706a8549b
Simon Kelley [Mon, 17 Apr 2023 15:23:06 +0000 (16:23 +0100)]
Fix paren blunder in aaba66efbd3b4e7283993ca3718df47706a8549b

Thanks to Dominik Derigs for spotting this.

2 years agoAdd --no-dhcpv4-interface and --no-dhcpv6-interface options.
Simon Kelley [Wed, 12 Apr 2023 21:55:14 +0000 (22:55 +0100)]
Add --no-dhcpv4-interface and --no-dhcpv6-interface options.

2 years agoTurn "used" member of struct iname into flags in preparation for more.
Simon Kelley [Wed, 12 Apr 2023 15:25:49 +0000 (16:25 +0100)]
Turn "used" member of struct iname into flags in preparation for more.

2 years agoMissed copyright date.
Simon Kelley [Wed, 5 Apr 2023 16:42:23 +0000 (17:42 +0100)]
Missed copyright date.

2 years agoMake --server=/#/<addr> behave the same as --server=<addr>
Simon Kelley [Wed, 5 Apr 2023 16:29:04 +0000 (17:29 +0100)]
Make --server=/#/<addr> behave the same as --server=<addr>

For consistency with --address and older dnsmasq releases.

2 years agoBump copyrights to 2023.
Simon Kelley [Wed, 5 Apr 2023 11:34:34 +0000 (12:34 +0100)]
Bump copyrights to 2023.

2 years agoFix long-term bug in TCP caching code which would lose NXDOMAIN.
Simon Kelley [Sat, 1 Apr 2023 21:03:49 +0000 (22:03 +0100)]
Fix long-term bug in TCP caching code which would lose NXDOMAIN.

A NXDOMAIN answer recieved over TCP by a child process would
be correctly sent back to the master process which would then
fail to insert it into the cache.

2 years agoUse a simpler arrangement for the all_addr union to avoid
Simon Kelley [Sat, 1 Apr 2023 20:35:26 +0000 (21:35 +0100)]
Use a simpler arrangement for the all_addr union to avoid
the compiler padding it with an extra 8 bytes.

Use the F_KEYTAG flag in a a cache record to discriminate between
an arbitrary RR stored entirely in the addr union and one
which has a point to block storage.

2 years agoFix copy-n-paste error in 138e1e2a2d918b37cb0274fe310d53be35acf4cf
Simon Kelley [Fri, 31 Mar 2023 23:50:29 +0000 (00:50 +0100)]
Fix copy-n-paste error in 138e1e2a2d918b37cb0274fe310d53be35acf4cf