support netmask/gateway for file plugin #147
Open
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
In my setup, I have multiple ranges on the same network. I'm using the
file
plugin to give each host a static IP and rely on thenetmask
androuter
plugin to set the right netmask/gateway to the DHCP offer. The config looks like this:leases_1.txt:
leases_2.txt:
config.yaml:
So a request from
00:11:22:33:44:55
gets a netmask set to255.255.255.0
and router to10.0.0.1
and then get the address set by thefile
plugin. This plugin then tells coredhcp to stop processing this request as it has found a match.A request from
11:22:33:44:55:66
gets a netmask set to255.255.255.0
, router to10.0.0.1
. The file plugin forleases_1.txt
does not find a match. The netmask is updated to255.255.255.128
, router to10.1.0.129
and then the file plugin forleases_2.txt
finds a match and the processing of this request is done.While this works, configuring this can become quite verbose when you have more than a couple of ranges in the same network. This PR allows to specify the netmask and gateway for IPv4 records directly in the leases file (IPv6 leases get their prefixes from router advertisements) so the configuration would become:
leases.txt:
config.yaml:
Since
LoadDHCPv4Records
andLoadDHCPv6Records
were almost identical by now, I merged them intoloadDHCPRecords
while at it.