Marek Vavruša [Fri, 29 Dec 2017 03:25:57 +0000 (19:25 -0800)]
daemon: unified query completion callback with trace callback in resolve
This is a followup on addition of trace callbacks in the resolver library,
to get rid of the Lua/C interfacing in daemon and unify it with the log tracing.
All modules can now install completion callback on the kr_request object that
will be called after the resolution is done.
Marek Vavruša [Thu, 21 Dec 2017 06:22:36 +0000 (22:22 -0800)]
daemon/worker: allow large responses for outbound over TCP
By default the reassembly packet buffer is set to EDNS buffer size,
which is correct for UDP, but not for TCP which may accept any
allowed response size. This should be only used for responses to
outbound queries over TCP, not for inbound TCP queries.
Marek Vavruša [Wed, 6 Dec 2017 00:52:40 +0000 (16:52 -0800)]
Implement worker coroutines for asynchronous background processing
This implements worker coroutines in Lua to perform non-blocking I/O and do many things concurrently.
For example a file watcher can be now implemented as:
```
local watcher = notify.opendir('/etc')
watcher:add('hosts')
-- Watch changes to /etc/hosts
worker.coroutine(function ()
for flags, name in watcher:changes() do
for flag in notify.flags(flags) do
print(name, notify[flag])
end
end
end)
```
In order to make this work, the runtime uses the cqueues library which
can run coroutines concurrently, and return a file descriptor to poll on
if it's blocked. The worker takes that file descriptor and calls
`event.socket(pollfd, resume_callback)` so that libuv can wake up
the worker when its ready again.
The cqueues library is still optional, but if it's not present following stuff
won't work:
Marek Vavruša [Tue, 28 Nov 2017 00:42:08 +0000 (16:42 -0800)]
modules/http: added /trace endpoint for request log tracing, added tests
This leverages the HTTP interface to trace execution of individual
requests. This is helpful for troubleshooting problems with a specific instance,
or to generate test files (as it writes out answers received).
Ideally it would also print a timeline of request processing broken down by
function (or layer) and the amount of time spent, but there's no
tracepoint for that yet.
Marek Vavruša [Mon, 27 Nov 2017 23:02:35 +0000 (15:02 -0800)]
lib: added support for trace_log for verbose messages
The `QRVERBOSE` macro uses the `query` pointer to find out whether the
request has trace log enabled. If it does, it uses trace log to log verbose messages using that callback (regardless of whether verbose mode is set or not).
This required changing of structure printing functions to formatting functions returning textual representation of the objects (dname, rrset, pkt).
This is potentially slower as creates heap objects, but it doesn't happen
in the hotpath so it doesn't really matter for verbose logs.
Marek Vavruša [Mon, 27 Nov 2017 22:59:55 +0000 (14:59 -0800)]
lib/rplan: remember request context in each query
This doesn't affect any of the objects lifetime, just provides a
convenience for logging as some subsystems take only pointer of queries
not the request object.
Marek Vavruša [Mon, 27 Nov 2017 22:19:10 +0000 (14:19 -0800)]
lib/resolve: add support for per-request logging
This is useful in many troubleshooting scenarios when you want debug logs
just for a single request. It's going to expand on TRACE flag functionality
in the next PRs, so that special requests can be invoked with various tracers attached.
Currently this is only available in the C modules that can set the callback,
it's not called anywhere in the library yet.
Petr Špaček [Fri, 8 Dec 2017 13:22:15 +0000 (14:22 +0100)]
daemon: add missing RR type definitions
Some RR type definitions present in IANA DNS parameters registry were
missing in kresd. This commit synchronizes the tables with IANA registry
as of 2017-12-08 13:20 UTC.
At the same time, this commit is
fixup! converted constant tables, support kres.type.TYPE1234
The mentioned commit accidentally removed NULL definition which broke TA
signaling module.
Petr Špaček [Thu, 7 Dec 2017 16:45:58 +0000 (17:45 +0100)]
rplan: fix kr_qflags_*() to work with more than 32 flags
Originally division around sizeof(uint32_t) caused silent truncation
for struct kr_qflags with sizes not multiple of 4 bytes.
Attempts to optimize using uint32_t blocks could lead to read/write
beyond end of uint32_t so I'm not willing to risk it.
Also, the code was refactored to avoid duplication between _set and _clear.
Quick look into assembly produced by gcc 7.2.1 with -O2 on x86_64 confirms that
all auxiliary functions got inlined so there are not extra function calls.
Unit tests are attached. These fail on the previous version of _set() and
_clear() and work now.
Petr Špaček [Thu, 7 Dec 2017 08:37:26 +0000 (09:37 +0100)]
CI: use Knot DNS 2.6 instead of master
Hopefully this will make build more reliable because breakage in Knot
DNS master will not affect us. On the other hand, we must not forget to
update Knot DNS in the image!
Vítězslav Kříž [Mon, 4 Dec 2017 14:15:33 +0000 (15:15 +0100)]
hints: server stop when root hints load failed
If user provides custom hints file with config option hints.root_file('file')
resovler fail with error. Before it just silently pass and may fail
when loading defaults file, which leads to confusing error message.
Petr Špaček [Fri, 1 Dec 2017 20:30:58 +0000 (21:30 +0100)]
fixup! client: move sources into separate directory
Previous cleanup attempt broke installation on systems without libedit.
client-install has to be defined at least as .PHONY target.
(I want to avoid if spagethi outside of client.mk.)
Petr Špaček [Fri, 1 Dec 2017 13:00:36 +0000 (14:00 +0100)]
client: move sources into separate directory
Let's not mix daemon and client files as client might grow to multiple
files in future. This will also help with upcomming changes to packaging
scripts.
Petr Špaček [Tue, 28 Nov 2017 10:27:43 +0000 (11:27 +0100)]
scripts: pack all submodules with make-archive.sh
It does not make sense to create "distribution" tarball with dirty
working tree or missing submodules, so this is now forbidden.
make-archive.sh requires clean working tree and all submodules.
Packing all submodules prevents us from releasing incomplete tarball,
especially around release time.
Distributions like Fedora are gradually getting ability to run
integration test suites so it does not hurt to pack everything including
test.
Marek Vavruša [Sun, 26 Nov 2017 00:54:11 +0000 (16:54 -0800)]
build: added `make coverage` to compute C and Lua code coverage
Currently it gathers gcov and luacov code coverage, and merges it
in a single lcov info file. It returns summary at the end which the
CI can parse and interpret. It can build a html report later using
the data.
Marek Vavruša [Sun, 26 Nov 2017 00:23:46 +0000 (16:23 -0800)]
tests/config: added a TAP-based test environment for modules/configs
I moved the test files to module directories because it allows
vendoring of whole modules including tests etc.
The test environment provides convenience functions and produces
test output in TAP format. Ideally all tests should use a common
format, so that CI can parse it provide better test output on PRs.
It seems like Gitlab CI doesn't support anything yet, but there
are two sort-of standards supported in CI tools - TAP and JUnit.
I chose TAP because it's easier to read for humans, cmocka supports it,
and it should be easier to adapt Deckard. There are also tools to
convert TAP into JUnit XML file.
Also added more tests for global functions and variables, and the
test tool now also tracks coverage (if `luacov` is installed).
Also fixed improper promotion of `ffi` to global variable.
```
$ luacheck --codes daemon/lua/
Checking daemon/lua/config.lua OK
Checking daemon/lua/kres-gen.lua OK
Checking daemon/lua/kres.lua OK
Checking daemon/lua/sandbox.lua OK
Checking daemon/lua/trust_anchors.lua OK
Checking daemon/lua/zonefile.lua OK
Marek Vavruša [Fri, 24 Nov 2017 04:32:01 +0000 (20:32 -0800)]
modules/predict: added test for prediction process
this tests that:
* sampling frequent queries works
* the code to find periodic appearences of the same name and type
* resolving predicted queries works
it doesn't test pessimistic cases or failure modes
Marek Vavruša [Fri, 24 Nov 2017 04:30:00 +0000 (20:30 -0800)]
tests/config: added basic assert support (compatible with busted)
There is no dependency on a testing library yet, so I added a
basic interface for mocking and asserting test values to get
something to start with. I'll probably replace it with busted
or telescope later on to get nicer testing output.
Marek Vavruša [Thu, 23 Nov 2017 07:50:58 +0000 (23:50 -0800)]
converted constant tables, support kres.type.TYPE1234
The difficulty with using structs as constant tables is that access
to non-existent fields throws an error. This is difficult to handle
without wrapping every access in a pcall, for example in predict module:
```
error: /usr/local/lib/kdns_modules/predict.lua:34: 'struct rr_type' has no member named 'TYPE65535'
```
So I converted the constant tables into regular Lua tables,
and added a metatable for RR types to allow looking up unnamed types,
in the TYPE%d format. Looking up non-existent fields will now
return nil instead of throwing an error.
Marek Vavruša [Thu, 23 Nov 2017 07:40:28 +0000 (23:40 -0800)]
tests: fixed config tests locking up on error, added test for predict
The config tests locked up on error as if error was raised from the
event callback, it would never reach the `quit()` statement, so
server would never close on error.
Added a script to make running these types of tests a little bit nicer
and to allow concurrent execution of config tests.
Added a test for the predict module, that fails on prediction
of unknown types:
```
error: /usr/local/lib/kdns_modules/predict.lua:34: 'struct rr_type' has no member named 'TYPE65535'
```
Marek Vavruša [Thu, 23 Nov 2017 02:57:39 +0000 (18:57 -0800)]
Added luacheck for linting Lua files and static analysis
This is super useful for checking things like misusing undefined
variables or modifying globals, especially in modules when it's
not immediately visible which variables are in the global
namespace and which are not.
I added several exceptions for files in daemon/lua and tests,
as for example sandbox module needs to legitimately modify
global namespace.
There's a lot of things failing, so I didn't make it part of the
standard `make check`, but we should eventually enable it to
improve code quality and spot problems with CI.