<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style type="text/css" style="display:none"><!--P{margin-top:0;margin-bottom:0;} p
        {margin-top:0;
        margin-bottom:0}--></style>
</head>
<body dir="ltr" style="font-size:12pt;color:#000000;background-color:#FFFFFF;font-family:Calibri,Arial,Helvetica,sans-serif;">
<p>Hello,</p>
<p><br>
</p>
<p>So, further to my email I have added the following lines to my version of dnsmasq:<br>
</p>
<p><br>
</p>
<p>src/cache.c/cache_reload:</p>
<p>   /* Make non-terminal records for all locally-define RRs */<br>
+  memset (&lrec, 0, sizeof (lrec));<br>
   lrec.flags = F_FORWARD | F_CONFIG | F_NAMEP | F_IMMORTAL;</p>
<p><br>
</p>
<p>src/cache.c/make_non_terminals:</p>
<p>       if (crecp)        {<br>
+      memcpy(crecp, source, sizeof (source));<br>
          crecp->flags = (source->flags | F_NAMEP) & ~(F_IPV4 | F_IPV6 | F_CNAME | F_SRV | F_DNSKEY | F_DS | F_REVERSE);<br>
-         crecp->ttd = source->ttd;<br>
          crecp->name.namep = name;<br>
</p>
<p><br>
</p>
<p><br>
</p>
<p>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":<br>
#ifndef NO_ID<br>
add_txt("version.bind", "dnsmasq-" VERSION, 0 );<br>
add_txt("authors.bind", "Simon Kelley", 0);</p>
<p>.........</p>
<p><br>
</p>
<p>The call to cache_reload calls make_non_terminals:</p>
<p>  for (txt = daemon->txt; txt; txt = txt->next)<br>
    {<br>
      lrec.name.namep = txt->name;<br>
      make_non_terminals(&lrec);<br>
    }</p>
<p><br>
</p>
<p>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".  </p>
<p><br>
</p>
The comment for make_non_terminals says:<br>
<p>      Creates empty cache entries for subnames (ie, for three.two.one, for two.one and one)</p>
<p><br>
</p>
<p>What is happening is that the function splits the string up by the delimiter ".". It does this by using:</p>
<p>while ((name = strchr (name, '.')))</p>
<p>    name++;<br>
</p>
<p><br>
</p>
<p>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.<br>
</p>
<p>      crecp->flags = (source->flags | F_NAMEP) & ~(F_IPV4 | F_IPV6 | F_CNAME | F_SRV | F_DNSKEY | F_DS | F_REVERSE);<br>
</p>
<p>      crecp->ttd = source->ttd;<br>
</p>
<p>      crecp->name.namep = name;<br>
      cache_hash(crecp);<br>
</p>
<p><br>
</p>
<p>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.<br>
</p>
<p><br>
</p>
<div id="Signature">
<div name="divtagdefaultwrapper" style="font-family:Calibri,Arial,Helvetica,sans-serif; font-size:; margin:0">
<span lang="en-NZ">
<div style="margin:0"><font size="2" face="Calibri,sans-serif"><span style="font-size:11pt"><font size="2" face="Arial,sans-serif"><span style="font-size:10pt">Best regards,<br>
<b><br>
John Gilmour<br>
</b></span></font></span></font></div>
<div style="margin:0"><font size="2" face="Calibri,sans-serif"><span style="font-size:11pt"><font size="2" face="Arial,sans-serif"><span style="font-size:9pt">Senior Software engineer<br>
</span></font></span></font></div>
<div style="margin:0"><font size="2" face="Calibri,sans-serif"><span style="font-size:11pt"><font size="2" face="Arial,sans-serif"><span style="font-size:9pt"><b>Allied Telesis Labs</b></span></font> |
<font size="2" face="Arial,sans-serif"><span style="font-size:9pt">27 Nazareth Ave | Christchurch 8024 | New Zealand</span></font></span></font></div>
<div style="margin:0"><font size="2" face="Calibri,sans-serif"><span style="font-size:11pt"><font size="2" face="Arial,sans-serif"><span style="font-size:9pt">Phone: +64 3 339 9554<br>
Fax: +64 3 339 3001</span></font><font size="2" face="Arial,sans-serif"><span style="font-size:9pt">
<br>
</span></font></span></font></div>
<div style="margin:0"><font size="2" face="Calibri,sans-serif"><span style="font-size:11pt"><font size="2" face="Arial,sans-serif"><span style="font-size:9pt">Web:
</span></font><a tabindex="-1" id="NoLP"><font size="2" face="Arial,sans-serif"><span style="font-size:9pt"><b><font color="black">alliedtelesis</font><font color="black"><span style="font-weight:normal">.com
</span></font></b></span></font></a><br>
</span></font><br>
<br>
<br>
</div>
</span></div>
</div>
<div dir="ltr" style="font-size:12pt; color:#000000; background-color:#FFFFFF; font-family:Calibri,Arial,Helvetica,sans-serif">
<hr tabindex="-1" style="display:inline-block; width:98%">
<div id="divRplyFwdMsg" dir="ltr"><font style="font-size:11pt" face="Calibri, sans-serif" color="#000000"><b>From:</b> John Gilmour<br>
<b>Sent:</b> Monday, 13 June 2022 7:16 p.m.<br>
<b>To:</b> dnsmasq-discuss@lists.thekelleys.org.uk<br>
<b>Subject:</b> DNSMASQ Cache </font>
<div> </div>
</div>
<div>
<p>Hello,</p>
<p><br>
</p>
<p>First time user so please bear with me.</p>
<p><br>
</p>
<p>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:<br>
struct crec lrec</p>
<p><br>
</p>
<p>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.</p>
<p><br>
</p>
<p>Is this just an oversight or is deliberately not set?</p>
<p><br>
</p>
<p>Best regards,</p>
<p><br>
</p>
<p>John.<br>
</p>
</div>
</div>
</body>
</html>