From 928525fb6204698294f3b8acae9a9f41878611e3 Mon Sep 17 00:00:00 2001 From: tonghuaroot Date: Sat, 20 Jun 2026 09:05:14 +0800 Subject: [PATCH 1/2] gh-151749: Add 5f00::/16 (RFC 9602) and 100:0:0:1::/64 (RFC 9780) to ipaddress IPv6 private networks --- Lib/ipaddress.py | 2 ++ Lib/test/test_ipaddress.py | 12 ++++++++++++ .../2026-06-20-01-00-43.gh-issue-151749.5vLBmS.rst | 4 ++++ 3 files changed, 18 insertions(+) create mode 100644 Misc/NEWS.d/next/Library/2026-06-20-01-00-43.gh-issue-151749.5vLBmS.rst diff --git a/Lib/ipaddress.py b/Lib/ipaddress.py index f1062a8cd052a5..9f96cb314ac447 100644 --- a/Lib/ipaddress.py +++ b/Lib/ipaddress.py @@ -2387,6 +2387,8 @@ class _IPv6Constants: IPv6Network('2002::/16'), # RFC 9637: https://www.rfc-editor.org/rfc/rfc9637.html#section-6-2.2 IPv6Network('3fff::/20'), + IPv6Network('5f00::/16'), # RFC 9602 Segment Routing (SRv6) SIDs + IPv6Network('100:0:0:1::/64'), # RFC 9780 Dummy IPv6 Prefix IPv6Network('fc00::/7'), IPv6Network('fe80::/10'), ] diff --git a/Lib/test/test_ipaddress.py b/Lib/test/test_ipaddress.py index 3f017b97dc28a3..0145891871751c 100644 --- a/Lib/test/test_ipaddress.py +++ b/Lib/test/test_ipaddress.py @@ -2499,6 +2499,18 @@ def testReservedIpv6(self): self.assertFalse(ipaddress.ip_address('2002::').is_global) # gh-124217: conform with RFC 9637 self.assertFalse(ipaddress.ip_address('3fff::').is_global) + # gh-151749: 5f00::/16 (RFC 9602) and 100:0:0:1::/64 (RFC 9780) + # are not globally reachable per the IANA registry. + for addr in ('5f00::', '5f00::1', + '5f00:ffff:ffff:ffff:ffff:ffff:ffff:ffff', + '100:0:0:1::', '100:0:0:1:ffff:ffff:ffff:ffff'): + self.assertFalse(ipaddress.ip_address(addr).is_global) + self.assertTrue(ipaddress.ip_address(addr).is_private) + # Addresses adjacent to the new ranges are unaffected. + for addr in ('5eff:ffff:ffff:ffff:ffff:ffff:ffff:ffff', '5f01::', + '100:0:0:2::'): + self.assertTrue(ipaddress.ip_address(addr).is_global) + self.assertFalse(ipaddress.ip_address(addr).is_private) # some generic IETF reserved addresses self.assertEqual(True, ipaddress.ip_address('100::').is_reserved) diff --git a/Misc/NEWS.d/next/Library/2026-06-20-01-00-43.gh-issue-151749.5vLBmS.rst b/Misc/NEWS.d/next/Library/2026-06-20-01-00-43.gh-issue-151749.5vLBmS.rst new file mode 100644 index 00000000000000..57dd6b5b2952d5 --- /dev/null +++ b/Misc/NEWS.d/next/Library/2026-06-20-01-00-43.gh-issue-151749.5vLBmS.rst @@ -0,0 +1,4 @@ +Fixed :attr:`ipaddress.IPv6Address.is_global` and +:attr:`ipaddress.IPv6Address.is_private` for the ``5f00::/16`` (:rfc:`9602`) +and ``100:0:0:1::/64`` (:rfc:`9780`) special-purpose ranges, which are not +globally reachable per the IANA registry. From 0e67dce89df04ac7329836e6b95dab2a658e1f1c Mon Sep 17 00:00:00 2001 From: tonghuaroot Date: Sat, 20 Jun 2026 09:13:22 +0800 Subject: [PATCH 2/2] gh-151749: Match surrounding comment and test style --- Lib/ipaddress.py | 6 ++++-- Lib/test/test_ipaddress.py | 15 +++------------ 2 files changed, 7 insertions(+), 14 deletions(-) diff --git a/Lib/ipaddress.py b/Lib/ipaddress.py index 9f96cb314ac447..7925f4034f1635 100644 --- a/Lib/ipaddress.py +++ b/Lib/ipaddress.py @@ -2387,8 +2387,10 @@ class _IPv6Constants: IPv6Network('2002::/16'), # RFC 9637: https://www.rfc-editor.org/rfc/rfc9637.html#section-6-2.2 IPv6Network('3fff::/20'), - IPv6Network('5f00::/16'), # RFC 9602 Segment Routing (SRv6) SIDs - IPv6Network('100:0:0:1::/64'), # RFC 9780 Dummy IPv6 Prefix + # RFC 9602: https://www.rfc-editor.org/rfc/rfc9602.html + IPv6Network('5f00::/16'), + # RFC 9780: https://www.rfc-editor.org/rfc/rfc9780.html + IPv6Network('100:0:0:1::/64'), IPv6Network('fc00::/7'), IPv6Network('fe80::/10'), ] diff --git a/Lib/test/test_ipaddress.py b/Lib/test/test_ipaddress.py index 0145891871751c..55667d57b1dcdd 100644 --- a/Lib/test/test_ipaddress.py +++ b/Lib/test/test_ipaddress.py @@ -2499,18 +2499,9 @@ def testReservedIpv6(self): self.assertFalse(ipaddress.ip_address('2002::').is_global) # gh-124217: conform with RFC 9637 self.assertFalse(ipaddress.ip_address('3fff::').is_global) - # gh-151749: 5f00::/16 (RFC 9602) and 100:0:0:1::/64 (RFC 9780) - # are not globally reachable per the IANA registry. - for addr in ('5f00::', '5f00::1', - '5f00:ffff:ffff:ffff:ffff:ffff:ffff:ffff', - '100:0:0:1::', '100:0:0:1:ffff:ffff:ffff:ffff'): - self.assertFalse(ipaddress.ip_address(addr).is_global) - self.assertTrue(ipaddress.ip_address(addr).is_private) - # Addresses adjacent to the new ranges are unaffected. - for addr in ('5eff:ffff:ffff:ffff:ffff:ffff:ffff:ffff', '5f01::', - '100:0:0:2::'): - self.assertTrue(ipaddress.ip_address(addr).is_global) - self.assertFalse(ipaddress.ip_address(addr).is_private) + # gh-151749: conform with RFC 9602 and RFC 9780 + self.assertFalse(ipaddress.ip_address('5f00::').is_global) + self.assertFalse(ipaddress.ip_address('100:0:0:1::').is_global) # some generic IETF reserved addresses self.assertEqual(True, ipaddress.ip_address('100::').is_reserved)