2 common = { pkgs, ... }: {
3 networking.firewall.enable = false;
4 networking.useDHCP = false;
5 # for a host utility with IPv6 support
6 environment.systemPackages = [ pkgs.bind ];
8 in import ./make-test-python.nix ({ pkgs, ...} : {
10 meta = with pkgs.lib.maintainers; {
11 maintainers = [ aszlig ];
15 clientv4 = { lib, nodes, ... }: {
17 networking.nameservers = lib.mkForce [
18 (lib.head nodes.server.config.networking.interfaces.eth1.ipv4.addresses).address
20 networking.interfaces.eth1.ipv4.addresses = [
21 { address = "192.168.0.2"; prefixLength = 24; }
25 clientv6 = { lib, nodes, ... }: {
27 networking.nameservers = lib.mkForce [
28 (lib.head nodes.server.config.networking.interfaces.eth1.ipv6.addresses).address
30 networking.interfaces.eth1.ipv4.addresses = [
31 { address = "dead:beef::2"; prefixLength = 24; }
35 server = { lib, ... }: {
37 networking.interfaces.eth1.ipv4.addresses = [
38 { address = "192.168.0.1"; prefixLength = 24; }
40 networking.interfaces.eth1.ipv6.addresses = [
41 { address = "dead:beef::1"; prefixLength = 64; }
43 services.nsd.enable = true;
44 services.nsd.rootServer = true;
45 services.nsd.interfaces = lib.mkForce [];
46 services.nsd.keys."tsig.example.com." = {
47 algorithm = "hmac-sha256";
48 keyFile = pkgs.writeTextFile { name = "tsig.example.com."; text = "aR3FJA92+bxRSyosadsJ8Aeeav5TngQW/H/EF9veXbc="; };
50 services.nsd.zones."example.com.".data = ''
51 @ SOA ns.example.com noc.example.com 666 7200 3600 1209600 3600
54 deleg NS ns.example.com
58 services.nsd.zones."example.com.".provideXFR = [ "0.0.0.0 tsig.example.com." ];
59 services.nsd.zones."deleg.example.com.".data = ''
60 @ SOA ns.example.com noc.example.com 666 7200 3600 1209600 3600
64 services.nsd.zones.".".data = ''
65 @ SOA ns.example.com noc.example.com 666 7200 3600 1209600 3600
75 clientv4.wait_for_unit("network.target")
76 clientv6.wait_for_unit("network.target")
77 server.wait_for_unit("nsd.service")
79 with subtest("server tsig.example.com."):
80 expected_tsig = " secret: \"aR3FJA92+bxRSyosadsJ8Aeeav5TngQW/H/EF9veXbc=\"\n"
81 tsig=server.succeed("cat /var/lib/nsd/private/tsig.example.com.")
82 assert expected_tsig == tsig, f"Expected /var/lib/nsd/private/tsig.example.com. to contain '{expected_tsig}', but found '{tsig}'"
84 def assert_host(type, rr, query, expected):
85 self = clientv4 if type == 4 else clientv6
86 out = self.succeed(f"host -{type} -t {rr} {query}").rstrip()
87 self.log(f"output: {out}")
91 ), f"DNS IPv{type} query on {query} gave '{out}' instead of '{expected}'"
95 with subtest(f"IPv{ipv}"):
96 assert_host(ipv, "a", "example.com", "has no [^ ]+ record")
97 assert_host(ipv, "aaaa", "example.com", "has no [^ ]+ record")
99 assert_host(ipv, "soa", "example.com", "SOA.*?noc\.example\.com")
100 assert_host(ipv, "a", "ipv4.example.com", "address 1.2.3.4$")
101 assert_host(ipv, "aaaa", "ipv6.example.com", "address abcd::eeff$")
103 assert_host(ipv, "a", "deleg.example.com", "address 9.8.7.6$")
104 assert_host(ipv, "aaaa", "deleg.example.com", "address fedc::bbaa$")
106 assert_host(ipv, "a", "root", "address 1.8.7.4$")
107 assert_host(ipv, "aaaa", "root", "address acbd::4$")