Commit Graph

2323 Commits

Author SHA1 Message Date
harry
0526792ebb Fix DHCPv6 relay on *BSD.
Analogous fix to 5a1f2c577d for DHCPv6 relay.
2024-12-17 23:17:27 +00:00
Simon Kelley
ab177cb153 Improve handling of non-QUERY DNS requests.
We can't answer and shouldn't forward non-QUERY DNS requests.

This patch fixes handling such requests from TCP connections; before
the connection would be closed without reply.

It also changes the RCODE in the answer from REFUSED to NOTIMP and
provides clearer logging.
2024-12-13 23:00:21 +00:00
Simon Kelley
3b74df4f55 Fix erroneous "DNSSEC validated" state with non-DNSSEC upstream servers.
When DNSEC validation is enabled, but a query is not validated
because it gets forwarded to a non-DNSEC-capable upstream
server, the rr_status array is not correctly cleared, with
the effect that the answer may be maked as DNSSEC validated
if the immediately preceding query was DNS signed and validated.
2024-12-10 15:01:59 +00:00
Simon Kelley
5483fead6a Support PXE proxy-DHCP and DHCP-relay at the same time.
When using PXE proxy-DHCP, dnsmasq supplies PXE information to
the client, which also talks to another "normal" DHCP server
for address allocation and similar. The normal DHCP server may
be on the local network, but it may also be remote, and accessed via
a DHCP relay. This change allows dnsmasq to act as both a
PXE proxy-DHCP server AND a DHCP relay for the same network.
2024-12-05 17:32:13 +00:00
Simon Kelley
7199531ff1 Add --dhcp-option-pxe config.
This acts almost exactly like --dhcp-option except that the defined option
is only sent when replying to PXE clients. More importantly, these
options are sent in reply PXE clients when dnsmasq in acting in PXE
proxy mode. In PXE proxy mode, the set of options sent is defined by
the PXE standard and the normal set of options is not sent. This config
allows arbitrary options in PXE-proxy replies. A typical use-case is
to send option 175 to iPXE. Thanks to Jason Berry for finding the
requirement for this.
2024-12-05 17:07:40 +00:00
Simon Kelley
5a1f2c577d Set sa_len field in DHCP relay code.
Ommision broke DHCP relay on *BSD.
2024-12-03 21:22:21 +00:00
Reynir Björnsson
6c9bc0156a Report multiple hostnames in --dhcp-host.
This is not supported, and doesn't behave as one might expect.
2024-12-01 23:50:18 +00:00
gen2dev
da2cc84854 Fix GCC-15, C23 compatibility and -Wincompatible-pointer-types errors
A bug in gentoo linux https://bugs.gentoo.org/945183 reported that dnsmasq 2.90 fails to compile with GCC 15.

The issue is that while previous versions of GCC defaulted to the C17 standard and C23 could be selected with
"-std=c23" or "-std=gnu23", GCC 15 defaults to C23. In C23 incompatible pointer types are an error instead of
a warning, so the "int (*callback)()" incomplete prototypes cause errors.

For example, compiling dnsmasq 2.90 with gcc 14.2.1 and "-std=gnu23" fails with errors such as:
    lease.c: In function `lease_find_interfaces':
    lease.c:467:34: warning: passing argument 3 of `iface_enumerate' from incompatible pointer type [-Wincompatible-pointer-types[https://gcc.gnu.org/onlinedocs/gcc/Warning-Options.html#index-Wincompatible-pointer-types]]
      467 |   iface_enumerate(AF_INET, &now, find_interface_v4);
          |                                  ^~~~~~~~~~~~~~~~~
          |                                  |
          |                                  int (*)(struct in_addr,  int,  char *, struct in_addr,  struct in_addr,  void *)
    In file included from lease.c:17:
    dnsmasq.h:1662:50: note: expected `int (*)(void)' but argument is of type `int (*)(struct in_addr,  int,  char *, struct in_addr,  struct in_addr,  void *)'
     1662 | int iface_enumerate(int family, void *parm, int (callback)());
          |                                             ~~~~~^~~~~~~~~~~

This patch uses a typedef'ed union of pointer types to get type checking of the pointers. If that's too complicated,
another way might be to use (void *) casts to disable type checking.

