diff options
author | Vladimír Čunát <vladimir.cunat@nic.cz> | 2020-04-02 09:01:11 +0200 |
---|---|---|
committer | Vladimír Čunát <vladimir.cunat@nic.cz> | 2020-04-02 14:35:43 +0200 |
commit | 55d3aa0a57f900ea1a9fe099505bc724cbaadcb4 (patch) | |
tree | 25ddb5d12f458980353f68360c89e8d1668eb78e | |
parent | modules/policy: make actions usable in postrules (diff) | |
download | knot-resolver-55d3aa0a57f900ea1a9fe099505bc724cbaadcb4.tar.xz knot-resolver-55d3aa0a57f900ea1a9fe099505bc724cbaadcb4.zip |
policy: fix qry parameter in postrules
Some rules need it and it was nil until now.
-rw-r--r-- | daemon/lua/kres-gen.lua | 1 | ||||
-rw-r--r-- | daemon/lua/kres.lua | 7 | ||||
-rw-r--r-- | lib/rplan.c | 6 | ||||
-rw-r--r-- | lib/rplan.h | 2 | ||||
-rw-r--r-- | modules/policy/policy.lua | 4 |
5 files changed, 18 insertions, 2 deletions
diff --git a/daemon/lua/kres-gen.lua b/daemon/lua/kres-gen.lua index 37743387..5b9b6927 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 bf9bde77..1bdc30a3 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 ae085512..18dc6b82 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 7ac29471..c2888726 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 b413eb07..23cba3df 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 } |