summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--lib/cache/api.c4
-rw-r--r--modules/serve_stale/serve_stale.lua18
2 files changed, 18 insertions, 4 deletions
diff --git a/lib/cache/api.c b/lib/cache/api.c
index 0cd18534..046dae20 100644
--- a/lib/cache/api.c
+++ b/lib/cache/api.c
@@ -237,9 +237,7 @@ int32_t get_new_ttl(const struct entry_h *entry, const struct kr_query *qry,
int res_stale = qry->stale_cb(res, owner, type, qry);
if (res_stale >= 0) {
VERBOSE_MSG(qry, "responding with stale answer\n");
- /* LATER: Perhaps we could use a more specific Stale
- * NXDOMAIN Answer code for applicable responses. */
- kr_request_set_extended_error(qry->request, KNOT_EDNS_EDE_STALE, "6Q6X");
+ qry->request->stale_accounted = true;
return res_stale;
}
}
diff --git a/modules/serve_stale/serve_stale.lua b/modules/serve_stale/serve_stale.lua
index c1528e80..7aa2ee78 100644
--- a/modules/serve_stale/serve_stale.lua
+++ b/modules/serve_stale/serve_stale.lua
@@ -11,7 +11,6 @@ M.callback = ffi.cast("kr_stale_cb",
function (ttl, _, _, qry)
--log_debug(ffi.C.SRVSTALE, ' => called back with TTL: ' .. tostring(ttl))
if ttl + 3600 * 24 > 0 then -- at most one day stale
- qry.request.stale_accounted = true
return 1
else
return -1
@@ -39,6 +38,23 @@ M.layer = {
return state
end,
+
+ answer_finalize = function (state, req)
+ local qry = req:resolved()
+ if state ~= kres.DONE or qry == nil then
+ return state
+ end
+
+ if req.stale_accounted and qry.stale_cb ~= nil then
+ if req.answer:rcode() == kres.rcode.NOERROR then
+ req:set_extended_error(kres.extended_error.STALE, 'WFAC')
+ elseif req.answer:rcode() == kres.rcode.NXDOMAIN then
+ req:set_extended_error(kres.extended_error.STALE_NXD, 'QSF6')
+ end
+ end
+
+ return state
+ end,
}
return M