If IP address object exists, mark a prefix as allocated/unavailable #3780

Closed
opened 2025-12-29 18:31:11 +01:00 by adam · 3 comments
Owner

Originally created by @garretwest on GitHub (Jun 12, 2020).

Environment

  • Python version: 3.7.4
  • NetBox version: 2.8.5

Proposed Functionality

As it stands, an IP address can be created without requiring it to belong to a parent prefix. This results in potentially bad data integrity.

An IP address object can be created, and a full prefix which includes the address will still show as Available in the Prefixes list.
addresses_active

prefix_available_addresses_assigned

This leads to prefixes being allocated where there may already be existing IP addresses, meaning that prefix is not actually available for use. In this instance, one would not simply be able to allocate the next available prefix with absolute certainty that it's not in use in Netbox, and must be cross-referenced in the IP Addresses tab to be sure.

I propose that if an IP address exists, that the Available status be removed from the prefix list for that portion of the prefix. Alternatively, it could be required to link an IP address to a parent prefix, or the prefix could be created based on the mask of the IP address object, if it doesn't exist already.

Use Case

Take 10.250.1.0/24 from the screenshots above, for example. If 10.250.1.1, 10.250.1.2, and 10.250.1.3 are already allocated from the prefix, then the /24 could be broken up into something smaller that does not include the allocated IP addresses.

So this would be broken up into:
10.250.1.4/30
10.250.1.8/29
10.250.1.16/28
10.250.1.32/27
10.250.1.64/26
10.250.1.128/25

These prefixes are all completely available as they do not have IP addresses allocated, and you could rely on the next available prefix function to ensure there aren't used addresses. I understand this creates a lot of small prefixes this way, but that is the unfortunate reality when someone carves IP addresses out of prefixes that don't exist.

Originally created by @garretwest on GitHub (Jun 12, 2020). <!-- NOTE: IF YOUR ISSUE DOES NOT FOLLOW THIS TEMPLATE, IT WILL BE CLOSED. This form is only for proposing specific new features or enhancements. If you have a general idea or question, please post to our mailing list instead of opening an issue: https://groups.google.com/forum/#!forum/netbox-discuss NOTE: Due to an excessive backlog of feature requests, we are not currently accepting any proposals which significantly extend NetBox's feature scope. Please describe the environment in which you are running NetBox. Be sure that you are running an unmodified instance of the latest stable release before submitting a bug report. --> ### Environment * Python version: 3.7.4 * NetBox version: 2.8.5 <!-- Describe in detail the new functionality you are proposing. Include any specific changes to work flows, data models, or the user interface. --> ### Proposed Functionality As it stands, an IP address can be created without requiring it to belong to a parent prefix. This results in potentially bad data integrity. An IP address object can be created, and a full prefix which includes the address will still show as **Available** in the Prefixes list. ![addresses_active](https://user-images.githubusercontent.com/29845853/84522257-859c3b80-ac93-11ea-92e9-61b474c9d217.png) ![prefix_available_addresses_assigned](https://user-images.githubusercontent.com/29845853/84219874-af384580-aa8e-11ea-99ef-e80e015f01d6.png) This leads to prefixes being allocated where there may already be existing IP addresses, meaning that prefix is not actually available for use. In this instance, one would not simply be able to allocate the next available prefix with absolute certainty that it's not in use in Netbox, and must be cross-referenced in the IP Addresses tab to be sure. I propose that if an IP address exists, that the **Available** status be removed from the prefix list for that portion of the prefix. Alternatively, it could be required to link an IP address to a parent prefix, or the prefix could be created based on the mask of the IP address object, if it doesn't exist already. <!-- Convey an example use case for your proposed feature. Write from the perspective of a NetBox user who would benefit from the proposed functionality and describe how. ---> ### Use Case Take 10.250.1.0/24 from the screenshots above, for example. If 10.250.1.1, 10.250.1.2, and 10.250.1.3 are already allocated from the prefix, then the /24 could be broken up into something smaller that does not include the allocated IP addresses. So this would be broken up into: 10.250.1.4/30 10.250.1.8/29 10.250.1.16/28 10.250.1.32/27 10.250.1.64/26 10.250.1.128/25 These prefixes are all completely available as they do not have IP addresses allocated, and you could rely on the next available prefix function to ensure there aren't used addresses. I understand this creates a lot of small prefixes this way, but that is the unfortunate reality when someone carves IP addresses out of prefixes that don't exist.
adam closed this issue 2025-12-29 18:31:11 +01:00
Author
Owner

@jeremystretch commented on GitHub (Jun 12, 2020):

This approach does not work in practice: There are simply too many variables and NetBox cannot possibly anticipate what the user intends when adding an IP address without a parent prefix, including what the parent prefix should actually be. Thus, the creation of prefixes is left to the user.

@jeremystretch commented on GitHub (Jun 12, 2020): This approach does not work in practice: There are simply too many variables and NetBox cannot possibly anticipate what the user intends when adding an IP address without a parent prefix, including what the parent prefix should actually be. Thus, the creation of prefixes is left to the user.
Author
Owner

@garretwest commented on GitHub (Jun 12, 2020):

What do you mean? The IP address object has a mask itself. The intention is right in the IP address object, whether /32, /24, /19, etc.

@garretwest commented on GitHub (Jun 12, 2020): What do you mean? The IP address object has a mask itself. The intention is right in the IP address object, whether /32, /24, /19, etc.
Author
Owner

@jsenecal commented on GitHub (Jun 14, 2020):

@garretwest, I believe that @jeremystretch means that, whilst we could infer the potential parent prefix from an IPAddress that has a mask that doesn't fit what is currently in the DB, there are too many other things to consider when creating said prefix. Thus, prefix creation is intended to be done "on purpose" rather than automagically.

In that case, one should actually create a container or reserved prefix to hold these /32s.

@jsenecal commented on GitHub (Jun 14, 2020): @garretwest, I believe that @jeremystretch means that, whilst we could infer the potential parent prefix from an `IPAddress` that has a mask that doesn't fit what is currently in the DB, there are too many other things to consider when creating said prefix. Thus, prefix creation is intended to be done "on purpose" rather than _automagically_. In that case, one should actually create a container or reserved prefix to hold these /32s.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#3780