Skip to content

Dhcp lease

Local DHCP lease files available to Lua routing helpers.

DHCP lease helpers require router-dhcp-lease (enabled by default) and router.dhcp-lease entries with type: dnsmasq or type: odhcp, a unique lease tag, and an optional path. Default paths are /tmp/dhcp.leases and /tmp/odhcpd.leases. Both formats support IPv4 and IPv6 in the same file.

DHCP helper Return value
find_dhcp_mac_v4(tag, ip) Lowercase colon-separated Ethernet MAC
find_dhcp_host_v4(tag, ip) Hostname
find_dhcp_duid_v6(tag, ip) Lowercase colon-separated client DUID
find_dhcp_iaid_v6(tag, ip) Numeric unsigned 32-bit IAID
find_dhcp_mac_v6(tag, ip) Ethernet MAC embedded in DUID-LL/LLT
find_dhcp_host_v6(tag, ip) Hostname

All DHCP helpers return nil for missing/expired leases or missing attributes. Unknown tags and invalid IPs (including the wrong family) raise Lua errors. They are available during script loading and routing without network or file I/O on the lookup path. IPv6 MAC extraction can return nil and does not necessarily identify the client's current interface. Delegated prefixes are ignored. Lease files reload automatically; failures retain the previous data with expiry still enforced. Missing initial files give empty results and are retried. Stores survive Lua reloads, and lease updates do not reset Lua state.

Example configuration:

router:
  dhcp-lease:
    - type: dnsmasq
      tag: lan-v4
      path: /tmp/dhcp.leases
    - type: odhcp
      tag: lan-v6
      path: /tmp/odhcpd.leases
  src: |
    return function(ctx)
      local host
      if ctx.src_ip_v4 then
        host = find_dhcp_host_v4("lan-v4", ctx.src_ip_v4)
      elseif ctx.src_ip_v6 then
        host = find_dhcp_host_v6("lan-v6", ctx.src_ip_v6)
      end
      if host == "blocked-device" then return "block" end
      return "direct"
    end

Variants

This enum is serialized with the YAML key type selecting the variant.

Tag value Carries Description
dnsmasq DnsmasqLeaseCfg —
odhcp OdhcpLeaseCfg —