Commit f942ad65 authored by Daniel Salzman's avatar Daniel Salzman

rdata: remove superfluous getters/setters

parent fc26cda0
......@@ -342,8 +342,7 @@ int knot_check_signature(const knot_rrset_t *covered,
// identify fields in the signature being validated
const knot_rdata_t *rr_data = knot_rdataset_at(&rrsigs->rrs, pos);
uint8_t *rdata = knot_rdata_data(rr_data);
uint8_t *rdata = knot_rdataset_at(&rrsigs->rrs, pos)->data;
if (!rdata) {
return KNOT_EINVAL;
}
......
......@@ -194,8 +194,8 @@ static bool nsec3param_valid(const knot_rdataset_t *rrs,
knot_rdata_t *rrd = knot_rdataset_at(rrs, 0);
dnssec_binary_t rdata = {
.size = knot_rdata_rdlen(rrd),
.data = knot_rdata_data(rrd),
.size = rrd->len,
.data = rrd->data,
};
dnssec_nsec3_params_t parsed = { 0 };
......
......@@ -26,14 +26,14 @@
#include "knot/query/requestor.h"
#include "knot/zone/zone.h"
static bool match_key_ds(zone_key_t *key, const knot_rdata_t *ds)
static bool match_key_ds(zone_key_t *key, knot_rdata_t *ds)
{
assert(key);
assert(ds);
dnssec_binary_t ds_rdata = {
.data = knot_rdata_data(ds),
.size = knot_rdata_rdlen(ds)
.size = ds->len,
.data = ds->data,
};
dnssec_binary_t cds_rdata = { 0 };
......
......@@ -45,14 +45,14 @@ static int serialize_rrset(wire_ctx_t *wire, const knot_rrset_t *rrset, long *ph
for ( ; *phase < rrset->rrs.rr_count; (*phase)++) {
const knot_rdata_t *rr = knot_rdataset_at(&rrset->rrs, *phase);
assert(rr);
uint16_t rdlen = knot_rdata_rdlen(rr);
uint16_t rdlen = rr->len;
if (wire_ctx_available(wire) < sizeof(uint32_t) + sizeof(uint16_t) + rdlen) {
return KNOT_EOK;
}
// Compatibility, but one TTL per rrset would be enough.
wire_ctx_write_u32(wire, rrset->ttl);
wire_ctx_write_u16(wire, rdlen);
wire_ctx_write(wire, knot_rdata_data(rr), rdlen);
wire_ctx_write(wire, rr->data, rdlen);
}
*phase = SERIALIZE_RRSET_DONE;
......@@ -171,7 +171,7 @@ static uint64_t rrset_binary_size(const knot_rrset_t *rrset)
assert(rr);
// TTL + RR size + RR.
size += sizeof(uint32_t) + sizeof(uint16_t) + knot_rdata_rdlen(rr);
size += sizeof(uint32_t) + sizeof(uint16_t) + rr->len;
}
return size;
......
......@@ -169,7 +169,7 @@ static bool rrset_empty(const knot_rrset_t *rrset)
}
if (rr_count == 1) {
const knot_rdata_t *rr = knot_rdataset_at(&rrset->rrs, 0);
return knot_rdata_rdlen(rr) == 0;
return rr->len == 0;
}
return false;
}
......
/* Copyright (C) 2016 CZ.NIC, z.s.p.o. <knot-dns@labs.nic.cz>
/* Copyright (C) 2017 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
......@@ -959,10 +959,10 @@ static int load_nsec3param(zone_contents_t *contents)
return KNOT_EINVAL;
}
const knot_rdata_t *rr = knot_rdataset_at(rrs, 0);
knot_rdata_t *rr = knot_rdataset_at(rrs, 0);
dnssec_binary_t rdata = {
.size = knot_rdata_rdlen(rr),
.data = knot_rdata_data(rr)
.size = rr->len,
.data = rr->data,
};
dnssec_nsec3_params_t new_params = { 0 };
......
......@@ -248,9 +248,7 @@ static int check_signature(const knot_rdataset_t *rrsigs, size_t pos,
}
const knot_rdata_t *rr_data = knot_rdataset_at(rrsigs, pos);
uint8_t *rdata = knot_rdata_data(rr_data);
if (knot_sign_ctx_add_data(sign_ctx, rdata, covered) != KNOT_EOK) {
if (knot_sign_ctx_add_data(sign_ctx, rr_data->data, covered) != KNOT_EOK) {
ret = KNOT_ENOMEM;
goto fail;
}
......@@ -362,8 +360,7 @@ static int check_rrsig_rdata(sem_handler_t *handler,
dnssec_key_t *key;
ret = dnssec_key_from_rdata(&key, zone->apex->owner,
knot_rdata_data(dnskey),
knot_rdata_rdlen(dnskey));
dnskey->data, dnskey->len);
if (ret != KNOT_EOK) {
continue;
}
......@@ -543,16 +540,14 @@ static int check_submission(const zone_node_t *node, semchecks_data_t *data)
dnssec_key_t *key;
int ret = dnssec_key_from_rdata(&key, data->zone->apex->owner,
knot_rdata_data(dnskey),
knot_rdata_rdlen(dnskey));
dnskey->data, dnskey->len);
if (ret != KNOT_EOK) {
return ret;
}
uint16_t flags = dnssec_key_get_flags(key);
dnssec_binary_t cds_calc = { 0 };
dnssec_binary_t cds_orig = { .size = knot_rdata_rdlen(cds),
.data = knot_rdata_data(cds) };
dnssec_binary_t cds_orig = { .size = cds->len, .data = cds->data };
ret = dnssec_key_create_ds(key, digest_type, &cds_calc);
if (ret != KNOT_EOK) {
dnssec_key_free(key);
......@@ -919,8 +914,7 @@ static int check_nsec3(const zone_node_t *node, semchecks_data_t *data)
const knot_rdataset_t *nsec3param = node_rdataset(data->zone->apex,
KNOT_RRTYPE_NSEC3PARAM);
knot_rdata_t *rrd = knot_rdataset_at(nsec3param, 0);
dnssec_binary_t rdata = { .size = knot_rdata_rdlen(rrd),
.data = knot_rdata_data(rrd)};
dnssec_binary_t rdata = { .size = rrd->len, .data = rrd->data };
ret = dnssec_nsec3_params_from_rdata(&params_apex, &rdata);
if (ret != DNSSEC_EOK) {
ret = knot_error_from_libdnssec(ret);
......@@ -1133,8 +1127,7 @@ static void check_dnskey(zone_contents_t *zone, sem_handler_t *handler)
knot_rdata_t *dnskey = knot_rdataset_at(dnskeys, i);
dnssec_key_t *key;
int ret = dnssec_key_from_rdata(&key, zone->apex->owner,
knot_rdata_data(dnskey),
knot_rdata_rdlen(dnskey));
dnskey->data, dnskey->len);
if (ret == KNOT_EOK) {
dnssec_key_free(key);
} else {
......
......@@ -489,8 +489,8 @@ static int write_rdata(const knot_rrset_t *rrset, uint16_t rrset_index,
.hint = KNOT_COMPR_HINT_RDATA + rrset_index
};
const uint8_t *src = knot_rdata_data(rdata);
size_t src_avail = knot_rdata_rdlen(rdata);
const uint8_t *src = rdata->data;
size_t src_avail = rdata->len;
if (src_avail > 0) {
/* Only write non-empty data. */
const knot_rdata_descriptor_t *desc =
......@@ -702,7 +702,7 @@ static int parse_rdata(const uint8_t *pkt_wire, size_t *pos, size_t pkt_size,
knot_rdata_t *rr = knot_rdataset_at(rrs, rrs->rr_count - 1);
assert(rr);
uint8_t *dst = knot_rdata_data(rr);
uint8_t *dst = rr->data;
size_t dst_avail = buffer_size;
/* Parse RDATA */
......
......@@ -55,42 +55,6 @@ inline static void knot_rdata_init(knot_rdata_t *rdata, uint16_t len, const uint
memcpy(rdata->data, data, len);
}
/*!
* \brief Returns RDATA size of single RR.
*
* \param rr RR whose size we want.
* \return RR size.
*/
inline static uint16_t knot_rdata_rdlen(const knot_rdata_t *rr)
{
assert(rr);
return rr->len;
}
/*!
* \brief Sets size for given RR.
*
* \param rr RR whose size we want to set.
* \param len Size to be set.
*/
inline static void knot_rdata_set_rdlen(knot_rdata_t *rr, uint16_t len)
{
assert(rr);
rr->len = len;
}
/*!
* \brief Returns pointer to RR data.
*
* \param rr RR whose data we want.
* \return RR data pointer.
*/
inline static uint8_t *knot_rdata_data(const knot_rdata_t *rr)
{
assert(rr);
return (uint8_t *)rr->data;
}
/*!
* \brief Returns actual size of the rdata structure for given rdata length.
*
......
......@@ -33,7 +33,7 @@ static knot_rdata_t *rr_seek(knot_rdata_t *rr, size_t pos)
uint8_t *raw = (uint8_t *)rr;
for (size_t i = 0; i < pos; i++) {
raw += knot_rdata_size(knot_rdata_rdlen((knot_rdata_t *)raw));
raw += knot_rdata_size(((knot_rdata_t *)raw)->len);
}
return (knot_rdata_t *)raw;
......@@ -58,8 +58,9 @@ static int add_rr_at(knot_rdataset_t *rrs, const knot_rdata_t *rr, size_t pos,
if (rrs == NULL || pos > rrs->rr_count || rrs->rr_count == UINT16_MAX) {
return KNOT_EINVAL;
}
const uint16_t size = knot_rdata_rdlen(rr);
const uint8_t *rdata = knot_rdata_data(rr);
const uint16_t size = rr->len;
const uint8_t *rdata = rr->data;
size_t total_size = knot_rdataset_size(rrs);
......@@ -89,7 +90,7 @@ static int add_rr_at(knot_rdataset_t *rrs, const knot_rdata_t *rr, size_t pos,
// Make space for new data by moving the array
uint8_t *dst = (uint8_t *)old_rr + knot_rdata_size(size);
size_t len = ((uint8_t *)last_rr + knot_rdata_size(knot_rdata_rdlen(last_rr))) - (uint8_t *)old_rr;
size_t len = ((uint8_t *)last_rr + knot_rdata_size(last_rr->len)) - (uint8_t *)old_rr;
memmove(dst, old_rr, len);
......@@ -112,11 +113,11 @@ static int remove_rr_at(knot_rdataset_t *rrs, size_t pos, knot_mm_t *mm)
assert(last_rr);
size_t total_size = knot_rdataset_size(rrs);
uint16_t old_size = knot_rdata_rdlen(old_rr);
uint16_t old_size = old_rr->len;
// Move RDATA
uint8_t *old_threshold = (uint8_t *)old_rr + knot_rdata_size(old_size);
uint8_t *last_threshold = (uint8_t *)last_rr + knot_rdata_size(knot_rdata_rdlen(last_rr));
uint8_t *last_threshold = (uint8_t *)last_rr + knot_rdata_size(last_rr->len);
memmove(old_rr, old_threshold, last_threshold - old_threshold);
if (rrs->rr_count > 1) {
......@@ -229,7 +230,7 @@ int knot_rdataset_gather(knot_rdataset_t *dst, knot_rdata_t **src, uint16_t coun
size_t size = 0;
for (int i = 0; i < count; ++i) {
size += knot_rdata_size(knot_rdata_rdlen(src[i]));
size += knot_rdata_size(src[i]->len);
}
knot_rdata_t *data = mm_alloc(mm, size);
......@@ -242,7 +243,7 @@ int knot_rdataset_gather(knot_rdataset_t *dst, knot_rdata_t **src, uint16_t coun
dst->data = data;
for (int i = 0; i < count; ++i) {
size_t len = knot_rdata_size(knot_rdata_rdlen(src[i]));
size_t len = knot_rdata_size(src[i]->len);
memcpy(data, src[i], len);
data += len;
}
......@@ -271,7 +272,7 @@ int knot_rdataset_reserve(knot_rdataset_t *rrs, size_t size, knot_mm_t *mm)
// We have to initialise the 'size' field in the reserved space.
knot_rdata_t *rr = knot_rdataset_at(rrs, rrs->rr_count - 1);
assert(rr);
knot_rdata_set_rdlen(rr, size);
rr->len = size;
return KNOT_EOK;
}
......@@ -421,8 +422,8 @@ int knot_rdataset_sort_at(knot_rdataset_t *rrs, size_t pos, knot_mm_t *mm)
assert(earlier_rr);
// Save the RR to be moved
const uint16_t size = knot_rdata_rdlen(rr);
const uint8_t *rdata = knot_rdata_data(rr);
const uint16_t size = rr->len;
const uint8_t *rdata = rr->data;
uint8_t buf[knot_rdata_size(size)];
knot_rdata_t *tmp_rr = (knot_rdata_t *)buf;
......@@ -430,11 +431,11 @@ int knot_rdataset_sort_at(knot_rdataset_t *rrs, size_t pos, knot_mm_t *mm)
// Move the array or just part of it
uint8_t *earlier_rr_moved = (uint8_t *)earlier_rr + knot_rdata_size(size);
size_t last_rr_size = knot_rdata_size(knot_rdata_rdlen(last_rr));
size_t last_rr_size = knot_rdata_size(last_rr->len);
memmove(earlier_rr_moved, earlier_rr, (last_rr + last_rr_size) - earlier_rr);
// Set new RR
knot_rdata_init(earlier_rr, size, knot_rdata_data(tmp_rr));
knot_rdata_init(earlier_rr, size, tmp_rr->data);
return KNOT_EOK;
}
......@@ -188,7 +188,7 @@ int knot_rdataset_sort_at(knot_rdataset_t *rrs, size_t pos, knot_mm_t *mm);
static inline
uint8_t *knot_rdata_offset(const knot_rdataset_t *rrs, size_t pos, size_t offset) {
knot_rdata_t *rr = knot_rdataset_at(rrs, pos);
return knot_rdata_data(rr) + offset;
return rr->data + offset;
}
/*! @} */
......@@ -1817,13 +1817,13 @@ int knot_rrset_txt_dump_data(const knot_rrset_t *rrset,
return KNOT_EINVAL;
}
const knot_rdata_t *rr_data = knot_rdataset_at(&rrset->rrs, pos);
knot_rdata_t *rr_data = knot_rdataset_at(&rrset->rrs, pos);
if (rr_data == NULL) {
return KNOT_EINVAL; /* bad pos or rrset->rrs */
}
uint8_t *data = knot_rdata_data(rr_data);
uint16_t data_len = knot_rdata_rdlen(rr_data);
uint8_t *data = rr_data->data;
uint16_t data_len = rr_data->len;
rrset_dump_params_t p = {
.style = style,
......
......@@ -202,8 +202,8 @@ int knot_rrset_rr_to_canonical(knot_rrset_t *rrset)
knot_rdata_t *rdata = knot_rdataset_at(&rrset->rrs, 0);
assert(rdata);
uint16_t rdlen = knot_rdata_rdlen(rdata);
uint8_t *pos = knot_rdata_data(rdata);
uint16_t rdlen = rdata->len;
uint8_t *pos = rdata->data;
uint8_t *endpos = pos + rdlen;
/* No RDATA */
......@@ -266,7 +266,7 @@ size_t knot_rrset_size(const knot_rrset_t *rrset)
const knot_rdata_t *rr = knot_rdataset_at(&rrset->rrs, i);
assert(rr);
/* 10B = TYPE + CLASS + TTL + RDLENGTH */
total_size += knot_rdata_rdlen(rr) + 10;
total_size += rr->len + 10;
}
return total_size;
......
/* Copyright (C) 2014 CZ.NIC, z.s.p.o. <knot-dns@labs.nic.cz>
/* Copyright (C) 2017 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
......@@ -25,7 +25,7 @@ int knot_a_addr(const knot_rdataset_t *rrs, size_t pos, struct sockaddr_in *dst)
KNOT_RDATASET_CHECK(rrs, pos, return KNOT_EINVAL);
knot_rdata_t *rr = knot_rdataset_at(rrs, pos);
return sockaddr_set_raw((struct sockaddr_storage *)dst, AF_INET,
knot_rdata_data(rr), knot_rdata_rdlen(rr));
rr->data, rr->len);
}
_public_
......@@ -34,5 +34,5 @@ int knot_aaaa_addr(const knot_rdataset_t *rrs, size_t pos, struct sockaddr_in6 *
KNOT_RDATASET_CHECK(rrs, pos, return KNOT_EINVAL);
knot_rdata_t *rr = knot_rdataset_at(rrs, pos);
return sockaddr_set_raw((struct sockaddr_storage *)dst, AF_INET6,
knot_rdata_data(rr), knot_rdata_rdlen(rr));
rr->data, rr->len);
}
/* Copyright (C) 2014 CZ.NIC, z.s.p.o. <knot-dns@labs.nic.cz>
/* Copyright (C) 2017 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
......@@ -44,5 +44,5 @@ void knot_dnskey_key(const knot_rdataset_t *rrs, size_t pos, uint8_t **key,
KNOT_RDATASET_CHECK(rrs, pos, return);
*key = knot_rdata_offset(rrs, pos, 4);
const knot_rdata_t *rr = knot_rdataset_at(rrs, pos);
*key_size = knot_rdata_rdlen(rr) - 4;
*key_size = rr->len - 4;
}
/* Copyright (C) 2015 CZ.NIC, z.s.p.o. <knot-dns@labs.nic.cz>
/* Copyright (C) 2017 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
......@@ -45,5 +45,5 @@ void knot_ds_digest(const knot_rdataset_t *rrs, size_t pos,
KNOT_RDATASET_CHECK(rrs, pos, return);
*digest = knot_rdata_offset(rrs, pos, 4);
const knot_rdata_t *rr = knot_rdataset_at(rrs, pos);
*digest_size = knot_rdata_rdlen(rr) - 4;
*digest_size = rr->len - 4;
}
/* Copyright (C) 2014 CZ.NIC, z.s.p.o. <knot-dns@labs.nic.cz>
/* Copyright (C) 2017 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
......@@ -33,6 +33,6 @@ void knot_nsec_bitmap(const knot_rdataset_t *rrs,
knot_rdata_t *rr = knot_rdataset_at(rrs, 0);
int next_size = knot_dname_size(knot_nsec_next(rrs));
*bitmap = knot_rdata_data(rr) + next_size;
*size = knot_rdata_rdlen(rr) - next_size;
*bitmap = rr->data + next_size;
*size = rr->len - next_size;
}
/* Copyright (C) 2011 CZ.NIC, z.s.p.o. <knot-dns@labs.nic.cz>
/* Copyright (C) 2017 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
......@@ -44,5 +44,5 @@ void knot_nsec3_bitmap(const knot_rdataset_t *rrs, size_t pos,
*bitmap = knot_rdata_offset(rrs, pos, offset);
const knot_rdata_t *rr = knot_rdataset_at(rrs, pos);
*size = knot_rdata_rdlen(rr) - offset;
*size = rr->len - offset;
}
......@@ -88,7 +88,7 @@ size_t knot_edns_wire_size(knot_rrset_t *opt_rr)
knot_rdata_t *rdata = knot_rdataset_at(&opt_rr->rrs, 0);
assert(rdata != NULL);
return KNOT_EDNS_MIN_SIZE + knot_rdata_rdlen(rdata);
return KNOT_EDNS_MIN_SIZE + rdata->len;
}
_public_
......@@ -226,8 +226,7 @@ static uint8_t *skip_option(wire_ctx_t *wire, uint16_t *code, uint16_t *full_len
*/
static uint8_t *find_option(knot_rdata_t *rdata, uint16_t opt_code)
{
wire_ctx_t wire = wire_ctx_init_const(knot_rdata_data(rdata),
knot_rdata_rdlen(rdata));
wire_ctx_t wire = wire_ctx_init_const(rdata->data, rdata->len);
uint8_t *position = NULL;
uint16_t code, full_len;
......@@ -265,10 +264,8 @@ static int delete_and_reserve_option(knot_rrset_t *opt_rr, uint16_t code,
knot_rdata_t *rdata = knot_rdataset_at(&opt_rr->rrs, 0);
assert(rdata != NULL);
wire_ctx_t rd_wire = wire_ctx_init_const(knot_rdata_data(rdata),
knot_rdata_rdlen(rdata));
wire_ctx_t wr_wire = wire_ctx_init(knot_rdata_data(rdata),
knot_rdata_rdlen(rdata));
wire_ctx_t rd_wire = wire_ctx_init_const(rdata->data, rdata->len);
wire_ctx_t wr_wire = wire_ctx_init(rdata->data, rdata->len);
uint16_t deleted_len = 0; // Total area length acquired by deleting.
......@@ -289,7 +286,7 @@ static int delete_and_reserve_option(knot_rrset_t *opt_rr, uint16_t code,
assert(wr_wire.error == KNOT_EOK);
} else {
// There isn't enough space for a copy.
memmove(knot_rdata_data(rdata) + wire_ctx_offset(&wr_wire),
memmove(rdata->data + wire_ctx_offset(&wr_wire),
rd_pos, full_len);
wire_ctx_skip(&wr_wire, full_len);
assert(wr_wire.error == KNOT_EOK);
......@@ -299,7 +296,7 @@ static int delete_and_reserve_option(knot_rrset_t *opt_rr, uint16_t code,
if (reserve && !wr_pos &&
deleted_len >= (KNOT_EDNS_OPTION_HDRLEN + size)) {
// Reserve this freed space.
wr_pos = knot_rdata_data(rdata) + wire_ctx_offset(&wr_wire);
wr_pos = rdata->data + wire_ctx_offset(&wr_wire);
deleted_len -= KNOT_EDNS_OPTION_HDRLEN + size;
wire_ctx_skip(&wr_wire, KNOT_EDNS_OPTION_HDRLEN + size);
}
......@@ -308,8 +305,8 @@ static int delete_and_reserve_option(knot_rrset_t *opt_rr, uint16_t code,
if (deleted_len > 0) {
// Adjust data length.
assert(knot_rdata_rdlen(rdata) >= deleted_len);
knot_rdata_set_rdlen(rdata, knot_rdata_rdlen(rdata) - deleted_len);
assert(rdata->len >= deleted_len);
rdata->len -= deleted_len;
}
if (reserve && wr_pos) {
......@@ -347,8 +344,8 @@ static uint8_t *edns_add(knot_rrset_t *opt, uint16_t code, uint16_t size,
// extract old RDATA
knot_rdata_t *old_rdata = knot_rdataset_at(&opt->rrs, 0);
uint8_t *old_data = knot_rdata_data(old_rdata);
uint16_t old_data_len = knot_rdata_rdlen(old_rdata);
uint8_t *old_data = old_rdata->data;
uint16_t old_data_len = old_rdata->len;
// construct new RDATA
......@@ -375,7 +372,7 @@ static uint8_t *edns_add(knot_rrset_t *opt, uint16_t code, uint16_t size,
return NULL;
}
return knot_rdata_data(knot_rdataset_at(&opt->rrs, 0)) + offset;
return knot_rdataset_at(&opt->rrs, 0)->data + offset;
}
_public_
......@@ -490,8 +487,7 @@ bool knot_edns_check_record(knot_rrset_t *opt_rr)
return false;
}
wire_ctx_t wire = wire_ctx_init_const(knot_rdata_data(rdata),
knot_rdata_rdlen(rdata));
wire_ctx_t wire = wire_ctx_init_const(rdata->data, rdata->len);
/* RFC2671 4.4: {uint16_t code, uint16_t len, data} */
// read data to the end or error
......
......@@ -67,8 +67,7 @@ void knot_rrsig_signature(const knot_rdataset_t *rrs, size_t pos,
uint8_t *rdata = knot_rdata_offset(rrs, pos, 0);
uint8_t *signer = rdata + 18;
const knot_rdata_t *rr = knot_rdataset_at(rrs, pos);
size_t total_size = knot_rdata_rdlen(rr);
size_t total_size = knot_rdataset_at(rrs, pos)->len;
size_t header_size = 18 + knot_dname_size(signer);
*signature = rdata + header_size;
......
......@@ -60,12 +60,11 @@ typedef enum tsig_off_t {
static uint8_t* rdata_seek(const knot_rrset_t *rr, tsig_off_t id, size_t nb)
{
const knot_rdata_t *rr_data = knot_rdataset_at(&rr->rrs, 0);
if (!rr_data || knot_rdata_rdlen(rr_data) == 0) {
if (!rr_data || rr_data->len == 0) {
return NULL;
}
wire_ctx_t wire = wire_ctx_init_const(knot_rdata_data(rr_data),
knot_rdata_rdlen(rr_data));
wire_ctx_t wire = wire_ctx_init_const(rr_data->data, rr_data->len);
/* TSIG RR names should be already sanitized on parse. */
int alg_len = knot_dname_size(wire.wire);
......@@ -243,8 +242,7 @@ int knot_tsig_rdata_set_other_data(knot_rrset_t *tsig, uint16_t len,
_public_
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);
return knot_rdataset_at(&tsig->rrs, 0)->data;
}
_public_
......@@ -412,9 +410,8 @@ _public_
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
return (tsig != NULL
&& knot_rdataset_at(&tsig->rrs, 0) != NULL
&& rdata_seek(tsig, TSIG_OTHER_O, 0) != NULL
&& knot_tsig_rdata_alg_name(tsig) != NULL
&& knot_tsig_rdata_time_signed(tsig) != 0);
......
/* Copyright (C) 2015 CZ.NIC, z.s.p.o. <knot-dns@labs.nic.cz>
/* Copyright (C) 2017 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
......@@ -24,8 +24,8 @@ size_t knot_txt_count(const knot_rdataset_t *rrs, size_t pos)
KNOT_RDATASET_CHECK(rrs, pos, return 0);
const knot_rdata_t *rdata = knot_rdataset_at(rrs, pos);
const uint8_t *start = knot_rdata_data(rdata);
const uint8_t *end = start + knot_rdata_rdlen(rdata);
const uint8_t *start = rdata->data;
const uint8_t *end = start + rdata->len;
size_t count = 0;
......@@ -42,8 +42,8 @@ const uint8_t *knot_txt_data(const knot_rdataset_t *rrs, size_t pos, size_t inde
KNOT_RDATASET_CHECK(rrs, pos, return NULL);
const knot_rdata_t *rdata = knot_rdataset_at(rrs, pos);
const uint8_t *start = knot_rdata_data(rdata);
const uint8_t *end = start + knot_rdata_rdlen(rdata);
const uint8_t *start = rdata->data;
const uint8_t *end = start + rdata->len;
const uint8_t *data = start;
......
/* Copyright (C) 2016 CZ.NIC, z.s.p.o. <knot-dns@labs.nic.cz>
/* Copyright (C) 2017 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
......@@ -231,8 +231,7 @@ static void print_section_opt(const knot_pkt_t *packet)
ercode_str);
knot_rdata_t *rdata = knot_rdataset_at(&packet->opt_rr->rrs, 0);
wire_ctx_t wire = wire_ctx_init_const(knot_rdata_data(rdata),
knot_rdata_rdlen(rdata));
wire_ctx_t wire = wire_ctx_init_const(rdata->data, rdata->len);
while (wire_ctx_available(&wire) >= KNOT_EDNS_OPTION_HDRLEN) {
uint16_t opt_code = wire_ctx_read_u16(&wire);
......
......@@ -98,8 +98,8 @@ static void check_option(knot_rdata_t *rdata, uint16_t opt_code,
{
assert(rdata != NULL);
uint8_t *data = knot_rdata_data(rdata);
uint16_t data_len = knot_rdata_rdlen(rdata);
uint8_t *data = rdata->data;
uint16_t data_len = rdata->len;
/* Check RDLENGTH according to given data length. */
bool check = (data_len >= 4 + opt_len);
......@@ -320,8 +320,8 @@ static bool check_rdata(const knot_rrset_t *opt_rr, uint16_t len, const uint8_t
knot_rdata_t *rdata = knot_rdataset_at(&opt_rr->rrs, 0);
assert(rdata != NULL);
const uint8_t *data_ptr = knot_rdata_data(rdata);
uint16_t data_len = knot_rdata_rdlen(rdata);
const uint8_t *data_ptr = rdata->data;
uint16_t data_len = rdata->len;
if (data_len != len) {
return false;
......
......@@ -33,16 +33,12 @@ int main(int argc, char *argv[])
knot_rdata_t *rdata = (knot_rdata_t *)buf1;
uint8_t payload[] = "abcdefghijklmnop";
knot_rdata_init(rdata, data_size, payload);
const bool set_ok = knot_rdata_rdlen(rdata) == data_size &&
memcmp(knot_rdata_data(rdata), payload, data_size) == 0;
const bool set_ok = rdata->len == data_size &&
memcmp(rdata->data, payload, data_size) == 0;
ok(set_ok, "rdata: init.");
// Test setters
knot_rdata_set_rdlen(rdata, 1);
ok(knot_rdata_rdlen(rdata) == 1, "rdata: set RDLEN.");
// Test compare
knot_rdata_set_rdlen(rdata, data_size);
rdata->len = data_size;
ok(knot_rdata_cmp(rdata, rdata) == 0, "rdata: cmp eq.");
knot_rdata_t *lower = rdata;
......@@ -53,10 +49,10 @@ int main(int argc, char *argv[])
ok(knot_rdata_cmp(greater, lower) > 0, "rdata: cmp greater.");
// Payloads will be the same.
memcpy(knot_rdata_data(greater), knot_rdata_data(lower), data_size);
memcpy(greater->data, lower->data, data_size);
assert(knot_rdata_cmp(lower, greater) == 0);
knot_rdata_set_rdlen(lower, data_size - 1);
lower->len = data_size - 1;
ok(knot_rdata_cmp(lower, greater) < 0, "rdata: cmp lower size.");
ok(knot_rdata_cmp(greater, lower) > 0, "rdata: cmp greater size.");
......
......@@ -188,7 +188,7 @@ int main(int argc, char *argv[])
RDATASET_INIT_WITH(rdataset, rdata_gt);
size_t old_rrs_size = knot_rdataset_size(&rdataset);
size_t rr_size = knot_rdata_rdlen(rdata_lo);
size_t rr_size = rdata_lo->len;
ret = knot_rdataset_reserve(&rdataset, rr_size, NULL);
size_t new_rrs_size = knot_rdataset_size(&rdataset);
bool reserve_ok = ret == KNOT_EOK && new_rrs_size == (old_rrs_size + knot_rdata_size(rr_size));
......
/* Copyright (C) 2016 CZ.NIC, z.s.p.o. <knot-dns@labs.nic.cz>
/* Copyright (C) 2017 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
......@@ -214,7 +214,7 @@ static void check_canon(uint8_t *wire, size_t size, size_t pos, bool canon,
is_int(KNOT_EOK, ret, "OK %s canonization", canon ? "with" : "without");
ok(memcmp(rrset.owner, qname, knot_dname_size(qname)) == 0, "compare owner");
uint8_t *rdata = knot_rdata_data(knot_rdataset_at(&rrset.rrs, 0));
uint8_t *rdata = knot_rdataset_at(&rrset.rrs, 0)->data;
ok(memcmp(rdata, dname, knot_dname_size(dname)) == 0, "compare rdata dname");
knot_rrset_clear(&rrset, NULL);
......
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