Commit 1e8e389d authored by Jan Kadlec's avatar Jan Kadlec

new_node: Packet modifed to store rrsets directly.

- RRSet copies removed, packet now stores rrsets directly (structure is
  copied, but copy is shallow)
parent fb54f4cd
......@@ -162,7 +162,7 @@ static int cmd_remote_reply(int c)
switch(ret) {
case KNOT_RCODE_NOERROR:
if (authority->count > 0) {
ret = cmd_remote_print_reply(authority->rr[0]);
ret = cmd_remote_print_reply(&authority->rr[0]);
}
break;
case KNOT_RCODE_REFUSED:
......
......@@ -39,7 +39,7 @@
/*! \brief Remote command structure. */
typedef struct remote_cmdargs_t {
const knot_rrset_t **arg;
const knot_rrset_t *arg;
unsigned argc;
knot_rcode_t rc;
char resp[CMDARGS_BUFLEN];
......@@ -93,7 +93,7 @@ static int remote_rdata_apply(server_t *s, remote_cmdargs_t* a, remote_zonef_t *
for (unsigned i = 0; i < a->argc; ++i) {
/* Process all zones in data section. */
const knot_rrset_t *rr = a->arg[i];
const knot_rrset_t *rr = &a->arg[i];
if (knot_rrset_type(rr) != KNOT_RRTYPE_NS) {
continue;
}
......@@ -531,7 +531,7 @@ static void log_command(const char *cmd, const remote_cmdargs_t* args)
size_t rest = CMDARGS_BUFLEN_LOG;
for (unsigned i = 0; i < args->argc; i++) {
const knot_rrset_t *rr = args->arg[i];
const knot_rrset_t *rr = &args->arg[i];
if (knot_rrset_type(rr) != KNOT_RRTYPE_NS) {
continue;
}
......
......@@ -278,16 +278,16 @@ int knot_nsec_changeset_remove(const knot_node_t *n,
bool knot_nsec_empty_nsec_and_rrsigs_in_node(const knot_node_t *n)
{
assert(n);
knot_rrset_t **rrsets = knot_node_rrsets(n);
knot_rrset_t **rrsets = knot_node_create_rrsets(n);
for (int i = 0; i < n->rrset_count; ++i) {
if (rrsets[i]->type != KNOT_RRTYPE_NSEC &&
rrsets[i]->type != KNOT_RRTYPE_RRSIG) {
knot_node_free_rrset_array(n, rrsets);
knot_node_free_created_rrsets(n, rrsets);
return false;
}
}
knot_node_free_rrset_array(n, rrsets);
knot_node_free_created_rrsets(n, rrsets);
return true;
}
......
......@@ -63,7 +63,7 @@ typedef int (*chain_iterate_create_cb)(knot_node_t *, knot_node_t *,
inline static void bitmap_add_node_rrsets(bitmap_t *bitmap,
const knot_node_t *node)
{
knot_rrset_t **node_rrsets = knot_node_rrsets(node);
knot_rrset_t **node_rrsets = knot_node_create_rrsets(node);
for (int i = 0; i < node->rrset_count; i++) {
const knot_rrset_t *rr = node_rrsets[i];
if (rr->type != KNOT_RRTYPE_NSEC &&
......@@ -71,7 +71,7 @@ inline static void bitmap_add_node_rrsets(bitmap_t *bitmap,
bitmap_add_type(bitmap, rr->type);
}
}
knot_node_free_rrset_array(node, node_rrsets);
knot_node_free_created_rrsets(node, node_rrsets);
}
/*!
......
......@@ -89,7 +89,7 @@ static bool are_nsec3_nodes_equal(const knot_node_t *a, const knot_node_t *b)
*/
static bool node_should_be_signed_nsec3(const knot_node_t *n)
{
knot_rrset_t **node_rrsets = knot_node_rrsets(n);
knot_rrset_t **node_rrsets = knot_node_create_rrsets(n);
for (int i = 0; i < n->rrset_count; i++) {
if (node_rrsets[i]->type == KNOT_RRTYPE_NSEC ||
node_rrsets[i]->type == KNOT_RRTYPE_RRSIG) {
......
......@@ -495,7 +495,7 @@ static int sign_node_rrsets(const knot_node_t *node,
knot_rrset_t rrsigs;
knot_node_fill_rrset(node, KNOT_RRTYPE_RRSIG, &rrsigs);
knot_rrset_t **node_rrsets = knot_node_rrsets(node);
knot_rrset_t **node_rrsets = knot_node_create_rrsets(node);
for (int i = 0; i < node->rrset_count; i++) {
const knot_rrset_t *rrset = node_rrsets[i];
if (rrset->type == KNOT_RRTYPE_RRSIG) {
......@@ -524,7 +524,7 @@ static int sign_node_rrsets(const knot_node_t *node,
}
}
knot_node_free_rrset_array(node, node_rrsets);
knot_node_free_created_rrsets(node, node_rrsets);
return remove_standalone_rrsigs(node, &rrsigs, changeset);
}
......
......@@ -35,25 +35,23 @@ 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 | KNOT_PF_FREE;
knot_rrset_t **rrsets = knot_node_rrsets(node);
unsigned flags = KNOT_PF_NOTRUNC;
/* Append all RRs. */
for (;i < rrset_count; ++i) {
if (rrsets[i]->type == KNOT_RRTYPE_SOA) {
knot_rrset_t rrset = RRSET_INIT_N(node, i);
if (rrset.type == KNOT_RRTYPE_SOA) {
continue;
}
ret = knot_pkt_put(pkt, 0, rrsets[i], flags);
ret = knot_pkt_put(pkt, 0, &rrset, flags);
/* If something failed, remember the current RR for later. */
if (ret != KNOT_EOK) {
state->cur_rrset = i;
knot_node_free_rrset_array(node, rrsets);
return ret;
}
}
knot_node_free_rrset_array(node, rrsets);
state->cur_rrset = 0;
return ret;
}
......@@ -134,11 +132,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_create_rrset(zone->apex, KNOT_RRTYPE_SOA);
knot_rrset_t soa_rr = RRSET_INIT(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 | KNOT_PF_FREE);
ret = knot_pkt_put(pkt, 0, &soa_rr, KNOT_PF_NOTRUNC);
if (ret != KNOT_EOK) {
return ret;
}
......@@ -159,7 +157,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 | KNOT_PF_FREE);
ret = knot_pkt_put(pkt, 0, &soa_rr, KNOT_PF_NOTRUNC);
}
/* Update counters. */
......
This diff is collapsed.
......@@ -160,7 +160,7 @@ static int ixfr_query_check(struct query_data *qdata)
NS_NEED_QTYPE(qdata, KNOT_RRTYPE_IXFR, KNOT_RCODE_FORMERR);
/* Need SOA authority record. */
const knot_pktsection_t *authority = knot_pkt_section(qdata->query, KNOT_AUTHORITY);
const knot_rrset_t *their_soa = authority->rr[0];
const knot_rrset_t *their_soa = &authority->rr[0];
if (authority->count < 1 || knot_rrset_type(their_soa) != KNOT_RRTYPE_SOA) {
qdata->rcode = KNOT_RCODE_FORMERR;
return NS_PROC_FAIL;
......@@ -201,7 +201,7 @@ static int ixfr_answer_init(struct query_data *qdata)
}
/* Compare serials. */
const knot_rrset_t *their_soa = knot_pkt_section(qdata->query, KNOT_AUTHORITY)->rr[0];
const knot_rrset_t *their_soa = &knot_pkt_section(qdata->query, KNOT_AUTHORITY)->rr[0];
knot_changesets_t *chgsets = NULL;
int ret = ixfr_load_chsets(&chgsets, qdata->zone, their_soa);
if (ret != KNOT_EOK) {
......@@ -263,12 +263,11 @@ 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;
knot_rrset_t *soa_rr = knot_node_create_rrset(apex, KNOT_RRTYPE_SOA);
if (soa_rr == NULL) {
knot_rrset_t soa_rr = RRSET_INIT(apex, KNOT_RRTYPE_SOA);
if (knot_rrset_empty(&soa_rr)) {
return NS_PROC_FAIL;
}
int ret = knot_pkt_put(pkt, 0, soa_rr, KNOT_PF_FREE);
knot_rrset_free(&soa_rr, NULL);
int ret = knot_pkt_put(pkt, 0, &soa_rr, 0);
if (ret != KNOT_EOK) {
qdata->rcode = KNOT_RCODE_SERVFAIL;
return NS_PROC_FAIL;
......
......@@ -59,18 +59,15 @@ 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_create_rrset(node, KNOT_RRTYPE_NSEC3);
knot_rrset_t *rrsigs = knot_node_create_rrset(node, KNOT_RRTYPE_RRSIG);
if (rrset == NULL) {
knot_rrset_t rrset = RRSET_INIT(node, KNOT_RRTYPE_NSEC3);
knot_rrset_t rrsigs = RRSET_INIT(node, KNOT_RRTYPE_RRSIG);
if (knot_rrset_empty(&rrset)) {
// bad zone, ignore
return KNOT_EOK;
}
int res = KNOT_EOK;
if (knot_rrset_rr_count(rrset) > 0) {
res = ns_put_rr(resp, rrset, rrsigs, COMPR_HINT_NONE,
KNOT_PF_CHECKDUP, qdata);
}
int res = ns_put_rr(resp, &rrset, &rrsigs, COMPR_HINT_NONE,
KNOT_PF_CHECKDUP, qdata);
/*! \note TC bit is already set, if something went wrong. */
......@@ -301,14 +298,13 @@ static int ns_put_nsec_wildcard(const knot_zone_contents_t *zone,
}
}
knot_rrset_t *rrset = knot_node_create_rrset(previous, KNOT_RRTYPE_NSEC);
knot_rrset_t *rrsigs = knot_node_create_rrset(previous, KNOT_RRTYPE_RRSIG);
knot_rrset_t rrset = RRSET_INIT(previous, KNOT_RRTYPE_NSEC);
int ret = KNOT_EOK;
if (rrset != NULL && knot_rrset_rr_count(rrset) > 0) {
if (!knot_rrset_empty(&rrset)) {
knot_rrset_t rrsigs = RRSET_INIT(previous, KNOT_RRTYPE_RRSIG);
// NSEC proving that there is no node with the searched name
ret = ns_put_rr(resp, rrset, rrsigs, COMPR_HINT_NONE, 0, qdata);
ret = ns_put_rr(resp, &rrset, &rrsigs, COMPR_HINT_NONE, 0, qdata);
}
return ret;
......@@ -478,8 +474,8 @@ static int ns_put_nsec_nxdomain(const knot_dname_t *qname,
struct query_data *qdata,
knot_pkt_t *resp)
{
knot_rrset_t *rrset = NULL;
knot_rrset_t *rrsigs = NULL;
knot_rrset_t rrset = { 0 };
knot_rrset_t rrsigs = { 0 };
// check if we have previous; if not, find one using the tree
if (previous == NULL) {
......@@ -503,16 +499,15 @@ dbg_ns_exec_verb(
);
// 1) NSEC proving that there is no node with the searched name
rrset = knot_node_create_rrset(previous, KNOT_RRTYPE_NSEC);
rrsigs = knot_node_create_rrset(previous, KNOT_RRTYPE_RRSIG);
if (rrset == NULL) {
knot_node_fill_rrset(previous, KNOT_RRTYPE_NSEC, &rrset);
knot_node_fill_rrset(previous, KNOT_RRTYPE_RRSIG, &rrsigs);
if (knot_rrset_empty(&rrset)) {
// no NSEC records
//return NS_ERR_SERVFAIL;
return KNOT_EOK;
}
int ret = ns_put_rr(resp, rrset, rrsigs, COMPR_HINT_NONE, 0, qdata);
int ret = ns_put_rr(resp, &rrset, &rrsigs, COMPR_HINT_NONE, 0, qdata);
if (ret != KNOT_EOK) {
dbg_ns("Failed to add NSEC for NXDOMAIN to response: %s\n",
knot_strerror(ret));
......@@ -556,13 +551,13 @@ dbg_ns_exec_verb(
knot_dname_free(&wildcard);
if (prev_new != previous) {
rrset = knot_node_create_rrset(prev_new, KNOT_RRTYPE_NSEC);
rrsigs = knot_node_create_rrset(prev_new, KNOT_RRTYPE_RRSIG);
if (rrset == NULL) {
knot_node_fill_rrset(prev_new, KNOT_RRTYPE_NSEC, &rrset);
knot_node_fill_rrset(prev_new, KNOT_RRTYPE_RRSIG, &rrsigs);
if (knot_rrset_empty(&rrset)) {
// bad zone, ignore
return KNOT_EOK;
}
ret = ns_put_rr(resp, rrset, rrsigs, COMPR_HINT_NONE, 0, qdata);
ret = ns_put_rr(resp, &rrset, &rrsigs, COMPR_HINT_NONE, 0, qdata);
if (ret != KNOT_EOK) {
dbg_ns("Failed to add second NSEC for NXDOMAIN to "
"response: %s\n", knot_strerror(ret));
......@@ -681,8 +676,6 @@ static int ns_put_nsec_nsec3_nodata(const knot_node_t *node,
/*! \todo Maybe distinguish different errors. */
int ret = KNOT_ERROR;
knot_rrset_t *rrset = NULL;
if (knot_is_nsec3_enabled(zone)) {
/* RFC5155 7.2.5 Wildcard No Data Responses */
......@@ -710,11 +703,11 @@ 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_create_rrset(node, KNOT_RRTYPE_NSEC))
!= NULL) {
knot_rrset_t rrset = RRSET_INIT(node, KNOT_RRTYPE_NSEC);
if (!knot_rrset_empty(&rrset)) {
dbg_ns_detail("Putting the RRSet to Authority\n");
knot_rrset_t *rrsigs = knot_node_create_rrset(node, KNOT_RRTYPE_RRSIG);
ret = ns_put_rr(resp, rrset, rrsigs, COMPR_HINT_NONE, 0, qdata);
knot_rrset_t rrsigs = RRSET_INIT(node, KNOT_RRTYPE_RRSIG);
ret = ns_put_rr(resp, &rrset, &rrsigs, COMPR_HINT_NONE, 0, qdata);
}
}
......@@ -766,10 +759,10 @@ 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_create_rrset(qdata->node, KNOT_RRTYPE_DS);
if (rrset != NULL) {
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);
knot_rrset_t rrset = RRSET_INIT(qdata->node, KNOT_RRTYPE_DS);
if (!knot_rrset_empty(&rrset)) {
knot_rrset_t rrsigs = RRSET_INIT(qdata->node, KNOT_RRTYPE_RRSIG);
return ns_put_rr(pkt, &rrset, &rrsigs, COMPR_HINT_NONE, 0, qdata);
}
/* DS doesn't exist => NODATA proof. */
......@@ -791,13 +784,14 @@ int nsec_append_rrsigs(knot_pkt_t *pkt, struct query_data *qdata, bool optional)
/* Append RRSIGs for section. */
struct rrsig_info *info = NULL;
WALK_LIST(info, qdata->rrsigs) {
knot_rrset_t *rrsig = info->synth_rrsig;
knot_rrset_t *rrsig = &info->synth_rrsig;
uint16_t compr_hint = info->rrinfo->compress_ptr[COMPR_HINT_OWNER];
ret = knot_pkt_put(pkt, compr_hint, rrsig, flags);
if (ret != KNOT_EOK) {
break;
}
info->synth_rrsig = NULL; /* RRSIG is owned by packet now. */
/* RRSIG is owned by packet now. */
knot_rrs_init(&info->synth_rrsig.rrs);
};
/* Clear the list. */
......@@ -814,8 +808,8 @@ void nsec_clear_rrsigs(struct query_data *qdata)
struct rrsig_info *info = NULL;
WALK_LIST(info, qdata->rrsigs) {
knot_rrset_t *rrsig = info->synth_rrsig;
knot_rrset_free(&rrsig, qdata->mm);
knot_rrset_t *rrsig = &info->synth_rrsig;
knot_rrs_clear(&rrsig->rrs, qdata->mm);
};
ptrlist_free(&qdata->rrsigs, qdata->mm);
......
......@@ -108,7 +108,7 @@ struct wildcard_hit {
/*! \brief RRSIG info node list. */
struct rrsig_info {
node_t n;
knot_rrset_t *synth_rrsig; /* Synthesized RRSIG. */
knot_rrset_t synth_rrsig; /* Synthesized RRSIG. */
knot_rrinfo_t *rrinfo; /* RR info. */
};
......
......@@ -94,7 +94,7 @@ int internet_notify(knot_pkt_t *pkt, struct query_data *qdata)
unsigned serial = 0;
const knot_pktsection_t *answer = knot_pkt_section(qdata->query, KNOT_ANSWER);
if (answer->count > 0) {
const knot_rrset_t *soa = answer->rr[0];
const knot_rrset_t *soa = &answer->rr[0];
if (knot_rrset_type(soa) == KNOT_RRTYPE_SOA) {
serial = knot_rrs_soa_serial(&soa->rrs);
dbg_ns("%s: received serial %u\n", __func__, serial);
......
......@@ -412,7 +412,7 @@ int knot_ddns_process_prereqs(const knot_pkt_t *query,
// packet will be destroyed
dbg_ddns_detail("Creating prereqs from following RRSet:\n");
ret = knot_ddns_add_prereq(*prereqs,
answer->rr[i],
&answer->rr[i],
knot_pkt_qclass(query));
if (ret != KNOT_EOK) {
dbg_ddns("Failed to add prerequisity RRSet:%s\n",
......@@ -1522,7 +1522,7 @@ static int knot_ddns_process_rem_all(knot_node_t *node,
*/
int ret = 0;
// The copy of rrsets is important here.
knot_rrset_t **rrsets = knot_node_rrsets(node);
knot_rrset_t **rrsets = knot_node_create_rrsets(node);
int count = knot_node_rrset_count(node);
if (rrsets == NULL && count != 0) {
......@@ -1676,7 +1676,7 @@ int knot_ddns_process_update(knot_zone_contents_t *zone,
const knot_pktsection_t *authority = knot_pkt_section(query, KNOT_AUTHORITY);
for (int i = 0; i < authority->count; ++i) {
rr = authority->rr[i];
rr = &authority->rr[i];
/* Check if the entry is correct. */
ret = knot_ddns_check_update(rr, query, rcode);
......
......@@ -89,11 +89,11 @@ dbg_xfrin_exec(
// the SOA should be the first (and only) RRSet in the response
const knot_pktsection_t *answer = knot_pkt_section(soa_response, KNOT_ANSWER);
if (answer->count < 1 || knot_rrset_type(answer->rr[0]) != KNOT_RRTYPE_SOA) {
if (answer->count < 1 || knot_rrset_type(&answer->rr[0]) != KNOT_RRTYPE_SOA) {
return KNOT_EMALF;
}
int64_t remote_serial = knot_rrs_soa_serial(&answer->rr[0]->rrs);
int64_t remote_serial = knot_rrs_soa_serial(&answer->rr[0].rrs);
if (remote_serial < 0) {
return KNOT_EMALF; // maybe some other error
}
......@@ -231,7 +231,7 @@ static int xfrin_take_rr(const knot_pktsection_t *answer, knot_rrset_t **rr, uin
{
int ret = KNOT_EOK;
if (*cur < answer->count) {
ret = knot_rrset_copy(answer->rr[*cur], rr, NULL);
ret = knot_rrset_copy(&answer->rr[*cur], rr, NULL);
*cur += 1;
} else {
*rr = NULL;
......
......@@ -209,6 +209,7 @@ int knot_node_add_rrset(knot_node_t *node, knot_rrset_t *rrset,
for (uint16_t i = 0; i < node->rrset_count; ++i) {
if (node->rrs[i].type == rrset->type) {
// TODO this is obviously a workaround
knot_rrset_t *node_rrset = rrset_from_rr_data(node, i, NULL);
if (node_rrset == NULL) {
......@@ -310,7 +311,7 @@ short knot_node_rrset_count(const knot_node_t *node)
/*----------------------------------------------------------------------------*/
knot_rrset_t **knot_node_rrsets(const knot_node_t *node)
knot_rrset_t **knot_node_create_rrsets(const knot_node_t *node)
{
if (node == NULL || node->rrset_count == 0) {
return NULL;
......@@ -322,7 +323,7 @@ knot_rrset_t **knot_node_rrsets(const knot_node_t *node)
for (int i = 0; i < node->rrset_count; ++i) {
cpy[i] = rrset_from_rr_data(node, i, NULL);
if (cpy[i] == NULL) {
knot_node_free_rrset_array(node, cpy);
knot_node_free_created_rrsets(node, cpy);
return NULL;
}
}
......@@ -680,10 +681,11 @@ void knot_node_free_rrsets(knot_node_t *node)
for (uint16_t i = 0; i < node->rrset_count; ++i) {
knot_rrs_clear(&node->rrs[i].rrs, NULL);
mm_free(NULL, node->rrs[i].additional);
}
}
void knot_node_free_rrset_array(const knot_node_t *node, knot_rrset_t **rrsets)
void knot_node_free_created_rrsets(const knot_node_t *node, knot_rrset_t **rrsets)
{
if (node == NULL) {
return;
......@@ -786,7 +788,7 @@ static void clear_rrset(knot_rrset_t *rrset)
rrset->owner = NULL;
rrset->type = 0;
rrset->rclass = KNOT_CLASS_IN;
knot_rrs_clear(&rrset->rrs, NULL);
knot_rrs_init(&rrset->rrs);
rrset->additional = NULL;
}
......@@ -804,7 +806,7 @@ void knot_node_fill_rrset(const knot_node_t *node, uint16_t type,
rrset->type = type;
rrset->rclass = KNOT_CLASS_IN;
rrset->rrs = node->rrs[i].rrs;
rrset->additional = NULL;
rrset->additional = node->rrs->additional;
}
}
if (!hit) {
......@@ -824,6 +826,6 @@ void knot_node_fill_rrset_pos(const knot_node_t *node, size_t pos,
rrset->type = rr_data->type;
rrset->rclass = KNOT_CLASS_IN;
rrset->rrs = rr_data->rrs;
rrset->additional = NULL;
rrset->additional = rr_data->additional;
}
......@@ -177,7 +177,7 @@ short knot_node_rrset_count(const knot_node_t *node);
*
* \return Newly allocated array of RRSets or NULL if an error occured.
*/
knot_rrset_t **knot_node_rrsets(const knot_node_t *node);
knot_rrset_t **knot_node_create_rrsets(const knot_node_t *node);
int knot_node_count_rrsets(const knot_node_t *node);
......@@ -376,7 +376,7 @@ void knot_node_clear_empty(knot_node_t *node);
* \param node Node to be destroyed.
*/
void knot_node_free_rrsets(knot_node_t *node);
void knot_node_free_rrset_array(const knot_node_t *node, knot_rrset_t **rrsets);
void knot_node_free_created_rrsets(const knot_node_t *node, knot_rrset_t **rrsets);
/*!
* \brief Destroys the node structure.
......@@ -432,6 +432,16 @@ static inline struct rr_data *knot_node_rr_data(const knot_node_t *node,
return &EMPTY_DATA;
}
static inline struct rr_data *knot_node_rr_data_n(const knot_node_t *node,
size_t pos)
{
if (node == NULL || pos >= node->rrset_count) {
return &EMPTY_DATA;
}
return &node->rrs[pos];
}
#define _RRSET_INIT(node, rr_data) \
{.owner = node->owner,\
.type = rr_data->type,\
......@@ -441,6 +451,8 @@ static inline struct rr_data *knot_node_rr_data(const knot_node_t *node,
#define RRSET_INIT(node, type) _RRSET_INIT(node, knot_node_rr_data(node, type))
#define RRSET_INIT_N(node, pos) _RRSET_INIT(node, knot_node_rr_data_n(node, pos))
#endif /* _KNOT_NODE_H_ */
/*! @} */
......@@ -169,7 +169,7 @@ static int knot_zone_diff_add_node(const knot_node_t *node,
}
/* Add all rrsets from node. */
knot_rrset_t **rrsets = knot_node_rrsets(node);
knot_rrset_t **rrsets = knot_node_create_rrsets(node);
if (rrsets == NULL) {
/* Empty non-terminals - legal case. */
dbg_zonediff_detail("zone_diff: Node has no RRSets.\n");
......@@ -188,7 +188,7 @@ static int knot_zone_diff_add_node(const knot_node_t *node,
}
}
knot_node_free_rrset_array(node, rrsets);
knot_node_free_created_rrsets(node, rrsets);
return KNOT_EOK;
}
......@@ -203,7 +203,7 @@ static int knot_zone_diff_remove_node(knot_changeset_t *changeset,
dbg_zonediff("zone_diff: remove_node: Removing node: ...\n");
knot_rrset_t **rrsets = knot_node_rrsets(node);
knot_rrset_t **rrsets = knot_node_create_rrsets(node);
if (rrsets == NULL) {
dbg_zonediff_verb("zone_diff: remove_node: "
"Nothing to remove.\n");
......@@ -226,7 +226,7 @@ static int knot_zone_diff_remove_node(knot_changeset_t *changeset,
}
}
knot_node_free_rrset_array(node, rrsets);
knot_node_free_created_rrsets(node, rrsets);
return KNOT_EOK;
}
......@@ -416,7 +416,7 @@ static int knot_zone_diff_node(knot_node_t **node_ptr, void *data)
dbg_zonediff_detail("zone_diff: diff_node: Node %p is present in "
"both trees.\n", node_owner);
/* The nodes are in both trees, we have to diff each RRSet. */
knot_rrset_t **rrsets = knot_node_rrsets(node);
knot_rrset_t **rrsets = knot_node_create_rrsets(node);
if (rrsets == NULL) {
dbg_zonediff("zone_diff: Node in first tree has no RRSets.\n");
/*
......@@ -476,10 +476,10 @@ static int knot_zone_diff_node(knot_node_t **node_ptr, void *data)
}
}
knot_node_free_rrset_array(node, rrsets);
knot_node_free_created_rrsets(node, rrsets);
/*! \todo move to one function with the code above. */
rrsets = knot_node_rrsets(node_in_second_tree);
rrsets = knot_node_create_rrsets(node_in_second_tree);
if (rrsets == NULL) {
return KNOT_EOK;
}
......@@ -507,7 +507,7 @@ static int knot_zone_diff_node(knot_node_t **node_ptr, void *data)
if (ret != KNOT_EOK) {
dbg_zonediff("zone_diff: diff_node: "
"Failed to add RRSet.\n");
knot_node_free_rrset_array(node, rrsets);
knot_node_free_created_rrsets(node, rrsets);
return ret;
}
} else {
......@@ -516,7 +516,7 @@ static int knot_zone_diff_node(knot_node_t **node_ptr, void *data)
}
}
knot_node_free_rrset_array(node, rrsets);
knot_node_free_created_rrsets(node, rrsets);
return KNOT_EOK;
}
......
......@@ -55,7 +55,7 @@ static int apex_node_dump_text(knot_node_t *node, dump_params_t *params)
params->buf[0] = '\0';
}
knot_rrset_t **rrsets = knot_node_rrsets(node);
knot_rrset_t **rrsets = knot_node_create_rrsets(node);
// Dump other records.
for (uint16_t i = 0; i < node->rrset_count; i++) {
......@@ -72,7 +72,7 @@ static int apex_node_dump_text(knot_node_t *node, dump_params_t *params)
if (knot_rrset_txt_dump(rrsets[i], params->buf, params->buflen,
params->style) < 0) {
knot_node_free_rrset_array(node, rrsets);
knot_node_free_created_rrsets(node, rrsets);
return KNOT_ENOMEM;
}
params->rr_count += knot_rrset_rr_count(rrsets[i]);
......@@ -80,7 +80,7 @@ static int apex_node_dump_text(knot_node_t *node, dump_params_t *params)
params->buf[0] = '\0';
}
knot_node_free_rrset_array(node, rrsets);
knot_node_free_created_rrsets(node, rrsets);
return KNOT_EOK;
}
......@@ -95,7 +95,7 @@ static int node_dump_text(knot_node_t *node, void *data)
return KNOT_EOK;
}
knot_rrset_t **rrsets = knot_node_rrsets(node);
knot_rrset_t **rrsets = knot_node_create_rrsets(node);
// Dump non-apex rrsets.
for (uint16_t i = 0; i < node->rrset_count; i++) {
......@@ -124,7 +124,7 @@ static int node_dump_text(knot_node_t *node, void *data)
if (knot_rrset_txt_dump(rrsets[i], params->buf, params->buflen,
params->style) < 0) {
knot_node_free_rrset_array(node, rrsets);
knot_node_free_created_rrsets(node, rrsets);
return KNOT_ENOMEM;
}
params->rr_count += knot_rrset_rr_count(rrsets[i]);
......@@ -132,7 +132,7 @@ static int node_dump_text(knot_node_t *node, void *data)
params->buf[0] = '\0';
}
knot_node_free_rrset_array(node, rrsets);
knot_node_free_created_rrsets(node, rrsets);
return KNOT_EOK;
}
......
......@@ -28,14 +28,15 @@
/*! \brief Scan packet for RRSet existence. */
static bool pkt_contains(const knot_pkt_t *packet,
const knot_rrset_t *rrset,
knot_rrset_compare_type_t cmp)
const knot_rrset_t *rrset)
{
assert(packet);
assert(rrset);
for (int i = 0; i < packet->rrset_count; ++i) {
if (knot_rrset_equal(packet->rr[i], rrset, cmp)) {
const uint16_t type = packet->rr[i].type;
const uint8_t *data = packet->rr[i].rrs.data;
if (type == rrset->type && data == rrset->rrs.data) {
return true;
}
}
......@@ -50,11 +51,9 @@ static void pkt_free_data(knot_pkt_t *pkt)
assert(pkt);
/* Free RRSets if applicable. */
knot_rrset_t *rr = NULL;
for (uint16_t i = 0; i < pkt->rrset_count; ++i) {
if (pkt->rr_info[i].flags & KNOT_PF_FREE) {
rr = (knot_rrset_t *)pkt->rr[i];
knot_rrset_free(&rr, &pkt->mm);
knot_rrs_clear(&pkt->rr[i].rrs, &pkt->mm);
}
}
......@@ -506,11 +505,11 @@ int knot_pkt_put(knot_pkt_t *pkt, uint16_t compr_hint, const knot_rrset_t *rr, u
rrinfo->pos = pkt->size;
rrinfo->flags = flags;
rrinfo->compress_ptr[0] = compr_hint;
pkt->rr[pkt->rrset_count] = rr;
pkt->rr[pkt->rrset_count] = *rr;
/* Check for double insertion. */
if ((flags & KNOT_PF_CHECKDUP) &&
pkt_contains(pkt, rr, KNOT_RRSET_COMPARE_PTR)) {
pkt_contains(pkt, rr)) {
return KNOT_EOK; /*! \todo return rather a number of added RRs */
}
......@@ -643,10 +642,10 @@ static int knot_pkt_merge_rr(knot_pkt_t *pkt, knot_rrset_t *rr, unsigned flags)
// try to find the RRSet in this array of RRSets
for (int i = 0; i < pkt->rrset_count; ++i) {
if (knot_rrset_equal(pkt->rr[i], rr, KNOT_RRSET_COMPARE_HEADER)) {
if (knot_rrset_equal(&pkt->rr[i], rr, KNOT_RRSET_COMPARE_HEADER)) {
int merged = 0;
int deleted_rrs = 0;
int rc = knot_rrset_merge_sort((knot_rrset_t *)pkt->rr[i],
int rc = knot_rrset_merge_sort((knot_rrset_t *)&pkt->rr[i],
rr, &merged, &deleted_rrs,
&pkt->mm);
if (rc != KNOT_EOK) {
......@@ -759,7 +758,7 @@ int knot_pkt_parse_rr(knot_pkt_t *pkt, unsigned flags)
}
/* Append to RR list. */
pkt->rr[pkt->rrset_count] = rr;
pkt->rr[pkt->rrset_count] = *rr;
++pkt->rrset_count;
/* Update section RRSet count. */
......@@ -854,7 +853,7 @@ int knot_pkt_parse_payload(knot_pkt_t *pkt, unsigned flags)
/* TSIG must be last record of AR if present. */
const knot_pktsection_t *ar = knot_pkt_section(pkt, KNOT_ADDITIONAL);
if (pkt->tsig_rr != NULL) {