Skip to content
Snippets Groups Projects
Commit 5ac3c016 authored by Jan Včelák's avatar Jan Včelák :rocket:
Browse files

libknot: remove debug outputs

parent bfc637da
No related branches found
No related tags found
No related merge requests found
/*!
* \file common/debug.h
*
* \author Jan Kadlec <jan.kadlec.@nic.cz>
* \author Lubos Slovak <lubos.slovak@nic.cz>
* \author Marek Vavrusa <marek.vavrusa@nic.cz>
*
* \brief Functions for debug output of structures.
*
* \addtogroup libknot
* @{
*/
/* Copyright (C) 2011 CZ.NIC, z.s.p.o. <knot-dns@labs.nic.cz>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#pragma once
#include <stdint.h>
#include <stdio.h>
#include "libknot/internal/log.h"
#include "libknot/internal/print.h"
/*
* Debug macros
*/
#ifdef KNOT_ZONES_DEBUG
#define KNOT_ZONE_DEBUG
#define KNOT_ZONEDIFF_DEBUG
#endif
#ifdef KNOT_NS_DEBUG
#define KNOT_EDNS_DEBUG
#endif
#ifdef KNOT_PACKET_DEBUG
#define KNOT_RESPONSE_DEBUG
#endif
#ifdef KNOT_RR_DEBUG
#define KNOT_RRSET_DEBUG
#endif
#ifdef KNOT_XFR_DEBUG
#define KNOT_TSIG_DEBUG
#endif
/******************************************************************************/
#ifdef KNOT_NS_DEBUG
/* Brief messages. */
#ifdef DEBUG_ENABLE_BRIEF
#define dbg_ns(msg...) log_msg(LOG_DEBUG, msg)
#define dbg_ns_hex(data, len) hex_log((data), (len))
#define dbg_ns_exec(cmds) do { cmds } while (0)
#else
#define dbg_ns(msg...)
#define dbg_ns_hex(data, len)
#define dbg_ns_exec(cmds)
#endif
/* Verbose messages. */
#ifdef DEBUG_ENABLE_VERBOSE
#define dbg_ns_verb(msg...) log_msg(LOG_DEBUG, msg)
#define dbg_ns_hex_verb(data, len) hex_log((data), (len))
#define dbg_ns_exec_verb(cmds) do { cmds } while (0)
#else
#define dbg_ns_verb(msg...)
#define dbg_ns_hex_verb(data, len)
#define dbg_ns_exec_verb(cmds)
#endif
/* Detail messages. */
#ifdef DEBUG_ENABLE_DETAILS
#define dbg_ns_detail(msg...) log_msg(LOG_DEBUG, msg)
#define dbg_ns_hex_detail(data, len) hex_log((data), (len))
#define dbg_ns_exec_detail(cmds) do { cmds } while (0)
#else
#define dbg_ns_detail(msg...)
#define dbg_ns_hex_detail(data, len)
#define dbg_ns_exec_detail(cmds)
#endif
/* No messages. */
#else
#define dbg_ns(msg...)
#define dbg_ns_hex(data, len)
#define dbg_ns_exec(cmds)
#define dbg_ns_verb(msg...)
#define dbg_ns_hex_verb(data, len)
#define dbg_ns_exec_verb(cmds)
#define dbg_ns_detail(msg...)
#define dbg_ns_hex_detail(data, len)
#define dbg_ns_exec_detail(cmds)
#endif
/******************************************************************************/
#ifdef KNOT_ZONE_DEBUG
/* Brief messages. */
#ifdef DEBUG_ENABLE_BRIEF
#define dbg_zone(msg...) log_msg(LOG_DEBUG, msg)
#define dbg_zone_hex(data, len) hex_log((data), (len))
#define dbg_zone_exec(cmds) do { cmds } while (0)
#else
#define dbg_zone(msg...)
#define dbg_zone_hex(data, len)
#define dbg_zone_exec(cmds)
#endif
/* Verbose messages. */
#ifdef DEBUG_ENABLE_VERBOSE
#define dbg_zone_verb(msg...) log_msg(LOG_DEBUG, msg)
#define dbg_zone_hex_verb(data, len) hex_log((data), (len))
#define dbg_zone_exec_verb(cmds) do { cmds } while (0)
#else
#define dbg_zone_verb(msg...)
#define dbg_zone_hex_verb(data, len)
#define dbg_zone_exec_verb(cmds)
#endif
/* Detail messages. */
#ifdef DEBUG_ENABLE_DETAILS
#define dbg_zone_detail(msg...) log_msg(LOG_DEBUG, msg)
#define dbg_zone_hex_detail(data, len) hex_log((data), (len))
#define dbg_zone_exec_detail(cmds) do { cmds } while (0)
#else
#define dbg_zone_detail(msg...)
#define dbg_zone_hex_detail(data, len)
#define dbg_zone_exec_detail(cmds)
#endif
/* No messages. */
#else
#define dbg_zone(msg...)
#define dbg_zone_hex(data, len)
#define dbg_zone_exec(cmds)
#define dbg_zone_verb(msg...)
#define dbg_zone_hex_verb(data, len)
#define dbg_zone_exec_verb(cmds)
#define dbg_zone_detail(msg...)
#define dbg_zone_hex_detail(data, len)
#define dbg_zone_exec_detail(cmds)
#endif
/******************************************************************************/
#ifdef KNOT_ZONEDIFF_DEBUG
/* Brief messages. */
#ifdef DEBUG_ENABLE_BRIEF
#define dbg_zonediff(msg...) fprintf(stderr, msg)
#define dbg_zonediff_hex(data, len) hex_print((data), (len))
#else
#define dbg_zonediff(msg...)
#define dbg_zonediff_hex(data, len)
#endif
/* Verbose messages. */
#ifdef DEBUG_ENABLE_VERBOSE
#define dbg_zonediff_verb(msg...) fprintf(stderr, msg)
#define dbg_zonediff_hex_verb(data, len) hex_print((data), (len))
#else
#define dbg_zonediff_verb(msg...)
#define dbg_zonediff_hex_verb(data, len)
#endif
/* Detail messages. */
#ifdef DEBUG_ENABLE_DETAILS
#define dbg_zonediff_detail(msg...) fprintf(stderr, msg)
#define dbg_zonediff_hex_detail(data, len) hex_print((data), (len))
#define dbg_zonediff_exec_detail(cmds) do { cmds } while (0)
#else
#define dbg_zonediff_detail(msg...)
#define dbg_zonediff_hex_detail(data, len)
#define dbg_zonediff_exec_detail(cmds)
#endif
/* No messages. */
#else
#define dbg_zonediff(msg...)
#define dbg_zonediff_hex(data, len)
#define dbg_zonediff_verb(msg...)
#define dbg_zonediff_hex_verb(data, len)
#define dbg_zonediff_detail(msg...)
#define dbg_zonediff_hex_detail(data, len)
#define dbg_zonediff_exec_detail(cmds)
#endif
/******************************************************************************/
#ifdef KNOT_RESPONSE_DEBUG
/* Brief messages. */
#ifdef DEBUG_ENABLE_BRIEF
#define dbg_response(msg...) log_msg(LOG_DEBUG, msg)
#define dbg_response_hex(data, len) hex_log((data), (len))
#define dbg_response_exec(cmds) do { cmds } while (0)
#else
#define dbg_response(msg...)
#define dbg_response_hex(data, len)
#define dbg_response_exec(cmds)
#endif
/* Verbose messages. */
#ifdef DEBUG_ENABLE_VERBOSE
#define dbg_response_verb(msg...) log_msg(LOG_DEBUG, msg)
#define dbg_response_hex_verb(data, len) hex_log((data), (len))
#define dbg_response_exec_verb(cmds) do { cmds } while (0)
#else
#define dbg_response_verb(msg...)
#define dbg_response_hex_verb(data, len)
#define dbg_response_exec_verb(cmds)
#endif
/* Detail messages. */
#ifdef DEBUG_ENABLE_DETAILS
#define dbg_response_detail(msg...) log_msg(LOG_DEBUG, msg)
#define dbg_response_hex_detail(data, len) hex_log((data), (len))
#define dbg_response_exec_detail(cmds) do { cmds } while (0)
#else
#define dbg_response_detail(msg...)
#define dbg_response_hex_detail(data, len)
#define dbg_response_exec_detail(cmds)
#endif
/* No messages. */
#else
#define dbg_response(msg...)
#define dbg_response_hex(data, len)
#define dbg_response_exec(cmds)
#define dbg_response_verb(msg...)
#define dbg_response_hex_verb(data, len)
#define dbg_response_exec_verb(cmds)
#define dbg_response_detail(msg...)
#define dbg_response_hex_detail(data, len)
#define dbg_response_exec_detail(cmds)
#endif
/******************************************************************************/
#ifdef KNOT_PACKET_DEBUG
/* Brief messages. */
#ifdef DEBUG_ENABLE_BRIEF
#define dbg_packet(msg...) log_msg(LOG_DEBUG, msg)
#define dbg_packet_hex(data, len) hex_log((data), (len))
#define dbg_packet_exec(cmds) do { cmds } while (0)
#else
#define dbg_packet(msg...)
#define dbg_packet_hex(data, len)
#define dbg_packet_exec(cmds)
#endif
/* Verbose messages. */
#ifdef DEBUG_ENABLE_VERBOSE
#define dbg_packet_verb(msg...) log_msg(LOG_DEBUG, msg)
#define dbg_packet_hex_verb(data, len) hex_log((data), (len))
#define dbg_packet_exec_verb(cmds) do { cmds } while (0)
#else
#define dbg_packet_verb(msg...)
#define dbg_packet_hex_verb(data, len)
#define dbg_packet_exec_verb(cmds)
#endif
/* Detail messages. */
#ifdef DEBUG_ENABLE_DETAILS
#define dbg_packet_detail(msg...) log_msg(LOG_DEBUG, msg)
#define dbg_packet_hex_detail(data, len) hex_log((data), (len))
#define dbg_packet_exec_detail(cmds) do { cmds } while (0)
#else
#define dbg_packet_detail(msg...)
#define dbg_packet_hex_detail(data, len)
#define dbg_packet_exec_detail(cmds)
#endif
/* No messages. */
#else
#define dbg_packet(msg...)
#define dbg_packet_hex(data, len)
#define dbg_packet_exec(cmds)
#define dbg_packet_verb(msg...)
#define dbg_packet_hex_verb(data, len)
#define dbg_packet_exec_verb(cmds)
#define dbg_packet_detail(msg...)
#define dbg_packet_hex_detail(data, len)
#define dbg_packet_exec_detail(cmds)
#endif
/******************************************************************************/
#ifdef KNOT_EDNS_DEBUG
/* Brief messages. */
#ifdef DEBUG_ENABLE_BRIEF
#define dbg_edns(msg...) log_msg(LOG_DEBUG, msg)
#define dbg_edns_hex(data, len) hex_log((data), (len))
#else
#define dbg_edns(msg...)
#define dbg_edns_hex(data, len)
#endif
/* Verbose messages. */
#ifdef DEBUG_ENABLE_VERBOSE
#define dbg_edns_verb(msg...) log_msg(LOG_DEBUG, msg)
#define dbg_edns_hex_verb(data, len) hex_log((data), (len))
#else
#define dbg_edns_verb(msg...)
#define dbg_edns_hex_verb(data, len)
#endif
/* Detail messages. */
#ifdef DEBUG_ENABLE_DETAILS
#define dbg_edns_detail(msg...) log_msg(LOG_DEBUG, msg)
#define dbg_edns_hex_detail(data, len) hex_log((data), (len))
#else
#define dbg_edns_detail(msg...)
#define dbg_edns_hex_detail(data, len)
#endif
/* No messages. */
#else
#define dbg_edns(msg...)
#define dbg_edns_hex(data, len)
#define dbg_edns_verb(msg...)
#define dbg_edns_hex_verb(data, len)
#define dbg_edns_detail(msg...)
#define dbg_edns_hex_detail(data, len)
#endif
/******************************************************************************/
#ifdef KNOT_TSIG_DEBUG
/* Brief messages. */
#ifdef DEBUG_ENABLE_BRIEF
#define dbg_tsig(msg...) log_msg(LOG_DEBUG, msg)
#define dbg_tsig_hex(data, len) hex_log((data), (len))
#else
#define dbg_tsig(msg...)
#define dbg_tsig_hex(data, len)
#endif
/* Verbose messages. */
#ifdef DEBUG_ENABLE_VERBOSE
#define dbg_tsig_verb(msg...) log_msg(LOG_DEBUG, msg)
#define dbg_tsig_hex_verb(data, len) hex_log((data), (len))
#else
#define dbg_tsig_verb(msg...)
#define dbg_tsig_hex_verb(data, len)
#endif
/* Detail messages. */
#ifdef DEBUG_ENABLE_DETAILS
#define dbg_tsig_detail(msg...) log_msg(LOG_DEBUG, msg)
#define dbg_tsig_hex_detail(data, len) hex_log((data), (len))
#else
#define dbg_tsig_detail(msg...)
#define dbg_tsig_hex_detail(data, len)
#endif
/* No messages. */
#else
#define dbg_tsig(msg...)
#define dbg_tsig_hex(data, len)
#define dbg_tsig_verb(msg...)
#define dbg_tsig_hex_verb(data, len)
#define dbg_tsig_detail(msg...)
#define dbg_tsig_hex_detail(data, len)
#endif
/******************************************************************************/
#ifdef KNOT_RRSET_DEBUG
/* Brief messages. */
#ifdef DEBUG_ENABLE_BRIEF
#define dbg_rrset(msg...) log_msg(LOG_DEBUG, msg)
#define dbg_rrset_hex(data, len) hex_log((data), (len))
#define dbg_rrset_exec(cmds) do { cmds } while (0)
#else
#define dbg_rrset(msg...)
#define dbg_rrset_hex(data, len)
#define dbg_rrset_exec(cmds)
#endif
/* Verbose messages. */
#ifdef DEBUG_ENABLE_VERBOSE
#define dbg_rrset_verb(msg...) log_msg(LOG_DEBUG, msg)
#define dbg_rrset_hex_verb(data, len) hex_log((data), (len))
#define dbg_rrset_exec_verb(cmds) do { cmds } while (0)
#else
#define dbg_rrset_verb(msg...)
#define dbg_rrset_hex_verb(data, len)
#define dbg_rrset_exec_verb(cmds)
#endif
/* Detail messages. */
#ifdef DEBUG_ENABLE_DETAILS
#define dbg_rrset_detail(msg...) log_msg(LOG_DEBUG, msg)
#define dbg_rrset_hex_detail(data, len) hex_log((data), (len))
#define dbg_rrset_exec_detail(cmds) do { cmds } while (0)
#else
#define dbg_rrset_detail(msg...)
#define dbg_rrset_hex_detail(data, len)
#define dbg_rrset_exec_detail(cmds)
#endif
/* No messages. */
#else
#define dbg_rrset(msg...)
#define dbg_rrset_hex(data, len)
#define dbg_rrset_exec(cmds)
#define dbg_rrset_verb(msg...)
#define dbg_rrset_hex_verb(data, len)
#define dbg_rrset_exec_verb(cmds)
#define dbg_rrset_detail(msg...)
#define dbg_rrset_hex_detail(data, len)
#define dbg_rrset_exec_detail(cmds)
#endif
/******************************************************************************/
#ifdef KNOT_DNSSEC_DEBUG
/* Brief messages. */
#ifdef DEBUG_ENABLE_BRIEF
#define dbg_dnssec(msg...) log_msg(LOG_DEBUG, msg)
#define dbg_dnssec_hex(data, len) hex_log((data), (len))
#define dbg_dnssec_exec(cmds) do { cmds } while (0)
#else
#define dbg_dnssec(msg...)
#define dbg_dnssec_hex(data, len)
#define dbg_dnssec_exec(cmds)
#endif
/* Verbose messages. */
#ifdef DEBUG_ENABLE_VERBOSE
#define dbg_dnssec_verb(msg...) log_msg(LOG_DEBUG, msg)
#define dbg_dnssec_hex_verb(data, len) hex_log((data), (len))
#define dbg_dnssec_exec_verb(cmds) do { cmds } while (0)
#else
#define dbg_dnssec_verb(msg...)
#define dbg_dnssec_hex_verb(data, len)
#define dbg_dnssec_exec_verb(cmds)
#endif
/* Detail messages. */
#ifdef DEBUG_ENABLE_DETAILS
#define dbg_dnssec_detail(msg...) log_msg(LOG_DEBUG, msg)
#define dbg_dnssec_hex_detail(data, len) hex_log((data), (len))
#define dbg_dnssec_exec_detail(cmds) do { cmds } while (0)
#else
#define dbg_dnssec_detail(msg...)
#define dbg_dnssec_hex_detail(data, len)
#define dbg_dnssec_exec_detail(cmds)
#endif
/* No messages. */
#else
#define dbg_dnssec(msg...)
#define dbg_dnssec_hex(data, len)
#define dbg_dnssec_exec(cmds)
#define dbg_dnssec_verb(msg...)
#define dbg_dnssec_hex_verb(data, len)
#define dbg_dnssec_exec_verb(cmds)
#define dbg_dnssec_detail(msg...)
#define dbg_dnssec_hex_detail(data, len)
#define dbg_dnssec_exec_detail(cmds)
#endif
/******************************************************************************/
/*! @} */
......@@ -58,12 +58,10 @@ int knot_compr_put_dname(const knot_dname_t *dname, uint8_t *dst, uint16_t max,
knot_compr_t *compr)
{
/* Write uncompressible names directly. */
dbg_packet("%s(%p,%p,%u,%p)\n", __func__, dname, dst, max, compr);
if (dname == NULL || dst == NULL) {
return KNOT_EINVAL;
}
if (compr == NULL || *dname == '\0') {
dbg_packet("%s: uncompressible, writing full name\n", __func__);
return knot_dname_to_wire(dst, dname, max);
}
......@@ -135,8 +133,7 @@ int knot_compr_put_dname(const knot_dname_t *dname, uint8_t *dst, uint16_t max,
compr->suffix.pos = wire_pos;
compr->suffix.labels = orig_labels;
}
dbg_packet("%s: compressed to %u bytes (match=%zu,@%zu)\n",
__func__, written, dname - match_begin, wire_pos);
return written;
}
......
......@@ -162,7 +162,6 @@ static int pkt_reset_sections(knot_pkt_t *pkt)
/*! \brief Clear packet payload and free allocated data. */
static void pkt_clear_payload(knot_pkt_t *pkt)
{
dbg_packet("%s(%p)\n", __func__, pkt);
assert(pkt);
/* Keep question. */
......@@ -204,7 +203,6 @@ _public_
knot_pkt_t *knot_pkt_new(void *wire, uint16_t len, mm_ctx_t *mm)
{
/* Default memory allocator if NULL. */
dbg_packet("%s(%p, %hu, %p)\n", __func__, wire, len, mm);
mm_ctx_t _mm;
if (mm == NULL) {
mm_ctx_init(&_mm);
......@@ -217,7 +215,6 @@ knot_pkt_t *knot_pkt_new(void *wire, uint16_t len, mm_ctx_t *mm)
_public_
int knot_pkt_copy(knot_pkt_t *dst, const knot_pkt_t *src)
{
dbg_packet("%s(%p, %p)\n", __func__, dst, src);
if (dst == NULL || src == NULL) {
return KNOT_EINVAL;
}
......@@ -245,7 +242,6 @@ int knot_pkt_copy(knot_pkt_t *dst, const knot_pkt_t *src)
_public_
int knot_pkt_init_response(knot_pkt_t *pkt, const knot_pkt_t *query)
{
dbg_packet("%s(%p, %p)\n", __func__, pkt, query);
if (pkt == NULL || query == NULL) {
return KNOT_EINVAL;
}
......@@ -253,7 +249,6 @@ int knot_pkt_init_response(knot_pkt_t *pkt, const knot_pkt_t *query)
/* Header + question size. */
size_t base_size = KNOT_WIRE_HEADER_SIZE + knot_pkt_question_size(query);
if (base_size > pkt->max_size) {
dbg_packet("%s: can't fit HEADER + QUESTION\n", __func__);
return KNOT_ESPACE;
}
......@@ -276,7 +271,6 @@ int knot_pkt_init_response(knot_pkt_t *pkt, const knot_pkt_t *query)
_public_
void knot_pkt_clear(knot_pkt_t *pkt)
{
dbg_packet("%s(%p)\n", __func__, pkt);
if (pkt == NULL) {
return;
}
......@@ -292,7 +286,6 @@ void knot_pkt_clear(knot_pkt_t *pkt)
_public_
void knot_pkt_free(knot_pkt_t **pkt)
{
dbg_packet("%s(%p)\n", __func__, pkt);
if (pkt == NULL || *pkt == NULL) {
return;
}
......@@ -305,7 +298,6 @@ void knot_pkt_free(knot_pkt_t **pkt)
(*pkt)->mm.free((*pkt)->wire);
}
dbg_packet("Freeing packet structure\n");
(*pkt)->mm.free(*pkt);
*pkt = NULL;
}
......@@ -313,7 +305,6 @@ void knot_pkt_free(knot_pkt_t **pkt)
_public_
int knot_pkt_reserve(knot_pkt_t *pkt, uint16_t size)
{
dbg_packet("%s(%p, %hu)\n", __func__, pkt, size);
if (pkt == NULL) {
return KNOT_EINVAL;
}
......@@ -330,7 +321,6 @@ int knot_pkt_reserve(knot_pkt_t *pkt, uint16_t size)
_public_
int knot_pkt_reclaim(knot_pkt_t *pkt, uint16_t size)
{
dbg_packet("%s(%p, %hu)\n", __func__, pkt, size);
if (pkt == NULL) {
return KNOT_EINVAL;
}
......@@ -347,7 +337,6 @@ int knot_pkt_reclaim(knot_pkt_t *pkt, uint16_t size)
_public_
uint16_t knot_pkt_type(const knot_pkt_t *pkt)
{
dbg_packet("%s(%p)\n", __func__, pkt);
if (pkt == NULL) {
return 0;
}
......@@ -382,7 +371,6 @@ uint16_t knot_pkt_type(const knot_pkt_t *pkt)
_public_
uint16_t knot_pkt_question_size(const knot_pkt_t *pkt)
{
dbg_packet("%s(%p)\n", __func__, pkt);
if (pkt == NULL || pkt->qname_size == 0) {
return 0;
}
......@@ -394,7 +382,6 @@ uint16_t knot_pkt_question_size(const knot_pkt_t *pkt)
_public_
const knot_dname_t *knot_pkt_qname(const knot_pkt_t *pkt)
{
dbg_packet("%s(%p)\n", __func__, pkt);
if (pkt == NULL || pkt->qname_size == 0) {
return NULL;
}
......@@ -406,7 +393,6 @@ const knot_dname_t *knot_pkt_qname(const knot_pkt_t *pkt)
_public_
uint16_t knot_pkt_qtype(const knot_pkt_t *pkt)
{
dbg_packet("%s(%p)\n", __func__, pkt);
if (pkt == NULL || pkt->qname_size == 0) {
return 0;
}
......@@ -419,7 +405,6 @@ uint16_t knot_pkt_qtype(const knot_pkt_t *pkt)
_public_
uint16_t knot_pkt_qclass(const knot_pkt_t *pkt)
{
dbg_packet("%s(%p)\n", __func__, pkt);
if (pkt == NULL || pkt->qname_size == 0) {
return 0;
}
......@@ -436,7 +421,6 @@ int knot_pkt_begin(knot_pkt_t *pkt, knot_section_t section_id)
}
/* Cannot step to lower section. */
dbg_packet("%s(%p, %u)\n", __func__, pkt, section_id);
assert(section_id >= pkt->current);
pkt->current = section_id;
......@@ -449,7 +433,6 @@ int knot_pkt_begin(knot_pkt_t *pkt, knot_section_t section_id)
_public_
int knot_pkt_put_question(knot_pkt_t *pkt, const knot_dname_t *qname, uint16_t qclass, uint16_t qtype)
{
dbg_packet("%s(%p, %p, %hu, %hu)\n", __func__, pkt, qname, qclass, qtype);
if (pkt == NULL || qname == NULL) {
return KNOT_EINVAL;
}
......@@ -489,7 +472,6 @@ _public_
int knot_pkt_put(knot_pkt_t *pkt, uint16_t compr_hint, const knot_rrset_t *rr,
uint16_t flags)
{
dbg_packet("%s(%p, %u, %p, %u)\n", __func__, pkt, compr_hint, rr, flags);
if (pkt == NULL || rr == NULL) {
return KNOT_EINVAL;
}
......@@ -521,11 +503,8 @@ int knot_pkt_put(knot_pkt_t *pkt, uint16_t compr_hint, const knot_rrset_t *rr,
/* Write RRSet to wireformat. */
int ret = knot_rrset_to_wire(rr, pos, maxlen, &compr);
if (ret < 0) {
dbg_packet("%s: rr_to_wire = %s\n,", __func__, knot_strerror(ret));
/* Truncate packet if required. */
if (ret == KNOT_ESPACE && !(flags & KNOT_PF_NOTRUNC)) {
dbg_packet("%s: set TC=1\n", __func__);
knot_wire_set_tc(pkt->wire);
}
return ret;
......@@ -546,9 +525,6 @@ int knot_pkt_put(knot_pkt_t *pkt, uint16_t compr_hint, const knot_rrset_t *rr,
pkt_rr_wirecount_add(pkt, pkt->current, rr_added);
}
dbg_packet("%s: added %u RRs (@%zu, len=%zu), pktsize=%zu\n",
__func__, rr_added, pkt->size - len, len, pkt->size);
return KNOT_EOK;
}
......@@ -556,7 +532,6 @@ _public_
const knot_pktsection_t *knot_pkt_section(const knot_pkt_t *pkt,
knot_section_t section_id)
{
dbg_packet("%s(%p, %u)\n", __func__, pkt, section_id);
if (pkt == NULL) {
return NULL;
}
......@@ -567,7 +542,6 @@ const knot_pktsection_t *knot_pkt_section(const knot_pkt_t *pkt,
_public_
int knot_pkt_parse(knot_pkt_t *pkt, unsigned flags)
{
dbg_packet("%s(%p, %u)\n", __func__, pkt, flags);
if (pkt == NULL) {
return KNOT_EINVAL;
}
......@@ -586,14 +560,12 @@ int knot_pkt_parse(knot_pkt_t *pkt, unsigned flags)
_public_
int knot_pkt_parse_question(knot_pkt_t *pkt)
{
dbg_packet("%s(%p)\n", __func__, pkt);
if (pkt == NULL) {
return KNOT_EINVAL;
}
/* Check at least header size. */
if (pkt->size < KNOT_WIRE_HEADER_SIZE) {
dbg_packet("%s: smaller than DNS header, NOREPLY\n", __func__);
return KNOT_EMALF;
}
......@@ -603,7 +575,6 @@ int knot_pkt_parse_question(knot_pkt_t *pkt)
/* Check QD count. */
uint16_t qd = knot_wire_get_qdcount(pkt->wire);
if (qd > 1) {
dbg_packet("%s: QD(%u) > 1, FORMERR\n", __func__, qd);
return KNOT_EMALF;
}
......@@ -624,7 +595,6 @@ int knot_pkt_parse_question(knot_pkt_t *pkt)
/* Check QCLASS/QTYPE size. */
uint16_t question_size = len + 2 * sizeof(uint16_t); /* QCLASS + QTYPE */
if (pkt->parsed + question_size > pkt->size) {
dbg_packet("%s: missing QCLASS/QTYPE, FORMERR\n", __func__);
return KNOT_EMALF;
}
......@@ -637,13 +607,10 @@ int knot_pkt_parse_question(knot_pkt_t *pkt)
/* \note Private for check_rr_constraints(). */
#define CHECK_AR_CONSTRAINTS(pkt, rr, var, check_func) \
if ((pkt)->current != KNOT_ADDITIONAL) { \
dbg_packet("%s: RRTYPE%u not in AR\n", __func__, rr->type); \
return KNOT_EMALF; \
} else if ((pkt)->var != NULL) { \
dbg_packet("%s: found 2nd RRTYPE%u\n", __func__, rr->type); \
return KNOT_EMALF; \
} else if (!check_func(rr)) { \
dbg_packet("%s: bad RRTYPE%u RDATA\n", __func__, rr->type); \
return KNOT_EMALF; \
} else { \
(pkt)->var = rr; \
......@@ -683,13 +650,11 @@ static int check_rr_constraints(knot_pkt_t *pkt, knot_rrset_t *rr, size_t rr_siz
_public_
int knot_pkt_parse_rr(knot_pkt_t *pkt, unsigned flags)
{
dbg_packet("%s(%p, %u)\n", __func__, pkt, flags);
if (pkt == NULL) {
return KNOT_EINVAL;
}
if (pkt->parsed >= pkt->size) {
dbg_packet("%s: parsed %zu/%zu data\n", __func__, pkt->parsed, pkt->size);
return KNOT_EFEWDATA;
}
......@@ -705,7 +670,6 @@ int knot_pkt_parse_rr(knot_pkt_t *pkt, unsigned flags)
ret = knot_rrset_rr_from_wire(pkt->wire, &pkt->parsed, pkt->max_size,
&pkt->mm, rr);
if (ret != KNOT_EOK) {
dbg_packet("%s: failed to parse RR\n", __func__);
return ret;
}
......@@ -723,7 +687,6 @@ int knot_pkt_parse_rr(knot_pkt_t *pkt, unsigned flags)
_public_
int knot_pkt_parse_section(knot_pkt_t *pkt, unsigned flags)
{
dbg_packet("%s(%p, %u)\n", __func__, pkt, flags);
if (pkt == NULL) {
return KNOT_EINVAL;
}
......@@ -736,8 +699,6 @@ int knot_pkt_parse_section(knot_pkt_t *pkt, unsigned flags)
for (rr_parsed = 0; rr_parsed < rr_count; ++rr_parsed) {
ret = knot_pkt_parse_rr(pkt, flags);
if (ret != KNOT_EOK) {
dbg_packet("%s: failed to parse RR %u/%u = %d\n",
__func__, rr_parsed, rr_count, ret);
return ret;
}
}
......@@ -748,7 +709,6 @@ int knot_pkt_parse_section(knot_pkt_t *pkt, unsigned flags)
_public_
int knot_pkt_parse_payload(knot_pkt_t *pkt, unsigned flags)
{
dbg_packet("%s(%p, %u)\n", __func__, pkt, flags);
if (pkt == NULL) {
return KNOT_EINVAL;
}
......@@ -761,14 +721,10 @@ int knot_pkt_parse_payload(knot_pkt_t *pkt, unsigned flags)
for (knot_section_t i = KNOT_ANSWER; i <= KNOT_ADDITIONAL; ++i) {
ret = knot_pkt_begin(pkt, i);
if (ret != KNOT_EOK) {
dbg_packet("%s: failed to begin section %u = %d\n",
__func__, i, ret);
return ret;
}
ret = knot_pkt_parse_section(pkt, flags);
if (ret != KNOT_EOK) {
dbg_packet("%s: failed to parse section %u = %d\n",
__func__, i, ret);
return ret;
}
}
......@@ -777,15 +733,12 @@ int knot_pkt_parse_payload(knot_pkt_t *pkt, unsigned flags)
const knot_pktsection_t *ar = knot_pkt_section(pkt, KNOT_ADDITIONAL);
if (pkt->tsig_rr != NULL) {
if (ar->count > 0 && pkt->tsig_rr->rrs.data != ar->rr[ar->count - 1].rrs.data) {
dbg_packet("%s: TSIG not last RR in AR.\n", __func__);
return KNOT_EMALF;
}
}
/* Check for trailing garbage. */
if (pkt->parsed < pkt->size) {
dbg_packet("%s: %zu bytes of trailing garbage\n",
__func__, pkt->size - pkt->parsed);
return KNOT_EMALF;
}
......
......@@ -46,7 +46,6 @@ int knot_layer_begin(knot_layer_t *ctx, const knot_layer_api_t *api, void *param
LAYER_CALL(ctx, begin, param);
dbg_ns("%s -> %s\n", __func__, LAYER_STATE_STR(ctx->state));
return ctx->state;
}
......@@ -54,7 +53,6 @@ _public_
int knot_layer_reset(knot_layer_t *ctx)
{
LAYER_CALL(ctx, reset);
dbg_ns("%s -> %s\n", __func__, LAYER_STATE_STR(ctx->state));
return ctx->state;
}
......@@ -62,7 +60,6 @@ _public_
int knot_layer_finish(knot_layer_t *ctx)
{
LAYER_CALL(ctx, finish);
dbg_ns("%s -> %s\n", __func__, LAYER_STATE_STR(ctx->state));
return ctx->state;
}
......@@ -70,7 +67,6 @@ _public_
int knot_layer_in(knot_layer_t *ctx, knot_pkt_t *pkt)
{
LAYER_CALL(ctx, in, pkt);
dbg_ns("%s -> %s\n", __func__, LAYER_STATE_STR(ctx->state));
return ctx->state;
}
......@@ -83,7 +79,6 @@ int knot_layer_out(knot_layer_t *ctx, knot_pkt_t *pkt)
default: LAYER_CALL(ctx, out, pkt); break;
}
dbg_ns("%s -> %s\n", __func__, LAYER_STATE_STR(ctx->state));
return ctx->state;
}
......
......@@ -249,10 +249,6 @@ int knot_edns_add_option(knot_rrset_t *opt_rr, uint16_t code,
uint8_t new_data[new_data_len];
dbg_edns_verb("EDNS: Adding option. Code: %u, length: %u, data:\n",
code, length);
dbg_edns_hex_verb((char *)data, length);
memcpy(new_data, old_data, old_data_len);
// write length and code in wireformat (convert endian)
wire_write_u16(new_data + old_data_len, code);
......
......@@ -69,9 +69,6 @@ static uint8_t* rdata_seek(const knot_rrset_t *rr, tsig_off_t id, size_t nb)
int alg_len = knot_dname_size(rd);
uint16_t lim = knot_rdata_rdlen(rr_data);
if (lim < alg_len + 5 * sizeof(uint16_t)) {
dbg_tsig("TSIG: rdata: not enough items "
"(has %"PRIu16", min %zu).\n",
lim, alg_len + 5 * sizeof(uint16_t));
return NULL;
}
......@@ -104,8 +101,6 @@ static uint8_t* rdata_seek(const knot_rrset_t *rr, tsig_off_t id, size_t nb)
/* Check remaining bytes. */
if (rd + nb > bp + lim) {
dbg_tsig("TSIG: rdata: not enough items (needs %zu, has %u).\n",
(rd-bp)+nb, lim);
return NULL;
}
......@@ -227,7 +222,6 @@ int knot_tsig_rdata_set_other_data(knot_rrset_t *tsig, uint16_t len,
const uint8_t *other_data)
{
if (len > TSIG_OTHER_MAXLEN) {
dbg_tsig("TSIG: rdata: other len > %zu B\n", TSIG_OTHER_MAXLEN);
return KNOT_EINVAL;
}
......@@ -257,21 +251,18 @@ knot_tsig_algorithm_t knot_tsig_rdata_alg(const knot_rrset_t *tsig)
/* Get the algorithm name. */
const knot_dname_t *alg_name = knot_tsig_rdata_alg_name(tsig);
if (!alg_name) {
dbg_tsig("TSIG: rdata: cannot get algorithm name.\n");
return KNOT_TSIG_ALG_NULL;
}
/* Convert alg name to string. */
char *name = knot_dname_to_str_alloc(alg_name);
if (!name) {
dbg_tsig("TSIG: rdata: cannot convert alg name.\n");
return KNOT_TSIG_ALG_NULL;
}
lookup_table_t *item = lookup_by_name(knot_tsig_alg_dnames_str, name);
free(name);
if (!item) {
dbg_tsig("TSIG: rdata: unknown algorithm.\n");
return KNOT_TSIG_ALG_NULL;
}
return item->id;
......@@ -372,7 +363,6 @@ int knot_tsig_alg_from_name(const knot_dname_t *alg_name)
lookup_table_t *found = lookup_by_name(knot_tsig_alg_dnames_str, name);
if (!found) {
dbg_tsig("Unknown algorithm: %s \n", name);
free(name);
return 0;
}
......
......@@ -50,7 +50,6 @@ static int check_algorithm(const knot_rrset_t *tsig_rr)
knot_tsig_algorithm_t alg = knot_tsig_alg_from_name(alg_name);
if (alg == 0) {
/*!< \todo is this error OK? */
dbg_tsig("TSIG: unknown algorithm.\n");
return KNOT_TSIG_EBADSIG;
}
......@@ -76,7 +75,6 @@ static int check_key(const knot_rrset_t *tsig_rr,
if (knot_dname_cmp(tsig_name, tsig_key->name) != 0) {
/*!< \todo which error. */
dbg_tsig("TSIG: unknown key: %s\n", name);
free(name);
return KNOT_TSIG_EBADKEY;
}
......@@ -90,26 +88,18 @@ static int compute_digest(const uint8_t *wire, size_t wire_len,
const knot_tsig_key_t *key)
{
if (!wire || !digest || !digest_len || !key) {
dbg_tsig("TSIG: digest: bad args.\n");
return KNOT_EINVAL;
}
if (!key->name) {
dbg_tsig("TSIG: digest: no algorithm\n");
return KNOT_EMALF;
}
knot_tsig_algorithm_t tsig_alg = key->algorithm;
if (tsig_alg == 0) {
dbg_tsig("TSIG: digest: unknown algorithm\n");
return KNOT_TSIG_EBADSIG;
}
dbg_tsig_detail("TSIG: key size: %zu\n", key->secret.size);
dbg_tsig_detail("TSIG: key:\n");
dbg_tsig_hex_detail((char *)key->secret.data, key->secret.size);
dbg_tsig_detail("Wire for signing is %zu bytes long.\n", wire_len);
/* Compute digest. */
HMAC_CTX ctx;
......@@ -156,7 +146,6 @@ static int check_time_signed(const knot_rrset_t *tsig_rr,
uint64_t prev_time_signed)
{
if (!tsig_rr) {
dbg_tsig("TSIG: check_time_signed: NULL argument.\n");
return KNOT_EINVAL;
}
......@@ -192,14 +181,12 @@ static int check_time_signed(const knot_rrset_t *tsig_rr,
static int write_tsig_variables(uint8_t *wire, const knot_rrset_t *tsig_rr)
{
if (wire == NULL || tsig_rr == NULL) {
dbg_tsig("TSIG: write tsig variables: NULL arguments.\n");
return KNOT_EINVAL;
}
/* Copy TSIG variables - starting with key name. */
const knot_dname_t *tsig_owner = tsig_rr->owner;
if (!tsig_owner) {
dbg_tsig("TSIG: write variables: no owner.\n");
return KNOT_EINVAL;
}
......@@ -211,20 +198,15 @@ static int write_tsig_variables(uint8_t *wire, const knot_rrset_t *tsig_rr)
/* Copy class. */
wire_write_u16(wire + offset, tsig_rr->rclass);
dbg_tsig_verb("TSIG: write variables: written CLASS: %u - \n",
tsig_rr->rclass);
dbg_tsig_hex_detail((char *)(wire + offset), sizeof(uint16_t));
offset += sizeof(uint16_t);
/* Copy TTL - always 0. */
wire_write_u32(wire + offset, knot_rdata_ttl(knot_rdataset_at(&tsig_rr->rrs, 0)));
dbg_tsig_hex_detail((char *)(wire + offset), sizeof(uint32_t));
offset += sizeof(uint32_t);
/* Copy alg name. */
const knot_dname_t *alg_name = knot_tsig_rdata_alg_name(tsig_rr);
if (!alg_name) {
dbg_tsig("TSIG: write variables: no algorithm name.\n");
return KNOT_EINVAL;
}
......@@ -232,8 +214,6 @@ static int write_tsig_variables(uint8_t *wire, const knot_rrset_t *tsig_rr)
uint8_t *alg_name_wire = wire + offset;
offset += knot_dname_to_wire(alg_name_wire, alg_name, KNOT_DNAME_MAXLEN);
if (knot_dname_to_lower(alg_name_wire) != KNOT_EOK) {
dbg_tsig("TSIG: write variables: cannot convert algorithm "
"to lowercase.\n");
return KNOT_EINVAL;
}
......@@ -241,14 +221,9 @@ static int write_tsig_variables(uint8_t *wire, const knot_rrset_t *tsig_rr)
/* Time signed. */
wire_write_u48(wire + offset, knot_tsig_rdata_time_signed(tsig_rr));
offset += 6;
dbg_tsig_verb("TSIG: write variables: time signed: %"PRIu64" \n",
knot_tsig_rdata_time_signed(tsig_rr));
dbg_tsig_hex_detail((char *)(wire + offset - 6), 6);
/* Fudge. */
wire_write_u16(wire + offset, knot_tsig_rdata_fudge(tsig_rr));
offset += sizeof(uint16_t);
dbg_tsig_verb("TSIG: write variables: fudge: %hu\n",
knot_tsig_rdata_fudge(tsig_rr));
/* TSIG error. */
wire_write_u16(wire + offset, knot_tsig_rdata_error(tsig_rr));
offset += sizeof(uint16_t);
......@@ -257,7 +232,6 @@ static int write_tsig_variables(uint8_t *wire, const knot_rrset_t *tsig_rr)
/* Get other data. */
const uint8_t *other_data = knot_tsig_rdata_other_data(tsig_rr);
if (!other_data) {
dbg_tsig("TSIG: write variables: no other data.\n");
return KNOT_EINVAL;
}
......@@ -269,7 +243,6 @@ static int write_tsig_variables(uint8_t *wire, const knot_rrset_t *tsig_rr)
offset += sizeof(uint16_t);
/* Skip the length. */
dbg_tsig_verb("Copying other data.\n");
memcpy(wire + offset, other_data, other_data_length);
return KNOT_EOK;
......@@ -278,7 +251,6 @@ static int write_tsig_variables(uint8_t *wire, const knot_rrset_t *tsig_rr)
static int wire_write_timers(uint8_t *wire, const knot_rrset_t *tsig_rr)
{
if (wire == NULL || tsig_rr == NULL) {
dbg_tsig("TSIG: write timers: NULL arguments.\n");
return KNOT_EINVAL;
}
......@@ -297,7 +269,6 @@ static int create_sign_wire(const uint8_t *msg, size_t msg_len,
const knot_tsig_key_t *key)
{
if (!msg || !key || digest_len == NULL) {
dbg_tsig("TSIG: create wire: bad args.\n");
return KNOT_EINVAL;
}
......@@ -308,9 +279,6 @@ static int create_sign_wire(const uint8_t *msg, size_t msg_len,
* Create tmp wire, it should contain message
* plus request mac plus tsig varibles.
*/
dbg_tsig_verb("Counting wire size: %zu, %zu, %zu.\n",
msg_len, request_mac_len,
knot_tsig_rdata_tsig_variables_length(tmp_tsig));
size_t wire_len = sizeof(uint8_t) *
(msg_len + request_mac_len + ((request_mac_len > 0)
? 2 : 0) +
......@@ -326,25 +294,17 @@ static int create_sign_wire(const uint8_t *msg, size_t msg_len,
/* Copy the request MAC - should work even if NULL. */
if (request_mac_len > 0) {
dbg_tsig_verb("Copying request MAC size\n");
wire_write_u16(pos, request_mac_len);
pos += 2;
dbg_tsig_verb("Copying request mac.\n");
memcpy(pos, request_mac, sizeof(uint8_t) * request_mac_len);
}
dbg_tsig_detail("TSIG: create wire: request mac:\n");
dbg_tsig_hex_detail((char *)pos, request_mac_len);
pos += request_mac_len;
/* Copy the original message. */
dbg_tsig_verb("Copying original message.\n");
memcpy(pos, msg, msg_len);
pos += msg_len;
/* Copy TSIG variables. */
dbg_tsig_verb("Writing TSIG variables.\n");
ret = write_tsig_variables(pos, tmp_tsig);
if (ret != KNOT_EOK) {
dbg_tsig("TSIG: create wire: failed to write TSIG "
"variables: %s\n", knot_strerror(ret));
free(wire);
return ret;
}
......@@ -352,8 +312,6 @@ static int create_sign_wire(const uint8_t *msg, size_t msg_len,
/* Compute digest. */
ret = compute_digest(wire, wire_len, digest, digest_len, key);
if (ret != KNOT_EOK) {
dbg_tsig("TSIG: create wire: failed to compute digest: %s\n",
knot_strerror(ret));
*digest_len = 0;
free(wire);
return ret;
......@@ -371,7 +329,6 @@ static int create_sign_wire_next(const uint8_t *msg, size_t msg_len,
const knot_tsig_key_t *key)
{
if (!msg || !key || digest_len == NULL) {
dbg_tsig("TSIG: create wire: bad args.\n");
return KNOT_EINVAL;
}
......@@ -382,9 +339,6 @@ static int create_sign_wire_next(const uint8_t *msg, size_t msg_len,
* Create tmp wire, it should contain message
* plus request mac plus tsig varibles.
*/
dbg_tsig_verb("Counting wire size: %zu, %zu, %zu.\n",
msg_len, prev_mac_len,
knot_tsig_rdata_tsig_timers_length());
size_t wire_len = sizeof(uint8_t) *
(msg_len + prev_mac_len +
knot_tsig_rdata_tsig_timers_length() + 2);
......@@ -396,23 +350,15 @@ static int create_sign_wire_next(const uint8_t *msg, size_t msg_len,
memset(wire, 0, wire_len);
/* Copy the request MAC - should work even if NULL. */
dbg_tsig_verb("Copying request mac size.\n");
wire_write_u16(wire, prev_mac_len);
dbg_tsig_verb("Copying request mac.\n");
memcpy(wire + 2, prev_mac, sizeof(uint8_t) * prev_mac_len);
dbg_tsig_detail("TSIG: create wire: request mac:\n");
dbg_tsig_hex_detail((char *)(wire + 2), prev_mac_len);
/* Copy the original message. */
dbg_tsig_verb("Copying original message.\n");
memcpy(wire + prev_mac_len + 2, msg, msg_len);
/* Copy TSIG variables. */
dbg_tsig_verb("Writing TSIG timers.\n");
ret = wire_write_timers(wire + prev_mac_len + msg_len + 2,
tmp_tsig);
if (ret != KNOT_EOK) {
dbg_tsig("TSIG: create wire: failed to write TSIG "
"timers: %s\n", knot_strerror(ret));
free(wire);
return ret;
}
......@@ -421,8 +367,6 @@ static int create_sign_wire_next(const uint8_t *msg, size_t msg_len,
ret = compute_digest(wire, wire_len,
digest, digest_len, key);
if (ret != KNOT_EOK) {
dbg_tsig("TSIG: create wire: failed to compute digest: %s\n",
knot_strerror(ret));
*digest_len = 0;
free(wire);
return ret;
......@@ -448,7 +392,6 @@ int knot_tsig_sign(uint8_t *msg, size_t *msg_len, size_t msg_max_len,
knot_rrset_new(key->name, KNOT_RRTYPE_TSIG, KNOT_CLASS_ANY,
NULL);
if (!tmp_tsig) {
dbg_tsig("TSIG: tmp_tsig = NULL\n");
return KNOT_ENOMEM;
}
......@@ -493,8 +436,6 @@ int knot_tsig_sign(uint8_t *msg, size_t *msg_len, size_t msg_max_len,
digest_tmp, &digest_tmp_len,
tmp_tsig, key);
if (ret != KNOT_EOK) {
dbg_tsig("TSIG: failed to create wire or sign wire: %s\n",
knot_strerror(ret));
knot_rrset_free(&tmp_tsig, NULL);
return ret;
}
......@@ -507,7 +448,6 @@ int knot_tsig_sign(uint8_t *msg, size_t *msg_len, size_t msg_max_len,
ret = knot_rrset_to_wire(tmp_tsig, msg + *msg_len,
msg_max_len - *msg_len, NULL);
if (ret < 0) {
dbg_tsig("TSIG: rrset_to_wire = %s\n", knot_strerror(ret));
*digest_len = 0;
knot_rrset_free(&tmp_tsig, NULL);
return ret;
......@@ -517,7 +457,6 @@ int knot_tsig_sign(uint8_t *msg, size_t *msg_len, size_t msg_max_len,
knot_rrset_free(&tmp_tsig, NULL);
dbg_tsig("TSIG: written TSIG RR (wire len %zu)\n", tsig_wire_len);
*msg_len += tsig_wire_len;
uint16_t arcount = knot_wire_get_arcount(msg);
......@@ -575,13 +514,6 @@ int knot_tsig_sign_next(uint8_t *msg, size_t *msg_len, size_t msg_max_len,
wire_write_timers(wire + prev_digest_len + to_sign_len + 2,
tmp_tsig);
dbg_tsig_detail("Previous digest: \n");
dbg_tsig_hex_detail((char *)prev_digest, prev_digest_len);
dbg_tsig_detail("Timers: \n");
dbg_tsig_hex_detail((char *)(wire + prev_digest_len + *msg_len),
KNOT_TSIG_TIMERS_LENGTH);
int ret = KNOT_ERROR;
ret = compute_digest(wire, wire_len,
digest_tmp, &digest_tmp_len, key);
......@@ -609,9 +541,6 @@ int knot_tsig_sign_next(uint8_t *msg, size_t *msg_len, size_t msg_max_len,
/* Set other data. */
knot_tsig_rdata_set_other_data(tmp_tsig, 0, NULL);
dbg_tsig_verb("Message max length: %zu, message length: %zu\n",
msg_max_len, *msg_len);
ret = knot_rrset_to_wire(tmp_tsig, msg + *msg_len,
msg_max_len - *msg_len, NULL);
if (ret < 0) {
......@@ -655,24 +584,18 @@ static int check_digest(const knot_rrset_t *tsig_rr,
return ret;
}
dbg_tsig_verb("TSIG: time checked.\n");
/* Check that libknot knows the algorithm. */
ret = check_algorithm(tsig_rr);
if (ret != KNOT_EOK) {
return ret;
}
dbg_tsig_verb("TSIG: algorithm checked.\n");
/* Check that key is valid, ie. the same as given in args. */
ret = check_key(tsig_rr, tsig_key);
if (ret != KNOT_EOK) {
return ret;
}
dbg_tsig_verb("TSIG: key validity checked.\n");
uint8_t *wire_to_sign = malloc(sizeof(uint8_t) * size);
if (!wire_to_sign) {
return KNOT_ENOMEM;
......@@ -702,13 +625,9 @@ static int check_digest(const knot_rrset_t *tsig_rr,
free(wire_to_sign);
if (ret != KNOT_EOK) {
dbg_tsig("Failed to create wire format for checking: %s.\n",
knot_strerror(ret));
return ret;
}
dbg_tsig_verb("TSIG: digest calculated\n");
/* Compare MAC from TSIG RR RDATA with just computed digest. */
/*!< \todo move to function. */
......@@ -720,17 +639,9 @@ static int check_digest(const knot_rrset_t *tsig_rr,
const uint8_t *tsig_mac = knot_tsig_rdata_mac(tsig_rr);
if (mac_length != knot_tsig_digest_length(alg)) {
dbg_tsig("TSIG: calculated digest length and given length do "
"not match!\n");
return KNOT_TSIG_EBADSIG;
}
dbg_tsig_verb("TSIG: calc digest :\n");
dbg_tsig_hex_verb((char *)digest_tmp, digest_tmp_len);
dbg_tsig_verb("TSIG: given digest:\n");
dbg_tsig_hex_verb((char *)tsig_mac, mac_length);
if (memcmp(tsig_mac, digest_tmp, mac_length) != 0) {
return KNOT_TSIG_EBADSIG;
}
......@@ -743,7 +654,6 @@ int knot_tsig_server_check(const knot_rrset_t *tsig_rr,
const uint8_t *wire, size_t size,
const knot_tsig_key_t *tsig_key)
{
dbg_tsig("tsig_server_check()\n");
return check_digest(tsig_rr, wire, size, NULL, 0, tsig_key,
0, 0);
}
......@@ -755,7 +665,6 @@ int knot_tsig_client_check(const knot_rrset_t *tsig_rr,
const knot_tsig_key_t *tsig_key,
uint64_t prev_time_signed)
{
dbg_tsig("tsig_client_check()\n");
return check_digest(tsig_rr, wire, size, request_mac,
request_mac_len, tsig_key,
prev_time_signed, 0);
......@@ -769,7 +678,6 @@ int knot_tsig_client_check_next(const knot_rrset_t *tsig_rr,
const knot_tsig_key_t *tsig_key,
uint64_t prev_time_signed)
{
dbg_tsig("tsig_client_check_next()\n");
return check_digest(tsig_rr, wire, size, prev_digest,
prev_digest_len, tsig_key,
prev_time_signed, 1);
......@@ -790,7 +698,6 @@ int knot_tsig_add(uint8_t *msg, size_t *msg_len, size_t msg_max_len,
knot_rrset_new(tsig_rr->owner, KNOT_RRTYPE_TSIG,
KNOT_CLASS_ANY, NULL);
if (!tmp_tsig) {
dbg_tsig("TSIG: tmp_tsig = NULL\n");
return KNOT_ENOMEM;
}
......@@ -826,7 +733,6 @@ int knot_tsig_append(uint8_t *msg, size_t *msg_len, size_t msg_max_len,
int ret = knot_rrset_to_wire(tsig_rr, msg + *msg_len,
msg_max_len - *msg_len, NULL);
if (ret < 0) {
dbg_tsig("TSIG: rrset_to_wire = %s\n", knot_strerror(ret));
return ret;
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment