1{ lib, ... }:
2{
3 name = "systemd-initrd-vlan";
4 meta.maintainers = [ lib.maintainers.majiir ];
5
6 # Tests VLAN interface configuration in systemd-initrd.
7 #
8 # Two nodes are configured for a tagged VLAN. (Note that they also still have
9 # their ordinary eth0 and eth1 interfaces, which are not VLAN-tagged.)
10 #
11 # The 'server' node waits forever in initrd (stage 1) with networking
12 # enabled. The 'client' node pings it to test network connectivity.
13
14 nodes =
15 let
16 network = id: {
17 networking = {
18 vlans."eth1.10" = {
19 id = 10;
20 interface = "eth1";
21 };
22 interfaces."eth1.10" = {
23 ipv4.addresses = [
24 {
25 address = "192.168.10.${id}";
26 prefixLength = 24;
27 }
28 ];
29 };
30 };
31 };
32 in
33 {
34 # Node that will use initrd networking.
35 server = network "1" // {
36 boot.initrd.systemd.enable = true;
37 boot.initrd.network.enable = true;
38 boot.initrd.systemd.services.boot-blocker = {
39 before = [ "initrd.target" ];
40 wantedBy = [ "initrd.target" ];
41 script = "sleep infinity";
42 serviceConfig.Type = "oneshot";
43 };
44 };
45
46 # Node that will ping the server.
47 client = network "2";
48 };
49
50 testScript = ''
51 start_all()
52 client.wait_for_unit("network.target")
53
54 # Wait for the regular (untagged) interface to be up.
55 def server_is_up(_) -> bool:
56 status, _ = client.execute("ping -n -c 1 server >&2")
57 return status == 0
58 with client.nested("waiting for server to come up"):
59 retry(server_is_up)
60
61 # Try to ping the (tagged) VLAN interface.
62 client.succeed("ping -n -w 10 -c 1 192.168.10.1 >&2")
63 '';
64}