Commit 7b9cc47f authored by Libor Peltan's avatar Libor Peltan Committed by Daniel Salzman

node: function wrapper to obtaining prev, parent and glue nodes

parent 6eb8875f
......@@ -701,9 +701,9 @@ static int nsec3_mark_empty(zone_node_t *node, void *data)
* but only temporarily! It must be set back right after
* the operation
*/
node->parent->children--;
node_parent(node)->children--;
/* Recurse using the parent node */
return nsec3_mark_empty(node->parent, data);
return nsec3_mark_empty(node_parent(node), data);
}
}
......@@ -724,7 +724,7 @@ static int nsec3_reset(zone_node_t *node, void *data)
/* If node was marked as empty, increase its parent's children
* count.
*/
node->parent->children++;
node_parent(node)->children++;
/* Clear the 'empty' flag. */
node->flags &= ~NODE_FLAGS_EMPTY;
}
......
......@@ -309,12 +309,13 @@ static glue_t *find_glue_for(const knot_rrset_t *rr, const knot_pkt_t *pkt)
return NULL;
}
static bool shall_sign_rr(const knot_rrset_t *rr, const knot_pkt_t *pkt)
static bool shall_sign_rr(const knot_rrset_t *rr, const knot_pkt_t *pkt, knotd_qdata_t *qdata)
{
if (pkt->current == KNOT_ADDITIONAL) {
glue_t *g = find_glue_for(rr, pkt);
assert(g); // finds actually the node which is rr in
return !(g->node->flags & NODE_FLAGS_NONAUTH);
const zone_node_t *gn = glue_node(g, qdata->extra->node);
return !(gn->flags & NODE_FLAGS_NONAUTH);
} else {
return !is_deleg(pkt) || rr->type == KNOT_RRTYPE_NSEC;
}
......@@ -338,7 +339,7 @@ static knotd_in_state_t sign_section(knotd_in_state_t state, knot_pkt_t *pkt,
uint16_t count_unsigned = section->count;
for (int i = 0; i < count_unsigned; i++) {
const knot_rrset_t *rr = knot_pkt_rr(section, i);
if (!shall_sign_rr(rr, pkt)) {
if (!shall_sign_rr(rr, pkt, qdata)) {
continue;
}
......
......@@ -190,7 +190,7 @@ static int put_delegation(knot_pkt_t *pkt, knotd_qdata_t *qdata)
{
/* Find closest delegation point. */
while (!(qdata->extra->node->flags & NODE_FLAGS_DELEG)) {
qdata->extra->node = qdata->extra->node->parent;
qdata->extra->node = node_parent(qdata->extra->node);
}
/* Insert NS record. */
......@@ -229,7 +229,7 @@ static int put_additional(knot_pkt_t *pkt, const knot_rrset_t *rr,
uint16_t hint = knot_compr_hint(info, KNOT_COMPR_HINT_RDATA +
glue->ns_pos);
knot_rrset_t rrsigs = node_rrset(glue->node, KNOT_RRTYPE_RRSIG);
knot_rrset_t rrsigs = node_rrset(glue_node(glue, qdata->extra->node), KNOT_RRTYPE_RRSIG);
for (int k = 0; k < ar_type_count; ++k) {
knot_rrset_t rrset = node_rrset(glue->node, ar_type_list[k]);
if (knot_rrset_empty(&rrset)) {
......@@ -385,7 +385,7 @@ static int name_not_found(knot_pkt_t *pkt, knotd_qdata_t *qdata)
/* Look up an authoritative encloser or its parent. */
const zone_node_t *node = qdata->extra->encloser;
while (node->rrset_count == 0 || node->flags & NODE_FLAGS_NONAUTH) {
node = node->parent;
node = node_parent(node);
assert(node);
}
......
......@@ -79,7 +79,7 @@ static const zone_node_t *nsec_previous(const zone_node_t *previous)
assert(previous);
while (!node_in_nsec(previous)) {
previous = previous->prev;
previous = node_prev(previous);
assert(previous);
}
......@@ -94,7 +94,7 @@ static const zone_node_t *nsec3_encloser(const zone_node_t *closest)
assert(closest);
while (!node_in_nsec3(closest)) {
closest = closest->parent;
closest = node_parent(closest);
assert(closest);
}
......@@ -322,7 +322,7 @@ static int put_nsec3_wildcard(const zone_node_t *wildcard,
knotd_qdata_t *qdata,
knot_pkt_t *resp)
{
const zone_node_t *cpe = nsec3_encloser(wildcard->parent);
const zone_node_t *cpe = nsec3_encloser(node_parent(wildcard));
return put_nsec3_next_closer(cpe, qname, zone, qdata, resp);
}
......
......@@ -23,16 +23,15 @@
int adjust_cb_flags(zone_node_t *node, const zone_contents_t *zone)
{
zone_node_t *parent = node_parent(node);
// check if this node is not a wildcard child of its parent
if (knot_dname_is_wildcard(node->owner)) {
assert(node->parent != NULL);
node->parent->flags |= NODE_FLAGS_WILDCARD_CHILD;
parent->flags |= NODE_FLAGS_WILDCARD_CHILD;
}
// set flags (delegation point, non-authoritative)
if (node->parent &&
(node->parent->flags & NODE_FLAGS_DELEG ||
node->parent->flags & NODE_FLAGS_NONAUTH)) {
if (parent && (parent->flags & NODE_FLAGS_DELEG || parent->flags & NODE_FLAGS_NONAUTH)) {
node->flags |= NODE_FLAGS_NONAUTH;
} else if (node_rrtype_exists(node, KNOT_RRTYPE_NS) && node != zone->apex) {
node->flags |= NODE_FLAGS_DELEG;
......
......@@ -228,7 +228,6 @@ static int add_node(zone_contents_t *zone, zone_node_t *node, bool create_parent
// set the found parent (in the zone) as the parent of the last
// inserted node
assert(node->parent == NULL);
node_set_parent(node, next_node);
}
......@@ -514,7 +513,7 @@ int zone_contents_find_dname(const zone_contents_t *zone,
node = prev;
size_t matched_labels = knot_dname_matched_labels(node->owner, name);
while (matched_labels < knot_dname_labels(node->owner, NULL)) {
node = node->parent;
node = node_parent(node);
assert(node);
}
......@@ -582,7 +581,7 @@ int zone_contents_find_nsec3(const zone_contents_t *zone,
// set the previous node of the found node
assert(match);
assert(*nsec3_node != NULL);
*nsec3_previous = (*nsec3_node)->prev;
*nsec3_previous = node_prev(*nsec3_node);
} else {
*nsec3_previous = prev;
}
......@@ -590,7 +589,7 @@ int zone_contents_find_nsec3(const zone_contents_t *zone,
// The previous may be from wrong NSEC3 chain. Search for previous from the right chain.
const zone_node_t *original_prev = *nsec3_previous;
while (!((*nsec3_previous)->flags & NODE_FLAGS_IN_NSEC3_CHAIN)) {
*nsec3_previous = (*nsec3_previous)->prev;
*nsec3_previous = node_prev(*nsec3_previous);
if (*nsec3_previous == original_prev || *nsec3_previous == NULL) {
// cycle
*nsec3_previous = NULL;
......
......@@ -260,6 +260,22 @@ void node_set_parent(zone_node_t *node, zone_node_t *parent)
}
}
zone_node_t *node_parent(const zone_node_t *node)
{
return node->parent;
}
zone_node_t *node_prev(const zone_node_t *node)
{
return node->prev;
}
const zone_node_t *glue_node(const glue_t *glue, const zone_node_t *another_zone_node)
{
UNUSED(another_zone_node);
return glue->node;
}
bool node_rrtype_is_signed(const zone_node_t *node, uint16_t type)
{
if (node == NULL) {
......
......@@ -181,6 +181,26 @@ knot_rdataset_t *node_rdataset(const zone_node_t *node, uint16_t type);
*/
void node_set_parent(zone_node_t *node, zone_node_t *parent);
/*!
* \brief Returns parent node (fixing bi-node issue) of given node.
*/
zone_node_t *node_parent(const zone_node_t *node);
/*!
* \brief Returns previous (lexicographically in same zone tree) node (fixing bi-node issue) of given node.
*/
zone_node_t *node_prev(const zone_node_t *node);
/*!
* \brief Return node referenced by a glue.
*
* \param glue Glue in question.
* \param another_zone_node Another node from the same zone.
*
* \return Glue node.
*/
const zone_node_t *glue_node(const glue_t *glue, const zone_node_t *another_zone_node);
/*!
* \brief Checks whether node contains any RRSIG for given type.
*
......
......@@ -1007,7 +1007,7 @@ static int check_nsec3(const zone_node_t *node, semchecks_data_t *data)
const zone_node_t *next_nsec3 = zone_contents_find_nsec3_node(data->zone,
next_dname);
if (next_nsec3 == NULL || next_nsec3->prev != node->nsec3_node) {
if (next_nsec3 == NULL || node_prev(next_nsec3) != node->nsec3_node) {
uint8_t *next = NULL;
int32_t next_len = base32hex_encode_alloc(next_dname_str,
next_dname_str_size,
......
......@@ -102,7 +102,7 @@ int zone_tree_get_less_or_equal(zone_tree_t *tree,
int exact_match = 0;
if (ret == KNOT_EOK) {
if (fval != NULL) {
*previous = (*found)->prev;
*previous = node_prev(*found);
}
exact_match = 1;
} else if (ret == 1) {
......@@ -120,7 +120,7 @@ int zone_tree_get_less_or_equal(zone_tree_t *tree,
return ret;
}
*previous = zone_tree_it_val(&it); /* leftmost */
*previous = (*previous)->prev; /* rightmost */
*previous = node_prev(*previous); /* rightmost */
*found = NULL;
zone_tree_it_free(&it);
}
......@@ -161,7 +161,7 @@ void zone_tree_delete_empty(zone_tree_t *tree, zone_node_t *node)
}
if (node->rrset_count == 0 && node->children == 0) {
zone_node_t *parent_node = node->parent;
zone_node_t *parent_node = node_parent(node);
if (parent_node != NULL) {
parent_node->children--;
fix_wildcard_child(parent_node, node->owner);
......
......@@ -60,7 +60,7 @@ int main(int argc, char *argv[])
zone_node_t *parent = node_new(dummy_owner, NULL);
assert(parent);
node_set_parent(node, parent);
ok(node->parent == parent && parent->children == 1, "Node: set parent.");
ok(node_parent(node) == parent && parent->children == 1, "Node: set parent.");
node_free(parent, 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