qmdnsengine icon indicating copy to clipboard operation
qmdnsengine copied to clipboard

Send multicast packets on all multicast-capable interfaces

Open cgutman opened this issue 6 years ago • 5 comments

On multi-homed hosts, the interface that will be used for outgoing multicast traffic is implementation-defined. As a result, the mDNS queries don't always go out on the interfaces where the discoverable hosts are.

We want to ensure that Server::sendMessageToAll() sends queries to all multicast-capable interfaces, so we should use QUdpSocket::setMulticastInterface() to do that.

cgutman avatar Aug 01 '19 04:08 cgutman

It would be great to have this feature in anytime soon

yuriy-mochurad avatar Aug 18 '20 12:08 yuriy-mochurad

I've just tried this but it isn't quite enough as Server::sendMessage() can be called to send to a multicast address (e.g. in HostnamePrivate::onMessageReceived()). My hack was to call sendMessageToAll() if message.address().isMulticast()... this was introduced in Qt 5.6 but is generic and less error-prone than checking for the MdnsIpv?Address matches. It is possible that the real bug is with Hostname calling sendMessage() rather than sendMessageToAll.

The other related change I made was to replicate the protocol check that sendMessage() does, so that the ipv4Socket is only used to send to IpV4 addresses.

If I was braver / it was my baby, I would consider having just the sendMessage() function and have it cope with multicast addresses on multi-homed systems and noting the protocol version.

NB: I had this issue due to using Hyper-V on Windows, which creates a virtual network interface that becomes an unintended sink for multicast messages that are not properly directed. I can tidy and share my code if @nitroshare says this is wanted and would merge it (this pull request was raised over a year ago, which indicates there is no interest in this issue).

beeka avatar Sep 24 '20 15:09 beeka

Hey I'd just like to say that this does interest me and this PR fixed my issues. It was also attributable to Hyper-V on Windows causing default routing of multicast packets getting lost on other interfaces.

mckaymatthew avatar Mar 13 '22 03:03 mckaymatthew

Another common configuration where this fix helps:

Standard home router, laptop connected by ethernet. And a device with mDNS service which have mDNS service inside it, working as Wi-Fi client or Wi-Fi Access point.

When the device is Wi-Fi client, qmdnsengine works. When the device in AP mode, qmdgsengine can't see it because sending mDNS packets only to ethernet.

asashnov avatar Mar 23 '22 08:03 asashnov

@cgutman

I found another instance where this is occurring, the library isn't tracking which interface a service query came in on, and is sending to a interface, which is not the correct one. I just updated the call to be sendMessageToAll, which isn't very conservative, but works. I don't want to duplicate your PR without talking to you, do you want to pull my change into your PR? https://github.com/mckaymatthew/qmdnsengine/commit/f7a1e88e0844ab5601c5595df3071e93eec95601

mckaymatthew avatar Feb 07 '23 04:02 mckaymatthew