[luci] [PATCH] modules/admin-core: add support for DUIDs in dhcp_leases()

Roman A. aka BasicXP x12ozmouse at ya.ru
Fri Aug 17 14:07:30 CEST 2012


This patch adds support for viewing a DUID of a DHCPv6 lease of dnsmasq-dhcpv6 package.

Here is the sample /tmp/dhcp.leases file of recent dnsmasq versions:

  1345236370 XX:XX:XX:XX:XX:XX 192.168.1.73 LAPTOP *
  1345235010 XX:XX:XX:XX:XX:XX 192.168.1.4 COMPUTER 01:XX:XX:XX:XX:XX:XX
  duid 00:01:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX
  1345205080 0 2001:67c:2158:a019::4 COMPUTER 00:01:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX

As we see here, if the MAC address field is 0, the lease is made for IPv6, thus we can use the last column to display the DUID. It can't be used for all leases, since the MAC address is prepended with "01:" in case of IPv4.

Signed-off-by: Roman A. aka BasicXP

---

Index: modules/admin-full/luasrc/view/admin_network/lease_status.htm
===================================================================
--- modules/admin-full/luasrc/view/admin_network/lease_status.htm	(revision 9067)
+++ modules/admin-full/luasrc/view/admin_network/lease_status.htm	(working copy)
@@ -51,7 +51,7 @@
 		<tr class="cbi-section-table-titles">
 			<th class="cbi-section-table-cell"><%:Hostname%></th>
 			<th class="cbi-section-table-cell"><%:IPv4-Address%></th>
-			<th class="cbi-section-table-cell"><%:MAC-Address%></th>
+			<th class="cbi-section-table-cell"><%:MAC-Address%> / <%:DUID></th>
 			<th class="cbi-section-table-cell"><%:Leasetime remaining%></th>
 		</tr>
 		<tr class="cbi-section-table-row">
Index: modules/admin-core/luasrc/tools/status.lua
===================================================================
--- modules/admin-core/luasrc/tools/status.lua	(revision 9067)
+++ modules/admin-core/luasrc/tools/status.lua	(working copy)
@@ -36,8 +36,11 @@
 			if not ln then
 				break
 			else
-				local ts, mac, ip, name = ln:match("^(%d+) (%S+) (%S+) (%S+)")
-				if ts and mac and ip and name then
+				local ts, mac, ip, name, duid = ln:match("^(%d+) (%S+) (%S+) (%S+) (%S+)")
+				if ts and mac and ip and name and duid then
+				    if mac == "0" then
+				        mac      = duid
+				    end
 					rv[#rv+1] = {
 						expires  = os.difftime(tonumber(ts) or 0, os.time()),
 						macaddr  = mac,


More information about the luci mailing list