2 * Copyright (C) 2004-2007, 2011, 2012 Internet Systems Consortium, Inc. ("ISC")
3 * Copyright (C) 1999-2001 Internet Software Consortium.
5 * Permission to use, copy, modify, and/or distribute this software for any
6 * purpose with or without fee is hereby granted, provided that the above
7 * copyright notice and this permission notice appear in all copies.
9 * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
10 * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
11 * AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
12 * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
13 * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
14 * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
15 * PERFORMANCE OF THIS SOFTWARE.
29 * Defines dns_cache_t, the cache object.
32 *\li A cache object contains DNS data of a single class.
33 * Multiple classes will be handled by creating multiple
34 * views, each with a different class and its own cache.
37 *\li See notes at the individual functions.
53 #include <isc/stdtime.h>
55 #include <dns/types.h>
64 dns_cache_create(isc_mem_t *cmctx, isc_taskmgr_t *taskmgr,
65 isc_timermgr_t *timermgr, dns_rdataclass_t rdclass,
66 const char *db_type, unsigned int db_argc, char **db_argv,
67 dns_cache_t **cachep);
69 dns_cache_create2(isc_mem_t *cmctx, isc_taskmgr_t *taskmgr,
70 isc_timermgr_t *timermgr, dns_rdataclass_t rdclass,
71 const char *cachename, const char *db_type,
72 unsigned int db_argc, char **db_argv, dns_cache_t **cachep);
74 dns_cache_create3(isc_mem_t *cmctx, isc_mem_t *hmctx, isc_taskmgr_t *taskmgr,
75 isc_timermgr_t *timermgr, dns_rdataclass_t rdclass,
76 const char *cachename, const char *db_type,
77 unsigned int db_argc, char **db_argv, dns_cache_t **cachep);
79 * Create a new DNS cache.
81 * dns_cache_create2() is used in BIND 9.7 and up but is not implemented
84 * dns_cache_create3() will create a cache using two separate memory
85 * contexts, one for cache data which can be cleaned and a separate one for
86 * memory allocated for the heap (which can grow without an upper limit and
87 * has no mechanism for shrinking).
89 * dns_cache_create() is a backward compatible version that internally
90 * specifies an empty cache name and a single memory context.
94 *\li 'cmctx' (and 'hmctx' if applicable) is a valid memory context.
96 *\li 'taskmgr' is a valid task manager and 'timermgr' is a valid timer
97 * manager, or both are NULL. If NULL, no periodic cleaning of the
98 * cache will take place.
100 *\li 'cachep' is a valid pointer, and *cachep == NULL
104 *\li '*cachep' is attached to the newly created cache
113 dns_cache_attach(dns_cache_t *cache, dns_cache_t **targetp);
115 * Attach *targetp to cache.
119 *\li 'cache' is a valid cache.
121 *\li 'targetp' points to a NULL dns_cache_t *.
125 *\li *targetp is attached to cache.
129 dns_cache_detach(dns_cache_t **cachep);
131 * Detach *cachep from its cache.
135 *\li 'cachep' points to a valid cache.
139 *\li *cachep is NULL.
141 *\li If '*cachep' is the last reference to the cache,
142 * all resources used by the cache will be freed
146 dns_cache_attachdb(dns_cache_t *cache, dns_db_t **dbp);
148 * Attach *dbp to the cache's database.
152 *\li This may be used to get a reference to the database for
153 * the purpose of cache lookups (XXX currently it is also
154 * the way to add data to the cache, but having a
155 * separate dns_cache_add() interface instead would allow
156 * more control over memory usage).
157 * The caller should call dns_db_detach() on the reference
158 * when it is no longer needed.
162 *\li 'cache' is a valid cache.
164 *\li 'dbp' points to a NULL dns_db *.
168 *\li *dbp is attached to the database.
173 dns_cache_setfilename(dns_cache_t *cache, const char *filename);
175 * If 'filename' is non-NULL, make the cache persistent.
176 * The cache's data will be stored in the given file.
177 * If 'filename' is NULL, make the cache non-persistent.
178 * Files that are no longer used are not unlinked automatically.
183 *\li Various file-related failures
187 dns_cache_load(dns_cache_t *cache);
189 * If the cache has a file name, load the cache contents from the file.
190 * Previous cache contents are not discarded.
191 * If no file name has been set, do nothing and return success.
194 *\li Multiple simultaneous attempts to load or dump the cache
195 * will be serialized with respect to one another, but
196 * the cache may be read and updated while the dump is
197 * in progress. Updates performed during loading
198 * may or may not be preserved, and reads may return
199 * either the old or the newly loaded data.
204 * \li Various failures depending on the database implementation type
208 dns_cache_dump(dns_cache_t *cache);
210 * If the cache has a file name, write the cache contents to disk,
211 * overwriting any preexisting file. If no file name has been set,
212 * do nothing and return success.
215 *\li Multiple simultaneous attempts to load or dump the cache
216 * will be serialized with respect to one another, but
217 * the cache may be read and updated while the dump is
218 * in progress. Updates performed during the dump may
219 * or may not be reflected in the dumped file.
224 * \li Various failures depending on the database implementation type
228 dns_cache_clean(dns_cache_t *cache, isc_stdtime_t now);
230 * Force immediate cleaning of the cache, freeing all rdatasets
231 * whose TTL has expired as of 'now' and that have no pending
236 dns_cache_setcleaninginterval(dns_cache_t *cache, unsigned int interval);
238 * Set the periodic cache cleaning interval to 'interval' seconds.
242 dns_cache_setcachesize(dns_cache_t *cache, isc_uint32_t size);
244 * Set the maximum cache size. 0 means unlimited.
248 dns_cache_flush(dns_cache_t *cache);
250 * Flushes all data from the cache.
258 dns_cache_flushname(dns_cache_t *cache, dns_name_t *name);
260 * Flushes a given name from the cache.
263 *\li 'cache' to be valid.
264 *\li 'name' to be valid.
269 *\li other error returns.
274 #endif /* DNS_CACHE_H */