luci-base: network.js: dynamically calculate IPv4 netmasks
authorJo-Philipp Wich <jo@mein.io>
Sun, 7 Jul 2019 18:12:42 +0000 (20:12 +0200)
committerJo-Philipp Wich <jo@mein.io>
Sun, 7 Jul 2019 18:12:42 +0000 (20:12 +0200)
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
modules/luci-base/htdocs/luci-static/resources/network.js

index 1f66c6ff9bcc1eabd7083c8387c4aafdd8072c5c..19640604e460ca2ab1b13c57840e17767fbc64ab 100644 (file)
@@ -1253,43 +1253,8 @@ Protocol = L.Class.extend({
 
        getNetmask: function() {
                var addrs = this._ubus('ipv4-address');
-               if (Array.isArray(addrs) && addrs.length) {
-                       switch (addrs[0].mask) {
-                       case  0: return '0.0.0.0';
-                       case  1: return '128.0.0.0';
-                       case  2: return '192.0.0.0';
-                       case  3: return '224.0.0.0';
-                       case  4: return '240.0.0.0';
-                       case  5: return '248.0.0.0';
-                       case  6: return '252.0.0.0';
-                       case  7: return '254.0.0.0';
-                       case  8: return '255.0.0.0';
-                       case  9: return '255.128.0.0';
-                       case 10: return '255.192.0.0';
-                       case 11: return '255.224.0.0';
-                       case 12: return '255.240.0.0';
-                       case 13: return '255.248.0.0';
-                       case 14: return '255.252.0.0';
-                       case 15: return '255.254.0.0';
-                       case 16: return '255.255.0.0';
-                       case 17: return '255.255.128.0';
-                       case 18: return '255.255.192.0';
-                       case 19: return '255.255.224.0';
-                       case 20: return '255.255.240.0';
-                       case 21: return '255.255.248.0';
-                       case 22: return '255.255.252.0';
-                       case 23: return '255.255.254.0';
-                       case 24: return '255.255.255.0';
-                       case 25: return '255.255.255.128';
-                       case 26: return '255.255.255.192';
-                       case 27: return '255.255.255.224';
-                       case 28: return '255.255.255.240';
-                       case 29: return '255.255.255.248';
-                       case 30: return '255.255.255.252';
-                       case 31: return '255.255.255.254';
-                       case 32: return '255.255.255.255';
-                       }
-               }
+               if (Array.isArray(addrs) && addrs.length)
+                       return prefixToMask(addrs[0].mask, false);
        },
 
        getGatewayAddr: function() {