summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJo-Philipp Wich2022-05-20 10:34:54 +0000
committerJo-Philipp Wich2022-05-20 10:34:54 +0000
commitc22eeeff1ef0884fd3c76f4ff2c72caa9de82fd5 (patch)
tree8a5b2a6d21441cbb99309a85e213c5250055876d
parent628d7917ea03a24de43a35fd90894cf8d5d62dc0 (diff)
downloadfirewall4-c22eeeff1ef0884fd3c76f4ff2c72caa9de82fd5.tar.gz
fw4: support negative CIDR bit notation
Add support for CIDR notation with a negative bit count to be compatible with firewall3. Signed-off-by: Jo-Philipp Wich <jo@mein.io>
-rw-r--r--root/usr/share/ucode/fw4.uc11
1 files changed, 8 insertions, 3 deletions
diff --git a/root/usr/share/ucode/fw4.uc b/root/usr/share/ucode/fw4.uc
index 7ea8bc3..cfef69c 100644
--- a/root/usr/share/ucode/fw4.uc
+++ b/root/usr/share/ucode/fw4.uc
@@ -131,14 +131,19 @@ const dscp_classes = {
};
function to_mask(bits, v6) {
- let m = [];
+ let m = [], n = false;
- if (bits < 0 || bits > (v6 ? 128 : 32))
+ if (bits < 0) {
+ n = true;
+ bits = -bits;
+ }
+
+ if (bits > (v6 ? 128 : 32))
return null;
for (let i = 0; i < (v6 ? 16 : 4); i++) {
let b = (bits < 8) ? bits : 8;
- m[i] = (0xff << (8 - b)) & 0xff;
+ m[i] = (n ? ~(0xff << (8 - b)) : (0xff << (8 - b))) & 0xff;
bits -= b;
}