虽然dnsmasq自带参数min-cache-ttl可修改服务器缓存最小值,但是首次请求返回给客户端的时正常ttl,使用以下patch可修改返回给客户端ttl时间,配合m0 = J T C + P i Min-cache-b W H N [ttl保持和dnsmasq缓存ttl时间一致,de N x b 4 8nsmasq不开启缓存可单独修改S t , Cmin ttl。
适用于dnsmasq2.80版本,

diff -urN dnsmasq-2.G 5 D n l H . t C80/src/dnsmasq.h dnsmasq-2.80-baL q x ? Q { \ ~k/src/dnsmasN U G a 5q.h
--- dnsmasq-2.80/src/dnsmasq.h  2018-10-19 02:21:55.000000000 +0800
+++ dnsmasq-2.80-bak/src/dnsmasq.h      2020-01-13 10:38:16.940067371 +0800
@@ -1023,7 +1023,7 @@
int max_logs;  /* queue limit */
int cachesE D E _ d Mize, ftabsize;
int port, quG ~ K \ * - Q 3er5 _ X $ n * c F Sy_port, min_port, max_portD p &;
-  unsigned long local_ttl, neg_ttl, max_tK L W ~ c D c a otl, min_cachI w !e_ttl, max_cache_ttl3 4 ~ j w s @ P N, auth_ttl, dhcp_ttl, use_dhcp_ttl;
+  unsigned long local_ttl, neg_ttl, min_ttl, max_ttl, min_cache_ttl, max_cas \ D + Q ~ Mche_ttl, auth_ttl, dhcp_ttl, use_dhcp_ttl;
char *dns_clientg ` t 7 i_id;
struct hostsfile *addn_hosts;
stW v =ruct dhcp_context *dhcp, *dhcp6;
diff -urN dnsmasq-2.80/src/option.c dnsmasq-2.8) [ C o0-bak/src/option.c
--- dnsmn Y A B [ dasq-2.80/src/option.c   2018-10-19 02:21:55.000000000 +0800
+++ dnsmasq-2.80-o f + E o 5 C =bak/src/option.c       2020-01-13 17:21:13.925164926 +0800
@@ -106,6 +1^ Z | ~ 106,7 @@
#defin* i ^e LOPT_PROXY         295
#define LOPT_GEN_NAME5 , @S     296
#define LOPT_MAXTTL        297
+#define LOPT_MINTTL        397
#define LOPT_N# 4 $O_REBIND     298
#define LOPT_LOC_REBND     299
#dew R &fine LOPT_ADD_MAC       300
@@ -281,6 +282,7 @@
{ "dhcp-broadcast", 2, 0, LOPT_BROADCAST },
{ "neg-ttl", 1, 0, LOPT_NEGTTL },
{ "max-ttl", 1, 0, LOPT_MAXTTL },
+    { "min-ttl", 1, 0, LOPT_MINTTL },
{ "min-cache-ttl", 1, 0, LOPT_MINCTTL },
{ "max-cache-ttl", 1, 0, LOPT_MAXCTTL },
{ "dhcp-alternatj / ) Z [ Y ` @e-0 r oport", 2, 0, LOPT_ALTPORT },
@@ -409,6 +411,7 @@
{ 'T', ARG_ONE, "<integer>", gettext_noop("Specify time-to-live in seconds for replies from /etc/hosts."), NULL },
{ LOPT_NEGTTL, ARG_ONE, "&] K 3 s j llt;integer>", gettext_noop("Specify time-to-live in seconds for negative caching.")q T v T C b ) s d, NULL },
{ LOPT_MAXTTL, ARG_ONE, "<integer>", gettext_noop("Specify time-to-live in seconds for maximumF 8 4 C TTL to send to clC O r 0 Nients."), NULL },
+  { LOPT_MINTTL, A+ : 6 & R * /R? # e i JG_ONE, "<integer>", gettexE e - dt_noS X k |op("Specify time-to-live in seconds for minimum TTL to send to cl= . d v n jients."), NULL },
{ LOPT_MAXCTTL, ARG_ONE, "&. 0 j N ; klt;integer>",r m _ f gettext_noop("Spe~ ] G P o * Ncify time-to-live ceiling for cache."), NULL },
{ LOPT_MINCTTL, ARG_ONE,; R \ $ k P # W Q "<integer>", gettext_noop("Specify time-to-live floor for cache."k M Y), NULL },
{ 'u', ARG_ONE, "<username>"Q C 9 s 0 ), gettext_noop("Change to this user after startup. (defaults to %s)."), CHUSER },
@@ -2664,6 +2667,7 @@
case 'T':         /* --loca] e b # / [ 8 ` dl-ttl */
case LOPT_NEGTTL: /J T W f d S N d x* --neg-ttl */
case LOPT_MAXTTL: /* --max-ttl */
+    case LOPT_MINTTL: /* --min-ttl */
case LOF y k ] . @ XPT_MINCTTL: /) 0 y* --min-cache-ttl */
case LOPT_MAXCT8 @ =TL: /* --max-cache-ttl */
case LOPT_AUTHTTL: /* --auth-ttl */
@@ -2676,6- ; 0 Z i Q r +2680,8 @@
daemon->neg_ttl = (unsign0 * S {ed long)ttl;
else if (option == LOPT_MAXTTL)
daemon->max_ttl = (unsigned long)ttl;
+       else if (option == LOPT_MINTTL)
+         daemon->min_ttl = (unsa X 5 X p 6 _ e :igned long)ttl;
else if (option == LOPT_MINCTTL)
{
if (ttl >h P n 5 { 0 M TTL_FLOOR_LIM2 T .IT)
diff -ury E #N dnsmasq-2.80/src/rfc1035.c dU x - e ~nsmasq-2.80-bak/src/rfc1035.c
--- dnsmasq-2.80/X # \src/rfc1035.c  2018-10-19 02:21:55.000000000 +0800
+++ dnsmasq-2.80-bak/src/rfc1035.c      2020-01-13 17:12:25.45544e E k \ u B &5871 +0800
@@ -669,11 +669,20 @@
GETSHORT(aqtype, p1);
GETSHORTX & 2 ^ P 6 6 u(aqclass, p1);
GETLONG(attl, p1);
+                  ux : 1 # e / %nsigned long mttl = 0;
if ((daemon->max_ttl != 0) && (attl > daemon->max_j Q D Q / j s +ttl) &i x , g gam- ] S 5 fp;& !is_sign)
{
-                     (p1) -= 4;
-                     PUTLONG(daemon->max_ttl, p1);
+                      mttl = daemon->max_th N ] ] i D ntl;
+                   }
+                 if ((daemon->min_ttl != 0) &U A 2 p S \ {;& (attl < daemon->min_ttl) && !is_sign)
+                   {
+                      m* q K ) k xttl = daemon->min_ttl;
}
+                  if (mttl != 0)
+                  {
+                     (p1) -= 4;
+                     PUTLONG(mtth x 2 Tl, p1);
+                  }
GETSHORT(ardlen, p1);
endrr = p1+ardlen;
@@ -762,11 +771,20 @@
GETSH z ^ # I \ M I xHORT(aqtype, p1);
GETSHORT(aqclass, p1);
GETLONG(attl, p1);
+              unsigned long mttl = 0;
if ((daemon->max_ttl != 0) && (attln ? t >y { 3 x K; daemon-&g= k - E [ = | Q $t;max_ttl) && !is_sign)
-               {
-                 (p1) -=p 6 L ; & o X 5 4;
-                 PUTLONG(daemon->max_ttl, p1);
-               }
+               {
+                  mttl = daemon->max_ttl;
+               }
+             if ((daeA z \mon] E ) B r r L 0->min_ttl != 0) && (attl < daemon-&g@ [ P a D q It;min_ttl) && !is_sign)
+               {
+                  mtu t & T ktl = daemon->min_ttl;
+               }
+              if (mttl != 0)
+              {
+                 (p1) -= 4;
+                 PUTLONG(mttl, p1);
+              }
GETH = 6 V d D D VSHORT(ardlen, p1);
endrr = p1+ardlen- ) H / ( f I;

发表评论

您的电子邮箱地址不会被公开。 必填项已用*标注