Also, some of the IPv6 callbacks had "int preferred, int valid" and some had
"unsigned int preferred, unsigned int valid". This patch changes them all to "unsigned int"
so they're the same and to avoid casting "u32" to "int", eg:
    u32 preferred = 0xffffffff;
    callback(..., (int)preferred, ...)
Even if those cast values aren't used in the callback, casting u32 to "int" feels bad, especially if "int" is 32 bits.
2024-12-01 22:53:16 +00:00
Simon Kelley
a8088e331a Modify the behaviour of --synth-domain for IPv6.
When deriving a domain name from an IPv6 address, an address
such as 1234:: would become 1234--.example.com, which is
not legal in IDNA2008. Stop using the :: compression method,
so 1234:: becomes
1234-0000-0000-0000-0000-0000-0000-0000.example.com
2024-11-27 23:12:41 +00:00
Simon Kelley
41d2ae3203 Make the packet-dump code work with a FIFO.
mkfifo /tmp/dnsmasq.pipe
dnsmasq --dumpfile=/tmp/dnsmasq.pipe ....
wireshark -i /tmp/dnsmasq.pipe

gives real-time display of network traffic in Wireshark.
2024-11-27 16:03:13 +00:00
Simon Kelley
c6bc22adc7 Add missing dump_packet_udp() call. 2024-11-27 00:19:32 +00:00
Simon Kelley
9c057566d5 Update CHANGELOG. 2024-11-25 23:38:56 +00:00
Simon Kelley
32a8f3e009 Finesse TCP timeouts for upstream connections.
Timeouts for TCP connections to non-responive servers are very long.
This in not appropriate for DNS connections.

Set timeouts for connection setup, sending data and recieving data.
The timeouts for connection setup and sending data are set at 5 seconds.
For recieving the reply this is doubled, to take into account the
time for usptream to actually get the answer.

Thanks to Petr Menšík for pointing out this problem, and finding a better
and more portable solution than the one in place heretofore.
2024-11-25 23:18:07 +00:00
Simon Kelley
481ff0ed10 Logging tweaks. 2024-11-25 10:17:50 +00:00
Simon Kelley
f04cf8506a Simplify EDNS0 packet size handling.
In the post 2020 flag-day world, we limit UDP packets to 1232 bytes
which can go anywhere, so the dodgy code to try and determine the
functional maxmimum packet size on the path from upstream servers
is obsolete.
2024-11-24 23:06:22 +00:00
Simon Kelley
04d7693d86 Tweak logging for truncated replies. 2024-11-24 22:13:44 +00:00
Simon Kelley
4ea23f7ea1 Default --fast-dns-retries on when doing DNSSEC.
When doing DNSSEC validation, a single downstream query may
trigger many upstream queries. On an unreliable network, there
may not be enough downstream retries to ensure that all these
queries complete.
2024-11-24 21:52:39 +00:00
Simon Kelley
163c05c61d Make locally generated truncated answers consistent.
process_reply() is no longer doing this.
2024-11-24 08:42:33 +00:00
Simon Kelley
d2790914df More edns0 rationalisation. 2024-11-24 00:37:40 +00:00
Simon Kelley
334e144c36 Don't empty reply packets received from upstream marked as truncated.
It's concievable that upstream, has provided a useful minimal reply.

After a patch from Rahul Thakur.
2024-11-23 23:38:31 +00:00
Simon Kelley
8bd54efceb Typo fix. 2024-11-23 22:53:34 +00:00
Simon Kelley
e5e8c14d87 Large refactor of EDNS0 UDP packet size handling.
This was kinda strange before, with a lot of cargo-cult copied code,
and no clear strategy.

Now it works like this:

When talking upstream we always add a pseudoheader, and set the
UDP packet size to --edns-packet-max unless we've had problems
talking to a server, when it's reduced to 1280 if that fixes things.

