Skip to content
Snippets Groups Projects

daemon: allow per-request variables in Lua

Merged Marek Vavrusa requested to merge lua-add-per-request-variables into master

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
Edited by Marek Vavrusa

Merge request reports

Loading
Loading

Activity

Filter activity
  • Approvals
  • Assignees & reviewers
  • Comments (from bots)
  • Comments (from users)
  • Commits & branches
  • Edits
  • Labels
  • Lock status
  • Mentions
  • Merge request status
  • Tracking
  • I very much like this, I was wondering about the same when I saw DNS64 module internals. Thank you!

  • added feature label

  • Grigorii Demidov marked the checklist item Add to to basic resolve tests as completed

    marked the checklist item Add to to basic resolve tests as completed

  • Grigorii Demidov marked the checklist item Add to to basic resolve tests as incomplete

    marked the checklist item Add to to basic resolve tests as incomplete

  • Marek Vavrusa added 188 commits

    added 188 commits

    • 3a8f8170...d316da92 - 187 commits from branch master
    • 4384af52 - daemon: allow per-request variables in Lua

    Compare with previous version

  • Marek Vavrusa unmarked as a Work In Progress

    unmarked as a Work In Progress

  • Marek Vavrusa changed the description

    changed the description

  • Marek Vavrusa marked the checklist item Add to to basic resolve tests as completed

    marked the checklist item Add to to basic resolve tests as completed

  • Marek Vavrusa marked the checklist item Update DNS64 module as completed

    marked the checklist item Update DNS64 module as completed

  • Marek Vavrusa marked the checklist item Add to library documentation as completed

    marked the checklist item Add to library documentation as completed

  • 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
  • Marek Vavrusa marked the checklist item Update DNS64 module as incomplete

    marked the checklist item Update DNS64 module as incomplete

  • Marek Vavrusa added 1 commit

    added 1 commit

    • 14de9110 - daemon: allow per-request variables in Lua

    Compare with previous version

  • Author Reporter

    @gdemidov uh, that's annoying. I'll remove it for now, but this should really be transparent.

  • Marek Vavrusa changed the description

    changed the description

  • mentioned in commit 7fae33f4

  • Grigorii Demidov mentioned in issue #363

    mentioned in issue #363

Please register or sign in to reply
Loading