]> git.ipfire.org Git - thirdparty/knot-resolver.git/commitdiff
Added missing test whether new query was created in cookie layer.
authorKarel Slany <karel.slany@nic.cz>
Tue, 31 May 2016 14:25:16 +0000 (16:25 +0200)
committerOndřej Surý <ondrej@sury.org>
Thu, 11 Aug 2016 12:06:45 +0000 (14:06 +0200)
lib/layer/cookies.c
lib/layer/iterate.c
lib/resolve.c

index f5088894f0d63d6c541197e137f630368e06977d..3f777935672be2a64661ad1019d4495a50e860bd 100644 (file)
@@ -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>
 #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;
 }
index e77a319c269b8eb38c786fc5be1cfd6c831b0394..f963596d07520de29201557562f6a6311fcc6c6b 100644 (file)
@@ -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;
        }
 
index 9100705c75649ebd77688859b56e6c837a4cb34f..1cc5f4a573c660beb7a9e5670d799ad0ef669983 100644 (file)
@@ -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);