Commit c449adcd authored by Dominik Taborsky's avatar Dominik Taborsky

changeset: add a parameter to rrset additions/removal for redundancy check

parent 794ff6dc
...@@ -145,7 +145,7 @@ static int connect_nsec_nodes(zone_node_t *a, zone_node_t *b, ...@@ -145,7 +145,7 @@ static int connect_nsec_nodes(zone_node_t *a, zone_node_t *b,
} }
// Add new NSEC to the changeset (no matter if old was removed) // Add new NSEC to the changeset (no matter if old was removed)
ret = changeset_add_rrset(data->changeset, &new_nsec); ret = changeset_add_rrset(data->changeset, &new_nsec, false);
knot_rdataset_clear(&new_nsec.rrs, NULL); knot_rdataset_clear(&new_nsec.rrs, NULL);
return ret; return ret;
} }
...@@ -223,7 +223,7 @@ int knot_nsec_changeset_remove(const zone_node_t *n, ...@@ -223,7 +223,7 @@ int knot_nsec_changeset_remove(const zone_node_t *n,
} }
if (!knot_rrset_empty(&nsec)) { if (!knot_rrset_empty(&nsec)) {
// update changeset // update changeset
result = changeset_rem_rrset(changeset, &nsec); result = changeset_rem_rrset(changeset, &nsec, false);
if (result != KNOT_EOK) { if (result != KNOT_EOK) {
return result; return result;
} }
...@@ -251,7 +251,7 @@ int knot_nsec_changeset_remove(const zone_node_t *n, ...@@ -251,7 +251,7 @@ int knot_nsec_changeset_remove(const zone_node_t *n,
} }
// store RRSIG // store RRSIG
result = changeset_rem_rrset(changeset, &synth_rrsigs); result = changeset_rem_rrset(changeset, &synth_rrsigs, false);
knot_rdataset_clear(&synth_rrsigs.rrs, NULL); knot_rdataset_clear(&synth_rrsigs.rrs, NULL);
} }
......
...@@ -286,7 +286,7 @@ static int remove_expired_rrsigs(const knot_rrset_t *covered, ...@@ -286,7 +286,7 @@ static int remove_expired_rrsigs(const knot_rrset_t *covered,
} }
if (!knot_rrset_empty(&to_remove) && result == KNOT_EOK) { if (!knot_rrset_empty(&to_remove) && result == KNOT_EOK) {
result = changeset_rem_rrset(changeset, &to_remove); result = changeset_rem_rrset(changeset, &to_remove, false);
} }
knot_rdataset_clear(&synth_rrsig.rrs, NULL); knot_rdataset_clear(&synth_rrsig.rrs, NULL);
...@@ -341,7 +341,7 @@ static int add_missing_rrsigs(const knot_rrset_t *covered, ...@@ -341,7 +341,7 @@ static int add_missing_rrsigs(const knot_rrset_t *covered,
} }
if (!knot_rrset_empty(&to_add) && result == KNOT_EOK) { if (!knot_rrset_empty(&to_add) && result == KNOT_EOK) {
result = changeset_add_rrset(changeset, &to_add); result = changeset_add_rrset(changeset, &to_add, false);
} }
knot_rdataset_clear(&to_add.rrs, NULL); knot_rdataset_clear(&to_add.rrs, NULL);
...@@ -374,7 +374,7 @@ static int remove_rrset_rrsigs(const knot_dname_t *owner, uint16_t type, ...@@ -374,7 +374,7 @@ static int remove_rrset_rrsigs(const knot_dname_t *owner, uint16_t type,
return KNOT_EOK; return KNOT_EOK;
} }
ret = changeset_rem_rrset(changeset, &synth_rrsig); ret = changeset_rem_rrset(changeset, &synth_rrsig, false);
knot_rdataset_clear(&synth_rrsig.rrs, NULL); knot_rdataset_clear(&synth_rrsig.rrs, NULL);
return ret; return ret;
...@@ -460,7 +460,7 @@ static int remove_standalone_rrsigs(const zone_node_t *node, ...@@ -460,7 +460,7 @@ static int remove_standalone_rrsigs(const zone_node_t *node,
if (ret != KNOT_EOK) { if (ret != KNOT_EOK) {
return ret; return ret;
} }
ret = changeset_rem_rrset(changeset, &to_remove); ret = changeset_rem_rrset(changeset, &to_remove, false);
knot_rdataset_clear(&to_remove.rrs, NULL); knot_rdataset_clear(&to_remove.rrs, NULL);
if (ret != KNOT_EOK) { if (ret != KNOT_EOK) {
return ret; return ret;
...@@ -747,7 +747,7 @@ static int remove_invalid_dnskeys(const knot_rrset_t *soa, ...@@ -747,7 +747,7 @@ static int remove_invalid_dnskeys(const knot_rrset_t *soa,
} }
if (!knot_rrset_empty(&to_remove) && result == KNOT_EOK) { if (!knot_rrset_empty(&to_remove) && result == KNOT_EOK) {
result = changeset_rem_rrset(changeset, &to_remove); result = changeset_rem_rrset(changeset, &to_remove, false);
} }
knot_rdataset_clear(&to_remove.rrs, NULL); knot_rdataset_clear(&to_remove.rrs, NULL);
...@@ -803,7 +803,7 @@ static int add_missing_dnskeys(const knot_rrset_t *soa, ...@@ -803,7 +803,7 @@ static int add_missing_dnskeys(const knot_rrset_t *soa,
} }
if (!knot_rrset_empty(&to_add) && result == KNOT_EOK) { if (!knot_rrset_empty(&to_add) && result == KNOT_EOK) {
result = changeset_add_rrset(changeset, &to_add); result = changeset_add_rrset(changeset, &to_add, false);
} }
knot_rdataset_clear(&to_add.rrs, NULL); knot_rdataset_clear(&to_add.rrs, NULL);
......
...@@ -475,13 +475,13 @@ static int solve_soa_add(const knot_rrset_t *rr, changeset_t *change, mm_ctx_t * ...@@ -475,13 +475,13 @@ static int solve_soa_add(const knot_rrset_t *rr, changeset_t *change, mm_ctx_t *
/*! \brief Adds single RR into remove section of changeset. */ /*! \brief Adds single RR into remove section of changeset. */
static int solve_del(const knot_rrset_t *rr, changeset_t *change, mm_ctx_t *mm) static int solve_del(const knot_rrset_t *rr, changeset_t *change, mm_ctx_t *mm)
{ {
return changeset_rem_rrset(change, rr); return changeset_rem_rrset(change, rr, false);
} }
/*! \brief Adds single RR into add section of changeset. */ /*! \brief Adds single RR into add section of changeset. */
static int solve_add(const knot_rrset_t *rr, changeset_t *change, mm_ctx_t *mm) static int solve_add(const knot_rrset_t *rr, changeset_t *change, mm_ctx_t *mm)
{ {
return changeset_add_rrset(change, rr); return changeset_add_rrset(change, rr, false);
} }
/*! \brief Decides what the next IXFR-in state should be. */ /*! \brief Decides what the next IXFR-in state should be. */
......
...@@ -742,10 +742,10 @@ static int changesets_unpack(changeset_t *chs) ...@@ -742,10 +742,10 @@ static int changesets_unpack(changeset_t *chs)
} else { } else {
/* Remove RRSets. */ /* Remove RRSets. */
if (in_remove_section) { if (in_remove_section) {
ret = changeset_rem_rrset(chs, &rrset); ret = changeset_rem_rrset(chs, &rrset, false);
} else { } else {
/* Add RRSets. */ /* Add RRSets. */
ret = changeset_add_rrset(chs, &rrset); ret = changeset_add_rrset(chs, &rrset, false);
} }
} }
knot_rrset_clear(&rrset, NULL); knot_rrset_clear(&rrset, NULL);
......
...@@ -271,18 +271,20 @@ size_t changeset_size(const changeset_t *ch) ...@@ -271,18 +271,20 @@ size_t changeset_size(const changeset_t *ch)
return size; return size;
} }
int changeset_add_rrset(changeset_t *ch, const knot_rrset_t *rrset) int changeset_add_rrset(changeset_t *ch, const knot_rrset_t *rrset, bool check_redundancy)
{ {
/* Check if there's any removal and remove that, then add this /* Check if there's any removal and remove that, then add this
* addition anyway. Required to change TTLs. */ * addition anyway. Required to change TTLs. */
need_to_insert(ch->remove, rrset); if(check_redundancy) {
need_to_insert(ch->remove, rrset);
}
return add_rr_to_zone(ch->add, &ch->soa_to, rrset); return add_rr_to_zone(ch->add, &ch->soa_to, rrset);
} }
int changeset_rem_rrset(changeset_t *ch, const knot_rrset_t *rrset) int changeset_rem_rrset(changeset_t *ch, const knot_rrset_t *rrset, bool check_redundancy)
{ {
if (need_to_insert(ch->add, rrset)) { if ((check_redundancy && need_to_insert(ch->add, rrset)) || !check_redundancy) {
return add_rr_to_zone(ch->remove, &ch->soa_from, rrset); return add_rr_to_zone(ch->remove, &ch->soa_from, rrset);
} else { } else {
return KNOT_EOK; return KNOT_EOK;
...@@ -296,7 +298,7 @@ int changeset_merge(changeset_t *ch1, const changeset_t *ch2) ...@@ -296,7 +298,7 @@ int changeset_merge(changeset_t *ch1, const changeset_t *ch2)
knot_rrset_t rrset = changeset_iter_next(&itt); knot_rrset_t rrset = changeset_iter_next(&itt);
while (!knot_rrset_empty(&rrset)) { while (!knot_rrset_empty(&rrset)) {
int ret = changeset_add_rrset(ch1, &rrset); int ret = changeset_add_rrset(ch1, &rrset, true);
if (ret != KNOT_EOK) { if (ret != KNOT_EOK) {
changeset_iter_clear(&itt); changeset_iter_clear(&itt);
return ret; return ret;
...@@ -309,7 +311,7 @@ int changeset_merge(changeset_t *ch1, const changeset_t *ch2) ...@@ -309,7 +311,7 @@ int changeset_merge(changeset_t *ch1, const changeset_t *ch2)
rrset = changeset_iter_next(&itt); rrset = changeset_iter_next(&itt);
while (!knot_rrset_empty(&rrset)) { while (!knot_rrset_empty(&rrset)) {
int ret = changeset_rem_rrset(ch1, &rrset); int ret = changeset_rem_rrset(ch1, &rrset, true);
if (ret != KNOT_EOK) { if (ret != KNOT_EOK) {
changeset_iter_clear(&itt); changeset_iter_clear(&itt);
return ret; return ret;
......
...@@ -96,7 +96,7 @@ size_t changeset_size(const changeset_t *ch); ...@@ -96,7 +96,7 @@ size_t changeset_size(const changeset_t *ch);
* *
* \return KNOT_E* * \return KNOT_E*
*/ */
int changeset_add_rrset(changeset_t *ch, const knot_rrset_t *rrset); int changeset_add_rrset(changeset_t *ch, const knot_rrset_t *rrset, bool check_redundancy);
/*! /*!
* \brief Add RRSet to 'remove' part of changeset. * \brief Add RRSet to 'remove' part of changeset.
...@@ -106,7 +106,7 @@ int changeset_add_rrset(changeset_t *ch, const knot_rrset_t *rrset); ...@@ -106,7 +106,7 @@ int changeset_add_rrset(changeset_t *ch, const knot_rrset_t *rrset);
* *
* \return KNOT_E* * \return KNOT_E*
*/ */
int changeset_rem_rrset(changeset_t *ch, const knot_rrset_t *rrset); int changeset_rem_rrset(changeset_t *ch, const knot_rrset_t *rrset, bool check_redundancy);
/*! /*!
* \brief Merges two changesets together. Legacy, to be removed with new zone API. * \brief Merges two changesets together. Legacy, to be removed with new zone API.
......
...@@ -263,7 +263,7 @@ void zone_update_clear(zone_update_t *update) ...@@ -263,7 +263,7 @@ void zone_update_clear(zone_update_t *update)
int zone_update_add(zone_update_t *update, const knot_rrset_t *rrset) int zone_update_add(zone_update_t *update, const knot_rrset_t *rrset)
{ {
if (update->flags & UPDATE_INCREMENTAL) { if (update->flags & UPDATE_INCREMENTAL) {
return changeset_add_rrset(&update->change, rrset); return changeset_add_rrset(&update->change, rrset, true);
} else if (update->flags & UPDATE_FULL) { } else if (update->flags & UPDATE_FULL) {
zone_node_t *n = NULL; zone_node_t *n = NULL;
return zone_contents_add_rr(update->new_cont, rrset, &n); return zone_contents_add_rr(update->new_cont, rrset, &n);
...@@ -275,7 +275,7 @@ int zone_update_add(zone_update_t *update, const knot_rrset_t *rrset) ...@@ -275,7 +275,7 @@ int zone_update_add(zone_update_t *update, const knot_rrset_t *rrset)
int zone_update_remove(zone_update_t *update, const knot_rrset_t *rrset) int zone_update_remove(zone_update_t *update, const knot_rrset_t *rrset)
{ {
if (update->flags & UPDATE_INCREMENTAL) { if (update->flags & UPDATE_INCREMENTAL) {
return changeset_rem_rrset(&update->change, rrset); return changeset_rem_rrset(&update->change, rrset, true);
} else { } else {
return KNOT_ENOTSUP; return KNOT_ENOTSUP;
} }
......
...@@ -92,7 +92,7 @@ static int knot_zone_diff_add_node(const zone_node_t *node, ...@@ -92,7 +92,7 @@ static int knot_zone_diff_add_node(const zone_node_t *node,
/* Add all rrsets from node. */ /* Add all rrsets from node. */
for (unsigned i = 0; i < node->rrset_count; i++) { for (unsigned i = 0; i < node->rrset_count; i++) {
knot_rrset_t rrset = node_rrset_at(node, i); knot_rrset_t rrset = node_rrset_at(node, i);
int ret = changeset_add_rrset(changeset, &rrset); int ret = changeset_add_rrset(changeset, &rrset, false);
if (ret != KNOT_EOK) { if (ret != KNOT_EOK) {
return ret; return ret;
} }
...@@ -107,7 +107,7 @@ static int knot_zone_diff_remove_node(changeset_t *changeset, ...@@ -107,7 +107,7 @@ static int knot_zone_diff_remove_node(changeset_t *changeset,
/* Remove all the RRSets of the node. */ /* Remove all the RRSets of the node. */
for (unsigned i = 0; i < node->rrset_count; i++) { for (unsigned i = 0; i < node->rrset_count; i++) {
knot_rrset_t rrset = node_rrset_at(node, i); knot_rrset_t rrset = node_rrset_at(node, i);
int ret = changeset_rem_rrset(changeset, &rrset); int ret = changeset_rem_rrset(changeset, &rrset, false);
if (ret != KNOT_EOK) { if (ret != KNOT_EOK) {
return ret; return ret;
} }
...@@ -194,7 +194,7 @@ static int knot_zone_diff_rdata(const knot_rrset_t *rrset1, ...@@ -194,7 +194,7 @@ static int knot_zone_diff_rdata(const knot_rrset_t *rrset1,
} }
if (!knot_rrset_empty(&to_remove)) { if (!knot_rrset_empty(&to_remove)) {
int ret = changeset_rem_rrset(changeset, &to_remove); int ret = changeset_rem_rrset(changeset, &to_remove, false);
knot_rdataset_clear(&to_remove.rrs, NULL); knot_rdataset_clear(&to_remove.rrs, NULL);
if (ret != KNOT_EOK) { if (ret != KNOT_EOK) {
knot_rdataset_clear(&to_add.rrs, NULL); knot_rdataset_clear(&to_add.rrs, NULL);
...@@ -203,7 +203,7 @@ static int knot_zone_diff_rdata(const knot_rrset_t *rrset1, ...@@ -203,7 +203,7 @@ static int knot_zone_diff_rdata(const knot_rrset_t *rrset1,
} }
if (!knot_rrset_empty(&to_add)) { if (!knot_rrset_empty(&to_add)) {
int ret = changeset_add_rrset(changeset, &to_add); int ret = changeset_add_rrset(changeset, &to_add, false);
knot_rdataset_clear(&to_add.rrs, NULL); knot_rdataset_clear(&to_add.rrs, NULL);
return ret; return ret;
} }
...@@ -273,7 +273,7 @@ static int knot_zone_diff_node(zone_node_t **node_ptr, void *data) ...@@ -273,7 +273,7 @@ static int knot_zone_diff_node(zone_node_t **node_ptr, void *data)
if (knot_rrset_empty(&rrset_from_second_node)) { if (knot_rrset_empty(&rrset_from_second_node)) {
/* RRSet has been removed. Make a copy and remove. */ /* RRSet has been removed. Make a copy and remove. */
int ret = changeset_rem_rrset( int ret = changeset_rem_rrset(
param->changeset, &rrset); param->changeset, &rrset, false);
if (ret != KNOT_EOK) { if (ret != KNOT_EOK) {
return ret; return ret;
} }
...@@ -301,7 +301,7 @@ static int knot_zone_diff_node(zone_node_t **node_ptr, void *data) ...@@ -301,7 +301,7 @@ static int knot_zone_diff_node(zone_node_t **node_ptr, void *data)
if (knot_rrset_empty(&rrset_from_first_node)) { if (knot_rrset_empty(&rrset_from_first_node)) {
/* RRSet has been added. Make a copy and add. */ /* RRSet has been added. Make a copy and add. */
int ret = changeset_add_rrset( int ret = changeset_add_rrset(
param->changeset, &rrset); param->changeset, &rrset, false);
if (ret != KNOT_EOK) { if (ret != KNOT_EOK) {
return ret; return ret;
} }
......
...@@ -48,20 +48,20 @@ int main(int argc, char *argv[]) ...@@ -48,20 +48,20 @@ int main(int argc, char *argv[])
uint8_t data[8] = "\7teststr"; uint8_t data[8] = "\7teststr";
knot_rrset_add_rdata(apex_txt_rr, data, sizeof(data), 3600, NULL); knot_rrset_add_rdata(apex_txt_rr, data, sizeof(data), 3600, NULL);
int ret = changeset_add_rrset(ch, apex_txt_rr); int ret = changeset_add_rrset(ch, apex_txt_rr, true);
ok(ret == KNOT_EOK, "changeset: add RRSet"); ok(ret == KNOT_EOK, "changeset: add RRSet");
ok(changeset_size(ch) == 1, "changeset: size add"); ok(changeset_size(ch) == 1, "changeset: size add");
ret = changeset_rem_rrset(ch, apex_txt_rr); ret = changeset_rem_rrset(ch, apex_txt_rr, true);
ok(ret == KNOT_EOK, "changeset: rem RRSet"); ok(ret == KNOT_EOK, "changeset: rem RRSet");
ok(changeset_size(ch) == 0, "changeset: size remove"); ok(changeset_size(ch) == 0, "changeset: size remove");
ok(changeset_empty(ch), "changeset: empty"); ok(changeset_empty(ch), "changeset: empty");
changeset_add_rrset(ch, apex_txt_rr); changeset_add_rrset(ch, apex_txt_rr, true);
// Add another RR to node. // Add another RR to node.
knot_rrset_t *apex_spf_rr = knot_rrset_new(d, KNOT_RRTYPE_SPF, KNOT_CLASS_IN, NULL); knot_rrset_t *apex_spf_rr = knot_rrset_new(d, KNOT_RRTYPE_SPF, KNOT_CLASS_IN, NULL);
assert(apex_spf_rr); assert(apex_spf_rr);
knot_rrset_add_rdata(apex_spf_rr, data, sizeof(data), 3600, NULL); knot_rrset_add_rdata(apex_spf_rr, data, sizeof(data), 3600, NULL);
ret = changeset_add_rrset(ch, apex_spf_rr); ret = changeset_add_rrset(ch, apex_spf_rr, true);
ok(ret == KNOT_EOK, "changeset: add multiple"); ok(ret == KNOT_EOK, "changeset: add multiple");
// Add another node. // Add another node.
...@@ -71,7 +71,7 @@ int main(int argc, char *argv[]) ...@@ -71,7 +71,7 @@ int main(int argc, char *argv[])
knot_rrset_t *other_rr = knot_rrset_new(d, KNOT_RRTYPE_TXT, KNOT_CLASS_IN, NULL); knot_rrset_t *other_rr = knot_rrset_new(d, KNOT_RRTYPE_TXT, KNOT_CLASS_IN, NULL);
assert(other_rr); assert(other_rr);
knot_rrset_add_rdata(other_rr, data, sizeof(data), 3600, NULL); knot_rrset_add_rdata(other_rr, data, sizeof(data), 3600, NULL);
ret = changeset_add_rrset(ch, other_rr); ret = changeset_add_rrset(ch, other_rr, true);
ok(ret == KNOT_EOK, "changeset: remove multiple"); ok(ret == KNOT_EOK, "changeset: remove multiple");
// Test add traversal. // Test add traversal.
...@@ -92,8 +92,8 @@ int main(int argc, char *argv[]) ...@@ -92,8 +92,8 @@ int main(int argc, char *argv[])
changeset_iter_clear(&it); changeset_iter_clear(&it);
ok(knot_rrset_empty(&iter), "changeset: traversal: skip non-terminals"); ok(knot_rrset_empty(&iter), "changeset: traversal: skip non-terminals");
changeset_rem_rrset(ch, apex_txt_rr); changeset_rem_rrset(ch, apex_txt_rr, true);
changeset_rem_rrset(ch, apex_txt_rr); changeset_rem_rrset(ch, apex_txt_rr, true);
// Test remove traversal. // Test remove traversal.
ret = changeset_iter_rem(&it, ch, false); ret = changeset_iter_rem(&it, ch, false);
...@@ -126,7 +126,7 @@ int main(int argc, char *argv[]) ...@@ -126,7 +126,7 @@ int main(int argc, char *argv[])
knot_dname_free(&apex_txt_rr->owner, NULL); knot_dname_free(&apex_txt_rr->owner, NULL);
apex_txt_rr->owner = knot_dname_from_str_alloc("something.test."); apex_txt_rr->owner = knot_dname_from_str_alloc("something.test.");
assert(apex_txt_rr->owner); assert(apex_txt_rr->owner);
ret = changeset_add_rrset(ch2, apex_txt_rr); ret = changeset_add_rrset(ch2, apex_txt_rr, true);
assert(ret == KNOT_EOK); assert(ret == KNOT_EOK);
// Add something to remove section. // Add something to remove section.
...@@ -134,7 +134,7 @@ int main(int argc, char *argv[]) ...@@ -134,7 +134,7 @@ int main(int argc, char *argv[])
apex_txt_rr->owner = apex_txt_rr->owner =
knot_dname_from_str_alloc("and.now.for.something.completely.different.test."); knot_dname_from_str_alloc("and.now.for.something.completely.different.test.");
assert(apex_txt_rr->owner); assert(apex_txt_rr->owner);
ret = changeset_rem_rrset(ch2, apex_txt_rr); ret = changeset_rem_rrset(ch2, apex_txt_rr, true);
assert(ret == KNOT_EOK); assert(ret == KNOT_EOK);
// Test merge. // Test merge.
......
...@@ -96,7 +96,7 @@ static void init_random_changeset(changeset_t *ch, const uint32_t from, const ui ...@@ -96,7 +96,7 @@ static void init_random_changeset(changeset_t *ch, const uint32_t from, const ui
for (size_t i = 0; i < size / 2; ++i) { for (size_t i = 0; i < size / 2; ++i) {
knot_rrset_t rr; knot_rrset_t rr;
init_random_rr(&rr, apex); init_random_rr(&rr, apex);
int ret = changeset_add_rrset(ch, &rr); int ret = changeset_add_rrset(ch, &rr, false);
assert(ret == KNOT_EOK); assert(ret == KNOT_EOK);
knot_rrset_clear(&rr, NULL); knot_rrset_clear(&rr, NULL);
} }
...@@ -105,7 +105,7 @@ static void init_random_changeset(changeset_t *ch, const uint32_t from, const ui ...@@ -105,7 +105,7 @@ static void init_random_changeset(changeset_t *ch, const uint32_t from, const ui
for (size_t i = 0; i < size / 2; ++i) { for (size_t i = 0; i < size / 2; ++i) {
knot_rrset_t rr; knot_rrset_t rr;
init_random_rr(&rr, apex); init_random_rr(&rr, apex);
int ret = changeset_rem_rrset(ch, &rr); int ret = changeset_rem_rrset(ch, &rr, false);
assert(ret == KNOT_EOK); assert(ret == KNOT_EOK);
knot_rrset_clear(&rr, NULL); knot_rrset_clear(&rr, NULL);
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment