Allow net IDs in /31, /32, /127, /128

This commit is contained in:
Austin de Coup-Crank 2023-05-15 14:52:29 -05:00
parent 159682124c
commit 478b27ae18

View File

@ -354,14 +354,14 @@ class IPAddressForm(TenancyForm, NetBoxModelForm):
# Do not allow assigning a network ID or broadcast address to an interface. # Do not allow assigning a network ID or broadcast address to an interface.
if interface: if interface:
if address := self.cleaned_data.get('address'): if address := self.cleaned_data.get('address'):
if address.ip == address.network: if address.ip == address.network and address.prefixlen not in (31, 32, 127, 128):
self.add_error( self.add_error(
'interface', 'interface',
"This address is a network ID, which may not be assigned to an interface.") f"{address} is a network ID, which may not be assigned to an interface.")
if address.ip == address.broadcast: if address.ip == address.broadcast:
self.add_error( self.add_error(
'interface', 'interface',
"This is a broadcast address, which may not be assigned to an interface.") f"{address} is a broadcast address, which may not be assigned to an interface.")
def save(self, *args, **kwargs): def save(self, *args, **kwargs):
ipaddress = super().save(*args, **kwargs) ipaddress = super().save(*args, **kwargs)