[host] advertise mDNS under the system host name - #3488
Conversation
There was a problem hiding this comment.
Code Review
This pull request updates src/host/rcp_host.cpp to configure the mDNS local host name using the system's hostname instead of the default "ot" during initialization. Feedback suggests increasing the hostname buffer size from 64 to 256 bytes to prevent gethostname from failing on longer hostnames, and truncating the first label to 63 characters to comply with mDNS label limits.
8211652 to
20c6412
Compare
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request updates src/host/rcp_host.cpp to configure the local mDNS hostname using the system's hostname when OTBR_ENABLE_MDNS_OPENTHREAD is enabled. The feedback suggests guarding the inclusion of <openthread/mdns.h> with #if OTBR_ENABLE_MDNS_OPENTHREAD to avoid compilation errors on older or custom OpenThread builds that lack mDNS support.
20c6412 to
5ce6bcc
Compare
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request updates 'RcpHost::Init' to retrieve the system's hostname using 'gethostname' and set it as the local mDNS hostname when 'OTBR_ENABLE_MDNS_OPENTHREAD' is enabled. The review feedback points out that truncating the hostname strictly at 63 bytes could cut a multi-byte UTF-8 character in half, leading to an invalid UTF-8 string, and suggests a code block to safely truncate UTF-8 strings.
With the OpenThread-core mDNS publisher the border router announces itself as "ot<extaddr>.local", a name nobody recognises: a Turris router shows up in Thread network listings as gibberish instead of the name its administrator gave the device. OpenThread provides otMdnsSetLocalHostName(), but it only works while the mDNS module is disabled, and the module follows the infra link state, so set the system host name right after instance initialisation. Best effort: on any failure the default stays. This covers RCP mode only. Under NCP the name is generated by the same core code on the co-processor and reaches the host readymade through the dnssd platform, so overriding it needs spinel support first. Assisted-By: Claude Opus 5
5ce6bcc to
8e8f15f
Compare
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request updates src/host/rcp_host.cpp to configure the mDNS local host name using the system's actual host name instead of the default 'ot'. It retrieves the host name via gethostname, sanitizes it to a single label of at most 63 octets (respecting UTF-8 boundaries), and applies it to the mDNS module, temporarily disabling and re-enabling the module if necessary. There are no review comments, and I have no feedback to provide.
There was a problem hiding this comment.
Code Review
This pull request updates src/host/rcp_host.cpp to configure the mDNS local host name using the system's actual hostname instead of the default 'ot'. It retrieves the hostname, truncates it to the first label, limits it to 63 octets while respecting UTF-8 boundaries, and applies it to the mDNS module, handling temporary disabling/re-enabling if necessary. There are no review comments, and I have no feedback to provide.
| char hostname[256]; | ||
|
|
||
| if (gethostname(hostname, sizeof(hostname)) == 0) | ||
| { |
There was a problem hiding this comment.
Thank you for this PR.
While I understand the goal, I don’t think the current approach is sufficient, and I would generally advise against it.
Key Considerations
-
Uniqueness and Conflict Resolution
Any host name announced over mDNS must be unique among all devices on the local network. If a name collision occurs, mDNS requires the host name to be changed or registration withdrawn. -
How OpenThread Native mDNS Handles ConflictsOpenThread’s native mDNS module does not automatically rename entities on collision. Instead, it fires callback notifications delegating conflict handling back to the caller (in this case, the platform layer).
Note on Border Router Context: The primary role of native mDNS on a Border Router is serving as an Advertising Proxy for SRP services registered by Thread devices. For SRP services, the Border Router cannot unilaterally change names on conflict because it does not own them—instead, it must report/reject the conflict back to the SRP client. -
Incompleteness of the Proposed Approach: Calling
otMdnsSetLocalHostName()at startup without registering a conflict callback leaves the system in a fragile state. If the administrator-assigned name collides with another device on the link, the local host name announcement will fail or conflict silently without recovery.
If you want to support administrator-defined host names, here are some options:
- Option A: Handle Conflicts in Platform / App Layer
Implement the conflict callback in the platform code. Upon receiving a conflict notification for the local host name, the platform logic generates an alternative unique name (may require to stop/start mDNS). - Option B: Native Auto-Renaming in OT Core (Conditional)
Extend OT native mDNS to support optional auto-renaming specifically for local host names (while strictly keeping it disabled for SRP-delegated records). This adds complexity to the core mDNS module. - Option C: Append a Unique Identifier (Simplest)
If the goal is simply to make the device recognizable while guaranteeing uniqueness, can append a unique hardware identifier to the administrator name (e.g.,<custom-name>-<extaddr>), avoiding collision resolution logic altogether.
Both Option A and Option B require developing new conflict-handling behavior and are non-trivial tasks with many edge cases to consider.
There was a problem hiding this comment.
Thanks for taking the time to review this! I'd rather not take any shortcuts and would instead try to implement this in the "most correct, RFC-adhering" way. Option C sounds relatively straightforward to do, but I'd be happy to investigate A or B too if there's a preference for either. Please advise.
There was a problem hiding this comment.
Thanks! I would personally lean toward Option B. While it’s likely the most complex one to implement, it provides a unified solution in the OpenThread core that benefits all platforms, not just POSIX.
There was a problem hiding this comment.
I'll take a look but it might be a few days until I get around to it. Converting to draft for the time being.
With the OpenThread-core mDNS publisher the border router announces itself as
ot<extaddr>.localinstead of the name its administrator gave it. Set the system host name viaotMdnsSetLocalHostName()right after instance initialisation (the only window where it works, since the mDNS module follows the infra link state). Best effort: on any failure the default stays.RCP mode only: under NCP the name is generated by the same core code on the co-processor and reaches the host readymade through the dnssd platform, so overriding it there needs spinel support first.