Skip to content

Commit

Permalink
dns_cache: fix serve-expired-ttl option issue.
Browse files Browse the repository at this point in the history
  • Loading branch information
pymumu committed Apr 26, 2024
1 parent 484251c commit 9642dc4
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 3 deletions.
3 changes: 3 additions & 0 deletions src/dns_cache.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions src/dns_cache.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
12 changes: 9 additions & 3 deletions src/dns_server.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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;
}

Expand Down

0 comments on commit 9642dc4

Please sign in to comment.