2024-12-10 20:29:24 +01:00
|
|
|
{
|
|
|
|
config,
|
|
|
|
lib,
|
|
|
|
pkgs,
|
|
|
|
...
|
|
|
|
}:
|
2017-01-17 13:45:43 +00:00
|
|
|
let
|
|
|
|
|
|
|
|
cfg = config.services.babeld;
|
|
|
|
|
2024-12-10 20:29:24 +01:00
|
|
|
conditionalBoolToString =
|
|
|
|
value: if (lib.isBool value) then (lib.boolToString value) else (toString value);
|
2017-11-10 11:46:11 +01:00
|
|
|
|
2024-12-10 20:29:24 +01:00
|
|
|
paramsString =
|
|
|
|
params:
|
|
|
|
lib.concatMapStringsSep " " (name: "${name} ${conditionalBoolToString (lib.getAttr name params)}") (
|
|
|
|
lib.attrNames params
|
|
|
|
);
|
2017-01-17 13:45:43 +00:00
|
|
|
|
2024-12-10 20:29:24 +01:00
|
|
|
interfaceConfig =
|
|
|
|
name:
|
2017-01-17 13:45:43 +00:00
|
|
|
let
|
2024-08-28 21:19:01 +02:00
|
|
|
interface = lib.getAttr name cfg.interfaces;
|
2017-01-17 13:45:43 +00:00
|
|
|
in
|
|
|
|
"interface ${name} ${paramsString interface}\n";
|
|
|
|
|
2024-12-10 20:29:24 +01:00
|
|
|
configFile =
|
|
|
|
with cfg;
|
|
|
|
pkgs.writeText "babeld.conf" (
|
|
|
|
''
|
|
|
|
skip-kernel-setup true
|
|
|
|
''
|
|
|
|
+ (lib.optionalString (cfg.interfaceDefaults != null) ''
|
|
|
|
default ${paramsString cfg.interfaceDefaults}
|
|
|
|
'')
|
|
|
|
+ (lib.concatMapStrings interfaceConfig (lib.attrNames cfg.interfaces))
|
|
|
|
+ extraConfig
|
|
|
|
);
|
2017-01-17 13:45:43 +00:00
|
|
|
|
|
|
|
in
|
|
|
|
|
|
|
|
{
|
|
|
|
|
2024-08-28 21:19:01 +02:00
|
|
|
meta.maintainers = with lib.maintainers; [ hexa ];
|
2021-04-26 23:40:32 +02:00
|
|
|
|
2017-01-17 13:45:43 +00:00
|
|
|
###### interface
|
|
|
|
|
|
|
|
options = {
|
|
|
|
|
|
|
|
services.babeld = {
|
|
|
|
|
2024-08-28 21:19:01 +02:00
|
|
|
enable = lib.mkEnableOption "the babeld network routing daemon";
|
2017-01-17 13:45:43 +00:00
|
|
|
|
2024-08-28 21:19:01 +02:00
|
|
|
interfaceDefaults = lib.mkOption {
|
2017-01-17 13:45:43 +00:00
|
|
|
default = null;
|
2024-04-13 14:54:15 +02:00
|
|
|
description = ''
|
2017-01-17 13:45:43 +00:00
|
|
|
A set describing default parameters for babeld interfaces.
|
2022-07-28 23:19:15 +02:00
|
|
|
See {manpage}`babeld(8)` for options.
|
2017-01-17 13:45:43 +00:00
|
|
|
'';
|
2024-08-28 21:19:01 +02:00
|
|
|
type = lib.types.nullOr (lib.types.attrsOf lib.types.unspecified);
|
2024-12-10 20:29:24 +01:00
|
|
|
example = {
|
|
|
|
type = "tunnel";
|
|
|
|
split-horizon = true;
|
|
|
|
};
|
2017-01-17 13:45:43 +00:00
|
|
|
};
|
|
|
|
|
2024-08-28 21:19:01 +02:00
|
|
|
interfaces = lib.mkOption {
|
2024-12-10 20:29:24 +01:00
|
|
|
default = { };
|
2024-04-13 14:54:15 +02:00
|
|
|
description = ''
|
2017-01-17 13:45:43 +00:00
|
|
|
A set describing babeld interfaces.
|
2022-07-28 23:19:15 +02:00
|
|
|
See {manpage}`babeld(8)` for options.
|
2017-01-17 13:45:43 +00:00
|
|
|
'';
|
2024-08-28 21:19:01 +02:00
|
|
|
type = lib.types.attrsOf (lib.types.attrsOf lib.types.unspecified);
|
2024-12-10 20:29:24 +01:00
|
|
|
example = {
|
|
|
|
enp0s2 = {
|
|
|
|
type = "wired";
|
|
|
|
hello-interval = 5;
|
|
|
|
split-horizon = "auto";
|
2017-01-17 13:45:43 +00:00
|
|
|
};
|
2024-12-10 20:29:24 +01:00
|
|
|
};
|
2017-01-17 13:45:43 +00:00
|
|
|
};
|
|
|
|
|
2024-08-28 21:19:01 +02:00
|
|
|
extraConfig = lib.mkOption {
|
2017-01-17 13:45:43 +00:00
|
|
|
default = "";
|
2024-08-28 21:19:01 +02:00
|
|
|
type = lib.types.lines;
|
2024-04-13 14:54:15 +02:00
|
|
|
description = ''
|
2017-01-17 13:45:43 +00:00
|
|
|
Options that will be copied to babeld.conf.
|
2022-07-28 23:19:15 +02:00
|
|
|
See {manpage}`babeld(8)` for details.
|
2017-01-17 13:45:43 +00:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
###### implementation
|
|
|
|
|
2024-08-28 21:19:01 +02:00
|
|
|
config = lib.mkIf config.services.babeld.enable {
|
2017-01-17 13:45:43 +00:00
|
|
|
|
2024-12-10 20:29:24 +01:00
|
|
|
boot.kernel.sysctl =
|
|
|
|
{
|
|
|
|
"net.ipv6.conf.all.forwarding" = 1;
|
|
|
|
"net.ipv6.conf.all.accept_redirects" = 0;
|
|
|
|
"net.ipv4.conf.all.forwarding" = 1;
|
|
|
|
"net.ipv4.conf.all.rp_filter" = 0;
|
|
|
|
}
|
|
|
|
// lib.mapAttrs' (
|
|
|
|
ifname: _: lib.nameValuePair "net.ipv4.conf.${ifname}.rp_filter" (lib.mkDefault 0)
|
|
|
|
) config.services.babeld.interfaces;
|
2020-11-24 22:41:21 +01:00
|
|
|
|
2017-01-17 13:45:43 +00:00
|
|
|
systemd.services.babeld = {
|
|
|
|
description = "Babel routing daemon";
|
|
|
|
after = [ "network.target" ];
|
|
|
|
wantedBy = [ "multi-user.target" ];
|
2020-09-18 01:53:52 +02:00
|
|
|
serviceConfig = {
|
|
|
|
ExecStart = "${pkgs.babeld}/bin/babeld -c ${configFile} -I /run/babeld/babeld.pid -S /var/lib/babeld/state";
|
2020-11-24 22:41:21 +01:00
|
|
|
AmbientCapabilities = [ "CAP_NET_ADMIN" ];
|
2020-09-18 01:53:52 +02:00
|
|
|
CapabilityBoundingSet = [ "CAP_NET_ADMIN" ];
|
2021-06-20 13:52:03 +02:00
|
|
|
DevicePolicy = "closed";
|
2020-11-24 22:41:21 +01:00
|
|
|
DynamicUser = true;
|
2024-12-10 20:29:24 +01:00
|
|
|
IPAddressAllow = [
|
|
|
|
"fe80::/64"
|
|
|
|
"ff00::/8"
|
|
|
|
"::1/128"
|
|
|
|
"127.0.0.0/8"
|
|
|
|
];
|
2020-09-18 01:53:52 +02:00
|
|
|
IPAddressDeny = "any";
|
|
|
|
LockPersonality = true;
|
|
|
|
NoNewPrivileges = true;
|
|
|
|
MemoryDenyWriteExecute = true;
|
|
|
|
ProtectSystem = "strict";
|
|
|
|
ProtectClock = true;
|
2020-11-24 22:41:21 +01:00
|
|
|
ProtectKernelTunables = true;
|
2020-09-18 01:53:52 +02:00
|
|
|
ProtectKernelModules = true;
|
|
|
|
ProtectKernelLogs = true;
|
|
|
|
ProtectControlGroups = true;
|
2024-12-10 20:29:24 +01:00
|
|
|
RestrictAddressFamilies = [
|
|
|
|
"AF_NETLINK"
|
|
|
|
"AF_INET6"
|
|
|
|
"AF_INET"
|
|
|
|
];
|
2020-09-18 01:53:52 +02:00
|
|
|
RestrictNamespaces = true;
|
|
|
|
RestrictRealtime = true;
|
|
|
|
RestrictSUIDSGID = true;
|
|
|
|
RemoveIPC = true;
|
|
|
|
ProtectHome = true;
|
|
|
|
ProtectHostname = true;
|
2021-06-20 13:52:03 +02:00
|
|
|
ProtectProc = "invisible";
|
2020-09-18 01:53:52 +02:00
|
|
|
PrivateMounts = true;
|
|
|
|
PrivateTmp = true;
|
|
|
|
PrivateDevices = true;
|
|
|
|
PrivateUsers = false; # kernel_route(ADD): Operation not permitted
|
2021-06-20 13:52:03 +02:00
|
|
|
ProcSubset = "pid";
|
2020-09-18 01:53:52 +02:00
|
|
|
SystemCallArchitectures = "native";
|
2021-06-20 13:52:03 +02:00
|
|
|
SystemCallFilter = [
|
|
|
|
"@system-service"
|
|
|
|
"~@privileged @resources"
|
|
|
|
];
|
2020-09-18 01:53:52 +02:00
|
|
|
UMask = "0177";
|
|
|
|
RuntimeDirectory = "babeld";
|
|
|
|
StateDirectory = "babeld";
|
|
|
|
};
|
2017-01-17 13:45:43 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
}
|