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>
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>
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>
* 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>
* 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>
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>
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>