Assign dns cache size without checking environment variable ANDROID_DNS_MODE
Since resolver functions have been moved from libc to libnetd_resolv, don't
need to determine if the caller is Netd via environment variable anymore.
Another reason is that if the caller sets dns server without setting
environment variable ANDROID_DNS_MODE with "local". The size of dns cache
will be set to 0. The zero size may cause unexpected hash table index in
_cache_lookup_p() because the index is counted by mod 0 (cache size).
Test: netd_{unit,integration}_test pass
resolv_integration_test pass
Change-Id: I3988909ce2df6c26bdfa02c993bb7a1a97dc7950
diff --git a/resolv/res_cache.cpp b/resolv/res_cache.cpp
index 8ae4be0..66c5c35 100644
--- a/resolv/res_cache.cpp
+++ b/resolv/res_cache.cpp
@@ -1292,25 +1292,12 @@
VLOG << "*** DNS CACHE FLUSHED ***";
}
-static int _res_cache_get_max_entries(void) {
- int cache_size = CONFIG_MAX_ENTRIES;
-
- const char* cache_mode = getenv("ANDROID_DNS_MODE");
- if (cache_mode == NULL || strcmp(cache_mode, "local") != 0) {
- // Don't use the cache in local mode. This is used by the proxy itself.
- cache_size = 0;
- }
-
- VLOG << "cache size: " << cache_size;
- return cache_size;
-}
-
static struct resolv_cache* _resolv_cache_create(void) {
struct resolv_cache* cache;
cache = (struct resolv_cache*) calloc(sizeof(*cache), 1);
if (cache) {
- cache->max_entries = _res_cache_get_max_entries();
+ cache->max_entries = CONFIG_MAX_ENTRIES;
cache->entries = (Entry*) calloc(sizeof(*cache->entries), cache->max_entries);
if (cache->entries) {
cache->mru_list.mru_prev = cache->mru_list.mru_next = &cache->mru_list;