Commit fb54f4cd authored by Jan Kadlec's avatar Jan Kadlec

new_node: removed knot_node_rrset()

- use rrset initialization macro instead, or create rrset explicitely
parent bc90abc9
......@@ -55,7 +55,7 @@ static knot_rrset_t *create_nsec_rrset(const knot_node_t *from,
bitmap_add_node_rrsets(&rr_types, from);
bitmap_add_type(&rr_types, KNOT_RRTYPE_NSEC);
bitmap_add_type(&rr_types, KNOT_RRTYPE_RRSIG);
if (knot_node_rrset(from, KNOT_RRTYPE_SOA)) {
if (knot_node_rrtype_exists(from, KNOT_RRTYPE_SOA)) {
bitmap_add_type(&rr_types, KNOT_RRTYPE_DNSKEY);
}
......@@ -99,7 +99,7 @@ static int connect_nsec_nodes(knot_node_t *a, knot_node_t *b,
return NSEC_NODE_SKIP;
}
knot_rrset_t *old_next_nsec = knot_node_get_rrset(b, KNOT_RRTYPE_NSEC);
knot_rrset_t *old_next_nsec = knot_node_create_rrset(b, KNOT_RRTYPE_NSEC);
int ret = 0;
/*!
......@@ -123,7 +123,7 @@ static int connect_nsec_nodes(knot_node_t *a, knot_node_t *b,
return KNOT_ENOMEM;
}
knot_rrset_t *old_nsec = knot_node_get_rrset(a, KNOT_RRTYPE_NSEC);
knot_rrset_t *old_nsec = knot_node_create_rrset(a, KNOT_RRTYPE_NSEC);
if (old_nsec != NULL) {
if (knot_rrset_equal(new_nsec, old_nsec,
KNOT_RRSET_COMPARE_WHOLE)) {
......@@ -216,26 +216,21 @@ int knot_nsec_changeset_remove(const knot_node_t *n,
int result = KNOT_EOK;
const knot_rrset_t *nsec = knot_node_rrset(n, KNOT_RRTYPE_NSEC);
knot_rrset_t *nsec = knot_node_create_rrset(n, KNOT_RRTYPE_NSEC);
if (nsec == NULL) {
nsec = knot_node_rrset(n, KNOT_RRTYPE_NSEC3);
nsec = knot_node_create_rrset(n, KNOT_RRTYPE_NSEC3);
}
const knot_rrset_t *rrsigs = knot_node_rrset(n, KNOT_RRTYPE_RRSIG);
// extract copy of NSEC
knot_rrset_t *old_nsec = NULL;
if (nsec == NULL) {
return KNOT_ENOMEM;
}
knot_rrset_t *rrsigs = knot_node_create_rrset(n, KNOT_RRTYPE_RRSIG);
if (nsec) {
result = knot_rrset_copy(nsec, &old_nsec, NULL);
if (result != KNOT_EOK) {
return result;
}
// update changeset
result = knot_changeset_add_rrset(changeset, old_nsec,
result = knot_changeset_add_rrset(changeset, nsec,
KNOT_CHANGESET_REMOVE);
if (result != KNOT_EOK) {
knot_rrset_free(&old_nsec, NULL);
knot_rrset_free(&rrsigs, NULL);
knot_rrset_free(&nsec, NULL);
return result;
}
}
......@@ -255,6 +250,7 @@ int knot_nsec_changeset_remove(const knot_node_t *n,
}
if (result != KNOT_EOK) {
knot_rrset_free(&rrsigs, NULL);
if (result != KNOT_ENOENT) {
return result;
}
......@@ -266,9 +262,11 @@ int knot_nsec_changeset_remove(const knot_node_t *n,
KNOT_CHANGESET_REMOVE);
if (result != KNOT_EOK) {
knot_rrset_free(&synth_rrsigs, NULL);
knot_rrset_free(&rrsigs, NULL);
return result;
}
}
knot_rrset_free(&rrsigs, NULL);
return KNOT_EOK;
}
......
......@@ -51,12 +51,12 @@ inline static bool valid_nsec3_node(const knot_node_t *node)
return false;
}
const knot_rrset_t *nsec3 = knot_node_rrset(node, KNOT_RRTYPE_NSEC3);
const knot_rrs_t *nsec3 = knot_node_rrs(node, KNOT_RRTYPE_NSEC3);
if (nsec3 == NULL) {
return false;
}
if (knot_rrset_rr_count(nsec3) != 1) {
if (knot_rrs_rr_count(nsec3) != 1) {
return false;
}
......@@ -72,10 +72,11 @@ static bool are_nsec3_nodes_equal(const knot_node_t *a, const knot_node_t *b)
return false;
}
const knot_rrset_t *a_rrset = knot_node_rrset(a, KNOT_RRTYPE_NSEC3);
const knot_rrset_t *b_rrset = knot_node_rrset(b, KNOT_RRTYPE_NSEC3);
return knot_rrset_equal(a_rrset, b_rrset, KNOT_RRSET_COMPARE_WHOLE);
knot_rrset_t a_rrset;
knot_rrset_t b_rrset;
knot_node_fill_rrset(a, KNOT_RRTYPE_NSEC3, &a_rrset);
knot_node_fill_rrset(b, KNOT_RRTYPE_NSEC3, &b_rrset);
return knot_rrset_equal(&a_rrset, &b_rrset, KNOT_RRSET_COMPARE_WHOLE);
}
/*!
......@@ -117,7 +118,7 @@ static int shallow_copy_signature(const knot_node_t *from, knot_node_t *to)
assert(valid_nsec3_node(from));
assert(valid_nsec3_node(to));
knot_rrset_t *from_sig = knot_node_get_rrset(from, KNOT_RRTYPE_RRSIG);
knot_rrset_t *from_sig = knot_node_create_rrset(from, KNOT_RRTYPE_RRSIG);
if (from_sig == NULL) {
return KNOT_EOK;
}
......@@ -175,7 +176,7 @@ static void free_nsec3_tree(knot_zone_tree_t *nodes)
for (/* NOP */; !hattrie_iter_finished(it); hattrie_iter_next(it)) {
knot_node_t *node = (knot_node_t *)*hattrie_iter_val(it);
// newly allocated NSEC3 nodes
knot_rrset_t *nsec3 = knot_node_get_rrset(node,
knot_rrset_t *nsec3 = knot_node_create_rrset(node,
KNOT_RRTYPE_NSEC3);
knot_rrset_free(&nsec3, NULL);
knot_node_free(&node);
......@@ -444,7 +445,7 @@ static int create_nsec3_nodes(const knot_zone_contents_t *zone, uint32_t ttl,
if (result != KNOT_EOK) {
break;
}
if (knot_node_rrset(node, KNOT_RRTYPE_NSEC)) {
if (knot_node_rrtype_exists(node, KNOT_RRTYPE_NSEC)) {
knot_node_set_removed_nsec(node);
}
if (knot_node_is_non_auth(node) || knot_node_is_empty(node)) {
......
......@@ -128,12 +128,10 @@ static int zone_sign(knot_zone_contents_t *zone, conf_zone_t *zone_config,
}
// update SOA if there were any changes
const knot_rrset_t *soa = knot_node_rrset(zone->apex,
KNOT_RRTYPE_SOA);
const knot_rrset_t *rrsigs = knot_node_rrset(zone->apex,
KNOT_RRTYPE_RRSIG);
assert(soa);
result = knot_zone_sign_update_soa(soa, rrsigs, &zone_keys, &policy,
knot_rrset_t soa = RRSET_INIT(zone->apex, KNOT_RRTYPE_SOA);
knot_rrset_t rrsigs = RRSET_INIT(zone->apex, KNOT_RRTYPE_RRSIG);
assert(!knot_rrset_empty(&soa));
result = knot_zone_sign_update_soa(&soa, &rrsigs, &zone_keys, &policy,
new_serial, out_ch);
if (result != KNOT_EOK) {
log_zone_error("%s Cannot update SOA record (%s). Not signing"
......@@ -240,12 +238,10 @@ int knot_dnssec_sign_changeset(const knot_zone_contents_t *zone,
}
// Update SOA RRSIGs
ret = knot_zone_sign_update_soa(knot_node_rrset(zone->apex,
KNOT_RRTYPE_SOA),
knot_node_rrset(zone->apex,
KNOT_RRTYPE_RRSIG),
&zone_keys, &policy, new_serial,
out_ch);
knot_rrset_t soa = RRSET_INIT(zone->apex, KNOT_RRTYPE_SOA);
knot_rrset_t rrsigs = RRSET_INIT(zone->apex, KNOT_RRTYPE_RRSIG);
ret = knot_zone_sign_update_soa(&soa, &rrsigs, &zone_keys, &policy,
new_serial, out_ch);
if (ret != KNOT_EOK) {
log_zone_error("%s Failed to sign SOA RR (%s)\n", msgpref,
knot_strerror(ret));
......
......@@ -73,7 +73,7 @@ static bool valid_signature_exists(const knot_rrset_t *covered,
{
assert(key);
if (!rrsigs) {
if (knot_rrset_empty(rrsigs)) {
return false;
}
......@@ -208,7 +208,7 @@ static int remove_expired_rrsigs(const knot_rrset_t *covered,
{
assert(changeset);
if (!rrsigs) {
if (knot_rrset_empty(rrsigs)) {
return KNOT_EOK;
}
......@@ -391,7 +391,7 @@ static int force_resign_rrset(const knot_rrset_t *covered,
{
assert(covered);
if (rrsigs) {
if (!knot_rrset_empty(rrsigs)) {
int result = remove_rrset_rrsigs(covered->owner, covered->type,
rrsigs, changeset);
if (result != KNOT_EOK) {
......@@ -450,7 +450,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_rrs_rrsig_type_covered(&rrsigs->rrs, i);
if (!knot_node_rrset(node, type_covered)) {
if (!knot_node_rrtype_exists(node, type_covered)) {
knot_rrset_t *to_remove = knot_rrset_new_from(rrsigs, NULL);
if (to_remove == NULL) {
return KNOT_ENOMEM;
......@@ -492,7 +492,8 @@ static int sign_node_rrsets(const knot_node_t *node,
assert(policy);
int result = KNOT_EOK;
const knot_rrset_t *rrsigs = knot_node_rrset(node, KNOT_RRTYPE_RRSIG);
knot_rrset_t rrsigs;
knot_node_fill_rrset(node, KNOT_RRTYPE_RRSIG, &rrsigs);
knot_rrset_t **node_rrsets = knot_node_rrsets(node);
for (int i = 0; i < node->rrset_count; i++) {
......@@ -511,10 +512,10 @@ static int sign_node_rrsets(const knot_node_t *node,
}
if (policy->forced_sign) {
result = force_resign_rrset(rrset, rrsigs, zone_keys, policy,
result = force_resign_rrset(rrset, &rrsigs, zone_keys, policy,
changeset);
} else {
result = resign_rrset(rrset, rrsigs, zone_keys, policy,
result = resign_rrset(rrset, &rrsigs, zone_keys, policy,
changeset, expires_at);
}
......@@ -525,7 +526,7 @@ static int sign_node_rrsets(const knot_node_t *node,
knot_node_free_rrset_array(node, node_rrsets);
return remove_standalone_rrsigs(node, rrsigs, changeset);
return remove_standalone_rrsigs(node, &rrsigs, changeset);
}
/*!
......@@ -726,11 +727,10 @@ static int remove_invalid_dnskeys(const knot_rrset_t *soa,
const knot_zone_keys_t *zone_keys,
knot_changeset_t *changeset)
{
assert(soa);
assert(soa->type == KNOT_RRTYPE_SOA);
assert(changeset);
if (!dnskeys) {
if (knot_rrset_empty(dnskeys)) {
return KNOT_EOK;
}
assert(dnskeys->type == KNOT_RRTYPE_DNSKEY);
......@@ -987,30 +987,33 @@ static int update_dnskeys(const knot_zone_contents_t *zone,
assert(changeset);
const knot_node_t *apex = zone->apex;
const knot_rrset_t *dnskeys = knot_node_rrset(apex, KNOT_RRTYPE_DNSKEY);
const knot_rrset_t *soa = knot_node_rrset(apex, KNOT_RRTYPE_SOA);
const knot_rrset_t *rrsigs = knot_node_rrset(apex, KNOT_RRTYPE_RRSIG);
if (!soa) {
knot_rrset_t dnskeys = { 0 };
knot_rrset_t soa = { 0 };
knot_rrset_t rrsigs = { 0 };
knot_node_fill_rrset(apex, KNOT_RRTYPE_SOA, &soa);
knot_node_fill_rrset(apex, KNOT_RRTYPE_RRSIG, &rrsigs);
knot_node_fill_rrset(apex, KNOT_RRTYPE_DNSKEY, &dnskeys);
if (knot_rrset_empty(&soa)) {
return KNOT_EINVAL;
}
int result;
size_t changes_before = knot_changeset_size(changeset);
result = remove_invalid_dnskeys(soa, dnskeys, zone_keys, changeset);
result = remove_invalid_dnskeys(&soa, &dnskeys, zone_keys, changeset);
if (result != KNOT_EOK) {
return result;
}
result = add_missing_dnskeys(soa, dnskeys, zone_keys, changeset);
result = add_missing_dnskeys(&soa, &dnskeys, zone_keys, changeset);
if (result != KNOT_EOK) {
return result;
}
knot_rrset_t *dnskey_rrsig = NULL;
result = knot_rrset_synth_rrsig(apex->owner, KNOT_RRTYPE_DNSKEY,
rrsigs, &dnskey_rrsig, NULL);
&rrsigs, &dnskey_rrsig, NULL);
if (result != KNOT_EOK) {
if (result != KNOT_ENOENT) {
return result;
......@@ -1018,8 +1021,8 @@ static int update_dnskeys(const knot_zone_contents_t *zone,
}
bool modified = (knot_changeset_size(changeset) != changes_before);
bool signatures_exist = (dnskeys &&
all_signatures_exist(dnskeys, dnskey_rrsig,
bool signatures_exist = (!knot_rrset_empty(&dnskeys) &&
all_signatures_exist(&dnskeys, dnskey_rrsig,
zone_keys, policy));
knot_rrset_free(&dnskey_rrsig, NULL);
if (!modified && signatures_exist) {
......@@ -1027,7 +1030,7 @@ static int update_dnskeys(const knot_zone_contents_t *zone,
}
dbg_dnssec_detail("Creating new signatures for DNSKEYs\n");
return update_dnskeys_rrsigs(dnskeys, rrsigs, soa, zone_keys, policy, changeset);
return update_dnskeys_rrsigs(&dnskeys, &rrsigs, &soa, zone_keys, policy, changeset);
}
/*!
......@@ -1161,20 +1164,18 @@ static int sign_changeset_wrap(knot_rrset_t *chg_rrset, void *data)
// If node is not in zone, all its RRSIGs were dropped - no-op
if (node) {
const knot_rrset_t *rrsigs = knot_node_rrset(node,
KNOT_RRTYPE_RRSIG);
const knot_rrset_t *zone_rrset =
knot_node_rrset(node, chg_rrset->type);
knot_rrset_t zone_rrset = RRSET_INIT(node, chg_rrset->type);
knot_rrset_t rrsigs = RRSET_INIT(node, KNOT_RRTYPE_RRSIG);
bool should_sign = false;
int ret = knot_zone_sign_rr_should_be_signed(node, zone_rrset,
int ret = knot_zone_sign_rr_should_be_signed(node, &zone_rrset,
&should_sign);
if (ret != KNOT_EOK) {
return ret;
}
// Check for RRSet in the 'already_signed' table
if (args->signed_tree && (should_sign && zone_rrset == NULL)) {
if (args->signed_tree && (should_sign && knot_rrset_empty(&zone_rrset))) {
bool already_signed = false;
int ret = rr_already_signed(chg_rrset, args->signed_tree,
......@@ -1189,7 +1190,7 @@ static int sign_changeset_wrap(knot_rrset_t *chg_rrset, void *data)
}
if (should_sign) {
return force_resign_rrset(zone_rrset, rrsigs,
return force_resign_rrset(&zone_rrset, &rrsigs,
args->zone_keys,
args->policy,
args->changeset);
......@@ -1205,7 +1206,7 @@ static int sign_changeset_wrap(knot_rrset_t *chg_rrset, void *data)
* the zone. We need to drop them as well.
*/
return remove_rrset_rrsigs(chg_rrset->owner,
chg_rrset->type, rrsigs,
chg_rrset->type, &rrsigs,
args->changeset);
}
}
......@@ -1307,10 +1308,10 @@ bool knot_zone_sign_soa_expired(const knot_zone_contents_t *zone,
return KNOT_EINVAL;
}
const knot_rrset_t *soa = knot_node_rrset(zone->apex, KNOT_RRTYPE_SOA);
const knot_rrset_t *rrsigs = knot_node_rrset(zone->apex, KNOT_RRTYPE_RRSIG);
assert(soa);
return !all_signatures_exist(soa, rrsigs, zone_keys, policy);
knot_rrset_t soa = RRSET_INIT(zone->apex, KNOT_RRTYPE_SOA);
knot_rrset_t rrsigs = RRSET_INIT(zone->apex, KNOT_RRTYPE_RRSIG);
assert(!knot_rrset_empty(&soa));
return !all_signatures_exist(&soa, &rrsigs, zone_keys, policy);
}
/*!
......@@ -1323,7 +1324,7 @@ int knot_zone_sign_update_soa(const knot_rrset_t *soa,
uint32_t new_serial,
knot_changeset_t *changeset)
{
if (!soa || !zone_keys || !policy || !changeset) {
if (knot_rrset_empty(soa) || !zone_keys || !policy || !changeset) {
return KNOT_EINVAL;
}
......@@ -1346,7 +1347,7 @@ int knot_zone_sign_update_soa(const knot_rrset_t *soa,
// remove signatures for old SOA (if there are any)
if (rrsigs) {
if (!knot_rrset_empty(rrsigs)) {
result = remove_rrset_rrsigs(soa->owner, soa->type, rrsigs,
changeset);
if (result != KNOT_EOK) {
......
......@@ -35,7 +35,7 @@ static int put_rrsets(knot_pkt_t *pkt, knot_node_t *node, struct axfr_proc *stat
int ret = KNOT_EOK;
int i = state->cur_rrset;
int rrset_count = knot_node_rrset_count(node);
unsigned flags = KNOT_PF_NOTRUNC;
unsigned flags = KNOT_PF_NOTRUNC | KNOT_PF_FREE;
knot_rrset_t **rrsets = knot_node_rrsets(node);
/* Append all RRs. */
......@@ -134,11 +134,11 @@ int xfr_process_list(knot_pkt_t *pkt, xfr_put_cb process_item, struct query_data
mm_ctx_t *mm = qdata->mm;
struct xfr_proc *xfer = qdata->ext;
knot_zone_contents_t *zone = qdata->zone->contents;
knot_rrset_t *soa_rr = knot_node_get_rrset(zone->apex, KNOT_RRTYPE_SOA);
knot_rrset_t *soa_rr = knot_node_create_rrset(zone->apex, KNOT_RRTYPE_SOA);
/* Prepend SOA on first packet. */
if (xfer->npkts == 0) {
ret = knot_pkt_put(pkt, 0, soa_rr, KNOT_PF_NOTRUNC);
ret = knot_pkt_put(pkt, 0, soa_rr, KNOT_PF_NOTRUNC | KNOT_PF_FREE);
if (ret != KNOT_EOK) {
return ret;
}
......@@ -159,7 +159,7 @@ int xfr_process_list(knot_pkt_t *pkt, xfr_put_cb process_item, struct query_data
/* Append SOA on last packet. */
if (ret == KNOT_EOK) {
ret = knot_pkt_put(pkt, 0, soa_rr, KNOT_PF_NOTRUNC);
ret = knot_pkt_put(pkt, 0, soa_rr, KNOT_PF_NOTRUNC | KNOT_PF_FREE);
}
/* Update counters. */
......
......@@ -188,9 +188,9 @@ static int put_answer(knot_pkt_t *pkt, uint16_t type, struct query_data *qdata)
break;
}
default: /* Single RRSet of given type. */
rrset = knot_node_get_rrset(qdata->node, type);
rrset = knot_node_create_rrset(qdata->node, type);
if (rrset) {
knot_rrset_t *rrsigs = knot_node_get_rrset(qdata->node, KNOT_RRTYPE_RRSIG);
knot_rrset_t *rrsigs = knot_node_create_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;
}
knot_rrset_t *ns_rrset = knot_node_get_rrset(zone->apex, KNOT_RRTYPE_NS);
knot_rrset_t *ns_rrset = knot_node_create_rrset(zone->apex, KNOT_RRTYPE_NS);
if (ns_rrset) {
knot_rrset_t *rrsigs = knot_node_get_rrset(zone->apex, KNOT_RRTYPE_RRSIG);
knot_rrset_t *rrsigs = knot_node_create_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 {
......@@ -234,8 +234,8 @@ static int put_authority_soa(knot_pkt_t *pkt, struct query_data *qdata,
{
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);
knot_rrset_t *rrsigs = knot_node_get_rrset(zone->apex, KNOT_RRTYPE_RRSIG);
knot_rrset_t *soa_rrset = knot_node_create_rrset(zone->apex, KNOT_RRTYPE_SOA);
knot_rrset_t *rrsigs = knot_node_create_rrset(zone->apex, KNOT_RRTYPE_RRSIG);
// if SOA's TTL is larger than MINIMUM, copy the RRSet and set
// MINIMUM as TTL
......@@ -269,8 +269,8 @@ static int put_delegation(knot_pkt_t *pkt, struct query_data *qdata)
}
/* Insert NS record. */
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);
knot_rrset_t *rrset = knot_node_create_rrset(qdata->node, KNOT_RRTYPE_NS);
knot_rrset_t *rrsigs = knot_node_create_rrset(qdata->node, KNOT_RRTYPE_RRSIG);
return ns_put_rr(pkt, rrset, rrsigs, COMPR_HINT_NONE, 0, qdata);
}
......@@ -300,9 +300,9 @@ static int put_additional(knot_pkt_t *pkt, const knot_rrset_t *rr,
continue;
}
knot_rrset_t *rrsigs = knot_node_get_rrset(node, KNOT_RRTYPE_RRSIG);
knot_rrset_t *rrsigs = knot_node_create_rrset(node, KNOT_RRTYPE_RRSIG);
for (int k = 0; k < ar_type_count; ++k) {
additional = knot_node_get_rrset(node, ar_type_list[k]);
additional = knot_node_create_rrset(node, ar_type_list[k]);
if (additional == NULL) {
continue;
}
......@@ -322,8 +322,8 @@ static int follow_cname(knot_pkt_t *pkt, uint16_t rrtype, struct query_data *qda
dbg_ns("%s(%p, %p)\n", __func__, pkt, qdata);
const knot_node_t *cname_node = qdata->node;
knot_rrset_t *cname_rr = knot_node_get_rrset(qdata->node, rrtype);
knot_rrset_t *rrsigs = knot_node_get_rrset(qdata->node, KNOT_RRTYPE_RRSIG);
knot_rrset_t *cname_rr = knot_node_create_rrset(qdata->node, rrtype);
knot_rrset_t *rrsigs = knot_node_create_rrset(qdata->node, KNOT_RRTYPE_RRSIG);
int ret = KNOT_EOK;
assert(cname_rr != NULL);
......@@ -401,7 +401,7 @@ static int name_found(knot_pkt_t *pkt, struct query_data *qdata)
uint16_t qtype = knot_pkt_qtype(pkt);
dbg_ns("%s(%p, %p)\n", __func__, pkt, qdata);
if (knot_node_rrset(qdata->node, KNOT_RRTYPE_CNAME) != NULL
if (knot_node_rrtype_exists(qdata->node, KNOT_RRTYPE_CNAME)
&& qtype != KNOT_RRTYPE_CNAME
&& qtype != KNOT_RRTYPE_RRSIG
&& qtype != KNOT_RRTYPE_ANY) {
......@@ -461,7 +461,7 @@ static int name_not_found(knot_pkt_t *pkt, struct query_data *qdata)
}
/* Name is under DNAME, use it for substitution. */
knot_rrset_t *dname_rrset = knot_node_get_rrset(qdata->encloser, KNOT_RRTYPE_DNAME);
knot_rrset_t *dname_rrset = knot_node_create_rrset(qdata->encloser, KNOT_RRTYPE_DNAME);
if (dname_rrset != NULL
&& knot_rrset_rr_count(dname_rrset) > 0) {
dbg_ns("%s: solving DNAME for name %p\n", __func__, qdata->name);
......
......@@ -263,8 +263,12 @@ static int ixfr_answer_soa(knot_pkt_t *pkt, struct query_data *qdata)
/* Guaranteed to have zone contents. */
const knot_node_t *apex = qdata->zone->contents->apex;
const knot_rrset_t *soa_rr = knot_node_rrset(apex, KNOT_RRTYPE_SOA);
int ret = knot_pkt_put(pkt, 0, soa_rr, 0);
knot_rrset_t *soa_rr = knot_node_create_rrset(apex, KNOT_RRTYPE_SOA);
if (soa_rr == NULL) {
return NS_PROC_FAIL;
}
int ret = knot_pkt_put(pkt, 0, soa_rr, KNOT_PF_FREE);
knot_rrset_free(&soa_rr, NULL);
if (ret != KNOT_EOK) {
qdata->rcode = KNOT_RCODE_SERVFAIL;
return NS_PROC_FAIL;
......
......@@ -59,8 +59,8 @@ static int ns_put_nsec3_from_node(const knot_node_t *node,
struct query_data *qdata,
knot_pkt_t *resp)
{
knot_rrset_t *rrset = knot_node_get_rrset(node, KNOT_RRTYPE_NSEC3);
knot_rrset_t *rrsigs = knot_node_get_rrset(node, KNOT_RRTYPE_RRSIG);
knot_rrset_t *rrset = knot_node_create_rrset(node, KNOT_RRTYPE_NSEC3);
knot_rrset_t *rrsigs = knot_node_create_rrset(node, KNOT_RRTYPE_RRSIG);
if (rrset == NULL) {
// bad zone, ignore
return KNOT_EOK;
......@@ -301,8 +301,8 @@ static int ns_put_nsec_wildcard(const knot_zone_contents_t *zone,
}
}
knot_rrset_t *rrset = knot_node_get_rrset(previous, KNOT_RRTYPE_NSEC);
knot_rrset_t *rrsigs = knot_node_get_rrset(previous, KNOT_RRTYPE_RRSIG);
knot_rrset_t *rrset = knot_node_create_rrset(previous, KNOT_RRTYPE_NSEC);
knot_rrset_t *rrsigs = knot_node_create_rrset(previous, KNOT_RRTYPE_RRSIG);
int ret = KNOT_EOK;
......@@ -503,8 +503,8 @@ dbg_ns_exec_verb(
);
// 1) NSEC proving that there is no node with the searched name
rrset = knot_node_get_rrset(previous, KNOT_RRTYPE_NSEC);
rrsigs = knot_node_get_rrset(previous, KNOT_RRTYPE_RRSIG);
rrset = knot_node_create_rrset(previous, KNOT_RRTYPE_NSEC);
rrsigs = knot_node_create_rrset(previous, KNOT_RRTYPE_RRSIG);
if (rrset == NULL) {
// no NSEC records
//return NS_ERR_SERVFAIL;
......@@ -556,8 +556,8 @@ dbg_ns_exec_verb(
knot_dname_free(&wildcard);
if (prev_new != previous) {
rrset = knot_node_get_rrset(prev_new, KNOT_RRTYPE_NSEC);
rrsigs = knot_node_get_rrset(prev_new, KNOT_RRTYPE_RRSIG);
rrset = knot_node_create_rrset(prev_new, KNOT_RRTYPE_NSEC);
rrsigs = knot_node_create_rrset(prev_new, KNOT_RRTYPE_RRSIG);
if (rrset == NULL) {
// bad zone, ignore
return KNOT_EOK;
......@@ -710,10 +710,10 @@ static int ns_put_nsec_nsec3_nodata(const knot_node_t *node,
}
} else {
dbg_ns("%s: adding NSEC NODATA\n", __func__);
if ((rrset = knot_node_get_rrset(node, KNOT_RRTYPE_NSEC))
if ((rrset = knot_node_create_rrset(node, KNOT_RRTYPE_NSEC))
!= NULL) {
dbg_ns_detail("Putting the RRSet to Authority\n");
knot_rrset_t *rrsigs = knot_node_get_rrset(node, KNOT_RRTYPE_RRSIG);
knot_rrset_t *rrsigs = knot_node_create_rrset(node, KNOT_RRTYPE_RRSIG);
ret = ns_put_rr(resp, rrset, rrsigs, COMPR_HINT_NONE, 0, qdata);
}
}
......@@ -766,9 +766,9 @@ int nsec_prove_dp_security(knot_pkt_t *pkt, struct query_data *qdata)
dbg_ns("%s(%p, %p)\n", __func__, pkt, qdata);
/* Add DS record if present. */
knot_rrset_t *rrset = knot_node_get_rrset(qdata->node, KNOT_RRTYPE_DS);
knot_rrset_t *rrset = knot_node_create_rrset(qdata->node, KNOT_RRTYPE_DS);
if (rrset != NULL) {
knot_rrset_t *rrsigs = knot_node_get_rrset(qdata->node, KNOT_RRTYPE_RRSIG);
knot_rrset_t *rrsigs = knot_node_create_rrset(qdata->node, KNOT_RRTYPE_RRSIG);
return ns_put_rr(pkt, rrset, rrsigs, COMPR_HINT_NONE, 0, qdata);
}
......
......@@ -51,8 +51,9 @@ int notify_create_request(const zone_t *zone, knot_pkt_t *pkt)
knot_wire_set_aa(pkt->wire);
knot_wire_set_opcode(pkt->wire, KNOT_OPCODE_NOTIFY);
const knot_rrset_t *soa_rr = knot_node_rrset(contents->apex, KNOT_RRTYPE_SOA);
return knot_pkt_put_question(pkt, soa_rr->owner, soa_rr->rclass, soa_rr->type);
knot_rrset_t soa_rr = RRSET_INIT(contents->apex, KNOT_RRTYPE_SOA);
assert(!knot_rrset_empty(&soa_rr));
return knot_pkt_put_question(pkt, soa_rr.owner, soa_rr.rclass, soa_rr.type);
}
int notify_process_response(knot_pkt_t *notify, int msgid)
......
......@@ -831,14 +831,14 @@ static bool apex_rr_changed(const knot_zone_contents_t *old_contents,
const knot_zone_contents_t *new_contents,
uint16_t type)
{
const knot_rrset_t *old_rr = knot_node_rrset(old_contents->apex, type);
const knot_rrset_t *new_rr = knot_node_rrset(new_contents->apex, type);
if (old_rr== NULL) {
return new_rr != NULL;
} else if (new_rr == NULL) {
return old_rr != NULL;
}
return !knot_rrset_equal(old_rr, new_rr, KNOT_RRSET_COMPARE_WHOLE);
knot_rrset_t old_rr = RRSET_INIT(old_contents->apex, type);
knot_rrset_t new_rr = RRSET_INIT(new_contents->apex, type);
if (knot_rrset_empty(&old_rr)) {
return !knot_rrset_empty(&new_rr);
} else if (knot_rrset_empty(&new_rr)) {
return !knot_rrset_empty(&old_rr);
}
return !knot_rrset_equal(&old_rr, &new_rr, KNOT_RRSET_COMPARE_WHOLE);
}
bool zones_dnskey_changed(const knot_zone_contents_t *old_contents,
......
......@@ -221,7 +221,7 @@ static int knot_ddns_check_exist(const knot_zone_contents_t *zone,
if (node == NULL) {
*rcode = KNOT_RCODE_NXRRSET;
return KNOT_ENONODE;
} else if (knot_node_rrset(node, knot_rrset_type(rrset)) == NULL) {
} else if (!knot_node_rrtype_exists(node, knot_rrset_type(rrset))) {
*rcode = KNOT_RCODE_NXRRSET;
return KNOT_ENORRSET;
}
......@@ -247,22 +247,20 @@ static int knot_ddns_check_exist_full(const knot_zone_contents_t *zone,
}
const knot_node_t *node;
const knot_rrset_t *found;
node = knot_zone_contents_find_node(zone, knot_rrset_owner(rrset));
if (node == NULL) {
*rcode = KNOT_RCODE_NXRRSET;
return KNOT_EPREREQ;
} else if ((found = knot_node_rrset(node, knot_rrset_type(rrset)))
== NULL) {
} else if (!knot_node_rrtype_exists(node, rrset->type)) {
*rcode = KNOT_RCODE_NXRRSET;
return KNOT_EPREREQ;
} else {
knot_rrset_t found = RRSET_INIT(node, rrset->type);
// do not have to compare the header, it is already done
assert(knot_rrset_type(found) == knot_rrset_type(rrset));
assert(knot_dname_cmp(knot_rrset_owner(found),
assert(knot_rrset_type(&found) == knot_rrset_type(rrset));
assert(knot_dname_cmp(knot_rrset_owner(&found),
knot_rrset_owner(rrset)) == 0);
if (!knot_rrset_equal(found, rrset, KNOT_RRSET_COMPARE_WHOLE)) {
if (!knot_rrset_equal(&found, rrset, KNOT_RRSET_COMPARE_WHOLE)) {
*rcode = KNOT_RCODE_NXRRSET;
return KNOT_EPREREQ;
}
......@@ -294,7 +292,7 @@ static int knot_ddns_check_not_exist(const knot_zone_contents_t *zone,
node = knot_zone_contents_find_node(zone, knot_rrset_owner(rrset));
if (node == NULL) {
return KNOT_EOK;
} else if (knot_node_rrset(node, knot_rrset_type(rrset)) == NULL) {
} else if (!knot_node_rrtype_exists(node, knot_rrset_type(rrset))) {
return KNOT_EOK;
}
......@@ -689,7 +687,7 @@ static int knot_ddns_process_add_cname(knot_node_t *node,
int ret = 0;
/* Get the current CNAME RR from the node. */
knot_rrset_t *removed = knot_node_get_rrset(node, KNOT_RRTYPE_CNAME);
knot_rrset_t *removed = knot_node_create_rrset(node, KNOT_RRTYPE_CNAME);
if (removed != NULL) {
/* If they are identical, ignore. */
......@@ -788,7 +786,7 @@ static int knot_ddns_process_add_soa(knot_node_t *node,
*/
/* Get the current SOA RR from the node. */
knot_rrset_t *removed = knot_node_get_rrset(node, KNOT_RRTYPE_SOA);
knot_rrset_t *removed = knot_node_create_rrset(node, KNOT_RRTYPE_SOA);
if (removed != NULL) {
dbg_ddns_detail("Found SOA in the node.\n");
......@@ -1064,13 +1062,13 @@ static int knot_ddns_process_add(const knot_rrset_t *rr,
log_zone_error("NSEC3PARAM RR may be added under apex name only!\n");
return KNOT_EDENIED;
}
if (knot_node_rrset(*node, KNOT_RRTYPE_NSEC3PARAM)) {
if (knot_node_rrtype_exists(*node, KNOT_RRTYPE_NSEC3PARAM)) {
/* Ignore if there is one already in the zone.*/
log_zone_warning("NSEC3PARAM already present in the zone. "
"Ignoring NSEC3PARAM from the UPDATE.\n");
return KNOT_EOK;
}
} else if (knot_node_rrset(*node, KNOT_RRTYPE_CNAME) != NULL) {
} else if (knot_node_rrtype_exists(*node, KNOT_RRTYPE_CNAME)) {
/*
* Adding RR to CNAME node. Ignore the UPDATE RR.
*
......@@ -1166,7 +1164,7 @@ static int knot_ddns_process_rem_rr(const knot_rrset_t *rr,
*/
assert(type != KNOT_RRTYPE_SOA);
int is_apex = knot_node_rrset(node, KNOT_RRTYPE_SOA) != NULL;
bool is_apex = knot_node_rrtype_exists(node, KNOT_RRTYPE_SOA);
/* If removing NS from an apex and there is only one NS left, ignore
* this removal right away. We do not have to check if the RRs match:
......@@ -1174,7 +1172,7 @@ static int knot_ddns_process_rem_rr(const knot_rrset_t *rr,
* - if they match, the last NS cannot be removed anyway.
*/
if (is_apex && type == KNOT_RRTYPE_NS
&& knot_rrset_rr_count(knot_node_rrset(node, type)) == 1) {
&& knot_rrs_rr_count(knot_node_rrs(node, type)) == 1) {
return KNOT_EOK;
}