Browse Source

net/wireguard: wg-quick: freebsd: workaround SIOCGIFSTATUS race in FreeBSD kernel

master
Bernhard Fröhlich 2 months ago
parent
commit
8b5644860d
Signed by: Bernhard Froehlich <decke@bluelife.at> GPG Key ID: 4DD88C3F9F3B8333
1 changed files with 23 additions and 13 deletions
  1. 23
    13
      net/wireguard/files/patch-b3e1a1b07d3631bd816f9bfc27452a89dc29fa28

net/wireguard/files/patch-4d8aab09932862bba6cf3fbb02ef57b3fbb438dd → net/wireguard/files/patch-b3e1a1b07d3631bd816f9bfc27452a89dc29fa28 View File

@@ -1,22 +1,22 @@
1
-From 4d8aab09932862bba6cf3fbb02ef57b3fbb438dd Mon Sep 17 00:00:00 2001
1
+From b3e1a1b07d3631bd816f9bfc27452a89dc29fa28 Mon Sep 17 00:00:00 2001
2 2
 From: "Jason A. Donenfeld" <Jason@zx2c4.com>
3 3
 Date: Sun, 21 Apr 2019 10:11:36 +0900
4 4
 Subject: wg-quick: freebsd: workaround SIOCGIFSTATUS race in FreeBSD kernel
5 5
 
6 6
 ---
7
- src/tools/wg-quick/freebsd.bash | 19 +++++++++++++++++--
8
- 1 file changed, 17 insertions(+), 2 deletions(-)
7
+ src/tools/wg-quick/freebsd.bash | 31 ++++++++++++++++++++++---------
8
+ 1 file changed, 22 insertions(+), 9 deletions(-)
9 9
 
10 10
 diff --git a/src/tools/wg-quick/freebsd.bash b/src/tools/wg-quick/freebsd.bash
11
-index 9d3a4026..6be161a3 100755
11
+index 9d3a4026..72e0bd04 100755
12 12
 --- wg-quick/freebsd.bash
13 13
 +++ wg-quick/freebsd.bash
14
-@@ -137,13 +137,27 @@ del_routes() {
14
+@@ -137,18 +137,30 @@ del_routes() {
15 15
  	done
16 16
  }
17 17
  
18 18
 +if_exists() {
19
-+	# The goal is simply to determine whether or not the interface exists. The
19
++	# HACK: The goal is simply to determine whether or not the interface exists. The
20 20
 +	# straight-forward way of doing this would be `ifconfig $INTERFACE`, but this
21 21
 +	# invokes the SIOCGIFSTATUS ioctl, which races with interface shutdown inside
22 22
 +	# the tun driver, resulting in a kernel panic. So we work around it the stupid
@@ -30,17 +30,27 @@ index 9d3a4026..6be161a3 100755
30 30
 +}
31 31
 +
32 32
  del_if() {
33
- 	local line monitor_pid
33
+-	local line monitor_pid
34 34
  	[[ $HAVE_SET_DNS -eq 0 ]] || unset_dns
35
- 	exec 39< <(exec route -n monitor 2>/dev/null)
36
- 	monitor_pid=$!
35
+-	exec 39< <(exec route -n monitor 2>/dev/null)
36
+-	monitor_pid=$!
37 37
  	cmd rm -f "/var/run/wireguard/$INTERFACE.sock"
38 38
 -	while ifconfig "$INTERFACE" >/dev/null 2>&1; do
39
+-		while read -r line; do
40
+-			[[ $line =~ ^RTM_IFANNOUNCE:.* ]] && break
41
+-		done <&39
39 42
 +	while if_exists; do
40
- 		while read -r line; do
41
- 			[[ $line =~ ^RTM_IFANNOUNCE:.* ]] && break
42
- 		done <&39
43
-@@ -274,7 +288,8 @@ monitor_daemon() {
43
++		# HACK: it would be nice to `route monitor` here and wait for RTM_IFANNOUNCE
44
++		# but it turns out that the announcement is made before the interface
45
++		# disappears so we sometimes get a hang. So, we're instead left with polling
46
++		# in a sleep loop like this.
47
++		sleep 0.1
48
+ 	done
49
+-	kill $monitor_pid
50
+ }
51
+ 
52
+ up_if() {
53
+@@ -274,7 +286,8 @@ monitor_daemon() {
44 54
  	# endpoints change.
45 55
  	while read -r event; do
46 56
  		[[ $event == RTM_* ]] || continue

Loading…
Cancel
Save