2
0
mirror of https://gitlab.isc.org/isc-projects/bind9 synced 2025-08-31 14:35:26 +00:00

4700. [func] Serving of stale answers is now supported. This

allows named to provide stale cached answers when
                        the authoritative server is under attack.
                        See max-stale-ttl, stale-answer-enable,
                        stale-answer-ttl. [RT #44790]
This commit is contained in:
Mark Andrews
2017-09-06 09:58:29 +10:00
parent e8a4edf0ed
commit df50751585
41 changed files with 1964 additions and 222 deletions

View File

@@ -89,6 +89,7 @@ typedef struct dns_totext_ctx {
dns_fixedname_t origin_fixname;
isc_uint32_t current_ttl;
isc_boolean_t current_ttl_valid;
dns_ttl_t serve_stale_ttl;
} dns_totext_ctx_t;
LIBDNS_EXTERNAL_DATA const dns_master_style_t
@@ -382,6 +383,7 @@ totext_ctx_init(const dns_master_style_t *style, dns_totext_ctx_t *ctx) {
ctx->neworigin = NULL;
ctx->current_ttl = 0;
ctx->current_ttl_valid = ISC_FALSE;
ctx->serve_stale_ttl = 0;
return (ISC_R_SUCCESS);
}
@@ -1032,6 +1034,8 @@ dump_rdatasets_text(isc_mem_t *mctx, const dns_name_t *name,
(ctx->style.flags & DNS_STYLEFLAG_NCACHE) == 0) {
/* Omit negative cache entries */
} else {
if (rds->ttl < ctx->serve_stale_ttl)
fprintf(f, "; stale\n");
isc_result_t result =
dump_rdataset(mctx, name, rds, ctx,
buffer, f);
@@ -1494,6 +1498,15 @@ dumpctx_create(isc_mem_t *mctx, dns_db_t *db, dns_dbversion_t *version,
dns_db_attach(db, &dctx->db);
dctx->do_date = dns_db_iscache(dctx->db);
if (dctx->do_date) {
/*
* Adjust the date backwards by the serve-stale TTL, if any.
* This is so the TTL will be loaded correctly when next started.
*/
(void)dns_db_getservestalettl(dctx->db,
&dctx->tctx.serve_stale_ttl);
dctx->now -= dctx->tctx.serve_stale_ttl;
}
if (dctx->format == dns_masterformat_text &&
(dctx->tctx.style.flags & DNS_STYLEFLAG_REL_OWNER) != 0) {
@@ -1553,6 +1566,9 @@ writeheader(dns_dumpctx_t *dctx) {
* it in the zone case.
*/
if (dctx->do_date) {
fprintf(dctx->f,
"; using a %d second stale ttl\n",
dctx->tctx.serve_stale_ttl);
result = dns_time32_totext(dctx->now, &buffer);
RUNTIME_CHECK(result == ISC_R_SUCCESS);
isc_buffer_usedregion(&buffer, &r);