From: Karel Slany Date: Fri, 22 May 2015 10:46:22 +0000 (+0200) Subject: lib/cache: RRSIG RRsets have a separate cache storing mechanism X-Git-Tag: v1.0.0-beta1~53^2~182 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=557d4cf2a2bb5b29c9e5d41774cd48918079becb;p=thirdparty%2Fknot-resolver.git lib/cache: RRSIG RRsets have a separate cache storing mechanism --- diff --git a/lib/cache.c b/lib/cache.c index afc3eba67..9c1102f75 100644 --- a/lib/cache.c +++ b/lib/cache.c @@ -320,3 +320,50 @@ int kr_cache_insert_rr(struct kr_cache_txn *txn, const knot_rrset_t *rr, uint32_ namedb_val_t data = { rr->rrs.data, knot_rdataset_size(&rr->rrs) }; return kr_cache_insert(txn, KR_CACHE_RR, rr->owner, rr->type, &header, data); } + +int kr_cache_peek_rrsig(struct kr_cache_txn *txn, knot_rrset_t *rr, uint32_t *timestamp) +{ + if (!txn || !rr || !timestamp) { + return kr_error(EINVAL); + } + + /* Check if the RRSet is in the cache. */ + struct kr_cache_entry *entry = kr_cache_peek(txn, KR_CACHE_RRSIG, rr->owner, rr->type, timestamp); + if (entry) { + rr->type = KNOT_RRTYPE_RRSIG; + rr->rrs.rr_count = entry->count; + rr->rrs.data = entry->data; + return kr_ok(); + } + + /* Not found. */ + return kr_error(ENOENT); +} + +int kr_cache_insert_rrsig(struct kr_cache_txn *txn, const knot_rrset_t *rr, uint16_t typec, uint32_t timestamp) +{ + if (!txn || !rr) { + return kr_error(EINVAL); + } + + /* Ignore empty records */ + if (knot_rrset_empty(rr)) { + return kr_ok(); + } + + /* Prepare header to write */ + struct kr_cache_entry header = { + .timestamp = timestamp, + .ttl = 0, + .count = rr->rrs.rr_count + }; + for (uint16_t i = 0; i < rr->rrs.rr_count; ++i) { + knot_rdata_t *rd = knot_rdataset_at(&rr->rrs, i); + if (knot_rdata_ttl(rd) > header.ttl) { + header.ttl = knot_rdata_ttl(rd); + } + } + + namedb_val_t data = { rr->rrs.data, knot_rdataset_size(&rr->rrs) }; + return kr_cache_insert(txn, KR_CACHE_RRSIG, rr->owner, typec, &header, data); +} diff --git a/lib/cache.h b/lib/cache.h index c26ab150f..7edd42169 100644 --- a/lib/cache.h +++ b/lib/cache.h @@ -24,6 +24,7 @@ enum kr_cache_tag { KR_CACHE_RR = 'R', KR_CACHE_PKT = 'P', KR_CACHE_SEC = 'S', + KR_CACHE_RRSIG = 'G', KR_CACHE_USER = 0x80 }; @@ -173,3 +174,24 @@ int kr_cache_materialize(knot_rrset_t *dst, const knot_rrset_t *src, uint32_t dr * @return 0 or an errcode */ int kr_cache_insert_rr(struct kr_cache_txn *txn, const knot_rrset_t *rr, uint32_t timestamp); + +/** + * Peek the cache for the given RRset signature (name, type) + * @note The RRset type must not be RRSIG but instead it must equal the type covered field of the sought RRSIG. + * @param txn transaction instance + * @param rr query RRSET (its rdataset and type may be changed depending on the result) + * @param timestamp current time (will be replaced with drift if successful) + * @return 0 or an errcode + */ +int kr_cache_peek_rrsig(struct kr_cache_txn *txn, knot_rrset_t *rr, uint32_t *timestamp); + +/** + * Insert the selected RRSIG RRSet of the selected type covered into cache, replacing any existing data. + * @note The RRSet must contain RRSIGS with only the specified type covered. + * @param txn transaction instance + * @param rr inserted RRSIG RRSet + * @param typec type covered of the RDATA + * @param timestamp current time + * @return 0 or an errcode + */ +int kr_cache_insert_rrsig(struct kr_cache_txn *txn, const knot_rrset_t *rr, uint16_t typec, uint32_t timestamp);