Skip to content

feat(mdns,homekit): IPv6 transport for HomeKit accessories - #2305

Open
TA2k wants to merge 2 commits into
AlexxIT:masterfrom
TA2k:feat/mdns-ipv6
Open

TA2k wants to merge 2 commits into
AlexxIT:masterfrom
TA2k:feat/mdns-ipv6

Conversation

@TA2k

@TA2k TA2k commented Jun 15, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Adds IPv6 mDNS serving alongside IPv4 for HomeKit accessories. If IPv4 mDNS cannot bind, the server can still advertise over IPv6. When neither family can start, the error includes both causes. Rebased onto current master, preserving its IPv4 interface selection and per-address bind diagnostics from #2304.

  • Track IPv6 interfaces independently of socket address zones, so global and unique-local addresses work. Join ff02::fb on each usable interface, set the multicast interface and hop limit, and use received packet information to select the response interface.
  • Return A and AAAA records for the same interface, including an A record when only the IPv6 mDNS socket could bind. Responses stay on the matching interface for both families.
  • Accept the QU question-class bit in both responders, following the relevant part of mdns: let a paired HomeKit controller find its accessory again #2607.
  • Advertise the correct HomeKit SRTP address family and initialize link-local remote zones before registering sessions, avoiding concurrent mutation of active UDP destinations.
  • Close failed/unused sockets and keep the existing AppendEntry signature. IPv6 socket options use the existing golang.org/x/net/ipv6 dependency; no dependency changes.

IPv6 browsing/client discovery is outside this change. On Windows, x/net/ipv6 does not expose incoming packet information, so the responder falls back to the source zone for link-local requests; global-source requests without a zone are not handled there.

Validation

  • go test -race ./pkg/mdns ./pkg/homekit ./pkg/srtp passes.
  • Regression coverage includes real IPv6 loopback packet-info reception, interface-specific IPv4/IPv6 replies, QU questions, A/AAAA wire encoding, IPv4 advertisement without an IPv4 mDNS listener, HomeKit TLV address families, and SRTP zone initialization before sending.
  • go vet ./pkg/mdns ./pkg/homekit ./pkg/srtp passes.
  • go build ./... passes on macOS/arm64 and cross-compiles for Linux/amd64, Windows/amd64 and FreeBSD/amd64.
  • Repository-wide go vet ./... reports the same existing findings on clean upstream master in pkg/bits, pkg/mqtt and pkg/webrtc.

Related work

@TA2k
TA2k changed the base branch from master to dev June 15, 2026 17:04
@TA2k

TA2k commented Jun 15, 2026

Copy link
Copy Markdown
Contributor Author

@skrashevich What is your opinion about that?

@skrashevich skrashevich self-assigned this Jun 29, 2026
@skrashevich

Copy link
Copy Markdown
Collaborator
  1. In most cases, daemons listen to [::]:5353, which binds them on both ipv4 and ipv6. Give a real repeatable example when the port is occupied on ipv4, but not occupied on ipv6

  2. PR needs to be rebased from dev to main anyway

@TA2k

TA2k commented Jun 29, 2026

Copy link
Copy Markdown
Contributor Author
  1. this is a very common use case if your host system is a NAS with mdns support for Timemachine this will occupy the ipv4 port if you now setup go2rtc in a docker you cannot use the mdns port and this means no HomeKit support
  2. done

@TA2k
TA2k changed the base branch from dev to master June 29, 2026 06:56
@skrashevich

skrashevich commented Jun 29, 2026 •

Copy link
Copy Markdown
Collaborator

this is a very common use case if your host system is a NAS with mdns support for Timemachine

Synology, for example?

@TA2k

TA2k commented Jun 29, 2026

Copy link
Copy Markdown
Contributor Author

Synology, Truenas, green nas

@TA2k

TA2k commented Sep 13, 2026

Copy link
Copy Markdown
Contributor Author

Did you think about this?

@AlexxIT AlexxIT self-assigned this Oct 1, 2026
@AlexxIT AlexxIT added kind/feature Proposes or implements a new capability or enhancement area/homekit HomeKit camera pairing, streaming, and accessory support labels Oct 1, 2026
@AlexxIT AlexxIT added the size/XL PR with 500-999 lines changed, excluding generated files. label Nov 26, 2026
@AlexxIT AlexxIT removed their assignment Nov 28, 2026
TA2k added 2 commits November 29, 2026 00:45
When another mDNS responder on the host already holds the IPv4 :5353
wildcard bind, go2rtc's HomeKit module exits with 'no interfaces for
listen' because the IPv4 path was the only one wired. This change adds
an IPv6 transport that runs alongside IPv4 best-effort, so HomeKit
keeps working in those setups.

Changes
- pkg/mdns: parallel IPv6 path. Per-interface udp6 senders, single
  [::]:5353 receiver with IPV6_JOIN_GROUP for ff02::fb. ListenMulticastUDP
  runs both families and returns errors.Join'd diagnostic only when
  neither came up; orphan sender FDs are closed when the matching
  receiver bind fails.
- pkg/mdns: AppendEntry kept with its original (msg, entry, service, ip)
  signature for external callers; new AppendEntryDual covers both A and
  AAAA so a query that arrived over IPv6 still gets a usable IPv4 record
  for clients that prefer v4 (this is what makes iOS HomeKit's HAP TCP
  connect succeed when only the v6 mDNS path is up).
- pkg/mdns: per-OS IPV6_MULTICAST_LOOP / IPV6_JOIN_GROUP constants
  (Linux 19/20, BSD/Windows 11/12). Loopback and link-local IPs are
  rejected when resolving an IP literal back to its interface; a small
  prefix list skips obvious docker/vpn interfaces in the v6 picker.
- pkg/homekit/consumer.go: SetupEndpoints response now sets the correct
  Address.IPVersion (HAP R15 §10.4.2) and uses the proper textual form
  for the v6 case; the legacy code's addr.IP.To4().String() returned
  '<nil>' on a v6 socket. When the controller signals an IPv6 link-local
  RTP endpoint, the local SRTP zone is copied so kernel writes succeed.
- pkg/srtp/session.go: Session.SetZone helper for the case above.

Compatibility
- IPv4 success path is unchanged.
- AppendEntry signature is unchanged (delegates to the new dual helper).
- New exported names: MulticastAddrV6, AppendEntryDual, Session.SetZone,
  three Browser fields (SendsV6/NetsV6/RecvV6) parallel to existing
  Sends/Nets/Recv.

Tested
- go build ./... and go test ./pkg/mdns/...
- linux/amd64 build deployed in a Frigate container running alongside
  another mDNS responder that holds the v4 wildcard bind: HomeKit
  pairing, snapshots and live stream all work over the LAN.
@TA2k

TA2k commented Nov 29, 2026

Copy link
Copy Markdown
Contributor Author

@AlexxIT merge conflicts resolved

@AlexxIT

AlexxIT commented Nov 29, 2026

Copy link
Copy Markdown
Owner

Thanks! There are a lot of changes. It's not a bug, but a very specific feature. Unfortunately, this review comes last.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/homekit HomeKit camera pairing, streaming, and accessory support kind/feature Proposes or implements a new capability or enhancement size/XL PR with 500-999 lines changed, excluding generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

homekit/mdns does not work on Docker-like IP-addresses

3 participants