guix-patches
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[bug#63402] [PATCH v3 3/3] services: wireguard: Workaround keep-alives b


From: Maxim Cournoyer
Subject: [bug#63402] [PATCH v3 3/3] services: wireguard: Workaround keep-alives bug.
Date: Tue, 16 May 2023 00:09:08 -0400

* gnu/services/vpn.scm (wireguard-configuration-file): Add the
'persistent-keepalive' option to the PostUp script to workaround a bug.
---
 gnu/services/vpn.scm | 24 +++++++++++++++---------
 1 file changed, 15 insertions(+), 9 deletions(-)

diff --git a/gnu/services/vpn.scm b/gnu/services/vpn.scm
index 3f66db79de..587bfcfc0e 100644
--- a/gnu/services/vpn.scm
+++ b/gnu/services/vpn.scm
@@ -774,18 +774,19 @@ (define (wireguard-configuration-file config)
                     (format #f "~@[PersistentKeepalive = ~a~]" keep-alive))))
         (string-join (remove string-null? lines) "\n"))))
 
-  (define (peers->preshared-keys peer keys)
-    (let ((public-key (wireguard-peer-public-key peer))
-          (preshared-key (wireguard-peer-preshared-key peer)))
-      (if preshared-key
-          (cons* public-key preshared-key keys)
-          keys)))
+  (define (peers->preshared-keys+keep-alive peer data)
+    (match-record peer <wireguard-peer>
+      (public-key preshared-key keep-alive)
+      (if (or preshared-key keep-alive)
+          (cons* public-key preshared-key keep-alive data)
+          data)))
 
   (match-record config <wireguard-configuration>
     (wireguard interface addresses port private-key peers dns
                pre-up post-up pre-down post-down table)
     (let* ((config-file (string-append interface ".conf"))
-           (peer-keys (fold peers->preshared-keys (list) peers))
+           (peer-keys+keep-alive (fold peers->preshared-keys+keep-alive
+                                       '() peers))
            (peers (map peer->config peers))
            (config
             (computed-file
@@ -805,9 +806,14 @@ (define (wireguard-configuration-file config)
                     #$@(if (null? pre-up)
                            '()
                            (list (format #f "~{PreUp = ~a~%~}" pre-up)))
+                    ;; Duplicate the persistent-keepalive setting here, to
+                    ;; workaround a bug in WireGuard where keep-alives are not
+                    ;; sent when an interface is initially brought up without
+                    ;; a private key.
                     (format #f "PostUp = ~a set %i private-key ~a\
-~{ peer ~a preshared-key ~a~}" #$(file-append wireguard "/bin/wg")
-#$private-key '#$peer-keys)
+~{ peer ~a~@[ preshared-key ~a~]~@[ persistent-keepalive ~a~]~}"
+                            #$(file-append wireguard "/bin/wg")
+                            #$private-key '#$peer-keys+keep-alive)
                     #$@(if (null? post-up)
                            '()
                            (list (format #f "~{PostUp = ~a~%~}" post-up)))
-- 
2.39.2






reply via email to

[Prev in Thread] Current Thread [Next in Thread]