-
Notifications
You must be signed in to change notification settings - Fork 233
Open
Description
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:
import socket
import struct
s = socket.socket(family=socket.AF_INET6, type=socket.SOCK_DGRAM)
s.setsockopt(socket.IPPROTO_IPV6, socket.IPV6_V6ONLY, False)
s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEPORT, 1)
s.setsockopt(socket.IPPROTO_IPV6, socket.IPV6_MULTICAST_HOPS, 255)
s.setsockopt(socket.IPPROTO_IPV6, socket.IPV6_MULTICAST_LOOP, True)
s.bind(('::2', 5353, 0, 0))
s.setsockopt(socket.IPPROTO_IPV6, socket.IPV6_MULTICAST_IF, struct.pack('@I', 1))
When this socket then is used, the stack trace appears:
s.sendto(b"Hello", ('ff02::fb', 5353, 0, 0))
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
OSError: [Errno 101] Network is unreachable
The relevant option seem to be the IPv6 specific binding to the interface index IPV6_MULTICAST_IF, in this case 1 for the loopback interface.
Metadata
Metadata
Assignees
Labels
No labels