2020-04-26 13:24:18 +01:00
|
|
|
{ kernelPackages ? null }:
|
|
|
|
|
2019-09-19 21:54:38 +01:00
|
|
|
let
|
|
|
|
listenPort = 12345;
|
|
|
|
socketNamespace = "foo";
|
|
|
|
interfaceNamespace = "bar";
|
|
|
|
node = {
|
|
|
|
networking.wireguard.interfaces.wg0 = {
|
|
|
|
listenPort = listenPort;
|
|
|
|
ips = [ "10.10.10.1/24" ];
|
|
|
|
privateKeyFile = "/etc/wireguard/private";
|
|
|
|
generatePrivateKeyFile = true;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
in
|
|
|
|
|
2020-04-26 13:24:18 +01:00
|
|
|
import ../make-test-python.nix ({ pkgs, lib, ... } : {
|
2019-09-19 21:54:38 +01:00
|
|
|
name = "wireguard-with-namespaces";
|
|
|
|
meta = with pkgs.stdenv.lib.maintainers; {
|
|
|
|
maintainers = [ asymmetric ];
|
|
|
|
};
|
|
|
|
|
|
|
|
nodes = {
|
|
|
|
# interface should be created in the socketNamespace
|
|
|
|
# and not moved from there
|
|
|
|
peer0 = pkgs.lib.attrsets.recursiveUpdate node {
|
2020-04-26 13:24:18 +01:00
|
|
|
boot = lib.mkIf (kernelPackages != null) { inherit kernelPackages; };
|
2019-09-19 21:54:38 +01:00
|
|
|
networking.wireguard.interfaces.wg0 = {
|
|
|
|
preSetup = ''
|
|
|
|
ip netns add ${socketNamespace}
|
|
|
|
'';
|
|
|
|
inherit socketNamespace;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
# interface should be created in the init namespace
|
|
|
|
# and moved to the interfaceNamespace
|
|
|
|
peer1 = pkgs.lib.attrsets.recursiveUpdate node {
|
2020-04-26 13:24:18 +01:00
|
|
|
boot = lib.mkIf (kernelPackages != null) { inherit kernelPackages; };
|
2019-09-19 21:54:38 +01:00
|
|
|
networking.wireguard.interfaces.wg0 = {
|
|
|
|
preSetup = ''
|
|
|
|
ip netns add ${interfaceNamespace}
|
|
|
|
'';
|
|
|
|
inherit interfaceNamespace;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
# interface should be created in the socketNamespace
|
|
|
|
# and moved to the interfaceNamespace
|
|
|
|
peer2 = pkgs.lib.attrsets.recursiveUpdate node {
|
2020-04-26 13:24:18 +01:00
|
|
|
boot = lib.mkIf (kernelPackages != null) { inherit kernelPackages; };
|
2019-09-19 21:54:38 +01:00
|
|
|
networking.wireguard.interfaces.wg0 = {
|
|
|
|
preSetup = ''
|
|
|
|
ip netns add ${socketNamespace}
|
|
|
|
ip netns add ${interfaceNamespace}
|
|
|
|
'';
|
|
|
|
inherit socketNamespace interfaceNamespace;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
# interface should be created in the socketNamespace
|
|
|
|
# and moved to the init namespace
|
|
|
|
peer3 = pkgs.lib.attrsets.recursiveUpdate node {
|
2020-04-26 13:24:18 +01:00
|
|
|
boot = lib.mkIf (kernelPackages != null) { inherit kernelPackages; };
|
2019-09-19 21:54:38 +01:00
|
|
|
networking.wireguard.interfaces.wg0 = {
|
|
|
|
preSetup = ''
|
|
|
|
ip netns add ${socketNamespace}
|
|
|
|
'';
|
|
|
|
inherit socketNamespace;
|
|
|
|
interfaceNamespace = "init";
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
testScript = ''
|
2019-12-15 14:10:09 +00:00
|
|
|
start_all()
|
2019-09-19 21:54:38 +01:00
|
|
|
|
2019-12-15 14:10:09 +00:00
|
|
|
for machine in peer0, peer1, peer2, peer3:
|
|
|
|
machine.wait_for_unit("wireguard-wg0.service")
|
2019-09-19 21:54:38 +01:00
|
|
|
|
2019-12-15 14:10:09 +00:00
|
|
|
peer0.succeed("ip -n ${socketNamespace} link show wg0")
|
|
|
|
peer1.succeed("ip -n ${interfaceNamespace} link show wg0")
|
|
|
|
peer2.succeed("ip -n ${interfaceNamespace} link show wg0")
|
|
|
|
peer3.succeed("ip link show wg0")
|
2019-09-19 21:54:38 +01:00
|
|
|
'';
|
|
|
|
})
|