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 28, 2024
1 parent 9642dc4 commit 5b3c47f
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 9 deletions.
4 changes: 4 additions & 0 deletions src/dns_conf.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
}

Expand Down
1 change: 1 addition & 0 deletions src/dns_conf.h
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
12 changes: 3 additions & 9 deletions src/dns_server.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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;
}

Expand Down

0 comments on commit 5b3c47f

Please sign in to comment.