Set WAN VLAN by number rather than by device.

This is more obviously what you want to do, and it makes supporting
devices with switches easier.
This commit is contained in:
Tim Wilkinson 2022-04-17 13:41:34 -07:00 committed by Joe AE6XE
parent 4f1b13deb6
commit 7515d6f841
1 changed files with 35 additions and 7 deletions

View File

@ -212,12 +212,13 @@ local settings = {
default = "1000" default = "1000"
}, },
{ {
key = "network.wan.ifname", key = "aredn.wan.vlanid",
type = "string", type = "string",
desc = "Specify WAN interface VLAN #. MUST be entered as ethX.YY where X is the interface (usually '0') and YY is the VLAN # to use.", desc = "Specify WAN VLAN #",
default = "", default = "",
condition = "supportsVLANChange()", condition = "supportsVLANChange()",
postcallback = "postChangeWANVLAN()", current = "currentWANVLAN()",
postcallback = "changeWANVLAN()",
needreboot = true needreboot = true
}, },
{ {
@ -463,7 +464,22 @@ function adjustTunnelInterfaceCount()
end end
end end
function postChangeWANVLAN() function currentWANVLAN()
for line in io.lines("/etc/config.mesh/_setup")
do
local vlan = line:match("^wan_intf = %w+%d+%.(%d+)")
if vlan then
return vlan
end
end
local vlan = aredn.hardware.get_board().network.wan.ifname:match("^%w+%.(%d+)")
if vlan then
return vlan
end
return ""
end
function changeWANVLAN()
local lines = {} local lines = {}
for line in io.lines("/etc/config.mesh/_setup") for line in io.lines("/etc/config.mesh/_setup")
do do
@ -472,7 +488,14 @@ function postChangeWANVLAN()
end end
end end
if newval ~= "" then if newval ~= "" then
lines[#lines + 1] = "wan_intf = " .. newval local wan_intf = ""
for dev in aredn.hardware.get_board().network.wan.ifname:gmatch("%S+")
do
wan_intf = wan_intf .. " " .. dev:match("^([^%.]+)") .. "." .. newval
end
if wan_intf ~= "" then
lines[#lines + 1] = "wan_intf =" .. wan_intf
end
end end
local f = io.open("/etc/config.mesh/_setup", "w") local f = io.open("/etc/config.mesh/_setup", "w")
if f then if f then
@ -674,8 +697,13 @@ html.print([[
for i, setting in ipairs(settings) for i, setting in ipairs(settings)
do do
if not setting.condition or loadstring("return " .. setting.condition)() then if not setting.condition or loadstring("return " .. setting.condition)() then
local a, b, c = setting.key:match("(.+)%.(.+)%.(.*)") local sval
local sval = cursor_get(a, b, c) if setting.current then
sval = loadstring("return " .. setting.current)()
else
local a, b, c = setting.key:match("(.+)%.(.+)%.(.*)")
sval = cursor_get(a, b, c)
end
sval = sval and tostring(sval) or "" sval = sval and tostring(sval) or ""
html.print([[<tr><td align="center"><span title="]] .. setting.desc .. [["><img src="/qmark.png" /></span></td><td>]] .. setting.key .. [[</td><td>]]) html.print([[<tr><td align="center"><span title="]] .. setting.desc .. [["><img src="/qmark.png" /></span></td><td>]] .. setting.key .. [[</td><td>]])
if setting.type == "string" then if setting.type == "string" then