blob: 5ce04f3987582cecc5a03c25a78c40f2a66bf072 [file] [log] [blame]
Serge Bazanski6abe4fa2020-10-03 00:18:34 +02001# A small Ethernet-over-IP service implementation.
2# Yes, that's the Mikrotik EoIP implementation. This one is somewhat sketchy
3# (notably, it pumps huge zero-padded frames into tap), so doesn't use it for
4# production. We currently only use it in the edge01.waw test framework to
5# bring vlans across test VMs.
6
7{ config, pkgs, lib, ... }:
8
9with lib;
10
11let
12 eoip = pkgs.stdenv.mkDerivation {
13 pname = "eoip";
14 version = "20180119";
15 nativeBuildInputs = with pkgs; [ cmake ];
16 src = pkgs.fetchFromGitHub {
17 owner = "amphineko";
18 repo = "eoiptapd";
19 rev = "5573a905bcbc001b503308665f098e82f451dc33";
20 sha256 = "0np9dzcw5w6jarzdv2yh3mbzz0wgw10sjqyi6pxan4ipr75v1b8s";
21 };
22 installPhase = ''
23 mkdir -p $out/bin
24 cp eoiptapd $out/bin/eoiptapd
25 '';
26 };
27
28 cfg = config.hscloud.eoip;
29
30in {
31 options.hscloud.eoip = {
32 interfaces = mkOption {
33 type = with types; attrsOf (submodule {
34 options = {
35 localV4 = mkOption {
36 type = types.str;
37 description = "Local outer IPv4 address";
38 };
39 remoteV4 = mkOption {
40 type = types.str;
41 description = "Remote outer IPv4 address";
42 };
43 id = mkOption {
44 type = types.int;
45 description = "Tunnel ID";
46 };
47 parent = mkOption {
48 type = types.str;
49 description = "Parent/outer device";
50 };
51 };
52 });
53 description = ''
54 EoIP interfaces to create.
55 '';
56 };
57 };
58
59 config.systemd.services = mapAttrs' (name: value: nameValuePair "${name}-eoip" {
60 wantedBy = [ "network.target" ];
61 wants = [
62 "${name}-netdev.service"
63 "network-addresses-${value.parent}.service"
64 ];
65 after = [
66 "network-addresses-${value.parent}.service"
67 ];
68 serviceConfig = {
69 Type = "simple";
70 ExecStart = "${eoip}/bin/eoiptapd -i ${name} -l ${value.localV4} -r ${value.remoteV4} -t ${toString value.id}";
71 Restart = "always";
72 RestartSec = "1";
73 };
74 }) cfg.interfaces;
75}