Development discussion of WireGuard
 help / color / mirror / Atom feed
From: "Loren McIntyre" <loren@mcint.io>
To: wireguard@lists.zx2c4.com
Subject: wg-quick: darwin: DNS cleanup & disabled/inactive interface causing setup to fail
Date: Thu, 21 Jan 2021 22:57:32 -0800	[thread overview]
Message-ID: <7a51e0ee-73f8-441a-9cdd-3aa305832c85@www.fastmail.com> (raw)

Hello!

I've been using wg-quick on macOS 10.14, with wireguard-tools at 1.0.20200827. I had one issue prompt investigation, DNS changes persisted after an interface failed to come up. I found a second, related issue, and added an extra error handling case in the wg-quick/darwin.bash script to fix the issue.
---
First, when some network interfaces or "services" are disabled, wg-quick would attempt to bring up the interface, in darwin.bash:449:cmd_up(), something errors and the trap handler runs before :446:monitor_daemon, but after / as-concluding :465:...set_dns, on INT / TERM / EXIT.

This failure occurred as set_dns concluded, but before monitor_daemon and its cleanup del_dns trap, so wg-quick leaves DNS for the system misconfigured. Adding del_dns to the cmd_up trap seems appropriate, and leaving del_dns in the monitor_daemon trap seems appropriate. 


Minimal reproduction of the DNS non-cleanup failure should require only: a network interface set to inactive/disabled in Network.prefPane, and using wg-quick to bring up an interface.
- Interface: disabled / wg-quick: fails. 
- Interface: enabled / wg-quick: succeeds. 
---
Second, when the last interface in the loop is disabled, `networksetup -setdnsservers 'EXAMPLE IF' 10.0.100.53`, returns only:
> (Please note: EXAMPLE IF is currently disabled)

Because `-e` is set for the whole script, when this line is read, the final comparison of the loop fails, causing EXIT when set_dns exits.
> src/wg-quick/darwin.bash:298:           while read -r response; do
> src/wg-quick/darwin.bash:299:                   [[ $response == *Error* ]] && echo "$response" >&2

See toy examples in:
> while read -r var ; do [[ $var == 2 ]] && echo "var: $var"; done < <(seq 3); echo ?$?
> while read -r var ; do [[ $var == 3 ]] && echo "var: $var"; done < <(seq 3); echo ?$?
---
Patches to follow

Best,
Loren

             reply	other threads:[~2021-01-24 16:30 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-01-22  6:57 Loren McIntyre [this message]
2021-01-22  6:58 ` [PATCH 1/2] wg-quick: darwin: restore original dns settings on failed up Loren McIntyre
2021-01-22  6:58   ` [PATCH 2/2] wg-quick: darwin: handle disabled interface Loren McIntyre

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=7a51e0ee-73f8-441a-9cdd-3aa305832c85@www.fastmail.com \
    --to=loren@mcint.io \
    --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).