Просмотр исходного кода

Closes #7252: Validate IP range size does not exceed max supported value

jeremystretch 4 лет назад
Родитель
Сommit
ad65e06d0a
3 измененных файлов с 9 добавлено и 0 удалено
  1. 3 0
      docs/models/ipam/iprange.md
  2. 1 0
      docs/release-notes/version-3.0.md
  3. 5 0
      netbox/ipam/models/ip.py

+ 3 - 0
docs/models/ipam/iprange.md

@@ -9,3 +9,6 @@ IP also ranges share the same functional roles as prefixes and VLANs, although t
 * Deprecated - No longer in use
 * Deprecated - No longer in use
 
 
 The status of a range does _not_ have any impact on its member IP addresses, which may have their statuses modified separately.
 The status of a range does _not_ have any impact on its member IP addresses, which may have their statuses modified separately.
+
+!!! note
+    The maximum supported size of an IP range is 2^32 - 1.

+ 1 - 0
docs/release-notes/version-3.0.md

@@ -13,6 +13,7 @@
 
 
 ### Bug Fixes
 ### Bug Fixes
 
 
+* [#7252](https://github.com/netbox-community/netbox/issues/7252) - Validate IP range size does not exceed max supported value
 * [#7294](https://github.com/netbox-community/netbox/issues/7294) - Fix SVG rendering for cable traces ending at unoccupied front ports
 * [#7294](https://github.com/netbox-community/netbox/issues/7294) - Fix SVG rendering for cable traces ending at unoccupied front ports
 * [#7304](https://github.com/netbox-community/netbox/issues/7304) - Require explicit values for all required choice fields during CSV import
 * [#7304](https://github.com/netbox-community/netbox/issues/7304) - Require explicit values for all required choice fields during CSV import
 * [#7321](https://github.com/netbox-community/netbox/issues/7321) - Don't overwrite multi-select custom fields during bulk edit
 * [#7321](https://github.com/netbox-community/netbox/issues/7321) - Don't overwrite multi-select custom fields during bulk edit

+ 5 - 0
netbox/ipam/models/ip.py

@@ -600,6 +600,11 @@ class IPRange(PrimaryModel):
             if overlapping_range:
             if overlapping_range:
                 raise ValidationError(f"Defined addresses overlap with range {overlapping_range} in VRF {self.vrf}")
                 raise ValidationError(f"Defined addresses overlap with range {overlapping_range} in VRF {self.vrf}")
 
 
+            # Validate maximum size
+            MAX_SIZE = 2 ** 32 - 1
+            if int(self.end_address.ip - self.start_address.ip) + 1 > MAX_SIZE:
+                raise ValidationError(f"Defined range exceeds maximum supported size ({MAX_SIZE})")
+
     def save(self, *args, **kwargs):
     def save(self, *args, **kwargs):
 
 
         # Record the range's size (number of IP addresses)
         # Record the range's size (number of IP addresses)