Skip to content

Commit

Permalink
Prevent find-resolv-conf.py from breaking with scoped IPv6 addresses
Browse files Browse the repository at this point in the history
  • Loading branch information
neoaggelos committed Dec 4, 2023
1 parent 5b0e6bd commit d989fda
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion scripts/find-resolv-conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,17 @@ def safe_is_non_loopback_address(address: str):
try:
return not ipaddress.ip_address(address).is_loopback
except ValueError:
return False
# NOTE(neoaggelos): https://github.com/canonical/microk8s/issues/4327
# Python 3.8 fails with scoped IPv6 address, e.g. "fe80::5054:ff:fe00:b61d%2"
# Try to remove the scope suffix, and accept if value is an IPv6 address
if "%" not in address:
return False

try:
ip = ipaddress.ip_address(address[: address.find("%")])
return ip.version == 6 and not ip.is_loopback
except (ValueError, IndexError):
return False


def find_resolv_conf_with_non_loopback_address(resolv_confs: list):
Expand Down

0 comments on commit d989fda

Please sign in to comment.