Skip to content

Samba: Add service discovery using mDNS - #4742

Open
atx32 wants to merge 8 commits into
home-assistant:masterfrom
atx32:master
Open

Samba: Add service discovery using mDNS#4742
atx32 wants to merge 8 commits into
home-assistant:masterfrom
atx32:master

Conversation

@atx32

@atx32 atx32 commented Jul 22, 2026

Copy link
Copy Markdown
Contributor

Added the capability to register smb service in mDNS for service discovery. This uses the RegisterService call on the org.freedesktop.resolve1 service so the OS level mDNS announcer systemd-resolved is used.

  • Use existing network_discovery configuration option for control of this feature.
  • Add glib package which provides gdbus command needed.
  • Add host_dbus: true to config.yaml to allow D-Bus access.
  • In smbd run script, use gdbus command to register smb service on port 445 in mDNS.
  • In smbd finish script, use gdbus command to unregister smb service in mDNS.
  • Bump version to 12.11.0 and update documentation and changelog.

Summary by CodeRabbit

Summary by CodeRabbit

  • New Features

    • Added DNS-SD/mDNS service discovery alongside WS-Discovery for Samba on local networks.
    • Samba service entries are automatically unregistered from mDNS when stopping.
  • Documentation

    • Updated configuration guidance and English translations to describe both discovery methods.
  • Chores

    • Updated the release to version 12.11.0.
    • Improved runtime support for network discovery.

@coderabbitai

coderabbitai Bot commented Jul 22, 2026

Copy link
Copy Markdown
Contributor

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 6892bc25-86e1-4867-b26a-d68229fae314

📥 Commits

Reviewing files that changed from the base of the PR and between 9732fc4 and 2bb1b37.

📒 Files selected for processing (1)
  • samba/rootfs/etc/s6-overlay/s6-rc.d/smbd/finish
🚧 Files skipped from review as they are similar to previous changes (1)
  • samba/rootfs/etc/s6-overlay/s6-rc.d/smbd/finish

📝 Walkthrough

Walkthrough

Adds configurable SMB service discovery over mDNS/DNS-SD. The change updates configuration and documentation, adds the glib runtime dependency, registers the SMB service during startup, and unregisters it during shutdown.

Changes

Samba network discovery

Layer / File(s) Summary
Discovery configuration and runtime prerequisites
samba/config.yaml, samba/Dockerfile, samba/DOCS.md, samba/translations/en.yaml, samba/CHANGELOG.md
Updates the add-on to version 12.11.0, enables host D-Bus access, installs glib, and documents DNS-SD/mDNS under network_discovery.
SMB service registration lifecycle
samba/rootfs/etc/s6-overlay/s6-rc.d/smbd/run, samba/rootfs/etc/s6-overlay/s6-rc.d/smbd/finish
Uses network_discovery to register _smb._tcp on port 445 through org.freedesktop.resolve1 before starting smbd. During shutdown, it unregisters the hostname-derived service.

Estimated code review effort: 2 (Simple) | ~10 minutes

Sequence Diagram(s)

sequenceDiagram
  participant smbd_run as smbd run script
  participant gdbus
  participant resolve1 as org.freedesktop.resolve1
  participant smbd
  smbd_run->>gdbus: Register _smb._tcp on port 445
  gdbus->>resolve1: RegisterService
  smbd_run->>smbd: Start smbd
  smbd-->>smbd_run: Exit
  smbd_run->>gdbus: Unregister hostname-derived service
  gdbus->>resolve1: UnregisterService
Loading

Possibly related PRs

  • home-assistant/addons#4738: Extends the network_discovery option from WSDD-only control to mDNS/DNS-SD registration and cleanup.

Suggested labels: add-on: samba

Suggested reviewers: agners

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly describes the primary change: adding mDNS service discovery to Samba.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@samba/rootfs/etc/s6-overlay/s6-rc.d/smbd/finish`:
- Around line 17-25: Update the mDNS lifecycle across the startup registration
and the finish cleanup: persist the object path returned by RegisterService,
then have the finish script unregister that saved path whenever it exists,
regardless of the current mdns configuration. Remove the hostname-derived path
construction and preserve the existing UnregisterService call against the stored
handle.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: ef74c770-3b38-4f27-8d27-ab0ff383fd34

📥 Commits

Reviewing files that changed from the base of the PR and between 6b5084c and 6ae2b7b.

📒 Files selected for processing (7)
  • samba/CHANGELOG.md
  • samba/DOCS.md
  • samba/Dockerfile
  • samba/config.yaml
  • samba/rootfs/etc/s6-overlay/s6-rc.d/smbd/finish
  • samba/rootfs/etc/s6-overlay/s6-rc.d/smbd/run
  • samba/translations/en.yaml

Comment thread samba/rootfs/etc/s6-overlay/s6-rc.d/smbd/finish Outdated

@agners agners left a comment

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 for your PR! This goes into the right direction.

Comment thread samba/config.yaml
- amd64
hassio_api: true
host_network: true
host_dbus: true

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.

Doing this directly from the app works, but it doesn't seem a good approach. It exposes much more attack surface to the app then necessary.

Ideally we extend the app configuration schema to allow service announcements, and let Supervisor handle the interaction with the host OS. We can take the arguments of org.freedesktop.resolve1.Manager.RegisterService as inspiration for the config API. See also my comment in #4468 (comment).

@atx32 atx32 Jul 31, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I have to admit what you are proposing is beyond my current capabilities. I would argue that both the ssh and matter_server apps have host_dbus: true, so I'm not sure why samba should be treated differently. If you're still not in favor of using D-Bus, I'll have to defer to someone more skilled to implement your preference.

@home-assistant
home-assistant Bot marked this pull request as draft July 27, 2026 07:19
@home-assistant

Copy link
Copy Markdown

Please take a look at the requested changes, and use the Ready for review button when you are done, thanks 👍

Learn more about our pull request process.

@atx32

atx32 commented Jul 31, 2026

Copy link
Copy Markdown
Contributor Author

Other than the debate over host_dbus, this should be good to go now. I'm now using the network_discovery option to enable/disable this feature. Descriptions of the config option have been updated to refer to both DNS-SD/mDNS and WS-Discovery.

@atx32
atx32 marked this pull request as ready for review July 31, 2026 01:36
@home-assistant
home-assistant Bot requested a review from agners July 31, 2026 01:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants