dnsmasq.git
4 months agoFix stupid thinko in immediately preceeding commit. domain-match-debug
Simon Kelley [Fri, 6 Jun 2025 13:59:49 +0000 (14:59 +0100)]
Fix stupid thinko in immediately preceeding commit.

4 months agoDebug printfs
Simon Kelley [Fri, 6 Jun 2025 08:43:48 +0000 (09:43 +0100)]
Debug printfs

4 months agoFix 5846f749e5d878b6b5f7c20f6975bc96b95e4aae origin/HEAD origin/master v2.92test12
Simon Kelley [Tue, 3 Jun 2025 21:16:50 +0000 (22:16 +0100)]
Fix 5846f749e5d878b6b5f7c20f6975bc96b95e4aae

Not sure how that bug got in there. Very (un)lucky choice
of test data, or last-minute "it'll be fine" modification I guess.

It was late, I can't remember.

Thanks to Dominik Derrigs for spotting the problem.

4 months agoFix crash in filter_servers(). v2.92test11
Simon Kelley [Mon, 2 Jun 2025 21:37:08 +0000 (22:37 +0100)]
Fix crash in filter_servers().

The bug occurs when we ask lookup_domain() for a server for a domain
which is not a general upstream server, by setting F_DOMAINSRV in the flags.

If there are no possible servers, because there are no upstream servers
defined (for instance, at startup) then the code steps off the end of an
array and SEGVs.

The bug has been latent for some time, but
3e659bd4ec6525ebe4518fd10b8e183997f46351 added a new call to lookup_domain()
which can actually trigger the bug if DNSSEC is enabled and a certain
amount of bad luck ensues.

Thanks to the testers extraordinaire at PiHole for reporting this.

4 months agoRewrite chunks of inotify.c to remove a memory leak. nxdomain-address
Simon Kelley [Thu, 29 May 2025 21:44:15 +0000 (22:44 +0100)]
Rewrite chunks of inotify.c to remove a memory leak.

The code is much easier to follow now, this shouldn't
happen again.

4 months agoUnbreak compilation on non-Linux systems (FreeBSD)
Matthias Andree [Sat, 24 May 2025 19:33:16 +0000 (21:33 +0200)]
Unbreak compilation on non-Linux systems (FreeBSD)

and put the void cast of netlink_warn under the same preprocessor
condition as its definition, #ifdef HAVE_LINUX_NETWORK.

4 months agoTftp code tweaks.
Simon Kelley [Sat, 24 May 2025 20:11:11 +0000 (21:11 +0100)]
Tftp code tweaks.

4 months agoRemove compiler warnings for obscure combinations of build options. rfc7440 origin/rfc7440 v2.92test10
Simon Kelley [Sat, 24 May 2025 14:09:53 +0000 (15:09 +0100)]
Remove compiler warnings for obscure combinations of build options.

4 months agoAdd TFTP options windowsize (RFC 7440) and timeout (RFC 2349).
Simon Kelley [Sat, 24 May 2025 08:09:39 +0000 (09:09 +0100)]
Add TFTP options windowsize (RFC 7440) and timeout (RFC 2349).

5 months agoOnly define variable "a" if we HAVE_LINUX_NETWORK
Matthias Andree [Wed, 21 May 2025 18:41:33 +0000 (20:41 +0200)]
Only define variable "a" if we HAVE_LINUX_NETWORK

Variable unsigned char a is defined unconditionally,
but it is only used if HAVE_LINUX_NETWORK is defined.
This triggers compiler warnings on, say, FreeBSD.

Fix by wrapping the definition in proper #ifdef.

5 months agoFix GCC's -Wunterminated-string-initialization warning in edns0.c.
Matthias Andree [Tue, 20 May 2025 19:07:27 +0000 (21:07 +0200)]
Fix GCC's -Wunterminated-string-initialization warning in edns0.c.

GCC complains that writing the five-character "ODNS\0" string into
a four-element char magic[4] array truncates the NUL character.
The warning's rationale is that this is incompatible with C++, or
maybe non-intentional.

GCC 8 has added a nonstring variable attribute, clang 20.1 does
not yet support this, but clang's Git head does.

Add an ATTRIBUTE_NONSTRING macro, currently only defined on GCC >= 8
as __attribute__ ((nonstring)).  This successfully suppresses
the warning on Fedora Linux 42's default compiler.

The alternative would be to replace the "ODNS" literal by {0} and
instead memcpy(opt.magic, "ODNS", sizeof(opt.magic)); on the next line,
which is correct, C++ compatible, but also less concise.

5 months agoAdd RRtypes HHIT and BRID to the table.
Simon Kelley [Wed, 21 May 2025 14:03:51 +0000 (15:03 +0100)]
Add RRtypes HHIT and BRID to the table.

5 months agoFix compiler warnings. v2.92test9
Simon Kelley [Sun, 18 May 2025 17:22:48 +0000 (18:22 +0100)]
Fix compiler warnings.

5 months agoOverhaul extract_addresses() function.
Simon Kelley [Sun, 18 May 2025 16:24:41 +0000 (17:24 +0100)]
Overhaul extract_addresses() function.

