Prechádzať zdrojové kódy

dns_cache: fix serve-expired-ttl option issue.

Nick Peng 1 rok pred
rodič
commit
9642dc41bb
3 zmenil súbory, kde vykonal 13 pridanie a 3 odobranie
  1. 3 0
      src/dns_cache.c
  2. 1 0
      src/dns_cache.h
  3. 9 3
      src/dns_server.c

+ 3 - 0
src/dns_cache.c

@@ -192,6 +192,9 @@ static void dns_cache_expired(struct tw_base *base, struct tw_timer_list *timer,
 		switch (tmout_act) {
 		case DNS_CACHE_TMOUT_ACTION_OK:
 			break;
+		case DNS_CACHE_TMOUT_ACTION_UPDATE:
+			dns_timer_mod(&dns_cache->timer, dns_cache->info.timeout);
+			return;
 		case DNS_CACHE_TMOUT_ACTION_DEL:
 			dns_cache_delete(dns_cache);
 			return;

+ 1 - 0
src/dns_cache.h

@@ -128,6 +128,7 @@ typedef enum DNS_CACHE_TMOUT_ACTION {
 	DNS_CACHE_TMOUT_ACTION_OK = 0,
 	DNS_CACHE_TMOUT_ACTION_DEL = 1,
 	DNS_CACHE_TMOUT_ACTION_RETRY = 2,
+	DNS_CACHE_TMOUT_ACTION_UPDATE = 3,
 } dns_cache_tmout_action_t;
 
 typedef dns_cache_tmout_action_t (*dns_cache_callback)(struct dns_cache *dns_cache);

+ 9 - 3
src/dns_server.c

@@ -77,6 +77,7 @@
 #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)
@@ -1632,12 +1633,13 @@ static int _dns_server_get_cache_timeout(struct dns_request *request, struct dns
 			timeout = ttl - 3;
 		}
 	} else {
-		timeout = ttl;
+		timeout = ttl + 3;
 		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) {
@@ -8340,6 +8342,10 @@ 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;
 }