0c27b3fe77ac1d5094ba3521e8142d9e7973133fMark Andrews * Copyright (C) 1999-2001, 2004-2007, 2009, 2011-2013, 2016 Internet Systems Consortium, Inc. ("ISC")
0c27b3fe77ac1d5094ba3521e8142d9e7973133fMark Andrews * This Source Code Form is subject to the terms of the Mozilla Public
0c27b3fe77ac1d5094ba3521e8142d9e7973133fMark Andrews * License, v. 2.0. If a copy of the MPL was not distributed with this
0c27b3fe77ac1d5094ba3521e8142d9e7973133fMark Andrews * file, You can obtain one at http://mozilla.org/MPL/2.0/.
adbc1771946365942cc149f6130c36f3aca44fb8Automatic Updater/* $Id: cache.h,v 1.32 2011/08/02 23:47:52 tbox Exp $ */
f951f076f3d321c52b824a866caff28ce4f8e06cAndreas Gustafsson ***** Module Info
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence * Defines dns_cache_t, the cache object.
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein *\li A cache object contains DNS data of a single class.
f951f076f3d321c52b824a866caff28ce4f8e06cAndreas Gustafsson * Multiple classes will be handled by creating multiple
f951f076f3d321c52b824a866caff28ce4f8e06cAndreas Gustafsson * views, each with a different class and its own cache.
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein *\li See notes at the individual functions.
f951f076f3d321c52b824a866caff28ce4f8e06cAndreas Gustafsson * Reliability:
70c7f4fb4fc589b04a68d67479d34eecd99c1991Evan Huntdns_cache_create(isc_mem_t *cmctx, isc_taskmgr_t *taskmgr,
f951f076f3d321c52b824a866caff28ce4f8e06cAndreas Gustafsson isc_timermgr_t *timermgr, dns_rdataclass_t rdclass,
6d12fdf96621801e80f3f4c2a8a569fe48766a20David Lawrence const char *db_type, unsigned int db_argc, char **db_argv,
70c7f4fb4fc589b04a68d67479d34eecd99c1991Evan Huntdns_cache_create2(isc_mem_t *cmctx, isc_taskmgr_t *taskmgr,
70c7f4fb4fc589b04a68d67479d34eecd99c1991Evan Hunt isc_timermgr_t *timermgr, dns_rdataclass_t rdclass,
70c7f4fb4fc589b04a68d67479d34eecd99c1991Evan Hunt unsigned int db_argc, char **db_argv, dns_cache_t **cachep);
70c7f4fb4fc589b04a68d67479d34eecd99c1991Evan Huntdns_cache_create3(isc_mem_t *cmctx, isc_mem_t *hmctx, isc_taskmgr_t *taskmgr,
7781f25078c491a9650dec555bdc86cb0ed49861Tatuya JINMEI 神明達哉 isc_timermgr_t *timermgr, dns_rdataclass_t rdclass,
7781f25078c491a9650dec555bdc86cb0ed49861Tatuya JINMEI 神明達哉 const char *cachename, const char *db_type,
7781f25078c491a9650dec555bdc86cb0ed49861Tatuya JINMEI 神明達哉 unsigned int db_argc, char **db_argv, dns_cache_t **cachep);
70c7f4fb4fc589b04a68d67479d34eecd99c1991Evan Hunt * Create a new DNS cache.
70c7f4fb4fc589b04a68d67479d34eecd99c1991Evan Hunt * dns_cache_create2() will create a named cache.
70c7f4fb4fc589b04a68d67479d34eecd99c1991Evan Hunt * dns_cache_create3() will create a named cache using two separate memory
70c7f4fb4fc589b04a68d67479d34eecd99c1991Evan Hunt * contexts, one for cache data which can be cleaned and a separate one for
70c7f4fb4fc589b04a68d67479d34eecd99c1991Evan Hunt * memory allocated for the heap (which can grow without an upper limit and
70c7f4fb4fc589b04a68d67479d34eecd99c1991Evan Hunt * has no mechanism for shrinking).
70c7f4fb4fc589b04a68d67479d34eecd99c1991Evan Hunt * dns_cache_create() is a backward compatible version that internally
70c7f4fb4fc589b04a68d67479d34eecd99c1991Evan Hunt * specifies an empty cache name and a single memory context.
70c7f4fb4fc589b04a68d67479d34eecd99c1991Evan Hunt *\li 'cmctx' (and 'hmctx' if applicable) is a valid memory context.
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein *\li 'taskmgr' is a valid task manager and 'timermgr' is a valid timer
f951f076f3d321c52b824a866caff28ce4f8e06cAndreas Gustafsson * manager, or both are NULL. If NULL, no periodic cleaning of the
f951f076f3d321c52b824a866caff28ce4f8e06cAndreas Gustafsson * cache will take place.
7781f25078c491a9650dec555bdc86cb0ed49861Tatuya JINMEI 神明達哉 *\li 'cachename' is a valid string. This must not be NULL.
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein *\li 'cachep' is a valid pointer, and *cachep == NULL
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein *\li '*cachep' is attached to the newly created cache
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein *\li #ISC_R_SUCCESS
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein *\li #ISC_R_NOMEMORY
f951f076f3d321c52b824a866caff28ce4f8e06cAndreas Gustafssondns_cache_attach(dns_cache_t *cache, dns_cache_t **targetp);
f951f076f3d321c52b824a866caff28ce4f8e06cAndreas Gustafsson * Attach *targetp to cache.
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein *\li 'cache' is a valid cache.
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein *\li 'targetp' points to a NULL dns_cache_t *.
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein *\li *targetp is attached to cache.
f951f076f3d321c52b824a866caff28ce4f8e06cAndreas Gustafsson * Detach *cachep from its cache.
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein *\li 'cachep' points to a valid cache.
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein *\li *cachep is NULL.
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein *\li If '*cachep' is the last reference to the cache,
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein * all resources used by the cache will be freed
97404c1965ae83ecbfe9cf7b06f67dce5e28c588Andreas Gustafssondns_cache_attachdb(dns_cache_t *cache, dns_db_t **dbp);
f951f076f3d321c52b824a866caff28ce4f8e06cAndreas Gustafsson * Attach *dbp to the cache's database.
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein *\li This may be used to get a reference to the database for
f951f076f3d321c52b824a866caff28ce4f8e06cAndreas Gustafsson * the purpose of cache lookups (XXX currently it is also
f951f076f3d321c52b824a866caff28ce4f8e06cAndreas Gustafsson * the way to add data to the cache, but having a
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence * separate dns_cache_add() interface instead would allow
f951f076f3d321c52b824a866caff28ce4f8e06cAndreas Gustafsson * more control over memory usage).
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence * The caller should call dns_db_detach() on the reference
f951f076f3d321c52b824a866caff28ce4f8e06cAndreas Gustafsson * when it is no longer needed.
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein *\li 'cache' is a valid cache.
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein *\li 'dbp' points to a NULL dns_db *.
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein *\li *dbp is attached to the database.
4e1d3e67cdc76609bad5f0310ac48de10b442b9fMark Andrewsdns_cache_setfilename(dns_cache_t *cache, const char *filename);
f951f076f3d321c52b824a866caff28ce4f8e06cAndreas Gustafsson * If 'filename' is non-NULL, make the cache persistent.
f951f076f3d321c52b824a866caff28ce4f8e06cAndreas Gustafsson * The cache's data will be stored in the given file.
f951f076f3d321c52b824a866caff28ce4f8e06cAndreas Gustafsson * If 'filename' is NULL, make the cache non-persistent.
f951f076f3d321c52b824a866caff28ce4f8e06cAndreas Gustafsson * Files that are no longer used are not unlinked automatically.
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein *\li #ISC_R_SUCCESS
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein *\li #ISC_R_NOMEMORY
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein *\li Various file-related failures
f951f076f3d321c52b824a866caff28ce4f8e06cAndreas Gustafsson * If the cache has a file name, load the cache contents from the file.
f951f076f3d321c52b824a866caff28ce4f8e06cAndreas Gustafsson * Previous cache contents are not discarded.
f951f076f3d321c52b824a866caff28ce4f8e06cAndreas Gustafsson * If no file name has been set, do nothing and return success.
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein *\li Multiple simultaneous attempts to load or dump the cache
f951f076f3d321c52b824a866caff28ce4f8e06cAndreas Gustafsson * will be serialized with respect to one another, but
f951f076f3d321c52b824a866caff28ce4f8e06cAndreas Gustafsson * the cache may be read and updated while the dump is
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence * in progress. Updates performed during loading
f951f076f3d321c52b824a866caff28ce4f8e06cAndreas Gustafsson * may or may not be preserved, and reads may return
f951f076f3d321c52b824a866caff28ce4f8e06cAndreas Gustafsson * either the old or the newly loaded data.
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein *\li #ISC_R_SUCCESS
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein * \li Various failures depending on the database implementation type
f951f076f3d321c52b824a866caff28ce4f8e06cAndreas Gustafsson * If the cache has a file name, write the cache contents to disk,
f951f076f3d321c52b824a866caff28ce4f8e06cAndreas Gustafsson * overwriting any preexisting file. If no file name has been set,
f951f076f3d321c52b824a866caff28ce4f8e06cAndreas Gustafsson * do nothing and return success.
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein *\li Multiple simultaneous attempts to load or dump the cache
f951f076f3d321c52b824a866caff28ce4f8e06cAndreas Gustafsson * will be serialized with respect to one another, but
f951f076f3d321c52b824a866caff28ce4f8e06cAndreas Gustafsson * the cache may be read and updated while the dump is
f951f076f3d321c52b824a866caff28ce4f8e06cAndreas Gustafsson * in progress. Updates performed during the dump may
f951f076f3d321c52b824a866caff28ce4f8e06cAndreas Gustafsson * or may not be reflected in the dumped file.
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein *\li #ISC_R_SUCCESS
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein * \li Various failures depending on the database implementation type
f951f076f3d321c52b824a866caff28ce4f8e06cAndreas Gustafssondns_cache_clean(dns_cache_t *cache, isc_stdtime_t now);
f951f076f3d321c52b824a866caff28ce4f8e06cAndreas Gustafsson * Force immediate cleaning of the cache, freeing all rdatasets
f951f076f3d321c52b824a866caff28ce4f8e06cAndreas Gustafsson * whose TTL has expired as of 'now' and that have no pending
8f79820c6930ee5ef6b4a54f36d2559400bdf47dAndreas Gustafssondns_cache_setcleaninginterval(dns_cache_t *cache, unsigned int interval);
8f79820c6930ee5ef6b4a54f36d2559400bdf47dAndreas Gustafsson * Set the periodic cache cleaning interval to 'interval' seconds.
7781f25078c491a9650dec555bdc86cb0ed49861Tatuya JINMEI 神明達哉dns_cache_getcleaninginterval(dns_cache_t *cache);
7781f25078c491a9650dec555bdc86cb0ed49861Tatuya JINMEI 神明達哉 * Get the periodic cache cleaning interval to 'interval' seconds.
7781f25078c491a9650dec555bdc86cb0ed49861Tatuya JINMEI 神明達哉 * Get the cache name.
2a184ff86544cc67c36e2ce6bb3ddb5ac44684b8Evan Huntdns_cache_setcachesize(dns_cache_t *cache, size_t size);
50a3152b7088546418c8edc0c89eeaf48560b035Andreas Gustafsson * Set the maximum cache size. 0 means unlimited.
7781f25078c491a9650dec555bdc86cb0ed49861Tatuya JINMEI 神明達哉dns_cache_getcachesize(dns_cache_t *cache);
7781f25078c491a9650dec555bdc86cb0ed49861Tatuya JINMEI 神明達哉 * Get the maximum cache size.
c20ffa38dee7efa0dc01822d4bac5e41729b9b61Brian Wellington * Flushes all data from the cache.
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein *\li #ISC_R_SUCCESS
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein *\li #ISC_R_NOMEMORY
01279934803dd45c007a58b61fe20c2852135b52Evan Huntdns_cache_flushnode(dns_cache_t *cache, dns_name_t *name,
01279934803dd45c007a58b61fe20c2852135b52Evan Hunt * Flush a given name from the cache. If 'tree' is true, then
01279934803dd45c007a58b61fe20c2852135b52Evan Hunt * also flush all names under 'name'.
01279934803dd45c007a58b61fe20c2852135b52Evan Hunt *\li 'cache' to be valid.
01279934803dd45c007a58b61fe20c2852135b52Evan Hunt *\li 'name' to be valid.
01279934803dd45c007a58b61fe20c2852135b52Evan Hunt *\li #ISC_R_SUCCESS
01279934803dd45c007a58b61fe20c2852135b52Evan Hunt *\li #ISC_R_NOMEMORY
01279934803dd45c007a58b61fe20c2852135b52Evan Hunt *\li other error returns.
6c8abf481df85a67c3f32f5f107b554d3ff5a3edMark Andrewsdns_cache_flushname(dns_cache_t *cache, dns_name_t *name);
01279934803dd45c007a58b61fe20c2852135b52Evan Hunt * Flush a given name from the cache. Equivalent to
01279934803dd45c007a58b61fe20c2852135b52Evan Hunt * dns_cache_flushpartial(cache, name, ISC_FALSE).
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein *\li 'cache' to be valid.
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein *\li 'name' to be valid.
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein *\li #ISC_R_SUCCESS
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein *\li #ISC_R_NOMEMORY
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein *\li other error returns.
dd2a0a6d2dec1c23787351e51b434a838dec5603Evan Hunt * Return a pointer to the stats collection object for 'cache'
dd2a0a6d2dec1c23787351e51b434a838dec5603Evan Hunt * Dump cache statistics and status in text to 'fp'
d640b4a0ab9dec252749793f78a1ed1e8551ea19Evan Huntdns_cache_updatestats(dns_cache_t *cache, isc_result_t result);
d640b4a0ab9dec252749793f78a1ed1e8551ea19Evan Hunt * Update cache statistics based on result code in 'result'
dd2a0a6d2dec1c23787351e51b434a838dec5603Evan Huntdns_cache_renderxml(dns_cache_t *cache, xmlTextWriterPtr writer);
dd2a0a6d2dec1c23787351e51b434a838dec5603Evan Hunt * Render cache statistics and status in XML for 'writer'.
dd2a0a6d2dec1c23787351e51b434a838dec5603Evan Hunt#endif /* HAVE_LIBXML2 */
feb067b25a8e33db62e2a7bf2e83bbb7f6eee845Evan Huntdns_cache_renderjson(dns_cache_t *cache, json_object *cstats);
feb067b25a8e33db62e2a7bf2e83bbb7f6eee845Evan Hunt * Render cache statistics and status in JSON
feb067b25a8e33db62e2a7bf2e83bbb7f6eee845Evan Hunt#endif /* HAVE_JSON */
4be63b1fd8c18dbeca1648d6cf22fa14f057a469David Lawrence#endif /* DNS_CACHE_H */