Commit 751bf435 authored by Jan Včelák's avatar Jan Včelák 🚀

server: store previous node for wildcard expansion source

The real previous name has to be stored because the wildcard
needn't be expanded from QNAME but can be expanded as a part
of CNAME/DNAME chain.
parent 2a264404
......@@ -49,7 +49,8 @@ static int wildcard_has_visited(struct query_data *qdata, const zone_node_t *nod
}
/*! \brief Mark given node as visited. */
static int wildcard_visit(struct query_data *qdata, const zone_node_t *node, const knot_dname_t *sname)
static int wildcard_visit(struct query_data *qdata, const zone_node_t *node,
const zone_node_t *prev, const knot_dname_t *sname)
{
assert(qdata);
assert(node);
......@@ -62,6 +63,7 @@ static int wildcard_visit(struct query_data *qdata, const zone_node_t *node, con
knot_mm_t *mm = qdata->mm;
struct wildcard_hit *item = mm_alloc(mm, sizeof(struct wildcard_hit));
item->node = node;
item->prev = prev;
item->sname = sname;
add_tail(&qdata->wildcards, (node_t *)item);
return KNOT_EOK;
......@@ -388,7 +390,7 @@ static int follow_cname(knot_pkt_t *pkt, uint16_t rrtype, struct query_data *qda
}
/* Put to wildcard node list. */
if (wildcard_visit(qdata, cname_node, qdata->name) != KNOT_EOK) {
if (wildcard_visit(qdata, cname_node, qdata->previous, qdata->name) != KNOT_EOK) {
return ERROR;
}
}
......@@ -448,14 +450,11 @@ static int name_not_found(knot_pkt_t *pkt, struct query_data *qdata)
qdata->node = wildcard_node;
assert(qdata->node != NULL);
/* keep encloser */
qdata->previous = NULL;
/* Follow expanded wildcard. */
int next_state = name_found(pkt, qdata);
/* Put to wildcard node list. */
if (wildcard_visit(qdata, wildcard_node, qdata->name) != KNOT_EOK) {
if (wildcard_visit(qdata, wildcard_node, qdata->previous, qdata->name) != KNOT_EOK) {
next_state = ERROR;
}
......
......@@ -85,6 +85,7 @@ struct query_data {
struct wildcard_hit {
node_t n;
const zone_node_t *node; /* Visited node. */
const zone_node_t *prev; /* Previous node from the SNAME. */
const knot_dname_t *sname; /* Name leading to this node. */
};
......
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