}
if (nread < 0 || !buf->base) {
- if (KR_LOG_LEVEL_IS(LOG_DEBUG)) {
+ if (kr_log_is_debug(IO, NULL)) {
struct sockaddr *peer = session_get_peer(s);
char *peer_str = kr_straddr(peer);
kr_log_debug(IO, "=> connection to '%s' closed by peer (%s)\n",
Decode data free space in session wire buffer. */
consumed = tls_process_input_data(s, (const uint8_t *)buf->base, nread);
if (consumed < 0) {
- if (KR_LOG_LEVEL_IS(LOG_DEBUG)) {
+ if (kr_log_is_debug(IO, NULL)) {
struct sockaddr *peer = session_get_peer(s);
char *peer_str = kr_straddr(peer);
kr_log_debug(IO, "=> connection to '%s': "
if (session_flags(s)->has_http) {
consumed = http_process_input_data(s, data, data_len);
if (consumed < 0) {
- if (KR_LOG_LEVEL_IS(LOG_DEBUG)) {
+ if (kr_log_is_debug(IO, NULL)) {
struct sockaddr *peer = session_get_peer(s);
char *peer_str = kr_straddr(peer);
kr_log_debug(IO, "=> connection to '%s': "
}
#ifdef DEBUG
- if (VERBOSE_STATUS) {
+ if (kr_log_is_debug(TLS, NULL)) {
char pin_base64[TLS_SHA256_BASE64_BUFLEN];
/* DEBUG: additionally compute and print the base64 pin.
* Not very efficient, but that's OK for DEBUG. */
if (handle->type == UV_TCP) {
if (status != 0) { // session probably not usable anymore; typically: ECONNRESET
- if (VERBOSE_STATUS) {
+ const struct kr_request *req = &task->ctx->req;
+ if (kr_log_is_debug(WORKER, req)) {
const char *peer_str = NULL;
if (!session_flags(s)->outgoing) {
peer_str = "hidden"; // avoid logging downstream IPs
}
if (!peer_str)
peer_str = "unknown"; // probably shouldn't happen
- kr_log_debug(WORKER, "=> disconnected from '%s': %s\n",
+ kr_log_req(req, 0, 0, WORKER,
+ "=> disconnected from '%s': %s\n",
peer_str, uv_strerror(status));
}
worker_end_tcp(s);
return;
}
+ const bool log_debug = kr_log_is_debug(WORKER, NULL);
+
/* Check if the connection is in the waiting list.
* If no, most likely this is timeouted connection
* which was removed from waiting list by
if (!s || s != session) {
/* session isn't on the waiting list.
* it's timeouted session. */
- if (VERBOSE_STATUS) {
+ if (log_debug) {
const char *peer_str = kr_straddr(peer);
kr_log_debug(WORKER, "=> connected to '%s', but session "
"is already timeouted, close\n",
/* session already in the connected list.
* Something went wrong, it can be due to races when kresd has tried
* to reconnect to upstream after unsuccessful attempt. */
- if (VERBOSE_STATUS) {
+ if (log_debug) {
const char *peer_str = kr_straddr(peer);
kr_log_debug(WORKER, "=> connected to '%s', but peer "
"is already connected, close\n",
}
if (status != 0) {
- if (VERBOSE_STATUS) {
+ if (log_debug) {
const char *peer_str = kr_straddr(peer);
kr_log_debug(WORKER, "=> connection to '%s' failed (%s), flagged as 'bad'\n",
peer_str ? peer_str : "", uv_strerror(status));
}
}
- if (VERBOSE_STATUS) {
+ if (log_debug) {
const char *peer_str = kr_straddr(peer);
kr_log_debug(WORKER, "=> connected to '%s'\n", peer_str ? peer_str : "");
}
}
struct kr_query *qry = task_get_last_pending_query(task);
- WITH_VERBOSE (qry) {
+ if (kr_log_is_debug_qry(WORKER, qry)) {
const char *peer_str = kr_straddr(peer);
VERBOSE_MSG(qry, "=> connection to '%s' failed (internal timeout)\n",
peer_str ? peer_str : "");
}
struct kr_query *qry = task_get_last_pending_query(task);
- WITH_VERBOSE (qry) {
+ if (kr_log_is_debug_qry(WORKER, qry)) {
const char *peer_str = kr_straddr(peer);
VERBOSE_MSG(qry, "=> connecting to: '%s'\n", peer_str ? peer_str : "");
}
static bool check_dname_for_lf(const knot_dname_t *n, const struct kr_query *qry/*logging*/)
{
const bool ret = knot_dname_size(n) == strlen((const char *)n) + 1;
- if (!ret) { WITH_VERBOSE(qry) {
+ if (!ret && kr_log_is_debug_qry(CACHE, qry)) {
auto_free char *n_str = kr_dname_text(n);
VERBOSE_MSG(qry, "=> skipping zero-containing name %s\n", n_str);
- } }
+ }
return ret;
}
{
const bool ret = !knot_rrtype_is_metatype(type)
&& type != KNOT_RRTYPE_RRSIG;
- if (!ret) { WITH_VERBOSE(qry) {
+ if (!ret && kr_log_is_debug_qry(CACHE, qry)) {
auto_free char *type_str = kr_rrtype_text(type);
VERBOSE_MSG(qry, "=> skipping RR type %s\n", type_str);
- } }
+ }
return ret;
}
struct kr_cache_p *peek)
{ /* Just wrap with extra verbose logging. */
const int ret = peek_exact_real(cache, name, type, peek);
- if (false && VERBOSE_STATUS) { /* too noisy for usual --verbose */
+ if (false && kr_log_is_debug(CACHE, NULL)) { /* too noisy for usual --verbose */
auto_free char *type_str = kr_rrtype_text(type),
*name_str = kr_dname_text(name);
const char *result_str = (ret == kr_ok() ? "hit" :
#define VERBOSE_MSG(qry, ...) QRVERBOSE((qry), CACHE, ## __VA_ARGS__)
+#define WITH_VERBOSE(qry) if (kr_log_is_debug_qry(CACHE, (qry)))
/** Shorthand for operations on cache backend */
#define cache_op(cache, op, ...) (cache)->api->op((cache)->db, &(cache)->stats, ## __VA_ARGS__)
if (kr_fails_assert(nsec_rr))
return kr_error(EFAULT);
- const uint32_t new_ttl_log =
- KR_LOG_LEVEL_IS(LOG_DEBUG) ? nsec_rr->ttl : -1;
const uint8_t *bm = knot_nsec_bitmap(nsec_rr->rrs.rdata);
uint16_t bm_size = knot_nsec_bitmap_len(nsec_rr->rrs.rdata);
int ret;
auto_free char *owner_str = kr_dname_text(nsec_rr->owner),
*next_str = kr_dname_text(knot_nsec_next(nsec_rr->rrs.rdata));
VERBOSE_MSG(qry, "=> NSEC wildcard: covered by: %s -> %s, new TTL %d\n",
- owner_str, next_str, new_ttl_log);
+ owner_str, next_str, nsec_rr->ttl);
}
return AR_SOA;
}
if (arw->set.rr) {
auto_free char *owner_str = kr_dname_text(nsec_rr->owner);
VERBOSE_MSG(qry, "%s: %s, new TTL %d\n",
- msg_start, owner_str, new_ttl_log);
+ msg_start, owner_str, nsec_rr->ttl);
} else {
/* don't repeat the RR if it's the same */
VERBOSE_MSG(qry, "%s, by the same RR\n", msg_start);
for (int i = 0; ;) {
int32_t log_new_ttl = -123456789; /* visually recognizable value */
ret = nsec_p_ttl(el[i], qry->timestamp.tv_sec, &log_new_ttl);
- if (!ret || VERBOSE_STATUS) {
+ if (!ret || kr_log_is_debug_qry(CACHE, qry)) {
nsec_p_init(&ans.nsec_p, el[i], !ret);
}
if (ret) {
const uint32_t ttl_max = MIN(knot_rrsig_original_ttl(rdata_j),
knot_rrsig_sig_expiration(rdata_j) - timestamp);
if (unlikely(covered->ttl > ttl_max)) {
- if (VERBOSE_STATUS) {
+ if (kr_log_is_debug_qry(VALIDATOR, vctx->log_qry)) {
auto_free char
*name_str = kr_dname_text(covered->owner),
*type_str = kr_rrtype_text(covered->type);
#define VERBOSE_MSG(...) QRVERBOSE(req->current_query, ITERATOR, __VA_ARGS__)
#define QVERBOSE_MSG(qry, ...) QRVERBOSE(qry, ITERATOR, __VA_ARGS__)
+#define WITH_VERBOSE(qry) if (kr_log_is_debug_qry(ITERATOR, (qry)))
/* Iterator often walks through packet section, this is an abstraction. */
typedef int (*rr_callback_t)(const knot_rrset_t *, unsigned, struct kr_request *);
* The most important part is to check for spoofing: is_paired_to_query() */
query->flags.PKT_IS_SANE = true;
- const knot_lookup_t *rcode = NULL;
- if (KR_LOG_LEVEL_IS(LOG_DEBUG))
- rcode = knot_lookup_by_id(knot_rcode_names, knot_wire_get_rcode(pkt->wire));
+ const knot_lookup_t *rcode = // just for logging but cheaper than a condition
+ knot_lookup_by_id(knot_rcode_names, knot_wire_get_rcode(pkt->wire));
// We can't return directly from the switch because we have to give feedback to server selection first
int ret = 0;
static void log_bogus_rrsig(kr_rrset_validation_ctx_t *vctx,
const knot_rrset_t *rr, const char *msg) {
- WITH_VERBOSE(vctx->log_qry) {
+ if (kr_log_is_debug_qry(VALIDATOR, vctx->log_qry)) {
auto_free char *name_text = kr_dname_text(rr->owner);
auto_free char *type_text = kr_rrtype_text(rr->type);
VERBOSE_MSG(vctx->log_qry, ">< %s: %s %s "
KR_EXPORT KR_PRINTF(4)
void kr_log_q1(const struct kr_query *qry, enum kr_log_group group, const char *tag, const char *fmt, ...);
-/** Block run in --verbose mode; optimized when not run. */
-#define VERBOSE_STATUS __builtin_expect(KR_LOG_LEVEL_IS(LOG_DEBUG), false) // TODO vyhodit
-#define WITH_VERBOSE(query) if(__builtin_expect(KR_LOG_LEVEL_IS(LOG_DEBUG) || kr_log_qtrace_enabled(query), false))
-
/** Return whether a particular log group in a request is in debug/verbose mode.
*
* Typically you use this as condition to compute some data to be logged,
*/
#define kr_log_is_debug(grp, req) \
__builtin_expect(kr_log_is_debug_fun(LOG_GRP_ ## grp, (req)), false)
-#define kr_log_is_debug_qry(grp, qry) kr_log_is_debug(grp, (qry)->request)
+#define kr_log_is_debug_qry(grp, qry) kr_log_is_debug(grp, (qry) ? (qry)->request : NULL)
KR_EXPORT
bool kr_log_is_debug_fun(enum kr_log_group group, const struct kr_request *req);
static void answer_fail(struct kr_request *request)
{
/* Note: OPT in SERVFAIL response is still useful for cookies/additional info. */
- if (VERBOSE_STATUS || kr_log_rtrace_enabled(request))
+ if (kr_log_is_debug(RESOLVER, request))
kr_log_req(request, 0, 0, RESOLVER,
"request failed, answering with empty SERVFAIL\n");
knot_pkt_t *answer = request->answer;
{
uint64_t resolving_time = now - qry->creation_time_mono;
if (resolving_time > KR_RESOLVE_TIME_LIMIT) {
- WITH_VERBOSE(qry) {
- VERBOSE_MSG(qry, "query resolution time limit exceeded\n");
- }
+ VERBOSE_MSG(qry, "query resolution time limit exceeded\n");
return true;
}
return false;
if (!qry->flags.CACHED) {
if (request->state & KR_STATE_FAIL) {
if (++request->count_fail_row > KR_CONSUME_FAIL_ROW_LIMIT) {
- if (VERBOSE_STATUS || kr_log_rtrace_enabled(request)) {
+ if (kr_log_is_debug(RESOLVER, request)) {
kr_log_req(request, 0, 2, RESOLVER,
"=> too many failures in a row, "
"bail out (mitigation for NXNSAttack "
kr_ta_get(trust_anchors, wanted_name)) {
qry->flags.DNSSEC_WANT = true;
want_secured = true;
- WITH_VERBOSE(qry) {
- KR_DNAME_GET_STR(qname_str, wanted_name);
- VERBOSE_MSG(qry, ">< TA: '%s'\n", qname_str);
+ if (kr_log_is_debug_qry(RESOLVER, qry)) {
+ KR_DNAME_GET_STR(qname_str, wanted_name);
+ VERBOSE_MSG(qry, ">< TA: '%s'\n", qname_str);
}
}
mm_free(qry->zone_cut.pool, qry->zone_cut.trust_anchor);
qry->zone_cut.trust_anchor = knot_rrset_copy(ta_rr, qry->zone_cut.pool);
- WITH_VERBOSE(qry) {
- KR_DNAME_GET_STR(qname_str, ta_rr->owner);
- VERBOSE_MSG(qry, ">< TA: '%s'\n", qname_str);
+ if (kr_log_is_debug_qry(RESOLVER, qry)) {
+ KR_DNAME_GET_STR(qname_str, ta_rr->owner);
+ VERBOSE_MSG(qry, ">< TA: '%s'\n", qname_str);
}
}
}
}
}
- WITH_VERBOSE(qry) {
-
- KR_DNAME_GET_STR(qname_str, knot_pkt_qname(packet));
- KR_DNAME_GET_STR(ns_name, transport->ns_name);
- KR_DNAME_GET_STR(zonecut_str, qry->zone_cut.name);
- KR_RRTYPE_GET_STR(type_str, knot_pkt_qtype(packet));
- const char *ns_str = kr_straddr(&transport->address.ip);
+ if (kr_log_is_debug_qry(RESOLVER, qry)) {
+ KR_DNAME_GET_STR(qname_str, knot_pkt_qname(packet));
+ KR_DNAME_GET_STR(ns_name, transport->ns_name);
+ KR_DNAME_GET_STR(zonecut_str, qry->zone_cut.name);
+ KR_RRTYPE_GET_STR(type_str, knot_pkt_qtype(packet));
+ const char *ns_str = kr_straddr(&transport->address.ip);
- VERBOSE_MSG(qry,
+ VERBOSE_MSG(qry,
"=> id: '%05u' querying: '%s'@'%s' zone cut: '%s' "
"qname: '%s' qtype: '%s' proto: '%s'\n",
qry->id, ns_name, ns_str ? ns_str : "", zonecut_str,
return NULL;
}
- WITH_VERBOSE(qry) {
VERBOSE_MSG(qry, "plan '%s' type '%s' uid [%05u.%02u]\n", "", "",
qry->request ? qry->request->uid : 0, qry->uid);
- }
return qry;
}
qry->sclass = cls;
qry->stype = type;
- WITH_VERBOSE(qry) {
- KR_DNAME_GET_STR(name_str, name);
- KR_RRTYPE_GET_STR(type_str, type);
- VERBOSE_MSG(parent, "plan '%s' type '%s' uid [%05u.%02u]\n",
- name_str, type_str,
- qry->request ? qry->request->uid : 0, qry->uid);
+ if (kr_log_is_debug_qry(PLAN, qry)) {
+ KR_DNAME_GET_STR(name_str, name);
+ KR_RRTYPE_GET_STR(type_str, type);
+ VERBOSE_MSG(parent, "plan '%s' type '%s' uid [%05u.%02u]\n",
+ name_str, type_str,
+ qry->request ? qry->request->uid : 0, qry->uid);
}
return qry;
}
state, qry->request->ctx->cache_rtt_tout_retry_interval);
#ifdef SELECTION_CHOICE_LOGGING
// This is sometimes useful for debugging, but usually too verbose
- WITH_VERBOSE(qry)
- {
+ if (kr_log_is_debug_qry(SELECTION, qry)) {
const char *ns_str = kr_straddr(&address->ip);
VERBOSE_MSG(qry, "rtt of %s is %d, variance is %d\n", ns_str,
state->rtt_state.srtt, state->rtt_state.variance);
if (transport->address_len == sizeof(struct in6_addr))
no6_success(qry);
- WITH_VERBOSE(qry)
- {
- KR_DNAME_GET_STR(ns_name, transport->ns_name);
- KR_DNAME_GET_STR(zonecut_str, qry->zone_cut.name);
- const char *ns_str = kr_straddr(&transport->address.ip);
+ if (kr_log_is_debug_qry(SELECTION, qry)) {
+ KR_DNAME_GET_STR(ns_name, transport->ns_name);
+ KR_DNAME_GET_STR(zonecut_str, qry->zone_cut.name);
+ const char *ns_str = kr_straddr(&transport->address.ip);
- VERBOSE_MSG(
- qry,
- "=> id: '%05u' updating: '%s'@'%s' zone cut: '%s'"
- " with rtt %u to srtt: %d and variance: %d \n",
- qry->id, ns_name, ns_str ? ns_str : "", zonecut_str,
- rtt, new_rtt_state.srtt, new_rtt_state.variance);
+ VERBOSE_MSG(
+ qry,
+ "=> id: '%05u' updating: '%s'@'%s' zone cut: '%s'"
+ " with rtt %u to srtt: %d and variance: %d \n",
+ qry->id, ns_name, ns_str ? ns_str : "", zonecut_str,
+ rtt, new_rtt_state.srtt, new_rtt_state.variance);
}
}
addr_state->error_count++;
addr_state->errors[sel_error]++;
- WITH_VERBOSE(qry)
- {
- KR_DNAME_GET_STR(ns_name, transport->ns_name);
- KR_DNAME_GET_STR(zonecut_str, qry->zone_cut.name);
- const char *ns_str = kr_straddr(&transport->address.ip);
- const char *err_str = kr_selection_error_str(sel_error);
-
- VERBOSE_MSG(
- qry,
- "=> id: '%05u' noting selection error: '%s'@'%s' zone cut: '%s' error: %d %s\n",
- qry->id, ns_name, ns_str ? ns_str : "", zonecut_str,
- sel_error, err_str ? err_str : "??");
+ if (kr_log_is_debug_qry(SELECTION, qry)) {
+ KR_DNAME_GET_STR(ns_name, transport->ns_name);
+ KR_DNAME_GET_STR(zonecut_str, qry->zone_cut.name);
+ const char *ns_str = kr_straddr(&transport->address.ip);
+ const char *err_str = kr_selection_error_str(sel_error);
+
+ VERBOSE_MSG(
+ qry,
+ "=> id: '%05u' noting selection error: '%s'@'%s'"
+ " zone cut: '%s' error: %d %s\n",
+ qry->id, ns_name, ns_str ? ns_str : "",
+ zonecut_str, sel_error, err_str ? err_str : "??");
}
}
qry->flags.DNSSEC_BOGUS = true;
}
- WITH_VERBOSE(qry)
+ if (kr_log_is_debug_qry(SELECTION, qry))
{
KR_DNAME_GET_STR(zonecut_str, qry->zone_cut.name);
if (*transport) {
infos[1] = fetch_addr(*pack, ns_name, KNOT_RRTYPE_AAAA, cut->pool, qry);
#if 0 /* rather unlikely to be useful unless changing some zcut code */
- WITH_VERBOSE(qry) {
+ if (kr_log_is_debug_qry(ZCUT, qry)) {
auto_free char *ns_name_txt = kr_dname_text(ns_name);
VERBOSE_MSG(qry, "NS %s infos: %d, %d\n",
ns_name_txt, (int)infos[0], (int)infos[1]);
all_bad = all_bad && infos[0] <= AI_LAST_BAD && infos[1] <= AI_LAST_BAD;
}
- if (all_bad) { WITH_VERBOSE(qry) {
+ if (all_bad && kr_log_is_debug_qry(ZCUT, qry)) {
auto_free char *name_txt = kr_dname_text(name);
VERBOSE_MSG(qry, "cut %s: all NSs bad, count = %d\n",
name_txt, (int)ns_rds.count);
- } }
+ }
knot_rdataset_clear(&ns_rds, cut->pool);
return all_bad ? ELOOP : kr_ok();
}
label, KNOT_RRTYPE_DNSKEY, cut->pool, qry);
}
update_cut_name(cut, label);
- WITH_VERBOSE(qry) {
+ if (kr_log_is_debug_qry(ZCUT, qry)) {
auto_free char *label_str = kr_dname_text(label);
VERBOSE_MSG(qry,
"found cut: %s (rank 0%.2o return codes: DS %d, DNSKEY %d)\n",
/** Printf a *binary* string in a human-readable way. */
void debug_printbin(const char *str, unsigned int len);
+/** Block run in --verbose mode; optimized when not run. */
+#define VERBOSE_STATUS __builtin_expect(KR_LOG_LEVEL_IS(LOG_DEBUG), false)
+/* TODO: replace when solving GC logging properly */
+