Commit 26275614 authored by Dominik Taborsky's avatar Dominik Taborsky

changesets: use flags instead of boolean parameter

parent a181d61d
......@@ -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)
ret = changeset_add_rrset(data->changeset, &new_nsec, false);
ret = changeset_add_rrset(data->changeset, &new_nsec, 0);
knot_rdataset_clear(&new_nsec.rrs, NULL);
return ret;
}
......@@ -223,7 +223,7 @@ int knot_nsec_changeset_remove(const zone_node_t *n,
}
if (!knot_rrset_empty(&nsec)) {
// update changeset
result = changeset_rem_rrset(changeset, &nsec, false);
result = changeset_rem_rrset(changeset, &nsec, 0);
if (result != KNOT_EOK) {
return result;
}
......@@ -251,7 +251,7 @@ int knot_nsec_changeset_remove(const zone_node_t *n,
}
// store RRSIG
result = changeset_rem_rrset(changeset, &synth_rrsigs, false);
result = changeset_rem_rrset(changeset, &synth_rrsigs, 0);
knot_rdataset_clear(&synth_rrsigs.rrs, NULL);
}
......
......@@ -286,7 +286,7 @@ static int remove_expired_rrsigs(const knot_rrset_t *covered,
}
if (!knot_rrset_empty(&to_remove) && result == KNOT_EOK) {
result = changeset_rem_rrset(changeset, &to_remove, false);
result = changeset_rem_rrset(changeset, &to_remove, 0);
}
knot_rdataset_clear(&synth_rrsig.rrs, NULL);
......@@ -341,7 +341,7 @@ static int add_missing_rrsigs(const knot_rrset_t *covered,
}
if (!knot_rrset_empty(&to_add) && result == KNOT_EOK) {
result = changeset_add_rrset(changeset, &to_add, false);
result = changeset_add_rrset(changeset, &to_add, 0);
}
knot_rdataset_clear(&to_add.rrs, NULL);
......@@ -374,7 +374,7 @@ static int remove_rrset_rrsigs(const knot_dname_t *owner, uint16_t type,
return KNOT_EOK;
}
ret = changeset_rem_rrset(changeset, &synth_rrsig, false);
ret = changeset_rem_rrset(changeset, &synth_rrsig, 0);
knot_rdataset_clear(&synth_rrsig.rrs, NULL);
return ret;
......@@ -460,7 +460,7 @@ static int remove_standalone_rrsigs(const zone_node_t *node,
if (ret != KNOT_EOK) {
return ret;
}
ret = changeset_rem_rrset(changeset, &to_remove, false);
ret = changeset_rem_rrset(changeset, &to_remove, 0);
knot_rdataset_clear(&to_remove.rrs, NULL);
if (ret != KNOT_EOK) {
return ret;
......@@ -747,7 +747,7 @@ static int remove_invalid_dnskeys(const knot_rrset_t *soa,
}
if (!knot_rrset_empty(&to_remove) && result == KNOT_EOK) {
result = changeset_rem_rrset(changeset, &to_remove, false);
result = changeset_rem_rrset(changeset, &to_remove, 0);
}
knot_rdataset_clear(&to_remove.rrs, NULL);
......@@ -803,7 +803,7 @@ static int add_missing_dnskeys(const knot_rrset_t *soa,
}
if (!knot_rrset_empty(&to_add) && result == KNOT_EOK) {
result = changeset_add_rrset(changeset, &to_add, false);
result = changeset_add_rrset(changeset, &to_add, 0);
}
knot_rdataset_clear(&to_add.rrs, NULL);
......
......@@ -477,13 +477,13 @@ static int solve_soa_add(const knot_rrset_t *rr, changeset_t *change, knot_mm_t
/*! \brief Adds single RR into remove section of changeset. */
static int solve_del(const knot_rrset_t *rr, changeset_t *change, knot_mm_t *mm)
{
return changeset_rem_rrset(change, rr, false);
return changeset_rem_rrset(change, rr, 0);
}
/*! \brief Adds single RR into add section of changeset. */
static int solve_add(const knot_rrset_t *rr, changeset_t *change, knot_mm_t *mm)
{
return changeset_add_rrset(change, rr, false);
return changeset_add_rrset(change, rr, 0);
}
/*! \brief Decides what the next IXFR-in state should be. */
......
......@@ -742,10 +742,10 @@ static int changesets_unpack(changeset_t *chs)
} else {
/* Remove RRSets. */
if (in_remove_section) {
ret = changeset_rem_rrset(chs, &rrset, false);
ret = changeset_rem_rrset(chs, &rrset, 0);
} else {
/* Add RRSets. */
ret = changeset_add_rrset(chs, &rrset, false);
ret = changeset_add_rrset(chs, &rrset, 0);
}
}
knot_rrset_clear(&rrset, NULL);
......
......@@ -256,7 +256,7 @@ size_t changeset_size(const changeset_t *ch)
return size;
}
int changeset_add_rrset(changeset_t *ch, const knot_rrset_t *rrset, bool check_redundancy)
int changeset_add_rrset(changeset_t *ch, const knot_rrset_t *rrset, unsigned flags)
{
if (!ch || !rrset) {
return KNOT_EINVAL;
......@@ -269,7 +269,7 @@ int changeset_add_rrset(changeset_t *ch, const knot_rrset_t *rrset, bool check_r
/* Check if there's any removal and remove that, then add this
* addition anyway. Required to change TTLs. */
if (check_redundancy) {
if (flags & CHANGESET_CHECK) {
/* If we delete the rrset, we need to hold a copy to add it later */
rrset = knot_rrset_copy(rrset, NULL);
if (rrset == NULL) {
......@@ -281,14 +281,14 @@ int changeset_add_rrset(changeset_t *ch, const knot_rrset_t *rrset, bool check_r
int ret = add_rr_to_contents(ch->add, rrset);
if (check_redundancy) {
if (flags & CHANGESET_CHECK) {
knot_rrset_free((knot_rrset_t **)&rrset, NULL);
}
return ret;
}
int changeset_rem_rrset(changeset_t *ch, const knot_rrset_t *rrset, bool check_redundancy)
int changeset_rem_rrset(changeset_t *ch, const knot_rrset_t *rrset, unsigned flags)
{
if (!ch || !rrset) {
return KNOT_EINVAL;
......@@ -301,7 +301,7 @@ int changeset_rem_rrset(changeset_t *ch, const knot_rrset_t *rrset, bool check_r
/* Check if there's any addition and remove that, then add this
* removal anyway. */
if (check_redundancy) {
if (flags & CHANGESET_CHECK) {
/* If we delete the rrset, we need to hold a copy to add it later */
rrset = knot_rrset_copy(rrset, NULL);
if (rrset == NULL) {
......@@ -313,7 +313,7 @@ int changeset_rem_rrset(changeset_t *ch, const knot_rrset_t *rrset, bool check_r
int ret = add_rr_to_contents(ch->remove, rrset);
if (check_redundancy) {
if (flags & CHANGESET_CHECK) {
knot_rrset_free((knot_rrset_t **)&rrset, NULL);
}
......@@ -327,7 +327,7 @@ int changeset_merge(changeset_t *ch1, const changeset_t *ch2)
knot_rrset_t rrset = changeset_iter_next(&itt);
while (!knot_rrset_empty(&rrset)) {
int ret = changeset_add_rrset(ch1, &rrset, true);
int ret = changeset_add_rrset(ch1, &rrset, CHANGESET_CHECK);
if (ret != KNOT_EOK) {
changeset_iter_clear(&itt);
return ret;
......@@ -340,7 +340,7 @@ int changeset_merge(changeset_t *ch1, const changeset_t *ch2)
rrset = changeset_iter_next(&itt);
while (!knot_rrset_empty(&rrset)) {
int ret = changeset_rem_rrset(ch1, &rrset, true);
int ret = changeset_rem_rrset(ch1, &rrset, CHANGESET_CHECK);
if (ret != KNOT_EOK) {
changeset_iter_clear(&itt);
return ret;
......
......@@ -28,6 +28,12 @@
#include "knot/zone/contents.h"
#include "contrib/ucw/lists.h"
/*! \brief Changeset addition/removal flags */
enum {
CHANGESET_NONE = 0,
CHANGESET_CHECK = 1 << 0, /*! Perform redundancy check on additions/removals */
};
/*! \brief One zone change, from 'soa_from' to 'soa_to'. */
typedef struct {
node_t n; /*!< List node. */
......@@ -93,7 +99,7 @@ size_t changeset_size(const changeset_t *ch);
*
* \return KNOT_E*
*/
int changeset_add_rrset(changeset_t *ch, const knot_rrset_t *rrset, bool check_redundancy);
int changeset_add_rrset(changeset_t *ch, const knot_rrset_t *rrset, unsigned flags);
/*!
* \brief Add RRSet to 'remove' part of changeset.
......@@ -104,7 +110,7 @@ int changeset_add_rrset(changeset_t *ch, const knot_rrset_t *rrset, bool check_r
*
* \return KNOT_E*
*/
int changeset_rem_rrset(changeset_t *ch, const knot_rrset_t *rrset, bool check_redundancy);
int changeset_rem_rrset(changeset_t *ch, const knot_rrset_t *rrset, unsigned flags);
/*!
* \brief Merges two changesets together. Legacy, to be removed with new zone API.
......
......@@ -269,7 +269,7 @@ void zone_update_clear(zone_update_t *update)
int zone_update_add(zone_update_t *update, const knot_rrset_t *rrset)
{
if (update->flags & UPDATE_INCREMENTAL) {
return changeset_add_rrset(&update->change, rrset, true);
return changeset_add_rrset(&update->change, rrset, CHANGESET_CHECK);
} else if (update->flags & UPDATE_FULL) {
zone_node_t *n = NULL;
return zone_contents_add_rr(update->new_cont, rrset, &n);
......@@ -281,7 +281,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)
{
if (update->flags & UPDATE_INCREMENTAL) {
return changeset_rem_rrset(&update->change, rrset, true);
return changeset_rem_rrset(&update->change, rrset, CHANGESET_CHECK);
} else {
return KNOT_ENOTSUP;
}
......
......@@ -91,7 +91,7 @@ static int knot_zone_diff_add_node(const zone_node_t *node,
/* Add all rrsets from node. */
for (unsigned i = 0; i < node->rrset_count; i++) {
knot_rrset_t rrset = node_rrset_at(node, i);
int ret = changeset_add_rrset(changeset, &rrset, false);
int ret = changeset_add_rrset(changeset, &rrset, 0);
if (ret != KNOT_EOK) {
return ret;
}
......@@ -106,7 +106,7 @@ static int knot_zone_diff_remove_node(changeset_t *changeset,
/* Remove all the RRSets of the node. */
for (unsigned i = 0; i < node->rrset_count; i++) {
knot_rrset_t rrset = node_rrset_at(node, i);
int ret = changeset_rem_rrset(changeset, &rrset, false);
int ret = changeset_rem_rrset(changeset, &rrset, 0);
if (ret != KNOT_EOK) {
return ret;
}
......@@ -193,7 +193,7 @@ static int knot_zone_diff_rdata(const knot_rrset_t *rrset1,
}
if (!knot_rrset_empty(&to_remove)) {
int ret = changeset_rem_rrset(changeset, &to_remove, false);
int ret = changeset_rem_rrset(changeset, &to_remove, 0);
knot_rdataset_clear(&to_remove.rrs, NULL);
if (ret != KNOT_EOK) {
knot_rdataset_clear(&to_add.rrs, NULL);
......@@ -202,7 +202,7 @@ static int knot_zone_diff_rdata(const knot_rrset_t *rrset1,
}
if (!knot_rrset_empty(&to_add)) {
int ret = changeset_add_rrset(changeset, &to_add, false);
int ret = changeset_add_rrset(changeset, &to_add, 0);
knot_rdataset_clear(&to_add.rrs, NULL);
return ret;
}
......@@ -272,7 +272,7 @@ static int knot_zone_diff_node(zone_node_t **node_ptr, void *data)
if (knot_rrset_empty(&rrset_from_second_node)) {
/* RRSet has been removed. Make a copy and remove. */
int ret = changeset_rem_rrset(
param->changeset, &rrset, false);
param->changeset, &rrset, 0);
if (ret != KNOT_EOK) {
return ret;
}
......@@ -300,7 +300,7 @@ static int knot_zone_diff_node(zone_node_t **node_ptr, void *data)
if (knot_rrset_empty(&rrset_from_first_node)) {
/* RRSet has been added. Make a copy and add. */
int ret = changeset_add_rrset(
param->changeset, &rrset, false);
param->changeset, &rrset, 0);
if (ret != KNOT_EOK) {
return ret;
}
......
......@@ -49,20 +49,20 @@ int main(int argc, char *argv[])
uint8_t data[8] = "\7teststr";
knot_rrset_add_rdata(apex_txt_rr, data, sizeof(data), 3600, NULL);
int ret = changeset_add_rrset(ch, apex_txt_rr, true);
int ret = changeset_add_rrset(ch, apex_txt_rr, CHANGESET_CHECK);
ok(ret == KNOT_EOK, "changeset: add RRSet");
ok(changeset_size(ch) == 1, "changeset: size add");
ret = changeset_rem_rrset(ch, apex_txt_rr, true);
ret = changeset_rem_rrset(ch, apex_txt_rr, CHANGESET_CHECK);
ok(ret == KNOT_EOK, "changeset: rem RRSet");
ok(changeset_size(ch) == 1, "changeset: size remove");
ok(!changeset_empty(ch), "changeset: empty");
changeset_add_rrset(ch, apex_txt_rr, true);
changeset_add_rrset(ch, apex_txt_rr, CHANGESET_CHECK);
// Add another RR to node.
knot_rrset_t *apex_spf_rr = knot_rrset_new(d, KNOT_RRTYPE_SPF, KNOT_CLASS_IN, NULL);
assert(apex_spf_rr);
knot_rrset_add_rdata(apex_spf_rr, data, sizeof(data), 3600, NULL);
ret = changeset_add_rrset(ch, apex_spf_rr, true);
ret = changeset_add_rrset(ch, apex_spf_rr, CHANGESET_CHECK);
ok(ret == KNOT_EOK, "changeset: add multiple");
// Add another node.
......@@ -72,7 +72,7 @@ int main(int argc, char *argv[])
knot_rrset_t *other_rr = knot_rrset_new(d, KNOT_RRTYPE_TXT, KNOT_CLASS_IN, NULL);
assert(other_rr);
knot_rrset_add_rdata(other_rr, data, sizeof(data), 3600, NULL);
ret = changeset_add_rrset(ch, other_rr, true);
ret = changeset_add_rrset(ch, other_rr, CHANGESET_CHECK);
ok(ret == KNOT_EOK, "changeset: remove multiple");
// Test add traversal.
......@@ -93,8 +93,8 @@ int main(int argc, char *argv[])
changeset_iter_clear(&it);
ok(knot_rrset_empty(&iter), "changeset: traversal: skip non-terminals");
changeset_rem_rrset(ch, apex_txt_rr, true);
changeset_rem_rrset(ch, apex_txt_rr, true);
changeset_rem_rrset(ch, apex_txt_rr, CHANGESET_CHECK);
changeset_rem_rrset(ch, apex_txt_rr, CHANGESET_CHECK);
// Test remove traversal.
ret = changeset_iter_rem(&it, ch, false);
......@@ -127,7 +127,7 @@ int main(int argc, char *argv[])
knot_dname_free(&apex_txt_rr->owner, NULL);
apex_txt_rr->owner = knot_dname_from_str_alloc("something.test.");
assert(apex_txt_rr->owner);
ret = changeset_add_rrset(ch2, apex_txt_rr, true);
ret = changeset_add_rrset(ch2, apex_txt_rr, CHANGESET_CHECK);
assert(ret == KNOT_EOK);
// Add something to remove section.
......@@ -135,7 +135,7 @@ int main(int argc, char *argv[])
apex_txt_rr->owner =
knot_dname_from_str_alloc("and.now.for.something.completely.different.test.");
assert(apex_txt_rr->owner);
ret = changeset_rem_rrset(ch2, apex_txt_rr, true);
ret = changeset_rem_rrset(ch2, apex_txt_rr, CHANGESET_CHECK);
assert(ret == KNOT_EOK);
// Test merge.
......
......@@ -97,7 +97,7 @@ static void init_random_changeset(changeset_t *ch, const uint32_t from, const ui
for (size_t i = 0; i < size / 2; ++i) {
knot_rrset_t rr;
init_random_rr(&rr, apex);
int ret = changeset_add_rrset(ch, &rr, false);
int ret = changeset_add_rrset(ch, &rr, 0);
assert(ret == KNOT_EOK);
knot_rrset_clear(&rr, NULL);
}
......@@ -106,7 +106,7 @@ static void init_random_changeset(changeset_t *ch, const uint32_t from, const ui
for (size_t i = 0; i < size / 2; ++i) {
knot_rrset_t rr;
init_random_rr(&rr, apex);
int ret = changeset_rem_rrset(ch, &rr, false);
int ret = changeset_rem_rrset(ch, &rr, 0);
assert(ret == KNOT_EOK);
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