diff options
author | 2021-03-17 09:46:08 -0600 | |
---|---|---|
committer | 2021-03-17 10:13:22 -0600 | |
commit | 8e0470dabb7f373ef41ab5aeb77068f84729f5da (patch) | |
tree | 7ea051b8eea1569bd0ebcea6334a9c6aa486fca4 /src | |
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>
Diffstat (limited to 'src')
-rw-r--r-- | src/Makefile | 4 | ||||
-rw-r--r-- | src/support.c | 20 | ||||
-rw-r--r-- | src/support.h | 15 |
3 files changed, 36 insertions, 3 deletions
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 |