autocore: ethinfo: add dsa display support

Support display any interface name for dsa.
Drop ipq sfp workaround which is not needed.
Add workaround for br* (only this repo needs).
This commit is contained in:
AmadeusGhost 2023-04-21 23:05:37 +08:00
parent 416eefadb9
commit 07ad0eefeb

View File

@ -1,40 +1,45 @@
#!/usr/bin/lua #!/usr/bin/lua
-- Copyright (C) 2022-2023 Tianling Shen <cnsztl@immortalwrt.org> -- Copyright (C) 2022 ImmortalWrt.org
-- Copyright (C) 2022-2023 Lean
local util = require "luci.util" local util = require "luci.util"
local jsonc = require "luci.jsonc" local jsonc = require "luci.jsonc"
local eth_info = {} local eth_info = {}
local ifname, stat local ifname, stat
for ifname, stat in pairs(util.ubus("network.device", "status")) do for ifname, stat in pairs(util.ubus("network.device", "status")) do
if ifname:match("^(eth%d+)$") == ifname then while true do
local status, speed, duplex if (ifname:match("^(br-.+)$")) == ifname then
break
else
local status, speed, duplex
status = stat.carrier and 1 or 0 if(stat.speed ~= nil) then
status = stat.carrier and 1 or 0
if not stat.carrier or not stat.speed or stat.speed:sub(1, 1) == "-" or stat.speed:find("65535") then if stat.speed:sub(1, 1) == "-" then
speed = " - " speed = " - "
else else
speed = stat.speed:sub(1, -2) .. "Mb/s" speed = stat.speed:sub(1, -2) .. "Mb/s"
end end
if speed == " - " then if stat.carrier and stat.speed:sub(-1) == "F" then
duplex = 0 duplex = 1
elseif stat.speed:sub(-1) == "F" then else
duplex = 1 duplex = 0
else end
duplex = 0
end
eth_info[#eth_info+1] = { name = ifname, status = status, eth_info[#eth_info+1] = { name = ifname, status = status,
speed = speed, duplex = duplex } speed = speed, duplex = duplex }
end end
break
end
end
end end
table.sort(eth_info, table.sort(eth_info,
function(a, b) function(a, b)
return a.name < b.name return a.name < b.name
end) end)
print(jsonc.stringify(eth_info)) print(jsonc.stringify(eth_info))