diff --git a/ipapython/ipautil.py b/ipapython/ipautil.py index 5a6bf5a27..1bb48d4fc 100644 --- a/ipapython/ipautil.py +++ b/ipapython/ipautil.py @@ -197,6 +197,7 @@ class CheckedIPAddress(UnsafeIPAddress): :return: InterfaceDetails named tuple or None if no interface has this address """ + root_logger.debug("Searching for an interface of IP address: %s", self) if self.version == 4: family = netifaces.AF_INET elif self.version == 6: @@ -213,10 +214,20 @@ class CheckedIPAddress(UnsafeIPAddress): # errors in IPNetwork ifaddr = ifdata['addr'].split(u'%', 1)[0] - ifnet = netaddr.IPNetwork('{addr}/{netmask}'.format( + # newer versions of netifaces provide IPv6 netmask in format + # 'ffff:ffff:ffff:ffff::/64'. We have to split and use prefix + # or the netmask with older versions + ifmask = ifdata['netmask'].split(u'/')[-1] + + ifaddrmask = '{addr}/{netmask}'.format( addr=ifaddr, - netmask=ifdata['netmask'] - )) + netmask=ifmask + ) + root_logger.debug( + "Testing local IP address: %s (interface: %s)", + ifaddrmask, interface) + + ifnet = netaddr.IPNetwork(ifaddrmask) if ifnet.ip == self: return InterfaceDetails(interface, ifnet)