2 * cachedb/cachedb.c - cache from a database external to the program module
4 * Copyright (c) 2016, NLnet Labs. All rights reserved.
6 * This software is open source.
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
12 * Redistributions of source code must retain the above copyright notice,
13 * this list of conditions and the following disclaimer.
15 * Redistributions in binary form must reproduce the above copyright notice,
16 * this list of conditions and the following disclaimer in the documentation
17 * and/or other materials provided with the distribution.
19 * Neither the name of the NLNET LABS nor the names of its contributors may
20 * be used to endorse or promote products derived from this software without
21 * specific prior written permission.
23 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
24 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
25 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
26 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
27 * HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
28 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
29 * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
30 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
31 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
32 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
33 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
39 * This file contains a module that uses an external database to cache
45 #include "cachedb/cachedb.h"
46 #include "util/regional.h"
47 #include "util/net_help.h"
48 #include "util/config_file.h"
49 #include "util/data/msgreply.h"
50 #include "util/data/msgencode.h"
51 #include "services/cache/dns.h"
52 #include "validator/val_neg.h"
53 #include "validator/val_secalgo.h"
54 #include "iterator/iter_utils.h"
55 #include "sldns/parseutil.h"
56 #include "sldns/wire2str.h"
57 #include "sldns/sbuffer.h"
59 #define CACHEDB_HASHSIZE 256 /* bit hash */
61 /** the unit test testframe for cachedb, its module state contains
62 * a cache for a couple queries (in memory). */
63 struct testframe_moddata {
66 /** key for single stored data element, NULL if none */
68 /** data for single stored data element, NULL if none */
70 /** length of stored data */
71 size_t stored_datalen;
75 testframe_init(struct module_env* env, struct cachedb_env* cachedb_env)
77 struct testframe_moddata* d;
79 verbose(VERB_ALGO, "testframe_init");
80 d = (struct testframe_moddata*)calloc(1,
81 sizeof(struct testframe_moddata));
82 cachedb_env->backend_data = (void*)d;
83 if(!cachedb_env->backend_data) {
84 log_err("out of memory");
87 lock_basic_init(&d->lock);
88 lock_protect(&d->lock, d, sizeof(*d));
93 testframe_deinit(struct module_env* env, struct cachedb_env* cachedb_env)
95 struct testframe_moddata* d = (struct testframe_moddata*)
96 cachedb_env->backend_data;
98 verbose(VERB_ALGO, "testframe_deinit");
101 lock_basic_destroy(&d->lock);
103 free(d->stored_data);
108 testframe_lookup(struct module_env* env, struct cachedb_env* cachedb_env,
109 char* key, struct sldns_buffer* result_buffer)
111 struct testframe_moddata* d = (struct testframe_moddata*)
112 cachedb_env->backend_data;
114 verbose(VERB_ALGO, "testframe_lookup of %s", key);
115 lock_basic_lock(&d->lock);
116 if(d->stored_key && strcmp(d->stored_key, key) == 0) {
117 if(d->stored_datalen > sldns_buffer_capacity(result_buffer)) {
118 lock_basic_unlock(&d->lock);
119 return 0; /* too large */
121 verbose(VERB_ALGO, "testframe_lookup found %d bytes",
122 (int)d->stored_datalen);
123 sldns_buffer_clear(result_buffer);
124 sldns_buffer_write(result_buffer, d->stored_data,
126 sldns_buffer_flip(result_buffer);
127 lock_basic_unlock(&d->lock);
130 lock_basic_unlock(&d->lock);
135 testframe_store(struct module_env* env, struct cachedb_env* cachedb_env,
136 char* key, uint8_t* data, size_t data_len)
138 struct testframe_moddata* d = (struct testframe_moddata*)
139 cachedb_env->backend_data;
141 lock_basic_lock(&d->lock);
142 verbose(VERB_ALGO, "testframe_store %s (%d bytes)", key, (int)data_len);
144 /* free old data element (if any) */
146 d->stored_key = NULL;
147 free(d->stored_data);
148 d->stored_data = NULL;
149 d->stored_datalen = 0;
151 d->stored_data = memdup(data, data_len);
152 if(!d->stored_data) {
153 lock_basic_unlock(&d->lock);
154 log_err("out of memory");
157 d->stored_datalen = data_len;
158 d->stored_key = strdup(key);
160 free(d->stored_data);
161 d->stored_data = NULL;
162 d->stored_datalen = 0;
163 lock_basic_unlock(&d->lock);
166 lock_basic_unlock(&d->lock);
167 /* (key,data) successfully stored */
170 /** The testframe backend is for unit tests */
171 static struct cachedb_backend testframe_backend = { "testframe",
172 testframe_init, testframe_deinit, testframe_lookup, testframe_store
175 /** find a particular backend from possible backends */
176 static struct cachedb_backend*
177 cachedb_find_backend(const char* str)
179 if(strcmp(str, testframe_backend.name) == 0)
180 return &testframe_backend;
181 /* TODO add more backends here */
185 /** apply configuration to cachedb module 'global' state */
187 cachedb_apply_cfg(struct cachedb_env* cachedb_env, struct config_file* cfg)
189 const char* backend_str = cfg->cachedb_backend;
191 /* If unspecified we use the in-memory test DB. */
193 backend_str = "testframe";
194 cachedb_env->backend = cachedb_find_backend(backend_str);
195 if(!cachedb_env->backend) {
196 log_err("cachedb: cannot find backend name '%s'", backend_str);
200 /* TODO see if more configuration needs to be applied or not */
205 cachedb_init(struct module_env* env, int id)
207 struct cachedb_env* cachedb_env = (struct cachedb_env*)calloc(1,
208 sizeof(struct cachedb_env));
210 log_err("malloc failure");
213 env->modinfo[id] = (void*)cachedb_env;
214 if(!cachedb_apply_cfg(cachedb_env, env->cfg)) {
215 log_err("cachedb: could not apply configuration settings.");
218 /* see if a backend is selected */
219 if(!cachedb_env->backend || !cachedb_env->backend->name)
221 if(!(*cachedb_env->backend->init)(env, cachedb_env)) {
222 log_err("cachedb: could not init %s backend",
223 cachedb_env->backend->name);
226 cachedb_env->enabled = 1;
231 cachedb_deinit(struct module_env* env, int id)
233 struct cachedb_env* cachedb_env;
234 if(!env || !env->modinfo[id])
236 cachedb_env = (struct cachedb_env*)env->modinfo[id];
239 if(cachedb_env->enabled) {
240 (*cachedb_env->backend->deinit)(env, cachedb_env);
244 env->modinfo[id] = NULL;
247 /** new query for cachedb */
249 cachedb_new(struct module_qstate* qstate, int id)
251 struct cachedb_qstate* iq = (struct cachedb_qstate*)regional_alloc(
252 qstate->region, sizeof(struct cachedb_qstate));
253 qstate->minfo[id] = iq;
256 memset(iq, 0, sizeof(*iq));
265 * @param qstate: our query state
266 * @param id: module id
267 * @param rcode: error code (DNS errcode).
268 * @return: 0 for use by caller, to make notation easy, like:
269 * return error_response(..).
272 error_response(struct module_qstate* qstate, int id, int rcode)
274 verbose(VERB_QUERY, "return error response %s",
275 sldns_lookup_by_id(sldns_rcodes, rcode)?
276 sldns_lookup_by_id(sldns_rcodes, rcode)->name:"??");
277 qstate->return_rcode = rcode;
278 qstate->return_msg = NULL;
279 qstate->ext_state[id] = module_finished;
284 * Hash the query name, type, class and dbacess-secret into lookup buffer.
285 * @param qstate: query state with query info
286 * and env->cfg with secret.
287 * @param buf: returned buffer with hash to lookup
288 * @param len: length of the buffer.
291 calc_hash(struct module_qstate* qstate, char* buf, size_t len)
295 uint8_t hash[CACHEDB_HASHSIZE/8];
296 const char* hex = "0123456789ABCDEF";
297 const char* secret = qstate->env->cfg->cachedb_secret ?
298 qstate->env->cfg->cachedb_secret : "default";
301 /* copy the hash info into the clear buffer */
302 if(clen + qstate->qinfo.qname_len < sizeof(clear)) {
303 memmove(clear+clen, qstate->qinfo.qname,
304 qstate->qinfo.qname_len);
305 clen += qstate->qinfo.qname_len;
307 if(clen + 4 < sizeof(clear)) {
308 uint16_t t = htons(qstate->qinfo.qtype);
309 uint16_t c = htons(qstate->qinfo.qclass);
310 memmove(clear+clen, &t, 2);
311 memmove(clear+clen+2, &c, 2);
314 if(secret && secret[0] && clen + strlen(secret) < sizeof(clear)) {
315 memmove(clear+clen, secret, strlen(secret));
316 clen += strlen(secret);
319 /* hash the buffer */
320 secalgo_hash_sha256(clear, clen, hash);
321 memset(clear, 0, clen);
323 /* hex encode output for portability (some online dbs need
324 * no nulls, no control characters, and so on) */
325 log_assert(len >= sizeof(hash)*2 + 1);
327 for(i=0; i<sizeof(hash); i++) {
328 buf[i*2] = hex[(hash[i]&0xf0)>>4];
329 buf[i*2+1] = hex[hash[i]&0x0f];
331 buf[sizeof(hash)*2] = 0;
334 /** convert data from return_msg into the data buffer */
336 prep_data(struct module_qstate* qstate, struct sldns_buffer* buf)
338 uint64_t timestamp, expiry;
340 struct edns_data edns;
341 memset(&edns, 0, sizeof(edns));
342 edns.edns_present = 1;
345 edns.edns_version = EDNS_ADVERTISED_VERSION;
346 edns.udp_size = EDNS_ADVERTISED_SIZE;
348 if(!qstate->return_msg || !qstate->return_msg->rep)
350 /* We don't store the reply if its TTL is 0 unless serve-expired is
351 * enabled. Such a reply won't be reusable and simply be a waste for
352 * the backend. It's also compatible with the default behavior of
353 * dns_cache_store_msg(). */
354 if(qstate->return_msg->rep->ttl == 0 &&
355 !qstate->env->cfg->serve_expired)
357 if(verbosity >= VERB_ALGO)
358 log_dns_msg("cachedb encoding", &qstate->return_msg->qinfo,
359 qstate->return_msg->rep);
360 if(!reply_info_answer_encode(&qstate->return_msg->qinfo,
361 qstate->return_msg->rep, 0, qstate->query_flags,
362 buf, 0, 1, qstate->env->scratch, 65535, &edns, 1, 0))
365 /* TTLs in the return_msg are relative to time(0) so we have to
366 * store that, we also store the smallest ttl in the packet+time(0)
367 * as the packet expiry time */
368 /* qstate->return_msg->rep->ttl contains that relative shortest ttl */
369 timestamp = (uint64_t)*qstate->env->now;
370 expiry = timestamp + (uint64_t)qstate->return_msg->rep->ttl;
371 timestamp = htobe64(timestamp);
372 expiry = htobe64(expiry);
373 oldlim = sldns_buffer_limit(buf);
374 if(oldlim + sizeof(timestamp)+sizeof(expiry) >=
375 sldns_buffer_capacity(buf))
376 return 0; /* doesn't fit. */
377 sldns_buffer_set_limit(buf, oldlim + sizeof(timestamp)+sizeof(expiry));
378 sldns_buffer_write_at(buf, oldlim, ×tamp, sizeof(timestamp));
379 sldns_buffer_write_at(buf, oldlim+sizeof(timestamp), &expiry,
385 /** check expiry, return true if matches OK */
387 good_expiry_and_qinfo(struct module_qstate* qstate, struct sldns_buffer* buf)
390 /* the expiry time is the last bytes of the buffer */
391 if(sldns_buffer_limit(buf) < sizeof(expiry))
393 sldns_buffer_read_at(buf, sldns_buffer_limit(buf)-sizeof(expiry),
394 &expiry, sizeof(expiry));
395 expiry = be64toh(expiry);
397 if((time_t)expiry < *qstate->env->now &&
398 !qstate->env->cfg->serve_expired)
404 /* Adjust the TTL of the given RRset by 'subtract'. If 'subtract' is
405 * negative, set the TTL to 0. */
407 packed_rrset_ttl_subtract(struct packed_rrset_data* data, time_t subtract)
410 size_t total = data->count + data->rrsig_count;
411 if(subtract >= 0 && data->ttl > subtract)
412 data->ttl -= subtract;
414 for(i=0; i<total; i++) {
415 if(subtract >= 0 && data->rr_ttl[i] > subtract)
416 data->rr_ttl[i] -= subtract;
417 else data->rr_ttl[i] = 0;
421 /* Adjust the TTL of a DNS message and its RRs by 'adjust'. If 'adjust' is
422 * negative, set the TTLs to 0. */
424 adjust_msg_ttl(struct dns_msg* msg, time_t adjust)
427 if(adjust >= 0 && msg->rep->ttl > adjust)
428 msg->rep->ttl -= adjust;
429 else msg->rep->ttl = 0;
430 msg->rep->prefetch_ttl = PREFETCH_TTL_CALC(msg->rep->ttl);
432 for(i=0; i<msg->rep->rrset_count; i++) {
433 packed_rrset_ttl_subtract((struct packed_rrset_data*)msg->
434 rep->rrsets[i]->entry.data, adjust);
438 /** convert dns message in buffer to return_msg */
440 parse_data(struct module_qstate* qstate, struct sldns_buffer* buf)
442 struct msg_parse* prs;
443 struct edns_data edns;
444 uint64_t timestamp, expiry;
446 size_t lim = sldns_buffer_limit(buf);
447 if(lim < LDNS_HEADER_SIZE+sizeof(timestamp)+sizeof(expiry))
448 return 0; /* too short */
450 /* remove timestamp and expiry from end */
451 sldns_buffer_read_at(buf, lim-sizeof(expiry), &expiry, sizeof(expiry));
452 sldns_buffer_read_at(buf, lim-sizeof(expiry)-sizeof(timestamp),
453 ×tamp, sizeof(timestamp));
454 expiry = be64toh(expiry);
455 timestamp = be64toh(timestamp);
457 /* parse DNS packet */
458 regional_free_all(qstate->env->scratch);
459 prs = (struct msg_parse*)regional_alloc(qstate->env->scratch,
460 sizeof(struct msg_parse));
462 return 0; /* out of memory */
463 memset(prs, 0, sizeof(*prs));
464 memset(&edns, 0, sizeof(edns));
465 sldns_buffer_set_limit(buf, lim - sizeof(expiry)-sizeof(timestamp));
466 if(parse_packet(buf, prs, qstate->env->scratch) != LDNS_RCODE_NOERROR) {
467 sldns_buffer_set_limit(buf, lim);
470 if(parse_extract_edns(prs, &edns, qstate->env->scratch) !=
471 LDNS_RCODE_NOERROR) {
472 sldns_buffer_set_limit(buf, lim);
476 qstate->return_msg = dns_alloc_msg(buf, prs, qstate->region);
477 sldns_buffer_set_limit(buf, lim);
478 if(!qstate->return_msg)
481 qstate->return_rcode = LDNS_RCODE_NOERROR;
483 /* see how much of the TTL expired, and remove it */
484 if(*qstate->env->now <= (time_t)timestamp) {
485 verbose(VERB_ALGO, "cachedb msg adjust by zero");
486 return 1; /* message from the future (clock skew?) */
488 adjust = *qstate->env->now - (time_t)timestamp;
489 if(qstate->return_msg->rep->ttl < adjust) {
490 verbose(VERB_ALGO, "cachedb msg expired");
491 /* If serve-expired is enabled, we still use an expired message
492 * setting the TTL to 0. */
493 if(qstate->env->cfg->serve_expired)
496 return 0; /* message expired */
498 verbose(VERB_ALGO, "cachedb msg adjusted down by %d", (int)adjust);
499 adjust_msg_ttl(qstate->return_msg, adjust);
501 /* Similar to the unbound worker, if serve-expired is enabled and
502 * the msg would be considered to be expired, mark the state so a
503 * refetch will be scheduled. The comparison between 'expiry' and
504 * 'now' should be redundant given how these values were calculated,
505 * but we check it just in case as does good_expiry_and_qinfo(). */
506 if(qstate->env->cfg->serve_expired &&
507 (adjust == -1 || (time_t)expiry < *qstate->env->now)) {
508 qstate->need_refetch = 1;
515 * Lookup the qstate.qinfo in extcache, store in qstate.return_msg.
516 * return true if lookup was successful.
519 cachedb_extcache_lookup(struct module_qstate* qstate, struct cachedb_env* ie)
521 char key[(CACHEDB_HASHSIZE/8)*2+1];
522 calc_hash(qstate, key, sizeof(key));
524 /* call backend to fetch data for key into scratch buffer */
525 if( !(*ie->backend->lookup)(qstate->env, ie, key,
526 qstate->env->scratch_buffer)) {
530 /* check expiry date and check if query-data matches */
531 if( !good_expiry_and_qinfo(qstate, qstate->env->scratch_buffer) ) {
535 /* parse dns message into return_msg */
536 if( !parse_data(qstate, qstate->env->scratch_buffer) ) {
543 * Store the qstate.return_msg in extcache for key qstate.info
546 cachedb_extcache_store(struct module_qstate* qstate, struct cachedb_env* ie)
548 char key[(CACHEDB_HASHSIZE/8)*2+1];
549 calc_hash(qstate, key, sizeof(key));
551 /* prepare data in scratch buffer */
552 if(!prep_data(qstate, qstate->env->scratch_buffer))
556 (*ie->backend->store)(qstate->env, ie, key,
557 sldns_buffer_begin(qstate->env->scratch_buffer),
558 sldns_buffer_limit(qstate->env->scratch_buffer));
562 * See if unbound's internal cache can answer the query
565 cachedb_intcache_lookup(struct module_qstate* qstate)
568 msg = dns_cache_lookup(qstate->env, qstate->qinfo.qname,
569 qstate->qinfo.qname_len, qstate->qinfo.qtype,
570 qstate->qinfo.qclass, qstate->query_flags,
571 qstate->region, qstate->env->scratch);
572 if(!msg && qstate->env->neg_cache) {
573 /* lookup in negative cache; may result in
574 * NOERROR/NODATA or NXDOMAIN answers that need validation */
575 msg = val_neg_getmsg(qstate->env->neg_cache, &qstate->qinfo,
576 qstate->region, qstate->env->rrset_cache,
577 qstate->env->scratch_buffer,
578 *qstate->env->now, 1/*add SOA*/, NULL);
582 /* this is the returned msg */
583 qstate->return_rcode = LDNS_RCODE_NOERROR;
584 qstate->return_msg = msg;
589 * Store query into the internal cache of unbound.
592 cachedb_intcache_store(struct module_qstate* qstate)
594 uint32_t store_flags = qstate->query_flags;
596 if(qstate->env->cfg->serve_expired)
597 store_flags |= DNSCACHE_STORE_ZEROTTL;
598 if(!qstate->return_msg)
600 (void)dns_cache_store(qstate->env, &qstate->qinfo,
601 qstate->return_msg->rep, 0, qstate->prefetch_leeway, 0,
602 qstate->region, store_flags);
606 * Handle a cachedb module event with a query
607 * @param qstate: query state (from the mesh), passed between modules.
608 * contains qstate->env module environment with global caches and so on.
609 * @param iq: query state specific for this module. per-query.
610 * @param ie: environment specific for this module. global.
611 * @param id: module id.
614 cachedb_handle_query(struct module_qstate* qstate,
615 struct cachedb_qstate* ATTR_UNUSED(iq),
616 struct cachedb_env* ie, int id)
618 /* check if we are enabled, and skip if so */
620 /* pass request to next module */
621 qstate->ext_state[id] = module_wait_module;
625 if(qstate->blacklist || qstate->no_cache_lookup) {
626 /* cache is blacklisted or we are instructed from edns to not look */
627 /* pass request to next module */
628 qstate->ext_state[id] = module_wait_module;
632 /* lookup inside unbound's internal cache */
633 if(cachedb_intcache_lookup(qstate)) {
634 if(verbosity >= VERB_ALGO) {
635 if(qstate->return_msg->rep)
636 log_dns_msg("cachedb internal cache lookup",
637 &qstate->return_msg->qinfo,
638 qstate->return_msg->rep);
639 else log_info("cachedb internal cache lookup: rcode %s",
640 sldns_lookup_by_id(sldns_rcodes, qstate->return_rcode)?
641 sldns_lookup_by_id(sldns_rcodes, qstate->return_rcode)->name:"??");
643 /* we are done with the query */
644 qstate->ext_state[id] = module_finished;
648 /* ask backend cache to see if we have data */
649 if(cachedb_extcache_lookup(qstate, ie)) {
650 if(verbosity >= VERB_ALGO)
651 log_dns_msg(ie->backend->name,
652 &qstate->return_msg->qinfo,
653 qstate->return_msg->rep);
654 /* store this result in internal cache */
655 cachedb_intcache_store(qstate);
656 /* we are done with the query */
657 qstate->ext_state[id] = module_finished;
661 /* no cache fetches */
662 /* pass request to next module */
663 qstate->ext_state[id] = module_wait_module;
667 * Handle a cachedb module event with a response from the iterator.
668 * @param qstate: query state (from the mesh), passed between modules.
669 * contains qstate->env module environment with global caches and so on.
670 * @param iq: query state specific for this module. per-query.
671 * @param ie: environment specific for this module. global.
672 * @param id: module id.
675 cachedb_handle_response(struct module_qstate* qstate,
676 struct cachedb_qstate* ATTR_UNUSED(iq), struct cachedb_env* ie, int id)
678 /* check if we are not enabled or instructed to not cache, and skip */
679 if(!ie->enabled || qstate->no_cache_store) {
680 /* we are done with the query */
681 qstate->ext_state[id] = module_finished;
685 /* store the item into the backend cache */
686 cachedb_extcache_store(qstate, ie);
688 /* we are done with the query */
689 qstate->ext_state[id] = module_finished;
693 cachedb_operate(struct module_qstate* qstate, enum module_ev event, int id,
694 struct outbound_entry* outbound)
696 struct cachedb_env* ie = (struct cachedb_env*)qstate->env->modinfo[id];
697 struct cachedb_qstate* iq = (struct cachedb_qstate*)qstate->minfo[id];
698 verbose(VERB_QUERY, "cachedb[module %d] operate: extstate:%s event:%s",
699 id, strextstate(qstate->ext_state[id]), strmodulevent(event));
700 if(iq) log_query_info(VERB_QUERY, "cachedb operate: query",
703 /* perform cachedb state machine */
704 if((event == module_event_new || event == module_event_pass) &&
706 if(!cachedb_new(qstate, id)) {
707 (void)error_response(qstate, id, LDNS_RCODE_SERVFAIL);
710 iq = (struct cachedb_qstate*)qstate->minfo[id];
712 if(iq && (event == module_event_pass || event == module_event_new)) {
713 cachedb_handle_query(qstate, iq, ie, id);
716 if(iq && (event == module_event_moddone)) {
717 cachedb_handle_response(qstate, iq, ie, id);
721 /* cachedb does not need to process responses at this time
723 cachedb_process_response(qstate, iq, ie, id, outbound, event);
727 if(event == module_event_error) {
728 verbose(VERB_ALGO, "got called with event error, giving up");
729 (void)error_response(qstate, id, LDNS_RCODE_SERVFAIL);
732 if(!iq && (event == module_event_moddone)) {
733 /* during priming, module done but we never started */
734 qstate->ext_state[id] = module_finished;
738 log_err("bad event for cachedb");
739 (void)error_response(qstate, id, LDNS_RCODE_SERVFAIL);
743 cachedb_inform_super(struct module_qstate* ATTR_UNUSED(qstate),
744 int ATTR_UNUSED(id), struct module_qstate* ATTR_UNUSED(super))
746 /* cachedb does not use subordinate requests at this time */
747 verbose(VERB_ALGO, "cachedb inform_super was called");
751 cachedb_clear(struct module_qstate* qstate, int id)
753 struct cachedb_qstate* iq;
756 iq = (struct cachedb_qstate*)qstate->minfo[id];
758 /* free contents of iq */
761 qstate->minfo[id] = NULL;
765 cachedb_get_mem(struct module_env* env, int id)
767 struct cachedb_env* ie = (struct cachedb_env*)env->modinfo[id];
770 return sizeof(*ie); /* TODO - more mem */
774 * The cachedb function block
776 static struct module_func_block cachedb_block = {
778 &cachedb_init, &cachedb_deinit, &cachedb_operate,
779 &cachedb_inform_super, &cachedb_clear, &cachedb_get_mem
782 struct module_func_block*
783 cachedb_get_funcblock(void)
785 return &cachedb_block;
787 #endif /* USE_CACHEDB */