1 # This test verifies that we can ping an IPv4-only server from an IPv6-only
2 # client via a NAT64 router using CLAT on the client. The hosts and networks
3 # are configured as follows:
6 # Client | clat Address: 192.0.0.1/32 (configured via clatd)
9 # | eth1 Address: Assigned via SLAAC within 2001:db8::/64
10 # | | Route: default via IPv6LL address
14 # | eth2 Address: 2001:db8::1/64
16 # | nat64 Address: 64:ff9b::1/128
17 # | Route: 64:ff9b::/96
18 # | Address: 192.0.2.0/32
19 # | Route: 192.0.2.0/24
21 # | eth1 Address: 100.64.0.1/24
25 # Server | eth1 Address: 100.64.0.2/24
26 # | Route: 192.0.2.0/24 via 100.64.0.1
29 import ./make-test-python.nix ({ pkgs, lib, ... }:
33 meta = with pkgs.lib.maintainers; {
34 maintainers = [ hax404 jmbaur ];
38 # The server is configured with static IPv4 addresses. RFC 6052 Section 3.1
39 # disallows the mapping of non-global IPv4 addresses like RFC 1918 into the
40 # Well-Known Prefix 64:ff9b::/96. TAYGA also does not allow the mapping of
41 # documentation space (RFC 5737). To circumvent this, 100.64.0.2/24 from
42 # RFC 6589 (Carrier Grade NAT) is used here.
43 # To reach the IPv4 address pool of the NAT64 gateway, there is a static
44 # route configured. In normal cases, where the router would also source NAT
45 # the pool addresses to one IPv4 addresses, this would not be needed.
47 virtualisation.vlans = [
52 interfaces.eth1 = lib.mkForce {};
57 matchConfig.Name = "eth1";
62 { Destination = "192.0.2.0/24"; Gateway = "100.64.0.1"; }
68 # The router is configured with static IPv4 addresses towards the server
69 # and IPv6 addresses towards the client. DNS64 is exposed towards the
70 # client so clatd is able to auto-discover the PLAT prefix. For NAT64, the
71 # Well-Known prefix 64:ff9b::/96 is used. NAT64 is done with TAYGA which
72 # provides the tun-interface nat64 and does the translation over it. The
73 # IPv6 packets are sent to this interfaces and received as IPv4 packets and
74 # vice versa. As TAYGA only translates IPv6 addresses to dedicated IPv4
75 # addresses, it needs a pool of IPv4 addresses which must be at least as
76 # big as the expected amount of clients. In this test, the packets from the
77 # pool are directly routed towards the client. In normal cases, there would
78 # be a second source NAT44 to map all clients behind one IPv4 address.
80 boot.kernel.sysctl = {
81 "net.ipv4.conf.all.forwarding" = 1;
82 "net.ipv6.conf.all.forwarding" = 1;
85 virtualisation.vlans = [
93 firewall.enable = false;
94 interfaces.eth1 = lib.mkForce {
96 addresses = [ { address = "100.64.0.1"; prefixLength = 24; } ];
99 interfaces.eth2 = lib.mkForce {
101 addresses = [ { address = "2001:db8::1"; prefixLength = 64; } ];
106 systemd.network.networks."40-eth2" = {
107 networkConfig.IPv6SendRA = true;
108 ipv6Prefixes = [ { Prefix = "2001:db8::/64"; } ];
109 ipv6PREF64Prefixes = [ { Prefix = "64:ff9b::/96"; } ];
116 services.resolved.extraConfig = ''
120 networking.extraHosts = ''
121 192.0.0.171 ipv4only.arpa
122 192.0.0.170 ipv4only.arpa
139 address = "192.0.2.0";
141 address = "192.0.2.1";
144 address = "192.0.2.0";
149 address = "2001:db8::1";
151 address = "64:ff9b::1";
154 address = "64:ff9b::";
161 # The client uses SLAAC to assign IPv6 addresses. To reach the IPv4-only
162 # server, the client starts the clat daemon which starts and configures the
163 # local IPv4 -> IPv6 translation via Tayga after discovering the PLAT
166 virtualisation.vlans = [
172 interfaces.eth1 = lib.mkForce {};
178 matchConfig.Name = "eth1";
180 # NOTE: clatd does not actually use the PREF64 prefix discovered by
181 # systemd-networkd (nor does systemd-networkd do anything with it,
182 # yet), but we set this to confirm it works. See the test script
184 ipv6AcceptRAConfig.UsePREF64 = true;
190 # NOTE: Perl's Net::DNS resolver does not seem to work well querying
191 # for AAAA records to systemd-resolved's default IPv4 bind address
192 # (127.0.0.53), so we add an IPv6 listener address to systemd-resolved
193 # and tell clatd to use that instead.
194 settings.dns64-servers = "::1";
197 # Allow clatd to find dns server. See comment above.
198 services.resolved.extraConfig = ''
199 DNSStubListenerExtra=::1
202 environment.systemPackages = [ pkgs.mtr ];
211 # wait for all machines to start up
212 for machine in client, router, server:
213 machine.wait_for_unit("network-online.target")
215 with subtest("Wait for tayga and clatd"):
216 router.wait_for_unit("tayga.service")
217 client.wait_for_unit("clatd.service")
218 # clatd checks if this system has IPv4 connectivity for 10 seconds
219 client.wait_until_succeeds(
220 'journalctl -u clatd -e | grep -q "Starting up TAYGA, using config file"'
223 with subtest("networkd exports PREF64 prefix"):
224 assert json.loads(client.succeed("networkctl status eth1 --json=short"))[
226 ]["PREF64"][0]["Prefix"] == [0x0, 0x64, 0xFF, 0x9B] + ([0] * 12)
228 with subtest("Test ICMP"):
229 client.wait_until_succeeds("ping -c 3 100.64.0.2 >&2")
231 with subtest("Test ICMP and show a traceroute"):
232 client.wait_until_succeeds("mtr --show-ips --report-wide 100.64.0.2 >&2")
234 client.log(client.execute("systemd-analyze security clatd.service")[1])