]> git.ipfire.org Git - thirdparty/knot-resolver.git/commitdiff
lib/cache: RRSIG RRsets have a separate cache storing mechanism
authorKarel Slany <karel.slany@nic.cz>
Fri, 22 May 2015 10:46:22 +0000 (12:46 +0200)
committerKarel Slany <karel.slany@nic.cz>
Mon, 29 Jun 2015 07:56:27 +0000 (09:56 +0200)
lib/cache.c
lib/cache.h

index afc3eba67dcbafe1304d1d4eba7e2b942e17d5fe..9c1102f75887663df45639323770124e8a7899df 100644 (file)
@@ -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);
+}
index c26ab150f3c260c2df19f68ca3ed1253ac922524..7edd42169de24c67cf9d2e7b8d385f719beec936 100644 (file)
@@ -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);