"wg-quick up wg0" runs 2 times when I start wireguard and when I stop wireguard one instance still runs. ---- root@backup1:~ # service wireguard start [#] ifconfig wg create name wg0 [#] wg setconf wg0 /dev/stdin [#] ifconfig wg0 inet 192.168.1.1/32 alias [#] ifconfig wg0 mtu 1420 [#] ifconfig wg0 up [#] route -q -n add -inet 192.168.2.1/32 -interface wg0 [+] Backgrounding route monitor ---- root@backup1:~ # ps -aux | grep wg0 root 28326 0.0 0.0 12868 2004 1 S+ 02:27 0:00.00 grep wg0 root 60342 0.0 0.0 14836 4208 1 S 02:27 0:00.00 /usr/local/bin/bash /usr/local/bin/wg-quick up wg0 root 94427 0.0 0.0 14836 4204 1 S 02:27 0:00.00 /usr/local/bin/bash /usr/local/bin/wg-quick up wg0 ---- root@backup1:~ # service wireguard stop [#] ifconfig wg0 destroy ---- root@backup1:~ # ps -aux | grep wg0 root 33140 0.0 0.0 12868 2004 1 S+ 02:27 0:00.00 grep wg0 root 94427 0.0 0.0 14836 4204 1 I 02:27 0:00.00 /usr/local/bin/bash /usr/local/bin/wg-quick up wg0
"route -n monitor" keeps the wg-quick script open. ---- root@backup1:~ # ps -aux | grep route root 23164 0.0 0.0 12796 2276 0 S 02:45 0:00.00 route -n monitor ---- kill -9 23164 ---- root@backup1:~ # ps -aux | grep wg0 root 40659 0.0 0.0 12868 2340 0 S+ 02:46 0:00.00 grep wg0
The service runs a little route watcher script in the background. When wg0 is destroyed, that little watcher script should terminate on its own. Are you saying that you're not seeing it terminate?
Yes it doesn't terminate.
Hmm not sure I'm seeing the same behavior you are: [root@devil ~]# wg-quick up demo [#] ifconfig wg create name demo [#] wg setconf demo /dev/stdin [#] ifconfig demo inet 192.168.4.203/24 alias [#] ifconfig demo mtu 1420 [#] ifconfig demo up [#] resolvconf -a demo -x [#] route -q -n add -inet 0.0.0.0/1 -interface demo [#] route -q -n add -inet 128.0.0.0/1 -interface demo [#] route -q -n delete -inet 163.172.161.0 [#] route -q -n add -inet 163.172.161.0 -gateway 10.0.2.2 [+] Backgrounding route monitor [root@devil ~]# ps aux|grep wg-quick root 1209 0.0 0.1 14840 4804 0 S 01:42 0:00.00 /usr/local/bin/bash /usr/local/bin/wg-quick up demo root 1213 0.0 0.1 14840 4796 0 S 01:42 0:00.00 /usr/local/bin/bash /usr/local/bin/wg-quick up demo root 1216 0.0 0.0 12872 2432 0 S+ 01:42 0:00.00 grep wg-quick [root@devil ~]# wg-quick down demo [#] ifconfig demo destroy [#] route -q -n delete -inet 163.172.161.0 [#] resolvconf -d demo [root@devil ~]# ps aux|grep wg-quick root 1290 0.0 0.0 12872 2432 0 S+ 01:42 0:00.00 grep wg-quick Can you reproduce similarly?
I also see the correct behavior (not the broken behavior) using service: [root@devil ~]# service wireguard start [#] ifconfig wg create name demo [#] wg setconf demo /dev/stdin [#] ifconfig demo inet 192.168.4.203/24 alias [#] ifconfig demo mtu 1420 [#] ifconfig demo up [#] resolvconf -a demo -x [#] route -q -n add -inet 0.0.0.0/1 -interface demo [#] route -q -n add -inet 128.0.0.0/1 -interface demo [#] route -q -n delete -inet 163.172.161.0 [#] route -q -n add -inet 163.172.161.0 -gateway 10.0.2.2 [+] Backgrounding route monitor [root@devil ~]# ps aux | grep wg-quick root 1436 0.0 0.1 14840 4720 0 S 01:44 0:00.00 /usr/local/bin/bash /usr/local/bin/wg-quick up demo root 1440 0.0 0.1 14840 4712 0 S 01:44 0:00.00 /usr/local/bin/bash /usr/local/bin/wg-quick up demo [root@devil ~]# service wireguard stop [#] ifconfig demo destroy [#] route -q -n delete -inet 163.172.161.0 [#] resolvconf -d demo [root@devil ~]# ps aux | grep wg-quick root 1524 0.0 0.0 12872 2432 0 S+ 01:45 0:00.00 grep wg-quick
I managed to repro! Tricky as it's a race condition. Let me know if this fixes it for you: https://git.zx2c4.com/wireguard-tools/commit/?id=96e42feb3f41e2161141d4958e2637d9dee6f90a
(In reply to Jason A. Donenfeld from comment #6) Yes the patch fixes it.
Great. So this can probably change to "IN PROGRESS" and then it can be closed when I cut a new wireguard-tools release with the fix.
https://cgit.freebsd.org/ports/commit/?id=b7985f90c1d3a2daaab5cdb1150884d2f322a621 Should be closable now.