summaryrefslogtreecommitdiffhomepage
path: root/modules/luci-base/luasrc/tools/status.lua
diff options
context:
space:
mode:
authorJo-Philipp Wich <jo@mein.io>2018-06-28 09:32:16 +0200
committerJo-Philipp Wich <jo@mein.io>2018-06-28 09:42:17 +0200
commitc61c5deac45cdaf1fbccc2d513a90a877e12eea0 (patch)
tree695603babe45c4af3e5a554e5c04d177cd339010 /modules/luci-base/luasrc/tools/status.lua
parentccbb17d26031a802ae02a9bea4063eb65b59ed86 (diff)
luci-base: luci.tools.status: add host_hints to DHCPv6 leases
Attempt to derive a MAC from the DHCPv6 lease DUID and use it to look up a host hint. If a hint is found, add it to the lease information. Signed-off-by: Jo-Philipp Wich <jo@mein.io>
Diffstat (limited to 'modules/luci-base/luasrc/tools/status.lua')
-rw-r--r--modules/luci-base/luasrc/tools/status.lua32
1 files changed, 32 insertions, 0 deletions
diff --git a/modules/luci-base/luasrc/tools/status.lua b/modules/luci-base/luasrc/tools/status.lua
index 0059ccceb0..635995310f 100644
--- a/modules/luci-base/luasrc/tools/status.lua
+++ b/modules/luci-base/luasrc/tools/status.lua
@@ -6,9 +6,25 @@ module("luci.tools.status", package.seeall)
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"
+ local sys = require "luci.sys"
local leasefile = "/tmp/dhcp.leases"
uci:foreach("dhcp", "dnsmasq",
@@ -87,6 +103,22 @@ local function dhcp_leases_common(family)
fd:close()
end
+ if family == 6 then
+ local _, lease
+ local hosts = sys.net.host_hints()
+ for _, lease in ipairs(rv) do
+ local mac = duid_to_mac(lease.duid)
+ local host = mac and hosts[mac]
+ if host then
+ if not lease.name then
+ lease.host_hint = host.name or host.ipv4 or host.ipv6
+ elseif host.name and lease.hostname ~= host.name then
+ lease.host_hint = host.name
+ end
+ end
+ end
+ end
+
return rv
end