Resolve mDNS hostname and service name collisions
The patches in this MR add support for hostname and service name conflict resolution for Avahi mDNS advertising.
These problems were discovered while running the Bonjour Conformance Test (by Apple) on a system running Samba. The
system would fail on the II.5 SRV Probing/Announcement subtest where the test suite verifies that when SRV probes are
denied, the implementation chooses a different service name.
Currently, the test fails with the following output:
BCT fail logs
NOTICE 2026-02-12 09:31:28.191247+0100: ---------Now testing: NEW-BCT._smb._tcp.local.---------
DEBUG_1 2026-02-12 09:31:28.191271+0100: Expected packet received
NOTICE 2026-02-12 09:31:28.191290+0100: NEW-BCT._smb._tcp.local., RESET_DENY -> RESET_CONFLICT_WIN
NOTICE 2026-02-12 09:31:28.191322+0100: Send denies:
NEW-BCT._smb._tcp.local.
DEBUG_1 2026-02-12 09:31:28.247646+0100: Expected packet received
NOTICE 2026-02-12 09:31:28.247725+0100: NeW-BCt._sMB._TCp.Local., RESET_CONFLICT_WIN -> SEND_CONFLICT_WIN
NOTICE 2026-02-12 09:31:28.247739+0100: Send conflicts:
NeW-BCt._sMB._TCp.Local.
NOTICE 2026-02-12 09:31:58.253258+0100: recv_packet timed out
DEBUG_1 2026-02-12 09:31:58.253352+0100: No packet received, timing out
DEBUG_1 2026-02-12 09:31:58.253367+0100: Resending the previous packets
NOTICE 2026-02-12 09:31:58.253379+0100: Send conflicts:
NeW-BCt._sMB._TCp.Local.
NOTICE 2026-02-12 09:32:28.258894+0100: recv_packet timed out
DEBUG_1 2026-02-12 09:32:28.259010+0100: No packet received, timing out
DEBUG_1 2026-02-12 09:32:28.259025+0100: Resending the previous packets
NOTICE 2026-02-12 09:32:28.259038+0100: Send conflicts:
NeW-BCt._sMB._TCp.Local.
NOTICE 2026-02-12 09:33:34.465569+0100: recv_packet timed out
DEBUG_1 2026-02-12 09:33:34.465680+0100: No packet received, timing out
DEBUG_1 2026-02-12 09:33:34.465695+0100: Resending the previous packets
NOTICE 2026-02-12 09:33:34.465708+0100: Send conflicts:
NeW-BCt._sMB._TCp.Local.
NOTICE 2026-02-12 09:34:04.471270+0100: recv_packet timed out
DEBUG_1 2026-02-12 09:34:04.471387+0100: No packet received, timing out
DEBUG_1 2026-02-12 09:34:04.471402+0100: Resending the previous packets
NOTICE 2026-02-12 09:34:04.471415+0100: Send conflicts:
NeW-BCt._sMB._TCp.Local.
NOTICE 2026-02-12 09:34:34.477568+0100: recv_packet timed out
DEBUG_1 2026-02-12 09:34:34.477686+0100: No packet received, timing out
The output for a service that implements conflict resolution properly looks like this:
BCT pass logs
NOTICE 2026-02-12 09:31:13.171570+0100: ---------Now testing: New-BCT._http._tcp.local.---------
DEBUG_1 2026-02-12 09:31:13.171594+0100: Expected packet received
NOTICE 2026-02-12 09:31:13.171613+0100: New-BCT._http._tcp.local., RESET_DENY -> RESET_CONFLICT_WIN
NOTICE 2026-02-12 09:31:13.171645+0100: Send denies:
New-BCT._http._tcp.local.
DEBUG_1 2026-02-12 09:31:13.310958+0100: Expected packet received
NOTICE 2026-02-12 09:31:13.311129+0100: NEw-BCt._HttP._tcp.lOcAl., RESET_CONFLICT_WIN -> SEND_CONFLICT_WIN
NOTICE 2026-02-12 09:31:13.311163+0100: Send conflicts:
NEw-BCt._HttP._tcp.lOcAl.
DEBUG_1 2026-02-12 09:31:13.451283+0100: Expected packet received
NOTICE 2026-02-12 09:31:13.451379+0100: new-BcT #2._HtTp._tcP.lOcal., SEND_CONFLICT_WIN -> SEND_DENY
NOTICE 2026-02-12 09:31:13.451404+0100: Send conflicts:
new-BcT #2._HtTp._tcP.lOcal.
DEBUG_1 2026-02-12 09:31:14.451881+0100: Expected packet received
WARNING 2026-02-12 09:31:14.451951+0100: Device changes its SRV instance name once it encountered conflicts at the very first place
WARNING 2026-02-12 09:31:14.451967+0100: Please modify the implementation of conflict resolving according to RFC 6762, Section 8.2. and Section 9.
WARNING 2026-02-12 09:31:14.451980+0100: Now switching to the legacy test mode
NOTICE 2026-02-12 09:31:14.452028+0100: NEw-bct #3._httP._Tcp.local., SEND_DENY -> LEGACY_DENY
NOTICE 2026-02-12 09:31:14.452047+0100: Send conflicts:
NEw-bct #3._httP._Tcp.local.
DEBUG_1 2026-02-12 09:31:15.417432+0100: Expected packet received
NOTICE 2026-02-12 09:31:15.417548+0100: New-bCt #4._http._tcp.LOcaL., LEGACY_DENY -> LEGACY_DENY
NOTICE 2026-02-12 09:31:15.417574+0100: Send denies:
New-bCt #4._http._tcp.LOcaL.
DEBUG_1 2026-02-12 09:31:16.418817+0100: Expected packet received
NOTICE 2026-02-12 09:31:16.418923+0100: New-BcT #5._httP._Tcp.Local., LEGACY_DENY -> LEGACY_DENY
NOTICE 2026-02-12 09:31:16.418948+0100: Send conflicts:
New-BcT #5._httP._Tcp.Local.
DEBUG_1 2026-02-12 09:31:17.420117+0100: Expected packet received
NOTICE 2026-02-12 09:31:17.420218+0100: New-BCt #6._Http._tCp.lOCal., LEGACY_DENY -> LEGACY_DENY
NOTICE 2026-02-12 09:31:17.420243+0100: Send denies:
New-BCt #6._Http._tCp.lOCal.
DEBUG_1 2026-02-12 09:31:18.421773+0100: Expected packet received
This MR makes the Samba daemon compliant with the Bonjour Conformance Test.
Hostname
Hostname conflict resolution is generally handled by the Avahi daemon. However, smbd fails to handle
AVAHI_CLIENT_S_COLLISION and AVAHI_CLIENT_S_REGISTERING states. When the server moves to those states, it will
eventually go back to AVAHI_CLIENT_S_RUNNING, recreating the services.
This MR fixes a bug where the entry group pointer would be overwritten without first freeing the previous one.
Service name
Service name conflict resolution code is missing from smbd. When the entry group enters the
AVAHI_ENTRY_GROUP_COLLISION state, the implementation should select a different service name and re-advertise it. A
new service name can be generated with the help of avahi_alternative_service_name (default to adding #<number>).
This MR handles AVAHI_ENTRY_GROUP_COLLISION states as well as AVAHI_ERR_COLLISION errors to update the service name.
The Avahi documentation is not clear about many of these behaviors, however this example can be taken as a reference implementation.
I couldn't find any test for Avahi, so this MR adds none. Manual testing includes:
- Verifying mDNS service is published
- Running the Bonjour Conformance Test successfully
- Restarting the Avahi daemon to verify re-connection
Sorry if this MR is too big for a first contribution, but I couldn't think of a way to reduce and keep it meaningful. Open to suggestions.
Checklist
-
Commits have
Signed-off-by:with name/author being identical to the Z commit author - (optional) This MR is just one part towards a larger feature.
-
(optional, if backport required) Bugzilla bug filed and
BUG:tag added - Test suite updated with functionality tests
- Test suite updated with negative tests
- Documentation updated
- CI timeout is 3h or higher ( see Settings/CICD/General pipelines/ Timeout)
Reviewer's checklist:
- There is a test suite reasonably covering new functionality or modifications
-
Function naming, parameters, return values, types, etc., are consistent
and according to
README.Coding.md - This feature/change has adequate documentation added
- No obvious mistakes in the code