Answering queries from downstream, we get the answer (either from
upstream or local data) If local data won't fit the advertised size
(or 512 if there's not pseudoheader) return truncated. If upstream
returns truncated, do likewise. If upstream is OK, but the answer is
too big for downstream, truncate the answer.
2024-11-23 22:38:41 +00:00
Simon Kelley
e778a28eee Remove obsolete comment. 2024-11-22 22:42:50 +00:00
Simon Kelley
4cf2f757ec Rationalise reties.
The saved query includes all the modifications, made on first
forwarding, which simplifies retries.
2024-11-22 22:23:36 +00:00
Simon Kelley
ae85ea3858 Fix buffer overflow when configured lease-change script name
is too long.

Thanks to Daniel Rhea for finding this one.
2024-11-21 15:42:49 +00:00
Simon Kelley
b087cf4a6c Fix out-of-bounds heap read in order_qsort().
We only need to order two server records on the ->serial field.
Literal address records are smaller and don't have
this field and don't need to be ordered on it.
To actually provoke this bug seems to need the same server-literal
to be repeated twice, eg --address=/a/1.1.1.1 --address-/a/1.1.1.1
which is clearly rare in the wild, but if it did exist it could
provoke a SIGSEV. Thanks to Daniel Rhea for fuzzing this one.
2024-11-21 15:28:31 +00:00
Simon Kelley
0adaf13438 Don't clear tcpfd for literal address server records.
They have smaller structs which don't include that field,
so this is a buffer overlow.

Error introduced in f5cdb007d8
2024-11-21 15:18:19 +00:00
Simon Kelley
b5ac983bf6 Fix wrong transaction ID when retrying DNSSEC queries. 2024-11-21 15:09:14 +00:00
Simon Kelley
498794ad85 Extralog tweaks to get log-id right in a couple of odd cases. 2024-11-03 23:40:43 +00:00
Simon Kelley
467fbd1086 Fix argument-order thinko on call to new lookup_frec() 2024-11-03 23:07:54 +00:00
Simon Kelley
7b7aef903e Handle error return from blockdata_alloc in all cases. 2024-11-02 22:37:51 +00:00
Simon Kelley
09a1839272 Don't send suspect answer as query to next server in DNS TCP codepath. 2024-11-02 22:18:56 +00:00
Simon Kelley
1b76e1c8ec Remove hash-questions.c - no longer required. 2024-11-02 21:29:47 +00:00
Simon Kelley
959d991d10 Replace query hashing in TCP code path. 2024-11-02 21:09:17 +00:00
Simon Kelley
ed6d29a784 Remove query hashing in UDP DNS code path.
Now we're always saving the query, this is no longer necessary,
and allows the removal of a lot of quite hairy code.

Much more code removal to come, once the TCP code path is also purged.
2024-11-02 15:33:37 +00:00
Simon Kelley
5d6399b71c DOn't churn a query though the blockdata store twice when forwarding it. 2024-11-01 16:50:15 +00:00
Simon Kelley
3b6df06fb8 Always save forwarded query locally.
We do this in many cases anyway (DNSSEC, fast-retry) and doing
it unconditionally allows much simplification of knarly code, to follow.
2024-11-01 16:06:58 +00:00
Simon Kelley
a9d46d42cb Tweak packet-reduction code going from TCP->UDP. 2024-10-13 23:09:48 +01:00
Simon Kelley
0338aa4586 Don't log bogus source address when doing fast retry. 2024-10-13 00:09:26 +01:00
Simon Kelley
d15d371051 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.
2024-10-12 22:32:21 +01:00
Simon Kelley
1c26ec2876 UDP-to-TCP bugfix: wrong calls to extract_name and
suppress rapid (UDP) retry once we've switched to TCP.
2024-10-04 17:20:33 +01:00
Simon Kelley
e9a7cd0a50 Fix DNSSEC work counting when swapping from UDP to TCP 2024-10-04 17:20:33 +01:00
Simon Kelley
f5cdb007d8 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.
2024-10-04 17:20:33 +01:00
Simon Kelley
46288c7e90 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.
2024-10-04 17:20:24 +01:00
Simon Kelley
d7d682637d Merge branch 'master' of ssh://thekelleys.org.uk/var/local/git/dnsmasq 2024-10-04 17:03:55 +01:00
Simon Kelley
f006be7842 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.
2024-10-04 16:59:14 +01:00
Simon Kelley
550c368ade Treat cache insertion failure of DNSKEY and DS records as
another resource problem and fail validation with suitable logging.
2024-03-27 16:00:06 +00:00
Simon Kelley
b8ff4bb762 Remove debian directory and replace with a git submodule. 2024-02-22 22:45:37 +00:00
Simon Kelley
9adbf009a6 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.
2024-02-21 00:46:25 +00:00
renmingshuai
ccff85ad72 [PATCH] Fix error introduced in 51471cafa5
Signed-off-by: renmingshuai <renmingshuai@huawei.com>
2024-02-21 00:24:25 +00:00