The proximate cause for doing this is to fix a bug that
causes replies to PTR queries with more than one answer to have the
second and subsequent answers ignored.

The fix turned into a small re-write which removed a very old hack.
When caching reponses which include CNAME records, the cache system
stores the CNAME with a link to the record representing the target of
the CNAME. This isn't possible for PTR records representing IP
addresses since the name stored is the target of the PTR, record and
its name is inferred from the address in the cache record. Such
cache records have the F_REVERSE flag set. To get
around this, long ago, the code which stores such records elided the
CNAME entirely, so
4.3.2.1.in-addr.arpa   CNAME 18/3.2.1.in-addr.arpa
18/3.2.1.in-addr.arpa   PTR   myhost.example.com

would be stored as
4.3.2.1.in-addr.arpa PTR   myhost.example.com

and returned from the cache to subsequent requestor in that form.

Since that hack was committed, dnsmasq has learned to cache arbitrary
RRs. So now we can store the PTR records for all the no-trivial cases.

The means the CNAME chains ending in PTR records don't get mangled,
and we can store PTR records whose name in not w.x.y.x.in-addr.arpa
or the IPv6 equivalent.

5 months agoCHANGELOG update. v2.92test8
Simon Kelley [Wed, 14 May 2025 21:38:14 +0000 (22:38 +0100)]
CHANGELOG update.

5 months ago--leasequery can now take a subnet argument.
Simon Kelley [Wed, 30 Apr 2025 10:44:47 +0000 (11:44 +0100)]
--leasequery can now take a subnet argument.

5 months agoAdd address filtering for leasequery.
Simon Kelley [Wed, 23 Apr 2025 15:47:50 +0000 (16:47 +0100)]
Add address filtering for leasequery.

5 months agoLog source address of leasequeries.
Simon Kelley [Wed, 23 Apr 2025 11:53:51 +0000 (12:53 +0100)]
Log source address of leasequeries.

5 months agoOmit message type from leasequery.c option dump.
Simon Kelley [Fri, 4 Apr 2025 21:42:44 +0000 (22:42 +0100)]
Omit message type from leasequery.c option dump.

5 months agoImplement RFC-4388 DHCPv4 leasequery.
Simon Kelley [Thu, 20 Mar 2025 15:59:55 +0000 (15:59 +0000)]
Implement RFC-4388 DHCPv4 leasequery.

5 months agoCHANGELOG update.
Simon Kelley [Wed, 14 May 2025 21:33:44 +0000 (22:33 +0100)]
CHANGELOG update.

5 months agoBetter error message when rejecting a TFTP transfer.
Simon Kelley [Wed, 14 May 2025 20:15:17 +0000 (21:15 +0100)]
Better error message when rejecting a TFTP transfer.

5 months agoTidy-up of TCP-child pipe handling code. v2.92test7
Simon Kelley [Sun, 11 May 2025 14:30:30 +0000 (15:30 +0100)]
Tidy-up of TCP-child pipe handling code.

Functionality is unchanged, but the code is easier to read and understand.

Also fix memory leak of blocks when cache insert fails.

5 months agoDNSSEC validation change for reverse lookups in RFC-1918 ranges and friends.
Simon Kelley [Fri, 9 May 2025 20:46:50 +0000 (21:46 +0100)]
DNSSEC validation change for reverse lookups in RFC-1918 ranges and friends.

The large public DNS services seem not to return proof-of-nonexistence
for DS records at the start of RFC-1918 in-addr.arpa domains and the their
IPv6 equivalents. 10.in-addr.arpa, 168.192.in-addr.arpa etc.

Since dnsmasq already has an option which instructs it not bother
upstream servers with pointless queries about these address ranges,
namely --bogus-priv, we extend that to enable behaviour which allows
dnsmasq to assume that insecure NXDOMAIN replies for these domains
are expected and to assume that the domains are legitimately unsigned.

This behaviour only matters when some address range is directed to
another upstream server using --rev-server. In that case it allows
replies from that server to pass DNSSEC validation. Without such a
server configured, queries are never sent upstream so they are never
validated and the new behaviour is moot.

5 months agoFix problems with ipset or nftset and TCP DNS transport. v2.92test6
Simon Kelley [Wed, 7 May 2025 22:38:15 +0000 (23:38 +0100)]
Fix problems with ipset or nftset and TCP DNS transport.

If DNS is happening over TCP, the query is handled by a forked
process. Of ipset ot nftset is configured, this might include
inserting addresses in the *sets. Before this update, that
was done by the forked process using handles inherited from the
parent "master" process.

This is inherently racy. If the master process or another
child process tries to do updates at the same time, the
updates can clash and fail.

To see this, you need a busy server doing lots of DNS
queries over TCP, and ipset or nftset configured.

Going forward, we use the already established pipe to send the
updates from the child back to the master process, which
serialises them.

5 months agoFix some edge cases wth domains and --address and --server. v2.92test5
Simon Kelley [Tue, 29 Apr 2025 15:33:22 +0000 (16:33 +0100)]
Fix some edge cases wth domains and --address and --server.

Consider what happens when the same domain appears in
--address and --server.

This commit fixes the order, I think correctly like this:
highest to lowest priority.

