diff options
author | menakite <29005531+menakite@users.noreply.github.com> | 2024-08-14 19:36:54 +0200 |
---|---|---|
committer | menakite <29005531+menakite@users.noreply.github.com> | 2024-08-19 18:03:59 +0200 |
commit | 39f4b5af72f3aca0174476235f43915477f20adb (patch) | |
tree | 56c975793fb3b54e149159fd88f5a8627f92ac1e /modules | |
parent | Merge !1591: modules/stats add answer.stale (diff) | |
download | knot-resolver-39f4b5af72f3aca0174476235f43915477f20adb.tar.xz knot-resolver-39f4b5af72f3aca0174476235f43915477f20adb.zip |
cache: move setting EDE "Stale Answer" to the the serve_stale module.
It is not guaranteed yet that the request will finish in state DONE.
This prevents other EDE codes from being applied to the request and in
case the request ends in FAIL state it produces a SERVFAIL answer with
EDE "Stale Answer", which is a bit weird.
Move setting EDEs in answer_finalize in the serve_stale module, where
the proper EDE in case of NXDOMAIN is set too.
Diffstat (limited to 'modules')
-rw-r--r-- | modules/serve_stale/serve_stale.lua | 18 |
1 files changed, 17 insertions, 1 deletions
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 |