Search code examples
dnsdnsmasq

How to know the default value of maximum TTL for Dnsmasq


I’m able to set a maximum TTL value with Dnsmasq by --max-ttl. But I wonder what the default value is if I don’t set --max-ttl. Does anyone know about it?


Solution

  • The default value is 0.

    The --max-ttl option sets up the max_ttl attribute as witnessed there:

    https://thekelleys.org.uk/gitweb/?p=dnsmasq.git;a=blob;f=src/option.c;h=3a870970b82335dcfa59b5cf1ad0ce765d4484a3;hb=HEAD#l3061

    3060         else if (option == LOPT_MAXTTL)
    3061           daemon->max_ttl = (unsigned long)ttl;
    

    It is defined like that, in src/dnsmasq.h:

    extern struct daemon {
      /* datastuctures representing the command-line and
         config file arguments. All set (including defaults)
         in option.c */
    
    [..]
    
      unsigned long local_ttl, neg_ttl, max_ttl, min_cache_ttl, max_cache_ttl, auth_ttl, dhcp_ttl, use_dhcp_ttl;
    

    So its default value is 0 per the C standard.

    Later, you can find tests on that value to trigger specific behavior in src/rfc1035.c:

      /* Return the Max TTL value if it is lower than the actual TTL */
      if (daemon->max_ttl == 0 || ((unsigned)(crecp->ttd - now) < daemon->max_ttl))
        return crecp->ttd - now;
      else
        return daemon->max_ttl;