--address with a IPv4 or IPv6 address (as long as the query matches the type)
--address with # for all-zeros, as long as the query is A or AAAA)
--address with no address, which returns NXDOMAIN or NOERROR for all types.
--server with address set to # to use the unqualified servers.
--server with matching domain.
--server without domain or from /etc/resolv.conf.

Note that the above is only valid when same domain appears.
The domain being matched is determined first, and has a higher
priority, so you can send google.com to a server and force com
to return NXDOMAIN and for google.com the server config will
override the address config, because there's a longer match.

5 months agoFix logging booboo.
Simon Kelley [Sun, 27 Apr 2025 22:25:30 +0000 (23:25 +0100)]
Fix logging booboo.

5 months agoTidy up pipe-to-parent code in DNS TCP path. v2.92test4
Simon Kelley [Wed, 23 Apr 2025 11:14:00 +0000 (12:14 +0100)]
Tidy up pipe-to-parent code in DNS TCP path.

6 months agoTidy up replies to non-QUERY DNS opcodes in auth mode.
Simon Kelley [Tue, 22 Apr 2025 17:07:24 +0000 (18:07 +0100)]
Tidy up replies to non-QUERY DNS opcodes in auth mode.

6 months agoLog format error from upstream as 'FORMERR'
Rob Gill [Sun, 20 Apr 2025 21:38:43 +0000 (22:38 +0100)]
Log format error from upstream as 'FORMERR'

Signed-off-by: Rob Gill <rrobgill@protonmail.com>
At the moment if a misformatted query is reported by the upstream server
it is not clear from the log.
Other error codes from RFC1035 (server failure, not implemented,
refused) are logged with text, but format error is logged merely as "1".

Such that an upstream reporting a format error is presently logged as eg:
Apr 20 12:01:55 dnsmasq[3023]: reply error is 1

After this patch they are logged informatively, eg:
Apr 20 12:48:40 dnsmasq[3023]: reply error is FORMERR

This is a two line fix, FORMERR is already defined in dns-protocol.h.

6 months agoAdd --log-queries=auth option.
Simon Kelley [Sun, 20 Apr 2025 21:20:52 +0000 (22:20 +0100)]
Add --log-queries=auth option.

6 months agoFix copy 'n paste error in DBUS server-statistics code.
Simon Kelley [Fri, 18 Apr 2025 22:50:46 +0000 (23:50 +0100)]
Fix copy 'n paste error in DBUS server-statistics code.

6 months agoDo a better job of 942a35f5177746d2080e7aa118dd1493a500e2d5 v2.92test3
Simon Kelley [Fri, 18 Apr 2025 13:01:14 +0000 (14:01 +0100)]
Do a better job of 942a35f5177746d2080e7aa118dd1493a500e2d5

6 months agoRevise negative DNS caching to better comply with RFC2308.
Simon Kelley [Wed, 16 Apr 2025 20:29:42 +0000 (21:29 +0100)]
Revise negative DNS caching to better comply with RFC2308.

6 months agoSilence compiler warnings.
Opty [Wed, 16 Apr 2025 15:00:47 +0000 (16:00 +0100)]
Silence compiler warnings.

6 months agoFix occasional crashes with DNSSEC and large nunbers of --address configs. v2.92test2
Simon Kelley [Fri, 4 Apr 2025 21:01:51 +0000 (22:01 +0100)]
Fix occasional crashes with DNSSEC and large nunbers of --address configs.

Commit 3e659bd4ec6525ebe4518fd10b8e183997f46351 removed the concept of
an usptream DNS server which is capable of DNSSEC: they are all
(at least in theory) now usable. As a very unfortunate side-effect,
this removed the filter that ensured that dnssec_server() ONLY
returns servers, and not domains with literal addresses.

If we try and do DNSSEC queries for a domain, and there's
a --address line which matches the domain, then dnssec_server()
will return that. This would break DNSSEC validation, but that's
turns out not to matter, because under these circumstances
dnssec_server() will probably return an out-of-bounds index into
the servers[] array, and the process dies with SIGSEGV.

Many thanks to the hard workers at the Tomato project who
found this bug and provided enough information to diagnose it.

6 months agoMultiple typo and spelling fixes.
Paul Donald [Sat, 29 Mar 2025 21:41:40 +0000 (21:41 +0000)]
Multiple typo and spelling fixes.

7 months agoDNAME documentation update. v2.92test1
Simon Kelley [Sat, 15 Mar 2025 17:02:02 +0000 (17:02 +0000)]
DNAME documentation update.

7 months agoImplement RFC6672 para 5.3.2. check for DNAME.
Simon Kelley [Sat, 15 Mar 2025 16:47:55 +0000 (16:47 +0000)]
Implement RFC6672 para 5.3.2. check for DNAME.

Also fix overflow checking of NSEC type maps.

7 months agoFix DNSSEC and DNAME.
Simon Kelley [Sat, 15 Mar 2025 09:05:47 +0000 (09:05 +0000)]
Fix DNSSEC and DNAME.

Do the correct things to validate replies which
include a DNAME record.

Thanks to Graham Clinch for pointing this out.

