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