Commit 999cc10b authored by Jan Kadlec's avatar Jan Kadlec

new_node: Removed obsolete RRSet API function.

- find_rr_pos was used as an intersect operation.
- added flag to compare TTLs for intersection operation - I don't like
  this, other way would be to check if one of the TTLs is 0 and ignore
it then, but I doubt that would be transparent enough.
parent 3550de14
......@@ -439,8 +439,10 @@ static bool node_contains_rr(const knot_node_t *node,
knot_rrset_t zone_rrset = knot_node_rrset(node, rr->type);
if (!knot_rrset_empty(&zone_rrset)) {
knot_rrset_t intersection;
const bool compare_ttls = false;
int ret = knot_rrset_intersection(&zone_rrset, rr,
&intersection, NULL);
&intersection, compare_ttls,
NULL);
if (ret != KNOT_EOK) {
return false;
}
......@@ -771,7 +773,9 @@ static int process_rem_rr(const knot_rrset_t *rr,
}
knot_rrset_t intersection;
int ret = knot_rrset_intersection(&to_modify, rr, &intersection, NULL);
const bool compare_ttls = false;
int ret = knot_rrset_intersection(&to_modify, rr, &intersection,
compare_ttls, NULL);
if (ret != KNOT_EOK) {
return ret;
}
......
......@@ -711,7 +711,9 @@ static bool can_remove(const knot_node_t *node, const knot_rrset_t *rr)
}
knot_rrset_t intersection;
knot_rrset_intersection(&node_rrset, rr, &intersection, NULL);
const bool compare_ttls = false;
knot_rrset_intersection(&node_rrset, rr, &intersection,
compare_ttls, NULL);
if (knot_rrset_empty(&intersection)) {
return false;
}
......
......@@ -201,6 +201,31 @@ static int knot_zone_diff_remove_node(knot_changeset_t *changeset,
return KNOT_EOK;
}
static bool rr_exists(const knot_rrset_t *in, const knot_rrset_t *ref,
size_t ref_pos)
{
// Create RRSet with single RR fron 'ref' RRSet, position 'ref_pos'.
knot_rrset_t ref_rr;
knot_rrset_init(&ref_rr, ref->owner, ref->type, ref->rclass);
int ret = knot_rrset_add_rr_from_rrset(&ref_rr, ref, ref_pos, NULL);
if (ret != KNOT_EOK) {
return false;
}
// Do an intersection with 'in' rrset, if non-empty, RR exists.
knot_rrset_t int_rr;
const bool compare_ttls = true;
ret = knot_rrset_intersection(in, &ref_rr, &int_rr, compare_ttls, NULL);
knot_rrs_clear(&ref_rr.rrs, NULL);
if (ret != KNOT_EOK) {
return false;
}
const bool exists = !knot_rrset_empty(&int_rr);
knot_rrs_clear(&int_rr.rrs, NULL);
return exists;
}
static int knot_zone_diff_rdata_return_changes(const knot_rrset_t *rrset1,
const knot_rrset_t *rrset2,
knot_rrset_t **changes)
......@@ -238,35 +263,19 @@ static int knot_zone_diff_rdata_return_changes(const knot_rrset_t *rrset1,
uint16_t rr1_count = knot_rrset_rr_count(rrset1);
for (uint16_t i = 0; i < rr1_count; ++i) {
size_t rr_pos = 0;
int ret = knot_rrset_find_rr_pos(rrset2, rrset1, i, &rr_pos);
if (ret == KNOT_ENOENT) {
if (!rr_exists(rrset2, rrset1, i)) {
/* No such RR is present in 'rrset2'. */
dbg_zonediff("zone_diff: diff_rdata: "
"No match for RR (type=%u owner=%p).\n",
rrset1->type,
rrset1->owner);
/* We'll copy index 'i' into 'changes' RRSet. */
ret = knot_rrset_add_rr_from_rrset(*changes, rrset1, i, NULL);
int ret = knot_rrset_add_rr_from_rrset(*changes,
rrset1, i, NULL);
if (ret != KNOT_EOK) {
knot_rrset_free(changes, NULL);
return ret;
}
} else if (ret == KNOT_EOK) {
if (knot_rrset_rr_ttl(rrset1, i) !=
knot_rrset_rr_ttl(rrset2, rr_pos)) {
// TTLs differ add a change
ret = knot_rrset_add_rr_from_rrset(*changes, rrset1, i, NULL);
if (ret != KNOT_EOK) {
knot_rrset_free(changes, NULL);
return ret;
}
}
} else {
dbg_zonediff("zone_diff: diff_rdata: Could not search "
"for RR (%s).\n", knot_strerror(ret));
knot_rrset_free(changes, NULL);
return ret;
}
}
......
......@@ -664,11 +664,11 @@ bool knot_rrset_equal(const knot_rrset_t *r1,
return r1 == r2;
}
if (!knot_dname_is_equal(r1->owner, r2->owner)) {
if (r1->type != r2->type) {
return false;
}
if (r1->type != r2->type) {
if (!knot_dname_is_equal(r1->owner, r2->owner)) {
return false;
}
......@@ -731,9 +731,8 @@ bool knot_rrset_is_nsec3rel(const knot_rrset_t *rr)
== KNOT_RRTYPE_NSEC3));
}
int knot_rrset_find_rr_pos(const knot_rrset_t *rr_search_in,
const knot_rrset_t *rr_reference, size_t pos,
size_t *pos_out)
static uint16_t find_rr_pos(const knot_rrset_t *rr_search_in,
const knot_rrset_t *rr_reference, size_t pos)
{
bool found = false;
uint16_t rr_count = knot_rrset_rr_count(rr_search_in);
......@@ -741,12 +740,11 @@ int knot_rrset_find_rr_pos(const knot_rrset_t *rr_search_in,
const knot_rr_t *in_rr = knot_rrs_rr(&rr_search_in->rrs, i);
const knot_rr_t *ref_rr = knot_rrs_rr(&rr_reference->rrs, pos);
if (knot_rr_cmp(in_rr, ref_rr) == 0) {
*pos_out = i;
found = true;
return i;
}
}
return found ? KNOT_EOK : KNOT_ENOENT;
return KNOT_ENOENT;
}
static int knot_rrset_remove_rr(knot_rrset_t *rrset,
......@@ -757,27 +755,14 @@ static int knot_rrset_remove_rr(knot_rrset_t *rrset,
* Position in first and second rrset can differ, we have
* to search for position first.
*/
size_t pos_to_remove = 0;
int ret = knot_rrset_find_rr_pos(rrset, rr_from, rdata_pos,
&pos_to_remove);
if (ret == KNOT_EOK) {
uint16_t pos_to_remove = find_rr_pos(rrset, rr_from, rdata_pos);
if (pos_to_remove >= 0) {
/* Position found, can be removed. */
dbg_rrset_detail("rr: remove_rr: Counter position found=%zu\n",
pos_to_remove);
assert(pos_to_remove < knot_rrset_rr_count(rrset));
ret = knot_rrs_remove_rr_at_pos(&rrset->rrs, pos_to_remove, mm);
if (ret != KNOT_EOK) {
dbg_rrset("Cannot remove RDATA from RRSet (%s).\n",
knot_strerror(ret));
return ret;
}
return knot_rrs_remove_rr_at_pos(&rrset->rrs, pos_to_remove, mm);
} else {
dbg_rrset_verb("rr: remove_rr: RDATA not found (%s).\n",
knot_strerror(ret));
return ret;
assert(pos_to_remove == KNOT_ENOENT);
return KNOT_ENOENT;
}
return KNOT_EOK;
}
int knot_rrset_add_rr_from_rrset(knot_rrset_t *dest, const knot_rrset_t *source,
......@@ -816,19 +801,30 @@ int knot_rrset_remove_rr_using_rrset(knot_rrset_t *from,
return KNOT_EOK;
}
static bool has_rr(const knot_rrset_t *rrset, const knot_rr_t *rr)
static bool has_rr(const knot_rrset_t *rrset, const knot_rr_t *rr, bool cmp_ttl)
{
for (uint16_t i = 0; i < rrset->rrs.rr_count; ++i) {
const knot_rr_t *cmp_rr = knot_rrs_rr(&rrset->rrs, i);
if (knot_rr_cmp(cmp_rr, rr) == 0) {
if (cmp_ttl) {
if (knot_rr_ttl(rr) != knot_rr_ttl(cmp_rr)) {
continue;
}
}
int cmp = knot_rr_cmp(cmp_rr, rr);
if (cmp == 0) {
// Match.
return true;
}
if (cmp > 0) {
// 'Bigger' RR present, no need to continue.
return false;
}
}
return false;
}
int knot_rrset_intersection(const knot_rrset_t *a, const knot_rrset_t *b,
knot_rrset_t *out, mm_ctx_t *mm)
knot_rrset_t *out, bool cmp_ttl, mm_ctx_t *mm)
{
if (a == NULL || b == NULL || !knot_dname_is_equal(a->owner, b->owner) ||
a->type != b->type) {
......@@ -838,7 +834,8 @@ int knot_rrset_intersection(const knot_rrset_t *a, const knot_rrset_t *b,
knot_rrset_init(out, a->owner, a->type, a->rclass);
for (uint16_t i = 0; i < a->rrs.rr_count; ++i) {
const knot_rr_t *rr = knot_rrs_rr(&a->rrs, i);
if (has_rr(b, rr)) {
if (has_rr(b, rr, cmp_ttl)) {
// Add RR into output intersection RRSet.
int ret = knot_rrset_add_rr_from_rrset(out, a, i, mm);
if (ret != KNOT_EOK) {
knot_rrs_clear(&out->rrs, mm);
......
......@@ -246,22 +246,6 @@ int knot_rrset_remove_rr_using_rrset(knot_rrset_t *from,
const knot_rrset_t *what,
mm_ctx_t *mm);
/*!
* \brief Finds RR at 'pos' position in 'rr_reference' RRSet in
* 'rr_search_in' RRSet. Position returned in 'pos_out'.
*
* \param rr_search_in Search in this RRSet.
* \param rr_reference Use RR from this RRSet.
* \param pos Index for 'rr_reference'.
* \param pos_out If found, position returned here.
*
* \retval KNOT_EOK if found, pos_out is set.
* \retval KNOT_ENOENT if not found.
*/
int knot_rrset_find_rr_pos(const knot_rrset_t *rr_search_in,
const knot_rrset_t *rr_reference, size_t pos,
size_t *pos_out);
/*!
* \brief Creates one RR from wire, stores it into 'rrset'
*
......@@ -329,18 +313,19 @@ bool knot_rrset_empty(const knot_rrset_t *rrset);
knot_rrset_t *knot_rrset_copy(const knot_rrset_t *src, mm_ctx_t *mm);
/*!
* \brief RRSet intersection.
* \brief RRSet intersection. Full compare is done, including RDATA.
*
* \param a First RRSet to intersect.
* \param b Second RRset to intersect.
* \param out Output RRSet with intersection, RDATA are created anew, owner is
* just a reference.
* \param mm Memory context.
* \param a First RRSet to intersect.
* \param b Second RRset to intersect.
* \param out Output RRSet with intersection, RDATA are created anew, owner is
* just a reference.
* \param cmp_ttl If set to true, TTLs will be compared as well.
* \param mm Memory context. Will be used to create new RDATA.
*
* \return KNOT_E*
*/
int knot_rrset_intersection(const knot_rrset_t *a, const knot_rrset_t *b,
knot_rrset_t *out, mm_ctx_t *mm);
knot_rrset_t *out, bool cmp_ttl, mm_ctx_t *mm);
/*!
* \brief Initializes given RRSet structure.
......
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