This lets the user specify a configuration file to load, disregarding
the builtin heuristics for locating it
Signed-off-by: Anatole Denis <anatole@unverle.fr>
This re-adds an `interface` keyword in the configuration to keep
compatibility with existing configuration files. The behaviour is
emulated in terms of the `listen` keyword.
Both cannot be used together, but since listen wasn't an accepted
keyword previously, users are expected to remove the old one when they
add the new one
Signed-off-by: Anatole Denis <anatole@unverle.fr>
This makes a server block without a listen instruction, by default:
* On v4 listen on broadcast (no functional change)
* On v6 listen on ff02::1:2 on all capable interfaces and ff05::1:3 on
the default multicast interface
Which should hopefully be a better solution than the behaviour from the
dhcp library (listening on wildcard)
Signed-off-by: Anatole Denis <anatole@unverle.fr>
Specifying a link-local multicast address to listen on without an
interface is rejected. Instead, list all available interfaces where it
makes sense ("MULTICAST" flag) and listen on all of them, which is the
least-surprising behaviour.
This will be needed to have sane default values since the RFC specifies
a default link-local multicast address to listen on
Document a surprising behaviour when interfaces appear and disappear
during runtime. Note it is *not* a regression as the previous behaviour
was worse (join the mcast group on only one interface with a default
route)
Signed-off-by: Anatole Denis <anatole@unverle.fr>
It wasn't really necessary to hold pointers inside a slice (itself a
pointer to array) inside a struct with pointer-recever methods. It's
easier to understand and reason about like this
Signed-off-by: Anatole Denis <anatole@unverle.fr>
This extends both the configuration and the server, to allow binding the
server(s) to multiple addresses at once.
The `listen` stanza can now accept either a string (for a single address) or
a list to listen to multiple addresses, ie all of these are valid:
```yaml
server6:
...
server6:
listen: "[2001:db8:🅰️2]"
...
server6:
listen:
- "[2001:db8:🅰️2]:530"
- "%eth0"
```
and the equivalent for server4
Signed-off-by: Anatole Denis <anatole@unverle.fr>
This removes the `interface` configuration statement and makes coredhcp
accept a wider range of specifications in the `listen` configuration
statement, notably:
* Omitting the statement entirely yields the default behaviour:
listening on `[::]:547`(and joining `ff02::1:2` and `ff05::1:3`) or
`0.0.0.0:67`
* Omitting the `:port` is accepted and means the default port for the
protocol version. Conversely specifying `:port` means `[::]:port` or
`0.0.0.0:port`
* `ip%iface` and `ip%iface:port` are accepted, and result in binding to the
specified interface. This is the general replacement for the
interface statement
* `%iface` and `%iface:port` are also accepted and mean the wildcard
address, for a direct replacement of having interface specified but
listen empty
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>
* Allow server with v4 to work without v6
Signed-off-by: Dipen Lad <dipen.lad@gmail.com>
* Add support for DHCPv4 relays
Signed-off-by: Dipen Lad <dipen.lad@gmail.com>