1{ lib, ... }:
2{
3 name = "systemd-initrd-bridge";
4 meta.maintainers = [ lib.maintainers.majiir ];
5
6 # Tests bridge interface configuration in systemd-initrd.
7 #
8 # The 'a' and 'b' nodes are connected to a 'bridge' node through different
9 # links. The 'bridge' node configures a bridge across them. It waits forever
10 # in initrd (stage 1) with networking enabled. 'a' and 'b' ping 'bridge' to
11 # test connectivity with the bridge interface. Then, 'a' pings 'b' to test
12 # the bridge itself.
13
14 nodes = {
15 bridge =
16 { config, lib, ... }:
17 {
18 boot.initrd.systemd.enable = true;
19 boot.initrd.network.enable = true;
20 boot.initrd.systemd.services.boot-blocker = {
21 before = [ "initrd.target" ];
22 wantedBy = [ "initrd.target" ];
23 script = "sleep infinity";
24 serviceConfig.Type = "oneshot";
25 };
26
27 networking.primaryIPAddress = lib.mkForce "192.168.1.${toString config.virtualisation.test.nodeNumber}";
28
29 virtualisation.interfaces.eth1 = {
30 vlan = 1;
31 assignIP = false;
32 };
33 virtualisation.interfaces.eth2 = {
34 vlan = 2;
35 assignIP = false;
36 };
37
38 networking.bridges.br0.interfaces = [
39 "eth1"
40 "eth2"
41 ];
42
43 networking.interfaces = {
44 br0.ipv4.addresses = [
45 {
46 address = config.networking.primaryIPAddress;
47 prefixLength = 24;
48 }
49 ];
50 };
51 };
52
53 a = {
54 virtualisation.vlans = [ 1 ];
55 };
56
57 b =
58 { config, ... }:
59 {
60 virtualisation.vlans = [ 2 ];
61 networking.primaryIPAddress = lib.mkForce "192.168.1.${toString config.virtualisation.test.nodeNumber}";
62 networking.interfaces.eth1.ipv4.addresses = lib.mkForce [
63 {
64 address = config.networking.primaryIPAddress;
65 prefixLength = 24;
66 }
67 ];
68 };
69 };
70
71 testScript = ''
72 start_all()
73 a.wait_for_unit("network.target")
74 b.wait_for_unit("network.target")
75
76 a.succeed("ping -n -w 10 -c 1 bridge >&2")
77 b.succeed("ping -n -w 10 -c 1 bridge >&2")
78
79 a.succeed("ping -n -w 10 -c 1 b >&2")
80 '';
81}