Skip to content
Permalink
Browse files

net/wireguard: wg-quick: freebsd: workaround SIOCGIFSTATUS race in Fr…

…eeBSD kernel
  • Loading branch information...
decke committed Apr 21, 2019
1 parent 8562333 commit f4454f5c1d5cd2995f054123a2157f9daaea05c0
Showing with 32 additions and 0 deletions.
  1. +1 −0 net/wireguard/Makefile
  2. +31 −0 net/wireguard/files/patch-69ffe5b7f58ce6f55dda2b9e13ff364a0d9b3dcd
@@ -2,6 +2,7 @@

PORTNAME= wireguard
PORTVERSION= 0.0.20190406
PORTREVISION= 1
CATEGORIES= net
MASTER_SITES= https://git.zx2c4.com/WireGuard/snapshot/
DISTNAME= WireGuard-${PORTVERSION}
@@ -0,0 +1,31 @@
From 69ffe5b7f58ce6f55dda2b9e13ff364a0d9b3dcd Mon Sep 17 00:00:00 2001
From: "Jason A. Donenfeld" <Jason@zx2c4.com>
Date: Sun, 21 Apr 2019 10:11:36 +0900
Subject: wg-quick: freebsd: workaround SIOCGIFSTATUS race in FreeBSD kernel

---
src/tools/wg-quick/freebsd.bash | 8 +++++++-
1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/src/tools/wg-quick/freebsd.bash b/src/tools/wg-quick/freebsd.bash
index 9d3a4026..a1a80d36 100755
--- wg-quick/freebsd.bash
+++ wg-quick/freebsd.bash
@@ -274,7 +274,13 @@ monitor_daemon() {
# endpoints change.
while read -r event; do
[[ $event == RTM_* ]] || continue
- ifconfig "$INTERFACE" >/dev/null 2>&1 || break
+ # The goal is simply to determine whether or not the interface exists. The
+ # straight-forward way of doing this would be `ifconfig $INTERFACE`, but this
+ # invokes the SIOCGIFSTATUS ioctl, which races with interface shutdown inside
+ # the tun driver, resulting in a kernel panic. So we work around it the stupid
+ # way by using the one utility that appears to call if_nametoindex fairly early
+ # and fails if it doesn't exist: `arp`.
+ arp -i "$INTERFACE" -a -n >/dev/null 2>&1 || break
[[ $AUTO_ROUTE4 -eq 1 || $AUTO_ROUTE6 -eq 1 ]] && set_endpoint_direct_route
# TODO: set the mtu as well, but only if up
done < <(route -n monitor)) & disown
--
cgit v1.2.1-20-gc37e

0 comments on commit f4454f5

Please sign in to comment.
You can’t perform that action at this time.