2019-11-16 12:13:51 +01:00
|
|
|
# This test predominantly tests systemd-networkd DHCP server, by
|
|
|
|
# setting up a DHCP server and client, and ensuring they are mutually
|
|
|
|
# reachable via the DHCP allocated address.
|
2023-05-17 17:35:40 +02:00
|
|
|
# Two DHCP servers are set up on bridge VLANs, testing to make sure that
|
|
|
|
# bridge VLAN settings are correctly applied.
|
|
|
|
#
|
|
|
|
# br0 ----untagged---v
|
|
|
|
# +---PVID 1+VLAN 2---[bridge]---PVID 2---eth1
|
|
|
|
# vlan2 ---VLAN 2----^
|
2019-11-16 12:13:51 +01:00
|
|
|
import ./make-test-python.nix ({pkgs, ...}: {
|
|
|
|
name = "systemd-networkd-dhcpserver";
|
2021-01-10 20:08:30 +01:00
|
|
|
meta = with pkgs.lib.maintainers; {
|
2023-07-23 04:21:28 +02:00
|
|
|
maintainers = [ ];
|
2019-11-16 12:13:51 +01:00
|
|
|
};
|
|
|
|
nodes = {
|
|
|
|
router = { config, pkgs, ... }: {
|
|
|
|
virtualisation.vlans = [ 1 ];
|
|
|
|
systemd.services.systemd-networkd.environment.SYSTEMD_LOG_LEVEL = "debug";
|
|
|
|
networking = {
|
|
|
|
useNetworkd = true;
|
|
|
|
useDHCP = false;
|
|
|
|
firewall.enable = false;
|
|
|
|
};
|
|
|
|
systemd.network = {
|
2023-05-17 17:35:40 +02:00
|
|
|
netdevs = {
|
|
|
|
br0 = {
|
|
|
|
enable = true;
|
|
|
|
netdevConfig = {
|
|
|
|
Name = "br0";
|
|
|
|
Kind = "bridge";
|
|
|
|
};
|
|
|
|
extraConfig = ''
|
|
|
|
[Bridge]
|
|
|
|
VLANFiltering=yes
|
|
|
|
DefaultPVID=none
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
vlan2 = {
|
|
|
|
enable = true;
|
|
|
|
netdevConfig = {
|
|
|
|
Name = "vlan2";
|
|
|
|
Kind = "vlan";
|
|
|
|
};
|
|
|
|
vlanConfig.Id = 2;
|
|
|
|
};
|
|
|
|
};
|
2019-11-16 12:13:51 +01:00
|
|
|
networks = {
|
|
|
|
# systemd-networkd will load the first network unit file
|
|
|
|
# that matches, ordered lexiographically by filename.
|
|
|
|
# /etc/systemd/network/{40-eth1,99-main}.network already
|
|
|
|
# exists. This network unit must be loaded for the test,
|
|
|
|
# however, hence why this network is named such.
|
|
|
|
"01-eth1" = {
|
|
|
|
name = "eth1";
|
2023-05-17 17:35:40 +02:00
|
|
|
networkConfig.Bridge = "br0";
|
|
|
|
bridgeVLANs = [
|
|
|
|
{ bridgeVLANConfig = { PVID = 2; EgressUntagged = 2; }; }
|
|
|
|
];
|
|
|
|
};
|
|
|
|
"02-br0" = {
|
|
|
|
name = "br0";
|
2019-11-16 12:13:51 +01:00
|
|
|
networkConfig = {
|
|
|
|
DHCPServer = true;
|
|
|
|
Address = "10.0.0.1/24";
|
2023-05-17 17:35:40 +02:00
|
|
|
VLAN = ["vlan2"];
|
|
|
|
};
|
|
|
|
dhcpServerConfig = {
|
|
|
|
PoolOffset = 100;
|
|
|
|
PoolSize = 1;
|
|
|
|
};
|
|
|
|
bridgeVLANs = [
|
|
|
|
{ bridgeVLANConfig = { PVID = 1; EgressUntagged = 1; }; }
|
|
|
|
{ bridgeVLANConfig = { VLAN = 2; }; }
|
|
|
|
];
|
|
|
|
};
|
|
|
|
"02-vlan2" = {
|
|
|
|
name = "vlan2";
|
|
|
|
networkConfig = {
|
|
|
|
DHCPServer = true;
|
|
|
|
Address = "10.0.2.1/24";
|
2019-11-16 12:13:51 +01:00
|
|
|
};
|
|
|
|
dhcpServerConfig = {
|
|
|
|
PoolOffset = 100;
|
|
|
|
PoolSize = 1;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
client = { config, pkgs, ... }: {
|
|
|
|
virtualisation.vlans = [ 1 ];
|
|
|
|
systemd.services.systemd-networkd.environment.SYSTEMD_LOG_LEVEL = "debug";
|
|
|
|
networking = {
|
|
|
|
useNetworkd = true;
|
|
|
|
useDHCP = false;
|
|
|
|
firewall.enable = false;
|
|
|
|
interfaces.eth1.useDHCP = true;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
testScript = { ... }: ''
|
|
|
|
start_all()
|
|
|
|
router.wait_for_unit("systemd-networkd-wait-online.service")
|
|
|
|
client.wait_for_unit("systemd-networkd-wait-online.service")
|
2023-05-17 17:35:40 +02:00
|
|
|
client.wait_until_succeeds("ping -c 5 10.0.2.1")
|
|
|
|
router.wait_until_succeeds("ping -c 5 10.0.2.100")
|
2019-11-16 12:13:51 +01:00
|
|
|
'';
|
|
|
|
})
|