mirror of
http://thekelleys.org.uk/git/dnsmasq.git
synced 2026-11-27 20:58:36 +00:00
Add --use-stale-cache option.
This commit is contained in:
8 files changed
+228
-66
No files matched your search
@@ -90,6 +90,16 @@ version 2.87
|
|||||||
when doing DNSSEC over unreliable upstream network. It comes
|
when doing DNSSEC over unreliable upstream network. It comes
|
||||||
with some cost in memory usage and network bandwidth.
|
with some cost in memory usage and network bandwidth.
|
||||||
|
|
||||||
|
Add -use-stale-cache option. When set, if a DNS name exists
|
||||||
|
in the cache, but its time-to-live has expired, dnsmasq will
|
||||||
|
return the data anyway. (It attempts to refresh the
|
||||||
|
data with an upstream query after returning the stale data.)
|
||||||
|
This can improve speed and reliability. It comes
|
||||||
|
at the expense of sometimes returning out-of-date data and
|
||||||
|
less efficient cache utilisation, since old data cannot be
|
||||||
|
flushed when its TTL expires, so the cache becomes
|
||||||
|
strictly least-recently-used.
|
||||||
|
|
||||||
|
|
||||||
version 2.86
|
version 2.86
|
||||||
Handle DHCPREBIND requests in the DHCPv6 server code.
|
Handle DHCPREBIND requests in the DHCPv6 server code.
|
||||||
|
|||||||
@@ -812,6 +812,12 @@ Disable negative caching. Negative caching allows dnsmasq to remember
|
|||||||
"no such domain" answers from upstream nameservers and answer
|
"no such domain" answers from upstream nameservers and answer
|
||||||
identical queries without forwarding them again.
|
identical queries without forwarding them again.
|
||||||
.TP
|
.TP
|
||||||
|
.B --use-stale-cache
|
||||||
|
When set, if a DNS name exists in the cache, but its time-to-live has expired, dnsmasq will return the data anyway. (It attempts to refresh the
|
||||||
|
data with an upstream query after returning the stale data.) This can improve speed and reliability. It comes at the expense
|
||||||
|
of sometimes returning out-of-date data and less efficient cache utilisation, since old data cannot be flushed when its TTL expires, so the cache becomes
|
||||||
|
strictly least-recently-used.
|
||||||
|
.TP
|
||||||
.B \-0, --dns-forward-max=<queries>
|
.B \-0, --dns-forward-max=<queries>
|
||||||
Set the maximum number of concurrent DNS queries. The default value is
|
Set the maximum number of concurrent DNS queries. The default value is
|
||||||
150, which should be fine for most setups. The only known situation
|
150, which should be fine for most setups. The only known situation
|
||||||
|
|||||||
@@ -374,6 +374,10 @@ static int is_outdated_cname_pointer(struct crec *crecp)
|
|||||||
|
|
||||||
static int is_expired(time_t now, struct crec *crecp)
|
static int is_expired(time_t now, struct crec *crecp)
|
||||||
{
|
{
|
||||||
|
/* Don't dump expired entries if we're using them, cache becomes strictly LRU in that case. */
|
||||||
|
if (option_bool(OPT_STALE_CACHE))
|
||||||
|
return 0;
|
||||||
|
|
||||||
if (crecp->flags & F_IMMORTAL)
|
if (crecp->flags & F_IMMORTAL)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
@@ -2079,6 +2083,8 @@ void log_query(unsigned int flags, char *name, union all_addr *addr, char *arg,
|
|||||||
name = arg;
|
name = arg;
|
||||||
verb = daemon->addrbuff;
|
verb = daemon->addrbuff;
|
||||||
}
|
}
|
||||||
|
else if (flags & F_STALE)
|
||||||
|
source = "cached-stale";
|
||||||
else
|
else
|
||||||
source = "cached";
|
source = "cached";
|
||||||
|
|
||||||
|
|||||||
@@ -2015,9 +2015,6 @@ static void check_dns_listeners(time_t now)
|
|||||||
|
|
||||||
buff = tcp_request(confd, now, &tcp_addr, netmask, auth_dns);
|
buff = tcp_request(confd, now, &tcp_addr, netmask, auth_dns);
|
||||||
|
|
||||||
shutdown(confd, SHUT_RDWR);
|
|
||||||
close(confd);
|
|
||||||
|
|
||||||
if (buff)
|
if (buff)
|
||||||
free(buff);
|
free(buff);
|
||||||
|
|
||||||
|
|||||||
+5
-2
@@ -279,7 +279,8 @@ struct event_desc {
|
|||||||
#define OPT_FILTER_AAAA 68
|
#define OPT_FILTER_AAAA 68
|
||||||
#define OPT_STRIP_ECS 69
|
#define OPT_STRIP_ECS 69
|
||||||
#define OPT_STRIP_MAC 70
|
#define OPT_STRIP_MAC 70
|
||||||
#define OPT_LAST 71
|
#define OPT_STALE_CACHE 71
|
||||||
|
#define OPT_LAST 72
|
||||||
|
|
||||||
#define OPTION_BITS (sizeof(unsigned int)*8)
|
#define OPTION_BITS (sizeof(unsigned int)*8)
|
||||||
#define OPTION_SIZE ( (OPT_LAST/OPTION_BITS)+((OPT_LAST%OPTION_BITS)!=0) )
|
#define OPTION_SIZE ( (OPT_LAST/OPTION_BITS)+((OPT_LAST%OPTION_BITS)!=0) )
|
||||||
@@ -510,6 +511,7 @@ struct crec {
|
|||||||
#define F_DOMAINSRV (1u<<28)
|
#define F_DOMAINSRV (1u<<28)
|
||||||
#define F_RCODE (1u<<29)
|
#define F_RCODE (1u<<29)
|
||||||
#define F_SRV (1u<<30)
|
#define F_SRV (1u<<30)
|
||||||
|
#define F_STALE (1u<<31)
|
||||||
|
|
||||||
#define UID_NONE 0
|
#define UID_NONE 0
|
||||||
/* Values of uid in crecs with F_CONFIG bit set. */
|
/* Values of uid in crecs with F_CONFIG bit set. */
|
||||||
@@ -1340,7 +1342,8 @@ void report_addresses(struct dns_header *header, size_t len, u32 mark);
|
|||||||
#endif
|
#endif
|
||||||
size_t answer_request(struct dns_header *header, char *limit, size_t qlen,
|
size_t answer_request(struct dns_header *header, char *limit, size_t qlen,
|
||||||
struct in_addr local_addr, struct in_addr local_netmask,
|
struct in_addr local_addr, struct in_addr local_netmask,
|
||||||
time_t now, int ad_reqd, int do_bit, int have_pseudoheader);
|
time_t now, int ad_reqd, int do_bit, int have_pseudoheader,
|
||||||
|
int *stale);
|
||||||
int check_for_bogus_wildcard(struct dns_header *header, size_t qlen, char *name,
|
int check_for_bogus_wildcard(struct dns_header *header, size_t qlen, char *name,
|
||||||
time_t now);
|
time_t now);
|
||||||
int check_for_ignored_address(struct dns_header *header, size_t qlen);
|
int check_for_ignored_address(struct dns_header *header, size_t qlen);
|
||||||
|
|||||||
+131
-48
@@ -1183,11 +1183,6 @@ void reply_query(int fd, time_t now)
|
|||||||
else if (udp_size < PACKETSZ)
|
else if (udp_size < PACKETSZ)
|
||||||
udp_size = PACKETSZ; /* Sanity check - can't reduce below default. RFC 6891 6.2.3 */
|
udp_size = PACKETSZ; /* Sanity check - can't reduce below default. RFC 6891 6.2.3 */
|
||||||
|
|
||||||
if (!is_sign &&
|
|
||||||
(nn = resize_packet(header, (size_t)n, pheader, plen)) &&
|
|
||||||
(forward->flags & FREC_DO_QUESTION))
|
|
||||||
add_do_bit(header, nn, (unsigned char *)pheader + plen);
|
|
||||||
|
|
||||||
header->ancount = htons(0);
|
header->ancount = htons(0);
|
||||||
header->nscount = htons(0);
|
header->nscount = htons(0);
|
||||||
header->arcount = htons(0);
|
header->arcount = htons(0);
|
||||||
@@ -1197,6 +1192,11 @@ void reply_query(int fd, time_t now)
|
|||||||
header->hb4 |= HB4_CD;
|
header->hb4 |= HB4_CD;
|
||||||
if (forward->flags & FREC_AD_QUESTION)
|
if (forward->flags & FREC_AD_QUESTION)
|
||||||
header->hb4 |= HB4_AD;
|
header->hb4 |= HB4_AD;
|
||||||
|
|
||||||
|
if (!is_sign &&
|
||||||
|
(nn = resize_packet(header, (size_t)n, pheader, plen)) &&
|
||||||
|
(forward->flags & FREC_DO_QUESTION))
|
||||||
|
add_do_bit(header, nn, (unsigned char *)pheader + plen);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1343,10 +1343,6 @@ static void return_reply(time_t now, struct frec *forward, struct dns_header *he
|
|||||||
{
|
{
|
||||||
header->id = htons(src->orig_id);
|
header->id = htons(src->orig_id);
|
||||||
|
|
||||||
#ifdef HAVE_DUMPFILE
|
|
||||||
dump_packet_udp(DUMP_REPLY, daemon->packet, (size_t)nn, NULL, &src->source, src->fd);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if defined(HAVE_CONNTRACK) && defined(HAVE_UBUS)
|
#if defined(HAVE_CONNTRACK) && defined(HAVE_UBUS)
|
||||||
if (option_bool(OPT_CMARK_ALST_EN))
|
if (option_bool(OPT_CMARK_ALST_EN))
|
||||||
{
|
{
|
||||||
@@ -1357,14 +1353,20 @@ static void return_reply(time_t now, struct frec *forward, struct dns_header *he
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
send_from(src->fd, option_bool(OPT_NOWILD) || option_bool (OPT_CLEVERBIND), daemon->packet, nn,
|
if (src->fd != -1)
|
||||||
&src->source, &src->dest, src->iface);
|
|
||||||
|
|
||||||
if (option_bool(OPT_EXTRALOG) && src != &forward->frec_src)
|
|
||||||
{
|
{
|
||||||
daemon->log_display_id = src->log_id;
|
#ifdef HAVE_DUMPFILE
|
||||||
daemon->log_source_addr = &src->source;
|
dump_packet_udp(DUMP_REPLY, daemon->packet, (size_t)nn, NULL, &src->source, src->fd);
|
||||||
log_query(F_UPSTREAM, "query", NULL, "duplicate", 0);
|
#endif
|
||||||
|
send_from(src->fd, option_bool(OPT_NOWILD) || option_bool (OPT_CLEVERBIND), daemon->packet, nn,
|
||||||
|
&src->source, &src->dest, src->iface);
|
||||||
|
|
||||||
|
if (option_bool(OPT_EXTRALOG) && src != &forward->frec_src)
|
||||||
|
{
|
||||||
|
daemon->log_display_id = src->log_id;
|
||||||
|
daemon->log_source_addr = &src->source;
|
||||||
|
log_query(F_UPSTREAM, "query", NULL, "duplicate", 0);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1777,13 +1779,17 @@ void receive_query(struct listener *listen, time_t now)
|
|||||||
#endif
|
#endif
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
int stale;
|
||||||
int ad_reqd = do_bit;
|
int ad_reqd = do_bit;
|
||||||
|
u16 hb3 = header->hb3, hb4 = header->hb4;
|
||||||
|
int fd = listen->fd;
|
||||||
|
|
||||||
/* RFC 6840 5.7 */
|
/* RFC 6840 5.7 */
|
||||||
if (header->hb4 & HB4_AD)
|
if (header->hb4 & HB4_AD)
|
||||||
ad_reqd = 1;
|
ad_reqd = 1;
|
||||||
|
|
||||||
m = answer_request(header, ((char *) header) + udp_size, (size_t)n,
|
m = answer_request(header, ((char *) header) + udp_size, (size_t)n,
|
||||||
dst_addr_4, netmask, now, ad_reqd, do_bit, have_pseudoheader);
|
dst_addr_4, netmask, now, ad_reqd, do_bit, have_pseudoheader, &stale);
|
||||||
|
|
||||||
if (m >= 1)
|
if (m >= 1)
|
||||||
{
|
{
|
||||||
@@ -1798,11 +1804,36 @@ void receive_query(struct listener *listen, time_t now)
|
|||||||
(char *)header, m, &source_addr, &dst_addr, if_index);
|
(char *)header, m, &source_addr, &dst_addr, if_index);
|
||||||
daemon->metrics[METRIC_DNS_LOCAL_ANSWERED]++;
|
daemon->metrics[METRIC_DNS_LOCAL_ANSWERED]++;
|
||||||
}
|
}
|
||||||
else if (forward_query(listen->fd, &source_addr, &dst_addr, if_index,
|
|
||||||
header, (size_t)n, ((char *) header) + udp_size, now, NULL, ad_reqd, do_bit))
|
if (m == 0 || stale)
|
||||||
daemon->metrics[METRIC_DNS_QUERIES_FORWARDED]++;
|
{
|
||||||
else
|
if (m != 0)
|
||||||
daemon->metrics[METRIC_DNS_LOCAL_ANSWERED]++;
|
{
|
||||||
|
size_t plen;
|
||||||
|
|
||||||
|
/* We answered with stale cache data, so forward the query anyway to
|
||||||
|
refresh that. Restore the query from the answer packet. */
|
||||||
|
pheader = find_pseudoheader(header, (size_t)m, &plen, NULL, NULL, NULL);
|
||||||
|
|
||||||
|
header->hb3 = hb3;
|
||||||
|
header->hb4 = hb4;
|
||||||
|
header->ancount = htons(0);
|
||||||
|
header->nscount = htons(0);
|
||||||
|
header->arcount = htons(0);
|
||||||
|
|
||||||
|
m = resize_packet(header, m, pheader, plen);
|
||||||
|
|
||||||
|
/* We've already answered the client, so don't send it the answer
|
||||||
|
when it comes back. */
|
||||||
|
fd = -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (forward_query(fd, &source_addr, &dst_addr, if_index,
|
||||||
|
header, (size_t)n, ((char *) header) + udp_size, now, NULL, ad_reqd, do_bit))
|
||||||
|
daemon->metrics[METRIC_DNS_QUERIES_FORWARDED]++;
|
||||||
|
else
|
||||||
|
daemon->metrics[METRIC_DNS_LOCAL_ANSWERED]++;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2029,8 +2060,9 @@ unsigned char *tcp_request(int confd, time_t now,
|
|||||||
unsigned char *pheader;
|
unsigned char *pheader;
|
||||||
unsigned int mark = 0;
|
unsigned int mark = 0;
|
||||||
int have_mark = 0;
|
int have_mark = 0;
|
||||||
int first, last;
|
int first, last, stale, do_stale = 0;
|
||||||
unsigned int flags = 0;
|
unsigned int flags = 0;
|
||||||
|
u16 hb3, hb4;
|
||||||
|
|
||||||
if (!packet || getpeername(confd, (struct sockaddr *)&peer_addr, &peer_len) == -1)
|
if (!packet || getpeername(confd, (struct sockaddr *)&peer_addr, &peer_len) == -1)
|
||||||
return packet;
|
return packet;
|
||||||
@@ -2085,12 +2117,36 @@ unsigned char *tcp_request(int confd, time_t now,
|
|||||||
{
|
{
|
||||||
int ede = EDE_UNSET;
|
int ede = EDE_UNSET;
|
||||||
|
|
||||||
if (query_count == TCP_MAX_QUERIES ||
|
if (query_count == TCP_MAX_QUERIES)
|
||||||
!packet ||
|
return packet;
|
||||||
!read_write(confd, &c1, 1, 1) || !read_write(confd, &c2, 1, 1) ||
|
|
||||||
!(size = c1 << 8 | c2) ||
|
if (do_stale)
|
||||||
!read_write(confd, payload, size, 1))
|
{
|
||||||
return packet;
|
size_t plen;
|
||||||
|
|
||||||
|
/* We answered the last query with stale data. Now try and get fresh data.
|
||||||
|
Restore query from answer. */
|
||||||
|
pheader = find_pseudoheader(header, m, &plen, NULL, NULL, NULL);
|
||||||
|
|
||||||
|
header->hb3 = hb3;
|
||||||
|
header->hb4 = hb4;
|
||||||
|
header->ancount = htons(0);
|
||||||
|
header->nscount = htons(0);
|
||||||
|
header->arcount = htons(0);
|
||||||
|
|
||||||
|
size = resize_packet(header, m, pheader, plen);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (!read_write(confd, &c1, 1, 1) || !read_write(confd, &c2, 1, 1) ||
|
||||||
|
!(size = c1 << 8 | c2) ||
|
||||||
|
!read_write(confd, payload, size, 1))
|
||||||
|
return packet;
|
||||||
|
|
||||||
|
/* for stale-answer processing. */
|
||||||
|
hb3 = header->hb3;
|
||||||
|
hb4 = header->hb4;
|
||||||
|
}
|
||||||
|
|
||||||
if (size < (int)sizeof(struct dns_header))
|
if (size < (int)sizeof(struct dns_header))
|
||||||
continue;
|
continue;
|
||||||
@@ -2116,24 +2172,27 @@ unsigned char *tcp_request(int confd, time_t now,
|
|||||||
struct auth_zone *zone;
|
struct auth_zone *zone;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
log_query_mysockaddr(F_QUERY | F_FORWARD, daemon->namebuff,
|
|
||||||
&peer_addr, auth_dns ? "auth" : "query", qtype);
|
|
||||||
|
|
||||||
#ifdef HAVE_CONNTRACK
|
#ifdef HAVE_CONNTRACK
|
||||||
is_single_query = 1;
|
is_single_query = 1;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
if (!do_stale)
|
||||||
|
{
|
||||||
|
log_query_mysockaddr(F_QUERY | F_FORWARD, daemon->namebuff,
|
||||||
|
&peer_addr, auth_dns ? "auth" : "query", qtype);
|
||||||
|
|
||||||
#ifdef HAVE_AUTH
|
#ifdef HAVE_AUTH
|
||||||
/* find queries for zones we're authoritative for, and answer them directly */
|
/* find queries for zones we're authoritative for, and answer them directly */
|
||||||
if (!auth_dns && !option_bool(OPT_LOCALISE))
|
if (!auth_dns && !option_bool(OPT_LOCALISE))
|
||||||
for (zone = daemon->auth_zones; zone; zone = zone->next)
|
for (zone = daemon->auth_zones; zone; zone = zone->next)
|
||||||
if (in_zone(zone, daemon->namebuff, NULL))
|
if (in_zone(zone, daemon->namebuff, NULL))
|
||||||
{
|
{
|
||||||
auth_dns = 1;
|
auth_dns = 1;
|
||||||
local_auth = 1;
|
local_auth = 1;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
norebind = domain_no_rebind(daemon->namebuff);
|
norebind = domain_no_rebind(daemon->namebuff);
|
||||||
@@ -2190,9 +2249,12 @@ unsigned char *tcp_request(int confd, time_t now,
|
|||||||
if (header->hb4 & HB4_AD)
|
if (header->hb4 & HB4_AD)
|
||||||
ad_reqd = 1;
|
ad_reqd = 1;
|
||||||
|
|
||||||
/* m > 0 if answered from cache */
|
if (do_stale)
|
||||||
m = answer_request(header, ((char *) header) + 65536, (size_t)size,
|
m = 0;
|
||||||
dst_addr_4, netmask, now, ad_reqd, do_bit, have_pseudoheader);
|
else
|
||||||
|
/* m > 0 if answered from cache */
|
||||||
|
m = answer_request(header, ((char *) header) + 65536, (size_t)size,
|
||||||
|
dst_addr_4, netmask, now, ad_reqd, do_bit, have_pseudoheader, &stale);
|
||||||
|
|
||||||
/* Do this by steam now we're not in the select() loop */
|
/* Do this by steam now we're not in the select() loop */
|
||||||
check_log_writer(1);
|
check_log_writer(1);
|
||||||
@@ -2311,6 +2373,9 @@ unsigned char *tcp_request(int confd, time_t now,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (do_stale)
|
||||||
|
break;
|
||||||
|
|
||||||
/* In case of local answer or no connections made. */
|
/* In case of local answer or no connections made. */
|
||||||
if (m == 0)
|
if (m == 0)
|
||||||
{
|
{
|
||||||
@@ -2322,10 +2387,10 @@ unsigned char *tcp_request(int confd, time_t now,
|
|||||||
{
|
{
|
||||||
u16 swap = htons((u16)ede);
|
u16 swap = htons((u16)ede);
|
||||||
|
|
||||||
if (ede != EDE_UNSET)
|
if (ede != EDE_UNSET)
|
||||||
m = add_pseudoheader(header, m, ((unsigned char *) header) + 65536, daemon->edns_pktsz, EDNS0_OPTION_EDE, (unsigned char *)&swap, 2, do_bit, 0);
|
m = add_pseudoheader(header, m, ((unsigned char *) header) + 65536, daemon->edns_pktsz, EDNS0_OPTION_EDE, (unsigned char *)&swap, 2, do_bit, 0);
|
||||||
else
|
else
|
||||||
m = add_pseudoheader(header, m, ((unsigned char *) header) + 65536, daemon->edns_pktsz, 0, NULL, 0, do_bit, 0);
|
m = add_pseudoheader(header, m, ((unsigned char *) header) + 65536, daemon->edns_pktsz, 0, NULL, 0, do_bit, 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2342,6 +2407,24 @@ unsigned char *tcp_request(int confd, time_t now,
|
|||||||
#endif
|
#endif
|
||||||
if (!read_write(confd, packet, m + sizeof(u16), 0))
|
if (!read_write(confd, packet, m + sizeof(u16), 0))
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
/* If we answered with stale data, this process will now try and get fresh data into
|
||||||
|
the cache then and cannot therefore accept new queries. Close the incoming
|
||||||
|
connection to signal that to the client. Then set do_stale and loop round
|
||||||
|
once more to try and get fresh data, after which we exit. */
|
||||||
|
if (stale)
|
||||||
|
{
|
||||||
|
shutdown(confd, SHUT_RDWR);
|
||||||
|
close(confd);
|
||||||
|
do_stale = 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* If we ran once to get fresh data, confd is already closed. */
|
||||||
|
if (!do_stale)
|
||||||
|
{
|
||||||
|
shutdown(confd, SHUT_RDWR);
|
||||||
|
close(confd);
|
||||||
}
|
}
|
||||||
|
|
||||||
return packet;
|
return packet;
|
||||||
|
|||||||
@@ -183,6 +183,7 @@ struct myoption {
|
|||||||
#define LOPT_CONF_SCRIPT 374
|
#define LOPT_CONF_SCRIPT 374
|
||||||
#define LOPT_RANDPORT_LIM 375
|
#define LOPT_RANDPORT_LIM 375
|
||||||
#define LOPT_FAST_RETRY 376
|
#define LOPT_FAST_RETRY 376
|
||||||
|
#define LOPT_STALE_CACHE 377
|
||||||
|
|
||||||
#ifdef HAVE_GETOPT_LONG
|
#ifdef HAVE_GETOPT_LONG
|
||||||
static const struct option opts[] =
|
static const struct option opts[] =
|
||||||
@@ -370,6 +371,7 @@ static const struct myoption opts[] =
|
|||||||
{ "quiet-tftp", 0, 0, LOPT_QUIET_TFTP },
|
{ "quiet-tftp", 0, 0, LOPT_QUIET_TFTP },
|
||||||
{ "port-limit", 1, 0, LOPT_RANDPORT_LIM },
|
{ "port-limit", 1, 0, LOPT_RANDPORT_LIM },
|
||||||
{ "fast-dns-retry", 1, 0, LOPT_FAST_RETRY },
|
{ "fast-dns-retry", 1, 0, LOPT_FAST_RETRY },
|
||||||
|
{ "use-stale-cache", 0, 0 , LOPT_STALE_CACHE },
|
||||||
{ NULL, 0, 0, 0 }
|
{ NULL, 0, 0, 0 }
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -427,6 +429,7 @@ static struct {
|
|||||||
{ 'M', ARG_DUP, "<bootp opts>", gettext_noop("Specify BOOTP options to DHCP server."), NULL },
|
{ 'M', ARG_DUP, "<bootp opts>", gettext_noop("Specify BOOTP options to DHCP server."), NULL },
|
||||||
{ 'n', OPT_NO_POLL, NULL, gettext_noop("Do NOT poll %s file, reload only on SIGHUP."), RESOLVFILE },
|
{ 'n', OPT_NO_POLL, NULL, gettext_noop("Do NOT poll %s file, reload only on SIGHUP."), RESOLVFILE },
|
||||||
{ 'N', OPT_NO_NEG, NULL, gettext_noop("Do NOT cache failed search results."), NULL },
|
{ 'N', OPT_NO_NEG, NULL, gettext_noop("Do NOT cache failed search results."), NULL },
|
||||||
|
{ LOPT_STALE_CACHE, OPT_STALE_CACHE, NULL, gettext_noop("Use expired cache data for faster reply."), NULL },
|
||||||
{ 'o', OPT_ORDER, NULL, gettext_noop("Use nameservers strictly in the order given in %s."), RESOLVFILE },
|
{ 'o', OPT_ORDER, NULL, gettext_noop("Use nameservers strictly in the order given in %s."), RESOLVFILE },
|
||||||
{ 'O', ARG_DUP, "<optspec>", gettext_noop("Specify options to be sent to DHCP clients."), NULL },
|
{ 'O', ARG_DUP, "<optspec>", gettext_noop("Specify options to be sent to DHCP clients."), NULL },
|
||||||
{ LOPT_FORCE, ARG_DUP, "<optspec>", gettext_noop("DHCP option sent even if the client does not request it."), NULL},
|
{ LOPT_FORCE, ARG_DUP, "<optspec>", gettext_noop("DHCP option sent even if the client does not request it."), NULL},
|
||||||
|
|||||||
+67
-13
@@ -1360,8 +1360,15 @@ int add_resource_record(struct dns_header *header, char *limit, int *truncp, int
|
|||||||
#undef CHECK_LIMIT
|
#undef CHECK_LIMIT
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int crec_isstale(struct crec *crecp, time_t now)
|
||||||
|
{
|
||||||
|
return (!(crecp->flags & F_IMMORTAL)) && difftime(crecp->ttd, now) < 0;
|
||||||
|
}
|
||||||
|
|
||||||
static unsigned long crec_ttl(struct crec *crecp, time_t now)
|
static unsigned long crec_ttl(struct crec *crecp, time_t now)
|
||||||
{
|
{
|
||||||
|
signed long ttl = difftime(crecp->ttd, now);
|
||||||
|
|
||||||
/* Return 0 ttl for DHCP entries, which might change
|
/* Return 0 ttl for DHCP entries, which might change
|
||||||
before the lease expires, unless configured otherwise. */
|
before the lease expires, unless configured otherwise. */
|
||||||
|
|
||||||
@@ -1370,8 +1377,8 @@ static unsigned long crec_ttl(struct crec *crecp, time_t now)
|
|||||||
int conf_ttl = daemon->use_dhcp_ttl ? daemon->dhcp_ttl : daemon->local_ttl;
|
int conf_ttl = daemon->use_dhcp_ttl ? daemon->dhcp_ttl : daemon->local_ttl;
|
||||||
|
|
||||||
/* Apply ceiling of actual lease length to configured TTL. */
|
/* Apply ceiling of actual lease length to configured TTL. */
|
||||||
if (!(crecp->flags & F_IMMORTAL) && (crecp->ttd - now) < conf_ttl)
|
if (!(crecp->flags & F_IMMORTAL) && ttl < conf_ttl)
|
||||||
return crecp->ttd - now;
|
return ttl;
|
||||||
|
|
||||||
return conf_ttl;
|
return conf_ttl;
|
||||||
}
|
}
|
||||||
@@ -1380,9 +1387,13 @@ static unsigned long crec_ttl(struct crec *crecp, time_t now)
|
|||||||
if (crecp->flags & F_IMMORTAL)
|
if (crecp->flags & F_IMMORTAL)
|
||||||
return crecp->ttd;
|
return crecp->ttd;
|
||||||
|
|
||||||
|
/* Stale cache entries. */
|
||||||
|
if (ttl < 0)
|
||||||
|
return 0;
|
||||||
|
|
||||||
/* Return the Max TTL value if it is lower than the actual TTL */
|
/* 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))
|
if (daemon->max_ttl == 0 || ((unsigned)ttl < daemon->max_ttl))
|
||||||
return crecp->ttd - now;
|
return ttl;
|
||||||
else
|
else
|
||||||
return daemon->max_ttl;
|
return daemon->max_ttl;
|
||||||
}
|
}
|
||||||
@@ -1395,7 +1406,8 @@ static int cache_validated(const struct crec *crecp)
|
|||||||
/* return zero if we can't answer from cache, or packet size if we can */
|
/* return zero if we can't answer from cache, or packet size if we can */
|
||||||
size_t answer_request(struct dns_header *header, char *limit, size_t qlen,
|
size_t answer_request(struct dns_header *header, char *limit, size_t qlen,
|
||||||
struct in_addr local_addr, struct in_addr local_netmask,
|
struct in_addr local_addr, struct in_addr local_netmask,
|
||||||
time_t now, int ad_reqd, int do_bit, int have_pseudoheader)
|
time_t now, int ad_reqd, int do_bit, int have_pseudoheader,
|
||||||
|
int *stale)
|
||||||
{
|
{
|
||||||
char *name = daemon->namebuff;
|
char *name = daemon->namebuff;
|
||||||
unsigned char *p, *ansp;
|
unsigned char *p, *ansp;
|
||||||
@@ -1411,6 +1423,9 @@ size_t answer_request(struct dns_header *header, char *limit, size_t qlen,
|
|||||||
size_t len;
|
size_t len;
|
||||||
int rd_bit = (header->hb3 & HB3_RD);
|
int rd_bit = (header->hb3 & HB3_RD);
|
||||||
|
|
||||||
|
if (stale)
|
||||||
|
*stale = 0;
|
||||||
|
|
||||||
/* never answer queries with RD unset, to avoid cache snooping. */
|
/* never answer queries with RD unset, to avoid cache snooping. */
|
||||||
if (ntohs(header->ancount) != 0 ||
|
if (ntohs(header->ancount) != 0 ||
|
||||||
ntohs(header->nscount) != 0 ||
|
ntohs(header->nscount) != 0 ||
|
||||||
@@ -1459,13 +1474,22 @@ size_t answer_request(struct dns_header *header, char *limit, size_t qlen,
|
|||||||
while (--count != 0 && (crecp = cache_find_by_name(NULL, name, now, F_CNAME | F_NXDOMAIN)))
|
while (--count != 0 && (crecp = cache_find_by_name(NULL, name, now, F_CNAME | F_NXDOMAIN)))
|
||||||
{
|
{
|
||||||
char *cname_target;
|
char *cname_target;
|
||||||
|
int stale_flag = 0;
|
||||||
|
|
||||||
|
if (crec_isstale(crecp, now))
|
||||||
|
{
|
||||||
|
if (stale)
|
||||||
|
*stale = 1;
|
||||||
|
|
||||||
|
stale_flag = F_STALE;
|
||||||
|
}
|
||||||
|
|
||||||
if (crecp->flags & F_NXDOMAIN)
|
if (crecp->flags & F_NXDOMAIN)
|
||||||
{
|
{
|
||||||
if (qtype == T_CNAME)
|
if (qtype == T_CNAME)
|
||||||
{
|
{
|
||||||
if (!dryrun)
|
if (!dryrun)
|
||||||
log_query(crecp->flags, name, NULL, record_source(crecp->uid), 0);
|
log_query(stale_flag | crecp->flags, name, NULL, record_source(crecp->uid), 0);
|
||||||
auth = 0;
|
auth = 0;
|
||||||
nxdomain = 1;
|
nxdomain = 1;
|
||||||
ans = 1;
|
ans = 1;
|
||||||
@@ -1487,7 +1511,7 @@ size_t answer_request(struct dns_header *header, char *limit, size_t qlen,
|
|||||||
|
|
||||||
if (!dryrun)
|
if (!dryrun)
|
||||||
{
|
{
|
||||||
log_query(crecp->flags, name, NULL, record_source(crecp->uid), 0);
|
log_query(stale_flag | crecp->flags, name, NULL, record_source(crecp->uid), 0);
|
||||||
if (add_resource_record(header, limit, &trunc, nameoffset, &ansp,
|
if (add_resource_record(header, limit, &trunc, nameoffset, &ansp,
|
||||||
crec_ttl(crecp, now), &nameoffset,
|
crec_ttl(crecp, now), &nameoffset,
|
||||||
T_CNAME, C_IN, "d", cname_target))
|
T_CNAME, C_IN, "d", cname_target))
|
||||||
@@ -1656,10 +1680,21 @@ size_t answer_request(struct dns_header *header, char *limit, size_t qlen,
|
|||||||
{
|
{
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
|
int stale_flag = 0;
|
||||||
|
|
||||||
|
if (crec_isstale(crecp, now))
|
||||||
|
{
|
||||||
|
if (stale)
|
||||||
|
*stale = 1;
|
||||||
|
|
||||||
|
stale_flag = F_STALE;
|
||||||
|
}
|
||||||
|
|
||||||
/* don't answer wildcard queries with data not from /etc/hosts or dhcp leases */
|
/* don't answer wildcard queries with data not from /etc/hosts or dhcp leases */
|
||||||
if (qtype == T_ANY && !(crecp->flags & (F_HOSTS | F_DHCP)))
|
if (qtype == T_ANY && !(crecp->flags & (F_HOSTS | F_DHCP)))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
|
|
||||||
if (!(crecp->flags & F_DNSSECOK))
|
if (!(crecp->flags & F_DNSSECOK))
|
||||||
sec_data = 0;
|
sec_data = 0;
|
||||||
|
|
||||||
@@ -1671,7 +1706,7 @@ size_t answer_request(struct dns_header *header, char *limit, size_t qlen,
|
|||||||
if (crecp->flags & F_NXDOMAIN)
|
if (crecp->flags & F_NXDOMAIN)
|
||||||
nxdomain = 1;
|
nxdomain = 1;
|
||||||
if (!dryrun)
|
if (!dryrun)
|
||||||
log_query(crecp->flags & ~F_FORWARD, name, &addr, NULL, 0);
|
log_query(stale_flag | (crecp->flags & ~F_FORWARD), name, &addr, NULL, 0);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -1679,7 +1714,7 @@ size_t answer_request(struct dns_header *header, char *limit, size_t qlen,
|
|||||||
auth = 0;
|
auth = 0;
|
||||||
if (!dryrun)
|
if (!dryrun)
|
||||||
{
|
{
|
||||||
log_query(crecp->flags & ~F_FORWARD, cache_get_name(crecp), &addr,
|
log_query(stale_flag | (crecp->flags & ~F_FORWARD), cache_get_name(crecp), &addr,
|
||||||
record_source(crecp->uid), 0);
|
record_source(crecp->uid), 0);
|
||||||
|
|
||||||
if (add_resource_record(header, limit, &trunc, nameoffset, &ansp,
|
if (add_resource_record(header, limit, &trunc, nameoffset, &ansp,
|
||||||
@@ -1810,6 +1845,16 @@ size_t answer_request(struct dns_header *header, char *limit, size_t qlen,
|
|||||||
(rd_bit && (!do_bit || cache_validated(crecp)) ))
|
(rd_bit && (!do_bit || cache_validated(crecp)) ))
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
|
int stale_flag = 0;
|
||||||
|
|
||||||
|
if (crec_isstale(crecp, now))
|
||||||
|
{
|
||||||
|
if (stale)
|
||||||
|
*stale = 1;
|
||||||
|
|
||||||
|
stale_flag = F_STALE;
|
||||||
|
}
|
||||||
|
|
||||||
/* don't answer wildcard queries with data not from /etc/hosts
|
/* don't answer wildcard queries with data not from /etc/hosts
|
||||||
or DHCP leases */
|
or DHCP leases */
|
||||||
if (qtype == T_ANY && !(crecp->flags & (F_HOSTS | F_DHCP | F_CONFIG)))
|
if (qtype == T_ANY && !(crecp->flags & (F_HOSTS | F_DHCP | F_CONFIG)))
|
||||||
@@ -1825,7 +1870,7 @@ size_t answer_request(struct dns_header *header, char *limit, size_t qlen,
|
|||||||
if (crecp->flags & F_NXDOMAIN)
|
if (crecp->flags & F_NXDOMAIN)
|
||||||
nxdomain = 1;
|
nxdomain = 1;
|
||||||
if (!dryrun)
|
if (!dryrun)
|
||||||
log_query(crecp->flags, name, NULL, NULL, 0);
|
log_query(stale_flag | crecp->flags, name, NULL, NULL, 0);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -1842,7 +1887,7 @@ size_t answer_request(struct dns_header *header, char *limit, size_t qlen,
|
|||||||
ans = 1;
|
ans = 1;
|
||||||
if (!dryrun)
|
if (!dryrun)
|
||||||
{
|
{
|
||||||
log_query(crecp->flags & ~F_REVERSE, name, &crecp->addr,
|
log_query(stale_flag | (crecp->flags & ~F_REVERSE), name, &crecp->addr,
|
||||||
record_source(crecp->uid), 0);
|
record_source(crecp->uid), 0);
|
||||||
|
|
||||||
if (add_resource_record(header, limit, &trunc, nameoffset, &ansp,
|
if (add_resource_record(header, limit, &trunc, nameoffset, &ansp,
|
||||||
@@ -1953,6 +1998,15 @@ size_t answer_request(struct dns_header *header, char *limit, size_t qlen,
|
|||||||
rd_bit && (!do_bit || (option_bool(OPT_DNSSEC_VALID) && !(crecp->flags & F_DNSSECOK))))
|
rd_bit && (!do_bit || (option_bool(OPT_DNSSEC_VALID) && !(crecp->flags & F_DNSSECOK))))
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
|
int stale_flag = 0;
|
||||||
|
|
||||||
|
if (crec_isstale(crecp, now))
|
||||||
|
{
|
||||||
|
if (stale)
|
||||||
|
*stale = 1;
|
||||||
|
|
||||||
|
stale_flag = F_STALE;
|
||||||
|
}
|
||||||
/* don't answer wildcard queries with data not from /etc/hosts or dhcp leases, except for NXDOMAIN */
|
/* don't answer wildcard queries with data not from /etc/hosts or dhcp leases, except for NXDOMAIN */
|
||||||
if (qtype == T_ANY && !(crecp->flags & (F_NXDOMAIN)))
|
if (qtype == T_ANY && !(crecp->flags & (F_NXDOMAIN)))
|
||||||
break;
|
break;
|
||||||
@@ -1968,12 +2022,12 @@ size_t answer_request(struct dns_header *header, char *limit, size_t qlen,
|
|||||||
if (crecp->flags & F_NXDOMAIN)
|
if (crecp->flags & F_NXDOMAIN)
|
||||||
nxdomain = 1;
|
nxdomain = 1;
|
||||||
if (!dryrun)
|
if (!dryrun)
|
||||||
log_query(crecp->flags, name, NULL, NULL, 0);
|
log_query(stale_flag | crecp->flags, name, NULL, NULL, 0);
|
||||||
}
|
}
|
||||||
else if (!dryrun)
|
else if (!dryrun)
|
||||||
{
|
{
|
||||||
char *target = blockdata_retrieve(crecp->addr.srv.target, crecp->addr.srv.targetlen, NULL);
|
char *target = blockdata_retrieve(crecp->addr.srv.target, crecp->addr.srv.targetlen, NULL);
|
||||||
log_query(crecp->flags, name, NULL, NULL, 0);
|
log_query(stale_flag | crecp->flags, name, NULL, NULL, 0);
|
||||||
|
|
||||||
if (add_resource_record(header, limit, &trunc, nameoffset, &ansp,
|
if (add_resource_record(header, limit, &trunc, nameoffset, &ansp,
|
||||||
crec_ttl(crecp, now), NULL, T_SRV, C_IN, "sssd",
|
crec_ttl(crecp, now), NULL, T_SRV, C_IN, "sssd",
|
||||||
|
|||||||
Reference in new issue
Block a user