Add ipv4 /32 and ipv6 /128 prefix support #4931

Closed
opened 2025-12-29 19:22:22 +01:00 by adam · 11 comments
Owner

Originally created by @crafty-ua on GitHub (May 20, 2021).

Originally assigned to: @crafty-ua on GitHub.

NetBox version

v2.10.3

Feature type

Change to existing functionality

Proposed functionality

Add ipv4 /32 and ipv6 /128 prefix support

Use case

While testing netbox I've noticed that it does not allow user to create single-host networks. In my case I would like to use such feature to track end-user IP-unnumbered allocations while also keeping those /32 networks linked to a vlan

Database changes

No response

External dependencies

No response

Originally created by @crafty-ua on GitHub (May 20, 2021). Originally assigned to: @crafty-ua on GitHub. ### NetBox version v2.10.3 ### Feature type Change to existing functionality ### Proposed functionality Add ipv4 /32 and ipv6 /128 prefix support ### Use case While testing netbox I've noticed that it does not allow user to create single-host networks. In my case I would like to use such feature to track end-user IP-unnumbered allocations while also keeping those /32 networks linked to a vlan ### Database changes _No response_ ### External dependencies _No response_
adam added the status: acceptedtype: feature labels 2025-12-29 19:22:22 +01:00
adam closed this issue 2025-12-29 19:22:22 +01:00
Author
Owner

@jeremystretch commented on GitHub (May 20, 2021):

I think it makes sense to allow this. IIRC we prevented the use of /32 and /128 masks originally to prevent confusion with IP addresses, but that was a long time ago.

@jeremystretch commented on GitHub (May 20, 2021): I think it makes sense to allow this. IIRC we prevented the use of /32 and /128 masks originally to prevent confusion with IP addresses, but that was a long time ago.
Author
Owner

@crafty-ua commented on GitHub (May 20, 2021):

@jeremystretch
Cool. I wonder if you would like me to create some sort of initial PR to implement such behavior?

@crafty-ua commented on GitHub (May 20, 2021): @jeremystretch Cool. I wonder if you would like me to create some sort of initial PR to implement such behavior?
Author
Owner

@jeremystretch commented on GitHub (May 20, 2021):

@crafty-ua let's leave this open for a bit to gather feedback. If there's no opposition, then yes. We should just need to remove the validation rules that check for /32 and /128 prefix lengths on the Prefix model.

@jeremystretch commented on GitHub (May 20, 2021): @crafty-ua let's leave this open for a bit to gather feedback. If there's no opposition, then yes. We should just need to remove the validation rules that check for /32 and /128 prefix lengths on the Prefix model.
Author
Owner

@crafty-ua commented on GitHub (May 20, 2021):

Awesome!

// 219d24274f -- That PR might be useful

@crafty-ua commented on GitHub (May 20, 2021): Awesome! // https://github.com/netbox-community/netbox/pull/3396/commits/219d24274ffb3bdd7387252559a32e49470fbb3c -- That PR might be useful
Author
Owner

@jeremystretch commented on GitHub (May 25, 2021):

@crafty-ua assigned this to you. You're good to submit a PR. 👍

@jeremystretch commented on GitHub (May 25, 2021): @crafty-ua assigned this to you. You're good to submit a PR. :+1:
Author
Owner

@jeremystretch commented on GitHub (Jun 4, 2021):

@crafty-ua are you still interested in submitting a PR for this? If not, I can take it.

@jeremystretch commented on GitHub (Jun 4, 2021): @crafty-ua are you still interested in submitting a PR for this? If not, I can take it.
Author
Owner

@crafty-ua commented on GitHub (Jun 4, 2021):

@jeremystretch
Sure. Just returned from a short vacation today

@crafty-ua commented on GitHub (Jun 4, 2021): @jeremystretch Sure. Just returned from a short vacation today
Author
Owner

@crafty-ua commented on GitHub (Jun 4, 2021):

Pushed an initial PR fully based on code 219d242. Going to try running some tests in lab later on tomorrow

@crafty-ua commented on GitHub (Jun 4, 2021): Pushed an initial PR fully based on code 219d242. Going to try running some tests in lab later on tomorrow
Author
Owner

@crafty-ua commented on GitHub (Jun 5, 2021):

Seems that we might need to update NetHostContained function to looks something similar to

class NetHostContained(Lookup):
    """
    Check for the host portion of an IP address without regard to its mask. This allows us to find e.g. 192.0.2.1/24
    when specifying a parent prefix of 192.0.2.0/26.
    """
    lookup_name = 'net_host_contained'

    def as_sql(self, qn, connection):
        lhs, lhs_params = self.process_lhs(qn, connection)
        rhs, rhs_params = self.process_rhs(qn, connection)
        params = lhs_params + rhs_params
        #return 'CAST(HOST(%s) AS INET) << %s' % (lhs, rhs), params
        return 'CAST(HOST(%s) AS INET) <<= %s' % (lhs, rhs), params
@crafty-ua commented on GitHub (Jun 5, 2021): Seems that we might need to update NetHostContained function to looks something similar to ``` class NetHostContained(Lookup): """ Check for the host portion of an IP address without regard to its mask. This allows us to find e.g. 192.0.2.1/24 when specifying a parent prefix of 192.0.2.0/26. """ lookup_name = 'net_host_contained' def as_sql(self, qn, connection): lhs, lhs_params = self.process_lhs(qn, connection) rhs, rhs_params = self.process_rhs(qn, connection) params = lhs_params + rhs_params #return 'CAST(HOST(%s) AS INET) << %s' % (lhs, rhs), params return 'CAST(HOST(%s) AS INET) <<= %s' % (lhs, rhs), params ```
Author
Owner

@jeremystretch commented on GitHub (Jun 8, 2021):

I'm not sure; can a /32 IPv4 prefix actually contain an IP address? I'm open to opinions but IMO I think it's fine to leave as-is.

@jeremystretch commented on GitHub (Jun 8, 2021): I'm not sure; can a /32 IPv4 prefix actually contain an IP address? I'm open to opinions but IMO I think it's fine to leave as-is.
Author
Owner

@basti1508 commented on GitHub (Jun 23, 2021):

I'm not sure; can a /32 IPv4 prefix actually contain an IP address? I'm open to opinions but IMO I think it's fine to leave as-is.

This leads to inconsistent views.

  1. e.g. if you habe a /32 aggregate and create a /32 prefix in it, utilization shows 100% but 0 prefixes.
  2. A /32 Ip Address in a /32 Prefix will show 0% utilization.
  3. If you set unique IPs to true, IP-Address Tab on a /32 Prefix will tell you that you can create a new IP there, even if it exists already. (error on creation try);
@basti1508 commented on GitHub (Jun 23, 2021): > I'm not sure; can a /32 IPv4 prefix actually contain an IP address? I'm open to opinions but IMO I think it's fine to leave as-is. This leads to inconsistent views. 1. e.g. if you habe a /32 aggregate and create a /32 prefix in it, utilization shows 100% but 0 prefixes. 2. A /32 Ip Address in a /32 Prefix will show 0% utilization. 2. If you set unique IPs to true, IP-Address Tab on a /32 Prefix will tell you that you can create a new IP there, even if it exists already. (error on creation try);
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#4931