| 82 | var errMatch = errors.New("match") |
| 83 | |
| 84 | func (c *CIDRMatch) Call(args []super.Value) super.Value { |
| 85 | maskVal := args[0].Under() |
| 86 | if maskVal.IsNull() || args[1].IsNull() { |
| 87 | return super.Null |
| 88 | } |
| 89 | if maskVal.Type() != super.TypeNet { |
| 90 | return c.sctx.WrapError("cidr_match: not a net", maskVal) |
| 91 | } |
| 92 | prefix := super.DecodeNet(maskVal.Bytes()) |
| 93 | err := args[1].Walk(func(typ super.Type, body scode.Bytes) error { |
| 94 | if typ.ID() == super.IDIP { |
| 95 | if prefix.Contains(super.DecodeIP(body)) { |
| 96 | return errMatch |
| 97 | } |
| 98 | } |
| 99 | return nil |
| 100 | }) |
| 101 | return super.NewBool(err == errMatch) |
| 102 | } |