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";
61 subnet = "10.0.0.0/29";
63 pool = "10.0.0.3 - 10.0.0.3";
67 # Enable communication between dhcp4 and a local dhcp-ddns
69 # https://kea.readthedocs.io/en/kea-2.2.0/arm/dhcp4-srv.html#ddns-for-dhcpv4
71 enable-updates = true;
74 ddns-send-updates = true;
75 ddns-qualifying-suffix = "lan.nixos.test.";
79 services.kea.dhcp-ddns = {
83 # Configure updates of a forward zone named `lan.nixos.test`
84 # hosted at the nameserver at 10.0.0.2
85 # https://kea.readthedocs.io/en/kea-2.2.0/arm/ddns.html#adding-forward-dns-servers
87 name = "lan.nixos.test.";
88 # Use a TSIG key in production!
91 ip-address = "10.0.0.2";
99 services.kea.ctrl-agent = {
102 http-host = "127.0.0.1";
104 control-sockets.dhcp4 = {
105 socket-type = "unix";
106 socket-name = "/run/kea/dhcp4.sock";
111 services.prometheus.exporters.kea = {
113 controlSocketPaths = [
114 "http://127.0.0.1:8000"
119 nameserver = { config, pkgs, ... }: {
120 virtualisation.vlans = [ 1 ];
124 firewall.allowedUDPPorts = [ 53 ];
133 Address = "10.0.0.2/29";
139 services.resolved.enable = false;
141 # Set up an authoritative nameserver, serving the `lan.nixos.test`
142 # zone and configure an ACL that allows dynamic updates from
143 # the router's ip address.
144 # This ACL is likely insufficient for production usage. Please
147 zone = pkgs.writeTextDir "lan.nixos.test.zone" ''
148 @ SOA ns.nixos.test nox.nixos.test 0 86400 7200 3600000 172800
150 nameserver A 10.0.0.3
153 zonesDir = pkgs.buildEnv {
167 log.syslog.any = "info";
170 address = "10.0.0.1";
176 zonefile-sync = "-1";
177 zonefile-load = "difference-no-serial";
178 journal-content = "all";
181 zone."lan.nixos.test" = {
182 file = "lan.nixos.test.zone";
192 client = { config, pkgs, ... }: {
193 virtualisation.vlans = [ 1 ];
194 systemd.services.systemd-networkd.environment.SYSTEMD_LOG_LEVEL = "debug";
198 firewall.enable = false;
199 interfaces.eth1.useDHCP = true;
203 testScript = { ... }: ''
205 router.wait_for_unit("kea-dhcp4-server.service")
206 client.wait_for_unit("systemd-networkd-wait-online.service")
207 client.wait_until_succeeds("ping -c 5 10.0.0.1")
208 router.wait_until_succeeds("ping -c 5 10.0.0.3")
209 nameserver.wait_until_succeeds("kdig +short client.lan.nixos.test @10.0.0.2 | grep -q 10.0.0.3")
210 router.log(router.execute("curl 127.0.0.1:9547")[1])
211 router.succeed("curl --no-buffer 127.0.0.1:9547 | grep -qE '^kea_dhcp4_addresses_assigned_total.*1.0$'")