]> git.ipfire.org Git - thirdparty/knot-resolver.git/commitdiff
lib/cache: simplify passing qry/req parameters
authorVladimír Čunát <vladimir.cunat@nic.cz>
Wed, 22 Jul 2020 08:29:16 +0000 (10:29 +0200)
committerVladimír Čunát <vladimir.cunat@nic.cz>
Mon, 12 Jun 2023 08:22:42 +0000 (10:22 +0200)
- kr_layer_t isn't really useful in the inner functions
  (it's mainly useful through ->state when returning from layer)
- kr_query seems a little more suitable to pass than kr_request

lib/cache/entry_pkt.c
lib/cache/impl.h
lib/cache/peek.c

index 884bfaa8c095782c6a3a133ee9ae43f826ea5b71..9499b69ab9045759128e132927f7eed33cbd1e84 100644 (file)
@@ -125,12 +125,9 @@ void stash_pkt(const knot_pkt_t *pkt, const struct kr_query *qry,
 }
 
 
-int answer_from_pkt(kr_layer_t *ctx, knot_pkt_t *pkt, uint16_t type,
+int answer_from_pkt(struct kr_query *qry, knot_pkt_t *pkt, uint16_t type,
                const struct entry_h *eh, const void *eh_bound, uint32_t new_ttl)
 {
-       struct kr_request *req = ctx->req;
-       struct kr_query *qry = req->current_query;
-
        const uint16_t msgid = knot_wire_get_id(pkt->wire);
 
        /* Ensure the wire buffer is large enough.  Strategy: fit and at least double. */
@@ -139,8 +136,8 @@ int answer_from_pkt(kr_layer_t *ctx, knot_pkt_t *pkt, uint16_t type,
        if (pkt_len > pkt->max_size) {
                pkt->max_size = MIN(KNOT_WIRE_MAX_PKTSIZE,
                                    MAX(pkt->max_size * 2, pkt_len));
-               mm_free(&ctx->req->pool, pkt->wire); /* no-op, but... */
-               pkt->wire = mm_alloc(&ctx->req->pool, pkt->max_size);
+               mm_free(&qry->request->pool, pkt->wire); /* no-op, but... */
+               pkt->wire = mm_alloc(&qry->request->pool, pkt->max_size);
                pkt->compr.wire = pkt->wire;
                /* TODO: ^^ nicer way how to replace knot_pkt_t::wire ? */
        }
index 305f36eb9ed5028f453bb0fa51b463a2ae90faef..e25d13fe6de33d339c6588db0f981f164f976120 100644 (file)
@@ -274,7 +274,7 @@ void stash_pkt(const knot_pkt_t *pkt, const struct kr_query *qry,
  * This assumes the TTL is OK and entry_h_consistent, but it may still return error.
  * On success it handles all the rest, incl. qry->flags.
  */
-int answer_from_pkt(kr_layer_t *ctx, knot_pkt_t *pkt, uint16_t type,
+int answer_from_pkt(struct kr_query *qry, knot_pkt_t *pkt, uint16_t type,
                const struct entry_h *eh, const void *eh_bound, uint32_t new_ttl);
 
 
index e1901ac3b7b28ecf306a81dc499e1943099829b5..5db1fbc822f15ae994b25d596a52ed6235516131 100644 (file)
 /* The whole file only exports peek_nosync().
  * Forwards for larger chunks of code: */
 
-static int found_exact_hit(kr_layer_t *ctx, knot_pkt_t *pkt, knot_db_val_t val,
+static int found_exact_hit(struct kr_query *qry, knot_pkt_t *pkt, knot_db_val_t val,
                           uint8_t lowest_rank);
 static int closest_NS(struct kr_cache *cache, struct key *k, entry_list_t el,
                        struct kr_query *qry, bool only_NS, bool is_DS);
-static int answer_simple_hit(kr_layer_t *ctx, knot_pkt_t *pkt, uint16_t type,
+static int answer_simple_hit(struct kr_query *qry, knot_pkt_t *pkt, uint16_t type,
                const struct entry_h *eh, const void *eh_bound, uint32_t new_ttl);
-static int answer_dname_hit(kr_layer_t *ctx, knot_pkt_t *pkt, const knot_dname_t *dname_owner,
+static int answer_dname_hit(struct kr_query *qry, knot_pkt_t *pkt, const knot_dname_t *dname_owner,
                const struct entry_h *eh, const void *eh_bound, uint32_t new_ttl);
 static int try_wild(struct key *k, struct answer *ans, const knot_dname_t *clencl_name,
                    uint16_t type, uint8_t lowest_rank,
@@ -124,7 +124,7 @@ int peek_nosync(kr_layer_t *ctx, knot_pkt_t *pkt)
                ret = cache_op(cache, read, &key, &val, 1);
                if (!ret) {
                        /* found an entry: test conditions, materialize into pkt, etc. */
-                       ret = found_exact_hit(ctx, pkt, val, lowest_rank);
+                       ret = found_exact_hit(qry, pkt, val, lowest_rank);
                }
        }
        if (!ret) {
@@ -159,7 +159,7 @@ int peek_nosync(kr_layer_t *ctx, knot_pkt_t *pkt)
                        return ctx->state;
                const int32_t new_ttl = get_new_ttl(v.data, qry, qry->sname,
                                                KNOT_RRTYPE_CNAME, qry->timestamp.tv_sec);
-               ret = answer_simple_hit(ctx, pkt, KNOT_RRTYPE_CNAME, v.data,
+               ret = answer_simple_hit(qry, pkt, KNOT_RRTYPE_CNAME, v.data,
                                        knot_db_val_bound(v), new_ttl);
                return ret == kr_ok() ? KR_STATE_DONE : ctx->state;
                }
@@ -170,7 +170,7 @@ int peek_nosync(kr_layer_t *ctx, knot_pkt_t *pkt)
                /* TTL: for simplicity, we just ask for TTL of the generated CNAME. */
                const int32_t new_ttl = get_new_ttl(v.data, qry, qry->sname,
                                                KNOT_RRTYPE_CNAME, qry->timestamp.tv_sec);
-               ret = answer_dname_hit(ctx, pkt, k->zname, v.data,
+               ret = answer_dname_hit(qry, pkt, k->zname, v.data,
                                        knot_db_val_bound(v), new_ttl);
                return ret == kr_ok() ? KR_STATE_DONE : ctx->state;
                }
@@ -422,12 +422,9 @@ static void answer_simple_qflags(struct kr_qflags *qf, const struct entry_h *eh,
        if (kr_fails_assert((ret) >= 0)) return kr_error((ret)); \
 } while (false)
 
-static int answer_simple_hit(kr_layer_t *ctx, knot_pkt_t *pkt, uint16_t type,
+static int answer_simple_hit(struct kr_query *qry, knot_pkt_t *pkt, uint16_t type,
                const struct entry_h *eh, const void *eh_bound, uint32_t new_ttl)
 {
-       struct kr_request *req = ctx->req;
-       struct kr_query *qry = req->current_query;
-
        /* All OK, so start constructing the (pseudo-)packet. */
        int ret = pkt_renew(pkt, qry->sname, qry->stype);
        CHECK_RET(ret);
@@ -451,12 +448,9 @@ static int answer_simple_hit(kr_layer_t *ctx, knot_pkt_t *pkt, uint16_t type,
        return kr_ok();
 }
 
-static int answer_dname_hit(kr_layer_t *ctx, knot_pkt_t *pkt, const knot_dname_t *dname_owner,
+static int answer_dname_hit(struct kr_query *qry, knot_pkt_t *pkt, const knot_dname_t *dname_owner,
                const struct entry_h *eh, const void *eh_bound, uint32_t new_ttl)
 {
-       struct kr_request *req = ctx->req;
-       struct kr_query *qry = req->current_query;
-
        /* All OK, so start constructing the (pseudo-)packet. */
        int ret = pkt_renew(pkt, qry->sname, qry->stype);
        CHECK_RET(ret);
@@ -510,12 +504,9 @@ static int answer_dname_hit(kr_layer_t *ctx, knot_pkt_t *pkt, const knot_dname_t
 #undef CHECK_RET
 
 /** TODO: description; see the single call site for now. */
-static int found_exact_hit(kr_layer_t *ctx, knot_pkt_t *pkt, knot_db_val_t val,
+static int found_exact_hit(struct kr_query *qry, knot_pkt_t *pkt, knot_db_val_t val,
                           uint8_t lowest_rank)
 {
-       struct kr_request *req = ctx->req;
-       struct kr_query *qry = req->current_query;
-
        int ret = entry_h_seek(&val, qry->stype);
        if (ret) return ret;
        const struct entry_h *eh = entry_h_consistent_E(val, qry->stype);
@@ -542,9 +533,9 @@ static int found_exact_hit(kr_layer_t *ctx, knot_pkt_t *pkt, knot_db_val_t val,
                 * possible that we could generate a higher-security negative proof.
                 * Rank is high-enough so we take it to save time searching;
                 * in practice this also helps in some incorrect zones (live-signed). */
-               return answer_from_pkt  (ctx, pkt, qry->stype, eh, eh_bound, new_ttl);
+               return answer_from_pkt  (qry, pkt, qry->stype, eh, eh_bound, new_ttl);
        } else {
-               return answer_simple_hit(ctx, pkt, qry->stype, eh, eh_bound, new_ttl);
+               return answer_simple_hit(qry, pkt, qry->stype, eh, eh_bound, new_ttl);
        }
 }