Skip to content

Commit

Permalink
convert absolute IP lookups to CIDR
Browse files Browse the repository at this point in the history
  • Loading branch information
Christos Vontas committed Nov 20, 2017
1 parent 8b9fd97 commit 6d1862d
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion search/query/ip_range.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,20 @@ func (q *IPRangeQuery) Field() string {
func (q *IPRangeQuery) Searcher(i index.IndexReader, m mapping.IndexMapping, options search.SearcherOptions) (search.Searcher, error) {
_, ipNet, err := net.ParseCIDR(q.CIDRVal)
if err != nil {
return nil, err
isIP := net.ParseIP(q.CIDRVal)
if isIP == nil {
return nil, err
}

if isIP.DefaultMask() != nil {
q.CIDRVal = q.CIDRVal + `/32`
} else {
q.CIDRVal = q.CIDRVal + `/128`
}
_, ipNet, err = net.ParseCIDR(q.CIDRVal)
if err != nil {
return nil, err
}
}
cq := ipRangeToConjuctionQuery(q.FieldVal, ipNet)
return cq.Searcher(i, m, options)
Expand Down

0 comments on commit 6d1862d

Please sign in to comment.