aboutsummaryrefslogtreecommitdiffstats
path: root/src/support.h
diff options
context:
space:
mode:
authorMatt Dunwoodie <ncon@noconroy.net>2021-04-16 22:21:34 +1000
committerMatt Dunwoodie <ncon@noconroy.net>2021-04-19 10:38:03 +1000
commit0b005923e758cec6d7420dff0c08a62f7c347066 (patch)
tree841e7bb0e2f763c025c988dcb7058f9b81fd21cf /src/support.h
parentif_wg: warn when we can't bind to sockets (diff)
downloadwireguard-freebsd-0b005923e758cec6d7420dff0c08a62f7c347066.tar.xz
wireguard-freebsd-0b005923e758cec6d7420dff0c08a62f7c347066.zip
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 <ncon@noconroy.net>
Diffstat (limited to 'src/support.h')
-rw-r--r--src/support.h21
1 files changed, 21 insertions, 0 deletions
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