blob: 622452bd84c8dc14f7f93e32b9e2bd54333bb6ff [file] [log] [blame]
Tim Windelschmidt6d33a432025-02-04 14:34:25 +01001// Copyright The Monogon Project Authors.
Lorenz Brun56a7ae62020-10-29 11:03:30 +01002// SPDX-License-Identifier: Apache-2.0
Lorenz Brun56a7ae62020-10-29 11:03:30 +01003
Serge Bazanski216fe7b2021-05-21 18:36:16 +02004// Package dhcp4c provides a client implementation of the DHCPv4 protocol
5// (RFC2131) and a few extensions for Linux-based systems.
Lorenz Brun56a7ae62020-10-29 11:03:30 +01006// The code is split into three main parts:
Tim Windelschmidt99e15112025-02-05 17:38:16 +01007// - The core DHCP state machine, which lives in dhcpc.go
8// - Mechanisms to send and receive DHCP messages, which live in transport/
9// - Standard callbacks which implement necessary kernel configuration steps in
10// a simple and standalone way living in callback/
Lorenz Brun56a7ae62020-10-29 11:03:30 +010011//
Serge Bazanski216fe7b2021-05-21 18:36:16 +020012// Since the DHCP protocol is ugly and underspecified (see
13// https://tools.ietf.org/html/draft-ietf-dhc-implementation-02 for a subset of
14// known issues), this client slightly bends the specification in the following
15// cases:
Tim Windelschmidt99e15112025-02-05 17:38:16 +010016// - IP fragmentation for DHCP messages is not supported for both sending and
17// receiving messages This is because the major servers (ISC, dnsmasq, ...)
18// do not implement it and just drop fragmented packets, so it would be
19// counterproductive to try to send them. The client just attempts to send
20// the full message and hopes it passes through to the server.
21// - The suggested timeouts and wait periods have been tightened significantly.
22// When the standard was written 10Mbps Ethernet with hubs was a common
23// interconnect. Using these would make the client extremely slow on today's
24// 1Gbps+ networks.
25// - Wrong data in DHCP responses is fixed up if possible. This fixing includes
26// dropping prohibited options, clamping semantically invalid data and
27// defaulting not set options as far as it's possible. Non-recoverable
28// responses (for example because a non-Unicast IP is handed out or lease
29// time is not set or zero) are still ignored. All data which can be stored
30// in both DHCP fields and options is also normalized to the corresponding
31// option.
32// - Duplicate Address Detection is not implemented by default. It's slow, hard
33// to implement correctly and generally not necessary on modern networks as
34// the servers already waste time checking for duplicate addresses. It's
35// possible to hook it in via a LeaseCallback if necessary in a given
36// application.
Lorenz Brun56a7ae62020-10-29 11:03:30 +010037//
Serge Bazanski216fe7b2021-05-21 18:36:16 +020038// Operationally, there's one known caveat to using this client: If the lease
39// offered during the select phase (in a DHCPOFFER) is not the same as the one
40// sent in the following DHCPACK the first one might be acceptable, but the
41// second one might not be. This can cause pathological behavior where the
42// client constantly switches between discovering and requesting states.
43// Depending on the reuse policies on the DHCP server this can cause the client
44// to consume all available IP addresses. Sadly there's no good way of fixing
45// this within the boundaries of the protocol. A DHCPRELEASE for the adresse
46// would need to be unicasted so the unaccepable address would need to be
47// configured which can be either impossible if it's not valid or not
48// acceptable from a security standpoint (for example because it overlaps with
49// a prefix used internally) and a DHCPDECLINE would cause the server to
50// blacklist the IP thus also depleting the IP pool.
51// This could be potentially avoided by originating DHCPRELEASE packages from a
52// userspace transport, but said transport would need to be routing- and
53// PMTU-aware which would make it even more complicated than the existing
Lorenz Brun56a7ae62020-10-29 11:03:30 +010054// BroadcastTransport.
55package dhcp4c