2017-01-17 13:45:43 +00:00
|
|
|
{ config, lib, pkgs, ... }:
|
|
|
|
|
|
|
|
with lib;
|
|
|
|
|
|
|
|
let
|
|
|
|
|
|
|
|
cfg = config.services.babeld;
|
|
|
|
|
2017-11-10 10:46:11 +00:00
|
|
|
conditionalBoolToString = value: if (isBool value) then (boolToString value) else (toString value);
|
|
|
|
|
2017-01-17 13:45:43 +00:00
|
|
|
paramsString = params:
|
2017-11-10 10:46:11 +00:00
|
|
|
concatMapStringsSep " " (name: "${name} ${conditionalBoolToString (getAttr name params)}")
|
2017-01-17 13:45:43 +00:00
|
|
|
(attrNames params);
|
|
|
|
|
|
|
|
interfaceConfig = name:
|
|
|
|
let
|
|
|
|
interface = getAttr name cfg.interfaces;
|
|
|
|
in
|
|
|
|
"interface ${name} ${paramsString interface}\n";
|
|
|
|
|
|
|
|
configFile = with cfg; pkgs.writeText "babeld.conf" (
|
2020-11-24 21:41:21 +00:00
|
|
|
''
|
|
|
|
skip-kernel-setup true
|
|
|
|
''
|
|
|
|
+ (optionalString (cfg.interfaceDefaults != null) ''
|
2017-01-17 13:45:43 +00:00
|
|
|
default ${paramsString cfg.interfaceDefaults}
|
|
|
|
'')
|
|
|
|
+ (concatMapStrings interfaceConfig (attrNames cfg.interfaces))
|
|
|
|
+ extraConfig);
|
|
|
|
|
|
|
|
in
|
|
|
|
|
|
|
|
{
|
|
|
|
|
2021-04-26 22:40:32 +01:00
|
|
|
meta.maintainers = with maintainers; [ hexa ];
|
|
|
|
|
2017-01-17 13:45:43 +00:00
|
|
|
###### interface
|
|
|
|
|
|
|
|
options = {
|
|
|
|
|
|
|
|
services.babeld = {
|
|
|
|
|
2020-04-20 19:05:26 +01:00
|
|
|
enable = mkEnableOption "the babeld network routing daemon";
|
2017-01-17 13:45:43 +00:00
|
|
|
|
|
|
|
interfaceDefaults = mkOption {
|
|
|
|
default = null;
|
|
|
|
description = ''
|
|
|
|
A set describing default parameters for babeld interfaces.
|
|
|
|
See <citerefentry><refentrytitle>babeld</refentrytitle><manvolnum>8</manvolnum></citerefentry> for options.
|
|
|
|
'';
|
|
|
|
type = types.nullOr (types.attrsOf types.unspecified);
|
|
|
|
example =
|
|
|
|
{
|
2017-11-10 10:47:38 +00:00
|
|
|
type = "tunnel";
|
2019-08-13 22:52:01 +01:00
|
|
|
split-horizon = true;
|
2017-01-17 13:45:43 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
interfaces = mkOption {
|
|
|
|
default = {};
|
|
|
|
description = ''
|
|
|
|
A set describing babeld interfaces.
|
|
|
|
See <citerefentry><refentrytitle>babeld</refentrytitle><manvolnum>8</manvolnum></citerefentry> for options.
|
|
|
|
'';
|
|
|
|
type = types.attrsOf (types.attrsOf types.unspecified);
|
|
|
|
example =
|
|
|
|
{ enp0s2 =
|
2017-11-10 10:47:38 +00:00
|
|
|
{ type = "wired";
|
2019-08-13 22:52:01 +01:00
|
|
|
hello-interval = 5;
|
|
|
|
split-horizon = "auto";
|
2017-01-17 13:45:43 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
extraConfig = mkOption {
|
|
|
|
default = "";
|
2021-01-26 19:31:29 +00:00
|
|
|
type = types.lines;
|
2017-01-17 13:45:43 +00:00
|
|
|
description = ''
|
|
|
|
Options that will be copied to babeld.conf.
|
|
|
|
See <citerefentry><refentrytitle>babeld</refentrytitle><manvolnum>8</manvolnum></citerefentry> for details.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
###### implementation
|
|
|
|
|
|
|
|
config = mkIf config.services.babeld.enable {
|
|
|
|
|
2020-11-24 21:41:21 +00: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;
|
|
|
|
|
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 00:53:52 +01:00
|
|
|
serviceConfig = {
|
|
|
|
ExecStart = "${pkgs.babeld}/bin/babeld -c ${configFile} -I /run/babeld/babeld.pid -S /var/lib/babeld/state";
|
2020-11-24 21:41:21 +00:00
|
|
|
AmbientCapabilities = [ "CAP_NET_ADMIN" ];
|
2020-09-18 00:53:52 +01:00
|
|
|
CapabilityBoundingSet = [ "CAP_NET_ADMIN" ];
|
2020-11-24 21:41:21 +00:00
|
|
|
DynamicUser = true;
|
2020-09-18 00:53:52 +01:00
|
|
|
IPAddressAllow = [ "fe80::/64" "ff00::/8" "::1/128" "127.0.0.0/8" ];
|
|
|
|
IPAddressDeny = "any";
|
|
|
|
LockPersonality = true;
|
|
|
|
NoNewPrivileges = true;
|
|
|
|
MemoryDenyWriteExecute = true;
|
|
|
|
ProtectSystem = "strict";
|
|
|
|
ProtectClock = true;
|
2020-11-24 21:41:21 +00:00
|
|
|
ProtectKernelTunables = true;
|
2020-09-18 00:53:52 +01:00
|
|
|
ProtectKernelModules = true;
|
|
|
|
ProtectKernelLogs = true;
|
|
|
|
ProtectControlGroups = true;
|
2021-04-13 01:41:54 +01:00
|
|
|
RestrictAddressFamilies = [ "AF_NETLINK" "AF_INET6" "AF_INET" ];
|
2020-09-18 00:53:52 +01:00
|
|
|
RestrictNamespaces = true;
|
|
|
|
RestrictRealtime = true;
|
|
|
|
RestrictSUIDSGID = true;
|
|
|
|
RemoveIPC = true;
|
|
|
|
ProtectHome = true;
|
|
|
|
ProtectHostname = true;
|
|
|
|
PrivateMounts = true;
|
|
|
|
PrivateTmp = true;
|
|
|
|
PrivateDevices = true;
|
|
|
|
PrivateUsers = false; # kernel_route(ADD): Operation not permitted
|
|
|
|
SystemCallArchitectures = "native";
|
|
|
|
SystemCallFilter = [ "@system-service" ];
|
|
|
|
UMask = "0177";
|
|
|
|
RuntimeDirectory = "babeld";
|
|
|
|
StateDirectory = "babeld";
|
|
|
|
};
|
2017-01-17 13:45:43 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
}
|