[Bug?] Error when browsing IP addresses from a prefix page #355

Closed
opened 2025-12-29 16:21:14 +01:00 by adam · 7 comments
Owner

Originally created by @LordBoBCUP on GitHub (Aug 12, 2016).

If I search for an IP from the search box on the front page, then select its parent prefix and select the IP address tab I get an error thrown. Outside valid IP address boundary! I have just upgraded to v1.5.1 directly from v1.4.0 Traceback is below.

Traceback:

File "/usr/local/lib/python2.7/dist-packages/django/core/handlers/exception.py" in inner

  1.         response = get_response(request)
    

File "/usr/local/lib/python2.7/dist-packages/django/core/handlers/base.py" in _legacy_get_response

  1.         response = self._get_response(request)
    

File "/usr/local/lib/python2.7/dist-packages/django/core/handlers/base.py" in _get_response

  1.             response = self.process_exception_by_middleware(e, request)
    

File "/usr/local/lib/python2.7/dist-packages/django/core/handlers/base.py" in _get_response

  1.             response = wrapped_callback(request, _callback_args, *_callback_kwargs)
    

File "/opt/netbox-1.5.1/netbox/ipam/views.py" in prefix_ipaddresses

  1. ipaddresses = add_available_ipaddresses(prefix.prefix, ipaddresses)
    

File "/opt/netbox-1.5.1/netbox/ipam/views.py" in add_available_ipaddresses

  1.         diff = int(ip.address.ip - prev_ip.address.ip)
    

File "/usr/local/lib/python2.7/dist-packages/netaddr/ip/init.py" in sub

  1.     new_value = int(self._value - num)
    

File "/usr/local/lib/python2.7/dist-packages/netaddr/ip/init.py" in rsub

  1.     raise IndexError('result outside valid IP address boundary!')
    

Exception Type: IndexError at /ipam/prefixes/1/ip-addresses/
Exception Value: result outside valid IP address boundary!

Originally created by @LordBoBCUP on GitHub (Aug 12, 2016). If I search for an IP from the search box on the front page, then select its parent prefix and select the IP address tab I get an error thrown. Outside valid IP address boundary! I have just upgraded to v1.5.1 directly from v1.4.0 Traceback is below. Traceback: File "/usr/local/lib/python2.7/dist-packages/django/core/handlers/exception.py" in inner 1. response = get_response(request) File "/usr/local/lib/python2.7/dist-packages/django/core/handlers/base.py" in _legacy_get_response 1. response = self._get_response(request) File "/usr/local/lib/python2.7/dist-packages/django/core/handlers/base.py" in _get_response 1. response = self.process_exception_by_middleware(e, request) File "/usr/local/lib/python2.7/dist-packages/django/core/handlers/base.py" in _get_response 1. response = wrapped_callback(request, _callback_args, *_callback_kwargs) File "/opt/netbox-1.5.1/netbox/ipam/views.py" in prefix_ipaddresses 1. ipaddresses = add_available_ipaddresses(prefix.prefix, ipaddresses) File "/opt/netbox-1.5.1/netbox/ipam/views.py" in add_available_ipaddresses 1. diff = int(ip.address.ip - prev_ip.address.ip) File "/usr/local/lib/python2.7/dist-packages/netaddr/ip/**init**.py" in **sub** 1. new_value = int(self._value - num) File "/usr/local/lib/python2.7/dist-packages/netaddr/ip/**init**.py" in **rsub** 1. raise IndexError('result outside valid IP address boundary!') Exception Type: IndexError at /ipam/prefixes/1/ip-addresses/ Exception Value: result outside valid IP address boundary!
adam added the type: bug label 2025-12-29 16:21:14 +01:00
adam closed this issue 2025-12-29 16:21:14 +01:00
Author
Owner

@jeremystretch commented on GitHub (Aug 12, 2016):

Can you provide a list of the IPs defined in that prefix? You can try looking through the admin UI, or run ./manage.py shell and paste in this code (replacing "192.168.0.0/24" with the affected prefix):

from ipam.models import *
for ip in IPAddress.objects.filter(address__net_contained='192.168.0.0/24'):
    print(ip)
@jeremystretch commented on GitHub (Aug 12, 2016): Can you provide a list of the IPs defined in that prefix? You can try looking through the admin UI, or run `./manage.py shell` and paste in this code (replacing "192.168.0.0/24" with the affected prefix): ``` from ipam.models import * for ip in IPAddress.objects.filter(address__net_contained='192.168.0.0/24'): print(ip) ```
Author
Owner

