go-net-dhcp is a pure-Go (no cgo) DHCPv4 server library. It
implements the RFC 2131 / 2132 wire format (Parse a DISCOVER/REQUEST,
BuildReply an OFFER / ACK / NAK), a stateless platform-agnostic decision
core (Decide), and a real Linux UDP/67 server bound to a single kernel
interface via SO_BINDTODEVICE. It targets the "one subnet, hand out a
lease per known MAC" case — a host that owns a bridge / VLAN and needs to answer
DHCP for the guests it spawns on it, without running an external dnsmasq.
You supply a Source that resolves a client MAC into a Lease;
the library never persists anything itself. The wire codec is hand-rolled, so the core
module has zero third-party dependencies; the optional Prometheus
adapter lives in its own sub-package.
Wire codec ready
RFC 2131 / 2132 parse + build — Parse decodes a DISCOVER/REQUEST (BOOTP header + magic cookie + TLV options), BuildReply emits an OFFER / ACK / NAK. Strict on framing, tolerant of unknown option codes, hand-rolled so the core has zero third-party dependencies.
Decision core ready
Decide(pkt, opts) runs the stateless state machine — DISCOVER→OFFER, REQUEST→ACK, mismatched requested-IP→NAK, unknown MAC / other message types→drop. Build-tag-free and portable, so it is unit-tested on every platform without a socket.
Linux UDP/67 server ready
LinuxServer binds UDP/67 to one kernel interface via SO_BINDTODEVICE + SO_BROADCAST + SO_REUSEADDR and replies by broadcast. The socket path is covered without root through injectable syscall seams, so every error branch runs in CI.
Cross-platform surface ready
A build stub on non-Linux plus a socket-free StubServer that drives the Source → Lease pipeline. Callers compile and test the integration surface on darwin / windows / *bsd; the real bind only ships on Linux.
Optional metrics ready
Pass any Metrics implementation in Options; a nil sink discards everything. A ready-made Prometheus adapter (dhcpv4_packets_total{outcome} + dhcpv4_handle_duration_seconds) lives in the prom sub-package so the core library keeps no Prometheus dependency.
Coverage & 6 arches ready
100% test coverage including error branches (socket paths via syscall seams, no root), gofmt + go vet clean, green across all six 64-bit Go arches (amd64, arm64, riscv64, loong64, ppc64le, s390x).
- ready capability complete (exit criteria met, nothing material left)
- active in progress (substantial work shipped, not yet finished)
- planned not started yet (or downstream by design)
Pure Go, cgo disabled, so it cross-compiles and embeds anywhere. A
hand-rolled RFC 2131 / 2132 wire codec keeps the core dependency-free; the socket path
is covered without root via injectable syscall seams; metrics are optional and the
Prometheus adapter is quarantined in the prom sub-package. Part of the
github.com/go-net-dhcp organization.