Commit 557d4cf2 authored by Karel Slaný's avatar Karel Slaný

lib/cache: RRSIG RRsets have a separate cache storing mechanism

parent ada0fd5c
......@@ -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);
}
......@@ -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);
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment