Browse Source

dns_cache: fix serve-expired-ttl option issue.

Nick Peng 1 year ago
parent
commit
5b3c47fa72
3 changed files with 8 additions and 9 deletions
  1. 4 0
      src/dns_conf.c
  2. 1 0
      src/dns_conf.h
  3. 3 9
      src/dns_server.c

+ 4 - 0
src/dns_conf.c

@@ -6462,6 +6462,10 @@ static void _dns_conf_group_post(void)
 		if ((group->dns_rr_ttl_max < group->dns_rr_ttl_min) && group->dns_rr_ttl_max > 0) {
 			group->dns_rr_ttl_max = group->dns_rr_ttl_min;
 		}
+
+		if (group->dns_serve_expired == 1 && group->dns_serve_expired_ttl == 0) {
+			group->dns_serve_expired_ttl = DNS_MAX_SERVE_EXPIRED_TIME;
+		}
 	}
 }
 

+ 1 - 0
src/dns_conf.h

@@ -61,6 +61,7 @@ extern "C" {
 #define DNS_MAX_REPLY_IP_NUM 8
 #define DNS_MAX_QUERY_LIMIT 65535
 #define DNS_DEFAULT_CHECKPOINT_TIME (3600 * 24)
+#define DNS_MAX_SERVE_EXPIRED_TIME (3600 * 24 * 365)
 #define MAX_INTERFACE_LEN 16
 
 #define SMARTDNS_CONF_FILE "/etc/smartdns/smartdns.conf"

+ 3 - 9
src/dns_server.c

@@ -77,7 +77,6 @@
 #define SOCKET_PRIORITY (6)
 #define CACHE_AUTO_ENABLE_SIZE (1024 * 1024 * 128)
 #define EXPIRED_DOMAIN_PREFETCH_TIME (3600 * 8)
-#define DNS_MAX_SERVE_EXPIRED_UPDATE_TIME (3600 * 24 * 7)
 #define DNS_MAX_DOMAIN_REFETCH_NUM 64
 #define DNS_SERVER_NEIGHBOR_CACHE_MAX_NUM 8192
 #define DNS_SERVER_NEIGHBOR_CACHE_TIMEOUT (3600 * 1)
@@ -1633,13 +1632,12 @@ static int _dns_server_get_cache_timeout(struct dns_request *request, struct dns
 			timeout = ttl - 3;
 		}
 	} else {
-		timeout = ttl + 3;
+		timeout = ttl;
 		if (is_serve_expired) {
 			timeout += request->conf->dns_serve_expired_ttl;
-			if (request->conf->dns_serve_expired_ttl == 0) {
-				timeout = DNS_MAX_SERVE_EXPIRED_UPDATE_TIME;
-			}
 		}
+
+		timeout += 3;
 	}
 
 	if (timeout <= 0) {
@@ -8342,10 +8340,6 @@ static dns_cache_tmout_action_t _dns_server_cache_expired(struct dns_cache *dns_
 		}
 	}
 
-	if (conf_group->dns_serve_expired == 1 && conf_group->dns_serve_expired_ttl == 0) {
-		return DNS_CACHE_TMOUT_ACTION_UPDATE;
-	}
-
 	return DNS_CACHE_TMOUT_ACTION_DEL;
 }