Commit bee40b5e authored by Daniel Salzman's avatar Daniel Salzman

nameserver: optimize NXDOMAIN answers

parent 473dc769
......@@ -131,31 +131,6 @@ static knot_dname_t *get_next_closer(const knot_dname_t *closest_encloser,
return knot_dname_copy(name, NULL);
}
/*!
* \brief Create a wildcard child of a name.
*
* \param name Parent of the wildcard.
*
* \return Wildcard child name, NULL on error.
*/
static knot_dname_t *wildcard_child_name(const knot_dname_t *name)
{
assert(name != NULL);
knot_dname_t *wildcard = knot_dname_from_str_alloc("*");
if (wildcard == NULL) {
return NULL;
}
wildcard = knot_dname_cat(wildcard, name);
if (wildcard == NULL) {
return NULL;
}
return wildcard;
}
/*!
* \brief Put NSEC/NSEC3 record with corresponding RRSIG into the response.
*/
......@@ -388,6 +363,19 @@ static int put_wildcard_answer(const zone_node_t *wildcard,
return ret;
}
/*!
* \brief Create a wildcard child of a name as a local variable.
*
* \param out Name of the output wariable.
* \param parent Parent of the wildcard.
*/
#define CREATE_WILDCARD(out, parent) \
int size = knot_dname_size(parent); \
if (size < 0 || size > KNOT_DNAME_MAXLEN - 2) return KNOT_EINVAL; \
uint8_t out[2 + size]; \
memcpy(out, "\x01""*", 2); \
memcpy(out + 2, parent, size);
/*!
* \brief Put NSECs for NXDOMAIN error into the response.
*
......@@ -426,14 +414,9 @@ static int put_nsec_nxdomain(const zone_contents_t *zone,
// NOTE: closest may be empty non-terminal and thus not authoritative.
knot_dname_t *wildcard = wildcard_child_name(closest->owner);
if (wildcard == NULL) {
return KNOT_ENOMEM;
}
ret = put_covering_nsec(zone, wildcard, qdata, resp);
knot_dname_free(&wildcard, NULL);
CREATE_WILDCARD(wildcard, closest->owner)
return ret;
return put_covering_nsec(zone, wildcard, qdata, resp);
}
/*!
......@@ -470,15 +453,9 @@ static int put_nsec3_nxdomain(const knot_dname_t *qname,
// NSEC3 covering the (nonexistent) wildcard at the closest encloser.
knot_dname_t *wildcard = wildcard_child_name(cpe->owner);
if (!wildcard) {
return KNOT_ENOMEM;
}
ret = put_covering_nsec3(zone, wildcard, qdata, resp);
knot_dname_free(&wildcard, NULL);
CREATE_WILDCARD(wildcard, cpe->owner)
return ret;
return put_covering_nsec3(zone, wildcard, qdata, resp);
}
/*!
......
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