Commit ecbdad70 authored by Karel Slaný's avatar Karel Slaný Committed by Ondřej Surý
Browse files

Added missing test whether new query was created in cookie layer.

parent e6471bcd
......@@ -14,8 +14,6 @@
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
//#define PRINT_PACKETS 1 /* Comment out to disable packet printing. */
#include <assert.h>
#include <ccan/json/json.h>
#include <libknot/db/db_lmdb.h>
......@@ -32,15 +30,6 @@
#include "lib/module.h"
#include "lib/layer.h"
#define print_packet_dflt(pkt) do { } while(0)
#if defined(PRINT_PACKETS)
#include "print_pkt.h"
#undef print_packet_dflt
#define print_packet_dflt(pkt) print_packet((pkt), &DEFAULT_STYLE_DIG)
#endif /* PRINT_PACKETS */
#define DEBUG_MSG(qry, fmt...) QRDEBUG(qry, "cookies", fmt)
/**
......@@ -351,21 +340,28 @@ static int check_response(knot_layer_t *ctx, knot_pkt_t *pkt)
uint16_t rcode = knot_pkt_get_ext_rcode(pkt);
if (rcode == KNOT_RCODE_BADCOOKIE) {
if (qry->flags & QUERY_COOKIE_AGAIN) {
struct kr_query *next = NULL;
if (!(qry->flags & QUERY_BADCOOKIE_AGAIN)) {
/* Received first BADCOOKIE, regenerate query. */
next = kr_rplan_push(&req->rplan, qry->parent,
qry->sname, qry->sclass,
qry->stype);
}
if (next) {
DEBUG_MSG(NULL, "%s\n", "BADCOOKIE querying again");
qry->flags |= QUERY_BADCOOKIE_AGAIN;
} else {
/* Either the planning of second request failed or
* BADCOOKIE received for the second time.
* Fall back to TCP. */
DEBUG_MSG(NULL, "%s\n", "falling back to TCP");
qry->flags &= ~QUERY_COOKIE_AGAIN;
qry->flags &= ~QUERY_BADCOOKIE_AGAIN;
qry->flags |= QUERY_TCP;
return KNOT_STATE_CONSUME;
} else {
struct kr_query *next = kr_rplan_push(&req->rplan, qry->parent, qry->sname, qry->sclass, qry->stype);
next->flags = qry->flags;
DEBUG_MSG(NULL, "%s\n", "BADCOOKIE querying again");
qry->flags |= QUERY_COOKIE_AGAIN;
return KNOT_STATE_CONSUME;
}
}
print_packet_dflt(pkt);
return KNOT_STATE_CONSUME;
}
return ctx->state;
}
......
......@@ -576,7 +576,7 @@ static int resolve(knot_layer_t *ctx, knot_pkt_t *pkt)
assert(pkt && ctx);
struct kr_request *req = ctx->data;
struct kr_query *query = req->current_query;
if (!query || (query->flags & (QUERY_RESOLVED|QUERY_COOKIE_AGAIN))) {
if (!query || (query->flags & (QUERY_RESOLVED|QUERY_BADCOOKIE_AGAIN))) {
return ctx->state;
}
......
......@@ -750,7 +750,7 @@ ns_election:
if (qry->flags & (QUERY_AWAIT_IPV4|QUERY_AWAIT_IPV6)) {
kr_nsrep_elect_addr(qry, request->ctx);
} else if (!qry->ns.name || !(qry->flags & (QUERY_TCP|QUERY_STUB|QUERY_COOKIE_AGAIN))) { /* Keep NS when requerying/stub/badcookie. */
} else if (!qry->ns.name || !(qry->flags & (QUERY_TCP|QUERY_STUB|QUERY_BADCOOKIE_AGAIN))) { /* Keep NS when requerying/stub/badcookie. */
/* Root DNSKEY must be fetched from the hints to avoid chicken and egg problem. */
if (qry->sname[0] == '\0' && qry->stype == KNOT_RRTYPE_DNSKEY) {
kr_zonecut_set_sbelt(request->ctx, &qry->zone_cut);
......
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