aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--MISSING.md2
-rw-r--r--README.md7
-rw-r--r--src/Makefile6
-rw-r--r--src/compat.h71
-rw-r--r--src/support.c20
-rw-r--r--src/support.h18
-rw-r--r--src/wg_cookie.c1
-rw-r--r--src/wg_noise.c3
8 files changed, 97 insertions, 31 deletions
diff --git a/MISSING.md b/MISSING.md
index 4a75f50..e688bb4 100644
--- a/MISSING.md
+++ b/MISSING.md
@@ -6,4 +6,4 @@ There are a few changes that we had in-tree that we now don't, and will need to
- The `PRIV_NET_WG` privilege.
- `sogetsockaddr` helper function, which belongs in `uipc_socket.c`.
-We're emulating these in support.h/support.c, but they should go away for the merge.
+We're emulating these in support.h, but they should go away for the merge.
diff --git a/README.md b/README.md
index 5596904..8b526c5 100644
--- a/README.md
+++ b/README.md
@@ -6,14 +6,11 @@ This is a kernel module for FreeBSD to support [WireGuard](https://www.wireguard
First make sure you have the latest net/wireguard package installed, version ≥1.0.20210315.
-Then, on FreeBSD 13.0:
+Then, on FreeBSD 12 & 13:
```
-# pkg install wireguard
# git clone https://git.zx2c4.com/wireguard-freebsd
-# cd wireguard-freebsd/src
-# make load
-# make install
+# make -C wireguard-freebsd/src load install
```
After that, it should be possible to use `wg(8)` and `wg-quick(8)` like usual, but with the faster kernel implementation.
diff --git a/src/Makefile b/src/Makefile
index c024ea1..e787882 100644
--- a/src/Makefile
+++ b/src/Makefile
@@ -1,9 +1,11 @@
# $FreeBSD$
-KMOD= if_wg
+KMOD= if_wg
SRCS= opt_inet.h opt_inet6.h device_if.h bus_if.h ifdi_if.h
-SRCS+= if_wg.c wg_noise.c wg_cookie.c crypto.c support.c
+SRCS+= if_wg.c wg_noise.c wg_cookie.c crypto.c
+
+CFLAGS+= -include compat.h
.include <bsd.kmod.mk>
diff --git a/src/compat.h b/src/compat.h
new file mode 100644
index 0000000..649e7dc
--- /dev/null
+++ b/src/compat.h
@@ -0,0 +1,71 @@
+/* SPDX-License-Identifier: MIT
+ *
+ * Copyright (C) 2021 Jason A. Donenfeld <Jason@zx2c4.com>. All Rights Reserved.
+ *
+ * compat.h contains functions that are backported from FreeBSD's main branch. It is different from
+ * support.h, which is for things that aren't _yet_ upstream or from OpenBSD.
+ */
+
+#include <sys/param.h>
+#if __FreeBSD_version < 1300000
+#define VIMAGE
+
+#include <sys/types.h>
+#include <sys/limits.h>
+#include <sys/endian.h>
+#include <sys/socket.h>
+#include <sys/libkern.h>
+#include <sys/malloc.h>
+#include <sys/proc.h>
+#include <sys/lock.h>
+#include <sys/smp.h>
+#include <sys/gtaskqueue.h>
+#include <sys/socketvar.h>
+#include <sys/protosw.h>
+#include <net/vnet.h>
+#include <net/if.h>
+#include <net/if_var.h>
+#include <vm/uma.h>
+
+#define taskqgroup_attach(a, b, c, d, e, f) taskqgroup_attach((a), (b), (c), -1, (f))
+#define taskqgroup_attach_cpu(a, b, c, d, e, f, g) taskqgroup_attach_cpu((a), (b), (c), (d), -1, (g))
+
+#undef NET_EPOCH_ENTER
+#define NET_EPOCH_ENTER(et) NET_EPOCH_ENTER_ET(et)
+#undef NET_EPOCH_EXIT
+#define NET_EPOCH_EXIT(et) NET_EPOCH_EXIT_ET(et)
+#define NET_EPOCH_CALL(f, c) epoch_call(net_epoch_preempt, (c), (f))
+#define NET_EPOCH_ASSERT() MPASS(in_epoch(net_epoch_preempt))
+
+#undef atomic_load_ptr
+#define atomic_load_ptr(p) (*(volatile __typeof(*p) *)(p))
+
+struct taskqgroup_cpu {
+ LIST_HEAD(, grouptask) tgc_tasks;
+ struct gtaskqueue *tgc_taskq;
+ int tgc_cnt;
+ int tgc_cpu;
+};
+
+struct taskqgroup {
+ struct taskqgroup_cpu tqg_queue[MAXCPU];
+ struct mtx tqg_lock;
+ const char * tqg_name;
+ int tqg_adjusting;
+ int tqg_stride;
+ int tqg_cnt;
+};
+
+static inline void taskqgroup_drain_all(struct taskqgroup *tqg)
+{
+ struct gtaskqueue *q;
+
+ for (int i = 0; i < mp_ncpus; i++) {
+ q = tqg->tqg_queue[i].tgc_taskq;
+ if (q == NULL)
+ continue;
+ gtaskqueue_drain_all(q);
+ }
+}
+
+#endif
diff --git a/src/support.c b/src/support.c
deleted file mode 100644
index 18ce91b..0000000
--- a/src/support.c
+++ /dev/null
@@ -1,20 +0,0 @@
-/* SPDX-License-Identifier: BSD-2-Clause-FreeBSD
- *
- * Copyright (C) 2015-2021 Jason A. Donenfeld <Jason@zx2c4.com>. All Rights Reserved.
- */
-
-#include "support.h"
-#include <sys/socketvar.h>
-#include <sys/protosw.h>
-#include <net/vnet.h>
-
-int
-sogetsockaddr(struct socket *so, struct sockaddr **nam)
-{
- int error;
-
- CURVNET_SET(so->so_vnet);
- error = (*so->so_proto->pr_usrreqs->pru_sockaddr)(so, nam);
- CURVNET_RESTORE();
- return (error);
-}
diff --git a/src/support.h b/src/support.h
index c4038cf..5256e62 100644
--- a/src/support.h
+++ b/src/support.h
@@ -2,6 +2,9 @@
*
* Copyright (C) 2021 Jason A. Donenfeld <Jason@zx2c4.com>. All Rights Reserved.
* Copyright (C) 2021 Matt Dunwoodie <ncon@noconroy.net>
+ *
+ * support.h contains functions that are either not _yet_ upstream in FreeBSD 14, or are shimmed
+ * from OpenBSD. It is different from compat.h, which is strictly for backports.
*/
#ifndef _WG_SUPPORT
@@ -15,6 +18,9 @@
#include <sys/malloc.h>
#include <sys/proc.h>
#include <sys/lock.h>
+#include <sys/socketvar.h>
+#include <sys/protosw.h>
+#include <net/vnet.h>
#include <vm/uma.h>
/* TODO the following is openbsd compat defines to allow us to copy the wg_*
@@ -65,7 +71,15 @@ siphash24(const SIPHASH_KEY *key, const void *src, size_t len)
#define IFT_WIREGUARD IFT_PPP
#endif
-int
-sogetsockaddr(struct socket *so, struct sockaddr **nam);
+static inline int
+sogetsockaddr(struct socket *so, struct sockaddr **nam)
+{
+ int error;
+
+ CURVNET_SET(so->so_vnet);
+ error = (*so->so_proto->pr_usrreqs->pru_sockaddr)(so, nam);
+ CURVNET_RESTORE();
+ return (error);
+}
#endif
diff --git a/src/wg_cookie.c b/src/wg_cookie.c
index bf0ce37..ab35ad4 100644
--- a/src/wg_cookie.c
+++ b/src/wg_cookie.c
@@ -7,6 +7,7 @@
#include <sys/types.h>
#include <sys/systm.h>
#include <sys/param.h>
+#include <sys/lock.h>
#include <sys/rwlock.h>
#include <sys/malloc.h> /* Because systm doesn't include M_NOWAIT, M_DEVBUF */
#include <sys/socket.h>
diff --git a/src/wg_noise.c b/src/wg_noise.c
index 42dcc87..23603f0 100644
--- a/src/wg_noise.c
+++ b/src/wg_noise.c
@@ -5,9 +5,10 @@
*/
#include <sys/types.h>
-#include <sys/systm.h>
#include <sys/param.h>
+#include <sys/lock.h>
#include <sys/rwlock.h>
+#include <sys/systm.h>
#include "support.h"
#include "wg_noise.h"