Commit fb6cdc4e authored by Lubos Slovak's avatar Lubos Slovak

Replaced wildcard child reference by a flag.

refs #216

Conflicts:
	src/knot/zone/node.h
parent 241a324a
......@@ -426,10 +426,14 @@ static int name_not_found(knot_pkt_t *pkt, struct query_data *qdata)
dbg_ns("%s(%p, %p)\n", __func__, pkt, qdata);
/* Name is covered by wildcard. */
const knot_node_t *wildcard_node = knot_node_wildcard_child(qdata->encloser);
if (wildcard_node) {
if (knot_node_has_wildcard_child(qdata->encloser)) {
dbg_ns("%s: name %p covered by wildcard\n", __func__, qdata->name);
qdata->node = wildcard_node;
/* Find wildcard child in the zone. */
qdata->node = knot_zone_contents_find_wildcard_child(
qdata->zone->contents, qdata->encloser);
assert(qdata->node != NULL);
/* keep encloser */
qdata->previous = NULL;
......@@ -437,8 +441,8 @@ static int name_not_found(knot_pkt_t *pkt, struct query_data *qdata)
int next_state = name_found(pkt, qdata);
/* Put to wildcard node list. */
if (wildcard_visit(qdata, wildcard_node, qdata->name) != KNOT_EOK) {
next_state = ERROR;
if (wildcard_visit(qdata, qdata->node, qdata->name) != KNOT_EOK) {
next_state = ERROR;
}
return next_state;
......
......@@ -1382,8 +1382,9 @@ static int xfrin_mark_empty(knot_node_t **node_p, void *data)
}
knot_node_set_empty(node);
if (node->parent) {
if (node->parent->wildcard_child == node) {
node->parent->wildcard_child = NULL;
if (knot_node_has_wildcard_child(node->parent)
&& knot_dname_is_wildcard(node->owner)) {
knot_node_clear_wildcard_child(node->parent);
}
node->parent->children--;
// Recurse using the parent node
......
......@@ -417,37 +417,27 @@ knot_dname_t *knot_node_get_owner(const knot_node_t *node)
/*----------------------------------------------------------------------------*/
knot_node_t *knot_node_get_wildcard_child(const knot_node_t *node)
void knot_node_set_wildcard_child(knot_node_t *node)
{
if (node == NULL) {
return NULL;
return;
}
return node->wildcard_child;
knot_node_flags_set(node, KNOT_NODE_FLAGS_WILDCARD_CHILD);
}
/*----------------------------------------------------------------------------*/
void knot_node_set_wildcard_child(knot_node_t *node,
knot_node_t *wildcard_child)
int knot_node_has_wildcard_child(const knot_node_t *node)
{
if (node == NULL) {
return;
}
node->wildcard_child = wildcard_child;
// assert(wildcard_child->parent == node);
return knot_node_flags_get(node, KNOT_NODE_FLAGS_WILDCARD_CHILD);
}
/*----------------------------------------------------------------------------*/
const knot_node_t *knot_node_wildcard_child(const knot_node_t *node)
void knot_node_clear_wildcard_child(knot_node_t *node)
{
if (node == NULL) {
return NULL;
}
return knot_node_get_wildcard_child(node);
knot_node_flags_clear(node, KNOT_NODE_FLAGS_WILDCARD_CHILD);
}
/*----------------------------------------------------------------------------*/
......@@ -501,8 +491,6 @@ void knot_node_update_refs(knot_node_t *node)
knot_node_update_ref(&node->prev);
// reference to parent
knot_node_update_ref(&node->parent);
// reference to wildcard child
knot_node_update_ref(&node->wildcard_child);
// reference to NSEC3 node
knot_node_update_ref(&node->nsec3_node);
}
......
......@@ -48,9 +48,6 @@ struct knot_node {
/*! \brief Type-ordered list of RRSets belonging to this node. */
knot_rrset_t **rrset_tree;
/*! \brief Wildcard node being the direct descendant of this node. */
struct knot_node *wildcard_child;
/*!
* \brief Previous node in canonical order.
*
......@@ -80,6 +77,7 @@ struct knot_node {
* 0x01 - node is a delegation point
* 0x02 - node is non-authoritative (under a delegation point)
* 0x04 - NSEC(3) was removed from the node.
* 0x08 - Node has a wildcard child.
* 0x10 - node is empty and will be deleted after update
*/
uint8_t flags;
......@@ -101,6 +99,8 @@ typedef enum {
/*! \brief Node is empty and will be deleted after update.
* \todo Remove after dname refactoring, update description in node. */
KNOT_NODE_FLAGS_EMPTY = 1 << 4,
/*! \brief Node has a wildcard child. */
KNOT_NODE_FLAGS_WILDCARD_CHILD = (uint8_t)0x08,
} knot_node_flags_t;
/*----------------------------------------------------------------------------*/
......@@ -288,7 +288,7 @@ const knot_node_t *knot_node_nsec3_node(const knot_node_t *node);
void knot_node_set_nsec3_node(knot_node_t *node, knot_node_t *nsec3_node);
/*!
* \brief Returns the owner of the node.
* \brief Returns the owner of the node as a const reference.
*
* \param node Node to get the owner of.
*
......@@ -297,33 +297,37 @@ void knot_node_set_nsec3_node(knot_node_t *node, knot_node_t *nsec3_node);
const knot_dname_t *knot_node_owner(const knot_node_t *node);
/*!
* \todo Document me.
* \brief Returns the owner of the node as a non-const reference.
*
* \param node Node to get the owner of.
*
* \return Owner of the given node.
*/
knot_dname_t *knot_node_get_owner(const knot_node_t *node);
/*!
* \brief Returns the wildcard child of the node.
*
* \param node Node to get the owner of.
* \brief Sets the wildcard child flag of the node.
*
* \return Wildcard child of the given node or NULL if it has none.
* \param node Node that has wildcard.
*/
const knot_node_t *knot_node_wildcard_child(const knot_node_t *node);
void knot_node_set_wildcard_child(knot_node_t *node);
/*!
* \brief Sets the wildcard child of the node.
* \brief Checks if node has a wildcard child.
*
* \param node Node to set the wildcard child of.
* \param wildcard_child Wildcard child of the node.
* \param node Node to check.
*
* \retval > 0 if the node has a wildcard child.
* \retval 0 otherwise.
*/
void knot_node_set_wildcard_child(knot_node_t *node,
knot_node_t *wildcard_child);
knot_node_t *knot_node_get_wildcard_child(const knot_node_t *node);
//const knot_node_t *knot_node_current(const knot_node_t *node);
int knot_node_has_wildcard_child(const knot_node_t *node);
//knot_node_t *knot_node_get_current(knot_node_t *node);
/*!
* \brief Clears the node's wildcard child flag.
*
* \param node Node to clear the flag in.
*/
void knot_node_clear_wildcard_child(knot_node_t *node);
const knot_node_t *knot_node_new_node(const knot_node_t *node);
......
......@@ -174,8 +174,12 @@ static int discover_additionals(knot_rrset_t *rr, knot_zone_contents_t *zone)
/* Try to find node for the dname in the RDATA. */
dname = knot_rdata_name(rr, i);
knot_zone_contents_find_dname(zone, dname, &node, &encloser, &prev);
if (node == NULL && encloser && encloser->wildcard_child) {
node = encloser->wildcard_child;
if (node == NULL && encloser
&& knot_node_has_wildcard_child(encloser)) {
/* Find wildcard child in the zone. */
node = knot_zone_contents_find_wildcard_child(zone,
encloser);
assert(node != NULL);
}
rr->additional[i] = (knot_node_t *)node;
......@@ -203,7 +207,7 @@ static int adjust_pointers(knot_node_t **tnode, void *data)
if (knot_dname_is_wildcard(knot_node_owner(node))) {
assert(knot_node_parent(node) != NULL);
knot_node_set_wildcard_child(knot_node_get_parent(node), node);
knot_node_set_wildcard_child(knot_node_get_parent(node));
}
// set flags (delegation point, non-authoritative)
......@@ -551,7 +555,7 @@ dbg_zone_exec_detail(
// check if the node is not wildcard child of the parent
if (knot_dname_is_wildcard(knot_node_owner(node))) {
knot_node_set_wildcard_child(zone->apex, node);
knot_node_set_wildcard_child(zone->apex);
}
} else {
while (parent != NULL &&
......@@ -576,7 +580,7 @@ dbg_zone_exec_detail(
/* Update node pointers. */
knot_node_set_parent(node, next_node);
if (knot_dname_is_wildcard(knot_node_owner(node))) {
knot_node_set_wildcard_child(next_node, node);
knot_node_set_wildcard_child(next_node);
}
++zone->node_count;
......@@ -1171,6 +1175,24 @@ knot_node_t *knot_zone_contents_get_apex(const knot_zone_contents_t *zone)
/*----------------------------------------------------------------------------*/
const knot_node_t *knot_zone_contents_find_wildcard_child(
const knot_zone_contents_t *contents, const knot_node_t *parent)
{
if (contents == NULL || parent == NULL
|| knot_node_owner(parent) == NULL) {
return NULL;
}
knot_dname_t *wildcard_name = knot_dname_from_str("*");
knot_dname_cat(wildcard_name, knot_node_owner(parent));
const knot_node_t *node = knot_zone_contents_find_node(contents,
wildcard_name);
knot_dname_free(&wildcard_name, NULL);
return node;
}
/*----------------------------------------------------------------------------*/
static int knot_zone_contents_adjust_nodes(knot_zone_tree_t *nodes,
knot_zone_adjust_arg_t *adjust_arg,
knot_zone_tree_apply_cb_t callback)
......
......@@ -315,6 +315,9 @@ const knot_node_t *knot_zone_contents_apex(
knot_node_t *knot_zone_contents_get_apex(
const knot_zone_contents_t *contents);
const knot_node_t *knot_zone_contents_find_wildcard_child(
const knot_zone_contents_t *contents, const knot_node_t *parent);
/*!
* \brief Sets parent and previous pointers and node flags. (cheap operation)
* For both normal and NSEC3 tree
......
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