Skip to content

Commit 0e01b21

Browse files
authored
✨ ip.cidr, ip.address and raw IP storage (#5292)
* ✨ ip.cidr and raw IP storage Signed-off-by: Dominik Richter <dominik.richter@gmail.com> * 🧹 rename mask -> prefixlength Signed-off-by: Dominik Richter <dominik.richter@gmail.com> * 🧹 expand int2ip types Signed-off-by: Dominik Richter <dominik.richter@gmail.com> * 🐛 print CIDR of IP by default Signed-off-by: Dominik Richter <dominik.richter@gmail.com> * 🐎 more efficient bitmask generator Signed-off-by: Dominik Richter <dominik.richter@gmail.com> * 📃 clarify IP internal vars Signed-off-by: Dominik Richter <dominik.richter@gmail.com> * ✨ add ip.address Signed-off-by: Dominik Richter <dominik.richter@gmail.com> * 🔨 switch from manual to proto-based IP marshaling Signed-off-by: Dominik Richter <dominik.richter@gmail.com> * 🧹 remove those unnecessary types Signed-off-by: Dominik Richter <dominik.richter@gmail.com> * 🧹 split up test for data conversion Signed-off-by: Dominik Richter <dominik.richter@gmail.com> --------- Signed-off-by: Dominik Richter <dominik.richter@gmail.com>
1 parent 76b4300 commit 0e01b21

File tree

15 files changed

+475
-146
lines changed

15 files changed

+475
-146
lines changed

cli/printer/mql.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -787,7 +787,7 @@ func (print *Printer) Data(typ types.Type, data interface{}, codeID string, bund
787787
return print.Secondary(data.(string))
788788

789789
case types.IP:
790-
return print.Secondary(data.(string))
790+
return print.Secondary(data.(llx.RawIP).String())
791791

792792
case types.ArrayLike:
793793
if data == nil {

llx/builtin.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -596,13 +596,15 @@ func init() {
596596
string("!=" + types.Empty): {f: stringNotEmptyV2, Label: "!="},
597597
string("==" + types.IP): {f: ipCmpIP, Label: "=="},
598598
string("!=" + types.IP): {f: ipNotIP, Label: "!="},
599-
"version": {f: ipVersion},
600-
"subnet": {f: ipSubnet},
599+
"address": {f: ipAddress},
600+
"cidr": {f: ipCIDR},
601+
"inRange": {f: ipInRange},
602+
"isUnspecified": {f: ipUnspecified},
601603
"prefix": {f: ipPrefix},
602604
"prefixLength": {f: ipPrefixLength},
605+
"subnet": {f: ipSubnet},
603606
"suffix": {f: ipSuffix},
604-
"isUnspecified": {f: ipUnspecified},
605-
"inRange": {f: ipInRange, Label: "inRange"},
607+
"version": {f: ipVersion},
606608
},
607609
types.ArrayLike: {
608610
"[]": {f: arrayGetIndexV2},

llx/builtin_global.go

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -272,17 +272,11 @@ func ipCall(e *blockExecutor, f *Function, ref uint64) (*RawData, uint64, error)
272272
return res, dref, err
273273
}
274274

275-
raw, ok := res.Value.(string)
276-
if ok {
277-
return IPData(raw), 0, nil
278-
}
279-
280-
rawInt, ok := res.Value.(int64)
281-
if ok {
282-
return IPData(int2ip(rawInt)), 0, nil
275+
ip, ok := any2ip(res.Value)
276+
if !ok {
277+
return nil, 0, errors.New("called `ip` with unsupported type (expected string, int or IP)")
283278
}
284-
285-
return nil, 0, errors.New("called `ip` with unsupported type (expected string or int)")
279+
return IPData(ip), 0, nil
286280
}
287281

288282
func stringCall(e *blockExecutor, f *Function, ref uint64) (*RawData, uint64, error) {

0 commit comments

Comments
 (0)