From: Vladimír Čunát Date: Thu, 2 Apr 2020 07:01:11 +0000 (+0200) Subject: policy: fix qry parameter in postrules X-Git-Tag: v5.1.0~19^2~1 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=55d3aa0a57f900ea1a9fe099505bc724cbaadcb4;p=thirdparty%2Fknot-resolver.git policy: fix qry parameter in postrules Some rules need it and it was nil until now. --- diff --git a/daemon/lua/kres-gen.lua b/daemon/lua/kres-gen.lua index 377433875..5b9b69275 100644 --- a/daemon/lua/kres-gen.lua +++ b/daemon/lua/kres-gen.lua @@ -153,6 +153,7 @@ typedef struct { struct kr_rplan { kr_qarray_t pending; kr_qarray_t resolved; + struct kr_query *initial; struct kr_request *request; knot_mm_t *pool; uint32_t next_uid; diff --git a/daemon/lua/kres.lua b/daemon/lua/kres.lua index bf9bde773..1bdc30a31 100644 --- a/daemon/lua/kres.lua +++ b/daemon/lua/kres.lua @@ -766,6 +766,13 @@ ffi.metatype( kr_request_t, { if req.current_query == nil then return nil end return req.current_query end, + -- returns the initial query that started the request + initial = function(req) + assert(ffi.istype(kr_request_t, req)) + local rplan = C.kr_resolve_plan(req) + if rplan.initial == nil then return nil end + return rplan.initial + end, -- Return last query on the resolution plan last = function(req) assert(ffi.istype(kr_request_t, req)) diff --git a/lib/rplan.c b/lib/rplan.c index ae0855121..18dc6b827 100644 --- a/lib/rplan.c +++ b/lib/rplan.c @@ -176,6 +176,12 @@ static struct kr_query *kr_rplan_push_query(struct kr_rplan *rplan, } } + assert((rplan->pending.len == 0 && rplan->resolved.len == 0) + == (rplan->initial == NULL)); + if (rplan->initial == NULL) { + rplan->initial = qry; + } + array_push(rplan->pending, qry); return qry; diff --git a/lib/rplan.h b/lib/rplan.h index 7ac294718..c2888726c 100644 --- a/lib/rplan.h +++ b/lib/rplan.h @@ -121,6 +121,8 @@ struct kr_rplan { as the last is the next one to solve, and they may be inter-dependent. */ kr_qarray_t resolved; /**< List of resolved queries. */ + struct kr_query *initial; /**< The initial query (also in pending or resolved). */ + struct kr_request *request; /**< Parent resolution request. */ knot_mm_t *pool; /**< Temporary memory pool. */ uint32_t next_uid; /**< Next value for kr_query::uid (incremental). */ diff --git a/modules/policy/policy.lua b/modules/policy/policy.lua index b413eb07a..23cba3dfc 100644 --- a/modules/policy/policy.lua +++ b/modules/policy/policy.lua @@ -880,7 +880,7 @@ policy.layer = { begin = function(state, req) -- Don't act on "finished" cases. if bit.band(state, bit.bor(kres.FAIL, kres.DONE)) ~= 0 then return state end - local qry = req:current() + local qry = req:initial() -- same as :current() but more descriptive return policy.evaluate(policy.rules, req, qry, state) or (special_names_optim(req, qry.sname) and policy.evaluate(policy.special_names, req, qry, state)) @@ -891,7 +891,7 @@ policy.layer = { if #policy.postrules == 0 then return state end -- Don't act on failed cases. if bit.band(state, kres.FAIL) ~= 0 then return state end - return policy.evaluate(policy.postrules, req, req:current(), state) or state + return policy.evaluate(policy.postrules, req, req:initial(), state) or state end }