This module consists of three binaries:
dhcpd2json
, thedhcpd.leases
parserdhcpd62json
, thedhcpd6.leases
parserdhcp-httpd
, the DHCP lease server
The dhcp-httpd
server module executes the dhcpd2json
and dhcpd62json
commands to fetch the leases in JSON format and then provide them via HTTP either in JSON or as an HTML page. The separation exists partly as a division of labor (although the DHCP lease data structures are currently in the same library that provides parsing functionality), and partly to protect the server from the log.Fatal
s scattered throughout the parser code.
This package also provides several adjacent pieces of functionality, as libraries:
- Parsers for both the
dhcp.leases
anddhcp6.leases
files (they are quite different) - A parser (
duid
) for the IAID+DUID string which ISC DHCP places afteria-na
or similar blocks in thedhcp6.leases
file. The string is made up of escaped octets which represent a binary four byte IAID (in the case ofia-na
) followed by a DUID of one of three flavors. - A utility library (
macvendor
) to lookup the vendor name from the IEEE prefix database files given a MAC address. - A utility library (
enterprisenumbers
) to lookup the organization name from the IANA database file given an enterprise number, this could be useuful when DUIDs are of the DUID-EN variety.
- First run
go generate
in thedhcpd
anddhcpd6
libraries to generate the parsers, this requiresgoyacc
. - Then, run
go generate
in themacvendors
andenterprisenumbers
libraries to pull down the latest IEEE and IANA database files. - Then, build the
dhcpd2json
,dhcpd62json
, anddhcp-httpd
binaries for your target platform, e.g.GOOS=linux GOARCH=amd64 go build .
in those directories.
Once the build is done, then:
- Copy binaries to
/usr/bin
on the target system. - Change SELinux context using e.g.
chcon -u system_u -t bin_t /usr/bin/dhcpd2json
andchcon -u system_u -t bin_t /usr/bin/dhcp-httpd
.
To see the lease listing visit the URL e.g. http://localhost:8080, or to see the JSON response:
$ curl -sL http://localhost:8080 | jq
Here is an example systemd unit file:
[Unit]
Description=DHCPv4 HTTP UI Server
Wants=network-online.target
After=network-online.target
After=time-sync.target
[Service]
Type=simple
User=dhcpd
Group=dhcpd
CapabilityBoundingSet=CAP_NET_BIND_SERVICE
AmbientCapabilities=CAP_NET_BIND_SERVICE
#EnvironmentFile=-/etc/sysconfig/dhcpd
ExecStart=/usr/bin/dhcp-httpd -v4f /var/lib/dhcpd/dhcpd.leases -v6f /var/lib/dhcpd/dhcpd6.leases -l :80
[Install]
WantedBy=multi-user.target