Skip to content

Commit 1da88cc

Browse files
committed
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 <[email protected]>
1 parent 7722292 commit 1da88cc

File tree

1 file changed

+24
-12
lines changed
  • modules/luci-base/htdocs/luci-static/resources/protocol

1 file changed

+24
-12
lines changed

modules/luci-base/htdocs/luci-static/resources/protocol/static.js

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,26 +8,38 @@ function isCIDR(value) {
88
}
99

1010
function calculateBroadcast(s, use_cfgvalue) {
11-
var readfn = use_cfgvalue ? 'cfgvalue' : 'formvalue',
12-
addropt = s.children.filter(function(o) { return o.option == 'ipaddr'})[0],
13-
addrvals = addropt ? L.toArray(addropt[readfn](s.section)) : [],
14-
maskopt = s.children.filter(function(o) { return o.option == 'netmask'})[0],
15-
maskval = maskopt ? maskopt[readfn](s.section) : null,
16-
firstsubnet = maskval ? addrvals[0] + '/' + maskval : addrvals.filter(function(a) { return a.indexOf('/') > 0 })[0];
17-
18-
if (firstsubnet == null)
11+
const readfn = use_cfgvalue ? 'cfgvalue' : 'formvalue';
12+
const addropt = s.children.find(o => o.option == 'ipaddr');
13+
const addrvals = addropt ? L.toArray(addropt[readfn](s.section)) : [];
14+
const maskopt = s.children.find(o => o.option == 'netmask');
15+
const maskval = maskopt ? maskopt[readfn](s.section) : null;
16+
let firstsubnet = null;
17+
18+
/* only form a subnet if both parts exist */
19+
if (addrvals.length && addrvals[0] && maskval)
20+
firstsubnet = addrvals[0] + '/' + maskval;
21+
else if (addrvals.length)
22+
firstsubnet = addrvals.find(a => a.indexOf('/') > 0);
23+
24+
if (!firstsubnet)
1925
return null;
2026

21-
var addr_mask = firstsubnet.split('/'),
22-
addr = validation.parseIPv4(addr_mask[0]),
23-
mask = addr_mask[1];
27+
const [addr_str, mask_str] = firstsubnet.split('/');
28+
const addr = validation.parseIPv4(addr_str);
29+
if (!addr)
30+
return null;
31+
32+
let mask = mask_str;
2433

2534
if (!isNaN(mask))
2635
mask = validation.parseIPv4(network.prefixToMask(+mask));
2736
else
2837
mask = validation.parseIPv4(mask);
2938

30-
var bc = [
39+
if (!mask)
40+
return null;
41+
42+
const bc = [
3143
addr[0] | (~mask[0] >>> 0 & 255),
3244
addr[1] | (~mask[1] >>> 0 & 255),
3345
addr[2] | (~mask[2] >>> 0 & 255),

0 commit comments

Comments
 (0)