Skip to content

edge-mdns: Fix #113: Optimize response when responding for multiple services - #114

Open
jboynes wants to merge 4 commits into
sysgrok:masterfrom
aeolionics-contrib:many_services
Open

jboynes wants to merge 4 commits into
sysgrok:masterfrom
aeolionics-contrib:many_services

Conversation

@jboynes

@jboynes jboynes commented Nov 21, 2026

Copy link
Copy Markdown

Fixes #113 by optimizing the content in the response and potentially spliiting into multiple messages:

  • compress text
  • de-duplicate response records
  • only include additional records strictly related to the answer
  • split the response into multiple parts.

The original issue was discovered on a embedded application on embassy-net and reproduced on host. Fix has been tested with Apple's mDNSResponder but any client should work. Server tested on host and on our embedded application.

Claude helped analyze the issue and co-authored this PR with me.

jboynes and others added 4 commits November 21, 2026 13:55
HostAnswersMdnsHandler and HostQuestions::query wrote every name in
full. They now build into domain's StaticCompressor, so a name repeats
as a pointer to where it was first written (RFC 1035, section 4.1.4),
which mDNS allows anywhere in a message (RFC 6762, section 18.14).

With a host, an HTTP service and a subtype, the announcement writes
`local` twice rather than 15 times (once more for the SRV target, which
domain doesn't compress). An announcement of ten DNS-SD services on one
host goes from 4,095 bytes to 2,009.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The answers a HostAnswersMdnsHandler is given often visit the same
record more than once: a ServiceAnswers gives its host's A and AAAA
records, so a host with several services gives them once for itself
and once for each service, and services of one type each give the same
DNS-SD enumeration record. Two questions about one name also got the
same answers twice. Each copy went into the message.

Now a record goes in only if the message doesn't have it already, in
its answer or additional section: the same owner, type, class and data,
whatever the TTL. That also keeps a record that answers a question out
of the additional section. domain's record data compares across octet
and name types, and our own Txt compares with a TXT record as read back
(eq_data), so nothing is written out to compare.

An announcement of ten DNS-SD services on one host goes from 2,009
bytes to 1,457.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
HostAnswersMdnsHandler decided whether to fill in the additional
section from every record the answers visited, not from those that
answered the question: a host with any service had an SRV and a PTR
record among them, so a reply to any query got every A, AAAA, SRV and
TXT record it had, whether browsing one service type, resolving one
instance, asking for the host's address, or enumerating the types.

Now a reply's additional records are those related to its answers, as
RFC 6763 (section 12) has it: the SRV and TXT records of the service
instances that PTR answers name (not for the service type
enumeration), and the A and AAAA records of the hosts that SRV records
in the message name. Two rounds find them: the second adds the
addresses for the SRV records that the first added.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
HostAnswersMdnsHandler built an announcement or a reply as one message,
so a host with more services than fit in the buffer got ShortBuf, and
the error ended Mdns::run. With a 1,500-byte buffer, ten DNS-SD
services on one host were already too many.

Now a message takes the answers that fit, and the rest go in further
messages. A message that leaves answers out comes back as the new
MdnsResponse::Partial, with the Continuation where the next part
starts, and the new MdnsHandler::handle_part prepares the part at a
Continuation. For HostAnswersMdnsHandler that is a position in the
order its answers visit their records; to a caller it is opaque: ask
for Continuation::FIRST, then pass back each next. handle_part defaults
to handle's one message, so other handlers keep working as they were.
ChainedHandler and &mut T pass it on, and Mdns sends every part of an
announcement or a reply.

Each part's additional records are those related to its own answers,
and those that don't fit are left out, as additional records are
optional. A reply to a legacy query is still one message, so its
answers must fit in one; an answer that doesn't fit in a message alone
is still ShortBuf.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@jboynes jboynes changed the title edge-mdns: Fix #113: Optimize response when respondind for multiple services edge-mdns: Fix #113: Optimize response when responding for multiple services Nov 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

edge-mdns: Cannot advertise many services due to response exceeding buffer.

1 participant