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)
/**
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;
}
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);