Repository navigation
resolved: remove entry from cache when goodbye packet received - #22751
Conversation
| if (min_ttl <= 0) { | ||
| /* New TTL is 0? Delete this specific entry... | ||
| * In RFC6762 10.1 for Good Bye packet TTL is 1 */ | ||
| if (min_ttl <= 1) { |
There was a problem hiding this comment.
hmm, as I read the RFC we should instead when min_ttl is zero go through all our matching cached entries and set the stored TTL to 1s.
There was a problem hiding this comment.
The ttl of incoming goodbye packet records is already being set to 1 before "dns_cache_put_positive" is called (line 399, resolved-mdns.c).
However in dns_cache_put_positive() for cache deletion ttl is checked for 0 instead of 1.
Due to this, records with goodbye packets aren't getting removed from cache.
The RFC says to change the TTL of goodbye packet records to 1, then take a look at them again after a second and delete them if no updates were received.
The current implementation seems to be taking care of setting the TTL to 1, but it doesn't account for the deletion.
This PR takes care of deletion, but ideally according to the RFC we should be waiting for 1 second before doing so.
There was a problem hiding this comment.
How about the following? When min_ttl == 1, find matching existing positive cache entries and update its TTL and cache lifetime DnsCacheItem.until.
There was a problem hiding this comment.
It makes sense to update the ttl/until of existing matching cache entries to 1 second when we get a TTL==0.
However, there also needs to be some sort of callback after one second to check if the entry was updated in the meantime, and remove the entry if no update was received.
Without this, the entry lingers in the cache indefinitely until the cache is pruned the next time.
We stumbled into this behavior while implementing #22532, with the aim of notifying clients when a service expires.
de26d89 to
b732975
Compare
| /* See the section 10.1 of RFC6762 */ | ||
| rr->ttl = 1; | ||
|
|
||
| r = sd_event_add_time_relative( |
There was a problem hiding this comment.
It is not necessary to call dns_cache_prune() after 1 second. As dns_cache_prune() is always called before calling dns_cache_lookup() is called. That is, the cache entry should be removed when we search cached entry.
Now I am confused, why do you want to explicitly remove the cache entry from the cache??
What issue do you want to solve??
There was a problem hiding this comment.
dns_cache_lookup() is only called when a packet is sent, which happens indeterminately.
RFC 6762 section 10.1 does mention that the entry should be deleted form the cache 1 second later.
This helps in keeping the cache up-to-date.
Without this, the entry would linger in cache indefinitely until the next packet is sent.
It also helps to notify the client immediately when a service sends a goodbye packet and expires (#22532).
There was a problem hiding this comment.
"the entry should be deleted form the cache 1 second later" does not mean we really need to remove the entry after 1 sec. But it is enough to drop the entry when it is requested later than 1sec.
In #22532, please call dns_cache_prune() before dns_cache_lookup() in mdns_subscriber_lookup_cache().
There was a problem hiding this comment.
Since goodbye packets are unsolicited, and this logic is actually independent of the RFC6762 section 5.2 stuff implemented in #22532, I figured it would make sense to add here.
|
hmm, what i don't get: why have a timer to remove these entries from the cache at all? it should suffice to clean this up when we query the cache, and encounter an entry which is now run over. we generally only clean the cache when using it, but not independently by timer. so why should we do so here? patching the ttl to 1 should mean that if we then query the cache it the record will be used still within that 1s but once the 1s is hit it won't anymore, even if it still exists in the cache. what am i missing? |
|
@poettering thanks for the review. Working on addressing your feedback. |
Not really. Why would it be beneficial to clean up the cache immediately when the timeout runs out? sounds much better to just do so when we deal with the cache anyway. i.e. usually it makes sense to avoid wakeups for nothing, and instead do all work when we are awake anyway... |
I see your point about avoiding unnecessary wakeups, but in the context of browsing services, we would like to keep the client up to date. Since we notify them on addition of services, we also want to notify them when a service expires. |
|
ah, hmm, yeah in the contetx of browsing it indeed makes sense to pro-actively clean up the cache when TTL runs out. But please add a comment about that clarifying this. |
b732975 to
a6efbdc
Compare
|
An -rc1 tag has been created and a release is being prepared, so please note that PRs introducing new features and APIs will be held back until the new version has been released. |
|
@poettering Added a comment clarifying the need for this. |
| /* Look at the cache 1 second later and remove stale entries. | ||
| * This is particularly useful to keep service browsers updated on service removal, | ||
| * as there are no other reliable triggers to propogate that info. */ | ||
| r = sd_event_add_time_relative( |
There was a problem hiding this comment.
so this will create one event source for each incoming mdns packet with ttl set to 0. that is a chance for a DoS, as clients can make us allocate basically unbounded memory, if they send us a ton of these packets within 1s.
Thus the event source object should be stored somewhere (in the scope object?), and if it already exists no new event source should be allocated. morevoer, the handler should check if there are RRs in the cache that should be flushed within less than 1s, and if so should immediately requeue a new event source to cover for that.
That way there's only one event source enqueued at max.
| USEC_PER_SEC, | ||
| 0, | ||
| mdns_goodbye_callback, | ||
| scope); |
There was a problem hiding this comment.
this will result in memory corruption: let's say a scope goes away (because a network interface goes away), but the event source is still queued. it will be called pointing to a scope that doesn't exist anymore. Bad things will then happen.
if you embedd a pointer to the eent source in DnsScope object, then you can also delete the event source whenever the scope goes away.
a6efbdc to
46660eb
Compare
| * This is particularly useful to keep service browsers updated on service removal, | ||
| * as there are no other reliable triggers to propogate that info. */ | ||
| if (!scope->mdns_goodbye_event_source) { | ||
| r = sd_event_add_time_relative( |
There was a problem hiding this comment.
Still I cannot follow why we need to actively clear the outdated cache entries here...
There was a problem hiding this comment.
In the context of continuous browsing (#22532), it would be useful to actively clear the outdated cache entries and notify the browser client(s).
To accomplish that, we would eventually add a call to mdns_notify_browsers_unsolicited_updates()
from mdns_goodbye_callback().
|
-> #30096 ? |
RFC6762 10.1 says that queriers receiving a Multicast DNS response with a TTL of zero SHOULD record a TTL of 1 and then delete the record one second later. Added a timer event to trigger a callback to clean-up the cache one second after a goodbye packet is received. The callback also checks for any cache entries expiring within the next one second and schedules follow-up cleanup callbacks accordingly.
46660eb to
cba136f
Compare
ttl of an incoming mdns goodbye packet is updated to 1 as per RFC6762 10.1. However, in dns_cache_put_positive(), we check for min_ttl <= 0 to remove the record from cache.
As a result, the entries for which goodbye packets are received do not get removed from cache. changed the check to min_ttl <= 1 to account for goodbye packets.