diff --git a/nixos-modules/hardware/nic.nix b/nixos-modules/hardware/nic.nix index fb0097f..fe65522 100644 --- a/nixos-modules/hardware/nic.nix +++ b/nixos-modules/hardware/nic.nix @@ -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; }; diff --git a/nixos-modules/lib/uplinks-option.nix b/nixos-modules/lib/uplinks-option.nix index fc26f6d..24a824f 100644 --- a/nixos-modules/lib/uplinks-option.nix +++ b/nixos-modules/lib/uplinks-option.nix @@ -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" ''