nixos: add dump option to child uplinks
This commit is contained in:
parent
a91dda99d8
commit
4e8c8f8e73
|
@ -3,59 +3,10 @@
|
||||||
with lib;
|
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 =
|
config =
|
||||||
# TODO: create drivers in both the first and second level inits
|
# 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
|
hardware.genode.platform.policies = let
|
||||||
mkPolicy = { name, platformPolicy }:
|
mkPolicy = { name, platformPolicy }:
|
||||||
pkgs.writeText "${name}.policy.dhall" ''${platformPolicy} "${name}"'';
|
pkgs.writeText "${name}.policy.dhall" ''${platformPolicy} "${name}"'';
|
||||||
|
@ -64,7 +15,7 @@ with lib;
|
||||||
(child: childAttrs:
|
(child: childAttrs:
|
||||||
lib.attrsets.mapAttrsToList (uplink: uplinkAttrs:
|
lib.attrsets.mapAttrsToList (uplink: uplinkAttrs:
|
||||||
mkPolicy {
|
mkPolicy {
|
||||||
name = "${child}-${uplink}.driver";
|
name = "${child}-${uplink}-driver";
|
||||||
inherit (uplinkAttrs) platformPolicy;
|
inherit (uplinkAttrs) platformPolicy;
|
||||||
}) childAttrs.uplinks) config.genode.core.children);
|
}) childAttrs.uplinks) config.genode.core.children);
|
||||||
|
|
||||||
|
@ -72,13 +23,13 @@ with lib;
|
||||||
|
|
||||||
genode.core.supportChildren = let
|
genode.core.supportChildren = let
|
||||||
|
|
||||||
mkUplinkDriver = { policyPrefix, driver, verbose }: {
|
mkUplinkDriver = { name, policyPrefix, driver, verbose }: {
|
||||||
package = with pkgs.genodePackages;
|
package = with pkgs.genodePackages;
|
||||||
{
|
{
|
||||||
ipxe = ipxe_nic_drv;
|
ipxe = ipxe_nic_drv;
|
||||||
virtio = virtio_nic_drv;
|
virtio = virtio_nic_drv;
|
||||||
}.${driver};
|
}.${driver};
|
||||||
configFile = pkgs.writeText "driver.dhall" ''
|
configFile = pkgs.writeText "${name}.dhall" ''
|
||||||
let Genode = env:DHALL_GENODE
|
let Genode = env:DHALL_GENODE
|
||||||
|
|
||||||
let Init = Genode.Init
|
let Init = Genode.Init
|
||||||
|
@ -104,15 +55,53 @@ with lib;
|
||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
|
|
||||||
otherDrivers = builtins.concatLists (lib.attrsets.mapAttrsToList
|
mkUplinkDump = { name, childName, policyPrefix }: {
|
||||||
(child: childAttrs:
|
package = pkgs.genodePackages.nic_dump;
|
||||||
lib.attrsets.mapAttrsToList (uplink: uplinkAttrs: {
|
configFile = pkgs.writeText "${name}.dhall" ''
|
||||||
name = "${child}-${uplink}.driver";
|
let Genode = env:DHALL_GENODE
|
||||||
value = mkUplinkDriver {
|
|
||||||
policyPrefix = "${child} -> ${uplink}";
|
let Init = Genode.Init
|
||||||
inherit (uplinkAttrs) driver verbose;
|
|
||||||
};
|
in λ(binary : Text) →
|
||||||
}) childAttrs.uplinks) config.genode.core.children);
|
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;
|
in builtins.listToAttrs otherDrivers;
|
||||||
};
|
};
|
||||||
|
|
|
@ -7,6 +7,7 @@ mkOption {
|
||||||
attrsOf (submodule {
|
attrsOf (submodule {
|
||||||
options = {
|
options = {
|
||||||
driver = mkOption { type = types.enum [ "ipxe" "virtio" ]; };
|
driver = mkOption { type = types.enum [ "ipxe" "virtio" ]; };
|
||||||
|
dump = mkEnableOption "packet logging";
|
||||||
platformPolicy = mkOption {
|
platformPolicy = mkOption {
|
||||||
type = types.path;
|
type = types.path;
|
||||||
default = builtins.toFile "driver.policy.dhall" ''
|
default = builtins.toFile "driver.policy.dhall" ''
|
||||||
|
|
Loading…
Reference in New Issue