You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Using IPVersion.All leads to OSError: [Errno 101] Network is unreachable logged #1357
When using AsyncZeroconf(ip_version=IPVersion.All) this can lead to the following warning being logged:
WARNING Error with socket 66 (('::1', 5353, 0, 0))): [Errno 101] Network is unreachable
Traceback (most recent call last):
File "/usr/local/lib/python3.11/asyncio/selector_events.py", line 1196, in sendto
self._sock.sendto(data, addr)
OSError: [Errno 101] Network is unreachable
It seems that listening to the IPv6 loopback on it's own isn't problematic, but when trying to send to that socket, it leads to the above error. The problematic socket is created via get_all_addresses_v6(), which returns the loopback interface with the ::1 address (the full tuple being (('::1', 0, 0), 1)).
This then leads to a socket with the follow options created:
zc_args["interfaces"] = [
str(source_ip)
for source_ip in await network.async_get_enabled_source_ips(hass)
if not source_ip.is_loopback
and not (isinstance(source_ip, IPv6Address) and source_ip.is_global)
and not (
isinstance(source_ip, IPv6Address)
and zc_args["ip_version"] == IPVersion.V4Only
)
and not (
isinstance(source_ip, IPv4Address)
and zc_args["ip_version"] == IPVersion.V6Only
)
]
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
OSError: [Errno 101] Network is unreachable
It seems that this is more related to the routing table, e.g. adding a route like this makes the error go away:
ip -6 route add table local multicast ff00::/8 dev lo proto kernel metric 255 pref medium
There is also an explicit flag which allows to turn on/off multicast on the loopback interface (by default it is off):
ip link set lo multicast on
With ifaddr/ifaddr#59 ifaddr will return the current state of that flag per interface.
However, in my testing using Arch Linux with Linux 6.14.2, even with multicast set to on, multicast is not working on the loopback interface (I don't see multicast packets from the same or other processes). It does work with a dummy interface though.
Activity
agners commentedon Feb 7, 2024
The problem here really is the missing multicast support flag on the loopback interface
E.g. a Ethernet interface has the flag:
On IPv4 it is probably not a problem since the socket option
IPV6_MULTICAST_IFto bind to a specific interface index is IPv6 specific.I found that e.g. the Matter SDK's minimal mDNS implementation simply skips loopback (see https://github.com/project-chip/connectedhomeip/blob/v1.2.0.1/src/lib/dnssd/minimal_mdns/AddressPolicy_DefaultImpl.cpp#L41-L53).
However, it seems we can learn that from the interface flags instead. But it would require a change in the ifaddr library.
bdraco commentedon Feb 7, 2024
Looks like macos has MULTICAST on lo0
bdraco commentedon Feb 7, 2024
linux 4.4.x
bdraco commentedon Feb 7, 2024
bdraco commentedon Feb 7, 2024
In HA we already explicitly exclude loopback
bdraco commentedon Feb 7, 2024
There is even a docstring that loopback doesn't work.
Someone might need it though so I think we can change
InterfaceChoice.Allto exclude loopback, and addInterfaceChoice.AllWithLoopbackagners commentedon Feb 7, 2024
There is a iflags, I think it would be the better indication.
Other interfaces might have that restriction too. E.g. a manually created dummy device:
agners commentedon Feb 7, 2024
This would allow to filter the interfaces smarter on our end: ifaddr/ifaddr#59
bdraco commentedon Feb 7, 2024
That would be better but realistically we don't have that information unless your PR gets merged
agners commentedon Apr 16, 2025
It seems that this is more related to the routing table, e.g. adding a route like this makes the error go away:
There is also an explicit flag which allows to turn on/off multicast on the loopback interface (by default it is off):
With ifaddr/ifaddr#59 ifaddr will return the current state of that flag per interface.
However, in my testing using Arch Linux with Linux 6.14.2, even with multicast set to on, multicast is not working on the loopback interface (I don't see multicast packets from the same or other processes). It does work with a dummy interface though.
🐛 fix(mdns): wrap Zeroconf() construction + ServiceInfo socket.inet_a…