daemon: allow per-request variables in Lua
The handlers in Lua can now store per-request variables that are automatically GC'd when the request is finished. This is useful for stateful modules, such as DNS64 that uses internal option flags for state tracking, or stats that previously couldn't be implemented in Lua
The layers can now get a variable table like so:
local vars = kres.request_t(r):vars()
vars.hello = true
The variables are persisted between different layers for each request.
TODO:
-
Add to to basic resolve tests Update DNS64 module-
Add to library documentation
Merge request reports
Activity
added feature label
added 188 commits
- 3a8f8170...d316da92 - 187 commits from branch
master
- 4384af52 - daemon: allow per-request variables in Lua
- 3a8f8170...d316da92 - 187 commits from branch
For me, the mechanism which allows to store per-request variables is OK.
But changes in DNS64 module looks a bit problematic due to forwarding mode. Unfortunately, for now resolver must to know if answer was synthesized. Otherwise it could make problems with validation.
https://gitlab.labs.nic.cz/knot/knot-resolver/blob/master/lib/resolve.c#L1002
Example. config
... modules = { ... "policy", "dns64", ... } ... dns64.config('fe80::21b:aabb:0:0') ... policy.add(policy.all(policy.TLS_FORWARD({{ "1.1.1.1", insecure = true }}))) ...
master
kdig alza.cz AAAA @127.0.0.1 -p 53000 +dnssec ;; ->>HEADER<<- opcode: QUERY; status: NOERROR; id: 58086 ;; Flags: qr rd ra; QUERY: 1; ANSWER: 1; AUTHORITY: 4; ADDITIONAL: 1 ;; EDNS PSEUDOSECTION: ;; Version: 0; flags: do; UDP size: 4096 B; ext-rcode: NOERROR ;; QUESTION SECTION: ;; alza.cz. IN AAAA ;; ANSWER SECTION: alza.cz. 271 IN AAAA fe80::21b:aabb:b9b5:b013 ;; AUTHORITY SECTION: ....blahblahblah... ;; Received 458 B ;; Time 2018-05-30 14:58:54 CEST ;; From 127.0.0.1@53000(UDP) in 81.0 ms
vs this branch
kdig alza.cz AAAA @127.0.0.1 -p 53000 +dnssec ;; ->>HEADER<<- opcode: QUERY; status: SERVFAIL; id: 13368 ;; Flags: qr rd ra; QUERY: 1; ANSWER: 0; AUTHORITY: 0; ADDITIONAL: 0 ;; QUESTION SECTION: ;; alza.cz. IN AAAA ;; Received 25 B ;; Time 2018-05-30 14:58:16 CEST ;; From 127.0.0.1@53000(UDP) in 39.9 ms
Could we consider using DNS64_MARK flag in query flags along with per request lua variables?
Edited by Grigorii Demidov@gdemidov uh, that's annoying. I'll remove it for now, but this should really be transparent.
mentioned in commit 7fae33f4
mentioned in issue #363