如何知道 Dnsmasq 的最大 TTL 默认值

How to know the default value of maximum TTL for Dnsmasq

我可以通过 --max-ttl 使用 Dnsmasq 设置最大 TTL 值。但是我想知道如果我不设置--max-ttl默认值是多少。有人知道吗?

默认值为0

--max-ttl 选项设置了 max_ttl 属性,如下所示:

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;

是这样定义的,在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;

所以它的默认值是 0 根据 C 标准。

稍后,您可以在 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;