A CoreDHCP plugin with a pull-through cache that uses SMD as its source of truth. This is part of the OpenCHAMI project.
This repository contains two plugins:
-
coresmd --- The purpose of this plugin is to provide DHCP leases based on data from SMD.
-
bootloop --- The purpose of this plugin is to be a "catch-all" that causes nodes/BMCs/etc. unknown to SMD to get a temporary IP address from a pool with a short, user-defined lease time. This is so that if they are ever added to SMD, they will quickly get a longer lease from the coresmd plugin.
An iPXE boot script that simply reboots is served to anything that can boot to force the whole DHCP handshake (DORA) to reoccur to obtain a new lease. If the plugin receives a DHCPREQUEST and its IP is already leased, a DHCPNAK is sent so that it will reinitiate the entire DHCP handshake.
The goal is to have any MAC addresses that are unknown continually try and get a new IP address in the case they become known, but to also give them (especially BMCs) a temporary IP address so that they can be discovered (e.g. by Magellan.
This is meant to be built statically into CoreDHCP using the coredhcp-generator.
This project uses GoReleaser to automate releases and include additional build metadata such as commit info, build time, and versioning. Below is a guide on how to set up and build the project locally using GoReleaser.
To include detailed build metadata, ensure the following environment variables are set:
- GIT_STATE: Indicates whether there are uncommitted changes in the working directory. Set to clean if the repository is clean, or dirty if there are uncommitted changes.
- BUILD_HOST: The hostname of the machine where the build is being performed.
- GO_VERSION: The version of Go used for the build. GoReleaser uses this to ensure consistent Go versioning information.
- BUILD_USER: The username of the person or system performing the build.
Set all the environment variables with:
export GIT_STATE=$(if git diff-index --quiet HEAD --; then echo 'clean'; else echo 'dirty'; fi)
export BUILD_HOST=$(hostname)
export GO_VERSION=$(go version | awk '{print $3}')
export BUILD_USER=$(whoami)
Once the environment variables are set, you can build the project locally using GoReleaser in snapshot mode (to avoid publishing).
Follow the installation instructions from GoReleaser’s documentation.
- Run GoReleaser in snapshot mode with the --snapshot and --skip-publish flags to create a local build without attempting to release it:
goreleaser release --snapshot --skip publish --clean
- Check the dist/ directory for the built binaries, which will include the metadata from the environment variables. You can inspect the binary output to confirm that the metadata was correctly embedded.
This repository includes a Dockerfile that builds CoreDHCP with its core plugins as well as this plugin.
docker build . --tag coresmd:latest
Prerequisites:
- go >= 1.21
- git
- bash
- sed
NOTE: Certain source files in CoreDHCP only build on Linux, which will cause build errors when building on other platforms like Mac.
It is recommended to do this within a clean directory.
-
Create directory for generated source files:
mkdir build
-
Clone CoreSMD (NOTE: This is not strictly necessary for CoreDHCP, but is necessary to include the plugin version).
git clone https://github.com/OpenCHAMI/coresmd
Generate the plugin version:
./coresmd/gen_version.bash
-
Clone CoreDHCP and change the working directory to the coredhcp-generator tool.
git clone https://github.com/coredhcp/coredhcp cd coredhcp/cmds/coredhcp-generator
-
Build the generator.
go mod download go build
-
Run the generator to generate the CoreDHCP source file.
./coredhcp-generator \ -f core-plugins.txt \ -t coredhcp.go.template \ -o ../../../build/coredhcp.go \ github.com/OpenCHAMI/coresmd/coresmd \ github.com/OpenCHAMI/coresmd/bootloop
You should see output similar to the following:
2024/10/25 10:33:42 Generating output file '../../../build/coredhcp.go' with 17 plugin(s): 2024/10/25 10:33:42 1) github.com/coredhcp/coredhcp/plugins/autoconfigure 2024/10/25 10:33:42 2) github.com/coredhcp/coredhcp/plugins/ipv6only 2024/10/25 10:33:42 3) github.com/coredhcp/coredhcp/plugins/nbp 2024/10/25 10:33:42 4) github.com/coredhcp/coredhcp/plugins/range 2024/10/25 10:33:42 5) github.com/coredhcp/coredhcp/plugins/leasetime 2024/10/25 10:33:42 6) github.com/coredhcp/coredhcp/plugins/mtu 2024/10/25 10:33:42 7) github.com/coredhcp/coredhcp/plugins/router 2024/10/25 10:33:42 8) github.com/OpenCHAMI/coresmd/bootloop 2024/10/25 10:33:42 9) github.com/coredhcp/coredhcp/plugins/sleep 2024/10/25 10:33:42 10) github.com/coredhcp/coredhcp/plugins/staticroute 2024/10/25 10:33:42 11) github.com/coredhcp/coredhcp/plugins/prefix 2024/10/25 10:33:42 12) github.com/coredhcp/coredhcp/plugins/serverid 2024/10/25 10:33:42 13) github.com/coredhcp/coredhcp/plugins/searchdomains 2024/10/25 10:33:42 14) github.com/OpenCHAMI/coresmd/coresmd 2024/10/25 10:33:42 15) github.com/coredhcp/coredhcp/plugins/dns 2024/10/25 10:33:42 16) github.com/coredhcp/coredhcp/plugins/file 2024/10/25 10:33:42 17) github.com/coredhcp/coredhcp/plugins/netmask 2024/10/25 10:33:42 Generated file '../../../build/coredhcp.go'. You can build it by running 'go build' in the output directory. ../../../build
-
Change directory into the directory, initialize it as a Go module.
cd ../../../build go mod init coredhcp # the module name doesn't matter go mod edit -go=1.21 go mod edit -replace=github.com/coredhcp/coredhcp=../coredhcp go mod edit -replace=github.com/OpenCHAMI/coresmd=../coresmd go mod tidy
-
Build CoreDHCP.
go build
You'll now have a coredhcp
binary in the current directory you can run.
CoreDHCP requires a config file to run. An example config.yaml
can be found at
resources/config.example.yaml
. That file contains comments on when/how to use
the coresmd and bootloop plugins, including which arguments to pass.
Before running CoreDHCP, the OpenCHAMI services (namely BSS and SMD) should already be configured and running using the base URL and boot script base URL configured in the CoreDHCP config file.
With default configuration, no preparation is needed.
Coresmd comes with a built-in TFTP server that includes iPXE bootloader binaries for 32-/64-bit x86/ARM (EFI) and legacy x86 CPU architectures.
When using the bootloop plugin, if the boot script path is set to "default" (see example config file), then the built-in reboot iPXE script is used for unknown nodes. This can be changed to a path in TFTP to an alternate custom iPXE boot script if different functionality is desired. Of course, whatever path is specified must exist on the TFTP server.
After the above prerequisites have been completed, CoreDHCP can be run with its config file. It can be run in a container or on bare metal, though if running via container host networking is required.
For example, to run using Docker:
docker run --rm -v <path_to_config_file>:/etc/coredhcp/config.yaml:ro ghcr.io/OpenCHAMI/coresmd:latest