From 41e0950db253bed0bdf6fb9e2f9cc72c355c0e36 Mon Sep 17 00:00:00 2001 From: Gregor Kleen Date: Sat, 23 Oct 2021 16:11:35 +0200 Subject: yggdrasil-wg: no udp2raw --- modules/yggdrasil-wg/default.nix | 45 ++++------------------------------------ 1 file changed, 4 insertions(+), 41 deletions(-) (limited to 'modules/yggdrasil-wg/default.nix') diff --git a/modules/yggdrasil-wg/default.nix b/modules/yggdrasil-wg/default.nix index 5a20c76f..49acb76e 100644 --- a/modules/yggdrasil-wg/default.nix +++ b/modules/yggdrasil-wg/default.nix @@ -4,7 +4,6 @@ with lib; let listenPort = 51820; - udp2rawPort = 51821; wgSubnet = "2a03:4000:52:ada:1"; wgSubnetLength = 80; wgHostLength = wgSubnetLength + 16; @@ -16,13 +15,11 @@ let { from = "vidhar"; to = "surtr"; endpointHost = "202.61.241.61"; - udp2raw = true; PersistentKeepalive = 25; } { from = "sif"; to = "surtr"; endpointHost = "202.61.241.61"; - # udp2raw = true; PersistentKeepalive = 25; } { from = "sif"; @@ -67,7 +64,9 @@ let in { AllowedIPs = wgHostIPs.${other}; PublicKey = trim (readFile (mkPublicKeyPath other)); - } // (optionalAttrs (from == hostName) (filterAttrs (n: _v: !(elem n ["from" "to" "endpointHost" "udp2raw"])) opts // optionalAttrs (opts ? "endpointHost" && from == hostName) (if opts ? "udp2raw" then { Endpoint = "127.0.0.1:${toString (udp2rawPort + opts.udp2raw)}"; } else { Endpoint = "${opts.endpointHost}:${toString listenPort}"; }))); + } // (optionalAttrs (from == hostName) (linkCfgFilterCustom opts // linkMkEndpointCfg opts)); + linkCfgFilterCustom = filterAttrs (n: _v: !(elem n ["from" "to" "endpointHost"])); + linkMkEndpointCfg = opts@{from, ...}: optionalAttrs (opts ? "endpointHost" && from == hostName) { Endpoint = "${opts.endpointHost}:${toString listenPort}"; }; linkToGreDev = opts@{from, to, ...}: let other = if from == hostName then to else from; @@ -104,7 +103,7 @@ let withOpts = listToAttrs (imap0 (ix: x: nameValuePair x.name (x.value // { ${optName} = ix; })) (filter (x: x.value.${optName} or false) (imap0 (ix: nameValuePair (toString ix)) xs))); withoutOpts = listToAttrs (map (nv: nameValuePair nv.name (removeAttrs nv.value [optName])) (filter (x: !(x.value.${optName} or false)) (imap0 (ix: nameValuePair (toString ix)) xs))); in genList (ix: withOpts.${toString ix} or withoutOpts.${toString ix}) (length xs); - mkLinks = optIx "udp2raw"; + mkLinks = id; toHexByte = n: let hex = toHexString n; in if (stringLength hex < 2) then "0${hex}" else hex; @@ -181,38 +180,6 @@ in { } // listToAttrs (imap0 linkToGreNetwork hostLinks); }; - systemd.services = listToAttrs (filter ({ value, ...}: value != null) (map (opts@{to, from, ...}: let other = if from == hostName then to else from; in nameValuePair "yggdrasil-udp2raw@${other}" (if opts ? "endpointHost" && opts ? "udp2raw" then { - path = with pkgs; [iptables]; - wantedBy = [ "network.target" ]; - serviceConfig = { - RuntimeDirectory = ["udp2raw-config-${other}"]; - RuntimeDirectoryMode = "0700"; - ExecStartPre = pkgs.writeShellScript "udp2raw-mkconfig-${other}.sh" '' - umask 0077 - secret=$(cat ${config.sops.secrets."yggdrasil-udp2raw-secret".path}) - cat >''${RUNTIME_DIRECTORY}/udp2raw.conf <