diff options
author | Elliott Hughes <enh@google.com> | 2012-05-07 10:41:52 -0700 |
---|---|---|
committer | android code review <noreply-gerritcodereview@google.com> | 2012-05-07 10:41:53 -0700 |
commit | 73a6566da337db50cfc73c369d774ac1905a30c2 (patch) | |
tree | a6765151894bf750499092d5f535e95d87591c29 /libc/netbsd | |
parent | 8657eafc3552f36c176667c1591beab255308da6 (diff) | |
parent | dd16182b4b3f107d5c26015622c1cb8c06619ad7 (diff) | |
download | bionic-73a6566da337db50cfc73c369d774ac1905a30c2.zip bionic-73a6566da337db50cfc73c369d774ac1905a30c2.tar.gz bionic-73a6566da337db50cfc73c369d774ac1905a30c2.tar.bz2 |
Merge "Remove expired dns cache entries before removing oldest"
Diffstat (limited to 'libc/netbsd')
-rw-r--r-- | libc/netbsd/resolv/res_cache.c | 26 |
1 files changed, 25 insertions, 1 deletions
diff --git a/libc/netbsd/resolv/res_cache.c b/libc/netbsd/resolv/res_cache.c index e88c221..284ca2f 100644 --- a/libc/netbsd/resolv/res_cache.c +++ b/libc/netbsd/resolv/res_cache.c @@ -1412,6 +1412,27 @@ _cache_remove_oldest( Cache* cache ) _cache_remove_p(cache, lookup); } +/* Remove all expired entries from the hash table. + */ +static void _cache_remove_expired(Cache* cache) { + Entry* e; + time_t now = _time_now(); + + for (e = cache->mru_list.mru_next; e != &cache->mru_list;) { + // Entry is old, remove + if (now >= e->expires) { + Entry** lookup = _cache_lookup_p(cache, e); + if (*lookup == NULL) { /* should not happen */ + XLOG("%s: ENTRY NOT IN HTABLE ?", __FUNCTION__); + return; + } + e = e->mru_next; + _cache_remove_p(cache, lookup); + } else { + e = e->mru_next; + } + } +} ResolvCacheStatus _resolv_cache_lookup( struct resolv_cache* cache, @@ -1526,7 +1547,10 @@ _resolv_cache_add( struct resolv_cache* cache, } if (cache->num_entries >= cache->max_entries) { - _cache_remove_oldest(cache); + _cache_remove_expired(cache); + if (cache->num_entries >= cache->max_entries) { + _cache_remove_oldest(cache); + } /* need to lookup again */ lookup = _cache_lookup_p(cache, key); e = *lookup; |