From: Grigorii Demidov Date: Mon, 5 Dec 2016 08:30:49 +0000 (+0100) Subject: layer/pktcache: additional checking for cache entry rank was added X-Git-Tag: v1.2.0-rc1~68^2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=9034bd9c816d213e1e8aa39ee71723e5cf6c0545;p=thirdparty%2Fknot-resolver.git layer/pktcache: additional checking for cache entry rank was added --- diff --git a/lib/layer/pktcache.c b/lib/layer/pktcache.c index 747d2e4d5..fc8999f3e 100644 --- a/lib/layer/pktcache.c +++ b/lib/layer/pktcache.c @@ -46,11 +46,18 @@ static void adjust_ttl(knot_rrset_t *rr, uint32_t drift) } } -static int loot_cache_pkt(struct kr_cache *cache, knot_pkt_t *pkt, const knot_dname_t *qname, - uint16_t rrtype, bool want_secure, uint32_t timestamp, uint8_t *flags) +/** @internal Try to find a shortcut directly to searched packet. */ +static int loot_pktcache(struct kr_cache *cache, knot_pkt_t *pkt, + struct kr_query *qry, uint8_t *flags) { + uint32_t timestamp = qry->timestamp.tv_sec; + const knot_dname_t *qname = qry->sname; + uint16_t rrtype = qry->stype; + const bool want_secure = (qry->flags & QUERY_DNSSEC_WANT); + struct kr_cache_entry *entry = NULL; - int ret = kr_cache_peek(cache, KR_CACHE_PKT, qname, rrtype, &entry, ×tamp); + int ret = kr_cache_peek(cache, KR_CACHE_PKT, qname, + rrtype, &entry, ×tamp); if (ret != 0) { /* Not in the cache */ return ret; } @@ -60,6 +67,12 @@ static int loot_cache_pkt(struct kr_cache *cache, knot_pkt_t *pkt, const knot_dn return kr_error(ENOENT); } + /* Check if entry is insecure and setup query flags if needed. */ + if (want_secure && entry->rank == KR_RANK_INSECURE) { + qry->flags |= QUERY_DNSSEC_INSECURE; + qry->flags &= ~QUERY_DNSSEC_WANT; + } + /* Copy answer, keep the original message id */ if (entry->count <= pkt->max_size) { /* Keep original header and copy cached */ @@ -90,16 +103,6 @@ static int loot_cache_pkt(struct kr_cache *cache, knot_pkt_t *pkt, const knot_dn return ret; } -/** @internal Try to find a shortcut directly to searched packet. */ -static int loot_pktcache(struct kr_cache *cache, knot_pkt_t *pkt, struct kr_query *qry, uint8_t *flags) -{ - uint32_t timestamp = qry->timestamp.tv_sec; - const knot_dname_t *qname = qry->sname; - uint16_t rrtype = qry->stype; - const bool want_secure = (qry->flags & QUERY_DNSSEC_WANT); - return loot_cache_pkt(cache, pkt, qname, rrtype, want_secure, timestamp, flags); -} - static int pktcache_peek(kr_layer_t *ctx, knot_pkt_t *pkt) { struct kr_query *qry = ctx->req->current_query;