1 # This tests whether UPnP port mappings can be created using Miniupnpd
3 # It runs a Miniupnpd service on one machine, and verifies
4 # a client can indeed create a port mapping using Miniupnpc. If
5 # this succeeds an external client will try to connect to the port
8 import ./make-test-python.nix ({ pkgs, ... }:
11 internalRouterAddress = "192.168.3.1";
12 internalClient1Address = "192.168.3.2";
13 externalRouterAddress = "80.100.100.1";
14 externalClient2Address = "80.100.100.2";
18 meta = with pkgs.lib.maintainers; {
19 maintainers = [ bobvanderlinden ];
26 { virtualisation.vlans = [ 1 2 ];
27 networking.nat.enable = true;
28 networking.nat.internalInterfaces = [ "eth2" ];
29 networking.nat.externalInterface = "eth1";
30 networking.firewall.enable = true;
31 networking.firewall.trustedInterfaces = [ "eth2" ];
32 networking.interfaces.eth1.ipv4.addresses = [
33 { address = externalRouterAddress; prefixLength = 24; }
35 networking.interfaces.eth2.ipv4.addresses = [
36 { address = internalRouterAddress; prefixLength = 24; }
38 services.miniupnpd = {
40 externalInterface = "eth1";
41 internalIPs = [ "eth2" ];
43 ext_ip=${externalRouterAddress}
50 { environment.systemPackages = [ pkgs.miniupnpc pkgs.netcat ];
51 virtualisation.vlans = [ 2 ];
52 networking.defaultGateway = internalRouterAddress;
53 networking.interfaces.eth1.ipv4.addresses = [
54 { address = internalClient1Address; prefixLength = 24; }
56 networking.firewall.enable = false;
58 services.httpd.enable = true;
59 services.httpd.virtualHosts.localhost = {
60 listen = [{ ip = "*"; port = 9000; }];
61 adminAddr = "foo@example.org";
62 documentRoot = "/tmp";
68 { environment.systemPackages = [ pkgs.miniupnpc ];
69 virtualisation.vlans = [ 1 ];
70 networking.interfaces.eth1.ipv4.addresses = [
71 { address = externalClient2Address; prefixLength = 24; }
73 networking.firewall.enable = false;
82 # Wait for network and miniupnpd.
83 router.wait_for_unit("network-online.target")
84 # $router.wait_for_unit("nat")
85 router.wait_for_unit("firewall.service")
86 router.wait_for_unit("miniupnpd")
88 client1.wait_for_unit("network-online.target")
90 client1.succeed("upnpc -a ${internalClient1Address} 9000 9000 TCP")
92 client1.wait_for_unit("httpd")
93 client2.wait_until_succeeds("curl -f http://${externalRouterAddress}:9000/")