Handle missing IPv6 support by the kernel

This is different from disabled IPv6.

Fixes #1050
This commit is contained in:
Unrud 2020-05-24 10:00:46 +02:00 committed by Unrud
parent 70a8d632fb
commit 6ec63ccc9b
2 changed files with 15 additions and 11 deletions

View File

@ -238,7 +238,9 @@ def serve(configuration, shutdown_socket):
# Address family not available (e.g. IPv6 disabled) # Address family not available (e.g. IPv6 disabled)
# macOS: IPv4 address for INET6 address family with # macOS: IPv4 address for INET6 address family with
# IPV6_V6ONLY set # IPV6_V6ONLY set
e.errno == errno.EADDRNOTAVAIL)): e.errno == errno.EADDRNOTAVAIL or
# Address family not supported
e.errno == errno.EAFNOSUPPORT)):
continue continue
raise RuntimeError("Failed to start server %r: %s" % ( raise RuntimeError("Failed to start server %r: %s" % (
format_address(address), e)) from e format_address(address), e)) from e

View File

@ -132,20 +132,22 @@ class TestBaseServerRequests(BaseTest):
socket.EAI_NONAME, server.COMPAT_EAI_ADDRFAMILY, socket.EAI_NONAME, server.COMPAT_EAI_ADDRFAMILY,
server.COMPAT_EAI_NODATA) or server.COMPAT_EAI_NODATA) or
str(exc_info.value) == "address family mismatched" or str(exc_info.value) == "address family mismatched" or
exc_info.value.errno == errno.EADDRNOTAVAIL) exc_info.value.errno == errno.EADDRNOTAVAIL or
exc_info.value.errno == errno.EAFNOSUPPORT)
def test_ipv6(self): def test_ipv6(self):
with socket.socket(socket.AF_INET6, socket.SOCK_STREAM) as sock: try:
# Only allow IPv6 connections to the IPv6 socket with socket.socket(socket.AF_INET6, socket.SOCK_STREAM) as sock:
sock.setsockopt(server.COMPAT_IPPROTO_IPV6, socket.IPV6_V6ONLY, 1) # Only allow IPv6 connections to the IPv6 socket
try: sock.setsockopt(
server.COMPAT_IPPROTO_IPV6, socket.IPV6_V6ONLY, 1)
# Find available port # Find available port
sock.bind(("::1", 0)) sock.bind(("::1", 0))
except OSError as e: self.sockname = sock.getsockname()[:2]
if e.errno == errno.EADDRNOTAVAIL: except OSError as e:
pytest.skip("IPv6 not supported") if e.errno in (errno.EADDRNOTAVAIL, errno.EAFNOSUPPORT):
raise pytest.skip("IPv6 not supported")
self.sockname = sock.getsockname()[:2] raise
self.configuration.update({ self.configuration.update({
"server": {"hosts": "[%s]:%d" % self.sockname}}, "test") "server": {"hosts": "[%s]:%d" % self.sockname}}, "test")
self.thread.start() self.thread.start()