summary refs log tree commit diff
path: root/nixos/tests/ipv6.nix
blob: d11eba764da3de96d4e3842de38558a2702c6a2d (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# Test of IPv6 functionality in NixOS, including whether router
# solicication/advertisement using radvd works.

import ./make-test.nix ({ pkgs, lib, ...} : {
  name = "ipv6";
  meta = with pkgs.stdenv.lib.maintainers; {
    maintainers = [ eelco ];
  };

  nodes =
    # Remove the interface configuration provided by makeTest so that the
    # interfaces are all configured implicitly
    { client = { ... }: { networking.interfaces = lib.mkForce {}; };

      server =
        { ... }:
        { services.httpd.enable = true;
          services.httpd.adminAddr = "foo@example.org";
          networking.firewall.allowedTCPPorts = [ 80 ];
        };

      router =
        { ... }:
        { services.radvd.enable = true;
          services.radvd.config =
            ''
              interface eth1 {
                AdvSendAdvert on;
                # ULA prefix (RFC 4193).
                prefix fd60:cc69:b537:1::/64 { };
              };
            '';
        };
    };

  testScript =
    ''
      # Start the router first so that it respond to router solicitations.
      $router->waitForUnit("radvd");

      startAll;

      $client->waitForUnit("network.target");
      $server->waitForUnit("network.target");
      $server->waitForUnit("httpd.service");

      # Wait until the given interface has a non-tentative address of
      # the desired scope (i.e. has completed Duplicate Address
      # Detection).
      sub waitForAddress {
          my ($machine, $iface, $scope) = @_;
          $machine->waitUntilSucceeds("[ `ip -o -6 addr show dev $iface scope $scope | grep -v tentative | wc -l` -ge 1 ]");
          my $ip = (split /[ \/]+/, $machine->succeed("ip -o -6 addr show dev $iface scope $scope"))[3];
          $machine->log("$scope address on $iface is $ip");
          return $ip;
      }

      subtest "loopback address", sub {
          $client->succeed("ping -c 1 ::1 >&2");
          $client->fail("ping -c 1 ::2 >&2");
      };

      subtest "local link addressing", sub {
          my $clientIp = waitForAddress $client, "eth1", "link";
          my $serverIp = waitForAddress $server, "eth1", "link";
          $client->succeed("ping -c 1 $clientIp%eth1 >&2");
          $client->succeed("ping -c 1 $serverIp%eth1 >&2");
      };

      subtest "global addressing", sub {
          my $clientIp = waitForAddress $client, "eth1", "global";
          my $serverIp = waitForAddress $server, "eth1", "global";
          $client->succeed("ping -c 1 $clientIp >&2");
          $client->succeed("ping -c 1 $serverIp >&2");
          $client->succeed("curl --fail -g http://[$serverIp]");
          $client->fail("curl --fail -g http://[$clientIp]");
      };
      subtest "privacy extensions", sub {
          my $ip = waitForAddress $client, "eth1", "global temporary";
          # Default route should have "src <temporary address>" in it
          $client->succeed("ip r g ::2 | grep $ip");
      };

      # TODO: test reachability of a machine on another network.
    '';
})