Also warn on duplicate IP/MAC addresses and use netip for a better API
Signed-off-by: Rick Beton <rick.beton@gmail.com>
Signed-off-by: Anatole Denis <natolumin@unverle.fr>
As documentation that the files aren't modified during the test
Signed-off-by: Rick Beton <rick.beton@gmail.com>
Signed-off-by: Anatole Denis <natolumin@unverle.fr>
This is mainly done for usage in a test context, where it would be nice to ensure that only a single IP address can be used.
Signed-off-by: Wielewout <vandewiel.wout@gmail.com>
Using the global rand source is deprecated since go 1.20, so instead we
make an explicit local one with a fixed seed
Signed-off-by: Anatole Denis <anatole@unverle.fr>
The sql query to save a record to the database did just an insert but no
update. This patch fixes it.
Signed-off-by: Andrea Barberio <insomniac@slackware.it>
The range plugin appends every new entry to a text file, without
deduplication, and collisions are possible.
Implementing deduplication on a text file is either inefficient or
tricky. Detecting collisions is inefficient, no matter if it's done in-memory
and then rewriting the entire text file every time, or by parsing the text
file every time.
Sqlite3 offers consistency, uniqueness without performance hit, and can
enforce more complex constraints.
However using sqlite3 requires using CGo, which has a bunch of issues:
* it complicates cross-compiling
* builds are slower
* deployments are more complicated (no more single binary, not easily at least)
I have been running CoreDHCP with the sqlite3-based range plugin in my
home network without issues so far, and no more duplication nor
collisions.
Signed-off-by: Andrea Barberio <insomniac@slackware.it>
Updated all the dependencies and addressed dependabot warnings from 12
to 20, starting at
https://github.com/coredhcp/coredhcp/security/dependabot/12 .
This also required dropping Go 1.14/1.15 and bump to the latest two
versions, 1.19 and 1.20.
Signed-off-by: Andrea Barberio <insomniac@slackware.it>
for configuring one or more classless static routes with DHCP option 121
Signed-off-by: Reinier Schoof <reinier@skoef.nl>
Signed-off-by: Reinier Schoof <reinier.schoof@nl.team.blue>
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>
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>
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>
coredhcp.go is not the entrypoint of main (that's cmds/coredhcp) and
contains many tightly-coupled things that could be separated.
This separates the logic into:
* server/serve.go handles setting up connections
* server/handle.go handles parsing and entry into handlers (in
preparation of a larger rewrite)
* plugins/plugin.go gets plugin loading (and doesn't need to access the
Server struct either)
Signed-off-by: Anatole Denis <anatole@unverle.fr>
There were many changes in the interfaces with the introduction of the
getters. I've fixed the compilation failures, but there must be several
other places we can probably simplify the code
Signed-off-by: Anatole Denis <anatole@unverle.fr>
These plugins don't support IPv6. With the new explicit plugin
registration, completely omitting the setup function for ipv6 in that
case is now possible.
Signed-off-by: Anatole Denis <anatole@unverle.fr>
Fixes#45
Do not use `init()` magic to register plugins, do it explicitly. This is
done by requiring plugins to declare a populated `Plugin` symbol of type
`plugins.Plugin`.
Signed-off-by: Andrea Barberio <insomniac@slackware.it>
https://github.com/insomniacslk/dhcp/pull/347 changed struct
OptIAAddress to use time.Duration for lifetimes. This is a breaking
change and users need to update.
Note that it still compiles without the changes as time.Duration is an
int64, but the values become incorrect (3600 ns rounded as 0s, instead of 3600s)
Signed-off-by: Anatole Denis <anatole@unverle.fr>
The nbp plugin adds support for network boot programs in both v4 and v6
scenarios. In DHCPv6 we support bootfile URL and params, in DHPv4 we
support tftp server and file name.
Signed-off-by: Andrea Barberio <insomniac@slackware.it>