luci-base: handle dhcp lease from odhcpd 2742/head
authorAnsuel Smith <ansuelsmth@gmail.com>
Sun, 2 Jun 2019 20:37:31 +0000 (22:37 +0200)
committerAnsuel Smith <ansuelsmth@gmail.com>
Mon, 3 Jun 2019 10:51:33 +0000 (12:51 +0200)
Currently only the dnsmasq lease file is read for hostname hint. If someone use only odhcpd as dhcp daemon the hostname resolution on wifi_assoc list is broken.

Signed-off-by: Ansuel Smith <ansuelsmth@gmail.com>
modules/luci-base/luasrc/sys.lua

index 4c6574368da45c3cef017916f568cd7c07fa5268..bb4c67fe88319a1d93afb2394f8e8a59533bc04a 100644 (file)
@@ -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)