On 27.3.2012 10:43, Martin Kosek wrote:
On Mon, 2012-03-19 at 14:02 +0100, Jan Cholasta wrote:
https://fedorahosted.org/freeipa/ticket/2138

Honza


This will work, I just think that a documentation of this issue can be
improved.

1) A short comment in the following part explaining why do we partition
by % would clarify it for non-IPv6 experts

+                except netaddr.AddrFormatError:
<<<
+                    addr = str(addr).partition('%')[0]
+                    addr = netaddr.IPAddress(addr, flags=self.netaddr_ip_flags)
+                    if addr.version != 6:

2) Patch comment can be improved as well

Thanks,
Martin


Updated patch attached.

Honza

--
Jan Cholasta
>From 1bec02112d4ff5b1e125e5b0f9fefa0b51d205d7 Mon Sep 17 00:00:00 2001
From: Jan Cholasta <jchol...@redhat.com>
Date: Mon, 19 Mar 2012 08:52:11 -0400
Subject: [PATCH] Parse zone indices in IPv6 addresses in CheckedIPAddress.

If a zone index is present in an IPv6 address, it is ignored.

ticket 2138
---
 ipapython/ipautil.py                 |   15 ++++++++++++++-
 tests/test_ipapython/test_ipautil.py |    4 ++++
 2 files changed, 18 insertions(+), 1 deletions(-)

diff --git a/ipapython/ipautil.py b/ipapython/ipautil.py
index d3bb38a..69c3289 100644
--- a/ipapython/ipautil.py
+++ b/ipapython/ipautil.py
@@ -97,7 +97,20 @@ class CheckedIPAddress(netaddr.IPAddress):
             pass
         else:
             try:
-                addr = netaddr.IPAddress(addr, flags=self.netaddr_ip_flags)
+                try:
+                    addr = netaddr.IPAddress(addr, flags=self.netaddr_ip_flags)
+                except netaddr.AddrFormatError:
+                    # netaddr.IPAddress doesn't handle zone indices in textual
+                    # IPv6 addresses. Try removing zone index and parse the
+                    # address again.
+                    if not isinstance(addr, basestring):
+                        raise
+                    addr, sep, foo = addr.partition('%')
+                    if sep != '%':
+                        raise
+                    addr = netaddr.IPAddress(addr, flags=self.netaddr_ip_flags)
+                    if addr.version != 6:
+                        raise
             except ValueError:
                 net = netaddr.IPNetwork(addr, flags=self.netaddr_ip_flags)
                 if not parse_netmask:
diff --git a/tests/test_ipapython/test_ipautil.py b/tests/test_ipapython/test_ipautil.py
index 68391c2..650e1ce 100644
--- a/tests/test_ipapython/test_ipautil.py
+++ b/tests/test_ipapython/test_ipautil.py
@@ -39,6 +39,8 @@ def test_ip_address():
     addrs = [
         ('10.11.12.13',     (10, 11, 12, 13),   8),
         ('10.11.12.13/14',  (10, 11, 12, 13),   14),
+        ('10.11.12.13%zoneid',),
+        ('10.11.12.13%zoneid/14',),
         ('10.11.12.1337',),
         ('10.11.12.13/33',),
         ('127.0.0.1',),
@@ -50,6 +52,8 @@ def test_ip_address():
 
         ('2001::1',         (0x2001, 0, 0, 0, 0, 0, 0, 1), 64),
         ('2001::1/72',      (0x2001, 0, 0, 0, 0, 0, 0, 1), 72),
+        ('2001::1%zoneid',  (0x2001, 0, 0, 0, 0, 0, 0, 1), 64),
+        ('2001::1%zoneid/72',),
         ('2001::1beef',),
         ('2001::1/129',),
         ('::1',),
-- 
1.7.7.6

_______________________________________________
Freeipa-devel mailing list
Freeipa-devel@redhat.com
https://www.redhat.com/mailman/listinfo/freeipa-devel

Reply via email to