Commit 12552eb3 authored by Marek Vavruša's avatar Marek Vavruša

layer/iterate: glue may be in ANSWER, cleanup

parent b2127d21
......@@ -159,11 +159,13 @@ static int update_answer(const knot_rrset_t *rr, unsigned hint, struct kr_reques
static void fetch_glue(knot_pkt_t *pkt, const knot_dname_t *ns, struct kr_query *qry)
{
const knot_pktsection_t *ar = knot_pkt_section(pkt, KNOT_ADDITIONAL);
for (unsigned i = 0; i < ar->count; ++i) {
const knot_rrset_t *rr = knot_pkt_rr(ar, i);
if (knot_dname_is_equal(ns, rr->owner)) {
(void) update_nsaddr(rr, qry);
for (knot_section_t i = KNOT_ANSWER; i <= KNOT_ADDITIONAL; ++i) {
const knot_pktsection_t *sec = knot_pkt_section(pkt, i);
for (unsigned k = 0; k < sec->count; ++k) {
const knot_rrset_t *rr = knot_pkt_rr(sec, k);
if (knot_dname_is_equal(ns, rr->owner)) {
(void) update_nsaddr(rr, qry);
}
}
}
}
......@@ -171,12 +173,14 @@ static void fetch_glue(knot_pkt_t *pkt, const knot_dname_t *ns, struct kr_query
/** Attempt to find glue for given nameserver name (best effort). */
static int has_glue(knot_pkt_t *pkt, const knot_dname_t *ns, struct kr_request *req)
{
const knot_pktsection_t *ar = knot_pkt_section(pkt, KNOT_ADDITIONAL);
for (unsigned i = 0; i < ar->count; ++i) {
const knot_rrset_t *rr = knot_pkt_rr(ar, i);
if (knot_dname_is_equal(ns, rr->owner) &&
(rr->type == KNOT_RRTYPE_A || rr->type == KNOT_RRTYPE_AAAA)) {
return 1;
for (knot_section_t i = KNOT_ANSWER; i <= KNOT_ADDITIONAL; ++i) {
const knot_pktsection_t *sec = knot_pkt_section(pkt, i);
for (unsigned k = 0; k < sec->count; ++k) {
const knot_rrset_t *rr = knot_pkt_rr(sec, k);
if (knot_dname_is_equal(ns, rr->owner) &&
(rr->type == KNOT_RRTYPE_A || rr->type == KNOT_RRTYPE_AAAA)) {
return 1;
}
}
}
return 0;
......
......@@ -51,11 +51,12 @@ static int invalidate_ns(struct kr_rplan *rplan, struct kr_query *qry)
}
}
static void ns_fetch_cut(struct kr_query *qry, struct kr_request *req)
static int ns_fetch_cut(struct kr_query *qry, struct kr_request *req)
{
struct kr_cache_txn txn;
int ret = 0;
if (kr_cache_txn_begin(&req->ctx->cache, &txn, NAMEDB_RDONLY) != 0) {
kr_zonecut_set_sbelt(&qry->zone_cut);
ret = kr_zonecut_set_sbelt(&qry->zone_cut);
} else {
/* If at/subdomain of parent zone cut, start from 'one up' to avoid loops */
struct kr_query *parent = qry->parent;
......@@ -64,9 +65,10 @@ static void ns_fetch_cut(struct kr_query *qry, struct kr_request *req)
start_from = parent->zone_cut.name;
}
/* Find closest zone cut from cache */
kr_zonecut_find_cached(req->ctx, &qry->zone_cut, start_from, &txn, qry->timestamp.tv_sec);
ret = kr_zonecut_find_cached(req->ctx, &qry->zone_cut, start_from, &txn, qry->timestamp.tv_sec);
kr_cache_txn_abort(&txn);
}
return ret;
}
static int ns_resolve_addr(struct kr_query *qry, struct kr_request *param)
......@@ -444,7 +446,10 @@ int kr_resolve_produce(struct kr_request *request, struct sockaddr **dst, int *t
* now it's the time to look up closest zone cut from cache.
*/
if (qry->flags & QUERY_AWAIT_CUT) {
ns_fetch_cut(qry, request);
int ret = ns_fetch_cut(qry, request);
if (ret != 0) {
return KNOT_STATE_FAIL;
}
qry->flags &= ~QUERY_AWAIT_CUT;
/* Update minimized QNAME if zone cut changed */
if (qry->zone_cut.name[0] != '\0' && !(qry->flags & QUERY_NO_MINIMIZE)) {
......
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