mjschultz / py-radix

Python radix tree implementation for IPv4 and IPv6 prefix matching.
Other
119 stars 37 forks source link

seemingly broken behavior with search_covered() #23

Closed crustymonkey closed 8 years ago

crustymonkey commented 8 years ago

Below is a quick test/results that look like broken search_covered behavior. This is after building py-radix using the following:

cd py-radix-0.9.3
python setup.py build
cd 
build/lib.linux-x86_64-2.7/

search_covered in [6] should return an empty list. Note that search_covering will return the correct nodes.

$ ipython
Python 2.7.10 (default, Oct 14 2015, 16:09:02) 
Type "copyright", "credits" or "license" for more information.

IPython 2.3.0 -- An enhanced Interactive Python.
?         -> Introduction and overview of IPython's features.
%quickref -> Quick reference.
help      -> Python's own help system.
object?   -> Details about 'object', use 'object??' for extra details.

In [1]: from radix import Radix

In [2]: r = Radix()

In [3]: r.add('10.0.0.0/24')
Out[3]: <_radix.RadixNode at 0x7f623fd630c0>

In [4]: r.add('0.0.0.0/0')
Out[4]: <_radix.RadixNode at 0x7f623fd63c90>

In [5]: r.search_covered('10.0.0.1')
Out[5]: [<_radix.RadixNode at 0x7f623fd630c0>]

In [6]: r.search_covered('10.0.0.1')[0].prefix
Out[6]: '10.0.0.0/24'
crustymonkey commented 8 years ago

It looks like this is specifically an issue with the C implementation. If I use the pure Python version, it works as expected (as far as I've tested to this point).

Edsall commented 8 years ago

I have just seen the same problem. It seems to be related to the 0/0 entry.

I have - r.add("192.168.1.133/32") r.add("0.0.0.0/0") r.search_covered returns both.

If I do - r.add("192.168.1.133/32") Then r.search_covered returns an empty set.

I am not sure if I am using C or pure Python version.

sorc1 commented 8 years ago

It's a bug in the C implementation. I'll fix it soon.

sorc1 commented 8 years ago

I've created pull request 24. Please check if it works as expected.

crustymonkey commented 8 years ago

I updated the pull request with this comment already. I can no longer repro the issue after patching so it looks like this change fixes the problem.

mjschultz commented 8 years ago

Thanks for the report; there should now be a py-radix==0.9.4 with the fix available in PyPI.