nixos: add dump option to child uplinks

This commit is contained in:
Ehmry - 2021-03-15 16:07:05 +01:00
parent a91dda99d8
commit 4e8c8f8e73
2 changed files with 51 additions and 61 deletions

View File

@ -3,59 +3,10 @@
with lib;
{
options = {
networking.interfaces = lib.mkOption {
type = with types;
attrsOf (submodule ({ ... }: {
options.genode = {
driver = mkOption { type = types.enum [ "ipxe" "virtio" ]; };
stack = mkOption {
type = with types; nullOr (enum [ "lwip" "lxip" ]);
default = "lwip";
};
};
}));
};
};
config =
# TODO: create drivers in both the first and second level inits
{
assertions = with builtins;
let
addrCheck = name: interface: {
assertion = lessThan (length interface.ipv4.addresses) 2;
message = "Genode interfaces do not support multihoming.";
};
routeCheck = name: interface: {
assertion = lessThan (length interface.ipv4.routes) 2;
message = "Genode interfaces do not support multiple routes.";
};
policyCheck = name: interface:
let
clientList = filter (x: x != null) (lib.mapAttrsToList
(childName: value:
if any (nic: nic == name) value.routeToNics then
childName
else
null) config.genode.core.children);
in {
assertion = clientList == [ ] || length clientList == 1;
message = "Multiple routes to Nic ${name}, ${clientList}";
};
in lib.lists.concatMap
(f: lib.mapAttrsToList f config.networking.interfaces) [
addrCheck
routeCheck
policyCheck
];
hardware.genode.platform.policies = let
mkPolicy = { name, platformPolicy }:
pkgs.writeText "${name}.policy.dhall" ''${platformPolicy} "${name}"'';
@ -64,7 +15,7 @@ with lib;
(child: childAttrs:
lib.attrsets.mapAttrsToList (uplink: uplinkAttrs:
mkPolicy {
name = "${child}-${uplink}.driver";
name = "${child}-${uplink}-driver";
inherit (uplinkAttrs) platformPolicy;
}) childAttrs.uplinks) config.genode.core.children);
@ -72,13 +23,13 @@ with lib;
genode.core.supportChildren = let
mkUplinkDriver = { policyPrefix, driver, verbose }: {
mkUplinkDriver = { name, policyPrefix, driver, verbose }: {
package = with pkgs.genodePackages;
{
ipxe = ipxe_nic_drv;
virtio = virtio_nic_drv;
}.${driver};
configFile = pkgs.writeText "driver.dhall" ''
configFile = pkgs.writeText "${name}.dhall" ''
let Genode = env:DHALL_GENODE
let Init = Genode.Init
@ -104,15 +55,53 @@ with lib;
'';
};
otherDrivers = builtins.concatLists (lib.attrsets.mapAttrsToList
(child: childAttrs:
lib.attrsets.mapAttrsToList (uplink: uplinkAttrs: {
name = "${child}-${uplink}.driver";
value = mkUplinkDriver {
policyPrefix = "${child} -> ${uplink}";
inherit (uplinkAttrs) driver verbose;
};
}) childAttrs.uplinks) config.genode.core.children);
mkUplinkDump = { name, childName, policyPrefix }: {
package = pkgs.genodePackages.nic_dump;
configFile = pkgs.writeText "${name}.dhall" ''
let Genode = env:DHALL_GENODE
let Init = Genode.Init
in λ(binary : Text)
Init.Child.flat
Init.Child.Attributes::{
, binary
, resources = Init.Resources::{ caps = 128, ram = Genode.units.MiB 6 }
, config = Init.Config::{
, attributes = toMap { downlink = "${childName}", uplink = "driver" }
, policies =
[ Init.Config.Policy::{
, service = "Nic"
, label = Init.LabelSelector.prefix "${policyPrefix}"
}
]
}
}
'';
};
otherDrivers = lib.lists.flatten (lib.attrsets.mapAttrsToList
(childName:
{ uplinks, ... }:
lib.attrsets.mapAttrsToList (uplink:
let
childLabel = "${childName} -> ${uplink}";
driverName = "${childName}-${uplink}-driver";
dumpName = "${childName}-${uplink}-dump";
in { driver, dump, verbose, ... }:
[(rec {
name = driverName;
value = mkUplinkDriver {
inherit name driver verbose;
policyPrefix = if dump then dumpName else childLabel;
};
})] ++ lib.lists.optional dump (rec {
name = dumpName;
value = mkUplinkDump {
inherit name childName;
policyPrefix = childLabel;
};
})) uplinks) config.genode.core.children);
in builtins.listToAttrs otherDrivers;
};

View File

@ -7,6 +7,7 @@ mkOption {
attrsOf (submodule {
options = {
driver = mkOption { type = types.enum [ "ipxe" "virtio" ]; };
dump = mkEnableOption "packet logging";
platformPolicy = mkOption {
type = types.path;
default = builtins.toFile "driver.policy.dhall" ''