Skip to content

Commit

Permalink
Merge !1592: cache: move setting EDE "Stale Answer" to the serve_stal…
Browse files Browse the repository at this point in the history
…e module
  • Loading branch information
vcunat committed Aug 20, 2024
2 parents e641138 + 39f4b5a commit 5ba521a
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
4 changes: 1 addition & 3 deletions lib/cache/api.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Expand Down
18 changes: 17 additions & 1 deletion modules/serve_stale/serve_stale.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 5ba521a

Please sign in to comment.