Skip to content

[host] advertise mDNS under the system host name - #3488

Draft
LorbusChris wants to merge 1 commit into
openthread:mainfrom
LorbusChris:mdns-hostname
Draft

[host] advertise mDNS under the system host name#3488
LorbusChris wants to merge 1 commit into
openthread:mainfrom
LorbusChris:mdns-hostname

Conversation

@LorbusChris

Copy link
Copy Markdown

With the OpenThread-core mDNS publisher the border router announces itself as ot<extaddr>.local instead of the name its administrator gave it. Set the system host name via otMdnsSetLocalHostName() 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.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread src/host/rcp_host.cpp Outdated
@LorbusChris
LorbusChris force-pushed the mdns-hostname branch 2 times, most recently from 8211652 to 20c6412 Compare July 30, 2026 07:55
@LorbusChris

Copy link
Copy Markdown
Author

/gemini review

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread src/host/rcp_host.cpp Outdated
@LorbusChris

Copy link
Copy Markdown
Author

/gemini review

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread src/host/rcp_host.cpp Outdated
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
@LorbusChris

Copy link
Copy Markdown
Author

/gemini review

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread src/host/rcp_host.cpp
char hostname[256];

if (gethostname(hostname, sizeof(hostname)) == 0)
{

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

  1. 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.

  2. 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.

  3. 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.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@LorbusChris LorbusChris changed the title [host] advertise mDNS under the system host name Draft: [host] advertise mDNS under the system host name Jul 31, 2026
@LorbusChris LorbusChris changed the title Draft: [host] advertise mDNS under the system host name [host] advertise mDNS under the system host name Jul 31, 2026
@LorbusChris
LorbusChris marked this pull request as draft July 31, 2026 16:23
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.

2 participants