]> git.ipfire.org Git - thirdparty/knot-resolver.git/commitdiff
policy: fix qry parameter in postrules
authorVladimír Čunát <vladimir.cunat@nic.cz>
Thu, 2 Apr 2020 07:01:11 +0000 (09:01 +0200)
committerVladimír Čunát <vladimir.cunat@nic.cz>
Thu, 2 Apr 2020 12:35:43 +0000 (14:35 +0200)
Some rules need it and it was nil until now.

daemon/lua/kres-gen.lua
daemon/lua/kres.lua
lib/rplan.c
lib/rplan.h
modules/policy/policy.lua

index 37743387596be1a4e94a9caa601d1cae12135df7..5b9b69275f56da1caa1680e6e4d4987b8bba812e 100644 (file)
@@ -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;
index bf9bde77315a51c221a791858315bbe59468b60d..1bdc30a31544f9ec6813a6145c7042ebe0760ec8 100644 (file)
@@ -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))
index ae0855121f8119195d86572208a05c0aad2fb4cf..18dc6b8276c0b3186b3ebd130d881b8a643a4a72 100644 (file)
@@ -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;
index 7ac294718e3dd07b6c2fcafe965eb57571c7a7e3..c2888726c1dd51ee839cf9b4a55dadef99a02143 100644 (file)
@@ -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). */
index b413eb07a6a4914755bdf74af29b972a12cb54c7..23cba3dfcfe7e8618dc790ba8b019e24d7b60d5e 100644 (file)
@@ -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
 }