Commit 7e339168 authored by Marek Vavrusa's avatar Marek Vavrusa

CNAME loop over wildcard is checked after RR is added.

This is to give requestor proof of the loop in single response.
Also added test for this case.
parent abb206ef
......@@ -293,30 +293,11 @@ static int follow_cname(knot_pkt_t *pkt, uint16_t rrtype, struct query_data *qda
const knot_node_t *cname_node = qdata->node;
knot_rrset_t *cname_rr = knot_node_get_rrset(qdata->node, rrtype);
int ret = KNOT_EOK;
unsigned flags = 0;
assert(cname_rr != NULL);
/* Is node a wildcard? */
if (knot_dname_is_wildcard(cname_node->owner)) {
/* Check if is not in wildcard nodes (loop). */
dbg_ns("%s: CNAME node %p is wildcard\n", __func__, cname_node);
if (wildcard_has_visited(qdata, cname_node)) {
dbg_ns("%s: node %p already visited => CNAME loop\n",
__func__, cname_node);
return HIT;
}
/* Put to wildcard node list. */
if (wildcard_visit(qdata, cname_node, qdata->name) != KNOT_EOK) {
return ERROR;
}
} else {
/* Normal CNAME name, check for duplicate. */
flags |= KNOT_PF_CHECKDUP;
}
/* Check whether RR is already in the packet. */
uint16_t flags = KNOT_PF_CHECKDUP;
/* Now, try to put CNAME to answer. */
uint16_t rr_count_before = pkt->rrset_count;
......@@ -351,6 +332,24 @@ static int follow_cname(knot_pkt_t *pkt, uint16_t rrtype, struct query_data *qda
}
}
/* If node is a wildcard, follow only if we didn't visit the same node
* earlier, as that would mean a CNAME loop. */
if (knot_dname_is_wildcard(cname_node->owner)) {
/* Check if is not in wildcard nodes (loop). */
dbg_ns("%s: CNAME node %p is wildcard\n", __func__, cname_node);
if (wildcard_has_visited(qdata, cname_node)) {
dbg_ns("%s: node %p already visited => CNAME loop\n",
__func__, cname_node);
return HIT;
}
/* Put to wildcard node list. */
if (wildcard_visit(qdata, cname_node, qdata->name) != KNOT_EOK) {
return ERROR;
}
}
/* Now follow the next CNAME TARGET. */
qdata->name = knot_rdata_cname_name(cname_rr);
......
......@@ -84,3 +84,7 @@ sub.*.wildcard A 6.7.8.9
"12345678901234567890123456789012345678901234567890"
"12345678901234567890123456789012345678901234567890"
"123456789" )
; CNAME loop
*.loop-entry CNAME jump.loop-target
*.loop-target CNAME jump.loop-entry
......@@ -183,6 +183,10 @@ resp.cmp(bind)
resp = knot.dig("a.wildcard-out.flags", "A", udp=True)
resp.cmp(bind)
# Wildcard leading to CNAME loop
resp = knot.dig("test.loop-entry.flags", "A", udp=True)
resp.cmp(bind)
''' Varied case tests. '''
# Negative (case preservation in question)
......
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