Skip to content

Commit

Permalink
Fixes #1620: Loosen IP address search filter to match all IPs that st…
Browse files Browse the repository at this point in the history
…art with the given string
  • Loading branch information
jeremystretch committed Oct 18, 2017
1 parent 6ae6209 commit 515645b
Showing 1 changed file with 4 additions and 6 deletions.
10 changes: 4 additions & 6 deletions netbox/ipam/filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -267,12 +267,10 @@ class Meta:
def search(self, queryset, name, value):
if not value.strip():
return queryset
qs_filter = Q(description__icontains=value)
try:
ipaddress = str(IPNetwork(value.strip()))
qs_filter |= Q(address__net_host=ipaddress)
except (AddrFormatError, ValueError):
pass
qs_filter = (
Q(description__icontains=value) |
Q(address__istartswith=value)
)
return queryset.filter(qs_filter)

def search_by_parent(self, queryset, name, value):
Expand Down

1 comment on commit 515645b

@oysteingy
Copy link

@oysteingy oysteingy commented on 515645b Nov 1, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi,
This does not appear to be working with IPv6.

(Pdb) nb.ipam.ip_addresses.filter('10.170.33')

(Lots of hits)

 (Pdb) nb.ipam.ip_addresses.filter(family=6)

(Lots of hits)

(Pdb) nb.ipam.ip_addresses.filter('EXISTING_TRUNCATED_IPV6_PREFIX')

(No hits)

It looks like nb.ipam.ip_addresses.filter is not able to lookup searches for existing IPv6 addresses either:

(Pdb) foo = nb.ipam.ip_addresses.filter(family=6)[0]
(Pdb) nb.ipam.ip_addresses.filter(foo)
[]

This works fine on 2.2.2, hence do I expect that this is somewhat related.

Please sign in to comment.