feat: derive the DIAL discovery grace from the advertised max-age#54
Merged
Conversation
A Discovery listener's eviction grace was a fixed 60s; a device's advertisement actually states its validity in CACHE-CONTROL max-age, so honor it. ParseCacheControlMaxAge (ssdp_message) reads the first max-age directive of the first CACHE-CONTROL field -- bare integer only, like the MX parse. Whitespace around '=' is tolerated: HTTP's cache-directive grammar has none, but UDA's own header templates and examples write "max-age = 1800" and devices copy them. The proxy stores a per-endpoint grace: each advertisement re-states it (absent/unparseable -> the 30-minute UDA-recommended default), clamped to 2 hours since the value is attacker-controlled and pins a scarce proxy slot. Rest listeners keep their fixed activity-refreshed grace (they are minted from description responses, which carry no max-age); a promoted endpoint keeps its advertised validity. The rest-vs-discovery grace ordering inverts (300s vs the 30-minute default), so the role-grace eviction test swaps phases.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Derive the DIAL Discovery listener's eviction grace from the advertisement's
CACHE-CONTROL: max-ageinstead of a fixed 60s.ParseCacheControlMaxAge(ssdp_message): first CACHE-CONTROL field, first max-age directive among its comma-separated directives, both case-insensitive. The value must be a bare integer fittinguint32_t(trailing OWS tolerated), like the MX parse. Whitespace around=is accepted: HTTP's cache-directive grammar has none, but UDA's own header templates and examples writemax-age = 1800and devices copy them. Longer tokens sharing the prefix (max-agenda=...) are skipped; a malformed max-age invalidates the field.DialProxy: endpoints carry a per-endpointgrace. Every advertisement re-states it — absent/unparseable falls toDEFAULT_DISCOVERY_GRACE(30 min, the UDA-recommended minimum device validity), and the value is clamped toMAX_DISCOVERY_GRACE(2 h) since it is attacker-controlled and sets a proxy-slot eviction deadline. Rest listeners keep their fixed activity-refreshed 300s grace (minted from description responses, which carry no max-age); a Discovery endpoint promoted to Rest keeps its advertised validity.Tests
13 new: 9 parser (incl. OWS-around-
=, longer-token disambiguation, garbage/overflow → default), 3 proxy-level (advertised grace honored, oversized clamp, re-advertisement replaces the grace in both directions), 1 reflector integration (max-age flows through the LOCATION rewrite: the listener outlives the default validity).Each behavior was verified to fail its test when the corresponding production line is removed (clamp, reuse-refresh, plumbing, advertised-sets-grace), then restored.
Verification