[Dnsmasq-discuss] Fwd: Fwd: [PATCH] Addressing hostsdir shortcomings
Simon Kelley
simon at thekelleys.org.uk
Sun Oct 16 21:32:17 UTC 2022
Patches applied with some changes.
Simon.
On 15/10/2022 07:57, Dominik Derigs wrote:
> Hey all,
>
> and here comes the third resubmission of my patches. I do still
> believe that they are improvements. Even one year after writing
> them, them do still apply cleanly on the master branch.
>
> Best,
> Dominik
>
> -------- Forwarded Message --------
> From: Dominik Derigs <dl6er at dl6er.de>
> To: dnsmasq-discuss at lists.thekelleys.org.uk
> <dnsmasq-discuss at lists.thekelleys.org.uk>, Simon Kelley
> <simon at thekelleys.org.uk>
> Subject: Fwd: [PATCH] Addressing hostsdir shortcomings
> Date: Sat, 02 Apr 2022 21:32:30 +0200
>
> Dear Simon,
>
> Second resubmission of my patches.
> They still apply cleanly to current master.
>
> Best,
> Dominik
>
> -------- Forwarded Message --------
> From: Dominik Derigs <dl6er at dl6er.de>
> To: dnsmasq-discuss at lists.thekelleys.org.uk
> <dnsmasq-discuss at lists.thekelleys.org.uk>, Simon Kelley
> <simon at thekelleys.org.uk>
> Subject: [PATCH] Addressing hostsdir shortcomings
> Date: Sat, 08 Jan 2022 11:45:32 +0100
>
> Hey Simon,
>
> dnsmasq v2.73 added --hostsdir which is an efficient way of re-
> loading only parts of the cache. When we tried to use hostsdir
> yesterday, we identified three problems. They are described
> below. Patches addressing them are attached.
>
> --- ISSUE 1 --- Logging imprecision
>
> Assume you have multiple files in hostsdir, dnsmasq can only log
> the directory not the file that was the real source:
>
> dnsmasq: read /home/test/hostsdir/hosts1 - 1 addresses
> dnsmasq: read /home/test/hostsdir/hosts2 - 1 addresses
> dnsmasq: read /home/test/hostsdir/hosts3 - 1 addresses
>
> dnsmasq: 1 127.0.0.1/34170 query[A] aaa from 127.0.0.1
> dnsmasq: 1 127.0.0.1/34170 /home/test/hostsdir aaa is 192.168.1.2
> dnsmasq: 1 127.0.0.1/34170 /home/test/hostsdir aaa is 192.168.1.1
> dnsmasq: 1 127.0.0.1/34170 /home/test/hostsdir aaa is 192.168.1.2
>
> This happens because the cache entries all use the same index
> that is the directory name.
>
> --- ISSUE 2 --- Outdated entries are not removed
>
> When hostsdir re-reads the file, it does not remove outdated
> entries. Assume you modify "192.168.1.1 aaa" to "192.168.1.2
> aaa", dnsmasq will now serve two A records for "aaa". This may be
> considered okay, however, if I add "192.168.1.1 bbb", PTR
> requests for this domain will still be replied with "aaa" which
> might be completely outdated information.
>
> --- ISSUE 3 --- Ever growing replies under certain situations
>
> When a users uses an editor that creates (temporary) files during
> editing (like "sed -i") or uses a script that writes files line
> by line (like "echo '' >> file"), they can quickly end up with
> strange things like
>
> dnsmasq: 3 127.0.0.1/34170 query[A] aaa from 127.0.0.1
> dnsmasq: 3 127.0.0.1/34170 /home/test/hostsdir aaa is 192.168.1.2
> dnsmasq: 3 127.0.0.1/34170 /home/test/hostsdir aaa is 192.168.1.1
> dnsmasq: 3 127.0.0.1/34170 /home/test/hostsdir aaa is 192.168.1.2
> dnsmasq: 3 127.0.0.1/34170 /home/test/hostsdir aaa is 192.168.1.2
> dnsmasq: 3 127.0.0.1/34170 /home/test/hostsdir aaa is 192.168.1.2
> dnsmasq: 3 127.0.0.1/34170 /home/test/hostsdir aaa is 192.168.1.2
> dnsmasq: 3 127.0.0.1/34170 /home/test/hostsdir aaa is 192.168.1.2
> dnsmasq: 3 127.0.0.1/34170 /home/test/hostsdir aaa is 192.168.1.2
> dnsmasq: 3 127.0.0.1/34170 /home/test/hostsdir aaa is 192.168.1.2
>
> which is not very meaningful. We check for duplicates before
> inserting into the cache, however, duplicate checking can be
> foiled here: add_hosts_entry() calls cache_find_by_name() only
> once (say it returned "192.168.1.1") so the memcmp() on the
> address fails and we can add an arbitrary amount of 192.168.1.2
> entries.
>
> For addressing issue 1, I added a new struct *dyndir having a
> linked list of struct *hostsfile. With this, cache_insert() can
> get the correct index. If a file is newly added, we just add a
> new *hostsfile entry to the list (index++).
>
> Issue 2 is an easy one as we can selectively clean the cache when
> we know the uid to be removed. This can be called before running
> read_hostsfile() to insert new stuff. I added MOVE_FROM and
> DELETE to inotify_add_watch() so we catch if a file was removed.
> In this case, we only remove old entries.
>
> Issue 3 is fixed by adding a loop over cache_find_by_name() in
> add_hosts_entry() to check possible multiple records.
>
> Best,
> Dominik
>
> [sent earlier as
> https://lists.thekelleys.org.uk/pipermail/dnsmasq-discuss/2021q3/015704.html
> ,
> resubmitting patches rebased on latest master]
>
>
More information about the Dnsmasq-discuss
mailing list