]> CyberLeo.Net >> Repos - FreeBSD/stable/8.git/blob - contrib/bind9/lib/dns/include/dns/cache.h
Update to version 9.6-ESV-R6, the latest from ISC, which contains numerous
[FreeBSD/stable/8.git] / contrib / bind9 / lib / dns / include / dns / cache.h
1 /*
2  * Copyright (C) 2004-2007, 2011, 2012  Internet Systems Consortium, Inc. ("ISC")
3  * Copyright (C) 1999-2001  Internet Software Consortium.
4  *
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.
8  *
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.
16  */
17
18 /* $Id$ */
19
20 #ifndef DNS_CACHE_H
21 #define DNS_CACHE_H 1
22
23 /*****
24  ***** Module Info
25  *****/
26
27 /*! \file dns/cache.h
28  * \brief
29  * Defines dns_cache_t, the cache object.
30  *
31  * Notes:
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.
35  *
36  * MP:
37  *\li   See notes at the individual functions.
38  *
39  * Reliability:
40  *
41  * Resources:
42  *
43  * Security:
44  *
45  * Standards:
46  */
47
48 /***
49  ***    Imports
50  ***/
51
52 #include <isc/lang.h>
53 #include <isc/stdtime.h>
54
55 #include <dns/types.h>
56
57 ISC_LANG_BEGINDECLS
58
59 /***
60  ***    Functions
61  ***/
62
63 isc_result_t
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);
68 isc_result_t
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);
73 isc_result_t
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);
78 /*%<
79  * Create a new DNS cache.
80  *
81  * dns_cache_create2() is used in BIND 9.7 and up but is not implemented
82  * here.
83  *
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).
88  *
89  * dns_cache_create() is a backward compatible version that internally
90  * specifies an empty cache name and a single memory context.
91  *
92  * Requires:
93  *
94  *\li   'cmctx' (and 'hmctx' if applicable) is a valid memory context.
95  *
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.
99  *
100  *\li   'cachep' is a valid pointer, and *cachep == NULL
101  *
102  * Ensures:
103  *
104  *\li   '*cachep' is attached to the newly created cache
105  *
106  * Returns:
107  *
108  *\li   #ISC_R_SUCCESS
109  *\li   #ISC_R_NOMEMORY
110  */
111
112 void
113 dns_cache_attach(dns_cache_t *cache, dns_cache_t **targetp);
114 /*%<
115  * Attach *targetp to cache.
116  *
117  * Requires:
118  *
119  *\li   'cache' is a valid cache.
120  *
121  *\li   'targetp' points to a NULL dns_cache_t *.
122  *
123  * Ensures:
124  *
125  *\li   *targetp is attached to cache.
126  */
127
128 void
129 dns_cache_detach(dns_cache_t **cachep);
130 /*%<
131  * Detach *cachep from its cache.
132  *
133  * Requires:
134  *
135  *\li   'cachep' points to a valid cache.
136  *
137  * Ensures:
138  *
139  *\li   *cachep is NULL.
140  *
141  *\li   If '*cachep' is the last reference to the cache,
142  *              all resources used by the cache will be freed
143  */
144
145 void
146 dns_cache_attachdb(dns_cache_t *cache, dns_db_t **dbp);
147 /*%<
148  * Attach *dbp to the cache's database.
149  *
150  * Notes:
151  *
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.
159  *
160  * Requires:
161  *
162  *\li   'cache' is a valid cache.
163  *
164  *\li   'dbp' points to a NULL dns_db *.
165  *
166  * Ensures:
167  *
168  *\li   *dbp is attached to the database.
169  */
170
171
172 isc_result_t
173 dns_cache_setfilename(dns_cache_t *cache, const char *filename);
174 /*%<
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.
179  *
180  * Returns:
181  *\li   #ISC_R_SUCCESS
182  *\li   #ISC_R_NOMEMORY
183  *\li   Various file-related failures
184  */
185
186 isc_result_t
187 dns_cache_load(dns_cache_t *cache);
188 /*%<
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.
192  *
193  * MT:
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.
200  *
201  * Returns:
202  *
203  *\li   #ISC_R_SUCCESS
204  *  \li    Various failures depending on the database implementation type
205  */
206
207 isc_result_t
208 dns_cache_dump(dns_cache_t *cache);
209 /*%<
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.
213  *
214  * MT:
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.
220  *
221  * Returns:
222  *
223  *\li   #ISC_R_SUCCESS
224  *  \li    Various failures depending on the database implementation type
225  */
226
227 isc_result_t
228 dns_cache_clean(dns_cache_t *cache, isc_stdtime_t now);
229 /*%<
230  * Force immediate cleaning of the cache, freeing all rdatasets
231  * whose TTL has expired as of 'now' and that have no pending
232  * references.
233  */
234
235 void
236 dns_cache_setcleaninginterval(dns_cache_t *cache, unsigned int interval);
237 /*%<
238  * Set the periodic cache cleaning interval to 'interval' seconds.
239  */
240
241 void
242 dns_cache_setcachesize(dns_cache_t *cache, isc_uint32_t size);
243 /*%<
244  * Set the maximum cache size.  0 means unlimited.
245  */
246
247 isc_result_t
248 dns_cache_flush(dns_cache_t *cache);
249 /*%<
250  * Flushes all data from the cache.
251  *
252  * Returns:
253  *\li   #ISC_R_SUCCESS
254  *\li   #ISC_R_NOMEMORY
255  */
256
257 isc_result_t
258 dns_cache_flushname(dns_cache_t *cache, dns_name_t *name);
259 /*
260  * Flushes a given name from the cache.
261  *
262  * Requires:
263  *\li   'cache' to be valid.
264  *\li   'name' to be valid.
265  *
266  * Returns:
267  *\li   #ISC_R_SUCCESS
268  *\li   #ISC_R_NOMEMORY
269  *\li   other error returns.
270  */
271
272 ISC_LANG_ENDDECLS
273
274 #endif /* DNS_CACHE_H */