Commit d8975a97 authored by Lubos Slovak's avatar Lubos Slovak

public-libs: Prefixes in tsig + some small fixes.

parent 3cb706f7
......@@ -719,7 +719,7 @@ static int zones_verify_tsig_query(const knot_pkt_t *query,
/*
* 1) Check if we support the requested algorithm.
*/
knot_tsig_algorithm_t alg = tsig_rdata_alg(query->tsig_rr);
knot_tsig_algorithm_t alg = knot_tsig_rdata_alg(query->tsig_rr);
if (knot_tsig_digest_length(alg) == 0) {
log_info("TSIG, unsupported algorithm, query NOTAUTH");
/*! \todo [TSIG] It is unclear from RFC if I
......@@ -758,7 +758,7 @@ static int zones_verify_tsig_query(const knot_pkt_t *query,
//memset(digest, 0 , digest_max_size);
//const uint8_t* mac = tsig_rdata_mac(tsig_rr);
size_t mac_len = tsig_rdata_mac_length(query->tsig_rr);
size_t mac_len = knot_tsig_rdata_mac_length(query->tsig_rr);
int ret = KNOT_EOK;
......@@ -790,7 +790,7 @@ static int zones_verify_tsig_query(const knot_pkt_t *query,
case KNOT_TSIG_EBADTIME:
*tsig_rcode = KNOT_TSIG_ERR_BADTIME;
// store the time signed from the query
*tsig_prev_time_signed = tsig_rdata_time_signed(query->tsig_rr);
*tsig_prev_time_signed = knot_tsig_rdata_time_signed(query->tsig_rr);
*rcode = KNOT_RCODE_NOTAUTH;
break;
case KNOT_EMALF:
......@@ -896,7 +896,7 @@ knot_pkt_t* remote_query(const char *query, const knot_tsig_key_t *key)
}
knot_wire_set_id(pkt->wire, knot_random_uint16_t());
knot_pkt_reserve(pkt, tsig_wire_maxsize(key));
knot_pkt_reserve(pkt, knot_tsig_wire_maxsize(key));
/* Question section. */
char *qname = strcdup(query, KNOT_CTL_REALM_EXT);
......
......@@ -239,7 +239,7 @@ int axfr_query_process(knot_pkt_t *pkt, struct query_data *qdata)
}
/* Reserve space for TSIG. */
knot_pkt_reserve(pkt, tsig_wire_maxsize(qdata->sign.tsig_key));
knot_pkt_reserve(pkt, knot_tsig_wire_maxsize(qdata->sign.tsig_key));
/* Answer current packet (or continue). */
struct axfr_proc *axfr = (struct axfr_proc *)qdata->ext;
......
......@@ -832,7 +832,7 @@ int internet_query(knot_pkt_t *response, struct query_data *qdata)
NS_NEED_AUTH(&qdata->zone->conf->acl.xfr_out, qdata);
/* Reserve space for TSIG. */
knot_pkt_reserve(response, tsig_wire_maxsize(qdata->sign.tsig_key));
knot_pkt_reserve(response, knot_tsig_wire_maxsize(qdata->sign.tsig_key));
}
NS_NEED_ZONE_CONTENTS(qdata, KNOT_RCODE_SERVFAIL); /* Expired */
......
......@@ -301,7 +301,7 @@ static int ixfr_answer_soa(knot_pkt_t *pkt, struct query_data *qdata)
}
/* Reserve space for TSIG. */
knot_pkt_reserve(pkt, tsig_wire_maxsize(qdata->sign.tsig_key));
knot_pkt_reserve(pkt, knot_tsig_wire_maxsize(qdata->sign.tsig_key));
/* Guaranteed to have zone contents. */
const zone_node_t *apex = qdata->zone->contents->apex;
......@@ -649,7 +649,7 @@ int ixfr_query(knot_pkt_t *pkt, struct query_data *qdata)
}
/* Reserve space for TSIG. */
knot_pkt_reserve(pkt, tsig_wire_maxsize(qdata->sign.tsig_key));
knot_pkt_reserve(pkt, knot_tsig_wire_maxsize(qdata->sign.tsig_key));
/* Answer current packet (or continue). */
ret = xfr_process_list(pkt, &ixfr_process_changeset, qdata);
......
......@@ -81,7 +81,7 @@ int notify_process_query(knot_pkt_t *pkt, struct query_data *qdata)
}
/* Reserve space for TSIG. */
knot_pkt_reserve(pkt, tsig_wire_maxsize(qdata->sign.tsig_key));
knot_pkt_reserve(pkt, knot_tsig_wire_maxsize(qdata->sign.tsig_key));
/* SOA RR in answer may be included, recover serial. */
const knot_pktsection_t *answer = knot_pkt_section(qdata->query, KNOT_ANSWER);
......
......@@ -522,7 +522,7 @@ bool process_query_acl_check(list_t *acl, struct query_data *qdata)
/* Authenticate with NOKEY if the packet isn't signed. */
if (query->tsig_rr) {
key_name = query->tsig_rr->owner;
key_alg = tsig_rdata_alg(query->tsig_rr);
key_alg = knot_tsig_rdata_alg(query->tsig_rr);
}
conf_iface_t *match = acl_find(acl, query_source, key_name);
......@@ -551,8 +551,8 @@ int process_query_verify(struct query_data *qdata)
/* Keep digest for signing response. */
/*! \note This memory will be rewritten for multi-pkt answers. */
ctx->tsig_digest = (uint8_t *)tsig_rdata_mac(query->tsig_rr);
ctx->tsig_digestlen = tsig_rdata_mac_length(query->tsig_rr);
ctx->tsig_digest = (uint8_t *)knot_tsig_rdata_mac(query->tsig_rr);
ctx->tsig_digestlen = knot_tsig_rdata_mac_length(query->tsig_rr);
/* Checking query. */
process_query_qname_case_restore(qdata, query);
......@@ -578,7 +578,7 @@ int process_query_verify(struct query_data *qdata)
case KNOT_TSIG_EBADTIME:
qdata->rcode = KNOT_RCODE_NOTAUTH;
qdata->rcode_tsig = KNOT_TSIG_ERR_BADTIME;
ctx->tsig_time_signed = tsig_rdata_time_signed(query->tsig_rr);
ctx->tsig_time_signed = knot_tsig_rdata_time_signed(query->tsig_rr);
break;
case KNOT_EMALF:
qdata->rcode = KNOT_RCODE_FORMERR;
......
......@@ -83,12 +83,12 @@ static int update_ctx_after_verify(tsig_ctx_t *ctx, knot_rrset_t *tsig_rr)
assert(ctx);
assert(tsig_rr);
if (ctx->digest_size != tsig_rdata_mac_length(tsig_rr)) {
if (ctx->digest_size != knot_tsig_rdata_mac_length(tsig_rr)) {
return KNOT_EMALF;
}
memcpy(ctx->digest, tsig_rdata_mac(tsig_rr), ctx->digest_size);
ctx->prev_signed_time = tsig_rdata_time_signed(tsig_rr);
memcpy(ctx->digest, knot_tsig_rdata_mac(tsig_rr), ctx->digest_size);
ctx->prev_signed_time = knot_tsig_rdata_time_signed(tsig_rr);
ctx->unsigned_count = 0;
ctx->buffer_used = 0;
......
......@@ -154,7 +154,7 @@ static int knot_zone_diff_rdata_return_changes(const knot_rrset_t *rrset1,
/* Create fake RRSet, it will be easier to handle. */
knot_rrset_init(changes, rrset1->owner, rrset1->type, rrset1->rclass);
const rdata_descriptor_t *desc = knot_get_rdata_descriptor(rrset1->type);
const knot_rdata_descriptor_t *desc = knot_get_rdata_descriptor(rrset1->type);
assert(desc);
uint16_t rr1_count = rrset1->rrs.rr_count;
......
......@@ -156,7 +156,7 @@ static const rdata_descriptor_t obsolete_rdata_descriptors[] = {
};
_public_
const rdata_descriptor_t *knot_get_rdata_descriptor(const uint16_t type)
const knot_rdata_descriptor_t *knot_get_rdata_descriptor(const uint16_t type)
{
if (type <= KNOT_RRTYPE_ANY &&
rdata_descriptors[type].type_name != NULL) {
......@@ -167,7 +167,7 @@ const rdata_descriptor_t *knot_get_rdata_descriptor(const uint16_t type)
}
_public_
const rdata_descriptor_t *knot_get_obsolete_rdata_descriptor(const uint16_t type)
const knot_rdata_descriptor_t *knot_get_obsolete_rdata_descriptor(const uint16_t type)
{
if (type <= KNOT_RRTYPE_NXT &&
obsolete_rdata_descriptors[type].type_name != NULL) {
......@@ -188,7 +188,7 @@ int knot_rrtype_to_string(const uint16_t rrtype,
int ret;
const rdata_descriptor_t *descr = knot_get_rdata_descriptor(rrtype);
const knot_rdata_descriptor_t *descr = knot_get_rdata_descriptor(rrtype);
if (descr->type_name != NULL) {
ret = snprintf(out, out_len, "%s", descr->type_name);
......
......@@ -160,7 +160,7 @@ typedef struct {
const int block_types[KNOT_MAX_RDATA_BLOCKS];
/*!< RR type name. */
const char *type_name;
} rdata_descriptor_t;
} knot_rdata_descriptor_t;
/*!
* \brief Gets rdata descriptor for given RR name.
......@@ -170,7 +170,7 @@ typedef struct {
* \retval RR descriptor for given name, NULL descriptor if
* unknown type.
*/
const rdata_descriptor_t *knot_get_rdata_descriptor(const uint16_t type);
const knot_rdata_descriptor_t *knot_get_rdata_descriptor(const uint16_t type);
/*!
* \brief Gets rdata descriptor for given RR name (obsolete version).
......@@ -180,7 +180,7 @@ const rdata_descriptor_t *knot_get_rdata_descriptor(const uint16_t type);
* \retval RR descriptor for given name, NULL descriptor if
* unknown type.
*/
const rdata_descriptor_t *knot_get_obsolete_rdata_descriptor(const uint16_t type);
const knot_rdata_descriptor_t *knot_get_obsolete_rdata_descriptor(const uint16_t type);
/*!
* \brief Converts numeric type representation to mnemonic string.
......
......@@ -20,6 +20,7 @@
#include "libknot/errcode.h"
#include "common/errors.h"
#include "libknot/common.h"
const error_table_t error_messages[] = {
......
......@@ -655,13 +655,13 @@ static int check_rr_constraints(knot_pkt_t *pkt, knot_rrset_t *rr, size_t rr_siz
/* Check RR constraints. */
switch(rr->type) {
case KNOT_RRTYPE_TSIG:
CHECK_AR_CONSTRAINTS(pkt, rr, tsig_rr, tsig_rdata_is_ok);
CHECK_AR_CONSTRAINTS(pkt, rr, tsig_rr, knot_tsig_rdata_is_ok);
/* Strip TSIG RR from wireformat and decrease ARCOUNT. */
if (!(flags & KNOT_PF_KEEPWIRE)) {
pkt->parsed -= rr_size;
pkt->size -= rr_size;
knot_wire_set_id(pkt->wire, tsig_rdata_orig_id(rr));
knot_wire_set_id(pkt->wire, knot_tsig_rdata_orig_id(rr));
knot_wire_set_arcount(pkt->wire, knot_wire_get_arcount(pkt->wire) - 1);
}
break;
......
......@@ -181,7 +181,7 @@ static int write_rdata_block(const uint8_t **src, size_t *src_avail,
*/
static int rdata_traverse(const uint8_t **src, size_t *src_avail,
uint8_t **dst, size_t *dst_avail,
const rdata_descriptor_t *desc,
const knot_rdata_descriptor_t *desc,
dname_config_t *dname_cfg, knot_rrset_wire_flags_t flags)
{
for (int i = 0; desc->block_types[i] != KNOT_RDATA_WF_END; i++) {
......@@ -388,7 +388,7 @@ static int write_rdata(const knot_rrset_t *rrset, uint16_t rrset_index,
size_t src_avail = knot_rdata_rdlen(rdata);
if (src_avail > 0) {
/* Only write non-empty data. */
const rdata_descriptor_t *desc =
const knot_rdata_descriptor_t *desc =
knot_get_rdata_descriptor(rrset->type);
int ret = rdata_traverse(&src, &src_avail, dst, dst_avail,
desc, &dname_cfg, flags);
......@@ -548,7 +548,7 @@ static int decompress_rdata_dname(const uint8_t **src, size_t *src_avail,
}
static bool allow_zero_rdata(const knot_rrset_t *rr,
const rdata_descriptor_t *desc)
const knot_rdata_descriptor_t *desc)
{
return rr->rclass != KNOT_CLASS_IN || // NONE and ANY for DDNS
rr->type == KNOT_RRTYPE_APL || // APL RR type
......@@ -570,7 +570,7 @@ static int parse_rdata(const uint8_t *pkt_wire, size_t *pos, size_t pkt_size,
return KNOT_EMALF;
}
const rdata_descriptor_t *desc = knot_get_rdata_descriptor(rrset->type);
const knot_rdata_descriptor_t *desc = knot_get_rdata_descriptor(rrset->type);
if (desc->type_name == NULL) {
desc = knot_get_obsolete_rdata_descriptor(rrset->type);
}
......
......@@ -54,6 +54,7 @@ typedef struct {
int ret;
} rrset_dump_params_t;
_public_
const knot_dump_style_t KNOT_DUMP_STYLE_DEFAULT = {
.wrap = false,
.show_class = false,
......
......@@ -125,7 +125,8 @@ static int tsig_rdata_set_tsig_error(knot_rrset_t *tsig, uint16_t tsig_error)
}
_public_
int tsig_create_rdata(knot_rrset_t *rr, const knot_dname_t *alg, uint16_t maclen, uint16_t tsig_err)
int knot_tsig_create_rdata(knot_rrset_t *rr, const knot_dname_t *alg,
uint16_t maclen, uint16_t tsig_err)
{
if (rr == NULL || alg == NULL) {
return KNOT_EINVAL;
......@@ -159,7 +160,7 @@ int tsig_create_rdata(knot_rrset_t *rr, const knot_dname_t *alg, uint16_t maclen
}
_public_
int tsig_rdata_set_time_signed(knot_rrset_t *tsig, uint64_t time)
int knot_tsig_rdata_set_time_signed(knot_rrset_t *tsig, uint64_t time)
{
uint8_t *rd = tsig_rdata_seek(tsig, TSIG_TSIGNED_O, 3*sizeof(uint16_t));
if (!rd) {
......@@ -171,19 +172,19 @@ int tsig_rdata_set_time_signed(knot_rrset_t *tsig, uint64_t time)
}
_public_
int tsig_rdata_store_current_time(knot_rrset_t *tsig)
int knot_tsig_rdata_store_current_time(knot_rrset_t *tsig)
{
if (!tsig) {
return KNOT_EINVAL;
}
time_t curr_time = time(NULL);
/*! \todo bleeding eyes. */
tsig_rdata_set_time_signed(tsig, (uint64_t)curr_time);
knot_tsig_rdata_set_time_signed(tsig, (uint64_t)curr_time);
return KNOT_EOK;
}
_public_
int tsig_rdata_set_fudge(knot_rrset_t *tsig, uint16_t fudge)
int knot_tsig_rdata_set_fudge(knot_rrset_t *tsig, uint16_t fudge)
{
uint8_t *rd = tsig_rdata_seek(tsig, TSIG_FUDGE_O, sizeof(uint16_t));
if (!rd) {
......@@ -195,7 +196,7 @@ int tsig_rdata_set_fudge(knot_rrset_t *tsig, uint16_t fudge)
}
_public_
int tsig_rdata_set_mac(knot_rrset_t *tsig, uint16_t length, const uint8_t *mac)
int knot_tsig_rdata_set_mac(knot_rrset_t *tsig, uint16_t length, const uint8_t *mac)
{
uint8_t *rd = tsig_rdata_seek(tsig, TSIG_MAC_O, length);
if (!rd) {
......@@ -210,7 +211,7 @@ int tsig_rdata_set_mac(knot_rrset_t *tsig, uint16_t length, const uint8_t *mac)
}
_public_
int tsig_rdata_set_orig_id(knot_rrset_t *tsig, uint16_t id)
int knot_tsig_rdata_set_orig_id(knot_rrset_t *tsig, uint16_t id)
{
uint8_t *rd = tsig_rdata_seek(tsig, TSIG_ORIGID_O, sizeof(uint16_t));
if (!rd) {
......@@ -223,8 +224,8 @@ int tsig_rdata_set_orig_id(knot_rrset_t *tsig, uint16_t id)
}
_public_
int tsig_rdata_set_other_data(knot_rrset_t *tsig, uint16_t len,
const uint8_t *other_data)
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);
......@@ -245,17 +246,17 @@ int tsig_rdata_set_other_data(knot_rrset_t *tsig, uint16_t len,
}
_public_
const knot_dname_t *tsig_rdata_alg_name(const knot_rrset_t *tsig)
const knot_dname_t *knot_tsig_rdata_alg_name(const knot_rrset_t *tsig)
{
const knot_rdata_t *rr_data = knot_rdataset_at(&tsig->rrs, 0);
return knot_rdata_data(rr_data);
}
_public_
knot_tsig_algorithm_t tsig_rdata_alg(const knot_rrset_t *tsig)
knot_tsig_algorithm_t knot_tsig_rdata_alg(const knot_rrset_t *tsig)
{
/* Get the algorithm name. */
const knot_dname_t *alg_name = tsig_rdata_alg_name(tsig);
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;
......@@ -279,7 +280,7 @@ knot_tsig_algorithm_t tsig_rdata_alg(const knot_rrset_t *tsig)
}
_public_
uint64_t tsig_rdata_time_signed(const knot_rrset_t *tsig)
uint64_t knot_tsig_rdata_time_signed(const knot_rrset_t *tsig)
{
/*! \todo How to return invalid value? */
uint8_t *rd = tsig_rdata_seek(tsig, TSIG_TSIGNED_O, 3*sizeof(uint16_t));
......@@ -290,7 +291,7 @@ uint64_t tsig_rdata_time_signed(const knot_rrset_t *tsig)
}
_public_
uint16_t tsig_rdata_fudge(const knot_rrset_t *tsig)
uint16_t knot_tsig_rdata_fudge(const knot_rrset_t *tsig)
{
uint8_t *rd = tsig_rdata_seek(tsig, TSIG_FUDGE_O, sizeof(uint16_t));
if (!rd) {
......@@ -300,7 +301,7 @@ uint16_t tsig_rdata_fudge(const knot_rrset_t *tsig)
}
_public_
const uint8_t *tsig_rdata_mac(const knot_rrset_t *tsig)
const uint8_t *knot_tsig_rdata_mac(const knot_rrset_t *tsig)
{
uint8_t *rd = tsig_rdata_seek(tsig, TSIG_MAC_O, 0);
if (!rd) {
......@@ -310,7 +311,7 @@ const uint8_t *tsig_rdata_mac(const knot_rrset_t *tsig)
}
_public_
size_t tsig_rdata_mac_length(const knot_rrset_t *tsig)
size_t knot_tsig_rdata_mac_length(const knot_rrset_t *tsig)
{
uint8_t *rd = tsig_rdata_seek(tsig, TSIG_MACLEN_O, sizeof(uint16_t));
if (!rd) {
......@@ -320,7 +321,7 @@ size_t tsig_rdata_mac_length(const knot_rrset_t *tsig)
}
_public_
uint16_t tsig_rdata_orig_id(const knot_rrset_t *tsig)
uint16_t knot_tsig_rdata_orig_id(const knot_rrset_t *tsig)
{
uint8_t *rd = tsig_rdata_seek(tsig, TSIG_ORIGID_O, sizeof(uint16_t));
if (!rd) {
......@@ -330,7 +331,7 @@ uint16_t tsig_rdata_orig_id(const knot_rrset_t *tsig)
}
_public_
uint16_t tsig_rdata_error(const knot_rrset_t *tsig)
uint16_t knot_tsig_rdata_error(const knot_rrset_t *tsig)
{
uint8_t *rd = tsig_rdata_seek(tsig, TSIG_ERROR_O, sizeof(uint16_t));
if (!rd) {
......@@ -340,7 +341,7 @@ uint16_t tsig_rdata_error(const knot_rrset_t *tsig)
}
_public_
const uint8_t *tsig_rdata_other_data(const knot_rrset_t *tsig)
const uint8_t *knot_tsig_rdata_other_data(const knot_rrset_t *tsig)
{
uint8_t *rd = tsig_rdata_seek(tsig, TSIG_OTHER_O, 0);
if (!rd) {
......@@ -350,7 +351,7 @@ const uint8_t *tsig_rdata_other_data(const knot_rrset_t *tsig)
}
_public_
uint16_t tsig_rdata_other_data_length(const knot_rrset_t *tsig)
uint16_t knot_tsig_rdata_other_data_length(const knot_rrset_t *tsig)
{
uint8_t *rd = tsig_rdata_seek(tsig, TSIG_OLEN_O, sizeof(uint16_t));
if (!rd) {
......@@ -360,7 +361,7 @@ uint16_t tsig_rdata_other_data_length(const knot_rrset_t *tsig)
}
_public_
int tsig_alg_from_name(const knot_dname_t *alg_name)
int knot_tsig_alg_from_name(const knot_dname_t *alg_name)
{
if (!alg_name) {
return 0;
......@@ -386,7 +387,7 @@ int tsig_alg_from_name(const knot_dname_t *alg_name)
}
_public_
size_t tsig_rdata_tsig_variables_length(const knot_rrset_t *tsig)
size_t knot_tsig_rdata_tsig_variables_length(const knot_rrset_t *tsig)
{
if (tsig == NULL) {
return 0;
......@@ -397,25 +398,33 @@ size_t tsig_rdata_tsig_variables_length(const knot_rrset_t *tsig)
return 0;
}
const knot_dname_t *alg_name = tsig_rdata_alg_name(tsig);
const knot_dname_t *alg_name = knot_tsig_rdata_alg_name(tsig);
if (!alg_name) {
return 0;
}
uint16_t other_data_length = tsig_rdata_other_data_length(tsig);
uint16_t other_data_length = knot_tsig_rdata_other_data_length(tsig);
return knot_dname_size(key_name) + knot_dname_size(alg_name) +
other_data_length + KNOT_TSIG_VARIABLES_LENGTH;
}
_public_
size_t tsig_rdata_tsig_timers_length()
size_t knot_tsig_rdata_tsig_timers_length()
{
/*! \todo Cleanup */
return KNOT_TSIG_TIMERS_LENGTH;
}
const char *tsig_alg_to_str(knot_tsig_algorithm_t alg)
/*!
* \brief Convert TSIG algorithm identifier to name.
*
* \param alg TSIG algorithm identifier.
*
* \retval TSIG algorithm string name.
* \retval Empty string if undefined.
*/
static const char *knot_tsig_alg_to_str(knot_tsig_algorithm_t alg)
{
knot_lookup_table_t *item;
......@@ -429,7 +438,7 @@ const char *tsig_alg_to_str(knot_tsig_algorithm_t alg)
}
_public_
const knot_dname_t *tsig_alg_to_dname(knot_tsig_algorithm_t alg)
const knot_dname_t *knot_tsig_alg_to_dname(knot_tsig_algorithm_t alg)
{
knot_lookup_table_t *item;
......@@ -443,13 +452,13 @@ const knot_dname_t *tsig_alg_to_dname(knot_tsig_algorithm_t alg)
}
_public_
size_t tsig_wire_maxsize(const knot_tsig_key_t *key)
size_t knot_tsig_wire_maxsize(const knot_tsig_key_t *key)
{
if (key == NULL) {
return 0;
}
size_t alg_name_size = strlen(tsig_alg_to_str(key->algorithm)) + 1;
size_t alg_name_size = strlen(knot_tsig_alg_to_str(key->algorithm)) + 1;
/*! \todo Used fixed size as a base. */
return knot_dname_size(key->name) +
......@@ -469,13 +478,13 @@ size_t tsig_wire_maxsize(const knot_tsig_key_t *key)
}
_public_
int tsig_rdata_is_ok(const knot_rrset_t *tsig)
int knot_tsig_rdata_is_ok(const knot_rrset_t *tsig)
{
/*! \todo Check size, needs to check variable-length fields. */
const knot_rdata_t *rr_data = knot_rdataset_at(&tsig->rrs, 0);
return (tsig
&& knot_rdata_data(rr_data) != NULL
&& tsig_rdata_seek(tsig, TSIG_OTHER_O, 0) != NULL
&& tsig_rdata_alg_name(tsig) != NULL
&& tsig_rdata_time_signed(tsig) != 0);
&& knot_tsig_rdata_alg_name(tsig) != NULL
&& knot_tsig_rdata_time_signed(tsig) != 0);
}
......@@ -77,57 +77,47 @@ typedef struct knot_sign_context {
* \retval KNOT_EINVAL
* \retval KNOT_EOK
*/
int tsig_create_rdata(knot_rrset_t *rr, const knot_dname_t *alg,
int knot_tsig_create_rdata(knot_rrset_t *rr, const knot_dname_t *alg,
uint16_t maclen, uint16_t tsig_err);
int tsig_rdata_set_time_signed(knot_rrset_t *tsig, uint64_t time);
int knot_tsig_rdata_set_time_signed(knot_rrset_t *tsig, uint64_t time);
int tsig_rdata_store_current_time(knot_rrset_t *tsig);
int knot_tsig_rdata_store_current_time(knot_rrset_t *tsig);
int tsig_rdata_set_fudge(knot_rrset_t *tsig, uint16_t fudge);
int knot_tsig_rdata_set_fudge(knot_rrset_t *tsig, uint16_t fudge);
int tsig_rdata_set_mac(knot_rrset_t *tsig, uint16_t length, const uint8_t *mac);
int knot_tsig_rdata_set_mac(knot_rrset_t *tsig, uint16_t length, const uint8_t *mac);
int tsig_rdata_set_orig_id(knot_rrset_t *tsig, uint16_t id);
int knot_tsig_rdata_set_orig_id(knot_rrset_t *tsig, uint16_t id);
int tsig_rdata_set_other_data(knot_rrset_t *tsig, uint16_t length,
int knot_tsig_rdata_set_other_data(knot_rrset_t *tsig, uint16_t length,
const uint8_t *other_data);
const knot_dname_t *tsig_rdata_alg_name(const knot_rrset_t *tsig);
const knot_dname_t *knot_tsig_rdata_alg_name(const knot_rrset_t *tsig);
knot_tsig_algorithm_t tsig_rdata_alg(const knot_rrset_t *tsig);
knot_tsig_algorithm_t knot_tsig_rdata_alg(const knot_rrset_t *tsig);
uint64_t tsig_rdata_time_signed(const knot_rrset_t *tsig);
uint64_t knot_tsig_rdata_time_signed(const knot_rrset_t *tsig);
uint16_t tsig_rdata_fudge(const knot_rrset_t *tsig);
uint16_t knot_tsig_rdata_fudge(const knot_rrset_t *tsig);
const uint8_t *tsig_rdata_mac(const knot_rrset_t *tsig);
const uint8_t *knot_tsig_rdata_mac(const knot_rrset_t *tsig);
size_t tsig_rdata_mac_length(const knot_rrset_t *tsig);
size_t knot_tsig_rdata_mac_length(const knot_rrset_t *tsig);
uint16_t tsig_rdata_orig_id(const knot_rrset_t *tsig);
uint16_t knot_tsig_rdata_orig_id(const knot_rrset_t *tsig);
uint16_t tsig_rdata_error(const knot_rrset_t *tsig);
uint16_t knot_tsig_rdata_error(const knot_rrset_t *tsig);
const uint8_t *tsig_rdata_other_data(const knot_rrset_t *tsig);
const uint8_t *knot_tsig_rdata_other_data(const knot_rrset_t *tsig);
uint16_t tsig_rdata_other_data_length(const knot_rrset_t *tsig);
uint16_t knot_tsig_rdata_other_data_length(const knot_rrset_t *tsig);
size_t tsig_rdata_tsig_variables_length(const knot_rrset_t *tsig);
size_t knot_tsig_rdata_tsig_variables_length(const knot_rrset_t *tsig);
size_t tsig_rdata_tsig_timers_length();
size_t knot_tsig_rdata_tsig_timers_length();
int tsig_alg_from_name(const knot_dname_t *name);
/*!
* \brief Convert TSIG algorithm identifier to name.
*
* \param alg TSIG algorithm identifier.
*
* \retval TSIG algorithm string name.
* \retval Empty string if undefined.
*/
const char *tsig_alg_to_str(knot_tsig_algorithm_t alg);
int knot_tsig_alg_from_name(const knot_dname_t *name);
/*!
* \brief Convert TSIG algorithm identifier to domain name.
......@@ -137,7 +127,7 @@ const char *tsig_alg_to_str(knot_tsig_algorithm_t alg);
* \retval TSIG algorithm string name.
* \retval Empty string if undefined.
*/
const knot_dname_t *tsig_alg_to_dname(knot_tsig_algorithm_t alg);
const knot_dname_t *knot_tsig_alg_to_dname(knot_tsig_algorithm_t alg);
/*!
* \brief Return TSIG RRSET maximum wire size for given algorithm.
......@@ -146,9 +136,9 @@ const knot_dname_t *tsig_alg_to_dname(knot_tsig_algorithm_t alg);
*
* \return RRSET wire size.
*/
size_t tsig_wire_maxsize(const knot_tsig_key_t *key);
size_t knot_tsig_wire_maxsize(const knot_tsig_key_t *key);
/*! \todo Documentation. */
int tsig_rdata_is_ok(const knot_rrset_t *tsig);
int knot_tsig_rdata_is_ok(const knot_rrset_t *tsig);
/*! @} */
......@@ -43,12 +43,12 @@ static int knot_tsig_check_algorithm(const knot_rrset_t *tsig_rr)
return KNOT_EINVAL;
}
const knot_dname_t *alg_name = tsig_rdata_alg_name(tsig_rr);
const knot_dname_t *alg_name = knot_tsig_rdata_alg_name(tsig_rr);
if (!alg_name) {
return KNOT_EMALF;
}
knot_tsig_algorithm_t alg = tsig_alg_from_name(alg_name);
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");
......@@ -162,11 +162,11 @@ static int knot_tsig_check_time_signed(const knot_rrset_t *tsig_rr,
}
/* Get the time signed and fudge values. */
uint64_t time_signed = tsig_rdata_time_signed(tsig_rr);
uint64_t time_signed = knot_tsig_rdata_time_signed(tsig_rr);
if (time_signed == 0) {
return KNOT_TSIG_EBADTIME;
}
uint16_t fudge = tsig_rdata_fudge(tsig_rr);
uint16_t fudge = knot_tsig_rdata_fudge(tsig_rr);
if (fudge == 0) {
return KNOT_TSIG_EBADTIME;
}
......@@ -224,7 +224,7 @@ static int knot_tsig_write_tsig_variables(uint8_t *wire,
offset += sizeof(uint32_t);
/* Copy alg name. */
const knot_dname_t *alg_name = tsig_rdata_alg_name(tsig_rr);
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;
......@@ -241,23 +241,23 @@ static int knot_tsig_write_tsig_variables(uint8_t *wire,
/* Following data are written in network order. */
/* Time signed. */
knot_wire_write_u48(wire + offset, tsig_rdata_time_signed(tsig_rr));
knot_wire_write_u48(wire + offset, knot_tsig_rdata_time_signed(tsig_rr));
offset += 6;
dbg_tsig_verb("TSIG: write variables: time signed: %"PRIu64" \n",
tsig_rdata_time_signed(tsig_rr));
knot_tsig_rdata_time_signed(tsig_rr));
dbg_tsig_hex_detail((char *)(wire + offset - 6), 6);
/* Fudge. */
knot_wire_write_u16(wire + offset, tsig_rdata_fudge(tsig_rr));
knot_wire_write_u16(wire + offset, knot_tsig_rdata_fudge(tsig_rr));
offset += sizeof(uint16_t);
dbg_tsig_verb("TSIG: write variables: fudge: %hu\n",
tsig_rdata_fudge(tsig_rr));
knot_tsig_rdata_fudge(tsig_rr));
/* TSIG error. */
knot_wire_write_u16(wire + offset, tsig_rdata_error(tsig_rr));
knot_wire_write_u16(wire + offset, knot_tsig_rdata_error(tsig_rr));
offset += sizeof(uint16_t);
/* Get other data length. */
uint16_t other_data_length = tsig_rdata_other_data_length(tsig_rr);
uint16_t other_data_length = knot_tsig_rdata_other_data_length(tsig_rr);
/* Get other data. */
const uint8_t *other_data = tsig_rdata_other_data(tsig_rr);
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;
......@@ -286,9 +286,9 @@ static int knot_tsig_wire_write_timers(uint8_t *wire,
}
//write time signed
knot_wire_write_u48(wire, tsig_rdata_time_signed(tsig_rr));
knot_wire_write_u48(wire, knot_tsig_rdata_time_signed(tsig_rr));
//write fudge
knot_wire_write_u16(wire + 6, tsig_rdata_fudge(tsig_rr));
knot_wire_write_u16(wire + 6, knot_tsig_rdata_fudge(tsig_rr));
return KNOT_EOK;
}
......@@ -314,11 +314,11 @@ static int knot_tsig_create_sign_wire(const uint8_t *msg, size_t msg_len,
*/
dbg_tsig_verb("Counting wire size: %zu, %zu, %zu.\n",
msg_len, request_mac_len,
tsig_rdata_tsig_variables_length(tmp_tsig));
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) +
tsig_rdata_tsig_variables_length(tmp_tsig));
knot_tsig_rdata_tsig_variables_length(tmp_tsig));
uint8_t *wire = malloc(wire_len);
if (!wire) {
KNOT_ERR_ALLOC_FAILED;
......@@ -390,10 +390,10 @@ static int knot_tsig_create_sign_wire_next(const uint8_t *msg, size_t msg_len,
*/
dbg_tsig_verb("Counting wire size: %zu, %zu, %zu.\n",
msg_len, prev_mac_len,
tsig_rdata_tsig_timers_length());
knot_tsig_rdata_tsig_timers_length());
size_t wire_len = sizeof(uint8_t) *
(msg_len + prev_mac_len +
tsig_rdata_tsig_timers_length() + 2);
knot_tsig_rdata_tsig_timers_length() + 2);
uint8_t *wire = malloc(wire_len);
if (!wire) {
KNOT_ERR_ALLOC_FAILED;
......@@ -464,13 +464,13 @@ int knot_tsig_sign(uint8_t *msg, size_t *msg_len,
uint16_t rdata_rcode = 0;
if (tsig_rcode == KNOT_TSIG_ERR_BADTIME)
rdata_rcode = tsig_rcode;
tsig_create_rdata(tmp_tsig, tsig_alg_to_dname(key->algorithm),
knot_tsig_create_rdata(tmp_tsig, knot_tsig_alg_to_dname(key->algorithm),
knot_tsig_digest_length(key->algorithm), rdata_rcode);
/* Distinguish BADTIME response. */
if (tsig_rcode == KNOT_TSIG_ERR_BADTIME) {
/* Set client's time signed into the time signed field. */
tsig_rdata_set_time_signed(tmp_tsig, request_time_signed);
knot_tsig_rdata_set_time_signed(tmp_tsig, request_time_signed);
/* Store current time into Other data. */
uint8_t time_signed[6];
......@@ -479,18 +479,18 @@ int knot_tsig_sign(uint8_t *msg, size_t *msg_len,
uint64_t time64 = curr_time;
knot_wire_write_u48(time_signed, time64);
tsig_rdata_set_other_data(tmp_tsig, 6, time_signed);