Commit Graph

226 Commits

Author SHA1 Message Date
Dominik Derigs
8f2a62b386 Extend cache dump: "!" as type for non-terminals, new flag "C" for config-provided and log source when applicable.
Signed-off-by: DL6ER <dl6er@dl6er.de>
2022-01-11 22:17:14 +00:00
Dominik Derigs
a6c0edd4f4 Fix header of cache dump. The width of the host and address fields are 30 and 40 characters, respectively.
Signed-off-by: DL6ER <dl6er@dl6er.de>
2022-01-11 22:16:48 +00:00
Simon Kelley
ff43d35aee Log port numbers in server addresses when non-standard ports in use. 2022-01-11 22:09:09 +00:00
Simon Kelley
ea33a01303 Fix rare "Internal error in cache" messages.
Fix error created in 1ce1c6beae

Many thanks to Hartmut Birr for finding the bug and bisecting to
the guilty commit.

The breaking commit creates cache entries which have F_NXDOMAIN
set but none of F_IPV4, F_IPV6 or F_SRV. If cache_scan_free() is called
to delete such an entry it will fail to do so.

If the cache has no free slots and the least-recently-used slot is such
an entry, then a new insertion will attempt to make space by calling
cache_scan_free(), which will fail when it should be impossible and
trigger the internal error.
2021-12-24 18:58:35 +00:00
Simon Kelley
9560658c5b Fix crash in PXE/netboot when DNS server disabled. 2021-10-19 15:33:41 +01:00
Simon Kelley
47aefca5e4 Add --nftset option, like --ipset but for the newer nftables.
Thanks to Chen Zhenge for the original patch, which I've
reworked. Any bugs down to SRK.
2021-09-27 21:49:28 +01:00
Simon Kelley
51ffae4eab Fix coverity detected issues in cache.c
Error: UNINIT (CWE-457): [#def27]
dnsmasq-2.86test7/src/cache.c:1193: var_decl: Declaring variable "lrec" without initializer.
dnsmasq-2.86test7/src/cache.c:1315: uninit_use_in_call: Using uninitialized value "lrec.ttd" when calling "make_non_terminals".
 # 1313|       {
 # 1314|         lrec.name.namep = txt->name;
 # 1315|->       make_non_terminals(&lrec);
 # 1316|       }
 # 1317|

Error: CLANG_WARNING: [#def29]
dnsmasq-2.86test7/src/cache.c:1552:15: warning[core.uninitialized.Assign]: Assigned value is garbage or undefined
 # 1550|   	{
 # 1551|   	  crecp->flags = (source->flags | F_NAMEP) & ~(F_IPV4 | F_IPV6 | F_CNAME | F_SRV | F_DNSKEY | F_DS | F_REVERSE);
 # 1552|-> 	  crecp->ttd = source->ttd;
 # 1553|   	  crecp->name.namep = name;
 # 1554|
2021-09-11 21:57:30 +01:00
Petr Menšík
2f45670951 Add safety checks to places pointed by Coverity
GCC Analyzer (experimental)

1. dnsmasq-2.85/src/forward.c:0: scope_hint: In function 'allocate_rfd.part.0'
2. dnsmasq-2.85/src/forward.c:2321:18: warning[-Wanalyzer-null-dereference]: dereference of NULL 'rfd'
 #  2319|     *fdlp = rfl;
 #  2320|
 #  2321|->   return rfl->rfd->fd;
 #  2322|   }
 #  2323|

1. dnsmasq-2.85/src/cache.c:0: scope_hint: In function 'log_query'
2. dnsmasq-2.85/src/cache.c:1969:20: warning[-Wanalyzer-null-dereference]: dereference of NULL 'name'
 #  1967|       source = "cached";
 #  1968|
 #  1969|->   if (strlen(name) == 0)
 #  1970|       name = ".";
 #  1971|

1. dnsmasq-2.85/src/cache.c:0: scope_hint: In function 'cache_scan_free'
2. dnsmasq-2.85/src/cache.c:436:20: warning[-Wanalyzer-null-argument]: use of NULL 'addr' where non-null expected
40. /usr/include/sys/un.h:37: included_from: Included from here.
41. dnsmasq-2.85/src/dnsmasq.h:101: included_from: Included from here.
42. dnsmasq-2.85/src/cache.c:17: included_from: Included from here.
43. /usr/include/string.h:64:12: note: argument 2 of 'memcmp' must be non-null
 #   434|   		   (flags & crecp->flags & F_REVERSE) &&
 #   435|   		   (flags & crecp->flags & (F_IPV4 | F_IPV6)) &&
 #   436|-> 		   memcmp(&crecp->addr, addr, addrlen) == 0)
 #   437|   	    {
 #   438|   	      *up = crecp->hash_next;
2021-09-11 14:48:17 +01:00
Dominik DL6ER
e0ce3c12f2 Add all current RR types to the table of type names used for query logging.
This patch also changes the method of calling querystr() such that
it is only called when logging is enabled, to eliminate any
possible performance problems from searching the larger table.
2021-09-10 23:13:53 +01:00
Dominik DL6ER
c83e33d608 Final logging tweaks. 2021-09-01 21:19:47 +01:00
Simon Kelley
7b80c75d9d Rationalise query-reply logging.
Try and log exactly what was returned, rather than just what
got cached. Also give validation status of RRsets if extra logging specified.

This commit also fixes a long-standing bug in caching of CNAME chains
leading to a PTR record.

Based on and inspired by a patch from Dominik DL6ER <dl6er@dl6er.de>
2021-08-31 18:23:03 +01:00
Simon Kelley
f83c6cf51a Return REFUSED in auth mode when we are not authoritative for the query. 2021-07-20 17:15:36 +01:00
Dominik DL6ER
e7ccd95c04 Add EDE return when no matching key found. 2021-07-09 22:12:42 +01:00
Simon Kelley
cb6d06bb54 Rationalise SERV_MARK use. 2021-07-01 23:00:22 +01:00
Simon Kelley
4205e2ebcf Reuse workspace bit in struct server ->flags. 2021-07-01 13:22:10 +01:00
Simon Kelley
6261aba026 Initial implementation of RFC-8914 extended DNS errors. 2021-06-26 00:38:01 +01:00
Simon Kelley
5ab7e4a475 Improve efficiency of DNSSEC.
The sharing point for DNSSEC RR data used to be when it entered the
cache, having been validated. After that queries requiring the KEY or
DS records would share the cached values. There is a common case in
dual-stack hosts that queries for A and AAAA records for the same
domain are made simultaneously.  If required keys were not in the
cache, this would result in two requests being sent upstream for the
same key data (and all the subsequent chain-of-trust queries.) Now we
combine these requests and elide the duplicates, resulting in fewer
queries upstream and better performance. To keep a better handle on
what's going on, the "extra" logging mode has been modified to
associate queries and answers for DNSSEC queries in the same way as
ordinary queries. The requesting address and port have been removed
from DNSSEC logging lines, since this is no longer strictly defined.
2021-06-15 15:27:29 +01:00
Simon Kelley
12a9aa7c62 Major rewrite of the DNS server and domain handling code.
This should be largely transparent, but it drastically
improves performance and reduces memory foot-print when
configuring large numbers domains of the form
local=/adserver.com/
or
local=/adserver.com/#

Lookup times now grow as log-to-base-2 of the number of domains,
rather than greater than linearly, as before.
The change makes multiple addresses associated with a domain work
address=/example.com/1.2.3.4
address=/example.com/5.6.7.8
It also handles multiple upstream servers for a domain better; using
the same try/retry alogrithms as non domain-specific servers. This
also applies to DNSSEC-generated queries.

Finally, some of the oldest and gnarliest code in dnsmasq has had
a significant clean-up. It's far from perfect, but it _is_ better.
2021-06-08 22:10:55 +01:00
Geert Stappers
3573ca0eec Chomp file ends
Removed empty lines from end of src/*.[ch] files.
If the new last line became '#endif'
was the condition of the '#if' added.
2021-04-09 17:27:36 +01:00
Simon Kelley
c8e8f5c204 Bump copyright notices for 2021. Happy New Year! 2021-01-24 21:59:37 +00:00
Simon Kelley
7e194a0a7d Apply floor of 60s to TTL of DNSKEY and DS records in cache.
Short TTLs and specifically zero TTLs can mess up DNSSEC validation.
2020-07-12 17:43:25 +01:00
Simon Kelley
2a8710ac2f Update copyrights to 2020. 2020-01-05 16:40:06 +00:00
Ville Skyttä
bf23c8a394 Spelling and format fixes. 2019-12-05 16:50:57 +00:00
Simon Kelley
1fd56c0e33 Tidy up CNAME representaion.
Use an explicit discriminator for the target union.
2019-10-30 12:58:28 +00:00
Simon Kelley
376cb97685 Extend non-terminal name handling to all locally configured RRs. 2019-10-29 22:58:55 +00:00
Simon Kelley
84449bf41c Generalise locally-configured CNAME handling.
It's now possible for the target of a CNAME to be any locally
configured RR or even point to a non-existent RR.
2019-10-29 22:24:19 +00:00
Simon Kelley
157d8cfd6a Don't silently discard all-zeroes adddresses in --host-record. 2019-10-25 17:46:49 +01:00
Simon Kelley
1292e1a557 Don't waste time caching zero-TTL DNS records. 2019-10-25 17:31:53 +01:00
Alin Nastac
e710c34469 Fix crash when negative SRV response over TCP gets stored in LRU cache entry.
Patch extended to receive side of pipe by SRK.
2019-09-30 15:30:26 +01:00
Simon Kelley
065e5bb0b1 More /etc/hosts linecount fixing. 2019-03-01 14:38:51 +00:00
Sven Mueller
162e5e0062 Fix bug added in 2.80 non-terminal code which returns NODATA instead of NXDOMAIN.
Thanks to Sven Muleller and Maciej Żenczykowski for work on this.

https://bugzilla.redhat.com/show_bug.cgi?id=1674067 refers.
2019-02-27 21:17:37 +00:00
Simon Kelley
4219adeeef Fix line counting when reading /etc/hosts. 2019-02-27 20:30:21 +00:00
Simon Kelley
4bf62f616b Tidy cache_blockdata_free() 2019-01-10 21:54:22 +00:00
Simon Kelley
2896e2485e Check for not(DS or DNSKEY) in is_outdated_cname_pointer()
Previous check was _for_ IPV4, IPv6 CNAME, and I missed adding SRV.
2019-01-09 15:12:34 +00:00
Simon Kelley
a90f09db4c Fix crash freeing negative SRV cache entries.
Thanks to Daniel for finding this one.
2019-01-09 15:08:16 +00:00
Simon Kelley
5b99eae59d Cache SRV records.
Inpsired by a patch from Jeremy Allison, but completely re-rolled
by srk. All bugs are mine.
2019-01-06 23:09:50 +00:00
Simon Kelley
2c594732eb File logic bug in cache-marshalling code. Introduced a couple of commits back. 2019-01-03 13:42:03 +00:00
Simon Kelley
cc921df9ce Remove nested struct/union in cache records and all_addr. 2019-01-02 22:48:59 +00:00
Simon Kelley
ab194ed7ca Futher address union tidying.
Pass DNSKEY and DS data into cache_insert via the address argument,
now these data types are included in struct all_addr.
2019-01-01 01:35:30 +00:00
Simon Kelley
65a01b71bb Tidy address-union handling: move class into explicit argument.
This moves the class argument to cache-insert into an argument,
rather then overloading a union in the address argument. Note that
tha class is NOT stored in the cache other than for DS/DNSKEY entries,
so must always be C_IN except for these. The data-extraction code
ensures this as it only attempts to cache C_IN class records.
2018-12-31 23:56:33 +00:00
Simon Kelley
bde46476ee Tidy all_addr union, merge log and rcode fields. 2018-12-31 23:28:24 +00:00
Simon Kelley
ee8750451b Remove ability to compile without IPv6 support.
This was the source of a large number of #ifdefs, originally
included for use with old embedded libc versions. I'm
sure no-one wants or needs IPv6-free code these days, so this
is a move towards more maintainable code.
2018-10-23 22:10:17 +01:00
Simon Kelley
a799ca0c63 Impove cache behaviour for TCP connections.
For ease of implementaion, dnsmasq has always forked a new process to
handle each incoming TCP connection. A side-effect of this is that any
DNS queries answered from TCP connections are not cached: when TCP
connections were rare, this was not a problem.  With the coming of
DNSSEC, it's now the case that some DNSSEC queries have answers which
spill to TCP, and if, for instance, this applies to the keys for the
root then those never get cached, and performance is very bad.  This
fix passes cache entries back from the TCP child process to the main
server process, and fixes the problem.
2018-10-18 19:35:29 +01:00
Simon Kelley
3a610a007f Finesse allocation of memory for "struct crec" cache entries.
These normally have enough space for a name of up to SMALLDNAME characters.
When used to hold /etc/hosts entries, they are allocated with just enough
bytes for the name held. When used to hold other configured stuff, (CNAMES
DS records. DHCP names etc), the name is replaced by a pointer to a string
held elsewhere, and F_NAMEP set. Hence only enough space to hold a char *
is needed, rather than SMALLDNAME bytes.
2018-09-26 16:50:35 +01:00
Simon Kelley
48b090cb5c Fix b6f926fbef to not SEGV on startup (rarely).
Many thanks to Kristian Evensen  for finding and diagnosing this.

We can't copy the whole of a crec structure in make_non_terminals, since
crec structures allocated to represent /etc/hosts entries are allocated with
just enough space for the actual name they contain, not the full
SMALLDNAME bytes declared in struct crec. Using structure copy therefore
copies beyond the end of the allocated source and, just occaisionally,
into unmapped memory, resulting in a SEGV.

Since the crecs we're making here always have F_NAMEP set, we're not
interested in copying the name field from the source anyway, we use the
namep part of the union and set it to point some way into the name
of the source crec to get the super-domain that we're representing.

The fix is therefore to copy the relevant fields of the crec, rather
than copying the whole and overwriting.
2018-09-26 12:53:59 +01:00
Simon Kelley
ea6cc33804 Handle memory allocation failure in make_non_terminals()
Thanks to Kristian Evensen for spotting the problem.
2018-09-18 23:21:17 +01:00
Simon Kelley
b758b67c37 Improve logging of RRs from --dns-rr. 2018-08-23 21:41:23 +01:00
Simon Kelley
cbfbd173c4 Fix broken DNSSEC records in previous. 2018-08-21 18:25:18 +01:00
Simon Kelley
b6f926fbef Don't return NXDOMAIN to empty non-terminals.
When a record is defined locally, eg an A record for one.two.example then
we already know that if we forward, eg an AAAA query for one.two.example,
and get back NXDOMAIN, then we need to alter that to NODATA. This is handled
by  check_for_local_domain(). But, if we forward two.example, because
one.two.example exists, then the answer to two.example should also be
a NODATA.

For most local records this is easy, just to substring matching.
for A, AAAA and CNAME records that are in the cache, it's more difficult.
The cache has no efficient way to find such records. The fix is to
insert empty (none of F_IPV4, F_IPV6 F_CNAME set) records for each
non-terminal.

The same considerations apply in auth mode, and the same basic mechanism
is used there too.
2018-08-21 17:46:52 +01:00
Julian Kornberger
aba8bbb6e3 Add collection of metrics
Data can be retreived via D-Bus und U-Bus
2018-07-21 21:55:08 +01:00