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

build: disabled default debug messages, optional with -DWITH_DEBUG

this is a small step for me, but a huge step for resolver
parent 24b6d7bd
......@@ -31,7 +31,7 @@ The following is a list of software required to build Knot DNS Resolver from sou
"`pkg-config`_", "*all*", "*(build only)* [#]_"
"C compiler", "*all*", "*(build only)* [#]_"
"libknot_ 2.0+", "*all*", "Knot DNS library."
"Lua_ 5.1+", "``daemon``", "Embeddable scripting language (LuaJIT_ is preferred)."
"LuaJIT_ 2.0+", "``daemon``", "Embedded scripting language (Lua_ 5.1+ with limitations)."
"libuv_ 1.0+", "``daemon``", "Multiplatform I/O and services."
There are also *optional* packages that enable specific functionality in Knot DNS Resolver, they are useful mainly for developers to build documentation and tests.
......@@ -42,7 +42,7 @@ There are also *optional* packages that enable specific functionality in Knot DN
"libmemcached_", "``modules/memcached``", "To build memcached backend module."
"hiredis_", "``modules/redis``", "To build redis backend module."
"cmocka_", "``unit tests``", "Unit testing framework."
"Python_", "``integration tests``", "For scripting tests, C header files are required (``python-dev``)"
"Python_", "``integration tests``", "For test scripts."
"GCCGO_", "``modules/go``", "For building Go modules, see modules documentation."
"Doxygen_", "``documentation``", "Generating API documentation."
"Sphinx_", "``documentation``", "Building this HTML/PDF documentation."
......@@ -72,15 +72,47 @@ You can hack on the container by changing the container entrypoint to shell like
Building from sources
---------------------
The Knot DNS Resolver depends on the development version of the Knot DNS library, and a reasonably recent version of `libuv`.
Several dependencies may not be in the packages yet, the script pulls and installs all dependencies in a chroot.
The Knot DNS Resolver depends on the the Knot DNS library, recent version of libuv_, and LuaJIT_.
.. code-block:: bash
$ make info # See what's missing
When you have all the dependencies ready, you can build and install.
.. code-block:: bash
$ make PREFIX="/usr/local"
$ make install
.. note:: Always build with ``PREFIX`` if you want to install, as it is hardcoded in the executable for module search path.
Alternatively you can build only specific parts of the project, i.e. ``library``.
.. code-block:: bash
$ make lib
$ make lib-install
.. note:: Documentation is not built by default, run ``make doc`` to build it.
Debug build
-----------
For debugging or tinkering purposes, it's useful to build the daemon with the debug messages enabled.
.. code-block:: bash
$ CFLAGS="-O0 -g -DWITH_DEBUG" make
.. warning:: If you want to track specific things like i.e. number of subrequests for given zone in production, use Lua modules or write custom layers rather then depending on debug output.
Building dependencies
~~~~~~~~~~~~~~~~~~~~~
Several dependencies may not be in the packages yet, the script pulls and installs all dependencies in a chroot.
You can avoid rebuilding dependencies by specifying `BUILD_IGNORE` variable, see the Dockerfile_ for example.
Usually you only really need to rebuild `libknot`.
Usually you only really need to rebuild libknot_.
.. code-block:: bash
......@@ -94,31 +126,12 @@ Usually you only really need to rebuild `libknot`.
.. code-block:: bash
$ make check libknot_CFLAGS="-I/opt/include" libknot_LIBS="-L/opt/lib -lknot -lknot-int -ldnssec"
$ make libknot_CFLAGS="-I/opt/include" libknot_LIBS="-L/opt/lib -lknot -lknot-int -ldnssec"
.. warning:: If the dependencies lie outside of library search path, you need to add them somehow.
Try ``LD_LIBRARY_PATH`` on Linux/BSD, and ``DYLD_FALLBACK_LIBRARY_PATH`` on OS X.
Otherwise you need to add the locations to linker search path.
When you have all the dependencies ready, you can build, test and install.
.. code-block:: bash
$ make PREFIX="/usr/local"
$ make check
$ make install
.. note:: Always build with ``PREFIX`` if you want to install, as it is hardcoded in the executable for module search path.
Alternatively you can build only specific parts of the project, i.e. ``library``.
.. code-block:: bash
$ make lib
$ make lib-install
.. note:: Documentation is not built by default, run ``make doc`` to build it.
Building extras
~~~~~~~~~~~~~~~
......
......@@ -19,7 +19,7 @@
#include "lib/defines.h"
#include "lib/resolve.h"
#ifndef NDEBUG
#ifdef WITH_DEBUG
/** @internal Print a debug message related to resolution. */
#define QRDEBUG(query, cls, fmt, ...) do { \
unsigned _ind = 0; \
......
......@@ -448,10 +448,11 @@ static int resolve(knot_layer_t *ctx, knot_pkt_t *pkt)
return KNOT_STATE_DONE;
}
/* Check response code. */
#ifndef NDEBUG
#ifdef WITH_DEBUG
lookup_table_t *rcode = lookup_by_id(knot_rcode_names, knot_wire_get_rcode(pkt->wire));
#endif
/* Check response code. */
switch(knot_wire_get_rcode(pkt->wire)) {
case KNOT_RCODE_NOERROR:
case KNOT_RCODE_NXDOMAIN:
......
......@@ -295,7 +295,7 @@ int kr_resolve(struct kr_context* ctx, knot_pkt_t *answer,
struct kr_request request;
request.pool = pool;
kr_resolve_begin(&request, ctx, answer);
#ifndef NDEBUG
#ifdef WITH_DEBUG
struct kr_rplan *rplan = &request.rplan; /* for DEBUG_MSG */
#endif
/* Resolve query, iteratively */
......@@ -433,20 +433,13 @@ int kr_resolve_produce(struct kr_request *request, struct sockaddr **dst, int *t
{
struct kr_rplan *rplan = &request->rplan;
struct kr_query *qry = kr_rplan_current(rplan);
unsigned ns_election_iter = 0;
/* No query left for resolution */
if (kr_rplan_empty(rplan)) {
return KNOT_STATE_FAIL;
}
#ifndef NDEBUG
unsigned ns_election_iter = 0;
char name_str[KNOT_DNAME_MAXLEN], type_str[16];
knot_dname_to_str(name_str, qry->sname, sizeof(name_str));
knot_rrtype_to_string(qry->stype, type_str, sizeof(type_str));
DEBUG_MSG("query '%s %s'\n", type_str, name_str);
#endif
/* Resolve current query and produce dependent or finish */
ITERATE_LAYERS(request, produce, packet);
if (request->state != KNOT_STATE_FAIL && knot_wire_get_qr(packet->wire)) {
......@@ -489,7 +482,10 @@ int kr_resolve_produce(struct kr_request *request, struct sockaddr **dst, int *t
/* If the query has already selected a NS and is waiting for IPv4/IPv6 record,
* elect best address only, otherwise elect a completely new NS.
*/
assert(++ns_election_iter < KR_ITER_LIMIT);
if(++ns_election_iter >= KR_ITER_LIMIT) {
DEBUG_MSG("=> couldn't agree NS decision, report this\n");
return KNOT_STATE_FAIL;
}
if (qry->flags & (QUERY_AWAIT_IPV4|QUERY_AWAIT_IPV6)) {
kr_nsrep_elect_addr(qry, request->ctx);
} else if (!(qry->flags & QUERY_TCP)) { /* Keep address when TCP retransmit. */
......@@ -518,7 +514,7 @@ int kr_resolve_produce(struct kr_request *request, struct sockaddr **dst, int *t
return KNOT_STATE_FAIL;
}
#ifndef NDEBUG
#ifdef WITH_DEBUG
char qname_str[KNOT_DNAME_MAXLEN], zonecut_str[KNOT_DNAME_MAXLEN], ns_str[SOCKADDR_STRLEN];
knot_dname_to_str(qname_str, knot_pkt_qname(packet), sizeof(qname_str));
struct sockaddr *addr = &qry->ns.addr.ip;
......@@ -535,10 +531,9 @@ int kr_resolve_produce(struct kr_request *request, struct sockaddr **dst, int *t
int kr_resolve_finish(struct kr_request *request, int state)
{
#ifndef NDEBUG
struct kr_rplan *rplan = &request->rplan;
DEBUG_MSG("finished: %d, mempool: %zu B\n", state, (size_t) mp_total_size(request->pool.ctx));
#endif
/* Finalize answer */
if (answer_finalize(request->answer) != 0) {
state = KNOT_STATE_FAIL;
......@@ -552,7 +547,7 @@ int kr_resolve_finish(struct kr_request *request, int state)
}
ITERATE_LAYERS(request, finish);
/* Clean up. */
kr_rplan_deinit(&request->rplan);
kr_rplan_deinit(rplan);
return KNOT_STATE_DONE;
}
......
......@@ -210,8 +210,8 @@ int kr_resolve_finish(struct kr_request *request, int state);
/**
* Return resolution plan.
* @param req request state
* @return pointer to rplan
* @param request request state
* @return pointer to rplan
*/
struct kr_rplan *kr_resolve_plan(struct kr_request *request);
......@@ -123,7 +123,7 @@ struct kr_query *kr_rplan_push(struct kr_rplan *rplan, struct kr_query *parent,
add_tail(&rplan->pending, &qry->node);
kr_zonecut_init(&qry->zone_cut, (const uint8_t *)"", rplan->pool);
#ifndef NDEBUG
#ifdef WITH_DEBUG
char name_str[KNOT_DNAME_MAXLEN], type_str[16];
knot_dname_to_str(name_str, name, sizeof(name_str));
knot_rrtype_to_string(type, type_str, sizeof(type_str));
......
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