Commit 2fa5b27c authored by Vladimír Čunát's avatar Vladimír Čunát

knot_rdata_* changes

The _t isn't uint8_t* anymore but a structure with .len and .data.
parent 60219f68
......@@ -254,8 +254,6 @@ _Bool knot_dname_is_sub(const knot_dname_t *, const knot_dname_t *);
int knot_dname_labels(const uint8_t *, const uint8_t *);
int knot_dname_size(const knot_dname_t *);
char *knot_dname_to_str(char *, const knot_dname_t *, size_t);
uint16_t knot_rdata_rdlen(const knot_rdata_t *);
uint8_t *knot_rdata_data(const knot_rdata_t *);
size_t knot_rdata_array_size(uint16_t);
knot_rdata_t *knot_rdataset_at(const knot_rdataset_t *, size_t);
int knot_rdataset_merge(knot_rdataset_t *, const knot_rdataset_t *, knot_mm_t *);
......
......@@ -105,8 +105,6 @@ printf "\tchar _stub[];\n};\n"
knot_dname_size
knot_dname_to_str
# Resource records
knot_rdata_rdlen
knot_rdata_data
knot_rdata_array_size
knot_rdataset_at
knot_rdataset_merge
......
......@@ -373,7 +373,7 @@ ffi.metatype( knot_rrset_t, {
rdata = function(rr, i)
assert(ffi.istype(knot_rrset_t, rr))
local rdata = knot.knot_rdataset_at(rr.rrs, i)
return ffi.string(knot.knot_rdata_data(rdata), knot.knot_rdata_rdlen(rdata))
return ffi.string(rdata.data, rdata.len)
end,
get = function(rr, i)
assert(ffi.istype(knot_rrset_t, rr))
......
......@@ -475,19 +475,18 @@ static ssize_t stash_rrset(struct kr_cache *cache, const struct kr_query *qry,
}
assert(rr->type == KNOT_RRTYPE_NSEC3);
const knot_rdata_t *np_data = knot_rdata_data(rr->rrs.data);
const int rdlen = knot_rdata_rdlen(rr->rrs.data);
if (rdlen <= 4) return kr_error(EILSEQ); /*< data from outside; less trust */
const int np_dlen = nsec_p_rdlen(np_data);
if (np_dlen > rdlen) return kr_error(EILSEQ);
key = key_NSEC3(k, encloser, nsec_p_mkHash(np_data));
const knot_rdata_t * const rdata = rr->rrs.data;
if (rdata->len <= 4) return kr_error(EILSEQ); /*< data from outside; less trust */
const int np_dlen = nsec_p_rdlen(rdata->data);
if (np_dlen > rdata->len) return kr_error(EILSEQ);
key = key_NSEC3(k, encloser, nsec_p_mkHash(rdata->data));
if (npp && !*npp) {
*npp = mm_alloc(&qry->request->pool, np_dlen);
if (!*npp) {
assert(!ENOMEM);
break;
}
memcpy(*npp, np_data, np_dlen);
memcpy(*npp, rdata->data, np_dlen);
}
break;
default:
......
......@@ -34,10 +34,10 @@ int rdataset_dematerialize(const knot_rdataset_t *rds, uint8_t * restrict data)
knot_rdata_t *rd = rds ? rds->data : NULL;
for (int i = 0; i < rr_count; ++i, rd = kr_rdataset_next(rd)) {
const uint16_t len = knot_rdata_rdlen(rd);
const uint16_t len = rd->len;
memcpy(data, &len, sizeof(len));
data += sizeof(len);
memcpy(data, knot_rdata_data(rd), len);
memcpy(data, rd->data, len);
data += len;
}
//return data - data0;
......
......@@ -181,7 +181,7 @@ static int kr_rrset_validate_with_key(kr_rrset_validation_ctx_t *vctx,
if (key == NULL) {
const knot_rdata_t *krr = knot_rdataset_at(&keys->rrs, key_pos);
int ret = kr_dnssec_key_from_rdata(&created_key, keys->owner,
knot_rdata_data(krr), knot_rdata_rdlen(krr));
krr->data, krr->len);
if (ret != 0) {
vctx->result = ret;
return vctx->result;
......@@ -292,14 +292,14 @@ int kr_dnskeys_trusted(kr_rrset_validation_ctx_t *vctx, const knot_rrset_t *ta)
*/
for (uint16_t i = 0; i < keys->rrs.rr_count; ++i) {
/* RFC4035 5.3.1, bullet 8 */ /* ZSK */
/* LATER(optim.): more efficient way to iterate than _at() */
const knot_rdata_t *krr = knot_rdataset_at(&keys->rrs, i);
const uint8_t *key_data = knot_rdata_data(krr);
if (!kr_dnssec_key_zsk(key_data) || kr_dnssec_key_revoked(key_data)) {
if (!kr_dnssec_key_zsk(krr->data) || kr_dnssec_key_revoked(krr->data)) {
continue;
}
struct dseckey *key = NULL;
if (kr_dnssec_key_from_rdata(&key, keys->owner, key_data, knot_rdata_rdlen(krr)) != 0) {
if (kr_dnssec_key_from_rdata(&key, keys->owner, krr->data, krr->len) != 0) {
continue;
}
if (kr_authenticate_referral(ta, (dnssec_key_t *) key) != 0) {
......
......@@ -55,9 +55,9 @@ static int nsec3_parameters(dnssec_nsec3_params_t *params, const knot_rrset_t *n
const size_t SALT_OFFSET = 5; /* First 5 octets contain { Alg, Flags, Iterations, Salt length } */
dnssec_binary_t rdata = {
.size = SALT_OFFSET + (size_t) knot_nsec3_salt_length(&nsec3->rrs, 0),
.data = knot_rdata_data(rr),
.data = /*const-cast*/(uint8_t *)rr->data,
};
if (rdata.size > knot_rdata_rdlen(rr))
if (rdata.size > rr->len)
return kr_error(EMSGSIZE);
int ret = dnssec_nsec3_params_from_rdata(params, &rdata);
......
......@@ -67,14 +67,14 @@ int kr_authenticate_referral(const knot_rrset_t *ref, const dnssec_key_t *key)
knot_rdata_t *rd = ref->rrs.data;
for (uint16_t i = 0; i < ref->rrs.rr_count; ++i) {
dnssec_binary_t ds_rdata = {
.size = knot_rdata_rdlen(rd),
.data = knot_rdata_data(rd)
.size = rd->len,
.data = rd->data
};
ret = authenticate_ds(key, &ds_rdata, knot_ds_digest_type(&ref->rrs, i));
if (ret == 0) { /* Found a good DS */
return kr_ok();
}
rd = kr_rdataset_next(rd);
rd = knot_rdataset_next(rd);
}
return kr_error(ret);
......@@ -287,10 +287,9 @@ int kr_check_signature(const knot_rrset_t *rrsigs, size_t pos,
}
uint32_t orig_ttl = knot_rrsig_original_ttl(&rrsigs->rrs, pos);
const knot_rdata_t *rr_data = knot_rdataset_at(&rrsigs->rrs, pos);
uint8_t *rdata = knot_rdata_data(rr_data);
const knot_rdata_t *rd = knot_rdataset_at(&rrsigs->rrs, pos);
if (sign_ctx_add_data(sign_ctx, rdata, covered, orig_ttl, trim_labels) != 0) {
if (sign_ctx_add_data(sign_ctx, rd->data, covered, orig_ttl, trim_labels) != 0) {
ret = kr_error(ENOMEM);
goto fail;
}
......
......@@ -158,19 +158,17 @@ static int update_nsaddr(const knot_rrset_t *rr, struct kr_query *query, int *gl
{
if (rr->type == KNOT_RRTYPE_A || rr->type == KNOT_RRTYPE_AAAA) {
const knot_rdata_t *rdata = rr->rrs.data;
const void *addr = knot_rdata_data(rdata);
const int addr_len = knot_rdata_rdlen(rdata);
char name_str[KR_DNAME_STR_MAXLEN];
char addr_str[INET6_ADDRSTRLEN];
WITH_VERBOSE(query) {
const int af = (addr_len == sizeof(struct in_addr)) ?
const int af = (rdata->len == sizeof(struct in_addr)) ?
AF_INET : AF_INET6;
knot_dname_to_str(name_str, rr->owner, sizeof(name_str));
name_str[sizeof(name_str) - 1] = 0;
inet_ntop(af, addr, addr_str, sizeof(addr_str));
inet_ntop(af, rdata->data, addr_str, sizeof(addr_str));
}
if (!(query->flags.ALLOW_LOCAL) &&
!is_valid_addr(addr, addr_len)) {
!is_valid_addr(rdata->data, rdata->len)) {
QVERBOSE_MSG(query, "<= ignoring invalid glue for "
"'%s': '%s'\n", name_str, addr_str);
return KR_STATE_CONSUME; /* Ignore invalid addresses */
......
......@@ -184,8 +184,6 @@ typedef array_t(ranked_rr_array_entry_t *) ranked_rr_array_t;
/** @internal RDATA array maximum size. */
#define RDATA_ARR_MAX (UINT16_MAX + sizeof(uint64_t))
/** @internal Next RDATA shortcut. */
#define kr_rdataset_next(rd) (rd + knot_rdata_array_size(knot_rdata_rdlen(rd)))
/** Concatenate N strings. */
KR_EXPORT
......
......@@ -184,17 +184,15 @@ int kr_zonecut_add(struct kr_zonecut *cut, const knot_dname_t *ns, const knot_rd
return kr_ok();
}
/* Check for duplicates */
uint16_t rdlen = knot_rdata_rdlen(rdata);
uint8_t *raw_addr = knot_rdata_data(rdata);
if (pack_obj_find(*pack, raw_addr, rdlen)) {
if (pack_obj_find(*pack, rdata->data, rdata->len)) {
return kr_ok();
}
/* Push new address */
int ret = pack_reserve_mm(**pack, 1, rdlen, kr_memreserve, cut->pool);
int ret = pack_reserve_mm(**pack, 1, rdata->len, kr_memreserve, cut->pool);
if (ret != 0) {
return kr_error(ENOMEM);
}
return pack_obj_push(*pack, raw_addr, rdlen);
return pack_obj_push(*pack, rdata->data, rdata->len);
}
int kr_zonecut_del(struct kr_zonecut *cut, const knot_dname_t *ns, const knot_rdata_t *rdata)
......@@ -211,7 +209,7 @@ int kr_zonecut_del(struct kr_zonecut *cut, const knot_dname_t *ns, const knot_rd
}
/* Remove address from the pack. */
if (rdata) {
ret = pack_obj_del(pack, knot_rdata_data(rdata), knot_rdata_rdlen(rdata));
ret = pack_obj_del(pack, rdata->data, rdata->len);
}
/* No servers left, remove NS from the set. */
if (pack->len == 0) {
......@@ -306,7 +304,7 @@ static void fetch_addr(struct kr_zonecut *cut, struct kr_cache *cache,
knot_rdata_t *rd = cached_rr.rrs.data;
for (uint16_t i = 0; i < cached_rr.rrs.rr_count; ++i) {
(void) kr_zonecut_add(cut, ns, rd);
rd = kr_rdataset_next(rd);
rd = knot_rdataset_next(rd);
}
}
......
-- Module interface
local ffi = require('ffi')
local knot = ffi.load(libknot_SONAME)
local priming = {}
priming.retry_time = 10 * sec -- retry time when priming fail
......@@ -51,9 +50,7 @@ local function address_callback(pkt, req)
local rr = section[i]
if rr.type == kres.type.A or rr.type == kres.type.AAAA then
for k = 0, rr.rrs.rr_count-1 do
local rdata = knot.knot_rdataset_at(rr.rrs, k)
rdata = ffi.string(rdata, knot.knot_rdata_array_size(knot.knot_rdata_rdlen(rdata)))
table.insert(internal.nsset[rr:owner()], rdata)
table.insert(internal.nsset[rr:owner()], rr.rrs:rdata(k))
end
end
end
......
......@@ -99,6 +99,7 @@ static inline void test_random_rr(knot_rrset_t *rr, uint32_t ttl)
{
static uint8_t owner_buf[KNOT_DNAME_MAXLEN];
static uint8_t rdata_buf[65535];
knot_rdata_t *rdata = (knot_rdata_t *)rdata_buf;
uint16_t num = rand() % (sizeof(owner_buf) - 2);
uint8_t tmp_buf[KNOT_DNAME_MAXLEN];
......@@ -112,11 +113,11 @@ static inline void test_random_rr(knot_rrset_t *rr, uint32_t ttl)
/* Create payload */
tmp_buf[0] = num;
test_randstr((char *)(tmp_buf + 1), tmp_buf[0] + 1);
knot_rdata_init(rdata_buf, num + 1, tmp_buf);
knot_rdata_init(rdata, num + 1, tmp_buf);
/* Assign static buffers. */
knot_rrset_init(rr, owner_buf, KNOT_RRTYPE_TXT, KNOT_CLASS_IN, ttl);
rr->rrs.rr_count = 1;
rr->rrs.data = rdata_buf;
rr->rrs.data = rdata;
}
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