From 0b005923e758cec6d7420dff0c08a62f7c347066 Mon Sep 17 00:00:00 2001 From: Matt Dunwoodie Date: Fri, 16 Apr 2021 22:21:34 +1000 Subject: if_wg: import latest wg_noise.{c,h} Note: this is a partial diff, introducing temporary bugs that will be resolved in following commits, detailed below. This commit brings wg_noise.{c,h} up to date with wireguard-openbsd. The primary motivator for this large patchset is to allow checking nonces serial, requiring a reference to the receiving keypair across noise_* calls. Due to requiring reference counting on the keypairs, we also take this opportunity to throw away the old locking and bring in EPOCH (roughly equivalent to SMR on OpenBSD and RCU on Linux). The changes to if_wg.c are purely to allow it to compile, there are most certainly refcount leaks present (to be addressed in the following commits). Readers should review wg_noise.{c,h} in their entirety rather than the diffs, as there are significant changes. if_wg.c can be reviewed, but must be contextualised with the following commits (repace wg_tag with wg_packet, encrypt mbuf in place). Signed-off-by: Matt Dunwoodie --- src/support.h | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'src/support.h') diff --git a/src/support.h b/src/support.h index 5256e62..99cd518 100644 --- a/src/support.h +++ b/src/support.h @@ -82,4 +82,25 @@ sogetsockaddr(struct socket *so, struct sockaddr **nam) return (error); } +/* These are defined in sys/compat/linuxkpi/common/include/linux/compiler.h, + * however I don't really want to include all that. */ +#define barrier() __asm__ __volatile__("": : :"memory") + +#define ACCESS_ONCE(x) (*(volatile __typeof(x) *)&(x)) + +#define WRITE_ONCE(x,v) do { \ + barrier(); \ + ACCESS_ONCE(x) = (v); \ + barrier(); \ +} while (0) + +#define READ_ONCE(x) ({ \ + __typeof(x) __var = ({ \ + barrier(); \ + ACCESS_ONCE(x); \ + }); \ + barrier(); \ + __var; \ +}) + #endif -- cgit v1.2.3-59-g8ed1b