From 2e6545b8be25406570fddc10fb42ed46856bbc28 Mon Sep 17 00:00:00 2001 From: cao-fei8 Date: Mon, 16 Jan 2023 19:03:56 +0800 Subject: [PATCH] Fix for is_loopback behaviour (issue: #222) Reference: https://github.com/netaddr/netaddr/commit/606a44b62ea7032f63e359aaaaabc0057e168890 Signed-off-by: cao-fei8 --- ...-is_loopback-behaviour-issue-222-223.patch | 68 +++++++++++++++++++ python-netaddr.spec | 6 +- 2 files changed, 73 insertions(+), 1 deletion(-) create mode 100644 0001-Fix-for-is_loopback-behaviour-issue-222-223.patch diff --git a/0001-Fix-for-is_loopback-behaviour-issue-222-223.patch b/0001-Fix-for-is_loopback-behaviour-issue-222-223.patch new file mode 100644 index 0000000..78dde97 --- /dev/null +++ b/0001-Fix-for-is_loopback-behaviour-issue-222-223.patch @@ -0,0 +1,68 @@ +From 606a44b62ea7032f63e359aaaaabc0057e168890 Mon Sep 17 00:00:00 2001 +From: niels +Date: Wed, 27 Jan 2021 20:44:12 +0100 +Subject: [PATCH] Fix for is_loopback behaviour (issue: #222) (#223) + +--- + netaddr/ip/__init__.py | 4 +-- + .../tests/ip/test_ip_network_categories.py | 26 +++++++++++++++++++ + 2 files changed, 28 insertions(+), 2 deletions(-) + create mode 100644 netaddr/tests/ip/test_ip_network_categories.py + +diff --git a/netaddr/ip/__init__.py b/netaddr/ip/__init__.py +index d1232eb..9e13b29 100644 +--- a/netaddr/ip/__init__.py ++++ b/netaddr/ip/__init__.py +@@ -151,7 +151,7 @@ class BaseIP(object): + if self._module.version == 4: + return self in IPV4_LOOPBACK + elif self._module.version == 6: +- return self == IPV6_LOOPBACK ++ return self in IPV6_LOOPBACK + + def is_private(self): + """ +@@ -1949,7 +1949,7 @@ IPV4_RESERVED = ( + #----------------------------------------------------------------------------- + # Cached IPv6 address range lookups. + #----------------------------------------------------------------------------- +-IPV6_LOOPBACK = IPAddress('::1') ++IPV6_LOOPBACK = IPNetwork('::1/128') + + IPV6_PRIVATE = ( + IPNetwork('fc00::/7'), # Unique Local Addresses (ULA) +diff --git a/netaddr/tests/ip/test_ip_network_categories.py b/netaddr/tests/ip/test_ip_network_categories.py +new file mode 100644 +index 0000000..9f9961e +--- /dev/null ++++ b/netaddr/tests/ip/test_ip_network_categories.py +@@ -0,0 +1,26 @@ ++from netaddr import IPNetwork ++ ++ ++def test_is_unicast(): ++ assert IPNetwork('192.0.2.0/24').is_unicast() ++ assert IPNetwork('fe80::1/48').is_unicast() ++ ++ ++def test_is_multicast(): ++ assert IPNetwork('239.192.0.1/24').is_multicast() ++ assert IPNetwork('ff00::/8').is_multicast() ++ ++ ++def test_is_private(): ++ assert IPNetwork('10.0.0.0/24').is_private() ++ assert IPNetwork('fc00::/7').is_private() ++ ++ ++def test_is_reserved(): ++ assert IPNetwork('240.0.0.0/24').is_reserved() ++ assert IPNetwork('0::/48').is_reserved() ++ ++ ++def test_is_loopback(): ++ assert IPNetwork('127.0.0.0/8').is_loopback() ++ assert IPNetwork('::1/128').is_loopback() +-- +2.33.0 + diff --git a/python-netaddr.spec b/python-netaddr.spec index c2d92f5..057f53b 100644 --- a/python-netaddr.spec +++ b/python-netaddr.spec @@ -1,6 +1,6 @@ Name: python-netaddr Version: 0.8.0 -Release: 4 +Release: 5 Summary: A pure Python network address representation and manipulation library License: BSD-3-Clause @@ -9,6 +9,7 @@ Source0: https://pypi.python.org/packages/source/n/netaddr/netaddr-%{vers Patch9000: elimate-ROC-in-python-netaddr.patch Patch9001: disable-test-oui-information.patch +Patch9002: 0001-Fix-for-is_loopback-behaviour-issue-222-223.patch BuildArch: noarch BuildRequires: python3-devel python3-setuptools python3-sphinx python3-pytest @@ -56,6 +57,9 @@ py.test-%{python3_version} %{_bindir}/netaddr %changelog +* Tue Jan 17 2023 caofei - 0.8.0-5 +- Fix for is_loopback behaviour (issue: #222) + * Wed May 11 2022 wulei - 0.8.0-4 - License compliance rectification