7 months agoMake extract_name() easier to call operating on first name in message.
Simon Kelley [Fri, 7 Feb 2025 22:13:31 +0000 (22:13 +0000)]
Make extract_name() easier to call operating on first name in message.

7 months agoMove find_pseudoheader() before add_edns0_config() in TCP codepath.
Simon Kelley [Fri, 28 Feb 2025 23:48:17 +0000 (23:48 +0000)]
Move find_pseudoheader() before add_edns0_config() in TCP codepath.

There's no point in checking if the query has edns0 headers _after_
adding our own.

This has the affect that if --add-cpe-id or --add-subnet or their friends
are configured,  a query via TCP without EDNS0 will get an answer with EDNS0.

It's highly unlikely that this breaks anything, but it is incorrect.

Thanks to  Tijs Van Buggenhout  for spotting this.

7 months agoSilence compiler warning.
Simon Kelley [Fri, 21 Feb 2025 00:04:34 +0000 (00:04 +0000)]
Silence compiler warning.

7 months agoSilence compiler warning.
Simon Kelley [Thu, 20 Feb 2025 23:55:04 +0000 (23:55 +0000)]
Silence compiler warning.

7 months agoAvoid division by zero with unlucky choices of max-port and min-port.
Simon Kelley [Thu, 20 Feb 2025 23:43:10 +0000 (23:43 +0000)]
Avoid division by zero with unlucky choices of max-port and min-port.

7 months agoFix (benign) use of uninitialised data.
Simon Kelley [Thu, 20 Feb 2025 23:27:24 +0000 (23:27 +0000)]
Fix (benign) use of uninitialised data.

7 months agoDefault --dump-mask to all-on, rather than all-off.
Simon Kelley [Mon, 10 Feb 2025 00:36:08 +0000 (00:36 +0000)]
Default --dump-mask to all-on, rather than all-off.

7 months agoFix query-combining for queries with class other than IN.
Simon Kelley [Sun, 9 Feb 2025 22:03:22 +0000 (22:03 +0000)]
Fix query-combining for queries with class other than IN.

Along the way, use of extract_request() and extract_name() got further
refined.

7 months agoMake extract_name() easier to call operating on first name in message.
Simon Kelley [Fri, 7 Feb 2025 22:13:31 +0000 (22:13 +0000)]
Make extract_name() easier to call operating on first name in message.

7 months agoRedesign the interaction between DNSSEC vaildation and per-domain servers.
Simon Kelley [Sun, 2 Feb 2025 20:28:54 +0000 (20:28 +0000)]
Redesign the interaction between DNSSEC vaildation and per-domain servers.

This should just work in all cases now. If the normal chain-of-trust exists into
the delegated domain then whether the domain is signed or not, DNSSEC
validation will function normally. In the case the delgated domain
is an "overlay" on top of the global DNS and no NS and/or DS records
exist connecting it to the global dns, then if the domain is
unsigned the situation will be handled by synthesising a
proof-of-non-existance-of-DS for the domain and queries will be
answered unvalidated; this action will be logged. A signed domain
without chain-of-trust can be validated if a suitable trust-anchor
is provided using --trust-anchor.

Thanks to Uwe Kleine-König for prompting this change, and contributing
valuable insights into what could be improved.

7 months agoRemove the concept of "DNSSEC incapable servers".
Simon Kelley [Sun, 2 Feb 2025 16:21:21 +0000 (16:21 +0000)]
Remove the concept of "DNSSEC incapable servers".

We're going to replace this with configured or extrapolated DS records.

7 months agoFix crash when no upstream servers defined. v2.91 v2.91rc6
Tijs Van Buggenhout [Fri, 14 Mar 2025 15:06:42 +0000 (15:06 +0000)]
Fix crash when no upstream servers defined.

This is a regession introduced in 3b6df06fb8cb3652d2e7afd085fae3f416408013.

When dnsmasq is started without upstreams (yet), but a
DNS query comes in that needs forwarding dnsmasq now potentially crashes as
the value for "first" variable is undetermined.

A segmentation violation occurs when the index
is out of bounds of  serverarray.

Credits go to pedro0311 <pedro@freshtomato.org>

7 months agoFix bogus compiler warnings.
Simon Kelley [Wed, 12 Mar 2025 15:44:19 +0000 (15:44 +0000)]
Fix bogus compiler warnings.

7 months agoDocumentation for --do-0x20-encode.
Simon Kelley [Sun, 9 Mar 2025 16:15:16 +0000 (16:15 +0000)]
Documentation for --do-0x20-encode.

7 months agoDefault-off 0x20 encoding and provide --do-0x20-encode option. holly/master
Simon Kelley [Tue, 4 Mar 2025 12:59:17 +0000 (12:59 +0000)]
Default-off 0x20 encoding and provide --do-0x20-encode option.

For now, this causes too many problems to default on.

Hopefully this will change for future releases.

7 months agoRevert 368ceff6e09941412ca58effb57e30ed78410a3e and fix correct problem.
Simon Kelley [Sat, 1 Mar 2025 22:43:23 +0000 (22:43 +0000)]
Revert 368ceff6e09941412ca58effb57e30ed78410a3e and fix correct problem.

