]> git.ipfire.org Git - thirdparty/knot-dns.git/commitdiff
node: function wrapper to obtaining prev, parent and glue nodes
authorLibor Peltan <libor.peltan@nic.cz>
Wed, 13 Feb 2019 17:14:44 +0000 (18:14 +0100)
committerDaniel Salzman <daniel.salzman@nic.cz>
Fri, 26 Apr 2019 12:39:58 +0000 (14:39 +0200)
src/knot/dnssec/nsec3-chain.c
src/knot/modules/onlinesign/onlinesign.c
src/knot/nameserver/internet.c
src/knot/nameserver/nsec_proofs.c
src/knot/zone/adjust.c
src/knot/zone/contents.c
src/knot/zone/node.c
src/knot/zone/node.h
src/knot/zone/semantic-check.c
src/knot/zone/zone-tree.c
tests/knot/test_node.c

index 0d93090361346c4282eedbebaa5037f6ac24d8b2..d20ba71eeee3e8c7d3588c50fe041233f7e8f9c4 100644 (file)
@@ -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;
        }
index 247bef5ab612502620bee9c19fdecad11c6bfe57..9eeb218917d823ea4f55fb123df26ac3a81e1966 100644 (file)
@@ -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;
                }
 
index 96db1889fe2a54b87a0ec11e021023a95145607f..0c834146c64be29db05c2ce36c8820feda2b8e65 100644 (file)
@@ -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);
        }
 
index 689bd328267bb60c823607fe9d23d8abe5151d99..41f4caac69630e55fb16781366a0d603f241c41b 100644 (file)
@@ -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);
 }
index 20541eb5c439f7393f71518cbbff44b3af6c8f85..ef3181c1db2bd167a13d6c79b6e4298e131d36b3 100644 (file)
 
 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;
index 426e61cb3e655f67f4c58a55a22fdd8f97b36542..1275a93faaab1f7e879db5faf88dd68a2dc840ea 100644 (file)
@@ -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;
index 0f31b5bb0b62afe86e56931c69c0d43dd231f8c2..8b8e7ad3bb4e363b0571c1958b4e56e35b63b1f8 100644 (file)
@@ -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) {
index 8a77bae6e424ee0ab333ba45f7c82f12222adce9..2c2eb408b635aa024136f29842babd7ad7fb3b28 100644 (file)
@@ -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.
  *
index eda497dc51be0bacfd468efe170e5c055fc5bec8..26bf2abf90c2a40cf6782168701e65e9666ac404 100644 (file)
@@ -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,
index e0e8b2ba76a63da6bd7bfb1324e2f1f015e8d466..9ec9fd6f50cbdb41cea577f753347d80a1450ec3 100644 (file)
@@ -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);
index 3abacaa7bf13d02fcbc22dd25fecf500c6830fe3..0721a4410b5f0ba191e11beee7f33ade6142d89c 100644 (file)
@@ -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);