local uci = require "luci.model.uci".cursor()
local ipc = require "luci.ip"
-local function duid_to_mac(duid)
- local b1, b2, b3, b4, b5, b6
-
- -- DUID-LLT / Ethernet
- if type(duid) == "string" and #duid == 28 then
- b1, b2, b3, b4, b5, b6 = duid:match("^00010001(%x%x)(%x%x)(%x%x)(%x%x)(%x%x)(%x%x)%x%x%x%x%x%x%x%x$")
-
- -- DUID-LL / Ethernet
- elseif type(duid) == "string" and #duid == 20 then
- b1, b2, b3, b4, b5, b6 = duid:match("^00030001(%x%x)(%x%x)(%x%x)(%x%x)(%x%x)(%x%x)$")
- end
-
- return b1 and ipc.checkmac(table.concat({ b1, b2, b3, b4, b5, b6 }, ":"))
-end
-
local function dhcp_leases_common(family)
local rv = { }
local nfs = require "nixio.fs"
elseif ip and iaid == "ipv4" and family == 4 then
rv[#rv+1] = {
expires = (expire >= 0) and os.difftime(expire, os.time()),
- macaddr = ipc.checkmac(duid:gsub("^(%x%x)(%x%x)(%x%x)(%x%x)(%x%x)(%x%x)$", "%1:%2:%3:%4:%5:%6")) or "00:00:00:00:00:00",
+ macaddr = sys.net.duid_to_mac(duid) or "00:00:00:00:00:00",
ipaddr = ip,
hostname = (name ~= "-") and name
}
local _, lease
local hosts = sys.net.host_hints()
for _, lease in ipairs(rv) do
- local mac = duid_to_mac(lease.duid)
+ local mac = sys.net.duid_to_mac(lease.duid)
local host = mac and hosts[mac]
if host then
if not lease.name then
return assoc
end
-
-function switch_status(devs)
- local dev
- local switches = { }
- for dev in devs:gmatch("[^%s,]+") do
- local ports = { }
- local swc = io.popen("swconfig dev %s show"
- % luci.util.shellquote(dev), "r")
-
- if swc then
- local l
- repeat
- l = swc:read("*l")
- if l then
- local port, up = l:match("port:(%d+) link:(%w+)")
- if port then
- local speed = l:match(" speed:(%d+)")
- local duplex = l:match(" (%w+)-duplex")
- local txflow = l:match(" (txflow)")
- local rxflow = l:match(" (rxflow)")
- local auto = l:match(" (auto)")
-
- ports[#ports+1] = {
- port = tonumber(port) or 0,
- speed = tonumber(speed) or 0,
- link = (up == "up"),
- duplex = (duplex == "full"),
- rxflow = (not not rxflow),
- txflow = (not not txflow),
- auto = (not not auto)
- }
- end
- end
- until not l
- swc:close()
- end
- switches[dev] = ports
- end
- return switches
-end