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";
48 dhcp-socket-type = "raw";
55 subnet = "10.0.0.0/29";
57 pool = "10.0.0.3 - 10.0.0.3";
61 # Enable communication between dhcp4 and a local dhcp-ddns
63 # https://kea.readthedocs.io/en/kea-2.2.0/arm/dhcp4-srv.html#ddns-for-dhcpv4
65 enable-updates = true;
68 ddns-send-updates = true;
69 ddns-qualifying-suffix = "lan.nixos.test.";
73 services.kea.dhcp-ddns = {
77 # Configure updates of a forward zone named `lan.nixos.test`
78 # hosted at the nameserver at 10.0.0.2
79 # https://kea.readthedocs.io/en/kea-2.2.0/arm/ddns.html#adding-forward-dns-servers
81 name = "lan.nixos.test.";
82 # Use a TSIG key in production!
85 ip-address = "10.0.0.2";
94 nameserver = { config, pkgs, ... }: {
95 virtualisation.vlans = [ 1 ];
99 firewall.allowedUDPPorts = [ 53 ];
108 Address = "10.0.0.2/29";
114 services.resolved.enable = false;
116 # Set up an authoritative nameserver, serving the `lan.nixos.test`
117 # zone and configure an ACL that allows dynamic updates from
118 # the router's ip address.
119 # This ACL is likely insufficient for production usage. Please
122 zone = pkgs.writeTextDir "lan.nixos.test.zone" ''
123 @ SOA ns.nixos.test nox.nixos.test 0 86400 7200 3600000 172800
125 nameserver A 10.0.0.3
128 zonesDir = pkgs.buildEnv {
142 log.syslog.any = "info";
145 address = "10.0.0.1";
151 zonefile-sync = "-1";
152 zonefile-load = "difference-no-serial";
153 journal-content = "all";
156 zone."lan.nixos.test" = {
157 file = "lan.nixos.test.zone";
167 client = { config, pkgs, ... }: {
168 virtualisation.vlans = [ 1 ];
169 systemd.services.systemd-networkd.environment.SYSTEMD_LOG_LEVEL = "debug";
173 firewall.enable = false;
174 interfaces.eth1.useDHCP = true;
178 testScript = { ... }: ''
180 router.wait_for_unit("kea-dhcp4-server.service")
181 client.wait_for_unit("systemd-networkd-wait-online.service")
182 client.wait_until_succeeds("ping -c 5 10.0.0.1")
183 router.wait_until_succeeds("ping -c 5 10.0.0.3")
184 nameserver.wait_until_succeeds("kdig +short client.lan.nixos.test @10.0.0.2 | grep -q 10.0.0.3")