mirror of
https://github.com/systemd/systemd-stable.git
synced 2025-01-11 05:17:44 +03:00
resolved: let's tweak how we calculate TTL left
When responding from DNS cache, let's slightly tweak how the TTL is lowered: as before let's round down when converting from our internal µs to the external seconds. (This is preferable, since records should better be cached too short instead of too long.) Let's avoid rounding down to zero though, since that has special semantics in many cases (in particular mDNS). Let's just use 1s in that case.
This commit is contained in:
parent
b974211acb
commit
a1acc6e332
@ -937,9 +937,18 @@ static int answer_add_clamp_ttl(
|
||||
assert(rr);
|
||||
|
||||
if (FLAGS_SET(query_flags, SD_RESOLVED_CLAMP_TTL)) {
|
||||
uint32_t left_ttl;
|
||||
|
||||
/* Let's determine how much time is left for this cache entry. Note that we round down, but
|
||||
* clamp this to be 1s at minimum, since we usually want records to remain cached better too
|
||||
* short a time than too long a time, but otoh don't want to return 0 ever, since that has
|
||||
* special semantics in various contexts — in particular in mDNS */
|
||||
|
||||
left_ttl = MAX(1U, LESS_BY(until, current) / USEC_PER_SEC);
|
||||
|
||||
patched = dns_resource_record_ref(rr);
|
||||
|
||||
r = dns_resource_record_clamp_ttl(&patched, LESS_BY(until, current) / USEC_PER_SEC);
|
||||
r = dns_resource_record_clamp_ttl(&patched, left_ttl);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
@ -947,7 +956,7 @@ static int answer_add_clamp_ttl(
|
||||
|
||||
if (rrsig) {
|
||||
patched_rrsig = dns_resource_record_ref(rrsig);
|
||||
r = dns_resource_record_clamp_ttl(&patched_rrsig, LESS_BY(until, current) / USEC_PER_SEC);
|
||||
r = dns_resource_record_clamp_ttl(&patched_rrsig, left_ttl);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user