From: Vladimír Čunát Date: Wed, 22 Jul 2020 08:29:16 +0000 (+0200) Subject: lib/cache: simplify passing qry/req parameters X-Git-Tag: v6.0.1~9^2~32 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=7ebe70eff3dd6a2eacd7290c56d1e8ddc19babfc;p=thirdparty%2Fknot-resolver.git lib/cache: simplify passing qry/req parameters - 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 --- diff --git a/lib/cache/entry_pkt.c b/lib/cache/entry_pkt.c index 884bfaa8c..9499b69ab 100644 --- a/lib/cache/entry_pkt.c +++ b/lib/cache/entry_pkt.c @@ -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 ? */ } diff --git a/lib/cache/impl.h b/lib/cache/impl.h index 305f36eb9..e25d13fe6 100644 --- a/lib/cache/impl.h +++ b/lib/cache/impl.h @@ -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); diff --git a/lib/cache/peek.c b/lib/cache/peek.c index e1901ac3b..5db1fbc82 100644 --- a/lib/cache/peek.c +++ b/lib/cache/peek.c @@ -10,13 +10,13 @@ /* 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); } }