luci-mod-status: fix sporadic logical interfaces resolve failures
authorJo-Philipp Wich <[email protected]>
Mon, 4 Mar 2024 22:54:24 +0000 (23:54 +0100)
committerJo-Philipp Wich <[email protected]>
Mon, 4 Mar 2024 22:58:21 +0000 (23:58 +0100)
Correct the incorrect netmask calculation logic leading to incorrect
network range comparisons in some cases.

Fixes: #6956
Signed-off-by: Jo-Philipp Wich <[email protected]>
modules/luci-mod-status/htdocs/luci-static/resources/view/status/routes.js

index 1f62321e3c476a78f8a2794486a45be56b81210d..37bb91f7150067a7f9846fd3d1eac8951443e29d 100644 (file)
@@ -13,13 +13,15 @@ var callNetworkInterfaceDump = rpc.declare({
 
 function applyMask(addr, mask, v6) {
        var words = v6 ? validation.parseIPv6(addr) : validation.parseIPv4(addr);
+       var bword = v6 ? 0xffff : 0xff;
+       var bwlen = v6 ? 16 : 8;
 
        if (!words || mask < 0 || mask > (v6 ? 128 : 32))
                return null;
 
        for (var i = 0; i < words.length; i++) {
-               var b = Math.min(mask, v6 ? 16 : 8);
-               words[i] &= ((1 << b) - 1);
+               var b = Math.min(mask, bwlen);
+               words[i] &= (bword << (bwlen - b)) & bword;
                mask -= b;
        }