From 1da88cc8884d036c50aa60887f146500ee48d482 Mon Sep 17 00:00:00 2001 From: Paul Donald Date: Thu, 30 Oct 2025 18:53:14 +0100 Subject: [PATCH] luci-base: fix static proto trace-back when a netmask is set but no IP is set A trace-back is produced when a netmask is set, and the contents of the IPv4 address field are removed or otherwise unset. Signed-off-by: Paul Donald --- .../luci-static/resources/protocol/static.js | 36 ++++++++++++------- 1 file changed, 24 insertions(+), 12 deletions(-) diff --git a/modules/luci-base/htdocs/luci-static/resources/protocol/static.js b/modules/luci-base/htdocs/luci-static/resources/protocol/static.js index 7eb115bd53..bf8684951e 100644 --- a/modules/luci-base/htdocs/luci-static/resources/protocol/static.js +++ b/modules/luci-base/htdocs/luci-static/resources/protocol/static.js @@ -8,26 +8,38 @@ function isCIDR(value) { } function calculateBroadcast(s, use_cfgvalue) { - var readfn = use_cfgvalue ? 'cfgvalue' : 'formvalue', - addropt = s.children.filter(function(o) { return o.option == 'ipaddr'})[0], - addrvals = addropt ? L.toArray(addropt[readfn](s.section)) : [], - maskopt = s.children.filter(function(o) { return o.option == 'netmask'})[0], - maskval = maskopt ? maskopt[readfn](s.section) : null, - firstsubnet = maskval ? addrvals[0] + '/' + maskval : addrvals.filter(function(a) { return a.indexOf('/') > 0 })[0]; - - if (firstsubnet == null) + const readfn = use_cfgvalue ? 'cfgvalue' : 'formvalue'; + const addropt = s.children.find(o => o.option == 'ipaddr'); + const addrvals = addropt ? L.toArray(addropt[readfn](s.section)) : []; + const maskopt = s.children.find(o => o.option == 'netmask'); + const maskval = maskopt ? maskopt[readfn](s.section) : null; + let firstsubnet = null; + + /* only form a subnet if both parts exist */ + if (addrvals.length && addrvals[0] && maskval) + firstsubnet = addrvals[0] + '/' + maskval; + else if (addrvals.length) + firstsubnet = addrvals.find(a => a.indexOf('/') > 0); + + if (!firstsubnet) return null; - var addr_mask = firstsubnet.split('/'), - addr = validation.parseIPv4(addr_mask[0]), - mask = addr_mask[1]; + const [addr_str, mask_str] = firstsubnet.split('/'); + const addr = validation.parseIPv4(addr_str); + if (!addr) + return null; + + let mask = mask_str; if (!isNaN(mask)) mask = validation.parseIPv4(network.prefixToMask(+mask)); else mask = validation.parseIPv4(mask); - var bc = [ + if (!mask) + return null; + + const bc = [ addr[0] | (~mask[0] >>> 0 & 255), addr[1] | (~mask[1] >>> 0 & 255), addr[2] | (~mask[2] >>> 0 & 255), -- 2.30.2