The next() function is broken for any TFTP packet with padding
which doesn't end with a zero.

Rewrite to handle such packets.

Thanks to Helge Deller <deller@gmx.de> for persisting in finding the
actual problem and proposing a solution. This patch is modelled on his,
but rewritten for personal preference by Simon Kelley, who is
responsible for all bugs.

7 months agoFix stupid error in allocating 0x20-flip bitmaps. v2.91rc5
Simon Kelley [Fri, 21 Feb 2025 14:41:34 +0000 (14:41 +0000)]
Fix stupid error in allocating 0x20-flip bitmaps.

8 months agoMerge branch 'master' of onyx:dnsmasq/dnsmasq
Simon Kelley [Fri, 21 Feb 2025 13:08:26 +0000 (13:08 +0000)]
Merge branch 'master' of onyx:dnsmasq/dnsmasq

8 months agoUse correct packet length when 0x20 flipping truncated packet.
Simon Kelley [Fri, 21 Feb 2025 13:02:04 +0000 (13:02 +0000)]
Use correct packet length when 0x20 flipping truncated packet.

This makes no difference in practice, since only the query is
operated on, but it is more correct.

8 months agoFix possible problems with case-encode bigmap array allocation.
Simon Kelley [Thu, 20 Feb 2025 22:59:04 +0000 (22:59 +0000)]
Fix possible problems with case-encode bigmap array allocation.

8 months agoUpdate plen when getting retried query from stash.
Simon Kelley [Mon, 10 Feb 2025 12:26:15 +0000 (12:26 +0000)]
Update plen when getting retried query from stash.

They should be equal, but that depends on untrusted data.

8 months agoYet another 0x20 fix. v2.91rc4
Simon Kelley [Sun, 9 Feb 2025 11:06:59 +0000 (11:06 +0000)]
Yet another 0x20 fix.

To complement the previous one, which fixed the retry path
when the query is retried from a different id/source address, this
fixes retries from the same id/source address.

8 months agoFix possible SIGSEGV in bpf.c
Simon Kelley [Sat, 8 Feb 2025 22:58:42 +0000 (22:58 +0000)]
Fix possible SIGSEGV in bpf.c

8 months agoFix 0x20 problem. v2.91rc3
Simon Kelley [Fri, 7 Feb 2025 19:56:33 +0000 (19:56 +0000)]
Fix 0x20 problem.

A retry to upstream DNS servers triggered by the following conditions

1) A query asking for the same data as a previous query which has not yet been answered.
2) The second query arrives more than two seconds after the first.
3) Either the source of the second query or the id field differs from the first.

fails to set the case of the retry to the same pattern as the first attempt.

However dnsmasq expects the reply from upstream to have the case
pattern of the first attempt.

If the answer to the retry arrives before the answer to the first
query, dnsmasq will notice the case mismatch, log an error, and
ignore the answer.

The worst case scenario would be the first upstream query or reply is
lost and there would follow a short period where all queries for that
particular domain would fail.

This is a 2.91 development issue, it doesn't apply to previous stable releases.

8 months agoTFTP off-by-2 bugfix v2.91rc2
Helge Deller [Thu, 6 Feb 2025 12:02:03 +0000 (13:02 +0100)]
TFTP off-by-2 bugfix

Some of my PA-RISC UNIX machines boot remotely via tftp, but dnsmasq
randomly fails to deliver (the identical file) to some of the machines.

I traced the issue and basically dnsmasq fails with error "unsupported
request from IP.x.y.z" (line 366 in tftp.c).

Here is an example package which is sent (516 hex bytes):
76 6d 6c 69 6e 75 78 00 6f 63 74 65 74 00 12 74 10 3c 00 00 00 00 00 01
a9 24 00 00 00 00 00 00 1e 38 00 00 00 00 00 00 1c a0 00 00 00 00 00 00
1d 08 00 00 00 00 00 00 1d 28 00 00 00 00 00 00 08 00 00 00 00 00 00 00
03 d8 00 00 00 00 00 00 00 00 00 00 00 00 00 00 1d 30 00 00 00 02 ff e0
00 00 00 00 03 60 a8 49 55 93 00 00 00 01 f0 d4 21 e4 00 00 00 00 00 00
1d 78 00 00 00 f0 f0 d8 51 38 00 00 00 f0 f0 d4 21 c0 00 00 00 00 00 00
00 00 00 00 00 00 00 01 aa b8 00 00 00 f0 f0 e9 62 7c 00 00 00 00 00 00
03 01 ff ff ff ff ff ff 03 00 ff ff ff ff ff ff ff ff 00 00 00 00 00 00
00 03 00 00 00 00 00 00 00 05 00 00 00 00 00 00 00 04 ff ff ff ff ff ff
ff ff 00 00 00 00 00 00 00 00 ff ff ff ff ff ff ff ff 00 00 00 00 00 00
00 05 00 00 00 00 00 00 1e 38 00 00 00 00 00 00 00 60 00 00 00 00 00 01
a6 68 00 00 00 00 00 00 00 03 00 00 00 00 00 00 00 ff 00 00 00 00 00 00
00 03 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 02 00 00 00 00 00 00
00 00 00 00 00 f0 f0 d8 4f 30 00 00 00 00 00 00 00 01 00 00 00 00 00 00
00 00 00 00 00 00 00 01 ae ec 00 00 00 00 00 00 1f 70 00 00 00 00 00 00
1e b8 00 00 03 60 a8 49 55 93 00 00 00 02 18 71 1a 00 00 00 00 00 00 00
00 03 00 00 00 00 00 00 00 03 00 00 00 00 00 00 1e 38 00 00 00 00 00 00
00 07 00 00 00 00 00 00 00 00 00 00 00 f0 f0 d2 f0 70 00 00 00 00 00 00
1f c0 00 00 00 f0 f0 d4 0b e8 00 00 00 00 00 00 00 01 00 00 00 00 00 00
00 60 ff ff ff fc 00 60 18 00 00 00 00 00 00 00 00 00 00 00 00 f0 f0 d8
8f d0 00 00 00 00 00 00 1f f8 00 00 00 00 00 00 00 00 00 00 00 f0 f0 d8
8d b8 00 00 00 00 00 00 1e e8 00 00

