summaryrefslogtreecommitdiffhomepage
path: root/modules/luci-base/luasrc/sys.lua
diff options
context:
space:
mode:
authorJo-Philipp Wich <jo@mein.io>2019-06-03 16:34:06 +0200
committerGitHub <noreply@github.com>2019-06-03 16:34:06 +0200
commitc8b7e7631b35f00c51666670b66f6a32c188f1d8 (patch)
treebdfc979803bd31fef691bc41d00b5fed56337edb /modules/luci-base/luasrc/sys.lua
parent4bbc033a968478d54a6c4bc2d8529abbfffdec6f (diff)
parentbb34a31e811266ec119002263fa35195bed055db (diff)
Merge pull request #2742 from Ansuel/odhcp-lease
luci-base: handle dhcp lease from odhcpd
Diffstat (limited to 'modules/luci-base/luasrc/sys.lua')
-rw-r--r--modules/luci-base/luasrc/sys.lua40
1 files changed, 39 insertions, 1 deletions
diff --git a/modules/luci-base/luasrc/sys.lua b/modules/luci-base/luasrc/sys.lua
index 7e4a9d63c..bb4c67fe8 100644
--- a/modules/luci-base/luasrc/sys.lua
+++ b/modules/luci-base/luasrc/sys.lua
@@ -137,7 +137,7 @@ end
net = {}
local function _nethints(what, callback)
- local _, k, e, mac, ip, name
+ local _, k, e, mac, ip, name, duid, iaid
local cur = uci.cursor()
local ifn = { }
local hosts = { }
@@ -189,6 +189,24 @@ local function _nethints(what, callback)
end
end
)
+
+ cur:foreach("dhcp", "odhcpd",
+ function(s)
+ if type(s.leasefile) == "string" and fs.access(s.leasefile) then
+ for e in io.lines(s.leasefile) do
+ duid, iaid, name, _, ip = e:match("^# %S+ (%S+) (%S+) (%S+) (-?%d+) %S+ %S+ ([0-9a-f:.]+)/[0-9]+")
+ mac = net.duid_to_mac(duid)
+ if mac then
+ if ip and iaid == "ipv4" then
+ _add(what, mac, ip, nil, name ~= "*" and name)
+ elseif ip then
+ _add(what, mac, nil, ip, name ~= "*" and name)
+ end
+ end
+ end
+ end
+ end
+ )
cur:foreach("dhcp", "host",
function(s)
@@ -386,6 +404,26 @@ function net.devices()
return devs
end
+function net.duid_to_mac(duid)
+ local b1, b2, b3, b4, b5, b6
+
+ if type(duid) == "string" then
+ -- DUID-LLT / Ethernet
+ if #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 #duid == 20 then
+ b1, b2, b3, b4, b5, b6 = duid:match("^00030001(%x%x)(%x%x)(%x%x)(%x%x)(%x%x)(%x%x)$")
+
+ -- DUID-LL / Ethernet (Without Header)
+ elseif #duid == 12 then
+ b1, b2, b3, b4, b5, b6 = duid:match("^(%x%x)(%x%x)(%x%x)(%x%x)(%x%x)(%x%x)$")
+ end
+ end
+
+ return b1 and luci.ip.checkmac(table.concat({ b1, b2, b3, b4, b5, b6 }, ":"))
+end
process = {}