From 5b3c47fa72921fd70b6c58e931a5aeb0861cc27b Mon Sep 17 00:00:00 2001 From: Nick Peng Date: Sun, 28 Apr 2024 22:32:50 +0800 Subject: [PATCH] dns_cache: fix serve-expired-ttl option issue. --- src/dns_conf.c | 4 ++++ src/dns_conf.h | 1 + src/dns_server.c | 12 +++--------- 3 files changed, 8 insertions(+), 9 deletions(-) diff --git a/src/dns_conf.c b/src/dns_conf.c index 9ff3e1afe2..0dce5035ff 100644 --- a/src/dns_conf.c +++ b/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; + } } } diff --git a/src/dns_conf.h b/src/dns_conf.h index 99cd095ab3..b875c7a003 100644 --- a/src/dns_conf.h +++ b/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" diff --git a/src/dns_server.c b/src/dns_server.c index d13c439dac..938a9f028a 100644 --- a/src/dns_server.c +++ b/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; }