Please note the last 3 bytes: "e8 00 00".
If the 3rd last byte is "00", then dnsmasq works and it fails it it's "e8".

So, the bug is in line 366 of tftp.c:
   filename = next(&p, end)
Here filename gets the value NULL from next(), because the "end" variable is off-by-2.
The fix is to change line 363 to add an offset of 2:
  end = packet + 2 + len;

Signed-off-by: Helge Deller <deller@gmx.de>
Closes: https://bugzilla.redhat.com/show_bug.cgi?id=2293793

8 months agoFix for case-sensitivity problems in DNS.
Simon Kelley [Thu, 6 Feb 2025 16:01:57 +0000 (16:01 +0000)]
Fix for case-sensitivity problems in DNS.

Fix a case sensitivity problem which has been lurking for a long while.
When we get example.com and Example.com and combine them, we send whichever
query arrives first upstream and then later answer it, and we also
answer the second with the same answer. That means that if example.com
arrives first, it will get the answer example.com - good - but Example.com
will _also_ get the answer example.com - not so good.

In theory, fixing this is simple without having to keep seperate
copies of all the queries: Just use the bit-vector representation
of case flipping that we have for 0x20-encoding to keep the
differences in case. The complication comes from the fact that
the existing bit-vector code only holds data on the first 32 alpha
letters, because we only flip that up to many for 0x20 encoding.

In practise, the delta between combined queries can almost always
be represented with that data, since almost all queries are
all lower case and we only purturb the first 32 letters with
0x20 encoding. It's therefore worth keeping the existing,
efficient data structure for the 99.9% of the time it works.
For the 0.1% it doesn't, however, one needs an arbitrary-length data
structure with the resource implications of that.

Thanks to Peter Tirsek for the well researched bug report which set me
on to these problems.

8 months agoFix bug in 0x20 encoding.
Simon Kelley [Thu, 6 Feb 2025 10:32:29 +0000 (10:32 +0000)]
Fix bug in 0x20 encoding.

We must only compare case when mapping an answer from upstream
to a forwarding record, not when checking a query to see if it's a
duplicate. Since the saved query name is scrambled, that ensures
that almost all such checks will wrongly fail.

Thanks to Peter Tirsek for an exemplary bug report for this.

8 months agoBump date on manpage. v2.91rc1
Simon Kelley [Wed, 5 Feb 2025 21:34:54 +0000 (21:34 +0000)]
Bump date on manpage.

8 months agoFix c99ism added in 0b6144583b128330e7cffa105bc9ccbc4d6f0692
Simon Kelley [Wed, 5 Feb 2025 21:02:54 +0000 (21:02 +0000)]
Fix c99ism added in 0b6144583b128330e7cffa105bc9ccbc4d6f0692

8 months agoSpell check v2.91 CHANGELOG
Matthias Andree [Wed, 5 Feb 2025 18:47:18 +0000 (19:47 +0100)]
Spell check v2.91 CHANGELOG

8 months agoLog failed TCP DNS connections upstream when --log-debug active.
Simon Kelley [Wed, 5 Feb 2025 17:15:52 +0000 (17:15 +0000)]
Log failed TCP DNS connections upstream when --log-debug active.

8 months agoManpage typo.
Simon Kelley [Wed, 5 Feb 2025 15:20:31 +0000 (15:20 +0000)]
Manpage typo.

8 months agoAdd --no-0x20-encode config option.
Simon Kelley [Mon, 3 Feb 2025 21:02:12 +0000 (21:02 +0000)]
Add --no-0x20-encode config option.

The "bit 0x20 encoding" implemented in 995a16ca0cd9767460c72a856909962a34fdbfbd
can interact badly with (hopefully) rare broken upstream servers. Provide
an option to turn it off and a log message to give a clue as to why DNS service
is non-functional.

8 months agoTweak to logging.
Simon Kelley [Mon, 3 Feb 2025 15:26:55 +0000 (15:26 +0000)]
Tweak to logging.

When a cached answer is too big, log

cached reply is truncated

and not

