nixos-module/container/dhcp-server: fix reservations

This commit is contained in:
Astro 2023-10-28 03:20:51 +02:00
parent 4901048463
commit 0e2c4c7afd
2 changed files with 73 additions and 57 deletions

View File

@ -8,52 +8,52 @@
fixed-hosts = { fixed-hosts = {
"172.22.99.96" = "08:00:27:bb:8c:b3"; "172.22.99.96" = "08:00:27:bb:8c:b3";
"172.22.99.98" = "08:00:27:aa:90:e2"; "172.22.99.98" = "08:00:27:aa:90:e2";
# "astrom.hq.c3d2.de" = "aa:00:5b:08:f0:5c"; # "astrom" = "aa:00:5b:08:f0:5c";
# "astron.hq.c3d2.de" = "aa:00:5b:08:f0:5b"; # "astron" = "aa:00:5b:08:f0:5b";
# "batman.hq.c3d2.de" = "5c:cf:7f:c0:05:28"; # "batman" = "5c:cf:7f:c0:05:28";
# "beere.hq.c3d2.de" = "b8:27:eb:ac:65:d2"; # "beere" = "b8:27:eb:ac:65:d2";
# "beere2.hq.c3d2.de" = "b8:27:eb:53:0b:27"; # "beere2" = "b8:27:eb:53:0b:27";
# "bender.hq.c3de.de" = "00:23:df:7e:c8:0a"; # "bender.hq.c3de.de" = "00:23:df:7e:c8:0a";
# "cider.hq.c3d2.de" = "00:0d:93:75:ee:fa"; # "cider" = "00:0d:93:75:ee:fa";
"dacbert.hq.c3d2.de" = "dc:a6:32:e0:46:bf"; "dacbert" = "dc:a6:32:e0:46:bf";
"dn42.hq.c3d2.de" = "aa:00:42:7a:32:46"; "dn42" = "aa:00:42:7a:32:46";
"drucker.hq.c3d2.de" = "00:23:c3:d2:12:0f"; # "drucker" = "00:23:c3:d2:12:0f";
# "feile.hq.c3d2.de" = "aa:00:5b:12:c1:f7"; # "feile" = "aa:00:5b:12:c1:f7";
# "fernandopoo.hq.c3d2.de" = "aa:00:f7:52:85:27"; # "fernandopoo" = "aa:00:f7:52:85:27";
# "fhem.hq.c3d2.de" = "b8:27:eb:9e:8b:db"; # "fhem" = "b8:27:eb:9e:8b:db";
# "git.hq.c3d2.de" = "aa:00:47:d8:57:10"; # "git" = "aa:00:47:d8:57:10";
"glotzbert.hq.c3d2.de" = "90:1b:0e:88:da:0a"; "glotzbert" = "90:1b:0e:88:da:0a";
"wled-nix-snowflake.hq.c3d2.de" = "44:17:93:10:77:e8"; # "wled-nix-snowflake" = "44:17:93:10:77:e8";
"wled-fairy-dust.hq.c3d2.de" = "3c:61:05:e3:2f:ad"; # "wled-fairy-dust" = "3c:61:05:e3:2f:ad";
"wled-warnbert.hq.c3d2.de" = "3c:61:05:fc:21:37"; # "wled-warnbert" = "3c:61:05:fc:21:37";
"wled-matrix.hq.c3d2.de" = "e8:db:84:e4:f4:30"; # "wled-matrix" = "e8:db:84:e4:f4:30";
# "ledball1.hq.c3d2.de" = "b8:27:eb:53:0b:27"; # "ledball1" = "b8:27:eb:53:0b:27";
# Beleuchtungskiste auf Traverse über Fernseher # Beleuchtungskiste auf Traverse über Fernseher
"ledbeere.hq.c3d2.de" = "b8:27:eb:60:99:59"; # "ledbeere" = "b8:27:eb:60:99:59";
# "leviathan.hq.c3d2.de" = "00:ff:08:31:db:e5"; # "leviathan" = "00:ff:08:31:db:e5";
# "lisbeth.hq.c3d2.de" = "b8:27:eb:a5:ee:5c"; # "lisbeth" = "b8:27:eb:a5:ee:5c";
# "marenz-build.hq.c3d2.de" = "44:1e:a1:59:2e:e8"; # "marenz-build" = "44:1e:a1:59:2e:e8";
"matemat.hq.c3d2.de" = "a2:1b:7c:e8:19:72"; # "matemat" = "a2:1b:7c:e8:19:72";
# "minecraft.hq.c3d2.de" = "4a:57:d3:64:fe:e9"; # "minecraft" = "4a:57:d3:64:fe:e9";
# "moleflap.hq.c3d2.de" = "aa:00:0d:b1:6c:67"; # "moleflap" = "aa:00:0d:b1:6c:67";
# "monit.hq.c3d2.de" = "00:23:ae:94:e7:19"; # "monit" = "00:23:ae:94:e7:19";
"pipebert.hq.c3d2.de" = "ec:a8:6b:fe:b4:cb"; "pipebert" = "ec:a8:6b:fe:b4:cb";
"public-access-proxy.hq.c3d2.de" = "12:24:5f:bd:9b:e7"; # "public-access-proxy" = "12:24:5f:bd:9b:e7";
"pulsebert.hq.c3d2.de" = "b8:27:eb:16:31:61"; "pulsebert" = "b8:27:eb:16:31:61";
# "ruststripe1.hq.c3d2.de" = "06:32:0e:39:21:69"; # "ruststripe1" = "06:32:0e:39:21:69";
"schalter.hq.c3d2.de" = "b8:27:eb:4c:be:ff"; # "schalter" = "b8:27:eb:4c:be:ff";
# "semanta.hq.c3d2.de" = "00:ff:e4:bb:ea:2a"; # "semanta" = "00:ff:e4:bb:ea:2a";
# "server2.hq.c3d2.de" = "d0:67:e5:f3:57:10"; # "server2" = "d0:67:e5:f3:57:10";
# "server3.hq.c3d2.de" = "e4:1f:13:2e:4f:c0"; # "server3" = "e4:1f:13:2e:4f:c0";
# "server4.hq.c3d2.de" = "00:9c:02:a9:26:01"; # "server4" = "00:9c:02:a9:26:01";
# "sharing.hq.c3d2.de" = "00:23:c3:d2:75:18"; # "sharing" = "00:23:c3:d2:75:18";
# "sofafon.hq.c3d2.de" = "b8:27:eb:23:8d:01"; # "sofafon" = "b8:27:eb:23:8d:01";
# "storage2.hq.c3d2.de" = "42:5e:0f:4e:f3:cc"; # "storage2" = "42:5e:0f:4e:f3:cc";
# "ustriper.hq.c3d2.de" = "aa:bb:95:33:bb:aa"; # "ustriper" = "aa:bb:95:33:bb:aa";
# "wiefelspuetz.hq.c3d2.de" = "aa:00:7f:01:8a:d0"; # "wiefelspuetz" = "aa:00:7f:01:8a:d0";
# "wormhole.hq.c3d2.de" = "00:23:c3:d2:00:76"; # "wormhole" = "00:23:c3:d2:00:76";
# "www1.hq.c3d2.de" = "aa:00:13:8b:03:47"; # "www1" = "aa:00:13:8b:03:47";
"riscbert.hq.c3d2.de" = "6c:cf:39:00:05:95"; # "riscbert" = "6c:cf:39:00:05:95";
}; };
time = 300; time = 300;
max-time = 30 * 86400; max-time = 30 * 86400;

