diff --git a/src/utils/kdig/kdig_exec.c b/src/utils/kdig/kdig_exec.c index 077abf5ed..2cd14640a 100644 --- a/src/utils/kdig/kdig_exec.c +++ b/src/utils/kdig/kdig_exec.c @@ -741,7 +741,7 @@ static int process_query_packet(const knot_pkt_t *query, } // Check for BADCOOKIE RCODE and repeat query with the new cookie if required. - if (knot_pkt_ext_rcode(reply) == KNOT_RCODE_BADCOOKIE && query_ctx->badcookie) { + if (knot_pkt_ext_rcode(reply) == KNOT_RCODE_BADCOOKIE && query_ctx->badcookie > 0) { printf("\n"); WARN("bad cookie from %s, retrying with the received one\n", net->remote_str); @@ -770,6 +770,8 @@ static int process_query_packet(const knot_pkt_t *query, // Restore the original client cookie. new_ctx.cc = query_ctx->cc; + new_ctx.badcookie--; + knot_pkt_t *new_query = create_query_packet(&new_ctx); ret = process_query_packet(new_query, net, &new_ctx, ignore_tc, sign_ctx, style); diff --git a/src/utils/kdig/kdig_params.c b/src/utils/kdig/kdig_params.c index 236d2ded3..337504e5d 100644 --- a/src/utils/kdig/kdig_params.c +++ b/src/utils/kdig/kdig_params.c @@ -43,6 +43,8 @@ #define DEFAULT_ALIGNMENT_SIZE 128 #define DEFAULT_TLS_OCSP_STAPLING (7 * 24 * 3600) +#define BADCOOKIE_RETRY_MAX 10 + static const flags_t DEFAULT_FLAGS_DIG = { .aa_flag = false, .tc_flag = false, @@ -1005,14 +1007,14 @@ static int opt_nocookie(const char *arg, void *query) static int opt_badcookie(const char *arg, void *query) { query_t *q = query; - q->badcookie = true; + q->badcookie = BADCOOKIE_RETRY_MAX; return KNOT_EOK; } static int opt_nobadcookie(const char *arg, void *query) { query_t *q = query; - q->badcookie = false; + q->badcookie = 0; return KNOT_EOK; } @@ -1480,7 +1482,7 @@ query_t *query_create(const char *owner, const query_t *conf) query->edns = -1; query->cc.len = 0; query->sc.len = 0; - query->badcookie = true; + query->badcookie = BADCOOKIE_RETRY_MAX; query->padding = -1; query->alignment = 0; tls_params_init(&query->tls); diff --git a/src/utils/kdig/kdig_params.h b/src/utils/kdig/kdig_params.h index 974b73745..9a35986bb 100644 --- a/src/utils/kdig/kdig_params.h +++ b/src/utils/kdig/kdig_params.h @@ -114,7 +114,7 @@ struct query { /*!< EDNS server cookie. */ knot_edns_cookie_t sc; /*!< Repeat query after BADCOOKIE. */ - bool badcookie; + int badcookie; /*!< EDNS0 padding (16unsigned + -1 ~ uninitialized, -2 ~ default, -3 ~ none). */ int32_t padding; /*!< Query alignment with EDNS0 padding (0 ~ uninitialized). */