···
9
+
inherit (lib.modules) mkIf mkMerge;
10
+
inherit (lib.options) mkOption mkPackageOption mkEnableOption;
11
+
inherit (lib.lists) optional optionals;
12
+
inherit (lib.strings)
16
+
inherit (lib) types;
17
+
cfg = config.services.vwifi;
27
+
The ${name} port. Set to null if we should leave it unset.
29
+
type = with types; nullOr port;
34
+
package = mkPackageOption pkgs "vwifi" { };
36
+
enable = mkEnableOption "mac80211_hwsim module";
37
+
numRadios = mkOption {
38
+
description = "The number of virtual radio interfaces to create.";
42
+
macPrefix = mkOption {
44
+
The prefix for MAC addresses to use, without the trailing ':'.
45
+
If one radio is created, you can specify the whole MAC address here.
46
+
The default is defined in vwifi/src/config.h.
48
+
type = types.strMatching "^(([0-9A-Fa-f]{2}:){0,5}[0-9A-Fa-f]{2})$";
49
+
default = "74:F8:F6";
53
+
enable = mkEnableOption "vwifi client";
54
+
spy = mkEnableOption "spy mode, useful for wireless monitors";
55
+
serverAddress = mkOption {
57
+
The address of the server. If set to null, will try to use the vsock protocol.
58
+
Note that this assumes that the server is spawned on the host and passed through to
59
+
QEMU, with something like:
61
+
-device vhost-vsock-pci,id=vwifi0,guest-cid=42
63
+
type = with types; nullOr str;
66
+
serverPort = mkOptionalPort "server port";
67
+
extraArgs = mkOption {
69
+
Extra arguments to pass to vwifi-client. You can use this if you want to bring
70
+
the radios up using vwifi-client instead of at boot.
72
+
type = with types; listOf str;
81
+
enable = mkEnableOption "vwifi server";
82
+
vsock.enable = mkEnableOption "vsock kernel module";
84
+
vhost = mkOptionalPort "vhost";
85
+
tcp = mkOptionalPort "TCP server";
86
+
spy = mkOptionalPort "spy interface";
87
+
control = mkOptionalPort "control interface";
89
+
openFirewall = mkEnableOption "opening the firewall for the TCP and spy ports";
90
+
extraArgs = mkOption {
92
+
Extra arguments to pass to vwifi-server. You can use this for things including
93
+
changing the ports or inducing packet loss.
95
+
type = with types; listOf str;
97
+
example = [ "--lost-packets" ];
104
+
(mkIf cfg.module.enable {
105
+
boot.kernelModules = [
108
+
boot.extraModprobeConfig = ''
109
+
# We'll add more radios using vwifi-add-interfaces in the systemd unit.
110
+
options mac80211_hwsim radios=0
112
+
systemd.services.vwifi-add-interfaces = mkIf (cfg.module.numRadios > 0) {
113
+
description = "vwifi interface bringup";
114
+
wantedBy = [ "network-pre.target" ];
120
+
(toString cfg.module.numRadios)
121
+
cfg.module.macPrefix
124
+
"${cfg.package}/bin/vwifi-add-interfaces ${escapeShellArgs args}";
129
+
assertion = !(hasSuffix ":" cfg.module.macPrefix);
131
+
services.vwifi.module.macPrefix should not have a trailing ":".
136
+
(mkIf cfg.client.enable {
137
+
systemd.services.vwifi-client =
140
+
optional cfg.client.spy "--spy"
141
+
++ optional (cfg.client.serverAddress != null) cfg.client.serverAddress
142
+
++ optionals (cfg.client.serverPort != null) [
144
+
cfg.client.serverPort
146
+
++ cfg.client.extraArgs;
149
+
description = "vwifi client";
150
+
wantedBy = [ "multi-user.target" ];
151
+
after = [ "network.target" ];
154
+
ExecStart = "${cfg.package}/bin/vwifi-client ${escapeShellArgs clientArgs}";
158
+
(mkIf cfg.server.enable {
159
+
boot.kernelModules = mkIf cfg.server.vsock.enable [
162
+
networking.firewall.allowedTCPPorts = mkIf cfg.server.openFirewall (
163
+
optional (cfg.server.ports.tcp != null) cfg.server.ports.tcp
164
+
++ optional (cfg.server.ports.spy != null) cfg.server.ports.spy
166
+
systemd.services.vwifi-server =
169
+
optionals (cfg.server.ports.vhost != null) [
171
+
(toString cfg.server.ports.vhost)
173
+
++ optionals (cfg.server.ports.tcp != null) [
175
+
(toString cfg.server.ports.tcp)
177
+
++ optionals (cfg.server.ports.spy != null) [
179
+
(toString cfg.server.ports.spy)
181
+
++ optionals (cfg.server.ports.control != null) [
183
+
(toString cfg.server.ports.control)
185
+
++ cfg.server.extraArgs;
188
+
description = "vwifi server";
189
+
wantedBy = [ "multi-user.target" ];
190
+
after = [ "network.target" ];
193
+
ExecStart = "${cfg.package}/bin/vwifi-server ${escapeShellArgs serverArgs}";
199
+
meta.maintainers = with lib.maintainers; [ numinit ];