Divert
Divert copied to clipboard
Bitwise operators not supported?
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!
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.
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
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.