From: Vladimír Čunát Date: Mon, 10 Sep 2018 13:19:43 +0000 (+0200) Subject: treewide nitpick: more sensitive detection of KR_STATE_FAIL X-Git-Tag: v4.1.0~14^2~4 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=ee7eadee2e055d6a8fa40f575dade84b75d2ba01;p=thirdparty%2Fknot-resolver.git treewide nitpick: more sensitive detection of KR_STATE_FAIL I don't know any particular case where the bit-test would succeed and equality wouldn't, but it seems better to take no chances. --- diff --git a/lib/layer/iterate.c b/lib/layer/iterate.c index be0fb1844..bedc54c7b 100644 --- a/lib/layer/iterate.c +++ b/lib/layer/iterate.c @@ -543,7 +543,7 @@ static int unroll_cname(knot_pkt_t *pkt, struct kr_request *req, bool referral, } else { int cnt_ = 0; state = update_nsaddr(rr, query->parent, &cnt_); - if (state == KR_STATE_FAIL) { + if (state & KR_STATE_FAIL) { return state; } } diff --git a/lib/resolve.c b/lib/resolve.c index 2d97e900e..594202385 100644 --- a/lib/resolve.c +++ b/lib/resolve.c @@ -575,7 +575,7 @@ static int answer_finalize(struct kr_request *request, int state) knot_pkt_t *answer = request->answer; /* Always set SERVFAIL for bogus answers. */ - if (state == KR_STATE_FAIL && rplan->pending.len > 0) { + if ((state & KR_STATE_FAIL) && rplan->pending.len > 0) { struct kr_query *last = array_tail(rplan->pending); if ((last->flags.DNSSEC_WANT) && (last->flags.DNSSEC_BOGUS)) { return answer_fail(request); @@ -853,7 +853,7 @@ static void update_nslist_score(struct kr_request *request, struct kr_query *qry { struct kr_context *ctx = request->ctx; /* On successful answer, update preference list RTT and penalise timer */ - if (request->state != KR_STATE_FAIL) { + if (!(request->state & KR_STATE_FAIL)) { /* Update RTT information for preference list */ update_nslist_rtt(ctx, qry, src); /* Do not complete NS address resolution on soft-fail. */ @@ -929,7 +929,7 @@ int kr_resolve_consume(struct kr_request *request, const struct sockaddr *src, k update_nslist_score(request, qry, src, packet); } /* Resolution failed, invalidate current NS. */ - if (request->state == KR_STATE_FAIL) { + if (request->state & KR_STATE_FAIL) { invalidate_ns(rplan, qry); qry->flags.RESOLVED = false; } @@ -1284,7 +1284,7 @@ static int zone_cut_check(struct kr_request *request, struct kr_query *qry, knot int state = KR_STATE_FAIL; do { state = ns_fetch_cut(qry, requested_name, request, packet); - if (state == KR_STATE_DONE || state == KR_STATE_FAIL) { + if (state == KR_STATE_DONE || (state & KR_STATE_FAIL)) { return state; } else if (state == KR_STATE_CONSUME) { requested_name = knot_wire_next_label(requested_name, NULL); @@ -1354,7 +1354,7 @@ int kr_resolve_produce(struct kr_request *request, struct sockaddr **dst, int *t /* Resolve current query and produce dependent or finish */ request->state = KR_STATE_PRODUCE; ITERATE_LAYERS(request, qry, produce, packet); - if (request->state != KR_STATE_FAIL && knot_wire_get_qr(packet->wire)) { + if (!(request->state & KR_STATE_FAIL) && knot_wire_get_qr(packet->wire)) { /* Produced an answer from cache, consume it. */ qry->secret = 0; request->state = KR_STATE_CONSUME; @@ -1542,7 +1542,7 @@ int kr_resolve_checkout(struct kr_request *request, const struct sockaddr *src, * don't affect the resolution or rest of the processing. */ int state = request->state; ITERATE_LAYERS(request, qry, checkout, packet, dst, type); - if (request->state == KR_STATE_FAIL) { + if (request->state & KR_STATE_FAIL) { request->state = state; /* Restore */ return kr_error(ECANCELED); } @@ -1592,7 +1592,7 @@ int kr_resolve_finish(struct kr_request *request, int state) { /* Finalize answer and construct wire-buffer. */ ITERATE_LAYERS(request, NULL, answer_finalize); - if (request->state == KR_STATE_FAIL) { + if (request->state & KR_STATE_FAIL) { state = KR_STATE_FAIL; } else if (answer_finalize(request, state) != 0) { state = KR_STATE_FAIL; diff --git a/modules/cookies/cookiemonster.c b/modules/cookies/cookiemonster.c index 7af7afa3f..6f0019245 100644 --- a/modules/cookies/cookiemonster.c +++ b/modules/cookies/cookiemonster.c @@ -423,7 +423,7 @@ int check_request(kr_layer_t *ctx) /* Request has no server cookie. */ return_state = invalid_sc_status(return_state, false, ignore_badcookie, req, answer); - if (return_state == KR_STATE_FAIL) { + if (return_state & KR_STATE_FAIL) { return return_state; } goto answer_add_cookies; @@ -449,7 +449,7 @@ int check_request(kr_layer_t *ctx) /* Invalid server cookie. */ return_state = invalid_sc_status(return_state, true, ignore_badcookie, req, answer); - if (return_state == KR_STATE_FAIL) { + if (return_state & KR_STATE_FAIL) { return return_state; } goto answer_add_cookies; diff --git a/modules/hints/hints.c b/modules/hints/hints.c index 613dcc651..72423d819 100644 --- a/modules/hints/hints.c +++ b/modules/hints/hints.c @@ -140,7 +140,7 @@ static int satisfy_forward(/*const*/ struct hints_data *data, static int query(kr_layer_t *ctx, knot_pkt_t *pkt) { struct kr_query *qry = ctx->req->current_query; - if (!qry || ctx->state & (KR_STATE_FAIL)) { + if (!qry || (ctx->state & KR_STATE_FAIL)) { return ctx->state; }