Bugfixes for alt networks and larger dhcp ranges (#1652)

This commit is contained in:
Tim Wilkinson 2024-10-26 21:37:35 -07:00 committed by GitHub
parent 1d05336818
commit 2a9a0528db
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 38 additions and 18 deletions

View File

@ -186,10 +186,11 @@ if (request.env.REQUEST_METHOD === "DELETE") {
} }
const dmz_mode = configuration.getSettingAsInt("dmz_mode", 3); const dmz_mode = configuration.getSettingAsInt("dmz_mode", 3);
const dhcp = configuration.getDHCP("nat"); const dhcp = configuration.getDHCP("nat");
const ds = split(dhcp.start, "."); const db = iptoarr(dhcp.base);
const de = split(dhcp.end, "."); const ds = iptoarr(dhcp.start);
const dhcp_start = int(ds[3]); const de = iptoarr(dhcp.end);
const dhcp_end = int(de[3]) + 256 * (de[2] - ds[2]); 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_proto = configuration.getSettingAsString("wan_proto", "disabled");
const wan_iface = split(configuration.getSettingAsString("wan_intf", ""), "."); const wan_iface = split(configuration.getSettingAsString("wan_intf", ""), ".");
const wan_vlan = wan_iface[1] ? wan_iface[1] : ""; const wan_vlan = wan_iface[1] ? wan_iface[1] : "";
@ -495,6 +496,7 @@ const gateway_altnet = dmz_mode === 1 ? dhcp.gateway : "";
endp = "[]"; endp = "[]";
} }
else { else {
const v = ip.validity.valid;
const i = ipv.split("."); const i = ipv.split(".");
const netip = (parseInt(i[3]) + 256 * parseInt(i[2])) & size; const netip = (parseInt(i[3]) + 256 * parseInt(i[2])) & size;
if (startv < 1 || endv >= size || (netip >= startv && netip <= endv)) { if (startv < 1 || endv >= size || (netip >= startv && netip <= endv)) {
@ -506,15 +508,17 @@ const gateway_altnet = dmz_mode === 1 ? dhcp.gateway : "";
if (ipv === base) { if (ipv === base) {
ipp = "[]"; ipp = "[]";
} }
startid.innerHTML = `Start offset from ${base} for allocating DHCP addresses`; startid.innerHTML = `Start offset from ${v ? base : "-"} for allocating DHCP addresses`;
endid.innerHTML = `End offset from ${base} for allocating DHCP addresses`; endid.innerHTML = `End offset from ${v ? base : "-"} for allocating DHCP addresses`;
} }
} }
netmask.pattern = netmaskp; netmask.pattern = netmaskp;
start.pattern = startp; start.pattern = startp;
end.pattern = endp; end.pattern = endp;
if (ip.name !== "lan44_dhcp_ip") {
ip.pattern = ipp; ip.pattern = ipp;
} }
}
function validateLANRange() function validateLANRange()
{ {
validateRange(htmx.find("input[name=lan_dhcp_ip]"), htmx.find("input[name=lan_dhcp_netmask]"), htmx.find("input[name=lan_dhcp_start]"), htmx.find("input[name=lan_dhcp_end]"), htmx.find("#lan_dhcp_start_m"), htmx.find("#lan_dhcp_end_m")); validateRange(htmx.find("input[name=lan_dhcp_ip]"), htmx.find("input[name=lan_dhcp_netmask]"), htmx.find("input[name=lan_dhcp_start]"), htmx.find("input[name=lan_dhcp_end]"), htmx.find("#lan_dhcp_start_m"), htmx.find("#lan_dhcp_end_m"));

View File

@ -71,7 +71,7 @@ if not best.destination then
end end
-- Update the dns and restart network if necessary -- 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 odns = ""
local f = io.open(dns_file) local f = io.open(dns_file)
if f then if f then

View File

@ -1152,7 +1152,8 @@ if nixio.fs.access("/etc/config.mesh/olsrd", "r") then
end end
if is_altnet_mode() then if is_altnet_mode() then
local a, b, c, d = cfg.lan_ip:match("(.*)%.(.*)%.(.*)%.(.*)") 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 end
if cfg.wifi_enable ~= "1" and is_notnull(cfg.wifi_ip) then if cfg.wifi_enable ~= "1" and is_notnull(cfg.wifi_ip) then

View File

@ -206,12 +206,17 @@ export function getDHCP(mode)
initSetup(); initSetup();
const setup = scursor.get_all("setup", "globals"); const setup = scursor.get_all("setup", "globals");
if (mode === "nat" || (!mode && setup.dmz_mode === "0")) { 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 { return {
enabled: setup.lan_dhcp !== "0" ? true : false, enabled: setup.lan_dhcp !== "0" ? true : false,
mode: 0, mode: 0,
start: `${root}${setup.dhcp_start}`, base: `${i[0]}.${i[1]}.${(b >> 8) & 255}.${b & 255}`,
end: `${root}${setup.dhcp_end}`, start: `${i[0]}.${i[1]}.${(s >> 8) & 255}.${s & 255}`,
end: `${i[0]}.${i[1]}.${(e >> 8) & 255}.${e & 255}`,
gateway: setup.lan_ip, gateway: setup.lan_ip,
mask: setup.lan_mask, mask: setup.lan_mask,
cidr: network.netmaskToCIDR(setup.lan_mask), cidr: network.netmaskToCIDR(setup.lan_mask),
@ -225,12 +230,17 @@ export function getDHCP(mode)
}; };
} }
else if (setup.dmz_mode === "1") { 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 { return {
enabled: setup.lan_dhcp !== "0" ? true : false, enabled: setup.lan_dhcp !== "0" ? true : false,
mode: 1, mode: 1,
start: `${root}${setup.dhcp_start}`, base: `${i[0]}.${i[1]}.${(b >> 8) & 255}.${b & 255}`,
end: `${root}${setup.dhcp_end}`, start: `${i[0]}.${i[1]}.${(s >> 8) & 255}.${s & 255}`,
end: `${i[0]}.${i[1]}.${(e >> 8) & 255}.${e & 255}`,
gateway: setup.lan_ip, gateway: setup.lan_ip,
mask: setup.lan_mask, mask: setup.lan_mask,
cidr: network.netmaskToCIDR(setup.lan_mask), cidr: network.netmaskToCIDR(setup.lan_mask),
@ -244,12 +254,17 @@ export function getDHCP(mode)
}; };
} }
else { 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 { return {
enabled: setup.lan_dhcp !== "0" ? true : false, enabled: setup.lan_dhcp !== "0" ? true : false,
mode: int(setup.dmz_mode), mode: int(setup.dmz_mode),
start: `${root}${setup.dmz_dhcp_start}`, base: `${i[0]}.${i[1]}.${(b >> 8) & 255}.${b & 255}`,
end: `${root}${setup.dmz_dhcp_end}`, 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, gateway: setup.dmz_lan_ip,
mask: setup.dmz_lan_mask, mask: setup.dmz_lan_mask,
cidr: network.netmaskToCIDR(setup.dmz_lan_mask), cidr: network.netmaskToCIDR(setup.dmz_lan_mask),