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 <mbabinsk@redhat.com>
Reviewed-By: Petr Vobornik <pvoborni@redhat.com>
This commit is contained in:
Martin Basti 2017-06-16 13:42:53 +02:00 committed by Martin Babinsky
parent 172a2e7456
commit 52b43c7168

View File

@ -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)