View File

@ -61,25 +61,41 @@ in
match-client-id = false; match-client-id = false;
host-reservation-identifiers = [ "hw-address" ]; host-reservation-identifiers = [ "hw-address" ];
reservations = concatMapDhcpNets (net: { hosts4, dhcp, ... }: reservations = concatMapDhcpNets (net: { hosts4, dhcp, ... }:
builtins.filter (r: r != null) ( lib.pipe dhcp.fixed-hosts [
builtins.attrValues ( (builtins.mapAttrs (fixedAddr: hwaddr:
builtins.mapAttrs (addr: hwaddr: if hosts4 ? ${fixedAddr}
then # fixedAddr is a known hostname
let
name = fixedAddr;
addr = hosts4.${fixedAddr};
in {
hostname = "${name}.${net}.zentralwerk.org";
hw-address = hwaddr;
ip-address = addr;
}
else
let let
names = builtins.attrNames ( names = builtins.attrNames (
lib.filterAttrs (_: hostAddr: lib.filterAttrs (_: hostAddr:
hostAddr == addr hostAddr == fixedAddr
) hosts4); ) hosts4);
name = builtins.head names; name = builtins.head names;
in in
if builtins.length names > 0 if builtins.length names > 0
then { then { # fixedAddr is IPv4 of a known hostname
hostname = "${name}.${net}.zentralwerk.org"; hostname = "${name}.${net}.zentralwerk.org";
hw-address = hwaddr; hw-address = hwaddr;
ip-address = hosts4.${name}; ip-address = hosts4.${name};
} } # fixedAddr is IPv4?
else null else {
) dhcp.fixed-hosts hw-address = hwaddr;
))); ip-address = fixedAddr;
}
))
builtins.attrValues
(builtins.filter (r: r != null))
]
);
# Netbooting # Netbooting
option-def = [ { option-def = [ {