0
0
Fork 0
mirror of https://github.com/NixOS/nixpkgs.git synced 2025-07-19 16:40:32 +03:00
nixpkgs/nixos/modules/services/networking/babeld.nix

165 lines
4.2 KiB
Nix
Raw Normal View History

{
config,
lib,
pkgs,
...
}:
2017-01-17 13:45:43 +00:00
let
cfg = config.services.babeld;
conditionalBoolToString =
value: if (lib.isBool value) then (lib.boolToString value) else (toString value);
paramsString =
params:
lib.concatMapStringsSep " " (name: "${name} ${conditionalBoolToString (lib.getAttr name params)}") (
lib.attrNames params
);
2017-01-17 13:45:43 +00:00
interfaceConfig =
name:
2017-01-17 13:45:43 +00:00
let
interface = lib.getAttr name cfg.interfaces;
2017-01-17 13:45:43 +00:00
in
"interface ${name} ${paramsString interface}\n";
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
{
meta.maintainers = with lib.maintainers; [ hexa ];
2017-01-17 13:45:43 +00:00
###### interface
options = {
services.babeld = {
enable = lib.mkEnableOption "the babeld network routing daemon";
2017-01-17 13:45:43 +00:00
interfaceDefaults = lib.mkOption {
2017-01-17 13:45:43 +00:00
default = null;
description = ''
2017-01-17 13:45:43 +00:00
A set describing default parameters for babeld interfaces.
See {manpage}`babeld(8)` for options.
2017-01-17 13:45:43 +00:00
'';
type = lib.types.nullOr (lib.types.attrsOf lib.types.unspecified);
example = {
type = "tunnel";
split-horizon = true;
};
2017-01-17 13:45:43 +00:00
};
interfaces = lib.mkOption {
default = { };
description = ''
2017-01-17 13:45:43 +00:00
A set describing babeld interfaces.
See {manpage}`babeld(8)` for options.
2017-01-17 13:45:43 +00:00
'';
type = lib.types.attrsOf (lib.types.attrsOf lib.types.unspecified);
example = {
enp0s2 = {
type = "wired";
hello-interval = 5;
split-horizon = "auto";
2017-01-17 13:45:43 +00:00
};
};
2017-01-17 13:45:43 +00:00
};
extraConfig = lib.mkOption {
2017-01-17 13:45:43 +00:00
default = "";
type = lib.types.lines;
description = ''
2017-01-17 13:45:43 +00:00
Options that will be copied to babeld.conf.
See {manpage}`babeld(8)` for details.
2017-01-17 13:45:43 +00:00
'';
};
};
};
###### implementation
config = lib.mkIf config.services.babeld.enable {
2017-01-17 13:45:43 +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" ];
serviceConfig = {
ExecStart = "${pkgs.babeld}/bin/babeld -c ${configFile} -I /run/babeld/babeld.pid -S /var/lib/babeld/state";
AmbientCapabilities = [ "CAP_NET_ADMIN" ];
CapabilityBoundingSet = [ "CAP_NET_ADMIN" ];
2021-06-20 13:52:03 +02:00
DevicePolicy = "closed";
DynamicUser = true;
IPAddressAllow = [
"fe80::/64"
"ff00::/8"
"::1/128"
"127.0.0.0/8"
];
IPAddressDeny = "any";
LockPersonality = true;
NoNewPrivileges = true;
MemoryDenyWriteExecute = true;
ProtectSystem = "strict";
ProtectClock = true;
ProtectKernelTunables = true;
ProtectKernelModules = true;
ProtectKernelLogs = true;
ProtectControlGroups = true;
RestrictAddressFamilies = [
"AF_NETLINK"
"AF_INET6"
"AF_INET"
];
RestrictNamespaces = true;
RestrictRealtime = true;
RestrictSUIDSGID = true;
RemoveIPC = true;
ProtectHome = true;
ProtectHostname = true;
2021-06-20 13:52:03 +02:00
ProtectProc = "invisible";
PrivateMounts = true;
PrivateTmp = true;
PrivateDevices = true;
PrivateUsers = false; # kernel_route(ADD): Operation not permitted
2021-06-20 13:52:03 +02:00
ProcSubset = "pid";
SystemCallArchitectures = "native";
2021-06-20 13:52:03 +02:00
SystemCallFilter = [
"@system-service"
"~@privileged @resources"
];
UMask = "0177";
RuntimeDirectory = "babeld";
StateDirectory = "babeld";
};
2017-01-17 13:45:43 +00:00
};
};
}