Commit ca6b2810 authored by Jan Kadlec's avatar Jan Kadlec

new_node: Remove unnecessary rrset allocations, removed changes from

updates.

- DDNS and changeset application will not work now, but it wouldn't work
  before either
parent 633befbb
......@@ -100,14 +100,13 @@ 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_create_rrset(b, KNOT_RRTYPE_NSEC);
int ret = 0;
/*!
* If the node has no other RRSets than NSEC (and possibly RRSIGs),
* just remove the NSEC and its RRSIG, they are redundant
*/
if (old_next_nsec != NULL
if (knot_node_rrtype_exists(b, KNOT_RRTYPE_NSEC)
&& knot_nsec_empty_nsec_and_rrsigs_in_node(b)) {
ret = knot_nsec_changeset_remove(b, data->changeset);
if (ret != KNOT_EOK) {
......@@ -124,9 +123,9 @@ static int connect_nsec_nodes(knot_node_t *a, knot_node_t *b,
return KNOT_ENOMEM;
}
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_t old_nsec = RRSET_INIT(a, KNOT_RRTYPE_NSEC);
if (!knot_rrset_empty(&old_nsec)) {
if (knot_rrset_equal(new_nsec, &old_nsec,
KNOT_RRSET_COMPARE_WHOLE)) {
// current NSEC is valid, do nothing
dbg_dnssec_detail("NSECs equal.\n");
......@@ -221,9 +220,6 @@ int knot_nsec_changeset_remove(const knot_node_t *n,
if (nsec == NULL) {
nsec = knot_node_create_rrset(n, KNOT_RRTYPE_NSEC3);
}
if (nsec == NULL) {
return KNOT_ENOMEM;
}
knot_rrset_t *rrsigs = knot_node_create_rrset(n, KNOT_RRTYPE_RRSIG);
if (nsec) {
// update changeset
......@@ -279,16 +275,14 @@ 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_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_created_rrsets(n, rrsets);
knot_rrset_t rrset = RRSET_INIT_N(n, i);
if (rrset.type != KNOT_RRTYPE_NSEC &&
rrset.type != KNOT_RRTYPE_RRSIG) {
return false;
}
}
knot_node_free_created_rrsets(n, rrsets);
return true;
}
......
......@@ -89,14 +89,14 @@ 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_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) {
knot_rrset_t rrset = RRSET_INIT_N(n, i);
if (rrset.type == KNOT_RRTYPE_NSEC ||
rrset.type == KNOT_RRTYPE_RRSIG) {
continue;
}
bool should_sign = false;
int ret = knot_zone_sign_rr_should_be_signed(n, node_rrsets[i],
int ret = knot_zone_sign_rr_should_be_signed(n, &rrset,
&should_sign);
assert(ret == KNOT_EOK); // No tree inside the function, no fail
if (should_sign) {
......@@ -122,7 +122,9 @@ static int shallow_copy_signature(const knot_node_t *from, knot_node_t *to)
if (from_sig == NULL) {
return KNOT_EOK;
}
return knot_node_add_rrset(to, from_sig, NULL);
int ret = knot_node_add_rrset(to, from_sig);
knot_rrset_free(&from_sig, NULL);
return ret;
}
/*!
......@@ -176,9 +178,8 @@ 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_create_rrset(node,
KNOT_RRTYPE_NSEC3);
knot_rrset_free(&nsec3, NULL);
knot_rrs_t *nsec3 = knot_node_get_rrs(node, KNOT_RRTYPE_NSEC3);
knot_rrs_clear(nsec3, NULL);
knot_node_free(&node);
}
......
......@@ -495,14 +495,13 @@ 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_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) {
knot_rrset_t rrset = RRSET_INIT_N(node, i);
if (rrset.type == KNOT_RRTYPE_RRSIG) {
continue;
}
bool should_sign = false;
result = knot_zone_sign_rr_should_be_signed(node, rrset,
result = knot_zone_sign_rr_should_be_signed(node, &rrset,
&should_sign);
if (result != KNOT_EOK) {
return result;
......@@ -512,10 +511,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);
}
......@@ -524,8 +523,6 @@ static int sign_node_rrsets(const knot_node_t *node,
}
}
knot_node_free_created_rrsets(node, node_rrsets);
return remove_standalone_rrsigs(node, &rrsigs, changeset);
}
......@@ -1467,7 +1464,7 @@ int knot_zone_sign_rr_should_be_signed(const knot_node_t *node,
}
*should_sign = false; // Only one case at the end is set to true
if (node == NULL || rrset == NULL) {
if (node == NULL || knot_rrset_empty(rrset)) {
return KNOT_EOK;
}
......
......@@ -207,13 +207,12 @@ static int knot_ns_process_update(const knot_pkt_t *query,
dbg_ns_verb("Applying the UPDATE and creating changeset...\n");
ret = knot_ddns_process_update(contents_copy, query,
knot_changesets_get_last(chgs),
chgs->changes, rcode, new_serial);
rcode, new_serial);
if (ret != KNOT_EOK) {
dbg_ns("Failed to apply UPDATE to the zone copy or no update"
" made: %s\n", (ret < 0) ? knot_strerror(ret)
: "No change made.");
xfrin_rollback_update(old_contents, &contents_copy,
chgs->changes);
xfrin_rollback_update(old_contents, &contents_copy);
return ret;
}
......@@ -223,8 +222,7 @@ static int knot_ns_process_update(const knot_pkt_t *query,
if (ret != KNOT_EOK) {
dbg_ns("Failed to finalize updated zone: %s\n",
knot_strerror(ret));
xfrin_rollback_update(old_contents, &contents_copy,
chgs->changes);
xfrin_rollback_update(old_contents, &contents_copy);
*rcode = (ret == KNOT_EMALF) ? KNOT_RCODE_FORMERR
: KNOT_RCODE_SERVFAIL;
return ret;
......@@ -326,8 +324,7 @@ static int zones_process_update_auth(struct query_data *qdata)
sec_chs = knot_changesets_create();
sec_ch = knot_changesets_create_changeset(sec_chs);
if (sec_chs == NULL || sec_ch == NULL) {
xfrin_rollback_update(old_contents, &new_contents,
chgsets->changes);
xfrin_rollback_update(old_contents, &new_contents);
knot_changesets_free(&chgsets);
free(msg);
return KNOT_ENOMEM;
......@@ -360,8 +357,7 @@ static int zones_process_update_auth(struct query_data *qdata)
if (ret != KNOT_EOK) {
log_zone_error("%s: Failed to sign incoming update (%s)"
"\n", msg, knot_strerror(ret));
xfrin_rollback_update(old_contents, &new_contents,
chgsets->changes);
xfrin_rollback_update(old_contents, &new_contents);
knot_changesets_free(&chgsets);
knot_changesets_free(&sec_chs);
free(msg);
......@@ -376,8 +372,7 @@ static int zones_process_update_auth(struct query_data *qdata)
if (ret != KNOT_EOK) {
log_zone_error("%s: Failed to save new entry to journal (%s)\n",
msg, knot_strerror(ret));
xfrin_rollback_update(old_contents, &new_contents,
chgsets->changes);
xfrin_rollback_update(old_contents, &new_contents);
zones_free_merged_changesets(chgsets, sec_chs);
free(msg);
return ret;
......@@ -414,8 +409,7 @@ static int zones_process_update_auth(struct query_data *qdata)
if (ret != KNOT_EOK) {
zones_store_changesets_rollback(transaction);
zones_free_merged_changesets(chgsets, sec_chs);
xfrin_rollback_update(old_contents, &new_contents,
chgsets->changes);
xfrin_rollback_update(old_contents, &new_contents);
free(msg);
return ret;
}
......@@ -427,8 +421,7 @@ static int zones_process_update_auth(struct query_data *qdata)
if (ret != KNOT_EOK) {
log_zone_error("%s: Failed to commit new journal entry "
"(%s).\n", msg, knot_strerror(ret));
xfrin_rollback_update(old_contents, &new_contents,
chgsets->changes);
xfrin_rollback_update(old_contents, &new_contents);
zones_free_merged_changesets(chgsets, sec_chs);
free(msg);
return ret;
......@@ -444,8 +437,7 @@ static int zones_process_update_auth(struct query_data *qdata)
log_zone_error("%s: Failed to replace current zone (%s)\n",
msg, knot_strerror(ret));
// Cleanup old and new contents
xfrin_rollback_update(old_contents, &new_contents,
chgsets->changes);
xfrin_rollback_update(old_contents, &new_contents);
/* Free changesets, but not the data. */
zones_free_merged_changesets(chgsets, sec_chs);
......@@ -455,9 +447,9 @@ static int zones_process_update_auth(struct query_data *qdata)
}
// Cleanup.
xfrin_cleanup_successful_update(chgsets->changes);
xfrin_cleanup_successful_update(NULL);
if (sec_chs) {
xfrin_cleanup_successful_update(sec_chs->changes);
xfrin_cleanup_successful_update(NULL);
}
// Free changesets, but not the data.
......
......@@ -1478,8 +1478,7 @@ int zones_store_and_apply_chgsets(knot_changesets_t *chs,
/* Commit transaction. */
ret = zones_store_changesets_commit(transaction);
if (ret != KNOT_EOK) {
xfrin_rollback_update(zone->contents, new_contents,
chs->changes);
xfrin_rollback_update(zone->contents, new_contents);
log_zone_error("%s Failed to commit stored changesets.\n", msgpref);
knot_changesets_free(&chs);
return ret;
......@@ -1495,15 +1494,14 @@ int zones_store_and_apply_chgsets(knot_changesets_t *chs,
if (switch_ret != KNOT_EOK) {
log_zone_error("%s Failed to replace current zone.\n", msgpref);
// Cleanup old and new contents
xfrin_rollback_update(zone->contents, new_contents,
chs->changes);
xfrin_rollback_update(zone->contents, new_contents);
/* Free changesets, but not the data. */
knot_changesets_free(&chs);
return KNOT_ERROR;
}
xfrin_cleanup_successful_update(chs->changes);
xfrin_cleanup_successful_update(NULL);
/* Free changesets, but not the data. */
knot_changesets_free(&chs);
......@@ -1926,8 +1924,7 @@ int zones_journal_apply(zone_t *zone)
XFR_TYPE_IIN);
rcu_read_lock();
if (apply_ret == KNOT_EOK) {
xfrin_cleanup_successful_update(
chsets->changes);
xfrin_cleanup_successful_update(NULL);
} else {
log_zone_error("Failed to apply "
"changesets to '%s' - Switch failed: "
......@@ -1937,8 +1934,7 @@ int zones_journal_apply(zone_t *zone)
// Cleanup old and new contents
xfrin_rollback_update(zone->contents,
&contents,
chsets->changes);
&contents);
}
}
}
......@@ -2020,7 +2016,6 @@ static int diff_after_load(zone_t *zone, zone_t *old_zone,
assert(!zones_changesets_empty(*diff_chs));
/* Apply DNSSEC changeset to the new zone. */
ret = xfrin_apply_changesets_directly(zone->contents,
(*diff_chs)->changes,
*diff_chs);
if (ret == KNOT_EOK) {
......@@ -2038,7 +2033,7 @@ static int diff_after_load(zone_t *zone, zone_t *old_zone,
return ret;
}
xfrin_cleanup_successful_update((*diff_chs)->changes);
xfrin_cleanup_successful_update(NULL);
knot_changesets_free(diff_chs);
assert(zone->conf->build_diffs);
}
......@@ -2109,7 +2104,6 @@ static int store_chgsets_after_load(zone_t *old_zone, zone_t *zone,
assert(!old_zone ||
old_zone->contents != zone->contents);
ret = xfrin_apply_changesets_directly(zone->contents,
diff_chs->changes,
diff_chs);
if (ret == KNOT_EOK) {
ret = xfrin_finalize_updated_zone(
......@@ -2133,7 +2127,7 @@ static int store_chgsets_after_load(zone_t *old_zone, zone_t *zone,
return ret;
}
xfrin_cleanup_successful_update(diff_chs->changes);
xfrin_cleanup_successful_update(NULL);
}
/* Commit transaction. */
......@@ -2162,8 +2156,7 @@ static int store_chgsets_after_load(zone_t *old_zone, zone_t *zone,
"switching zone (%s).\n",
zone->conf->name, knot_strerror(ret));
// Cleanup old and new contents
xfrin_rollback_update(zone->contents, &new_contents,
diff_chs->changes);
xfrin_rollback_update(zone->contents, &new_contents);
return ret;
}
......
......@@ -54,14 +54,6 @@ int knot_changesets_init(knot_changesets_t **changesets)
// Init list with changesets
init_list(&(*changesets)->sets);
// Init changes structure
(*changesets)->changes = xmalloc(sizeof(knot_changes_t));
// Init changes' allocator (storing RRs)
(*changesets)->changes->mem_ctx = (*changesets)->mmc_rr;
// Init changes' lists
init_list(&(*changesets)->changes->new_rrsets);
init_list(&(*changesets)->changes->old_rrsets);
return KNOT_EOK;
}
......@@ -178,32 +170,6 @@ int knot_changeset_add_rr(knot_changeset_t *chgs, knot_rrset_t *rr,
}
}
int knot_changes_add_rrset(knot_changes_t *ch, knot_rrset_t *rrset,
knot_changes_part_t part)
{
if (ch == NULL || rrset == NULL) {
return KNOT_EINVAL;
}
knot_rr_ln_t *rr_node =
ch->mem_ctx.alloc(ch->mem_ctx.ctx, sizeof(knot_rr_ln_t));
if (rr_node == NULL) {
// This will not happen with mp_alloc, but allocator can change
ERR_ALLOC_FAILED;
return KNOT_ENOMEM;
}
rr_node->rr = rrset;
if (part == KNOT_CHANGES_NEW) {
add_tail(&ch->new_rrsets, (node_t *)rr_node);
} else {
assert(part == KNOT_CHANGES_OLD);
add_tail(&ch->old_rrsets, (node_t *)rr_node);
}
return KNOT_EOK;
}
static void knot_changeset_store_soa(knot_rrset_t **chg_soa,
uint32_t *chg_serial, knot_rrset_t *soa)
{
......@@ -337,7 +303,6 @@ void knot_changesets_free(knot_changesets_t **changesets)
knot_rrset_free(&(*changesets)->first_soa, NULL);
free((*changesets)->changes);
free(*changesets);
*changesets = NULL;
}
......@@ -65,23 +65,6 @@ typedef struct knot_rr_ln {
knot_rrset_t *rr; /*!< Actual usable data. */
} knot_rr_ln_t;
/*! \brief Partial changes done to zones - used for update/transfer rollback. */
typedef struct {
/*!
* Memory context. Ideally a pool allocator since there is a possibility
* of many changes in one transfer/update.
*/
mm_ctx_t mem_ctx;
/*!
* Deleted after successful update.
*/
list_t old_rrsets;
/*!
* Deleted after failed update.
*/
list_t new_rrsets;
} knot_changes_t;
/*----------------------------------------------------------------------------*/
/*!
......@@ -95,7 +78,6 @@ typedef struct {
size_t count; /*!< Changeset count. */
knot_rrset_t *first_soa; /*!< First received SOA. */
uint32_t flags; /*!< DDNS / IXFR flags. */
knot_changes_t *changes; /*!< Partial changes. */
} knot_changesets_t;
/*----------------------------------------------------------------------------*/
......@@ -105,11 +87,6 @@ typedef enum {
KNOT_CHANGESET_REMOVE
} knot_changeset_part_t;
typedef enum {
KNOT_CHANGES_OLD,
KNOT_CHANGES_NEW,
} knot_changes_part_t;
/*----------------------------------------------------------------------------*/
/*!
......@@ -246,20 +223,6 @@ int knot_changeset_apply(knot_changeset_t *changeset,
*/
void knot_changesets_free(knot_changesets_t **changesets);
/*!
* \brief Add RRSet to changes structure.
* RRSet is either inserted to 'old' or to 'new' list.
*
* \param chgs Change to add RRSet into.
* \param rrset RRSet to be added.
* \param part Add to 'old' or 'new'?
*
* \retval KNOT_EOK on success.
* \retval Error code on failure.
*/
int knot_changes_add_rrset(knot_changes_t *ch, knot_rrset_t *rrset,
knot_changes_part_t part);
/*!
* \brief Merges two changesets together, second changeset's lists are kept.
*
......@@ -275,11 +238,6 @@ int knot_changes_add_rrset(knot_changes_t *ch, knot_rrset_t *rrset,
*/
int knot_changeset_merge(knot_changeset_t *ch1, knot_changeset_t *ch2);
/*!
* \param changes Double pointer of changes structure to be freed.
*/
void knot_changes_free(knot_changes_t **changes);
#endif /* _KNOT_CHANGESETS_H_ */
/*! @} */
This diff is collapsed.
......@@ -69,7 +69,6 @@ int knot_ddns_check_prereqs(const knot_zone_contents_t *zone,
int knot_ddns_process_update(knot_zone_contents_t *zone,
const knot_pkt_t *query,
knot_changeset_t *changeset,
knot_changes_t *changes,
uint16_t *rcode, uint32_t new_serial);
void knot_ddns_prereqs_free(knot_ddns_prereq_t **prereq);
......
This diff is collapsed.
......@@ -184,7 +184,6 @@ int xfrin_apply_changesets_dnssec_ddns(knot_zone_contents_t *z_old,
* \return Other error code if the application went wrong.
*/
int xfrin_apply_changesets_directly(knot_zone_contents_t *contents,
knot_changes_t *changes,
knot_changesets_t *chsets);
int xfrin_prepare_zone_copy(knot_zone_contents_t *old_contents,
......@@ -203,22 +202,18 @@ int xfrin_switch_zone(zone_t *zone,
knot_zone_contents_t *new_contents,
int transfer_type);
void xfrin_cleanup_successful_update(knot_changes_t *changes);
void xfrin_cleanup_successful_update(knot_zone_contents_t *zone);
void xfrin_rollback_update(knot_zone_contents_t *old_contents,
knot_zone_contents_t **new_contents,
knot_changes_t *changes);
knot_zone_contents_t **new_contents);
int xfrin_copy_rrset(knot_node_t *node, uint16_t type,
knot_rrset_t **rrset, knot_changes_t *changes,
int save_new);
knot_rrset_t **rrset);
int xfrin_copy_old_rrset(knot_rrset_t *old, knot_rrset_t **copy,
knot_changes_t *changes, int save_new);
int xfrin_copy_old_rrset(knot_rrset_t *old, knot_rrset_t **copy);
int xfrin_replace_rrset_in_node(knot_node_t *node,
knot_rrset_t *rrset_new,
knot_changes_t *changes,
knot_zone_contents_t *contents);
void xfrin_zone_contents_free(knot_zone_contents_t **contents);
......
......@@ -200,8 +200,7 @@ int knot_node_add_rrset_replace(knot_node_t *node, knot_rrset_t *rrset)
return knot_node_add_rrset_no_merge(node, rrset);
}
int knot_node_add_rrset(knot_node_t *node, knot_rrset_t *rrset,
knot_rrset_t **out_rrset)
int knot_node_add_rrset(knot_node_t *node, knot_rrset_t *rrset)
{
if (node == NULL) {
return KNOT_EINVAL;
......
......@@ -133,13 +133,11 @@ knot_node_t *knot_node_new(const knot_dname_t *owner, knot_node_t *parent,
*
* \param node Node to add the RRSet to.
* \param rrset RRSet to add.
* \param rrset Stores destination RRSet in case of merge.
*
* \retval KNOT_EOK on success.
* \retval KNOT_ERROR if the RRSet could not be inserted.
*/
int knot_node_add_rrset(knot_node_t *node, knot_rrset_t *rrset,
knot_rrset_t **out_rrset);
int knot_node_add_rrset(knot_node_t *node, knot_rrset_t *rrset);
int knot_node_add_rrset_replace(knot_node_t *node, knot_rrset_t *rrset);
......
......@@ -616,9 +616,9 @@ int knot_zone_contents_create_node(knot_zone_contents_t *contents,
/*----------------------------------------------------------------------------*/
static int insert_rr(knot_zone_contents_t *z, knot_rrset_t *rr, knot_node_t **n,
knot_rrset_t **rrset, bool nsec3)
bool nsec3)
{
if (z == NULL || rr == NULL || n == NULL || rrset == NULL) {
if (z == NULL || knot_rrset_empty(rr) || n == NULL) {
return KNOT_EINVAL;
}
......@@ -646,7 +646,7 @@ static int insert_rr(knot_zone_contents_t *z, knot_rrset_t *rr, knot_node_t **n,
}
}
return knot_node_add_rrset(*n, rr, rrset);
return knot_node_add_rrset(*n, rr);
}
static bool to_nsec3_tree(const knot_rrset_t *rr)
......@@ -655,10 +655,9 @@ static bool to_nsec3_tree(const knot_rrset_t *rr)
}
int knot_zone_contents_add_rr(knot_zone_contents_t *z,
knot_rrset_t *rr, knot_node_t **n,
knot_rrset_t **rrset)
knot_rrset_t *rr, knot_node_t **n)
{
return insert_rr(z, rr, n, rrset, to_nsec3_tree(rr));
return insert_rr(z, rr, n, to_nsec3_tree(rr));
}
int knot_zone_contents_add_rrset(knot_zone_contents_t *zone,
......@@ -696,7 +695,7 @@ dbg_zone_exec_detail(
/*! \todo REMOVE RRSET */
if (dupl == KNOT_RRSET_DUPL_MERGE) {
rc = knot_node_add_rrset(*node, rrset, NULL);
rc = knot_node_add_rrset(*node, rrset);
} else {
rc = knot_node_add_rrset_no_merge(*node, rrset);
}
......
......@@ -127,8 +127,7 @@ int knot_zone_contents_create_node(knot_zone_contents_t *contents,
knot_node_t **node);
int knot_zone_contents_add_rr(knot_zone_contents_t *z,
knot_rrset_t *rr, knot_node_t **n,
knot_rrset_t **rrset);
knot_rrset_t *rr, knot_node_t **n);
/*!
* \brief Adds a RRSet to the given zone.
......
......@@ -89,8 +89,7 @@ int zcreator_step(zcreator_t *zc, knot_rrset_t *rr)
}
knot_node_t *node = NULL;
knot_rrset_t *zone_rrset = NULL;
int ret = knot_zone_contents_add_rr(zc->z, rr, &node, &zone_rrset);
int ret = knot_zone_contents_add_rr(zc->z, rr, &node);
if (ret < 0) {
if (!handle_err(zc, rr, ret)) {
// Fatal error
......@@ -100,12 +99,12 @@ int zcreator_step(zcreator_t *zc, knot_rrset_t *rr)
return KNOT_EOK;
}
assert(node);
// assert(zone_rrset);
// Do RRSet and node semantic checks
bool sem_fatal_error = false;
err_handler_t err_handler;
err_handler_init(&err_handler);
// TODO
// ret = sem_check_rrset(node, zone_rrset, &err_handler);
// if (ret != KNOT_EOK) {
// return ret;
......
......@@ -163,71 +163,37 @@ static int knot_zone_diff_changeset_remove_rrset(knot_changeset_t *changeset,
static int knot_zone_diff_add_node(const knot_node_t *node,
knot_changeset_t *changeset)
{
if (node == NULL || changeset == NULL) {
dbg_zonediff("zone_diff: add_node: NULL arguments.\n");
return KNOT_EINVAL;
}
/* Add all rrsets from 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");
return KNOT_EOK;
}
for (uint i = 0; i < knot_node_rrset_count(node); i++) {
assert(rrsets[i]);
knot_rrset_t rrset = RRSET_INIT_N(node, i);
int ret = knot_zone_diff_changeset_add_rrset(changeset,
rrsets[i]);
&rrset);
if (ret != KNOT_EOK) {
dbg_zonediff("zone_diff: add_node: Cannot add RRSet (%s).\n",
knot_strerror(ret));
free(rrsets);
return ret;
}
}
knot_node_free_created_rrsets(node, rrsets);
return KNOT_EOK;
}
static int knot_zone_diff_remove_node(knot_changeset_t *changeset,
const knot_node_t *node)
{
if (changeset == NULL || node == NULL) {
dbg_zonediff("zone_diff: remove_node: NULL parameters.\n");
return KNOT_EINVAL;
}
dbg_zonediff("zone_diff: remove_node: Removing node: ...\n");
knot_rrset_t **rrsets = knot_node_create_rrsets(node);
if (rrsets == NULL) {
dbg_zonediff_verb("zone_diff: remove_node: "
"Nothing to remove.\n");
return KNOT_EOK;
}
dbg_zonediff_detail("zone_diff: remove_node: Will be removing %d RRSets.\n",
knot_node_rrset_count(node));
/* Remove all the RRSets of the node. */
for (uint i = 0; i < knot_node_rrset_count(node); i++) {
knot_rrset_t rrset = RRSET_INIT_N(node, i);
int ret = knot_zone_diff_changeset_remove_rrset(changeset,
rrsets[i]);
&rrset);
if (ret != KNOT_EOK) {
dbg_zonediff("zone_diff: remove_node: Failed to "
"remove rrset. Error: %s\n",
knot_strerror(ret));
free(rrsets);
return ret;
}
}
knot_node_free_created_rrsets(node, rrsets);
return KNOT_EOK;
}
......
......@@ -55,11 +55,10 @@ static int apex_node_dump_text(knot_node_t *node, dump_params_t *params)
params->buf[0] = '\0';
}
knot_rrset_t **rrsets = knot_node_create_rrsets(node);
// Dump other records.
for (uint16_t i = 0; i < node->rrset_count; i++) {
switch (rrsets[i]->type) {
knot_rrset_t rrset = RRSET_INIT_N(node, i);
switch (rrset.type) {
case KNOT_RRTYPE_NSEC:
continue;
case KNOT_RRTYPE_RRSIG:
......@@ -70,17 +69,15 @@ static int apex_node_dump_text(knot_node_t *node, dump_params_t *params)
break;
}
if (knot_rrset_txt_dump(rrsets[i], params->buf, params->buflen,
if (knot_rrset_txt_dump(&rrset, params->buf, params->buflen,
params->style) < 0) {
knot_node_free_created_rrsets(node, rrsets);
return KNOT_ENOMEM;
}
params->rr_count += knot_rrset_rr_count(rrsets[i]);
params->rr_count += knot_rrset_rr_count(&rrset);
fprintf(params->file, "%s", params->buf);
params->buf[0] = '\0';
}
knot_node_free_created_rrsets(node, rrsets);
return KNOT_EOK;
}
......@@ -95,11 +92,10 @@ static int node_dump_text(knot_node_t *node, void *data)
return KNOT_EOK;
}
knot_rrset_t **rrsets = knot_node_create_rrsets(node);
// Dump non-apex rrsets.
for (uint16_t i = 0; i < node->rrset_count; i++) {
switch (rrsets[i]->type) {