fix(mdns): pin IPv6 multicast interface index on multi-adapter hosts#6473
Open
ohrensessel wants to merge 1 commit into
Open
fix(mdns): pin IPv6 multicast interface index on multi-adapter hosts#6473ohrensessel wants to merge 1 commit into
ohrensessel wants to merge 1 commit into
Conversation
On hosts with multiple network adapters — common on Windows with Hyper-V, WSL, or VPN virtual interfaces — IPv6 mDNS discovery silently fails because both the multicast group join and the outbound multicast socket use interface index 0 (the OS-default), which may resolve to a virtual adapter rather than the physical LAN interface. The IPv4 path is unaffected because it passes the real interface address to join_multicast_v4. The IPv6 path has two separate issues: 1. join_multicast_v6 is called with index 0 instead of the index of the interface that owns the bound address. 2. The send socket is built from a plain UdpSocket without setting IPV6_MULTICAST_IF, so outbound multicast packets exit the wrong adapter regardless of which interface we joined on. Fix: resolve the interface index by matching the bound IPv6 address against the host interfaces via if-addrs, then use that index for both the multicast group join and IPV6_MULTICAST_IF on the send socket. Falls back to index 0 when the address cannot be matched, preserving the existing behaviour on single-interface hosts. Closes the two TODO comments left in the code for this exact issue.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Disclaimer
Yes, this is AI generated. I stumbled upon the problem with mDNS on Windows in a small project I was doing. Hope this is of any use.
Problem
On hosts with multiple network adapters — common on Windows with Hyper-V, WSL,
or VPN virtual interfaces — IPv6 mDNS discovery silently fails. Both the
multicast group join and the outbound multicast socket use interface index
0(the OS default), which may resolve to a virtual adapter rather than the
physical LAN interface. Linux tolerates this because it typically has fewer
adapters and a more predictable default, but Windows does not.
The IPv4 path is unaffected because it passes the real interface address to
join_multicast_v4. The IPv6 path has two separate issues that the existingTODO comments already acknowledge:
join_multicast_v6is called with index0instead of the index of theinterface that owns the bound address.
UdpSocketwithout settingIPV6_MULTICAST_IF, so outbound multicast packets exit the wrong adapterregardless of which interface was joined.
Fix
Resolve the interface index by matching the bound IPv6 address against the
host's network interfaces via
if-addrs, then use that index for both:join_multicast_v6)set_multicast_if_v6on the send socket,built via
socket2which is already a dependency)Falls back to index
0when the address cannot be matched, preserving theexisting behaviour on single-interface hosts.
This closes both TODO comments left in the code for this exact issue.
Testing
Verified on a Windows host with Hyper-V and WSL virtual adapters where IPv6
mDNS previously produced no discoveries. After the fix, peers on the same
physical LAN segment are discovered correctly.