Bug 255286 - net/wireguard-tools wg-quick up wg0 runs 2 times
Summary: net/wireguard-tools wg-quick up wg0 runs 2 times
Status: Closed FIXED
Alias: None
Product: Ports & Packages
Classification: Unclassified
Component: Individual Port(s) (show other bugs)
Version: Latest
Hardware: amd64 Any
: --- Affects Only Me
Assignee: Bernhard Froehlich
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2021-04-20 23:33 UTC by Christos Chatzaras
Modified: 2021-04-25 13:51 UTC (History)
2 users (show)

See Also:
bugzilla: maintainer-feedback? (decke)


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Christos Chatzaras 2021-04-20 23:33:26 UTC
"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
Comment 1 Christos Chatzaras 2021-04-20 23:48:13 UTC
"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
Comment 2 Jason A. Donenfeld 2021-04-20 23:56:38 UTC
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?
Comment 3 Christos Chatzaras 2021-04-21 00:25:43 UTC
Yes it doesn't terminate.
Comment 4 Jason A. Donenfeld 2021-04-21 01:42:49 UTC
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?
Comment 5 Jason A. Donenfeld 2021-04-21 01:45:56 UTC
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
Comment 6 Jason A. Donenfeld 2021-04-21 03:37:30 UTC
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
Comment 7 Christos Chatzaras 2021-04-21 08:52:33 UTC
(In reply to Jason A. Donenfeld from comment #6)

Yes the patch fixes it.
Comment 8 Jason A. Donenfeld 2021-04-23 01:39:42 UTC
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.
Comment 9 Jason A. Donenfeld 2021-04-25 13:48:00 UTC
https://cgit.freebsd.org/ports/commit/?id=b7985f90c1d3a2daaab5cdb1150884d2f322a621

Should be closable now.