منصوبے کے بارے میں
dhcp-golib is a DHCP client library meant to be embedded in a Go program. It takes a lease on a network interface, keeps it renewed, and emits events when the lease changes. It deliberately does not apply anything to the link: adding the address, routes or resolver is left to the caller. That separation is what allows a single process to hold leases on several interfaces at once.
It implements both DHCPv4 and DHCPv6, targets Linux, and depends only on the Go standard library. The protocol runs inside the process; it does not shell out to dhcpcd or dhclient and does not require root.
Capabilities described in the README include:
- Lease lifecycle: acquire, renew at T1, rebind at T2, expire when no server answers, and release (including handling a server refusal such as DHCPNAK or a DHCPv6 status code).
- Address conflict checks before announcing an address, with decline and recovery, following RFC 5227 on IPv4 and RFC 4862 on IPv6.
- Restart persistence: a durable lease journal lets a restarted process ask for the address it previously held (INIT-REBOOT / Confirm), and a torn journal tail is repaired before new records are appended.
- Reporting of address, gateway, static routes, link MTU, DNS servers and search list, with absolute deadlines resolved from the options.
- A pure, replayable protocol core: no clock and no I/O inside the state machine, so a captured exchange can be replayed offline and deterministically.
- Event kinds are Acquired, Changed, Renewed, Lost, Failed and Configured, kept separate so a caller that must reconfigure an interface knows which happened.
DHCPv6 is a separate client type sharing no socket, journal or state enumeration with the IPv4 client, so a dual-stack endpoint can run both. The README states IPv6 is not finished: it takes and keeps a lease, reads the Router Advertisement flags, and supports server-initiated Reconfigure signed with the key the server gave the client. Address formation from a prefix (SLAAC), prefix delegation (IA_PD), Rapid Commit and temporary addresses (IA_TA) are listed as planned for v1.0.0 or later.
Explicitly out of scope: applying addresses, routes or resolvers to the link; address management; acting as a relay agent; DHCPFORCERENEW on IPv4; the DHCPv6 Client FQDN name option; DHCPINFORM on IPv4; reusing a lease after an unanswered reboot; and non-Linux platforms. IPv4 unicast renewal requires the peer's hardware address and does not fall back to broadcast.
The library is pre-1.0 with an unstable API that may change between tagged releases. It is written for and consumed by the docker-net-dhcp network plugin; the library is MIT-licensed while the plugin is GPL-3.0. Testing is driven by a single verify.sh arbiter that needs no root, and the test suite runs against a real dnsmasq server on a veth pair in an unprivileged namespace, asserted against the server's own log and lease file.
Comments
0 Rating appears after 10 ratings
Sign in to join the discussion.