Exclude global scope IPv6 when setting up zeroconf interfaces (#54632)

This commit is contained in:
J. Nick Koston 2021-08-18 11:00:09 -05:00 committed by GitHub
parent 8d37fd08c7
commit 5d19575a84
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 17 additions and 5 deletions

View file

@ -162,10 +162,14 @@ async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
interfaces.extend(
ipv4["address"]
for ipv4 in ipv4s
if not ipaddress.ip_address(ipv4["address"]).is_loopback
if not ipaddress.IPv4Address(ipv4["address"]).is_loopback
)
if adapter["ipv6"] and adapter["index"] not in interfaces:
interfaces.append(adapter["index"])
if ipv6s := adapter["ipv6"]:
for ipv6_addr in ipv6s:
address = ipv6_addr["address"]
v6_ip_address = ipaddress.IPv6Address(address)
if not v6_ip_address.is_global and not v6_ip_address.is_loopback:
interfaces.append(ipv6_addr["address"])
aio_zc = await _async_get_instance(hass, **zc_args)
zeroconf = cast(HaZeroconf, aio_zc.zeroconf)

View file

@ -799,7 +799,14 @@ async def test_async_detect_interfaces_setting_empty_route(hass, mock_async_zero
hass.bus.async_fire(EVENT_HOMEASSISTANT_STARTED)
await hass.async_block_till_done()
assert mock_zc.mock_calls[0] == call(
interfaces=[1, "192.168.1.5", "172.16.1.5", 3], ip_version=IPVersion.All
interfaces=[
"2001:db8::",
"fe80::1234:5678:9abc:def0",
"192.168.1.5",
"172.16.1.5",
"fe80::dead:beef:dead:beef",
],
ip_version=IPVersion.All,
)
@ -862,5 +869,6 @@ async def test_async_detect_interfaces_explicitly_set_ipv6(hass, mock_async_zero
await hass.async_block_till_done()
assert mock_zc.mock_calls[0] == call(
interfaces=["192.168.1.5", 1], ip_version=IPVersion.All
interfaces=["192.168.1.5", "fe80::dead:beef:dead:beef"],
ip_version=IPVersion.All,
)