Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove subnet mask from IP Addresses #14717

Closed
llamafilm opened this issue Jan 7, 2024 · 6 comments
Closed

Remove subnet mask from IP Addresses #14717

llamafilm opened this issue Jan 7, 2024 · 6 comments
Labels
type: feature Introduction of new functionality to the application

Comments

@llamafilm
Copy link
Contributor

NetBox version

v3.7.0

Feature type

Change to existing functionality

Proposed functionality

Currently the subnet mask length is an attribute of each IP address. I think it would make more sense for this to be an attribute of the prefix instead. I propose these changes:

  • Add a mandatory "parent prefix" field for IP addresses. This means you must create the Prefix before creating a new IP Address.
  • IP addresses are always entered in dotted notation without mask (e.g. 10.1.2.3)
  • Add a user preference to display IP addresses in CIDR notation based on its parent prefix. (I would never use this, I just mention it to avoid breaking anyone's workflow.) Otherwise they will be displayed in dotted notation.
  • A one-time upgrade script modifies all existing addresses and creates any missing prefixes.

Use case

The current model is redundant, and there is a risk that users enter the wrong mask length when creating a new IP Address, as described here: #8731 (reply in thread).
One way to avoid this risk is by instructing users to always use /32, which effectively makes that mask_length attribute useless, so in that case you would still need to refer to the IP Prefix to find it.
Moving the mask length to be an attribute of the Prefix would reduce the operational burden for data entry, and it would align better with the single source of truth concept. As a general rule, all IP addresses under the same parent prefix should share the same same mask length. I can't think of any exceptions to that.
This would also make it easier on the eyes when looking at big lists of addresses

Database changes

My best guess, not knowing Netbox very well:

  • add mandatory prefix_id field to ipam_ipaddress

External dependencies

none

@llamafilm llamafilm added the type: feature Introduction of new functionality to the application label Jan 7, 2024
@llamafilm
Copy link
Contributor Author

It's already possible to create an IP Address with no mask, and if you do this, Netbox automatically turns it into a /32 for display. Example from nbshell:

>>> ip = IPAddress(address='192.168.5.1')
>>> ip.save()
>>> IPAddress.objects.last()
<IPAddress: 192.168.5.1/32>

The Postgres data is stored like this:

netbox=> SELECT address FROM ipam_ipaddress ORDER BY id DESC LIMIT 2;
     address     
-----------------
 192.168.5.1
 10.37.163.37/24

Apparently the mask requirement is only here in the GUI form:

# Ensure that a subnet mask has been specified. This prevents IPs from defaulting to a /32 or /128.
if len(value.split('/')) != 2:
raise ValidationError('CIDR mask (e.g. /24) is required.')

@kkthxbye-code
Copy link
Contributor

It's already possible to create an IP Address with no mask, and if you do this, Netbox automatically turns it into a /32 for display. Example from nbshell:

>>> ip = IPAddress(address='192.168.5.1')
>>> ip.save()
>>> IPAddress.objects.last()
<IPAddress: 192.168.5.1/32>

You have to call full_clean() on the object before saving, otherwise no validation is executed.

@llamafilm
Copy link
Contributor Author

otherwise no validation is executed.

@kkthxbye-code I don't think that's accurate. See my other question #14718.

Anyway, in this example, full_clean does not make any difference, it still passes validation.

@kkthxbye-code
Copy link
Contributor

Anyway, in this example, full_clean does not make any difference, it still passes validation.

Regardless, being able to do something in nbshell has no bearing on how netbox is designed and as such should not be used as arguments in feature requests. nbshell and custom scripts are "power user" features, and requires knowledge of django to use.

@ITJamie
Copy link
Contributor

ITJamie commented Jan 8, 2024

this feels like it would be dependent on #7845

@jeremystretch
Copy link
Member

Netbox automatically turns it into a /32 for display.

Which is a subnet mask, albeit likely not the correct one for the IP address.

This discussion has run its course and we will not be making any changes.

@jeremystretch jeremystretch closed this as not planned Won't fix, can't repro, duplicate, stale Jan 8, 2024
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Apr 8, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
type: feature Introduction of new functionality to the application
Projects
None yet
Development

No branches or pull requests

4 participants