From 7f2f98885b68b9b9d7208587df3f277c22806b2b Mon Sep 17 00:00:00 2001 From: jeremystretch Date: Thu, 6 May 2021 13:59:10 -0400 Subject: [PATCH] Fixes #6350: Include first & last IP addresses when allocating available IPv6 addresses via the REST API --- docs/release-notes/version-2.11.md | 1 + netbox/ipam/models/ip.py | 14 +++----------- 2 files changed, 4 insertions(+), 11 deletions(-) diff --git a/docs/release-notes/version-2.11.md b/docs/release-notes/version-2.11.md index 69f10b6e5..cf0ca9cd5 100644 --- a/docs/release-notes/version-2.11.md +++ b/docs/release-notes/version-2.11.md @@ -18,6 +18,7 @@ * [#6321](https://github.com/netbox-community/netbox/issues/6321) - Restore "add an IP" button under prefix IPs view * [#6333](https://github.com/netbox-community/netbox/issues/6333) - Fix filtering of circuit terminations by primary key * [#6339](https://github.com/netbox-community/netbox/issues/6339) - Improve ordering of interfaces when viewing virtual chassis master +* [#6350](https://github.com/netbox-community/netbox/issues/6350) - Include first & last IP addresses when allocating available IPv6 addresses via the REST API * [#6355](https://github.com/netbox-community/netbox/issues/6355) - Fix caching error when swapping A/Z circuit terminations * [#6357](https://github.com/netbox-community/netbox/issues/6357) - Fix ProviderNetwork nested API serializer * [#6363](https://github.com/netbox-community/netbox/issues/6363) - Correct pre-population of cluster group when creating a cluster diff --git a/netbox/ipam/models/ip.py b/netbox/ipam/models/ip.py index e521dc5c9..2490a0c5a 100644 --- a/netbox/ipam/models/ip.py +++ b/netbox/ipam/models/ip.py @@ -426,19 +426,11 @@ class Prefix(PrimaryModel): child_ips = netaddr.IPSet([ip.address.ip for ip in self.get_child_ips()]) available_ips = prefix - child_ips - # All IP addresses within a pool are considered usable - if self.is_pool: + # IPv6, pool, or IPv4 /31 sets are fully usable + if self.family == 6 or self.is_pool or self.prefix.prefixlen == 31: return available_ips - # All IP addresses within a point-to-point prefix (IPv4 /31 or IPv6 /127) are considered usable - if ( - self.prefix.version == 4 and self.prefix.prefixlen == 31 # RFC 3021 - ) or ( - self.prefix.version == 6 and self.prefix.prefixlen == 127 # RFC 6164 - ): - return available_ips - - # Omit first and last IP address from the available set + # For "normal" IPv4 prefixes, omit first and last addresses available_ips -= netaddr.IPSet([ netaddr.IPAddress(self.prefix.first), netaddr.IPAddress(self.prefix.last),