From 56d04b3dccc967630d869006dfbd0003fcfedabe Mon Sep 17 00:00:00 2001 From: Martin Basti Date: Fri, 16 Jun 2017 13:42:53 +0200 Subject: [PATCH] python-netifaces: update to reflect upstream changes python-netifaces now provides IPv6 netmask in format mask/prefix. It breaks freeipa as it is unexpected format for python-netaddr. We must split netmask and provide only prefix for netaddr. https://pagure.io/freeipa/issue/7021 Reviewed-By: Martin Babinsky Reviewed-By: Petr Vobornik --- ipapython/ipautil.py | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/ipapython/ipautil.py b/ipapython/ipautil.py index 5a6bf5a..1bb48d4 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) -- 2.9.4