Commit af6b296c authored by Marek Vavruša's avatar Marek Vavruša

lib/rplan: can now access resolved queries

parent eb8cfc36
......@@ -90,10 +90,12 @@ struct query_flag {
static const int NO_MINIMIZE = 1 << 0;
static const int NO_IPV6 = 1 << 2;
static const int NO_IPV4 = 1 << 3;
static const int RESOLVED = 1 << 5;
static const int AWAIT_CUT = 1 << 8;
static const int CACHED = 1 << 10;
static const int NO_CACHE = 1 << 11;
static const int EXPIRING = 1 << 12;
static const int DNSSEC_WANT = 1 << 14;
};
/*
......@@ -227,6 +229,8 @@ struct kr_rplan *kr_resolve_plan(struct kr_request *request);
/* Resolution plan */
struct kr_query *kr_rplan_push(struct kr_rplan *rplan, struct kr_query *parent,
const knot_dname_t *name, uint16_t cls, uint16_t type);
struct kr_query *kr_rplan_resolved(struct kr_rplan *rplan);
struct kr_query *kr_rplan_next(struct kr_query *qry);
/* Query */
/* Utils */
unsigned kr_rand_uint(unsigned max);
......@@ -316,7 +320,11 @@ ffi.metatype( knot_pkt_t, {
local kr_query_t = ffi.typeof('struct kr_query')
ffi.metatype( kr_query_t, {
__index = {
name = function(qry) return ffi.string(qry.sname) end,
name = function(qry, new_name) return ffi.string(qry.sname) end,
next = function(qry)
assert(qry)
return C.kr_rplan_next(qry)
end,
},
})
-- Metatype for request
......@@ -327,6 +335,10 @@ ffi.metatype( kr_request_t, {
assert(req)
return req.current_query
end,
resolved = function(req)
assert(req)
return C.kr_rplan_resolved(C.kr_resolve_plan(req))
end,
push = function(req, qname, qtype, qclass, flags, parent)
assert(req)
local rplan = C.kr_resolve_plan(req)
......@@ -336,6 +348,10 @@ ffi.metatype( kr_request_t, {
end
return qry
end,
pop = function(req, qry)
assert(req)
return C.kr_rplan_pop(C.kr_resolve_plan(req), qry)
end,
},
})
......
......@@ -249,13 +249,29 @@ You primarily need to retrieve currently processed query.
print(current.type, current.class, current.id, current.flags)
end
As described in the layers, you can not only retrieve information about current query, but also push new ones.
In layers that either begin or finalize, you can walk the list of resolved queries.
.. code-block:: lua
local last = req:resolved()
print(last.type)
last = last:next()
if last ~= nil then
print(last.type)
end
As described in the layers, you can not only retrieve information about current query, but also push new ones or pop old ones.
.. code-block:: lua
-- Push new query
local qry = req:push(pkt:qname(), kres.type.SOA, kres.class.IN)
qry.flags = kres.query.AWAIT_CUT
-- Pop the query, this will erase it from resolution plan
req:pop(qry)
.. _libknot: https://gitlab.labs.nic.cz/labs/knot/tree/master/src/libknot
.. _`processing API`: https://gitlab.labs.nic.cz/labs/knot/tree/master/src/libknot/processing
.. _bindings: https://gitlab.labs.nic.cz/knot/resolver/blob/master/daemon/lua/kres.lua#L361
......
......@@ -154,3 +154,19 @@ bool kr_rplan_satisfies(struct kr_query *closure, const knot_dname_t *name, uint
}
return false;
}
struct kr_query *kr_rplan_resolved(struct kr_rplan *rplan)
{
if (EMPTY_LIST(rplan->resolved)) {
return NULL;
}
return TAIL(rplan->resolved);
}
struct kr_query *kr_rplan_next(struct kr_query *qry)
{
if (!qry) {
return NULL;
}
return (struct kr_query *)qry->node.prev; /* The lists are used as stack, TOP is the TAIL. */
}
\ No newline at end of file
......@@ -133,4 +133,10 @@ int kr_rplan_pop(struct kr_rplan *rplan, struct kr_query *qry);
/**
* Return true if resolution chain satisfies given query.
*/
bool kr_rplan_satisfies(struct kr_query *closure, const knot_dname_t *name, uint16_t cls, uint16_t type);
\ No newline at end of file
bool kr_rplan_satisfies(struct kr_query *closure, const knot_dname_t *name, uint16_t cls, uint16_t type);
/** Return last resolved query. */
struct kr_query *kr_rplan_resolved(struct kr_rplan *rplan);
/** Return query predecessor. */
struct kr_query *kr_rplan_next(struct kr_query *qry);
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment