diff --git a/files/app/main/status/e/network.ut b/files/app/main/status/e/network.ut index 211e350a..cbc2c875 100755 --- a/files/app/main/status/e/network.ut +++ b/files/app/main/status/e/network.ut @@ -186,10 +186,11 @@ if (request.env.REQUEST_METHOD === "DELETE") { } const dmz_mode = configuration.getSettingAsInt("dmz_mode", 3); const dhcp = configuration.getDHCP("nat"); -const ds = split(dhcp.start, "."); -const de = split(dhcp.end, "."); -const dhcp_start = int(ds[3]); -const dhcp_end = int(de[3]) + 256 * (de[2] - ds[2]); +const db = iptoarr(dhcp.base); +const ds = iptoarr(dhcp.start); +const de = iptoarr(dhcp.end); +const dhcp_start = (ds[2] - db[2]) * 256 + (ds[3] - db[3]); +const dhcp_end = (de[2] - db[2]) * 256 + (de[3] - db[3]); const wan_proto = configuration.getSettingAsString("wan_proto", "disabled"); const wan_iface = split(configuration.getSettingAsString("wan_intf", ""), "."); const wan_vlan = wan_iface[1] ? wan_iface[1] : ""; @@ -495,6 +496,7 @@ const gateway_altnet = dmz_mode === 1 ? dhcp.gateway : ""; endp = "[]"; } else { + const v = ip.validity.valid; const i = ipv.split("."); const netip = (parseInt(i[3]) + 256 * parseInt(i[2])) & size; if (startv < 1 || endv >= size || (netip >= startv && netip <= endv)) { @@ -506,14 +508,16 @@ const gateway_altnet = dmz_mode === 1 ? dhcp.gateway : ""; if (ipv === base) { ipp = "[]"; } - startid.innerHTML = `Start offset from ${base} for allocating DHCP addresses`; - endid.innerHTML = `End offset from ${base} for allocating DHCP addresses`; + startid.innerHTML = `Start offset from ${v ? base : "-"} for allocating DHCP addresses`; + endid.innerHTML = `End offset from ${v ? base : "-"} for allocating DHCP addresses`; } } netmask.pattern = netmaskp; start.pattern = startp; end.pattern = endp; - ip.pattern = ipp; + if (ip.name !== "lan44_dhcp_ip") { + ip.pattern = ipp; + } } function validateLANRange() { diff --git a/files/etc/cron.hourly/check-supernodes b/files/etc/cron.hourly/check-supernodes index add27b05..e7222d9f 100755 --- a/files/etc/cron.hourly/check-supernodes +++ b/files/etc/cron.hourly/check-supernodes @@ -71,7 +71,7 @@ if not best.destination then end -- Update the dns and restart network if necessary -local dns = "#" .. best.destination .. "\nserver=/local.mesh/" .. best.destination .. "\nrev-server=10.0.0.0/8," ..best.destination .. "\nrev-server=172.31.0.0/16," .. best.destination .. "\nrev-server=172.30.0.0/16," .. best.destination .. "\n" +local dns = "#" .. best.destination .. "\nserver=/local.mesh/" .. best.destination .. "\nrev-server=10.0.0.0/8," ..best.destination .. "\nrev-server=172.31.0.0/16," .. best.destination .. "\nrev-server=172.30.0.0/16," .. best.destination .. "\nrev-server=44.0.0.0/9," .. best.destination .. "\nrev-server=44.128.0.0/10," .. best.destination .. "\n" local odns = "" local f = io.open(dns_file) if f then diff --git a/files/usr/local/bin/node-setup b/files/usr/local/bin/node-setup index 2ee85a97..87d3dbc9 100755 --- a/files/usr/local/bin/node-setup +++ b/files/usr/local/bin/node-setup @@ -1152,7 +1152,8 @@ if nixio.fs.access("/etc/config.mesh/olsrd", "r") then end if is_altnet_mode() then local a, b, c, d = cfg.lan_ip:match("(.*)%.(.*)%.(.*)%.(.*)") - of:write(string.format("\nconfig Hna4\n\toption netaddr %s.%s.%s.%d\n\toption netmask %s\n\n", a, b, c, d - 1, cfg.lan_mask)) + local m, n, o, p = cfg.lan_mask:match("(.*)%.(.*)%.(.*)%.(.*)") + of:write(string.format("\nconfig Hna4\n\toption netaddr %s.%s.%d.%d\n\toption netmask %s\n\n", a, b, nixio.bit.band(c, o), nixio.bit.band(d, p), cfg.lan_mask)) end if cfg.wifi_enable ~= "1" and is_notnull(cfg.wifi_ip) then diff --git a/files/usr/share/ucode/aredn/configuration.uc b/files/usr/share/ucode/aredn/configuration.uc index f66771fc..0186285c 100755 --- a/files/usr/share/ucode/aredn/configuration.uc +++ b/files/usr/share/ucode/aredn/configuration.uc @@ -206,12 +206,17 @@ export function getDHCP(mode) initSetup(); const setup = scursor.get_all("setup", "globals"); if (mode === "nat" || (!mode && setup.dmz_mode === "0")) { - const root = replace(setup.lan_ip, /\d+$/, ""); + const i = iptoarr(setup.lan_ip); + const m = iptoarr(setup.lan_mask); + const b = ((i[2] & m[2]) * 256 + (i[3] & m[3])); + const s = b + int(setup.dhcp_start); + const e = b + int(setup.dhcp_end); return { enabled: setup.lan_dhcp !== "0" ? true : false, mode: 0, - start: `${root}${setup.dhcp_start}`, - end: `${root}${setup.dhcp_end}`, + base: `${i[0]}.${i[1]}.${(b >> 8) & 255}.${b & 255}`, + start: `${i[0]}.${i[1]}.${(s >> 8) & 255}.${s & 255}`, + end: `${i[0]}.${i[1]}.${(e >> 8) & 255}.${e & 255}`, gateway: setup.lan_ip, mask: setup.lan_mask, cidr: network.netmaskToCIDR(setup.lan_mask), @@ -225,12 +230,17 @@ export function getDHCP(mode) }; } else if (setup.dmz_mode === "1") { - const root = replace(setup.lan_ip, /\d+$/, ""); + const i = iptoarr(setup.lan_ip); + const m = iptoarr(setup.lan_mask); + const b = ((i[2] & m[2]) * 256 + (i[3] & m[3])); + const s = b + int(setup.dhcp_start); + const e = b + int(setup.dhcp_end); return { enabled: setup.lan_dhcp !== "0" ? true : false, mode: 1, - start: `${root}${setup.dhcp_start}`, - end: `${root}${setup.dhcp_end}`, + base: `${i[0]}.${i[1]}.${(b >> 8) & 255}.${b & 255}`, + start: `${i[0]}.${i[1]}.${(s >> 8) & 255}.${s & 255}`, + end: `${i[0]}.${i[1]}.${(e >> 8) & 255}.${e & 255}`, gateway: setup.lan_ip, mask: setup.lan_mask, cidr: network.netmaskToCIDR(setup.lan_mask), @@ -244,12 +254,17 @@ export function getDHCP(mode) }; } else { - const root = replace(setup.dmz_lan_ip, /\d+$/, ""); + const i = iptoarr(setup.dmz_lan_ip); + const m = iptoarr(setup.dmz_lan_mask); + const b = ((i[2] & m[2]) * 256 + (i[3] & m[3])); + const s = b + int(setup.dmz_dhcp_start); + const e = b + int(setup.dmz_dhcp_end); return { enabled: setup.lan_dhcp !== "0" ? true : false, mode: int(setup.dmz_mode), - start: `${root}${setup.dmz_dhcp_start}`, - end: `${root}${setup.dmz_dhcp_end}`, + base: `${i[0]}.${i[1]}.${(b >> 8) & 255}.${b & 255}`, + start: `${i[0]}.${i[1]}.${(s >> 8) & 255}.${s & 255}`, + end: `${i[0]}.${i[1]}.${(e >> 8) & 255}.${e & 255}`, gateway: setup.dmz_lan_ip, mask: setup.dmz_lan_mask, cidr: network.netmaskToCIDR(setup.dmz_lan_mask),