cache.h 5.31 KB
Newer Older
1
/*
Bob Halley's avatar
Bob Halley committed
2
 * Copyright (C) 1999, 2000  Internet Software Consortium.
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65
 * 
 * Permission to use, copy, modify, and distribute this software for any
 * purpose with or without fee is hereby granted, provided that the above
 * copyright notice and this permission notice appear in all copies.
 * 
 * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS
 * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES
 * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE
 * CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
 * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
 * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
 * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
 * SOFTWARE.
 */

#ifndef DNS_CACHE_H
#define DNS_CACHE_H 1

/*****
 ***** Module Info
 *****/

/*
 * cache
 *
 * Defines dns_cache_t, the cache object.  
 *
 * Notes:
 * 	A cache object contains DNS data of a single class.
 *	Multiple classes will be handled by creating multiple
 *	views, each with a different class and its own cache.
 *
 * MP:
 *	See notes at the individual functions.
 *
 * Reliability:
 *
 * Resources:
 *
 * Security:
 *
 * Standards:
 */

/***
 ***	Imports
 ***/

#include <isc/lang.h>
#include <isc/mem.h>
#include <isc/task.h>
#include <isc/timer.h>
#include <isc/stdtime.h>

#include <dns/types.h>
#include <dns/result.h>

ISC_LANG_BEGINDECLS

/***
 ***	Functions
 ***/

66
isc_result_t 
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89
dns_cache_create(isc_mem_t *mctx, isc_taskmgr_t *taskmgr,
		 isc_timermgr_t *timermgr, dns_rdataclass_t rdclass,
		 char *db_type, unsigned int db_argc, char **db_argv,
		 dns_cache_t **cachep);
/*
 * Create a new DNS cache.  
 *
 * Requires:
 *
 *	'mctx' is a valid memory context
 *
 *	'taskmgr' is a valid task manager and 'timermgr' is a valid timer
 * 	manager, or both are NULL.  If NULL, no periodic cleaning of the
 * 	cache will take place.
 *
 *	'cachep' is a valid pointer, and *cachep == NULL
 *
 * Ensures:
 *
 *	'*cachep' is attached to the newly created cache
 *
 * Returns:
 *
90 91
 *	ISC_R_SUCCESS
 *	ISC_R_NOMEMORY
92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128
 */

void
dns_cache_attach(dns_cache_t *cache, dns_cache_t **targetp);
/*
 * Attach *targetp to cache.
 *
 * Requires:
 *
 *	'cache' is a valid cache.
 *
 *	'targetp' points to a NULL dns_cache_t *.
 *
 * Ensures:
 *
 *	*targetp is attached to cache.
 */

void
dns_cache_detach(dns_cache_t **cachep);
/*
 * Detach *cachep from its cache.
 *
 * Requires:
 *
 *	'cachep' points to a valid cache.
 *
 * Ensures:
 *
 *	*cachep is NULL.
 *
 *	If '*cachep' is the last reference to the cache,
 *
 *		All resources used by the cache will be freed
 */

void
129
dns_cache_attachdb(dns_cache_t *cache, dns_db_t **dbp);
130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154
/*
 * Attach *dbp to the cache's database.
 *
 * Notes:
 *
 *	This may be used to get a reference to the database for
 *	the purpose of cache lookups (XXX currently it is also
 * 	the way to add data to the cache, but having a
 * 	separate dns_cache_add() interface instead would allow 
 * 	more control over memory usage).
 *	The caller should call dns_db_detach() on the reference 
 *	when it is no longer needed.
 *
 * Requires:
 *
 *	'cache' is a valid cache.
 *
 *	'dbp' points to a NULL dns_db *.
 *
 * Ensures:
 *
 *	*dbp is attached to the database.
 */


155
isc_result_t
156 157 158 159 160 161 162 163
dns_cache_setfilename(dns_cache_t *cahce, char *filename);
/*
 * If 'filename' is non-NULL, make the cache persistent.
 * The cache's data will be stored in the given file.
 * If 'filename' is NULL, make the cache non-persistent.
 * Files that are no longer used are not unlinked automatically.
 *
 * Returns:
164 165
 *	ISC_R_SUCCESS
 *	ISC_R_NOMEMORY
166 167 168
 *	Various file-related failures
 */

169
isc_result_t
170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185
dns_cache_load(dns_cache_t *cache);
/*
 * If the cache has a file name, load the cache contents from the file.
 * Previous cache contents are not discarded.
 * If no file name has been set, do nothing and return success.
 *
 * MT:
 *	Multiple simultaneous attempts to load or dump the cache 
 * 	will be serialized with respect to one another, but
 *	the cache may be read and updated while the dump is
 *	in progress.  Updates performed during loading 
 *	may or may not be preserved, and reads may return
 * 	either the old or the newly loaded data.
 *
 * Returns:
 *
186
 *	ISC_R_SUCCESS
187 188 189
 *      Various failures depending on the database implementation type
 */

190
isc_result_t
191 192 193 194 195 196 197 198 199 200 201 202 203 204 205
dns_cache_dump(dns_cache_t *cache);
/*
 * If the cache has a file name, write the cache contents to disk,
 * overwriting any preexisting file.  If no file name has been set,
 * do nothing and return success.
 *
 * MT:
 *	Multiple simultaneous attempts to load or dump the cache 
 * 	will be serialized with respect to one another, but
 *	the cache may be read and updated while the dump is
 *	in progress.  Updates performed during the dump may
 * 	or may not be reflected in the dumped file.
 * 
 * Returns:
 *
206
 *	ISC_R_SUCCESS
207 208 209
 *      Various failures depending on the database implementation type
 */

210
isc_result_t
211 212 213 214 215 216 217
dns_cache_clean(dns_cache_t *cache, isc_stdtime_t now);
/*
 * Force immediate cleaning of the cache, freeing all rdatasets
 * whose TTL has expired as of 'now' and that have no pending
 * references.
 */

218 219 220 221 222 223
void
dns_cache_setcleaninginterval(dns_cache_t *cache, unsigned int interval);
/*
 * Set the periodic cache cleaning interval to 'interval' seconds.
 */ 

224 225
ISC_LANG_ENDDECLS

226
#endif /* DNS_CACHE_H */