Commit Graph

28 Commits

Author SHA1 Message Date
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
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
17ea625277 added tests to file plugin
Signed-off-by: Reinier Schoof <reinier@skoef.nl>
2021-10-13 10:47:05 +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
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
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
Pablo Mazzini
1f868210be simplify boot file URL 2019-10-09 16:19:29 +01:00
Andrea Barberio
04b1f8354b [plugins/file] do not stop when an entry is found
The plugin currently stops when when an entry is found. This does not
let the following plugins to run, and it makes no sense.

Signed-off-by: Andrea Barberio <insomniac@slackware.it>
2019-09-25 18:56:02 +01:00
Andrea Barberio
4861d2ce08 Added license headers
Signed-off-by: Andrea Barberio <insomniac@slackware.it>
2019-09-18 13:59:16 +01:00
Anatole Denis
79f78359c2 plugins/dns: Implement DHCPv6 support (#54)
* plugins/dns: Implemented DHCPv6 support

Signed-off-by: Anatole Denis <anatole@unverle.fr>

* plugins/file: Remove hardcoded DNS servers

Those are handled by the DNS plugin and don't need to be hardcoded anymore

Signed-off-by: Anatole Denis <anatole@unverle.fr>

* plugins/dns: Only send option when requested

Both DHCP versions have a means for the client to specify what
additional information to send with replies. This adds logic to respect
that.

There is a difference between the protocols as to what happens when this
option doesn't exist. In DHCPv6, the option is mandatory. In DHCPv4 it
is not and indicates the server may send whatever it deems relevant

Signed-off-by: Anatole Denis <anatole@unverle.fr>

* Update dhcp library dependency

This pulls the enhancement from https://github.com/insomniacslk/dhcp/pull/315

generated by `go get github.com/insomniacslk/dhcp && go mod tidy`

Signed-off-by: Anatole Denis <anatole@unverle.fr>
2019-09-17 09:32:31 +01:00
Anatole Denis
1a8a757049 Stop returning nil, false in plugins (#51)
* handler: Fix documentation of plugin chaining

This condition was backwards: if the boolean is false, the next plugins
are called and any invalid or nil packet is very likely to cause crashes
in the next plugin. OTOH if true, we stop execution anyway and don't
send a message when resp == nil, so it's OK to be nil or invalid then

Signed-off-by: Anatole Denis <anatole@unverle.fr>

* plugins/file: Avoid nil returns to next plugin

`return nil, false` passes a nil dhcp message to the next plugin in
chain, which is almost guaranteed to crash or fail in some other way.
The proper way to ignore a valid message (because we don't know what to
do with it) is to return the resp argument. The ipv4 version of the
plugin already does so.

Add a note about file being a terminating plugin when a response is
chosen

Signed-off-by: Anatole Denis <anatole@unverle.fr>

* plugins/server_id: Uniformize error returns

`return resp, false` after a log.Fatal is misleading, since the program
will have crashed at this point. `return nil, true` is still dead code
but conveys the meaning of "abort here" better

Same thing for the DHCPv4 version of the code which was forgotten in the
original commit.

Remove the test for `resp == nil` since the previous commits in this
series removed the possibility of receiving a nil resp as argument

Fixes: 4a73abd6 ("plugins/server_id: Abort when ServerID is nil")
Signed-off-by: Anatole Denis <anatole@unverle.fr>
2019-09-13 20:02:35 +01:00
Anatole Denis
b566efa666 plugins: Decapsulate DHCPv6 relayed requests
The `request` argument to handlers passes the full DHCPv6 message as
received by the server. Notably, relayed messages will stay encapsulated
in each other. These two plugins (server_id and file) are accessing the
options of the outermost message, causing incorrect behavior when
handling relayed messages.

Signed-off-by: Anatole Denis <anatole@unverle.fr>
2019-09-12 23:00:48 +02:00
Andrea Barberio
8f8c7489f6 [plugins/file] fix docs
godoc github.com/coredhcp/coredhcp/plugins/file now shows up correctly

Signed-off-by: Andrea Barberio <insomniac@slackware.it>
2019-08-26 23:08:05 +01:00
Andrea Barberio
a8ccf129b5 [plugins/file] Added documentation
Signed-off-by: Andrea Barberio <insomniac@slackware.it>
2019-08-26 22:18:23 +01:00
Andrea Barberio
b9d7c74d44 Logger: add prefix to log lines
This is useful to automatically provide context about what component of
the framework is emitting a log line.

Example output:
```
$ go build && sudo ./coredhcp
[2019-08-25T21:39:26+01:00]  INFO plugins: Registering plugin "dns"
[2019-08-25T21:39:26+01:00]  INFO plugins: Registering plugin "file"
[2019-08-25T21:39:26+01:00]  INFO plugins: Registering plugin "netmask"
[2019-08-25T21:39:26+01:00]  INFO plugins: Registering plugin "range"
[2019-08-25T21:39:26+01:00]  INFO plugins: Registering plugin "router"
[2019-08-25T21:39:26+01:00]  INFO plugins: Registering plugin "server_id"
[2019-08-25T21:39:26+01:00]  INFO config: Loading configuration
[2019-08-25T21:39:26+01:00]  INFO config: DHCPv4: found plugin `server_id` with 1 args: [10.10.10.1]
[2019-08-25T21:39:26+01:00]  INFO config: DHCPv4: found plugin `dns` with 2 args: [8.8.8.8 8.8.4.4]
[2019-08-25T21:39:26+01:00]  INFO config: DHCPv4: found plugin `router` with 1 args: [10.10.10.1]
[2019-08-25T21:39:26+01:00]  INFO config: DHCPv4: found plugin `netmask` with 1 args: [255.255.255.0]
[2019-08-25T21:39:26+01:00]  INFO config: DHCPv4: found plugin `range` with 4 args: [leases.txt 10.10.10.100 10.10.10.200 60s]
[2019-08-25T21:39:26+01:00]  INFO coredhcp: Loading plugins...
[2019-08-25T21:39:26+01:00]  INFO coredhcp: DHCPv4: loading plugin `server_id`
[2019-08-25T21:39:26+01:00]  INFO plugins/server_id: plugins/server_id: loading `server_id` plugin for DHCPv4
[2019-08-25T21:39:26+01:00]  INFO coredhcp: DHCPv4: loading plugin `dns`
[2019-08-25T21:39:26+01:00]  INFO plugins/dns: loaded plugin for DHCPv4.
[2019-08-25T21:39:26+01:00]  INFO plugins/dns: loaded 2 DNS servers.
[2019-08-25T21:39:26+01:00]  INFO coredhcp: DHCPv4: loading plugin `router`
[2019-08-25T21:39:26+01:00]  INFO plugins/router: plugins/router: loaded plugin for DHCPv4.
[2019-08-25T21:39:26+01:00]  INFO plugins/router: plugins/router: loaded 1 router IP addresses.
[2019-08-25T21:39:26+01:00]  INFO coredhcp: DHCPv4: loading plugin `netmask`
[2019-08-25T21:39:26+01:00]  INFO plugins/netmask: plugins/netmask: loaded plugin for DHCPv4.
[2019-08-25T21:39:26+01:00]  INFO plugins/netmask: plugins/netmask: loaded client netmask
[2019-08-25T21:39:26+01:00]  INFO coredhcp: DHCPv4: loading plugin `range`
[2019-08-25T21:39:26+01:00]  INFO plugins/range: plugins/range: reading leases from leases.txt
[2019-08-25T21:39:26+01:00]  INFO plugins/range: plugins/range: loaded 1 leases from leases.txt
[2019-08-25T21:39:26+01:00]  INFO coredhcp: Starting DHCPv4 listener on 0.0.0.0:67
[2019-08-25T21:39:26+01:00]  INFO coredhcp: Waiting
```

Signed-off-by: Andrea Barberio <insomniac@slackware.it>
2019-08-26 09:49:10 +02:00
borna-blazevic
1e3cb1982d IPv4 server plugin (#40)
* Basic DHCPv4 server, needs more work

Signed-off-by: borna_blazevic <borna.blazevic@sartura.hr>
2019-08-23 09:53:34 +01:00
Andrea Barberio
4b1e2c6c17 Added FIXME entries
Signed-off-by: Andrea Barberio <insomniac@slackware.it>
2019-07-15 20:55:55 +01:00
Andrea Barberio
c54b03d33a CI: linters and fixes
Signed-off-by: Andrea Barberio <insomniac@slackware.it>
2019-07-14 20:19:52 +01:00
Andrea Barberio
5b3e2075c1 plugins/file: better logging
Signed-off-by: Andrea Barberio <insomniac@slackware.it>
2019-07-14 17:06:38 +01:00
Andrea Barberio
c7d962327a Config file now requires interface name
The interface name is necessary to create multicast listeners.

Signed-off-by: Andrea Barberio <insomniac@slackware.it>
2019-04-19 20:37:10 +01:00
Andrea Barberio
f3d1f9896c Implemented DHCPv4 main handler 2019-01-19 17:23:41 +00:00
Andrea Barberio
0f423ad80d Switched to logrus 2019-01-06 11:47:51 +01:00
Andrea Barberio
c18c21e923 Fixed imports with new path 2018-12-19 14:34:21 +00:00
Andrea Barberio
8092679242 Initial import 2018-11-27 20:20:28 +00:00