Divert icon indicating copy to clipboard operation
Divert copied to clipboard

Bitwise operators not supported?

Open oriolarcas opened this issue 4 years ago • 3 comments

I was trying to implement filters for IP network masks, and it seems that bitwise AND or OR operators are not supported. It came as a surprise, since I think this should be relatively straightforward to implement (new "&" and "|" bitwise operators) and would be a valuable feature.

Is it already implemented and I got it wrong? Otherwise, is there a workaround, besides doing it in userspace? I'd be happy to work on a PR if needed.

Great project, congratulations anyway!

oriolarcas avatar Jan 15 '21 17:01 oriolarcas

I see that this was suggested in issue https://github.com/basil00/Divert/issues/52#issuecomment-495427033:

Would be nice if we could get bitwise operations in the filter language &, |, ^, ~, at minimum bitwise and would be super useful and far more efficient and and uniformly distributed.

oriolarcas avatar Jan 15 '21 17:01 oriolarcas

In case somebody else is looking into this, finally I will be using the comparison operators "<=" and ">=" to check IP network ranges.

E.g., to check for 192.168.1.0/24, I will use the filter:

ip.DstAddr >= 192.168.1.0 and ip.DstAddr <= 192.168.1.255

oriolarcas avatar Jan 18 '21 16:01 oriolarcas

No, bitwise or other operators are not supported, and I agree this would be a nice addition to the filter language. I can keep this open as a feature request, but it would take some effort to implement, so might not added for a while.

basil00 avatar Jan 25 '21 13:01 basil00