config reply is truncated

8 months agoClean up some of the man page formatting.
Paul Donald [Fri, 31 Jan 2025 20:52:55 +0000 (21:52 +0100)]
Clean up some of the man page formatting.

Some writing was improved for clarity, especially regarding the use of
tags which can be confusing and difficult to grasp.

8 months agobelt-and-braces extra call to check_log_writer() in tcp_request()
Simon Kelley [Sat, 1 Feb 2025 15:24:24 +0000 (15:24 +0000)]
belt-and-braces extra call to check_log_writer() in tcp_request()

8 months agoFix potential memory leak v2.91test10
Brian Haley [Thu, 23 Jan 2025 23:26:45 +0000 (18:26 -0500)]
Fix potential memory leak

When a new IPv6 address is being added to a dhcp_config
struct, if there is anything invalid regarding the prefix
it looks like there is a potential memory leak.
ret_err_free() should be used to free it.

Also, the new addrlist struct is being linked into
the existing addr6 list in the dhcp_config before the
validity check, it is best to defer this insertion
until later so an invalid entry is not present, since
the CONFIG_ADDR6 flag might not have been set yet.

Signed-off-by: Brian Haley <haleyb.dev@gmail.com>
8 months agoMove debian submodule to submodules/dnsmasq-debian.
Simon Kelley [Fri, 24 Jan 2025 21:05:43 +0000 (21:05 +0000)]
Move debian submodule to submodules/dnsmasq-debian.

8 months agoBump copyrights to 2025.
Simon Kelley [Thu, 23 Jan 2025 17:08:39 +0000 (17:08 +0000)]
Bump copyrights to 2025.

9 months agoCorrect BNF for --trust-anchor in manpage. v2.91test9
Simon Kelley [Mon, 20 Jan 2025 16:11:40 +0000 (16:11 +0000)]
Correct BNF for --trust-anchor in manpage.

9 months agoRemove misleading comment.
Simon Kelley [Mon, 20 Jan 2025 15:55:42 +0000 (15:55 +0000)]
Remove misleading comment.

9 months agoConvert DNS names in logs to all lower case.
Simon Kelley [Mon, 20 Jan 2025 15:25:26 +0000 (15:25 +0000)]
Convert DNS names in logs to all lower case.

0x20 encoding makes them look odd, otherwise.

9 months agoImplement "DNS-0x20 encoding".
Simon Kelley [Sun, 19 Jan 2025 21:44:19 +0000 (21:44 +0000)]
Implement "DNS-0x20 encoding".

This provides extra protection against reply-spoof attacks.

Since DNS queries are case-insensitive, it's possible to randomly flip
the case of letters in a query and still get the correct answer back.
This adds an extra dimension for a cache-poisoning attacker to guess
when sending replies in-the-blind since it's expected that the
legitimate answer will have the same pattern of upper and lower case
as the query, so any replies which don't can be ignored as
malicious.

The amount of extra entropy clearly depends on the number
of a-z and A-Z characters in the query, and this implementation puts a
hard limit of 32 bits to make rescource allocation easy. This about
doubles entropy over the standard random ID and random port
combination.

9 months agoCase-sensitive matching of questions and answers.
Simon Kelley [Sun, 19 Jan 2025 00:08:36 +0000 (00:08 +0000)]
Case-sensitive matching of questions and answers.

When checking that an answer is the answer to the question that
we asked, compare the name in a case-sensitive manner.

Clients can set the letters in a query to a random pattern of
uppercase and lowercase to add more randomness as protection against
cache-poisoning attacks, and we don't want to nullify that.

This actually restores the status quo before
commit ed6d29a78475f9ec91141120aba53490bc1dc39a
since matching questions and answers using a checksum
can't help but be case sensitive.

This patch is a preparation for introducing DNS-0x20
in the dnsmasq query path.

9 months agoFix log message fields in wrong order in some auth replies. v2.91test8
Simon Kelley [Sat, 18 Jan 2025 23:56:23 +0000 (23:56 +0000)]
Fix log message fields in wrong order in some auth replies.

9 months agoRename cache_validated() to cache_not_validated().
Simon Kelley [Sat, 18 Jan 2025 23:26:06 +0000 (23:26 +0000)]
Rename cache_validated() to cache_not_validated().

Let's give the poor programmers a chance.

9 months agoFix subtle bug in arbitrary-RR caching.
Simon Kelley [Sat, 18 Jan 2025 22:40:30 +0000 (22:40 +0000)]
Fix subtle bug in arbitrary-RR caching.

If the client asks for DNSSEC RRs via the do bit, and
we have an answer cached, we can only return the cached
answer if the RR was not validated. This is because
we don't the extra info (RRSIGS, NSECs) for a complete
validated answer. In that case we have to forward again.

This bug was that the "is the cache entry validated" test was
in an outer loop rather than an inner one. A cache hit on
a different RRtype that wasn't validated would satify the
condition to use the cache, even if the cache entry for
the required RRtype didn't. The only time when there can be a mix
of validated and non validated cache entries for the same domain
is when most are not validated, but one is a negative cache for
a DS record.

This bug took a long time to find.

