router: allow assigning ips per duid

This commit is contained in:
chayleaf 2023-10-24 00:16:14 +07:00
parent 73b1b3b47d
commit ce2d2e4a78
2 changed files with 16 additions and 4 deletions

View file

@ -282,6 +282,7 @@ in {
]; ];
router-settings.dhcp6Reservations = [ router-settings.dhcp6Reservations = [
{ ipAddress = serverAddress6; { ipAddress = serverAddress6;
duid = cfg.serverDuid;
macAddress = cfg.serverMac; } macAddress = cfg.serverMac; }
{ ipAddress = vacuumAddress6; { ipAddress = vacuumAddress6;
macAddress = cfg.vacuumMac; } macAddress = cfg.vacuumMac; }
@ -434,11 +435,11 @@ in {
gateways = [ netAddresses.lan6 ]; gateways = [ netAddresses.lan6 ];
radvdSettings.AdvAutonomous = true; radvdSettings.AdvAutonomous = true;
coreradSettings.autonomous = true; coreradSettings.autonomous = true;
# don't autoallocate addresses, keep autonomous ones # don't allocate addresses for most devices
keaSettings.pools = [ ]; keaSettings.pools = [ ];
# just assign the reservations # just assign the reservations
keaSettings.reservations = map (res: { keaSettings.reservations = map (res:
hw-address = res.macAddress; (if res.duid != null then { duid = res.duid; } else { hw-address = res.macAddress; }) // {
ip-addresses = [ res.ipAddress ]; ip-addresses = [ res.ipAddress ];
}) cfg.dhcp6Reservations; }) cfg.dhcp6Reservations;
}); });

View file

@ -13,6 +13,11 @@
description = "server's mac address"; description = "server's mac address";
type = lib.types.str; type = lib.types.str;
}; };
serverDuid = lib.mkOption {
description = "server's duid";
type = with lib.types; nullOr str;
default = null;
};
serverInitrdMac = lib.mkOption { serverInitrdMac = lib.mkOption {
description = "server's mac address in initrd"; description = "server's mac address in initrd";
type = lib.types.str; type = lib.types.str;
@ -92,9 +97,15 @@
description = "device's ip address"; description = "device's ip address";
}; };
options.macAddress = lib.mkOption { options.macAddress = lib.mkOption {
type = lib.types.str; type = with lib.types; nullOr str;
default = null;
description = "device's mac address"; description = "device's mac address";
}; };
options.duid = lib.mkOption {
type = with lib.types; nullOr str;
default = null;
description = "device's duid";
};
}); });
}; };
dnatRules = lib.mkOption { dnatRules = lib.mkOption {