Hooks

Hook Methods

onDHCPRequestBefore(request)

Called before the DHCP response is generated.

onDHCPRequestAfter(request, response)

Called after the DHCP response is generated.

Environment

gravity Object

log(msg: any)

Logs a message to the stdout of the Gravity node this hook is run on.

node: string

The identifier of the node this hook is run on.

version: string

The version of Gravity on the node this hook is run on.

role

A reference to the Role instance this hook was triggered by.

net Object

parseIP(ip: string, family: string)

Parse an IP address from the string ip and return it as an array of bytes. family determines if the IP should be parsed as IPv4 or IPv6.

dhcp Object

Opt(code: number, data: byte[])

Create a DHCP option with the code and data given.

Examples

Set Option 43 for UniFi Adoption

const UniFiPrefix = [0x01, 0x04];
const UniFiIP = net.parseIP("192.168.1.100", "v4");
function onDHCPRequestAfter(req, res) {
    res.UpdateOption(dhcp.Opt(43, [...UniFiPrefix, ...UniFiIP]))
}