Development discussion of WireGuard
 help / color / mirror / Atom feed
From: David Ventura <davidventura27@gmail.com>
To: wireguard@lists.zx2c4.com
Subject: Wireguard-go behavior on network-interface change
Date: Fri, 3 Sep 2021 18:41:12 +0200	[thread overview]
Message-ID: <CA+UPfZ7bqKdff147=trSRWGGhbCg8VP2WHePWFT8JYZD3YarHg@mail.gmail.com> (raw)

Hi
I am running wireguard-go on linux (as a fallback for no kernel
modules available on some devices, that is being worked on in
parallel) and hitting an unexpected issue:

When a mobile device changes network, the interfaces (or an unknown,
to me, part of the network stack) are temporarily unavailable.
Depending on the timing of these changes, sometimes wireguard-go will
shut down and sometimes it will time-out for up to 15 seconds and
recover:

Recovery-1:
DEBUG: (wg0) 2021/09/03 18:13:35 peer(B3D6…YQVk) - Sending keepalive packet
ERROR: (wg0) 2021/09/03 18:13:35 peer(B3D6…YQVk) - Failed to send data
packet network is unreachable
DEBUG: (wg0) 2021/09/03 18:13:41 peer(B3D6…YQVk) - Received handshake initiation

Recovery-2:
DEBUG: (wg0) 2021/09/03 18:13:57 peer(B3D6…YQVk) - Sending keepalive packet
ERROR: (wg0) 2021/09/03 18:14:11 peer(B3D6…YQVk) - Failed to send data
packet network is unreachable
ERROR: (wg0) 2021/09/03 18:14:12 peer(B3D6…YQVk) - Failed to send data
packet network is unreachable
ERROR: (wg0) 2021/09/03 18:14:13 peer(B3D6…YQVk) - Failed to send data
packet network is unreachable
ERROR: (wg0) 2021/09/03 18:14:14 peer(B3D6…YQVk) - Failed to send data
packet network is unreachable
ERROR: (wg0) 2021/09/03 18:14:15 peer(B3D6…YQVk) - Failed to send data
packet network is unreachable
ERROR: (wg0) 2021/09/03 18:14:16 peer(B3D6…YQVk) - Failed to send data
packet network is unreachable
ERROR: (wg0) 2021/09/03 18:14:17 peer(B3D6…YQVk) - Failed to send data
packet network is unreachable
ERROR: (wg0) 2021/09/03 18:14:18 peer(B3D6…YQVk) - Failed to send data
packet network is unreachable
DEBUG: (wg0) 2021/09/03 18:14:31 peer(B3D6…YQVk) - Sending keepalive packet
DEBUG: (wg0) 2021/09/03 18:15:41 peer(B3D6…YQVk) - Received handshake initiation

Recovery-3:
DEBUG: (wg0) 2021/09/03 18:16:06 peer(B3D6…YQVk) - Sending keepalive packet
DEBUG: (wg0) 2021/09/03 18:16:24 peer(B3D6…YQVk) - Retrying handshake
because we stopped hearing back after 15 seconds
DEBUG: (wg0) 2021/09/03 18:16:24 peer(B3D6…YQVk) - Sending handshake initiation


These cases are fine with me, however, sometimes this happens:

ERROR: (wg0) 2021/09/03 18:16:38 Failed to read packet from TUN
device: netlink socket closed: resource temporarily unavailable

After which `device.Close()` is called and the program exits.

Is it possible to change this behavior?

I don't know much about wg internals _or_ golang, so I tried this silly patch:

diff --git a/device/send.go b/device/send.go
index c4aa5b9..b02814f 100644
--- a/device/send.go
+++ b/device/send.go
@@ -272,7 +272,9 @@ func (device *Device) RoutineReadFromTUN() {
                if err != nil {
                        if !device.isClosed.Get() {
                                logError.Println("Failed to read
packet from TUN device:", err)
-                               device.Close()
+                               device.PutMessageBuffer(elem.buffer)
+                               device.PutOutboundElement(elem)
+                               continue
                        }

which, as you could expect, did not work. It does leave wireguard
running and the interface is still there, but the communication is
broken.

David


-- 
Stack is the new term for "I have no idea what I'm actually using".

                 reply	other threads:[~2021-09-05 11:12 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CA+UPfZ7bqKdff147=trSRWGGhbCg8VP2WHePWFT8JYZD3YarHg@mail.gmail.com' \
    --to=davidventura27@gmail.com \
    --cc=wireguard@lists.zx2c4.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).