Skip to content

Commit 9642dc4

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

File tree

3 files changed

+13
-3
lines changed

3 files changed

+13
-3
lines changed

src/dns_cache.c

+3
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,9 @@ static void dns_cache_expired(struct tw_base *base, struct tw_timer_list *timer,
192192
switch (tmout_act) {
193193
case DNS_CACHE_TMOUT_ACTION_OK:
194194
break;
195+
case DNS_CACHE_TMOUT_ACTION_UPDATE:
196+
dns_timer_mod(&dns_cache->timer, dns_cache->info.timeout);
197+
return;
195198
case DNS_CACHE_TMOUT_ACTION_DEL:
196199
dns_cache_delete(dns_cache);
197200
return;

src/dns_cache.h

+1
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,7 @@ typedef enum DNS_CACHE_TMOUT_ACTION {
128128
DNS_CACHE_TMOUT_ACTION_OK = 0,
129129
DNS_CACHE_TMOUT_ACTION_DEL = 1,
130130
DNS_CACHE_TMOUT_ACTION_RETRY = 2,
131+
DNS_CACHE_TMOUT_ACTION_UPDATE = 3,
131132
} dns_cache_tmout_action_t;
132133

133134
typedef dns_cache_tmout_action_t (*dns_cache_callback)(struct dns_cache *dns_cache);

src/dns_server.c

+9-3
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@
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)
8081
#define DNS_MAX_DOMAIN_REFETCH_NUM 64
8182
#define DNS_SERVER_NEIGHBOR_CACHE_MAX_NUM 8192
8283
#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
16321633
timeout = ttl - 3;
16331634
}
16341635
} else {
1635-
timeout = ttl;
1636+
timeout = ttl + 3;
16361637
if (is_serve_expired) {
16371638
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+
}
16381642
}
1639-
1640-
timeout += 3;
16411643
}
16421644

16431645
if (timeout <= 0) {
@@ -8340,6 +8342,10 @@ static dns_cache_tmout_action_t _dns_server_cache_expired(struct dns_cache *dns_
83408342
}
83418343
}
83428344

8345+
if (conf_group->dns_serve_expired == 1 && conf_group->dns_serve_expired_ttl == 0) {
8346+
return DNS_CACHE_TMOUT_ACTION_UPDATE;
8347+
}
8348+
83438349
return DNS_CACHE_TMOUT_ACTION_DEL;
83448350
}
83458351

0 commit comments

Comments
 (0)