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

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

Closed
LordBoBCUP opened this issue Aug 12, 2016 · 7 comments
Closed

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

LordBoBCUP opened this issue Aug 12, 2016 · 7 comments
Labels
type: bug A confirmed report of unexpected behavior in the application

Comments

@LordBoBCUP
Copy link

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!

@jeremystretch
Copy link
Member

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 jeremystretch added the type: bug A confirmed report of unexpected behavior in the application label Aug 12, 2016
@LordBoBCUP
Copy link
Author

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

@jeremystretch
Copy link
Member

What's the parent prefix? 10.59.218.128/27?

@LordBoBCUP
Copy link
Author

Parent is 10.59.218.128/26

@jeremystretch
Copy link
Member

jeremystretch commented 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)

@LordBoBCUP
Copy link
Author

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.

@jeremystretch
Copy link
Member

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.

if-fi pushed a commit to if-fi/netbox that referenced this issue Oct 1, 2016
if-fi pushed a commit to if-fi/netbox that referenced this issue Oct 1, 2016
@lock lock bot locked as resolved and limited conversation to collaborators Jan 19, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
type: bug A confirmed report of unexpected behavior in the application
Projects
None yet
Development

No branches or pull requests

2 participants