continued enhancements for multi-wan capabilities
Skyweave Test, Lint, and Deploy Ritual / Test and Lint Code (push) Failing after 28s
Skyweave Test, Lint, and Deploy Ritual / Deploy to Roof Unit (push) Has been skipped

This commit is contained in:
wes
2025-06-29 10:15:40 -04:00
parent f61a392d60
commit d83c16d6c3
2 changed files with 43 additions and 10 deletions
+13 -10
View File
@@ -6,21 +6,22 @@ local network_handler = {}
-- Original: function handlers.get_network_config(params) -- Original: function handlers.get_network_config(params)
function network_handler.get_network_config(request_context) function network_handler.get_network_config(request_context)
local iface = request_context.query.interface or "wan" -- Default to "wan" local wan_iface_name = request_context.query.interface or "wan" -- Default to "wan"
local wan_lte_iface_name = "wan_lte"
-- Ensure utils are available for these calls -- Ensure utils are available for these calls
local live_dns_list, live_search_domains = utils.get_live_dns_servers_from_resolv(iface) local live_wan_dns_list, live_search_domains = utils.get_live_dns_servers_from_resolv(wan_iface_name)
local live_gateway_ip, live_gateway_iface = utils.get_active_default_gateway() local live_gateway_ip, live_gateway_iface = utils.get_active_default_gateway()
-- get_live_interface_info returns: address, mask, device, leasetime, error_message -- get_live_interface_info returns: address, mask, device, leasetime, error_message
local live_wan_ip, live_wan_netmask, ifname, dhcp_lease_time, err_msg_live_info = utils.get_live_interface_info(iface) local live_wan_ip, live_wan_netmask, ifname, dhcp_lease_time, err_msg_live_info = utils.get_live_interface_info(wan_iface_name)
local station_info, err = utils.get_station_dump_info("vif-sta0") local station_info, err = utils.get_station_dump_info("vif-sta0")
-- Handle potential error from get_live_interface_info if needed, e.g. log err_msg_live_info -- Handle potential error from get_live_interface_info if needed, e.g. log err_msg_live_info
local response_data = { errCode = 0, errMsg = "OK"} local response_data = { errCode = 0, errMsg = "OK"}
response_data.wwan = { response_data.wan = {
ssid = utils.uci_get("wireless.wwan.ssid") or "", ssid = utils.uci_get("wireless.wwan.ssid") or "",
bssid = station_info.bssid or "", bssid = station_info.bssid or "",
tx_rate = station_info["tx bitrate"], tx_rate = station_info["tx bitrate"],
@@ -29,13 +30,14 @@ function network_handler.get_network_config(request_context)
encryption = utils.uci_get("wireless.wwan.encryption") or "", encryption = utils.uci_get("wireless.wwan.encryption") or "",
key = utils.uci_get("wireless.wwan.key") or "", key = utils.uci_get("wireless.wwan.key") or "",
device = utils.uci_get("wireless.wwan.device") or "", device = utils.uci_get("wireless.wwan.device") or "",
wan_dns1 = live_dns_list and live_dns_list[1] or "", wan_dns1 = live_wan_dns_list and live_wan_dns_list[1] or "",
wan_dns2 = live_dns_list and live_dns_list[2] or "", wan_dns2 = live_wan_dns_list and live_wan_dns_list[2] or "",
wan_gateway = live_gateway_ip or "", --wan_gateway = live_gateway_ip or "",
wan_gateway = utils.get_gateway_for_interface("vif-sta0") or "",
wan_ip = live_wan_ip or "", wan_ip = live_wan_ip or "",
wan_netmask = live_wan_netmask or "", wan_netmask = live_wan_netmask or "",
wan_ifname = ifname or "", -- from get_live_interface_info wan_ifname = ifname or "", -- from get_live_interface_info
wan_iface = iface, -- the logical interface name queried wan_iface = wan_iface_name, -- the logical interface name queried
wan_dhcp_lease_time = dhcp_lease_time or "" -- from get_live_interface_info wan_dhcp_lease_time = dhcp_lease_time or "" -- from get_live_interface_info
} }
response_data.lan = { response_data.lan = {
@@ -48,9 +50,10 @@ function network_handler.get_network_config(request_context)
domain = utils.uci_get("dhcp.@dnsmasq[0].domain") or "", domain = utils.uci_get("dhcp.@dnsmasq[0].domain") or "",
ignore = utils.uci_get("dhcp.lan.ignore") or "" -- bool, uci_get returns "0" or "1" ignore = utils.uci_get("dhcp.lan.ignore") or "" -- bool, uci_get returns "0" or "1"
} }
response_data.lte = { response_data.wan_lte = {
imei = utils.get_modem_imei() or "", imei = utils.get_modem_imei() or "",
iccid = utils.get_sim_iccid() or "" iccid = utils.get_sim_iccid() or "",
wan_gateway = utils.get_gateway_for_interface("wwan0") or "",
} }
return response_data return response_data
end end
+30
View File
@@ -265,6 +265,36 @@ function utils.get_active_default_gateway()
return active_route.gateway, active_route.iface return active_route.gateway, active_route.iface
end end
---
-- Retrieves the configured gateway for a specific interface by name, regardless of its metric.
-- This is achieved by executing a shell command via the popen rite.
-- @param interface_name (string) The name of the interface (e.g., "wwan0", "vif-sta0").
-- @return (string) The gateway IP address, or nil if not found.
--
function utils.get_gateway_for_interface(interface_name)
-- We shall not suffer an unsanctioned interface name to proceed.
if not interface_name or (interface_name ~= "wwan0" and interface_name ~= "vif-sta0") then
-- Log the transgression and reject the impure input.
logger -t GHI-UTILS "Rejected unsanctified interface name: " .. tostring(interface_name)
return nil
end
-- Construct the sacred shell incantation using the provided interface name.
local command = string.format("route -n | grep '^0\\.0\\.0\\.0' | grep '%s' | awk '{print $2}'", interface_name)
-- Invoke the command and receive its output.
local gateway_ip_raw = utils.execute_command(command)
if gateway_ip_raw and gateway_ip_raw ~= "" then
-- Purify the output, removing the taint of newlines and whitespace to return only the IP.
local gateway_ip = gateway_ip_raw:match("^(%S+)")
return gateway_ip
end
-- If no gateway was found, the path is unknown.
return nil
end
-- ============================================================================= -- =============================================================================
-- A new litany to parse the data-psalms of 'iw dev station dump' -- A new litany to parse the data-psalms of 'iw dev station dump'
-- Transmutes the raw text into a structured Lua table. -- Transmutes the raw text into a structured Lua table.