2010-05-20 21:07:32 +00:00
|
|
|
# This is a simple distributed test involving a topology with two
|
|
|
|
# separate virtual networks - the "inside" and the "outside" - with a
|
|
|
|
# client on the inside network, a server on the outside network, and a
|
|
|
|
# router connected to both that performs Network Address Translation
|
|
|
|
# for the client.
|
|
|
|
|
2014-04-14 12:02:44 +00:00
|
|
|
import ./make-test.nix {
|
2014-06-28 14:04:49 +00:00
|
|
|
name = "nat";
|
2010-05-20 21:07:32 +00:00
|
|
|
|
|
|
|
nodes =
|
2011-09-14 18:20:50 +00:00
|
|
|
{ client =
|
2010-05-21 14:12:03 +00:00
|
|
|
{ config, pkgs, nodes, ... }:
|
2010-05-20 21:07:32 +00:00
|
|
|
{ virtualisation.vlans = [ 1 ];
|
2014-04-11 15:15:56 +00:00
|
|
|
networking.firewall.allowPing = true;
|
2010-05-21 14:12:03 +00:00
|
|
|
networking.defaultGateway =
|
2014-08-31 16:46:16 +00:00
|
|
|
(head nodes.router.config.networking.interfaces.eth2.ip4).address;
|
2010-05-20 21:07:32 +00:00
|
|
|
};
|
|
|
|
|
2011-09-14 18:20:50 +00:00
|
|
|
router =
|
2010-05-20 21:07:32 +00:00
|
|
|
{ config, pkgs, ... }:
|
|
|
|
{ virtualisation.vlans = [ 2 1 ];
|
2014-04-11 15:15:56 +00:00
|
|
|
networking.firewall.allowPing = true;
|
2011-03-10 12:08:39 +00:00
|
|
|
networking.nat.enable = true;
|
2013-10-30 16:37:45 +00:00
|
|
|
networking.nat.internalIPs = [ "192.168.1.0/24" ];
|
2011-03-10 12:08:39 +00:00
|
|
|
networking.nat.externalInterface = "eth1";
|
2010-05-20 21:07:32 +00:00
|
|
|
};
|
|
|
|
|
2011-09-14 18:20:50 +00:00
|
|
|
server =
|
2010-05-20 21:07:32 +00:00
|
|
|
{ config, pkgs, ... }:
|
|
|
|
{ virtualisation.vlans = [ 2 ];
|
2014-04-11 15:15:56 +00:00
|
|
|
networking.firewall.enable = false;
|
2010-05-20 21:07:32 +00:00
|
|
|
services.httpd.enable = true;
|
|
|
|
services.httpd.adminAddr = "foo@example.org";
|
2011-03-10 13:03:47 +00:00
|
|
|
services.vsftpd.enable = true;
|
|
|
|
services.vsftpd.anonymousUser = true;
|
2010-05-20 21:07:32 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
testScript =
|
2010-05-21 14:31:05 +00:00
|
|
|
{ nodes, ... }:
|
2010-05-20 21:07:32 +00:00
|
|
|
''
|
|
|
|
startAll;
|
|
|
|
|
|
|
|
# The router should have access to the server.
|
2012-10-29 20:01:36 +00:00
|
|
|
$server->waitForUnit("network.target");
|
2012-10-24 16:22:53 +00:00
|
|
|
$server->waitForUnit("httpd");
|
|
|
|
$router->waitForUnit("network.target");
|
2011-03-10 12:08:39 +00:00
|
|
|
$router->succeed("curl --fail http://server/ >&2");
|
|
|
|
|
|
|
|
# The client should be also able to connect via the NAT router.
|
2012-10-24 16:22:53 +00:00
|
|
|
$router->waitForUnit("nat");
|
|
|
|
$client->waitForUnit("network.target");
|
2011-03-10 12:08:39 +00:00
|
|
|
$client->succeed("curl --fail http://server/ >&2");
|
|
|
|
$client->succeed("ping -c 1 server >&2");
|
2011-09-14 18:20:50 +00:00
|
|
|
|
2011-03-10 13:03:47 +00:00
|
|
|
# Test whether passive FTP works.
|
2012-10-24 16:22:53 +00:00
|
|
|
$server->waitForUnit("vsftpd");
|
2011-03-10 13:03:47 +00:00
|
|
|
$server->succeed("echo Hello World > /home/ftp/foo.txt");
|
|
|
|
$client->succeed("curl -v ftp://server/foo.txt >&2");
|
2011-09-14 18:20:50 +00:00
|
|
|
|
2011-03-10 13:03:47 +00:00
|
|
|
# Test whether active FTP works.
|
|
|
|
$client->succeed("curl -v -P - ftp://server/foo.txt >&2");
|
|
|
|
|
|
|
|
# Test ICMP.
|
|
|
|
$client->succeed("ping -c 1 router >&2");
|
|
|
|
$router->succeed("ping -c 1 client >&2");
|
2011-09-14 18:20:50 +00:00
|
|
|
|
2011-03-10 12:08:39 +00:00
|
|
|
# If we turn off NAT, the client shouldn't be able to reach the server.
|
2012-10-24 16:11:21 +00:00
|
|
|
$router->stopJob("nat");
|
2011-03-10 12:08:39 +00:00
|
|
|
$client->fail("curl --fail --connect-timeout 5 http://server/ >&2");
|
|
|
|
$client->fail("ping -c 1 server >&2");
|
|
|
|
|
|
|
|
# And make sure that restarting the NAT job works.
|
2012-10-29 20:01:36 +00:00
|
|
|
$router->succeed("systemctl start nat");
|
2011-03-10 12:08:39 +00:00
|
|
|
$client->succeed("curl --fail http://server/ >&2");
|
|
|
|
$client->succeed("ping -c 1 server >&2");
|
2010-05-20 21:07:32 +00:00
|
|
|
'';
|
|
|
|
|
|
|
|
}
|