2021-02-13 12:13:41 +00:00
|
|
|
# Support for GRETap interfaces in NixOS' scripted networking.
|
|
|
|
#
|
|
|
|
# We currently only use it in the edge01.waw test framework to bring vlans
|
|
|
|
# across test VMs.
|
|
|
|
|
|
|
|
{ config, pkgs, lib, ... }:
|
|
|
|
|
|
|
|
with lib;
|
|
|
|
|
|
|
|
let
|
|
|
|
cfg = config.hscloud.gretap;
|
|
|
|
|
|
|
|
in {
|
|
|
|
options.hscloud.gretap = {
|
|
|
|
interfaces = mkOption {
|
|
|
|
type = with types; attrsOf (submodule {
|
|
|
|
options = {
|
|
|
|
localV4 = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
description = "Local outer IPv4 address";
|
|
|
|
};
|
|
|
|
remoteV4 = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
description = "Remote outer IPv4 address";
|
|
|
|
};
|
|
|
|
id = mkOption {
|
|
|
|
type = types.int;
|
|
|
|
description = "Tunnel ID";
|
|
|
|
};
|
|
|
|
parent = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
description = "Parent/outer device";
|
|
|
|
};
|
|
|
|
};
|
|
|
|
});
|
|
|
|
description = ''
|
|
|
|
GRETap interfaces to create.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
config.boot.kernelModules = [ "fou" ];
|
|
|
|
config.systemd.services = mapAttrs' (name: value: nameValuePair "${name}-gretap" {
|
2022-06-12 10:26:02 +00:00
|
|
|
wants = if config.networking.useNetworkd then [
|
|
|
|
"systemd-networkd.service"
|
|
|
|
] else [
|
2021-02-13 12:13:41 +00:00
|
|
|
"${name}-netdev.service"
|
|
|
|
"network-addresses-${value.parent}.service"
|
|
|
|
];
|
2022-06-12 10:26:02 +00:00
|
|
|
after = if config.networking.useNetworkd then [
|
|
|
|
"systemd-networkd.service"
|
|
|
|
] else [
|
2021-02-13 12:13:41 +00:00
|
|
|
"network-addresses-${value.parent}.service"
|
|
|
|
];
|
2022-06-12 10:26:02 +00:00
|
|
|
before = if config.networking.useNetworkd then [] else [
|
2021-02-13 12:13:41 +00:00
|
|
|
"network-addresses-${name}.service"
|
|
|
|
];
|
2022-06-12 10:26:02 +00:00
|
|
|
wantedBy = if config.networking.useNetworkd then [
|
|
|
|
"network-online.target"
|
|
|
|
] else [
|
2021-02-13 12:13:41 +00:00
|
|
|
"network-addresses-${name}.service"
|
|
|
|
];
|
|
|
|
serviceConfig = {
|
|
|
|
Type = "oneshot";
|
2022-06-12 10:26:02 +00:00
|
|
|
ExecStart = "${pkgs.iproute2}/bin/ip link add name ${name} type gretap remote ${value.remoteV4} local ${value.localV4} key ${toString value.id}";
|
2021-02-13 12:13:41 +00:00
|
|
|
};
|
|
|
|
}) cfg.interfaces;
|
|
|
|
}
|