|
@@ -268,7 +268,8 @@ static void _dns_cache_remove_by_domain(struct dns_cache_key *cache_key)
|
|
|
pthread_mutex_unlock(&dns_cache_head.lock);
|
|
|
}
|
|
|
|
|
|
-static int _dns_cache_insert(struct dns_cache_info *info, struct dns_cache_data *cache_data, struct list_head *head)
|
|
|
+static int _dns_cache_insert(struct dns_cache_info *info, struct dns_cache_data *cache_data, struct list_head *head,
|
|
|
+ int timeout)
|
|
|
{
|
|
|
uint32_t key = 0;
|
|
|
struct dns_cache *dns_cache = NULL;
|
|
@@ -297,7 +298,7 @@ static int _dns_cache_insert(struct dns_cache_info *info, struct dns_cache_data
|
|
|
dns_cache->cache_data = cache_data;
|
|
|
dns_cache->timer.function = dns_cache_expired;
|
|
|
dns_cache->timer.del_function = dns_cache_timer_release;
|
|
|
- dns_cache->timer.expires = info->timeout;
|
|
|
+ dns_cache->timer.expires = timeout;
|
|
|
dns_cache->timer.data = dns_cache;
|
|
|
pthread_mutex_lock(&dns_cache_head.lock);
|
|
|
hash_table_add(dns_cache_head.cache_hash, &dns_cache->node, key);
|
|
@@ -359,7 +360,7 @@ int dns_cache_insert(struct dns_cache_key *cache_key, int rcode, int ttl, int sp
|
|
|
time(&info.insert_time);
|
|
|
time(&info.replace_time);
|
|
|
|
|
|
- return _dns_cache_insert(&info, cache_data, &dns_cache_head.cache_list);
|
|
|
+ return _dns_cache_insert(&info, cache_data, &dns_cache_head.cache_list, timeout);
|
|
|
}
|
|
|
|
|
|
struct dns_cache *dns_cache_lookup(struct dns_cache_key *cache_key)
|
|
@@ -509,19 +510,17 @@ static int _dns_cache_read_to_cache(struct dns_cache_record *cache_record, struc
|
|
|
struct dns_cache_info *info = &cache_record->info;
|
|
|
|
|
|
time_t now = time(NULL);
|
|
|
- unsigned int seed_tmp = now;
|
|
|
int passed_time = now - info->replace_time;
|
|
|
int timeout = info->timeout - passed_time;
|
|
|
- if (timeout < DNS_CACHE_READ_TIMEOUT * 2) {
|
|
|
- timeout = DNS_CACHE_READ_TIMEOUT + (rand_r(&seed_tmp) % DNS_CACHE_READ_TIMEOUT);
|
|
|
+ if ((timeout > dns_conf_serve_expired_ttl + info->ttl) && dns_conf_serve_expired_ttl >= 0) {
|
|
|
+ timeout = dns_conf_serve_expired_ttl + info->ttl;
|
|
|
}
|
|
|
|
|
|
- if (timeout > dns_conf_serve_expired_ttl && dns_conf_serve_expired_ttl >= 0) {
|
|
|
- timeout = dns_conf_serve_expired_ttl;
|
|
|
+ if (timeout < DNS_CACHE_READ_TIMEOUT * 2) {
|
|
|
+ timeout = DNS_CACHE_READ_TIMEOUT + (rand() % DNS_CACHE_READ_TIMEOUT);
|
|
|
}
|
|
|
- info->timeout = timeout;
|
|
|
|
|
|
- if (_dns_cache_insert(&cache_record->info, cache_data, head) != 0) {
|
|
|
+ if (_dns_cache_insert(&cache_record->info, cache_data, head, timeout) != 0) {
|
|
|
tlog(TLOG_ERROR, "insert cache data failed.");
|
|
|
cache_data = NULL;
|
|
|
goto errout;
|