18 Commits

Author SHA1 Message Date
Anatole Denis
6eeca26bee config: Allow overriding config location from flags
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>
2020-05-01 19:01:59 +02:00
Anatole Denis
227f60d8eb config: Re-add interface keyword to keep compatibility
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>
2020-04-21 19:45:39 +01:00
Anatole Denis
18c78ca266 config: Setup pleasant defaults for listen
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>
2020-04-21 19:45:39 +01:00
Anatole Denis
fcc0c8fbb9 config: Expand unspecified ll-mcast to all interfaces
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>
2020-04-21 19:45:39 +01:00
Anatole Denis
52c5f423c8 config: Remove a layer of indirection in ServerConfig
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>
2020-04-21 19:45:39 +01:00
Anatole Denis
ca2b5ac2d6 Allow listening on multiple addresses at once
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>
2020-04-21 19:45:39 +01:00
Anatole Denis
3806733ad7 config: Extend getListenAddress for ip%zone
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>
2020-04-21 19:45:39 +01:00
Andrea Barberio
4861d2ce08 Added license headers
Signed-off-by: Andrea Barberio <insomniac@slackware.it>
2019-09-18 13:59:16 +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
Andrea Barberio
3fc2408960 dhcpv6: Joining multicast group offloaded to dhcp library
This has been offloaded to the DHCP library in
https://github.com/insomniacslk/dhcp/pull/278

Signed-off-by: Andrea Barberio <insomniac@slackware.it>
2019-04-29 19:03:19 +01:00
Dipen Lad
372d95460f Improved DHCP v4 support (#25)
* 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>
2019-04-22 13:14:48 +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
ad0749218a Unified config and plugin loading for v6 and v4 2019-01-14 23:27:55 +00:00
Andrea Barberio
6c9cb6d64b Cleaner Config interface 2019-01-13 11:48:08 +00:00
Andrea Barberio
db6f273f55 Added Travis-CI configuration 2019-01-12 18:58:58 +00:00
Andrea Barberio
0f423ad80d Switched to logrus 2019-01-06 11:47:51 +01:00
Andrea Barberio
8092679242 Initial import 2018-11-27 20:20:28 +00:00