modules/wowlan: move options to "ipv4" attrset for future protocol expansion

This commit is contained in:
2023-09-28 20:09:04 +00:00
parent 60e5f6b41b
commit 9205e076c5
2 changed files with 7 additions and 9 deletions

View File

@@ -25,8 +25,8 @@
sane.services.wg-home.ip = config.sane.hosts.by-name."moby".wg-home.ip;
sane.wowlan.enable = true;
sane.wowlan.patterns = [
{ destPort = 22; } # wake on SSH
{ srcPort = 2587; } # wake on `ntfy-sh` push from servo
{ ipv4.destPort = 22; } # wake on SSH
{ ipv4.srcPort = 2587; } # wake on `ntfy-sh` push from servo
];
# XXX colin: phosh doesn't work well with passwordless login,

View File

@@ -25,7 +25,7 @@ let
cfg = config.sane.wowlan;
patternOpts = with lib; types.submodule {
options = {
destPort = mkOption {
ipv4.destPort = mkOption {
type = types.nullOr types.port;
default = null;
description = ''
@@ -34,7 +34,7 @@ let
(e.g. this machine made a long-running HTTP request, and the other side finally has data for us).
'';
};
srcPort = mkOption {
ipv4.srcPort = mkOption {
type = types.nullOr types.port;
default = null;
description = ''
@@ -59,12 +59,10 @@ let
"0" + (lib.toHexString b)
else
lib.toHexString b;
# formatPattern: patternOpts -> String
# formatIpv4Pattern: patternOpts.ipv4 -> String
# produces a string like this (example matches source port=0x0a1b):
# "-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:0a:1b:-:-"
#
# N.B.: the produced patterns match ONLY IPv4 -- not IPv6!
formatPattern = pat: let
formatIpv4Pattern = pat: let
destPortBytes = if pat.destPort != null then {
high = pat.destPort / 256;
low = lib.mod pat.destPort 256;
@@ -139,7 +137,7 @@ in
path = [ pkgs.iw pkgs.wirelesstools ];
script = let
writePattern = pat: ''
iwpriv wlan0 wow_set_pattern pattern=${formatPattern pat}
iwpriv wlan0 wow_set_pattern pattern=${formatIpv4Pattern pat.ipv4}
'';
writePatterns = lib.concatStringsSep
"\n"