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