]> git.ipfire.org Git - thirdparty/knot-resolver.git/commitdiff
cache: tidy code
authorVladimír Čunát <vladimir.cunat@nic.cz>
Fri, 9 Feb 2018 09:03:07 +0000 (10:03 +0100)
committerVladimír Čunát <vladimir.cunat@nic.cz>
Fri, 9 Feb 2018 09:03:07 +0000 (10:03 +0100)
lib/cache/api.c

index 2dc43ba14f8adfc1960d984e434a87a553181e0e..7b63d5912d68d5227813b434608ea7def00240b9 100644 (file)
@@ -312,6 +312,7 @@ int cache_peek(kr_layer_t *ctx, knot_pkt_t *pkt)
 {
        struct kr_request *req = ctx->req;
        struct kr_query *qry = req->current_query;
+       /* We first check various exit-conditions and then call the _real function. */
 
        if (ctx->state & (KR_STATE_FAIL|KR_STATE_DONE) || qry->flags.NO_CACHE
            || (qry->flags.CACHE_TRIED && !qry->stale_cb)
@@ -319,27 +320,11 @@ int cache_peek(kr_layer_t *ctx, knot_pkt_t *pkt)
            || qry->sclass != KNOT_CLASS_IN) {
                return ctx->state; /* Already resolved/failed or already tried, etc. */
        }
-       int ret = cache_peek_real(ctx, pkt);
-       kr_cache_sync(&req->ctx->cache);
-       return ret;
-}
-
-
-/**
- * \note we don't transition to KR_STATE_FAIL even in case of "unexpected errors".
- */
-static int cache_peek_real(kr_layer_t *ctx, knot_pkt_t *pkt)
-{
-       struct kr_request *req = ctx->req;
-       struct kr_query *qry = req->current_query;
-       struct kr_cache *cache = &req->ctx->cache;
-
        /* ATM cache only peeks for qry->sname and that would be useless
         * to repeat on every iteration, so disable it from now on.
         * LATER(optim.): assist with more precise QNAME minimization. */
        qry->flags.CACHE_TRIED = true;
 
-       struct key k_storage, *k = &k_storage;
        if (qry->stype == KNOT_RRTYPE_NSEC) {
                VERBOSE_MSG(qry, "=> skipping stype NSEC\n");
                return ctx->state;
@@ -351,6 +336,23 @@ static int cache_peek_real(kr_layer_t *ctx, knot_pkt_t *pkt)
                }
                return ctx->state;
        }
+
+       int ret = cache_peek_real(ctx, pkt);
+       kr_cache_sync(&req->ctx->cache);
+       return ret;
+}
+
+
+/**
+ * \note we don't transition to KR_STATE_FAIL even in case of "unexpected errors".
+ */
+static int cache_peek_real(kr_layer_t *ctx, knot_pkt_t *pkt)
+{
+       struct kr_request *req = ctx->req;
+       struct kr_query *qry = req->current_query;
+       struct kr_cache *cache = &req->ctx->cache;
+
+       struct key k_storage, *k = &k_storage;
        int ret = kr_dname_lf(k->buf, qry->sname, false);
        if (ret) {
                return ctx->state;