79 Commits

Author SHA1 Message Date
cbrejla
a0841cb303 support v4 dhcp inform messages
Signed-off-by: cbrejla <christoph.brejla@gmail.com>
2026-02-17 19:22:48 +01:00
Rick Beton
60ec8025cd file: Homogenize logging levels with other plugins
Signed-off-by: Rick Beton <rick.beton@gmail.com>
Signed-off-by: Anatole Denis <natolumin@unverle.fr>
2026-01-17 14:58:07 +01:00
Rick Beton
d087353b4b file: Rework leases file parsing to allow trailing comments
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>
2026-01-17 14:58:07 +01:00
Rick Beton
c8a9de0e8b file/tests: Close lease files before running tests
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>
2026-01-17 14:58:07 +01:00
Anatole Denis
6b627b2954 Fix license header for range plugin tests
Fixes: da62c7b1bd5622e127f9e664659299972274e048

Signed-off-by: Anatole Denis <anatole@unverle.fr>
2026-01-12 20:07:56 +01:00
Nikita Vakula
da62c7b1bd
Add DHCP RELEASE message support (#266)
Implement DHCP RELEASE message handling in the range plugin

Signed-off-by: Nikita Vakula <programmistov.programmist@gmail.com>
2026-01-10 20:59:01 +01:00
Wielewout
f7e98e4e35 feat(plugins/range): add support for a single IP address
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>
2025-08-06 09:02:28 +02:00
Anatole Denis
bd8c8089a5 Remove use of deprecated rand.Read
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>
2024-07-09 11:23:56 +02:00
Brian Candler
12a2f4060a Add support for IPv6-only preferred (RFC8925) and
control of link-local autoconfigure (RFC2563)

Signed-off-by: Brian Candler <b.candler@pobox.com>
2024-02-27 19:47:03 +01:00
Andrea Barberio
321f8a6a0c plugins/range: fixed memory leak in sqlite3 usage
Signed-off-by: Andrea Barberio <insomniac@slackware.it>
2024-02-20 21:48:28 +01:00
Andrea Barberio
4458e77f16 plugins/range: added hostname field to database
Signed-off-by: Andrea Barberio <insomniac@slackware.it>
2024-01-19 15:14:36 +01:00
Andrea Barberio
db61ab1cea Replace use of deprecated io/ioutil
All the calls have been converted to their new equivalent.

Signed-off-by: Andrea Barberio <insomniac@slackware.it>
2023-10-18 10:42:47 +02:00
Andrea Barberio
60d5d298be [plugins/range] fix SQL query for record persistence
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>
2023-10-17 10:24:30 +02:00
Andrea Barberio
c43db00314 [plugins/range] use sqlite3 instead of text file
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>
2023-10-14 10:19:02 +02:00
Andrea Barberio
3e32ddb5ac Fix dependabot warnings, bump Go vesions to 1.19 and 1.20
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>
2023-08-08 21:50:49 +02:00
Adphi
a2552c5c1b range: re-allocate leased ips on start up (fixes #153)
Signed-off-by: Adphi <philippe.adrien.nousse@gmail.com>
2022-06-02 17:23:01 +02:00
Adphi
0f369d7237
plugins: add mtu (#149)
Signed-off-by: Adphi <philippe.adrien.nousse@gmail.com>
2022-01-03 14:10:54 +01:00
Reinier Schoof
dcca4ae19a ignore comment lines in file plugin
Signed-off-by: Reinier Schoof <reinier@skoef.nl>
2021-11-29 12:00:46 +01:00
Reinier Schoof
c780ba84df refresh records when leases file is updated
Signed-off-by: Reinier Schoof <reinier@skoef.nl>
2021-11-16 17:38:18 +01:00
Reinier Schoof
461b03784a fixed errors messages and added tests for netmask plugin
Signed-off-by: Reinier Schoof <reinier@skoef.nl>
2021-11-16 17:29:31 +01:00
Reinier Schoof
17ea625277 added tests to file plugin
Signed-off-by: Reinier Schoof <reinier@skoef.nl>
2021-10-13 10:47:05 +02:00
Reinier Schoof
3e75f3b9c4 support booting over HTTP(S) or FTP for DHCPv4 2021-10-12 11:25:57 +02:00
Reinier Schoof
2176f33418 added staticroute plugin
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>
2021-08-30 13:54:04 +02:00
Andrea Barberio
00cc6002b6 Created sleep plugin
The `sleep` plugin introduces a delay in the chain of response to a DHCP
transaction.

Signed-off-by: Andrea Barberio <insomniac@slackware.it>
2021-03-17 20:04:07 +00:00
toshic
10c40bd4e9
Fix address usage check (#125)
Signed-off-by: Anton Kortunov <toshik@yandex-team.ru>

Co-authored-by: Anton Kortunov <toshik@yandex-team.ru>
2021-03-10 18:29:21 +01:00
Anatole Denis
8a89011b1f allocators: Export an error for no address available
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>
2021-02-03 14:04:44 +00:00
Anatole Denis
2a7eb16899 plugins/range: Also persist leases when extending them
Signed-off-by: Anatole Denis <anatole@unverle.fr>
2021-02-03 14:04:44 +00:00
Anatole Denis
1ccd30ecc5 plugins/range: Revamp to make use of allocator
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>
2021-02-03 14:04:44 +00:00
Anatole Denis
9d3fd8dbad plugins/range: Remove setup6 function for range
Signed-off-by: Anatole Denis <anatole@unverle.fr>
2021-02-03 14:04:44 +00:00
Anatole Denis
b6dcd5d4ac allocators: Create a bitmap allocator for IPv4
Signed-off-by: Anatole Denis <anatole@unverle.fr>
2021-02-03 14:04:44 +00:00
Anatole Denis
7b65f6832a plugins/prefix: Fix a panic with empty hints
A missing nilcheck caused prefix allocation to panic for requests
without hints

Signed-off-by: Anatole Denis <anatole@unverle.fr>
2021-01-27 22:28:47 +00:00
William Kronmiller
9e42cc2ca0
Add domain search list plugin (#116)
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>
2021-01-18 20:24:24 +01:00
Anatole Denis
a9aa31766d allocators/bitmap: Lock the bitmap on use
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>
2020-08-09 19:05:58 +02:00
Anatole Denis
de9ac24a42 plugins/prefix: Implement basic lease allocation logic
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>
2020-08-09 19:05:58 +02:00
Anatole Denis
fb0d278233 plugins/allocators: Rename fixedsize to bitmap
Allocators themselves are implementation details for now; bitmap
reflects better the properties of this allocator

Signed-off-by: Anatole Denis <anatole@unverle.fr>
2020-08-09 19:05:58 +02:00
Anatole Denis
6342ac1088 plugins/prefix: Initial plugin handler
Signed-off-by: Anatole Denis <anatole@unverle.fr>
2020-08-09 19:05:58 +02:00
Anatole Denis
6ee08879be plugins: IPv6 Prefix Delegation allocator scaffolding
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>
2020-08-09 19:05:58 +02:00
Brad Beam
156c774032 fix: Create leases file if it does not exist
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>
2020-08-09 09:52:46 +02:00
Anatole Denis
1549302e6c plugin/file: Use an iaid from request in response
Signed-off-by: Anatole Denis <anatole@unverle.fr>
2020-05-01 17:48:01 +01:00
Anatole Denis
355828e59d Split coredhcp.go into server/
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>
2020-04-21 19:45:39 +01:00
Anatole Denis
77ed8c8872 Update dhcp library to latest upstream
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>
2020-04-21 20:35:10 +02:00
Anatole Denis
9afdd65e04 Remove DHCPv6 stub implementations in unsupported plugins
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>
2020-04-21 19:34:50 +01:00
Marc-André Lureau
b4aa45e6f7 serverid: fix v4ServerID copy
net.IP can be 16 bytes, let's copy the To4 version which should be 4 bytes.

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
2020-02-13 23:29:15 +00:00
Andrea Barberio
8bd5261895 Register plugins explicitly
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>
2020-02-07 15:58:02 +00:00
Anatole Denis
70b6e1f8b3 file: Update for breaking changes in insomniacslk/dhcp
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>
2020-01-06 14:48:09 +01:00
Andrea Barberio
dd3966185c [plugins/nbp] Implemented conditional NBP handling
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>
2019-12-18 20:32:05 +00:00
Andrea Barberio
47b2f98fc9 [plugins/file] better logging
Signed-off-by: Andrea Barberio <insomniac@slackware.it>
2019-11-22 14:43:10 +00:00
Andrea Barberio
a10583e456 Moved redis plugin to coredhcp/plugins
We are going to store non-core plugins in a separate repo

Signed-off-by: Andrea Barberio <insomniac@slackware.it>
2019-11-21 18:39:17 +00:00
kworm83
6e2a8c4506 Initial commit of a proposed default lease time plugin. (#66)
* Initial commit of a proposed default lease time plugin.

Signed-off-by: kevin <kworm@missouri-telecom.com>
2019-11-21 16:37:28 +00:00
kworm83
eaaeff9d7a Proposed redis plugin (#64)
* simplify boot file URL

Signed-off-by: kevin <kworm@missouri-telecom.com>
2019-11-20 14:35:43 +00:00