vuls: init at 0.27.0
[NixPkgs.git] / nixos / tests / systemd-networkd-dhcpserver.nix
blobfda0c9d641938046a0572b830444d9bfec036ea5
1 # This test predominantly tests systemd-networkd DHCP server, by
2 # setting up a DHCP server and client, and ensuring they are mutually
3 # reachable via the DHCP allocated address.
4 # Two DHCP servers are set up on bridge VLANs, testing to make sure that
5 # bridge VLAN settings are correctly applied.
7 # br0 ----untagged---v
8 #                    +---PVID 1+VLAN 2---[bridge]---PVID 2---eth1
9 # vlan2 ---VLAN 2----^
10 import ./make-test-python.nix ({pkgs, ...}: {
11   name = "systemd-networkd-dhcpserver";
12   meta = with pkgs.lib.maintainers; {
13     maintainers = [ ];
14   };
15   nodes = {
16     router = { config, pkgs, ... }: {
17       virtualisation.vlans = [ 1 ];
18       systemd.services.systemd-networkd.environment.SYSTEMD_LOG_LEVEL = "debug";
19       networking = {
20         useNetworkd = true;
21         useDHCP = false;
22         firewall.enable = false;
23       };
24       systemd.network = {
25         netdevs = {
26           br0 = {
27             enable = true;
28             netdevConfig = {
29               Name = "br0";
30               Kind = "bridge";
31             };
32             extraConfig = ''
33               [Bridge]
34               VLANFiltering=yes
35               DefaultPVID=none
36             '';
37           };
38           vlan2 = {
39             enable = true;
40             netdevConfig = {
41               Name = "vlan2";
42               Kind = "vlan";
43             };
44             vlanConfig.Id = 2;
45           };
46         };
47         networks = {
48           # systemd-networkd will load the first network unit file
49           # that matches, ordered lexiographically by filename.
50           # /etc/systemd/network/{40-eth1,99-main}.network already
51           # exists. This network unit must be loaded for the test,
52           # however, hence why this network is named such.
53           "01-eth1" = {
54             name = "eth1";
55             networkConfig.Bridge = "br0";
56             bridgeVLANs = [
57               { PVID = 2; EgressUntagged = 2; }
58             ];
59           };
60           "02-br0" = {
61             name = "br0";
62             networkConfig = {
63               DHCPServer = true;
64               Address = "10.0.0.1/24";
65               VLAN = ["vlan2"];
66             };
67             dhcpServerConfig = {
68               PoolOffset = 100;
69               PoolSize = 1;
70             };
71             bridgeVLANs = [
72               { PVID = 1; EgressUntagged = 1; }
73               { VLAN = 2; }
74             ];
75           };
76           "02-vlan2" = {
77             name = "vlan2";
78             networkConfig = {
79               DHCPServer = true;
80               Address = "10.0.2.1/24";
81             };
82             dhcpServerConfig = {
83               PoolOffset = 100;
84               PoolSize = 1;
85             };
86           };
87         };
88       };
89     };
91     client = { config, pkgs, ... }: {
92       virtualisation.vlans = [ 1 ];
93       systemd.services.systemd-networkd.environment.SYSTEMD_LOG_LEVEL = "debug";
94       networking = {
95         useNetworkd = true;
96         useDHCP = false;
97         firewall.enable = false;
98         interfaces.eth1.useDHCP = true;
99       };
100     };
101   };
102   testScript = { ... }: ''
103     start_all()
105     router.systemctl("start network-online.target")
106     client.systemctl("start network-online.target")
107     router.wait_for_unit("systemd-networkd-wait-online.service")
108     client.wait_for_unit("systemd-networkd-wait-online.service")
109     client.wait_until_succeeds("ping -c 5 10.0.2.1")
110     router.wait_until_succeeds("ping -c 5 10.0.2.100")
111   '';