Commit Graph

18 Commits

Author SHA1 Message Date
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