1# Test of IPv6 functionality in NixOS, including whether router
2# solicication/advertisement using radvd works.
3
4{ pkgs, lib, ... }:
5{
6 name = "ipv6";
7 meta = with pkgs.lib.maintainers; {
8 maintainers = [ ];
9 };
10
11 nodes = {
12 # We use lib.mkForce here to remove the interface configuration
13 # provided by makeTest, so that the interfaces are all configured
14 # implicitly.
15
16 # This client should use privacy extensions fully, having a
17 # completely-default network configuration.
18 client_defaults.networking.interfaces = lib.mkForce { };
19
20 # Both of these clients should obtain temporary addresses, but
21 # not use them as the default source IP. We thus run the same
22 # checks against them — but the configuration resulting in this
23 # behaviour is different.
24
25 # Here, by using an altered default value for the global setting...
26 client_global_setting = {
27 networking.interfaces = lib.mkForce { };
28 networking.tempAddresses = "enabled";
29 };
30 # and here, by setting this on the interface explicitly.
31 client_interface_setting = {
32 networking.tempAddresses = "disabled";
33 networking.interfaces = lib.mkForce {
34 eth1.tempAddress = "enabled";
35 };
36 };
37
38 server = {
39 services.httpd.enable = true;
40 services.httpd.adminAddr = "foo@example.org";
41 networking.firewall.allowedTCPPorts = [ 80 ];
42 # disable testing driver's default IPv6 address.
43 networking.interfaces.eth1.ipv6.addresses = lib.mkForce [ ];
44 };
45
46 router =
47 { ... }:
48 {
49 services.radvd.enable = true;
50 services.radvd.config = ''
51 interface eth1 {
52 AdvSendAdvert on;
53 # ULA prefix (RFC 4193).
54 prefix fd60:cc69:b537:1::/64 { };
55 };
56 '';
57 };
58 };
59
60 testScript = ''
61 import re
62
63 # Start the router first so that it respond to router solicitations.
64 router.wait_for_unit("radvd")
65
66 clients = [client_defaults, client_global_setting, client_interface_setting]
67
68 start_all()
69
70 for client in clients:
71 client.wait_for_unit("network.target")
72 server.wait_for_unit("network.target")
73 server.wait_for_unit("httpd.service")
74
75 # Wait until the given interface has a non-tentative address of
76 # the desired scope (i.e. has completed Duplicate Address
77 # Detection).
78 def wait_for_address(machine, iface, scope, temporary=False):
79 temporary_flag = "temporary" if temporary else "-temporary"
80 cmd = f"ip -o -6 addr show dev {iface} scope {scope} -tentative {temporary_flag}"
81
82 machine.wait_until_succeeds(f"[ `{cmd} | wc -l` -eq 1 ]")
83 output = machine.succeed(cmd)
84 ip = re.search(r"inet6 ([0-9a-f:]{2,})/", output).group(1)
85
86 if temporary:
87 scope = scope + " temporary"
88 machine.log(f"{scope} address on {iface} is {ip}")
89 return ip
90
91
92 with subtest("Loopback address can be pinged"):
93 client_defaults.succeed("ping -c 1 ::1 >&2")
94 client_defaults.fail("ping -c 1 2001:db8:: >&2")
95
96 with subtest("Local link addresses can be obtained and pinged"):
97 for client in clients:
98 client_ip = wait_for_address(client, "eth1", "link")
99 server_ip = wait_for_address(server, "eth1", "link")
100 client.succeed(f"ping -c 1 {client_ip}%eth1 >&2")
101 client.succeed(f"ping -c 1 {server_ip}%eth1 >&2")
102
103 with subtest("Global addresses can be obtained, pinged, and reached via http"):
104 for client in clients:
105 client_ip = wait_for_address(client, "eth1", "global")
106 server_ip = wait_for_address(server, "eth1", "global")
107 client.succeed(f"ping -c 1 {client_ip} >&2")
108 client.succeed(f"ping -c 1 {server_ip} >&2")
109 client.succeed(f"curl --fail -g http://[{server_ip}]")
110 client.fail(f"curl --fail -g http://[{client_ip}]")
111
112 with subtest(
113 "Privacy extensions: Global temporary address is used as default source address"
114 ):
115 ip = wait_for_address(client_defaults, "eth1", "global", temporary=True)
116 # Default route should have "src <temporary address>" in it
117 client_defaults.succeed(f"ip route get 2001:db8:: | grep 'src {ip}'")
118
119 for client, setting_desc in (
120 (client_global_setting, "global"),
121 (client_interface_setting, "interface"),
122 ):
123 with subtest(f'Privacy extensions: "enabled" through {setting_desc} setting)'):
124 # We should be obtaining both a temporary address and an EUI-64 address...
125 ip = wait_for_address(client, "eth1", "global")
126 assert "ff:fe" in ip
127 ip_temp = wait_for_address(client, "eth1", "global", temporary=True)
128 # But using the EUI-64 one.
129 client.succeed(f"ip route get 2001:db8:: | grep 'src {ip}'")
130 '';
131}