Home | History | Annotate | Download | only in resolv

Lines Matching defs:Cache

48 /* This code implements a small and *simple* DNS resolver cache.
50 * It is only used to cache DNS answers for a time defined by the smallest TTL
52 * to be a full DNS cache, since we plan to implement that in the future in a
64 * to keep an answer in the cache.
67 * (and should be solved by the later full DNS cache process).
73 * that a full DNS cache is expected to do.
77 * - the client calls _resolv_cache_get() to obtain a handle to the cache.
78 * this will initialize the cache on first usage. the result can be NULL
79 * if the cache is disabled.
88 * answer to the cache.
96 * - when network settings change, the cache must be flushed since the list
106 * that the cache is only flushed once per network change.
110 * this code is called if its value is "0", then the resolver cache is
119 /* default number of entries kept in the cache. This value has been
147 * * 2) we've made this a system-wide cache, so the cost is less (it's not
155 /* name of the system property that can be used to set the cache size */
166 /* set to 1 to debug cache operations */
417 * TTL : 32 : seconds to cache this RR (0=none)
598 * type of query we can cache, or 0 otherwise
999 /* cache entry. for simplicity, 'hash' and 'hlink' are inlined in this
1073 * keep the answer in the cache.
1092 // a response with no answers? Cache this negative result.
1172 /* allocate a new entry as a cache node */
1243 } Cache;
1248 Cache* cache;
1265 _cache_flush_pending_requests_locked( struct resolv_cache* cache )
1268 if (cache) {
1269 ri = cache->pending_requests.next;
1280 cache->pending_requests.next = NULL;
1288 _cache_check_pending_request_locked( struct resolv_cache* cache, Entry* key )
1293 if (cache && key) {
1294 ri = cache->pending_requests.next;
1295 prev = &cache->pending_requests;
1316 pthread_cond_timedwait(&ri->cond, &cache->lock, &ts);
1324 * matching the key has been added to the cache */
1326 _cache_notify_waiting_tid_locked( struct resolv_cache* cache, Entry* key )
1330 if (cache && key) {
1331 ri = cache->pending_requests.next;
1332 prev = &cache->pending_requests;
1351 /* notify the cache that the query failed */
1353 _resolv_cache_query_failed( struct resolv_cache* cache,
1359 if (cache && entry_init_key(key, query, querylen)) {
1360 pthread_mutex_lock(&cache->lock);
1361 _cache_notify_waiting_tid_locked(cache, key);
1362 pthread_mutex_unlock(&cache->lock);
1367 _cache_flush_locked( Cache* cache )
1371 for (nn = 0; nn < cache->max_entries; nn++)
1373 Entry** pnode = (Entry**) &cache->entries[nn];
1383 _cache_flush_pending_requests_locked(cache);
1385 cache->mru_list.mru_next = cache->mru_list.mru_prev = &cache->mru_list;
1386 cache->num_entries = 0;
1387 cache->last_id = 0;
1390 "*** DNS CACHE FLUSHED ***\n"
1394 /* Return max number of entries allowed in the cache,
1395 * i.e. cache size. The cache size is either defined
1408 // Don't use the cache in local mode. This is used by the
1410 XLOG("setup cache for non-cache process. size=0, %s", cache_mode);
1423 XLOG("cache size: %d", result);
1430 struct resolv_cache* cache;
1432 cache = calloc(sizeof(*cache), 1);
1433 if (cache) {
1434 cache->max_entries = _res_cache_get_max_entries();
1435 cache->entries = calloc(sizeof(*cache->entries), cache->max_entries);
1436 if (cache->entries) {
1437 cache->generation = ~0U;
1438 pthread_mutex_init( &cache->lock, NULL );
1439 cache->mru_list.mru_prev = cache->mru_list.mru_next = &cache->mru_list;
1440 XLOG("%s: cache created\n", __FUNCTION__);
1442 free(cache);
1443 cache = NULL;
1446 return cache;
1463 _cache_dump_mru( Cache* cache )
1468 p = _bprint(temp, end, "MRU LIST (%2d): ", cache->num_entries);
1469 for (e = cache->mru_list.mru_next; e != &cache->mru_list; e = e->mru_next)
1533 _cache_lookup_p( Cache* cache,
1536 int index = key->hash % cache->max_entries;
1537 Entry** pnode = (Entry**) &cache->entries[ index ];
1559 _cache_add_p( Cache* cache,
1564 e->id = ++cache->last_id;
1565 entry_mru_add(e, &cache->mru_list);
1566 cache->num_entries += 1;
1569 e->id, cache->num_entries);
1577 _cache_remove_p( Cache* cache,
1583 e->id, cache->num_entries-1);
1588 cache->num_entries -= 1;
1594 _cache_remove_oldest( Cache* cache )
1596 Entry* oldest = cache->mru_list.mru_prev;
1597 Entry** lookup = _cache_lookup_p(cache, oldest);
1604 XLOG("Cache full - removing oldest");
1607 _cache_remove_p(cache, lookup);
1612 static void _cache_remove_expired(Cache* cache) {
1616 for (e = cache->mru_list.mru_next; e != &cache->mru_list;) {
1619 Entry** lookup = _cache_lookup_p(cache, e);
1625 _cache_remove_p(cache, lookup);
1633 _resolv_cache_lookup( struct resolv_cache* cache,
1650 /* we don't cache malformed queries */
1655 /* lookup cache */
1656 pthread_mutex_lock( &cache->lock );
1661 lookup = _cache_lookup_p(cache, key);
1665 XLOG( "NOT IN CACHE");
1668 if (!_cache_check_pending_request_locked(cache, key)) {
1671 lookup = _cache_lookup_p(cache, key);
1683 XLOG( " NOT IN CACHE (STALE ENTRY %p DISCARDED)", *lookup );
1685 _cache_remove_p(cache, lookup);
1700 if (e != cache->mru_list.mru_next) {
1702 entry_mru_add( e, &cache->mru_list );
1705 XLOG( "FOUND IN CACHE entry=%p", e );
1709 pthread_mutex_unlock( &cache->lock );
1715 _resolv_cache_add( struct resolv_cache* cache,
1733 pthread_mutex_lock( &cache->lock );
1743 lookup = _cache_lookup_p(cache, key);
1747 XLOG("%s: ALREADY IN CACHE
1752 if (cache->num_entries >= cache->max_entries) {
1753 _cache_remove_expired(cache);
1754 if (cache->num_entries >= cache->max_entries) {
1755 _cache_remove_oldest(cache);
1758 lookup = _cache_lookup_p(cache, key);
1761 XLOG("%s: ALREADY IN CACHE (%p) ? IGNORING ADD",
1772 _cache_add_p(cache, lookup, e);
1776 _cache_dump_mru(cache);
1779 _cache_notify_waiting_tid_locked(cache, key);
1780 pthread_mutex_unlock( &cache->lock );
1810 /* find the first cache that has an associated interface and return the name of the interface */
1817 /* gets cache associated with an interface name, or NULL if none exists */
1821 /* look up the named cache, and creates one if needed */
1823 /* empty the named cache */
1825 /* empty the nameservers set for the named cache */
1848 /* the cache is disabled */
1862 struct resolv_cache *cache;
1880 cache = _get_res_cache_for_iface_locked(iface);
1883 XLOG("_get_res_cache: iface = %s, cache=%p\n", iface, cache);
1884 return cache;
1893 struct resolv_cache* cache = _find_named_cache_locked(ifname);
1894 if (!cache) {
1897 cache = _resolv_cache_create();
1898 if (cache) {
1900 cache_info->cache = cache;
1910 return cache;
1922 // if default interface not set then use the first cache
1925 // method will be deleted/obsolete when cache per interface
1938 struct resolv_cache* cache = _get_res_cache_for_iface_locked(ifname);
1940 if (cache != NULL) {
1941 pthread_mutex_lock( &cache->lock );
1942 if (cache->generation != generation) {
1943 _cache_flush_locked(cache);
1944 cache->generation = generation;
1946 pthread_mutex_unlock( &cache->lock );
1980 struct resolv_cache* cache = _find_named_cache_locked(ifname);
1981 if (cache) {
1982 pthread_mutex_lock(&cache->lock);
1983 _cache_flush_locked(cache);
1984 pthread_mutex_unlock(&cache->lock);
2013 if (info != NULL) return info->cache;
2091 // creates the cache if not created
2142 // flush cache since new settings
2429 // if default interface not set. Get first cache with an interface
2497 // now do search domains. Note that we cache the offsets as this code runs alot