Commit 8ebd8667 authored by Daniel Salzman's avatar Daniel Salzman

Adapt to new rrtype and rdataset API

parent 5060f153
......@@ -182,7 +182,7 @@ static int zone_status(zone_t *zone, ctl_args_t *args)
if (zone->contents != NULL) {
knot_rdataset_t *soa = node_rdataset(zone->contents->apex,
KNOT_RRTYPE_SOA);
ret = snprintf(buff, sizeof(buff), "%u", knot_soa_serial(soa));
ret = snprintf(buff, sizeof(buff), "%u", knot_soa_serial(soa->rdata));
} else {
ret = snprintf(buff, sizeof(buff), "none");
}
......
......@@ -100,7 +100,7 @@ static int ds_query_consume(knot_layer_t *layer, knot_pkt_t *pkt)
return KNOT_STATE_FAIL;
}
if (match_key_ds(data->key, knot_rdataset_at(&rr->rrs, 0))) {
if (match_key_ds(data->key, rr->rrs.rdata)) {
match = true;
break;
}
......
......@@ -370,14 +370,13 @@ static zone_node_t *create_nsec3_node_for_node(const zone_node_t *node,
static int connect_nsec3_base(knot_rdataset_t *a_rrs, const knot_dname_t *b_name)
{
assert(a_rrs);
uint8_t algorithm = knot_nsec3_algorithm(a_rrs, 0);
uint8_t algorithm = knot_nsec3_alg(a_rrs->rdata);
if (algorithm == 0) {
return KNOT_EINVAL;
}
uint8_t *raw_hash = NULL;
uint8_t raw_length = 0;
knot_nsec3_next_hashed(a_rrs, 0, &raw_hash, &raw_length);
uint8_t raw_length = knot_nsec3_next_len(a_rrs->rdata);
uint8_t *raw_hash = (uint8_t *)knot_nsec3_next(a_rrs->rdata);
if (raw_hash == NULL) {
return KNOT_EINVAL;
}
......@@ -606,7 +605,8 @@ static int fix_nsec3_for_node(zone_update_t *update, const dnssec_nsec3_params_t
ret = changeset_add_removal(chgset, &rem_rrsig, 0);
}
}
knot_nsec3_next_hashed(&rem_nsec3.rrs, 0, &next_hash, &next_length);
next_hash = (uint8_t *)knot_nsec3_next(rem_nsec3.rrs.rdata);
next_length = knot_nsec3_next_len(rem_nsec3.rrs.rdata);
}
}
......@@ -621,9 +621,8 @@ static int fix_nsec3_for_node(zone_update_t *update, const dnssec_nsec3_params_t
// copy hash of next element from removed record
if (next_hash != NULL) {
uint8_t *raw_hash = NULL;
uint8_t raw_length = 0;
knot_nsec3_next_hashed(&add_nsec3.rrs, 0, &raw_hash, &raw_length);
uint8_t *raw_hash = (uint8_t *)knot_nsec3_next(add_nsec3.rrs.rdata);
uint8_t raw_length = knot_nsec3_next_len(add_nsec3.rrs.rdata);
assert(raw_hash != NULL);
if (raw_length != next_length) {
ret = KNOT_EMALF;
......
/* Copyright (C) 2017 CZ.NIC, z.s.p.o. <knot-dns@labs.nic.cz>
/* Copyright (C) 2018 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
......@@ -22,7 +22,7 @@
static uint32_t zone_soa_min_ttl(const zone_contents_t *zone)
{
knot_rrset_t soa = node_rrset(zone->apex, KNOT_RRTYPE_SOA);
return knot_soa_minimum(&soa.rrs);
return knot_soa_minimum(soa.rrs.rdata);
}
static uint32_t zone_soa_ttl(const zone_contents_t *zone)
......
......@@ -285,15 +285,16 @@ int knot_synth_rrsig(uint16_t type, const knot_rdataset_t *rrsig_rrs,
return KNOT_EINVAL;
}
knot_rdata_t *rr_to_copy = rrsig_rrs->rdata;
for (int i = 0; i < rrsig_rrs->count; ++i) {
if (type == knot_rrsig_type_covered(rrsig_rrs, i)) {
const knot_rdata_t *rr_to_copy = knot_rdataset_at(rrsig_rrs, i);
if (type == knot_rrsig_type_covered(rr_to_copy)) {
int ret = knot_rdataset_add(out_sig, rr_to_copy, mm);
if (ret != KNOT_EOK) {
knot_rdataset_clear(out_sig, mm);
return ret;
}
}
rr_to_copy = knot_rdataset_next(rr_to_copy);
}
return out_sig->count > 0 ? KNOT_EOK : KNOT_ENOENT;
......@@ -304,19 +305,17 @@ int knot_synth_rrsig(uint16_t type, const knot_rdataset_t *rrsig_rrs,
/*!
* \brief Check if the signature is expired.
*
* \param rrsigs RR set with RRSIGs.
* \param pos Number of RR in the RR set.
* \param rrsig RRSIG rdata.
* \param policy DNSSEC policy.
*
* \return Signature is expired or should be replaced soon.
*/
static bool is_expired_signature(const knot_rrset_t *rrsigs, size_t pos,
uint32_t now, uint32_t refresh_before)
static bool is_expired_signature(const knot_rdata_t *rrsig, uint32_t now,
uint32_t refresh_before)
{
assert(!knot_rrset_empty(rrsigs));
assert(rrsigs->type == KNOT_RRTYPE_RRSIG);
assert(rrsig);
uint32_t expire_at = knot_rrsig_sig_expiration(&rrsigs->rrs, pos);
uint32_t expire_at = knot_rrsig_sig_expiration(rrsig);
uint32_t expire_in = expire_at > now ? expire_at - now : 0;
return expire_in <= refresh_before;
......@@ -333,21 +332,21 @@ int knot_check_signature(const knot_rrset_t *covered,
return KNOT_EINVAL;
}
if (is_expired_signature(rrsigs, pos, dnssec_ctx->now,
knot_rdata_t *rrsig = knot_rdataset_at(&rrsigs->rrs, pos);
assert(rrsig);
if (is_expired_signature(rrsig, dnssec_ctx->now,
dnssec_ctx->policy->rrsig_refresh_before)) {
return DNSSEC_INVALID_SIGNATURE;
}
// identify fields in the signature being validated
uint8_t *rdata = knot_rdataset_at(&rrsigs->rrs, pos)->data;
if (!rdata) {
return KNOT_EINVAL;
}
dnssec_binary_t signature = { 0 };
knot_rrsig_signature(&rrsigs->rrs, pos, &signature.data, &signature.size);
if (!signature.data) {
dnssec_binary_t signature = {
.size = knot_rrsig_signature_len(rrsig),
.data = (uint8_t *)knot_rrsig_signature(rrsig)
};
if (signature.data == NULL) {
return KNOT_EINVAL;
}
......@@ -358,7 +357,7 @@ int knot_check_signature(const knot_rrset_t *covered,
return result;
}
result = knot_sign_ctx_add_data(sign_ctx, rdata, covered);
result = knot_sign_ctx_add_data(sign_ctx, rrsig->data, covered);
if (result != KNOT_EOK) {
return result;
}
......
......@@ -269,8 +269,8 @@ int knot_dnssec_sign_update(zone_update_t *update, zone_sign_reschedule_t *resch
goto done;
}
bool soa_changed = (knot_soa_serial(node_rdataset(update->zone->contents->apex, KNOT_RRTYPE_SOA)) !=
knot_soa_serial(node_rdataset(update->new_cont->apex, KNOT_RRTYPE_SOA)));
bool soa_changed = (knot_soa_serial(node_rdataset(update->zone->contents->apex, KNOT_RRTYPE_SOA)->rdata) !=
knot_soa_serial(node_rdataset(update->new_cont->apex, KNOT_RRTYPE_SOA)->rdata));
if (zone_update_no_change(update) && !soa_changed &&
!knot_zone_sign_soa_expired(update->new_cont, &keyset, &ctx)) {
......
......@@ -178,10 +178,9 @@ static bool nsec3param_valid(const knot_rdataset_t *rrs,
return false;
}
knot_rdata_t *rrd = knot_rdataset_at(rrs, 0);
dnssec_binary_t rdata = {
.size = rrd->len,
.data = rrd->data,
.size = rrs->rdata->len,
.data = rrs->rdata->data,
};
dnssec_nsec3_params_t parsed = { 0 };
......@@ -342,7 +341,7 @@ int knot_zone_create_nsec_chain(zone_update_t *update,
return KNOT_EINVAL;
}
uint32_t nsec_ttl = knot_soa_minimum(soa);
uint32_t nsec_ttl = knot_soa_minimum(soa->rdata);
dnssec_nsec3_params_t params = nsec3param_init(ctx->policy, ctx->zone);
changeset_t ch;
......@@ -409,8 +408,8 @@ int knot_zone_fix_nsec_chain(zone_update_t *update,
return KNOT_EINVAL;
}
uint32_t nsec_ttl_old = knot_soa_minimum(soa_old);
uint32_t nsec_ttl_new = knot_soa_minimum(soa_new);
uint32_t nsec_ttl_old = knot_soa_minimum(soa_old->rdata);
uint32_t nsec_ttl_new = knot_soa_minimum(soa_new->rdata);
dnssec_nsec3_params_t params = nsec3param_init(ctx->policy, ctx->zone);
changeset_t ch;
......
......@@ -111,9 +111,11 @@ static bool valid_signature_exists(const knot_rrset_t *covered,
}
uint16_t rrsigs_rdata_count = rrsigs->rrs.count;
knot_rdata_t *rdata = rrsigs->rrs.rdata;
for (uint16_t i = 0; i < rrsigs_rdata_count; i++) {
uint16_t rr_keytag = knot_rrsig_key_tag(&rrsigs->rrs, i);
uint16_t rr_covered = knot_rrsig_type_covered(&rrsigs->rrs, i);
uint16_t rr_keytag = knot_rrsig_key_tag(rdata);
uint16_t rr_covered = knot_rrsig_type_covered(rdata);
rdata = knot_rdataset_next(rdata);
uint16_t keytag = dnssec_key_get_keytag(key);
if (rr_keytag != keytag || rr_covered != covered->type) {
......@@ -200,40 +202,18 @@ static bool all_signatures_exist(const knot_rrset_t *covered,
return true;
}
/*!
* \brief Get zone key for given RRSIG (checks key tag only).
*
* \param rrsigs RR set with RRSIGs.
* \param pos Number of RR in RR set.
* \param keys Zone keys.
*
* \return Dynarray of such keys.
*/
static keyptr_dynarray_t get_matching_zone_keys(const knot_rrset_t *rrsigs,
size_t pos, const zone_keyset_t *keys)
{
assert(rrsigs && rrsigs->type == KNOT_RRTYPE_RRSIG);
assert(keys);
uint16_t keytag = knot_rrsig_key_tag(&rrsigs->rrs, pos);
return get_zone_keys(keys, keytag);
}
/*!
* \brief Note earliest expiration of a signature.
*
* \param rrsigs RR set with RRSIGs.
* \param pos Position of RR in rrsigs.
* \param rrsig RRSIG rdata.
* \param expires_at Current earliest expiration, will be updated.
*/
static void note_earliest_expiration(const knot_rrset_t *rrsigs, size_t pos,
knot_time_t *expires_at)
static void note_earliest_expiration(const knot_rdata_t *rrsig, knot_time_t *expires_at)
{
assert(rrsigs);
assert(rrsig);
assert(expires_at);
uint32_t curr_rdata = knot_rrsig_sig_expiration(&rrsigs->rrs, pos);
uint32_t curr_rdata = knot_rrsig_sig_expiration(rrsig);
knot_time_t current = knot_time_from_u32(curr_rdata);
*expires_at = knot_time_min(current, *expires_at);
}
......@@ -280,7 +260,10 @@ static int remove_expired_rrsigs(const knot_rrset_t *covered,
uint16_t rrsig_rdata_count = synth_rrsig.rrs.count;
for (uint16_t i = 0; i < rrsig_rdata_count; i++) {
struct keyptr_dynarray keys = get_matching_zone_keys(&synth_rrsig, i, zone_keys);
knot_rdata_t *rr = knot_rdataset_at(&synth_rrsig.rrs, i);
uint16_t keytag = knot_rrsig_key_tag(rr);
struct keyptr_dynarray keys = get_zone_keys(zone_keys, keytag);
int endloop = 0; // 1 - continue; 2 - break
dynarray_foreach(keyptr, zone_key_t *, key, keys) {
......@@ -291,7 +274,7 @@ static int remove_expired_rrsigs(const knot_rrset_t *covered,
(*key)->key, (*key)->ctx, dnssec_ctx);
if (result == KNOT_EOK) {
// valid signature
note_earliest_expiration(&synth_rrsig, i, expires_at);
note_earliest_expiration(rr, expires_at);
endloop = 1;
break;
} else if (result != DNSSEC_INVALID_SIGNATURE) {
......@@ -311,8 +294,7 @@ static int remove_expired_rrsigs(const knot_rrset_t *covered,
to_remove = create_empty_rrsigs_for(&synth_rrsig);
}
knot_rdata_t *rr_rem = knot_rdataset_at(&synth_rrsig.rrs, i);
result = knot_rdataset_add(&to_remove.rrs, rr_rem, NULL);
result = knot_rdataset_add(&to_remove.rrs, rr, NULL);
if (result != KNOT_EOK) {
break;
}
......@@ -482,14 +464,14 @@ static int remove_standalone_rrsigs(const zone_node_t *node,
}
uint16_t rrsigs_rdata_count = rrsigs->rrs.count;
knot_rdata_t *rdata = rrsigs->rrs.rdata;
for (uint16_t i = 0; i < rrsigs_rdata_count; ++i) {
uint16_t type_covered = knot_rrsig_type_covered(&rrsigs->rrs, i);
uint16_t type_covered = knot_rrsig_type_covered(rdata);
if (!node_rrtype_exists(node, type_covered)) {
knot_rrset_t to_remove;
knot_rrset_init(&to_remove, rrsigs->owner, rrsigs->type,
rrsigs->rclass, rrsigs->ttl);
knot_rdata_t *rr_rem = knot_rdataset_at(&rrsigs->rrs, i);
int ret = knot_rdataset_add(&to_remove.rrs, rr_rem, NULL);
int ret = knot_rdataset_add(&to_remove.rrs, rdata, NULL);
if (ret != KNOT_EOK) {
return ret;
}
......@@ -499,6 +481,7 @@ static int remove_standalone_rrsigs(const zone_node_t *node,
return ret;
}
}
rdata = knot_rdataset_next(rdata);
}
return KNOT_EOK;
......
......@@ -239,7 +239,7 @@ int event_load(conf_t *conf, zone_t *zone)
// Schedule depedent events.
const knot_rdataset_t *soa = zone_soa(zone);
zone->timers.soa_expire = knot_soa_expire(soa);
zone->timers.soa_expire = knot_soa_expire(soa->rdata);
if (dnssec_enable) {
event_dnssec_reschedule(conf, zone, &dnssec_refresh, false); // false since we handle NOTIFY below
......
/* Copyright (C) 2016 CZ.NIC, z.s.p.o. <knot-dns@labs.nic.cz>
/* Copyright (C) 2018 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
......@@ -109,7 +109,7 @@ static int send_notify(conf_t *conf, zone_t *zone, const knot_rrset_t *soa,
if (ret == KNOT_EOK) {
NOTIFY_LOG(LOG_INFO, zone->name, dst,
"serial %u", knot_soa_serial(&soa->rrs));
"serial %u", knot_soa_serial(soa->rrs.rdata));
} else if (knot_pkt_ext_rcode(req->resp) == 0) {
NOTIFY_LOG(LOG_WARNING, zone->name, dst,
"failed (%s)", knot_strerror(ret));
......
......@@ -420,15 +420,15 @@ static int ixfr_finalize(struct refresh_data *data)
uint32_t old_serial = local_serial;
changeset_t *chs = NULL;
WALK_LIST(chs, data->ixfr.changesets) {
master_serial = knot_soa_serial(&chs->soa_to->rrs);
knot_soa_serial_set(&chs->soa_from->rrs, local_serial);
master_serial = knot_soa_serial(chs->soa_to->rrs.rdata);
knot_soa_serial_set(chs->soa_from->rrs.rdata, local_serial);
if (have_lastsigned && (serial_compare(lastsigned_serial, local_serial) & SERIAL_MASK_GEQ)) {
local_serial = lastsigned_serial;
}
if (serial_compare(master_serial, local_serial) != SERIAL_GREATER) {
conf_val_t val = conf_zone_get(data->conf, C_SERIAL_POLICY, data->zone->name);
local_serial = serial_next(local_serial, conf_opt(&val));
knot_soa_serial_set(&chs->soa_to->rrs, local_serial);
knot_soa_serial_set(chs->soa_to->rrs.rdata, local_serial);
} else {
local_serial = master_serial;
}
......@@ -698,7 +698,7 @@ static enum xfr_type determine_xfr_type(const knot_pktsection_t *answer,
if (answer->count == 1) {
if (rr_one->type == KNOT_RRTYPE_SOA) {
return serial_is_current(zone_serial, knot_soa_serial(&rr_one->rrs)) ?
return serial_is_current(zone_serial, knot_soa_serial(rr_one->rrs.rdata)) ?
XFR_TYPE_UPTODATE : XFR_TYPE_UNDETERMINED;
}
return XFR_TYPE_ERROR;
......@@ -731,7 +731,7 @@ static int ixfr_consume(knot_pkt_t *pkt, struct refresh_data *data)
if (data->ixfr.proc == NULL) {
const knot_pktsection_t *answer = knot_pkt_section(pkt, KNOT_ANSWER);
uint32_t master_serial = knot_soa_serial(&data->soa->rrs);
uint32_t master_serial = knot_soa_serial(data->soa->rrs.rdata);
(void)zone_get_master_serial(data->zone, &master_serial);
data->xfr_type = determine_xfr_type(answer, master_serial,
data->initial_soa_copy);
......@@ -838,9 +838,9 @@ static int soa_query_consume(knot_layer_t *layer, knot_pkt_t *pkt)
return KNOT_STATE_FAIL;
}
uint32_t local_serial = knot_soa_serial(&data->soa->rrs);
uint32_t local_serial = knot_soa_serial(data->soa->rrs.rdata);
(void)zone_get_master_serial(data->zone, &local_serial);
uint32_t remote_serial = knot_soa_serial(&rr->rrs);
uint32_t remote_serial = knot_soa_serial(rr->rrs.rdata);
bool current = serial_is_current(local_serial, remote_serial);
bool master_uptodate = serial_is_current(remote_serial, local_serial);
......@@ -876,7 +876,7 @@ static int transfer_produce(knot_layer_t *layer, knot_pkt_t *pkt)
knot_rrset_free(sending_soa, data->mm);
return KNOT_STATE_FAIL;
}
knot_soa_serial_set(&sending_soa->rrs, master_serial);
knot_soa_serial_set(sending_soa->rrs.rdata, master_serial);
knot_pkt_begin(pkt, KNOT_AUTHORITY);
knot_pkt_put(pkt, KNOT_COMPR_HINT_QNAME, sending_soa, 0);
knot_rrset_free(sending_soa, data->mm);
......@@ -1114,13 +1114,13 @@ int event_refresh(conf_t *conf, zone_t *zone)
const knot_rdataset_t *soa = zone_soa(zone);
if (ret == KNOT_EOK) {
zone->timers.soa_expire = knot_soa_expire(soa);
zone->timers.soa_expire = knot_soa_expire(soa->rdata);
zone->timers.last_refresh = now;
zone->timers.next_refresh = now + knot_soa_refresh(soa);
zone->timers.next_refresh = now + knot_soa_refresh(soa->rdata);
} else {
time_t next = 0;
if (soa) {
next = knot_soa_retry(soa);
next = knot_soa_retry(soa->rdata);
} else {
next = bootstrap_next(&zone->timers);
}
......
......@@ -1003,7 +1003,7 @@ int journal_load_bootstrap(journal_t *j, list_t *dst)
goto jlb_end;
}
add_tail(dst, &bch->n);
uint32_t from = knot_soa_serial(&bch->soa_to->rrs);
uint32_t from = knot_soa_serial(bch->soa_to->rrs.rdata);
uint32_t ls = txn->shadow_md.last_serial;
iterate(j, txn, load_list_itercb, JOURNAL_ITERATION_CHANGESETS, &dst,
......@@ -1286,7 +1286,7 @@ static int merge_unflushed_changesets(journal_t *j, txn_t *_txn, changeset_t **m
txn->ret = load_one(j, txn, from, mch);
if (!was_merged && was_flushed && txn->ret == KNOT_EOK) {
// we have to jump to ONE AFTER last_flushed
from = knot_soa_serial(&(*mch)->soa_to->rrs);
from = knot_soa_serial((*mch)->soa_to->rrs.rdata);
changeset_free(*mch);
*mch = NULL;
txn->ret = load_one(j, txn, from, mch);
......@@ -1295,7 +1295,7 @@ static int merge_unflushed_changesets(journal_t *j, txn_t *_txn, changeset_t **m
if (txn->ret != KNOT_EOK) {
goto m_u_ch_end;
}
from = knot_soa_serial(&(*mch)->soa_to->rrs);
from = knot_soa_serial((*mch)->soa_to->rrs.rdata);
if (!serial_equal(from, txn->shadow_md.last_serial_to)) {
txn->ret = iterate(j, txn, merge_itercb, JOURNAL_ITERATION_CHANGESETS,
......@@ -1437,7 +1437,7 @@ static int store_changesets(journal_t *j, list_t *changesets)
// PART 4: continuity and duplicity check
changeset_t * chs_head = (HEAD(*changesets));
bool is_first_bootstrap = (chs_head->soa_from == NULL);
uint32_t serial = is_first_bootstrap ? 0 : knot_soa_serial(&chs_head->soa_from->rrs);
uint32_t serial = is_first_bootstrap ? 0 : knot_soa_serial(chs_head->soa_from->rrs.rdata);
if (md_flag(txn, SERIAL_TO_VALID) && (is_first_bootstrap ||
!serial_equal(txn->shadow_md.last_serial_to, serial)) &&
!inserting_bootstrap /* if inserting bootstrap, drop_journal() was called, so no discontinuity */) {
......@@ -1455,7 +1455,7 @@ static int store_changesets(journal_t *j, list_t *changesets)
txn_restart(txn);
}
WALK_LIST(ch, *changesets) {
uint32_t serial_to = knot_soa_serial(&ch->soa_to->rrs);
uint32_t serial_to = knot_soa_serial(ch->soa_to->rrs.rdata);
bool is_this_bootstrap = (ch->soa_from == NULL);
bool is_this_merged = (inserting_merged && ch == TAIL(*changesets));
if (is_this_bootstrap || is_this_merged) {
......@@ -1497,8 +1497,8 @@ static int store_changesets(journal_t *j, list_t *changesets)
bool is_this_merged = (inserting_merged && ch == TAIL(*changesets));
bool is_this_bootstrap = (ch->soa_from == NULL);
uint32_t serial = is_this_bootstrap ? 0 : knot_soa_serial(&ch->soa_from->rrs);
uint32_t serial_to = knot_soa_serial(&ch->soa_to->rrs);
uint32_t serial = is_this_bootstrap ? 0 : knot_soa_serial(ch->soa_from->rrs.rdata);
uint32_t serial_to = knot_soa_serial(ch->soa_to->rrs.rdata);
while (serialize_unfinished(sctx)) {
size_t chunk_size;
......@@ -2088,7 +2088,7 @@ int journal_check(journal_t *j, journal_check_level_t warn_level)
ret = load_bootstrap_changeset(j, txn, &ch);
switch (ret) {
case KNOT_EOK:
sto = knot_soa_serial(&ch->soa_to->rrs);
sto = knot_soa_serial(ch->soa_to->rrs.rdata);
jch_info("bootstrap changeset loaded, sto %u", sto);
changeset_free(ch);
break;
......@@ -2108,7 +2108,7 @@ int journal_check(journal_t *j, journal_check_level_t warn_level)
goto check_merged;
}
sfrom = knot_soa_serial(&ch->soa_from->rrs), sto = knot_soa_serial(&ch->soa_to->rrs);
sfrom = knot_soa_serial(ch->soa_from->rrs.rdata), sto = knot_soa_serial(ch->soa_to->rrs.rdata);
if (!serial_equal(txn->shadow_md.first_serial, sfrom)) {
jch_warn("first changeset's serial 'from' %u is not ok", sfrom);
}
......@@ -2120,7 +2120,7 @@ int journal_check(journal_t *j, journal_check_level_t warn_level)
jch_warn("can't read last flushed changeset %u (%s)",
txn->shadow_md.last_flushed, knot_strerror(ret));
} else {
first_unflushed = knot_soa_serial(&ch->soa_to->rrs);
first_unflushed = knot_soa_serial(ch->soa_to->rrs.rdata);
}
}
if (ret == KNOT_EOK) {
......@@ -2135,7 +2135,7 @@ int journal_check(journal_t *j, journal_check_level_t warn_level)
if (ret != KNOT_EOK) {
jch_warn("can't read second changeset %u (%s)", sto, knot_strerror(ret));
} else {
sfrom = knot_soa_serial(&ch->soa_from->rrs);
sfrom = knot_soa_serial(ch->soa_from->rrs.rdata);
if (!serial_equal(sfrom, sto)) {
jch_warn("second changeset's serial 'from' %u is not ok", sfrom);
}
......@@ -2160,14 +2160,14 @@ int journal_check(journal_t *j, journal_check_level_t warn_level)
}
ch = HEAD(l);
if (!serial_equal(sfrom, knot_soa_serial(&ch->soa_from->rrs))) {
if (!serial_equal(sfrom, knot_soa_serial(ch->soa_from->rrs.rdata))) {
jch_warn("first listed changeset's serial 'from' %u is not ok",
knot_soa_serial(&ch->soa_from->rrs));
knot_soa_serial(ch->soa_from->rrs.rdata));
}
ch = TAIL(l);
if (!serial_equal(sto, knot_soa_serial(&ch->soa_to->rrs))) {
if (!serial_equal(sto, knot_soa_serial(ch->soa_to->rrs.rdata))) {
jch_warn("last listed changeset's serial 'to' %u is not ok",
knot_soa_serial(&ch->soa_to->rrs));
knot_soa_serial(ch->soa_to->rrs.rdata));
}
changesets_free(&l);
......@@ -2181,8 +2181,8 @@ check_merged:
if (ret != KNOT_EOK) {
jch_warn("can't read merged changeset (%s)", knot_strerror(ret));
} else {
sfrom = knot_soa_serial(&ch->soa_from->rrs);
sto = knot_soa_serial(&ch->soa_to->rrs);
sfrom = knot_soa_serial(ch->soa_from->rrs.rdata);
sto = knot_soa_serial(ch->soa_to->rrs.rdata);
jch_info("merged changeset %u -> %u (size %zu)", sfrom, sto,
changeset_serialized_size(ch));
if (!serial_equal(sfrom, txn->shadow_md.merged_serial)) {
......
......@@ -272,12 +272,11 @@ static uint64_t rrset_binary_size(const knot_rrset_t *rrset)
uint64_t size = knot_dname_size(rrset->owner) + 3 * sizeof(uint16_t);
// RRs.
knot_rdata_t *rr = rrset->rrs.rdata;
for (uint16_t i = 0; i < rrset->rrs.count; i++) {
const knot_rdata_t *rr = knot_rdataset_at(&rrset->rrs, i);
assert(rr);
// TTL + RR size + RR.
size += sizeof(uint32_t) + sizeof(uint16_t) + rr->len;
rr = knot_rdataset_next(rr);
}
return size;
......
......@@ -93,7 +93,7 @@ static uint32_t dnskey_ttl(knotd_qdata_t *qdata)
static uint32_t nsec_ttl(knotd_qdata_t *qdata)
{
knot_rrset_t soa = knotd_qdata_zone_apex_rrset(qdata, KNOT_RRTYPE_SOA);
return knot_soa_minimum(&soa.rrs);
return knot_soa_minimum(soa.rrs.rdata);
}
/*!
......
/* Copyright (C) 2017 CZ.NIC, z.s.p.o. <knot-dns@labs.nic.cz>
/* Copyright (C) 2018 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
......@@ -59,7 +59,7 @@ static const knot_dname_t *name_from_rrsig(const knot_rrset_t *rr)
}
// This is a signature.
return knot_rrsig_signer_name(&rr->rrs, 0);
return knot_rrsig_signer_name(rr->rrs.rdata);
}
static const knot_dname_t *name_from_authrr(const knot_rrset_t *rr)
......
......@@ -355,7 +355,7 @@ static void incr_edns_option(knotd_mod_t *mod, const knot_pkt_t *pkt, unsigned c
return;
}
knot_rdata_t *rdata = knot_rdataset_at(&pkt->opt_rr->rrs, 0);
knot_rdata_t *rdata = pkt->opt_rr->rrs.rdata;
if (rdata == NULL || rdata->len == 0) {
return;
}
......
......@@ -72,7 +72,7 @@ static int dname_cname_synth(const knot_rrset_t *dname_rr,
/* Replace last labels of qname with DNAME. */
const knot_dname_t *dname_wire = dname_rr->owner;
const knot_dname_t *dname_tgt = knot_dname_target(&dname_rr->rrs);
const knot_dname_t *dname_tgt = knot_dname_target(dname_rr->rrs.rdata);
size_t labels = knot_dname_labels(dname_wire, NULL);
knot_dname_t *cname = knot_dname_replace_suffix(qname, labels, dname_tgt, mm);
if (cname == NULL) {
......@@ -102,10 +102,10 @@ static int dname_cname_synth(const knot_rrset_t *dname_rr,
static bool dname_cname_cannot_synth(const knot_rrset_t *rrset, const knot_dname_t *qname)
{
if (knot_dname_labels(qname, NULL) - knot_dname_labels(rrset->owner, NULL) +
knot_dname_labels(knot_dname_target(&rrset->rrs), NULL) > KNOT_DNAME_MAXLABELS) {
knot_dname_labels(knot_dname_target(rrset->rrs.rdata), NULL) > KNOT_DNAME_MAXLABELS) {
return true;
} else if (knot_dname_size(qname) - knot_dname_size(rrset->owner) +
knot_dname_size(knot_dname_target(&rrset->rrs)) > KNOT_DNAME_MAXLEN) {
knot_dname_size(knot_dname_target(rrset->rrs.rdata)) > KNOT_DNAME_MAXLEN) {
return true;
} else {
return false;
......@@ -309,7 +309,7 @@ static int follow_cname(knot_pkt_t *pkt, uint16_t rrtype, knotd_qdata_t *qdata)
}
/* Now follow the next CNAME TARGET. */
qdata->name = knot_cname_name(&cname_rr.rrs);
qdata->name = knot_cname_name(cname_rr.rrs.rdata);
return KNOTD_IN_STATE_FOLLOW;
}
......
......@@ -102,7 +102,7 @@ static int ixfr_load_chsets(chgset_ctx_list_t *chgsets, zone_t *zone,
/* Compare serials. */
uint32_t serial_to = zone_contents_serial(zone->contents);
uint32_t serial_from = knot_soa_serial(&their_soa->rrs);
uint32_t serial_from = knot_soa_serial(their_soa->rrs.rdata);
if (serial_compare(serial_to, serial_from) & SERIAL_MASK_LEQ) { /* We have older/same age zone. */
return KNOT_EUPTODATE;
}
......
......@@ -70,7 +70,7 @@ int notify_process_query(knot_pkt_t *pkt, knotd_qdata_t *qdata)
if (answer->count > 0) {
const knot_rrset_t *soa = knot_pkt_rr(answer, 0);
if (soa->type == KNOT_RRTYPE_SOA) {
uint32_t serial = knot_soa_serial(&soa->rrs);
uint32_t serial = knot_soa_serial(soa->rrs.rdata);
uint32_t zone_serial = zone_contents_serial(zone->contents);
(void)zone_get_master_serial(zone, &zone_serial);
NOTIFY_LOG(LOG_INFO, qdata, "received, serial %u", serial);
......
......@@ -114,24 +114,25 @@ static int add_new_data(apply_ctx_t *ctx, knot_rdata_t *new_data)
}
/*! \brief Returns true if given RR is present in node and can be removed. */
static bool can_remove(const zone_node_t *node, const knot_rrset_t *rr)
static bool can_remove(const zone_node_t *node, const knot_rrset_t *rrset)
{
if (node == NULL) {
// Node does not exist, cannot remove anything.
return false;
}
const knot_rdataset_t *node_rrs = node_rdataset(node, rr->type);
const knot_rdataset_t *node_rrs = node_rdataset(node, rrset->type);
if (node_rrs == NULL) {
// Node does not have this type at all.
return false;
}
for (uint16_t i = 0; i < rr->rrs.count; ++i) {
knot_rdata_t *rr_cmp = knot_rdataset_at(&rr->rrs, i);
knot_rdata_t *rr_cmp = rrset->rrs.rdata;
for (uint16_t i = 0; i < rrset->rrs.count; ++i) {
if (knot_rdataset_member(node_rrs, rr_cmp)) {
// At least one RR matches.
return true;
}
rr_cmp = knot_rdataset_next(rr_cmp);
}
// Node does have the type, but no RRs match.
......@@ -194,7 +195,7 @@ static int apply_single(apply_ctx_t *ctx, const changeset_t *chset)
// check if serial matches
const knot_rdataset_t *soa = node_rdataset(contents->apex, KNOT_RRTYPE_SOA);
if (soa == NULL || (!ignore_soa && knot_soa_serial(soa) != knot_soa_serial(&chset->soa_from->rrs))) {
if (soa == NULL || (!ignore_soa && knot_soa_serial(soa->rdata) != knot_soa_serial(chset->soa_from->rrs.rdata))) {
return KNOT_EINVAL;
}
......
......@@ -160,18 +160,17 @@ static int check_not_in_use(zone_update_t *update,
}
}
/*!< \brief Returns true if rrset has 0 data or RDATA of size 0 (we need TTL).*/
/*!< \brief Returns true if rrset has 0 data or RDATA of size 0 (we need TTL). */
static bool rrset_empty(const knot_rrset_t *rrset)
{
uint16_t rr_count = rrset->rrs.count;
if (rr_count == 0) {
switch (rrset->rrs.count) {
case 0:
return true;
case 1:
return rrset->rrs.rdata->len == 0;
default:
return false;
}
if (rr_count == 1) {