From ecbdad7035211cc467bd7d9e7f6a85e9682ff13c Mon Sep 17 00:00:00 2001 From: Karel Slany Date: Tue, 31 May 2016 16:25:16 +0200 Subject: [PATCH] Added missing test whether new query was created in cookie layer. --- lib/layer/cookies.c | 40 ++++++++++++++++++---------------------- lib/layer/iterate.c | 2 +- lib/resolve.c | 2 +- 3 files changed, 20 insertions(+), 24 deletions(-) diff --git a/lib/layer/cookies.c b/lib/layer/cookies.c index f5088894f..3f7779356 100644 --- a/lib/layer/cookies.c +++ b/lib/layer/cookies.c @@ -14,8 +14,6 @@ along with this program. If not, see . */ -//#define PRINT_PACKETS 1 /* Comment out to disable packet printing. */ - #include #include #include @@ -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; } diff --git a/lib/layer/iterate.c b/lib/layer/iterate.c index e77a319c2..f963596d0 100644 --- a/lib/layer/iterate.c +++ b/lib/layer/iterate.c @@ -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; } diff --git a/lib/resolve.c b/lib/resolve.c index 9100705c7..1cc5f4a57 100644 --- a/lib/resolve.c +++ b/lib/resolve.c @@ -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); -- 2.47.3