URL: https://github.com/freeipa/freeipa/pull/876
Author: MartinBasti
 Title: #876: python-netifaces: update to reflect upstream changes
Action: synchronized

To pull the PR as Git branch:
git remote add ghfreeipa https://github.com/freeipa/freeipa
git fetch ghfreeipa pull/876/head:pr876
git checkout pr876
From 42b125584a50672e5536c6e66830f1cff685b127 Mon Sep 17 00:00:00 2001
From: Martin Basti <mba...@redhat.com>
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
---
 ipapython/ipautil.py | 17 ++++++++++++++---
 1 file changed, 14 insertions(+), 3 deletions(-)

diff --git a/ipapython/ipautil.py b/ipapython/ipautil.py
index a277ed8747..f214ccbbc2 100644
--- a/ipapython/ipautil.py
+++ b/ipapython/ipautil.py
@@ -195,6 +195,7 @@ def get_matching_interface(self):
         """Find matching local interface for address
         :return: Interface name 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:
@@ -212,10 +213,20 @@ def get_matching_interface(self):
                 # 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 == self._net or (
                                 self._net is None and ifnet.ip == self):
                     self._net = ifnet
_______________________________________________
FreeIPA-devel mailing list -- freeipa-devel@lists.fedorahosted.org
To unsubscribe send an email to freeipa-devel-le...@lists.fedorahosted.org

Reply via email to