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

lib: indented and descriptive debug messages

parent 194e3ac6
......@@ -28,12 +28,6 @@
#include "lib/cache.h"
#include "lib/defines.h"
#ifndef NDEBUG
#define DEBUG_MSG(fmt, ...) fprintf(stderr, "[cache] " fmt, ## __VA_ARGS__)
#else
#define DEBUG_MSG(fmt, ...)
#endif
#define db_api namedb_lmdb_api()
namedb_t *kr_cache_open(const char *handle, mm_ctx_t *mm, size_t maxsize)
......@@ -103,13 +97,7 @@ int kr_cache_peek(namedb_txn_t *txn, knot_rrset_t *rr, uint32_t *timestamp)
/* Check if the RRSet is in the cache. */
struct kr_cache_rrset *found_rr = cache_rr(txn, rr->owner, rr->type);
if (found_rr != NULL) {
#ifndef NDEBUG
char name_str[KNOT_DNAME_MAXLEN];
knot_dname_to_str(name_str, rr->owner, sizeof(name_str));
char type_str[16];
knot_rrtype_to_string(rr->type, type_str, sizeof(type_str));
DEBUG_MSG("read '%s %s' => %u RRs\n", name_str, type_str, found_rr->count);
#endif
/* Assign data and return success. */
rr->rrs.rr_count = found_rr->count;
rr->rrs.data = found_rr->data;
......@@ -183,14 +171,6 @@ int kr_cache_insert(namedb_txn_t *txn, const knot_rrset_t *rr, uint32_t timestam
namedb_val_t key = { keybuf, key_len };
namedb_val_t val = { NULL, sizeof(struct kr_cache_rrset) + knot_rdataset_size(&rr->rrs) };
#ifndef NDEBUG
char name_str[KNOT_DNAME_MAXLEN];
knot_dname_to_str(name_str, rr->owner, sizeof(name_str));
char type_str[16];
knot_rrtype_to_string(rr->type, type_str, sizeof(type_str));
DEBUG_MSG("write '%s %s' => %u RRs (key=%zuB,data=%zuB)\n", name_str, type_str, rr->rrs.rr_count, key.len, val.len);
#endif
int ret = db_api->insert(txn, &key, &val, 0);
if (ret != KNOT_EOK) {
return ret;
......@@ -211,16 +191,6 @@ int kr_cache_remove(namedb_txn_t *txn, const knot_rrset_t *rr)
size_t key_len = cache_key(keybuf, rr->owner, rr->type);
namedb_val_t key = { keybuf, key_len };
#ifndef NDEBUG
char name_str[KNOT_DNAME_MAXLEN];
knot_dname_to_str(name_str, rr->owner, sizeof(name_str));
char type_str[16];
knot_rrtype_to_string(rr->type, type_str, sizeof(type_str));
DEBUG_MSG("del '%s %s'\n", name_str, type_str);
#endif
/* TODO: selective deletion by RRSet subtraction */
return db_api->del(txn, &key);
}
......
......@@ -32,3 +32,15 @@ struct kr_layer_param {
struct kr_rplan *rplan;
knot_pkt_t *answer;
};
/*! \internal Print a debug message related to resolution. */
#ifndef NDEBUG
#define QRDEBUG(query, cls, fmt, ...) do { \
unsigned _ind = 0; \
for (struct kr_query *q = (query); q; q = q->parent, _ind += 2); \
fprintf(stderr, "[%s] %*s" fmt, cls, _ind, "", ## __VA_ARGS__); \
} while (0)
#else
#define QRDEBUG(query, cls, fmt, ...)
#endif
......@@ -26,11 +26,7 @@
#include "lib/rplan.h"
#include "lib/defines.h"
#ifndef NDEBUG
#define DEBUG_MSG(fmt, ...) fprintf(stderr, "[qiter] " fmt, ## __VA_ARGS__)
#else
#define DEBUG_MSG(fmt, ...)
#endif
#define DEBUG_MSG(fmt...) QRDEBUG(kr_rplan_current(param->rplan), "iter", fmt)
/* Packet classification. */
enum {
......@@ -277,9 +273,8 @@ static void finalize_answer(knot_pkt_t *pkt, struct kr_layer_param *param)
}
/*! \brief Error handling, RFC1034 5.3.3, 4d. */
static int resolve_error(knot_pkt_t *pkt, struct kr_layer_param *param, int errcode)
static int resolve_error(knot_pkt_t *pkt, struct kr_layer_param *param)
{
DEBUG_MSG("resolution error => %s\n", knot_strerror(errcode));
return KNOT_NS_PROC_FAIL;
}
......@@ -332,12 +327,10 @@ static int prepare_query(knot_layer_t *ctx, knot_pkt_t *pkt)
}
#ifndef NDEBUG
char name_str[KNOT_DNAME_MAXLEN], zonecut_str[KNOT_DNAME_MAXLEN], ns_str[KNOT_DNAME_MAXLEN], type_str[16];
char zonecut_str[KNOT_DNAME_MAXLEN], ns_str[KNOT_DNAME_MAXLEN];
knot_dname_to_str(ns_str, query->zone_cut.ns, sizeof(ns_str));
knot_dname_to_str(zonecut_str, query->zone_cut.name, sizeof(zonecut_str));
knot_dname_to_str(name_str, qname, sizeof(name_str));
knot_rrtype_to_string(qtype, type_str, sizeof(type_str));
DEBUG_MSG("query '%s %s' zone cut '%s' nameserver '%s'\n", name_str, type_str, zonecut_str, ns_str);
DEBUG_MSG("=> querying nameserver '%s' zone cut '%s'\n", ns_str, zonecut_str);
#endif
/* Query built, expect answer. */
......@@ -359,17 +352,19 @@ static int resolve(knot_layer_t *ctx, knot_pkt_t *pkt)
/* Check for packet processing errors first. */
if (pkt->parsed < pkt->size) {
return resolve_error(pkt, param, KNOT_EMALF);
DEBUG_MSG("=> malformed response\n");
return resolve_error(pkt, param);
} else if (!is_paired_to_query(pkt, query)) {
DEBUG_MSG("ignoring mismatching response\n");
DEBUG_MSG("=> ignoring mismatching response\n");
return KNOT_NS_PROC_MORE;
} else if (knot_wire_get_tc(pkt->wire)) {
DEBUG_MSG("truncated response, failover to TCP\n");
DEBUG_MSG("=> truncated response, failover to TCP\n");
struct kr_query *cur = kr_rplan_current(param->rplan);
if (cur) {
/* Fail if already on TCP. */
if (cur->flags & QUERY_TCP) {
return resolve_error(pkt, param, KNOT_EMALF);
DEBUG_MSG("=> TC=1 with TCP, bailing out\n");
return resolve_error(pkt, param);
}
cur->flags |= QUERY_TCP;
}
......@@ -382,7 +377,8 @@ static int resolve(knot_layer_t *ctx, knot_pkt_t *pkt)
case KNOT_RCODE_NXDOMAIN:
break; /* OK */
default:
return resolve_error(pkt, param, KNOT_ERROR);
DEBUG_MSG("=> rcode: %d\n", knot_wire_get_rcode(pkt->wire));
return resolve_error(pkt, param);
}
/* Resolve authority to see if it's referral or authoritative. */
......@@ -390,9 +386,11 @@ static int resolve(knot_layer_t *ctx, knot_pkt_t *pkt)
state = process_authority(pkt, param);
switch(state) {
case KNOT_NS_PROC_MORE: /* Not referral, process answer. */
DEBUG_MSG("=> rcode: %d\n", knot_wire_get_rcode(pkt->wire));
state = process_answer(pkt, param);
break;
case KNOT_NS_PROC_DONE: /* Referral, try to find glue. */
DEBUG_MSG("=> referral response, follow\n");
state = process_additional(pkt, param);
break;
default:
......
......@@ -23,11 +23,7 @@
#include "lib/layer/static.h"
#include "lib/layer/iterate.h"
#ifndef NDEBUG
#define DEBUG_MSG(fmt, ...) fprintf(stderr, "[cache] " fmt, ## __VA_ARGS__)
#else
#define DEBUG_MSG(fmt, ...)
#endif
#define DEBUG_MSG(fmt...) QRDEBUG(kr_rplan_current(param->rplan), " cc ", fmt)
typedef int (*rr_callback_t)(const knot_rrset_t *, unsigned, struct kr_layer_param *);
......@@ -98,6 +94,7 @@ static int read_cache(knot_layer_t *ctx, knot_pkt_t *pkt)
/* Try to find expected record first. */
int state = read_cache_rr(txn, &cache_rr, timestamp, callback, param);
if (state == KNOT_NS_PROC_DONE) {
DEBUG_MSG("=> satisfied from cache\n");
kr_rplan_pop(param->rplan, cur);
return state;
}
......@@ -250,6 +247,7 @@ static int write_cache(knot_layer_t *ctx, knot_pkt_t *pkt)
/* Cache only positive answers. */
/*! \todo Negative answers cache support */
if (knot_wire_get_rcode(pkt->wire) != KNOT_RCODE_NOERROR) {
DEBUG_MSG("write NCACHE (NOTIMPL)\n");
return ctx->state;
}
......@@ -257,10 +255,10 @@ static int write_cache(knot_layer_t *ctx, knot_pkt_t *pkt)
int ret = KNOT_EOK;
if (knot_wire_get_aa(pkt->wire)) {
ret = write_cache_answer(pkt, txn, pool, timestamp);
} else {
ret = write_cache_authority(pkt, txn, pool, timestamp);
}
ret = write_cache_authority(pkt, txn, pool, timestamp);
/* Cache full, do what we must. */
if (ret == KNOT_ESPACE) {
kr_cache_clear(txn);
......
......@@ -16,6 +16,8 @@
#include "lib/layer/static.h"
#define DEBUG_MSG(fmt...) QRDEBUG(NULL, "hint", fmt)
static int reset(knot_layer_t *ctx)
{
/* TODO: sync, cleanup after resolution */
......@@ -26,9 +28,6 @@ static int begin(knot_layer_t *ctx, void *param)
{
ctx->data = param;
struct kr_context *resolve = ((struct kr_layer_param *)param)->ctx;
assert(resolve);
/* TODO: read static hosts file */
return ctx->state;
......
......@@ -19,11 +19,7 @@
#include "lib/layer/stats.h"
#include "lib/rplan.h"
#ifndef NDEBUG
#define DEBUG_MSG(fmt, ...) fprintf(stderr, "[stats] " fmt, ## __VA_ARGS__)
#else
#define DEBUG_MSG(fmt, ...)
#endif
#define DEBUG_MSG(fmt...) QRDEBUG(NULL, "stat", fmt)
//static void update_stats(struct kr_ns *ns, double rtt)
//{
......
......@@ -28,11 +28,7 @@
#include "lib/layer/static.h"
#include "lib/layer/stats.h"
#ifndef NDEBUG
#define DEBUG_MSG(fmt, ...) fprintf(stderr, "[reslv] " fmt, ## __VA_ARGS__)
#else
#define DEBUG_MSG(fmt, ...)
#endif
#define DEBUG_MSG(fmt...) QRDEBUG(kr_rplan_current(param->rplan), "resl", fmt)
/* Defines */
#define ITER_LIMIT 50
......@@ -86,8 +82,16 @@ static int iterate(struct knot_requestor *requestor, struct kr_layer_param *para
struct kr_rplan *rplan = param->rplan;
struct kr_query *cur = kr_rplan_current(rplan);
#ifndef NDEBUG
char name_str[KNOT_DNAME_MAXLEN], type_str[16];
knot_dname_to_str(name_str, cur->sname, sizeof(name_str));
knot_rrtype_to_string(cur->stype, type_str, sizeof(type_str));
DEBUG_MSG("query '%s %s'\n", name_str, type_str);
#endif
/* Invalid address for current zone cut. */
if (sockaddr_len((struct sockaddr *)&cur->zone_cut.addr) < 1) {
DEBUG_MSG("=> ns missing A/AAAA, invalidating\n");
return invalidate_ns(rplan, cur);
}
......@@ -108,10 +112,12 @@ static int iterate(struct knot_requestor *requestor, struct kr_layer_param *para
}
/* Network error, retry over TCP. */
if (ret != KNOT_LAYER_ERROR && !(cur->flags & QUERY_TCP)) {
DEBUG_MSG("=> ns unreachable, retrying over TCP\n");
cur->flags |= QUERY_TCP;
return iterate(requestor, param);
}
/* Resolution failed, invalidate current NS and reset to UDP. */
DEBUG_MSG("=> resolution failed: '%s', invalidating\n", knot_strerror(ret));
ret = invalidate_ns(rplan, cur);
cur->flags &= ~QUERY_TCP;
}
......@@ -135,7 +141,7 @@ static int resolve_iterative(struct kr_layer_param *param, mm_ctx_t *pool)
while((ret == KNOT_EOK) && !kr_rplan_empty(param->rplan)) {
ret = iterate(&requestor, param);
if (++iter_count > ITER_LIMIT) {
DEBUG_MSG("iteration limit %d reached => SERVFAIL\n", ITER_LIMIT);
DEBUG_MSG("iteration limit %d reached\n", ITER_LIMIT);
ret = KNOT_ELIMIT;
}
}
......
......@@ -22,12 +22,9 @@
#include "lib/context.h"
#include "lib/cache.h"
#include "lib/defines.h"
#include "lib/layer.h"
#ifndef NDEBUG
#define DEBUG_MSG(fmt, ...) fprintf(stderr, "[rplan] " fmt, ## __VA_ARGS__)
#else
#define DEBUG_MSG(fmt, ...)
#endif
#define DEBUG_MSG(qry, fmt...) QRDEBUG(qry, "plan", fmt)
static struct kr_query *query_create(mm_ctx_t *pool, const knot_dname_t *name)
{
......@@ -108,6 +105,7 @@ struct kr_query *kr_rplan_push(struct kr_rplan *rplan, struct kr_query *parent,
if (rplan == NULL) {
return NULL;
}
struct kr_query *qry = query_create(rplan->pool, name);
if (qry == NULL) {
return NULL;
......@@ -129,7 +127,7 @@ struct kr_query *kr_rplan_push(struct kr_rplan *rplan, struct kr_query *parent,
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));
DEBUG_MSG("plan '%s' type '%s'\n", name_str, type_str);
DEBUG_MSG(parent, "plan '%s' type '%s'\n", name_str, type_str);
#endif
return qry;
......
......@@ -24,12 +24,7 @@
#include "lib/zonecut.h"
#include "lib/rplan.h"
#include "lib/defines.h"
#ifndef NDEBUG
#define DEBUG_MSG(fmt, ...) fprintf(stderr, "[z-cut] " fmt, ## __VA_ARGS__)
#else
#define DEBUG_MSG(fmt, ...)
#endif
#include "lib/layer.h"
/* \brief Root hint descriptor. */
struct hint_info {
......@@ -84,11 +79,6 @@ int kr_set_zone_cut(struct kr_zonecut *cut, const knot_dname_t *name, const knot
/* Invalidate address. */
cut->addr.ss_family = AF_UNSPEC;
char zonecut_str[KNOT_DNAME_MAXLEN], ns_str[KNOT_DNAME_MAXLEN];
knot_dname_to_str(ns_str, cut->ns, sizeof(ns_str));
knot_dname_to_str(zonecut_str, cut->name, sizeof(zonecut_str));
DEBUG_MSG("zone cut set '%s' ns '%s'\n", zonecut_str, ns_str);
return KNOT_EOK;
}
......
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