Serge Bazanski | cc769a5 | 2021-02-13 13:13:41 +0100 | [diff] [blame] | 1 | # Support for GRETap interfaces in NixOS' scripted networking. |
| 2 | # |
| 3 | # We currently only use it in the edge01.waw test framework to bring vlans |
| 4 | # across test VMs. |
| 5 | |
| 6 | { config, pkgs, lib, ... }: |
| 7 | |
| 8 | with lib; |
| 9 | |
| 10 | let |
| 11 | cfg = config.hscloud.gretap; |
| 12 | |
| 13 | in { |
| 14 | options.hscloud.gretap = { |
| 15 | interfaces = mkOption { |
| 16 | type = with types; attrsOf (submodule { |
| 17 | options = { |
| 18 | localV4 = mkOption { |
| 19 | type = types.str; |
| 20 | description = "Local outer IPv4 address"; |
| 21 | }; |
| 22 | remoteV4 = mkOption { |
| 23 | type = types.str; |
| 24 | description = "Remote outer IPv4 address"; |
| 25 | }; |
| 26 | id = mkOption { |
| 27 | type = types.int; |
| 28 | description = "Tunnel ID"; |
| 29 | }; |
| 30 | parent = mkOption { |
| 31 | type = types.str; |
| 32 | description = "Parent/outer device"; |
| 33 | }; |
| 34 | }; |
| 35 | }); |
| 36 | description = '' |
| 37 | GRETap interfaces to create. |
| 38 | ''; |
| 39 | }; |
| 40 | }; |
| 41 | |
| 42 | config.boot.kernelModules = [ "fou" ]; |
| 43 | config.systemd.services = mapAttrs' (name: value: nameValuePair "${name}-gretap" { |
| 44 | wants = [ |
| 45 | "${name}-netdev.service" |
| 46 | "network-addresses-${value.parent}.service" |
| 47 | ]; |
| 48 | after = [ |
| 49 | "network-addresses-${value.parent}.service" |
| 50 | ]; |
| 51 | before = [ |
| 52 | "network-addresses-${name}.service" |
| 53 | ]; |
| 54 | wantedBy = [ |
| 55 | "network-addresses-${name}.service" |
| 56 | ]; |
| 57 | serviceConfig = { |
| 58 | Type = "oneshot"; |
Serge Bazanski | 225a5c7 | 2021-02-13 13:15:57 +0100 | [diff] [blame] | 59 | ExecStart = "${pkgs.iproute2}/bin/ip link add name ${name} type gretap remote ${value.remoteV4} local ${value.localV4} key ${toString value.id}"; |
Serge Bazanski | cc769a5 | 2021-02-13 13:13:41 +0100 | [diff] [blame] | 60 | }; |
| 61 | }) cfg.interfaces; |
| 62 | } |