Skip to content

Commit 5b3c47f

Browse files
committed
dns_cache: fix serve-expired-ttl option issue.
1 parent 9642dc4 commit 5b3c47f

File tree

3 files changed

+8
-9
lines changed

3 files changed

+8
-9
lines changed

src/dns_conf.c

+4
Original file line numberDiff line numberDiff line change
@@ -6462,6 +6462,10 @@ static void _dns_conf_group_post(void)
64626462
if ((group->dns_rr_ttl_max < group->dns_rr_ttl_min) && group->dns_rr_ttl_max > 0) {
64636463
group->dns_rr_ttl_max = group->dns_rr_ttl_min;
64646464
}
6465+
6466+
if (group->dns_serve_expired == 1 && group->dns_serve_expired_ttl == 0) {
6467+
group->dns_serve_expired_ttl = DNS_MAX_SERVE_EXPIRED_TIME;
6468+
}
64656469
}
64666470
}
64676471

src/dns_conf.h

+1
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ extern "C" {
6161
#define DNS_MAX_REPLY_IP_NUM 8
6262
#define DNS_MAX_QUERY_LIMIT 65535
6363
#define DNS_DEFAULT_CHECKPOINT_TIME (3600 * 24)
64+
#define DNS_MAX_SERVE_EXPIRED_TIME (3600 * 24 * 365)
6465
#define MAX_INTERFACE_LEN 16
6566

6667
#define SMARTDNS_CONF_FILE "/etc/smartdns/smartdns.conf"

src/dns_server.c

+3-9
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,6 @@
7777
#define SOCKET_PRIORITY (6)
7878
#define CACHE_AUTO_ENABLE_SIZE (1024 * 1024 * 128)
7979
#define EXPIRED_DOMAIN_PREFETCH_TIME (3600 * 8)
80-
#define DNS_MAX_SERVE_EXPIRED_UPDATE_TIME (3600 * 24 * 7)
8180
#define DNS_MAX_DOMAIN_REFETCH_NUM 64
8281
#define DNS_SERVER_NEIGHBOR_CACHE_MAX_NUM 8192
8382
#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
16331632
timeout = ttl - 3;
16341633
}
16351634
} else {
1636-
timeout = ttl + 3;
1635+
timeout = ttl;
16371636
if (is_serve_expired) {
16381637
timeout += request->conf->dns_serve_expired_ttl;
1639-
if (request->conf->dns_serve_expired_ttl == 0) {
1640-
timeout = DNS_MAX_SERVE_EXPIRED_UPDATE_TIME;
1641-
}
16421638
}
1639+
1640+
timeout += 3;
16431641
}
16441642

16451643
if (timeout <= 0) {
@@ -8342,10 +8340,6 @@ static dns_cache_tmout_action_t _dns_server_cache_expired(struct dns_cache *dns_
83428340
}
83438341
}
83448342

8345-
if (conf_group->dns_serve_expired == 1 && conf_group->dns_serve_expired_ttl == 0) {
8346-
return DNS_CACHE_TMOUT_ACTION_UPDATE;
8347-
}
8348-
83498343
return DNS_CACHE_TMOUT_ACTION_DEL;
83508344
}
83518345

0 commit comments

Comments
 (0)