Skip to content
Snippets Groups Projects
Commit 52b9d5fb authored by Daniel Salzman's avatar Daniel Salzman Committed by David Vasek
Browse files

contents: refactor zone_contents_find_dname()

parent 91fb954b
No related branches found
No related tags found
No related merge requests found
Pipeline #132209 passed
......@@ -300,50 +300,37 @@ int zone_contents_find_dname(const zone_contents_t *zone,
int found = zone_tree_get_less_or_equal(zone->nodes, name, &node, &prev);
if (found < 0) {
// error
return found;
} else if (found == 1) {
// exact match
// if previous==NULL, zone not adjusted yet
}
assert(node);
*match = node;
if (previous != NULL) { // Null previous means zone not adjusted yet.
assert(prev);
*previous = prev;
}
// WARNING: for the sake of efficiency, Knot does not handle \0 byte in qname correctly
// which can lead to disasters here and there. This should cover most of the cases.
if (found == 1) {
// WARNING: for the sake of efficiency, Knot does not handle \0 byte
// in qname correctly, which can lead to disasters here and there.
// The following check should cover most of the cases.
assert(node);
bool node_nullbyte = (node->flags & NODE_FLAGS_NULLBYTE);
if (node_nullbyte != name_nullbyte ||
(node_nullbyte && !knot_dname_is_equal(node->owner, name))) {
goto nxd;
}
*match = node;
*closest = node;
if (previous != NULL) {
assert(prev);
*previous = prev;
}
return ZONE_NAME_FOUND;
} else {
// closest match
assert(!node && prev);
nxd:
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);
assert(node);
}
*match = NULL;
*closest = node;
if (previous != NULL) {
*previous = prev;
if (node_nullbyte == name_nullbyte &&
(!node_nullbyte || knot_dname_is_equal(node->owner, name))) {
*closest = node;
return ZONE_NAME_FOUND;
}
}
return ZONE_NAME_NOT_FOUND;
assert(prev);
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);
assert(node);
}
*closest = node;
return ZONE_NAME_NOT_FOUND;
}
const zone_node_t *zone_contents_find_nsec3_node(const zone_contents_t *zone,
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment