2017-03-06 12:23:45 +00:00
|
|
|
{ system ? builtins.currentSystem
|
2018-11-11 08:41:11 +00:00
|
|
|
, config ? {}
|
2018-11-12 15:18:58 +00:00
|
|
|
, pkgs ? import ../.. { inherit system config; }
|
2017-03-06 12:23:45 +00:00
|
|
|
# bool: whether to use networkd in the tests
|
|
|
|
, networkd }:
|
2016-02-29 19:06:55 +00:00
|
|
|
|
2019-12-15 21:21:17 +00:00
|
|
|
with import ../lib/testing-python.nix { inherit system pkgs; };
|
2020-03-13 20:47:07 +00:00
|
|
|
with pkgs.lib;
|
2016-02-29 19:06:55 +00:00
|
|
|
|
|
|
|
let
|
2021-06-23 15:46:46 +00:00
|
|
|
qemu-common = import ../lib/qemu-common.nix { inherit (pkgs) lib pkgs; };
|
2020-04-20 20:06:02 +00:00
|
|
|
|
|
|
|
router = { config, pkgs, lib, ... }:
|
2020-03-13 20:47:07 +00:00
|
|
|
with pkgs.lib;
|
2016-02-29 19:06:55 +00:00
|
|
|
let
|
|
|
|
vlanIfs = range 1 (length config.virtualisation.vlans);
|
|
|
|
in {
|
2018-09-02 10:13:06 +00:00
|
|
|
environment.systemPackages = [ pkgs.iptables ]; # to debug firewall rules
|
2016-02-29 19:06:55 +00:00
|
|
|
virtualisation.vlans = [ 1 2 3 ];
|
2017-01-14 16:01:46 +00:00
|
|
|
boot.kernel.sysctl."net.ipv6.conf.all.forwarding" = true;
|
2016-02-29 19:06:55 +00:00
|
|
|
networking = {
|
|
|
|
useDHCP = false;
|
|
|
|
useNetworkd = networkd;
|
2017-01-14 16:01:46 +00:00
|
|
|
firewall.checkReversePath = true;
|
|
|
|
firewall.allowedUDPPorts = [ 547 ];
|
2019-08-05 11:03:38 +00:00
|
|
|
interfaces = mkOverride 0 (listToAttrs (forEach vlanIfs (n:
|
2016-02-29 19:06:55 +00:00
|
|
|
nameValuePair "eth${toString n}" {
|
2017-12-03 04:14:54 +00:00
|
|
|
ipv4.addresses = [ { address = "192.168.${toString n}.1"; prefixLength = 24; } ];
|
|
|
|
ipv6.addresses = [ { address = "fd00:1234:5678:${toString n}::1"; prefixLength = 64; } ];
|
2016-02-29 19:06:55 +00:00
|
|
|
})));
|
|
|
|
};
|
2017-01-14 16:01:46 +00:00
|
|
|
services.dhcpd4 = {
|
2016-02-29 19:06:55 +00:00
|
|
|
enable = true;
|
|
|
|
interfaces = map (n: "eth${toString n}") vlanIfs;
|
2020-07-26 08:03:38 +00:00
|
|
|
extraConfig = flip concatMapStrings vlanIfs (n: ''
|
2016-02-29 19:06:55 +00:00
|
|
|
subnet 192.168.${toString n}.0 netmask 255.255.255.0 {
|
|
|
|
option routers 192.168.${toString n}.1;
|
2021-02-10 18:53:35 +00:00
|
|
|
range 192.168.${toString n}.3 192.168.${toString n}.254;
|
2016-02-29 19:06:55 +00:00
|
|
|
}
|
2020-04-20 20:06:02 +00:00
|
|
|
'')
|
|
|
|
;
|
2020-07-26 08:03:38 +00:00
|
|
|
machines = flip map vlanIfs (vlan:
|
2020-04-20 20:06:02 +00:00
|
|
|
{
|
|
|
|
hostName = "client${toString vlan}";
|
2021-06-23 15:46:46 +00:00
|
|
|
ethernetAddress = qemu-common.qemuNicMac vlan 1;
|
2020-04-20 20:06:02 +00:00
|
|
|
ipAddress = "192.168.${toString vlan}.2";
|
|
|
|
}
|
|
|
|
);
|
2016-02-29 19:06:55 +00:00
|
|
|
};
|
2017-01-14 16:01:46 +00:00
|
|
|
services.radvd = {
|
|
|
|
enable = true;
|
|
|
|
config = flip concatMapStrings vlanIfs (n: ''
|
|
|
|
interface eth${toString n} {
|
|
|
|
AdvSendAdvert on;
|
|
|
|
AdvManagedFlag on;
|
|
|
|
AdvOtherConfigFlag on;
|
|
|
|
|
|
|
|
prefix fd00:1234:5678:${toString n}::/64 {
|
|
|
|
AdvAutonomous off;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
'');
|
|
|
|
};
|
|
|
|
services.dhcpd6 = {
|
|
|
|
enable = true;
|
|
|
|
interfaces = map (n: "eth${toString n}") vlanIfs;
|
|
|
|
extraConfig = ''
|
|
|
|
authoritative;
|
|
|
|
'' + flip concatMapStrings vlanIfs (n: ''
|
|
|
|
subnet6 fd00:1234:5678:${toString n}::/64 {
|
|
|
|
range6 fd00:1234:5678:${toString n}::2 fd00:1234:5678:${toString n}::2;
|
|
|
|
}
|
|
|
|
'');
|
|
|
|
};
|
2016-02-29 19:06:55 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
testCases = {
|
|
|
|
loopback = {
|
|
|
|
name = "Loopback";
|
2022-06-02 18:16:25 +00:00
|
|
|
nodes.client = { pkgs, ... }: with pkgs.lib; {
|
|
|
|
networking.useDHCP = false;
|
|
|
|
networking.useNetworkd = networkd;
|
|
|
|
};
|
2016-02-29 19:06:55 +00:00
|
|
|
testScript = ''
|
2019-12-15 21:21:17 +00:00
|
|
|
start_all()
|
2022-06-02 18:16:25 +00:00
|
|
|
client.wait_for_unit("network.target")
|
|
|
|
loopback_addresses = client.succeed("ip addr show lo")
|
2019-12-15 21:21:17 +00:00
|
|
|
assert "inet 127.0.0.1/8" in loopback_addresses
|
|
|
|
assert "inet6 ::1/128" in loopback_addresses
|
2016-02-29 19:06:55 +00:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
static = {
|
|
|
|
name = "Static";
|
|
|
|
nodes.router = router;
|
2020-03-13 20:47:07 +00:00
|
|
|
nodes.client = { pkgs, ... }: with pkgs.lib; {
|
2023-05-22 03:38:52 +00:00
|
|
|
virtualisation.interfaces.enp1s0.vlan = 1;
|
|
|
|
virtualisation.interfaces.enp2s0.vlan = 2;
|
2014-11-25 23:40:49 +00:00
|
|
|
networking = {
|
|
|
|
useNetworkd = networkd;
|
2016-02-29 19:06:55 +00:00
|
|
|
useDHCP = false;
|
|
|
|
defaultGateway = "192.168.1.1";
|
2022-06-18 07:25:56 +00:00
|
|
|
defaultGateway6 = "fd00:1234:5678:1::1";
|
2023-05-22 03:38:52 +00:00
|
|
|
interfaces.enp1s0.ipv4.addresses = [
|
2016-02-29 19:06:55 +00:00
|
|
|
{ address = "192.168.1.2"; prefixLength = 24; }
|
|
|
|
{ address = "192.168.1.3"; prefixLength = 32; }
|
|
|
|
{ address = "192.168.1.10"; prefixLength = 32; }
|
|
|
|
];
|
2023-05-22 03:38:52 +00:00
|
|
|
interfaces.enp2s0.ipv4.addresses = [
|
2016-02-29 19:06:55 +00:00
|
|
|
{ address = "192.168.2.2"; prefixLength = 24; }
|
|
|
|
];
|
2014-11-25 23:40:49 +00:00
|
|
|
};
|
|
|
|
};
|
2018-07-20 20:56:59 +00:00
|
|
|
testScript = { ... }:
|
2016-02-29 19:06:55 +00:00
|
|
|
''
|
2019-12-15 21:21:17 +00:00
|
|
|
start_all()
|
2016-02-29 19:06:55 +00:00
|
|
|
|
2019-12-15 21:21:17 +00:00
|
|
|
client.wait_for_unit("network.target")
|
|
|
|
router.wait_for_unit("network-online.target")
|
2016-02-29 19:06:55 +00:00
|
|
|
|
2019-12-15 21:21:17 +00:00
|
|
|
with subtest("Make sure dhcpcd is not started"):
|
|
|
|
client.fail("systemctl status dhcpcd.service")
|
2016-02-29 19:06:55 +00:00
|
|
|
|
2019-12-15 21:21:17 +00:00
|
|
|
with subtest("Test vlan 1"):
|
|
|
|
client.wait_until_succeeds("ping -c 1 192.168.1.1")
|
|
|
|
client.wait_until_succeeds("ping -c 1 192.168.1.2")
|
|
|
|
client.wait_until_succeeds("ping -c 1 192.168.1.3")
|
|
|
|
client.wait_until_succeeds("ping -c 1 192.168.1.10")
|
2016-02-29 19:06:55 +00:00
|
|
|
|
2019-12-15 21:21:17 +00:00
|
|
|
router.wait_until_succeeds("ping -c 1 192.168.1.1")
|
|
|
|
router.wait_until_succeeds("ping -c 1 192.168.1.2")
|
|
|
|
router.wait_until_succeeds("ping -c 1 192.168.1.3")
|
|
|
|
router.wait_until_succeeds("ping -c 1 192.168.1.10")
|
2016-02-29 19:06:55 +00:00
|
|
|
|
2019-12-15 21:21:17 +00:00
|
|
|
with subtest("Test vlan 2"):
|
|
|
|
client.wait_until_succeeds("ping -c 1 192.168.2.1")
|
|
|
|
client.wait_until_succeeds("ping -c 1 192.168.2.2")
|
2016-02-29 19:06:55 +00:00
|
|
|
|
2019-12-15 21:21:17 +00:00
|
|
|
router.wait_until_succeeds("ping -c 1 192.168.2.1")
|
|
|
|
router.wait_until_succeeds("ping -c 1 192.168.2.2")
|
2016-02-29 19:06:55 +00:00
|
|
|
|
2019-12-15 21:21:17 +00:00
|
|
|
with subtest("Test default gateway"):
|
|
|
|
router.wait_until_succeeds("ping -c 1 192.168.3.1")
|
|
|
|
client.wait_until_succeeds("ping -c 1 192.168.3.1")
|
2022-06-18 07:25:56 +00:00
|
|
|
router.wait_until_succeeds("ping -c 1 fd00:1234:5678:3::1")
|
|
|
|
client.wait_until_succeeds("ping -c 1 fd00:1234:5678:3::1")
|
2015-12-18 06:09:42 +00:00
|
|
|
'';
|
2016-02-29 19:06:55 +00:00
|
|
|
};
|
2022-06-02 18:16:25 +00:00
|
|
|
routeType = {
|
|
|
|
name = "RouteType";
|
|
|
|
nodes.client = { pkgs, ... }: with pkgs.lib; {
|
|
|
|
networking = {
|
|
|
|
useDHCP = false;
|
|
|
|
useNetworkd = networkd;
|
|
|
|
interfaces.eth1.ipv4.routes = [{
|
|
|
|
address = "192.168.1.127";
|
|
|
|
prefixLength = 32;
|
|
|
|
type = "local";
|
|
|
|
}];
|
|
|
|
};
|
|
|
|
};
|
|
|
|
testScript = ''
|
|
|
|
start_all()
|
|
|
|
client.wait_for_unit("network.target")
|
|
|
|
client.succeed("ip -4 route list table local | grep 'local 192.168.1.127'")
|
|
|
|
'';
|
|
|
|
};
|
2022-04-05 19:28:38 +00:00
|
|
|
dhcpDefault = {
|
|
|
|
name = "useDHCP-by-default";
|
|
|
|
nodes.router = router;
|
|
|
|
nodes.client = { lib, ... }: {
|
|
|
|
# Disable test driver default config
|
|
|
|
networking.interfaces = lib.mkForce {};
|
2022-04-29 21:35:53 +00:00
|
|
|
networking.useNetworkd = networkd;
|
2023-05-22 03:38:52 +00:00
|
|
|
virtualisation.interfaces.enp1s0.vlan = 1;
|
2022-04-05 19:28:38 +00:00
|
|
|
};
|
|
|
|
testScript = ''
|
|
|
|
start_all()
|
|
|
|
client.wait_for_unit("multi-user.target")
|
2023-05-22 03:38:52 +00:00
|
|
|
client.wait_until_succeeds("ip addr show dev enp1s0 | grep '192.168.1'")
|
2022-04-05 19:28:38 +00:00
|
|
|
client.shell_interact()
|
|
|
|
client.succeed("ping -c 1 192.168.1.1")
|
|
|
|
router.succeed("ping -c 1 192.168.1.1")
|
|
|
|
router.succeed("ping -c 1 192.168.1.2")
|
2022-04-29 11:12:05 +00:00
|
|
|
client.succeed("ping -c 1 192.168.1.2")
|
2022-04-05 19:28:38 +00:00
|
|
|
'';
|
|
|
|
};
|
2016-02-29 19:06:55 +00:00
|
|
|
dhcpSimple = {
|
|
|
|
name = "SimpleDHCP";
|
|
|
|
nodes.router = router;
|
2020-03-13 20:47:07 +00:00
|
|
|
nodes.client = { pkgs, ... }: with pkgs.lib; {
|
2023-05-22 03:38:52 +00:00
|
|
|
virtualisation.interfaces.enp1s0.vlan = 1;
|
|
|
|
virtualisation.interfaces.enp2s0.vlan = 2;
|
2016-02-29 19:06:55 +00:00
|
|
|
networking = {
|
|
|
|
useNetworkd = networkd;
|
2019-09-23 14:37:58 +00:00
|
|
|
useDHCP = false;
|
2023-05-22 03:38:52 +00:00
|
|
|
interfaces.enp1s0.useDHCP = true;
|
|
|
|
interfaces.enp2s0.useDHCP = true;
|
2014-11-25 23:40:49 +00:00
|
|
|
};
|
|
|
|
};
|
2018-07-20 20:56:59 +00:00
|
|
|
testScript = { ... }:
|
2016-02-29 19:06:55 +00:00
|
|
|
''
|
2019-12-15 21:21:17 +00:00
|
|
|
start_all()
|
|
|
|
|
|
|
|
client.wait_for_unit("network.target")
|
|
|
|
router.wait_for_unit("network-online.target")
|
|
|
|
|
|
|
|
with subtest("Wait until we have an ip address on each interface"):
|
2023-05-22 03:38:52 +00:00
|
|
|
client.wait_until_succeeds("ip addr show dev enp1s0 | grep -q '192.168.1'")
|
|
|
|
client.wait_until_succeeds("ip addr show dev enp1s0 | grep -q 'fd00:1234:5678:1:'")
|
|
|
|
client.wait_until_succeeds("ip addr show dev enp2s0 | grep -q '192.168.2'")
|
|
|
|
client.wait_until_succeeds("ip addr show dev enp2s0 | grep -q 'fd00:1234:5678:2:'")
|
2019-12-15 21:21:17 +00:00
|
|
|
|
|
|
|
with subtest("Test vlan 1"):
|
|
|
|
client.wait_until_succeeds("ping -c 1 192.168.1.1")
|
|
|
|
client.wait_until_succeeds("ping -c 1 192.168.1.2")
|
|
|
|
client.wait_until_succeeds("ping -c 1 fd00:1234:5678:1::1")
|
|
|
|
client.wait_until_succeeds("ping -c 1 fd00:1234:5678:1::2")
|
|
|
|
|
|
|
|
router.wait_until_succeeds("ping -c 1 192.168.1.1")
|
|
|
|
router.wait_until_succeeds("ping -c 1 192.168.1.2")
|
|
|
|
router.wait_until_succeeds("ping -c 1 fd00:1234:5678:1::1")
|
|
|
|
router.wait_until_succeeds("ping -c 1 fd00:1234:5678:1::2")
|
|
|
|
|
|
|
|
with subtest("Test vlan 2"):
|
|
|
|
client.wait_until_succeeds("ping -c 1 192.168.2.1")
|
|
|
|
client.wait_until_succeeds("ping -c 1 192.168.2.2")
|
|
|
|
client.wait_until_succeeds("ping -c 1 fd00:1234:5678:2::1")
|
|
|
|
client.wait_until_succeeds("ping -c 1 fd00:1234:5678:2::2")
|
|
|
|
|
|
|
|
router.wait_until_succeeds("ping -c 1 192.168.2.1")
|
|
|
|
router.wait_until_succeeds("ping -c 1 192.168.2.2")
|
|
|
|
router.wait_until_succeeds("ping -c 1 fd00:1234:5678:2::1")
|
|
|
|
router.wait_until_succeeds("ping -c 1 fd00:1234:5678:2::2")
|
2016-02-29 19:06:55 +00:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
dhcpOneIf = {
|
|
|
|
name = "OneInterfaceDHCP";
|
|
|
|
nodes.router = router;
|
2020-03-13 20:47:07 +00:00
|
|
|
nodes.client = { pkgs, ... }: with pkgs.lib; {
|
2023-05-22 03:38:52 +00:00
|
|
|
virtualisation.interfaces.enp1s0.vlan = 1;
|
|
|
|
virtualisation.interfaces.enp2s0.vlan = 2;
|
2016-02-29 19:06:55 +00:00
|
|
|
networking = {
|
|
|
|
useNetworkd = networkd;
|
|
|
|
useDHCP = false;
|
2023-05-22 03:38:52 +00:00
|
|
|
interfaces.enp1s0 = {
|
2020-04-13 17:17:56 +00:00
|
|
|
mtu = 1343;
|
2016-02-29 19:06:55 +00:00
|
|
|
useDHCP = true;
|
2014-11-25 23:40:49 +00:00
|
|
|
};
|
|
|
|
};
|
2016-02-29 19:06:55 +00:00
|
|
|
};
|
2018-07-20 20:56:59 +00:00
|
|
|
testScript = { ... }:
|
2016-02-29 19:06:55 +00:00
|
|
|
''
|
2019-12-15 21:21:17 +00:00
|
|
|
start_all()
|
2014-11-25 23:40:49 +00:00
|
|
|
|
2019-12-15 21:21:17 +00:00
|
|
|
with subtest("Wait for networking to come up"):
|
|
|
|
client.wait_for_unit("network.target")
|
|
|
|
router.wait_for_unit("network.target")
|
2014-11-25 23:40:49 +00:00
|
|
|
|
2019-12-15 21:21:17 +00:00
|
|
|
with subtest("Wait until we have an ip address on each interface"):
|
2023-05-22 03:38:52 +00:00
|
|
|
client.wait_until_succeeds("ip addr show dev enp1s0 | grep -q '192.168.1'")
|
2014-11-25 23:40:49 +00:00
|
|
|
|
2020-04-13 17:17:56 +00:00
|
|
|
with subtest("ensure MTU is set"):
|
2023-05-22 03:38:52 +00:00
|
|
|
assert "mtu 1343" in client.succeed("ip link show dev enp1s0")
|
2020-04-13 17:17:56 +00:00
|
|
|
|
2019-12-15 21:21:17 +00:00
|
|
|
with subtest("Test vlan 1"):
|
|
|
|
client.wait_until_succeeds("ping -c 1 192.168.1.1")
|
|
|
|
client.wait_until_succeeds("ping -c 1 192.168.1.2")
|
2014-11-25 23:40:49 +00:00
|
|
|
|
2019-12-15 21:21:17 +00:00
|
|
|
router.wait_until_succeeds("ping -c 1 192.168.1.1")
|
|
|
|
router.wait_until_succeeds("ping -c 1 192.168.1.2")
|
2014-11-25 23:40:49 +00:00
|
|
|
|
2019-12-15 21:21:17 +00:00
|
|
|
with subtest("Test vlan 2"):
|
|
|
|
client.wait_until_succeeds("ping -c 1 192.168.2.1")
|
|
|
|
client.fail("ping -c 1 192.168.2.2")
|
2014-11-25 23:40:49 +00:00
|
|
|
|
2019-12-15 21:21:17 +00:00
|
|
|
router.wait_until_succeeds("ping -c 1 192.168.2.1")
|
|
|
|
router.fail("ping -c 1 192.168.2.2")
|
2016-02-29 19:06:55 +00:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
bond = let
|
2020-03-13 20:47:07 +00:00
|
|
|
node = address: { pkgs, ... }: with pkgs.lib; {
|
2023-05-22 03:38:52 +00:00
|
|
|
virtualisation.interfaces.enp1s0.vlan = 1;
|
|
|
|
virtualisation.interfaces.enp2s0.vlan = 2;
|
2016-02-29 19:06:55 +00:00
|
|
|
networking = {
|
|
|
|
useNetworkd = networkd;
|
|
|
|
useDHCP = false;
|
2022-02-22 16:29:41 +00:00
|
|
|
bonds.bond0 = {
|
2023-05-22 03:38:52 +00:00
|
|
|
interfaces = [ "enp1s0" "enp2s0" ];
|
2022-02-22 16:29:41 +00:00
|
|
|
driverOptions.mode = "802.3ad";
|
2014-11-25 23:40:49 +00:00
|
|
|
};
|
2022-02-22 16:29:41 +00:00
|
|
|
interfaces.bond0.ipv4.addresses = mkOverride 0
|
2016-02-29 19:06:55 +00:00
|
|
|
[ { inherit address; prefixLength = 30; } ];
|
2014-11-25 23:40:49 +00:00
|
|
|
};
|
|
|
|
};
|
2016-02-29 19:06:55 +00:00
|
|
|
in {
|
|
|
|
name = "Bond";
|
|
|
|
nodes.client1 = node "192.168.1.1";
|
|
|
|
nodes.client2 = node "192.168.1.2";
|
2018-07-20 20:56:59 +00:00
|
|
|
testScript = { ... }:
|
2016-02-29 19:06:55 +00:00
|
|
|
''
|
2019-12-15 21:21:17 +00:00
|
|
|
start_all()
|
2016-02-29 19:06:55 +00:00
|
|
|
|
2019-12-15 21:21:17 +00:00
|
|
|
with subtest("Wait for networking to come up"):
|
|
|
|
client1.wait_for_unit("network.target")
|
|
|
|
client2.wait_for_unit("network.target")
|
2016-02-29 19:06:55 +00:00
|
|
|
|
2019-12-15 21:21:17 +00:00
|
|
|
with subtest("Test bonding"):
|
|
|
|
client1.wait_until_succeeds("ping -c 2 192.168.1.1")
|
|
|
|
client1.wait_until_succeeds("ping -c 2 192.168.1.2")
|
2016-02-29 19:06:55 +00:00
|
|
|
|
2019-12-15 21:21:17 +00:00
|
|
|
client2.wait_until_succeeds("ping -c 2 192.168.1.1")
|
|
|
|
client2.wait_until_succeeds("ping -c 2 192.168.1.2")
|
2022-02-22 16:29:41 +00:00
|
|
|
|
|
|
|
with subtest("Verify bonding mode"):
|
|
|
|
for client in client1, client2:
|
|
|
|
client.succeed('grep -q "Bonding Mode: IEEE 802.3ad Dynamic link aggregation" /proc/net/bonding/bond0')
|
2016-02-29 19:06:55 +00:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
bridge = let
|
2020-03-13 20:47:07 +00:00
|
|
|
node = { address, vlan }: { pkgs, ... }: with pkgs.lib; {
|
2023-05-22 03:38:52 +00:00
|
|
|
virtualisation.interfaces.enp1s0.vlan = vlan;
|
2016-02-29 19:06:55 +00:00
|
|
|
networking = {
|
|
|
|
useNetworkd = networkd;
|
|
|
|
useDHCP = false;
|
2023-05-22 03:38:52 +00:00
|
|
|
interfaces.enp1s0.ipv4.addresses = [ { inherit address; prefixLength = 24; } ];
|
2014-11-25 23:40:49 +00:00
|
|
|
};
|
2016-02-29 19:06:55 +00:00
|
|
|
};
|
|
|
|
in {
|
|
|
|
name = "Bridge";
|
|
|
|
nodes.client1 = node { address = "192.168.1.2"; vlan = 1; };
|
|
|
|
nodes.client2 = node { address = "192.168.1.3"; vlan = 2; };
|
2020-03-13 20:47:07 +00:00
|
|
|
nodes.router = { pkgs, ... }: with pkgs.lib; {
|
2023-05-22 03:38:52 +00:00
|
|
|
virtualisation.interfaces.enp1s0.vlan = 1;
|
|
|
|
virtualisation.interfaces.enp2s0.vlan = 2;
|
2016-02-29 19:06:55 +00:00
|
|
|
networking = {
|
|
|
|
useNetworkd = networkd;
|
|
|
|
useDHCP = false;
|
2023-05-22 03:38:52 +00:00
|
|
|
bridges.bridge.interfaces = [ "enp1s0" "enp2s0" ];
|
2017-12-03 04:13:14 +00:00
|
|
|
interfaces.eth1.ipv4.addresses = mkOverride 0 [ ];
|
|
|
|
interfaces.eth2.ipv4.addresses = mkOverride 0 [ ];
|
|
|
|
interfaces.bridge.ipv4.addresses = mkOverride 0
|
2016-02-29 19:06:55 +00:00
|
|
|
[ { address = "192.168.1.1"; prefixLength = 24; } ];
|
2014-11-25 23:40:49 +00:00
|
|
|
};
|
|
|
|
};
|
2018-07-20 20:56:59 +00:00
|
|
|
testScript = { ... }:
|
2016-02-29 19:06:55 +00:00
|
|
|
''
|
2019-12-15 21:21:17 +00:00
|
|
|
start_all()
|
2016-02-29 19:06:55 +00:00
|
|
|
|
2019-12-15 21:21:17 +00:00
|
|
|
with subtest("Wait for networking to come up"):
|
|
|
|
for machine in client1, client2, router:
|
|
|
|
machine.wait_for_unit("network.target")
|
2016-02-29 19:06:55 +00:00
|
|
|
|
2019-12-15 21:21:17 +00:00
|
|
|
with subtest("Test bridging"):
|
|
|
|
client1.wait_until_succeeds("ping -c 1 192.168.1.1")
|
|
|
|
client1.wait_until_succeeds("ping -c 1 192.168.1.2")
|
|
|
|
client1.wait_until_succeeds("ping -c 1 192.168.1.3")
|
2016-02-29 19:06:55 +00:00
|
|
|
|
2019-12-15 21:21:17 +00:00
|
|
|
client2.wait_until_succeeds("ping -c 1 192.168.1.1")
|
|
|
|
client2.wait_until_succeeds("ping -c 1 192.168.1.2")
|
|
|
|
client2.wait_until_succeeds("ping -c 1 192.168.1.3")
|
2016-02-29 19:06:55 +00:00
|
|
|
|
2019-12-15 21:21:17 +00:00
|
|
|
router.wait_until_succeeds("ping -c 1 192.168.1.1")
|
|
|
|
router.wait_until_succeeds("ping -c 1 192.168.1.2")
|
|
|
|
router.wait_until_succeeds("ping -c 1 192.168.1.3")
|
2016-02-29 19:06:55 +00:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
macvlan = {
|
|
|
|
name = "MACVLAN";
|
|
|
|
nodes.router = router;
|
2020-03-13 20:47:07 +00:00
|
|
|
nodes.client = { pkgs, ... }: with pkgs.lib; {
|
2018-09-02 10:13:06 +00:00
|
|
|
environment.systemPackages = [ pkgs.iptables ]; # to debug firewall rules
|
2023-05-22 03:38:52 +00:00
|
|
|
virtualisation.interfaces.enp1s0.vlan = 1;
|
2016-02-29 19:06:55 +00:00
|
|
|
networking = {
|
|
|
|
useNetworkd = networkd;
|
2019-09-23 14:37:58 +00:00
|
|
|
useDHCP = false;
|
2018-09-02 10:13:06 +00:00
|
|
|
firewall.logReversePathDrops = true; # to debug firewall rules
|
|
|
|
# reverse path filtering rules for the macvlan interface seem
|
|
|
|
# to be incorrect, causing the test to fail. Disable temporarily.
|
|
|
|
firewall.checkReversePath = false;
|
2023-05-22 03:38:52 +00:00
|
|
|
macvlans.macvlan.interface = "enp1s0";
|
|
|
|
interfaces.enp1s0.useDHCP = true;
|
|
|
|
interfaces.macvlan.useDHCP = true;
|
2014-11-25 23:40:49 +00:00
|
|
|
};
|
|
|
|
};
|
2018-07-20 20:56:59 +00:00
|
|
|
testScript = { ... }:
|
2016-02-29 19:06:55 +00:00
|
|
|
''
|
2019-12-15 21:21:17 +00:00
|
|
|
start_all()
|
|
|
|
|
|
|
|
with subtest("Wait for networking to come up"):
|
|
|
|
client.wait_for_unit("network.target")
|
|
|
|
router.wait_for_unit("network.target")
|
|
|
|
|
|
|
|
with subtest("Wait until we have an ip address on each interface"):
|
2023-05-22 03:38:52 +00:00
|
|
|
client.wait_until_succeeds("ip addr show dev enp1s0 | grep -q '192.168.1'")
|
2019-12-15 21:21:17 +00:00
|
|
|
client.wait_until_succeeds("ip addr show dev macvlan | grep -q '192.168.1'")
|
|
|
|
|
|
|
|
with subtest("Print lots of diagnostic information"):
|
|
|
|
router.log("**********************************************")
|
|
|
|
router.succeed("ip addr >&2")
|
|
|
|
router.succeed("ip route >&2")
|
|
|
|
router.execute("iptables-save >&2")
|
|
|
|
client.log("==============================================")
|
|
|
|
client.succeed("ip addr >&2")
|
|
|
|
client.succeed("ip route >&2")
|
|
|
|
client.execute("iptables-save >&2")
|
|
|
|
client.log("##############################################")
|
|
|
|
|
|
|
|
with subtest("Test macvlan creates routable ips"):
|
|
|
|
client.wait_until_succeeds("ping -c 1 192.168.1.1")
|
|
|
|
client.wait_until_succeeds("ping -c 1 192.168.1.2")
|
|
|
|
client.wait_until_succeeds("ping -c 1 192.168.1.3")
|
|
|
|
|
|
|
|
router.wait_until_succeeds("ping -c 1 192.168.1.1")
|
|
|
|
router.wait_until_succeeds("ping -c 1 192.168.1.2")
|
|
|
|
router.wait_until_succeeds("ping -c 1 192.168.1.3")
|
2016-02-29 19:06:55 +00:00
|
|
|
'';
|
|
|
|
};
|
2021-08-11 09:02:47 +00:00
|
|
|
fou = {
|
|
|
|
name = "foo-over-udp";
|
|
|
|
nodes.machine = { ... }: {
|
2023-05-22 03:38:52 +00:00
|
|
|
virtualisation.interfaces.enp1s0.vlan = 1;
|
2021-08-11 09:02:47 +00:00
|
|
|
networking = {
|
|
|
|
useNetworkd = networkd;
|
|
|
|
useDHCP = false;
|
2023-05-22 03:38:52 +00:00
|
|
|
interfaces.enp1s0.ipv4.addresses = [ { address = "192.168.1.1"; prefixLength = 24; } ];
|
2021-08-11 09:02:47 +00:00
|
|
|
fooOverUDP = {
|
|
|
|
fou1 = { port = 9001; };
|
|
|
|
fou2 = { port = 9002; protocol = 41; };
|
|
|
|
fou3 = mkIf (!networkd)
|
|
|
|
{ port = 9003; local.address = "192.168.1.1"; };
|
|
|
|
fou4 = mkIf (!networkd)
|
2023-05-22 03:38:52 +00:00
|
|
|
{ port = 9004; local = { address = "192.168.1.1"; dev = "enp1s0"; }; };
|
2021-08-11 09:02:47 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
systemd.services = {
|
2023-05-22 03:38:52 +00:00
|
|
|
fou3-fou-encap.after = optional (!networkd) "network-addresses-enp1s0.service";
|
2021-08-11 09:02:47 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
testScript = { ... }:
|
|
|
|
''
|
|
|
|
import json
|
|
|
|
|
|
|
|
machine.wait_for_unit("network.target")
|
|
|
|
fous = json.loads(machine.succeed("ip -json fou show"))
|
|
|
|
assert {"port": 9001, "gue": None, "family": "inet"} in fous, "fou1 exists"
|
|
|
|
assert {"port": 9002, "ipproto": 41, "family": "inet"} in fous, "fou2 exists"
|
|
|
|
'' + optionalString (!networkd) ''
|
|
|
|
assert {
|
|
|
|
"port": 9003,
|
|
|
|
"gue": None,
|
|
|
|
"family": "inet",
|
|
|
|
"local": "192.168.1.1",
|
|
|
|
} in fous, "fou3 exists"
|
|
|
|
assert {
|
|
|
|
"port": 9004,
|
|
|
|
"gue": None,
|
|
|
|
"family": "inet",
|
|
|
|
"local": "192.168.1.1",
|
2023-05-22 03:38:52 +00:00
|
|
|
"dev": "enp1s0",
|
2021-08-11 09:02:47 +00:00
|
|
|
} in fous, "fou4 exists"
|
|
|
|
'';
|
|
|
|
};
|
2016-02-29 19:06:55 +00:00
|
|
|
sit = let
|
2020-03-13 20:47:07 +00:00
|
|
|
node = { address4, remote, address6 }: { pkgs, ... }: with pkgs.lib; {
|
2023-05-22 03:38:52 +00:00
|
|
|
virtualisation.interfaces.enp1s0.vlan = 1;
|
2016-02-29 19:06:55 +00:00
|
|
|
networking = {
|
|
|
|
useNetworkd = networkd;
|
|
|
|
useDHCP = false;
|
|
|
|
sits.sit = {
|
|
|
|
inherit remote;
|
|
|
|
local = address4;
|
2023-05-22 03:38:52 +00:00
|
|
|
dev = "enp1s0";
|
2014-11-25 23:40:49 +00:00
|
|
|
};
|
2023-05-22 03:38:52 +00:00
|
|
|
interfaces.enp1s0.ipv4.addresses = mkOverride 0
|
2016-02-29 19:06:55 +00:00
|
|
|
[ { address = address4; prefixLength = 24; } ];
|
2017-12-03 04:13:14 +00:00
|
|
|
interfaces.sit.ipv6.addresses = mkOverride 0
|
2016-02-29 19:06:55 +00:00
|
|
|
[ { address = address6; prefixLength = 64; } ];
|
2014-11-25 23:40:49 +00:00
|
|
|
};
|
|
|
|
};
|
2016-02-29 19:06:55 +00:00
|
|
|
in {
|
|
|
|
name = "Sit";
|
2021-08-11 10:48:43 +00:00
|
|
|
# note on firewalling: the two nodes are explicitly asymmetric.
|
|
|
|
# client1 sends SIT packets in UDP, but accepts only proto-41 incoming.
|
|
|
|
# client2 does the reverse, sending in proto-41 and accepting only UDP incoming.
|
|
|
|
# that way we'll notice when either SIT itself or FOU breaks.
|
|
|
|
nodes.client1 = args@{ pkgs, ... }:
|
|
|
|
mkMerge [
|
|
|
|
(node { address4 = "192.168.1.1"; remote = "192.168.1.2"; address6 = "fc00::1"; } args)
|
|
|
|
{
|
|
|
|
networking = {
|
|
|
|
firewall.extraCommands = "iptables -A INPUT -p 41 -j ACCEPT";
|
|
|
|
sits.sit.encapsulation = { type = "fou"; port = 9001; };
|
|
|
|
};
|
|
|
|
}
|
|
|
|
];
|
|
|
|
nodes.client2 = args@{ pkgs, ... }:
|
|
|
|
mkMerge [
|
|
|
|
(node { address4 = "192.168.1.2"; remote = "192.168.1.1"; address6 = "fc00::2"; } args)
|
|
|
|
{
|
|
|
|
networking = {
|
|
|
|
firewall.allowedUDPPorts = [ 9001 ];
|
|
|
|
fooOverUDP.fou1 = { port = 9001; protocol = 41; };
|
|
|
|
};
|
|
|
|
}
|
|
|
|
];
|
2018-07-20 20:56:59 +00:00
|
|
|
testScript = { ... }:
|
2016-02-29 19:06:55 +00:00
|
|
|
''
|
2019-12-15 21:21:17 +00:00
|
|
|
start_all()
|
2016-02-29 19:06:55 +00:00
|
|
|
|
2019-12-15 21:21:17 +00:00
|
|
|
with subtest("Wait for networking to be configured"):
|
|
|
|
client1.wait_for_unit("network.target")
|
|
|
|
client2.wait_for_unit("network.target")
|
2016-02-29 19:06:55 +00:00
|
|
|
|
2019-12-15 21:21:17 +00:00
|
|
|
# Print diagnostic information
|
|
|
|
client1.succeed("ip addr >&2")
|
|
|
|
client2.succeed("ip addr >&2")
|
2016-02-29 19:06:55 +00:00
|
|
|
|
2019-12-15 21:21:17 +00:00
|
|
|
with subtest("Test ipv6"):
|
|
|
|
client1.wait_until_succeeds("ping -c 1 fc00::1")
|
|
|
|
client1.wait_until_succeeds("ping -c 1 fc00::2")
|
2016-02-29 19:06:55 +00:00
|
|
|
|
2019-12-15 21:21:17 +00:00
|
|
|
client2.wait_until_succeeds("ping -c 1 fc00::1")
|
|
|
|
client2.wait_until_succeeds("ping -c 1 fc00::2")
|
2016-02-29 19:06:55 +00:00
|
|
|
'';
|
|
|
|
};
|
2021-12-07 15:44:00 +00:00
|
|
|
gre = let
|
|
|
|
node = { pkgs, ... }: with pkgs.lib; {
|
|
|
|
networking = {
|
|
|
|
useNetworkd = networkd;
|
|
|
|
useDHCP = false;
|
2022-03-16 05:48:15 +00:00
|
|
|
firewall.extraCommands = "ip6tables -A nixos-fw -p gre -j nixos-fw-accept";
|
2021-12-07 15:44:00 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
in {
|
|
|
|
name = "GRE";
|
|
|
|
nodes.client1 = args@{ pkgs, ... }:
|
|
|
|
mkMerge [
|
|
|
|
(node args)
|
|
|
|
{
|
2022-03-16 05:48:15 +00:00
|
|
|
virtualisation.vlans = [ 1 2 4 ];
|
2021-12-07 15:44:00 +00:00
|
|
|
networking = {
|
|
|
|
greTunnels = {
|
|
|
|
greTunnel = {
|
|
|
|
local = "192.168.2.1";
|
|
|
|
remote = "192.168.2.2";
|
|
|
|
dev = "eth2";
|
2022-03-22 14:54:25 +00:00
|
|
|
ttl = 225;
|
2021-12-07 15:44:00 +00:00
|
|
|
type = "tap";
|
|
|
|
};
|
2022-03-16 05:48:15 +00:00
|
|
|
gre6Tunnel = {
|
|
|
|
local = "fd00:1234:5678:4::1";
|
|
|
|
remote = "fd00:1234:5678:4::2";
|
|
|
|
dev = "eth3";
|
2022-03-22 14:54:25 +00:00
|
|
|
ttl = 255;
|
2022-03-16 05:48:15 +00:00
|
|
|
type = "tun6";
|
|
|
|
};
|
2021-12-07 15:44:00 +00:00
|
|
|
};
|
|
|
|
bridges.bridge.interfaces = [ "greTunnel" "eth1" ];
|
|
|
|
interfaces.eth1.ipv4.addresses = mkOverride 0 [];
|
|
|
|
interfaces.bridge.ipv4.addresses = mkOverride 0 [
|
|
|
|
{ address = "192.168.1.1"; prefixLength = 24; }
|
|
|
|
];
|
2022-03-16 05:48:15 +00:00
|
|
|
interfaces.eth3.ipv6.addresses = [
|
|
|
|
{ address = "fd00:1234:5678:4::1"; prefixLength = 64; }
|
|
|
|
];
|
|
|
|
interfaces.gre6Tunnel.ipv6.addresses = mkOverride 0 [
|
|
|
|
{ address = "fc00::1"; prefixLength = 64; }
|
|
|
|
];
|
2021-12-07 15:44:00 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
];
|
|
|
|
nodes.client2 = args@{ pkgs, ... }:
|
|
|
|
mkMerge [
|
|
|
|
(node args)
|
|
|
|
{
|
2022-03-16 05:48:15 +00:00
|
|
|
virtualisation.vlans = [ 2 3 4 ];
|
2021-12-07 15:44:00 +00:00
|
|
|
networking = {
|
|
|
|
greTunnels = {
|
|
|
|
greTunnel = {
|
|
|
|
local = "192.168.2.2";
|
|
|
|
remote = "192.168.2.1";
|
|
|
|
dev = "eth1";
|
2022-03-22 14:54:25 +00:00
|
|
|
ttl = 225;
|
2021-12-07 15:44:00 +00:00
|
|
|
type = "tap";
|
|
|
|
};
|
2022-03-16 05:48:15 +00:00
|
|
|
gre6Tunnel = {
|
|
|
|
local = "fd00:1234:5678:4::2";
|
|
|
|
remote = "fd00:1234:5678:4::1";
|
|
|
|
dev = "eth3";
|
2022-03-22 14:54:25 +00:00
|
|
|
ttl = 255;
|
2022-03-16 05:48:15 +00:00
|
|
|
type = "tun6";
|
|
|
|
};
|
2021-12-07 15:44:00 +00:00
|
|
|
};
|
|
|
|
bridges.bridge.interfaces = [ "greTunnel" "eth2" ];
|
|
|
|
interfaces.eth2.ipv4.addresses = mkOverride 0 [];
|
|
|
|
interfaces.bridge.ipv4.addresses = mkOverride 0 [
|
|
|
|
{ address = "192.168.1.2"; prefixLength = 24; }
|
|
|
|
];
|
2022-03-16 05:48:15 +00:00
|
|
|
interfaces.eth3.ipv6.addresses = [
|
|
|
|
{ address = "fd00:1234:5678:4::2"; prefixLength = 64; }
|
|
|
|
];
|
|
|
|
interfaces.gre6Tunnel.ipv6.addresses = mkOverride 0 [
|
|
|
|
{ address = "fc00::2"; prefixLength = 64; }
|
|
|
|
];
|
2021-12-07 15:44:00 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
];
|
|
|
|
testScript = { ... }:
|
|
|
|
''
|
2022-03-22 14:54:25 +00:00
|
|
|
import json
|
2021-12-07 15:44:00 +00:00
|
|
|
start_all()
|
|
|
|
|
|
|
|
with subtest("Wait for networking to be configured"):
|
|
|
|
client1.wait_for_unit("network.target")
|
|
|
|
client2.wait_for_unit("network.target")
|
|
|
|
|
|
|
|
# Print diagnostic information
|
|
|
|
client1.succeed("ip addr >&2")
|
|
|
|
client2.succeed("ip addr >&2")
|
|
|
|
|
|
|
|
with subtest("Test GRE tunnel bridge over VLAN"):
|
|
|
|
client1.wait_until_succeeds("ping -c 1 192.168.1.2")
|
|
|
|
|
|
|
|
client2.wait_until_succeeds("ping -c 1 192.168.1.1")
|
2022-03-16 05:48:15 +00:00
|
|
|
|
|
|
|
client1.wait_until_succeeds("ping -c 1 fc00::2")
|
|
|
|
|
|
|
|
client2.wait_until_succeeds("ping -c 1 fc00::1")
|
2022-03-22 14:54:25 +00:00
|
|
|
|
|
|
|
with subtest("Test GRE tunnel TTL"):
|
|
|
|
links = json.loads(client1.succeed("ip -details -json link show greTunnel"))
|
|
|
|
assert links[0]['linkinfo']['info_data']['ttl'] == 225, "ttl not set for greTunnel"
|
|
|
|
|
|
|
|
links = json.loads(client2.succeed("ip -details -json link show gre6Tunnel"))
|
|
|
|
assert links[0]['linkinfo']['info_data']['ttl'] == 255, "ttl not set for gre6Tunnel"
|
2021-12-07 15:44:00 +00:00
|
|
|
'';
|
|
|
|
};
|
2016-02-29 19:06:55 +00:00
|
|
|
vlan = let
|
2020-03-13 20:47:07 +00:00
|
|
|
node = address: { pkgs, ... }: with pkgs.lib; {
|
2016-02-29 19:06:55 +00:00
|
|
|
#virtualisation.vlans = [ 1 ];
|
|
|
|
networking = {
|
|
|
|
useNetworkd = networkd;
|
|
|
|
useDHCP = false;
|
|
|
|
vlans.vlan = {
|
|
|
|
id = 1;
|
|
|
|
interface = "eth0";
|
2014-11-25 23:40:49 +00:00
|
|
|
};
|
2017-12-03 04:13:14 +00:00
|
|
|
interfaces.eth0.ipv4.addresses = mkOverride 0 [ ];
|
|
|
|
interfaces.eth1.ipv4.addresses = mkOverride 0 [ ];
|
|
|
|
interfaces.vlan.ipv4.addresses = mkOverride 0
|
2016-02-29 19:06:55 +00:00
|
|
|
[ { inherit address; prefixLength = 24; } ];
|
2014-11-25 23:40:49 +00:00
|
|
|
};
|
|
|
|
};
|
2016-02-29 19:06:55 +00:00
|
|
|
in {
|
|
|
|
name = "vlan";
|
|
|
|
nodes.client1 = node "192.168.1.1";
|
|
|
|
nodes.client2 = node "192.168.1.2";
|
2018-07-20 20:56:59 +00:00
|
|
|
testScript = { ... }:
|
2016-02-29 19:06:55 +00:00
|
|
|
''
|
2019-12-15 21:21:17 +00:00
|
|
|
start_all()
|
2016-02-29 19:06:55 +00:00
|
|
|
|
2019-12-15 21:21:17 +00:00
|
|
|
with subtest("Wait for networking to be configured"):
|
|
|
|
client1.wait_for_unit("network.target")
|
|
|
|
client2.wait_for_unit("network.target")
|
2016-02-29 19:06:55 +00:00
|
|
|
|
2019-12-15 21:21:17 +00:00
|
|
|
with subtest("Test vlan is setup"):
|
|
|
|
client1.succeed("ip addr show dev vlan >&2")
|
|
|
|
client2.succeed("ip addr show dev vlan >&2")
|
2016-02-29 19:06:55 +00:00
|
|
|
'';
|
2014-11-25 23:40:49 +00:00
|
|
|
};
|
2022-07-21 13:32:53 +00:00
|
|
|
vlan-ping = let
|
|
|
|
baseIP = number: "10.10.10.${number}";
|
|
|
|
vlanIP = number: "10.1.1.${number}";
|
2023-05-22 03:38:52 +00:00
|
|
|
baseInterface = "enp1s0";
|
2022-07-21 13:32:53 +00:00
|
|
|
vlanInterface = "vlan42";
|
|
|
|
node = number: {pkgs, ... }: with pkgs.lib; {
|
2023-05-22 03:38:52 +00:00
|
|
|
virtualisation.interfaces.enp1s0.vlan = 1;
|
2022-07-21 13:32:53 +00:00
|
|
|
networking = {
|
|
|
|
#useNetworkd = networkd;
|
|
|
|
useDHCP = false;
|
|
|
|
vlans.${vlanInterface} = { id = 42; interface = baseInterface; };
|
|
|
|
interfaces.${baseInterface}.ipv4.addresses = mkOverride 0 [{ address = baseIP number; prefixLength = 24; }];
|
|
|
|
interfaces.${vlanInterface}.ipv4.addresses = mkOverride 0 [{ address = vlanIP number; prefixLength = 24; }];
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
serverNodeNum = "1";
|
|
|
|
clientNodeNum = "2";
|
|
|
|
|
|
|
|
in {
|
|
|
|
name = "vlan-ping";
|
|
|
|
nodes.server = node serverNodeNum;
|
|
|
|
nodes.client = node clientNodeNum;
|
|
|
|
testScript = { ... }:
|
|
|
|
''
|
|
|
|
start_all()
|
|
|
|
|
|
|
|
with subtest("Wait for networking to be configured"):
|
|
|
|
server.wait_for_unit("network.target")
|
|
|
|
client.wait_for_unit("network.target")
|
|
|
|
|
|
|
|
with subtest("Test ping on base interface in setup"):
|
|
|
|
client.succeed("ping -I ${baseInterface} -c 1 ${baseIP serverNodeNum}")
|
|
|
|
server.succeed("ping -I ${baseInterface} -c 1 ${baseIP clientNodeNum}")
|
|
|
|
|
|
|
|
with subtest("Test ping on vlan subinterface in setup"):
|
|
|
|
client.succeed("ping -I ${vlanInterface} -c 1 ${vlanIP serverNodeNum}")
|
|
|
|
server.succeed("ping -I ${vlanInterface} -c 1 ${vlanIP clientNodeNum}")
|
|
|
|
'';
|
|
|
|
};
|
2018-01-31 04:52:22 +00:00
|
|
|
virtual = {
|
|
|
|
name = "Virtual";
|
2022-03-20 23:15:30 +00:00
|
|
|
nodes.machine = {
|
2019-09-23 14:37:58 +00:00
|
|
|
networking.useNetworkd = networkd;
|
2019-10-08 15:09:05 +00:00
|
|
|
networking.useDHCP = false;
|
2019-08-13 21:52:01 +00:00
|
|
|
networking.interfaces.tap0 = {
|
2017-12-03 04:14:54 +00:00
|
|
|
ipv4.addresses = [ { address = "192.168.1.1"; prefixLength = 24; } ];
|
|
|
|
ipv6.addresses = [ { address = "2001:1470:fffd:2096::"; prefixLength = 64; } ];
|
2018-01-31 04:52:22 +00:00
|
|
|
virtual = true;
|
2020-04-13 17:17:56 +00:00
|
|
|
mtu = 1342;
|
|
|
|
macAddress = "02:de:ad:be:ef:01";
|
2018-01-31 04:52:22 +00:00
|
|
|
};
|
2019-08-13 21:52:01 +00:00
|
|
|
networking.interfaces.tun0 = {
|
2017-12-03 04:14:54 +00:00
|
|
|
ipv4.addresses = [ { address = "192.168.1.2"; prefixLength = 24; } ];
|
|
|
|
ipv6.addresses = [ { address = "2001:1470:fffd:2097::"; prefixLength = 64; } ];
|
2018-01-31 04:52:22 +00:00
|
|
|
virtual = true;
|
2020-04-13 17:17:56 +00:00
|
|
|
mtu = 1343;
|
2018-01-31 04:52:22 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
testScript = ''
|
2019-12-15 21:21:17 +00:00
|
|
|
targetList = """
|
2018-08-26 12:24:07 +00:00
|
|
|
tap0: tap persist user 0
|
|
|
|
tun0: tun persist user 0
|
2019-12-15 21:21:17 +00:00
|
|
|
""".strip()
|
|
|
|
|
|
|
|
with subtest("Wait for networking to come up"):
|
|
|
|
machine.start()
|
2020-04-13 17:15:08 +00:00
|
|
|
machine.wait_for_unit("network.target")
|
2019-12-15 21:21:17 +00:00
|
|
|
|
|
|
|
with subtest("Test interfaces set up"):
|
|
|
|
list = machine.succeed("ip tuntap list | sort").strip()
|
|
|
|
assert (
|
|
|
|
list == targetList
|
|
|
|
), """
|
|
|
|
The list of virtual interfaces does not match the expected one:
|
|
|
|
Result:
|
|
|
|
{}
|
|
|
|
Expected:
|
|
|
|
{}
|
|
|
|
""".format(
|
|
|
|
list, targetList
|
|
|
|
)
|
2020-04-13 17:17:56 +00:00
|
|
|
with subtest("Test MTU and MAC Address are configured"):
|
2020-11-25 19:08:03 +00:00
|
|
|
machine.wait_until_succeeds("ip link show dev tap0 | grep 'mtu 1342'")
|
|
|
|
machine.wait_until_succeeds("ip link show dev tun0 | grep 'mtu 1343'")
|
2020-04-13 17:17:56 +00:00
|
|
|
assert "02:de:ad:be:ef:01" in machine.succeed("ip link show dev tap0")
|
2020-04-13 17:15:08 +00:00
|
|
|
'' # network-addresses-* only exist in scripted networking
|
|
|
|
+ optionalString (!networkd) ''
|
2019-12-15 21:21:17 +00:00
|
|
|
with subtest("Test interfaces clean up"):
|
|
|
|
machine.succeed("systemctl stop network-addresses-tap0")
|
|
|
|
machine.sleep(10)
|
|
|
|
machine.succeed("systemctl stop network-addresses-tun0")
|
|
|
|
machine.sleep(10)
|
|
|
|
residue = machine.succeed("ip tuntap list")
|
|
|
|
assert (
|
2021-05-08 21:36:39 +00:00
|
|
|
residue == ""
|
2019-12-15 21:21:17 +00:00
|
|
|
), "Some virtual interface has not been properly cleaned:\n{}".format(residue)
|
2018-01-31 04:52:22 +00:00
|
|
|
'';
|
|
|
|
};
|
2018-02-01 14:50:35 +00:00
|
|
|
privacy = {
|
|
|
|
name = "Privacy";
|
2018-07-20 20:56:59 +00:00
|
|
|
nodes.router = { ... }: {
|
2023-05-22 03:38:52 +00:00
|
|
|
virtualisation.interfaces.enp1s0.vlan = 1;
|
2018-02-01 14:50:35 +00:00
|
|
|
boot.kernel.sysctl."net.ipv6.conf.all.forwarding" = true;
|
|
|
|
networking = {
|
|
|
|
useNetworkd = networkd;
|
2019-09-23 14:37:58 +00:00
|
|
|
useDHCP = false;
|
2023-05-22 03:38:52 +00:00
|
|
|
interfaces.enp1s0.ipv6.addresses = singleton {
|
2017-12-03 04:14:54 +00:00
|
|
|
address = "fd00:1234:5678:1::1";
|
|
|
|
prefixLength = 64;
|
2018-02-01 14:50:35 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
services.radvd = {
|
|
|
|
enable = true;
|
|
|
|
config = ''
|
2023-05-22 03:38:52 +00:00
|
|
|
interface enp1s0 {
|
2018-02-01 14:50:35 +00:00
|
|
|
AdvSendAdvert on;
|
|
|
|
AdvManagedFlag on;
|
|
|
|
AdvOtherConfigFlag on;
|
|
|
|
|
|
|
|
prefix fd00:1234:5678:1::/64 {
|
|
|
|
AdvAutonomous on;
|
|
|
|
AdvOnLink on;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
};
|
2020-03-13 20:47:07 +00:00
|
|
|
nodes.client_with_privacy = { pkgs, ... }: with pkgs.lib; {
|
2023-05-22 03:38:52 +00:00
|
|
|
virtualisation.interfaces.enp1s0.vlan = 1;
|
2018-02-01 14:50:35 +00:00
|
|
|
networking = {
|
|
|
|
useNetworkd = networkd;
|
2019-09-23 14:37:58 +00:00
|
|
|
useDHCP = false;
|
2023-05-22 03:38:52 +00:00
|
|
|
interfaces.enp1s0 = {
|
2020-01-30 10:57:09 +00:00
|
|
|
tempAddress = "default";
|
2017-12-03 04:14:54 +00:00
|
|
|
ipv4.addresses = mkOverride 0 [ ];
|
|
|
|
ipv6.addresses = mkOverride 0 [ ];
|
2019-09-23 14:37:58 +00:00
|
|
|
useDHCP = true;
|
2018-02-01 14:50:35 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
2020-03-13 20:47:07 +00:00
|
|
|
nodes.client = { pkgs, ... }: with pkgs.lib; {
|
2023-05-22 03:38:52 +00:00
|
|
|
virtualisation.interfaces.enp1s0.vlan = 1;
|
2019-07-09 06:06:52 +00:00
|
|
|
networking = {
|
|
|
|
useNetworkd = networkd;
|
2019-09-23 14:37:58 +00:00
|
|
|
useDHCP = false;
|
2023-05-22 03:38:52 +00:00
|
|
|
interfaces.enp1s0 = {
|
2020-01-30 10:57:09 +00:00
|
|
|
tempAddress = "enabled";
|
2019-07-09 06:06:52 +00:00
|
|
|
ipv4.addresses = mkOverride 0 [ ];
|
|
|
|
ipv6.addresses = mkOverride 0 [ ];
|
2019-09-23 14:37:58 +00:00
|
|
|
useDHCP = true;
|
2019-07-09 06:06:52 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
2018-07-20 20:56:59 +00:00
|
|
|
testScript = { ... }:
|
2018-02-01 14:50:35 +00:00
|
|
|
''
|
2019-12-15 21:21:17 +00:00
|
|
|
start_all()
|
|
|
|
|
|
|
|
client.wait_for_unit("network.target")
|
|
|
|
client_with_privacy.wait_for_unit("network.target")
|
|
|
|
router.wait_for_unit("network-online.target")
|
|
|
|
|
|
|
|
with subtest("Wait until we have an ip address"):
|
|
|
|
client_with_privacy.wait_until_succeeds(
|
2023-05-22 03:38:52 +00:00
|
|
|
"ip addr show dev enp1s0 | grep -q 'fd00:1234:5678:1:'"
|
2019-12-15 21:21:17 +00:00
|
|
|
)
|
2023-05-22 03:38:52 +00:00
|
|
|
client.wait_until_succeeds("ip addr show dev enp1s0 | grep -q 'fd00:1234:5678:1:'")
|
2019-12-15 21:21:17 +00:00
|
|
|
|
|
|
|
with subtest("Test vlan 1"):
|
|
|
|
client_with_privacy.wait_until_succeeds("ping -c 1 fd00:1234:5678:1::1")
|
|
|
|
client.wait_until_succeeds("ping -c 1 fd00:1234:5678:1::1")
|
|
|
|
|
|
|
|
with subtest("Test address used is temporary"):
|
|
|
|
client_with_privacy.wait_until_succeeds(
|
|
|
|
"! ip route get fd00:1234:5678:1::1 | grep -q ':[a-f0-9]*ff:fe[a-f0-9]*:'"
|
|
|
|
)
|
|
|
|
|
|
|
|
with subtest("Test address used is EUI-64"):
|
|
|
|
client.wait_until_succeeds(
|
|
|
|
"ip route get fd00:1234:5678:1::1 | grep -q ':[a-f0-9]*ff:fe[a-f0-9]*:'"
|
|
|
|
)
|
2018-02-01 14:50:35 +00:00
|
|
|
'';
|
|
|
|
};
|
2017-07-28 14:45:58 +00:00
|
|
|
routes = {
|
|
|
|
name = "routes";
|
2022-03-20 23:15:30 +00:00
|
|
|
nodes.machine = {
|
2021-11-03 23:19:54 +00:00
|
|
|
networking.useNetworkd = networkd;
|
2017-07-28 14:45:58 +00:00
|
|
|
networking.useDHCP = false;
|
2019-08-13 21:52:01 +00:00
|
|
|
networking.interfaces.eth0 = {
|
2017-12-03 04:13:14 +00:00
|
|
|
ipv4.addresses = [ { address = "192.168.1.2"; prefixLength = 24; } ];
|
|
|
|
ipv6.addresses = [ { address = "2001:1470:fffd:2097::"; prefixLength = 64; } ];
|
|
|
|
ipv6.routes = [
|
2017-07-28 14:45:58 +00:00
|
|
|
{ address = "fdfd:b3f0::"; prefixLength = 48; }
|
|
|
|
{ address = "2001:1470:fffd:2098::"; prefixLength = 64; via = "fdfd:b3f0::1"; }
|
|
|
|
];
|
2017-12-03 04:13:14 +00:00
|
|
|
ipv4.routes = [
|
2021-11-03 23:19:54 +00:00
|
|
|
{ address = "10.0.0.0"; prefixLength = 16; options = {
|
|
|
|
mtu = "1500";
|
|
|
|
# Explicitly set scope because iproute and systemd-networkd
|
|
|
|
# disagree on what the scope should be
|
|
|
|
# if the type is the default "unicast"
|
|
|
|
scope = "link";
|
|
|
|
}; }
|
2017-07-28 14:45:58 +00:00
|
|
|
{ address = "192.168.2.0"; prefixLength = 24; via = "192.168.1.1"; }
|
|
|
|
];
|
|
|
|
};
|
|
|
|
virtualisation.vlans = [ ];
|
|
|
|
};
|
|
|
|
|
|
|
|
testScript = ''
|
2020-04-13 17:16:12 +00:00
|
|
|
targetIPv4Table = [
|
|
|
|
"10.0.0.0/16 proto static scope link mtu 1500",
|
|
|
|
"192.168.1.0/24 proto kernel scope link src 192.168.1.2",
|
|
|
|
"192.168.2.0/24 via 192.168.1.1 proto static",
|
|
|
|
]
|
|
|
|
|
|
|
|
targetIPv6Table = [
|
|
|
|
"2001:1470:fffd:2097::/64 proto kernel metric 256 pref medium",
|
|
|
|
"2001:1470:fffd:2098::/64 via fdfd:b3f0::1 proto static metric 1024 pref medium",
|
|
|
|
"fdfd:b3f0::/48 proto static metric 1024 pref medium",
|
|
|
|
]
|
2019-12-15 21:21:17 +00:00
|
|
|
|
|
|
|
machine.start()
|
|
|
|
machine.wait_for_unit("network.target")
|
|
|
|
|
|
|
|
with subtest("test routing tables"):
|
|
|
|
ipv4Table = machine.succeed("ip -4 route list dev eth0 | head -n3").strip()
|
|
|
|
ipv6Table = machine.succeed("ip -6 route list dev eth0 | head -n3").strip()
|
2020-04-13 17:16:12 +00:00
|
|
|
assert [
|
|
|
|
l.strip() for l in ipv4Table.splitlines()
|
|
|
|
] == targetIPv4Table, """
|
2019-12-15 21:21:17 +00:00
|
|
|
The IPv4 routing table does not match the expected one:
|
|
|
|
Result:
|
|
|
|
{}
|
|
|
|
Expected:
|
|
|
|
{}
|
|
|
|
""".format(
|
|
|
|
ipv4Table, targetIPv4Table
|
|
|
|
)
|
2020-04-13 17:16:12 +00:00
|
|
|
assert [
|
|
|
|
l.strip() for l in ipv6Table.splitlines()
|
|
|
|
] == targetIPv6Table, """
|
2019-12-15 21:21:17 +00:00
|
|
|
The IPv6 routing table does not match the expected one:
|
|
|
|
Result:
|
|
|
|
{}
|
|
|
|
Expected:
|
|
|
|
{}
|
|
|
|
""".format(
|
|
|
|
ipv6Table, targetIPv6Table
|
|
|
|
)
|
|
|
|
|
2021-11-03 23:19:54 +00:00
|
|
|
'' + optionalString (!networkd) ''
|
2019-12-15 21:21:17 +00:00
|
|
|
with subtest("test clean-up of the tables"):
|
|
|
|
machine.succeed("systemctl stop network-addresses-eth0")
|
|
|
|
ipv4Residue = machine.succeed("ip -4 route list dev eth0 | head -n-3").strip()
|
|
|
|
ipv6Residue = machine.succeed("ip -6 route list dev eth0 | head -n-3").strip()
|
|
|
|
assert (
|
2021-05-08 21:36:39 +00:00
|
|
|
ipv4Residue == ""
|
2019-12-15 21:21:17 +00:00
|
|
|
), "The IPv4 routing table has not been properly cleaned:\n{}".format(ipv4Residue)
|
|
|
|
assert (
|
2021-05-08 21:36:39 +00:00
|
|
|
ipv6Residue == ""
|
2019-12-15 21:21:17 +00:00
|
|
|
), "The IPv6 routing table has not been properly cleaned:\n{}".format(ipv6Residue)
|
2017-07-28 14:45:58 +00:00
|
|
|
'';
|
|
|
|
};
|
2023-05-22 03:38:52 +00:00
|
|
|
rename = if networkd then {
|
2021-02-18 17:12:48 +00:00
|
|
|
name = "RenameInterface";
|
2022-03-20 23:15:30 +00:00
|
|
|
nodes.machine = { pkgs, ... }: {
|
2021-02-18 17:12:48 +00:00
|
|
|
virtualisation.vlans = [ 1 ];
|
|
|
|
networking = {
|
|
|
|
useNetworkd = networkd;
|
|
|
|
useDHCP = false;
|
|
|
|
};
|
2023-05-22 03:38:52 +00:00
|
|
|
systemd.network.links."10-custom_name" = {
|
|
|
|
matchConfig.MACAddress = "52:54:00:12:01:01";
|
|
|
|
linkConfig.Name = "custom_name";
|
|
|
|
};
|
|
|
|
};
|
2021-02-18 17:12:48 +00:00
|
|
|
testScript = ''
|
|
|
|
machine.succeed("udevadm settle")
|
|
|
|
print(machine.succeed("ip link show dev custom_name"))
|
|
|
|
'';
|
2023-05-22 03:38:52 +00:00
|
|
|
} else {
|
|
|
|
name = "RenameInterface";
|
2023-01-30 07:02:52 +00:00
|
|
|
nodes = { };
|
2023-05-22 03:38:52 +00:00
|
|
|
testScript = "";
|
|
|
|
};
|
2020-03-10 23:24:50 +00:00
|
|
|
# even with disabled networkd, systemd.network.links should work
|
|
|
|
# (as it's handled by udev, not networkd)
|
|
|
|
link = {
|
|
|
|
name = "Link";
|
|
|
|
nodes.client = { pkgs, ... }: {
|
|
|
|
virtualisation.vlans = [ 1 ];
|
|
|
|
networking = {
|
|
|
|
useNetworkd = networkd;
|
|
|
|
useDHCP = false;
|
|
|
|
};
|
|
|
|
systemd.network.links."50-foo" = {
|
|
|
|
matchConfig = {
|
|
|
|
Name = "foo";
|
|
|
|
Driver = "dummy";
|
|
|
|
};
|
|
|
|
linkConfig.MTUBytes = "1442";
|
|
|
|
};
|
|
|
|
};
|
|
|
|
testScript = ''
|
|
|
|
print(client.succeed("ip l add name foo type dummy"))
|
|
|
|
print(client.succeed("stat /etc/systemd/network/50-foo.link"))
|
|
|
|
client.succeed("udevadm settle")
|
2022-02-24 22:08:00 +00:00
|
|
|
assert "mtu 1442" in client.succeed("ip l show dev foo")
|
2020-03-10 23:24:50 +00:00
|
|
|
'';
|
|
|
|
};
|
2021-09-02 01:46:26 +00:00
|
|
|
wlanInterface = let
|
|
|
|
testMac = "06:00:00:00:02:00";
|
|
|
|
in {
|
|
|
|
name = "WlanInterface";
|
2022-03-20 23:15:30 +00:00
|
|
|
nodes.machine = { pkgs, ... }: {
|
2021-09-02 01:46:26 +00:00
|
|
|
boot.kernelModules = [ "mac80211_hwsim" ];
|
|
|
|
networking.wlanInterfaces = {
|
|
|
|
wlan0 = { device = "wlan0"; };
|
|
|
|
wap0 = { device = "wlan0"; mac = testMac; };
|
|
|
|
};
|
|
|
|
};
|
|
|
|
testScript = ''
|
|
|
|
machine.start()
|
|
|
|
machine.wait_for_unit("network.target")
|
|
|
|
machine.wait_until_succeeds("ip address show wap0 | grep -q ${testMac}")
|
|
|
|
machine.fail("ip address show wlan0 | grep -q ${testMac}")
|
|
|
|
'';
|
|
|
|
};
|
2023-05-27 17:10:44 +00:00
|
|
|
naughtyInterfaceNames = let
|
|
|
|
ifnames = [
|
|
|
|
# flags of ip-address
|
|
|
|
"home" "temporary" "optimistic"
|
|
|
|
"bridge_slave" "flush"
|
|
|
|
# flags of ip-route
|
|
|
|
"up" "type" "nomaster" "address"
|
|
|
|
# other
|
|
|
|
"very_loong_name" "lowerUpper" "-"
|
|
|
|
];
|
|
|
|
in {
|
|
|
|
name = "naughtyInterfaceNames";
|
|
|
|
nodes.machine = { pkgs, ... }: {
|
|
|
|
networking.useNetworkd = networkd;
|
|
|
|
networking.bridges = listToAttrs
|
|
|
|
(flip map ifnames
|
|
|
|
(name: { inherit name; value.interfaces = []; }));
|
|
|
|
};
|
|
|
|
testScript = ''
|
|
|
|
machine.start()
|
|
|
|
machine.wait_for_unit("network.target")
|
|
|
|
for ifname in ${builtins.toJSON ifnames}:
|
|
|
|
machine.wait_until_succeeds(f"ip link show dev '{ifname}' | grep -q '{ifname}'")
|
|
|
|
'';
|
|
|
|
};
|
2023-05-22 03:38:52 +00:00
|
|
|
caseSensitiveRenaming = {
|
|
|
|
name = "CaseSensitiveRenaming";
|
|
|
|
nodes.machine = { pkgs, ... }: {
|
|
|
|
virtualisation.interfaces.enCustom.vlan = 11;
|
|
|
|
networking = {
|
|
|
|
useNetworkd = networkd;
|
|
|
|
useDHCP = false;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
testScript = ''
|
|
|
|
machine.succeed("udevadm settle")
|
|
|
|
print(machine.succeed("ip link show dev enCustom"))
|
|
|
|
machine.wait_until_succeeds("ip link show dev enCustom | grep -q '52:54:00:12:0b:01")
|
|
|
|
'';
|
|
|
|
};
|
2016-02-29 19:06:55 +00:00
|
|
|
};
|
|
|
|
|
2020-03-13 20:47:07 +00:00
|
|
|
in mapAttrs (const (attrs: makeTest (attrs // {
|
2016-02-29 19:06:55 +00:00
|
|
|
name = "${attrs.name}-Networking-${if networkd then "Networkd" else "Scripted"}";
|
|
|
|
}))) testCases
|