mirror of
https://github.com/netbox-community/netbox.git
synced 2025-08-17 04:58:16 -06:00
Added support for /32 and /128 prefixes
This commit is contained in:
parent
068a0e2257
commit
219d24274f
2
.gitignore
vendored
2
.gitignore
vendored
@ -12,3 +12,5 @@ fabfile.py
|
|||||||
gunicorn_config.py
|
gunicorn_config.py
|
||||||
.DS_Store
|
.DS_Store
|
||||||
.vscode
|
.vscode
|
||||||
|
/.vs/ProjectSettings.json
|
||||||
|
/.vs
|
||||||
|
@ -346,16 +346,6 @@ class Prefix(ChangeLoggedModel, CustomFieldModel):
|
|||||||
|
|
||||||
if self.prefix:
|
if self.prefix:
|
||||||
|
|
||||||
# Disallow host masks
|
|
||||||
if self.prefix.version == 4 and self.prefix.prefixlen == 32:
|
|
||||||
raise ValidationError({
|
|
||||||
'prefix': "Cannot create host addresses (/32) as prefixes. Create an IPv4 address instead."
|
|
||||||
})
|
|
||||||
elif self.prefix.version == 6 and self.prefix.prefixlen == 128:
|
|
||||||
raise ValidationError({
|
|
||||||
'prefix': "Cannot create host addresses (/128) as prefixes. Create an IPv6 address instead."
|
|
||||||
})
|
|
||||||
|
|
||||||
# Enforce unique IP space (if applicable)
|
# Enforce unique IP space (if applicable)
|
||||||
if (self.vrf is None and settings.ENFORCE_GLOBAL_UNIQUE) or (self.vrf and self.vrf.enforce_unique):
|
if (self.vrf is None and settings.ENFORCE_GLOBAL_UNIQUE) or (self.vrf and self.vrf.enforce_unique):
|
||||||
duplicate_prefixes = self.get_duplicates()
|
duplicate_prefixes = self.get_duplicates()
|
||||||
@ -423,6 +413,10 @@ class Prefix(ChangeLoggedModel, CustomFieldModel):
|
|||||||
Return all IPAddresses within this Prefix and VRF. If this Prefix is a container in the global table, return
|
Return all IPAddresses within this Prefix and VRF. If this Prefix is a container in the global table, return
|
||||||
child IPAddresses belonging to any VRF.
|
child IPAddresses belonging to any VRF.
|
||||||
"""
|
"""
|
||||||
|
if self.prefix.prefixlen == 32:
|
||||||
|
return IPAddress.objects.filter(vrf=self.vrf, address__net_host=str(self.prefix.cidr))
|
||||||
|
if self.prefix.prefixlen == 128:
|
||||||
|
return IPAddress.objects.filter(vrf=self.vrf, address__net_host=str(self.prefix.cidr))
|
||||||
if self.vrf is None and self.status == PREFIX_STATUS_CONTAINER:
|
if self.vrf is None and self.status == PREFIX_STATUS_CONTAINER:
|
||||||
return IPAddress.objects.filter(address__net_host_contained=str(self.prefix))
|
return IPAddress.objects.filter(address__net_host_contained=str(self.prefix))
|
||||||
else:
|
else:
|
||||||
@ -452,9 +446,9 @@ class Prefix(ChangeLoggedModel, CustomFieldModel):
|
|||||||
|
|
||||||
# All IP addresses within a point-to-point prefix (IPv4 /31 or IPv6 /127) are considered usable
|
# All IP addresses within a point-to-point prefix (IPv4 /31 or IPv6 /127) are considered usable
|
||||||
if (
|
if (
|
||||||
self.family == 4 and self.prefix.prefixlen == 31 # RFC 3021
|
self.family == 4 and self.prefix.prefixlen >= 31 # RFC 3021
|
||||||
) or (
|
) or (
|
||||||
self.family == 6 and self.prefix.prefixlen == 127 # RFC 6164
|
self.family == 6 and self.prefix.prefixlen >= 127 # RFC 6164
|
||||||
):
|
):
|
||||||
return available_ips
|
return available_ips
|
||||||
|
|
||||||
|
@ -649,7 +649,7 @@ class IPAddressView(PermissionRequiredMixin, View):
|
|||||||
|
|
||||||
# Parent prefixes table
|
# Parent prefixes table
|
||||||
parent_prefixes = Prefix.objects.filter(
|
parent_prefixes = Prefix.objects.filter(
|
||||||
vrf=ipaddress.vrf, prefix__net_contains=str(ipaddress.address.ip)
|
vrf=ipaddress.vrf, prefix__net_contains_or_equals=str(ipaddress.address.ip)
|
||||||
).select_related(
|
).select_related(
|
||||||
'site', 'role'
|
'site', 'role'
|
||||||
)
|
)
|
||||||
|
Loading…
Reference in New Issue
Block a user