pgreco / rpms / ipa

Forked from forks/areguera/rpms/ipa 4 years ago
Clone
Blob Blame History Raw
From fd11c06c34a45688c7609872b93413823f9ccb4d Mon Sep 17 00:00:00 2001
From: Martin Basti <mbasti@redhat.com>
Date: Mon, 5 Sep 2016 14:33:58 +0200
Subject: [PATCH] Fix parse errors with link-local addresses

Link-local addresses received from netifaces contains '%suffix' that
causes parse error in IPNetwork class. We must remove %suffix before
it us used in IPNetwork objects.

https://fedorahosted.org/freeipa/ticket/6296

Reviewed-By: Tomas Krizek <tkrizek@redhat.com>
---
 ipapython/ipautil.py | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/ipapython/ipautil.py b/ipapython/ipautil.py
index fdfebb65ecb8b62108852f6517b5ffb22fd7eedc..a099ea45747100946aa97bb5010ae58c49a089ba 100644
--- a/ipapython/ipautil.py
+++ b/ipapython/ipautil.py
@@ -173,8 +173,13 @@ class CheckedIPAddress(UnsafeIPAddress):
             iface = None
             for interface in netifaces.interfaces():
                 for ifdata in netifaces.ifaddresses(interface).get(family, []):
+
+                    # link-local addresses contain '%suffix' that causes parse
+                    # errors in IPNetwork
+                    ifaddr = ifdata['addr'].split(u'%', 1)[0]
+
                     ifnet = netaddr.IPNetwork('{addr}/{netmask}'.format(
-                        addr=ifdata['addr'],
+                        addr=ifaddr,
                         netmask=ifdata['netmask']
                     ))
                     if ifnet == self._net or (
-- 
2.7.4