Forgot one item: doing a blended version would be good also. Replacing the DHCP parse lease code with the commit/release/expiry would be cool!
For experimenting, this code can the added `/var/ipfire/dhcp/dhcpd.conf.local`. The output will appear in the messages log with the "dhcpd" tag.
``` on commit { set noname = concat("dhcp-", binary-to-ascii(10, 8, "-", leased-address)); set ClientIP = binary-to-ascii(10, 8, ".", leased-address); set ClientDHCID = concat ( suffix (concat ("0", binary-to-ascii (16, 8, "", substring(hardware,1,1))),2), ":", suffix (concat ("0", binary-to-ascii (16, 8, "", substring(hardware,2,1))),2), ":", suffix (concat ("0", binary-to-ascii (16, 8, "", substring(hardware,3,1))),2), ":", suffix (concat ("0", binary-to-ascii (16, 8, "", substring(hardware,4,1))),2), ":", suffix (concat ("0", binary-to-ascii (16, 8, "", substring(hardware,5,1))),2), ":", suffix (concat ("0", binary-to-ascii (16, 8, "", substring(hardware,6,1))),2) );
set ClientName = pick-first-value(option host-name, config-option-host-name, client-name, noname);
set secondNibble = substring(binary-to-ascii(16, 8, "", substring(hardware, 1, 1)), 1, 1); set leftByte = substring(hardware, 1, 1);
log(concat("Commit: IP: ", ClientIP, " MAC: ", ClientDHCID, " Name: ", ClientName, " secondNibble: ", secondNibble));
#execute("/root/dhcpdconf/dhcpEvent.sh", "commit", ClientIP, ClientDHCID, ClientName); }
on release { set ClientIP = binary-to-ascii(10, 8, ".", leased-address); set ClientDHCID = concat ( suffix (concat ("0", binary-to-ascii (16, 8, "", substring(hardware,1,1))),2), ":", suffix (concat ("0", binary-to-ascii (16, 8, "", substring(hardware,2,1))),2), ":", suffix (concat ("0", binary-to-ascii (16, 8, "", substring(hardware,3,1))),2), ":", suffix (concat ("0", binary-to-ascii (16, 8, "", substring(hardware,4,1))),2), ":", suffix (concat ("0", binary-to-ascii (16, 8, "", substring(hardware,5,1))),2), ":", suffix (concat ("0", binary-to-ascii (16, 8, "", substring(hardware,6,1))),2) );
log(concat("Release: IP: ", ClientIP, " MAC: ", ClientDHCID)); #execute("/root/dhcpdconf/dhcpEvent.sh", "release", ClientIP, ClientDHCID, ClientName); }
on expiry { set ClientIP = binary-to-ascii(10, 8, ".", leased-address); # cannot get a ClientMac here, apparently this only works when actually receiving a packet
log(concat("Expired: IP: ", ClientIP)); #execute("/root/dhcpdconf/dhcpEvent.sh", "expiry", ClientIP, ClientDHCID, "");
# cannot get a ClientName here, for some reason that always fails # however the dhcp update script will obtain the short hostname. } ```