1 # This test verifies DHCPv4 interaction between a client and a router.
2 # For successful DHCP allocations a dynamic update request is sent
3 # towards a nameserver to allocate a name in the lan.nixos.test zone.
4 # We then verify whether client and router can ping each other, and
5 # that the nameserver can resolve the clients fqdn to the correct IP
8 import ./make-test-python.nix ({ pkgs, lib, ...}: {
9 meta.maintainers = with lib.maintainers; [ hexa ];
14 router = { config, pkgs, ... }: {
15 virtualisation.vlans = [ 1 ];
19 firewall.allowedUDPPorts = [ 67 ];
28 Address = "10.0.0.1/29";
34 services.kea.dhcp4 = {
37 valid-lifetime = 3600;
44 name = "/var/lib/kea/dhcp4.leases";
49 socket-name = "/run/kea/dhcp4.sock";
53 dhcp-socket-type = "raw";
60 subnet = "10.0.0.0/29";
62 pool = "10.0.0.3 - 10.0.0.3";
66 # Enable communication between dhcp4 and a local dhcp-ddns
68 # https://kea.readthedocs.io/en/kea-2.2.0/arm/dhcp4-srv.html#ddns-for-dhcpv4
70 enable-updates = true;
73 ddns-send-updates = true;
74 ddns-qualifying-suffix = "lan.nixos.test.";
78 services.kea.dhcp-ddns = {
82 # Configure updates of a forward zone named `lan.nixos.test`
83 # hosted at the nameserver at 10.0.0.2
84 # https://kea.readthedocs.io/en/kea-2.2.0/arm/ddns.html#adding-forward-dns-servers
86 name = "lan.nixos.test.";
87 # Use a TSIG key in production!
90 ip-address = "10.0.0.2";
98 services.kea.ctrl-agent = {
101 http-host = "127.0.0.1";
103 control-sockets.dhcp4 = {
104 socket-type = "unix";
105 socket-name = "/run/kea/dhcp4.sock";
110 services.prometheus.exporters.kea = {
112 controlSocketPaths = [
113 "http://127.0.0.1:8000"
118 nameserver = { config, pkgs, ... }: {
119 virtualisation.vlans = [ 1 ];
123 firewall.allowedUDPPorts = [ 53 ];
132 Address = "10.0.0.2/29";
138 services.resolved.enable = false;
140 # Set up an authoritative nameserver, serving the `lan.nixos.test`
141 # zone and configure an ACL that allows dynamic updates from
142 # the router's ip address.
143 # This ACL is likely insufficient for production usage. Please
146 zone = pkgs.writeTextDir "lan.nixos.test.zone" ''
147 @ SOA ns.nixos.test nox.nixos.test 0 86400 7200 3600000 172800
149 nameserver A 10.0.0.3
152 zonesDir = pkgs.buildEnv {
166 log.syslog.any = "info";
169 address = "10.0.0.1";
175 zonefile-sync = "-1";
176 zonefile-load = "difference-no-serial";
177 journal-content = "all";
180 zone."lan.nixos.test" = {
181 file = "lan.nixos.test.zone";
191 client = { config, pkgs, ... }: {
192 virtualisation.vlans = [ 1 ];
193 systemd.services.systemd-networkd.environment.SYSTEMD_LOG_LEVEL = "debug";
197 firewall.enable = false;
198 interfaces.eth1.useDHCP = true;
202 testScript = { ... }: ''
204 router.wait_for_unit("kea-dhcp4-server.service")
205 client.wait_for_unit("systemd-networkd-wait-online.service")
206 client.wait_until_succeeds("ping -c 5 10.0.0.1")
207 router.wait_until_succeeds("ping -c 5 10.0.0.3")
208 nameserver.wait_until_succeeds("kdig +short client.lan.nixos.test @10.0.0.2 | grep -q 10.0.0.3")
209 router.log(router.execute("curl 127.0.0.1:9547")[1])
210 router.succeed("curl --no-buffer 127.0.0.1:9547 | grep -qE '^kea_dhcp4_addresses_assigned_total.*1.0$'")