dnsmasq: add support for mini-ttl

This commit is contained in:
CN_SZTL 2020-03-16 04:43:23 +08:00
parent 6f0f3c23fa
commit 81c88ae048
No known key found for this signature in database
GPG Key ID: 6850B6345C862176
4 changed files with 121 additions and 2 deletions

View File

@ -10,7 +10,7 @@ include $(TOPDIR)/rules.mk
PKG_NAME:=dnsmasq
PKG_UPSTREAM_VERSION:=2.81rc3
PKG_VERSION:=$(subst test,~~test,$(subst rc,~rc,$(PKG_UPSTREAM_VERSION)))
PKG_RELEASE:=2
PKG_RELEASE:=3
PKG_SOURCE:=$(PKG_NAME)-$(PKG_UPSTREAM_VERSION).tar.xz
PKG_SOURCE_URL:=http://thekelleys.org.uk/dnsmasq/release-candidates

View File

@ -871,6 +871,8 @@ dnsmasq_start()
append_parm "$cfg" logfacility "--log-facility"
append_parm "$cfg" mini_ttl "--min-ttl"
append_parm "$cfg" cachesize "--cache-size"
append_parm "$cfg" dnsforwardmax "--dns-forward-max"
append_parm "$cfg" port "--port"

View File

@ -0,0 +1,117 @@
diff --git a/src/dnsmasq.h b/src/dnsmasq.h
--- a/src/dnsmasq.h 2020-03-16 04:31:43.337573724 +0800
+++ b/src/dnsmasq.h 2020-03-16 04:32:07.138008046 +0800
@@ -1029,7 +1029,7 @@
int max_logs; /* queue limit */
int cachesize, ftabsize;
int port, query_port, min_port, max_port;
- unsigned long local_ttl, neg_ttl, max_ttl, min_cache_ttl, max_cache_ttl, auth_ttl, dhcp_ttl, use_dhcp_ttl;
+ unsigned long local_ttl, neg_ttl, max_ttl, max_ttl, min_cache_ttl, max_cache_ttl, auth_ttl, dhcp_ttl, use_dhcp_ttl;
char *dns_client_id;
struct hostsfile *addn_hosts;
struct dhcp_context *dhcp, *dhcp6;
diff --git a/src/option.c b/src/option.c
--- a/src/option.c 2020-03-16 04:33:35.999622026 +0800
+++ b/src/option.c 2020-03-16 04:40:44.839289942 +0800
@@ -105,6 +105,7 @@
#define LOPT_TAG_IF 294
#define LOPT_PROXY 295
#define LOPT_GEN_NAMES 296
+#define LOPT_MINTTL 361
#define LOPT_MAXTTL 297
#define LOPT_NO_REBIND 298
#define LOPT_LOC_REBND 299
@@ -167,7 +168,7 @@
#define LOPT_IGNORE_CLID 358
#define LOPT_SINGLE_PORT 359
#define LOPT_SCRIPT_TIME 360
-
+
#ifdef HAVE_GETOPT_LONG
static const struct option opts[] =
#else
@@ -284,6 +285,7 @@
{ "dhcp-name-match", 1, 0, LOPT_NAME_MATCH },
{ "dhcp-broadcast", 2, 0, LOPT_BROADCAST },
{ "neg-ttl", 1, 0, LOPT_NEGTTL },
+ { "min-ttl", 1, 0, LOPT_MINTTL },
{ "max-ttl", 1, 0, LOPT_MAXTTL },
{ "min-cache-ttl", 1, 0, LOPT_MINCTTL },
{ "max-cache-ttl", 1, 0, LOPT_MAXCTTL },
@@ -410,6 +412,7 @@
{ 't', ARG_ONE, "<host_name>", gettext_noop("Specify default target in an MX record."), NULL },
{ 'T', ARG_ONE, "<integer>", gettext_noop("Specify time-to-live in seconds for replies from /etc/hosts."), NULL },
{ LOPT_NEGTTL, ARG_ONE, "<integer>", gettext_noop("Specify time-to-live in seconds for negative caching."), NULL },
+ { LOPT_MINTTL, ARG_ONE, "<integer>", gettext_noop("Specify time-to-live in seconds for minimum TTL to send to clients."), NULL },
{ LOPT_MAXTTL, ARG_ONE, "<integer>", gettext_noop("Specify time-to-live in seconds for maximum TTL to send to clients."), NULL },
{ LOPT_MAXCTTL, ARG_ONE, "<integer>", gettext_noop("Specify time-to-live ceiling for cache."), NULL },
{ LOPT_MINCTTL, ARG_ONE, "<integer>", gettext_noop("Specify time-to-live floor for cache."), NULL },
@@ -2812,6 +2815,7 @@
case 'T': /* --local-ttl */
case LOPT_NEGTTL: /* --neg-ttl */
+ case LOPT_MINTTL: /* --min-ttl */
case LOPT_MAXTTL: /* --max-ttl */
case LOPT_MINCTTL: /* --min-cache-ttl */
case LOPT_MAXCTTL: /* --max-cache-ttl */
@@ -2823,6 +2827,8 @@
ret_err(gen_err);
else if (option == LOPT_NEGTTL)
daemon->neg_ttl = (unsigned long)ttl;
+ else if (option == LOPT_MINTTL)
+ daemon->min_ttl = (unsigned long)ttl;
else if (option == LOPT_MAXTTL)
daemon->max_ttl = (unsigned long)ttl;
else if (option == LOPT_MINCTTL)
diff --git a/src/rfc1035.c b/src/rfc1035.c
--- a/src/rfc1035.c 2020-03-08 23:56:19.000000000 +0800
+++ b/src/rfc1035.c 2020-03-16 04:41:50.888215364 +0800
@@ -664,11 +664,20 @@
GETSHORT(aqtype, p1);
GETSHORT(aqclass, p1);
GETLONG(attl, p1);
+ unsigned long mttl = 0;
if ((daemon->max_ttl != 0) && (attl > daemon->max_ttl) && !is_sign)
{
- (p1) -= 4;
- PUTLONG(daemon->max_ttl, p1);
- }
+ mttl = daemon->max_ttl;
+ }
+ if ((daemon->min_ttl != 0) && (attl < daemon->min_ttl) && !is_sign)
+ {
+ mttl = daemon->min_ttl;
+ }
+ if (mttl != 0)
+ {
+ (p1) -= 4;
+ PUTLONG(mttl, p1);
+ }
GETSHORT(ardlen, p1);
endrr = p1+ardlen;
@@ -760,11 +769,20 @@
GETSHORT(aqtype, p1);
GETSHORT(aqclass, p1);
GETLONG(attl, p1);
+ unsigned long mttl = 0;
if ((daemon->max_ttl != 0) && (attl > daemon->max_ttl) && !is_sign)
- {
- (p1) -= 4;
- PUTLONG(daemon->max_ttl, p1);
- }
+ {
+ mttl = daemon->max_ttl;
+ }
+ if ((daemon->min_ttl != 0) && (attl < daemon->min_ttl) && !is_sign)
+ {
+ mttl = daemon->min_ttl;
+ }
+ if (mttl != 0)
+ {
+ (p1) -= 4;
+ PUTLONG(mttl, p1);
+ }
GETSHORT(ardlen, p1);
endrr = p1+ardlen;

View File

@ -31,7 +31,7 @@ index d8c57d6..1cc65bf 100644
#define LOPT_IGNORE_CLID 358
#define LOPT_SINGLE_PORT 359
#define LOPT_SCRIPT_TIME 360
+#define LOPT_FILTER_AAAA 361
+#define LOPT_FILTER_AAAA 362
#ifdef HAVE_GETOPT_LONG
static const struct option opts[] =