Commit bc90abc9 authored by Jan Kadlec's avatar Jan Kadlec

new_node: Code converted to new rrs API

- kept RRSet copies somewhere (node has to create them now)
- replaced knot_rrset_t with knot_rrs_t elsewhere
- semantic checks simplified
parent 110b4f46
......@@ -100,7 +100,7 @@ static int remote_rdata_apply(server_t *s, remote_cmdargs_t* a, remote_zonef_t *
uint16_t rr_count = knot_rrset_rr_count(rr);
for (uint16_t i = 0; i < rr_count; i++) {
const knot_dname_t *dn = knot_rdata_ns_name(rr, i);
const knot_dname_t *dn = knot_rrs_ns_name(&rr->rrs, i);
rcu_read_lock();
zone = knot_zonedb_find(s->zone_db, dn);
if (cb(s, zone) != KNOT_EOK) {
......@@ -235,13 +235,13 @@ static int remote_c_zonestatus(server_t *s, remote_cmdargs_t* a)
const zone_t *zone = knot_zonedb_iter_val(&it);
/* Fetch latest serial. */
const knot_rrset_t *soa_rrs = 0;
const knot_rrs_t *soa_rrs = NULL;
uint32_t serial = 0;
if (zone->contents) {
soa_rrs = knot_node_rrset(zone->contents->apex,
KNOT_RRTYPE_SOA);
soa_rrs = knot_node_rrs(zone->contents->apex,
KNOT_RRTYPE_SOA);
assert(soa_rrs != NULL);
serial = knot_rdata_soa_serial(soa_rrs);
serial = knot_rrs_soa_serial(soa_rrs);
}
/* Evalute zone type. */
......@@ -538,7 +538,7 @@ static void log_command(const char *cmd, const remote_cmdargs_t* args)
uint16_t rr_count = knot_rrset_rr_count(rr);
for (uint16_t j = 0; j < rr_count; j++) {
const knot_dname_t *dn = knot_rdata_ns_name(rr, j);
const knot_dname_t *dn = knot_rrs_ns_name(&rr->rrs, j);
char *name = knot_dname_to_str(dn);
int ret = snprintf(params, rest, " %s", name);
......
......@@ -372,16 +372,16 @@ static int connect_nsec3_nodes(knot_node_t *a, knot_node_t *b,
assert(a->rrset_count == 1);
knot_rrset_t *a_rrset = knot_node_get_rrset(a, KNOT_RRTYPE_NSEC3);
assert(a_rrset);
uint8_t algorithm = knot_rdata_nsec3_algorithm(a_rrset, 0);
knot_rrs_t *a_rrs = knot_node_get_rrs(a, KNOT_RRTYPE_NSEC3);
assert(a_rrs);
uint8_t algorithm = knot_rrs_nsec3_algorithm(a_rrs, 0);
if (algorithm == 0) {
return KNOT_EINVAL;
}
uint8_t *raw_hash = NULL;
uint8_t raw_length = 0;
knot_rdata_nsec3_next_hashed(a_rrset, 0, &raw_hash, &raw_length);
knot_rrs_nsec3_next_hashed(a_rrs, 0, &raw_hash, &raw_length);
if (raw_hash == NULL) {
return KNOT_EINVAL;
}
......
......@@ -94,12 +94,12 @@ static bool get_zone_soa_min_ttl(const knot_zone_contents_t *zone,
assert(ttl);
knot_node_t *apex = zone->apex;
knot_rrset_t *soa = knot_node_get_rrset(apex, KNOT_RRTYPE_SOA);
const knot_rrs_t *soa = knot_node_rrs(apex, KNOT_RRTYPE_SOA);
if (!soa) {
return false;
}
uint32_t result = knot_rdata_soa_minimum(soa);
uint32_t result = knot_rrs_soa_minimum(soa);
if (result == 0) {
return false;
}
......
......@@ -79,8 +79,8 @@ static bool valid_signature_exists(const knot_rrset_t *covered,
uint16_t rrsigs_rdata_count = knot_rrset_rr_count(rrsigs);
for (uint16_t i = 0; i < rrsigs_rdata_count; i++) {
uint16_t keytag = knot_rdata_rrsig_key_tag(rrsigs, i);
uint16_t type_covered = knot_rdata_rrsig_type_covered(rrsigs, i);
uint16_t keytag = knot_rrs_rrsig_key_tag(&rrsigs->rrs, i);
uint16_t type_covered = knot_rrs_rrsig_type_covered(&rrsigs->rrs, i);
if (keytag != key->keytag || type_covered != covered->type) {
continue;
}
......@@ -163,7 +163,7 @@ static const knot_zone_key_t *get_matching_zone_key(const knot_rrset_t *rrsigs,
assert(rrsigs && rrsigs->type == KNOT_RRTYPE_RRSIG);
assert(keys);
uint16_t keytag = knot_rdata_rrsig_key_tag(rrsigs, pos);
uint16_t keytag = knot_rrs_rrsig_key_tag(&rrsigs->rrs, pos);
return knot_get_zone_key(keys, keytag);
}
......@@ -181,7 +181,7 @@ static void note_earliest_expiration(const knot_rrset_t *rrsigs, size_t pos,
assert(rrsigs);
assert(expires_at);
const uint32_t current = knot_rdata_rrsig_sig_expiration(rrsigs, pos);
const uint32_t current = knot_rrs_rrsig_sig_expiration(&rrsigs->rrs, pos);
if (current < *expires_at) {
*expires_at = current;
}
......@@ -449,7 +449,7 @@ static int remove_standalone_rrsigs(const knot_node_t *node,
uint16_t rrsigs_rdata_count = knot_rrset_rr_count(rrsigs);
for (uint16_t i = 0; i < rrsigs_rdata_count; ++i) {
uint16_t type_covered = knot_rdata_rrsig_type_covered(rrsigs, i);
uint16_t type_covered = knot_rrs_rrsig_type_covered(&rrsigs->rrs, i);
if (!knot_node_rrset(node, type_covered)) {
knot_rrset_t *to_remove = knot_rrset_new_from(rrsigs, NULL);
if (to_remove == NULL) {
......@@ -1329,7 +1329,7 @@ int knot_zone_sign_update_soa(const knot_rrset_t *soa,
dbg_dnssec_verb("Updating SOA...\n");
uint32_t serial = knot_rdata_soa_serial(soa);
uint32_t serial = knot_rrs_soa_serial(&soa->rrs);
if (serial == UINT32_MAX && policy->soa_up == KNOT_SOA_SERIAL_UPDATE) {
// TODO: this is wrong, the value should be 'rewound' to 0 in this case
return KNOT_EINVAL;
......@@ -1370,7 +1370,7 @@ int knot_zone_sign_update_soa(const knot_rrset_t *soa,
return result;
}
knot_rdata_soa_serial_set(soa_to, new_serial);
knot_rrs_soa_serial_set(&soa_to->rrs, new_serial);
// add signatures for new SOA
......
......@@ -71,7 +71,7 @@ static knot_rrset_t *dname_cname_synth(const knot_rrset_t *dname_rr,
/* Replace last labels of qname with DNAME. */
const knot_dname_t *dname_wire = knot_rrset_owner(dname_rr);
const knot_dname_t *dname_tgt = knot_rdata_dname_target(dname_rr);
const knot_dname_t *dname_tgt = knot_rrs_dname_target(&dname_rr->rrs);
int labels = knot_dname_labels(dname_wire, NULL);
knot_dname_t *cname = knot_dname_replace_suffix(qname, labels, dname_tgt);
if (cname == NULL) {
......@@ -103,7 +103,7 @@ static bool dname_cname_cannot_synth(const knot_rrset_t *rrset, const knot_dname
{
if (knot_dname_labels(qname, NULL)
- knot_dname_labels(knot_rrset_owner(rrset), NULL)
+ knot_dname_labels(knot_rdata_dname_target(rrset), NULL)
+ knot_dname_labels(knot_rrs_dname_target(&rrset->rrs), NULL)
> KNOT_DNAME_MAXLABELS) {
return true;
} else {
......@@ -153,7 +153,7 @@ static int put_rrsig(const knot_dname_t *sig_owner, uint16_t type,
*/
static int put_answer(knot_pkt_t *pkt, uint16_t type, struct query_data *qdata)
{
const knot_rrset_t *rrset = NULL;
knot_rrset_t *rrset = NULL;
/* Wildcard expansion or exact match, either way RRSet owner is
* is QNAME. We can fake name synthesis by setting compression hint to
......@@ -190,7 +190,7 @@ static int put_answer(knot_pkt_t *pkt, uint16_t type, struct query_data *qdata)
default: /* Single RRSet of given type. */
rrset = knot_node_get_rrset(qdata->node, type);
if (rrset) {
const knot_rrset_t *rrsigs = knot_node_rrset(qdata->node, KNOT_RRTYPE_RRSIG);
knot_rrset_t *rrsigs = knot_node_get_rrset(qdata->node, KNOT_RRTYPE_RRSIG);
ret = ns_put_rr(pkt, rrset, rrsigs, compr_hint, 0, qdata);
}
break;
......@@ -217,9 +217,9 @@ static int put_authority_ns(knot_pkt_t *pkt, struct query_data *qdata)
return KNOT_EOK;
}
const knot_rrset_t *ns_rrset = knot_node_rrset(zone->apex, KNOT_RRTYPE_NS);
knot_rrset_t *ns_rrset = knot_node_get_rrset(zone->apex, KNOT_RRTYPE_NS);
if (ns_rrset) {
const knot_rrset_t *rrsigs = knot_node_rrset(zone->apex, KNOT_RRTYPE_RRSIG);
knot_rrset_t *rrsigs = knot_node_get_rrset(zone->apex, KNOT_RRTYPE_RRSIG);
return ns_put_rr(pkt, ns_rrset, rrsigs, COMPR_HINT_NONE,
KNOT_PF_NOTRUNC|KNOT_PF_CHECKDUP, qdata);
} else {
......@@ -233,20 +233,20 @@ static int put_authority_soa(knot_pkt_t *pkt, struct query_data *qdata,
const knot_zone_contents_t *zone)
{
dbg_ns("%s(%p, %p)\n", __func__, pkt, zone);
assert(knot_node_rrtype_exists(zone->apex, KNOT_RRTYPE_SOA));
knot_rrset_t *soa_rrset = knot_node_get_rrset(zone->apex, KNOT_RRTYPE_SOA);
assert(soa_rrset);
const knot_rrset_t *rrsigs = knot_node_rrset(zone->apex, KNOT_RRTYPE_RRSIG);
knot_rrset_t *rrsigs = knot_node_get_rrset(zone->apex, KNOT_RRTYPE_RRSIG);
// if SOA's TTL is larger than MINIMUM, copy the RRSet and set
// MINIMUM as TTL
int ret = KNOT_EOK;
uint32_t flags = KNOT_PF_NOTRUNC;
uint32_t min = knot_rdata_soa_minimum(soa_rrset);
uint32_t min = knot_rrs_soa_minimum(&soa_rrset->rrs);
if (min < knot_rrset_rr_ttl(soa_rrset, 0)) {
ret = knot_rrset_copy(soa_rrset, &soa_rrset, &pkt->mm);
if (ret != KNOT_EOK) {
return ret;
}
// ret = knot_rrset_copy(soa_rrset, &soa_rrset, &pkt->mm);
// if (ret != KNOT_EOK) {
// return ret;
// }
knot_rrset_rr_set_ttl(soa_rrset, 0, min);
flags |= KNOT_PF_FREE;
......@@ -269,8 +269,8 @@ static int put_delegation(knot_pkt_t *pkt, struct query_data *qdata)
}
/* Insert NS record. */
const knot_rrset_t *rrset = knot_node_rrset(qdata->node, KNOT_RRTYPE_NS);
const knot_rrset_t *rrsigs = knot_node_rrset(qdata->node, KNOT_RRTYPE_RRSIG);
knot_rrset_t *rrset = knot_node_get_rrset(qdata->node, KNOT_RRTYPE_NS);
knot_rrset_t *rrsigs = knot_node_get_rrset(qdata->node, KNOT_RRTYPE_RRSIG);
return ns_put_rr(pkt, rrset, rrsigs, COMPR_HINT_NONE, 0, qdata);
}
......@@ -287,7 +287,7 @@ static int put_additional(knot_pkt_t *pkt, const knot_rrset_t *rr,
uint32_t flags = KNOT_PF_NOTRUNC|KNOT_PF_CHECKDUP;
uint16_t hint = COMPR_HINT_NONE;
const knot_node_t *node = NULL;
const knot_rrset_t *additional = NULL;
knot_rrset_t *additional = NULL;
/* All RRs should have additional node cached or NULL. */
uint16_t rr_rdata_count = knot_rrset_rr_count(rr);
......@@ -300,9 +300,9 @@ static int put_additional(knot_pkt_t *pkt, const knot_rrset_t *rr,
continue;
}
const knot_rrset_t *rrsigs = knot_node_rrset(node, KNOT_RRTYPE_RRSIG);
knot_rrset_t *rrsigs = knot_node_get_rrset(node, KNOT_RRTYPE_RRSIG);
for (int k = 0; k < ar_type_count; ++k) {
additional = knot_node_rrset(node, ar_type_list[k]);
additional = knot_node_get_rrset(node, ar_type_list[k]);
if (additional == NULL) {
continue;
}
......@@ -323,7 +323,7 @@ static int follow_cname(knot_pkt_t *pkt, uint16_t rrtype, struct query_data *qda
const knot_node_t *cname_node = qdata->node;
knot_rrset_t *cname_rr = knot_node_get_rrset(qdata->node, rrtype);
const knot_rrset_t *rrsigs = knot_node_rrset(qdata->node, KNOT_RRTYPE_RRSIG);
knot_rrset_t *rrsigs = knot_node_get_rrset(qdata->node, KNOT_RRTYPE_RRSIG);
int ret = KNOT_EOK;
assert(cname_rr != NULL);
......@@ -383,7 +383,7 @@ static int follow_cname(knot_pkt_t *pkt, uint16_t rrtype, struct query_data *qda
}
/* Now follow the next CNAME TARGET. */
qdata->name = knot_rdata_cname_name(cname_rr);
qdata->name = knot_rrs_cname_name(&cname_rr->rrs);
#ifdef KNOT_NS_DEBUG
char *cname_str = knot_dname_to_str(cname_node->owner);
......@@ -658,8 +658,8 @@ static int solve_additional_dnssec(int state, knot_pkt_t *pkt, struct query_data
}
}
int ns_put_rr(knot_pkt_t *pkt, const knot_rrset_t *rr,
const knot_rrset_t *rrsigs, uint16_t compr_hint,
int ns_put_rr(knot_pkt_t *pkt, knot_rrset_t *rr,
knot_rrset_t *rrsigs, uint16_t compr_hint,
uint32_t flags, struct query_data *qdata)
{
/* RFC3123 s.6 - empty APL is valid, ignore other empty RRs. */
......@@ -670,10 +670,12 @@ int ns_put_rr(knot_pkt_t *pkt, const knot_rrset_t *rr,
}
// Copy all RRs for now TODO
knot_rrset_t *to_free = rr;
int ret = knot_rrset_copy(rr, (knot_rrset_t **)&rr, &pkt->mm);
if (ret != KNOT_EOK) {
return KNOT_ENOMEM;
}
knot_rrset_free(&to_free, NULL);
flags |= KNOT_PF_FREE;
/* Wildcard expansion applies only for answers. */
......@@ -713,6 +715,7 @@ int ns_put_rr(knot_pkt_t *pkt, const knot_rrset_t *rr,
knot_rrinfo_t *rrinfo = &pkt->rr_info[pkt->rrset_count - 1];
ret = put_rrsig(rr->owner, rr->type, rrsigs, rrinfo, qdata);
}
knot_rrset_free(&rrsigs, NULL);
return ret;
}
......
......@@ -54,8 +54,8 @@ int internet_answer(knot_pkt_t *resp, struct query_data *qdata);
*
* \return KNOT_E*
*/
int ns_put_rr(knot_pkt_t *pkt, const knot_rrset_t *rr,
const knot_rrset_t *rrsigs, uint16_t compr_hint,
int ns_put_rr(knot_pkt_t *pkt, knot_rrset_t *rr,
knot_rrset_t *rrsigs, uint16_t compr_hint,
uint32_t flags, struct query_data *qdata);
/*! \brief Require given QUERY TYPE or return error code. */
......
......@@ -130,10 +130,8 @@ static int ixfr_load_chsets(knot_changesets_t **chgsets, const zone_t *zone,
assert(zone);
/* Compare serials. */
const knot_node_t *apex = zone->contents->apex;
const knot_rrset_t *our_soa = knot_node_rrset(apex, KNOT_RRTYPE_SOA);
uint32_t serial_to = knot_rdata_soa_serial(our_soa);
uint32_t serial_from = knot_rdata_soa_serial(their_soa);
uint32_t serial_to = knot_zone_serial(zone->contents);
uint32_t serial_from = knot_rrs_soa_serial(&their_soa->rrs);
int ret = knot_serial_compare(serial_to, serial_from);
if (ret <= 0) { /* We have older/same age zone. */
return KNOT_EUPTODATE;
......@@ -297,8 +295,8 @@ int ixfr_answer(knot_pkt_t *pkt, struct query_data *qdata)
case KNOT_EOK: /* OK */
ixfr = (struct ixfr_proc*)qdata->ext;
IXFR_LOG(LOG_INFO, "Started (serial %u -> %u).",
knot_rdata_soa_serial(ixfr->soa_from),
knot_rdata_soa_serial(ixfr->soa_to));
knot_rrs_soa_serial(&ixfr->soa_from->rrs),
knot_rrs_soa_serial(&ixfr->soa_to->rrs));
break;
case KNOT_EUPTODATE: /* Our zone is same age/older, send SOA. */
IXFR_LOG(LOG_INFO, "Zone is up-to-date.");
......@@ -385,20 +383,10 @@ int ixfr_process_answer(knot_pkt_t *pkt, knot_ns_xfr_t *xfr)
case XFRIN_RES_SOA_ONLY: {
// compare the SERIAL from the changeset with the zone's
// serial
const knot_node_t *apex = zone->contents->apex;
if (apex == NULL) {
return KNOT_ERROR;
}
const knot_rrset_t *zone_soa = knot_node_rrset(
apex, KNOT_RRTYPE_SOA);
if (zone_soa == NULL) {
return KNOT_ERROR;
}
uint32_t zone_serial = knot_zone_serial(zone->contents);
if (knot_serial_compare(
knot_rdata_soa_serial(chgsets->first_soa),
knot_rdata_soa_serial(zone_soa))
knot_rrs_soa_serial(&chgsets->first_soa->rrs),
zone_serial)
> 0) {
if ((xfr->flags & XFR_FLAG_UDP) != 0) {
// IXFR over UDP
......
......@@ -60,14 +60,14 @@ static int ns_put_nsec3_from_node(const knot_node_t *node,
knot_pkt_t *resp)
{
knot_rrset_t *rrset = knot_node_get_rrset(node, KNOT_RRTYPE_NSEC3);
const knot_rrset_t *rrsigs = knot_node_rrset(node, KNOT_RRTYPE_RRSIG);
knot_rrset_t *rrsigs = knot_node_get_rrset(node, KNOT_RRTYPE_RRSIG);
if (rrset == NULL) {
// bad zone, ignore
return KNOT_EOK;
}
int res = KNOT_EOK;
if (knot_rrset_rr_count(rrset)) {
if (knot_rrset_rr_count(rrset) > 0) {
res = ns_put_rr(resp, rrset, rrsigs, COMPR_HINT_NONE,
KNOT_PF_CHECKDUP, qdata);
}
......@@ -301,8 +301,8 @@ static int ns_put_nsec_wildcard(const knot_zone_contents_t *zone,
}
}
const knot_rrset_t *rrset = knot_node_rrset(previous, KNOT_RRTYPE_NSEC);
const knot_rrset_t *rrsigs = knot_node_rrset(previous, KNOT_RRTYPE_RRSIG);
knot_rrset_t *rrset = knot_node_get_rrset(previous, KNOT_RRTYPE_NSEC);
knot_rrset_t *rrsigs = knot_node_get_rrset(previous, KNOT_RRTYPE_RRSIG);
int ret = KNOT_EOK;
......@@ -479,7 +479,7 @@ static int ns_put_nsec_nxdomain(const knot_dname_t *qname,
knot_pkt_t *resp)
{
knot_rrset_t *rrset = NULL;
const knot_rrset_t *rrsigs = NULL;
knot_rrset_t *rrsigs = NULL;
// check if we have previous; if not, find one using the tree
if (previous == NULL) {
......@@ -713,7 +713,7 @@ static int ns_put_nsec_nsec3_nodata(const knot_node_t *node,
if ((rrset = knot_node_get_rrset(node, KNOT_RRTYPE_NSEC))
!= NULL) {
dbg_ns_detail("Putting the RRSet to Authority\n");
const knot_rrset_t *rrsigs = knot_node_rrset(node, KNOT_RRTYPE_RRSIG);
knot_rrset_t *rrsigs = knot_node_get_rrset(node, KNOT_RRTYPE_RRSIG);
ret = ns_put_rr(resp, rrset, rrsigs, COMPR_HINT_NONE, 0, qdata);
}
}
......@@ -768,7 +768,7 @@ int nsec_prove_dp_security(knot_pkt_t *pkt, struct query_data *qdata)
/* Add DS record if present. */
knot_rrset_t *rrset = knot_node_get_rrset(qdata->node, KNOT_RRTYPE_DS);
if (rrset != NULL) {
const knot_rrset_t *rrsigs = knot_node_get_rrset(qdata->node, KNOT_RRTYPE_RRSIG);
knot_rrset_t *rrsigs = knot_node_get_rrset(qdata->node, KNOT_RRTYPE_RRSIG);
return ns_put_rr(pkt, rrset, rrsigs, COMPR_HINT_NONE, 0, qdata);
}
......
......@@ -95,7 +95,7 @@ int internet_notify(knot_pkt_t *pkt, struct query_data *qdata)
if (answer->count > 0) {
const knot_rrset_t *soa = answer->rr[0];
if (knot_rrset_type(soa) == KNOT_RRTYPE_SOA) {
serial = knot_rdata_soa_serial(soa);
serial = knot_rrs_soa_serial(&soa->rrs);
dbg_ns("%s: received serial %u\n", __func__, serial);
} else { /* Ignore */
dbg_ns("%s: NOTIFY answer != SOA_RR\n", __func__);
......
......@@ -197,10 +197,9 @@ static void log_zone_load_info(const zone_t *zone, const char *zone_name,
int64_t serial = 0;
if (zone->contents && zone->contents->apex) {
knot_rrset_t *soa;
soa = knot_node_get_rrset(zone->contents->apex, KNOT_RRTYPE_SOA);
serial = knot_rdata_soa_serial(soa);
knot_rrset_free(&soa, NULL);
const knot_rrs_t *soa = knot_node_rrs(zone->contents->apex,
KNOT_RRTYPE_SOA);
serial = knot_rrs_soa_serial(soa);
}
log_zone_info("Zone '%s' %s (serial %" PRId64 ")\n", zone_name, action, serial);
......
......@@ -64,7 +64,7 @@ static uint32_t zones_jitter(uint32_t interval)
* \param rr_func RDATA specificator.
* \return Timer in miliseconds.
*/
static uint32_t zones_soa_timer(zone_t *zone, uint32_t (*rr_func)(const knot_rrset_t*))
static uint32_t zones_soa_timer(zone_t *zone, uint32_t (*rr_func)(const knot_rrs_t*))
{
if (!zone) {
dbg_zones_verb("zones: zones_soa_timer() called "
......@@ -75,7 +75,7 @@ static uint32_t zones_soa_timer(zone_t *zone, uint32_t (*rr_func)(const knot_rrs
uint32_t ret = 0;
/* Retrieve SOA RDATA. */
const knot_rrset_t *soa_rrs = 0;
const knot_rrs_t *soa_rrs = NULL;
rcu_read_lock();
......@@ -85,10 +85,9 @@ static uint32_t zones_soa_timer(zone_t *zone, uint32_t (*rr_func)(const knot_rrs
return 0;
}
soa_rrs = knot_node_rrset(zc->apex, KNOT_RRTYPE_SOA);
soa_rrs = knot_node_rrs(zc->apex, KNOT_RRTYPE_SOA);
assert(soa_rrs != NULL);
ret = rr_func(soa_rrs);
knot_rrset_free(&soa_rrs, NULL);
rcu_read_unlock();
......@@ -104,7 +103,7 @@ static uint32_t zones_soa_timer(zone_t *zone, uint32_t (*rr_func)(const knot_rrs
*/
static uint32_t zones_soa_refresh(zone_t *zone)
{
return zones_soa_timer(zone, knot_rdata_soa_refresh);
return zones_soa_timer(zone, knot_rrs_soa_refresh);
}
/*!
......@@ -115,7 +114,7 @@ static uint32_t zones_soa_refresh(zone_t *zone)
*/
static uint32_t zones_soa_retry(zone_t *zone)
{
return zones_soa_timer(zone, knot_rdata_soa_retry);
return zones_soa_timer(zone, knot_rrs_soa_retry);
}
/*!
......@@ -126,7 +125,7 @@ static uint32_t zones_soa_retry(zone_t *zone)
*/
static uint32_t zones_soa_expire(zone_t *zone)
{
return zones_soa_timer(zone, knot_rdata_soa_expire);
return zones_soa_timer(zone, knot_rrs_soa_expire);
}
/*!
......@@ -509,7 +508,7 @@ int zones_changesets_from_binary(knot_changesets_t *chgsets)
dbg_xfr_verb("xfr: reading RRSets to REMOVE, first RR is %hu\n",
knot_rrset_type(rrset));
assert(knot_rrset_type(rrset) == KNOT_RRTYPE_SOA);
assert(chs->serial_from == knot_rdata_soa_serial(rrset));
assert(chs->serial_from == knot_rrs_soa_serial(&rrset->rrs));
knot_changeset_add_soa(chs, rrset, KNOT_CHANGESET_REMOVE);
/* Read remaining RRSets */
......@@ -959,11 +958,11 @@ int zones_zonefile_sync(zone_t *zone, journal_t *journal)
}
/* Latest zone serial. */
const knot_rrset_t *soa_rrs = 0;
soa_rrs = knot_node_rrset(contents->apex, KNOT_RRTYPE_SOA);
const knot_rrs_t *soa_rrs = knot_node_rrs(contents->apex,
KNOT_RRTYPE_SOA);
assert(soa_rrs != NULL);
int64_t serial_ret = knot_rdata_soa_serial(soa_rrs);
int64_t serial_ret = knot_rrs_soa_serial(soa_rrs);
if (serial_ret < 0) {
rcu_read_unlock();
pthread_mutex_unlock(&zone->lock);
......@@ -1876,11 +1875,10 @@ int zones_journal_apply(zone_t *zone)
}
/* Fetch SOA serial. */
const knot_rrset_t *soa_rrs = 0;
soa_rrs = knot_node_rrset(contents->apex, KNOT_RRTYPE_SOA);
const knot_rrs_t *soa_rrs = 0;
soa_rrs = knot_node_rrs(contents->apex, KNOT_RRTYPE_SOA);
assert(soa_rrs != NULL);
int64_t serial_ret = knot_rdata_soa_serial(soa_rrs);
knot_rrset_free(&soa_rrs, NULL);
int64_t serial_ret = knot_rrs_soa_serial(soa_rrs);
if (serial_ret < 0) {
rcu_read_unlock();
return KNOT_EINVAL;
......
......@@ -208,7 +208,7 @@ static void knot_changeset_store_soa(knot_rrset_t **chg_soa,
uint32_t *chg_serial, knot_rrset_t *soa)
{
*chg_soa = soa;
*chg_serial = knot_rdata_soa_serial(soa);
*chg_serial = knot_rrs_soa_serial(&soa->rrs);
}
void knot_changeset_add_soa(knot_changeset_t *changeset, knot_rrset_t *soa,
......
......@@ -800,8 +800,8 @@ static int knot_ddns_process_add_soa(knot_node_t *node,
}
/* Check that the serial is indeed larger than the current one*/
assert(knot_serial_compare(knot_rdata_soa_serial(removed),
knot_rdata_soa_serial(rr)) < 0);
assert(knot_serial_compare(knot_rrs_soa_serial(&removed->rrs),
knot_rrs_soa_serial(&rr->rrs)) < 0);
/* 1) Store it to 'changes', together with its RRSIGs. */
ret = knot_changes_add_rrset(changes, removed, KNOT_CHANGES_OLD);
......@@ -1645,11 +1645,9 @@ int knot_ddns_process_update(knot_zone_contents_t *zone,
int ret = KNOT_EOK;
/* Copy base SOA RR. */
const knot_rrset_t *soa = knot_node_rrset(knot_zone_contents_apex(zone),
KNOT_RRTYPE_SOA);
knot_rrset_t *soa_begin = NULL;
knot_rrset_t *soa_begin = knot_node_get_rrset(knot_zone_contents_apex(zone),
KNOT_RRTYPE_SOA);
knot_rrset_t *soa_end = NULL;
ret = knot_rrset_copy(soa, &soa_begin, NULL);
if (ret == KNOT_EOK) {
knot_changeset_add_soa(changeset, soa_begin,
KNOT_CHANGESET_REMOVE);
......@@ -1659,7 +1657,7 @@ int knot_ddns_process_update(knot_zone_contents_t *zone,
}
/* Current SERIAL */
int64_t sn = knot_rdata_soa_serial(soa_begin);
int64_t sn = knot_rrs_soa_serial(&soa_begin->rrs);
int64_t sn_new;
/* Set the new serial according to policy. */
......@@ -1710,7 +1708,7 @@ int knot_ddns_process_update(knot_zone_contents_t *zone,
if (knot_rrset_type(rr) == KNOT_RRTYPE_SOA
&& (knot_rrset_class(rr) == KNOT_CLASS_NONE
|| knot_rrset_class(rr) == KNOT_CLASS_ANY
|| knot_serial_compare(knot_rdata_soa_serial(rr),
|| knot_serial_compare(knot_rrs_soa_serial(&rr->rrs),
sn) <= 0)) {
// This ignores also SOA removals
dbg_ddns_verb("Ignoring SOA...\n");
......@@ -1737,7 +1735,7 @@ int knot_ddns_process_update(knot_zone_contents_t *zone,
// we need the RR copy, that's why this code is here
if (knot_rrset_type(rr) == KNOT_RRTYPE_SOA) {
int64_t sn_rr = knot_rdata_soa_serial(rr);
int64_t sn_rr = knot_rrs_soa_serial(&rr->rrs);
dbg_ddns_verb("Replacing SOA. Old serial: %"PRId64", "
"new serial: %"PRId64"\n", sn_new, sn_rr);
assert(knot_serial_compare(sn_rr, sn) > 0);
......@@ -1758,14 +1756,14 @@ int knot_ddns_process_update(knot_zone_contents_t *zone,
}
/* If not set, create new SOA. */
ret = knot_rrset_copy(soa, &soa_end, NULL);
ret = knot_rrset_copy(soa_begin, &soa_end, NULL);
if (ret != KNOT_EOK) {
dbg_ddns("Failed to copy ending SOA: %s\n",
knot_strerror(ret));
*rcode = KNOT_RCODE_SERVFAIL;
return ret;
}
knot_rdata_soa_serial_set(soa_end, sn_new);
knot_rrs_soa_serial_set(&soa_end->rrs, sn_new);
/* And replace it in the zone. */
ret = xfrin_replace_rrset_in_node(
......
......@@ -63,10 +63,9 @@ int xfrin_transfer_needed(const knot_zone_contents_t *zone,
/*
* Retrieve the local Serial
*/
const knot_rrset_t *soa_rrset =
knot_node_rrset(knot_zone_contents_apex(zone),
KNOT_RRTYPE_SOA);
if (soa_rrset == NULL) {
const knot_rrs_t *soa_rrs =
knot_node_rrs(knot_zone_contents_apex(zone), KNOT_RRTYPE_SOA);
if (soa_rrs == NULL) {
char *name = knot_dname_to_str(knot_node_owner(
knot_zone_contents_apex(zone)));
dbg_xfrin("SOA RRSet missing in the zone %s!\n", name);
......@@ -74,7 +73,7 @@ int xfrin_transfer_needed(const knot_zone_contents_t *zone,
return KNOT_ERROR;
}
int64_t local_serial = knot_rdata_soa_serial(soa_rrset);
int64_t local_serial = knot_rrs_soa_serial(soa_rrs);
if (local_serial < 0) {
dbg_xfrin_exec(
char *name = knot_dname_to_str(knot_rrset_owner(soa_rrset));
......@@ -94,7 +93,7 @@ dbg_xfrin_exec(
return KNOT_EMALF;
}
int64_t remote_serial = knot_rdata_soa_serial(answer->rr[0]);
int64_t remote_serial = knot_rrs_soa_serial(&answer->rr[0]->rrs);
if (remote_serial < 0) {
return KNOT_EMALF; // maybe some other error
}
......@@ -474,8 +473,8 @@ dbg_xfrin_exec_verb(
goto cleanup;
}
if (knot_rdata_soa_serial(rr)
== knot_rdata_soa_serial((*chs)->first_soa)) {
if (knot_rrs_soa_serial(&rr->rrs)
== knot_rrs_soa_serial(&(*chs)->first_soa->rrs)) {
/*! \note [TSIG] Check TSIG, we're at the end of
* transfer.
......@@ -541,8 +540,8 @@ dbg_xfrin_exec_verb(
if (knot_rrset_type(rr) == KNOT_RRTYPE_SOA) {
log_zone_info("%s Serial %u -> %u.\n",
xfr->msg,
knot_rdata_soa_serial(chset->soa_from),
knot_rdata_soa_serial(chset->soa_to));
knot_rrs_soa_serial(&chset->soa_from->rrs),
knot_rrs_soa_serial(&chset->soa_to->rrs));
state = -1;
continue;
} else {
......@@ -1120,11 +1119,7 @@ dbg_xfrin_exec_verb(
is_nsec3 = 0;
// check if the RRSet belongs to the NSEC3 tree
if ((knot_rrset_type(rr) == KNOT_RRTYPE_NSEC3)
|| (knot_rrset_type(rr) == KNOT_RRTYPE_RRSIG
&& knot_rdata_rrsig_type_covered(rr, 0)
== KNOT_RRTYPE_NSEC3))
{
if (knot_rrset_is_nsec3rel(rr)) {
dbg_xfrin_verb("Removed RRSet belongs to NSEC3 tree.\n");
is_nsec3 = 1;
}
......@@ -1197,11 +1192,7 @@ dbg_xfrin_exec_verb(
is_nsec3 = 0;
// check if the RRSet belongs to the NSEC3 tree
if ((knot_rrset_type(rr) == KNOT_RRTYPE_NSEC3)
|| (knot_rrset_type(rr) == KNOT_RRTYPE_RRSIG
&& knot_rdata_rrsig_type_covered(rr, 0)
== KNOT_RRTYPE_NSEC3))
{
if (knot_rrset_is_nsec3rel(rr)) {
dbg_xfrin_detail("This is NSEC3-related RRSet.\n");
is_nsec3 = 1;
}
......@@ -1322,9 +1313,8 @@ static int xfrin_apply_changeset(knot_zone_contents_t *contents,
chset->serial_from, chset->serial_to);
// check if serial matches
const knot_rrset_t *soa = knot_node_rrset(contents->apex,
KNOT_RRTYPE_SOA);
if (soa == NULL || knot_rdata_soa_serial(soa)
const knot_rrs_t *soa = knot_node_rrs(contents->apex, KNOT_RRTYPE_SOA);
if (soa == NULL || knot_rrs_soa_serial(soa)
!= chset->serial_from) {
dbg_xfrin("SOA serials do not match!!\n");
return KNOT_ERROR;
......
......@@ -246,6 +246,26 @@ const knot_rrset_t *knot_node_rrset(const knot_node_t *node,
return knot_node_get_rrset(node, type);
}
const knot_rrs_t *knot_node_rrs(const knot_node_t *node, uint16_t type)
{
return (const knot_rrs_t *)knot_node_get_rrs(node, type);
}
knot_rrs_t *knot_node_get_rrs(const knot_node_t *node, uint16_t type)
{
if (node == NULL) {
return NULL;
}
for (uint16_t i = 0; i < node->rrset_count; ++i) {
if (node->rrs[i].type == type) {
return &node->rrs[i].rrs;
}
}
return NULL;
}
/*----------------------------------------------------------------------------*/
knot_rrset_t *knot_node_get_rrset(const knot_node_t *node, uint16_t type)
......@@ -745,22 +765,20 @@ bool knot_node_rrtype_is_signed(const knot_node_t *node, uint16_t type)
return false;
}
const knot_rrset_t *rrsigs = knot_node_rrset(node, KNOT_RRTYPE_RRSIG);
const knot_rrs_t *rrsigs = knot_node_rrs(node, KNOT_RRTYPE_RRSIG);
if (rrsigs == NULL) {
return false;
}