diff options
author | 2021-03-17 09:46:08 -0600 | |
---|---|---|
committer | 2021-03-17 10:13:22 -0600 | |
commit | 8e0470dabb7f373ef41ab5aeb77068f84729f5da (patch) | |
tree | 7ea051b8eea1569bd0ebcea6334a9c6aa486fca4 | |
parent | Initial import (diff) | |
download | wireguard-freebsd-8e0470dabb7f373ef41ab5aeb77068f84729f5da.tar.xz wireguard-freebsd-8e0470dabb7f373ef41ab5aeb77068f84729f5da.zip |
support: prepare for out of tree builds
This involves weird backporting things. Hopefully support.c here is not
as bad as compat.h on Linux.
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
-rw-r--r-- | MISSING.md | 9 | ||||
-rw-r--r-- | README.md | 12 | ||||
-rw-r--r-- | src/Makefile | 4 | ||||
-rw-r--r-- | src/support.c | 20 | ||||
-rw-r--r-- | src/support.h | 15 |
5 files changed, 56 insertions, 4 deletions
diff --git a/MISSING.md b/MISSING.md new file mode 100644 index 0000000..4a75f50 --- /dev/null +++ b/MISSING.md @@ -0,0 +1,9 @@ +### Things missing out-of-tree + +There are a few changes that we had in-tree that we now don't, and will need to add back when this is merged. + +- Link local address for the new ether type, `IFT_WIREGUARD`. +- 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. @@ -4,6 +4,16 @@ This is a kernel module for FreeBSD to support [WireGuard](https://www.wireguard ### Installation instructions +First make sure you have the latest net/wireguard package installed, version ≥1.0.20210315. + +Then, on FreeBSD 13.0: + ``` -TODO +# pkg install wireguard +# git clone https://git.zx2c4.com/wireguard-freebsd +# cd wireguard-freebsd/src +# make load +# make 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 d65cf80..c024ea1 100644 --- a/src/Makefile +++ b/src/Makefile @@ -2,10 +2,8 @@ KMOD= if_wg -.PATH: ${SRCTOP}/sys/dev/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 +SRCS+= if_wg.c wg_noise.c wg_cookie.c crypto.c support.c .include <bsd.kmod.mk> diff --git a/src/support.c b/src/support.c new file mode 100644 index 0000000..18ce91b --- /dev/null +++ b/src/support.c @@ -0,0 +1,20 @@ +/* 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 f613f40..c4038cf 100644 --- a/src/support.h +++ b/src/support.h @@ -10,6 +10,7 @@ #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> @@ -51,6 +52,20 @@ siphash24(const SIPHASH_KEY *key, const void *src, size_t len) return (SipHashX(&ctx, 2, 4, (const uint8_t *)key, src, len)); } + +#ifndef ARRAY_SIZE #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0])) +#endif + +#ifndef PRIV_NET_WG +#define PRIV_NET_WG PRIV_NET_HWIOCTL +#endif + +#ifndef IFT_WIREGUARD +#define IFT_WIREGUARD IFT_PPP +#endif + +int +sogetsockaddr(struct socket *so, struct sockaddr **nam); #endif |