drkjam/netaddr — pull request #55 by akgood (2013-07-15 22:15:47+00:00)
Title: Rel 0.7.x

`smallest_matching_cidr()` and `all_matching_cidrs()` will not always produce the correct result. Say you have a list:

nets = ['0.0.0.0/0', '10.0.0.0/8', '192.168.0.0/16']

then, if you call

netaddr.smallest_matching_cidr('192.168.0.1', nets)

you will get back '0.0.0.0/0', rather than '192.168.0.0/16'. Once `smallest_matching_cidr()` and `all_matching_cidrs()` find *any* match, they will abort their loops and return a value as soon as they find any subsequent non-matching IP range.

Instead, we need to ensure that no further matches can possibly exist in the list; we should be able to do this by checking to see if the non-matching range we're testing is *outside* the smallest range we've found so far.