Switch to Kea for dhcp4 servec
This commit is contained in:
+64
-32
@@ -6,7 +6,8 @@ let
|
|||||||
|
|
||||||
join-lines = concatStringsSep "\n";
|
join-lines = concatStringsSep "\n";
|
||||||
|
|
||||||
traceout = out: builtins.trace out out;
|
inherit (pkgs.lib.ip)
|
||||||
|
getNetworkBase maskFromV32Network networkMinIp networkMaxIp;
|
||||||
|
|
||||||
in {
|
in {
|
||||||
|
|
||||||
@@ -14,6 +15,11 @@ in {
|
|||||||
|
|
||||||
enable = mkEnableOption "Enable local network configuration (DHCP & DNS).";
|
enable = mkEnableOption "Enable local network configuration (DHCP & DNS).";
|
||||||
|
|
||||||
|
state-directory = mkOption {
|
||||||
|
type = str;
|
||||||
|
description = "Path at which to store server state.";
|
||||||
|
};
|
||||||
|
|
||||||
domain = mkOption {
|
domain = mkOption {
|
||||||
type = str;
|
type = str;
|
||||||
description = "The domain to use for the local network.";
|
description = "The domain to use for the local network.";
|
||||||
@@ -120,38 +126,64 @@ in {
|
|||||||
hostname
|
hostname
|
||||||
]) other-hosts;
|
]) other-hosts;
|
||||||
|
|
||||||
services.dhcpd4 = let zone = cfg.zone-definition;
|
services.kea = {
|
||||||
in {
|
|
||||||
enable = true;
|
enable = true;
|
||||||
|
settings = {
|
||||||
machines = mapAttrsToList (hostname: hostOpts: {
|
interfaces-config.interfaces = cfg.dhcp-interfaces;
|
||||||
ethernetAddress = hostOpts.mac-address;
|
lease-database = {
|
||||||
hostName = hostname;
|
name = "${cfg.state-directory}/dhcp4.leases";
|
||||||
ipAddress = hostOpts.ipv4-address;
|
type = "memfile";
|
||||||
}) (filterAttrs (host: hostOpts:
|
persist = true;
|
||||||
hostOpts.mac-address != null && hostOpts.ipv4-address != null)
|
};
|
||||||
zone.hosts);
|
valid-lifetime = 4000;
|
||||||
|
rebind-timer = 2000;
|
||||||
interfaces = cfg.dhcp-interfaces;
|
renew-timer = 1000;
|
||||||
|
option-data = [
|
||||||
extraConfig = ''
|
{
|
||||||
subnet ${pkgs.lib.ip.getNetworkBase cfg.network} netmask ${
|
name = "domain-name-servers";
|
||||||
pkgs.lib.ip.maskFromV32Network cfg.network
|
data = cfg.dns-servers;
|
||||||
} {
|
}
|
||||||
authoritative;
|
{
|
||||||
option subnet-mask ${pkgs.lib.ip.maskFromV32Network cfg.network};
|
name = "subnet-mask";
|
||||||
option broadcast-address ${pkgs.lib.ip.networkMaxIp cfg.network};
|
data = maskFromV32Network cfg.network;
|
||||||
option routers ${cfg.gateway};
|
}
|
||||||
option domain-name-servers ${concatStringsSep " " cfg.dns-servers};
|
{
|
||||||
option domain-name "${cfg.domain}";
|
name = "broadcast-address";
|
||||||
option domain-search "${
|
data = networkMaxIp cfg.network;
|
||||||
concatStringsSep " " ([ cfg.domain ] ++ cfg.search-domains)
|
}
|
||||||
}";
|
{
|
||||||
range ${pkgs.lib.ip.networkMinIp cfg.dhcp-dynamic-network} ${
|
name = "routers";
|
||||||
pkgs.lib.ip.networkMaxButOneIp cfg.dhcp-dynamic-network
|
data = cfg.gateway;
|
||||||
};
|
}
|
||||||
}
|
{
|
||||||
'';
|
name = "domain-name";
|
||||||
|
data = cfg.domain;
|
||||||
|
}
|
||||||
|
{
|
||||||
|
name = "domain-search";
|
||||||
|
data = [ cfg.domain ] ++ cfg.search-domains;
|
||||||
|
}
|
||||||
|
];
|
||||||
|
subnet4 = [{
|
||||||
|
pools = [{
|
||||||
|
pool = let
|
||||||
|
minIp = networkMinIp cfg.dhcp-dynamic-network;
|
||||||
|
maxIp = networkMaxIp cfg.dhcp-dynamic-nework;
|
||||||
|
in "${minIp} - ${maxIp}";
|
||||||
|
}];
|
||||||
|
subnet = cfg.network;
|
||||||
|
reservations = let
|
||||||
|
hostsWithMac = filterAttrs (_: hostOpts:
|
||||||
|
!isNull hostOpts.mac-address && !isNull hostOpts.ipv4-address)
|
||||||
|
cfg.zone-definition.hosts;
|
||||||
|
in mapAttrsToList (hostname:
|
||||||
|
{ mac-address, ipv4-address, ... }: {
|
||||||
|
enthernetAddress = mac-address;
|
||||||
|
hostName = hostname;
|
||||||
|
ipAddress = ipv4-address;
|
||||||
|
}) hostsWithMac;
|
||||||
|
}];
|
||||||
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
services.bind = let
|
services.bind = let
|
||||||
|
|||||||
Reference in New Issue
Block a user