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 via email to