mirror of
https://github.com/netbox-community/netbox.git
synced 2025-07-14 09:51:22 -06:00
Fixes #4510: Enforce address family for device primary IPv4/v6 addresses
This commit is contained in:
parent
cc721efe97
commit
ada55dfdfb
@ -14,6 +14,7 @@
|
|||||||
* [#4388](https://github.com/netbox-community/netbox/issues/4388) - Fix detection of connected endpoints when connecting rear ports
|
* [#4388](https://github.com/netbox-community/netbox/issues/4388) - Fix detection of connected endpoints when connecting rear ports
|
||||||
* [#4489](https://github.com/netbox-community/netbox/issues/4489) - Fix display of parent/child role on device type view
|
* [#4489](https://github.com/netbox-community/netbox/issues/4489) - Fix display of parent/child role on device type view
|
||||||
* [#4496](https://github.com/netbox-community/netbox/issues/4496) - Fix exception when validating certain models via REST API
|
* [#4496](https://github.com/netbox-community/netbox/issues/4496) - Fix exception when validating certain models via REST API
|
||||||
|
* [#4510](https://github.com/netbox-community/netbox/issues/4510) - Enforce address family for device primary IPv4/v6 addresses
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
|
@ -1514,24 +1514,30 @@ class Device(ChangeLoggedModel, ConfigContextModel, CustomFieldModel):
|
|||||||
# Validate primary IP addresses
|
# Validate primary IP addresses
|
||||||
vc_interfaces = self.vc_interfaces.all()
|
vc_interfaces = self.vc_interfaces.all()
|
||||||
if self.primary_ip4:
|
if self.primary_ip4:
|
||||||
|
if self.primary_ip4.family != 4:
|
||||||
|
raise ValidationError({
|
||||||
|
'primary_ip4': f"{self.primary_ip4} is not an IPv4 address."
|
||||||
|
})
|
||||||
if self.primary_ip4.interface in vc_interfaces:
|
if self.primary_ip4.interface in vc_interfaces:
|
||||||
pass
|
pass
|
||||||
elif self.primary_ip4.nat_inside is not None and self.primary_ip4.nat_inside.interface in vc_interfaces:
|
elif self.primary_ip4.nat_inside is not None and self.primary_ip4.nat_inside.interface in vc_interfaces:
|
||||||
pass
|
pass
|
||||||
else:
|
else:
|
||||||
raise ValidationError({
|
raise ValidationError({
|
||||||
'primary_ip4': "The specified IP address ({}) is not assigned to this device.".format(
|
'primary_ip4': f"The specified IP address ({self.primary_ip4}) is not assigned to this device."
|
||||||
self.primary_ip4),
|
|
||||||
})
|
})
|
||||||
if self.primary_ip6:
|
if self.primary_ip6:
|
||||||
|
if self.primary_ip6.family != 6:
|
||||||
|
raise ValidationError({
|
||||||
|
'primary_ip6': f"{self.primary_ip4} is not an IPv6 address."
|
||||||
|
})
|
||||||
if self.primary_ip6.interface in vc_interfaces:
|
if self.primary_ip6.interface in vc_interfaces:
|
||||||
pass
|
pass
|
||||||
elif self.primary_ip6.nat_inside is not None and self.primary_ip6.nat_inside.interface in vc_interfaces:
|
elif self.primary_ip6.nat_inside is not None and self.primary_ip6.nat_inside.interface in vc_interfaces:
|
||||||
pass
|
pass
|
||||||
else:
|
else:
|
||||||
raise ValidationError({
|
raise ValidationError({
|
||||||
'primary_ip6': "The specified IP address ({}) is not assigned to this device.".format(
|
'primary_ip6': f"The specified IP address ({self.primary_ip6}) is not assigned to this device."
|
||||||
self.primary_ip6),
|
|
||||||
})
|
})
|
||||||
|
|
||||||
# Validate manufacturer/platform
|
# Validate manufacturer/platform
|
||||||
|
Loading…
Reference in New Issue
Block a user