Commit f71867c9 authored by Grigorii Demidov's avatar Grigorii Demidov Committed by Vladimír Čunát

lib: forwarding, cleanup & simplification; reuse existing code, delete unnecessary code blocks

parent bf594fdc
......@@ -639,7 +639,7 @@ static int process_answer(knot_pkt_t *pkt, struct kr_request *req)
VERBOSE_MSG("<= cname chain, following\n");
/* Check if the same query was already resolved */
for (int i = 0; i < req->rplan.resolved.len; ++i) {
struct kr_query * q = req->rplan.resolved.at[i];
struct kr_query *q = req->rplan.resolved.at[i];
if (q->parent == query->parent &&
q->sclass == query->sclass &&
q->stype == query->stype &&
......@@ -652,15 +652,15 @@ static int process_answer(knot_pkt_t *pkt, struct kr_request *req)
if (!next) {
return KR_STATE_FAIL;
}
next->flags |= QUERY_AWAIT_CUT;
if (query->flags & QUERY_FORWARD) {
next->flags |= (QUERY_FORWARD | QUERY_AWAIT_CUT);
next->forward_flags |= QUERY_CNAME;
state = kr_nsrep_copy_set(&next->ns, &query->ns);
if (state != kr_ok()) {
return KR_STATE_FAIL;
if (query->parent == NULL) {
state = kr_nsrep_copy_set(&next->ns, &query->ns);
if (state != kr_ok()) {
return KR_STATE_FAIL;
}
}
} else {
next->flags |= QUERY_AWAIT_CUT;
}
next->cname_parent = query;
/* Want DNSSEC if and only if it's posible to secure
......
......@@ -462,10 +462,6 @@ static int rrsig_not_found(kr_layer_t *ctx, const knot_rrset_t *rr)
next->flags |= QUERY_AWAIT_CUT;
}
if (qry->flags & QUERY_FORWARD) {
int state = kr_nsrep_copy_set(&next->ns, &qry->ns);
if (state != kr_ok()) {
return KR_STATE_FAIL;
}
next->flags &= ~QUERY_AWAIT_CUT;
}
next->flags |= QUERY_DNSSEC_WANT;
......@@ -600,8 +596,7 @@ static int unsigned_forward(kr_layer_t *ctx, knot_pkt_t *pkt)
if (!nods && qtype != KNOT_RRTYPE_DS) {
struct kr_rplan *rplan = &req->rplan;
struct kr_query *next = kr_rplan_push(rplan, qry, qry->sname, qry->sclass, KNOT_RRTYPE_DS);
int state = kr_nsrep_copy_set(&next->ns, &qry->ns);
if (state != kr_ok()) {
if (!next) {
return KR_STATE_FAIL;
}
kr_zonecut_set(&next->zone_cut, qry->zone_cut.name);
......@@ -660,9 +655,9 @@ static int check_signer(kr_layer_t *ctx, knot_pkt_t *pkt)
}
} else if (qry->stype != KNOT_RRTYPE_DS) {
struct kr_rplan *rplan = &req->rplan;
struct kr_query *next = kr_rplan_push(rplan, qry, qry->sname, qry->sclass, KNOT_RRTYPE_DS);
int state = kr_nsrep_copy_set(&next->ns, &qry->ns);
if (state != kr_ok()) {
struct kr_query *next = kr_rplan_push(rplan, qry, qry->sname,
qry->sclass, KNOT_RRTYPE_DS);
if (!next) {
return KR_STATE_FAIL;
}
kr_zonecut_set(&next->zone_cut, qry->zone_cut.name);
......
......@@ -976,10 +976,6 @@ static int forward_trust_chain_check(struct kr_request *request, struct kr_query
if (!next) {
return KR_STATE_FAIL;
}
int state = kr_nsrep_copy_set(&next->ns, &qry->ns);
if (state != kr_ok()) {
return KR_STATE_FAIL;
}
return KR_STATE_DONE;
}
......@@ -1021,18 +1017,11 @@ static int forward_trust_chain_check(struct kr_request *request, struct kr_query
}
if (ds_req && !ns_req && (minimized || resume)) {
struct kr_query *next = kr_rplan_push(rplan, qry, wanted_name,
qry->sclass, KNOT_RRTYPE_NS);
struct kr_query *next = zone_cut_subreq(rplan, qry, wanted_name,
KNOT_RRTYPE_NS);
if (!next) {
return KR_STATE_FAIL;
}
int state = kr_nsrep_copy_set(&next->ns, &qry->ns);
if (state != kr_ok()) {
return KR_STATE_FAIL;
}
kr_zonecut_set(&next->zone_cut, qry->zone_cut.name);
kr_zonecut_copy_trust(&next->zone_cut, &qry->zone_cut);
next->flags |= QUERY_DNSSEC_WANT;
return KR_STATE_DONE;
}
......@@ -1085,17 +1074,11 @@ static int forward_trust_chain_check(struct kr_request *request, struct kr_query
ta_name = (has_ta ? qry->zone_cut.trust_anchor->owner : NULL);
refetch_ta = (!has_ta || !knot_dname_is_equal(wanted_name, ta_name));
if (!nods && want_secured && refetch_ta) {
struct kr_query *next = kr_rplan_push(rplan, qry, wanted_name, qry->sclass, KNOT_RRTYPE_DS);
struct kr_query *next = zone_cut_subreq(rplan, qry, wanted_name,
KNOT_RRTYPE_DS);
if (!next) {
return KR_STATE_FAIL;
}
int state = kr_nsrep_copy_set(&next->ns, &qry->ns);
if (state != kr_ok()) {
return KR_STATE_FAIL;
}
kr_zonecut_set(&next->zone_cut, qry->zone_cut.name);
kr_zonecut_copy_trust(&next->zone_cut, &qry->zone_cut);
next->flags |= QUERY_DNSSEC_WANT;
return KR_STATE_DONE;
}
......@@ -1108,10 +1091,6 @@ static int forward_trust_chain_check(struct kr_request *request, struct kr_query
if (!next) {
return KR_STATE_FAIL;
}
int state = kr_nsrep_copy_set(&next->ns, &qry->ns);
if (state != kr_ok()) {
return KR_STATE_FAIL;
}
return KR_STATE_DONE;
}
......@@ -1170,15 +1149,7 @@ static int trust_chain_check(struct kr_request *request, struct kr_query *qry)
if (!next) {
return KR_STATE_FAIL;
}
if (qry->flags & QUERY_FORWARD) {
int state = kr_nsrep_copy_set(&next->ns, &qry->ns);
if (state != kr_ok()) {
return KR_STATE_FAIL;
}
} else {
next->flags |= QUERY_AWAIT_CUT;
}
next->flags |= QUERY_DNSSEC_WANT;
next->flags |= (QUERY_AWAIT_CUT | QUERY_DNSSEC_WANT);
return KR_STATE_DONE;
}
/* Try to fetch missing DNSKEY (either missing or above current cut).
......
......@@ -138,6 +138,15 @@ static struct kr_query *kr_rplan_push_query(struct kr_rplan *rplan,
qry->reorder = qry->flags & QUERY_REORDER_RR
? knot_wire_get_id(rplan->request->answer->wire)
: 0;
/* When forwarding, keep the nameserver addresses. */
if (parent && (parent->flags & qry->flags & QUERY_FORWARD)) {
ret = kr_nsrep_copy_set(&qry->ns, &parent->ns);
if (ret) {
return NULL;
}
}
array_push(rplan->pending, qry);
return qry;
......
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