9 months agoFix fubar that could return unsigned NODATA response when do bit set.
Simon Kelley [Sat, 18 Jan 2025 22:16:29 +0000 (22:16 +0000)]
Fix fubar that could return unsigned NODATA response when do bit set.

9 months agoHandle DS queries to auth zones.
Simon Kelley [Fri, 17 Jan 2025 17:49:29 +0000 (17:49 +0000)]
Handle DS queries to auth zones.

When dnsmasq is configured to act as an authoritative server and has
an authoritative zone configured, and recieves a query for
that zone _as_forwarder_ it answers the query directly rather
than forwarding it. This doesn't affect the answer, but it
saves dnsmasq forwarding the query to the recusor upstream,
whch then bounces it back to dnsmasq in auth mode. The
exception should be when the query is for the root of zone, for a DS
RR. The answer to that has to come from the parent, via the
recursor, and will typically be a proof-of-nonexistence since
dnsmasq doesn't support signed zones. This patch suppresses
local answers and forces forwarding to the upstream recursor
for such queries. It stops breakage when a DNSSEC validating
client makes queries to dnsmasq acting as forwarder for a zone
for which it is authoritative.

9 months agoExtend build fingerprinting to include CFLAGS.
Simon Kelley [Fri, 17 Jan 2025 16:48:08 +0000 (16:48 +0000)]
Extend build fingerprinting to include CFLAGS.

If the value of CFLAGS is changed between builds, the makefile
will rebuid, in the same way as for COPTS.

9 months agoTweak handling of duplicate DNS answers via UDP.
Simon Kelley [Mon, 13 Jan 2025 20:22:42 +0000 (20:22 +0000)]
Tweak handling of duplicate DNS answers via UDP.

If we get a duplicate answer for a query via UDP which we have
either already received and started DNSSEC validation, or was
truncated and we've passed to TCP, then just ignore it.

The code was already in place, but had evolved wonky and
only worked for error replies which would otherwise prompt
a retransmit.

9 months agoTweak 7d915a0bb94260073ec7aa4dd00b787f3ea4b9e8 v2.91test7
Simon Kelley [Mon, 13 Jan 2025 11:03:30 +0000 (11:03 +0000)]
Tweak 7d915a0bb94260073ec7aa4dd00b787f3ea4b9e8

A downstream query may have gone to TCP, not just DNSSEC queries.

9 months agoAttempt to keep running if a child process dies.
Simon Kelley [Mon, 13 Jan 2025 10:56:19 +0000 (10:56 +0000)]
Attempt to keep running if a child process dies.

If a child process dies unexpectedly, log the error and
try and tidy up so the main process continues to run and
doesn't block awaiting the dead child.

9 months agoFix another 509afcd1d2f9edbd1e11c9abd0f335f02baa7fc4 SNAFU
Simon Kelley [Mon, 13 Jan 2025 10:29:47 +0000 (10:29 +0000)]
Fix another 509afcd1d2f9edbd1e11c9abd0f335f02baa7fc4 SNAFU

9 months agoImprove "no upstream servers configured" when D-Bus is enabled
Andrew Sayers [Sun, 12 Jan 2025 14:24:35 +0000 (14:24 +0000)]
Improve "no upstream servers configured" when D-Bus is enabled

Print a specific INFO message instead of a generic WARNING message,
so users know what to do.

Starting dnsmasq without upstream servers indicates a problem by default,
but is perfectly normal with D-Bus enabled.  For example, NetworkManager
starts dnsmasq with no upstream servers, then immediately populates it
over D-Bus.

9 months agoFix SNAFU in 509afcd1d2f9edbd1e11c9abd0f335f02baa7fc4
Simon Kelley [Sun, 12 Jan 2025 22:28:12 +0000 (22:28 +0000)]
Fix SNAFU in 509afcd1d2f9edbd1e11c9abd0f335f02baa7fc4

9 months agoDon't do retries over UDP when we've sent the query by TCP.
Simon Kelley [Sun, 12 Jan 2025 22:02:05 +0000 (22:02 +0000)]
Don't do retries over UDP when we've sent the query by TCP.

9 months agoRefactor poll() loop.
Simon Kelley [Sun, 12 Jan 2025 21:36:09 +0000 (21:36 +0000)]
Refactor poll() loop.

Handling events on file descriptors can result in new file
descriptors being created or old ones being deleted. As such
the results of the last call to poll() become invalid in subtle
ways.

After handling each file descriptor in  check_dns_listeners()
return, to go around the poll() loop again and get valid data
for the new situation.

Thanks to Dominik Derigs for his indefatigable sleuthing of this one.

9 months agoTreat replies with CD flag set the same for UDP and TCP code paths.
Simon Kelley [Sun, 12 Jan 2025 16:25:07 +0000 (16:25 +0000)]
Treat replies with CD flag set the same for UDP and TCP code paths.

9 months agoReturn EDE OTHER error when DNSSEC validation abandoned.
Simon Kelley [Sun, 12 Jan 2025 16:00:09 +0000 (16:00 +0000)]
Return EDE OTHER error when DNSSEC validation abandoned.

This distinguishes the case where we found a message was bogus
from cases where the process failed.