From 81c88ae048cbd1c9d5024a18d646b87f9af4a86b Mon Sep 17 00:00:00 2001 From: CN_SZTL Date: Mon, 16 Mar 2020 04:43:23 +0800 Subject: [PATCH] dnsmasq: add support for mini-ttl --- package/network/services/dnsmasq/Makefile | 2 +- .../services/dnsmasq/files/dnsmasq.init | 2 + .../dnsmasq/patches/910-mini-ttl.patch | 117 ++++++++++++++++++ ...aa.patch => 911-dnsmasq-filter-aaaa.patch} | 2 +- 4 files changed, 121 insertions(+), 2 deletions(-) create mode 100644 package/network/services/dnsmasq/patches/910-mini-ttl.patch rename package/network/services/dnsmasq/patches/{996-dnsmasq-filter-aaaa.patch => 911-dnsmasq-filter-aaaa.patch} (98%) diff --git a/package/network/services/dnsmasq/Makefile b/package/network/services/dnsmasq/Makefile index 0bee31c0e6..3961770ca8 100644 --- a/package/network/services/dnsmasq/Makefile +++ b/package/network/services/dnsmasq/Makefile @@ -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 diff --git a/package/network/services/dnsmasq/files/dnsmasq.init b/package/network/services/dnsmasq/files/dnsmasq.init index 56a3553db3..954c629bca 100644 --- a/package/network/services/dnsmasq/files/dnsmasq.init +++ b/package/network/services/dnsmasq/files/dnsmasq.init @@ -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" diff --git a/package/network/services/dnsmasq/patches/910-mini-ttl.patch b/package/network/services/dnsmasq/patches/910-mini-ttl.patch new file mode 100644 index 0000000000..f9d9c1339a --- /dev/null +++ b/package/network/services/dnsmasq/patches/910-mini-ttl.patch @@ -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, "", gettext_noop("Specify default target in an MX record."), NULL }, + { 'T', ARG_ONE, "", gettext_noop("Specify time-to-live in seconds for replies from /etc/hosts."), NULL }, + { LOPT_NEGTTL, ARG_ONE, "", gettext_noop("Specify time-to-live in seconds for negative caching."), NULL }, ++ { LOPT_MINTTL, ARG_ONE, "", gettext_noop("Specify time-to-live in seconds for minimum TTL to send to clients."), NULL }, + { LOPT_MAXTTL, ARG_ONE, "", gettext_noop("Specify time-to-live in seconds for maximum TTL to send to clients."), NULL }, + { LOPT_MAXCTTL, ARG_ONE, "", gettext_noop("Specify time-to-live ceiling for cache."), NULL }, + { LOPT_MINCTTL, ARG_ONE, "", 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; + diff --git a/package/network/services/dnsmasq/patches/996-dnsmasq-filter-aaaa.patch b/package/network/services/dnsmasq/patches/911-dnsmasq-filter-aaaa.patch similarity index 98% rename from package/network/services/dnsmasq/patches/996-dnsmasq-filter-aaaa.patch rename to package/network/services/dnsmasq/patches/911-dnsmasq-filter-aaaa.patch index 2b28936ac1..7b8f0ce6ce 100644 --- a/package/network/services/dnsmasq/patches/996-dnsmasq-filter-aaaa.patch +++ b/package/network/services/dnsmasq/patches/911-dnsmasq-filter-aaaa.patch @@ -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[] =