[Dnsmasq-discuss] DNSMASQ Cache
John Gilmour
John.Gilmour at alliedtelesis.co.nz
Thu Jun 16 04:46:24 UTC 2022
Hello,
So, further to my email I have added the following lines to my version of dnsmasq:
src/cache.c/cache_reload:
/* Make non-terminal records for all locally-define RRs */
+ memset (&lrec, 0, sizeof (lrec));
lrec.flags = F_FORWARD | F_CONFIG | F_NAMEP | F_IMMORTAL;
src/cache.c/make_non_terminals:
if (crecp) {
+ memcpy(crecp, source, sizeof (source));
crecp->flags = (source->flags | F_NAMEP) & ~(F_IPV4 | F_IPV6 | F_CNAME | F_SRV | F_DNSKEY | F_DS | F_REVERSE);
- crecp->ttd = source->ttd;
crecp->name.namep = name;
Also, there seems to me to be a bug in make_non_terminals. As best as I can tell, there is a "daemon->txt" structure that contains a number of entries. These are added to the daemon in "src/option.c/read_opts":
#ifndef NO_ID
add_txt("version.bind", "dnsmasq-" VERSION, 0 );
add_txt("authors.bind", "Simon Kelley", 0);
.........
The call to cache_reload calls make_non_terminals:
for (txt = daemon->txt; txt; txt = txt->next)
{
lrec.name.namep = txt->name;
make_non_terminals(&lrec);
}
I believe that there should be 1 entry in the cache for each of the read_opts. But there is not. There is only one entry with the name "bind".
The comment for make_non_terminals says:
Creates empty cache entries for subnames (ie, for three.two.one, for two.one and one)
What is happening is that the function splits the string up by the delimiter ".". It does this by using:
while ((name = strchr (name, '.')))
name++;
So, when it gets to the following code the name equals "bind" and this is all it adds to the cache. Subsequent attempts to add new read_opts boil down to "bind" so after the reload the entire cache consists of only one "bind" entry.
crecp->flags = (source->flags | F_NAMEP) & ~(F_IPV4 | F_IPV6 | F_CNAME | F_SRV | F_DNSKEY | F_DS | F_REVERSE);
crecp->ttd = source->ttd;
crecp->name.namep = name;
cache_hash(crecp);
I am not sure what is supposed to be added to the cache - the full name, each delimited name, just the last name. If you could advise me on this function I would be eternally grateful.
Best regards,
John Gilmour
Senior Software engineer
Allied Telesis Labs | 27 Nazareth Ave | Christchurch 8024 | New Zealand
Phone: +64 3 339 9554
Fax: +64 3 339 3001
Web: alliedtelesis.com
________________________________
From: John Gilmour
Sent: Monday, 13 June 2022 7:16 p.m.
To: dnsmasq-discuss at lists.thekelleys.org.uk
Subject: DNSMASQ Cache
Hello,
First time user so please bear with me.
I have some quite specific in-house code that relies on the "cache->ttd" value. I have noticed that the function "cache_reload" in "src/cache.c" defines the following variable:
struct crec lrec
Further down in this function it makes non-terminal records for all locally-defined RRs. It may be more of a question but why are the "ttd", "uid" and "ns_id" fields not initialized before the various calls to "make_non_terminals(&lrec)". When I check the value of the "cache->ttd" in this function it's clearly just going to be random.
Is this just an oversight or is deliberately not set?
Best regards,
John.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.thekelleys.org.uk/pipermail/dnsmasq-discuss/attachments/20220616/5ad5058c/attachment.htm>
More information about the Dnsmasq-discuss
mailing list