@LordBoBCUP commented on GitHub (Aug 13, 2016):

Hi Jeremy,

The shell returned :
10.59.218.129/27
10.59.218.131/27
10.59.218.134/27
10.59.218.137/27
10.59.218.138/27
10.59.218.143/27
10.59.218.145/27
10.59.218.146/27
10.59.218.147/27
10.59.218.148/27
10.59.218.149/27
10.59.218.150/27
10.59.218.151/27
10.59.218.152/27
10.59.218.156/27
10.59.218.157/27

@LordBoBCUP commented on GitHub (Aug 13, 2016): Hi Jeremy, The shell returned : 10.59.218.129/27 10.59.218.131/27 10.59.218.134/27 10.59.218.137/27 10.59.218.138/27 10.59.218.143/27 10.59.218.145/27 10.59.218.146/27 10.59.218.147/27 10.59.218.148/27 10.59.218.149/27 10.59.218.150/27 10.59.218.151/27 10.59.218.152/27 10.59.218.156/27 10.59.218.157/27
Author
Owner

@jeremystretch commented on GitHub (Aug 13, 2016):

What's the parent prefix? 10.59.218.128/27?

@jeremystretch commented on GitHub (Aug 13, 2016): What's the parent prefix? 10.59.218.128/27?
Author
Owner

@LordBoBCUP commented on GitHub (Aug 13, 2016):

Parent is 10.59.218.128/26

@LordBoBCUP commented on GitHub (Aug 13, 2016): Parent is 10.59.218.128/26
Author
Owner

@jeremystretch commented on GitHub (Aug 13, 2016):

This bug seems to occur when you have one or more IPs define with differing mask lengths. Try searching for all IPs within the /26 (/ipam/ip-addresses/?parent=10.59.218.157%2F26) and you'll probably find one or more with a /26 mask. (If the parent is a /26, they're probably all supposed to have a /26 mask).

The error triggers because the IPs with larger masks are sorted before those with smaller masks. Not sure why that is, but I'll dig into it. In the interim, you should be able to work around it by adjusting the mask for all IPs in the prefix to match.

Also, the query I gave you above is incorrect. It should have been the following (which will include any /26 IPs):

from ipam.models import *
for ip in IPAddress.objects.filter(address__net_contained_or_equal='192.168.0.0/24'):
    print(ip)
@jeremystretch commented on GitHub (Aug 13, 2016): This bug seems to occur when you have one or more IPs define with differing mask lengths. Try searching for all IPs within the /26 (`/ipam/ip-addresses/?parent=10.59.218.157%2F26`) and you'll probably find one or more with a /26 mask. (If the parent is a /26, they're probably all supposed to have a /26 mask). The error triggers because the IPs with larger masks are sorted before those with smaller masks. Not sure why that is, but I'll dig into it. In the interim, you should be able to work around it by adjusting the mask for all IPs in the prefix to match. Also, the query I gave you above is incorrect. It should have been the following (which will include any /26 IPs): ``` from ipam.models import * for ip in IPAddress.objects.filter(address__net_contained_or_equal='192.168.0.0/24'): print(ip) ```
Author
Owner

@LordBoBCUP commented on GitHub (Aug 13, 2016):

Thanks Jeremy, looks like I got sucked in by excel's fill down function auto-incrementing and missed it when I bulk imported from yes our current excel sheets. Swapped them to the /26 mask and the steps to cause the error longer result in an error and work as expected.

@LordBoBCUP commented on GitHub (Aug 13, 2016): Thanks Jeremy, looks like I got sucked in by excel's fill down function auto-incrementing and missed it when I bulk imported from yes our current excel sheets. Swapped them to the /26 mask and the steps to cause the error longer result in an error and work as expected.
Author
Owner

@jeremystretch commented on GitHub (Aug 15, 2016):

So, after casting an IP address using HOST() PostgreSQL treats it as text, which destroys the ordering logic. The solution (or at least a solution) is to re-cast the value back to its original form using INET(). This effectively removes the prefix length and treats each IP as a /32 or /128.

@jeremystretch commented on GitHub (Aug 15, 2016): So, after casting an IP address using `HOST()` PostgreSQL treats it as text, which destroys the ordering logic. The solution (or at least _a_ solution) is to re-cast the value back to its original form using `INET()`. This effectively removes the prefix length and treats each IP as a /32 or /128.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#355