When the broadcast bit isn't set in the request, send responses to the L3 address we're assigning, using the peer L2 address, as that's the preferred behavior according to the RFC
Signed-off-by: Daniel Zainzinger <dza1@mailbox.org>
Co-authored-by: Daniel Zainzinger <dza1@mailbox.org>
Viper doesn't support running from gopath at all anymore
(https://github.com/spf13/viper/blob/master/TROUBLESHOOTING.md#cannot-find-package)
causing the hcl import error.
We can actually just init a stub go module here, and let whichever of
our dependencies specify their own needs in their own go.mod files. This
ends up resolving to "latest" for all our dependencies, which is roughly
equivalent to not having modules at all
Signed-off-by: Anatole Denis <anatole@unverle.fr>
This is a sentinel error that downstream users should be able to compare
against to identify when the allocator is out of addresses, move it from
the bitmap allocator package to the general allocator interface package
Signed-off-by: Anatole Denis <anatole@unverle.fr>
Mixed improvements to overhaul the plugin
* Use the allocator interface to allocate IPs
* Focus on correctness by wrapping a lock for now; we'll improve that
with some more fine-grained concurrency later
* move things related to file storage of leases to a separate source
file and add some minimal sanity-check tests
* Don't open and close the file descriptor on every single packet
Signed-off-by: Anatole Denis <anatole@unverle.fr>
Codecov uses the location of files on disk during coverage, which in our
action has an additional prefix compared to the path in the repo, making
some of the stats in codecov not work.
https://docs.codecov.io/docs/fixing-paths explains how to address that
Signed-off-by: Anatole Denis <anatole@unverle.fr>
Switched `cmd/coredhcp-generator`, and as a consequence also
`cmd/coredhcp`, to `spf13/pflag` instead of the standard `flag`.
`pflag` gives GNU-style flags and supports args before flags, among many
other things.
Also copied `go.mod` and `go.sum` to the destination directory so it can
be built with go modules.
Signed-off-by: Andrea Barberio <insomniac@slackware.it>
Add searchdomains plugin to specify a list of default
search domains for DHCPv4 and DHCPv6 clients.
Signed-off-by: William Rory Kronmiller <wkronmiller@Williams-MacBook-Pro.local>
This allocator was not safe for concurrent access. Add a simple lock
around operations on the bitmap itself to protect from that
Signed-off-by: Anatole Denis <anatole@unverle.fr>
This implements the meat of the plugin, which stores allocated leases
(only in memory) but also a basic heuristic to allocate leases to
requests.
The logic will not provide the best fit; it tries to do something
reasonable but there is no universal best behavior here.
Performance hasn't been considered at this point, because lease storage
will be moved out into its own plugin(s) in the future.
Signed-off-by: Anatole Denis <anatole@unverle.fr>
Allocators themselves are implementation details for now; bitmap
reflects better the properties of this allocator
Signed-off-by: Anatole Denis <anatole@unverle.fr>
To build an IPv6 Prefix Delegation plugin, we'll need allocation
strategies as well as the plugin itself.
This adds scaffolding for prefix allocators
* allocator.go contains interfaces to interact with the allocators
* ipcalc has helper functions to simplify indexing tables/hash ipv6
addresses
* fixedsize is a trivial allocator that always reserves a prefix of the
same size (eg /64) regardless of what the client requests
Signed-off-by: Anatole Denis <anatole@unverle.fr>
golangci-lint's documentation recommends running from a stable version
(and doesn't guarantee master will work). We did not have issues because
we accidentally had it in our go.mod, so we had a pinned version.
Signed-off-by: Anatole Denis <anatole@unverle.fr>
Go 1.13 introduced a new interface in the standard library to wrap
errors and the %w modifier to fmt.Errorf which we couldn't use before
since our go.mod declares go 1.12
Signed-off-by: Anatole Denis <anatole@unverle.fr>
We had a couple modules in the go.mod that we don't use anymore since
plugins were moved out into a separate repo.
Ran go mod tidy to also add missed indirect deps
Signed-off-by: Anatole Denis <anatole@unverle.fr>
If the leases.txt file was not present on the system, coredhcp would
fail to start --
```
level=info msg="DHCPv4: loading plugin `range`" prefix=plugins
level=warning msg="Failed to close file leases.txt: invalid argument" prefix="plugins/range"
level=fatal msg="cannot open lease file leases.txt: open leases.txt: no such file or directory" prefix=main
```
This changes the call to include the O_CREATE flag to create the
leases file if it does not already exist.
Signed-off-by: Brad Beam <brad.beam@b-rad.info>
This revamps the provided example configuration to have a
self-documented example configuration file, with comments explaining
each available option and its meaning
Signed-off-by: Anatole Denis <anatole@unverle.fr>
This lets the user specify a configuration file to load, disregarding
the builtin heuristics for locating it
Signed-off-by: Anatole Denis <anatole@unverle.fr>
Linters don't depend on the go version, they can run only once instead
of once per go version, simplifying the standard tests
Signed-off-by: Anatole Denis <anatole@unverle.fr>
Force the plugin list to be sorted in the generator, and change
cmd/coredhcp/main.go to use the same naming scheme and order as the
generated version
Signed-off-by: Anatole Denis <anatole@unverle.fr>
The template and the base main.go have drifted. This updates the
template to follow the current main.go in cmds/coredhcp.
Signed-off-by: Anatole Denis <anatole@unverle.fr>
The "range" plugin has a name that conflicts with a reserved keyword.
Use "pl_<pluginname>" as import name for all plugins, which will not
conflict with any reserved keywords for go 1, removing the special case
Signed-off-by: Anatole Denis <anatole@unverle.fr>
Including the ability to specify plugins as cli args, and the
possibility of giving builtin plugins as shortnames
Signed-off-by: Anatole Denis <anatole@unverle.fr>
For plugins passed on the CLI, accept the bare name (eg "dns") for core
plugins, for simpler invocations for testing eg `./coredhcp-generator dns file`
The -from option (using a separate file) still requires the full import
path
Signed-off-by: Anatole Denis <anatole@unverle.fr>